started mc settings

This commit is contained in:
kremsy 2014-01-05 19:00:11 +01:00
parent 797843e057
commit c60c1e5c30
4 changed files with 138 additions and 66 deletions

View File

@ -2,30 +2,31 @@
namespace ManiaControl\Configurators; namespace ManiaControl\Configurators;
use FML\Controls\Quads\Quad_UIConstruction_Buttons;
use ManiaControl\ManiaControl;
use ManiaControl\Callbacks\CallbackListener;
use ManiaControl\Callbacks\CallbackManager;
use ManiaControl\Manialinks\ManialinkManager;
use ManiaControl\Manialinks\ManialinkPageAnswerListener;
use ManiaControl\Players\Player;
use FML\ManiaLink;
use FML\ManiaLinks;
use FML\Controls\Frame; use FML\Controls\Frame;
use FML\Controls\Label; use FML\Controls\Label;
use FML\Controls\Labels\Label_Text; use FML\Controls\Labels\Label_Text;
use FML\Controls\Quad; use FML\Controls\Quad;
use FML\Controls\Quads\Quad_BgRaceScore2; use FML\Controls\Quads\Quad_BgRaceScore2;
use FML\Controls\Quads\Quad_Icons64x64_1; use FML\Controls\Quads\Quad_Icons64x64_1;
use FML\Controls\Quads\Quad_UIConstruction_Buttons;
use FML\ManiaLink;
use FML\ManiaLinks;
use FML\Script\Menus; use FML\Script\Menus;
use FML\Script\Pages; use FML\Script\Pages;
use FML\Script\Script; use FML\Script\Script;
use FML\Script\Tooltips; use FML\Script\Tooltips;
use ManiaControl\Callbacks\CallbackListener;
use ManiaControl\Callbacks\CallbackManager;
use ManiaControl\Commands\CommandListener; use ManiaControl\Commands\CommandListener;
use ManiaControl\ManiaControl;
use ManiaControl\Manialinks\ManialinkManager;
use ManiaControl\Manialinks\ManialinkPageAnswerListener;
use ManiaControl\Players\Player;
require_once __DIR__ . '/ConfiguratorMenu.php'; require_once __DIR__ . '/ConfiguratorMenu.php';
require_once __DIR__ . '/ScriptSettings.php'; require_once __DIR__ . '/ScriptSettings.php';
require_once __DIR__ . '/ServerSettings.php'; require_once __DIR__ . '/ServerSettings.php';
require_once __DIR__ . '/ManiaControlSettings.php';
/** /**
* Class managing ingame ManiaControl configuration * Class managing ingame ManiaControl configuration
@ -36,21 +37,22 @@ class Configurator implements CallbackListener, CommandListener, ManialinkPageAn
/** /**
* Constants * Constants
*/ */
const ACTION_TOGGLEMENU = 'Configurator.ToggleMenuAction'; const ACTION_TOGGLEMENU = 'Configurator.ToggleMenuAction';
const ACTION_SAVECONFIG = 'Configurator.SaveConfigAction'; const ACTION_SAVECONFIG = 'Configurator.SaveConfigAction';
const SETTING_MENU_POSX = 'Menu Widget Position: X'; const SETTING_MENU_POSX = 'Menu Widget Position: X';
const SETTING_MENU_POSY = 'Menu Widget Position: Y'; const SETTING_MENU_POSY = 'Menu Widget Position: Y';
const SETTING_MENU_WIDTH = 'Menu Widget Width'; const SETTING_MENU_WIDTH = 'Menu Widget Width';
const SETTING_MENU_HEIGHT = 'Menu Widget Height'; const SETTING_MENU_HEIGHT = 'Menu Widget Height';
const SETTING_MENU_STYLE = 'Menu Widget BackgroundQuad Style'; const SETTING_MENU_STYLE = 'Menu Widget BackgroundQuad Style';
const SETTING_MENU_SUBSTYLE = 'Menu Widget BackgroundQuad Substyle'; const SETTING_MENU_SUBSTYLE = 'Menu Widget BackgroundQuad Substyle';
/** /**
* Private properties * Private properties
*/ */
private $maniaControl = null; private $maniaControl = null;
private $scriptSettings = null; private $scriptSettings = null;
private $serverSettings = null; private $serverSettings = null;
private $maniaControlSettings = null;
private $menus = array(); private $menus = array();
private $playersMenuShown = array(); private $playersMenuShown = array();
@ -62,7 +64,7 @@ class Configurator implements CallbackListener, CommandListener, ManialinkPageAn
public function __construct(ManiaControl $maniaControl) { public function __construct(ManiaControl $maniaControl) {
$this->maniaControl = $maniaControl; $this->maniaControl = $maniaControl;
$this->addActionsMenuItem(); $this->addActionsMenuItem();
// Init settings // Init settings
$this->maniaControl->settingManager->initSetting($this, self::SETTING_MENU_POSX, 0.); $this->maniaControl->settingManager->initSetting($this, self::SETTING_MENU_POSX, 0.);
$this->maniaControl->settingManager->initSetting($this, self::SETTING_MENU_POSY, 3.); $this->maniaControl->settingManager->initSetting($this, self::SETTING_MENU_POSY, 3.);
@ -70,24 +72,28 @@ class Configurator implements CallbackListener, CommandListener, ManialinkPageAn
$this->maniaControl->settingManager->initSetting($this, self::SETTING_MENU_HEIGHT, 81.); $this->maniaControl->settingManager->initSetting($this, self::SETTING_MENU_HEIGHT, 81.);
$this->maniaControl->settingManager->initSetting($this, self::SETTING_MENU_STYLE, Quad_BgRaceScore2::STYLE); $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); $this->maniaControl->settingManager->initSetting($this, self::SETTING_MENU_SUBSTYLE, Quad_BgRaceScore2::SUBSTYLE_HandleSelectable);
// Register for page answers // Register for page answers
$this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_TOGGLEMENU, $this, 'handleToggleMenuAction'); $this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_TOGGLEMENU, $this, 'handleToggleMenuAction');
$this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_SAVECONFIG, $this, 'handleSaveConfigAction'); $this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_SAVECONFIG, $this, 'handleSaveConfigAction');
// Register for callbacks // Register for callbacks
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERDISCONNECT, $this, 'handlePlayerDisconnect'); $this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERDISCONNECT, $this, 'handlePlayerDisconnect');
$this->maniaControl->callbackManager->registerCallbackListener(ScriptSettings::CB_SCRIPTSETTING_CHANGED, $this, 'reopenMenu'); $this->maniaControl->callbackManager->registerCallbackListener(ScriptSettings::CB_SCRIPTSETTING_CHANGED, $this, 'reopenMenu');
$this->maniaControl->callbackManager->registerCallbackListener(ServerSettings::CB_SERVERSETTING_CHANGED, $this, 'reopenMenu'); $this->maniaControl->callbackManager->registerCallbackListener(ServerSettings::CB_SERVERSETTING_CHANGED, $this, 'reopenMenu');
// Create script settings
$this->scriptSettings = new ScriptSettings($maniaControl);
$this->addMenu($this->scriptSettings);
// Create server settings // Create server settings
$this->serverSettings = new ServerSettings($maniaControl); $this->serverSettings = new ServerSettings($maniaControl);
$this->addMenu($this->serverSettings); $this->addMenu($this->serverSettings);
// Create script settings
$this->scriptSettings = new ScriptSettings($maniaControl);
$this->addMenu($this->scriptSettings);
// Create Mania Control Settings
$this->maniaControlSettings = new ServerSettings($maniaControl);
$this->addMenu($this->maniaControlSettings);
// Register for commands // Register for commands
$this->maniaControl->commandManager->registerCommandListener('config', $this, 'handleConfigCommand', true); $this->maniaControl->commandManager->registerCommandListener('config', $this, 'handleConfigCommand', true);
} }
@ -116,8 +122,8 @@ class Configurator implements CallbackListener, CommandListener, ManialinkPageAn
* @param array $callback * @param array $callback
*/ */
public function reopenMenu(array $callback) { public function reopenMenu(array $callback) {
foreach ($this->playersMenuShown as $login => $shown) { foreach($this->playersMenuShown as $login => $shown) {
if ($shown == true) { if($shown == true) {
$player = $this->maniaControl->playerManager->getPlayer($login); $player = $this->maniaControl->playerManager->getPlayer($login);
$this->showMenu($player); $this->showMenu($player);
} }
@ -127,7 +133,7 @@ class Configurator implements CallbackListener, CommandListener, ManialinkPageAn
/** /**
* Handle toggle menu action * Handle toggle menu action
* *
* @param array $callback * @param array $callback
* @param Player $player * @param Player $player
*/ */
public function handleToggleMenuAction(array $callback, Player $player) { public function handleToggleMenuAction(array $callback, Player $player) {
@ -137,11 +143,11 @@ class Configurator implements CallbackListener, CommandListener, ManialinkPageAn
/** /**
* Save the config data received from the manialink * Save the config data received from the manialink
* *
* @param array $callback * @param array $callback
* @param Player $player * @param Player $player
*/ */
public function handleSaveConfigAction(array $callback, Player $player) { public function handleSaveConfigAction(array $callback, Player $player) {
foreach ($this->menus as $menu) { foreach($this->menus as $menu) {
$menu->saveConfigData($callback[1], $player); $menu->saveConfigData($callback[1], $player);
} }
} }
@ -162,7 +168,7 @@ class Configurator implements CallbackListener, CommandListener, ManialinkPageAn
* @param Player $player * @param Player $player
*/ */
public function showMenu(Player $player) { public function showMenu(Player $player) {
$manialink = $this->buildManialink(); $manialink = $this->buildManialink();
$manialinkText = $manialink->render()->saveXML(); $manialinkText = $manialink->render()->saveXML();
$this->maniaControl->manialinkManager->sendManialink($manialinkText, $player->login); $this->maniaControl->manialinkManager->sendManialink($manialinkText, $player->login);
$this->maniaControl->manialinkManager->disableAltMenu($player); $this->maniaControl->manialinkManager->disableAltMenu($player);
@ -176,7 +182,7 @@ class Configurator implements CallbackListener, CommandListener, ManialinkPageAn
*/ */
public function hideMenu(Player $player) { public function hideMenu(Player $player) {
$emptyManialink = new ManiaLink(ManialinkManager::MAIN_MLID); $emptyManialink = new ManiaLink(ManialinkManager::MAIN_MLID);
$manialinkText = $emptyManialink->render()->saveXML(); $manialinkText = $emptyManialink->render()->saveXML();
$this->maniaControl->manialinkManager->sendManialink($manialinkText, $player->login); $this->maniaControl->manialinkManager->sendManialink($manialinkText, $player->login);
$this->maniaControl->manialinkManager->enableAltMenu($player); $this->maniaControl->manialinkManager->enableAltMenu($player);
unset($this->playersMenuShown[$player->login]); unset($this->playersMenuShown[$player->login]);
@ -188,10 +194,9 @@ class Configurator implements CallbackListener, CommandListener, ManialinkPageAn
* @param Player $player * @param Player $player
*/ */
public function toggleMenu(Player $player) { public function toggleMenu(Player $player) {
if (isset($this->playersMenuShown[$player->login])) { if(isset($this->playersMenuShown[$player->login])) {
$this->hideMenu($player); $this->hideMenu($player);
} } else {
else {
$this->showMenu($player); $this->showMenu($player);
} }
} }
@ -202,52 +207,52 @@ class Configurator implements CallbackListener, CommandListener, ManialinkPageAn
* @param bool $forceBuild * @param bool $forceBuild
*/ */
private function buildManialink($forceBuild = false) { private function buildManialink($forceBuild = false) {
$menuPosX = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MENU_POSX); $menuPosX = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MENU_POSX);
$menuPosY = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MENU_POSY); $menuPosY = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MENU_POSY);
$menuWidth = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MENU_WIDTH); $menuWidth = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MENU_WIDTH);
$menuHeight = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MENU_HEIGHT); $menuHeight = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MENU_HEIGHT);
$quadStyle = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MENU_STYLE); $quadStyle = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MENU_STYLE);
$quadSubstyle = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MENU_SUBSTYLE); $quadSubstyle = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MENU_SUBSTYLE);
$menuListWidth = $menuWidth * 0.3; $menuListWidth = $menuWidth * 0.3;
$menuItemHeight = 10.; $menuItemHeight = 10.;
$subMenuWidth = $menuWidth - $menuListWidth; $subMenuWidth = $menuWidth - $menuListWidth;
$subMenuHeight = $menuHeight; $subMenuHeight = $menuHeight;
$manialinks = new ManiaLinks(); $manialinks = new ManiaLinks();
$manialink = new ManiaLink(ManialinkManager::MAIN_MLID); $manialink = new ManiaLink(ManialinkManager::MAIN_MLID);
$manialinks->add($manialink); $manialinks->add($manialink);
$frame = new Frame(); $frame = new Frame();
$manialink->add($frame); $manialink->add($frame);
$frame->setPosition($menuPosX, $menuPosY); $frame->setPosition($menuPosX, $menuPosY);
$backgroundQuad = new Quad(); $backgroundQuad = new Quad();
$frame->add($backgroundQuad); $frame->add($backgroundQuad);
$backgroundQuad->setSize($menuWidth, $menuHeight); $backgroundQuad->setSize($menuWidth, $menuHeight);
$backgroundQuad->setStyles($quadStyle, $quadSubstyle); $backgroundQuad->setStyles($quadStyle, $quadSubstyle);
$menuItemsFrame = new Frame(); $menuItemsFrame = new Frame();
$frame->add($menuItemsFrame); $frame->add($menuItemsFrame);
$menuItemsFrame->setX($menuWidth * -0.5 + $menuListWidth * 0.5); $menuItemsFrame->setX($menuWidth * -0.5 + $menuListWidth * 0.5);
$itemsBackgroundQuad = new Quad(); $itemsBackgroundQuad = new Quad();
$menuItemsFrame->add($itemsBackgroundQuad); $menuItemsFrame->add($itemsBackgroundQuad);
$itemsBackgroundQuad->setSize($menuListWidth, $menuHeight); $itemsBackgroundQuad->setSize($menuListWidth, $menuHeight);
$itemsBackgroundQuad->setStyles($quadStyle, $quadSubstyle); $itemsBackgroundQuad->setStyles($quadStyle, $quadSubstyle);
$menusFrame = new Frame(); $menusFrame = new Frame();
$frame->add($menusFrame); $frame->add($menusFrame);
$menusFrame->setX($menuWidth * -0.5 + $menuListWidth + $subMenuWidth * 0.5); $menusFrame->setX($menuWidth * -0.5 + $menuListWidth + $subMenuWidth * 0.5);
// Create script and features // Create script and features
$script = new Script(); $script = new Script();
$manialink->setScript($script); $manialink->setScript($script);
$menuRelationships = array(); $menuRelationships = array();
$menuItemY = $menuHeight * 0.42; $menuItemY = $menuHeight * 0.42;
foreach ($this->menus as $index => $menu) { foreach($this->menus as $index => $menu) {
// Add title // Add title
$menuItemLabel = new Label(); $menuItemLabel = new Label();
$menuItemsFrame->add($menuItemLabel); $menuItemsFrame->add($menuItemLabel);
@ -255,18 +260,18 @@ class Configurator implements CallbackListener, CommandListener, ManialinkPageAn
$menuItemLabel->setSize($menuListWidth * 0.9, $menuItemHeight * 0.9); $menuItemLabel->setSize($menuListWidth * 0.9, $menuItemHeight * 0.9);
$menuItemLabel->setStyle(Label_Text::STYLE_TextCardRaceRank); $menuItemLabel->setStyle(Label_Text::STYLE_TextCardRaceRank);
$menuItemLabel->setText('$z' . $menu->getTitle() . '$z'); $menuItemLabel->setText('$z' . $menu->getTitle() . '$z');
// Add menu // Add menu
$menuControl = $menu->getMenu($subMenuWidth, $subMenuHeight, $script); $menuControl = $menu->getMenu($subMenuWidth, $subMenuHeight, $script);
if ($index > 0) { if($index > 0) {
$menuControl->setVisible(false); $menuControl->setVisible(false);
} }
$menusFrame->add($menuControl); $menusFrame->add($menuControl);
$script->addMenu($menuItemLabel, $menuControl); $script->addMenu($menuItemLabel, $menuControl);
$menuItemY -= $menuItemHeight * 1.1; $menuItemY -= $menuItemHeight * 1.1;
} }
// Add Close Quad (X) // Add Close Quad (X)
$closeQuad = new Quad_Icons64x64_1(); $closeQuad = new Quad_Icons64x64_1();
$frame->add($closeQuad); $frame->add($closeQuad);
@ -274,7 +279,7 @@ class Configurator implements CallbackListener, CommandListener, ManialinkPageAn
$closeQuad->setSize(6, 6); $closeQuad->setSize(6, 6);
$closeQuad->setSubStyle(Quad_Icons64x64_1::SUBSTYLE_QuitRace); $closeQuad->setSubStyle(Quad_Icons64x64_1::SUBSTYLE_QuitRace);
$closeQuad->setAction(self::ACTION_TOGGLEMENU); $closeQuad->setAction(self::ACTION_TOGGLEMENU);
// Add close button // Add close button
$closeButton = new Label(); $closeButton = new Label();
$frame->add($closeButton); $frame->add($closeButton);
@ -285,7 +290,7 @@ class Configurator implements CallbackListener, CommandListener, ManialinkPageAn
$closeButton->setTranslate(true); $closeButton->setTranslate(true);
$closeButton->setText('$zClose$z'); $closeButton->setText('$zClose$z');
$closeButton->setAction(self::ACTION_TOGGLEMENU); $closeButton->setAction(self::ACTION_TOGGLEMENU);
// Add save button // Add save button
$saveButton = new Label(); $saveButton = new Label();
$frame->add($saveButton); $frame->add($saveButton);
@ -296,7 +301,7 @@ class Configurator implements CallbackListener, CommandListener, ManialinkPageAn
$saveButton->setTranslate(true); $saveButton->setTranslate(true);
$saveButton->setText('$zSave$z'); $saveButton->setText('$zSave$z');
$saveButton->setAction(self::ACTION_SAVECONFIG); $saveButton->setAction(self::ACTION_SAVECONFIG);
return $manialinks; return $manialinks;
} }

View File

@ -0,0 +1,66 @@
<?php
/**
* Class offering a Configurator for Script Settings
*
* @author steeffeen & kremsy
*/
namespace ManiaControl\Configurators;
use FML\Script\Script;
use ManiaControl\ManiaControl;
use ManiaControl\Players\Player;
class ManiaControlSettings implements ConfiguratorMenu{
/**
* Constants
*/
const TITLE = 'ManiaControl Settings';
/**
* Private Properties
*/
private $maniaControl = null;
/**
* Create a new Script Settings Instance
*
* @param ManiaControl $maniaControl
*/
public function __construct(ManiaControl $maniaControl) {
$this->maniaControl = $maniaControl;
}
/**
* Get the Menu Title
*
* @return string
*/
public function getTitle() {
self::TITLE;
}
/**
* Get the Configurator Menu Frame
*
* @param float $width
* @param float $height
* @param Script $script
* @return \FML\Controls\Frame
*/
public function getMenu($width, $height, Script $script) {
var_dump($this->maniaControl->settingManager->getSettings());
// TODO: Implement getMenu() method.
}
/**
* Save the Config Data
*
* @param array $configData
* @param Player $player
*/
public function saveConfigData(array $configData, Player $player) {
// TODO: Implement saveConfigData() method.
}
}

View File

@ -5,6 +5,8 @@ namespace ManiaControl\Maps;
use FML\Controls\Quad; use FML\Controls\Quad;
use FML\Controls\Quads\Quad_Icons64x64_1; use FML\Controls\Quads\Quad_Icons64x64_1;
use FML\Controls\Quads\Quad_UIConstruction_Buttons; use FML\Controls\Quads\Quad_UIConstruction_Buttons;
use FML\ManiaLink;
use FML\Script\EUISound;
use ManiaControl\Admin\AuthenticationManager; use ManiaControl\Admin\AuthenticationManager;
use ManiaControl\Callbacks\CallbackListener; use ManiaControl\Callbacks\CallbackListener;
use ManiaControl\Callbacks\CallbackManager; use ManiaControl\Callbacks\CallbackManager;
@ -73,13 +75,13 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener, Callb
$itemQuad->setImageFocus($this->maniaControl->manialinkManager->iconManager->getIcon(IconManager::MX_ICON_MOVER)); $itemQuad->setImageFocus($this->maniaControl->manialinkManager->iconManager->getIcon(IconManager::MX_ICON_MOVER));
$itemQuad->setAction(self::ACTION_OPEN_XLIST); $itemQuad->setAction(self::ACTION_OPEN_XLIST);
$this->maniaControl->actionsMenu->addPlayerMenuItem($itemQuad, 5, 'Open MX List'); $this->maniaControl->actionsMenu->addPlayerMenuItem($itemQuad, 5, 'Open MX List');
// Menu Open List // Menu Open List
$itemQuad = new Quad_Icons64x64_1(); $itemQuad = new Quad_Icons64x64_1();
$itemQuad->setSubStyle($itemQuad::SUBSTYLE_ToolRoot); $itemQuad->setSubStyle($itemQuad::SUBSTYLE_ToolRoot);
$itemQuad->setAction(self::ACTION_OPEN_MAPLIST); $itemQuad->setAction(self::ACTION_OPEN_MAPLIST);
$this->maniaControl->actionsMenu->addPlayerMenuItem($itemQuad, 10, 'Open MapList'); $this->maniaControl->actionsMenu->addPlayerMenuItem($itemQuad, 10, 'Open MapList');
// Menu RestartMap // Menu RestartMap
$itemQuad = new Quad_UIConstruction_Buttons(); $itemQuad = new Quad_UIConstruction_Buttons();
$itemQuad->setSubStyle($itemQuad::SUBSTYLE_Reload); $itemQuad->setSubStyle($itemQuad::SUBSTYLE_Reload);

View File

@ -417,7 +417,6 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$switchToQuad->setText("»"); $switchToQuad->setText("»");
$switchToQuad->setTextColor("0F0"); $switchToQuad->setTextColor("0F0");
//$switchToQuad->setAction(self::ACTION_CONFIRM_SWITCHTO_MAP . "." . ($id));
$confirmFrame = $this->buildConfirmFrame($maniaLink, $y, $id); $confirmFrame = $this->buildConfirmFrame($maniaLink, $y, $id);
$script->addToggle($switchToQuad, $confirmFrame); $script->addToggle($switchToQuad, $confirmFrame);