2013-11-28 17:36:39 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace ManiaControl\Configurators;
|
|
|
|
|
|
|
|
use ManiaControl\ManiaControl;
|
|
|
|
use FML\Controls\Frame;
|
|
|
|
use FML\Controls\Label;
|
|
|
|
use FML\Script\Pages;
|
|
|
|
use FML\Script\Tooltips;
|
|
|
|
use FML\Controls\Control;
|
|
|
|
use FML\Controls\Quads\Quad_Icons64x64_1;
|
|
|
|
use FML\Controls\Labels\Label_Text;
|
|
|
|
use FML\Controls\Entry;
|
|
|
|
use ManiaControl\Players\Player;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class offering a configurator for current script settings
|
|
|
|
*
|
|
|
|
* @author steeffeen & kremsy
|
|
|
|
*/
|
2013-12-12 19:41:37 +01:00
|
|
|
// TODO: boolean script settings not as entries
|
2013-11-28 17:36:39 +01:00
|
|
|
class ScriptSettings implements ConfiguratorMenu {
|
|
|
|
/**
|
|
|
|
* Constants
|
|
|
|
*/
|
2013-12-12 19:41:37 +01:00
|
|
|
const ACTION_PREFIX_SETTING = 'ScriptSetting.';
|
2013-11-28 17:36:39 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Private properties
|
|
|
|
*/
|
|
|
|
private $maniaControl = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new script settings instance
|
|
|
|
*
|
|
|
|
* @param ManiaControl $maniaControl
|
|
|
|
*/
|
|
|
|
public function __construct(ManiaControl $maniaControl) {
|
|
|
|
$this->maniaControl = $maniaControl;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @see \ManiaControl\Configurators\ConfiguratorMenu::getTitle()
|
|
|
|
*/
|
|
|
|
public function getTitle() {
|
2013-12-12 19:41:37 +01:00
|
|
|
return 'Script Settings';
|
2013-11-28 17:36:39 +01:00
|
|
|
}
|
2013-12-12 19:41:37 +01:00
|
|
|
|
2013-11-28 17:36:39 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @see \ManiaControl\Configurators\ConfiguratorMenu::getMenu()
|
|
|
|
*/
|
|
|
|
public function getMenu($width, $height, Pages $pages, Tooltips $tooltips) {
|
|
|
|
$frame = new Frame();
|
|
|
|
|
|
|
|
$this->maniaControl->client->query('GetModeScriptInfo');
|
|
|
|
$scriptInfo = $this->maniaControl->client->getResponse();
|
|
|
|
$scriptParams = $scriptInfo['ParamDescs'];
|
|
|
|
|
|
|
|
$this->maniaControl->client->query('GetModeScriptSettings');
|
|
|
|
$scriptSettings = $this->maniaControl->client->getResponse();
|
|
|
|
|
|
|
|
// Config
|
|
|
|
$pagerSize = 9.;
|
|
|
|
$settingHeight = 5.;
|
|
|
|
$labelTextSize = 2;
|
2013-12-09 09:07:55 +01:00
|
|
|
$pageMaxCount = 13;
|
2013-11-28 17:36:39 +01:00
|
|
|
|
|
|
|
// Pagers
|
|
|
|
$pagerPrev = new Quad_Icons64x64_1();
|
|
|
|
$frame->add($pagerPrev);
|
2013-12-04 00:40:37 +01:00
|
|
|
$pagerPrev->setPosition($width * 0.39, $height * -0.44, 2);
|
2013-11-28 17:36:39 +01:00
|
|
|
$pagerPrev->setSize($pagerSize, $pagerSize);
|
|
|
|
$pagerPrev->setSubStyle(Quad_Icons64x64_1::SUBSTYLE_ArrowPrev);
|
|
|
|
|
|
|
|
$pagerNext = new Quad_Icons64x64_1();
|
|
|
|
$frame->add($pagerNext);
|
2013-12-04 00:40:37 +01:00
|
|
|
$pagerNext->setPosition($width * 0.45, $height * -0.44, 2);
|
2013-11-28 17:36:39 +01:00
|
|
|
$pagerNext->setSize($pagerSize, $pagerSize);
|
|
|
|
$pagerNext->setSubStyle(Quad_Icons64x64_1::SUBSTYLE_ArrowNext);
|
|
|
|
|
|
|
|
$pageCountLabel = new Label();
|
|
|
|
$frame->add($pageCountLabel);
|
|
|
|
$pageCountLabel->setHAlign(Control::RIGHT);
|
2013-12-04 00:40:37 +01:00
|
|
|
$pageCountLabel->setPosition($width * 0.35, $height * -0.44, 1);
|
2013-11-28 17:36:39 +01:00
|
|
|
$pageCountLabel->setStyle('TextTitle1');
|
|
|
|
$pageCountLabel->setTextSize(2);
|
|
|
|
|
|
|
|
// Setting pages
|
|
|
|
$pageFrames = array();
|
2013-12-12 19:41:37 +01:00
|
|
|
$y = 0.;
|
2013-11-28 17:36:39 +01:00
|
|
|
foreach ($scriptParams as $index => $scriptParam) {
|
|
|
|
$settingName = $scriptParam['Name'];
|
|
|
|
if (!isset($scriptSettings[$settingName])) continue;
|
|
|
|
|
|
|
|
if (!isset($pageFrame)) {
|
|
|
|
$pageFrame = new Frame();
|
|
|
|
$frame->add($pageFrame);
|
|
|
|
array_push($pageFrames, $pageFrame);
|
2013-12-09 09:07:55 +01:00
|
|
|
$y = $height * 0.41;
|
2013-11-28 17:36:39 +01:00
|
|
|
}
|
|
|
|
|
2013-12-09 09:07:55 +01:00
|
|
|
$settingFrame = new Frame();
|
|
|
|
$pageFrame->add($settingFrame);
|
|
|
|
$settingFrame->setY($y);
|
|
|
|
|
2013-12-12 19:41:37 +01:00
|
|
|
$nameLabel = new Label_Text();
|
2013-12-09 09:07:55 +01:00
|
|
|
$settingFrame->add($nameLabel);
|
2013-11-28 17:36:39 +01:00
|
|
|
$nameLabel->setHAlign(Control::LEFT);
|
2013-12-09 09:07:55 +01:00
|
|
|
$nameLabel->setX($width * -0.46);
|
2013-11-28 17:36:39 +01:00
|
|
|
$nameLabel->setSize($width * 0.4, $settingHeight);
|
2013-12-12 19:41:37 +01:00
|
|
|
$nameLabel->setStyle($nameLabel::STYLE_TextCardSmall);
|
2013-11-28 17:36:39 +01:00
|
|
|
$nameLabel->setTextSize($labelTextSize);
|
|
|
|
$nameLabel->setText($settingName);
|
|
|
|
|
2013-12-09 09:07:55 +01:00
|
|
|
$entry = new Entry();
|
|
|
|
$settingFrame->add($entry);
|
|
|
|
$entry->setHAlign(Control::RIGHT);
|
|
|
|
$entry->setX($width * 0.44);
|
2013-12-12 19:41:37 +01:00
|
|
|
$entry->setSize($width * 0.4, $settingHeight);
|
|
|
|
$entry->setName(self::ACTION_PREFIX_SETTING . $settingName);
|
2013-12-09 09:07:55 +01:00
|
|
|
$settingValue = $scriptSettings[$settingName];
|
|
|
|
if ($settingValue === false) {
|
|
|
|
$settingValue = 0;
|
|
|
|
}
|
|
|
|
$entry->setDefault($settingValue);
|
2013-12-12 19:41:37 +01:00
|
|
|
|
2013-12-09 13:45:58 +01:00
|
|
|
$descriptionLabel = new Label();
|
|
|
|
$pageFrame->add($descriptionLabel);
|
|
|
|
$descriptionLabel->setHAlign(Control::LEFT);
|
|
|
|
$descriptionLabel->setPosition($width * -0.45, $height * -0.44);
|
|
|
|
$descriptionLabel->setSize($width * 0.7, $settingHeight);
|
|
|
|
$descriptionLabel->setTranslate(true);
|
|
|
|
$descriptionLabel->setTextPrefix('Desc: ');
|
|
|
|
$descriptionLabel->setText($scriptParam['Desc']);
|
|
|
|
$tooltips->add($nameLabel, $descriptionLabel);
|
2013-11-28 17:36:39 +01:00
|
|
|
|
|
|
|
$y -= $settingHeight;
|
|
|
|
if ($index % $pageMaxCount == $pageMaxCount - 1) {
|
|
|
|
unset($pageFrame);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$pages->add(array(-1 => $pagerPrev, 1 => $pagerNext), $pageFrames, $pageCountLabel);
|
|
|
|
|
|
|
|
return $frame;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @see \ManiaControl\Configurators\ConfiguratorMenu::saveConfigData()
|
|
|
|
*/
|
|
|
|
public function saveConfigData(array $configData, Player $player) {
|
|
|
|
$this->maniaControl->client->query('GetModeScriptSettings');
|
|
|
|
$scriptSettings = $this->maniaControl->client->getResponse();
|
2013-12-12 19:41:37 +01:00
|
|
|
// var_dump($configData);
|
|
|
|
// var_dump($scriptSettings);
|
|
|
|
$prefixLength = strlen(self::ACTION_PREFIX_SETTING);
|
2013-11-28 17:36:39 +01:00
|
|
|
foreach ($configData[3] as $dataName => $dataValue) {
|
2013-12-12 19:41:37 +01:00
|
|
|
if (substr($dataName, 0, $prefixLength) != self::ACTION_PREFIX_SETTING) continue;
|
2013-11-28 17:36:39 +01:00
|
|
|
|
|
|
|
$settingName = substr($dataName, $prefixLength);
|
2013-12-12 19:41:37 +01:00
|
|
|
|
|
|
|
// TODO: apply new script settings
|
2013-11-28 17:36:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|