script settings fixed for fml update
This commit is contained in:
parent
5a5c422703
commit
c69a00aa43
application/core
@ -22,15 +22,14 @@ use ManiaControl\Players\Player;
|
|||||||
*
|
*
|
||||||
* @author steeffeen & kremsy
|
* @author steeffeen & kremsy
|
||||||
*/
|
*/
|
||||||
class ScriptSettings implements ConfiguratorMenu,CallbackListener {
|
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_SCRIPTSETTINGS_CHANGED = 'ScriptSettings.SettingsChanged';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Private properties
|
* Private properties
|
||||||
*/
|
*/
|
||||||
@ -39,12 +38,14 @@ class ScriptSettings implements ConfiguratorMenu,CallbackListener {
|
|||||||
/**
|
/**
|
||||||
* Create a new script settings instance
|
* Create a new script settings instance
|
||||||
*
|
*
|
||||||
* @param ManiaControl $maniaControl
|
* @param ManiaControl $maniaControl
|
||||||
*/
|
*/
|
||||||
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');
|
// Register for callbacks
|
||||||
|
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this,
|
||||||
|
'handleManialinkPageAnswer');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -94,10 +95,10 @@ class ScriptSettings implements ConfiguratorMenu,CallbackListener {
|
|||||||
$pagerNext->setPosition($width * 0.45, $height * -0.44, 2);
|
$pagerNext->setPosition($width * 0.45, $height * -0.44, 2);
|
||||||
$pagerNext->setSize($pagerSize, $pagerSize);
|
$pagerNext->setSize($pagerSize, $pagerSize);
|
||||||
$pagerNext->setSubStyle(Quad_Icons64x64_1::SUBSTYLE_ArrowNext);
|
$pagerNext->setSubStyle(Quad_Icons64x64_1::SUBSTYLE_ArrowNext);
|
||||||
|
|
||||||
$script->addPager($pagerPrev, -1);
|
$script->addPager($pagerPrev, -1);
|
||||||
$script->addPager($pagerNext, 1);
|
$script->addPager($pagerNext, 1);
|
||||||
|
|
||||||
$pageCountLabel = new Label();
|
$pageCountLabel = new Label();
|
||||||
$frame->add($pageCountLabel);
|
$frame->add($pageCountLabel);
|
||||||
$pageCountLabel->setHAlign(Control::RIGHT);
|
$pageCountLabel->setHAlign(Control::RIGHT);
|
||||||
@ -105,22 +106,27 @@ class ScriptSettings implements ConfiguratorMenu,CallbackListener {
|
|||||||
$pageCountLabel->setStyle('TextTitle1');
|
$pageCountLabel->setStyle('TextTitle1');
|
||||||
$pageCountLabel->setTextSize(2);
|
$pageCountLabel->setTextSize(2);
|
||||||
|
|
||||||
|
$script->addPageLabel($pageCountLabel);
|
||||||
|
|
||||||
// Setting pages
|
// Setting pages
|
||||||
$pageFrames = array();
|
$pageFrames = array();
|
||||||
$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)) {
|
||||||
$pageFrame = new Frame();
|
$pageFrame = new Frame();
|
||||||
$frame->add($pageFrame);
|
$frame->add($pageFrame);
|
||||||
|
if (!empty($pageFrames)) {
|
||||||
|
$pageFrame->setVisible(false);
|
||||||
|
}
|
||||||
array_push($pageFrames, $pageFrame);
|
array_push($pageFrames, $pageFrame);
|
||||||
$y = $height * 0.41;
|
$y = $height * 0.41;
|
||||||
|
$script->addPage($pageFrame, count($pageFrames));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$settingFrame = new Frame();
|
$settingFrame = new Frame();
|
||||||
$pageFrame->add($settingFrame);
|
$pageFrame->add($settingFrame);
|
||||||
$settingFrame->setY($y);
|
$settingFrame->setY($y);
|
||||||
@ -133,18 +139,18 @@ class ScriptSettings implements ConfiguratorMenu,CallbackListener {
|
|||||||
$nameLabel->setStyle($nameLabel::STYLE_TextCardSmall);
|
$nameLabel->setStyle($nameLabel::STYLE_TextCardSmall);
|
||||||
$nameLabel->setTextSize($labelTextSize);
|
$nameLabel->setTextSize($labelTextSize);
|
||||||
$nameLabel->setText($settingName);
|
$nameLabel->setText($settingName);
|
||||||
|
|
||||||
|
|
||||||
$settingValue = $scriptSettings[$settingName];
|
$settingValue = $scriptSettings[$settingName];
|
||||||
|
|
||||||
$substyle = '';
|
$substyle = '';
|
||||||
if($settingValue === false){
|
if ($settingValue === false) {
|
||||||
$substyle = Quad_Icons64x64_1::SUBSTYLE_LvlRed;
|
$substyle = Quad_Icons64x64_1::SUBSTYLE_LvlRed;
|
||||||
}else if($settingValue === true){
|
}
|
||||||
|
else if ($settingValue === true) {
|
||||||
$substyle = Quad_Icons64x64_1::SUBSTYLE_LvlGreen;
|
$substyle = Quad_Icons64x64_1::SUBSTYLE_LvlGreen;
|
||||||
}
|
}
|
||||||
|
|
||||||
if($substyle != ''){
|
if ($substyle != '') {
|
||||||
$quad = new Quad_Icons64x64_1();
|
$quad = new Quad_Icons64x64_1();
|
||||||
$settingFrame->add($quad);
|
$settingFrame->add($quad);
|
||||||
$quad->setX($width / 2 * 0.545);
|
$quad->setX($width / 2 * 0.545);
|
||||||
@ -153,18 +159,18 @@ class ScriptSettings implements ConfiguratorMenu,CallbackListener {
|
|||||||
$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();
|
||||||
$settingFrame->add($entry);
|
$settingFrame->add($entry);
|
||||||
$entry->setStyle(Label_Text::STYLE_TextValueSmall);
|
$entry->setStyle(Label_Text::STYLE_TextValueSmall);
|
||||||
$entry->setHAlign(Control::CENTER);
|
$entry->setHAlign(Control::CENTER);
|
||||||
$entry->setX($width /2 * 0.55);
|
$entry->setX($width / 2 * 0.55);
|
||||||
$entry->setTextSize(1);
|
$entry->setTextSize(1);
|
||||||
$entry->setSize($width * 0.3, $settingHeight * 0.9);
|
$entry->setSize($width * 0.3, $settingHeight * 0.9);
|
||||||
$entry->setName(self::ACTION_PREFIX_SETTING . $settingName);
|
$entry->setName(self::ACTION_PREFIX_SETTING . $settingName);
|
||||||
$entry->setDefault($settingValue);
|
$entry->setDefault($settingValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$descriptionLabel = new Label();
|
$descriptionLabel = new Label();
|
||||||
$pageFrame->add($descriptionLabel);
|
$pageFrame->add($descriptionLabel);
|
||||||
@ -173,19 +179,17 @@ class ScriptSettings implements ConfiguratorMenu,CallbackListener {
|
|||||||
$descriptionLabel->setSize($width * 0.7, $settingHeight);
|
$descriptionLabel->setSize($width * 0.7, $settingHeight);
|
||||||
$descriptionLabel->setTextSize($labelTextSize);
|
$descriptionLabel->setTextSize($labelTextSize);
|
||||||
$descriptionLabel->setTranslate(true);
|
$descriptionLabel->setTranslate(true);
|
||||||
//$descriptionLabel->setTextPrefix('Desc: ');
|
// $descriptionLabel->setTextPrefix('Desc: ');
|
||||||
$descriptionLabel->setText($scriptParam['Desc']);
|
$descriptionLabel->setText($scriptParam['Desc']);
|
||||||
$script->addTooltip($nameLabel, $descriptionLabel);
|
$script->addTooltip($nameLabel, $descriptionLabel);
|
||||||
|
|
||||||
$y -= $settingHeight;
|
$y -= $settingHeight;
|
||||||
if ($index % $pageMaxCount == $pageMaxCount - 1) {
|
if ($index % $pageMaxCount == $pageMaxCount - 1) {
|
||||||
$script->addPage($pageFrame, $index, "test"); //TODO not working
|
$script->addPage($pageFrame, $index, "test"); // TODO not working
|
||||||
unset($pageFrame);
|
unset($pageFrame);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//$pages->add(array(-1 => $pagerPrev, 1 => $pagerNext), $pageFrames, $pageCountLabel);
|
|
||||||
|
|
||||||
return $frame;
|
return $frame;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -197,104 +201,106 @@ class ScriptSettings implements ConfiguratorMenu,CallbackListener {
|
|||||||
$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 = '';
|
$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);
|
||||||
|
|
||||||
foreach($scriptSettings as $key => $value){
|
foreach ($scriptSettings as $key => $value) {
|
||||||
if($key == $settingName){
|
if ($key == $settingName) {
|
||||||
//Check if something has been changed
|
// Check if something has been changed
|
||||||
if($setting["Value"] != $value){
|
if ($setting["Value"] != $value) {
|
||||||
$chatMessage .= '$FFF'.$settingName.'$z$s$FF0 to $FFF' . $setting["Value"].', ';
|
$chatMessage .= '$FFF' . $settingName . '$z$s$FF0 to $FFF' . $setting["Value"] . ', ';
|
||||||
}
|
}
|
||||||
//Setting found, cast type, break the inner loop
|
// Setting found, cast type, break the inner loop
|
||||||
settype($setting["Value"], gettype($value));
|
settype($setting["Value"], gettype($value));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$newSettings[$settingName] = $setting["Value"];
|
$newSettings[$settingName] = $setting["Value"];
|
||||||
}
|
}
|
||||||
|
|
||||||
//Nothing has been changed
|
// Nothing has been changed
|
||||||
if($chatMessage = ''){
|
if ($chatMessage = '') {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$success = $this->maniaControl->client->query('SetModeScriptSettings', $newSettings);
|
$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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$chatMessage = substr($chatMessage, 0, strlen($chatMessage) - 2);
|
||||||
$chatMessage = substr($chatMessage, 0, strlen($chatMessage)-2);
|
$chatMessage = str_replace("S_", "", $chatMessage);
|
||||||
$chatMessage = str_replace("S_","",$chatMessage);
|
|
||||||
|
|
||||||
$title = $this->maniaControl->authenticationManager->getAuthLevelName($player->authLevel);
|
$title = $this->maniaControl->authenticationManager->getAuthLevelName($player->authLevel);
|
||||||
|
|
||||||
$this->maniaControl->chat->sendInformation('$ff0' . $title . ' $<' . $player->nickname . '$> set Scriptsettings $<' . $chatMessage . '$>!');
|
$this->maniaControl->chat->sendInformation(
|
||||||
|
'$ff0' . $title . ' $<' . $player->nickname . '$> set Scriptsettings $<' . $chatMessage . '$>!');
|
||||||
|
|
||||||
// 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
|
// Trigger own callback
|
||||||
$this->maniaControl->callbackManager->triggerCallback(self::CB_SCRIPTSETTINGS_CHANGED, array(self::CB_SCRIPTSETTINGS_CHANGED));
|
$this->maniaControl->callbackManager->triggerCallback(self::CB_SCRIPTSETTINGS_CHANGED, array(self::CB_SCRIPTSETTINGS_CHANGED));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called on ManialinkPageAnswer
|
* Called on ManialinkPageAnswer
|
||||||
|
*
|
||||||
* @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)
|
if (!$boolSetting) return;
|
||||||
return;
|
|
||||||
|
|
||||||
$actionArray = explode(".", $actionId);
|
$actionArray = explode(".", $actionId);
|
||||||
|
|
||||||
$player = $this->maniaControl->playerManager->getPlayer($callback[1][1]);
|
$player = $this->maniaControl->playerManager->getPlayer($callback[1][1]);
|
||||||
$this->setCheckboxSetting($player, $actionArray[2]);
|
$this->setCheckboxSetting($player, $actionArray[2]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Toogle a boolean value setting
|
* Toogle a boolean value setting
|
||||||
|
*
|
||||||
* @param Player $player
|
* @param Player $player
|
||||||
* @param $setting
|
* @param $setting
|
||||||
*/
|
*/
|
||||||
public function setCheckboxSetting(Player $player, $setting){
|
public function setCheckboxSetting(Player $player, $setting) {
|
||||||
$this->maniaControl->client->query('GetModeScriptSettings');
|
$this->maniaControl->client->query('GetModeScriptSettings');
|
||||||
$scriptSettings = $this->maniaControl->client->getResponse();
|
$scriptSettings = $this->maniaControl->client->getResponse();
|
||||||
|
|
||||||
$newSetting = array();
|
$newSetting = array();
|
||||||
foreach($scriptSettings as $key => $value){
|
foreach ($scriptSettings as $key => $value) {
|
||||||
if($key == $setting){ //Setting found
|
if ($key == $setting) { // Setting found
|
||||||
$newSetting[$key] = $value == true ? false : true; //toggle setting
|
$newSetting[$key] = $value == true ? false : true; // toggle setting
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$success = $this->maniaControl->client->query('SetModeScriptSettings', $newSetting);
|
$success = $this->maniaControl->client->query('SetModeScriptSettings', $newSetting);
|
||||||
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';
|
$valString = ($newSetting[$setting]) ? 'true' : 'false';
|
||||||
$chatMessage = '$FFF'.$setting.'$z$s$FF0 to $FFF' . $valString;
|
$chatMessage = '$FFF' . $setting . '$z$s$FF0 to $FFF' . $valString;
|
||||||
$chatMessage = str_replace("S_","",$chatMessage);
|
$chatMessage = str_replace("S_", "", $chatMessage);
|
||||||
|
|
||||||
$title = $this->maniaControl->authenticationManager->getAuthLevelName($player->authLevel);
|
$title = $this->maniaControl->authenticationManager->getAuthLevelName($player->authLevel);
|
||||||
$this->maniaControl->chat->sendInformation('$ff0' . $title . ' $<' . $player->nickname . '$> set Scriptsetting $<' . $chatMessage . '$>!');
|
$this->maniaControl->chat->sendInformation(
|
||||||
|
'$ff0' . $title . ' $<' . $player->nickname . '$> set Scriptsetting $<' . $chatMessage . '$>!');
|
||||||
|
|
||||||
// log console message
|
// log console message
|
||||||
$this->maniaControl->log(Formatter::stripCodes($title . ' ' . $player->nickname . ' set Scriptsetting ' . $chatMessage . '!'));
|
$this->maniaControl->log(Formatter::stripCodes($title . ' ' . $player->nickname . ' set Scriptsetting ' . $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_SCRIPTSETTINGS_CHANGED, array(self::CB_SCRIPTSETTINGS_CHANGED));
|
||||||
}
|
}
|
||||||
|
@ -391,7 +391,7 @@ if (Event.Control.HasClass(\"" . self::CLASS_PAGER . "\")) {
|
|||||||
foreach (PageControl in Page.GetClassChildren_Result) {
|
foreach (PageControl in Page.GetClassChildren_Result) {
|
||||||
if (!PageControl.HasClass(PagesId)) continue;
|
if (!PageControl.HasClass(PagesId)) continue;
|
||||||
declare PageLabel <=> (PageControl as CMlLabel);
|
declare PageLabel <=> (PageControl as CMlLabel);
|
||||||
PageLabel.Value = (FML_PageNumber[PagesId]+1)^\"/\"^(FML_MaxPageNumber[PagesId]+1);
|
PageLabel.Value = FML_PageNumber[PagesId]^\"/\"^FML_MaxPageNumber[PagesId];
|
||||||
}
|
}
|
||||||
}";
|
}";
|
||||||
$pagesLabels = Builder::getLabelImplementationBlock(self::LABEL_MOUSECLICK, $pagesScript);
|
$pagesLabels = Builder::getLabelImplementationBlock(self::LABEL_MOUSECLICK, $pagesScript);
|
||||||
|
Loading…
Reference in New Issue
Block a user