- Improvements of and for the Ingame Configurator
This commit is contained in:
parent
9bed5b3d3f
commit
c39d35d1fe
@ -17,7 +17,6 @@ class CallbackManager {
|
||||
const CB_MC_1_SECOND = 'ManiaControl.1Second';
|
||||
const CB_MC_5_SECOND = 'ManiaControl.5Second';
|
||||
const CB_MC_1_MINUTE = 'ManiaControl.1Minute';
|
||||
const CB_MC_3_MINUTE = 'ManiaControl.3Minute';
|
||||
const CB_MC_ONINIT = 'ManiaControl.OnInit';
|
||||
const CB_MC_CLIENTUPDATED = 'ManiaControl.ClientUpdated';
|
||||
const CB_MC_BEGINMAP = 'ManiaControl.BeginMap';
|
||||
@ -55,7 +54,6 @@ class CallbackManager {
|
||||
private $last1Second = -1;
|
||||
private $last5Second = -1;
|
||||
private $last1Minute = -1;
|
||||
private $last3Minute = -1;
|
||||
|
||||
/**
|
||||
* Construct callbacks manager
|
||||
@ -248,13 +246,6 @@ class CallbackManager {
|
||||
}
|
||||
$this->last1Minute = time();
|
||||
$this->triggerCallback(self::CB_MC_1_MINUTE, array(self::CB_MC_1_MINUTE));
|
||||
|
||||
// 3 minute
|
||||
if ($this->last3Minute > time() - 180) {
|
||||
return;
|
||||
}
|
||||
$this->last3Minute = time();
|
||||
$this->triggerCallback(self::CB_MC_3_MINUTE, array(self::CB_MC_3_MINUTE));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3,25 +3,37 @@
|
||||
namespace ManiaControl\Configurators;
|
||||
|
||||
use ManiaControl\ManiaControl;
|
||||
use ManiaControl\Callbacks\CallbackListener;
|
||||
use ManiaControl\Callbacks\CallbackManager;
|
||||
use ManiaControl\Manialinks\ManialinkPageAnswerListener;
|
||||
use ManiaControl\Players\Player;
|
||||
use FML\ManiaLink;
|
||||
use FML\Controls\Quad;
|
||||
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\Quads\Quad_BgRaceScore2;
|
||||
|
||||
/**
|
||||
* Class managing ingame ManiaControl configuration
|
||||
*
|
||||
* @author steeffeen & kremsy
|
||||
*/
|
||||
class Configurator implements ManialinkPageAnswerListener {
|
||||
class Configurator implements CallbackListener, ManialinkPageAnswerListener {
|
||||
/**
|
||||
* Constants
|
||||
*/
|
||||
const ACTION_CONFIG = 'Configurator.ConfigAction';
|
||||
const MLID_MENU = 'Configurator.Menu.MLID';
|
||||
const ACTION_TOGGLEMENU = 'Configurator.ToggleMenuAction';
|
||||
|
||||
/**
|
||||
* Private properties
|
||||
*/
|
||||
private $maniaControl = null;
|
||||
private $playersMenuShown = array();
|
||||
private $manialink = null;
|
||||
private $emptyManialink = null;
|
||||
|
||||
/**
|
||||
* Create a new Configurator
|
||||
@ -32,17 +44,88 @@ class Configurator implements ManialinkPageAnswerListener {
|
||||
$this->maniaControl = $maniaControl;
|
||||
$this->addAdminMenuItem();
|
||||
|
||||
// Register for page answer
|
||||
$this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_CONFIG, $this, 'handlePageAnswer');
|
||||
// Register for page answers
|
||||
$this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_TOGGLEMENU, $this,
|
||||
'handleToggleMenuAction');
|
||||
|
||||
// Register for callbacks
|
||||
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERDISCONNECT, $this,
|
||||
'handlePlayerDisconnect');
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle PageAnswer callback
|
||||
* Handle toggle menu action
|
||||
*
|
||||
* @param array $callback
|
||||
* @param Player $player
|
||||
*/
|
||||
public function handlePageAnswer(array $callback, Player $player) {
|
||||
public function handleToggleMenuAction(array $callback, Player $player) {
|
||||
if (isset($this->playersMenuShown[$player->login])) {
|
||||
$this->hideMenu($player);
|
||||
return;
|
||||
}
|
||||
$this->showMenu($player);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle PlayerDisconnect callback
|
||||
*
|
||||
* @param array $callback
|
||||
*/
|
||||
public function handlePlayerDisconnect(array $callback) {
|
||||
$login = $callback[1][0];
|
||||
if (isset($this->playersMenuShown[$login])) {
|
||||
unset($this->playersMenuShown[$login]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the menu to the player
|
||||
*
|
||||
* @param Player $player
|
||||
*/
|
||||
private function showMenu(Player $player) {
|
||||
$this->buildManialink();
|
||||
$manialinkText = $this->manialink->render()->saveXML();
|
||||
$this->maniaControl->manialinkManager->sendManialink($manialinkText, $player->login);
|
||||
$this->maniaControl->manialinkManager->disableAltMenu($player);
|
||||
$this->playersMenuShown[$player->login] = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hide the menu for the player
|
||||
*
|
||||
* @param Player $player
|
||||
*/
|
||||
private function hideMenu(Player $player) {
|
||||
$this->buildManialink();
|
||||
$manialinkText = $this->emptyManialink->render()->saveXML();
|
||||
$this->maniaControl->manialinkManager->sendManialink($manialinkText, $player->login);
|
||||
$this->maniaControl->manialinkManager->enableAltMenu($player);
|
||||
unset($this->playersMenuShown[$player->login]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build menu manialink if necessary
|
||||
*
|
||||
* @param bool $forceBuild
|
||||
*/
|
||||
private function buildManialink($forceBuild = false) {
|
||||
if (is_object($this->manialink) && !$forceBuild) return;
|
||||
|
||||
$this->emptyManialink = new ManiaLink(self::MLID_MENU);
|
||||
|
||||
$manialink = new ManiaLink(self::MLID_MENU);
|
||||
|
||||
$frame = new Frame();
|
||||
$manialink->add($frame);
|
||||
|
||||
$backgroundQuad = new Quad_BgRaceScore2();
|
||||
$frame->add($backgroundQuad);
|
||||
$backgroundQuad->setSize(100, 70);
|
||||
$backgroundQuad->setSubStyle($backgroundQuad::SUBSTYLE_HandleSelectable);
|
||||
|
||||
$this->manialink = $manialink;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -51,8 +134,7 @@ class Configurator implements ManialinkPageAnswerListener {
|
||||
private function addAdminMenuItem() {
|
||||
$itemQuad = new Quad();
|
||||
$itemQuad->setStyles('Icons128x32_1', 'Settings');
|
||||
$itemQuad->setAction(self::ACTION_CONFIG);
|
||||
|
||||
$itemQuad->setAction(self::ACTION_TOGGLEMENU);
|
||||
$this->maniaControl->adminMenu->addMenuItem($itemQuad, 5);
|
||||
}
|
||||
}
|
||||
|
@ -14,6 +14,20 @@ class Quad_BgsPlayerCard extends Quad {
|
||||
* Constants
|
||||
*/
|
||||
const STYLE = 'BgsPlayerCard';
|
||||
const SUBSTYLE_BgActivePlayerCard = 'BgActivePlayerCard';
|
||||
const SUBSTYLE_BgActivePlayerName = 'BgActivePlayerName';
|
||||
const SUBSTYLE_BgActivePlayerScore = 'BgActivePlayerScore';
|
||||
const SUBSTYLE_BgCard = 'BgCard';
|
||||
const SUBSTYLE_BgCardSystem = 'BgCardSystem';
|
||||
const SUBSTYLE_BgMediaTracker = 'BgMediaTracker';
|
||||
const SUBSTYLE_BgPlayerCard = 'BgPlayerCard';
|
||||
const SUBSTYLE_BgPlayerCardBig = 'BgPlayerCardBig';
|
||||
const SUBSTYLE_BgPlayerCardSmall = 'BgPlayerCardSmall';
|
||||
const SUBSTYLE_BgPlayerName = 'BgPlayerName';
|
||||
const SUBSTYLE_BgPlayerScore = 'BgPlayerScore';
|
||||
const SUBSTYLE_BgRacePlayerLine = 'BgRacePlayerLine';
|
||||
const SUBSTYLE_BgRacePlayerName = 'BgRacePlayerName';
|
||||
const SUBSTYLE_ProgressBar = 'ProgressBar';
|
||||
|
||||
/**
|
||||
* Construct BgsPlayerCard quad
|
||||
@ -21,9 +35,6 @@ class Quad_BgsPlayerCard extends Quad {
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
$this->setStyle(self::STYLE);
|
||||
array("BgActivePlayerCard", "BgActivePlayerName", "BgActivePlayerScore", "BgCard", "BgCardSystem", "BgMediaTracker",
|
||||
"BgPlayerCard", "BgPlayerCardBig", "BgPlayerCardSmall", "BgPlayerName", "BgPlayerScore", "BgRacePlayerLine",
|
||||
"BgRacePlayerName", "ProgressBar");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -14,6 +14,12 @@ class Quad_EnergyBar extends Quad {
|
||||
* Constants
|
||||
*/
|
||||
const STYLE = 'EnergyBar';
|
||||
const SUBSTYLE_BgText = 'BgText';
|
||||
const SUBSTYLE_EnergyBar = 'EnergyBar';
|
||||
const SUBSTYLE_EnergyBar_0_25 = 'EnergyBar_0.25';
|
||||
const SUBSTYLE_EnergyBar_Thin = 'EnergyBar_Thin';
|
||||
const SUBSTYLE_HeaderGaugeLeft = 'HeaderGaugeLeft';
|
||||
const SUBSTYLE_HeaderGaugeRight = 'HeaderGaugeRight';
|
||||
|
||||
/**
|
||||
* Construct EnergyBar quad
|
||||
@ -21,7 +27,6 @@ class Quad_EnergyBar extends Quad {
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
$this->setStyle(self::STYLE);
|
||||
array("BgText", "EnergyBar", "EnergyBar_0.25", "EnergyBar_Thin", "HeaderGaugeLeft", "HeaderGaugeRight");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5,6 +5,7 @@ namespace ManiaControl\Manialinks;
|
||||
use ManiaControl\ManiaControl;
|
||||
use ManiaControl\Callbacks\CallbackListener;
|
||||
use ManiaControl\Callbacks\CallbackManager;
|
||||
use ManiaControl\Players\Player;
|
||||
|
||||
require_once __DIR__ . '/StyleManager.php';
|
||||
require_once __DIR__ . '/../FML/autoload.php';
|
||||
@ -125,6 +126,26 @@ class ManialinkManager implements CallbackListener {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable the alt menu for the player
|
||||
*
|
||||
* @param Player $player
|
||||
* @return bool
|
||||
*/
|
||||
public function enableAltMenu(Player $player) {
|
||||
return $this->maniaControl->client->query('TriggerModeScriptEvent', 'LibXmlRpc_EnableAltMenu', $player->login);
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable the alt menu for the player
|
||||
*
|
||||
* @param Player $player
|
||||
* @return bool
|
||||
*/
|
||||
public function disableAltMenu(Player $player) {
|
||||
return $this->maniaControl->client->query('TriggerModeScriptEvent', 'LibXmlRpc_DisableAltMenu', $player->login);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
@ -306,6 +306,28 @@ class SettingManager {
|
||||
$settingStatement->close();
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all settings
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getSettings() {
|
||||
$mysqli = $this->maniaControl->database->mysqli;
|
||||
$query = "SELECT * FROM `" . self::TABLE_SETTINGS . "`
|
||||
ORDER BY `class` ASC, `setting` ASC;";
|
||||
$result = $mysqli->query($query);
|
||||
if ($mysqli->error) {
|
||||
trigger_error($mysqli->error);
|
||||
return null;
|
||||
}
|
||||
$settings = array();
|
||||
while ($setting = $result->fetch_object()) {
|
||||
array_push($settings, $setting);
|
||||
}
|
||||
$result->free();
|
||||
return $settings;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
Loading…
Reference in New Issue
Block a user