Mysidia Adoptables Support Forum  

Home Community Mys-Script Creative Off-Topic
Go Back   Mysidia Adoptables Support Forum > Mysidia Adoptables > Questions and Supports

Notices

Reply
 
Thread Tools Display Modes
  #1  
Old 12-14-2014, 05:35 AM
parayna's Avatar
parayna parayna is offline
Member
 
Join Date: May 2013
Location: Devon, UK
Posts: 342
Gender: Female
Credits: 16,101
parayna is on a distinguished road
Default How to write a proper shop page?

Can someone please help me write a proper shop page? I want to create a custom page that I make myself as that is the only way to get the placement I want for the shopkeepers (I don't know how to do it in the default shop files). So I guess I would like to ask if someone can help me write 'get' and 'getview' pages for items.. and where it deducts the price of the item from their inventory and they can also choose the quantity at some point.

The reason I want this is so that I can have a shopkeeper and then images of items underneath, and when they click the image it takes them to another page where they can maybe select the quantity? They then click buy and it deducts the money set by me in the adminCP and adds it to their inventory..

Kyttias was kind enough to help me with doing this for adoptables so I have included them in spoilers in case anyone wants help with the structure.. sorry for asking but I have already tried what I can think of and it hasn't worked >.< Thank you... I really want to get my shops up and running for my beta testers XD

  Spoiler: 'get' page 
PHP Code:
 <?php

use Resource\Native\Integer;
use 
Resource\Native\String;

class 
GetController extends AppController{

    private 
$id;
      
    public function 
__construct(){
    
        
parent::__construct("member");
        
$mysidia Registry::get("mysidia");
    
        if(
$mysidia->usergroup->getpermission("canadopt") != "yes"){
            throw new 
NoPermissionException("permission");
        }    
    }
    
    public function 
index(){
           
//don't let people access yoursite.com/get
        
throw new InvalidActionException("global_action");

    }
    
      
//yoursite.com/get/id
    
public function id(){
        
$mysidia Registry::get("mysidia");

        
//get ID_NUMBER
        
$pageURL 'http';
        if (
$_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
        
$pageURL .= "://";
        if (
$_SERVER["SERVER_PORT"] != "80") {
        
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
        } else {
        
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
        }
        
        
$parts Explode('/'$pageURL);
        
$id $parts[count($parts) - 1];
        
        if(!
$id) throw new InvalidIDException("global_id");
        
        
//---------- Edit here
        /* In this part, we check if the ID is actually part of the IDs available to adopt! 
        * If you want adoptable 1 and 7 to be available through get/id/number, you gotta add
        * 1 and 7 to the array
        */ 
        
        
$id_array = [1,2];//add your OK numbers here
        
$count count($id_array);
        
$found false;
        
        for(
$i 0$i $count$i++)
        {
            
//if ID is inside the array, then it's OK
            
if($id == $id_array[$i]){
                
$found true;
                break;
            }
        }
        
        
//the ID wasnt found inside the array, throw error
        
if(!$found)
            throw new 
NoPermissionException("This adoptable is not available through this method.");
        
        
//---------- 

        //after checking:
        
$this->access "member";
            
$this->handleAccess();    
            
        
//get adoptable information
        
$adopt = new Adoptable($id);                    
                        
        
$conditions $adopt->getConditions();
        if(!
$conditions->checkConditions()) throw new NoPermissionException("condition");
        
        
$name $adopt->getType();
            
$alts $adopt->getAltStatus();
           
$code $adopt->getCode();
        
$gender $adopt->getGender();
        
        
//insert into database
            
$mysidia->db->insert("owned_adoptables", array("aid" => NULL"type" => $name"name" => $name"owner" => $mysidia->user->username"currentlevel" => 0"totalclicks" => 0"code" => $code"imageurl" => NULL"usealternates" => $alts"tradestatus" => 'fortrade'"isfrozen" => 'no'"gender" => $gender"offsprings" => 0"lastbred" => 0));
        
        
//get its info
        
$aid $mysidia->db->select("owned_adoptables", array("aid"), "code='{$code}' and owner='{$mysidia->user->username}'")->fetchColumn();
        
$this->setField("aid", new Integer($aid));
            
$this->setField("name", new String($name));            
        
$this->setField("eggImage", new String($adopt->getEggImage()));
        
        
        
    }
    
}
?>


  Spoiler: 'getview' page 
PHP Code:
 <?php

class GetView extends View{
    
    public function 
index(){
    
        
$mysidia Registry::get("mysidia");
        
$document $this->document;        
            
$document->setTitle("Adopt a pet");
            
       }
       
           public function 
id(){
        
$document $this->document;    
        
$document->setTitle("Adopt a pet");        
        
        
$aid $this->getField("aid")->getValue();
        
$name $this->getField("name")->getValue();
        
$eggImage $this->getField("eggImage")->getValue();
        
        
//display information
        
$image = new Image($eggImage);
        
$image->setLineBreak(TRUE);    
            
$document->setTitle("Catching {$id} ");
        
        
$document->add($image);
        
$document->addLangvar("Congratulations!  You just adopted {$name}. <br>You can now manage {$name} on the ");
        
$document->add(new Link("myadopts""Myadopts Page."));
        
$document->add(new Comment(""));
        
$document->add(new Link("myadopts/manage/{$aid}""Click Here to Manage {$name}"));
        
$document->add(new Comment(""));
        
$document->add(new Link("myadopts/bbcode/{$aid}""Click Here to get BBCodes/HTML Codes for {$name}"));
        
$document->add(new Comment(""));
        
$document->addLangvar("Be sure and");
        
$document->add(new Link("levelup/{$aid}""feed "));
        
$document->addLangvar("{$name} with clicks so that they grow!");
        
    }

    
}
?>


They are both seperate files so I guess items would need to be called getitem and getitemview? Or something like that XD Thanks if someone helps me... this has stumped me for days >.<

(It would also be nice if someone could help me with the 'adopt' shops. Or would it still be the same file? And you just put in their adoptable id? It's just I may not want all of my pets up for free, like they are from the adoptable page at the moment)
Reply With Quote
  #2  
Old 12-14-2014, 02:13 PM
Kyttias's Avatar
Kyttias Kyttias is offline
Premium Member
 
Join Date: Jan 2014
Posts: 857
Gender: Unknown/Other
Credits: 87,010
Kyttias is on a distinguished road
Default

Hmm... Well... I modified my default shop pages. Specifically, classes/class_itemshop.php. Outside of that, I really can't help. Shops are tied to three or four other files and having to clone all of them would just be tedious. Save backups of the original classes/class_itemshop.php, and bear with me. (And I assume the class for adoptshop would be similar, but I actually haven't modified mine yet.) Because you add items to shops through the AdminCP, these additional files I'm talking about all work together to display the items that belong in a particular shop, pull up item information, and construct the functionality needed for the buttons. To recreate it all, you'd need exactly the same files already in place -- so you really have no choice but to work with them, else work entirely from scratch with little help from the community.

Inside public function display is where all the important magic is happening for this. So examine everything going on in this function in its default state and try to wrap your head around it.

If you could draw or create a visual mockup/representation of what you want the finished product to look like, I can try to help from there? I will also need to know the name of at least two item shops to start my example, but the more the merrier. I designed my shops to use tooltips, but any arrangement of information is possible.

You want two things - to render an NPC image based on the shop, and, I assume to change the entire way items are listed.

As a start, in public function display:
PHP Code:
# Choose the NPC image based on the name of the shop
    
switch ($this->shopname) {
        case 
"Crossed Roads":                     
            
$npc_img "http://fc00.deviantart.net/fs71/f/2014/262/a/2/base_npc_60_by_kyttias-d7zqrnf.png";
            break;
        case 
"Spectrum"
            
$npc_img "http://fc00.deviantart.net/fs70/f/2014/313/a/c/base_npc_2_60_by_kyttias-d85ww5k.png";    
            break;
        default; 
            
$npc_img "http://placekitten.com/g/200/500";
            break;
    }
            
# Now let's render the NPC, use css to position the div with the class name of .shop_npc
    
$document->add(new Comment("<div class='shop_npc'><img src='{$npc_img}'/></div>"FALSE)); 
I have two shops, Crossed Roads and Spectrum. If I make a shop and forget to list it here, it will use the default.

The switch statement I've constructed above is using $this->shopname. The word "this" means, literally, defined inside this class. This page. Up at the top you'll find public $shopname;. If you were some other page, you'd need to pull up that information with a function yourself. Why create a page for each shop if each shop is going to need to pull all the same data from the database to construct itself? This is the entire basis of object oriented PHP - to avoid repeating yourself.

So this is why I encourage you to modify the default shop rendering.

If you'll show me how you want items to display, if you don't want the default table that is, I can get to the next step. ^^

-

But, then again, upon reading closer, I think you may also be wanting an entirely new kind of shop? One that uses items, rather than currency? (Possibly multiple items? And currency in addition? How complex.)

If you like the default shops as they are, you can ignore everything I've said. But an entirely new kind of shop that uses items as a currency would need work beyond what I can do in a single night.

I mean, I like the concept, so I can try to tinker over winter break. How many shops of this kind were you wanting? Just one, or many?
__________________
Please do not contact me directly outside of Mysidia.
I also cannot troubleshoot code more than two years old - I legit don't remember it.

Last edited by Kyttias; 12-14-2014 at 02:26 PM.
Reply With Quote
  #3  
Old 12-14-2014, 03:55 PM
parayna's Avatar
parayna parayna is offline
Member
 
Join Date: May 2013
Location: Devon, UK
Posts: 342
Gender: Female
Credits: 16,101
parayna is on a distinguished road
Default

Well, no I kind of wanted a normal shop (money as the currency). Items as a currency would be weird to me XD But that's kind of what I wanted (what you have put) where it displays NPC's above the items (so like yours but below them instead of next to them). I can quickly get a draft of what I would kind of like...

EDIT:
  Spoiler: Image 


Sorry for messy handwriting *^* I can't write with this tablet

Translations:

Top: *Shop name (like normal)*
Big pink box: Whatever text I want them to say (including links if needed using <a href> tags)
Arrow pointing to box: Wouldn't be pink. Would most likely just be white.
Small pink box: Item image
Text under small pink box: item name, item price, buy button
Arrow 1 leading to small pink box: Maybe also a choice to select how many to buy?
Arrow 2 leading to small pink box: That would then be repeated until the end of the row and carried on underneath (with each different item)

(Also, thank the lord for image editing programs XD)


And the names are not yet fully thought of XD But I take it you can literally just change them to whatever? If so, I guess it wouldn't matter what the example names are ^_^

Thank you for helping me! You've helped a lot! ^_^
~Parayna

Last edited by parayna; 01-02-2015 at 12:16 AM.
Reply With Quote
  #4  
Old 12-14-2014, 06:11 PM
Kyttias's Avatar
Kyttias Kyttias is offline
Premium Member
 
Join Date: Jan 2014
Posts: 857
Gender: Unknown/Other
Credits: 87,010
Kyttias is on a distinguished road
Default

Great! This shouldn't be so hard, then. (Though now I do kind of want an item exchange system, but I think I can just squint over the alchemy mod for hints on that.)

My only foreseeable issue with your design above is in the displaying of items, for the user's sake - how will they know what the item does before they buy it? If you can, get me some more detail on what you want there. (Though if each shop has a specific type of item, there is much less confusion overall and descriptions may be irrelevant.)

Let's get done building how we want to display the page in plain HTML first, then I can work on converting it. ^^ As a start, this covers what you have in mind so far, -ish? http://jsbin.com/jabufegula/1/edit?html,css,output (You can turn off tabs for the html/css/output displays at the top, as well as drag the widths of each of these windows. By default, the output window may be narrow, so drag it wider to get the full feel of it.)
__________________
Please do not contact me directly outside of Mysidia.
I also cannot troubleshoot code more than two years old - I legit don't remember it.
Reply With Quote
  #5  
Old 12-14-2014, 06:21 PM
parayna's Avatar
parayna parayna is offline
Member
 
Join Date: May 2013
Location: Devon, UK
Posts: 342
Gender: Female
Credits: 16,101
parayna is on a distinguished road
Default

Yeah. That is actually exactly what I had in mind XD For what the items do, I was either thinking of it either telling you before you buy (maybe leading to a seperate page) or having a hover over box thing (forgot the name :P) The only problem though there would be the mobile users thing.. not sure if it would work for them :/ But I dunno... XD I need some sort of description showing as even though the items will be in certain shops, they may increase the click value by different amounts (for example)

Thank you ^_^,

~Parayna
Reply With Quote
  #6  
Old 12-14-2014, 06:56 PM
Kyttias's Avatar
Kyttias Kyttias is offline
Premium Member
 
Join Date: Jan 2014
Posts: 857
Gender: Unknown/Other
Credits: 87,010
Kyttias is on a distinguished road
Default

I could probably get these tooltips to work? They're mobile-friendly, anyway. If you want tooltips in other areas of your site, then I can direct you where to save the files. ^^ Or if not, I can include them all in this one page.

I couldn't seem to find a pure-Javascript version (I didn't have much time to scour the net for a mobile-friendly pure-Javascript version). The jQuery version works just fine, you'll just also need the jQuery library. My Bootstrap theme comes with it, but I don't know that any of the default themes do, or if you included it while building your own. Let me know if you don't have it and I can either help you put it in or find an alternative. (There's a discussion to be had on whether the jQuery library is too big for mobile browsing, my general conclusion is no, it's not too big. And it'll only have a delay in loading the first time, not every consecutive time. And linking the same copy from the same content delivery network, CDN, that Google/YouTube/other major sites use means there's a chance the users will already have the jQuery library already cached, so there won't be delay at all.)

Do you have any requirements for things you want the NPCs to say? The same thing every time? Or a random thing from a list of several possible things (it can be random for each individual store, that's how I'm doing it)?
__________________
Please do not contact me directly outside of Mysidia.
I also cannot troubleshoot code more than two years old - I legit don't remember it.

Last edited by Kyttias; 12-14-2014 at 07:06 PM.
Reply With Quote
  #7  
Old 12-14-2014, 07:20 PM
parayna's Avatar
parayna parayna is offline
Member
 
Join Date: May 2013
Location: Devon, UK
Posts: 342
Gender: Female
Credits: 16,101
parayna is on a distinguished road
Default

If you could get the tooltips to work that would be amazing! Probably, if they go well, I would like to use them in other places as well (probably the inventory and the world feature when that gets implemented later in the open beta stage of the site) ^_^

I don't think I have the jQuery library.. but I am not totally sure. All of the themes I am using are based on the 'default' default mysidia theme and then I just changed aspects to fit what I wanted (images, colours, and sizes wise). Most of my betas have agreed to test out features cross platform so I would soon be able to figure out if there were any problems to be had on the mobile devices.

And I was kind of thinking of having them say different things, usually based around the same sort of idea as their other sayings (and yeah, for each different shop, as a way of being more varied and easier for people to digest). So probably using an array (which thankfully I sort of know how to do as I learnt how to make a gumball machine using arrays for a school project and that I may implement into my site as a mini game that gives out prizes, when I decide to sort games out of course.. XD)

But yeah. ^_^
Reply With Quote
  #8  
Old 12-14-2014, 07:55 PM
Kyttias's Avatar
Kyttias Kyttias is offline
Premium Member
 
Join Date: Jan 2014
Posts: 857
Gender: Unknown/Other
Credits: 87,010
Kyttias is on a distinguished road
Default

^^ I'm almost done but I need to eat dinner first. I'll be back in two hours or so with everything ready to go.
__________________
Please do not contact me directly outside of Mysidia.
I also cannot troubleshoot code more than two years old - I legit don't remember it.
Reply With Quote
  #9  
Old 12-14-2014, 08:02 PM
parayna's Avatar
parayna parayna is offline
Member
 
Join Date: May 2013
Location: Devon, UK
Posts: 342
Gender: Female
Credits: 16,101
parayna is on a distinguished road
Default

Thank you! It's actually past midnight here so I will be going to bed now XD But in the morning I can come back online ^_^

Thanks~
Reply With Quote
  #10  
Old 12-14-2014, 09:49 PM
Kyttias's Avatar
Kyttias Kyttias is offline
Premium Member
 
Join Date: Jan 2014
Posts: 857
Gender: Unknown/Other
Credits: 87,010
Kyttias is on a distinguished road
Default

Alright! Over in classes/class_itemshop.php, replace public function display with this one:
PHP Code:
    public function display(){
        
$mysidia Registry::get("mysidia");
        
$document $mysidia->frame->getDocument();              
        
$document->addLangvar($mysidia->lang->select_item);
      
        if(
$this->gettotal() == 0){
            
$document->addLangvar($mysidia->lang->empty);
            return 
FALSE;
        }

        
# Choose the NPC image based on the name of the shop
        
switch ($this->shopname) {
            case 
"Crossed Roads":                     
                
$npc_img "http://fc00.deviantart.net/fs71/f/2014/262/a/2/base_npc_60_by_kyttias-d7zqrnf.png";
                
#Based on the random number, sets a quote for $npc_text
                
$num Rand (1,6);   
                switch (
$num) { 
                        case 
1$npc_text "Time is money."; break; 
                        case 
2$npc_text "Isn't icecream super?"; break; 
                        case 
3$npc_text "Welcome to {$this->shopname}!"; break; 
                        case 
4$npc_text "Off to see the wizard?"; break; 
                        case 
5$npc_text "Tomorrow is another day..."; break; 
                        case 
6$npc_text "PHP is cool!"; }                            
                break;
            case 
"Spectrum"
                
$npc_img "http://fc00.deviantart.net/fs70/f/2014/313/a/c/base_npc_2_60_by_kyttias-d85ww5k.png";
                
#Based on the random number, sets a quote for $npc_text
                
$num Rand (1,6);   
                switch (
$num) { 
                        case 
1$npc_text "Time is money."; break; 
                        case 
2$npc_text "Isn't icecream super?"; break; 
                        case 
3$npc_text "Welcome to {$this->shopname}!"; break; 
                        case 
4$npc_text "Off to see the wizard?"; break; 
                        case 
5$npc_text "Tomorrow is another day..."; break; 
                        case 
6$npc_text "PHP is cool!"; }                   
                break;
            default; 
                
$npc_img "http://placekitten.com/g/200/500";
                
$npc_text "Welcome to {$this->shopname}!";
                break;
        }
        
        
# let's begin rendering the page
        
$document->add(new Comment("
            <style>
                .s_top {
                  overflow:hidden;
                  display: block;
                }
                .sc_npc_text{  
                  width: 40%;
                  float: left;
                  height: 100%;
                  padding: 10px;
                  margin: 10px;
                  font-family: 'Trebuchet MS', Helvetica, sans-serif;
                }
                .sc_npc_img{  
                  width: 40%;
                  float: left;
                }
                .sc_item {
                  display: inline-block;
                  padding: 5px;
                  text-align: center;
                  font-family: 'Trebuchet MS', Helvetica, sans-serif;
                  font-size: 14px;
                  margin-bottom: 3px;
                }
                .s_panel {
                  border-radius: 4px;
                  border: 1px solid #466ec3;
                  background-color: #ccf3f6;  
                }
                .s_input { width: 20px; }
            </style>
            <!-- START Container for Text and NPC -->
                <div class='s_top s_container'>
                    <div class='s_panel sc_npc_text'><p>
{$npc_text}</p></div>
                    <div class='sc_npc_img'><img  src='
{$npc_img}' height='300'></div>    
                </div>
            <!-- END Container for Text and NPC -->
            <!-- START Container for Items -->
                  <div class='s_container'>    
        "
FALSE));    
            
        
# Now render each item the store has
        
foreach($this->items as $stockitem){
              
$item $this->getitem($stockitem);
            
              
#descriptions of the item functions
            
switch ($item->function) {
                case 
"Click1"$usage "<b>use:</b> Feed a pet to give them {$item->value} EXP.";
                    break;
                  case 
"Click2"$usage "<b>use:</b> Feed a pet to set their EXP to {$item->value}.";
                    break;
                  case 
"Click3"$usage "<b>use:</b> Resets today's earned EXP to 0.";
                    break;
                  case 
"Level1"$usage "<b>use:</b> Raises a pet's Level by {$item->value}.";
                    break;
                  case 
"Level2"$usage "<b>use:</b> Sets your pet's Level to {$item->value}.";
                    break;
                case 
"Level3"$usage "<b>use:</b> Makes your pet Level 0 again!";
                    break;
                case 
"Gender"$usage "<b>use:</b> Swaps your pet's gender to its opposite!";
                    break;            
                default;
                    
$usage "";
                    break;
            }                        

            
# Now let's render each item icon, name, price and tooltip
            
$document->add(new Comment("
                <div class='s_panel sc_item'>

                <!-- 
                // This is where I would get the tooltip working, but it's not currently
                <abbr rel='tooltip' title=\"
{$item->description} <em>{$usage}</em>.\"><img src='{$item->imageurl}'></abbr> 
                -->
                
                <img src='
{$item->imageurl}'>
                  <br/>
                  <b>
{$item->itemname}</b>
                  <br/>
                  
{$item->price} Credits<br/>
                "
FALSE));

            
# Building the Buy form
            
$buyForm = new FormBuilder("buyform""../purchase/{$mysidia->input->get("shop")}""post");
            
$buyForm->setLineBreak(FALSE);
            
$buyForm->buildPasswordField("hidden""action""purchase")
                    ->
buildPasswordField("hidden""itemname"$item->itemname)
                    ->
buildPasswordField("hidden""shopname"$shop->shopname)
                    ->
buildPasswordField("hidden""shoptype""itemshop")
                    ->
buildPasswordField("hidden""salestax"$shop->salestax);
            
$quantity = new TextField("quantity");
            
$quantity->setSize(3);
            
$quantity->setMaxLength(3);
            
$quantity->setLineBreak(FALSE);        
            
$buy = new Button("Buy""buy""buy");
            
$buy->setLineBreak(FALSE);
            
$buyForm->add($quantity);
            
$buyForm->add($buy);

            
# Actually adding in the Quantity field Buy button now
             
$document->add($buyForm);

            
# Now we finish off the item by closing its div
            
$document->add(new Comment("</div>"FALSE)); 
        }  

        
# And that's a wrap
        
$document->add(new Comment("</div><!-- END Container for Items -->"FALSE));

    } 
This is my first draft, but does not have tooltips for a description in place functioning yet. But it's definitely 99% done now. Do feel free to move the stylesheet out and join it with your existing template one. I needed it here for testing. ^^;

The usage descriptions have less to do with your item description and everything to do with what item function they have. It detects what category of function the item is stored as in the database and then will display appropriate text based on that. It's basically something I've done in addition to the existing description, but is entirely optional. (And it's not yet apparent, as the tooltips are not implemented yet). It's just something I created for my own site so I wouldn't have to repeat myself in the description of an item, leaving the functionality in a separate variable than the flavor text. ^^
__________________
Please do not contact me directly outside of Mysidia.
I also cannot troubleshoot code more than two years old - I legit don't remember it.

Last edited by Kyttias; 12-14-2014 at 09:54 PM.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
visitors do not write messages in the shoutbox? kratosvr Questions and Supports 1 10-29-2011 07:45 PM
Not show shop adopts on adopt page SilverDragonTears Questions and Supports 0 08-16-2011 06:57 PM
Ad code "unable to write" LilPixie Questions and Supports 4 03-26-2009 01:07 PM
Re-Write suggestions rosepose Suggestions and Feature Requests 4 03-22-2009 07:13 PM
Suggestions For The Possible Re Write gjac1 Suggestions and Feature Requests 2 03-19-2009 05:15 AM


All times are GMT -5. The time now is 11:50 PM.

Currently Active Users: 455 (0 members and 455 guests)
Threads: 4,080, Posts: 32,024, Members: 2,016
Welcome to our newest members, jolob.
BETA





What's New?

What's Hot?

What's Popular?


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
vBCommerce I v2.0.0 Gold ©2010, PixelFX Studios
vBCredits I v2.0.0 Gold ©2010, PixelFX Studios
Emoticons by darkmoon3636