finished scriptsettings

This commit is contained in:
kremsy 2013-12-30 20:12:53 +01:00
parent a5d219a566
commit 6d41ef72c0
2 changed files with 114 additions and 16 deletions

View File

@ -72,6 +72,7 @@ class Configurator implements CallbackListener, ManialinkPageAnswerListener {
// Register for page answers // Register for page answers
$this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_TOGGLEMENU, $this, $this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_TOGGLEMENU, $this,
'handleToggleMenuAction'); 'handleToggleMenuAction');
$this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_SAVECONFIG, $this, $this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_SAVECONFIG, $this,
'handleSaveConfigAction'); 'handleSaveConfigAction');
@ -79,6 +80,8 @@ class Configurator implements CallbackListener, ManialinkPageAnswerListener {
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERDISCONNECT, $this, $this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERDISCONNECT, $this,
'handlePlayerDisconnect'); 'handlePlayerDisconnect');
$this->maniaControl->callbackManager->registerCallbackListener(ScriptSettings::CB_SCRIPTSETTINGS_CHANGED, $this, 'reopenMenu');
// Create script settings // Create script settings
$this->scriptSettings = new ScriptSettings($maniaControl); $this->scriptSettings = new ScriptSettings($maniaControl);
$this->addMenu($this->scriptSettings); $this->addMenu($this->scriptSettings);
@ -93,6 +96,18 @@ class Configurator implements CallbackListener, ManialinkPageAnswerListener {
array_push($this->menus, $menu); array_push($this->menus, $menu);
} }
/**
* Reopens the Menu
* @param array $callback
*/
public function reopenMenu(array $callback){
foreach($this->playersMenuShown as $login => $shown){
if($shown == true){
$player = $this->maniaControl->playerManager->getPlayer($login);
$this->showMenu($player);
}
}
}
/** /**
* Handle toggle menu action * Handle toggle menu action
* *

View File

@ -2,6 +2,8 @@
namespace ManiaControl\Configurators; namespace ManiaControl\Configurators;
use ManiaControl\Callbacks\CallbackListener;
use ManiaControl\Callbacks\CallbackManager;
use ManiaControl\Formatter; use ManiaControl\Formatter;
use ManiaControl\ManiaControl; use ManiaControl\ManiaControl;
use FML\Controls\Frame; use FML\Controls\Frame;
@ -19,12 +21,14 @@ use ManiaControl\Players\Player;
* *
* @author steeffeen & kremsy * @author steeffeen & kremsy
*/ */
// TODO: boolean script settings not as entries class ScriptSettings implements ConfiguratorMenu,CallbackListener {
class ScriptSettings implements ConfiguratorMenu {
/** /**
* Constants * Constants
*/ */
const ACTION_PREFIX_SETTING = 'ScriptSetting.'; const ACTION_PREFIX_SETTING = 'ScriptSetting.';
const ACTION_SETTING_BOOL = 'ScriptSetting.ActionBoolSetting';
const CB_SCRIPTSETTINGS_CHANGED = 'ScriptSettings.SettingsChanged';
/** /**
* Private properties * Private properties
@ -38,6 +42,8 @@ class ScriptSettings implements ConfiguratorMenu {
*/ */
public function __construct(ManiaControl $maniaControl) { public function __construct(ManiaControl $maniaControl) {
$this->maniaControl = $maniaControl; $this->maniaControl = $maniaControl;
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer');
} }
/** /**
@ -100,6 +106,7 @@ class ScriptSettings implements ConfiguratorMenu {
$y = 0.; $y = 0.;
foreach ($scriptParams as $index => $scriptParam) { foreach ($scriptParams as $index => $scriptParam) {
$settingName = $scriptParam['Name']; $settingName = $scriptParam['Name'];
if (!isset($scriptSettings[$settingName])) continue; if (!isset($scriptSettings[$settingName])) continue;
if (!isset($pageFrame)) { if (!isset($pageFrame)) {
@ -109,6 +116,7 @@ class ScriptSettings implements ConfiguratorMenu {
$y = $height * 0.41; $y = $height * 0.41;
} }
$settingFrame = new Frame(); $settingFrame = new Frame();
$pageFrame->add($settingFrame); $pageFrame->add($settingFrame);
$settingFrame->setY($y); $settingFrame->setY($y);
@ -122,17 +130,38 @@ class ScriptSettings implements ConfiguratorMenu {
$nameLabel->setTextSize($labelTextSize); $nameLabel->setTextSize($labelTextSize);
$nameLabel->setText($settingName); $nameLabel->setText($settingName);
$settingValue = $scriptSettings[$settingName];
$substyle = '';
$action = '';
if($settingValue === false){
$substyle = Quad_Icons64x64_1::SUBSTYLE_LvlRed;
}else if($settingValue === true){
$substyle = Quad_Icons64x64_1::SUBSTYLE_LvlGreen;
}
if($substyle != ''){
$quad = new Quad_Icons64x64_1();
$settingFrame->add($quad);
$quad->setX($width / 2 * 0.545);
$quad->setZ(-0.01);
$quad->setSubStyle($substyle);
$quad->setSize(4, 4);
$quad->setHAlign(Control::CENTER);
$quad->setAction(self::ACTION_SETTING_BOOL . "." . $settingName);
}else{
$entry = new Entry(); $entry = new Entry();
$settingFrame->add($entry); $settingFrame->add($entry);
$entry->setHAlign(Control::RIGHT); $entry->setStyle(Label_Text::STYLE_TextValueSmall);
$entry->setX($width * 0.44); $entry->setHAlign(Control::CENTER);
$entry->setSize($width * 0.4, $settingHeight); $entry->setX($width /2 * 0.55);
$entry->setTextSize(1);
$entry->setSize($width * 0.3, $settingHeight * 0.9);
$entry->setName(self::ACTION_PREFIX_SETTING . $settingName); $entry->setName(self::ACTION_PREFIX_SETTING . $settingName);
$settingValue = $scriptSettings[$settingName];
if ($settingValue === false) {
$settingValue = 0;
}
$entry->setDefault($settingValue); $entry->setDefault($settingValue);
}
$descriptionLabel = new Label(); $descriptionLabel = new Label();
$pageFrame->add($descriptionLabel); $pageFrame->add($descriptionLabel);
@ -203,5 +232,59 @@ class ScriptSettings implements ConfiguratorMenu {
// log console message // log console message
$this->maniaControl->log(Formatter::stripCodes($title . ' ' . $player->nickname . ' set Scriptsettings ' . $chatMessage . '!')); $this->maniaControl->log(Formatter::stripCodes($title . ' ' . $player->nickname . ' set Scriptsettings ' . $chatMessage . '!'));
// Trigger own callback
$this->maniaControl->callbackManager->triggerCallback(self::CB_SCRIPTSETTINGS_CHANGED, array(self::CB_SCRIPTSETTINGS_CHANGED));
}
/**
* Called on ManialinkPageAnswer
* @param array $callback
*/
public function handleManialinkPageAnswer(array $callback){
$actionId = $callback[1][2];
$boolSetting = (strpos($actionId, self::ACTION_SETTING_BOOL) === 0);
if(!$boolSetting)
return;
$actionArray = explode(".", $actionId);
$player = $this->maniaControl->playerManager->getPlayer($callback[1][1]);
$this->setCheckboxSetting($player, $actionArray[2]);
}
/**
* Toogle a boolean value setting
* @param Player $player
* @param $setting
*/
public function setCheckboxSetting(Player $player, $setting){
$this->maniaControl->client->query('GetModeScriptSettings');
$scriptSettings = $this->maniaControl->client->getResponse();
$newSetting = array();
foreach($scriptSettings as $key => $value){
if($key == $setting){ //Setting found
$newSetting[$key] = $value == true ? false : true; //toggle setting
break;
}
}
$success = $this->maniaControl->client->query('SetModeScriptSettings', $newSetting);
if (!$success) {
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $player->login);
return;
}
$valString = ($newSetting[$setting]) ? 'true' : 'false';
$chatMessage = '$FFF'.$setting.'$z$s$FF0 to $FFF' . $valString;
$chatMessage = str_replace("S_","",$chatMessage);
$title = $this->maniaControl->authenticationManager->getAuthLevelName($player->authLevel);
$this->maniaControl->chat->sendInformation('$ff0' . $title . ' $<' . $player->nickname . '$> set Scriptsetting $<' . $chatMessage . '$>!');
// Trigger own callback
$this->maniaControl->callbackManager->triggerCallback(self::CB_SCRIPTSETTINGS_CHANGED, array(self::CB_SCRIPTSETTINGS_CHANGED));
} }
} }