- Ingame configurator -> script settings
- fixed local records plugin - fixed systeminfo command - FML update
This commit is contained in:
@ -8,12 +8,19 @@ use ManiaControl\Callbacks\CallbackManager;
|
||||
use ManiaControl\Manialinks\ManialinkPageAnswerListener;
|
||||
use ManiaControl\Players\Player;
|
||||
use FML\ManiaLink;
|
||||
use FML\Controls\Quad;
|
||||
use FML\Controls\Control;
|
||||
use FML\Controls\Frame;
|
||||
use FML\Controls\Quads\Quad_UiSMSpectatorScoreBig;
|
||||
use FML\Controls\Quads\Quad_EnergyBar;
|
||||
use FML\Controls\Quads\Quad_BgsPlayerCard;
|
||||
use FML\Controls\Label;
|
||||
use FML\Controls\Labels\Label_Text;
|
||||
use FML\Controls\Quad;
|
||||
use FML\Controls\Quads\Quad_BgRaceScore2;
|
||||
use FML\Script\Menus;
|
||||
use FML\Script\Pages;
|
||||
use FML\Script\Script;
|
||||
use FML\Script\Tooltips;
|
||||
|
||||
require_once __DIR__ . '/ConfiguratorMenu.php';
|
||||
require_once __DIR__ . '/ScriptSettings.php';
|
||||
|
||||
/**
|
||||
* Class managing ingame ManiaControl configuration
|
||||
@ -26,14 +33,22 @@ class Configurator implements CallbackListener, ManialinkPageAnswerListener {
|
||||
*/
|
||||
const MLID_MENU = 'Configurator.Menu.MLID';
|
||||
const ACTION_TOGGLEMENU = 'Configurator.ToggleMenuAction';
|
||||
const ACTION_SAVECONFIG = 'Configurator.SaveConfigAction';
|
||||
const SETTING_MENU_POSX = 'Menu Widget Position: X';
|
||||
const SETTING_MENU_POSY = 'Menu Widget Position: Y';
|
||||
const SETTING_MENU_WIDTH = 'Menu Widget Width';
|
||||
const SETTING_MENU_HEIGHT = 'Menu Widget Height';
|
||||
const SETTING_MENU_STYLE = 'Menu Widget BackgroundQuad Style';
|
||||
const SETTING_MENU_SUBSTYLE = 'Menu Widget BackgroundQuad Substyle';
|
||||
|
||||
/**
|
||||
* Private properties
|
||||
*/
|
||||
private $maniaControl = null;
|
||||
private $scriptSettings = null;
|
||||
private $menus = array();
|
||||
private $playersMenuShown = array();
|
||||
private $manialink = null;
|
||||
private $emptyManialink = null;
|
||||
|
||||
/**
|
||||
* Create a new Configurator
|
||||
@ -44,13 +59,37 @@ class Configurator implements CallbackListener, ManialinkPageAnswerListener {
|
||||
$this->maniaControl = $maniaControl;
|
||||
$this->addAdminMenuItem();
|
||||
|
||||
// Init settings
|
||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_MENU_POSX, 0.);
|
||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_MENU_POSY, 0.);
|
||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_MENU_WIDTH, 170.);
|
||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_MENU_HEIGHT, 90.);
|
||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_MENU_STYLE, Quad_BgRaceScore2::STYLE);
|
||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_MENU_SUBSTYLE,
|
||||
Quad_BgRaceScore2::SUBSTYLE_HandleSelectable);
|
||||
|
||||
// Register for page answers
|
||||
$this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_TOGGLEMENU, $this,
|
||||
'handleToggleMenuAction');
|
||||
$this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_SAVECONFIG, $this,
|
||||
'handleSaveConfigAction');
|
||||
|
||||
// Register for callbacks
|
||||
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERDISCONNECT, $this,
|
||||
'handlePlayerDisconnect');
|
||||
|
||||
// Create script settings
|
||||
$this->scriptSettings = new ScriptSettings($maniaControl);
|
||||
$this->addMenu($this->scriptSettings);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a configurator menu
|
||||
*
|
||||
* @param ConfiguratorMenu $menu
|
||||
*/
|
||||
public function addMenu(ConfiguratorMenu $menu) {
|
||||
array_push($this->menus, $menu);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -67,6 +106,18 @@ class Configurator implements CallbackListener, ManialinkPageAnswerListener {
|
||||
$this->showMenu($player);
|
||||
}
|
||||
|
||||
/**
|
||||
* Save the config data received from the manialink
|
||||
*
|
||||
* @param array $callback
|
||||
* @param Player $player
|
||||
*/
|
||||
public function handleSaveConfigAction(array $callback, Player $player) {
|
||||
foreach ($this->menus as $menu) {
|
||||
$menu->saveConfigData($callback[1], $player);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle PlayerDisconnect callback
|
||||
*
|
||||
@ -74,9 +125,7 @@ class Configurator implements CallbackListener, ManialinkPageAnswerListener {
|
||||
*/
|
||||
public function handlePlayerDisconnect(array $callback) {
|
||||
$login = $callback[1][0];
|
||||
if (isset($this->playersMenuShown[$login])) {
|
||||
unset($this->playersMenuShown[$login]);
|
||||
}
|
||||
unset($this->playersMenuShown[$login]);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -98,8 +147,8 @@ class Configurator implements CallbackListener, ManialinkPageAnswerListener {
|
||||
* @param Player $player
|
||||
*/
|
||||
private function hideMenu(Player $player) {
|
||||
$this->buildManialink();
|
||||
$manialinkText = $this->emptyManialink->render()->saveXML();
|
||||
$emptyManialink = new ManiaLink(self::MLID_MENU);
|
||||
$manialinkText = $emptyManialink->render()->saveXML();
|
||||
$this->maniaControl->manialinkManager->sendManialink($manialinkText, $player->login);
|
||||
$this->maniaControl->manialinkManager->enableAltMenu($player);
|
||||
unset($this->playersMenuShown[$player->login]);
|
||||
@ -111,19 +160,98 @@ class Configurator implements CallbackListener, ManialinkPageAnswerListener {
|
||||
* @param bool $forceBuild
|
||||
*/
|
||||
private function buildManialink($forceBuild = false) {
|
||||
if (is_object($this->manialink) && !$forceBuild) return;
|
||||
$menuPosX = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MENU_POSX);
|
||||
$menuPosY = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MENU_POSY);
|
||||
$menuWidth = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MENU_WIDTH);
|
||||
$menuHeight = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MENU_HEIGHT);
|
||||
$quadStyle = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MENU_STYLE);
|
||||
$quadSubstyle = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MENU_SUBSTYLE);
|
||||
|
||||
$this->emptyManialink = new ManiaLink(self::MLID_MENU);
|
||||
$menuListWidth = $menuWidth * 0.3;
|
||||
$menuItemHeight = 10.;
|
||||
$subMenuWidth = $menuWidth - $menuListWidth;
|
||||
$subMenuHeight = $menuHeight;
|
||||
|
||||
$manialink = new ManiaLink(self::MLID_MENU);
|
||||
|
||||
$frame = new Frame();
|
||||
$manialink->add($frame);
|
||||
$frame->setPosition($menuPosX, $menuPosY);
|
||||
|
||||
$backgroundQuad = new Quad_BgRaceScore2();
|
||||
$backgroundQuad = new Quad();
|
||||
$frame->add($backgroundQuad);
|
||||
$backgroundQuad->setSize(100, 70);
|
||||
$backgroundQuad->setSubStyle($backgroundQuad::SUBSTYLE_HandleSelectable);
|
||||
$backgroundQuad->setSize($menuWidth, $menuHeight);
|
||||
$backgroundQuad->setStyles($quadStyle, $quadSubstyle);
|
||||
|
||||
$menuItemsFrame = new Frame();
|
||||
$frame->add($menuItemsFrame);
|
||||
$menuItemsFrame->setX($menuWidth * -0.5 + $menuListWidth * 0.5);
|
||||
|
||||
$itemsBackgroundQuad = new Quad();
|
||||
$menuItemsFrame->add($itemsBackgroundQuad);
|
||||
$itemsBackgroundQuad->setSize($menuListWidth, $menuHeight);
|
||||
$itemsBackgroundQuad->setStyles($quadStyle, $quadSubstyle);
|
||||
|
||||
$menusFrame = new Frame();
|
||||
$frame->add($menusFrame);
|
||||
$menusFrame->setX($menuWidth * -0.5 + $menuListWidth + $subMenuWidth * 0.5);
|
||||
|
||||
// Create script and features
|
||||
$script = new Script();
|
||||
$manialink->setScript($script);
|
||||
|
||||
$pages = new Pages();
|
||||
$script->addFeature($pages);
|
||||
|
||||
$tooltips = new Tooltips();
|
||||
$script->addFeature($tooltips);
|
||||
|
||||
$menus = new Menus();
|
||||
$script->addFeature($menus);
|
||||
|
||||
$menuRelationships = array();
|
||||
$menuItemY = $menuHeight * 0.42;
|
||||
foreach ($this->menus as $menu) {
|
||||
// Add title
|
||||
$menuItemLabel = new Label();
|
||||
$menuItemsFrame->add($menuItemLabel);
|
||||
$menuItemLabel->setY($menuItemY);
|
||||
$menuItemLabel->setSize($menuListWidth * 0.9, $menuItemHeight * 0.9);
|
||||
$menuItemLabel->setStyle(Label_Text::STYLE_TextCardRaceRank);
|
||||
$menuItemLabel->setText($menu->getTitle());
|
||||
|
||||
// Add menu
|
||||
$menuControl = $menu->getMenu($subMenuWidth, $subMenuHeight, $pages, $tooltips);
|
||||
$menusFrame->add($menuControl);
|
||||
|
||||
// Add menu relationship
|
||||
array_push($menuRelationships, array($menuItemLabel, $menuControl));
|
||||
|
||||
$menuItemY -= $menuItemHeight * 1.1;
|
||||
}
|
||||
$menus->add($menuRelationships);
|
||||
|
||||
// Add close button
|
||||
$closeButton = new Label();
|
||||
$frame->add($closeButton);
|
||||
$closeButton->setPosition($menuWidth * -0.5 + $menuListWidth * 0.29, $menuHeight * -0.43);
|
||||
$closeButton->setSize($menuListWidth * 0.3, $menuListWidth * 0.1);
|
||||
$closeButton->setStyle(Label_Text::STYLE_TextButtonNavBack);
|
||||
$closeButton->setTextPrefix('$999');
|
||||
$closeButton->setTranslate(true);
|
||||
$closeButton->setText('Close');
|
||||
$closeButton->setAction(self::ACTION_TOGGLEMENU);
|
||||
|
||||
// Add save button
|
||||
$saveButton = new Label();
|
||||
$frame->add($saveButton);
|
||||
$saveButton->setPosition($menuWidth * -0.5 + $menuListWidth * 0.71, $menuHeight * -0.43);
|
||||
$saveButton->setSize($menuListWidth * 0.3, $menuListWidth * 0.1);
|
||||
$saveButton->setStyle(Label_Text::STYLE_TextButtonNavBack);
|
||||
$saveButton->setTextPrefix('$0f5');
|
||||
$saveButton->setTranslate(true);
|
||||
$saveButton->setText('Save');
|
||||
$saveButton->setAction(self::ACTION_SAVECONFIG);
|
||||
|
||||
$this->manialink = $manialink;
|
||||
}
|
||||
|
Reference in New Issue
Block a user