From 4951829017fe0500b1170fd6fd706bd6ab5c44da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steffen=20Schro=CC=88der?= Date: Thu, 28 Nov 2013 17:36:39 +0100 Subject: [PATCH] - Ingame configurator -> script settings - fixed local records plugin - fixed systeminfo command - FML update --- .../core/Configurators/Configurator.php | 158 ++++++++++++++-- .../core/Configurators/ConfiguratorMenu.php | 43 +++++ .../core/Configurators/ScriptSettings.php | 174 ++++++++++++++++++ application/core/FML/Controls/Entry.php | 103 +++++++++++ .../core/FML/Controls/Labels/Label_Button.php | 1 - application/core/Server/ServerCommands.php | 2 +- application/plugins/LocalRecords.php | 8 +- 7 files changed, 468 insertions(+), 21 deletions(-) create mode 100644 application/core/Configurators/ConfiguratorMenu.php create mode 100644 application/core/Configurators/ScriptSettings.php diff --git a/application/core/Configurators/Configurator.php b/application/core/Configurators/Configurator.php index 804012fd..424924b7 100644 --- a/application/core/Configurators/Configurator.php +++ b/application/core/Configurators/Configurator.php @@ -8,12 +8,19 @@ use ManiaControl\Callbacks\CallbackManager; use ManiaControl\Manialinks\ManialinkPageAnswerListener; use ManiaControl\Players\Player; use FML\ManiaLink; -use FML\Controls\Quad; +use FML\Controls\Control; use FML\Controls\Frame; -use FML\Controls\Quads\Quad_UiSMSpectatorScoreBig; -use FML\Controls\Quads\Quad_EnergyBar; -use FML\Controls\Quads\Quad_BgsPlayerCard; +use FML\Controls\Label; +use FML\Controls\Labels\Label_Text; +use FML\Controls\Quad; use FML\Controls\Quads\Quad_BgRaceScore2; +use FML\Script\Menus; +use FML\Script\Pages; +use FML\Script\Script; +use FML\Script\Tooltips; + +require_once __DIR__ . '/ConfiguratorMenu.php'; +require_once __DIR__ . '/ScriptSettings.php'; /** * Class managing ingame ManiaControl configuration @@ -26,14 +33,22 @@ class Configurator implements CallbackListener, ManialinkPageAnswerListener { */ const MLID_MENU = 'Configurator.Menu.MLID'; const ACTION_TOGGLEMENU = 'Configurator.ToggleMenuAction'; + const ACTION_SAVECONFIG = 'Configurator.SaveConfigAction'; + const SETTING_MENU_POSX = 'Menu Widget Position: X'; + const SETTING_MENU_POSY = 'Menu Widget Position: Y'; + const SETTING_MENU_WIDTH = 'Menu Widget Width'; + const SETTING_MENU_HEIGHT = 'Menu Widget Height'; + const SETTING_MENU_STYLE = 'Menu Widget BackgroundQuad Style'; + const SETTING_MENU_SUBSTYLE = 'Menu Widget BackgroundQuad Substyle'; /** * Private properties */ private $maniaControl = null; + private $scriptSettings = null; + private $menus = array(); private $playersMenuShown = array(); private $manialink = null; - private $emptyManialink = null; /** * Create a new Configurator @@ -44,13 +59,37 @@ class Configurator implements CallbackListener, ManialinkPageAnswerListener { $this->maniaControl = $maniaControl; $this->addAdminMenuItem(); + // Init settings + $this->maniaControl->settingManager->initSetting($this, self::SETTING_MENU_POSX, 0.); + $this->maniaControl->settingManager->initSetting($this, self::SETTING_MENU_POSY, 0.); + $this->maniaControl->settingManager->initSetting($this, self::SETTING_MENU_WIDTH, 170.); + $this->maniaControl->settingManager->initSetting($this, self::SETTING_MENU_HEIGHT, 90.); + $this->maniaControl->settingManager->initSetting($this, self::SETTING_MENU_STYLE, Quad_BgRaceScore2::STYLE); + $this->maniaControl->settingManager->initSetting($this, self::SETTING_MENU_SUBSTYLE, + Quad_BgRaceScore2::SUBSTYLE_HandleSelectable); + // Register for page answers $this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_TOGGLEMENU, $this, 'handleToggleMenuAction'); + $this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_SAVECONFIG, $this, + 'handleSaveConfigAction'); // Register for callbacks $this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERDISCONNECT, $this, 'handlePlayerDisconnect'); + + // Create script settings + $this->scriptSettings = new ScriptSettings($maniaControl); + $this->addMenu($this->scriptSettings); + } + + /** + * Add a configurator menu + * + * @param ConfiguratorMenu $menu + */ + public function addMenu(ConfiguratorMenu $menu) { + array_push($this->menus, $menu); } /** @@ -67,6 +106,18 @@ class Configurator implements CallbackListener, ManialinkPageAnswerListener { $this->showMenu($player); } + /** + * Save the config data received from the manialink + * + * @param array $callback + * @param Player $player + */ + public function handleSaveConfigAction(array $callback, Player $player) { + foreach ($this->menus as $menu) { + $menu->saveConfigData($callback[1], $player); + } + } + /** * Handle PlayerDisconnect callback * @@ -74,9 +125,7 @@ class Configurator implements CallbackListener, ManialinkPageAnswerListener { */ public function handlePlayerDisconnect(array $callback) { $login = $callback[1][0]; - if (isset($this->playersMenuShown[$login])) { - unset($this->playersMenuShown[$login]); - } + unset($this->playersMenuShown[$login]); } /** @@ -98,8 +147,8 @@ class Configurator implements CallbackListener, ManialinkPageAnswerListener { * @param Player $player */ private function hideMenu(Player $player) { - $this->buildManialink(); - $manialinkText = $this->emptyManialink->render()->saveXML(); + $emptyManialink = new ManiaLink(self::MLID_MENU); + $manialinkText = $emptyManialink->render()->saveXML(); $this->maniaControl->manialinkManager->sendManialink($manialinkText, $player->login); $this->maniaControl->manialinkManager->enableAltMenu($player); unset($this->playersMenuShown[$player->login]); @@ -111,19 +160,98 @@ class Configurator implements CallbackListener, ManialinkPageAnswerListener { * @param bool $forceBuild */ private function buildManialink($forceBuild = false) { - if (is_object($this->manialink) && !$forceBuild) return; + $menuPosX = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MENU_POSX); + $menuPosY = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MENU_POSY); + $menuWidth = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MENU_WIDTH); + $menuHeight = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MENU_HEIGHT); + $quadStyle = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MENU_STYLE); + $quadSubstyle = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MENU_SUBSTYLE); - $this->emptyManialink = new ManiaLink(self::MLID_MENU); + $menuListWidth = $menuWidth * 0.3; + $menuItemHeight = 10.; + $subMenuWidth = $menuWidth - $menuListWidth; + $subMenuHeight = $menuHeight; $manialink = new ManiaLink(self::MLID_MENU); $frame = new Frame(); $manialink->add($frame); + $frame->setPosition($menuPosX, $menuPosY); - $backgroundQuad = new Quad_BgRaceScore2(); + $backgroundQuad = new Quad(); $frame->add($backgroundQuad); - $backgroundQuad->setSize(100, 70); - $backgroundQuad->setSubStyle($backgroundQuad::SUBSTYLE_HandleSelectable); + $backgroundQuad->setSize($menuWidth, $menuHeight); + $backgroundQuad->setStyles($quadStyle, $quadSubstyle); + + $menuItemsFrame = new Frame(); + $frame->add($menuItemsFrame); + $menuItemsFrame->setX($menuWidth * -0.5 + $menuListWidth * 0.5); + + $itemsBackgroundQuad = new Quad(); + $menuItemsFrame->add($itemsBackgroundQuad); + $itemsBackgroundQuad->setSize($menuListWidth, $menuHeight); + $itemsBackgroundQuad->setStyles($quadStyle, $quadSubstyle); + + $menusFrame = new Frame(); + $frame->add($menusFrame); + $menusFrame->setX($menuWidth * -0.5 + $menuListWidth + $subMenuWidth * 0.5); + + // Create script and features + $script = new Script(); + $manialink->setScript($script); + + $pages = new Pages(); + $script->addFeature($pages); + + $tooltips = new Tooltips(); + $script->addFeature($tooltips); + + $menus = new Menus(); + $script->addFeature($menus); + + $menuRelationships = array(); + $menuItemY = $menuHeight * 0.42; + foreach ($this->menus as $menu) { + // Add title + $menuItemLabel = new Label(); + $menuItemsFrame->add($menuItemLabel); + $menuItemLabel->setY($menuItemY); + $menuItemLabel->setSize($menuListWidth * 0.9, $menuItemHeight * 0.9); + $menuItemLabel->setStyle(Label_Text::STYLE_TextCardRaceRank); + $menuItemLabel->setText($menu->getTitle()); + + // Add menu + $menuControl = $menu->getMenu($subMenuWidth, $subMenuHeight, $pages, $tooltips); + $menusFrame->add($menuControl); + + // Add menu relationship + array_push($menuRelationships, array($menuItemLabel, $menuControl)); + + $menuItemY -= $menuItemHeight * 1.1; + } + $menus->add($menuRelationships); + + // Add close button + $closeButton = new Label(); + $frame->add($closeButton); + $closeButton->setPosition($menuWidth * -0.5 + $menuListWidth * 0.29, $menuHeight * -0.43); + $closeButton->setSize($menuListWidth * 0.3, $menuListWidth * 0.1); + $closeButton->setStyle(Label_Text::STYLE_TextButtonNavBack); + $closeButton->setTextPrefix('$999'); + $closeButton->setTranslate(true); + $closeButton->setText('Close'); + $closeButton->setAction(self::ACTION_TOGGLEMENU); + + // Add save button + $saveButton = new Label(); + $frame->add($saveButton); + $saveButton->setPosition($menuWidth * -0.5 + $menuListWidth * 0.71, $menuHeight * -0.43); + $saveButton->setSize($menuListWidth * 0.3, $menuListWidth * 0.1); + $saveButton->setStyle(Label_Text::STYLE_TextButtonNavBack); + $saveButton->setTextPrefix('$0f5'); + $saveButton->setTranslate(true); + $saveButton->setText('Save'); + $saveButton->setAction(self::ACTION_SAVECONFIG); $this->manialink = $manialink; } diff --git a/application/core/Configurators/ConfiguratorMenu.php b/application/core/Configurators/ConfiguratorMenu.php new file mode 100644 index 00000000..01310a44 --- /dev/null +++ b/application/core/Configurators/ConfiguratorMenu.php @@ -0,0 +1,43 @@ + diff --git a/application/core/Configurators/ScriptSettings.php b/application/core/Configurators/ScriptSettings.php new file mode 100644 index 00000000..78db645e --- /dev/null +++ b/application/core/Configurators/ScriptSettings.php @@ -0,0 +1,174 @@ +maniaControl = $maniaControl; + + // Init settings + $this->maniaControl->settingManager->initSetting($this, self::SETTING_TITLE, 'Script Settings'); + $this->maniaControl->settingManager->initSetting($this, self::SETTING_STYLE_SETTING, Label_Text::STYLE_TextStaticSmall); + $this->maniaControl->settingManager->initSetting($this, self::SETTING_STYLE_DESCRIPTION, Label_Text::STYLE_TextTips); + } + + /** + * + * @see \ManiaControl\Configurators\ConfiguratorMenu::getTitle() + */ + public function getTitle() { + return $this->maniaControl->settingManager->getSetting($this, self::SETTING_TITLE); + } + + /** + * + * @see \ManiaControl\Configurators\ConfiguratorMenu::getMenu() + */ + public function getMenu($width, $height, Pages $pages, Tooltips $tooltips) { + $frame = new Frame(); + + $this->maniaControl->client->query('GetModeScriptInfo'); + $scriptInfo = $this->maniaControl->client->getResponse(); + $scriptParams = $scriptInfo['ParamDescs']; + + $this->maniaControl->client->query('GetModeScriptSettings'); + $scriptSettings = $this->maniaControl->client->getResponse(); + + // Config + $labelStyleSetting = $this->maniaControl->settingManager->getSetting($this, self::SETTING_STYLE_SETTING); + $labelStyleDescription = $this->maniaControl->settingManager->getSetting($this, self::SETTING_STYLE_DESCRIPTION); + $pagerSize = 9.; + $settingHeight = 5.; + $labelTextSize = 2; + $pageMaxCount = 15; + + // Pagers + $pagerPrev = new Quad_Icons64x64_1(); + $frame->add($pagerPrev); + $pagerPrev->setPosition($width * 0.39, $height * -0.44); + $pagerPrev->setSize($pagerSize, $pagerSize); + $pagerPrev->setSubStyle(Quad_Icons64x64_1::SUBSTYLE_ArrowPrev); + + $pagerNext = new Quad_Icons64x64_1(); + $frame->add($pagerNext); + $pagerNext->setPosition($width * 0.45, $height * -0.44); + $pagerNext->setSize($pagerSize, $pagerSize); + $pagerNext->setSubStyle(Quad_Icons64x64_1::SUBSTYLE_ArrowNext); + + $pageCountLabel = new Label(); + $frame->add($pageCountLabel); + $pageCountLabel->setHAlign(Control::RIGHT); + $pageCountLabel->setPosition($width * 0.35, $height * -0.44); + $pageCountLabel->setStyle('TextTitle1'); + $pageCountLabel->setTextSize(2); + + // Setting pages + $pageFrames = array(); + foreach ($scriptParams as $index => $scriptParam) { + $settingName = $scriptParam['Name']; + if (!isset($scriptSettings[$settingName])) continue; + + if (!isset($pageFrame)) { + $pageFrame = new Frame(); + $frame->add($pageFrame); + array_push($pageFrames, $pageFrame); + $y = $height * 0.43; + } + + $nameLabel = new Label(); + $pageFrame->add($nameLabel); + $nameLabel->setHAlign(Control::LEFT); + $nameLabel->setPosition($width * -0.46, $y); + $nameLabel->setSize($width * 0.4, $settingHeight); + $nameLabel->setStyle($labelStyleSetting); + $nameLabel->setTextSize($labelTextSize); + $nameLabel->setText($settingName); + + $decriptionLabel = new Label(); + $pageFrame->add($decriptionLabel); + $decriptionLabel->setHAlign(Control::LEFT); + $decriptionLabel->setPosition($width * -0.45, $height * -0.44); + $decriptionLabel->setSize($width * 0.7, $settingHeight); + $decriptionLabel->setStyle($labelStyleDescription); + $decriptionLabel->setTranslate(true); + $decriptionLabel->setTextPrefix('Desc: '); + $decriptionLabel->setText($scriptParam['Desc']); + $tooltips->add($nameLabel, $decriptionLabel); + + $entry = new Entry(); + $pageFrame->add($entry); + $entry->setHAlign(Control::RIGHT); + $entry->setPosition($width * 0.46, $y); + $entry->setSize($width * 0.45, $settingHeight); + $entry->setName(self::NAME_PREFIX . $settingName); + $settingValue = $scriptSettings[$settingName]; + if ($settingValue === false) { + $settingValue = 0; + } + $entry->setDefault($settingValue); + + $y -= $settingHeight; + if ($index % $pageMaxCount == $pageMaxCount - 1) { + unset($pageFrame); + } + } + + $pages->add(array(-1 => $pagerPrev, 1 => $pagerNext), $pageFrames, $pageCountLabel); + + return $frame; + } + + /** + * + * @see \ManiaControl\Configurators\ConfiguratorMenu::saveConfigData() + */ + public function saveConfigData(array $configData, Player $player) { + $this->maniaControl->client->query('GetModeScriptSettings'); + $scriptSettings = $this->maniaControl->client->getResponse(); +// var_dump($configData); +// var_dump($scriptSettings); + $prefixLength = strlen(self::NAME_PREFIX); + foreach ($configData[3] as $dataName => $dataValue) { + if (substr($dataName, 0, $prefixLength) != self::NAME_PREFIX) continue; + + $settingName = substr($dataName, $prefixLength); + } + } +} + +?> diff --git a/application/core/FML/Controls/Entry.php b/application/core/FML/Controls/Entry.php index d71f027a..1555b236 100644 --- a/application/core/FML/Controls/Entry.php +++ b/application/core/FML/Controls/Entry.php @@ -2,6 +2,11 @@ namespace FML\Controls; +use FML\Types\NewLineable; +use FML\Types\Scriptable; +use FML\Types\Styleable; +use FML\Types\TextFormatable; + /** * Class representing CMlEntry * @@ -13,6 +18,13 @@ class Entry extends Control implements NewLineable, Scriptable, Styleable, TextF */ protected $name = ''; protected $default = null; + protected $autoNewLine = 0; + protected $scriptEvents = 0; + protected $style = ''; + protected $textColor = ''; + protected $textSize = -1; + protected $areaColor = ''; + protected $areaFocusColor = ''; /** * Construct a new entry control @@ -46,6 +58,76 @@ class Entry extends Control implements NewLineable, Scriptable, Styleable, TextF return $this; } + /** + * + * @see \FML\Types\NewLineable::setAutoNewLine() + * @return \FML\Controls\Entry + */ + public function setAutoNewLine($autoNewLine) { + $this->autoNewLine = ($autoNewLine ? 1 : 0); + return $this; + } + + /** + * + * @see \FML\Types\Scriptable::setScriptEvents() + * @return \FML\Controls\Entry + */ + public function setScriptEvents($scriptEvents) { + $this->scriptEvents = ($scriptEvents ? 1 : 0); + return $this; + } + + /** + * + * @see \FML\Types\Styleable::setStyle() + * @return \FML\Controls\Entry + */ + public function setStyle($style) { + $this->style = $style; + return $this; + } + + /** + * + * @see \FML\Types\TextFormatable::setTextColor() + * @return \FML\Controls\Entry + */ + public function setTextColor($textColor) { + $this->textColor = $textColor; + return $this; + } + + /** + * + * @see \FML\Types\TextFormatable::setTextSize() + * @return \FML\Controls\Entry + */ + public function setTextSize($textSize) { + $this->textSize = $textSize; + return $this; + } + + /** + * + * @see \FML\Types\TextFormatable::setAreaColor() + * @return \FML\Controls\Entry + */ + public function setAreaColor($areaColor) { + $this->areaColor = $areaFocusColor; + return $this; + } + + /** + * + * @see \FML\Types\TextFormatable::setAreaFocusColor() + * @return \FML\Controls\Entry + */ + public function setAreaFocusColor($areaFocusColor) { + $this->areaFocusColor = $areaFocusColor; + return $this; + } + /** * * @see \FML\Control::render() @@ -58,6 +140,27 @@ class Entry extends Control implements NewLineable, Scriptable, Styleable, TextF if ($this->default !== null) { $xml->setAttribute('default', $this->default); } + if ($this->autoNewLine) { + $xml->setAttribute('autonewline', $this->autoNewLine); + } + if ($this->scriptEvents) { + $xml->setAttribute('scriptevents', $this->scriptEvents); + } + if ($this->style) { + $xml->setAttribute('style', $this->style); + } + if ($this->textColor) { + $xml->setAttribute('textcolor', $this->textColor); + } + if ($this->textSize >= 0.) { + $xml->setAttribute('textsize', $this->textSize); + } + if ($this->areaColor) { + $xml->setAttribute('areacolor', $this->areaColor); + } + if ($this->areaFocusColor) { + $xml->setAttribute('areafocuscolor', $this->areaFocusColor); + } return $xml; } } diff --git a/application/core/FML/Controls/Labels/Label_Button.php b/application/core/FML/Controls/Labels/Label_Button.php index 385f21b2..b7296d36 100644 --- a/application/core/FML/Controls/Labels/Label_Button.php +++ b/application/core/FML/Controls/Labels/Label_Button.php @@ -24,7 +24,6 @@ class Label_Button extends Label { const STYLE_CardButtonSmall = 'CardButtonSmall'; const STYLE_CardButtonSmallL = 'CardButtonSmallL'; const STYLE_CardButtonSmallS = 'CardButtonSmallS'; - const STYLE_CardButtonSmallS = 'CardButtonSmallS'; const STYLE_CardButtonSmallWide = 'CardButtonSmallWide'; const STYLE_CardButtonSmallXL = 'CardButtonSmallXL'; const STYLE_CardButtonSmallXS = 'CardButtonSmallXS'; diff --git a/application/core/Server/ServerCommands.php b/application/core/Server/ServerCommands.php index 3b051f80..030884d3 100644 --- a/application/core/Server/ServerCommands.php +++ b/application/core/Server/ServerCommands.php @@ -80,7 +80,7 @@ class ServerCommands implements CallbackListener, CommandListener { } $systemInfo = $this->maniaControl->server->getSystemInfo(); $message = 'SystemInfo: ip=' . $systemInfo['PublishedIp'] . ', port=' . $systemInfo['Port'] . ', p2pPort=' . - $systemInfo['P2PPort'] . ', title=' . $systemInfo['TitleId'] . ', login=' . $systemInfo['ServerLogin'] . ', '; + $systemInfo['P2PPort'] . ', title=' . $systemInfo['TitleId'] . ', login=' . $systemInfo['ServerLogin'] . '.'; return $this->maniaControl->chat->sendInformation($message, $player->login); } diff --git a/application/plugins/LocalRecords.php b/application/plugins/LocalRecords.php index 20f54cf8..a7267e29 100644 --- a/application/plugins/LocalRecords.php +++ b/application/plugins/LocalRecords.php @@ -279,13 +279,13 @@ class LocalRecordsPlugin extends Plugin implements CallbackListener { $backgroundQuad = new Quad(); $recordFrame->add($backgroundQuad); - $backgroundQuad->setSize($width, $lineHeight); + $backgroundQuad->setSize($width * 1.03, $lineHeight * 1.25); $backgroundQuad->setStyles($quadStyle, $quadSubstyle); $rankLabel = new Label(); $recordFrame->add($rankLabel); $rankLabel->setHAlign(Control::LEFT); - $rankLabel->setPosition($width * -0.47); + $rankLabel->setX($width * -0.47); $rankLabel->setSize($width * 0.06, $lineHeight); $rankLabel->setTextSize(1); $rankLabel->setTextPrefix('$o'); @@ -294,7 +294,7 @@ class LocalRecordsPlugin extends Plugin implements CallbackListener { $nameLabel = new Label(); $recordFrame->add($nameLabel); $nameLabel->setHAlign(Control::LEFT); - $nameLabel->setPosition($width * -0.4); + $nameLabel->setX($width * -0.4); $nameLabel->setSize($width * 0.6, $lineHeight); $nameLabel->setTextSize(1); $nameLabel->setText($record->nickname); @@ -302,7 +302,7 @@ class LocalRecordsPlugin extends Plugin implements CallbackListener { $timeLabel = new Label(); $recordFrame->add($timeLabel); $timeLabel->setHAlign(Control::RIGHT); - $timeLabel->setPosition($width * 0.47); + $timeLabel->setX($width * 0.47); $timeLabel->setSize($width * 0.25, $lineHeight); $timeLabel->setTextSize(1); $timeLabel->setText(Formatter::formatTime($record->time));