Fixed a display bug in WidgetPlugin, minor fixes LocalRecordsPlugin

This commit is contained in:
Jocy 2017-05-19 13:33:02 +02:00
parent f8363441bb
commit 0631c53ed9
2 changed files with 31 additions and 28 deletions

View File

@ -21,6 +21,7 @@ use ManiaControl\Logger;
use ManiaControl\ManiaControl; use ManiaControl\ManiaControl;
use ManiaControl\Manialinks\LabelLine; use ManiaControl\Manialinks\LabelLine;
use ManiaControl\Manialinks\ManialinkManager; use ManiaControl\Manialinks\ManialinkManager;
use ManiaControl\Manialinks\ManialinkPageAnswerListener;
use ManiaControl\Maps\Map; use ManiaControl\Maps\Map;
use ManiaControl\Players\Player; use ManiaControl\Players\Player;
use ManiaControl\Players\PlayerManager; use ManiaControl\Players\PlayerManager;
@ -36,12 +37,12 @@ use ManiaControl\Utils\Formatter;
* @copyright 2014-2017 ManiaControl Team * @copyright 2014-2017 ManiaControl Team
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3 * @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/ */
class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerListener, Plugin { class LocalRecordsPlugin implements ManialinkPageAnswerListener,CallbackListener, CommandListener, TimerListener, Plugin {
/* /*
* Constants * Constants
*/ */
const ID = 7; const ID = 7;
const VERSION = 0.3; const VERSION = 0.4;
const NAME = 'Local Records Plugin'; const NAME = 'Local Records Plugin';
const AUTHOR = 'MCTeam'; const AUTHOR = 'MCTeam';
const MLID_RECORDS = 'ml_local_records'; const MLID_RECORDS = 'ml_local_records';
@ -149,6 +150,8 @@ class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerList
$this->maniaControl->getCommandManager()->registerCommandListener(array('recs', 'records'), $this, 'showRecordsList', false, 'Shows a list of Local Records on the current map.'); $this->maniaControl->getCommandManager()->registerCommandListener(array('recs', 'records'), $this, 'showRecordsList', false, 'Shows a list of Local Records on the current map.');
$this->maniaControl->getCommandManager()->registerCommandListener('delrec', $this, 'deleteRecord', true, 'Removes a record from the database.'); $this->maniaControl->getCommandManager()->registerCommandListener('delrec', $this, 'deleteRecord', true, 'Removes a record from the database.');
$this->maniaControl->getManialinkManager()->registerManialinkPageAnswerListener(self::ACTION_SHOW_RECORDSLIST,$this,'handleShowRecordsList');
$this->updateManialink = true; $this->updateManialink = true;
return true; return true;
@ -265,11 +268,10 @@ class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerList
$titleLabel->setText($title); $titleLabel->setText($title);
$titleLabel->setTranslate(true); $titleLabel->setTranslate(true);
$preGeneratedRecordsFrame = $this->generateRecordsFrame($records, $lines - 2 * $recordsBeforeAfter - 1); $topRecordsCount = $lines - $recordsBeforeAfter * 2 - 1;
$preGeneratedRecordsFrame = $this->generateRecordsFrame($records, $topRecordsCount);
$players = $this->maniaControl->getPlayerManager()->getPlayers(); $players = $this->maniaControl->getPlayerManager()->getPlayers();
$topRecordsCount = $lines - $recordsBeforeAfter * 2 - 1;
foreach ($players as $player) { foreach ($players as $player) {
if (isset($playerRecords[$player->index]) && $playerRecords[$player->index] >= $topRecordsCount) { if (isset($playerRecords[$player->index]) && $playerRecords[$player->index] >= $topRecordsCount) {
@ -281,13 +283,13 @@ class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerList
//Line separator //Line separator
$quad = new Quad(); $quad = new Quad();
$frame->addChild($quad); $frame->addChild($quad);
$quad->setStyles(Quad_Bgs1InRace::STYLE,Quad_Bgs1InRace::SUBSTYLE_BgCardList); $quad->setStyles(Quad_Bgs1InRace::STYLE, Quad_Bgs1InRace::SUBSTYLE_BgCardList);
$quad->setSize($width,0.4); $quad->setSize($width, 0.4);
$quad->setY($y + $lineHeight / 2); $quad->setY($y + $lineHeight / 2);
//Generate the Records around a player and display below topRecords //Generate the Records around a player and display below topRecords
for ($i = $playerIndex - $recordsBeforeAfter; $i <= $playerIndex + $recordsBeforeAfter; $i++) { for ($i = $playerIndex - $recordsBeforeAfter; $i <= $playerIndex + $recordsBeforeAfter; $i++) {
$recordFrame = $this->generateRecordLineFrame($records[$i],$player); $recordFrame = $this->generateRecordLineFrame($records[$i], $player);
$recordFrame->setY($y); $recordFrame->setY($y);
$frame->addChild($recordFrame); $frame->addChild($recordFrame);
$y -= $lineHeight; $y -= $lineHeight;
@ -345,8 +347,8 @@ class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerList
if ($player && $player->index == $record->playerIndex) { if ($player && $player->index == $record->playerIndex) {
$quad = new Quad(); $quad = new Quad();
$recordFrame->addChild($quad); $recordFrame->addChild($quad);
$quad->setStyles(Quad_Bgs1InRace::STYLE,Quad_Bgs1InRace::SUBSTYLE_BgCardList); $quad->setStyles(Quad_Bgs1InRace::STYLE, Quad_Bgs1InRace::SUBSTYLE_BgCardList);
$quad->setSize($width,$lineHeight); $quad->setSize($width, $lineHeight);
} }
return $recordFrame; return $recordFrame;
@ -415,6 +417,7 @@ class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerList
/** /**
* Handle Setting Changed Callback * Handle Setting Changed Callback
* *
* @internal
* @param Setting $setting * @param Setting $setting
*/ */
public function handleSettingChanged(Setting $setting) { public function handleSettingChanged(Setting $setting) {
@ -440,6 +443,7 @@ class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerList
/** /**
* Handle Checkpoint Callback * Handle Checkpoint Callback
* *
* @internal
* @param OnWayPointEventStructure $callback * @param OnWayPointEventStructure $callback
*/ */
public function handleCheckpointCallback(OnWayPointEventStructure $structure) { public function handleCheckpointCallback(OnWayPointEventStructure $structure) {
@ -453,6 +457,7 @@ class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerList
/** /**
* Handle Finish Callback * Handle Finish Callback
* *
* @internal
* @param \ManiaControl\Callbacks\Structures\TrackMania\OnWayPointEventStructure $structure * @param \ManiaControl\Callbacks\Structures\TrackMania\OnWayPointEventStructure $structure
*/ */
public function handleFinishCallback(OnWayPointEventStructure $structure) { public function handleFinishCallback(OnWayPointEventStructure $structure) {
@ -469,7 +474,7 @@ class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerList
return; return;
} }
$checkpointsString = $this->getCheckpoints($player->login); $checkpointsString = $this->getCheckpointmas($player->login);
$this->checkpoints[$player->login] = array(); $this->checkpoints[$player->login] = array();
// Check old record of the player // Check old record of the player
@ -591,6 +596,7 @@ class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerList
/** /**
* Handle Player Connect Callback * Handle Player Connect Callback
* @internal
*/ */
public function handlePlayerConnect() { public function handlePlayerConnect() {
$this->updateManialink = true; $this->updateManialink = true;
@ -598,27 +604,23 @@ class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerList
/** /**
* Handle Begin Map Callback * Handle Begin Map Callback
* @internal
*/ */
public function handleMapBegin() { public function handleMapBegin() {
$this->updateManialink = true; $this->updateManialink = true;
} }
/** /**
* Handle PlayerManialinkPageAnswer callback * Handle the ManiaLink answer of the showRecordsList action
* *
* @internal
* @param array $callback * @param array $callback
* @param \ManiaControl\Players\Player $player
*/ */
public function handleManialinkPageAnswer(array $callback) { public function handleShowRecordsList(array $callback, Player $player){
$actionId = $callback[1][2];
//TODO manialinkpageanswerlsitener
$login = $callback[1][1];
$player = $this->maniaControl->getPlayerManager()->getPlayer($login);
if ($actionId === self::ACTION_SHOW_RECORDSLIST) {
$this->showRecordsList(array(), $player); $this->showRecordsList(array(), $player);
} }
}
/** /**
* Shows a ManiaLink list with the local records. * Shows a ManiaLink list with the local records.

View File

@ -334,7 +334,6 @@ class WidgetPlugin implements CallbackListener, TimerListener, Plugin {
$label->setTextSize(1.3); $label->setTextSize(1.3);
$label->setText(Formatter::stripDirtyCodes($serverName)); $label->setText(Formatter::stripDirtyCodes($serverName));
$label->setTextColor('fff'); $label->setTextColor('fff');
//$label->setAutoNewLine(true);
// Player Quad / Label // Player Quad / Label
$label = new Label_Text(); $label = new Label_Text();
@ -345,6 +344,7 @@ class WidgetPlugin implements CallbackListener, TimerListener, Plugin {
$label->setScale(0.8); $label->setScale(0.8);
$label->setText($playerCount . " / " . $maxPlayers['NextValue']); $label->setText($playerCount . " / " . $maxPlayers['NextValue']);
$label->setTextColor('fff'); $label->setTextColor('fff');
$label->setWidth($width / 2 - 8);
$quad = new Quad_Icons128x128_1(); $quad = new Quad_Icons128x128_1();
$frame->addChild($quad); $frame->addChild($quad);
@ -355,17 +355,18 @@ class WidgetPlugin implements CallbackListener, TimerListener, Plugin {
// Spectator Quad / Label // Spectator Quad / Label
$label = new Label_Text(); $label = new Label_Text();
$frame->addChild($label); $frame->addChild($label);
$label->setPosition(2, -1.5, 0.2); $label->setPosition(3, -1.5, 0.2);
$label->setHorizontalAlign($label::LEFT); $label->setHorizontalAlign($label::LEFT);
$label->setTextSize(1); $label->setTextSize(1);
$label->setScale(0.8); $label->setScale(0.8);
$label->setText($spectatorCount . " / " . $maxSpectators['NextValue']); $label->setText($spectatorCount . " / " . $maxSpectators['NextValue']);
$label->setTextColor('fff'); $label->setTextColor('fff');
$label->setWidth($width / 2 - 8);
$quad = new Quad_Icons64x64_1(); $quad = new Quad_Icons64x64_1();
$frame->addChild($quad); $frame->addChild($quad);
$quad->setSubStyle($quad::SUBSTYLE_Camera); $quad->setSubStyle($quad::SUBSTYLE_Camera);
$quad->setPosition(0, -1.6, 0.2); $quad->setPosition(1, -1.6, 0.2);
$quad->setSize(3.3, 2.5); $quad->setSize(3.3, 2.5);
// Favorite quad // Favorite quad