TrackManiaControl/application/core/Players/PlayerDetailed.php

267 lines
6.9 KiB
PHP
Raw Normal View History

2014-01-03 16:24:03 +01:00
<?php
2014-01-03 16:24:35 +01:00
namespace ManiaControl\Players;
2014-01-03 21:16:20 +01:00
2014-01-03 17:09:24 +01:00
use FML\Controls\Control;
2014-01-03 16:24:35 +01:00
use FML\Controls\Frame;
2014-01-03 17:09:24 +01:00
use FML\Controls\Labels\Label_Text;
2014-01-03 16:24:35 +01:00
use FML\Controls\Quad;
2014-01-03 19:41:00 +01:00
use FML\Controls\Quads\Quad_BgsPlayerCard;
2014-01-03 16:24:35 +01:00
use FML\Controls\Quads\Quad_Icons64x64_1;
use FML\ManiaLink;
use FML\Script\Script;
2014-01-03 19:14:07 +01:00
use ManiaControl\Formatter;
2014-01-03 16:24:35 +01:00
use ManiaControl\ManiaControl;
use ManiaControl\Manialinks\ManialinkManager;
2014-01-03 19:14:07 +01:00
use ManiaControl\Statistics\StatisticManager;
2014-01-03 16:24:35 +01:00
2014-01-03 16:24:03 +01:00
/**
2014-01-03 16:24:35 +01:00
* Player Detailed Page
*
* @author steeffeen & kremsy
2014-01-03 16:24:03 +01:00
*/
2014-01-03 16:24:35 +01:00
class PlayerDetailed {
2014-01-03 16:24:03 +01:00
2014-01-03 16:24:35 +01:00
/**
* Private properties
*/
private $maniaControl = null;
2014-01-03 16:24:03 +01:00
2014-01-03 16:24:35 +01:00
/**
* Create a new Player Detailed instance
*
* @param ManiaControl $maniaControl
*/
public function __construct(ManiaControl $maniaControl) {
$this->maniaControl = $maniaControl;
// settings
$this->width = $this->maniaControl->manialinkManager->styleManager->getListWidgetsWidth();
$this->height = $this->maniaControl->manialinkManager->styleManager->getListWidgetsHeight();
$this->quadStyle = $this->maniaControl->manialinkManager->styleManager->getDefaultMainWindowStyle();
$this->quadSubstyle = $this->maniaControl->manialinkManager->styleManager->getDefaultMainWindowSubStyle();
}
public function showPlayerDetailed(Player $player, $targetLogin) {
2014-01-03 21:16:20 +01:00
$target = $this->maniaControl->playerManager->getPlayer($targetLogin);
2014-01-03 16:24:35 +01:00
$maniaLink = new ManiaLink(ManialinkManager::MAIN_MLID);
// Create script and features
$script = new Script();
$maniaLink->setScript($script);
// mainframe
$frame = new Frame();
$maniaLink->add($frame);
$frame->setSize($this->width, $this->height);
$frame->setPosition(0, 0);
// Background Quad
$backgroundQuad = new Quad();
$frame->add($backgroundQuad);
$backgroundQuad->setSize($this->width, $this->height);
$backgroundQuad->setStyles($this->quadStyle, $this->quadSubstyle);
// Add Close Quad (X)
$closeQuad = new Quad_Icons64x64_1();
$frame->add($closeQuad);
$closeQuad->setPosition($this->width * 0.483, $this->height * 0.467, 3);
$closeQuad->setSize(6, 6);
$closeQuad->setSubStyle(Quad_Icons64x64_1::SUBSTYLE_QuitRace);
$closeQuad->setAction(ManialinkManager::ACTION_CLOSEWIDGET);
2014-01-03 16:24:03 +01:00
2014-01-03 17:09:24 +01:00
$y = $this->height / 2 - 10;
2014-01-03 20:29:42 +01:00
//Nation Quad
$countryQuad = new Quad();
$frame->add($countryQuad);
$countryCode = Formatter::mapCountry($target->getCountry());
$countryQuad->setImage("file://Skins/Avatars/Flags/{$countryCode}.dds");
$countryQuad->setPosition(-$this->width / 2 + 10, $y);
$countryQuad->setSize(5, 5);
$countryQuad->setZ(-0.1);
$countryQuad->setHAlign(Control::LEFT);
2014-01-03 17:09:24 +01:00
//Nickname
2014-01-03 20:29:42 +01:00
2014-01-03 17:09:24 +01:00
$label = new Label_Text();
$frame->add($label);
2014-01-03 20:29:42 +01:00
$label->setPosition(-$this->width / 2 + 15, $y);
2014-01-03 17:09:24 +01:00
$label->setText($target->nickname);
$label->setHAlign(Control::LEFT);
//Define MainLabel (Login)
$y -= 5;
$mainLabel = new Label_Text();
$frame->add($mainLabel);
$mainLabel->setPosition(-$this->width / 2 + 10, $y);
$mainLabel->setTextSize(1.2);
$mainLabel->setHAlign(Control::LEFT);
$mainLabel->setText("Login:");
$y -= 5;
$label = clone $mainLabel;
$frame->add($label);
$label->setY($y);
$label->setText("Nation: ");
$y -= 5;
$label = clone $mainLabel;
$frame->add($label);
$label->setY($y);
$label->setText("Province:");
$y -= 5;
$label = clone $mainLabel;
$frame->add($label);
$label->setY($y);
$label->setText("Authorization:");
$y -= 5;
$label = clone $mainLabel;
$frame->add($label);
$label->setY($y);
$label->setText("Ladder Rank:");
$y -= 5;
$label = clone $mainLabel;
$frame->add($label);
$label->setY($y);
$label->setText("Ladder Score:");
$y -= 5;
$label = clone $mainLabel;
$frame->add($label);
$label->setY($y);
$label->setText("Plays since:");
//Login
2014-01-03 21:16:20 +01:00
$y = $this->height / 2 - 15;
2014-01-03 17:09:24 +01:00
$mainLabel = new Label_Text();
$frame->add($mainLabel);
$mainLabel->setPosition(-$this->width / 2 + 30, $y);
$mainLabel->setText($target->login);
$mainLabel->setTextSize(1.2);
$mainLabel->setHAlign(Control::LEFT);
//Country
$y -= 5;
$label = clone $mainLabel;
$frame->add($label);
$label->setY($y);
$label->setText($target->getCountry());
//Province
$y -= 5;
$label = clone $mainLabel;
$frame->add($label);
$label->setY($y);
$label->setText($target->getProvince());
//AuthLevel
$y -= 5;
$label = clone $mainLabel;
$frame->add($label);
$label->setY($y);
$label->setText($this->maniaControl->authenticationManager->getAuthLevelName($target->authLevel));
//LadderRank
$y -= 5;
$label = clone $mainLabel;
$frame->add($label);
$label->setY($y);
$label->setText($target->ladderRank);
//LadderScore
$y -= 5;
$label = clone $mainLabel;
$frame->add($label);
$label->setY($y);
2014-01-03 21:16:20 +01:00
$label->setText(round($target->ladderScore, 2));
2014-01-03 17:09:24 +01:00
//Played Since
$y -= 5;
$label = clone $mainLabel;
$frame->add($label);
$label->setY($y);
$label->setText(date("Y-m-d", time() - 3600 * 24 * $target->maniaPlanetPlayDays));
//Avatar
$label = new Label_Text();
$frame->add($label);
$label->setPosition($this->width / 2 - 10, $this->height / 2 - 10);
$label->setText("Avatar");
$label->setTextSize(1.3);
$label->setHAlign(Control::RIGHT);
$quad = new Quad();
$frame->add($quad);
2014-01-03 17:36:10 +01:00
$quad->setImage('file://' . $target->avatar);
2014-01-03 17:09:24 +01:00
$quad->setPosition($this->width / 2 - 10, $this->height / 2 - 10);
$quad->setAlign(Control::RIGHT, Control::TOP);
$quad->setSize(20, 20);
2014-01-03 17:36:10 +01:00
//Statistics
$frame->add($this->statisticsFrame($target));
2014-01-03 17:09:24 +01:00
2014-01-03 16:24:35 +01:00
// render and display xml
$this->maniaControl->manialinkManager->displayWidget($maniaLink, $player);
}
2014-01-03 17:36:10 +01:00
2014-01-03 21:16:20 +01:00
public function statisticsFrame($player) {
2014-01-03 17:36:10 +01:00
$frame = new Frame();
/*$mainLabel = new Label_Text();
$frame->add($mainLabel);
$mainLabel->setPosition(-$this->width / 2 + 50, $this->height / 2 - 10);
$mainLabel->setTextSize(1.2);
$mainLabel->setHAlign(Control::LEFT);
$mainLabel->setText("Statistics");*/
2014-01-03 18:37:51 +01:00
$playerStats = $this->maniaControl->statisticManager->getAllPlayerStats($player);
2014-01-03 17:36:10 +01:00
2014-01-03 21:16:20 +01:00
$y = $this->height / 2 - 15;
2014-01-03 19:41:00 +01:00
$id = 1;
2014-01-03 21:16:20 +01:00
foreach($playerStats as $stat) {
2014-01-03 18:37:51 +01:00
$statProperties = $stat[0];
2014-01-03 21:16:20 +01:00
$value = $stat[1];
2014-01-03 18:37:51 +01:00
2014-01-03 21:16:20 +01:00
if($statProperties->type == StatisticManager::STAT_TYPE_TIME) {
2014-01-03 19:14:07 +01:00
$value = Formatter::formatTimeH($value);
}
2014-01-03 19:41:00 +01:00
if($id % 2 != 0) {
$lineQuad = new Quad_BgsPlayerCard();
$frame->add($lineQuad);
$lineQuad->setSize(49, 4);
$lineQuad->setSubStyle($lineQuad::SUBSTYLE_BgPlayerCardBig);
$lineQuad->setPosition(-$this->width / 2 + 66, $y, 0.001);
$lineQuad->setHAlign(Control::LEFT);
}
2014-01-03 18:37:51 +01:00
$label = new Label_Text();
$frame->add($label);
$label->setPosition(-$this->width / 2 + 70, $y);
$label->setText($statProperties->name);
$label->setHAlign(Control::LEFT);
$label->setTextSize(1.5);
$label = new Label_Text();
$frame->add($label);
$label->setPosition(-$this->width / 2 + 100, $y);
$label->setText($value);
$label->setHAlign(Control::LEFT);
$label->setTextSize(1.5);
$y -= 4;
2014-01-03 19:41:00 +01:00
$id++;
2014-01-03 18:37:51 +01:00
}
2014-01-03 17:36:10 +01:00
return $frame;
}
2014-01-03 16:24:03 +01:00
}