script settings fixed for fml update

This commit is contained in:
Steffen Schröder 2013-12-31 13:51:30 +01:00
parent 5a5c422703
commit c69a00aa43
2 changed files with 76 additions and 70 deletions

View File

@ -22,13 +22,12 @@ use ManiaControl\Players\Player;
*
* @author steeffeen & kremsy
*/
class ScriptSettings implements ConfiguratorMenu,CallbackListener {
class ScriptSettings implements ConfiguratorMenu, CallbackListener {
/**
* Constants
*/
const ACTION_PREFIX_SETTING = 'ScriptSetting.';
const ACTION_SETTING_BOOL = 'ScriptSetting.ActionBoolSetting';
const CB_SCRIPTSETTINGS_CHANGED = 'ScriptSettings.SettingsChanged';
/**
@ -44,7 +43,9 @@ class ScriptSettings implements ConfiguratorMenu,CallbackListener {
public function __construct(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');
}
/**
@ -105,6 +106,8 @@ class ScriptSettings implements ConfiguratorMenu,CallbackListener {
$pageCountLabel->setStyle('TextTitle1');
$pageCountLabel->setTextSize(2);
$script->addPageLabel($pageCountLabel);
// Setting pages
$pageFrames = array();
$y = 0.;
@ -116,11 +119,14 @@ class ScriptSettings implements ConfiguratorMenu,CallbackListener {
if (!isset($pageFrame)) {
$pageFrame = new Frame();
$frame->add($pageFrame);
if (!empty($pageFrames)) {
$pageFrame->setVisible(false);
}
array_push($pageFrames, $pageFrame);
$y = $height * 0.41;
$script->addPage($pageFrame, count($pageFrames));
}
$settingFrame = new Frame();
$pageFrame->add($settingFrame);
$settingFrame->setY($y);
@ -134,17 +140,17 @@ class ScriptSettings implements ConfiguratorMenu,CallbackListener {
$nameLabel->setTextSize($labelTextSize);
$nameLabel->setText($settingName);
$settingValue = $scriptSettings[$settingName];
$substyle = '';
if($settingValue === false){
if ($settingValue === false) {
$substyle = Quad_Icons64x64_1::SUBSTYLE_LvlRed;
}else if($settingValue === true){
}
else if ($settingValue === true) {
$substyle = Quad_Icons64x64_1::SUBSTYLE_LvlGreen;
}
if($substyle != ''){
if ($substyle != '') {
$quad = new Quad_Icons64x64_1();
$settingFrame->add($quad);
$quad->setX($width / 2 * 0.545);
@ -153,19 +159,19 @@ class ScriptSettings implements ConfiguratorMenu,CallbackListener {
$quad->setSize(4, 4);
$quad->setHAlign(Control::CENTER);
$quad->setAction(self::ACTION_SETTING_BOOL . "." . $settingName);
}else{
}
else {
$entry = new Entry();
$settingFrame->add($entry);
$entry->setStyle(Label_Text::STYLE_TextValueSmall);
$entry->setHAlign(Control::CENTER);
$entry->setX($width /2 * 0.55);
$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->setDefault($settingValue);
}
$descriptionLabel = new Label();
$pageFrame->add($descriptionLabel);
$descriptionLabel->setHAlign(Control::LEFT);
@ -173,19 +179,17 @@ class ScriptSettings implements ConfiguratorMenu,CallbackListener {
$descriptionLabel->setSize($width * 0.7, $settingHeight);
$descriptionLabel->setTextSize($labelTextSize);
$descriptionLabel->setTranslate(true);
//$descriptionLabel->setTextPrefix('Desc: ');
// $descriptionLabel->setTextPrefix('Desc: ');
$descriptionLabel->setText($scriptParam['Desc']);
$script->addTooltip($nameLabel, $descriptionLabel);
$y -= $settingHeight;
if ($index % $pageMaxCount == $pageMaxCount - 1) {
$script->addPage($pageFrame, $index, "test"); //TODO not working
$script->addPage($pageFrame, $index, "test"); // TODO not working
unset($pageFrame);
}
}
//$pages->add(array(-1 => $pagerPrev, 1 => $pagerNext), $pageFrames, $pageCountLabel);
return $frame;
}
@ -205,13 +209,13 @@ class ScriptSettings implements ConfiguratorMenu,CallbackListener {
$settingName = substr($setting['Name'], $prefixLength);
foreach($scriptSettings as $key => $value){
if($key == $settingName){
//Check if something has been changed
if($setting["Value"] != $value){
$chatMessage .= '$FFF'.$settingName.'$z$s$FF0 to $FFF' . $setting["Value"].', ';
foreach ($scriptSettings as $key => $value) {
if ($key == $settingName) {
// 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
// Setting found, cast type, break the inner loop
settype($setting["Value"], gettype($value));
break;
}
@ -219,8 +223,8 @@ class ScriptSettings implements ConfiguratorMenu,CallbackListener {
$newSettings[$settingName] = $setting["Value"];
}
//Nothing has been changed
if($chatMessage = ''){
// Nothing has been changed
if ($chatMessage = '') {
return;
}
@ -230,13 +234,13 @@ class ScriptSettings implements ConfiguratorMenu,CallbackListener {
return;
}
$chatMessage = substr($chatMessage, 0, strlen($chatMessage)-2);
$chatMessage = str_replace("S_","",$chatMessage);
$chatMessage = substr($chatMessage, 0, strlen($chatMessage) - 2);
$chatMessage = str_replace("S_", "", $chatMessage);
$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
$this->maniaControl->log(Formatter::stripCodes($title . ' ' . $player->nickname . ' set Scriptsettings ' . $chatMessage . '!'));
@ -247,14 +251,14 @@ class ScriptSettings implements ConfiguratorMenu,CallbackListener {
/**
* Called on ManialinkPageAnswer
*
* @param array $callback
*/
public function handleManialinkPageAnswer(array $callback){
public function handleManialinkPageAnswer(array $callback) {
$actionId = $callback[1][2];
$boolSetting = (strpos($actionId, self::ACTION_SETTING_BOOL) === 0);
if(!$boolSetting)
return;
if (!$boolSetting) return;
$actionArray = explode(".", $actionId);
@ -264,17 +268,18 @@ class ScriptSettings implements ConfiguratorMenu,CallbackListener {
/**
* Toogle a boolean value setting
*
* @param Player $player
* @param $setting
*/
public function setCheckboxSetting(Player $player, $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
foreach ($scriptSettings as $key => $value) {
if ($key == $setting) { // Setting found
$newSetting[$key] = $value == true ? false : true; // toggle setting
break;
}
}
@ -286,11 +291,12 @@ class ScriptSettings implements ConfiguratorMenu,CallbackListener {
}
$valString = ($newSetting[$setting]) ? 'true' : 'false';
$chatMessage = '$FFF'.$setting.'$z$s$FF0 to $FFF' . $valString;
$chatMessage = str_replace("S_","",$chatMessage);
$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 . '$>!');
$this->maniaControl->chat->sendInformation(
'$ff0' . $title . ' $<' . $player->nickname . '$> set Scriptsetting $<' . $chatMessage . '$>!');
// log console message
$this->maniaControl->log(Formatter::stripCodes($title . ' ' . $player->nickname . ' set Scriptsetting ' . $chatMessage . '!'));

View File

@ -391,7 +391,7 @@ if (Event.Control.HasClass(\"" . self::CLASS_PAGER . "\")) {
foreach (PageControl in Page.GetClassChildren_Result) {
if (!PageControl.HasClass(PagesId)) continue;
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);