refactor codestyle (chaining)
This commit is contained in:
@ -41,10 +41,8 @@ class CustomUIManager implements CallbackListener, TimerListener {
|
||||
$this->prepareManialink();
|
||||
|
||||
// Callbacks
|
||||
$this->maniaControl->getCallbackManager()
|
||||
->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerJoined');
|
||||
$this->maniaControl->getTimerManager()
|
||||
->registerTimerListening($this, 'handle1Second', 1000);
|
||||
$this->maniaControl->getCallbackManager()->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerJoined');
|
||||
$this->maniaControl->getTimerManager()->registerTimerListening($this, 'handle1Second', 1000);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -72,12 +70,10 @@ class CustomUIManager implements CallbackListener, TimerListener {
|
||||
*/
|
||||
public function updateManialink(Player $player = null) {
|
||||
if ($player) {
|
||||
$this->maniaControl->getManialinkManager()
|
||||
->sendManialink($this->customUI, $player);
|
||||
$this->maniaControl->getManialinkManager()->sendManialink($this->customUI, $player);
|
||||
return;
|
||||
}
|
||||
$this->maniaControl->getManialinkManager()
|
||||
->sendManialink($this->customUI);
|
||||
$this->maniaControl->getManialinkManager()->sendManialink($this->customUI);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -90,10 +86,9 @@ class CustomUIManager implements CallbackListener, TimerListener {
|
||||
|
||||
//TODO: validate necessity
|
||||
//send it again after 500ms
|
||||
$this->maniaControl->getTimerManager()
|
||||
->registerOneTimeListening($this, function () use (&$player) {
|
||||
$this->updateManialink($player);
|
||||
}, 500);
|
||||
$this->maniaControl->getTimerManager()->registerOneTimeListening($this, function () use (&$player) {
|
||||
$this->updateManialink($player);
|
||||
}, 500);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -51,10 +51,8 @@ class IconManager implements CallbackListener {
|
||||
$this->addDefaultIcons();
|
||||
|
||||
// Callbacks
|
||||
$this->maniaControl->getCallbackManager()
|
||||
->registerCallbackListener(Callbacks::AFTERINIT, $this, 'handleAfterInit');
|
||||
$this->maniaControl->getCallbackManager()
|
||||
->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerConnect');
|
||||
$this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::AFTERINIT, $this, 'handleAfterInit');
|
||||
$this->maniaControl->getCallbackManager()->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerConnect');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -116,8 +114,7 @@ class IconManager implements CallbackListener {
|
||||
}
|
||||
|
||||
// Send manialink
|
||||
$this->maniaControl->getManialinkManager()
|
||||
->sendManialink($maniaLink, $player);
|
||||
$this->maniaControl->getManialinkManager()->sendManialink($maniaLink, $player);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -66,8 +66,7 @@ class ManialinkManager implements ManialinkPageAnswerListener, CallbackListener
|
||||
|
||||
// Callbacks
|
||||
$this->registerManialinkPageAnswerListener(self::ACTION_CLOSEWIDGET, $this, 'closeWidgetCallback');
|
||||
$this->maniaControl->getCallbackManager()
|
||||
->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer');
|
||||
$this->maniaControl->getCallbackManager()->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -176,8 +175,7 @@ class ManialinkManager implements ManialinkPageAnswerListener, CallbackListener
|
||||
public function handleManialinkPageAnswer(array $callback) {
|
||||
$actionId = $callback[1][2];
|
||||
$login = $callback[1][1];
|
||||
$player = $this->maniaControl->getPlayerManager()
|
||||
->getPlayer($login);
|
||||
$player = $this->maniaControl->getPlayerManager()->getPlayer($login);
|
||||
|
||||
if (array_key_exists($actionId, $this->pageAnswerListeners) && is_array($this->pageAnswerListeners[$actionId])) {
|
||||
// Inform page answer listeners
|
||||
@ -212,10 +210,8 @@ class ManialinkManager implements ManialinkPageAnswerListener, CallbackListener
|
||||
// TODO make check by manialinkId, getter is needed to avoid uses on non main widgets
|
||||
$this->disableAltMenu($player);
|
||||
// Trigger callback
|
||||
$player = $this->maniaControl->getPlayerManager()
|
||||
->getPlayer($player);
|
||||
$this->maniaControl->getCallbackManager()
|
||||
->triggerCallback(self::CB_MAIN_WINDOW_OPENED, $player, $widgetName);
|
||||
$player = $this->maniaControl->getPlayerManager()->getPlayer($player);
|
||||
$this->maniaControl->getCallbackManager()->triggerCallback(self::CB_MAIN_WINDOW_OPENED, $player, $widgetName);
|
||||
}
|
||||
}
|
||||
|
||||
@ -237,17 +233,14 @@ class ManialinkManager implements ManialinkPageAnswerListener, CallbackListener
|
||||
|
||||
try {
|
||||
if (!$logins) {
|
||||
return $this->maniaControl->getClient()
|
||||
->sendDisplayManialinkPage(null, $manialinkText, $timeout, $hideOnClick);
|
||||
return $this->maniaControl->getClient()->sendDisplayManialinkPage(null, $manialinkText, $timeout, $hideOnClick);
|
||||
}
|
||||
if (is_string($logins)) {
|
||||
$success = $this->maniaControl->getClient()
|
||||
->sendDisplayManialinkPage($logins, $manialinkText, $timeout, $hideOnClick);
|
||||
$success = $this->maniaControl->getClient()->sendDisplayManialinkPage($logins, $manialinkText, $timeout, $hideOnClick);
|
||||
return $success;
|
||||
}
|
||||
if ($logins instanceof Player) {
|
||||
$success = $this->maniaControl->getClient()
|
||||
->sendDisplayManialinkPage($logins->login, $manialinkText, $timeout, $hideOnClick);
|
||||
$success = $this->maniaControl->getClient()->sendDisplayManialinkPage($logins->login, $manialinkText, $timeout, $hideOnClick);
|
||||
return $success;
|
||||
}
|
||||
if (is_array($logins)) {
|
||||
@ -276,8 +269,7 @@ class ManialinkManager implements ManialinkPageAnswerListener, CallbackListener
|
||||
public function disableAltMenu($player) {
|
||||
$login = Player::parseLogin($player);
|
||||
try {
|
||||
$success = $this->maniaControl->getClient()
|
||||
->triggerModeScriptEvent('LibXmlRpc_DisableAltMenu', $login);
|
||||
$success = $this->maniaControl->getClient()->triggerModeScriptEvent('LibXmlRpc_DisableAltMenu', $login);
|
||||
} catch (GameModeException $e) {
|
||||
return false;
|
||||
}
|
||||
@ -306,10 +298,8 @@ class ManialinkManager implements ManialinkPageAnswerListener, CallbackListener
|
||||
$this->enableAltMenu($player);
|
||||
|
||||
// Trigger callback
|
||||
$player = $this->maniaControl->getPlayerManager()
|
||||
->getPlayer($player);
|
||||
$this->maniaControl->getCallbackManager()
|
||||
->triggerCallback(self::CB_MAIN_WINDOW_CLOSED, $player);
|
||||
$player = $this->maniaControl->getPlayerManager()->getPlayer($player);
|
||||
$this->maniaControl->getCallbackManager()->triggerCallback(self::CB_MAIN_WINDOW_CLOSED, $player);
|
||||
} else {
|
||||
$this->hideManialink($widgetId, $player);
|
||||
}
|
||||
@ -341,8 +331,7 @@ class ManialinkManager implements ManialinkPageAnswerListener, CallbackListener
|
||||
public function enableAltMenu($player) {
|
||||
$login = Player::parseLogin($player);
|
||||
try {
|
||||
$success = $this->maniaControl->getClient()
|
||||
->triggerModeScriptEvent('LibXmlRpc_EnableAltMenu', $login);
|
||||
$success = $this->maniaControl->getClient()->triggerModeScriptEvent('LibXmlRpc_EnableAltMenu', $login);
|
||||
} catch (GameModeException $e) {
|
||||
return false;
|
||||
}
|
||||
|
@ -50,24 +50,16 @@ class StyleManager {
|
||||
$this->maniaControl = $maniaControl;
|
||||
|
||||
// Settings
|
||||
$this->maniaControl->getSettingManager()
|
||||
->initSetting($this, self::SETTING_LABEL_DEFAULT_STYLE, Label_Text::STYLE_TextTitle1);
|
||||
$this->maniaControl->getSettingManager()
|
||||
->initSetting($this, self::SETTING_QUAD_DEFAULT_STYLE, Quad_Bgs1InRace::STYLE);
|
||||
$this->maniaControl->getSettingManager()
|
||||
->initSetting($this, self::SETTING_QUAD_DEFAULT_SUBSTYLE, Quad_Bgs1InRace::SUBSTYLE_BgTitleShadow);
|
||||
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_LABEL_DEFAULT_STYLE, Label_Text::STYLE_TextTitle1);
|
||||
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_QUAD_DEFAULT_STYLE, Quad_Bgs1InRace::STYLE);
|
||||
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_QUAD_DEFAULT_SUBSTYLE, Quad_Bgs1InRace::SUBSTYLE_BgTitleShadow);
|
||||
|
||||
// Main Widget
|
||||
$this->maniaControl->getSettingManager()
|
||||
->initSetting($this, self::SETTING_MAIN_WIDGET_DEFAULT_STYLE, Quad_BgRaceScore2::STYLE);
|
||||
$this->maniaControl->getSettingManager()
|
||||
->initSetting($this, self::SETTING_MAIN_WIDGET_DEFAULT_SUBSTYLE, Quad_BgRaceScore2::SUBSTYLE_HandleSelectable);
|
||||
$this->maniaControl->getSettingManager()
|
||||
->initSetting($this, self::SETTING_LIST_WIDGETS_WIDTH, 150.);
|
||||
$this->maniaControl->getSettingManager()
|
||||
->initSetting($this, self::SETTING_LIST_WIDGETS_HEIGHT, 80.);
|
||||
$this->maniaControl->getSettingManager()
|
||||
->initSetting($this, self::SETTING_ICON_DEFAULT_OFFSET_SM, 20.);
|
||||
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_MAIN_WIDGET_DEFAULT_STYLE, Quad_BgRaceScore2::STYLE);
|
||||
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_MAIN_WIDGET_DEFAULT_SUBSTYLE, Quad_BgRaceScore2::SUBSTYLE_HandleSelectable);
|
||||
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_LIST_WIDGETS_WIDTH, 150.);
|
||||
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_LIST_WIDGETS_HEIGHT, 80.);
|
||||
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_ICON_DEFAULT_OFFSET_SM, 20.);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -76,8 +68,7 @@ class StyleManager {
|
||||
* @return float
|
||||
*/
|
||||
public function getDefaultIconOffsetSM() {
|
||||
return $this->maniaControl->getSettingManager()
|
||||
->getSettingValue($this, self::SETTING_ICON_DEFAULT_OFFSET_SM);
|
||||
return $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_ICON_DEFAULT_OFFSET_SM);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -86,8 +77,7 @@ class StyleManager {
|
||||
* @return string
|
||||
*/
|
||||
public function getDefaultLabelStyle() {
|
||||
return $this->maniaControl->getSettingManager()
|
||||
->getSettingValue($this, self::SETTING_LABEL_DEFAULT_STYLE);
|
||||
return $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_LABEL_DEFAULT_STYLE);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -96,8 +86,7 @@ class StyleManager {
|
||||
* @return string
|
||||
*/
|
||||
public function getDefaultQuadStyle() {
|
||||
return $this->maniaControl->getSettingManager()
|
||||
->getSettingValue($this, self::SETTING_QUAD_DEFAULT_STYLE);
|
||||
return $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_QUAD_DEFAULT_STYLE);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -106,8 +95,7 @@ class StyleManager {
|
||||
* @return string
|
||||
*/
|
||||
public function getDefaultQuadSubstyle() {
|
||||
return $this->maniaControl->getSettingManager()
|
||||
->getSettingValue($this, self::SETTING_QUAD_DEFAULT_SUBSTYLE);
|
||||
return $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_QUAD_DEFAULT_SUBSTYLE);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -121,11 +109,7 @@ class StyleManager {
|
||||
|
||||
// Predefine Description Label
|
||||
$descriptionLabel = new Label();
|
||||
$descriptionLabel->setAlign($descriptionLabel::LEFT, $descriptionLabel::TOP)
|
||||
->setPosition($width * -0.5 + 10, $height * -0.5 + 5)
|
||||
->setSize($width * 0.7, 4)
|
||||
->setTextSize(2)
|
||||
->setVisible(false);
|
||||
$descriptionLabel->setAlign($descriptionLabel::LEFT, $descriptionLabel::TOP)->setPosition($width * -0.5 + 10, $height * -0.5 + 5)->setSize($width * 0.7, 4)->setTextSize(2)->setVisible(false);
|
||||
|
||||
return $descriptionLabel;
|
||||
}
|
||||
@ -136,8 +120,7 @@ class StyleManager {
|
||||
* @return float
|
||||
*/
|
||||
public function getListWidgetsWidth() {
|
||||
return $this->maniaControl->getSettingManager()
|
||||
->getSettingValue($this, self::SETTING_LIST_WIDGETS_WIDTH);
|
||||
return $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_LIST_WIDGETS_WIDTH);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -146,8 +129,7 @@ class StyleManager {
|
||||
* @return float
|
||||
*/
|
||||
public function getListWidgetsHeight() {
|
||||
return $this->maniaControl->getSettingManager()
|
||||
->getSettingValue($this, self::SETTING_LIST_WIDGETS_HEIGHT);
|
||||
return $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_LIST_WIDGETS_HEIGHT);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -177,49 +159,34 @@ class StyleManager {
|
||||
|
||||
// mainframe
|
||||
$frame = new Frame();
|
||||
$frame->setSize($width, $height)
|
||||
->setZ(35); //TODO place before scoreboards
|
||||
$frame->setSize($width, $height)->setZ(35); //TODO place before scoreboards
|
||||
|
||||
// Background Quad
|
||||
$backgroundQuad = new Quad();
|
||||
$frame->add($backgroundQuad);
|
||||
$backgroundQuad->setZ(-2)
|
||||
->setSize($width, $height)
|
||||
->setStyles($quadStyle, $quadSubstyle);
|
||||
$backgroundQuad->setZ(-2)->setSize($width, $height)->setStyles($quadStyle, $quadSubstyle);
|
||||
|
||||
// Add Close Quad (X)
|
||||
$closeQuad = new Quad_Icons64x64_1();
|
||||
$frame->add($closeQuad);
|
||||
$closeQuad->setPosition($width * 0.483, $height * 0.467, 3)
|
||||
->setSize(6, 6)
|
||||
->setSubStyle($closeQuad::SUBSTYLE_QuitRace)
|
||||
->setAction(ManialinkManager::ACTION_CLOSEWIDGET);
|
||||
$closeQuad->setPosition($width * 0.483, $height * 0.467, 3)->setSize(6, 6)->setSubStyle($closeQuad::SUBSTYLE_QuitRace)->setAction(ManialinkManager::ACTION_CLOSEWIDGET);
|
||||
|
||||
if ($script) {
|
||||
$pagerSize = 6.;
|
||||
$pagerPrev = new Quad_Icons64x64_1();
|
||||
$frame->add($pagerPrev);
|
||||
$pagerPrev->setPosition($width * 0.42, $height * -0.44, 2)
|
||||
->setSize($pagerSize, $pagerSize)
|
||||
->setSubStyle($pagerPrev::SUBSTYLE_ArrowPrev);
|
||||
$pagerPrev->setPosition($width * 0.42, $height * -0.44, 2)->setSize($pagerSize, $pagerSize)->setSubStyle($pagerPrev::SUBSTYLE_ArrowPrev);
|
||||
|
||||
$pagerNext = new Quad_Icons64x64_1();
|
||||
$frame->add($pagerNext);
|
||||
$pagerNext->setPosition($width * 0.45, $height * -0.44, 2)
|
||||
->setSize($pagerSize, $pagerSize)
|
||||
->setSubStyle($pagerNext::SUBSTYLE_ArrowNext);
|
||||
$pagerNext->setPosition($width * 0.45, $height * -0.44, 2)->setSize($pagerSize, $pagerSize)->setSubStyle($pagerNext::SUBSTYLE_ArrowNext);
|
||||
|
||||
$pageCountLabel = new Label_Text();
|
||||
$frame->add($pageCountLabel);
|
||||
$pageCountLabel->setHAlign($pageCountLabel::RIGHT)
|
||||
->setPosition($width * 0.40, $height * -0.44, 1)
|
||||
->setStyle($pageCountLabel::STYLE_TextTitle1)
|
||||
->setTextSize(1.3);
|
||||
$pageCountLabel->setHAlign($pageCountLabel::RIGHT)->setPosition($width * 0.40, $height * -0.44, 1)->setStyle($pageCountLabel::STYLE_TextTitle1)->setTextSize(1.3);
|
||||
|
||||
if ($paging) {
|
||||
$paging->addButton($pagerNext)
|
||||
->addButton($pagerPrev)
|
||||
->setLabel($pageCountLabel);
|
||||
$paging->addButton($pagerNext)->addButton($pagerPrev)->setLabel($pageCountLabel);
|
||||
}
|
||||
}
|
||||
|
||||
@ -232,8 +199,7 @@ class StyleManager {
|
||||
* @return string
|
||||
*/
|
||||
public function getDefaultMainWindowStyle() {
|
||||
return $this->maniaControl->getSettingManager()
|
||||
->getSettingValue($this, self::SETTING_MAIN_WIDGET_DEFAULT_STYLE);
|
||||
return $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MAIN_WIDGET_DEFAULT_STYLE);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -242,7 +208,6 @@ class StyleManager {
|
||||
* @return string
|
||||
*/
|
||||
public function getDefaultMainWindowSubStyle() {
|
||||
return $this->maniaControl->getSettingManager()
|
||||
->getSettingValue($this, self::SETTING_MAIN_WIDGET_DEFAULT_SUBSTYLE);
|
||||
return $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MAIN_WIDGET_DEFAULT_SUBSTYLE);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user