Alt image not appearing
I have an adoptable that's supposed to have different male and female adult stages, but for the life of me I can't get the adult males to only use the alternate image. I couldn't get the 1.3.4 version gender specific image mod by kyytias to work, so I had to work on my own. This is what I have in myadoptsview:
PHP Code:
<style>
.decor {
width: 100px;
height: 500px;
position: absolute;
top: 17%;
left: 47%;
z-index: 1;
}
.adopt {
position: absolute;
left: 48%;
z-index: 2;
}
.pinfo {
position: absolute;
right: 16%;
}
.button {
background: #ab6d33;
background: -webkit-gradient(linear, left top, left bottom, from(#c48041), to(#ab6d33));
background: -webkit-linear-gradient(top, #c48041, #ab6d33);
background: -moz-linear-gradient(top, #c48041, #ab6d33);
background: -ms-linear-gradient(top, #c48041, #ab6d33);
background: -o-linear-gradient(top, #c48041, #ab6d33);
padding: 11px 22px;
-webkit-border-radius: 20px;
-moz-border-radius: 20px;
border-radius: 20px;
-webkit-box-shadow: rgba(0,0,0,1) 0 1px 0;
-moz-box-shadow: rgba(0,0,0,1) 0 1px 0;
box-shadow: rgba(0,0,0,1) 0 1px 0;
text-shadow: rgba(0,0,0,.4) 0 1px 0;
color: #000000;
font-size: 12px;
vertical-align: middle;
}
.button:hover {
border-top-color: #edad71;
background: #edad71;
color: #000000;
}
.button:active {
border-top-color: #bf7a39;
background: #bf7a39;
}
.myTable { width:600px; border-collapse:collapse; }
.myTable th { background-color:#543210;width:600px; padding:5px;border:5px solid #543210;color:#000;}
.myTable td { padding:5px;border:5px solid #543210;height:100px; }
</style>
<?php
use Resource\Native\String;
use Resource\Collection\LinkedList;
use Resource\Collection\LinkedHashMap;
use Resource\Collection\ArrayList;
class MyadoptsView extends View{
public function index(){
$mysidia = Registry::get("mysidia");
$document = $this->document;
$document->setTitle($this->lang->title);
$pagination = $this->getField("pagination");
$stmt = $this->getField("stmt")->get();
if($stmt->rowCount() == 0){
$document->addLangvar($this->lang->empty);
return;
}
$shelfSpace = $mysidia->db->select("users", array("shelfspace"))->fetchColumn();
$adoptAmount = $mysidia->db->select("owned_adoptables", array("aid"), "owner = '{$mysidia->user->username}'")->rowCount();
$document->add(new Comment("<div class='pinfo'>"));
$document->add(new Comment("<h1>Pantry Stats</h1>"));
$document->add(new Comment("Shelf space: {$adoptAmount}/{$shelfSpace} <b>(<a href='url'>+</a>)</b>"));
$document->add(new Comment("</div>"));
$adoptTable = new TableBuilder("adopttable", 650);
$adoptTable->setAlign(new Align("center", "middle"));
$adoptTable->buildHeaders("Pet", "Info", "Manage");
while($aid = $stmt->fetchColumn()){
$adopt = new OwnedAdoptable($aid);
$gender_lookup = $mysidia->db->select("owned_adoptables", array("gender"), "aid = '{$adopt->getAdoptID()}'")->fetchColumn();
$type = $adopt->getType();
if ($gender_lookup == "m") { $Gender = "Male"; }
if ($gender_lookup == "f") { $Gender = "Female"; }
$cells = new LinkedList;
$cells->add(new TCell($adopt->getImage("gui")));
$cells->add(new TCell("<b>{$adopt->getName()}<br></br> Level {$adopt->getCurrentLevel()} <br></br> {$Gender}</b>"));
$cells->add(new TCell(new Link("myadopts/manage/{$aid}", "Manage Pet")));
$adoptTable->buildRow($cells);
}
$document->add($adoptTable);
$document->addLangvar($pagination->showPage());
}
public function manage(){
$mysidia = Registry::get("mysidia");
$aid = $this->getField("aid")->getValue();
$name = $this->getField("name")->getValue();
$adopt = new OwnedAdoptable($aid);
$gender_lookup = $mysidia->db->select("owned_adoptables", array("gender"), "aid = '{$adopt->getAdoptID()}'")->fetchColumn();
if ($gender_lookup == "m") { $Gender = "Male"; }
if ($gender_lookup == "f") { $Gender = "Female"; }
$alt = $adopt->getAltStatus;
$type = $adopt->getType();
$currentlevel = $adopt->getCurrentLevel();
$image = $adopt->getImage("gui");
$altimage = $adopt->getAltImage("gui");
$petbio = $this->getField("petbio");
$health = $adopt->getHealth();
$mood = $adopt->getMood();
$background = $adopt->getAdoptBackground();
$document = $this->document;
$document->setTitle("<center>{$name}</center>");
$document->add(new Comment("<center>"));
if ($background == ""){
$document->add($image);
}
else{
$document->add(new Comment("<div class='adopt'>"));
if ($type == "Cranberry Tufted Deer"){
if($Gender == "Male"){
if($currentlevel == "3"){
$document->add($altimage);
}
}
}
else{
$document->add($image);
}
$document->add(new Comment("</div>"));
$document->add(new Comment("<br></br><br></br><br></br><br></br><br></br><br></br><br></br>"));
$document->add(new Comment ("<div class='decor'><img src='{$mysidia->path->getAbsolute()}picuploads/backgrounds/{$background}.png'</div>"));
}
$document->add(new Comment("</center>"));
$document->add(new Comment("<center><table class='myTable'>
<tr>
<th>Needs</th>
</tr>
<tr>
<td>Health: <progress max='100' value='{$health}'></progress> <br></br>Mood: <progress max='100' value='{$mood}'></progress></td>
</tr>
</table>"));
$document->add(new Comment("<center><table class='myTable'>
<tr>
<th>Info</th>
</tr>
<tr>
<td>
<a href='http://adopttest.mysidiahost.com/levelup/click/{$aid}'>Play</a> | <a href='http://adopttest.mysidiahost.com/myadopts/stats/{$aid}'>Stats</a> | <a href='http://adopttest.mysidiahost.com/myadopts/bbcode/{$aid}'>Codes</a> | <a href='http://adopttest/myadopts/freeze/{$aid}'>(Un)Freeze</a><br>
<ul>
<li><strong>Type:</strong> {$adopt->getType()}</li>
<li><strong>Sex:</strong> {$Gender}</li>
<li><strong>Trade Status:</strong> {$adopt->getTradeStatus()}
<li><strong>LVL:</strong> {$adopt->getCurrentLevel()}</li>
<li><strong>Total EXP:</strong> {$adopt->getTotalClicks()} </li>
<li><strong>Bio:</strong> {$adopt->getPetbio()} </li>
</ul></td>
</tr>
</table>"));
$document->add(new Comment("<center><table class='myTable'>
<tr>
<th>Manage</th>
</tr>
<tr>
<td><a href='http://adopttest.mysidiahost.com/myadopts/rename/{$aid}' class='button'>Rename</a>
<a href='http://adopttest.mysidiahost.com/myadopts/changepetbio/{$aid}' class='button'>Change Bio</a>
<a href='http://adopttest.mysidiahost.com/pound/pound/{$aid}' class='button'>Send to Pound</a>
<a href='http://adopttest.mysidiahost.com/myadopts/trade/{$aid}' class='button'>Trade Status</a>
<a href='http://adopttest.mysidiahost.com/myadopts/releasepet/{$aid}' class='button'>Eat</a></td>
</tr>
</table></center>"));
}
public function stats(){
$mysidia = Registry::get("mysidia");
$adopt = $this->getField("adopt");
$image = $this->getField("image");
$stmt = $this->getField("stmt")->get();
$document = $this->document;
$document->setTitle($adopt->getName().$this->lang->stats);
$document->add($image);
$document->add($adopt->getStats());
$document->addLangvar("<h2>{$adopt->getName()}'s Voters:</h2><br>{$this->lang->voters}<br><br>");
$fields = new LinkedHashMap;
$fields->put(new String("username"), new String("getUsername"));
$fields->put(new String("date"), NULL);
$fields->put(new String("username::profile"), new String("getProfileImage"));
$fields->put(new String("username::message"), new String("getPMImage"));
$voterTable = new TableBuilder("voters", 500);
$voterTable->setAlign(new Align("center"));
$voterTable->buildHeaders("User", "Date Voted", "Profile", "PM");
$voterTable->setHelper(new UserTableHelper);
$voterTable->buildTable($stmt, $fields);
$document->add($voterTable);
}
public function bbcode(){
$mysidia = Registry::get("mysidia");
$adopt = $this->getField("adopt");
$document = $this->document;
$document->setTitle($this->lang->bbcode.$adopt->getName());
$document->addLangvar($this->lang->bbcode_info);
$document->add(new Comment("<br>"));
$forumComment = new Comment("Forum BBCode: ");
$forumComment->setUnderlined();
$forumcode = "[url={$mysidia->path->getAbsolute()}levelup/click/{$adopt->getAdoptID()}][img]{$mysidia->path->getAbsolute()}levelup/siggy/{$adopt->getAdoptID()}[/img][/url]";
$forumArea = new TextArea("forumcode", $forumcode, 4, 50);
$forumArea->setReadOnly(TRUE);
$altComment = new Comment("Alternative BBCode: ");
$altComment->setUnderlined();
$altcode = "[url={$mysidia->path->getAbsolute()}levelup/click/{$adopt->getAdoptID()}][img]{$mysidia->path->getAbsolute()}get/{$adopt->getAdoptID()}.gif"[/img][/url]";
$altArea = new TextArea("altcode", $altcode, 4, 50);
$altArea->setReadOnly(TRUE);
$htmlComment = new Comment("HTML BBCode: ");
$htmlComment->setUnderlined();
$htmlcode = "<a href='{$mysidia->path->getAbsolute()}levelup/click/{$adopt->getAdoptID()}' target='_blank'>
<img src='{$mysidia->path->getAbsolute()}levelup/siggy/{$adopt->getAdoptID()}' border=0></a>";
$htmlArea = new TextArea("htmlcode", $htmlcode, 4, 50);
$htmlArea->setReadOnly(TRUE);
$document->add($forumComment);
$document->add($forumArea);
$document->add($altComment);
$document->add(($mysidia->settings->usealtbbcode == "yes")?$altArea:new Comment("The Admin has disabled Alt BBCode for this site."));
$document->add($htmlComment);
$document->add($htmlArea);
}
public function rename(){
$mysidia = Registry::get("mysidia");
$adopt = $this->getField("adopt");
$image = $this->getField("image");
$health = $adopt->getHealth();
$mood = $adopt->getMood();
$addHealth = $adopt->getHealth() + 10;
$document = $this->document;
if($mysidia->input->post("submit")){
$document->setTitle($this->lang->rename_success_title);
$document->add($image);
$message = "<br>{$this->lang->rename_success}{$mysidia->input->post("adoptname")}.
You can now manage {$mysidia->input->post("adoptname")} on the";
$document->addLangvar($message);
$document->add(new Link("myadopts/manage/{$adopt->getAdoptID()}", "My Adopts Page"));
$adopt->setHealth($addHealth, "update");
if ($health > 100){$adopt->setHealth(100, "update");
$document->add(new Comment("<br></br>{$adopt->getName()} has full health!"));
}
return;
}
$document->setTitle($this->lang->rename.$adopt->getName());
$document->add($image);
$document->addLangvar("<br />{$this->lang->rename_default}{$adopt->getName()}{$this->lang->rename_details}<br />");
$renameForm = new FormBuilder("renameform", "", "post");
$renameForm->buildTextField("adoptname")->buildButton("Rename Adopt", "submit", "submit");
$document->add($renameForm);
}
public function changepetbio(){
$mysidia = Registry::get("mysidia");
$adopt = $this->getField("adopt");
$image = $this->getField("image");
$document = $this->document;
if($mysidia->input->post("submit")){
$document->setTitle($this->lang->changebio_success_title);
$document->add($image);
$message = "<br>{$this->lang->changebio_success}{$adopt->getName()}.
You can now manage {$mysidia->input->post("adoptname")} on the";
$document->addLangvar($message);
$document->add(new Link("myadopts/manage/{$adopt->getAdoptID()}", "My Adopts Page"));
return;
}
$document->setTitle($this->lang->changebio.$adopt->getName());
$document->add($image);
$document->addLangvar("<br />{$this->lang->changebio_default}{$adopt->getName()}{$this->lang->changebio_details}<br />");
$petbioForm = new FormBuilder("petbioform", "", "post");
$petbioForm->buildTextArea("petbio")->buildButton("Change Bio", "submit", "submit");
$document->add($petbioForm);
}
public function trade(){
$mysidia = Registry::get("mysidia");
$aid = $this->getField("aid")->getValue();
$image = $this->getField("image");
$message = $this->getField("message")->getValue();
$document = $this->document;
$document->setTitle($this->lang->trade);
$document->add($image);
$document->addLangvar($message);
}
public function freeze(){
$mysidia = Registry::get("mysidia");
$adopt = $this->getField("adopt");
$image = $this->getField("image");
$message = $this->getField("message")->getValue();
$document = $this->document;
$document->setTitle($this->lang->freeze);
if($mysidia->input->get("confirm") == "confirm"){
$document->addLangvar($message);
$document->add(new Link("myadopts/manage/{$adopt->getAdoptID()}", "My Adopts Page"));
}
else{
$document->add($image);
$document->add(new Comment("<br /><b>{$adopt->getName()}'s Current Status: "));
if($adopt->isfrozen() == "yes"){
$document->add(new Image("templates/icons/freeze.gif", "Frozen"));
$document->add(new Comment("Frozen<br<br>"));
$document->add(new Comment($this->lang->freeze));
$document->add(new Image("templates/icons/unfreeze.gif", "Unfreeze"));
$document->add(new Link("myadopts/freeze/{$adopt->getAdoptID()}/confirm", "Unfreeze this Adoptable", TRUE));
}
else{
$document->add(new Image("templates/icons/unfreeze.gif", "Not Frozen"));
$document->add(new Comment("Not Frozen<br><br>"));
$document->add(new Comment($this->lang->freeze));
$document->add(new Image("templates/icons/freeze.gif", "Greeze"));
$document->add(new Link("myadopts/freeze/{$adopt->getAdoptID()}/confirm", "Freeze this Adoptable", TRUE));
}
$document->add(new Comment("<br><br>"));
$document->add(new Image("templates/icons/warning.gif"));
$document->addLangvar($this->lang->freeze_warning);
}
}
public function releasepet(){
$mysidia = Registry::get("mysidia");
$adopt = $this->getField("adopt");
$image = $this->getField("image");
$document = $this->document;
if($mysidia->input->post("submit")){
$document->setTitle("Successfully Eaten Pet");
$document->add($image);
$document->add(new Comment("<br/>You quickly gobble up the bab. You monster. "));
return;
}
$document->setTitle("Eat ".$adopt->getName());
$document->add($image);
$document->addLangvar("<br/>You can eat {$adopt->getName()} here. Are you sure you want to do this? <b>This cannot be undone</b><br/>");
$releaseButton = new FormBuilder("releasebutton", "", "post");
$releaseButton->buildButton("Eat!", "submit", "submit");
$document->add($releaseButton);
}
}
?>
and class_ownedadoptable:
PHP Code:
<?php
class OwnedAdoptable extends Adoptable{
protected $aid;
public $name;
protected $owner;
public $currentlevel;
protected $totalclicks;
protected $code;
protected $imageurl;
protected $usealternates;
protected $tradestatus;
protected $isfrozen;
protected $gender;
protected $offsprings;
protected $lastbred;
protected $nextlevel;
protected $voters;
protected $statname;
public $petbio;
public $companion;
public $item;
public $type;
public $health;
public $mood;
public function __construct($aid, $owner = ""){
$mysidia = Registry::get("mysidia");
$whereClause = "aid ='{$aid}'";
if(!empty($owner)) $whereClause .= " and owner = '{$owner}'";
$row = $mysidia->db->select("owned_adoptables", array(), $whereClause)->fetchObject();
if(!is_object($row)) throw new AdoptNotfoundException("Adoptable ID {$aid} does not exist or does not belong to the owner specified...");
parent::__construct($row->type);
foreach($row as $key => $val){
$this->$key = $val;
}
}
public function getAdoptID(){
return $this->aid;
}
public function getName(){
return $this->name;
}
public function setName($name, $assignMode = ""){
if($assignMode == Model::UPDATE) $this->save("name", $name);
$this->name = $name;
}
public function getOwner($fetchMode = ""){
if($fetchMode == Model::MODEL) return new Member($this->owner);
else return $this->owner;
}
public function setOwner($owner, $assignMode = ""){
if($assignMode == Model::UPDATE) $this->save("owner", $owner);
$this->owner = $owner;
}
public function getCurrentLevel($fetchMode = ""){
if($fetchMode == Model::MODEL) return new AdoptLevel($this->type, $this->currentlevel);
else return $this->currentlevel;
}
public function setCurrentLevel($level, $assignMode = ""){
if($assignMode == Model::UPDATE){
$this->save("currentlevel", $level);
if($this->getAltStatus() == "yes") $this->save("usealternates", "yes");
}
$this->currentlevel = $level;
}
public function getTotalClicks(){
return $this->totalclicks;
}
public function setTotalClicks($clicks, $assignMode = ""){
if($assignMode == Model::UPDATE) $this->save("totalclicks", $clicks);
$this->totalclicks = $clicks;
}
public function getCode(){
return $this->code;
}
public function getImageURL($fetchMode = ""){
if($fetchMode == Model::GUI) return new Image($this->imageurl);
else return $this->imageurl;
}
public function useAlternates(){
return $this->usealternates;
}
public function getTradeStatus(){
return $this->tradestatus;
}
public function setTradeStatus($status, $assignMode = ""){
if($assignMode == Model::UPDATE) $this->save("tradestatus", $status);
$this->tradestatus = $status;
}
public function isFrozen(){
return $this->isfrozen;
}
public function setFrozen($frozen = TRUE, $assignMode = ""){
if($assignMode == Model::UPDATE) $this->save("isfrozen", $frozen);
$this->isfrozen = $frozen;
}
public function getGender($fetchMode = ""){
if($fetchMode == Model::GUI) return new Image("picuploads/{$this->gender}.png");
else return $this->gender;
}
public function getOffsprings(){
return $this->offsprings;
}
public function setOffsprings($offsprings = 1, $assignMode = ""){
$this->offsprings = $offsprings;
if($assignMode == Model::UPDATE) $this->save("offsprings", $this->offsprings);
}
public function getLastBred($fetchMode = ""){
if($fetchMode == Model::OBJ) return new DateTime($this->lastbred);
return $this->lastbred;
}
public function setLastBred($lastBred = 0, $assignMode = ""){
if($assignMode == Model::UPDATE) $this->save("lastbred", $lastBred);
$this->lastbred = $lastBred;
}
public function getAltStatus(){
if($this->alternates == "enabled" and $this->currentlevel == $this->altoutlevel){
$rand = mt_rand(1, $this->altchance);
if($rand == 1) return "yes";
}
return "no";
}
public function getImage($fetchMode = ""){
if($this->imageurl) return $this->getImageUrl($fetchMode);
if($this->currentlevel == 0) return $this->getEggImage($fetchMode);
$mysidia = Registry::get("mysidia");
$level = $this->getCurrentLevel("model");
$type = $this->getType();
if($this->useAlternates() == "yes") return $level->getAlternateImage($fetchMode);
if($this->useAlternates() == "yes"){
if ($type == "Cranberry Tufted Deer"){
return $level->getAlternateImage($fetchMode);
}
}
else return $level->getPrimaryImage($fetchMode);
}
public function getAltImage($fetchMode = ""){
if($this->imageurl) return $this->getImageUrl($fetchMode);
if($this->currentlevel == 0) return $this->getEggImage($fetchMode);
$mysidia = Registry::get("mysidia");
$level = $this->getCurrentLevel("model");
return $level->getAlternateImage($fetchMode);
}
public function hasNextLevel(){
try{
$this->nextlevel = new AdoptLevel($this->type, $this->currentlevel + 1);
return TRUE;
}
catch(LevelNotfoundException $lne){
return FALSE;
}
}
public function getNextLevel(){
if(!$this->nextlevel) return FALSE;
return $this->nextlevel;
}
public function getLevelupClicks(){
if(!$this->nextlevel) return FALSE;
return $this->nextlevel->getRequiredClicks() - $this->totalclicks;
}
public function getStats(){
$mysidia = Registry::get("mysidia");
$document = $mysidia->frame->getDocument();
$stats = new Division("adoptstats");
$stats->add(new Comment("<br><br><b>Total Clicks: {$this->totalclicks}"));
$stats->add(new Comment("Gender: ", FALSE));
$stats->add(new Image("picuploads/{$this->gender}.png"));
$adoptStats = "<br>Original Owner: {$this->originalowner}<br>Birthday: {$this->birthday}<br>Trade Status: {$this->tradestatus}<br> Current Level: {$this->currentlevel}<br>Next Level: {$nextLevel}</b>";
if($this->hasNextLevel()){
$level = $this->getNextLevel();
$levelupClicks = $this->getLevelupClicks();
$nextLevel = $level->getLevel().$mysidia->lang->clicks.$levelupClicks;
}
else $nextLevel = $mysidia->lang->maximum;
$adoptStats = "<br>Trade Status: {$this->tradestatus}<br>
Current Level: {$this->currentlevel}<br>Next Level: {$nextLevel}</b>";
$stats->add(new Comment($adoptStats));
return $stats;
}
public function hasVoter($user, $date = ""){
if(!$date) $date = new DateTime;
$mysidia = Registry::get("mysidia");
if($user instanceof Member){
$whereClause = "adoptableid='{$this->aid}' and username = '{$user->username}' and date = '{$date->format('Y-m-d')}'";
}
else{
$ip = secure($_SERVER['REMOTE_ADDR']);
$whereClause = "adoptableid='{$mysidia->input->get("aid")}' and ip = '{$ip}' and date = '{$date->format('Y-m-d')}'";
}
$void = $mysidia->db->select("vote_voters", array("void"), $whereClause)->fetchColumn();
if(is_numeric($void)) return TRUE;
else return FALSE;
}
protected function save($field, $value){
$mysidia = Registry::get("mysidia");
$mysidia->db->update("owned_adoptables", array($field => $value), "aid='{$this->aid}'");
}
public function getAdoptstatname(){
return $this->statname;
}
public function getPetbio(){
return $this->petbio;
}
public function setPetbio($petbio, $assignMode = ""){
if($assignMode == Model::UPDATE) $this->save("petbio", $petbio);
$this->petbio = $petbio;
}
public function getCompanion(){
return $this->companion;
}
public function getItem(){
return $this->item;
}
public function getType(){
return $this->type;
}
public function getHealth(){
return $this->health;
}
public function getMood(){
return $this->mood;
}
public function setHealth($health, $assignMode = ""){
if($assignMode == Model::UPDATE) $this->save("health", $health);
$this->health = $health;
}
public function setMood($mood, $assignMode = ""){
if($assignMode == Model::UPDATE) $this->save("mood", $mood);
$this->health = $mood;
}
}
?>
I was trying to come up with something simple like: If the adoptable is a level 3 male cranberry tufted deer, then it would use the alternate image. Otherwise it would use the regular image.
|