- Improved ManialinkManager
- First Step for ingame Configurator - AdminMenu - StyleManager - Callbacks of PlayerManager
This commit is contained in:
@ -1,31 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace ManiaControl\Manialinks;
|
||||
|
||||
/**
|
||||
* Handler for manialink ids
|
||||
*
|
||||
* @author kremsy & steeffeen
|
||||
*/
|
||||
class ManialinkIdHandler {
|
||||
/**
|
||||
* Private properties
|
||||
*/
|
||||
private $maniaLinkIdCount = 0;
|
||||
|
||||
/**
|
||||
* Reserve manialink ids
|
||||
*
|
||||
* @param int $count
|
||||
* @return array with manialink Ids
|
||||
*/
|
||||
public function reserveManiaLinkIds($count) {
|
||||
$manialinkIds = array();
|
||||
for ($i = 0; $i < $count; $i++) {
|
||||
array_push($manialinkIds, $this->maniaLinkIdCount++);
|
||||
}
|
||||
return $manialinkIds;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@ -6,7 +6,7 @@ use ManiaControl\ManiaControl;
|
||||
use ManiaControl\Callbacks\CallbackListener;
|
||||
use ManiaControl\Callbacks\CallbackManager;
|
||||
|
||||
require_once __DIR__ . '/ManialinkPageAnswerListener.php';
|
||||
require_once __DIR__ . '/StyleManager.php';
|
||||
require_once __DIR__ . '/../FML/autoload.php';
|
||||
|
||||
/**
|
||||
@ -15,11 +15,16 @@ require_once __DIR__ . '/../FML/autoload.php';
|
||||
* @author steeffeen & kremsy
|
||||
*/
|
||||
class ManialinkManager implements CallbackListener {
|
||||
/**
|
||||
* Public properties
|
||||
*/
|
||||
public $styleManager = null;
|
||||
/**
|
||||
* Private properties
|
||||
*/
|
||||
private $maniaControl = null;
|
||||
private $pageAnswerListeners = array();
|
||||
private $maniaLinkIdCount = 0;
|
||||
|
||||
/**
|
||||
* Create a new manialink manager
|
||||
@ -28,6 +33,9 @@ class ManialinkManager implements CallbackListener {
|
||||
*/
|
||||
public function __construct(ManiaControl $maniaControl) {
|
||||
$this->maniaControl = $maniaControl;
|
||||
$this->styleManager = new StyleManager($maniaControl);
|
||||
|
||||
// Register for callbacks
|
||||
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this,
|
||||
'handleManialinkPageAnswer');
|
||||
}
|
||||
@ -35,32 +43,56 @@ class ManialinkManager implements CallbackListener {
|
||||
/**
|
||||
* Register a new manialink page answer listener
|
||||
*
|
||||
* @param string $manialinkId
|
||||
* @param string $actionId
|
||||
* @param ManialinkPageAnswerListener $listener
|
||||
* @param string $method
|
||||
* @return bool
|
||||
*/
|
||||
public function registerManialinkPageAnswerListener($manialinkId, ManialinkPageAnswerListener $listener, $method) {
|
||||
public function registerManialinkPageAnswerListener($actionId, ManialinkPageAnswerListener $listener, $method) {
|
||||
if (!method_exists($listener, $method)) {
|
||||
trigger_error("Given listener for manialinkId '{$manialinkId}' doesn't have callback method '{$method}'.");
|
||||
trigger_error("Given listener for actionId '{$actionId}' doesn't have callback method '{$method}'!");
|
||||
return false;
|
||||
}
|
||||
if (!array_key_exists($manialinkId, $this->pageAnswerListeners) || !is_array($this->pageAnswerListeners[$manialinkId])) {
|
||||
if (!array_key_exists($actionId, $this->pageAnswerListeners) || !is_array($this->pageAnswerListeners[$actionId])) {
|
||||
// Init listeners array
|
||||
$this->pageAnswerListeners[$manialinkId] = array();
|
||||
$this->pageAnswerListeners[$actionId] = array();
|
||||
}
|
||||
// Register page answer listener
|
||||
array_push($this->pageAnswerListeners[$manialinkId], array($listener, $method));
|
||||
array_push($this->pageAnswerListeners[$actionId], array($listener, $method));
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reserve manialink ids
|
||||
*
|
||||
* @param int $count
|
||||
* @return array
|
||||
*/
|
||||
public function reserveManiaLinkIds($count) {
|
||||
$manialinkIds = array();
|
||||
for ($i = 0; $i < $count; $i++) {
|
||||
array_push($manialinkIds, $this->maniaLinkIdCount++);
|
||||
}
|
||||
return $manialinkIds;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle ManialinkPageAnswer callback
|
||||
*
|
||||
* @param array $callback
|
||||
*/
|
||||
public function handleManialinkPageAnswer(array $callback) {
|
||||
var_dump($callback);
|
||||
$actionId = $callback[1][2];
|
||||
$login = $callback[1][1];
|
||||
$player = $this->maniaControl->playerManager->getPlayer($login);
|
||||
if (!array_key_exists($actionId, $this->pageAnswerListeners) || !is_array($this->pageAnswerListeners[$actionId])) {
|
||||
// No page answer listener registered
|
||||
return;
|
||||
}
|
||||
// Inform page answer listeners
|
||||
foreach ($this->pageAnswerListeners[$actionId] as $listener) {
|
||||
call_user_func(array($listener[0], $listener[1]), $callback, $player);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
67
application/core/Manialinks/StyleManager.php
Normal file
67
application/core/Manialinks/StyleManager.php
Normal file
@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace ManiaControl\Manialinks;
|
||||
|
||||
use ManiaControl\ManiaControl;
|
||||
|
||||
/**
|
||||
* Class managing default control styles
|
||||
*
|
||||
* @author steeffeen & kremsy
|
||||
*/
|
||||
class StyleManager {
|
||||
/**
|
||||
* Constants
|
||||
*/
|
||||
const SETTING_LABEL_DEFAULT_STYLE = 'Default Label Style';
|
||||
const SETTING_QUAD_DEFAULT_STYLE = 'Default Quad Style';
|
||||
const SETTING_QUAD_DEFAULT_SUBSTYLE = 'Default Quad SubStyle';
|
||||
|
||||
/**
|
||||
* Private properties
|
||||
*/
|
||||
private $maniaControl = null;
|
||||
|
||||
/**
|
||||
* Create a new style manager instance
|
||||
*
|
||||
* @param ManiaControl $maniaControl
|
||||
*/
|
||||
public function __construct(ManiaControl $maniaControl) {
|
||||
$this->maniaControl = $maniaControl;
|
||||
|
||||
// Init settings
|
||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_LABEL_DEFAULT_STYLE, 'TextTitle1');
|
||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_QUAD_DEFAULT_STYLE, 'Bgs1InRace');
|
||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_QUAD_DEFAULT_SUBSTYLE, 'BgTitleShadow');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default label style
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDefaultLabelStyle() {
|
||||
return $this->maniaControl->settingManager->getSetting($this, self::SETTING_LABEL_DEFAULT_STYLE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default quad style
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDefaultQuadStyle() {
|
||||
return $this->maniaControl->settingManager->getSetting($this, self::SETTING_QUAD_DEFAULT_STYLE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default quad substyle
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDefaultQuadSubstyle() {
|
||||
return $this->maniaControl->settingManager->getSetting($this, self::SETTING_QUAD_DEFAULT_SUBSTYLE);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
Reference in New Issue
Block a user