Mysidia Adoptables Support Forum

Mysidia Adoptables Support Forum (http://www.mysidiaadoptables.com/forum/index.php)
-   Mys v1.3.x Mods (http://www.mysidiaadoptables.com/forum/forumdisplay.php?f=42)
-   -   Mys v1.3.4 Item Pages (http://www.mysidiaadoptables.com/forum/showthread.php?t=5542)

Abronsyth 12-28-2017 10:03 PM

Item Pages
 
I wanted to make my inventory pages nice and clean, plus make greater use of the item system (as my site requires users to assign items to pets). So I came up with this and, after a lot of screeching in frustration, I have it working. It still needs some work in spifying it up and streamlining the process, but I have seen folks bring it up before so figured I'd share it as-is.

First! I cannot recall if it is dependent on Kyttias's mod, but it may very well be so note you'll want to install this mod first: http://mysidiaadoptables.com/forum/s...ead.php?t=4741

Okay, so let's get started. The good news is you do not have to touch your database at all (whew!).

Assuming you have Kyttias' mod installed, the first part we're going to edit is how we display items in the inventory. Open up inventoryview.php and scroll to where you see the notation; # Rendering items now
Now I replaced everything between that note, and the closing bracket ( } ) for this line; for($i = 0; $i < $iids->length(); $i++){.
PHP Code:

$document->add(new Comment("<div class=\"s_panel sc_item\">
            <img rel=\"tooltip\" title=\"
{$usage}\" src=\"{$item->imageurl}\"/><br>
              <b>
{$item->itemname}</b><br> Own &times;{$item->quantity}<br>"FALSE));
           
                
$useForm = new FormBuilder("useform""inventory/uses""post");
                
$useForm->setLineBreak(FALSE);
                
$useForm->buildPasswordField("hidden""action""use")
                        ->
buildPasswordField("hidden""itemname"$item->itemname)
                        ->
buildButton("Manage""use""use");
                
$document->add($useForm);
                
                
$document->add(new Comment("</div>"FALSE)); 

What this does is makes it so we see the item's image, name, how many you own, and a "Manage" button. The manage button is clickable but totally useless right now.

Now we're going to replace EVERYTHING between the END of the INDEX function and the START of the TOSS function with this messy chunk of code;
PHP Code:

    public function uses(){
        
$mysidia Registry::get("mysidia");
        
$document $this->document;
        
$itemname $mysidia->input->post("itemname");    
        
$image $mysidia->db->select("items", array("imageurl"), "itemname='{$mysidia->input->post("itemname")}'")->fetchColumn();
        
$consumable $mysidia->db->select("items", array("consumable"), "consumable='yes'")->fetchColumn();
        
$quantity $mysidia->db->select("inventory", array("quantity"), "itemname='{$itemname}'" AND "owner='{$mysidia->user->username}'")->fetchColumn();
        
        if(
$mysidia->input->post("aid")){
            
$message = (string)$this->getField("message");
            
$document->setTitle($mysidia->lang->global_action_complete);
            
$document->addLangvar($message);
            return;        
        }
        
        
$petMap $this->getField("petMap");
        
$document->setTitle("Manage Item");
        
$document->add(new Comment("<center><b>{$itemname}</b><br>
<img src='
{$image}'/><br>
<b>Owned:</b> 
{$quantity}</center>"));
if(
$consumable) {
    
$document->add(new Comment("<h2>Use</h2>"));
        
$document->addLangvar($mysidia->lang->select);        
        
$chooseFrom = new Form("chooseform""uses""post");
        
        
$adoptable = new DropdownList("aid");
        
$adoptable->add(new Option("None Selected""none"));
        if(
$petMap->size() > 0){
            
$iterator $petMap->iterator();
            while(
$iterator->hasNext()){
                
$adopt $iterator->nextEntry();
                
$adoptable->add(new Option($adopt->getValue(), $adopt->getKey()));
            }
        }        
        
$chooseFrom->add($adoptable);
        
        
$chooseFrom->add(new PasswordField("hidden""itemname"$mysidia->input->post("itemname")));
        
$chooseFrom->add(new PasswordField("hidden""validation""valid"));
        
$chooseFrom->add(new Button("Choose this pet""submit""submit"));
        
$document->add($chooseFrom);}
else{
             
$document->add(new Comment("<button style='cursor:not-allowed;' type='button'>Unusable</button><br><br>"FALSE));
            }
        
        
//SELL FORM//
        
$price $mysidia->db->select("items", array("price"), "itemname='{$mysidia->input->post("itemname")}'")->fetchColumn();
        
$sellback $price 2;
            if(
$item->function == "Key") {
            
$document->add(new Comment("
            <button style='cursor:not-allowed;' type='button'>Unsellable</button> "
FALSE));
            }    
            else {
                
$sellForm = new FormBuilder("sellform""sell""post");
                
$sellForm->setLineBreak(FALSE);
                
$sellForm->buildPasswordField("hidden""action""sell")
                         ->
buildPasswordField("hidden""itemname"$mysidia->input->post("itemname"));
                
$quantity = new TextField("quantity");
                
$quantity->setSize(3);
                
$quantity->setMaxLength(3);
                
$quantity->setLineBreak(FALSE);

                
$sell = new Button("Sell""sell""sell");
                
$sell->setLineBreak(FALSE);

                
$sellForm->add($quantity);
                
$sellForm->add($sell);
        
$document->add(new Comment("<h2>Sell for {$sellback} {$mysidia->settings->cost} Each</h2>"));
                            
$document->add($sellForm);
    }}
    
    public function 
sell(){
        
$mysidia Registry::get("mysidia");
        
$document $this->document;
        
$document->setTitle($this->lang->global_transaction_complete);
        
$document->addLangvar("{$this->lang->sell}{$mysidia->input->post("quantity")} {$mysidia->input->post("itemname")} {$this->lang->sell2}");
    } 

What this does is create a page to manage that item. It shows the item's name, image, and quantity owned. It also shows two forms, a Use form, and a Sell form. The use form only works if the item is consumable, otherwise it states "unusable," and the sell form does NOT work for "Key" items. To use it, it shows a drop-down of the user's pets. To sell it the page shows the price it's worth, and lets the user put the quantity to sell in the box. (Don't worry, they cannot sell more than they own).

That's all there is to it! I know the code itself is messy and the manage page could use some beautifying, but I'll leave that to you.

If you have questions/comments/etc just post and I'll get to it when I am able :veeee:

Happy new year, y'all!

Dinocanid 12-29-2017 08:44 AM

It looks great, thanks! It looks like you forgot to include the styling for the items, since every items appears underneath each other instead of next to each other. I fixed it by adding style tags though:
PHP Code:

$document->add(new Comment("
            <style>
                .sc_item {
                  display: inline-table;
                  padding: 5px;
                  text-align: center;
                  font-family: 'Trebuchet MS', Helvetica, sans-serif;
                  font-size: 14px;
                  margin-bottom: 3px;
                }
                .s_panel {
                  border-radius: 2px;
                  border: 1px solid #CCC;
                  background-color: #FBFDF2;  
                  height: 200px;
                }
            </style>     
            <div class='s_panel sc_item'> 
            <img rel='tooltip' title='
{$usage}' src='{$item->imageurl}' style='height:100px; width:auto;'><br> 
              <b>
{$item->itemname}</b><br> Own &times;{$item->quantity}<br>"FALSE)); 

I think it only works without adding style tags if you added Kyttias's styling in your theme's css file.

Abronsyth 12-29-2017 08:39 PM

Oops, thank you for that! I don't notate my modifications well in the moment lol :eye:

Kyttias 12-30-2017 12:34 AM

I'm tickled people are making mods from my mods and sharing 'em. :happycbig:

Silver_Brick 12-30-2017 07:44 AM

Great work abro i really appreciate it and i don't think so this is really based on kyttias mod .

Abronsyth 12-30-2017 10:31 AM

@Kyttias, I have learned a lot from your mods on what's possible/how to do things, and a lot of them have the perfect set-up to expand on, they're great :colonu:

@Silver_Brick, thank you, you're welcome, and it's definitely heavily "inspired"/derrived from it, but I am sure that you can modify it to use w/out Kyttias' mod.


All times are GMT -5. The time now is 04:28 PM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.