completely rework Admin UI plugin
This commit is contained in:
		| @@ -6,31 +6,20 @@ use FML\Controls\Frame; | |||||||
| use FML\Controls\Label; | use FML\Controls\Label; | ||||||
| use FML\Controls\Quad; | use FML\Controls\Quad; | ||||||
| use FML\ManiaLink; | use FML\ManiaLink; | ||||||
|  | use ManiaControl\Admin\AuthenticationManager; | ||||||
| use ManiaControl\Manialinks\ManialinkManager; | use ManiaControl\Manialinks\ManialinkManager; | ||||||
| use ManiaControl\Manialinks\ManialinkPageAnswerListener; | use ManiaControl\Manialinks\ManialinkPageAnswerListener; | ||||||
|  |  | ||||||
| use ManiaControl\Callbacks\CallbackListener; | use ManiaControl\Callbacks\CallbackListener; | ||||||
| use ManiaControl\Logger; |  | ||||||
| use ManiaControl\ManiaControl; | use ManiaControl\ManiaControl; | ||||||
| use ManiaControl\Plugins\Plugin; | use ManiaControl\Plugins\Plugin; | ||||||
| use ManiaControl\Plugins\PluginManager; |  | ||||||
| use ManiaControl\Plugins\PluginMenu; |  | ||||||
| use ManiaControl\Settings\Setting; | use ManiaControl\Settings\Setting; | ||||||
| use ManiaControl\Settings\SettingManager; | use ManiaControl\Settings\SettingManager; | ||||||
| use ManiaControl\Callbacks\TimerListener; | use ManiaControl\Callbacks\TimerListener; | ||||||
| use ManiaControl\Callbacks\Callbacks; | use ManiaControl\Callbacks\Callbacks; | ||||||
| use ManiaControl\Callbacks\CallbackManager; |  | ||||||
|  |  | ||||||
| use ManiaControl\Players\Player; | use ManiaControl\Players\Player; | ||||||
| use ManiaControl\Players\PlayerManager; | use ManiaControl\Players\PlayerManager; | ||||||
|  |  | ||||||
| if (!class_exists('MatchManagerSuite\MatchManagerCore')) { |  | ||||||
| 	$this->maniaControl->getChat()->sendErrorToAdmins('MatchManager Core is required to use one of MatchManager plugin. Install it and restart Maniacontrol'); |  | ||||||
| 	Logger::logError('MatchManager Core is required to use one of MatchManager plugin. Install it and restart Maniacontrol'); |  | ||||||
| 	return false; |  | ||||||
| } |  | ||||||
|  |  | ||||||
| /** | /** | ||||||
|  * MatchManager Admin UI |  * MatchManager Admin UI | ||||||
|  * |  * | ||||||
| @@ -42,38 +31,29 @@ class MatchManagerAdminUI implements CallbackListener, ManialinkPageAnswerListen | |||||||
| 	 * Constants | 	 * Constants | ||||||
| 	 */ | 	 */ | ||||||
| 	const PLUGIN_ID											= 174; | 	const PLUGIN_ID											= 174; | ||||||
| 	const PLUGIN_VERSION									= 1.2; | 	const PLUGIN_VERSION									= 2.0; | ||||||
| 	const PLUGIN_NAME										= 'MatchManager Admin UI'; | 	const PLUGIN_NAME										= 'MatchManager Admin UI'; | ||||||
| 	const PLUGIN_AUTHOR										= 'Beu'; | 	const PLUGIN_AUTHOR										= 'Beu'; | ||||||
|  |  | ||||||
| 	const MLID_ADMINUI_SIDEMENU	 							= 'Matchmanager.AdminUI'; | 	const MLID_ADMINUI_SIDEMENU	 							= 'Matchmanager.AdminUI'; | ||||||
|  |  | ||||||
| 	const ML_ACTION_CORE_MANAGESETTINGS						= 'MatchManager.AdminUI.ManageSettings'; |  | ||||||
| 	const ML_ACTION_CORE_STOPMATCH							= 'MatchManager.AdminUI.StopMatch'; |  | ||||||
| 	const ML_ACTION_CORE_PAUSEMATCH							= 'MatchManager.AdminUI.PauseMatch'; |  | ||||||
| 	const ML_ACTION_CORE_SKIPROUND							= 'MatchManager.AdminUI.SkipRound'; |  | ||||||
| 	const ML_ACTION_CORE_STARTMATCH							= 'MatchManager.AdminUI.StartMatch'; |  | ||||||
| 	const ML_ACTION_MULTIPLECONFIGMANAGER_OPENCONFIGMANAGER	= 'MatchManager.AdminUI.OpenConfigManager'; |  | ||||||
| 	const ML_ACTION_GSHEET_MANAGESETTINGS					= 'MatchManager.AdminUI.ManageGSheet'; |  | ||||||
|  |  | ||||||
|  |  | ||||||
| 	const SETTING_POSX										= 'Position X of the plugin'; | 	const SETTING_POSX										= 'Position X of the plugin'; | ||||||
| 	const SETTING_POSY										= 'Position Y of the plugin'; | 	const SETTING_POSY										= 'Position Y of the plugin'; | ||||||
|  | 	const SETTING_ADMIN_LEVEL 								= 'Minimum Admin level to see the Admin UI'; | ||||||
|  |  | ||||||
| 	// MatchManagerWidget Properties | 	const ML_ITEM_SIZE 		= 6.; | ||||||
| 	const MATCHMANAGERCORE_PLUGIN							= 'MatchManagerSuite\MatchManagerCore'; |  | ||||||
| 	const MATCHMANAGERGSHEET_PLUGIN							= 'MatchManagerSuite\MatchManagerGSheet'; |  | ||||||
| 	const MATCHMANAGERMULTIPLECONFIGMANAGER_PLUGIN			= 'MatchManagerSuite\MatchManagerMultipleConfigManager'; |  | ||||||
|  |  | ||||||
| 	/* | 	/* | ||||||
| 	 * Private properties | 	 * Private properties | ||||||
| 	 */ | 	 */ | ||||||
| 	/** @var ManiaControl $maniaControl */ | 	/** @var ManiaControl $maniaControl */ | ||||||
| 	private $maniaControl 			= null; | 	private $maniaControl 			= null; | ||||||
| 	/** @var \MatchManagerSuite\MatchManagerCore */ |  | ||||||
| 	private $MatchManagerCore 		= null; |  | ||||||
|  |  | ||||||
| 	private $manialink 				= null; | 	private $manialink 				= null; | ||||||
|  | 	private $updateManialink 		= true; | ||||||
|  |  | ||||||
|  | 	/** @var MatchManagerAdminUI_MenuItem[] */ | ||||||
|  | 	private $menuItems					= []; | ||||||
|  |  | ||||||
| 	/** | 	/** | ||||||
| 	 * @param \ManiaControl\ManiaControl $maniaControl | 	 * @param \ManiaControl\ManiaControl $maniaControl | ||||||
| @@ -125,15 +105,14 @@ class MatchManagerAdminUI implements CallbackListener, ManialinkPageAnswerListen | |||||||
| 	public function load(ManiaControl $maniaControl) { | 	public function load(ManiaControl $maniaControl) { | ||||||
| 		// Init plugin | 		// Init plugin | ||||||
| 		$this->maniaControl = $maniaControl; | 		$this->maniaControl = $maniaControl; | ||||||
| 		if (!$this->maniaControl->getPluginManager()->getSavedPluginStatus(self::MATCHMANAGERCORE_PLUGIN)) { |  | ||||||
| 			throw new \Exception('MatchManager Core is needed to use ' . self::PLUGIN_NAME); |  | ||||||
| 		} |  | ||||||
| 		 | 		 | ||||||
| 		// All callbacks are loaded in handleAfterInit | 		$this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::AFTERLOOP, $this, 'handleAfterLoop'); | ||||||
| 		$this->maniaControl->getTimerManager()->registerOneTimeListening($this, 'afterPluginInit', 1); | 		$this->maniaControl->getCallbackManager()->registerCallbackListener(SettingManager::CB_SETTING_CHANGED, $this, 'updateSettings'); | ||||||
|  | 		$this->maniaControl->getCallbackManager()->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerConnect'); | ||||||
|  |  | ||||||
| 		$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_POSX, 156., ""); | 		$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_POSX, 156., ""); | ||||||
| 		$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_POSY, 24., ""); | 		$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_POSY, 24., ""); | ||||||
|  | 		$this->maniaControl->getAuthenticationManager()->definePluginPermissionLevel($this, self::SETTING_ADMIN_LEVEL, AuthenticationManager::AUTH_LEVEL_ADMIN); | ||||||
|  |  | ||||||
| 		return true; | 		return true; | ||||||
| 	} | 	} | ||||||
| @@ -147,33 +126,14 @@ class MatchManagerAdminUI implements CallbackListener, ManialinkPageAnswerListen | |||||||
|  |  | ||||||
| 	/** | 	/** | ||||||
| 	 * afterPluginInit | 	 * afterPluginInit | ||||||
| 	 * Plugins are loaded alphabetically, so we have to we wait they are all loaded before check. |  | ||||||
| 	 * We can't use AFTER_INIT Callback to make it visible when enabled manually |  | ||||||
| 	 * | 	 * | ||||||
| 	 * @return void  | 	 * @return void  | ||||||
| 	 */ | 	 */ | ||||||
| 	public function afterPluginInit() { | 	public function handleAfterLoop() { | ||||||
| 		$this->MatchManagerCore = $this->maniaControl->getPluginManager()->getPlugin(self::MATCHMANAGERCORE_PLUGIN); | 		if ($this->updateManialink) { | ||||||
| 		if ($this->MatchManagerCore === null) { | 			$this->updateManialink = false; | ||||||
| 			$this->maniaControl->getChat()->sendErrorToAdmins('MatchManager Core is needed to use ' . self::PLUGIN_NAME . ' plugin.'); |  | ||||||
| 			$this->maniaControl->getPluginManager()->deactivatePlugin((get_class())); |  | ||||||
| 			return; |  | ||||||
| 		} |  | ||||||
|  |  | ||||||
| 			$this->generateManialink(); | 			$this->generateManialink(); | ||||||
| 		$this->displayManialink(); | 		} | ||||||
|  |  | ||||||
| 		$this->maniaControl->getCallbackManager()->registerCallbackListener(PluginManager::CB_PLUGIN_LOADED, $this, 'handlePluginLoaded'); |  | ||||||
| 		$this->maniaControl->getCallbackManager()->registerCallbackListener(PluginManager::CB_PLUGIN_UNLOADED, $this, 'handlePluginUnloaded'); |  | ||||||
| 		$this->maniaControl->getCallbackManager()->registerCallbackListener(SettingManager::CB_SETTING_CHANGED, $this, 'updateSettings'); |  | ||||||
| 		$this->maniaControl->getCallbackManager()->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerConnect'); |  | ||||||
|  |  | ||||||
| 		$this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::MP_STARTMATCHSTART, $this, 'generateManialink'); |  | ||||||
| 		$this->maniaControl->getCallbackManager()->registerCallbackListener(MatchManagerCore::CB_MATCHMANAGER_STARTMATCH, $this, 'generateManialink'); |  | ||||||
| 		$this->maniaControl->getCallbackManager()->registerCallbackListener(MatchManagerCore::CB_MATCHMANAGER_ENDMATCH, $this, 'generateManialink'); |  | ||||||
| 		$this->maniaControl->getCallbackManager()->registerCallbackListener(MatchManagerCore::CB_MATCHMANAGER_STOPMATCH, $this, 'generateManialink'); |  | ||||||
|  |  | ||||||
| 		$this->maniaControl->getCallbackManager()->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer'); |  | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	/** | 	/** | ||||||
| @@ -183,7 +143,7 @@ class MatchManagerAdminUI implements CallbackListener, ManialinkPageAnswerListen | |||||||
| 	 */ | 	 */ | ||||||
| 	public function updateSettings(Setting $setting) { | 	public function updateSettings(Setting $setting) { | ||||||
| 		if ($setting->belongsToClass($this)) { | 		if ($setting->belongsToClass($this)) { | ||||||
| 			$this->generateManialink(); | 			$this->updateManialink = true; | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| @@ -193,8 +153,9 @@ class MatchManagerAdminUI implements CallbackListener, ManialinkPageAnswerListen | |||||||
| 	 * @param Player $player | 	 * @param Player $player | ||||||
| 	 */ | 	 */ | ||||||
| 	public function handlePlayerConnect(Player $player) { | 	public function handlePlayerConnect(Player $player) { | ||||||
| 		if ($player->authLevel > 0) { | 		$authLevel = $this->maniaControl->getAuthenticationManager()->getAuthLevelInt($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_ADMIN_LEVEL)); | ||||||
| 			$this->maniaControl->getManialinkManager()->sendManialink($this->manialink,$player->login); | 		if ($this->maniaControl->getAuthenticationManager()->checkRight($player, $authLevel)) { | ||||||
|  | 			$this->maniaControl->getManialinkManager()->sendManialink($this->manialink, $player->login); | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 	 | 	 | ||||||
| @@ -204,82 +165,19 @@ class MatchManagerAdminUI implements CallbackListener, ManialinkPageAnswerListen | |||||||
| 	 * @return void | 	 * @return void | ||||||
| 	 */ | 	 */ | ||||||
| 	private function displayManialink() { | 	private function displayManialink() { | ||||||
| 		$admins = $this->maniaControl->getAuthenticationManager()->getAdmins(); | 		$authLevel = $this->maniaControl->getAuthenticationManager()->getAuthLevelInt($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_ADMIN_LEVEL)); | ||||||
| 		if (!empty($admins)) { | 		$admins = $this->maniaControl->getAuthenticationManager()->getAdmins($authLevel); | ||||||
|  | 		if (count($admins) > 0) { | ||||||
| 			$this->maniaControl->getManialinkManager()->sendManialink($this->manialink, $admins); | 			$this->maniaControl->getManialinkManager()->sendManialink($this->manialink, $admins); | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 	 | 	 | ||||||
| 	/** |  | ||||||
| 	 * handleManialinkPageAnswer |  | ||||||
| 	 * |  | ||||||
| 	 * @param  array $callback |  | ||||||
| 	 * @return void |  | ||||||
| 	 */ |  | ||||||
| 	public function handleManialinkPageAnswer(array $callback) { |  | ||||||
| 		$actionId    = $callback[1][2]; |  | ||||||
| 		$actionArray = explode('.', $actionId); |  | ||||||
| 		if ($actionArray[0] != "MatchManager" || $actionArray[1] != "AdminUI") { |  | ||||||
| 			return; |  | ||||||
| 		} |  | ||||||
|  |  | ||||||
| 		$login = $callback[1][1]; |  | ||||||
| 		$player = $this->maniaControl->getPlayerManager()->getPlayer($login); |  | ||||||
| 		if ($player->authLevel <= 0) { |  | ||||||
| 			return; |  | ||||||
| 		} |  | ||||||
|  |  | ||||||
| 		switch ($actionId) { |  | ||||||
| 			case self::ML_ACTION_CORE_MANAGESETTINGS: |  | ||||||
| 				$pluginMenu = $this->maniaControl->getPluginManager()->getPluginMenu(); |  | ||||||
| 				if (defined("\ManiaControl\ManiaControl::ISTRACKMANIACONTROL")) { |  | ||||||
| 					$player->setCache($pluginMenu, PluginMenu::CACHE_SETTING_CLASS, "PluginMenu.Settings." . self::MATCHMANAGERCORE_PLUGIN); |  | ||||||
| 				} else { |  | ||||||
| 					$player->setCache($pluginMenu, PluginMenu::CACHE_SETTING_CLASS, self::MATCHMANAGERCORE_PLUGIN); |  | ||||||
| 				} |  | ||||||
| 				$this->maniaControl->getConfigurator()->showMenu($player, $pluginMenu); |  | ||||||
| 				break; |  | ||||||
| 			case self::ML_ACTION_CORE_STOPMATCH: |  | ||||||
| 				$this->MatchManagerCore->MatchStop(); |  | ||||||
| 				break; |  | ||||||
| 			case self::ML_ACTION_CORE_PAUSEMATCH: |  | ||||||
| 				$this->MatchManagerCore->setNadeoPause(); |  | ||||||
| 				break; |  | ||||||
| 			case self::ML_ACTION_CORE_SKIPROUND: |  | ||||||
| 				$this->MatchManagerCore->onCommandMatchEndWU(array(), $player);  |  | ||||||
| 				$this->MatchManagerCore->onCommandUnsetPause(array(), $player);  |  | ||||||
| 				$this->MatchManagerCore->onCommandMatchEndRound(array(), $player);  |  | ||||||
| 				break; |  | ||||||
| 			case self::ML_ACTION_CORE_STARTMATCH: |  | ||||||
| 				$this->MatchManagerCore->MatchStart(); |  | ||||||
| 				break; |  | ||||||
| 			case self::ML_ACTION_MULTIPLECONFIGMANAGER_OPENCONFIGMANAGER: |  | ||||||
| 				/** @var \MatchManagerSuite\MatchManagerMultipleConfigManager */ |  | ||||||
| 				$MatchManagerMultipleConfigManager = $this->maniaControl->getPluginManager()->getPlugin(self::MATCHMANAGERMULTIPLECONFIGMANAGER_PLUGIN); |  | ||||||
| 				if ($MatchManagerMultipleConfigManager !== null) { |  | ||||||
| 					$MatchManagerMultipleConfigManager->showConfigListUI(array(), $player); |  | ||||||
| 				} |  | ||||||
| 				break; |  | ||||||
| 			case self::ML_ACTION_GSHEET_MANAGESETTINGS: |  | ||||||
| 				$pluginMenu = $this->maniaControl->getPluginManager()->getPluginMenu(); |  | ||||||
| 				if (defined("\ManiaControl\ManiaControl::ISTRACKMANIACONTROL")) { |  | ||||||
| 					$player->setCache($pluginMenu, PluginMenu::CACHE_SETTING_CLASS, "PluginMenu.Settings." . self::MATCHMANAGERGSHEET_PLUGIN); |  | ||||||
| 				} else { |  | ||||||
| 					$player->setCache($pluginMenu, PluginMenu::CACHE_SETTING_CLASS, self::MATCHMANAGERGSHEET_PLUGIN); |  | ||||||
| 				} |  | ||||||
| 				$this->maniaControl->getConfigurator()->showMenu($player, $pluginMenu); |  | ||||||
| 				break; |  | ||||||
| 		} |  | ||||||
| 	} |  | ||||||
| 	 |  | ||||||
| 	/** | 	/** | ||||||
| 	 * generate, store and automatically send it to the admin | 	 * generate, store and automatically send it to the admin | ||||||
| 	 * | 	 * | ||||||
| 	 * @return void | 	 * @return void | ||||||
| 	 */ | 	 */ | ||||||
| 	public function generateManialink() { | 	public function generateManialink() { | ||||||
| 		if ($this->MatchManagerCore === null) return; |  | ||||||
| 		$itemSize          = 6.; |  | ||||||
| 		$quadStyle         = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultQuadStyle(); | 		$quadStyle         = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultQuadStyle(); | ||||||
| 		$quadSubstyle      = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultQuadSubstyle(); | 		$quadSubstyle      = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultQuadSubstyle(); | ||||||
| 		$itemMarginFactorX = 1.3; | 		$itemMarginFactorX = 1.3; | ||||||
| @@ -293,6 +191,7 @@ class MatchManagerAdminUI implements CallbackListener, ManialinkPageAnswerListen | |||||||
| 		$posX = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_POSX); | 		$posX = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_POSX); | ||||||
| 		$posY = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_POSY); | 		$posY = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_POSY); | ||||||
|  |  | ||||||
|  | 		if (count($this->menuItems) > 0) { | ||||||
| 			// Admin Menu Icon Frame | 			// Admin Menu Icon Frame | ||||||
| 			$iconFrame = new Frame(); | 			$iconFrame = new Frame(); | ||||||
| 			$frame->addChild($iconFrame); | 			$frame->addChild($iconFrame); | ||||||
| @@ -300,21 +199,21 @@ class MatchManagerAdminUI implements CallbackListener, ManialinkPageAnswerListen | |||||||
|  |  | ||||||
| 			$backgroundQuad = new Quad(); | 			$backgroundQuad = new Quad(); | ||||||
| 			$iconFrame->addChild($backgroundQuad); | 			$iconFrame->addChild($backgroundQuad); | ||||||
| 		$backgroundQuad->setSize($itemSize * $itemMarginFactorX, $itemSize * $itemMarginFactorY); | 			$backgroundQuad->setSize(self::ML_ITEM_SIZE * $itemMarginFactorX, self::ML_ITEM_SIZE * $itemMarginFactorY); | ||||||
| 			$backgroundQuad->setStyles($quadStyle, $quadSubstyle); | 			$backgroundQuad->setStyles($quadStyle, $quadSubstyle); | ||||||
| 			$backgroundQuad->setZ(-1.); | 			$backgroundQuad->setZ(-1.); | ||||||
|  |  | ||||||
| 			$itemQuad = new Label(); | 			$itemQuad = new Label(); | ||||||
| 			$iconFrame->addChild($itemQuad); | 			$iconFrame->addChild($itemQuad); | ||||||
| 			$itemQuad->setText('$fc3$w🏆$m'); | 			$itemQuad->setText('$fc3$w🏆$m'); | ||||||
| 		$itemQuad->setSize($itemSize, $itemSize); | 			$itemQuad->setSize(self::ML_ITEM_SIZE, self::ML_ITEM_SIZE); | ||||||
| 			$itemQuad->setAreaFocusColor("00000000"); | 			$itemQuad->setAreaFocusColor("00000000"); | ||||||
| 			$itemQuad->setAreaColor("00000000"); | 			$itemQuad->setAreaColor("00000000"); | ||||||
|  |  | ||||||
| 			// Admin Menu Description | 			// Admin Menu Description | ||||||
| 			$descriptionLabel = new Label(); | 			$descriptionLabel = new Label(); | ||||||
| 			$frame->addChild($descriptionLabel); | 			$frame->addChild($descriptionLabel); | ||||||
| 		$descriptionLabel->setAlign($descriptionLabel::RIGHT, $descriptionLabel::TOP); | 			$descriptionLabel->setAlign(Label::RIGHT, Label::TOP); | ||||||
| 			$descriptionLabel->setSize(40, 4); | 			$descriptionLabel->setSize(40, 4); | ||||||
| 			$descriptionLabel->setTextSize(1); | 			$descriptionLabel->setTextSize(1); | ||||||
| 			$descriptionLabel->setTextColor('fff'); | 			$descriptionLabel->setTextColor('fff'); | ||||||
| @@ -323,7 +222,7 @@ class MatchManagerAdminUI implements CallbackListener, ManialinkPageAnswerListen | |||||||
| 			// Admin Menu | 			// Admin Menu | ||||||
| 			$popoutFrame = new Frame(); | 			$popoutFrame = new Frame(); | ||||||
| 			$frame->addChild($popoutFrame); | 			$frame->addChild($popoutFrame); | ||||||
| 		$popoutFrame->setPosition($posX - $itemSize * 0.5, $posY); | 			$popoutFrame->setPosition($posX - self::ML_ITEM_SIZE * 0.5, $posY); | ||||||
| 			$popoutFrame->setHorizontalAlign($popoutFrame::RIGHT); | 			$popoutFrame->setHorizontalAlign($popoutFrame::RIGHT); | ||||||
| 			$popoutFrame->setVisible(false); | 			$popoutFrame->setVisible(false); | ||||||
|  |  | ||||||
| @@ -331,134 +230,136 @@ class MatchManagerAdminUI implements CallbackListener, ManialinkPageAnswerListen | |||||||
| 			$popoutFrame->addChild($backgroundQuad); | 			$popoutFrame->addChild($backgroundQuad); | ||||||
| 			$backgroundQuad->setHorizontalAlign($backgroundQuad::RIGHT); | 			$backgroundQuad->setHorizontalAlign($backgroundQuad::RIGHT); | ||||||
| 			$backgroundQuad->setStyles($quadStyle, $quadSubstyle); | 			$backgroundQuad->setStyles($quadStyle, $quadSubstyle); | ||||||
|  |  | ||||||
| 			$backgroundQuad->setZ(-1.); | 			$backgroundQuad->setZ(-1.); | ||||||
|  |  | ||||||
| 			$itemQuad->addToggleFeature($popoutFrame); | 			$itemQuad->addToggleFeature($popoutFrame); | ||||||
|  |  | ||||||
| 			// Add items | 			// Add items | ||||||
| 		$itemPosX = -1; | 			$itemPosX = -4.; | ||||||
|  |  | ||||||
| 		// Settings: | 			// sort by Order desc | ||||||
| 		$menuQuad = new Quad(); | 			usort($this->menuItems, function($a, $b) { | ||||||
| 		$popoutFrame->addChild($menuQuad); | 				return $b->getOrder() <=> $a->getOrder(); | ||||||
| 		$menuQuad->setStyle("UICommon64_1"); | 			}); | ||||||
| 		$menuQuad->setSubStyle("Settings_light"); |  | ||||||
| 		$menuQuad->setSize($itemSize, $itemSize); |  | ||||||
| 		$menuQuad->setX($itemPosX); |  | ||||||
| 		$menuQuad->setHorizontalAlign($menuQuad::RIGHT); |  | ||||||
| 		$itemPosX -= $itemSize * 1.05; |  | ||||||
| 		$menuQuad->addTooltipLabelFeature($descriptionLabel, "Manage Core Settings"); |  | ||||||
| 		$menuQuad->setAction(self::ML_ACTION_CORE_MANAGESETTINGS); |  | ||||||
|  |  | ||||||
| 		$MatchManagerMultipleConfigManager = $this->maniaControl->getPluginManager()->getPlugin(self::MATCHMANAGERMULTIPLECONFIGMANAGER_PLUGIN); | 			foreach ($this->menuItems as $menuItem) { | ||||||
| 		if ($MatchManagerMultipleConfigManager !== null) { | 				$menuItem->buildControl($popoutFrame, $descriptionLabel, $itemPosX); | ||||||
| 			$menuQuad = new Quad(); | 				$itemPosX -= self::ML_ITEM_SIZE * 1.05; | ||||||
| 			$popoutFrame->addChild($menuQuad); |  | ||||||
| 			$menuQuad->setStyle("UICommon64_2"); |  | ||||||
| 			$menuQuad->setSubStyle("Plugin_light"); |  | ||||||
| 			$menuQuad->setSize($itemSize, $itemSize); |  | ||||||
| 			$menuQuad->setX($itemPosX); |  | ||||||
| 			$menuQuad->setHorizontalAlign($menuQuad::RIGHT); |  | ||||||
| 			$itemPosX -= $itemSize * 1.05; |  | ||||||
| 			$menuQuad->addTooltipLabelFeature($descriptionLabel, "Manage Multiple Configs"); |  | ||||||
| 			$menuQuad->setAction(self::ML_ACTION_MULTIPLECONFIGMANAGER_OPENCONFIGMANAGER); |  | ||||||
| 			} | 			} | ||||||
|  |  | ||||||
| 		$MatchManagerGsheet = $this->maniaControl->getPluginManager()->getPlugin(self::MATCHMANAGERGSHEET_PLUGIN); | 			$descriptionLabel->setPosition($posX - (count($popoutFrame->getChildren()) - 1) * self::ML_ITEM_SIZE * 1.05 - 5, $posY); | ||||||
| 		if ($MatchManagerGsheet !== null) { | 			$backgroundQuad->setSize((count($popoutFrame->getChildren()) - 1) * self::ML_ITEM_SIZE * 1.05 + 2, self::ML_ITEM_SIZE * $itemMarginFactorY); | ||||||
| 			$menuQuad = new Quad(); |  | ||||||
| 			$popoutFrame->addChild($menuQuad); |  | ||||||
| 			$menuQuad->setStyle("UICommon64_2"); |  | ||||||
| 			$menuQuad->setSubStyle("DisplayIcons_light"); |  | ||||||
| 			$menuQuad->setSize($itemSize, $itemSize); |  | ||||||
| 			$menuQuad->setX($itemPosX); |  | ||||||
| 			$menuQuad->setHorizontalAlign($menuQuad::RIGHT); |  | ||||||
| 			$itemPosX -= $itemSize * 1.05; |  | ||||||
| 			$menuQuad->addTooltipLabelFeature($descriptionLabel, "Manage Google Sheet config"); |  | ||||||
| 			$menuQuad->setAction(self::ML_ACTION_GSHEET_MANAGESETTINGS); |  | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		if ($this->MatchManagerCore->getMatchStatus()) { |  | ||||||
| 			$menuQuad = new Quad(); |  | ||||||
| 			$popoutFrame->addChild($menuQuad); |  | ||||||
| 			$menuQuad->setStyle("UICommon64_1"); |  | ||||||
| 			$menuQuad->setSubStyle("Stop_light"); |  | ||||||
| 			$menuQuad->setSize($itemSize, $itemSize); |  | ||||||
| 			$menuQuad->setX($itemPosX); |  | ||||||
| 			$menuQuad->setHorizontalAlign($menuQuad::RIGHT); |  | ||||||
| 			$itemPosX -= $itemSize * 1.05; |  | ||||||
| 			$menuQuad->addTooltipLabelFeature($descriptionLabel, "Stop the match"); |  | ||||||
| 			$menuQuad->setAction(self::ML_ACTION_CORE_STOPMATCH); |  | ||||||
|  |  | ||||||
| 			$menuQuad = new Quad(); |  | ||||||
| 			$popoutFrame->addChild($menuQuad); |  | ||||||
| 			$menuQuad->setStyle("UICommon64_1"); |  | ||||||
| 			$menuQuad->setSubStyle("Pause_light"); |  | ||||||
| 			$menuQuad->setSize($itemSize, $itemSize); |  | ||||||
| 			$menuQuad->setX($itemPosX); |  | ||||||
| 			$menuQuad->setHorizontalAlign($menuQuad::RIGHT); |  | ||||||
| 			$itemPosX -= $itemSize * 1.05; |  | ||||||
| 			$menuQuad->addTooltipLabelFeature($descriptionLabel, "Pause the match"); |  | ||||||
| 			$menuQuad->setAction(self::ML_ACTION_CORE_PAUSEMATCH); |  | ||||||
|  |  | ||||||
| 			$menuQuad = new Quad(); |  | ||||||
| 			$popoutFrame->addChild($menuQuad); |  | ||||||
| 			$menuQuad->setStyle("UICommon64_1"); |  | ||||||
| 			$menuQuad->setSubStyle("Cross_light"); |  | ||||||
| 			$menuQuad->setSize($itemSize, $itemSize); |  | ||||||
| 			$menuQuad->setX($itemPosX); |  | ||||||
| 			$menuQuad->setHorizontalAlign($menuQuad::RIGHT); |  | ||||||
| 			$itemPosX -= $itemSize * 1.05; |  | ||||||
| 			$menuQuad->addTooltipLabelFeature($descriptionLabel, "Skip the round / Warmup / Pause"); |  | ||||||
| 			$menuQuad->setAction(self::ML_ACTION_CORE_SKIPROUND); |  | ||||||
| 		} else { |  | ||||||
| 			$menuQuad = new Quad(); |  | ||||||
| 			$popoutFrame->addChild($menuQuad); |  | ||||||
| 			$menuQuad->setStyle("UICommon64_1"); |  | ||||||
| 			$menuQuad->setSubStyle("Play_light"); |  | ||||||
| 			$menuQuad->setSize($itemSize, $itemSize); |  | ||||||
| 			$menuQuad->setX($itemPosX); |  | ||||||
| 			$menuQuad->setHorizontalAlign($menuQuad::RIGHT); |  | ||||||
| 			$itemPosX -= $itemSize * 1.05; |  | ||||||
| 			$menuQuad->addTooltipLabelFeature($descriptionLabel, "Start the match"); |  | ||||||
| 			$menuQuad->setAction(self::ML_ACTION_CORE_STARTMATCH); |  | ||||||
| 		} |  | ||||||
|  |  | ||||||
| 		$descriptionLabel->setPosition($posX - (count($popoutFrame->getChildren()) - 1) * $itemSize * 1.05 - 5, $posY); |  | ||||||
| 		$backgroundQuad->setSize((count($popoutFrame->getChildren()) - 1) * $itemSize * 1.05 + 2, $itemSize * $itemMarginFactorY); |  | ||||||
|  |  | ||||||
| 		$this->manialink = $maniaLink; | 		$this->manialink = $maniaLink; | ||||||
| 		$this->displayManialink(); | 		$this->displayManialink(); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	/** | 	public function addMenuItem(MatchManagerAdminUI_MenuItem $menuItem) { | ||||||
| 	 * handlePluginUnloaded | 		$this->removeMenuItem($menuItem->getActionId()); | ||||||
| 	 * | 		$this->menuItems[] = $menuItem; | ||||||
| 	 * @param  string $pluginClass |  | ||||||
| 	 * @param  Plugin $plugin | 		$this->updateManialink = true; | ||||||
| 	 * @return void |  | ||||||
| 	 */ |  | ||||||
| 	public function handlePluginUnloaded(string $pluginClass, Plugin $plugin) { |  | ||||||
| 		if ($pluginClass == self::MATCHMANAGERCORE_PLUGIN) { |  | ||||||
| 			$this->maniaControl->getChat()->sendErrorToAdmins(self::PLUGIN_NAME . " disabled because MatchManager Core is now disabled"); |  | ||||||
| 			$this->maniaControl->getPluginManager()->deactivatePlugin((get_class())); |  | ||||||
| 	} | 	} | ||||||
| 		if (strstr($pluginClass, "MatchManagerSuite")) { |  | ||||||
| 			$this->generateManialink(); | 	public function removeMenuItem(string $actionId) { | ||||||
|  | 		$this->menuItems = array_filter($this->menuItems, function($menuItem) use ($actionId) { | ||||||
|  | 			return $menuItem->getActionId() !== $actionId; | ||||||
|  | 		}); | ||||||
|  |  | ||||||
|  | 		$this->updateManialink = true; | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  |  | ||||||
|  | class MatchManagerAdminUI_MenuItem { | ||||||
|  | 	private string $actionId	; | ||||||
|  | 	private int $order = 100; | ||||||
|  | 	private string $description = ''; | ||||||
|  | 	private string $text = ''; | ||||||
|  | 	private string $imageUrl = ''; | ||||||
|  | 	private string $style = ''; | ||||||
|  | 	private string $subStyle = ''; | ||||||
|  | 	private float $size = MatchManagerAdminUI::ML_ITEM_SIZE; | ||||||
|  |  | ||||||
|  | 	public function getActionId() { | ||||||
|  | 		return $this->actionId; | ||||||
|  | 	} | ||||||
|  | 	public function setActionId(string $actionId) { | ||||||
|  | 		$this->actionId = $actionId; | ||||||
|  | 		return $this; | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	public function getOrder() { | ||||||
|  | 		return $this->order; | ||||||
|  | 	} | ||||||
|  | 	public function setOrder(int $order) { | ||||||
|  | 		$this->order = $order; | ||||||
|  | 		return $this; | ||||||
|  | 	} | ||||||
|  | 	 | ||||||
|  | 	public function getDescription() { | ||||||
|  | 		return $this->description; | ||||||
|  | 	} | ||||||
|  | 	public function setDescription(string $description) { | ||||||
|  | 		$this->description = $description; | ||||||
|  | 		return $this; | ||||||
|  | 	} | ||||||
|  | 	 | ||||||
|  | 	public function getImageUrl() { | ||||||
|  | 		return $this->imageUrl; | ||||||
|  | 	} | ||||||
|  | 	public function setImageUrl(string $imageUrl) { | ||||||
|  | 		$this->imageUrl = $imageUrl; | ||||||
|  | 		return $this; | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	public function getSize() { | ||||||
|  | 		return $this->size; | ||||||
|  | 	} | ||||||
|  | 	public function setSize(float $size) { | ||||||
|  | 		$this->size = $size; | ||||||
|  | 		return $this; | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	public function getStyle() { | ||||||
|  | 		return $this->imageUrl; | ||||||
|  | 	} | ||||||
|  | 	public function setStyle(string $style) { | ||||||
|  | 		$this->style = $style; | ||||||
|  | 		return $this; | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	public function getSubStyle() { | ||||||
|  | 		return $this->imageUrl; | ||||||
|  | 	} | ||||||
|  | 	public function setSubStyle(string $subStyle) { | ||||||
|  | 		$this->subStyle = $subStyle; | ||||||
|  | 		return $this; | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	public function buildControl(Frame $parent, Label $descriptionLabel, float $posX) { | ||||||
|  | 		$control = null; | ||||||
|  | 		if ($this->text !== '') { | ||||||
|  | 			$control = new Label(); | ||||||
|  | 			$control->setText($this->text); | ||||||
|  | 		} else { | ||||||
|  | 			$control = new Quad(); | ||||||
|  | 			if ($this->imageUrl !== '') { | ||||||
|  | 				$control->setImageUrl($this->imageUrl); | ||||||
|  | 				$control->setKeepRatio('fit'); | ||||||
|  | 				$control->setColorize('ffffff'); | ||||||
|  | 			} else if ($this->style !== '') { | ||||||
|  | 				$control->setStyles($this->style, $this->subStyle); | ||||||
|  | 			} else { | ||||||
|  | 				$control->setBackgroundColor('cccccc'); | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 	/** | 		$parent->addChild($control); | ||||||
| 	 * handlePluginLoaded | 		$control->setSize($this->size, $this->size); | ||||||
| 	 * | 		$control->setX($posX); | ||||||
| 	 * @param  string $pluginClass | 		$control->setHorizontalAlign(Quad::CENTER); | ||||||
| 	 * @param  Plugin $plugin | 		$control->addTooltipLabelFeature($descriptionLabel, $this->description); | ||||||
| 	 * @return void | 		$control->setAction($this->actionId); | ||||||
| 	 */ |  | ||||||
| 	public function handlePluginLoaded(string $pluginClass, Plugin $plugin) { |  | ||||||
| 		if (strstr($pluginClass, "MatchManagerSuite")) { |  | ||||||
| 			$this->generateManialink(); |  | ||||||
| 		} |  | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
| @@ -29,6 +29,8 @@ use ManiaControl\Configurator\GameModeSettings; | |||||||
| use ManiaControl\Utils\Formatter; | use ManiaControl\Utils\Formatter; | ||||||
| use Maniaplanet\DedicatedServer\InvalidArgumentException; | use Maniaplanet\DedicatedServer\InvalidArgumentException; | ||||||
| use ManiaControl\Callbacks\TimerListener; // for pause | use ManiaControl\Callbacks\TimerListener; // for pause | ||||||
|  | use ManiaControl\Plugins\PluginManager; | ||||||
|  | use ManiaControl\Plugins\PluginMenu; | ||||||
|  |  | ||||||
| /** | /** | ||||||
|  * MatchManager Core |  * MatchManager Core | ||||||
| @@ -54,6 +56,16 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen | |||||||
| 	const DB_MATCHESTEAMSRESULT								= 'MatchManager_MatchesTeamsResult'; | 	const DB_MATCHESTEAMSRESULT								= 'MatchManager_MatchesTeamsResult'; | ||||||
| 	const MLID_MATCH_PAUSE_WIDGET							= 'Pause Widget'; | 	const MLID_MATCH_PAUSE_WIDGET							= 'Pause Widget'; | ||||||
|  |  | ||||||
|  | 	// Other MatchManager plugin | ||||||
|  | 	const MATCHMANAGERADMINUI_PLUGIN							= 'MatchManagerSuite\MatchManagerAdminUI'; | ||||||
|  |  | ||||||
|  | 	// Actions | ||||||
|  | 	const ML_ACTION_OPENSETTINGS						= 'MatchManagerSuite\MatchManagerCore.OpenSettings'; | ||||||
|  | 	const ML_ACTION_SKIPROUND 							= 'MatchManagerSuite\MatchManagerCore.SkipRound'; | ||||||
|  | 	const ML_ACTION_PAUSEMATCH 							= 'MatchManagerSuite\MatchManagerCore.PauseMatch'; | ||||||
|  | 	const ML_ACTION_STOPMATCH 							= 'MatchManagerSuite\MatchManagerCore.StopMatch'; | ||||||
|  | 	const ML_ACTION_STARTMATCH 							= 'MatchManagerSuite\MatchManagerCore.StartMatch'; | ||||||
|  |  | ||||||
| 	// Internal Callback Trigger | 	// Internal Callback Trigger | ||||||
| 	const CB_MATCHMANAGER_BEGINMAP							= 'MatchManager.BeginMap'; | 	const CB_MATCHMANAGER_BEGINMAP							= 'MatchManager.BeginMap'; | ||||||
| 	const CB_MATCHMANAGER_ENDROUND							= 'MatchManager.EndRound'; | 	const CB_MATCHMANAGER_ENDROUND							= 'MatchManager.EndRound'; | ||||||
| @@ -450,8 +462,12 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen | |||||||
| 		$this->maniaControl->getCommandManager()->registerCommandListener(array('matchendpause','endpause'), $this, 'onCommandUnsetPause', true, 'End the pause during a match.'); | 		$this->maniaControl->getCommandManager()->registerCommandListener(array('matchendpause','endpause'), $this, 'onCommandUnsetPause', true, 'End the pause during a match.'); | ||||||
|  |  | ||||||
| 		//Register Callbacks | 		//Register Callbacks | ||||||
|  | 		$this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::AFTERINIT, $this, 'handleAfterInit'); | ||||||
|  | 		$this->maniaControl->getCallbackManager()->registerCallbackListener(PluginManager::CB_PLUGIN_LOADED, $this, 'handlePluginLoaded'); | ||||||
|  |  | ||||||
| 		$this->maniaControl->getCallbackManager()->registerCallbackListener(SettingManager::CB_SETTING_CHANGED, $this, 'updateSettings'); | 		$this->maniaControl->getCallbackManager()->registerCallbackListener(SettingManager::CB_SETTING_CHANGED, $this, 'updateSettings'); | ||||||
| 		$this->maniaControl->getCallbackManager()->registerCallbackListener(GameModeSettings::CB_GAMEMODESETTINGS_CHANGED, $this, 'updateGMvariables'); | 		$this->maniaControl->getCallbackManager()->registerCallbackListener(GameModeSettings::CB_GAMEMODESETTINGS_CHANGED, $this, 'updateGMvariables'); | ||||||
|  | 		$this->maniaControl->getCallbackManager()->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer'); | ||||||
|  |  | ||||||
| 		$this->maniaControl->getCallbackManager()->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerConnect'); | 		$this->maniaControl->getCallbackManager()->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerConnect'); | ||||||
| 		$this->maniaControl->getCallbackManager()->registerCallbackListener(PlayerManager::CB_PLAYERDISCONNECT, $this, 'handlePlayerDisconnect'); | 		$this->maniaControl->getCallbackManager()->registerCallbackListener(PlayerManager::CB_PLAYERDISCONNECT, $this, 'handlePlayerDisconnect'); | ||||||
| @@ -468,6 +484,8 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen | |||||||
| 		$this->maniaControl->getCommunicationManager()->registerCommunicationListener("Match.MatchStart", $this, function () { return new CommunicationAnswer($this->MatchStart()); }); | 		$this->maniaControl->getCommunicationManager()->registerCommunicationListener("Match.MatchStart", $this, function () { return new CommunicationAnswer($this->MatchStart()); }); | ||||||
| 		$this->maniaControl->getCommunicationManager()->registerCommunicationListener("Match.MatchStop", $this, function () { return new CommunicationAnswer($this->MatchStop()); }); | 		$this->maniaControl->getCommunicationManager()->registerCommunicationListener("Match.MatchStop", $this, function () { return new CommunicationAnswer($this->MatchStop()); }); | ||||||
| 		$this->maniaControl->getCommunicationManager()->registerCommunicationListener("Match.GetMatchOptions", $this, function () { return new CommunicationAnswer($this->getGMSettings($this->currentgmbase,$this->currentcustomgm)); });	 | 		$this->maniaControl->getCommunicationManager()->registerCommunicationListener("Match.GetMatchOptions", $this, function () { return new CommunicationAnswer($this->getGMSettings($this->currentgmbase,$this->currentcustomgm)); });	 | ||||||
|  |  | ||||||
|  | 		$this->updateAdminUIMenuItems(); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	/** | 	/** | ||||||
| @@ -475,6 +493,16 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen | |||||||
| 	 */ | 	 */ | ||||||
| 	public function unload() { | 	public function unload() { | ||||||
| 		$this->closePauseWidget(); | 		$this->closePauseWidget(); | ||||||
|  |  | ||||||
|  | 		/** @var \MatchManagerSuite\MatchManagerAdminUI|null */ | ||||||
|  | 		$adminUIPlugin = $this->maniaControl->getPluginManager()->getPlugin(self::MATCHMANAGERADMINUI_PLUGIN); | ||||||
|  | 		if ($adminUIPlugin !== null) { | ||||||
|  | 			$adminUIPlugin->removeMenuItem(self::ML_ACTION_OPENSETTINGS); | ||||||
|  | 			$adminUIPlugin->removeMenuItem(self::ML_ACTION_STARTMATCH); | ||||||
|  | 			$adminUIPlugin->removeMenuItem(self::ML_ACTION_SKIPROUND); | ||||||
|  | 			$adminUIPlugin->removeMenuItem(self::ML_ACTION_PAUSEMATCH); | ||||||
|  | 			$adminUIPlugin->removeMenuItem(self::ML_ACTION_STOPMATCH); | ||||||
|  | 		} | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	/** | 	/** | ||||||
| @@ -671,6 +699,43 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen | |||||||
| 	 * MARK: Internal Functions | 	 * MARK: Internal Functions | ||||||
| 	 */ | 	 */ | ||||||
|  |  | ||||||
|  | 	/** | ||||||
|  | 	 * Add items in AdminUI plugin | ||||||
|  | 	 */ | ||||||
|  | 	public function updateAdminUIMenuItems() { | ||||||
|  | 		/** @var \MatchManagerSuite\MatchManagerAdminUI|null */ | ||||||
|  | 		$adminUIPlugin = $this->maniaControl->getPluginManager()->getPlugin(self::MATCHMANAGERADMINUI_PLUGIN); | ||||||
|  | 		if ($adminUIPlugin === null) return; | ||||||
|  |  | ||||||
|  | 		$menuItem = new \MatchManagerSuite\MatchManagerAdminUI_MenuItem(); | ||||||
|  | 		$menuItem->setActionId(self::ML_ACTION_OPENSETTINGS)->setOrder(99999)->setStyle('UICommon64_1')->setSubStyle('Settings_light')->setDescription('Open Core Settings'); | ||||||
|  | 		$adminUIPlugin->addMenuItem($menuItem); | ||||||
|  |  | ||||||
|  | 		if ($this->matchStarted) { | ||||||
|  | 			$adminUIPlugin->removeMenuItem(self::ML_ACTION_STARTMATCH); | ||||||
|  | 			 | ||||||
|  | 			$menuItem = new \MatchManagerSuite\MatchManagerAdminUI_MenuItem(); | ||||||
|  | 			$menuItem->setActionId(self::ML_ACTION_SKIPROUND)->setOrder(0)->setStyle('UICommon64_1')->setSubStyle('Cross_light')->setDescription('Skip the round / Warmup / Pause'); | ||||||
|  | 			$adminUIPlugin->addMenuItem($menuItem); | ||||||
|  |  | ||||||
|  | 			$menuItem = new \MatchManagerSuite\MatchManagerAdminUI_MenuItem(); | ||||||
|  | 			$menuItem->setActionId(self::ML_ACTION_PAUSEMATCH)->setOrder(1)->setStyle('UICommon64_1')->setSubStyle('Pause_light')->setDescription('Pause the match'); | ||||||
|  | 			$adminUIPlugin->addMenuItem($menuItem); | ||||||
|  |  | ||||||
|  | 			$menuItem = new \MatchManagerSuite\MatchManagerAdminUI_MenuItem(); | ||||||
|  | 			$menuItem->setActionId(self::ML_ACTION_STOPMATCH)->setOrder(2)->setStyle('UICommon64_1')->setSubStyle('Stop_light')->setDescription('Stop the match'); | ||||||
|  | 			$adminUIPlugin->addMenuItem($menuItem); | ||||||
|  | 		} else { | ||||||
|  | 			$adminUIPlugin->removeMenuItem(self::ML_ACTION_SKIPROUND); | ||||||
|  | 			$adminUIPlugin->removeMenuItem(self::ML_ACTION_PAUSEMATCH); | ||||||
|  | 			$adminUIPlugin->removeMenuItem(self::ML_ACTION_STOPMATCH); | ||||||
|  |  | ||||||
|  | 			$menuItem = new \MatchManagerSuite\MatchManagerAdminUI_MenuItem(); | ||||||
|  | 			$menuItem->setActionId(self::ML_ACTION_STARTMATCH)->setOrder(0)->setStyle('UICommon64_1')->setSubStyle('Play_light')->setDescription('Start the match'); | ||||||
|  | 			$adminUIPlugin->addMenuItem($menuItem); | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  |  | ||||||
| 	/** | 	/** | ||||||
| 	 * Update Widgets on Setting Changes | 	 * Update Widgets on Setting Changes | ||||||
| 	 * | 	 * | ||||||
| @@ -1135,6 +1200,7 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen | |||||||
| 				'mapshidden'	=> $this->mapshidden, | 				'mapshidden'	=> $this->mapshidden, | ||||||
| 				'maps'			=> $this->maps]; | 				'maps'			=> $this->maps]; | ||||||
| 			$this->maniaControl->getCallbackManager()->triggerCallback(self::CB_MATCHMANAGER_STARTMATCH, $this->matchid, $settings); | 			$this->maniaControl->getCallbackManager()->triggerCallback(self::CB_MATCHMANAGER_STARTMATCH, $this->matchid, $settings); | ||||||
|  | 			$this->updateAdminUIMenuItems(); | ||||||
|  |  | ||||||
| 			Logger::log("Skip map"); | 			Logger::log("Skip map"); | ||||||
| 			$this->maniaControl->getMapManager()->getMapActions()->skipMap(); | 			$this->maniaControl->getMapManager()->getMapActions()->skipMap(); | ||||||
| @@ -1230,6 +1296,7 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen | |||||||
| 			Logger::log("Match finished"); | 			Logger::log("Match finished"); | ||||||
|  |  | ||||||
| 			$this->resetMatchVariables(); | 			$this->resetMatchVariables(); | ||||||
|  | 			$this->updateAdminUIMenuItems(); | ||||||
|  |  | ||||||
| 			// Teams Specifics variables | 			// Teams Specifics variables | ||||||
| 			$this->currentteamsscore = []; | 			$this->currentteamsscore = []; | ||||||
| @@ -1280,6 +1347,7 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen | |||||||
| 			} | 			} | ||||||
|  |  | ||||||
| 			$this->resetMatchVariables(); | 			$this->resetMatchVariables(); | ||||||
|  | 			$this->updateAdminUIMenuItems(); | ||||||
| 		} catch (Exception $e) { | 		} catch (Exception $e) { | ||||||
| 			$this->maniaControl->getChat()->sendErrorToAdmins($this->chatprefix . 'Can not stop match: ' . $e->getMessage()); | 			$this->maniaControl->getChat()->sendErrorToAdmins($this->chatprefix . 'Can not stop match: ' . $e->getMessage()); | ||||||
| 		} | 		} | ||||||
| @@ -2186,4 +2254,57 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen | |||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | 	/* | ||||||
|  | 	 * MARK: Internal Callbacks | ||||||
|  | 	 */ | ||||||
|  | 	public function handleAfterInit() { | ||||||
|  | 		$this->updateAdminUIMenuItems(); | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	public function handlePluginLoaded(string $pluginClass) { | ||||||
|  | 		if ($pluginClass === self::MATCHMANAGERADMINUI_PLUGIN) { | ||||||
|  | 			$this->updateAdminUIMenuItems(); | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	public function handleManialinkPageAnswer($callback) { | ||||||
|  | 		$actionId    = $callback[1][2]; | ||||||
|  | 		$actionArray = explode('.', $actionId); | ||||||
|  | 		if ($actionArray[0] !== self::class) { | ||||||
|  | 			return; | ||||||
|  | 		} | ||||||
|  |  | ||||||
|  | 		$login = $callback[1][1]; | ||||||
|  | 		$player = $this->maniaControl->getPlayerManager()->getPlayer($login); | ||||||
|  | 		$authLevel = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MATCH_AUTHLEVEL); | ||||||
|  | 		if (!$this->maniaControl->getAuthenticationManager()->checkRight($player, AuthenticationManager::getAuthLevel($authLevel))) { | ||||||
|  | 			return; | ||||||
|  | 		} | ||||||
|  |  | ||||||
|  | 		switch ($actionId) { | ||||||
|  | 			case self::ML_ACTION_OPENSETTINGS: | ||||||
|  | 				$pluginMenu = $this->maniaControl->getPluginManager()->getPluginMenu(); | ||||||
|  | 				if (defined("\ManiaControl\ManiaControl::ISTRACKMANIACONTROL")) { | ||||||
|  | 					$player->setCache($pluginMenu, PluginMenu::CACHE_SETTING_CLASS, "PluginMenu.Settings." . self::class); | ||||||
|  | 				} else { | ||||||
|  | 					$player->setCache($pluginMenu, PluginMenu::CACHE_SETTING_CLASS, self::class); | ||||||
|  | 				} | ||||||
|  | 				$this->maniaControl->getConfigurator()->showMenu($player, $pluginMenu); | ||||||
|  | 			case self::ML_ACTION_STOPMATCH: | ||||||
|  | 				$this->MatchStop(); | ||||||
|  | 				break; | ||||||
|  | 			case self::ML_ACTION_PAUSEMATCH: | ||||||
|  | 				$this->setNadeoPause(); | ||||||
|  | 				break; | ||||||
|  | 			case self::ML_ACTION_SKIPROUND: | ||||||
|  | 				$this->onCommandMatchEndWU(array(), $player);  | ||||||
|  | 				$this->onCommandUnsetPause(array(), $player);  | ||||||
|  | 				$this->onCommandMatchEndRound(array(), $player);  | ||||||
|  | 				break; | ||||||
|  | 			case self::ML_ACTION_STARTMATCH: | ||||||
|  | 				$this->MatchStart(); | ||||||
|  | 				break; | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
| } | } | ||||||
|   | |||||||
| @@ -13,8 +13,11 @@ use ManiaControl\Settings\SettingManager; | |||||||
| use ManiaControl\Files\AsyncHttpRequest; | use ManiaControl\Files\AsyncHttpRequest; | ||||||
| use ManiaControl\Commands\CommandListener; | use ManiaControl\Commands\CommandListener; | ||||||
| use ManiaControl\Admin\AuthenticationManager; | use ManiaControl\Admin\AuthenticationManager; | ||||||
|  | use ManiaControl\Callbacks\Callbacks; | ||||||
| use ManiaControl\Callbacks\TimerListener; | use ManiaControl\Callbacks\TimerListener; | ||||||
|  | use ManiaControl\Manialinks\ManialinkPageAnswerListener; | ||||||
| use ManiaControl\Players\PlayerManager; | use ManiaControl\Players\PlayerManager; | ||||||
|  | use ManiaControl\Plugins\PluginMenu; | ||||||
| use ManiaControl\Utils\WebReader; | use ManiaControl\Utils\WebReader; | ||||||
|  |  | ||||||
| if (!class_exists('MatchManagerSuite\MatchManagerCore')) { | if (!class_exists('MatchManagerSuite\MatchManagerCore')) { | ||||||
| @@ -31,7 +34,7 @@ use MatchManagerSuite\MatchManagerCore; | |||||||
|  * @author		Beu |  * @author		Beu | ||||||
|  * @license		http://www.gnu.org/licenses/ GNU General Public License, Version 3 |  * @license		http://www.gnu.org/licenses/ GNU General Public License, Version 3 | ||||||
|  */ |  */ | ||||||
| class MatchManagerGSheet implements  CallbackListener, TimerListener, CommandListener, Plugin { | class MatchManagerGSheet implements  CallbackListener, TimerListener, CommandListener, ManialinkPageAnswerListener, Plugin { | ||||||
| 	/* | 	/* | ||||||
| 	 * Constants | 	 * Constants | ||||||
| 	 */ | 	 */ | ||||||
| @@ -40,6 +43,12 @@ class MatchManagerGSheet implements  CallbackListener, TimerListener, CommandLis | |||||||
| 	const PLUGIN_NAME										= 'MatchManager GSheet'; | 	const PLUGIN_NAME										= 'MatchManager GSheet'; | ||||||
| 	const PLUGIN_AUTHOR										= 'Beu'; | 	const PLUGIN_AUTHOR										= 'Beu'; | ||||||
|  |  | ||||||
|  | 	// Other MatchManager plugin | ||||||
|  | 	const MATCHMANAGERADMINUI_PLUGIN							= 'MatchManagerSuite\MatchManagerAdminUI'; | ||||||
|  |  | ||||||
|  | 	// Actions | ||||||
|  | 	const ML_ACTION_OPENSETTINGS 							= 'MatchManagerSuite\MatchManagerGSheet.OpenSettings'; | ||||||
|  |  | ||||||
| 	// MatchManagerGSheet Properties | 	// MatchManagerGSheet Properties | ||||||
| 	const DB_GSHEETSECRETSETTINGS							= 'MatchManagerGSheet_SecretSettings'; | 	const DB_GSHEETSECRETSETTINGS							= 'MatchManagerGSheet_SecretSettings'; | ||||||
|  |  | ||||||
| @@ -161,6 +170,11 @@ class MatchManagerGSheet implements  CallbackListener, TimerListener, CommandLis | |||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		// Callbacks | 		// Callbacks | ||||||
|  | 		$this->maniaControl->getManialinkManager()->registerManialinkPageAnswerListener(self::ML_ACTION_OPENSETTINGS, $this, 'handleActionOpenSettings'); | ||||||
|  | 		$this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::AFTERINIT, $this, 'handleAfterInit'); | ||||||
|  | 		$this->maniaControl->getCallbackManager()->registerCallbackListener(PluginManager::CB_PLUGIN_LOADED, $this, 'handlePluginLoaded'); | ||||||
|  |  | ||||||
|  | 		$this->maniaControl->getCallbackManager()->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerConnect'); | ||||||
| 		$this->maniaControl->getCallbackManager()->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerConnect'); | 		$this->maniaControl->getCallbackManager()->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerConnect'); | ||||||
| 		$this->maniaControl->getCallbackManager()->registerCallbackListener(PluginManager::CB_PLUGIN_UNLOADED, $this, 'handlePluginUnloaded'); | 		$this->maniaControl->getCallbackManager()->registerCallbackListener(PluginManager::CB_PLUGIN_UNLOADED, $this, 'handlePluginUnloaded'); | ||||||
| 		$this->maniaControl->getCallbackManager()->registerCallbackListener(SettingManager::CB_SETTING_CHANGED, $this, 'updateSettings'); | 		$this->maniaControl->getCallbackManager()->registerCallbackListener(SettingManager::CB_SETTING_CHANGED, $this, 'updateSettings'); | ||||||
| @@ -185,6 +199,8 @@ class MatchManagerGSheet implements  CallbackListener, TimerListener, CommandLis | |||||||
| 		 | 		 | ||||||
| 		$this->maniaControl->getChat()->sendErrorToAdmins('Since MatchManagerGSheet 2.0, Player names are in the results and no more in a separated list'); | 		$this->maniaControl->getChat()->sendErrorToAdmins('Since MatchManagerGSheet 2.0, Player names are in the results and no more in a separated list'); | ||||||
|  |  | ||||||
|  | 		$this->updateAdminUIMenuItems(); | ||||||
|  |  | ||||||
| 		return true; | 		return true; | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| @@ -192,6 +208,31 @@ class MatchManagerGSheet implements  CallbackListener, TimerListener, CommandLis | |||||||
| 	 * @see \ManiaControl\Plugins\Plugin::unload() | 	 * @see \ManiaControl\Plugins\Plugin::unload() | ||||||
| 	 */ | 	 */ | ||||||
| 	public function unload() { | 	public function unload() { | ||||||
|  | 		/** @var \MatchManagerSuite\MatchManagerAdminUI|null */ | ||||||
|  | 		$adminUIPlugin = $this->maniaControl->getPluginManager()->getPlugin(self::MATCHMANAGERADMINUI_PLUGIN); | ||||||
|  | 		if ($adminUIPlugin !== null) { | ||||||
|  | 			$adminUIPlugin->removeMenuItem(self::ML_ACTION_OPENSETTINGS); | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	/** | ||||||
|  | 	 * handle Plugin Loaded | ||||||
|  | 	 *  | ||||||
|  | 	 * @param string $pluginClass  | ||||||
|  | 	 */ | ||||||
|  | 	public function handleAfterInit() { | ||||||
|  | 		$this->updateAdminUIMenuItems(); | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	/** | ||||||
|  | 	 * handle Plugin Loaded | ||||||
|  | 	 *  | ||||||
|  | 	 * @param string $pluginClass  | ||||||
|  | 	 */ | ||||||
|  | 	public function handlePluginLoaded(string $pluginClass) { | ||||||
|  | 		if ($pluginClass === self::MATCHMANAGERADMINUI_PLUGIN) { | ||||||
|  | 			$this->updateAdminUIMenuItems(); | ||||||
|  | 		} | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	/** | 	/** | ||||||
| @@ -257,6 +298,39 @@ class MatchManagerGSheet implements  CallbackListener, TimerListener, CommandLis | |||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | 	/** | ||||||
|  | 	 * handle Open settings manialink action | ||||||
|  | 	 *  | ||||||
|  | 	 * @param array $callback  | ||||||
|  | 	 * @param Player $player  | ||||||
|  | 	 */ | ||||||
|  | 	public function handleActionOpenSettings(array $callback, Player $player) { | ||||||
|  | 		if ($player->authLevel <= 0) return; | ||||||
|  |  | ||||||
|  | 		$pluginMenu = $this->maniaControl->getPluginManager()->getPluginMenu(); | ||||||
|  | 		if (defined("\ManiaControl\ManiaControl::ISTRACKMANIACONTROL")) { | ||||||
|  | 			$player->setCache($pluginMenu, PluginMenu::CACHE_SETTING_CLASS, "PluginMenu.Settings." . self::class); | ||||||
|  | 		} else { | ||||||
|  | 			$player->setCache($pluginMenu, PluginMenu::CACHE_SETTING_CLASS, self::class); | ||||||
|  | 		} | ||||||
|  | 		$this->maniaControl->getConfigurator()->showMenu($player, $pluginMenu); | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	/** | ||||||
|  | 	 * Add items in AdminUI plugin | ||||||
|  | 	 */ | ||||||
|  | 	public function updateAdminUIMenuItems() { | ||||||
|  | 		/** @var \MatchManagerSuite\MatchManagerAdminUI|null */ | ||||||
|  | 		$adminUIPlugin = $this->maniaControl->getPluginManager()->getPlugin(self::MATCHMANAGERADMINUI_PLUGIN); | ||||||
|  | 		if ($adminUIPlugin === null) return; | ||||||
|  |  | ||||||
|  | 		$adminUIPlugin->removeMenuItem(self::ML_ACTION_OPENSETTINGS); | ||||||
|  |  | ||||||
|  | 		$menuItem = new \MatchManagerSuite\MatchManagerAdminUI_MenuItem(); | ||||||
|  | 		$menuItem->setActionId(self::ML_ACTION_OPENSETTINGS)->setOrder(100)->setStyle('UICommon64_2')->setSubStyle('DisplayIcons_light')->setDescription('Open Gsheet Settings'); | ||||||
|  | 		$adminUIPlugin->addMenuItem($menuItem); | ||||||
|  | 	} | ||||||
|  |  | ||||||
| 	public function onCommandMatchGSheet(array $chatCallback, Player $player) { | 	public function onCommandMatchGSheet(array $chatCallback, Player $player) { | ||||||
| 		$authLevel = $this->maniaControl->getSettingManager()->getSettingValue($this->MatchManagerCore, MatchManagerCore::SETTING_MATCH_AUTHLEVEL); | 		$authLevel = $this->maniaControl->getSettingManager()->getSettingValue($this->MatchManagerCore, MatchManagerCore::SETTING_MATCH_AUTHLEVEL); | ||||||
| 		if (!$this->maniaControl->getAuthenticationManager()->checkRight($player, AuthenticationManager::getAuthLevel($authLevel))) { | 		if (!$this->maniaControl->getAuthenticationManager()->checkRight($player, AuthenticationManager::getAuthLevel($authLevel))) { | ||||||
|   | |||||||
| @@ -17,12 +17,14 @@ use ManiaControl\Manialinks\ManialinkPageAnswerListener; | |||||||
|  |  | ||||||
| use ManiaControl\Callbacks\CallbackListener; | use ManiaControl\Callbacks\CallbackListener; | ||||||
| use ManiaControl\Callbacks\CallbackManager; | use ManiaControl\Callbacks\CallbackManager; | ||||||
|  | use ManiaControl\Callbacks\Callbacks; | ||||||
| use ManiaControl\Logger; | use ManiaControl\Logger; | ||||||
| use ManiaControl\ManiaControl; | use ManiaControl\ManiaControl; | ||||||
| use ManiaControl\Players\Player; | use ManiaControl\Players\Player; | ||||||
| use ManiaControl\Plugins\Plugin; | use ManiaControl\Plugins\Plugin; | ||||||
| use ManiaControl\Plugins\PluginManager; | use ManiaControl\Plugins\PluginManager; | ||||||
| use ManiaControl\Commands\CommandListener; | use ManiaControl\Commands\CommandListener; | ||||||
|  | use ManiaControl\Plugins\PluginMenu; | ||||||
|  |  | ||||||
| if (!class_exists('MatchManagerSuite\MatchManagerCore')) { | if (!class_exists('MatchManagerSuite\MatchManagerCore')) { | ||||||
| 	$this->maniaControl->getChat()->sendErrorToAdmins('MatchManager Core is required to use one of MatchManager plugin. Install it and restart Maniacontrol'); | 	$this->maniaControl->getChat()->sendErrorToAdmins('MatchManager Core is required to use one of MatchManager plugin. Install it and restart Maniacontrol'); | ||||||
| @@ -48,15 +50,17 @@ class MatchManagerMultipleConfigManager implements ManialinkPageAnswerListener, | |||||||
|  |  | ||||||
| 	// MatchManagerWidget Properties | 	// MatchManagerWidget Properties | ||||||
| 	const MATCHMANAGERCORE_PLUGIN							= 'MatchManagerSuite\MatchManagerCore'; | 	const MATCHMANAGERCORE_PLUGIN							= 'MatchManagerSuite\MatchManagerCore'; | ||||||
|  | 	const MATCHMANAGERADMINUI_PLUGIN						= 'MatchManagerSuite\MatchManagerAdminUI'; | ||||||
|  |  | ||||||
| 	const DB_MATCHCONFIG									= 'MatchManager_MatchConfigs'; | 	const DB_MATCHCONFIG									= 'MatchManager_MatchConfigs'; | ||||||
|  |  | ||||||
| 	const ML_ID												= 'MatchManager.MultiConfigManager.UI'; | 	const ML_ID												= 'MatchManager.MultiConfigManager.UI'; | ||||||
| 	const ML_ACTION_REMOVE_CONFIG							= 'MatchManager.MultiConfigManager.RemoveConfig'; | 	const ML_ACTION_OPENSETTINGS							= 'MatchManagerSuite\MatchManagerMultipleConfigManager.OpenSettings'; | ||||||
| 	const ML_ACTION_LOAD_CONFIG								= 'MatchManager.MultiConfigManager.LoadConfig'; | 	const ML_ACTION_REMOVE_CONFIG							= 'MatchManagerSuite\MatchManagerMultipleConfigManager.RemoveConfig'; | ||||||
| 	const ML_ACTION_LOAD_CONFIG_PAGE						= 'MatchManager.MultiConfigManager.LoadConfigPage'; | 	const ML_ACTION_LOAD_CONFIG								= 'MatchManagerSuite\MatchManagerMultipleConfigManager.LoadConfig'; | ||||||
| 	const ML_ACTION_SAVE_CONFIG								= 'MatchManager.MultiConfigManager.SaveConfig'; | 	const ML_ACTION_LOAD_CONFIG_PAGE						= 'MatchManagerSuite\MatchManagerMultipleConfigManager.LoadConfigPage'; | ||||||
| 	const ML_ACTION_SAVE_CONFIG_PAGE						= 'MatchManager.MultiConfigManager.SaveConfigPage'; | 	const ML_ACTION_SAVE_CONFIG								= 'MatchManagerSuite\MatchManagerMultipleConfigManager.SaveConfig'; | ||||||
|  | 	const ML_ACTION_SAVE_CONFIG_PAGE						= 'MatchManagerSuite\MatchManagerMultipleConfigManager.SaveConfigPage'; | ||||||
| 	const ML_NAME_CONFIGNAME								= 'MatchManager.MultiConfigManager.ConfigName'; | 	const ML_NAME_CONFIGNAME								= 'MatchManager.MultiConfigManager.ConfigName'; | ||||||
|  |  | ||||||
| 	const CB_LOADCONFIG										= 'MatchManager.MultiConfigManager.LoadConfig'; | 	const CB_LOADCONFIG										= 'MatchManager.MultiConfigManager.LoadConfig'; | ||||||
| @@ -125,13 +129,15 @@ class MatchManagerMultipleConfigManager implements ManialinkPageAnswerListener, | |||||||
| 			throw new \Exception('MatchManager Core is needed to use MatchManager Players Pause plugin'); | 			throw new \Exception('MatchManager Core is needed to use MatchManager Players Pause plugin'); | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
|  | 		$this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::AFTERINIT, $this, 'handleAfterInit'); | ||||||
|  | 		$this->maniaControl->getCallbackManager()->registerCallbackListener(PluginManager::CB_PLUGIN_LOADED, $this, 'handlePluginLoaded'); | ||||||
| 		$this->maniaControl->getCallbackManager()->registerCallbackListener(PluginManager::CB_PLUGIN_UNLOADED, $this, 'handlePluginUnloaded'); | 		$this->maniaControl->getCallbackManager()->registerCallbackListener(PluginManager::CB_PLUGIN_UNLOADED, $this, 'handlePluginUnloaded'); | ||||||
| 		$this->maniaControl->getCallbackManager()->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer'); | 		$this->maniaControl->getCallbackManager()->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer'); | ||||||
|  |  | ||||||
| 		$this->maniaControl->getCommandManager()->registerCommandListener('matchconfig', $this, 'showConfigListUI', true, 'Start a match'); | 		$this->maniaControl->getCommandManager()->registerCommandListener('matchconfig', $this, 'showConfigListUI', true, 'Start a match'); | ||||||
|  |  | ||||||
|  |  | ||||||
| 		$this->initTables(); | 		$this->initTables(); | ||||||
|  | 		$this->updateAdminUIMenuItems(); | ||||||
| 		return true; | 		return true; | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| @@ -139,6 +145,31 @@ class MatchManagerMultipleConfigManager implements ManialinkPageAnswerListener, | |||||||
| 	 * @see \ManiaControl\Plugins\Plugin::unload() | 	 * @see \ManiaControl\Plugins\Plugin::unload() | ||||||
| 	 */ | 	 */ | ||||||
| 	public function unload() { | 	public function unload() { | ||||||
|  | 		/** @var \MatchManagerSuite\MatchManagerAdminUI|null */ | ||||||
|  | 		$adminUIPlugin = $this->maniaControl->getPluginManager()->getPlugin(self::MATCHMANAGERADMINUI_PLUGIN); | ||||||
|  | 		if ($adminUIPlugin !== null) { | ||||||
|  | 			$adminUIPlugin->removeMenuItem(self::ML_ACTION_OPENSETTINGS); | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	/** | ||||||
|  | 	 * handle Plugin Loaded | ||||||
|  | 	 *  | ||||||
|  | 	 * @param string $pluginClass  | ||||||
|  | 	 */ | ||||||
|  | 	public function handleAfterInit() { | ||||||
|  | 		$this->updateAdminUIMenuItems(); | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	/** | ||||||
|  | 	 * handle Plugin Loaded | ||||||
|  | 	 *  | ||||||
|  | 	 * @param string $pluginClass  | ||||||
|  | 	 */ | ||||||
|  | 	public function handlePluginLoaded(string $pluginClass) { | ||||||
|  | 		if ($pluginClass === self::MATCHMANAGERADMINUI_PLUGIN) { | ||||||
|  | 			$this->updateAdminUIMenuItems(); | ||||||
|  | 		} | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	/** | 	/** | ||||||
| @@ -174,6 +205,21 @@ class MatchManagerMultipleConfigManager implements ManialinkPageAnswerListener, | |||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | 	/** | ||||||
|  | 	 * Add items in AdminUI plugin | ||||||
|  | 	 */ | ||||||
|  | 	public function updateAdminUIMenuItems() { | ||||||
|  | 		/** @var \MatchManagerSuite\MatchManagerAdminUI|null */ | ||||||
|  | 		$adminUIPlugin = $this->maniaControl->getPluginManager()->getPlugin(self::MATCHMANAGERADMINUI_PLUGIN); | ||||||
|  | 		if ($adminUIPlugin === null) return; | ||||||
|  |  | ||||||
|  | 		$adminUIPlugin->removeMenuItem(self::ML_ACTION_OPENSETTINGS); | ||||||
|  |  | ||||||
|  | 		$menuItem = new \MatchManagerSuite\MatchManagerAdminUI_MenuItem(); | ||||||
|  | 		$menuItem->setActionId(self::ML_ACTION_OPENSETTINGS)->setOrder(200)->setStyle('UICommon64_2')->setSubStyle('Plugin_light')->setDescription('Manage Multiple Configs'); | ||||||
|  | 		$adminUIPlugin->addMenuItem($menuItem); | ||||||
|  | 	} | ||||||
|  |  | ||||||
| 	/** | 	/** | ||||||
| 	 * handleManialinkPageAnswer | 	 * handleManialinkPageAnswer | ||||||
| 	 * | 	 * | ||||||
| @@ -181,10 +227,10 @@ class MatchManagerMultipleConfigManager implements ManialinkPageAnswerListener, | |||||||
| 	 * @return void | 	 * @return void | ||||||
| 	 */ | 	 */ | ||||||
| 	public function handleManialinkPageAnswer(array $callback) { | 	public function handleManialinkPageAnswer(array $callback) { | ||||||
| 		Logger::log("handleManialinkPageAnswer"); |  | ||||||
| 		$actionId    = $callback[1][2]; | 		$actionId    = $callback[1][2]; | ||||||
| 		$actionArray = explode('.', $actionId); | 		$actionArray = explode('.', $actionId); | ||||||
| 		if ($actionArray[0] != "MatchManager" || $actionArray[1] != "MultiConfigManager") { |  | ||||||
|  | 		if ($actionArray[0] !== self::class) { | ||||||
| 			return; | 			return; | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| @@ -194,9 +240,10 @@ class MatchManagerMultipleConfigManager implements ManialinkPageAnswerListener, | |||||||
| 			return; | 			return; | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		$action = $actionArray[0] . '.' . $actionArray[1] . '.' . $actionArray[2]; | 		switch ($actionId) { | ||||||
|  | 			case self::ML_ACTION_OPENSETTINGS: | ||||||
| 		switch ($action) { | 				$this->showConfigListUI(array(), $player); | ||||||
|  | 				break; | ||||||
| 			case self::ML_ACTION_REMOVE_CONFIG: | 			case self::ML_ACTION_REMOVE_CONFIG: | ||||||
| 				$id = intval($actionArray[3]); | 				$id = intval($actionArray[3]); | ||||||
| 				Logger::log("[MatchManagerMultipleConfigManager] Removing config: " . $id); | 				Logger::log("[MatchManagerMultipleConfigManager] Removing config: " . $id); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user