Mys 1.3.6 Adoptables with Backgrounds mod 1.3.6

Forum
Last Post
Threads / Messages

Kesstryl

Member
Member
Joined
Feb 22, 2012
Messages
206
Points
28
Mysidian Dollar
11,706
This is a very simple mod that sets a default background to your pets and changes it from your item inventory. You do not need to manually remove and add backgrounds, the background will simply update and move the old one back into your inventory when you use a new one. Less clicking.

Lets start with the database stuff:

Go to your items_functions table and add this:
INSERT INTO `adopts_items_functions` (`ifid`, `function`, `intent`, `description`)
VALUES (NULL, 'Background1', 'Adoptable', 'Background you can equip to one of your adoptables.');

Go to phpmyadmin and go to adopts_owned_adoptables. Go to structure and click to add these columns to the end of the table. Enter these details:
ALTER TABLE `adopts_owned_adoptables` ADD ``bgitemid`` INT NOT NULL DEFAULT 'id_of_your_default_background_image';
ALTER TABLE `adopts_owned_adoptables` ADD ``adoptbackground`` VARCHAR(500) NULL DEFAULT 'http://localhost/mysidia1.3.6/picuploads/your_default_background_image.png(or .gif or .jpg)';



Go to
model->domainmodel->itemfunction

find this: protected $validFunctions = ["Valuable", "Level1", "Level2", "Level3", "Click1", "Click2", "Breed1", "Breed2", "Alts1", "Alts2", "Name1", "Name2"];

and add ,"Background1" at the end so it looks like this:
Code:
protected $validFunctions = ["Valuable", "Level1", "Level2", "Level3", "Click1", "Click2", "Breed1", "Breed2", "Alts1", "Alts2", "Name1", "Name2","Background1"];

At the bottom of the class on that page add this method:

Code:
    protected function applyBackground1(OwnedItem $item, OwnedAdoptable $adopt){
        $mysidia = Registry::get("mysidia");
        if($item->hasCategory("Background")){
        $oldItem = new OwnedItem($adopt->getBackgroundID(), $mysidia->user->getID());
        $oldItem->add(1, $mysidia->user->getID());
        $mysidia->db->update("owned_adoptables", ["bgitemid" => $item->getID(), "adoptbackground" => $item->getImageURL()], "aid ='{$adopt->getID()}' and owner='{$item->getOwner()}'");
        $message = "You have changed your pet's background! <a href='{$mysidia->path->getAbsolute()}myadopts/manage/{$adopt->getID()}'>My Adopts manage page</a>. ";
        $delitem = $item->remove(0, $mysidia->user->getID());
        }
        else{
        $message = "There was an error applying this background";
        }
        return $note;
    }

Now go to
model->domainmodel->ownedadoptable

add this at top with protected the other protected variables:

protected $bgitemid;
protected $adoptbackground;

add these somewhere above or below the method calling adopt image function:


Code:
    public function getBackgroundID(){ //get background image item id
        return $this->bgitemid;
    }

    public function getAdoptBackground(){
        return $this->adoptbackground;
    }

Go to view/main/myadoptsview

make sure these are in namespace block

use Resource\GUI\Element\Background;
use Resource\GUI\Document\Division;

Right now I have my pets with backgrounds viewable on my adopts manage page. Here's how I set up my view with the manage method:

Code:
    public function manage(){     
        $document = $this->document;     
        $ownedAdopt = $this->getField("ownedAdopt");
        $adoptbackground = "{$ownedAdopt->getAdoptBackground()}";
        $background = new Image($adoptbackground);
        $background->setType("background");
        $image = $this->getField("image");
        $document->setTitle("Managing {$ownedAdopt->getName()}");

        $petImage = new Division(NULL,"petimage");
        $petImage->setAlign(new Align("center", "center"));
        $petImage->setBackground($background);
        $petImage->add($image);

        $document->add($petImage);
        $document->add(new Comment("<br><br>This page allows you to manage {$ownedAdopt->getName()}.  Click on an option below to change settings.<br>"));
        $document->add(new Image("templates/icons/add.gif"));
        $document->add(new Link("levelup/click/{$ownedAdopt->getID()}", " Level Up {$ownedAdopt->getName()}", TRUE));
        $document->add(new Image("templates/icons/stats.gif"));
        $document->add(new Link("myadopts/stats/{$ownedAdopt->getID()}", " Get Stats for {$ownedAdopt->getName()}", TRUE));
        $document->add(new Image("templates/icons/bbcodes.gif"));
        $document->add(new Link("myadopts/bbcode/{$ownedAdopt->getID()}", " Get BBCodes / HTML Codes for {$ownedAdopt->getName()}", TRUE));
           $document->add(new Image("templates/icons/title.gif"));
        $document->add(new Link("myadopts/rename/{$ownedAdopt->getID()}", " Rename {$ownedAdopt->getName()}", TRUE));
        $document->add(new Image("templates/icons/trade.gif"));
        $document->add(new Link("myadopts/trade/{$ownedAdopt->getID()}", " Change Trade status for {$ownedAdopt->getName()}", TRUE));
        $document->add(new Image("templates/icons/freeze.gif"));
        $document->add(new Link("myadopts/freeze/{$ownedAdopt->getID()}", " Freeze or Unfreeze {$ownedAdopt->getName()}", TRUE));
        $document->add(new Image("templates/icons/delete.gif"));
        $document->add(new Link("pound/pound/{$ownedAdopt->getID()}", " Pound {$ownedAdopt->getName()}", TRUE));
        $document->add(new Link("myadopts/index/}", "Return to Manage Adoptables page"));     
    }

Finally use CSS to adjust how the the background and pet are displayed. The myadoptsview code above adds a new div id called petimage which you can style in your templates CSS:

Mine looks like this:
Code:
#petimage{
background-size: cover;
background-position: center;
background-repeat: no-repeat;
width: 500px;
height: 250;
margin: auto;
display: flex;
justify-content: center;
align-items: center;
}

If you have any trouble with this, I probably forgot to post something here so make sure you let me know.
 
Last edited:
Really great Mod, thank you for all this!

One question, how would I add this to stats so its seen by all members?



I haven't coded in some time and I am very rusty ...

If anyone knows thanks in advance.


Update: Tried this to add a new background and got an error:


An error has occured ...​



The item specified is invalid...


Maybe I have the wrong item ID in bgitem? What ID do I need to use for that? Should I put something in value? I am using the ID number from adopts items.. and I have its category as Background...

I also tried using the ID number from the adoptbackground. Can't seem to get it to work.
 
Really great Mod, thank you for all this!

One question, how would I add this to stats so its seen by all members?



I haven't coded in some time and I am very rusty ...

If anyone knows thanks in advance.


Update: Tried this to add a new background and got an error:


An error has occured ...​



The item specified is invalid...


Maybe I have the wrong item ID in bgitem? What ID do I need to use for that? Should I put something in value? I am using the ID number from adopts items.. and I have its category as Background...

I also tried using the ID number from the adoptbackground. Can't seem to get it to work.
Making public profiles for all pets is not in the scope of this mod, but it is something I hope to work on at some point. The public can see your favorite pet with the background.

the ID should be pulled from the database automatically in the model from this part:

Now go to
model->domainmodel->ownedadoptable

add this at top with protected the other protected variables:

protected $bgitemid;
protected $adoptbackground;

add these somewhere above or below the method calling adopt image function:




Code:

public function getBackgroundID(){ //get background image item id
return $this->bgitemid;
}

public function getAdoptBackground(){
return $this->adoptbackground;
}

as long as it's called bgitemid in your database, it should be called correctly without manual input from you.
 
Thank you for this information!

I really appreciate it.

I haven't been coding in some time and really got rusty, getting back into it.
 
Had a thought, not sure how it would work.

Would one be able to use this to apply items in *front* of the pets?

Seems it wouldn't be a hard thing to alter to do that, and wow, the possibilities! Wouldn't want it to stretch across of course, thinking something that allows toys etc to be shown in front of pets ...

They'd be small, and need to stay small to look right ...
 
This mod uses the html background property to add backgrounds to the image divs. Adding items would require layering images and right now I have no clue how to do that yet in 1.3.6, but I plan to look into it into the future. Right now I have other more important things to get working on my site so it will be awhile before I visit this idea.
 
I realize I forgot to add showing backgrounds on favorite pet public page so I'll add it here

Go to model/viewmodel/uerprofileviewmodel

add this in the namespace stuff:

use Model\DomainModel\OwnedAdoptable;

and make sure this is added

Code:
    public function getFavpet(){
        $favpet = $this->model->getFavpet();
        return $favpet ? new Link("levelup/click/{$favpet}", new Image("levelup/siggy/{$favpet}"), TRUE)
                       : new Comment("None Selected");    
    }

    public function getFavpetBackground(){
        $favpet = $this->model->getFavpet();
        $adopt = new OwnedAdoptable($favpet);
        $adoptbackground = $adopt->getAdoptBackground();
        return $adoptbackground;
    }

and further down replace the displayAdopts() function with this:

Code:
    protected function displayAdopts(){
        $division = new Division;
        $spotlight = new Comment(".:AdoptSpotlight:.");
        $spotlight->setHeading(2);
        $division->add($spotlight);

        $adoptbackground = $this->getFavpetBackground();
        $background = new Image($adoptbackground);
        $background->setType("background");    
        $petImage = new Division(NULL,"petimage");
        $petImage->setAlign(new Align("center", "center"));
        $petImage->setBackground($background);
        $petImage->add($this->getFavpet());
        $division->add($petImage);
        $division->add(new Comment($this->model->getAbout()));
       
        $user = $this->model->getUser();
        $title = new Comment("{$user->getUsername()}'s Pets:");
        $title->setBold(TRUE);
        $title->setUnderlined(TRUE);
        $division->add($title);

        $adopts = $user->getOwnedAdopts();
        foreach($adopts as $adopt){
            $division->add(new Link("levelup/click/{$adopt->getAdoptID()}", $adopt->getImage(Model::GUI)));
        }
        return $division;
    }

On reflection it would probably be better to call the background from ownedadoptableviewmodel but I'll leave this here for now until I get around to tweaking my site and making sure it works.
 
Thank you! Will be adding this and trying it today, appreciate the update!
 

Similar threads

Users who are viewing this thread

  • Forum Contains New Posts
  • Forum Contains No New Posts

Forum statistics

Threads
4,277
Messages
33,118
Members
1,602
Latest member
BerrieMilk
BETA

Latest Threads

Top