small fixes
This commit is contained in:
parent
734619e744
commit
706f30636e
@ -136,10 +136,12 @@ class ManialinkManager implements ManialinkPageAnswerListener, CallbackListener
|
|||||||
return $this->maniaControl->client->sendDisplayManialinkPage(null, $manialinkText, $timeout, $hideOnClick);
|
return $this->maniaControl->client->sendDisplayManialinkPage(null, $manialinkText, $timeout, $hideOnClick);
|
||||||
}
|
}
|
||||||
if (is_string($logins)) {
|
if (is_string($logins)) {
|
||||||
return $this->maniaControl->client->sendDisplayManialinkPage($logins, $manialinkText, $timeout, $hideOnClick);
|
$success = $this->maniaControl->client->sendDisplayManialinkPage($logins, $manialinkText, $timeout, $hideOnClick);
|
||||||
|
return $success;
|
||||||
}
|
}
|
||||||
if ($logins instanceof Player) {
|
if ($logins instanceof Player) {
|
||||||
return $this->maniaControl->client->sendDisplayManialinkPage($logins->login, $manialinkText, $timeout, $hideOnClick);
|
$success = $this->maniaControl->client->sendDisplayManialinkPage($logins->login, $manialinkText, $timeout, $hideOnClick);
|
||||||
|
return $success;
|
||||||
}
|
}
|
||||||
if (is_array($logins)) {
|
if (is_array($logins)) {
|
||||||
$success = true;
|
$success = true;
|
||||||
@ -153,6 +155,10 @@ class ManialinkManager implements ManialinkPageAnswerListener, CallbackListener
|
|||||||
return $success;
|
return $success;
|
||||||
}
|
}
|
||||||
} catch(Exception $e) {
|
} catch(Exception $e) {
|
||||||
|
if($e->getMessage() == "Login unknown."){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$this->maniaControl->errorHandler->triggerDebugNotice("Exception while sending Manialink: " . $e->getMessage());
|
||||||
// TODO: only possible valid exception should be "wrong login" - throw others (like connection error)
|
// TODO: only possible valid exception should be "wrong login" - throw others (like connection error)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -202,7 +202,7 @@ class PlayerManager implements CallbackListener {
|
|||||||
$player->updateSpectatorStatus($callback[1][0]["SpectatorStatus"]);
|
$player->updateSpectatorStatus($callback[1][0]["SpectatorStatus"]);
|
||||||
|
|
||||||
//Check if Player finished joining the game
|
//Check if Player finished joining the game
|
||||||
if ($player->hasJoinedGame && !$prevJoinState) {
|
if($player->hasJoinedGame && !$prevJoinState){
|
||||||
if ($this->maniaControl->settingManager->getSetting($this, self::SETTING_JOIN_LEAVE_MESSAGES) && !$player->isFakePlayer()) {
|
if ($this->maniaControl->settingManager->getSetting($this, self::SETTING_JOIN_LEAVE_MESSAGES) && !$player->isFakePlayer()) {
|
||||||
$string = array(0 => '$0f0Player', 1 => '$0f0Moderator', 2 => '$0f0Admin', 3 => '$0f0SuperAdmin', 4 => '$0f0MasterAdmin');
|
$string = array(0 => '$0f0Player', 1 => '$0f0Moderator', 2 => '$0f0Admin', 3 => '$0f0SuperAdmin', 4 => '$0f0MasterAdmin');
|
||||||
$chatMessage = '$s$0f0' . $string[$player->authLevel] . ' $fff' . $player->nickname . '$z$s$0f0 Nation:$fff ' . $player->getCountry() . ' $z$s$0f0joined!';
|
$chatMessage = '$s$0f0' . $string[$player->authLevel] . ' $fff' . $player->nickname . '$z$s$0f0 Nation:$fff ' . $player->getCountry() . ' $z$s$0f0joined!';
|
||||||
|
@ -1,19 +1,19 @@
|
|||||||
<?php
|
<?php
|
||||||
use ManiaControl\Callbacks\TimerListener;
|
|
||||||
use ManiaControl\Formatter;
|
|
||||||
use ManiaControl\ManiaControl;
|
|
||||||
use ManiaControl\Callbacks\CallbackListener;
|
|
||||||
use ManiaControl\Callbacks\CallbackManager;
|
|
||||||
use ManiaControl\Maps\Map;
|
|
||||||
use ManiaControl\Players\Player;
|
|
||||||
use ManiaControl\Players\PlayerManager;
|
|
||||||
use ManiaControl\Plugins\Plugin;
|
|
||||||
use FML\ManiaLink;
|
|
||||||
use FML\Controls\Control;
|
use FML\Controls\Control;
|
||||||
use FML\Controls\Frame;
|
use FML\Controls\Frame;
|
||||||
use FML\Controls\Label;
|
use FML\Controls\Label;
|
||||||
use FML\Controls\Quad;
|
use FML\Controls\Quad;
|
||||||
|
use FML\ManiaLink;
|
||||||
|
use ManiaControl\Callbacks\CallbackListener;
|
||||||
|
use ManiaControl\Callbacks\CallbackManager;
|
||||||
|
use ManiaControl\Callbacks\TimerListener;
|
||||||
|
use ManiaControl\Formatter;
|
||||||
|
use ManiaControl\ManiaControl;
|
||||||
|
use ManiaControl\Maps\Map;
|
||||||
use ManiaControl\Maps\MapManager;
|
use ManiaControl\Maps\MapManager;
|
||||||
|
use ManiaControl\Players\Player;
|
||||||
|
use ManiaControl\Players\PlayerManager;
|
||||||
|
use ManiaControl\Plugins\Plugin;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ManiaControl Local Records Plugin
|
* ManiaControl Local Records Plugin
|
||||||
@ -24,25 +24,24 @@ class LocalRecordsPlugin implements CallbackListener, TimerListener, Plugin {
|
|||||||
/**
|
/**
|
||||||
* Constants
|
* Constants
|
||||||
*/
|
*/
|
||||||
const ID = 7;
|
const ID = 7;
|
||||||
const VERSION = 0.1;
|
const VERSION = 0.1;
|
||||||
const MLID_RECORDS = 'ml_local_records';
|
const MLID_RECORDS = 'ml_local_records';
|
||||||
const TABLE_RECORDS = 'mc_localrecords';
|
const TABLE_RECORDS = 'mc_localrecords';
|
||||||
const SETTING_WIDGET_TITLE = 'Widget Title';
|
const SETTING_WIDGET_TITLE = 'Widget Title';
|
||||||
const SETTING_WIDGET_POSX = 'Widget Position: X';
|
const SETTING_WIDGET_POSX = 'Widget Position: X';
|
||||||
const SETTING_WIDGET_POSY = 'Widget Position: Y';
|
const SETTING_WIDGET_POSY = 'Widget Position: Y';
|
||||||
const SETTING_WIDGET_WIDTH = 'Widget Width';
|
const SETTING_WIDGET_WIDTH = 'Widget Width';
|
||||||
const SETTING_WIDGET_LINESCOUNT = 'Widget Displayed Lines Count';
|
const SETTING_WIDGET_LINESCOUNT = 'Widget Displayed Lines Count';
|
||||||
const SETTING_WIDGET_LINEHEIGHT = 'Widget Line Height';
|
const SETTING_WIDGET_LINEHEIGHT = 'Widget Line Height';
|
||||||
const SETTING_NOTIFY_ONLY_DRIVER = 'Notify only the Driver on New Records';
|
const SETTING_NOTIFY_ONLY_DRIVER = 'Notify only the Driver on New Records';
|
||||||
const SETTING_NOTIFY_BEST_RECORDS = 'Notify Publicly only for the X Best Records';
|
const SETTING_NOTIFY_BEST_RECORDS = 'Notify Publicly only for the X Best Records';
|
||||||
const SETTING_ADJUST_OUTER_BORDER = 'Adjust outer Border to Number of actual Records';
|
const SETTING_ADJUST_OUTER_BORDER = 'Adjust outer Border to Number of actual Records';
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Private Properties
|
* Private Properties
|
||||||
*/
|
*/
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @var maniaControl $maniaControl
|
* @var maniaControl $maniaControl
|
||||||
*/
|
*/
|
||||||
private $maniaControl = null;
|
private $maniaControl = null;
|
||||||
@ -59,13 +58,12 @@ class LocalRecordsPlugin implements CallbackListener, TimerListener, Plugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @see \ManiaControl\Plugins\Plugin::load()
|
* @see \ManiaControl\Plugins\Plugin::load()
|
||||||
*/
|
*/
|
||||||
public function load(ManiaControl $maniaControl) {
|
public function load(ManiaControl $maniaControl) {
|
||||||
$this->maniaControl = $maniaControl;
|
$this->maniaControl = $maniaControl;
|
||||||
$this->initTables();
|
$this->initTables();
|
||||||
|
|
||||||
// Init settings
|
// Init settings
|
||||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_WIDGET_TITLE, 'Local Records');
|
$this->maniaControl->settingManager->initSetting($this, self::SETTING_WIDGET_TITLE, 'Local Records');
|
||||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_WIDGET_POSX, -139.);
|
$this->maniaControl->settingManager->initSetting($this, self::SETTING_WIDGET_POSX, -139.);
|
||||||
@ -76,19 +74,18 @@ class LocalRecordsPlugin implements CallbackListener, TimerListener, Plugin {
|
|||||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_NOTIFY_ONLY_DRIVER, false);
|
$this->maniaControl->settingManager->initSetting($this, self::SETTING_NOTIFY_ONLY_DRIVER, false);
|
||||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_NOTIFY_BEST_RECORDS, -1);
|
$this->maniaControl->settingManager->initSetting($this, self::SETTING_NOTIFY_BEST_RECORDS, -1);
|
||||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_ADJUST_OUTER_BORDER, false);
|
$this->maniaControl->settingManager->initSetting($this, self::SETTING_ADJUST_OUTER_BORDER, false);
|
||||||
|
|
||||||
// Register for callbacks
|
// Register for callbacks
|
||||||
$this->maniaControl->timerManager->registerTimerListening($this, 'handle1Second', 1000);
|
$this->maniaControl->timerManager->registerTimerListening($this, 'handle1Second', 1000);
|
||||||
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_AFTERINIT, $this, 'handleAfterInit');
|
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_AFTERINIT, $this, 'handleAfterInit');
|
||||||
$this->maniaControl->callbackManager->registerCallbackListener(MapManager::CB_BEGINMAP, $this, 'handleMapBegin');
|
$this->maniaControl->callbackManager->registerCallbackListener(MapManager::CB_BEGINMAP, $this, 'handleMapBegin');
|
||||||
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_TM_PLAYERFINISH, $this,
|
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_TM_PLAYERFINISH, $this, 'handlePlayerFinish');
|
||||||
'handlePlayerFinish');
|
$this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerConnect');
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @see \ManiaControl\Plugins\Plugin::unload()
|
* @see \ManiaControl\Plugins\Plugin::unload()
|
||||||
*/
|
*/
|
||||||
public function unload() {
|
public function unload() {
|
||||||
@ -102,7 +99,7 @@ class LocalRecordsPlugin implements CallbackListener, TimerListener, Plugin {
|
|||||||
*/
|
*/
|
||||||
private function initTables() {
|
private function initTables() {
|
||||||
$mysqli = $this->maniaControl->database->mysqli;
|
$mysqli = $this->maniaControl->database->mysqli;
|
||||||
$query = "CREATE TABLE IF NOT EXISTS `" . self::TABLE_RECORDS . "` (
|
$query = "CREATE TABLE IF NOT EXISTS `" . self::TABLE_RECORDS . "` (
|
||||||
`index` int(11) NOT NULL AUTO_INCREMENT,
|
`index` int(11) NOT NULL AUTO_INCREMENT,
|
||||||
`mapIndex` int(11) NOT NULL,
|
`mapIndex` int(11) NOT NULL,
|
||||||
`playerIndex` int(11) NOT NULL,
|
`playerIndex` int(11) NOT NULL,
|
||||||
@ -118,7 +115,6 @@ class LocalRecordsPlugin implements CallbackListener, TimerListener, Plugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @see \ManiaControl\Plugins\Plugin::getId()
|
* @see \ManiaControl\Plugins\Plugin::getId()
|
||||||
*/
|
*/
|
||||||
public static function getId() {
|
public static function getId() {
|
||||||
@ -126,7 +122,6 @@ class LocalRecordsPlugin implements CallbackListener, TimerListener, Plugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @see \ManiaControl\Plugins\Plugin::getName()
|
* @see \ManiaControl\Plugins\Plugin::getName()
|
||||||
*/
|
*/
|
||||||
public static function getName() {
|
public static function getName() {
|
||||||
@ -134,7 +129,6 @@ class LocalRecordsPlugin implements CallbackListener, TimerListener, Plugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @see \ManiaControl\Plugins\Plugin::getVersion()
|
* @see \ManiaControl\Plugins\Plugin::getVersion()
|
||||||
*/
|
*/
|
||||||
public static function getVersion() {
|
public static function getVersion() {
|
||||||
@ -142,7 +136,6 @@ class LocalRecordsPlugin implements CallbackListener, TimerListener, Plugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @see \ManiaControl\Plugins\Plugin::getAuthor()
|
* @see \ManiaControl\Plugins\Plugin::getAuthor()
|
||||||
*/
|
*/
|
||||||
public static function getAuthor() {
|
public static function getAuthor() {
|
||||||
@ -150,7 +143,6 @@ class LocalRecordsPlugin implements CallbackListener, TimerListener, Plugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @see \ManiaControl\Plugins\Plugin::getDescription()
|
* @see \ManiaControl\Plugins\Plugin::getDescription()
|
||||||
*/
|
*/
|
||||||
public static function getDescription() {
|
public static function getDescription() {
|
||||||
@ -174,16 +166,16 @@ class LocalRecordsPlugin implements CallbackListener, TimerListener, Plugin {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$this->updateManialink = false;
|
$this->updateManialink = false;
|
||||||
$manialink = $this->buildManialink();
|
$manialink = $this->buildManialink();
|
||||||
$this->maniaControl->manialinkManager->sendManialink($manialink);
|
$this->maniaControl->manialinkManager->sendManialink($manialink);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle PlayerConnect callback
|
* Handle PlayerConnect callback
|
||||||
*
|
*
|
||||||
* @param array $callback
|
* @param Player $player
|
||||||
*/
|
*/
|
||||||
public function handlePlayerConnect(array $callback) {
|
public function handlePlayerConnect(Player $player) {
|
||||||
$this->updateManialink = true;
|
$this->updateManialink = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -207,17 +199,17 @@ class LocalRecordsPlugin implements CallbackListener, TimerListener, Plugin {
|
|||||||
// Invalid player or time
|
// Invalid player or time
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$login = $data[1];
|
$login = $data[1];
|
||||||
$player = $this->maniaControl->playerManager->getPlayer($login);
|
$player = $this->maniaControl->playerManager->getPlayer($login);
|
||||||
if (!$player) {
|
if (!$player) {
|
||||||
// Invalid player
|
// Invalid player
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$time = $data[2];
|
$time = $data[2];
|
||||||
$map = $this->maniaControl->mapManager->getCurrentMap();
|
$map = $this->maniaControl->mapManager->getCurrentMap();
|
||||||
|
|
||||||
// Check old record of the player
|
// Check old record of the player
|
||||||
$oldRecord = $this->getLocalRecord($map, $player);
|
$oldRecord = $this->getLocalRecord($map, $player);
|
||||||
if ($oldRecord) {
|
if ($oldRecord) {
|
||||||
@ -227,16 +219,15 @@ class LocalRecordsPlugin implements CallbackListener, TimerListener, Plugin {
|
|||||||
}
|
}
|
||||||
if ($oldRecord->time == $time) {
|
if ($oldRecord->time == $time) {
|
||||||
// Same time
|
// Same time
|
||||||
$message = '$<' . $player->nickname . '$> equalized her/his $<$o' . $oldRecord->rank . '.$> Local Record: ' .
|
$message = '$<' . $player->nickname . '$> equalized her/his $<$o' . $oldRecord->rank . '.$> Local Record: ' . Formatter::formatTime($oldRecord->time);
|
||||||
Formatter::formatTime($oldRecord->time);
|
|
||||||
$this->maniaControl->chat->sendInformation($message);
|
$this->maniaControl->chat->sendInformation($message);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save time
|
// Save time
|
||||||
$mysqli = $this->maniaControl->database->mysqli;
|
$mysqli = $this->maniaControl->database->mysqli;
|
||||||
$query = "INSERT INTO `" . self::TABLE_RECORDS . "` (
|
$query = "INSERT INTO `" . self::TABLE_RECORDS . "` (
|
||||||
`mapIndex`,
|
`mapIndex`,
|
||||||
`playerIndex`,
|
`playerIndex`,
|
||||||
`time`
|
`time`
|
||||||
@ -252,21 +243,18 @@ class LocalRecordsPlugin implements CallbackListener, TimerListener, Plugin {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$this->updateManialink = true;
|
$this->updateManialink = true;
|
||||||
|
|
||||||
// Announce record
|
// Announce record
|
||||||
$newRecord = $this->getLocalRecord($map, $player);
|
$newRecord = $this->getLocalRecord($map, $player);
|
||||||
$notifyOnlyDriver = $this->maniaControl->settingManager->getSetting($this, self::SETTING_NOTIFY_ONLY_DRIVER);
|
$notifyOnlyDriver = $this->maniaControl->settingManager->getSetting($this, self::SETTING_NOTIFY_ONLY_DRIVER);
|
||||||
$notifyOnlyBestRecords = $this->maniaControl->settingManager->getSetting($this, self::SETTING_NOTIFY_BEST_RECORDS);
|
$notifyOnlyBestRecords = $this->maniaControl->settingManager->getSetting($this, self::SETTING_NOTIFY_BEST_RECORDS);
|
||||||
if ($notifyOnlyDriver || $notifyOnlyBestRecords > 0 && $newRecord->rank > $notifyOnlyBestRecords) {
|
if ($notifyOnlyDriver || $notifyOnlyBestRecords > 0 && $newRecord->rank > $notifyOnlyBestRecords) {
|
||||||
$improvement = ((!$oldRecord || $newRecord->rank < $oldRecord->rank) ? 'gained the' : 'improved Your');
|
$improvement = ((!$oldRecord || $newRecord->rank < $oldRecord->rank) ? 'gained the' : 'improved Your');
|
||||||
$message = 'You ' . $improvement . ' $<$o' . $newRecord->rank . '.$> Local Record: ' .
|
$message = 'You ' . $improvement . ' $<$o' . $newRecord->rank . '.$> Local Record: ' . Formatter::formatTime($newRecord->time);
|
||||||
Formatter::formatTime($newRecord->time);
|
|
||||||
$this->maniaControl->chat->sendInformation($message, $player->login);
|
$this->maniaControl->chat->sendInformation($message, $player->login);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
$improvement = ((!$oldRecord || $newRecord->rank < $oldRecord->rank) ? 'gained the' : 'improved the');
|
$improvement = ((!$oldRecord || $newRecord->rank < $oldRecord->rank) ? 'gained the' : 'improved the');
|
||||||
$message = '$<' . $player->nickname . '$> ' . $improvement . ' $<$o' . $newRecord->rank . '.$> Local Record: ' .
|
$message = '$<' . $player->nickname . '$> ' . $improvement . ' $<$o' . $newRecord->rank . '.$> Local Record: ' . Formatter::formatTime($newRecord->time);
|
||||||
Formatter::formatTime($newRecord->time);
|
|
||||||
$this->maniaControl->chat->sendInformation($message);
|
$this->maniaControl->chat->sendInformation($message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -281,25 +269,25 @@ class LocalRecordsPlugin implements CallbackListener, TimerListener, Plugin {
|
|||||||
if (!$map) {
|
if (!$map) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
$title = $this->maniaControl->settingManager->getSetting($this, self::SETTING_WIDGET_TITLE);
|
$title = $this->maniaControl->settingManager->getSetting($this, self::SETTING_WIDGET_TITLE);
|
||||||
$pos_x = $this->maniaControl->settingManager->getSetting($this, self::SETTING_WIDGET_POSX);
|
$pos_x = $this->maniaControl->settingManager->getSetting($this, self::SETTING_WIDGET_POSX);
|
||||||
$pos_y = $this->maniaControl->settingManager->getSetting($this, self::SETTING_WIDGET_POSY);
|
$pos_y = $this->maniaControl->settingManager->getSetting($this, self::SETTING_WIDGET_POSY);
|
||||||
$width = $this->maniaControl->settingManager->getSetting($this, self::SETTING_WIDGET_WIDTH);
|
$width = $this->maniaControl->settingManager->getSetting($this, self::SETTING_WIDGET_WIDTH);
|
||||||
$lines = $this->maniaControl->settingManager->getSetting($this, self::SETTING_WIDGET_LINESCOUNT);
|
$lines = $this->maniaControl->settingManager->getSetting($this, self::SETTING_WIDGET_LINESCOUNT);
|
||||||
$lineHeight = $this->maniaControl->settingManager->getSetting($this, self::SETTING_WIDGET_LINEHEIGHT);
|
$lineHeight = $this->maniaControl->settingManager->getSetting($this, self::SETTING_WIDGET_LINEHEIGHT);
|
||||||
$labelStyle = $this->maniaControl->manialinkManager->styleManager->getDefaultLabelStyle();
|
$labelStyle = $this->maniaControl->manialinkManager->styleManager->getDefaultLabelStyle();
|
||||||
$quadStyle = $this->maniaControl->manialinkManager->styleManager->getDefaultQuadStyle();
|
$quadStyle = $this->maniaControl->manialinkManager->styleManager->getDefaultQuadStyle();
|
||||||
$quadSubstyle = $this->maniaControl->manialinkManager->styleManager->getDefaultQuadSubstyle();
|
$quadSubstyle = $this->maniaControl->manialinkManager->styleManager->getDefaultQuadSubstyle();
|
||||||
|
|
||||||
$records = $this->getLocalRecords($map);
|
$records = $this->getLocalRecords($map);
|
||||||
if (!is_array($records)) {
|
if (!is_array($records)) {
|
||||||
trigger_error("Couldn't fetch player records.");
|
trigger_error("Couldn't fetch player records.");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
$manialink = new ManiaLink(self::MLID_RECORDS);
|
$manialink = new ManiaLink(self::MLID_RECORDS);
|
||||||
$frame = new Frame();
|
$frame = new Frame();
|
||||||
$manialink->add($frame);
|
$manialink->add($frame);
|
||||||
$frame->setPosition($pos_x, $pos_y);
|
$frame->setPosition($pos_x, $pos_y);
|
||||||
|
|
||||||
@ -307,10 +295,10 @@ class LocalRecordsPlugin implements CallbackListener, TimerListener, Plugin {
|
|||||||
$frame->add($backgroundQuad);
|
$frame->add($backgroundQuad);
|
||||||
$backgroundQuad->setVAlign(Control::TOP);
|
$backgroundQuad->setVAlign(Control::TOP);
|
||||||
$adjustOuterBorder = $this->maniaControl->settingManager->getSetting($this, self::SETTING_ADJUST_OUTER_BORDER);
|
$adjustOuterBorder = $this->maniaControl->settingManager->getSetting($this, self::SETTING_ADJUST_OUTER_BORDER);
|
||||||
$height = 7. + ($adjustOuterBorder ? count($records) : $lines) * $lineHeight;
|
$height = 7. + ($adjustOuterBorder ? count($records) : $lines) * $lineHeight;
|
||||||
$backgroundQuad->setSize($width * 1.05, $height);
|
$backgroundQuad->setSize($width * 1.05, $height);
|
||||||
$backgroundQuad->setStyles($quadStyle, $quadSubstyle);
|
$backgroundQuad->setStyles($quadStyle, $quadSubstyle);
|
||||||
|
|
||||||
$titleLabel = new Label();
|
$titleLabel = new Label();
|
||||||
$frame->add($titleLabel);
|
$frame->add($titleLabel);
|
||||||
$titleLabel->setPosition(0, $lineHeight * -0.9);
|
$titleLabel->setPosition(0, $lineHeight * -0.9);
|
||||||
@ -319,15 +307,15 @@ class LocalRecordsPlugin implements CallbackListener, TimerListener, Plugin {
|
|||||||
$titleLabel->setTextSize(2);
|
$titleLabel->setTextSize(2);
|
||||||
$titleLabel->setText($title);
|
$titleLabel->setText($title);
|
||||||
$titleLabel->setTranslate(true);
|
$titleLabel->setTranslate(true);
|
||||||
|
|
||||||
// Times
|
// Times
|
||||||
foreach ($records as $index => $record) {
|
foreach($records as $index => $record) {
|
||||||
if ($index >= $lines) {
|
if ($index >= $lines) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
$y = -8. - $index * $lineHeight;
|
$y = -8. - $index * $lineHeight;
|
||||||
|
|
||||||
$recordFrame = new Frame();
|
$recordFrame = new Frame();
|
||||||
$frame->add($recordFrame);
|
$frame->add($recordFrame);
|
||||||
$recordFrame->setPosition(0, $y);
|
$recordFrame->setPosition(0, $y);
|
||||||
@ -336,7 +324,7 @@ class LocalRecordsPlugin implements CallbackListener, TimerListener, Plugin {
|
|||||||
$recordFrame->add($backgroundQuad);
|
$recordFrame->add($backgroundQuad);
|
||||||
$backgroundQuad->setSize($width * 1.04, $lineHeight * 1.4);
|
$backgroundQuad->setSize($width * 1.04, $lineHeight * 1.4);
|
||||||
$backgroundQuad->setStyles($quadStyle, $quadSubstyle);
|
$backgroundQuad->setStyles($quadStyle, $quadSubstyle);
|
||||||
|
|
||||||
$rankLabel = new Label();
|
$rankLabel = new Label();
|
||||||
$recordFrame->add($rankLabel);
|
$recordFrame->add($rankLabel);
|
||||||
$rankLabel->setHAlign(Control::LEFT);
|
$rankLabel->setHAlign(Control::LEFT);
|
||||||
@ -345,7 +333,7 @@ class LocalRecordsPlugin implements CallbackListener, TimerListener, Plugin {
|
|||||||
$rankLabel->setTextSize(1);
|
$rankLabel->setTextSize(1);
|
||||||
$rankLabel->setTextPrefix('$o');
|
$rankLabel->setTextPrefix('$o');
|
||||||
$rankLabel->setText($record->rank);
|
$rankLabel->setText($record->rank);
|
||||||
|
|
||||||
$nameLabel = new Label();
|
$nameLabel = new Label();
|
||||||
$recordFrame->add($nameLabel);
|
$recordFrame->add($nameLabel);
|
||||||
$nameLabel->setHAlign(Control::LEFT);
|
$nameLabel->setHAlign(Control::LEFT);
|
||||||
@ -353,7 +341,7 @@ class LocalRecordsPlugin implements CallbackListener, TimerListener, Plugin {
|
|||||||
$nameLabel->setSize($width * 0.6, $lineHeight);
|
$nameLabel->setSize($width * 0.6, $lineHeight);
|
||||||
$nameLabel->setTextSize(1);
|
$nameLabel->setTextSize(1);
|
||||||
$nameLabel->setText($record->nickname);
|
$nameLabel->setText($record->nickname);
|
||||||
|
|
||||||
$timeLabel = new Label();
|
$timeLabel = new Label();
|
||||||
$recordFrame->add($timeLabel);
|
$recordFrame->add($timeLabel);
|
||||||
$timeLabel->setHAlign(Control::RIGHT);
|
$timeLabel->setHAlign(Control::RIGHT);
|
||||||
@ -362,7 +350,7 @@ class LocalRecordsPlugin implements CallbackListener, TimerListener, Plugin {
|
|||||||
$timeLabel->setTextSize(1);
|
$timeLabel->setTextSize(1);
|
||||||
$timeLabel->setText(Formatter::formatTime($record->time));
|
$timeLabel->setText(Formatter::formatTime($record->time));
|
||||||
}
|
}
|
||||||
|
|
||||||
return $manialink->render()->saveXML();
|
return $manialink->render()->saveXML();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -375,8 +363,8 @@ class LocalRecordsPlugin implements CallbackListener, TimerListener, Plugin {
|
|||||||
*/
|
*/
|
||||||
public function getLocalRecords(Map $map, $limit = -1) {
|
public function getLocalRecords(Map $map, $limit = -1) {
|
||||||
$mysqli = $this->maniaControl->database->mysqli;
|
$mysqli = $this->maniaControl->database->mysqli;
|
||||||
$limit = ($limit > 0 ? "LIMIT " . $limit : "");
|
$limit = ($limit > 0 ? "LIMIT " . $limit : "");
|
||||||
$query = "SELECT * FROM (
|
$query = "SELECT * FROM (
|
||||||
SELECT recs.*, @rank := @rank + 1 as `rank` FROM `" . self::TABLE_RECORDS . "` recs, (SELECT @rank := 0) ra
|
SELECT recs.*, @rank := @rank + 1 as `rank` FROM `" . self::TABLE_RECORDS . "` recs, (SELECT @rank := 0) ra
|
||||||
WHERE recs.`mapIndex` = {$map->index}
|
WHERE recs.`mapIndex` = {$map->index}
|
||||||
ORDER BY recs.`time` ASC
|
ORDER BY recs.`time` ASC
|
||||||
@ -389,7 +377,7 @@ class LocalRecordsPlugin implements CallbackListener, TimerListener, Plugin {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
$records = array();
|
$records = array();
|
||||||
while ($record = $result->fetch_object()) {
|
while($record = $result->fetch_object()) {
|
||||||
array_push($records, $record);
|
array_push($records, $record);
|
||||||
}
|
}
|
||||||
$result->free();
|
$result->free();
|
||||||
@ -399,13 +387,13 @@ class LocalRecordsPlugin implements CallbackListener, TimerListener, Plugin {
|
|||||||
/**
|
/**
|
||||||
* Retrieve the local record for the given map and login
|
* Retrieve the local record for the given map and login
|
||||||
*
|
*
|
||||||
* @param Map $map
|
* @param Map $map
|
||||||
* @param Player $player
|
* @param Player $player
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
private function getLocalRecord(Map $map, Player $player) {
|
private function getLocalRecord(Map $map, Player $player) {
|
||||||
$mysqli = $this->maniaControl->database->mysqli;
|
$mysqli = $this->maniaControl->database->mysqli;
|
||||||
$query = "SELECT records.* FROM (
|
$query = "SELECT records.* FROM (
|
||||||
SELECT recs.*, @rank := @rank + 1 as `rank` FROM `" . self::TABLE_RECORDS . "` recs, (SELECT @rank := 0) ra
|
SELECT recs.*, @rank := @rank + 1 as `rank` FROM `" . self::TABLE_RECORDS . "` recs, (SELECT @rank := 0) ra
|
||||||
WHERE recs.`mapIndex` = {$map->index}
|
WHERE recs.`mapIndex` = {$map->index}
|
||||||
ORDER BY recs.`time` ASC) records
|
ORDER BY recs.`time` ASC) records
|
||||||
|
Loading…
Reference in New Issue
Block a user