Improved Script Settings and Configurator Menu
This commit is contained in:
parent
5fb76e2428
commit
98f70cb70b
@ -79,7 +79,7 @@ class Configurator implements CallbackListener, CommandListener, ManialinkPageAn
|
|||||||
// Register for callbacks
|
// Register for callbacks
|
||||||
$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');
|
$this->maniaControl->callbackManager->registerCallbackListener(ScriptSettings::CB_SCRIPTSETTING_CHANGED, $this, 'reopenMenu');
|
||||||
|
|
||||||
// Create script settings
|
// Create script settings
|
||||||
$this->scriptSettings = new ScriptSettings($maniaControl);
|
$this->scriptSettings = new ScriptSettings($maniaControl);
|
||||||
@ -242,14 +242,6 @@ class Configurator implements CallbackListener, CommandListener, ManialinkPageAn
|
|||||||
$script = new Script();
|
$script = new Script();
|
||||||
$manialink->setScript($script);
|
$manialink->setScript($script);
|
||||||
|
|
||||||
$pages = null;
|
|
||||||
/*
|
|
||||||
* $pages = new Pages(); $script->addFeature($pages); $tooltips = new Tooltips(); $script->addFeature($tooltips); $menus = new
|
|
||||||
* Menus(); $script->addFeature($menus);
|
|
||||||
*/
|
|
||||||
|
|
||||||
// $script->addPager()
|
|
||||||
|
|
||||||
$menuRelationships = array();
|
$menuRelationships = array();
|
||||||
$menuItemY = $menuHeight * 0.42;
|
$menuItemY = $menuHeight * 0.42;
|
||||||
foreach ($this->menus as $index => $menu) {
|
foreach ($this->menus as $index => $menu) {
|
||||||
@ -262,20 +254,16 @@ class Configurator implements CallbackListener, CommandListener, ManialinkPageAn
|
|||||||
// $menuItemLabel->setText('$z' . $menu->getTitle() . '$z');
|
// $menuItemLabel->setText('$z' . $menu->getTitle() . '$z');
|
||||||
|
|
||||||
// Add menu
|
// Add menu
|
||||||
$menuControl = $menu->getMenu($subMenuWidth, $subMenuHeight, $pages, $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);
|
||||||
|
|
||||||
// Add menu relationship
|
|
||||||
// array_push($menuRelationships, array($menuItemLabel, $menuControl));
|
|
||||||
$script->addMenu($menuItemLabel, $menuControl);
|
$script->addMenu($menuItemLabel, $menuControl);
|
||||||
|
|
||||||
$menuItemY -= $menuItemHeight * 1.1;
|
$menuItemY -= $menuItemHeight * 1.1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// $menus->add($menuRelationships);
|
|
||||||
|
|
||||||
// Add Close Quad (X)
|
// Add Close Quad (X)
|
||||||
$closeQuad = new Quad_Icons64x64_1();
|
$closeQuad = new Quad_Icons64x64_1();
|
||||||
$frame->add($closeQuad);
|
$frame->add($closeQuad);
|
||||||
|
@ -8,33 +8,31 @@ use FML\Script\Tooltips;
|
|||||||
use ManiaControl\Players\Player;
|
use ManiaControl\Players\Player;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Interface for configurator menus
|
* Interface for Configurator Menus
|
||||||
*
|
*
|
||||||
* @author steeffeen & kremsy
|
* @author steeffeen & kremsy
|
||||||
*/
|
*/
|
||||||
interface ConfiguratorMenu {
|
interface ConfiguratorMenu {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the menu title
|
* Get the Menu Title
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getTitle();
|
public function getTitle();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the configurator menu
|
* Get the Configurator Menu Frame
|
||||||
*
|
*
|
||||||
* @param float $width
|
* @param float $width
|
||||||
* @param float $height
|
* @param float $height
|
||||||
* @param $pages temp removed
|
* @param Script $script
|
||||||
* @param \FML\Script\Script $script
|
* @return \FML\Controls\Frame
|
||||||
* @internal param \FML\Script\Tooltips $tooltips
|
|
||||||
* @return \FML\Controls\Control
|
|
||||||
*/
|
*/
|
||||||
public function getMenu($width, $height, $pages, Script $script);
|
public function getMenu($width, $height, Script $script);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Save the config data
|
* Save the Config Data
|
||||||
*
|
*
|
||||||
* @param array $configData
|
* @param array $configData
|
||||||
* @param Player $player
|
* @param Player $player
|
||||||
|
@ -18,7 +18,7 @@ use FML\Controls\Entry;
|
|||||||
use ManiaControl\Players\Player;
|
use ManiaControl\Players\Player;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class offering a configurator for current script settings
|
* Class offering a Configurator for Script Settings
|
||||||
*
|
*
|
||||||
* @author steeffeen & kremsy
|
* @author steeffeen & kremsy
|
||||||
*/
|
*/
|
||||||
@ -27,16 +27,16 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener {
|
|||||||
* Constants
|
* Constants
|
||||||
*/
|
*/
|
||||||
const ACTION_PREFIX_SETTING = 'ScriptSetting.';
|
const ACTION_PREFIX_SETTING = 'ScriptSetting.';
|
||||||
const ACTION_SETTING_BOOL = 'ScriptSetting.ActionBoolSetting';
|
const ACTION_SETTING_BOOL = 'ScriptSetting.ActionBoolSetting.';
|
||||||
const CB_SCRIPTSETTINGS_CHANGED = 'ScriptSettings.SettingsChanged';
|
const CB_SCRIPTSETTING_CHANGED = 'ScriptSettings.SettingChanged';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Private properties
|
* Private Properties
|
||||||
*/
|
*/
|
||||||
private $maniaControl = null;
|
private $maniaControl = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new script settings instance
|
* Create a new Script Settings Instance
|
||||||
*
|
*
|
||||||
* @param ManiaControl $maniaControl
|
* @param ManiaControl $maniaControl
|
||||||
*/
|
*/
|
||||||
@ -60,7 +60,7 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener {
|
|||||||
*
|
*
|
||||||
* @see \ManiaControl\Configurators\ConfiguratorMenu::getMenu()
|
* @see \ManiaControl\Configurators\ConfiguratorMenu::getMenu()
|
||||||
*/
|
*/
|
||||||
public function getMenu($width, $height, $pages, Script $script) {
|
public function getMenu($width, $height, Script $script) {
|
||||||
$frame = new Frame();
|
$frame = new Frame();
|
||||||
|
|
||||||
$this->maniaControl->client->query('GetModeScriptInfo');
|
$this->maniaControl->client->query('GetModeScriptInfo');
|
||||||
@ -158,7 +158,7 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener {
|
|||||||
$quad->setSubStyle($substyle);
|
$quad->setSubStyle($substyle);
|
||||||
$quad->setSize(4, 4);
|
$quad->setSize(4, 4);
|
||||||
$quad->setHAlign(Control::CENTER);
|
$quad->setHAlign(Control::CENTER);
|
||||||
$quad->setAction(self::ACTION_SETTING_BOOL . "." . $settingName);
|
$quad->setAction(self::ACTION_SETTING_BOOL . $settingName);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$entry = new Entry();
|
$entry = new Entry();
|
||||||
@ -185,7 +185,6 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener {
|
|||||||
|
|
||||||
$y -= $settingHeight;
|
$y -= $settingHeight;
|
||||||
if ($index % $pageMaxCount == $pageMaxCount - 1) {
|
if ($index % $pageMaxCount == $pageMaxCount - 1) {
|
||||||
$script->addPage($pageFrame, $index, "test"); // TODO not working
|
|
||||||
unset($pageFrame);
|
unset($pageFrame);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -200,107 +199,111 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener {
|
|||||||
public function saveConfigData(array $configData, Player $player) {
|
public function saveConfigData(array $configData, Player $player) {
|
||||||
$this->maniaControl->client->query('GetModeScriptSettings');
|
$this->maniaControl->client->query('GetModeScriptSettings');
|
||||||
$scriptSettings = $this->maniaControl->client->getResponse();
|
$scriptSettings = $this->maniaControl->client->getResponse();
|
||||||
|
|
||||||
$prefixLength = strlen(self::ACTION_PREFIX_SETTING);
|
$prefixLength = strlen(self::ACTION_PREFIX_SETTING);
|
||||||
|
|
||||||
$chatMessage = '';
|
|
||||||
$newSettings = array();
|
$newSettings = array();
|
||||||
foreach ($configData[3] as $setting) {
|
foreach ($configData[3] as $setting) {
|
||||||
if (substr($setting['Name'], 0, $prefixLength) != self::ACTION_PREFIX_SETTING) continue;
|
if (substr($setting['Name'], 0, $prefixLength) != self::ACTION_PREFIX_SETTING) continue;
|
||||||
|
|
||||||
$settingName = substr($setting['Name'], $prefixLength);
|
$settingName = substr($setting['Name'], $prefixLength);
|
||||||
|
if (!isset($scriptSettings[$settingName])) {
|
||||||
foreach ($scriptSettings as $key => $value) {
|
var_dump('no setting ' . $settingName);
|
||||||
if ($key == $settingName) {
|
continue;
|
||||||
// Check if something has been changed
|
|
||||||
if ($setting["Value"] != $value) {
|
|
||||||
$chatMessage .= '$FFF' . $settingName . '$z$s$FF0 to $FFF' . $setting["Value"] . ', ';
|
|
||||||
}
|
|
||||||
// Setting found, cast type, break the inner loop
|
|
||||||
settype($setting["Value"], gettype($value));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$newSettings[$settingName] = $setting["Value"];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Nothing has been changed
|
if ($setting['Value'] == $scriptSettings[$settingName]) {
|
||||||
if ($chatMessage = '') {
|
// Not changed
|
||||||
return;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$success = $this->maniaControl->client->query('SetModeScriptSettings', $newSettings);
|
$newSettings[$settingName] = $setting['Value'];
|
||||||
if (!$success) {
|
settype($newSettings[$settingName], gettype($scriptSettings[$settingName]));
|
||||||
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $player->login);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$chatMessage = substr($chatMessage, 0, strlen($chatMessage) - 2);
|
$this->applyNewScriptSettings($newSettings, $player);
|
||||||
$chatMessage = str_replace("S_", "", $chatMessage);
|
|
||||||
|
|
||||||
$title = $this->maniaControl->authenticationManager->getAuthLevelName($player->authLevel);
|
|
||||||
|
|
||||||
$this->maniaControl->chat->sendInformation(
|
|
||||||
'$ff0' . $title . ' $<' . $player->nickname . '$> set Scriptsettings $<' . $chatMessage . '$>!');
|
|
||||||
|
|
||||||
// log console message
|
|
||||||
$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
|
* Handle ManialinkPageAnswer Callback
|
||||||
*
|
*
|
||||||
* @param array $callback
|
* @param array $callback
|
||||||
*/
|
*/
|
||||||
public function handleManialinkPageAnswer(array $callback) {
|
public function handleManialinkPageAnswer(array $callback) {
|
||||||
$actionId = $callback[1][2];
|
$actionId = $callback[1][2];
|
||||||
$boolSetting = (strpos($actionId, self::ACTION_SETTING_BOOL) === 0);
|
$boolSetting = (strpos($actionId, self::ACTION_SETTING_BOOL) === 0);
|
||||||
|
|
||||||
if (!$boolSetting) return;
|
if (!$boolSetting) return;
|
||||||
|
|
||||||
$actionArray = explode(".", $actionId);
|
$actionArray = explode(".", $actionId);
|
||||||
|
$setting = $actionArray[2];
|
||||||
|
|
||||||
$player = $this->maniaControl->playerManager->getPlayer($callback[1][1]);
|
$login = $callback[1][1];
|
||||||
$this->setCheckboxSetting($player, $actionArray[2]);
|
$player = $this->maniaControl->playerManager->getPlayer($login);
|
||||||
|
|
||||||
|
$this->toggleBooleanSetting($setting, $player);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Toogle a boolean value setting
|
* Toogle a Boolean Setting
|
||||||
*
|
*
|
||||||
* @param Player $player
|
* @param Player $player
|
||||||
* @param $setting
|
* @param $setting
|
||||||
*/
|
*/
|
||||||
public function setCheckboxSetting(Player $player, $setting) {
|
public function toggleBooleanSetting($setting, Player $player) {
|
||||||
$this->maniaControl->client->query('GetModeScriptSettings');
|
$this->maniaControl->client->query('GetModeScriptSettings');
|
||||||
$scriptSettings = $this->maniaControl->client->getResponse();
|
$scriptSettings = $this->maniaControl->client->getResponse();
|
||||||
|
|
||||||
$newSetting = array();
|
if (!isset($scriptSettings[$setting])) {
|
||||||
foreach ($scriptSettings as $key => $value) {
|
var_dump('no setting ' . $setting);
|
||||||
if ($key == $setting) { // Setting found
|
return;
|
||||||
$newSetting[$key] = $value == true ? false : true; // toggle setting
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$success = $this->maniaControl->client->query('SetModeScriptSettings', $newSetting);
|
$newSettings = array();
|
||||||
|
$newSettings[$setting] = ($scriptSettings[$setting] ? false : true);
|
||||||
|
|
||||||
|
$this->applyNewScriptSettings($newSettings, $player);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Apply the Array of new Script Settings
|
||||||
|
*
|
||||||
|
* @param array $newSettings
|
||||||
|
* @param Player $player
|
||||||
|
*/
|
||||||
|
private function applyNewScriptSettings(array $newSettings, Player $player) {
|
||||||
|
if (!$newSettings) return;
|
||||||
|
$success = $this->maniaControl->client->query('SetModeScriptSettings', $newSettings);
|
||||||
if (!$success) {
|
if (!$success) {
|
||||||
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $player->login);
|
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $player->login);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$valString = ($newSetting[$setting]) ? 'true' : 'false';
|
// Notifications
|
||||||
$chatMessage = '$FFF' . preg_replace('/^S_/', '', $setting) . '$z$s$FF0 to $FFF' . $valString;
|
foreach ($newSettings as $setting => $value) {
|
||||||
|
|
||||||
$title = $this->maniaControl->authenticationManager->getAuthLevelName($player->authLevel);
|
$title = $this->maniaControl->authenticationManager->getAuthLevelName($player->authLevel);
|
||||||
$this->maniaControl->chat->sendInformation(
|
$chatMessage = '$ff0' . $title . ' $<' . $player->nickname . '$> set ScriptSetting ';
|
||||||
'$ff0' . $title . ' $<' . $player->nickname . '$> set ScriptSetting $<' . $chatMessage . '$>!');
|
$chatMessage .= '$<' . '$fff' . preg_replace('/^S_/', '', $setting) . '$z$s$ff0 to $fff' . $this->parseSettingValue($value) .
|
||||||
|
'$>!';
|
||||||
|
|
||||||
// log console message
|
$this->maniaControl->chat->sendInformation($chatMessage);
|
||||||
$this->maniaControl->log(Formatter::stripCodes($title . ' ' . $player->nickname . ' set Scriptsetting ' . $chatMessage . '!'));
|
$this->maniaControl->log(Formatter::stripCodes($chatMessage));
|
||||||
|
|
||||||
// Trigger own callback
|
// Trigger own callback
|
||||||
$this->maniaControl->callbackManager->triggerCallback(self::CB_SCRIPTSETTINGS_CHANGED, array(self::CB_SCRIPTSETTINGS_CHANGED));
|
$this->maniaControl->callbackManager->triggerCallback(self::CB_SCRIPTSETTING_CHANGED,
|
||||||
|
array(self::CB_SCRIPTSETTING_CHANGED, $setting, $value));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse the Setting Value to a String Representation
|
||||||
|
*
|
||||||
|
* @param mixed $value
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
private function parseSettingValue($value) {
|
||||||
|
if (is_bool($value)) {
|
||||||
|
return ($value ? 'True' : 'False');
|
||||||
|
}
|
||||||
|
return (string) $value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -58,7 +58,7 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu {
|
|||||||
*
|
*
|
||||||
* @see \ManiaControl\Configurators\ConfiguratorMenu::getMenu()
|
* @see \ManiaControl\Configurators\ConfiguratorMenu::getMenu()
|
||||||
*/
|
*/
|
||||||
public function getMenu($width, $height, $pages, Script $script) {
|
public function getMenu($width, $height, Script $script) {
|
||||||
$frame = new Frame();
|
$frame = new Frame();
|
||||||
|
|
||||||
$pluginClasses = $this->maniaControl->pluginManager->getPluginClasses();
|
$pluginClasses = $this->maniaControl->pluginManager->getPluginClasses();
|
||||||
@ -165,7 +165,7 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu {
|
|||||||
|
|
||||||
// $script->addPager($pageFrames, 1 , $pageCountLabel);
|
// $script->addPager($pageFrames, 1 , $pageCountLabel);
|
||||||
// $script->addPage(array(-1 => $pagerPrev, 1 => $pagerNext), $pageFrames, $pageCountLabel);
|
// $script->addPage(array(-1 => $pagerPrev, 1 => $pagerNext), $pageFrames, $pageCountLabel);
|
||||||
//$pages->add(array(-1 => $pagerPrev, 1 => $pagerNext), $pageFrames, $pageCountLabel);
|
// $pages->add(array(-1 => $pagerPrev, 1 => $pagerNext), $pageFrames, $pageCountLabel);
|
||||||
|
|
||||||
return $frame;
|
return $frame;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user