Mys 1.3.6 Adoptables with Backgrounds mod 1.3.6

Forum
Last Post
Threads / Messages

Kesstryl

Member
Member
Joined
Feb 22, 2012
Messages
221
Points
28
Mysidian Dollar
11,848
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 applyBackground(OwnedItem $item, OwnedAdoptable $adopt){
        $mysidia = Registry::get("mysidia");
        if($item->hasCategory("Background")){
            if($adopt->getBackgroundID() > 0){
                $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()}'");
            $note = "You have changed your pet's background! <br><a href='{$mysidia->path->getAbsolute()}myadopts/manage/{$adopt->getID()}'>My Adopts manage page</a>. ";
            $delitem = $item->remove(0, $mysidia->user->getID());
        }
        else{
        $note = "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!
 
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.
I found a fix for the item is invalid error. Replace the model/domainmodel/itemfunctions block for the background function with this:
Code:
    protected function applyBackground(OwnedItem $item, OwnedAdoptable $adopt){
        $mysidia = Registry::get("mysidia");
        if($item->hasCategory("Background")){
            if($adopt->getBackgroundID() > 0){
                $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()}'");
            $note = "You have changed your pet's background! <br><a href='{$mysidia->path->getAbsolute()}myadopts/manage/{$adopt->getID()}'>My Adopts manage page</a>. ";
            $delitem = $item->remove(0, $mysidia->user->getID());
        }
        else{
        $note = "There was an error applying this background";
        }
        return $note;
    }
 
Going to work on this again, over the weekend I think :) Thanks for the update on this, seems to be a good fix! :)
 
Seems to be working, thank you again! Also, I changed the word applyBackground to applyBackground1, in the item functions.


Code:
protected function applyBackground(OwnedItem $item, OwnedAdoptable $adopt){


Code:
protected function applyBackground1(OwnedItem $item, OwnedAdoptable $adopt){


Question:

How would I add this for the Stats or Levelup page?

Might that show up to other members?


Also .. I think this can be used to add items. Just make sure they are shown not where the pet itself is. So you are adding them to the back, so to speak. Backgrounds with items/pets for pets, etc ! Can only have one background at a time, so just one background or item/pet background, but its something!
 
Last edited:
Example -- and he can easy get a background that has a companion pet, an item, etc ... without layering :)

Bubby.png
 
Example -- and he can easy get a background that has a companion pet, an item, etc ... without layering :)

View attachment 865
I'll take a look at this tomorrow. I'm sure it will have to do with calling the background function from ownedadoptable model within the level up controller and passing it into the level up view in the same manner as was done in the myadopts view.
 
Example -- and he can easy get a background that has a companion pet, an item, etc ... without layering :)

View attachment 865
Code:
        $image = $adopt->getImage(Model::GUI);

        $petImage = new Division(NULL,"petimage");
        $petImage->setAlign(new Align("center", "center"));
        $petImage->setBackground($background);
        $petImage->add($image);
        $petImage->setLineBreak(TRUE);        
       
        $summary = new Division;
        $summary->setAlign(new Align("center"));
        $summary->add($petImage);
        $summary->add(new Comment("{$this->lang->gave}{$adopt->getName()} one {$this->lang->unit}."));
I got it to work on Level up pages.

Go to levelupview and add this at the top with the other namespace things:

use Resource\GUI\Element\Background;

Go to the click function and add this chunk of code over everything between the first and last lines in this code block including the first and last lines:
Code:
        $image = $adopt->getImage(Model::GUI);

        $petImage = new Division(NULL,"petimage");
        $petImage->setAlign(new Align("center", "center"));
        $petImage->setBackground($background);
        $petImage->add($image);
        $petImage->setLineBreak(TRUE);         
        
        $summary = new Division;
        $summary->setAlign(new Align("center"));
        $summary->add($petImage);
        $summary->add(new Comment("{$this->lang->gave}{$adopt->getName()} one {$this->lang->unit}."));
 
WOW ... thank you so much!!!! When I am not swamped at work I will add this, so excited! :) :)
 
Not sure what I am doing wrong. Not showing for me on Level Up .. not sure why, made sure to follow closely what to put where. At least I think I did :D And I did remember to add the namespace bit too ...



Code:
class LevelupView extends View{
    
    public function click(){
        
        
        $mysidia = Registry::get("mysidia");
        $document = $this->document;               
        $adopt = $this->getField("adopt");           
        $reward = $this->getField("reward");
        $document->setTitle("{$this->lang->gave} {$adopt->getName()} one {$this->lang->unit}");


                $image = $adopt->getImage(Model::GUI);


        $petImage = new Division(NULL,"petimage");
        $petImage->setAlign(new Align("center", "center"));
        $petImage->setBackground($background);
        $petImage->add($image);
        $petImage->setLineBreak(TRUE);         
        
        $summary = new Division;
        $summary->setAlign(new Align("center"));
        $summary->add($petImage);
        $summary->add(new Comment("{$this->lang->gave}{$adopt->getName()} one {$this->lang->unit}."));
        
        
        
        
        $summary->add(new Comment($this->lang->encourage));
        if($mysidia->user->isLoggedIn()){
 
I'll post my block to compare:

Code:
namespace View\Main;
use Resource\Collection\ArrayList;
use Resource\Core\Model;
use Resource\Core\Registry;
use Resource\Core\View;
use Resource\GUI\Component\Image;
use Resource\GUI\Component\Link;
use Resource\GUI\Container\Table;
use Resource\GUI\Container\TCell;
use Resource\GUI\Container\TRow;
use Resource\GUI\Document\Comment;
use Resource\GUI\Document\Division;
use Resource\GUI\Element\Background;
use Resource\GUI\Element\Align;

class LevelupView extends View{
    
    public function click(){
        $mysidia = Registry::get("mysidia");
        $document = $this->document;               
        $adopt = $this->getField("adopt");           
        $reward = $this->getField("reward");
        $document->setTitle("{$this->lang->gave} {$adopt->getName()} one {$this->lang->unit}");

        $adoptbackground = "{$adopt->getAdoptBackground()}";
        $background = new Image($adoptbackground);
        $background->setType("background");
        $image = $adopt->getImage(Model::GUI);

        $petImage = new Division(NULL,"petimage");
        $petImage->setAlign(new Align("center", "center"));
        $petImage->setBackground($background);
        $petImage->add($image);
        $petImage->setLineBreak(TRUE);         
        
        $summary = new Division;
        $summary->setAlign(new Align("center"));
        $summary->add($petImage);
        $summary->add(new Comment("{$this->lang->gave}{$adopt->getName()} one {$this->lang->unit}."));
        $summary->add(new Comment($this->lang->encourage));
        if($mysidia->user->isLoggedIn()){
            $summary->add(new Comment("<br> You have earned {$reward} {$mysidia->settings->cost} for leveling up this adoptable. "));
            $summary->add(new Comment("You now have {$mysidia->user->getMoney()} {$mysidia->settings->cost}"));
            $itemdrop = $this->getField("itemdrop");
            if($itemdrop) $summary->add(new Comment("Congratulations, you have acquired an item {$itemdrop->getItemName()} by clicking this adoptable!"));
            $summary->add(new Link("levelup/profile/{$adopt->getAdoptID()}", "Visit this Adoptable"));
            $summary->add(new Comment("</br>"));
        }
        $summary->add(new Link("myadopts/index/}", "Go to Your Adoptables"));
        $summary->add(new Comment("</br>"));
        $summary->add(new Link("levelup/daycare/}", "Go to the Daycare"));
        $document->add($summary);
    }
 
Not sure what I am doing wrong. Not showing for me on Level Up .. not sure why, made sure to follow closely what to put where. At least I think I did :D And I did remember to add the namespace bit too ...



Code:
class LevelupView extends View{
   
    public function click(){
       
       
        $mysidia = Registry::get("mysidia");
        $document = $this->document;              
        $adopt = $this->getField("adopt");          
        $reward = $this->getField("reward");
        $document->setTitle("{$this->lang->gave} {$adopt->getName()} one {$this->lang->unit}");


                $image = $adopt->getImage(Model::GUI);


        $petImage = new Division(NULL,"petimage");
        $petImage->setAlign(new Align("center", "center"));
        $petImage->setBackground($background);
        $petImage->add($image);
        $petImage->setLineBreak(TRUE);        
       
        $summary = new Division;
        $summary->setAlign(new Align("center"));
        $summary->add($petImage);
        $summary->add(new Comment("{$this->lang->gave}{$adopt->getName()} one {$this->lang->unit}."));
       
       
       
       
        $summary->add(new Comment($this->lang->encourage));
        if($mysidia->user->isLoggedIn()){
My bad, I left off a couple bits of code that gets the background information. Look at my code above and you will see what I forgot to include
 
My bad, I left off a couple bits of code that gets the background information. Look at my code above and you will see what I forgot to include


Awesome!!!

Thank you so much, works perfect now!! Just a couple lines can make all the difference ...
 

Similar threads

Users who are viewing this thread

  • Forum Contains New Posts
  • Forum Contains No New Posts

Forum statistics

Threads
4,299
Messages
33,231
Members
1,608
Latest member
qwerty
BETA

Latest Threads

Latest Posts

Top