2013-12-04 00:40:37 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace ManiaControl\Plugins;
|
|
|
|
|
2014-06-15 03:15:06 +02:00
|
|
|
use FML\Components\CheckBox;
|
2014-06-15 03:23:44 +02:00
|
|
|
use FML\Components\ValuePicker;
|
2014-01-18 20:05:50 +01:00
|
|
|
use FML\Controls\Entry;
|
2013-12-04 00:40:37 +01:00
|
|
|
use FML\Controls\Frame;
|
2013-12-09 20:31:02 +01:00
|
|
|
use FML\Controls\Label;
|
2014-01-05 20:42:16 +01:00
|
|
|
use FML\Controls\Labels\Label_Button;
|
2013-12-09 20:31:02 +01:00
|
|
|
use FML\Controls\Labels\Label_Text;
|
2014-06-15 03:15:06 +02:00
|
|
|
use FML\Controls\Quad;
|
2014-04-16 01:22:31 +02:00
|
|
|
use FML\Controls\Quads\Quad_Icons128x128_1;
|
2014-05-02 17:40:47 +02:00
|
|
|
use FML\Controls\Quads\Quad_Icons128x32_1;
|
2013-12-12 19:41:37 +01:00
|
|
|
use FML\Controls\Quads\Quad_Icons64x64_1;
|
2014-04-27 16:22:12 +02:00
|
|
|
use FML\Script\Features\Paging;
|
2014-01-05 20:42:16 +01:00
|
|
|
use FML\Script\Script;
|
2014-01-31 16:55:01 +01:00
|
|
|
use ManiaControl\Admin\AuthenticationManager;
|
2013-12-12 19:41:37 +01:00
|
|
|
use ManiaControl\Callbacks\CallbackListener;
|
2014-01-05 20:42:16 +01:00
|
|
|
use ManiaControl\Callbacks\CallbackManager;
|
2014-07-25 15:45:10 +02:00
|
|
|
use ManiaControl\Configurator\ConfiguratorMenu;
|
2014-08-05 01:49:13 +02:00
|
|
|
use ManiaControl\Logger;
|
2014-01-05 20:42:16 +01:00
|
|
|
use ManiaControl\ManiaControl;
|
2014-01-18 21:05:45 +01:00
|
|
|
use ManiaControl\Manialinks\ManialinkPageAnswerListener;
|
2014-01-05 20:42:16 +01:00
|
|
|
use ManiaControl\Players\Player;
|
2014-05-13 14:32:30 +02:00
|
|
|
use ManiaControl\Settings\Setting;
|
2022-04-10 22:11:28 +02:00
|
|
|
use ManiaControl\Settings\SettingManager;
|
|
|
|
|
2013-12-04 00:40:37 +01:00
|
|
|
|
|
|
|
/**
|
2014-04-12 12:14:37 +02:00
|
|
|
* Configurator for enabling and disabling Plugins
|
2013-12-04 00:40:37 +01:00
|
|
|
*
|
2014-05-02 17:40:47 +02:00
|
|
|
* @author ManiaControl Team <mail@maniacontrol.com>
|
2020-01-22 10:39:35 +01:00
|
|
|
* @copyright 2014-2020 ManiaControl Team
|
2014-05-02 17:40:47 +02:00
|
|
|
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
2013-12-04 00:40:37 +01:00
|
|
|
*/
|
2014-01-18 21:05:45 +01:00
|
|
|
class PluginMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAnswerListener {
|
2014-04-12 12:14:37 +02:00
|
|
|
/*
|
2013-12-12 19:41:37 +01:00
|
|
|
* Constants
|
|
|
|
*/
|
2014-02-13 00:46:41 +01:00
|
|
|
const ACTION_PREFIX_ENABLEPLUGIN = 'PluginMenu.Enable.';
|
|
|
|
const ACTION_PREFIX_DISABLEPLUGIN = 'PluginMenu.Disable.';
|
|
|
|
const ACTION_PREFIX_SETTINGS = 'PluginMenu.Settings.';
|
2014-05-27 23:00:24 +02:00
|
|
|
const ACTION_PREFIX_SETTING = 'PluginMenuSetting.';
|
2022-04-10 22:11:28 +02:00
|
|
|
const ACTION_PREFIX_SETTING_LINK = 'PluginMenuSettingLink.';
|
|
|
|
const ACTION_PREFIX_MANAGE_SETTING_LINK = 'PluginMenu.ManageSettingsLink.';
|
2014-02-13 00:46:41 +01:00
|
|
|
const ACTION_BACK_TO_PLUGINS = 'PluginMenu.BackToPlugins';
|
2014-04-16 01:22:31 +02:00
|
|
|
const ACTION_PREFIX_UPDATEPLUGIN = 'PluginMenu.Update.';
|
2014-04-16 01:38:28 +02:00
|
|
|
const ACTION_UPDATEPLUGINS = 'PluginMenu.Update.All';
|
2014-01-31 16:55:01 +01:00
|
|
|
const SETTING_PERMISSION_CHANGE_PLUGIN_SETTINGS = 'Change Plugin Settings';
|
2023-08-14 22:32:48 +02:00
|
|
|
const SETTING_CHECK_UPDATE_WHEN_OPENING = 'Check update when opening the menu';
|
2014-05-09 20:11:48 +02:00
|
|
|
const CACHE_SETTING_CLASS = 'PluginMenuCache.SettingClass';
|
2014-01-18 21:05:45 +01:00
|
|
|
|
2014-04-12 12:14:37 +02:00
|
|
|
/*
|
2014-07-25 16:28:47 +02:00
|
|
|
* Private properties
|
2013-12-04 00:40:37 +01:00
|
|
|
*/
|
2014-08-02 22:31:46 +02:00
|
|
|
/** @var ManiaControl $maniaControl */
|
2013-12-04 00:40:37 +01:00
|
|
|
private $maniaControl = null;
|
|
|
|
|
|
|
|
/**
|
2014-08-03 01:34:18 +02:00
|
|
|
* Construct a new plugin menu instance
|
2013-12-04 00:40:37 +01:00
|
|
|
*
|
2013-12-31 14:50:28 +01:00
|
|
|
* @param ManiaControl $maniaControl
|
2013-12-04 00:40:37 +01:00
|
|
|
*/
|
|
|
|
public function __construct(ManiaControl $maniaControl) {
|
|
|
|
$this->maniaControl = $maniaControl;
|
2014-01-05 20:42:16 +01:00
|
|
|
|
2023-08-14 22:32:48 +02:00
|
|
|
// Settings
|
|
|
|
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_CHECK_UPDATE_WHEN_OPENING, true);
|
|
|
|
|
2014-08-03 01:34:18 +02:00
|
|
|
// Callbacks
|
2014-08-13 11:05:52 +02:00
|
|
|
$this->maniaControl->getCallbackManager()->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer');
|
|
|
|
$this->maniaControl->getManialinkManager()->registerManialinkPageAnswerListener(self::ACTION_BACK_TO_PLUGINS, $this, 'backToPlugins');
|
2014-08-03 01:34:18 +02:00
|
|
|
|
|
|
|
// Permissions
|
2014-08-13 11:05:52 +02:00
|
|
|
$this->maniaControl->getAuthenticationManager()->definePermissionLevel(self::SETTING_PERMISSION_CHANGE_PLUGIN_SETTINGS, AuthenticationManager::AUTH_LEVEL_SUPERADMIN);
|
2013-12-04 00:40:37 +01:00
|
|
|
}
|
|
|
|
|
2014-01-18 21:05:45 +01:00
|
|
|
/**
|
2017-03-25 18:40:15 +01:00
|
|
|
* @see \ManiaControl\Configurator\ConfiguratorMenu::getTitle()
|
2014-01-18 21:05:45 +01:00
|
|
|
*/
|
2014-07-24 23:15:25 +02:00
|
|
|
public static function getTitle() {
|
|
|
|
return 'Plugins';
|
2014-01-18 21:05:45 +01:00
|
|
|
}
|
|
|
|
|
2014-05-02 17:40:47 +02:00
|
|
|
/**
|
2014-07-25 16:28:47 +02:00
|
|
|
* Return back to the plugins overview page
|
2014-07-24 23:15:25 +02:00
|
|
|
*
|
|
|
|
* @param array $callback
|
|
|
|
* @param Player $player
|
2014-05-02 17:40:47 +02:00
|
|
|
*/
|
2014-07-24 23:15:25 +02:00
|
|
|
public function backToPlugins($callback, Player $player) {
|
|
|
|
$player->destroyCache($this, self::CACHE_SETTING_CLASS);
|
2014-08-13 11:05:52 +02:00
|
|
|
$this->maniaControl->getConfigurator()->showMenu($player, $this);
|
2014-05-02 17:40:47 +02:00
|
|
|
}
|
|
|
|
|
2013-12-04 00:40:37 +01:00
|
|
|
/**
|
2017-03-25 18:40:15 +01:00
|
|
|
* @see \ManiaControl\Configurator\ConfiguratorMenu::getMenu()
|
2013-12-04 00:40:37 +01:00
|
|
|
*/
|
2014-04-30 05:27:23 +02:00
|
|
|
public function getMenu($width, $height, Script $script, Player $player) {
|
2014-05-02 17:40:47 +02:00
|
|
|
$paging = new Paging();
|
|
|
|
$script->addFeature($paging);
|
|
|
|
$frame = new Frame();
|
2014-01-05 20:42:16 +01:00
|
|
|
|
2014-08-13 11:05:52 +02:00
|
|
|
$pluginClasses = $this->maniaControl->getPluginManager()->getPluginClasses();
|
2014-01-05 20:42:16 +01:00
|
|
|
|
2013-12-12 19:41:37 +01:00
|
|
|
// Config
|
2014-05-09 20:11:48 +02:00
|
|
|
$pagerSize = 9.;
|
|
|
|
$entryHeight = 5.;
|
2024-07-13 14:47:11 +02:00
|
|
|
$pageMaxCount = floor(($height - 16) / $entryHeight);
|
2014-01-05 20:42:16 +01:00
|
|
|
|
2013-12-12 19:41:37 +01:00
|
|
|
// Pagers
|
|
|
|
$pagerPrev = new Quad_Icons64x64_1();
|
2017-03-25 19:15:50 +01:00
|
|
|
$frame->addChild($pagerPrev);
|
2024-07-13 14:47:11 +02:00
|
|
|
$pagerPrev->setPosition($width * 0.5 - 12, $height * -0.5 + 5, 2);
|
2013-12-12 19:41:37 +01:00
|
|
|
$pagerPrev->setSize($pagerSize, $pagerSize);
|
|
|
|
$pagerPrev->setSubStyle(Quad_Icons64x64_1::SUBSTYLE_ArrowPrev);
|
2014-01-05 20:42:16 +01:00
|
|
|
|
2013-12-12 19:41:37 +01:00
|
|
|
$pagerNext = new Quad_Icons64x64_1();
|
2017-03-25 19:15:50 +01:00
|
|
|
$frame->addChild($pagerNext);
|
2024-07-13 14:47:11 +02:00
|
|
|
$pagerNext->setPosition($width * 0.5 - 5, $height * -0.5 + 5, 2);
|
2013-12-12 19:41:37 +01:00
|
|
|
$pagerNext->setSize($pagerSize, $pagerSize);
|
|
|
|
$pagerNext->setSubStyle(Quad_Icons64x64_1::SUBSTYLE_ArrowNext);
|
2014-01-05 20:42:16 +01:00
|
|
|
|
2017-03-25 18:40:15 +01:00
|
|
|
$paging->addButtonControl($pagerNext);
|
|
|
|
$paging->addButtonControl($pagerPrev);
|
2014-01-05 20:42:16 +01:00
|
|
|
|
2013-12-12 19:41:37 +01:00
|
|
|
$pageCountLabel = new Label_Text();
|
2017-03-25 19:15:50 +01:00
|
|
|
$frame->addChild($pageCountLabel);
|
|
|
|
$pageCountLabel->setHorizontalAlign($pageCountLabel::RIGHT);
|
2024-07-13 14:47:11 +02:00
|
|
|
$pageCountLabel->setPosition($width * 0.5 - 16, $height * -0.5 + 5, 1);
|
2013-12-12 19:41:37 +01:00
|
|
|
$pageCountLabel->setStyle($pageCountLabel::STYLE_TextTitle1);
|
|
|
|
$pageCountLabel->setTextSize(2);
|
2014-01-05 20:42:16 +01:00
|
|
|
|
2014-05-02 17:40:47 +02:00
|
|
|
$paging->setLabel($pageCountLabel);
|
2014-01-18 20:05:50 +01:00
|
|
|
|
2022-04-10 22:11:28 +02:00
|
|
|
$SubMenu = $player->getCache($this, self::CACHE_SETTING_CLASS);
|
|
|
|
if ($SubMenu) {
|
2014-05-09 20:11:48 +02:00
|
|
|
// Show Settings Menu
|
2022-04-10 22:11:28 +02:00
|
|
|
if (strpos($SubMenu, self::ACTION_PREFIX_SETTINGS) === 0) {
|
|
|
|
$settingClass = substr($SubMenu, strlen(self::ACTION_PREFIX_SETTINGS));
|
|
|
|
return $this->getPluginSettingsMenu($frame, $width, $height, $paging, $player, $settingClass);
|
|
|
|
} else if (strpos($SubMenu, self::ACTION_PREFIX_MANAGE_SETTING_LINK) === 0) {
|
|
|
|
$settingClass = substr($SubMenu, strlen(self::ACTION_PREFIX_MANAGE_SETTING_LINK));
|
|
|
|
return $this->getManageSettingsLink($frame, $width, $height, $paging, $player, $settingClass);
|
|
|
|
}
|
2014-01-18 20:05:50 +01:00
|
|
|
}
|
|
|
|
|
2014-05-09 20:11:48 +02:00
|
|
|
// Display normal Plugin List
|
2013-12-12 19:41:37 +01:00
|
|
|
// Plugin pages
|
2014-06-14 14:32:29 +02:00
|
|
|
$posY = 0.;
|
2023-08-14 22:32:48 +02:00
|
|
|
|
2023-09-08 14:55:38 +02:00
|
|
|
$pluginUpdates = null;
|
2023-08-14 22:32:48 +02:00
|
|
|
if ($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_CHECK_UPDATE_WHEN_OPENING)) {
|
|
|
|
$pluginUpdates = $this->maniaControl->getUpdateManager()->getPluginUpdateManager()->getPluginsUpdates();
|
|
|
|
}
|
2014-04-16 14:16:37 +02:00
|
|
|
|
2014-06-14 15:48:27 +02:00
|
|
|
usort($pluginClasses, function ($pluginClassA, $pluginClassB) {
|
|
|
|
/** @var Plugin $pluginClassA */
|
|
|
|
/** @var Plugin $pluginClassB */
|
|
|
|
return strcmp($pluginClassA::getName(), $pluginClassB::getName());
|
2014-05-01 14:41:07 +02:00
|
|
|
});
|
|
|
|
|
2024-07-13 14:47:11 +02:00
|
|
|
$repositionnedFrame = new Frame();
|
|
|
|
$frame->addChild($repositionnedFrame);
|
|
|
|
$repositionnedFrame->setPosition($width * -0.5, $height * 0.5);
|
|
|
|
|
|
|
|
$pagesFrame = new Frame();
|
|
|
|
$repositionnedFrame->addChild($pagesFrame);
|
|
|
|
$pagesFrame->setY(-1);
|
|
|
|
|
2024-07-14 15:25:20 +02:00
|
|
|
$descriptionLabel = new Label();
|
|
|
|
$repositionnedFrame->addChild($descriptionLabel);
|
|
|
|
$descriptionLabel->setAlign($descriptionLabel::LEFT, $descriptionLabel::TOP);
|
|
|
|
$descriptionLabel->setPosition(3, $height * -1 + 16);
|
|
|
|
$descriptionLabel->setSize($width - 30, 20);
|
|
|
|
$descriptionLabel->setTextSize(1);
|
|
|
|
$descriptionLabel->setTranslate(true);
|
|
|
|
$descriptionLabel->setVisible(false);
|
|
|
|
$descriptionLabel->setMaxLines(5);
|
|
|
|
$descriptionLabel->setLineSpacing(1);
|
|
|
|
|
|
|
|
$tooltip = new Label();
|
|
|
|
$repositionnedFrame->addChild($tooltip);
|
|
|
|
$tooltip->setAlign($descriptionLabel::LEFT, $descriptionLabel::TOP);
|
|
|
|
$tooltip->setPosition(3, $height * -1 + 5);
|
|
|
|
$tooltip->setSize($width - 30, 5);
|
|
|
|
$tooltip->setTextSize(1);
|
|
|
|
$tooltip->setTranslate(true);
|
|
|
|
$tooltip->setVisible(false);
|
|
|
|
|
2024-07-13 14:47:11 +02:00
|
|
|
$index = 0;
|
2014-05-11 15:28:53 +02:00
|
|
|
$pageFrame = null;
|
2024-07-13 14:47:11 +02:00
|
|
|
foreach ($pluginClasses as $pluginClass) {
|
2014-02-13 00:46:41 +01:00
|
|
|
/** @var Plugin $pluginClass */
|
2014-05-09 20:11:48 +02:00
|
|
|
if ($index % $pageMaxCount === 0) {
|
2013-12-09 20:31:02 +01:00
|
|
|
$pageFrame = new Frame();
|
2024-07-13 14:47:11 +02:00
|
|
|
$pagesFrame->addChild($pageFrame);
|
2017-03-25 18:40:15 +01:00
|
|
|
$paging->addPageControl($pageFrame);
|
2024-07-13 14:47:11 +02:00
|
|
|
$index = 1;
|
2013-12-09 20:31:02 +01:00
|
|
|
}
|
2014-01-05 20:42:16 +01:00
|
|
|
|
2014-08-13 11:05:52 +02:00
|
|
|
$active = $this->maniaControl->getPluginManager()->isPluginActive($pluginClass);
|
2014-01-05 20:42:16 +01:00
|
|
|
|
2013-12-12 19:41:37 +01:00
|
|
|
$pluginFrame = new Frame();
|
2017-03-25 19:15:50 +01:00
|
|
|
$pageFrame->addChild($pluginFrame);
|
2024-07-13 14:47:11 +02:00
|
|
|
$pluginFrame->setY($entryHeight * $index * -1);
|
2014-01-05 20:42:16 +01:00
|
|
|
|
2013-12-12 19:41:37 +01:00
|
|
|
$activeQuad = new Quad_Icons64x64_1();
|
2017-03-25 19:15:50 +01:00
|
|
|
$pluginFrame->addChild($activeQuad);
|
2024-07-14 15:25:20 +02:00
|
|
|
$activeQuad->setPosition(5, 0, 1);
|
2013-12-12 19:41:37 +01:00
|
|
|
$activeQuad->setSize($entryHeight * 0.9, $entryHeight * 0.9);
|
2014-02-13 00:46:41 +01:00
|
|
|
if ($active) {
|
2013-12-12 19:41:37 +01:00
|
|
|
$activeQuad->setSubStyle($activeQuad::SUBSTYLE_LvlGreen);
|
2014-01-05 20:42:16 +01:00
|
|
|
} else {
|
2013-12-12 19:41:37 +01:00
|
|
|
$activeQuad->setSubStyle($activeQuad::SUBSTYLE_LvlRed);
|
|
|
|
}
|
2014-01-05 20:42:16 +01:00
|
|
|
|
2013-12-12 19:41:37 +01:00
|
|
|
$nameLabel = new Label_Text();
|
2017-03-25 19:15:50 +01:00
|
|
|
$pluginFrame->addChild($nameLabel);
|
|
|
|
$nameLabel->setHorizontalAlign($nameLabel::LEFT);
|
2024-07-14 15:25:20 +02:00
|
|
|
$nameLabel->setX(7.5);
|
2024-07-13 14:47:11 +02:00
|
|
|
$nameLabel->setSize($width - 50, $entryHeight);
|
2013-12-12 19:41:37 +01:00
|
|
|
$nameLabel->setStyle($nameLabel::STYLE_TextCardSmall);
|
2014-05-09 20:11:48 +02:00
|
|
|
$nameLabel->setTextSize(2);
|
2013-12-12 19:41:37 +01:00
|
|
|
$nameLabel->setText($pluginClass::getName());
|
2014-01-05 20:42:16 +01:00
|
|
|
|
2013-12-12 19:41:37 +01:00
|
|
|
$description = "Author: {$pluginClass::getAuthor()}\nVersion: {$pluginClass::getVersion()}\nDesc: {$pluginClass::getDescription()}";
|
2024-07-14 15:25:20 +02:00
|
|
|
$nameLabel->addTooltipLabelFeature($descriptionLabel, $description);
|
2014-01-05 20:42:16 +01:00
|
|
|
|
2014-01-18 20:05:50 +01:00
|
|
|
$quad = new Quad_Icons128x32_1();
|
2017-03-25 19:15:50 +01:00
|
|
|
$pluginFrame->addChild($quad);
|
2014-01-18 20:05:50 +01:00
|
|
|
$quad->setSubStyle($quad::SUBSTYLE_Settings);
|
2024-07-14 15:25:20 +02:00
|
|
|
$quad->setX($width - 37);
|
2014-01-18 21:05:45 +01:00
|
|
|
$quad->setZ(1);
|
2014-01-18 20:05:50 +01:00
|
|
|
$quad->setSize(5, 5);
|
|
|
|
$quad->setAction(self::ACTION_PREFIX_SETTINGS . $pluginClass);
|
2024-07-14 15:25:20 +02:00
|
|
|
$quad->addTooltipLabelFeature($tooltip, "Open settings of ". $pluginClass::getName());
|
2014-01-18 20:05:50 +01:00
|
|
|
|
2013-12-12 19:41:37 +01:00
|
|
|
$statusChangeButton = new Label_Button();
|
2017-03-25 19:15:50 +01:00
|
|
|
$pluginFrame->addChild($statusChangeButton);
|
|
|
|
$statusChangeButton->setHorizontalAlign($statusChangeButton::RIGHT);
|
2024-07-13 14:47:11 +02:00
|
|
|
$statusChangeButton->setX($width - 6);
|
2024-07-14 15:25:20 +02:00
|
|
|
$statusChangeButton->setStyle($statusChangeButton::STYLE_CardButtonSmallS);
|
2014-02-13 00:46:41 +01:00
|
|
|
if ($active) {
|
2013-12-12 19:41:37 +01:00
|
|
|
$statusChangeButton->setText('Deactivate');
|
|
|
|
$statusChangeButton->setAction(self::ACTION_PREFIX_DISABLEPLUGIN . $pluginClass);
|
2024-07-14 15:25:20 +02:00
|
|
|
$statusChangeButton->addTooltipLabelFeature($tooltip, "Deactivate plugin ". $pluginClass::getName());
|
|
|
|
|
2014-01-05 20:42:16 +01:00
|
|
|
} else {
|
2013-12-12 19:41:37 +01:00
|
|
|
$statusChangeButton->setText('Activate');
|
|
|
|
$statusChangeButton->setAction(self::ACTION_PREFIX_ENABLEPLUGIN . $pluginClass);
|
2024-07-14 15:25:20 +02:00
|
|
|
$statusChangeButton->addTooltipLabelFeature($tooltip, "Activate plugin ". $pluginClass::getName());
|
2013-12-12 19:41:37 +01:00
|
|
|
}
|
2014-01-05 20:42:16 +01:00
|
|
|
|
2014-06-14 14:32:29 +02:00
|
|
|
if ($pluginUpdates && array_key_exists($pluginClass::getId(), $pluginUpdates)) {
|
2014-04-16 01:22:31 +02:00
|
|
|
$quadUpdate = new Quad_Icons128x128_1();
|
2017-03-25 19:15:50 +01:00
|
|
|
$pluginFrame->addChild($quadUpdate);
|
2014-04-16 01:22:31 +02:00
|
|
|
$quadUpdate->setSubStyle($quadUpdate::SUBSTYLE_ProfileVehicle);
|
2024-07-13 14:47:11 +02:00
|
|
|
$quadUpdate->setX($width - 3.5);
|
2014-04-16 01:22:31 +02:00
|
|
|
$quadUpdate->setZ(2);
|
|
|
|
$quadUpdate->setSize(5, 5);
|
|
|
|
$quadUpdate->setAction(self::ACTION_PREFIX_UPDATEPLUGIN . $pluginClass);
|
|
|
|
}
|
|
|
|
|
2024-07-13 14:47:11 +02:00
|
|
|
$index++;
|
2013-12-09 20:31:02 +01:00
|
|
|
}
|
2014-01-05 20:42:16 +01:00
|
|
|
|
2014-06-14 14:32:29 +02:00
|
|
|
if ($pluginUpdates) {
|
2014-04-16 01:42:40 +02:00
|
|
|
$updatePluginsButton = new Label_Button();
|
2017-03-25 19:15:50 +01:00
|
|
|
$frame->addChild($updatePluginsButton);
|
|
|
|
$updatePluginsButton->setHorizontalAlign($updatePluginsButton::RIGHT);
|
2023-09-08 16:00:30 +02:00
|
|
|
$updatePluginsButton->setPosition($width * 0.5, $height * -0.37, 2);
|
2014-04-16 14:16:37 +02:00
|
|
|
$updatePluginsButton->setWidth(10);
|
|
|
|
$updatePluginsButton->setStyle($updatePluginsButton::STYLE_CardButtonSmallS);
|
2014-05-02 17:40:47 +02:00
|
|
|
$updatePluginsButton->setText(count($pluginUpdates) . ' update(s)');
|
2014-04-16 01:42:40 +02:00
|
|
|
$updatePluginsButton->setAction(self::ACTION_UPDATEPLUGINS);
|
|
|
|
}
|
2014-04-16 01:38:28 +02:00
|
|
|
|
2013-12-04 00:40:37 +01:00
|
|
|
return $frame;
|
|
|
|
}
|
|
|
|
|
2014-05-09 20:11:48 +02:00
|
|
|
/**
|
|
|
|
* Get the Frame with the Plugin Settings
|
|
|
|
*
|
|
|
|
* @param Frame $frame
|
|
|
|
* @param float $width
|
|
|
|
* @param float $height
|
|
|
|
* @param Paging $paging
|
|
|
|
* @param Player $player
|
|
|
|
* @param string $settingClass
|
|
|
|
* @return Frame
|
|
|
|
*/
|
|
|
|
private function getPluginSettingsMenu(Frame $frame, $width, $height, Paging $paging, Player $player, $settingClass) {
|
2014-06-15 03:15:06 +02:00
|
|
|
// TODO: centralize menu code to use by mc settings and plugin settings
|
2014-08-13 11:05:52 +02:00
|
|
|
$settings = $this->maniaControl->getSettingManager()->getSettingsByClass($settingClass);
|
2022-04-10 22:11:28 +02:00
|
|
|
$isunlinkable = $this->maniaControl->getSettingManager()->getSettingValue($this->maniaControl->getSettingManager(), SettingManager::SETTING_ALLOW_UNLINK_SERVER);
|
2014-05-09 20:11:48 +02:00
|
|
|
|
2024-07-13 14:47:11 +02:00
|
|
|
$repositionnedFrame = new Frame();
|
|
|
|
$frame->addChild($repositionnedFrame);
|
|
|
|
$repositionnedFrame->setPosition($width * -0.5, $height * 0.5);
|
|
|
|
|
|
|
|
$pagesFrame = new Frame();
|
|
|
|
$repositionnedFrame->addChild($pagesFrame);
|
|
|
|
$pagesFrame->setY(-8.);
|
|
|
|
|
|
|
|
if ($isunlinkable) {
|
|
|
|
$pagesFrame->setX(5.); // move a bit the settings to diplay the padlocks
|
|
|
|
$innerWidth = $width - 6;
|
|
|
|
} else {
|
|
|
|
$pagesFrame->setX(2.);
|
|
|
|
$innerWidth = $width - 3;
|
|
|
|
}
|
|
|
|
|
|
|
|
$innerHeight = $height - 8 - 10;
|
|
|
|
$settingHeight = 5.;
|
2024-07-14 15:25:20 +02:00
|
|
|
$valueWidth = $innerWidth * 0.3;
|
2024-07-13 14:47:11 +02:00
|
|
|
$pageSettingsMaxCount = floor($innerHeight / $settingHeight);
|
|
|
|
$index = 0;
|
|
|
|
|
|
|
|
$pageFrame = null;
|
2014-05-11 15:28:53 +02:00
|
|
|
|
2014-06-15 03:15:06 +02:00
|
|
|
//Headline Label
|
|
|
|
$headLabel = new Label_Text();
|
2024-07-13 14:47:11 +02:00
|
|
|
$repositionnedFrame->addChild($headLabel);
|
2017-03-25 19:15:50 +01:00
|
|
|
$headLabel->setHorizontalAlign($headLabel::LEFT);
|
2024-07-13 14:47:11 +02:00
|
|
|
$headLabel->setPosition(3, -6);
|
|
|
|
$headLabel->setSize($width - 6, $settingHeight);
|
2014-06-15 03:15:06 +02:00
|
|
|
$headLabel->setStyle($headLabel::STYLE_TextCardSmall);
|
|
|
|
$headLabel->setTextSize(3);
|
|
|
|
$headLabel->setText($settingClass);
|
|
|
|
$headLabel->setTextColor('ff0');
|
|
|
|
|
2022-04-10 22:11:28 +02:00
|
|
|
if (count($settings) > 64) {
|
|
|
|
Logger::logWarning("You can't send more than 64 fields in Manialink Action");
|
|
|
|
$this->maniaControl->getChat()->sendError("Some settings may not be saved because it has more than 64", $player);
|
|
|
|
}
|
|
|
|
|
2014-05-09 20:11:48 +02:00
|
|
|
foreach ($settings as $setting) {
|
|
|
|
if ($index % $pageSettingsMaxCount === 0) {
|
|
|
|
$pageFrame = new Frame();
|
2024-07-13 14:47:11 +02:00
|
|
|
$pagesFrame->addChild($pageFrame);
|
2017-03-25 18:40:15 +01:00
|
|
|
$paging->addPageControl($pageFrame);
|
2024-07-13 14:47:11 +02:00
|
|
|
$index = 1;
|
2014-05-09 20:11:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$settingFrame = new Frame();
|
2017-03-25 19:15:50 +01:00
|
|
|
$pageFrame->addChild($settingFrame);
|
2024-07-13 14:47:11 +02:00
|
|
|
$settingFrame->setY($settingHeight * $index * -1);
|
2014-05-09 20:11:48 +02:00
|
|
|
|
|
|
|
$nameLabel = new Label_Text();
|
2017-03-25 19:15:50 +01:00
|
|
|
$settingFrame->addChild($nameLabel);
|
|
|
|
$nameLabel->setHorizontalAlign($nameLabel::LEFT);
|
2024-07-13 14:47:11 +02:00
|
|
|
$nameLabel->setSize($innerWidth * 0.6, $settingHeight);
|
2014-05-09 20:11:48 +02:00
|
|
|
$nameLabel->setStyle($nameLabel::STYLE_TextCardSmall);
|
|
|
|
$nameLabel->setTextSize(2);
|
|
|
|
$nameLabel->setText($setting->setting);
|
2014-06-22 19:02:18 +02:00
|
|
|
$nameLabel->setTextColor('fff');
|
2014-05-09 20:11:48 +02:00
|
|
|
|
2020-05-19 22:07:18 +02:00
|
|
|
$descriptionLabel = new Label_Text();
|
2024-07-13 14:47:11 +02:00
|
|
|
$repositionnedFrame->addChild($descriptionLabel);
|
2020-05-19 22:07:18 +02:00
|
|
|
$descriptionLabel->setHorizontalAlign($descriptionLabel::LEFT);
|
2024-07-13 14:47:11 +02:00
|
|
|
$descriptionLabel->setPosition(3, $height * -1 + 10);
|
|
|
|
$descriptionLabel->setSize($innerWidth - 6, $settingHeight);
|
|
|
|
$descriptionLabel->setTextSize(1);
|
2020-05-19 22:07:18 +02:00
|
|
|
$descriptionLabel->setTranslate(true);
|
|
|
|
$nameLabel->addTooltipLabelFeature($descriptionLabel, $setting->description);
|
|
|
|
|
2022-04-10 22:11:28 +02:00
|
|
|
if ($isunlinkable) {
|
|
|
|
$quadlink = new Quad();
|
|
|
|
$settingFrame->addChild($quadlink);
|
2024-07-13 14:47:11 +02:00
|
|
|
$quadlink->setPosition(-2, 0.2);
|
2022-04-10 22:11:28 +02:00
|
|
|
$quadlink->setSize(4, 4);
|
|
|
|
$quadlink->setColorize("ccccccaa");
|
|
|
|
$quadlink->setStyle("UICommon64_1");
|
|
|
|
$quadlink->setSubStyle("Padlock_light");
|
|
|
|
$quadlink->setStyleSelected($setting->linked);
|
|
|
|
}
|
|
|
|
|
2014-05-13 14:32:30 +02:00
|
|
|
if ($setting->type === Setting::TYPE_BOOL) {
|
2014-06-15 03:15:06 +02:00
|
|
|
// Boolean checkbox
|
|
|
|
$quad = new Quad();
|
2024-07-13 14:47:11 +02:00
|
|
|
$quad->setPosition($innerWidth - $valueWidth / 2, 0);
|
2014-05-09 20:11:48 +02:00
|
|
|
$quad->setSize(4, 4);
|
2014-06-15 03:15:06 +02:00
|
|
|
$checkBox = new CheckBox(self::ACTION_PREFIX_SETTING . $setting->index, $setting->value, $quad);
|
2017-03-25 19:15:50 +01:00
|
|
|
$settingFrame->addChild($checkBox);
|
2014-06-15 03:23:44 +02:00
|
|
|
} else if ($setting->type === Setting::TYPE_SET) {
|
|
|
|
// SET value picker
|
|
|
|
$label = new Label_Text();
|
2024-07-13 14:47:11 +02:00
|
|
|
$label->setPosition($innerWidth - $valueWidth / 2, 0);
|
|
|
|
$label->setSize($valueWidth, $settingHeight * 0.9);
|
2014-06-15 03:23:44 +02:00
|
|
|
$label->setStyle($label::STYLE_TextValueSmall);
|
|
|
|
$label->setTextSize(1);
|
|
|
|
$valuePicker = new ValuePicker(self::ACTION_PREFIX_SETTING . $setting->index, $setting->set, $setting->value, $label);
|
2017-03-25 19:15:50 +01:00
|
|
|
$settingFrame->addChild($valuePicker);
|
2014-06-15 03:15:06 +02:00
|
|
|
} else {
|
|
|
|
// Value entry
|
|
|
|
$entry = new Entry();
|
2017-03-25 19:15:50 +01:00
|
|
|
$settingFrame->addChild($entry);
|
2024-07-13 14:47:11 +02:00
|
|
|
$entry->setPosition($innerWidth - $valueWidth / 2, 0);
|
|
|
|
$entry->setSize($valueWidth, $settingHeight * 0.9);
|
2014-06-15 03:23:44 +02:00
|
|
|
$entry->setTextSize(1);
|
2023-07-10 17:12:57 +02:00
|
|
|
$entry->setMaxLength(1000);
|
2014-06-15 03:23:44 +02:00
|
|
|
$entry->setStyle(Label_Text::STYLE_TextValueSmall);
|
2014-06-15 03:15:06 +02:00
|
|
|
$entry->setName(self::ACTION_PREFIX_SETTING . $setting->index);
|
|
|
|
$entry->setDefault($setting->value);
|
2014-05-09 20:11:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$index++;
|
|
|
|
}
|
|
|
|
|
2014-06-22 19:02:18 +02:00
|
|
|
$backButton = new Label_Button();
|
2024-07-13 14:47:11 +02:00
|
|
|
$repositionnedFrame->addChild($backButton);
|
2014-06-22 19:02:18 +02:00
|
|
|
$backButton->setStyle($backButton::STYLE_CardMain_Quit);
|
2017-03-25 19:15:50 +01:00
|
|
|
$backButton->setHorizontalAlign($backButton::LEFT);
|
2020-05-19 22:07:18 +02:00
|
|
|
$backButton->setScale(0.5);
|
2014-06-22 19:02:18 +02:00
|
|
|
$backButton->setText('Back');
|
2024-07-13 14:47:11 +02:00
|
|
|
$backButton->setPosition(5 , $height * -1 + 5);
|
2014-06-22 19:02:18 +02:00
|
|
|
$backButton->setAction(self::ACTION_BACK_TO_PLUGINS);
|
2014-05-09 20:11:48 +02:00
|
|
|
|
2022-04-10 22:11:28 +02:00
|
|
|
if ($isunlinkable) {
|
|
|
|
$mapNameButton = $this->maniaControl->getManialinkManager()->getElementBuilder()->buildRoundTextButton(
|
|
|
|
'Manage settings link',
|
|
|
|
30,
|
|
|
|
5,
|
|
|
|
self::ACTION_PREFIX_MANAGE_SETTING_LINK . $settingClass
|
|
|
|
);
|
2024-07-13 14:47:11 +02:00
|
|
|
$repositionnedFrame->addChild($mapNameButton);
|
|
|
|
$mapNameButton->setPosition(60, $height * -1 + 5);
|
2022-04-10 22:11:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return $frame;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* getManageSettingsLink
|
|
|
|
*
|
|
|
|
* @param Frame $frame
|
|
|
|
* @param float $width
|
|
|
|
* @param float $height
|
|
|
|
* @param Paging $paging
|
|
|
|
* @param Player $player
|
|
|
|
* @param mixed $settingClass
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function getManageSettingsLink(Frame $frame, $width, $height, Paging $paging, Player $player, $settingClass) {
|
|
|
|
$settings = $this->maniaControl->getSettingManager()->getSettingsByClass($settingClass);
|
|
|
|
|
2024-07-13 14:47:11 +02:00
|
|
|
$repositionnedFrame = new Frame();
|
|
|
|
$frame->addChild($repositionnedFrame);
|
|
|
|
$repositionnedFrame->setPosition($width * -0.5, $height * 0.5);
|
|
|
|
|
|
|
|
$pagesFrame = new Frame();
|
|
|
|
$repositionnedFrame->addChild($pagesFrame);
|
|
|
|
$pagesFrame->setY(-8.);
|
|
|
|
$pagesFrame->setX(5.);
|
|
|
|
|
|
|
|
$innerWidth = $width - 6;
|
|
|
|
$innerHeight = $height - 8 - 10;
|
|
|
|
$settingHeight = 5.;
|
|
|
|
$pageSettingsMaxCount = floor($innerHeight / $settingHeight);
|
|
|
|
$index = 0;
|
|
|
|
|
2022-04-10 22:11:28 +02:00
|
|
|
$pageFrame = null;
|
|
|
|
|
|
|
|
if (count($settings) > 64) {
|
|
|
|
Logger::logWarning("You can't send more than 64 fields in Manialink Action");
|
|
|
|
$this->maniaControl->getChat()->sendError("Some settings may not be saved because it has more than 64", $player);
|
|
|
|
}
|
|
|
|
|
|
|
|
//Headline Label
|
|
|
|
$headLabel = new Label_Text();
|
2024-07-13 14:47:11 +02:00
|
|
|
$repositionnedFrame->addChild($headLabel);
|
2022-04-10 22:11:28 +02:00
|
|
|
$headLabel->setHorizontalAlign($headLabel::LEFT);
|
2024-07-13 14:47:11 +02:00
|
|
|
$headLabel->setPosition(3, -6);
|
|
|
|
$headLabel->setSize($width - 6, $settingHeight);
|
2022-04-10 22:11:28 +02:00
|
|
|
$headLabel->setStyle($headLabel::STYLE_TextCardSmall);
|
|
|
|
$headLabel->setTextSize(3);
|
|
|
|
$headLabel->setText($settingClass);
|
|
|
|
$headLabel->setTextColor('ff0');
|
|
|
|
|
|
|
|
foreach ($settings as $setting) {
|
|
|
|
if ($index % $pageSettingsMaxCount === 0) {
|
|
|
|
$pageFrame = new Frame();
|
2024-07-13 14:47:11 +02:00
|
|
|
$pagesFrame->addChild($pageFrame);
|
2022-04-10 22:11:28 +02:00
|
|
|
$paging->addPageControl($pageFrame);
|
2024-07-13 14:47:11 +02:00
|
|
|
$index = 1;
|
2022-04-10 22:11:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$settingFrame = new Frame();
|
|
|
|
$pageFrame->addChild($settingFrame);
|
2024-07-13 14:47:11 +02:00
|
|
|
$settingFrame->setY($settingHeight * $index * -1);
|
2022-04-10 22:11:28 +02:00
|
|
|
|
|
|
|
$nameLabel = new Label_Text();
|
|
|
|
$settingFrame->addChild($nameLabel);
|
|
|
|
$nameLabel->setHorizontalAlign($nameLabel::LEFT);
|
2024-07-13 14:47:11 +02:00
|
|
|
$nameLabel->setSize($innerWidth * 0.6, $settingHeight);
|
2022-04-10 22:11:28 +02:00
|
|
|
$nameLabel->setStyle($nameLabel::STYLE_TextCardSmall);
|
|
|
|
$nameLabel->setTextSize(2);
|
|
|
|
$nameLabel->setText($setting->setting);
|
|
|
|
$nameLabel->setTextColor('fff');
|
|
|
|
|
|
|
|
$descriptionLabel = new Label_Text();
|
2024-07-13 14:47:11 +02:00
|
|
|
$repositionnedFrame->addChild($descriptionLabel);
|
2022-04-10 22:11:28 +02:00
|
|
|
$descriptionLabel->setHorizontalAlign($descriptionLabel::LEFT);
|
2024-07-13 14:47:11 +02:00
|
|
|
$descriptionLabel->setPosition(3, $height * -1 + 10);
|
|
|
|
$descriptionLabel->setSize($innerWidth - 6, $settingHeight);
|
|
|
|
$descriptionLabel->setTextSize(1);
|
2022-04-10 22:11:28 +02:00
|
|
|
$descriptionLabel->setTranslate(true);
|
|
|
|
$nameLabel->addTooltipLabelFeature($descriptionLabel, $setting->description);
|
|
|
|
|
|
|
|
$quad = new Quad();
|
2024-07-13 14:47:11 +02:00
|
|
|
$quad->setPosition($innerWidth - $innerWidth * 0.3 / 2, 0.2);
|
2022-04-10 22:11:28 +02:00
|
|
|
$quad->setSize(4, 4);
|
|
|
|
$checkBox = new CheckBox(self::ACTION_PREFIX_SETTING_LINK . $setting->index, $setting->linked, $quad);
|
|
|
|
$checkBox->setEnabledDesign("UICommon64_1", "Padlock_light");
|
|
|
|
$checkBox->setDisabledDesign("UICommon64_1", "Padlock_light");
|
|
|
|
$settingFrame->addChild($checkBox);
|
|
|
|
|
|
|
|
$index++;
|
|
|
|
}
|
|
|
|
|
|
|
|
$backButton = new Label_Button();
|
2024-07-13 14:47:11 +02:00
|
|
|
$repositionnedFrame->addChild($backButton);
|
2022-04-10 22:11:28 +02:00
|
|
|
$backButton->setStyle($backButton::STYLE_CardMain_Quit);
|
|
|
|
$backButton->setHorizontalAlign($backButton::LEFT);
|
|
|
|
$backButton->setScale(0.5);
|
|
|
|
$backButton->setText('Back');
|
2024-07-13 14:47:11 +02:00
|
|
|
$backButton->setPosition(5 , $height * -1 + 5);
|
2022-04-10 22:11:28 +02:00
|
|
|
$backButton->setAction(self::ACTION_PREFIX_SETTINGS . $settingClass);
|
|
|
|
|
2014-05-09 20:11:48 +02:00
|
|
|
return $frame;
|
|
|
|
}
|
|
|
|
|
2013-12-12 19:41:37 +01:00
|
|
|
/**
|
|
|
|
* Handle PlayerManialinkPageAnswer callback
|
|
|
|
*
|
2013-12-31 14:50:28 +01:00
|
|
|
* @param array $callback
|
2013-12-12 19:41:37 +01:00
|
|
|
*/
|
|
|
|
public function handleManialinkPageAnswer(array $callback) {
|
2014-06-15 03:15:06 +02:00
|
|
|
$actionId = $callback[1][2];
|
|
|
|
$enable = (strpos($actionId, self::ACTION_PREFIX_ENABLEPLUGIN) === 0);
|
|
|
|
$disable = (strpos($actionId, self::ACTION_PREFIX_DISABLEPLUGIN) === 0);
|
|
|
|
$settings = (strpos($actionId, self::ACTION_PREFIX_SETTINGS) === 0);
|
2022-04-10 22:11:28 +02:00
|
|
|
$managelink = (strpos($actionId, self::ACTION_PREFIX_MANAGE_SETTING_LINK) === 0);
|
|
|
|
if (!$enable && !$disable && !$settings && !$managelink) {
|
2013-12-12 19:41:37 +01:00
|
|
|
return;
|
|
|
|
}
|
2014-05-09 19:40:20 +02:00
|
|
|
|
2017-05-12 21:06:43 +02:00
|
|
|
$login = $callback[1][1];
|
|
|
|
$player = $this->maniaControl->getPlayerManager()->getPlayer($login);
|
|
|
|
if (!$player) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-06-05 20:47:36 +02:00
|
|
|
if (!$this->maniaControl->getAuthenticationManager()->checkPermission($player, self::SETTING_PERMISSION_CHANGE_PLUGIN_SETTINGS))
|
|
|
|
{
|
|
|
|
$this->maniaControl->getAuthenticationManager()->sendNotAllowed($player);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-02-13 00:46:41 +01:00
|
|
|
if ($enable) {
|
2013-12-12 19:41:37 +01:00
|
|
|
$pluginClass = substr($actionId, strlen(self::ACTION_PREFIX_ENABLEPLUGIN));
|
2014-02-13 00:46:41 +01:00
|
|
|
/** @var Plugin $pluginClass */
|
2014-08-13 11:05:52 +02:00
|
|
|
$activated = $this->maniaControl->getPluginManager()->activatePlugin($pluginClass, $player->login);
|
2014-02-13 00:46:41 +01:00
|
|
|
if ($activated) {
|
2014-08-13 11:05:52 +02:00
|
|
|
$this->maniaControl->getChat()->sendSuccess($pluginClass::getName() . ' activated!', $player);
|
2014-08-05 02:08:41 +02:00
|
|
|
Logger::logInfo("{$player->login} activated '{$pluginClass}'!", true);
|
2014-01-05 20:42:16 +01:00
|
|
|
} else {
|
2014-08-13 11:05:52 +02:00
|
|
|
$this->maniaControl->getChat()->sendError('Error activating ' . $pluginClass::getName() . '!', $player);
|
2013-12-14 23:33:23 +01:00
|
|
|
}
|
2014-02-13 00:46:41 +01:00
|
|
|
} else if ($disable) {
|
2013-12-12 19:41:37 +01:00
|
|
|
$pluginClass = substr($actionId, strlen(self::ACTION_PREFIX_DISABLEPLUGIN));
|
2014-02-13 00:46:41 +01:00
|
|
|
/** @var Plugin $pluginClass */
|
2014-08-13 11:05:52 +02:00
|
|
|
$deactivated = $this->maniaControl->getPluginManager()->deactivatePlugin($pluginClass);
|
2014-02-13 00:46:41 +01:00
|
|
|
if ($deactivated) {
|
2014-08-13 11:05:52 +02:00
|
|
|
$this->maniaControl->getChat()->sendSuccess($pluginClass::getName() . ' deactivated!', $player);
|
2014-08-05 02:08:41 +02:00
|
|
|
Logger::logInfo("{$player->login} deactivated '{$pluginClass}'!", true);
|
2014-01-05 20:42:16 +01:00
|
|
|
} else {
|
2014-08-13 11:05:52 +02:00
|
|
|
$this->maniaControl->getChat()->sendError('Error deactivating ' . $pluginClass::getName() . '!', $player);
|
2013-12-14 23:33:23 +01:00
|
|
|
}
|
2022-04-10 22:11:28 +02:00
|
|
|
} else if ($settings || $managelink) {
|
2014-05-09 19:40:20 +02:00
|
|
|
// Open Settings Menu
|
2022-04-10 22:11:28 +02:00
|
|
|
$player->setCache($this, self::CACHE_SETTING_CLASS, $actionId);
|
2013-12-12 19:41:37 +01:00
|
|
|
}
|
2014-01-05 20:42:16 +01:00
|
|
|
|
2014-05-09 19:40:20 +02:00
|
|
|
// Reopen the Menu
|
2014-08-13 11:05:52 +02:00
|
|
|
$this->maniaControl->getConfigurator()->showMenu($player, $this);
|
2013-12-12 19:41:37 +01:00
|
|
|
}
|
2014-01-18 20:05:50 +01:00
|
|
|
|
2014-05-02 17:40:47 +02:00
|
|
|
/**
|
2017-03-25 18:40:15 +01:00
|
|
|
* @see \ManiaControl\Configurator\ConfiguratorMenu::saveConfigData()
|
2014-05-02 17:40:47 +02:00
|
|
|
*/
|
|
|
|
public function saveConfigData(array $configData, Player $player) {
|
2014-08-13 11:05:52 +02:00
|
|
|
if (!$this->maniaControl->getAuthenticationManager()->checkPermission($player, self::SETTING_PERMISSION_CHANGE_PLUGIN_SETTINGS)
|
2014-08-05 02:17:41 +02:00
|
|
|
) {
|
2014-08-13 11:05:52 +02:00
|
|
|
$this->maniaControl->getAuthenticationManager()->sendNotAllowed($player);
|
2014-05-02 17:40:47 +02:00
|
|
|
return;
|
|
|
|
}
|
2022-04-10 22:11:28 +02:00
|
|
|
|
|
|
|
if (!$configData[3] || (strpos($configData[3][0]['Name'], self::ACTION_PREFIX_SETTING) !== 0 && strpos($configData[3][0]['Name'], self::ACTION_PREFIX_SETTING_LINK) !== 0)) {
|
2014-05-02 17:40:47 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-06-15 03:23:44 +02:00
|
|
|
foreach ($configData[3] as $settingData) {
|
2022-04-10 22:11:28 +02:00
|
|
|
if (!$settingData || !isset($settingData['Value'])) {
|
2014-05-02 17:40:47 +02:00
|
|
|
continue;
|
|
|
|
}
|
2022-04-10 22:11:28 +02:00
|
|
|
$data = explode(".", $settingData["Name"]);
|
|
|
|
$type = $data[0];
|
|
|
|
$index = $data[1];
|
2014-05-02 17:40:47 +02:00
|
|
|
|
2022-04-10 22:11:28 +02:00
|
|
|
$settingObjectByIndex = $this->maniaControl->getSettingManager()->getSettingObjectByIndex($index);
|
|
|
|
if (!$settingObjectByIndex) {
|
2014-05-02 17:40:47 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2022-04-10 22:11:28 +02:00
|
|
|
if ($type . "." == self::ACTION_PREFIX_SETTING_LINK) {
|
|
|
|
if ($settingData['Value'] && !$settingObjectByIndex->linked) {
|
|
|
|
$this->maniaControl->getSettingManager()->deleteSettingUnlinked($settingObjectByIndex);
|
|
|
|
$setting = $this->maniaControl->getSettingManager()->getSettingObject($settingObjectByIndex->class, $settingObjectByIndex->setting);
|
|
|
|
$setting->linked = True;
|
|
|
|
} else if (!$settingData['Value'] && $settingObjectByIndex->linked) {
|
|
|
|
$setting = $settingObjectByIndex;
|
|
|
|
$setting->linked = false;
|
|
|
|
$this->maniaControl->getSettingManager()->setSettingUnlinked($setting);
|
|
|
|
} else {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$setting = $settingObjectByIndex;
|
|
|
|
if ($settingData['Value'] == $setting->value) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$setting->value = $settingData['Value'];
|
|
|
|
}
|
|
|
|
$this->maniaControl->getSettingManager()->saveSetting($setting);
|
2014-05-02 17:40:47 +02:00
|
|
|
}
|
|
|
|
|
2014-08-13 11:05:52 +02:00
|
|
|
$this->maniaControl->getChat()->sendSuccess('Plugin Settings saved!', $player);
|
2014-05-16 20:42:37 +02:00
|
|
|
|
2014-06-15 03:23:44 +02:00
|
|
|
// Reopen the Menu
|
2014-08-13 11:05:52 +02:00
|
|
|
$this->maniaControl->getConfigurator()->showMenu($player, $this);
|
2014-05-02 17:40:47 +02:00
|
|
|
}
|
2013-12-04 00:40:37 +01:00
|
|
|
}
|