Mys 1.3.6 Adoptables with Backgrounds mod 1.3.6

Forum
Last Post
Threads / Messages

Kesstryl

Member
Member
Joined
Feb 22, 2012
Messages
159
Points
18
Mysidian Dollar
11,212
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:

Similar threads

Users who are viewing this thread

  • Forum Contains New Posts
  • Forum Contains No New Posts

Forum statistics

Threads
4,249
Messages
32,876
Members
1,597
Latest member
emotidogzz
BETA

Latest Threads

Latest Posts

Top