- improved configurator menu for mc settings
-> fixed bug caused by 64 entries limit
This commit is contained in:
parent
4e6db622b2
commit
fed10c4a59
@ -171,7 +171,7 @@ class Configurator implements CallbackListener, CommandListener, ManialinkPageAn
|
|||||||
* @param int $menuId
|
* @param int $menuId
|
||||||
*/
|
*/
|
||||||
public function showMenu(Player $player, $menuId = 0) {
|
public function showMenu(Player $player, $menuId = 0) {
|
||||||
$manialink = $this->buildManialink($menuId);
|
$manialink = $this->buildManialink($menuId, $player);
|
||||||
$this->maniaControl->manialinkManager->displayWidget($manialink, $player, "Configurator");
|
$this->maniaControl->manialinkManager->displayWidget($manialink, $player, "Configurator");
|
||||||
$this->playersMenuShown[$player->login] = true;
|
$this->playersMenuShown[$player->login] = true;
|
||||||
}
|
}
|
||||||
@ -231,7 +231,7 @@ class Configurator implements CallbackListener, CommandListener, ManialinkPageAn
|
|||||||
$i = 0;
|
$i = 0;
|
||||||
foreach($this->menus as $menu) {
|
foreach($this->menus as $menu) {
|
||||||
/** @var ConfiguratorMenu $menu */
|
/** @var ConfiguratorMenu $menu */
|
||||||
if ($menu->getTitle() == $name) {
|
if ($menu == $name || $menu->getTitle() == $name) {
|
||||||
return $i;
|
return $i;
|
||||||
}
|
}
|
||||||
$i++;
|
$i++;
|
||||||
@ -246,7 +246,7 @@ class Configurator implements CallbackListener, CommandListener, ManialinkPageAn
|
|||||||
* @internal param bool $forceBuild
|
* @internal param bool $forceBuild
|
||||||
* @return \FML\ManiaLink
|
* @return \FML\ManiaLink
|
||||||
*/
|
*/
|
||||||
private function buildManialink($menuIdShown = 0) {
|
private function buildManialink($menuIdShown = 0, Player $player) {
|
||||||
$menuPosX = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MENU_POSX);
|
$menuPosX = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MENU_POSX);
|
||||||
$menuPosY = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MENU_POSY);
|
$menuPosY = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MENU_POSY);
|
||||||
$menuWidth = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MENU_WIDTH);
|
$menuWidth = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MENU_WIDTH);
|
||||||
@ -305,7 +305,7 @@ class Configurator implements CallbackListener, CommandListener, ManialinkPageAn
|
|||||||
|
|
||||||
//Show a Menu
|
//Show a Menu
|
||||||
if ($menuId == $menuIdShown) {
|
if ($menuId == $menuIdShown) {
|
||||||
$menuControl = $menu->getMenu($subMenuWidth, $subMenuHeight, $script);
|
$menuControl = $menu->getMenu($subMenuWidth, $subMenuHeight, $script, $player);
|
||||||
$menusFrame->add($menuControl);
|
$menusFrame->add($menuControl);
|
||||||
$menuScript->addElement($menuItemLabel, $menuControl);
|
$menuScript->addElement($menuItemLabel, $menuControl);
|
||||||
}
|
}
|
||||||
@ -343,11 +343,10 @@ class Configurator implements CallbackListener, CommandListener, ManialinkPageAn
|
|||||||
$saveButton->setTranslate(true);
|
$saveButton->setTranslate(true);
|
||||||
$saveButton->setText('$zSave$z');
|
$saveButton->setText('$zSave$z');
|
||||||
$saveButton->setAction(self::ACTION_SAVECONFIG);
|
$saveButton->setAction(self::ACTION_SAVECONFIG);
|
||||||
|
|
||||||
return $manialink;
|
return $manialink;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle ManialinkPageAnswer Callback
|
* Handle ManialinkPageAnswer Callback
|
||||||
*
|
*
|
||||||
|
@ -27,9 +27,10 @@ interface ConfiguratorMenu {
|
|||||||
* @param float $width
|
* @param float $width
|
||||||
* @param float $height
|
* @param float $height
|
||||||
* @param Script $script
|
* @param Script $script
|
||||||
|
* @param Player $player
|
||||||
* @return \FML\Controls\Frame
|
* @return \FML\Controls\Frame
|
||||||
*/
|
*/
|
||||||
public function getMenu($width, $height, Script $script);
|
public function getMenu($width, $height, Script $script, Player $player);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Save the Config Data
|
* Save the Config Data
|
||||||
|
@ -15,10 +15,15 @@ use ManiaControl\Callbacks\CallbackListener;
|
|||||||
use ManiaControl\Callbacks\CallbackManager;
|
use ManiaControl\Callbacks\CallbackManager;
|
||||||
use ManiaControl\ManiaControl;
|
use ManiaControl\ManiaControl;
|
||||||
use ManiaControl\Players\Player;
|
use ManiaControl\Players\Player;
|
||||||
|
use ManiaControl\Callbacks\Callbacks;
|
||||||
|
use ManiaControl\Players\PlayerManager;
|
||||||
|
use FML\Types\Playable;
|
||||||
|
use FML\Controls\Labels\Label_Button;
|
||||||
|
use ManiaControl\Settings\SettingManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class offering a Configurator for ManiaControl Settings
|
* Class offering a Configurator for ManiaControl Settings
|
||||||
*
|
*
|
||||||
* @author steeffeen & kremsy
|
* @author steeffeen & kremsy
|
||||||
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
|
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
|
||||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||||
@ -27,32 +32,46 @@ class ManiaControlSettings implements ConfiguratorMenu, CallbackListener {
|
|||||||
/*
|
/*
|
||||||
* Constants
|
* Constants
|
||||||
*/
|
*/
|
||||||
const TITLE = 'ManiaControl Settings';
|
const TITLE = 'ManiaControl Settings';
|
||||||
const ACTION_PREFIX_SETTING = 'ManiaControlSettings';
|
const ACTION_PREFIX_SETTING = 'MCSetting.';
|
||||||
const ACTION_SETTING_BOOL = 'ManiaControlSettings.ActionBoolSetting.';
|
const ACTION_PREFIX_SETTINGCLASS = 'MCSettingClass.';
|
||||||
|
const ACTION_SETTINGCLASS_BACK = 'MCSettingClassBack';
|
||||||
|
const ACTION_SETTING_BOOL = 'MCSettings.ActionBoolSetting.';
|
||||||
const SETTING_PERMISSION_CHANGE_MC_SETTINGS = 'Change ManiaControl Settings';
|
const SETTING_PERMISSION_CHANGE_MC_SETTINGS = 'Change ManiaControl Settings';
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Private Properties
|
* Private Properties
|
||||||
*/
|
*/
|
||||||
private $maniaControl = null;
|
private $maniaControl = null;
|
||||||
|
private $playersSettingCategoryOpened = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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;
|
||||||
|
|
||||||
// Register for callbacks
|
// Register for callbacks
|
||||||
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer');
|
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer');
|
||||||
$this->maniaControl->authenticationManager->definePermissionLevel(self::SETTING_PERMISSION_CHANGE_MC_SETTINGS, AuthenticationManager::AUTH_LEVEL_SUPERADMIN);
|
$this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERDISCONNECT, $this, 'handlePlayerDisconnect');
|
||||||
|
|
||||||
|
$this->maniaControl->authenticationManager->definePermissionLevel(self::SETTING_PERMISSION_CHANGE_MC_SETTINGS, AuthenticationManager::AUTH_LEVEL_ADMIN);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle Player Disconnect Callback
|
||||||
|
*
|
||||||
|
* @param Player $player
|
||||||
|
*/
|
||||||
|
public function handlePlayerDisconnect(Player $player) {
|
||||||
|
unset($this->playersSettingCategoryOpened[$player->login]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the Menu Title
|
* Get the Menu Title
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getTitle() {
|
public function getTitle() {
|
||||||
@ -60,81 +79,172 @@ class ManiaControlSettings implements ConfiguratorMenu, CallbackListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the Configurator Menu Frame
|
|
||||||
*
|
*
|
||||||
* @param float $width
|
* @see \ManiaControl\Configurators\ConfiguratorMenu::getMenu()
|
||||||
* @param float $height
|
*/
|
||||||
|
public function getMenu($width, $height, Script $script, Player $player) {
|
||||||
|
if (isset($this->playersSettingCategoryOpened[$player->login]) && strlen($this->playersSettingCategoryOpened[$player->login]) > 0) {
|
||||||
|
return $this->getMenuSettingsForClass($this->playersSettingCategoryOpened[$player->login], $width, $height, $script, $player);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return $this->getMenuSettingClasses($width, $height, $script, $player);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the Menu showing all possible Classes
|
||||||
|
*
|
||||||
|
* @param float $width
|
||||||
|
* @param float $height
|
||||||
* @param Script $script
|
* @param Script $script
|
||||||
|
* @param Player $player
|
||||||
* @return \FML\Controls\Frame
|
* @return \FML\Controls\Frame
|
||||||
*/
|
*/
|
||||||
public function getMenu($width, $height, Script $script) {
|
private function getMenuSettingClasses($width, $height, Script $script, Player $player) {
|
||||||
$paging = new Paging();
|
$settingClasses = $this->maniaControl->settingManager->getSettingClasses(true);
|
||||||
$script->addFeature($paging);
|
|
||||||
$frame = new Frame();
|
$paging = new Paging();
|
||||||
|
$script->addFeature($paging);
|
||||||
|
$frame = new Frame();
|
||||||
|
|
||||||
// Config
|
// Config
|
||||||
$pagerSize = 9.;
|
$pagerSize = 9.;
|
||||||
$settingHeight = 5.;
|
$settingHeight = 5.;
|
||||||
$labelTextSize = 2;
|
$pageMaxCount = 13;
|
||||||
$pageMaxCount = 13;
|
$y = 0;
|
||||||
|
|
||||||
//Pagers
|
// Pagers
|
||||||
$pagerPrev = new Quad_Icons64x64_1();
|
$pagerPrev = new Quad_Icons64x64_1();
|
||||||
$frame->add($pagerPrev);
|
$frame->add($pagerPrev);
|
||||||
$pagerPrev->setPosition($width * 0.39, $height * -0.44, 2);
|
$pagerPrev->setPosition($width * 0.39, $height * -0.44, 2);
|
||||||
$pagerPrev->setSize($pagerSize, $pagerSize);
|
$pagerPrev->setSize($pagerSize, $pagerSize);
|
||||||
$pagerPrev->setSubStyle(Quad_Icons64x64_1::SUBSTYLE_ArrowPrev);
|
$pagerPrev->setSubStyle($pagerPrev::SUBSTYLE_ArrowPrev);
|
||||||
|
|
||||||
$pagerNext = new Quad_Icons64x64_1();
|
$pagerNext = new Quad_Icons64x64_1();
|
||||||
$frame->add($pagerNext);
|
$frame->add($pagerNext);
|
||||||
$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($pagerNext::SUBSTYLE_ArrowNext);
|
||||||
|
|
||||||
$paging->addButton($pagerNext);
|
$paging->addButton($pagerNext);
|
||||||
$paging->addButton($pagerPrev);
|
$paging->addButton($pagerPrev);
|
||||||
|
|
||||||
$pageCountLabel = new Label();
|
$pageCountLabel = new Label_Text();
|
||||||
$frame->add($pageCountLabel);
|
$frame->add($pageCountLabel);
|
||||||
$pageCountLabel->setHAlign(Control::RIGHT);
|
$pageCountLabel->setHAlign($pageCountLabel::RIGHT);
|
||||||
$pageCountLabel->setPosition($width * 0.35, $height * -0.44, 1);
|
$pageCountLabel->setPosition($width * 0.35, $height * -0.44, 1);
|
||||||
$pageCountLabel->setStyle('TextTitle1');
|
$pageCountLabel->setStyle($pageCountLabel::STYLE_TextTitle1);
|
||||||
$pageCountLabel->setTextSize(2);
|
$pageCountLabel->setTextSize(2);
|
||||||
|
|
||||||
$paging->setLabel($pageCountLabel);
|
$paging->setLabel($pageCountLabel);
|
||||||
|
|
||||||
/** @var ManiaControl/SettingManager $this->maniaControl->settingManager */
|
$pageFrame = null;
|
||||||
$settings = $this->maniaControl->settingManager->getSettings();
|
$index = 0;
|
||||||
|
foreach ($settingClasses as $settingClass) {
|
||||||
$pluginClasses = $this->maniaControl->pluginManager->getPluginClasses();
|
if (!$pageFrame) {
|
||||||
|
|
||||||
$pageFrames = array();
|
|
||||||
$y = 0;
|
|
||||||
$index = 1;
|
|
||||||
$prevClass = '';
|
|
||||||
foreach($settings as $setting) {
|
|
||||||
//Don't display Plugin Settings
|
|
||||||
if (array_search($setting->class, $pluginClasses) !== FALSE) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
|
||||||
$y = $height * 0.41;
|
$y = $height * 0.41;
|
||||||
$paging->addPage($pageFrame);
|
$paging->addPage($pageFrame);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$classLabel = new Label_Text();
|
||||||
|
$pageFrame->add($classLabel);
|
||||||
|
$classLabel->setHAlign($classLabel::LEFT);
|
||||||
|
$classLabel->setPosition($width * -0.45, $y);
|
||||||
|
$classLabel->setSize($width * 0.9, $settingHeight * 0.9);
|
||||||
|
$classLabel->setStyle($classLabel::STYLE_TextCardSmall);
|
||||||
|
$classLabel->setTextSize(2);
|
||||||
|
$classLabel->setText($settingClass);
|
||||||
|
$classLabel->setTextColor('fff');
|
||||||
|
$classLabel->setAction(self::ACTION_PREFIX_SETTINGCLASS . $settingClass);
|
||||||
|
|
||||||
|
$y -= $settingHeight;
|
||||||
|
|
||||||
|
if ($index % $pageMaxCount == $pageMaxCount - 1) {
|
||||||
|
$pageFrame = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$index++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $frame;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the Menu showing the Settings for the given Class
|
||||||
|
*
|
||||||
|
* @param string $settingClass
|
||||||
|
* @param float $width
|
||||||
|
* @param float $height
|
||||||
|
* @param Script $script
|
||||||
|
* @param Player $player
|
||||||
|
* @return \FML\Controls\Frame
|
||||||
|
*/
|
||||||
|
private function getMenuSettingsForClass($settingClass, $width, $height, Script $script, Player $player) {
|
||||||
|
$settings = $this->maniaControl->settingManager->getSettingsByClass($settingClass);
|
||||||
|
|
||||||
|
$paging = new Paging();
|
||||||
|
$script->addFeature($paging);
|
||||||
|
$frame = new Frame();
|
||||||
|
|
||||||
|
// Config
|
||||||
|
$pagerSize = 9.;
|
||||||
|
$settingHeight = 5.;
|
||||||
|
$labelTextSize = 2;
|
||||||
|
$pageMaxCount = 13;
|
||||||
|
|
||||||
|
// Pagers
|
||||||
|
$pagerPrev = new Quad_Icons64x64_1();
|
||||||
|
$frame->add($pagerPrev);
|
||||||
|
$pagerPrev->setPosition($width * 0.39, $height * -0.44, 2);
|
||||||
|
$pagerPrev->setSize($pagerSize, $pagerSize);
|
||||||
|
$pagerPrev->setSubStyle($pagerPrev::SUBSTYLE_ArrowPrev);
|
||||||
|
|
||||||
|
$pagerNext = new Quad_Icons64x64_1();
|
||||||
|
$frame->add($pagerNext);
|
||||||
|
$pagerNext->setPosition($width * 0.45, $height * -0.44, 2);
|
||||||
|
$pagerNext->setSize($pagerSize, $pagerSize);
|
||||||
|
$pagerNext->setSubStyle($pagerNext::SUBSTYLE_ArrowNext);
|
||||||
|
|
||||||
|
$paging->addButton($pagerNext);
|
||||||
|
$paging->addButton($pagerPrev);
|
||||||
|
|
||||||
|
$pageCountLabel = new Label_Text();
|
||||||
|
$frame->add($pageCountLabel);
|
||||||
|
$pageCountLabel->setHAlign($pageCountLabel::RIGHT);
|
||||||
|
$pageCountLabel->setPosition($width * 0.35, $height * -0.44);
|
||||||
|
$pageCountLabel->setStyle($pageCountLabel::STYLE_TextTitle1);
|
||||||
|
$pageCountLabel->setTextSize(2);
|
||||||
|
|
||||||
|
$paging->setLabel($pageCountLabel);
|
||||||
|
|
||||||
|
$backLabel = new Label_Button();
|
||||||
|
$frame->add($backLabel);
|
||||||
|
$backLabel->setPosition($width * -0.49, $height * -0.44);
|
||||||
|
$backLabel->setHAlign($backLabel::LEFT);
|
||||||
|
$backLabel->setTextSize(2);
|
||||||
|
$backLabel->setText('Back');
|
||||||
|
$backLabel->setAction(self::ACTION_SETTINGCLASS_BACK);
|
||||||
|
|
||||||
|
$pageFrame = null;
|
||||||
|
$index = 0;
|
||||||
|
foreach ($settings as $setting) {
|
||||||
|
if (!$pageFrame) {
|
||||||
|
$pageFrame = new Frame();
|
||||||
|
$frame->add($pageFrame);
|
||||||
|
$y = $height * 0.41;
|
||||||
|
$paging->addPage($pageFrame);
|
||||||
|
}
|
||||||
|
|
||||||
$settingFrame = new Frame();
|
$settingFrame = new Frame();
|
||||||
$pageFrame->add($settingFrame);
|
$pageFrame->add($settingFrame);
|
||||||
$settingFrame->setY($y);
|
$settingFrame->setY($y);
|
||||||
|
|
||||||
//Headline Label
|
// TODO: display currently select setting class
|
||||||
if ($prevClass != $setting->class) {
|
|
||||||
|
// Headline Label
|
||||||
|
if (false) {
|
||||||
$headLabel = new Label_Text();
|
$headLabel = new Label_Text();
|
||||||
$settingFrame->add($headLabel);
|
$settingFrame->add($headLabel);
|
||||||
$headLabel->setHAlign(Control::LEFT);
|
$headLabel->setHAlign(Control::LEFT);
|
||||||
@ -144,28 +254,8 @@ class ManiaControlSettings implements ConfiguratorMenu, CallbackListener {
|
|||||||
$headLabel->setTextSize($labelTextSize);
|
$headLabel->setTextSize($labelTextSize);
|
||||||
$headLabel->setText($setting->class);
|
$headLabel->setText($setting->class);
|
||||||
$headLabel->setTextColor("F00");
|
$headLabel->setTextColor("F00");
|
||||||
|
} // Headline
|
||||||
$y -= $settingHeight;
|
|
||||||
|
|
||||||
|
|
||||||
if ($index % $pageMaxCount == $pageMaxCount - 1) {
|
|
||||||
$pageFrame = new Frame();
|
|
||||||
$frame->add($pageFrame);
|
|
||||||
if (!empty($pageFrames)) {
|
|
||||||
$pageFrame->setVisible(false);
|
|
||||||
}
|
|
||||||
array_push($pageFrames, $pageFrame);
|
|
||||||
$y = $height * 0.41;
|
|
||||||
$paging->addPage($pageFrame);
|
|
||||||
}
|
|
||||||
|
|
||||||
$index++;
|
|
||||||
|
|
||||||
$settingFrame = new Frame();
|
|
||||||
$pageFrame->add($settingFrame);
|
|
||||||
$settingFrame->setY($y);
|
|
||||||
} //Headline Label finished
|
|
||||||
|
|
||||||
$nameLabel = new Label_Text();
|
$nameLabel = new Label_Text();
|
||||||
$settingFrame->add($nameLabel);
|
$settingFrame->add($nameLabel);
|
||||||
$nameLabel->setHAlign(Control::LEFT);
|
$nameLabel->setHAlign(Control::LEFT);
|
||||||
@ -175,57 +265,42 @@ class ManiaControlSettings implements ConfiguratorMenu, CallbackListener {
|
|||||||
$nameLabel->setTextSize($labelTextSize);
|
$nameLabel->setTextSize($labelTextSize);
|
||||||
$nameLabel->setText($setting->setting);
|
$nameLabel->setText($setting->setting);
|
||||||
$nameLabel->setTextColor("FFF");
|
$nameLabel->setTextColor("FFF");
|
||||||
|
|
||||||
$substyle = '';
|
if ($setting->type === SettingManager::TYPE_BOOL) {
|
||||||
|
|
||||||
|
|
||||||
$entry = new Entry();
|
|
||||||
$settingFrame->add($entry);
|
|
||||||
$entry->setStyle(Label_Text::STYLE_TextValueSmall);
|
|
||||||
$entry->setHAlign(Control::CENTER);
|
|
||||||
$entry->setX($width / 2 * 0.65);
|
|
||||||
$entry->setTextSize(1);
|
|
||||||
$entry->setSize($width * 0.3, $settingHeight * 0.9);
|
|
||||||
$entry->setName(self::ACTION_PREFIX_SETTING . '.' . $setting->index);
|
|
||||||
$entry->setDefault($setting->value);
|
|
||||||
|
|
||||||
|
|
||||||
if ($setting->type == "bool") {
|
|
||||||
if ($setting->value == "0") {
|
|
||||||
$substyle = Quad_Icons64x64_1::SUBSTYLE_LvlRed;
|
|
||||||
} else if ($setting->value == "1") {
|
|
||||||
$substyle = Quad_Icons64x64_1::SUBSTYLE_LvlGreen;
|
|
||||||
}
|
|
||||||
|
|
||||||
$quad = new Quad_Icons64x64_1();
|
$quad = new Quad_Icons64x64_1();
|
||||||
$settingFrame->add($quad);
|
$settingFrame->add($quad);
|
||||||
$quad->setX($width / 2 * 0.6);
|
$quad->setX($width / 2 * 0.6);
|
||||||
$quad->setZ(-0.01);
|
$quad->setZ(-0.01);
|
||||||
$quad->setSubStyle($substyle);
|
$quad->setSubStyle(($setting->value ? $quad::SUBSTYLE_LvlGreen : $quad::SUBSTYLE_LvlRed));
|
||||||
$quad->setSize(4, 4);
|
$quad->setSize(4, 4);
|
||||||
$quad->setHAlign(Control::CENTER2);
|
|
||||||
$quad->setAction(self::ACTION_SETTING_BOOL . $setting->index);
|
$quad->setAction(self::ACTION_SETTING_BOOL . $setting->index);
|
||||||
$entry->setVisible(false);
|
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
$entry = new Entry();
|
||||||
$prevClass = $setting->class;
|
$settingFrame->add($entry);
|
||||||
|
$entry->setStyle(Label_Text::STYLE_TextValueSmall);
|
||||||
|
$entry->setX($width / 2 * 0.65);
|
||||||
|
$entry->setTextSize(1);
|
||||||
|
$entry->setSize($width * 0.3, $settingHeight * 0.9);
|
||||||
|
$entry->setName(self::ACTION_PREFIX_SETTING . $setting->index);
|
||||||
|
$entry->setDefault($setting->value);
|
||||||
|
}
|
||||||
|
|
||||||
$y -= $settingHeight;
|
$y -= $settingHeight;
|
||||||
if ($index % $pageMaxCount == $pageMaxCount - 1) {
|
if ($index % $pageMaxCount == $pageMaxCount - 1) {
|
||||||
unset($pageFrame);
|
$pageFrame = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
$index++;
|
$index++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $frame;
|
return $frame;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Save the Config Data
|
* Save the Config Data
|
||||||
*
|
*
|
||||||
* @param array $configData
|
* @param array $configData
|
||||||
* @param Player $player
|
* @param Player $player
|
||||||
*/
|
*/
|
||||||
public function saveConfigData(array $configData, Player $player) {
|
public function saveConfigData(array $configData, Player $player) {
|
||||||
@ -233,83 +308,100 @@ class ManiaControlSettings implements ConfiguratorMenu, CallbackListener {
|
|||||||
$this->maniaControl->authenticationManager->sendNotAllowed($player);
|
$this->maniaControl->authenticationManager->sendNotAllowed($player);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (!$configData[3] || strpos($configData[3][0]['Name'], self::ACTION_PREFIX_SETTING) !== 0) {
|
||||||
$prefix = explode(".", $configData[3][0]['Name']);
|
// TODO: improve needed, this won't save configData passed by boolean setting change
|
||||||
if ($prefix[0] != self::ACTION_PREFIX_SETTING) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$maniaControlSettings = $this->maniaControl->settingManager->getSettings();
|
$maniaControlSettings = $this->maniaControl->settingManager->getSettings();
|
||||||
|
|
||||||
$prefixLength = strlen(self::ACTION_PREFIX_SETTING);
|
$prefixLength = strlen(self::ACTION_PREFIX_SETTING);
|
||||||
|
|
||||||
foreach($configData[3] as $setting) {
|
foreach ($configData[3] as $setting) {
|
||||||
$settingName = substr($setting['Name'], $prefixLength + 1);
|
$settingName = substr($setting['Name'], $prefixLength);
|
||||||
|
|
||||||
$oldSetting = $maniaControlSettings[$settingName];
|
$oldSetting = $maniaControlSettings[$settingName];
|
||||||
if ($setting['Value'] == $oldSetting->value || $oldSetting->type == 'bool') {
|
if ($setting['Value'] == $oldSetting->value || $oldSetting->type == 'bool') {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->maniaControl->settingManager->setSetting($oldSetting->class, $oldSetting->setting, $setting['Value']);
|
$this->maniaControl->settingManager->setSetting($oldSetting->class, $oldSetting->setting, $setting['Value']);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Reopen the Menu
|
// Reopen the Menu
|
||||||
$menuId = $this->maniaControl->configurator->getMenuId($this->getTitle());
|
$menuId = $this->maniaControl->configurator->getMenuId($this->getTitle());
|
||||||
$this->maniaControl->configurator->reopenMenu($player, $menuId);
|
$this->maniaControl->configurator->reopenMenu($player, $menuId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle ManialinkPageAnswer Callback
|
* 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);
|
if ($actionId === self::ACTION_SETTINGCLASS_BACK) {
|
||||||
if (!$boolSetting) {
|
// Back to classes list
|
||||||
return;
|
$login = $callback[1][1];
|
||||||
|
$player = $this->maniaControl->playerManager->getPlayer($login);
|
||||||
|
unset($this->playersSettingCategoryOpened[$player->login]);
|
||||||
|
$menuId = $this->maniaControl->configurator->getMenuId($this);
|
||||||
|
$this->maniaControl->configurator->showMenu($player, $menuId);
|
||||||
|
}
|
||||||
|
else if (strpos($actionId, self::ACTION_SETTING_BOOL) === 0) {
|
||||||
|
// Bool setting change
|
||||||
|
$settingIndex = (int) substr($actionId, strlen(self::ACTION_SETTING_BOOL));
|
||||||
|
|
||||||
|
$login = $callback[1][1];
|
||||||
|
$player = $this->maniaControl->playerManager->getPlayer($login);
|
||||||
|
|
||||||
|
// Toggle the Boolean Setting
|
||||||
|
$this->toggleBooleanSetting($settingIndex, $player);
|
||||||
|
|
||||||
|
if ($callback[1][3]) {
|
||||||
|
// Save all Changes
|
||||||
|
$this->saveConfigData($callback[1], $player);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// Reopen menu directly
|
||||||
|
$menuId = $this->maniaControl->configurator->getMenuId($this);
|
||||||
|
$this->maniaControl->configurator->reopenMenu($player, $menuId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (strpos($actionId, self::ACTION_PREFIX_SETTINGCLASS) === 0) {
|
||||||
|
// Setting class selected
|
||||||
|
$settingClass = substr($actionId, strlen(self::ACTION_PREFIX_SETTINGCLASS));
|
||||||
|
|
||||||
|
$login = $callback[1][1];
|
||||||
|
$player = $this->maniaControl->playerManager->getPlayer($login);
|
||||||
|
|
||||||
|
$this->playersSettingCategoryOpened[$player->login] = $settingClass;
|
||||||
|
|
||||||
|
$menuId = $this->maniaControl->configurator->getMenuId($this);
|
||||||
|
$this->maniaControl->configurator->showMenu($player, $menuId);
|
||||||
}
|
}
|
||||||
|
|
||||||
$actionArray = explode(".", $actionId);
|
|
||||||
$setting = $actionArray[2];
|
|
||||||
|
|
||||||
$login = $callback[1][1];
|
|
||||||
$player = $this->maniaControl->playerManager->getPlayer($login);
|
|
||||||
|
|
||||||
// Toggle the Boolean Setting
|
|
||||||
$this->toggleBooleanSetting($setting, $player);
|
|
||||||
|
|
||||||
// Save all Changes
|
|
||||||
$this->saveConfigData($callback[1], $player);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Toggles a Boolean Value
|
* Toggles a Boolean Value
|
||||||
*
|
*
|
||||||
* @param $setting
|
* @param int $settingIndex
|
||||||
* @param Player $player
|
* @param Player $player
|
||||||
*/
|
*/
|
||||||
public function toggleBooleanSetting($setting, Player $player) {
|
public function toggleBooleanSetting($settingIndex, Player $player) {
|
||||||
if (!$this->maniaControl->authenticationManager->checkPermission($player, self::SETTING_PERMISSION_CHANGE_MC_SETTINGS)) {
|
if (!$this->maniaControl->authenticationManager->checkPermission($player, self::SETTING_PERMISSION_CHANGE_MC_SETTINGS)) {
|
||||||
$this->maniaControl->authenticationManager->sendNotAllowed($player);
|
$this->maniaControl->authenticationManager->sendNotAllowed($player);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$oldSetting = $this->maniaControl->settingManager->getSettingByIndex($setting);
|
$oldSetting = $this->maniaControl->settingManager->getSettingByIndex($settingIndex);
|
||||||
|
|
||||||
if (!isset($oldSetting)) {
|
if (!isset($oldSetting)) {
|
||||||
var_dump('no setting ' . $setting);
|
var_dump('no setting ' . $settingIndex);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Toggle value
|
// Toggle value
|
||||||
if ($oldSetting->value == "1") {
|
$this->maniaControl->settingManager->setSetting($oldSetting->class, $oldSetting->setting, !$oldSetting->value);
|
||||||
$this->maniaControl->settingManager->setSetting($oldSetting->class, $oldSetting->setting, "0");
|
|
||||||
} else {
|
|
||||||
$this->maniaControl->settingManager->setSetting($oldSetting->class, $oldSetting->setting, "1");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
|
||||||
|
@ -165,7 +165,7 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener {
|
|||||||
/**
|
/**
|
||||||
* @see \ManiaControl\Configurators\ConfiguratorMenu::getMenu()
|
* @see \ManiaControl\Configurators\ConfiguratorMenu::getMenu()
|
||||||
*/
|
*/
|
||||||
public function getMenu($width, $height, Script $script) {
|
public function getMenu($width, $height, Script $script, Player $player) {
|
||||||
$paging = new Paging();
|
$paging = new Paging();
|
||||||
$script->addFeature($paging);
|
$script->addFeature($paging);
|
||||||
$frame = new Frame();
|
$frame = new Frame();
|
||||||
@ -310,9 +310,7 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener {
|
|||||||
$this->maniaControl->authenticationManager->sendNotAllowed($player);
|
$this->maniaControl->authenticationManager->sendNotAllowed($player);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (!$configData[3] || strpos($configData[3][0]['Name'], self::ACTION_PREFIX_SETTING) !== 0) {
|
||||||
$prefix = explode(".", $configData[3][0]['Name']);
|
|
||||||
if ($prefix[0] != self::ACTION_PREFIX_SETTING) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -326,8 +324,6 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener {
|
|||||||
|
|
||||||
$newSettings = array();
|
$newSettings = array();
|
||||||
foreach($configData[3] as $setting) {
|
foreach($configData[3] as $setting) {
|
||||||
|
|
||||||
|
|
||||||
$settingName = substr($setting['Name'], $prefixLength + 1);
|
$settingName = substr($setting['Name'], $prefixLength + 1);
|
||||||
if (!isset($scriptSettings[$settingName])) {
|
if (!isset($scriptSettings[$settingName])) {
|
||||||
var_dump('no setting ' . $settingName);
|
var_dump('no setting ' . $settingName);
|
||||||
|
@ -137,7 +137,7 @@ class ServerSettings implements ConfiguratorMenu, CallbackListener {
|
|||||||
/**
|
/**
|
||||||
* @see \ManiaControl\Configurators\ConfiguratorMenu::getMenu()
|
* @see \ManiaControl\Configurators\ConfiguratorMenu::getMenu()
|
||||||
*/
|
*/
|
||||||
public function getMenu($width, $height, Script $script) {
|
public function getMenu($width, $height, Script $script, Player $player) {
|
||||||
$paging = new Paging();
|
$paging = new Paging();
|
||||||
$script->addFeature($paging);
|
$script->addFeature($paging);
|
||||||
$frame = new Frame();
|
$frame = new Frame();
|
||||||
@ -269,9 +269,7 @@ class ServerSettings implements ConfiguratorMenu, CallbackListener {
|
|||||||
$this->maniaControl->authenticationManager->sendNotAllowed($player);
|
$this->maniaControl->authenticationManager->sendNotAllowed($player);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (!$configData[3] || strpos($configData[3][0]['Name'], self::ACTION_PREFIX_SETTING) !== 0) {
|
||||||
$prefix = explode(".", $configData[3][0]['Name']);
|
|
||||||
if ($prefix[0] != self::ACTION_PREFIX_SETTING) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,7 +60,7 @@ class PluginInstallMenu implements CallbackListener, ConfiguratorMenu, Manialink
|
|||||||
* @param Script $script
|
* @param Script $script
|
||||||
* @return \FML\Controls\Frame
|
* @return \FML\Controls\Frame
|
||||||
*/
|
*/
|
||||||
public function getMenu($width, $height, Script $script) {
|
public function getMenu($width, $height, Script $script, Player $player) {
|
||||||
$paging = new Paging();
|
$paging = new Paging();
|
||||||
$script->addFeature($paging);
|
$script->addFeature($paging);
|
||||||
$frame = new Frame();
|
$frame = new Frame();
|
||||||
|
@ -81,7 +81,7 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAns
|
|||||||
/**
|
/**
|
||||||
* @see \ManiaControl\Configurators\ConfiguratorMenu::getMenu()
|
* @see \ManiaControl\Configurators\ConfiguratorMenu::getMenu()
|
||||||
*/
|
*/
|
||||||
public function getMenu($width, $height, Script $script) {
|
public function getMenu($width, $height, Script $script, Player $player) {
|
||||||
$paging = new Paging();
|
$paging = new Paging();
|
||||||
$script->addFeature($paging);
|
$script->addFeature($paging);
|
||||||
$frame = new Frame();
|
$frame = new Frame();
|
||||||
@ -360,9 +360,7 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAns
|
|||||||
$this->maniaControl->authenticationManager->sendNotAllowed($player);
|
$this->maniaControl->authenticationManager->sendNotAllowed($player);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (!$configData[3] || strpos($configData[3][0]['Name'], self::ACTION_PREFIX_SETTING) !== 0) {
|
||||||
$prefix = explode(".", $configData[3][0]['Name']);
|
|
||||||
if ($prefix[0] != self::ACTION_PREFIX_SETTING) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -300,8 +300,6 @@ class SettingManager implements CallbackListener {
|
|||||||
public function setSetting($object, $settingName, $value) {
|
public function setSetting($object, $settingName, $value) {
|
||||||
$className = $this->getClassName($object);
|
$className = $this->getClassName($object);
|
||||||
|
|
||||||
var_dump($className, $settingName, $value);
|
|
||||||
|
|
||||||
$mysqli = $this->maniaControl->database->mysqli;
|
$mysqli = $this->maniaControl->database->mysqli;
|
||||||
$settingQuery = "UPDATE `" . self::TABLE_SETTINGS . "`
|
$settingQuery = "UPDATE `" . self::TABLE_SETTINGS . "`
|
||||||
SET `value` = ?
|
SET `value` = ?
|
||||||
@ -403,7 +401,7 @@ class SettingManager implements CallbackListener {
|
|||||||
public function getSettingsByClass($object) {
|
public function getSettingsByClass($object) {
|
||||||
$className = $this->getClassName($object);
|
$className = $this->getClassName($object);
|
||||||
$mysqli = $this->maniaControl->database->mysqli;
|
$mysqli = $this->maniaControl->database->mysqli;
|
||||||
$query = "SELECT * FROM `" . self::TABLE_SETTINGS . "` WHERE `class`= '" . $mysqli->escape_string($className) . "'
|
$query = "SELECT * FROM `" . self::TABLE_SETTINGS . "` WHERE `class` = '" . $mysqli->escape_string($className) . "'
|
||||||
ORDER BY `setting` ASC;";
|
ORDER BY `setting` ASC;";
|
||||||
$result = $mysqli->query($query);
|
$result = $mysqli->query($query);
|
||||||
if ($mysqli->error) {
|
if ($mysqli->error) {
|
||||||
@ -445,7 +443,7 @@ class SettingManager implements CallbackListener {
|
|||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function getSettingClasses($hidePluginClasses = true) {
|
public function getSettingClasses($hidePluginClasses = false) {
|
||||||
$mysqli = $this->maniaControl->database->mysqli;
|
$mysqli = $this->maniaControl->database->mysqli;
|
||||||
$query = "SELECT DISTINCT `class` FROM `" . self::TABLE_SETTINGS . "`
|
$query = "SELECT DISTINCT `class` FROM `" . self::TABLE_SETTINGS . "`
|
||||||
ORDER BY `class` ASC;";
|
ORDER BY `class` ASC;";
|
||||||
|
Loading…
Reference in New Issue
Block a user