TrackManiaControl/application/core/Players/PlayerDetailed.php

278 lines
7.3 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 16:24:35 +01:00
use FML\Controls\Frame;
2014-01-05 00:02:13 +01:00
use FML\Controls\Labels\Label_Button;
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\ManiaLink;
use FML\Script\Script;
use ManiaControl\ManiaControl;
use ManiaControl\Manialinks\ManialinkManager;
2014-01-03 19:14:07 +01:00
use ManiaControl\Statistics\StatisticManager;
use ManiaControl\Utils\Formatter;
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
*
2014-05-02 17:50:30 +02:00
* @author ManiaControl Team <mail@maniacontrol.com>
* @copyright 2014 ManiaControl Team
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
2014-01-03 16:24:03 +01:00
*/
2014-01-03 16:24:35 +01:00
class PlayerDetailed {
/*
2014-01-28 22:27:33 +01:00
* Constants
*/
const STATS_PER_COLUMN = 13;
2014-01-03 16:24:03 +01:00
/*
* Private properties
2014-01-03 16:24:35 +01:00
*/
/** @var ManiaControl $maniaControl */
2014-01-03 16:24:35 +01:00
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
2014-01-03 16:24:35 +01:00
*
* @param ManiaControl $maniaControl
*/
public function __construct(ManiaControl $maniaControl) {
$this->maniaControl = $maniaControl;
// Settings
$this->width = $this->maniaControl->getManialinkManager()->getStyleManager()->getListWidgetsWidth();
$this->height = $this->maniaControl->getManialinkManager()->getStyleManager()->getListWidgetsHeight();
$this->quadStyle = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultMainWindowStyle();
$this->quadSubstyle = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultMainWindowSubStyle();
2014-01-03 16:24:35 +01:00
}
/**
* Show a Frame with detailed Information about the Target Player
*
* @param Player $player
* @param string $targetLogin
*/
2014-01-03 16:24:35 +01:00
public function showPlayerDetailed(Player $player, $targetLogin) {
/** @var Player $target */
$target = $this->maniaControl->getPlayerManager()->getPlayer($targetLogin);
2014-01-28 22:27:33 +01:00
// Create ManiaLink
2014-01-03 16:24:35 +01:00
$maniaLink = new ManiaLink(ManialinkManager::MAIN_MLID);
2014-01-28 22:27:33 +01:00
$script = $maniaLink->getScript();
// Main frame
$frame = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultListFrame($script);
2014-01-28 22:27:33 +01:00
$maniaLink->add($frame);
2014-01-03 16:24:35 +01:00
// Create script and features
$script = new Script();
$maniaLink->setScript($script);
$posY = $this->height / 2 - 7;
2014-01-03 20:29:42 +01:00
//Nation Quad
$countryQuad = new Quad();
$frame->add($countryQuad);
2014-04-13 11:50:07 +02:00
$countryQuad->setImage("file://ZoneFlags/Login/{$targetLogin}/country");
$countryQuad->setPosition(-$this->width / 2 + 10, $posY);
2014-01-03 20:29:42 +01:00
$countryQuad->setSize(5, 5);
$countryQuad->setZ(-0.1);
2014-06-22 19:02:18 +02:00
$countryQuad->setHAlign($countryQuad::LEFT);
2014-01-03 20:29:42 +01:00
2014-01-03 17:09:24 +01:00
//Nickname
$label = new Label_Text();
$frame->add($label);
$label->setPosition(-$this->width / 2 + 15, $posY);
2014-01-03 17:09:24 +01:00
$label->setText($target->nickname);
2014-06-22 19:02:18 +02:00
$label->setHAlign($label::LEFT);
2014-01-03 17:09:24 +01:00
//Define MainLabel (Login)
$posY -= 8;
2014-01-03 17:09:24 +01:00
$mainLabel = new Label_Text();
$frame->add($mainLabel);
$mainLabel->setPosition(-$this->width / 2 + 10, $posY);
2014-01-03 17:09:24 +01:00
$mainLabel->setTextSize(1.2);
2014-06-22 19:02:18 +02:00
$mainLabel->setHAlign($mainLabel::LEFT);
$mainLabel->setText('Login: ');
2014-01-03 17:09:24 +01:00
$posY -= 5;
2014-01-03 17:09:24 +01:00
$label = clone $mainLabel;
$frame->add($label);
$label->setY($posY);
2014-06-22 19:02:18 +02:00
$label->setText('Nation: ');
2014-01-03 17:09:24 +01:00
$posY -= 5;
2014-01-03 17:09:24 +01:00
$label = clone $mainLabel;
$frame->add($label);
$label->setY($posY);
2014-06-22 19:02:18 +02:00
$label->setText('Province: ');
2014-01-03 17:09:24 +01:00
$posY -= 5;
2014-01-03 17:09:24 +01:00
$label = clone $mainLabel;
$frame->add($label);
$label->setY($posY);
2014-06-22 19:02:18 +02:00
$label->setText('Authorization: ');
2014-01-03 17:09:24 +01:00
$posY -= 5;
2014-01-03 17:09:24 +01:00
$label = clone $mainLabel;
$frame->add($label);
$label->setY($posY);
2014-01-03 17:09:24 +01:00
$label->setText("Ladder Rank:");
$posY -= 5;
2014-01-03 17:09:24 +01:00
$label = clone $mainLabel;
$frame->add($label);
$label->setY($posY);
2014-06-22 19:02:18 +02:00
$label->setText('Ladder Score: ');
2014-01-03 17:09:24 +01:00
$posY -= 5;
2014-01-03 17:09:24 +01:00
$label = clone $mainLabel;
$frame->add($label);
$label->setY($posY);
2014-06-22 19:02:18 +02:00
$label->setText('Inscribed Zone: ');
2014-01-28 22:27:33 +01:00
$posY -= 5;
2014-01-28 22:27:33 +01:00
$label = clone $mainLabel;
$frame->add($label);
$label->setY($posY);
2014-01-28 22:27:33 +01:00
$label->setText('Avatar');
2014-01-03 17:09:24 +01:00
//Login
$posY = $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, $posY);
2014-01-03 17:09:24 +01:00
$mainLabel->setText($target->login);
$mainLabel->setTextSize(1.2);
2014-06-22 19:02:18 +02:00
$mainLabel->setHAlign($mainLabel::LEFT);
2014-01-03 17:09:24 +01:00
//Country
$posY -= 5;
2014-01-03 17:09:24 +01:00
$label = clone $mainLabel;
$frame->add($label);
$label->setY($posY);
2014-01-03 17:09:24 +01:00
$label->setText($target->getCountry());
//Province
$posY -= 5;
2014-01-03 17:09:24 +01:00
$label = clone $mainLabel;
$frame->add($label);
$label->setY($posY);
2014-01-03 17:09:24 +01:00
$label->setText($target->getProvince());
//AuthLevel
$posY -= 5;
2014-01-03 17:09:24 +01:00
$label = clone $mainLabel;
$frame->add($label);
$label->setY($posY);
$label->setText($this->maniaControl->getAuthenticationManager()->getAuthLevelName($target->authLevel));
2014-01-03 17:09:24 +01:00
//LadderRank
$posY -= 5;
2014-01-03 17:09:24 +01:00
$label = clone $mainLabel;
$frame->add($label);
$label->setY($posY);
2014-01-03 17:09:24 +01:00
$label->setText($target->ladderRank);
//LadderScore
$posY -= 5;
2014-01-03 17:09:24 +01:00
$label = clone $mainLabel;
$frame->add($label);
$label->setY($posY);
2014-01-03 21:16:20 +01:00
$label->setText(round($target->ladderScore, 2));
2014-01-03 17:09:24 +01:00
//Played Since
$posY -= 5;
2014-01-03 17:09:24 +01:00
$label = clone $mainLabel;
$frame->add($label);
$label->setY($posY);
2014-06-22 19:02:18 +02:00
$label->setText(date('d M Y', time() - 3600 * 24 * $target->daysSinceZoneInscription));
2014-01-03 17:09:24 +01:00
$quad = new Quad();
$frame->add($quad);
2014-04-13 11:50:07 +02:00
$quad->setImage('file://Avatars/' . $targetLogin . "/default");
2014-01-28 22:27:33 +01:00
$quad->setPosition(-$this->width / 2 + 50, -$this->height / 2 + 34);
2014-06-22 19:02:18 +02:00
$quad->setAlign($quad::RIGHT, $quad::TOP);
2014-01-03 17:09:24 +01:00
$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-05 00:02:13 +01:00
$quad = new Label_Button();
$frame->add($quad);
$quad->setStyle($quad::STYLE_CardMain_Quit);
2014-06-22 19:02:18 +02:00
$quad->setHAlign($quad::LEFT);
2014-01-05 00:02:13 +01:00
$quad->setScale(0.75);
2014-06-22 19:02:18 +02:00
$quad->setText('Back');
2014-01-05 00:02:13 +01:00
$quad->setPosition(-$this->width / 2 + 7, -$this->height / 2 + 7);
$quad->setAction(PlayerCommands::ACTION_OPEN_PLAYERLIST);
2014-01-03 16:24:35 +01:00
// render and display xml
$this->maniaControl->getManialinkManager()->displayWidget($maniaLink, $player, 'PlayerDetailed');
2014-01-03 16:24:35 +01:00
}
2014-01-03 17:36:10 +01:00
/**
* Build a Frame with Statistics about the given Player
*
* @param Player $player
* @return Frame
*/
public function statisticsFrame(Player $player) {
2014-01-03 17:36:10 +01:00
$frame = new Frame();
$playerStats = $this->maniaControl->getStatisticManager()->getAllPlayerStats($player);
$posY = $this->height / 2 - 15;
$posX = -$this->width / 2 + 52;
$index = 1;
2014-01-29 20:51:53 +01:00
2014-05-02 17:50:30 +02:00
foreach ($playerStats as $stat) {
$value = (float)$stat[1];
if (!$value) {
2014-01-28 22:27:33 +01:00
continue;
}
$statProperties = $stat[0];
if ($statProperties->type === StatisticManager::STAT_TYPE_TIME) {
2014-06-15 02:50:13 +02:00
$value = Formatter::formatTimeH($value);
} else if ($statProperties->type === StatisticManager::STAT_TYPE_FLOAT) {
$value = round($value, 2);
2014-01-03 19:14:07 +01:00
}
if ($index % 2 !== 0) {
2014-01-03 19:41:00 +01:00
$lineQuad = new Quad_BgsPlayerCard();
$frame->add($lineQuad);
$lineQuad->setSize(49, 4);
$lineQuad->setSubStyle($lineQuad::SUBSTYLE_BgPlayerCardBig);
$lineQuad->setPosition($posX, $posY, 0.001);
2014-06-22 19:02:18 +02:00
$lineQuad->setHAlign($lineQuad::LEFT);
2014-01-03 19:41:00 +01:00
}
2014-01-03 18:37:51 +01:00
$label = new Label_Text();
$frame->add($label);
$label->setPosition($posX + 4, $posY);
2014-01-03 18:37:51 +01:00
$label->setText($statProperties->name);
2014-06-22 19:02:18 +02:00
$label->setHAlign($label::LEFT);
2014-01-03 18:37:51 +01:00
$label->setTextSize(1.5);
$label = new Label_Text();
$frame->add($label);
$label->setPosition($posX + 40, $posY);
2014-01-03 18:37:51 +01:00
$label->setText($value);
$label->setTextSize(1.5);
$posY -= 4;
$index++;
2014-01-28 22:27:33 +01:00
if ($index > self::STATS_PER_COLUMN) {
$posY = $this->height / 2 - 15;
$posX += 47;
$index = 0;
2014-01-28 22:27:33 +01:00
}
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
}