- Improved ManialinkManager
- First Step for ingame Configurator - AdminMenu - StyleManager - Callbacks of PlayerManager
This commit is contained in:
parent
e09f3ee95f
commit
9bed5b3d3f
@ -1,5 +1,152 @@
|
||||
<?php
|
||||
|
||||
namespace ManiaControl\Admin;
|
||||
|
||||
use ManiaControl\ManiaControl;
|
||||
use ManiaControl\Callbacks\CallbackListener;
|
||||
use ManiaControl\Callbacks\CallbackManager;
|
||||
use FML\ManiaLink;
|
||||
use FML\Controls\Control;
|
||||
use FML\Controls\Frame;
|
||||
use FML\Controls\Quad;
|
||||
use ManiaControl\Players\Player;
|
||||
use ManiaControl\Players\PlayerManager;
|
||||
|
||||
/**
|
||||
* Class offering and managing the admin menu
|
||||
*
|
||||
* @author steeffeen & kremsy
|
||||
*/
|
||||
class AdminMenu implements CallbackListener {
|
||||
/**
|
||||
* Constants
|
||||
*/
|
||||
const MLID_MENU = 'AdminMenu.MLID';
|
||||
const SETTING_MENU_POSX = 'Menu Position: X';
|
||||
const SETTING_MENU_POSY = 'Menu Position: Y';
|
||||
const SETTING_MENU_ITEMSIZE = 'Menu Item Size';
|
||||
|
||||
/**
|
||||
* Private properties
|
||||
*/
|
||||
private $maniaControl = null;
|
||||
private $manialink = null;
|
||||
private $menuItems = array();
|
||||
|
||||
/**
|
||||
* Create a new admin menu
|
||||
*
|
||||
* @param ManiaControl $maniaControl
|
||||
*/
|
||||
public function __construct(ManiaControl $maniaControl) {
|
||||
$this->maniaControl = $maniaControl;
|
||||
|
||||
// Init settings
|
||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_MENU_POSX, 130.);
|
||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_MENU_POSY, -70.);
|
||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_MENU_ITEMSIZE, 6.);
|
||||
|
||||
// Register for callbacks
|
||||
$this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_ONINIT, $this, 'handleOnInit');
|
||||
$this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERJOINED, $this, 'handlePlayerJoined');
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new menu item
|
||||
*
|
||||
* @param Control $control
|
||||
* @param float $order
|
||||
*/
|
||||
public function addMenuItem(Control $control, $order = 0.) {
|
||||
if (!isset($this->menuItems[$order])) {
|
||||
$this->menuItems[$order] = array();
|
||||
}
|
||||
array_push($this->menuItems[$order], $control);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle ManiaControl OnInit callback
|
||||
*
|
||||
* @param array $callback
|
||||
*/
|
||||
public function handleOnInit(array $callback) {
|
||||
$this->buildManialink();
|
||||
$manialinkText = $this->manialink->render()->saveXML();
|
||||
$players = $this->maniaControl->playerManager->getPlayers();
|
||||
foreach ($players as $player) {
|
||||
if (!$this->checkPlayerRight($player)) continue;
|
||||
$this->maniaControl->manialinkManager->sendManialink($manialinkText, $player->login);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle PlayerConnect callback
|
||||
*
|
||||
* @param array $callback
|
||||
*/
|
||||
public function handlePlayerJoined(array $callback) {
|
||||
$player = $callback[1];
|
||||
if (!$player || !$this->checkPlayerRight($player)) return;
|
||||
$this->buildManialink();
|
||||
$manialinkText = $this->manialink->render()->saveXML();
|
||||
$this->maniaControl->manialinkManager->sendManialink($manialinkText, $player->login);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the player has access to the admin menu
|
||||
*
|
||||
* @param Player $player
|
||||
* @return bool
|
||||
*/
|
||||
private function checkPlayerRight(Player $player) {
|
||||
return AuthenticationManager::checkRight($player, AuthenticationManager::AUTH_LEVEL_OPERATOR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the menu manialink if necessary
|
||||
*
|
||||
* @param bool $forceBuild
|
||||
*/
|
||||
private function buildManialink($forceBuild = false) {
|
||||
if (is_object($this->manialink) && !$forceBuild) return;
|
||||
|
||||
$posX = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MENU_POSX);
|
||||
$posY = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MENU_POSY);
|
||||
$itemSize = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MENU_ITEMSIZE);
|
||||
$quadStyle = $this->maniaControl->manialinkManager->styleManager->getDefaultQuadStyle();
|
||||
$quadSubstyle = $this->maniaControl->manialinkManager->styleManager->getDefaultQuadSubstyle();
|
||||
|
||||
$itemCount = count($this->menuItems);
|
||||
$itemMarginFactorX = 1.3;
|
||||
$itemMarginFactorY = 1.2;
|
||||
|
||||
$manialink = new ManiaLink(self::MLID_MENU);
|
||||
|
||||
$frame = new Frame();
|
||||
$manialink->add($frame);
|
||||
$frame->setPosition($posX, $posY);
|
||||
|
||||
$backgroundQuad = new Quad();
|
||||
$frame->add($backgroundQuad);
|
||||
$backgroundQuad->setSize($itemCount * $itemSize * $itemMarginFactorX, $itemSize * $itemMarginFactorY);
|
||||
$backgroundQuad->setStyles($quadStyle, $quadSubstyle);
|
||||
|
||||
$itemsFrame = new Frame();
|
||||
$frame->add($itemsFrame);
|
||||
|
||||
// Add items
|
||||
$x = 0.5 * $itemSize * $itemMarginFactorX;
|
||||
foreach ($this->menuItems as $itemOrder => $menuItems) {
|
||||
foreach ($menuItems as $menuItem) {
|
||||
$menuItem->setSize($itemSize, $itemSize);
|
||||
$itemsFrame->add($menuItem);
|
||||
|
||||
$x += $itemSize * $itemMarginFactorX;
|
||||
}
|
||||
}
|
||||
|
||||
$this->manialink = $manialink;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
@ -185,9 +185,6 @@ class AuthenticationManager implements CommandListener {
|
||||
* @return bool
|
||||
*/
|
||||
public static function checkRight(Player $player, $neededAuthLevel) {
|
||||
if (!$player) {
|
||||
return false;
|
||||
}
|
||||
return ($player->authLevel >= $neededAuthLevel);
|
||||
}
|
||||
|
||||
|
@ -2,8 +2,6 @@
|
||||
|
||||
namespace ManiaControl\Callbacks;
|
||||
|
||||
require_once __DIR__ . '/CallbackListener.php';
|
||||
|
||||
use ManiaControl\ManiaControl;
|
||||
|
||||
/**
|
||||
|
@ -2,8 +2,6 @@
|
||||
|
||||
namespace ManiaControl\Commands;
|
||||
|
||||
require_once __DIR__ . '/CommandListener.php';
|
||||
|
||||
use ManiaControl\ManiaControl;
|
||||
use ManiaControl\Admin\AuthenticationManager;
|
||||
use ManiaControl\Callbacks\CallbackListener;
|
||||
@ -60,30 +58,28 @@ class CommandManager implements CallbackListener {
|
||||
* Handle chat callback
|
||||
*
|
||||
* @param array $callback
|
||||
* @return bool
|
||||
*/
|
||||
public function handleChatCallback(array $callback) {
|
||||
// Check for command
|
||||
if (!$callback[1][3]) {
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
// Check for valid player
|
||||
$player = $this->maniaControl->playerManager->getPlayer($callback[1][1]);
|
||||
if (!$player) {
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
// Handle command
|
||||
$command = explode(" ", substr($callback[1][2], 1));
|
||||
$command = strtolower($command[0]);
|
||||
if (!array_key_exists($command, $this->commandListeners) || !is_array($this->commandListeners[$command])) {
|
||||
// No command listener registered
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
// Inform command listeners
|
||||
foreach ($this->commandListeners[$command] as $listener) {
|
||||
call_user_func(array($listener[0], $listener[1]), $callback, $player);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
60
application/core/Configurators/Configurator.php
Normal file
60
application/core/Configurators/Configurator.php
Normal file
@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace ManiaControl\Configurators;
|
||||
|
||||
use ManiaControl\ManiaControl;
|
||||
use ManiaControl\Manialinks\ManialinkPageAnswerListener;
|
||||
use ManiaControl\Players\Player;
|
||||
use FML\Controls\Quad;
|
||||
|
||||
/**
|
||||
* Class managing ingame ManiaControl configuration
|
||||
*
|
||||
* @author steeffeen & kremsy
|
||||
*/
|
||||
class Configurator implements ManialinkPageAnswerListener {
|
||||
/**
|
||||
* Constants
|
||||
*/
|
||||
const ACTION_CONFIG = 'Configurator.ConfigAction';
|
||||
|
||||
/**
|
||||
* Private properties
|
||||
*/
|
||||
private $maniaControl = null;
|
||||
|
||||
/**
|
||||
* Create a new Configurator
|
||||
*
|
||||
* @param ManiaControl $maniaControl
|
||||
*/
|
||||
public function __construct(ManiaControl $maniaControl) {
|
||||
$this->maniaControl = $maniaControl;
|
||||
$this->addAdminMenuItem();
|
||||
|
||||
// Register for page answer
|
||||
$this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_CONFIG, $this, 'handlePageAnswer');
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle PageAnswer callback
|
||||
*
|
||||
* @param array $callback
|
||||
* @param Player $player
|
||||
*/
|
||||
public function handlePageAnswer(array $callback, Player $player) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Add menu item to the admin menu
|
||||
*/
|
||||
private function addAdminMenuItem() {
|
||||
$itemQuad = new Quad();
|
||||
$itemQuad->setStyles('Icons128x32_1', 'Settings');
|
||||
$itemQuad->setAction(self::ACTION_CONFIG);
|
||||
|
||||
$this->maniaControl->adminMenu->addMenuItem($itemQuad, 5);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@ -2,26 +2,34 @@
|
||||
|
||||
namespace ManiaControl;
|
||||
|
||||
use ManiaControl\Admin\AdminMenu;
|
||||
use ManiaControl\Admin\AuthenticationManager;
|
||||
use ManiaControl\Callbacks\CallbackManager;
|
||||
use ManiaControl\Commands\CommandListener;
|
||||
use ManiaControl\Commands\CommandManager;
|
||||
use ManiaControl\Manialinks\ManialinkIdHandler;
|
||||
use ManiaControl\Configurators\Configurator;
|
||||
use ManiaControl\Manialinks\ManialinkManager;
|
||||
use ManiaControl\Maps\MapManager;
|
||||
use ManiaControl\Players\Player;
|
||||
use ManiaControl\Players\PlayerManager;
|
||||
use ManiaControl\Plugins\PluginManager;
|
||||
use ManiaControl\Server\Server;
|
||||
use ManiaControl\Manialinks\ManialinkManager;
|
||||
|
||||
require_once __DIR__ . '/Callbacks/CallbackManager.php';
|
||||
require_once __DIR__ . '/Commands/CommandManager.php';
|
||||
require_once __DIR__ . '/Callbacks/CallbackListener.php';
|
||||
require_once __DIR__ . '/Commands/CommandListener.php';
|
||||
require_once __DIR__ . '/Manialinks/ManialinkPageAnswerListener.php';
|
||||
require_once __DIR__ . '/Admin/AdminMenu.php';
|
||||
require_once __DIR__ . '/Admin/AuthenticationManager.php';
|
||||
require_once __DIR__ . '/Callbacks/CallbackManager.php';
|
||||
require_once __DIR__ . '/Chat.php';
|
||||
require_once __DIR__ . '/ColorUtil.php';
|
||||
require_once __DIR__ . '/Commands/CommandManager.php';
|
||||
require_once __DIR__ . '/Configurators/Configurator.php';
|
||||
require_once __DIR__ . '/Database.php';
|
||||
require_once __DIR__ . '/FileUtil.php';
|
||||
require_once __DIR__ . '/Formatter.php';
|
||||
require_once __DIR__ . '/Manialinks/ManialinkIdHandler.php';
|
||||
require_once __DIR__ . '/ManiaExchange/mxinfofetcher.inc.php';
|
||||
require_once __DIR__ . '/ManiaExchange/mxinfosearcher.inc.php';
|
||||
require_once __DIR__ . '/Manialinks/ManialinkManager.php';
|
||||
require_once __DIR__ . '/Maps/Map.php';
|
||||
require_once __DIR__ . '/Maps/MapManager.php';
|
||||
@ -30,9 +38,6 @@ require_once __DIR__ . '/Plugins/PluginManager.php';
|
||||
require_once __DIR__ . '/Server/Server.php';
|
||||
require_once __DIR__ . '/Settings/SettingManager.php';
|
||||
require_once __DIR__ . '/GbxDataFetcher/gbxdatafetcher.inc.php';
|
||||
require_once __DIR__ . '/ManiaExchange/mxinfofetcher.inc.php';
|
||||
require_once __DIR__ . '/ManiaExchange/mxinfosearcher.inc.php';
|
||||
require_once __DIR__ . '/ColorUtil.php';
|
||||
list($endiantest) = array_values(unpack('L1L', pack('V', 1)));
|
||||
if ($endiantest == 1) {
|
||||
require_once __DIR__ . '/PhpRemote/GbxRemote.inc.php';
|
||||
@ -57,9 +62,11 @@ class ManiaControl implements CommandListener {
|
||||
/**
|
||||
* Public properties
|
||||
*/
|
||||
public $adminMenu = null;
|
||||
public $authenticationManager = null;
|
||||
public $callbackManager = null;
|
||||
public $chat = null;
|
||||
public $configurator = null;
|
||||
public $client = null;
|
||||
public $commandManager = null;
|
||||
public $database = null;
|
||||
@ -81,8 +88,9 @@ class ManiaControl implements CommandListener {
|
||||
public function __construct() {
|
||||
$this->database = new Database($this);
|
||||
$this->callbackManager = new CallbackManager($this);
|
||||
$this->manialinkManager = new ManialinkManager($this);
|
||||
$this->settingManager = new SettingManager($this);
|
||||
$this->manialinkManager = new ManialinkManager($this);
|
||||
$this->adminMenu = new AdminMenu($this);
|
||||
$this->chat = new Chat($this);
|
||||
$this->commandManager = new CommandManager($this);
|
||||
$this->server = new Server($this);
|
||||
@ -90,6 +98,7 @@ class ManiaControl implements CommandListener {
|
||||
$this->authenticationManager = new AuthenticationManager($this);
|
||||
$this->mapManager = new MapManager($this);
|
||||
$this->pluginManager = new PluginManager($this);
|
||||
$this->configurator = new Configurator($this);
|
||||
|
||||
$this->commandManager->registerCommandListener('version', $this, 'command_Version');
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@ -18,6 +18,8 @@ class PlayerManager implements CallbackListener {
|
||||
/**
|
||||
* Constants
|
||||
*/
|
||||
const CB_PLAYERJOINED = 'PlayerManagerCallback.PlayerJoined';
|
||||
const CB_ONINIT = 'PlayerManagerCallback.OnInit';
|
||||
const TABLE_PLAYERS = 'mc_players';
|
||||
const SETTING_JOIN_LEAVE_MESSAGES = 'Enable Join & Leave Messages';
|
||||
|
||||
@ -34,9 +36,12 @@ class PlayerManager implements CallbackListener {
|
||||
*/
|
||||
public function __construct(ManiaControl $maniaControl) {
|
||||
$this->maniaControl = $maniaControl;
|
||||
|
||||
$this->initTables();
|
||||
|
||||
// Init settings
|
||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_JOIN_LEAVE_MESSAGES, false);
|
||||
|
||||
// Register for callbacks
|
||||
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MC_ONINIT, $this, 'onInit');
|
||||
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERCONNECT, $this, 'playerConnect');
|
||||
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERDISCONNECT, $this,
|
||||
@ -82,9 +87,6 @@ class PlayerManager implements CallbackListener {
|
||||
* @param array $callback
|
||||
*/
|
||||
public function onInit(array $callback) {
|
||||
// register settings
|
||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_JOIN_LEAVE_MESSAGES, false);
|
||||
|
||||
// Add all players
|
||||
$this->maniaControl->client->query('GetPlayerList', 300, 0, 2);
|
||||
$playerList = $this->maniaControl->client->getResponse();
|
||||
@ -97,6 +99,9 @@ class PlayerManager implements CallbackListener {
|
||||
$player = new Player($playerInfo);
|
||||
$this->addPlayer($player);
|
||||
}
|
||||
|
||||
// Trigger own callback
|
||||
$this->maniaControl->callbackManager->triggerCallback(self::CB_ONINIT, array(self::CB_ONINIT));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -111,9 +116,7 @@ class PlayerManager implements CallbackListener {
|
||||
$player = new Player($playerInfo);
|
||||
$this->addPlayer($player);
|
||||
|
||||
if (!$this->maniaControl->settingManager->getSetting($this, self::SETTING_JOIN_LEAVE_MESSAGES)) {
|
||||
return;
|
||||
}
|
||||
if ($this->maniaControl->settingManager->getSetting($this, self::SETTING_JOIN_LEAVE_MESSAGES)) {
|
||||
// TODO: improve styling?
|
||||
$string = array(0 => 'New Player', 1 => '$0f0Operator', 2 => '$0f0Admin', 3 => '$0f0MasterAdmin', 4 => '$0f0MasterAdmin');
|
||||
$nickname = Formatter::stripCodes($player->nickname);
|
||||
@ -122,6 +125,10 @@ class PlayerManager implements CallbackListener {
|
||||
' $ff0Ladder: $fff' . $player->ladderRank);
|
||||
}
|
||||
|
||||
// Trigger own callback
|
||||
$this->maniaControl->callbackManager->triggerCallback(self::CB_PLAYERJOINED, array(self::CB_PLAYERJOINED, $player));
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle playerDisconnect callback
|
||||
*
|
||||
|
@ -1,41 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace ManiaControl\Settings;
|
||||
|
||||
use ManiaControl\ManiaControl;
|
||||
use ManiaControl\Callbacks\CallbackListener;
|
||||
use ManiaControl\Callbacks\CallbackManager;
|
||||
|
||||
/**
|
||||
* Ingame setting configurator class
|
||||
*
|
||||
* @author kremsy & steeffeen
|
||||
*/
|
||||
class SettingConfigurator implements CallbackListener {
|
||||
/**
|
||||
* Private properties
|
||||
*/
|
||||
private $maniaControl = null;
|
||||
|
||||
/**
|
||||
* Construct setting configurator
|
||||
*
|
||||
* @param \ManiaControl\ManiaControl $maniaControl
|
||||
*/
|
||||
public function __construct(ManiaControl $maniaControl) {
|
||||
$this->maniaControl = $maniaControl;
|
||||
|
||||
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MC_ONINIT, $this, 'onInit');
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle OnInit callback
|
||||
*
|
||||
* @param array $callback
|
||||
*/
|
||||
public function onInit(array $callback) {
|
||||
// TODO: handle callback
|
||||
// $this->maniaControl->manialinkUtil->
|
||||
// $this->maniaControl->chat->sendChat("test");
|
||||
}
|
||||
}
|
@ -2,10 +2,6 @@
|
||||
|
||||
namespace ManiaControl;
|
||||
|
||||
require_once __DIR__ . '/SettingConfigurator.php';
|
||||
|
||||
use ManiaControl\Settings\SettingConfigurator;
|
||||
|
||||
/**
|
||||
* Class managing settings and configurations
|
||||
*
|
||||
@ -37,7 +33,6 @@ class SettingManager {
|
||||
public function __construct(ManiaControl $maniaControl) {
|
||||
$this->maniaControl = $maniaControl;
|
||||
$this->initTables();
|
||||
$this->configurator = new SettingConfigurator($maniaControl);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -372,11 +372,14 @@ class KarmaPlugin extends Plugin implements CallbackListener {
|
||||
private function buildManialink($forceBuild = false) {
|
||||
if (is_object($this->manialink) && !$forceBuild) return;
|
||||
|
||||
$title = $this->maniaControl->settingManager->getSetting($this, self::SETTING_WIDGET_TITLE, 'Map-Karma');
|
||||
$title = $this->maniaControl->settingManager->getSetting($this, self::SETTING_WIDGET_TITLE);
|
||||
$pos_x = $this->maniaControl->settingManager->getSetting($this, self::SETTING_WIDGET_POSX);
|
||||
$pos_y = $this->maniaControl->settingManager->getSetting($this, self::SETTING_WIDGET_POSY);
|
||||
$width = $this->maniaControl->settingManager->getSetting($this, self::SETTING_WIDGET_WIDTH);
|
||||
$height = $this->maniaControl->settingManager->getSetting($this, self::SETTING_WIDGET_HEIGHT);
|
||||
$labelStyle = $this->maniaControl->manialinkManager->styleManager->getDefaultLabelStyle();
|
||||
$quadStyle = $this->maniaControl->manialinkManager->styleManager->getDefaultQuadStyle();
|
||||
$quadSubstyle = $this->maniaControl->manialinkManager->styleManager->getDefaultQuadSubstyle();
|
||||
|
||||
$manialink = new ManiaLink(self::MLID_KARMA);
|
||||
|
||||
@ -388,13 +391,13 @@ class KarmaPlugin extends Plugin implements CallbackListener {
|
||||
$frame->add($backgroundQuad);
|
||||
$backgroundQuad->setY($height * 0.15);
|
||||
$backgroundQuad->setSize($width, $height);
|
||||
$backgroundQuad->setStyles('Bgs1InRace', 'BgTitleShadow');
|
||||
$backgroundQuad->setStyles($quadStyle, $quadSubstyle);
|
||||
|
||||
$titleLabel = new Label();
|
||||
$frame->add($titleLabel);
|
||||
$titleLabel->setY($height * 0.36);
|
||||
$titleLabel->setWidth($width * 0.85);
|
||||
$titleLabel->setStyle('TextTitle1');
|
||||
$titleLabel->setStyle($labelStyle);
|
||||
$titleLabel->setTranslate(true);
|
||||
$titleLabel->setTextSize(1);
|
||||
$titleLabel->setText($title);
|
||||
|
@ -27,6 +27,12 @@ class LocalRecordsPlugin extends Plugin implements CallbackListener {
|
||||
const VERSION = '1.0';
|
||||
const MLID_RECORDS = 'ml_local_records';
|
||||
const TABLE_RECORDS = 'mc_localrecords';
|
||||
const SETTING_WIDGET_TITLE = 'Widget Title';
|
||||
const SETTING_WIDGET_POSX = 'Widget Position: X';
|
||||
const SETTING_WIDGET_POSY = 'Widget Position: Y';
|
||||
const SETTING_WIDGET_WIDTH = 'Widget Width';
|
||||
const SETTING_WIDGET_LINESCOUNT = 'Widget Displayed Lines Count';
|
||||
const SETTING_WIDGET_LINEHEIGHT = 'Widget Line Height';
|
||||
|
||||
/**
|
||||
* Private properties
|
||||
@ -38,10 +44,16 @@ class LocalRecordsPlugin extends Plugin implements CallbackListener {
|
||||
*/
|
||||
public function __construct(ManiaControl $maniaControl) {
|
||||
$this->maniaControl = $maniaControl;
|
||||
|
||||
// Init tables
|
||||
$this->initTables();
|
||||
|
||||
// Init settings
|
||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_WIDGET_TITLE, 'Local Records');
|
||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_WIDGET_POSX, -139.);
|
||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_WIDGET_POSY, 65.);
|
||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_WIDGET_WIDTH, 40.);
|
||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_WIDGET_LINESCOUNT, 25);
|
||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_WIDGET_LINEHEIGHT, 4.);
|
||||
|
||||
// Register for callbacks
|
||||
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MC_ONINIT, $this, 'handleOnInit');
|
||||
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MC_1_SECOND, $this, 'handle1Second');
|
||||
@ -66,8 +78,9 @@ class LocalRecordsPlugin extends Plugin implements CallbackListener {
|
||||
PRIMARY KEY (`index`),
|
||||
UNIQUE KEY `player_map_record` (`mapIndex`,`playerIndex`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1;";
|
||||
if (!$mysqli->query($query)) {
|
||||
trigger_error("Couldn't create records table. " . $mysqli->error, E_USER_ERROR);
|
||||
$mysqli->query($query);
|
||||
if ($mysqli->error) {
|
||||
trigger_error($mysqli->error, E_USER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
@ -77,7 +90,6 @@ class LocalRecordsPlugin extends Plugin implements CallbackListener {
|
||||
* @param array $callback
|
||||
*/
|
||||
public function handleOnInit(array $callback) {
|
||||
// Let manialinks update
|
||||
$this->updateManialink = true;
|
||||
}
|
||||
|
||||
@ -87,12 +99,10 @@ class LocalRecordsPlugin extends Plugin implements CallbackListener {
|
||||
* @param array $callback
|
||||
*/
|
||||
public function handle1Second(array $callback) {
|
||||
// Send records manialinks if needed
|
||||
if ($this->updateManialink) {
|
||||
$manialink = $this->buildLocalManialink();
|
||||
$this->sendManialink($manialink);
|
||||
if (!$this->updateManialink) return;
|
||||
$this->updateManialink = false;
|
||||
}
|
||||
$manialink = $this->buildManialink();
|
||||
$this->sendManialink($manialink);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -217,18 +227,21 @@ class LocalRecordsPlugin extends Plugin implements CallbackListener {
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function buildLocalManialink() {
|
||||
private function buildManialink() {
|
||||
$map = $this->maniaControl->mapManager->getCurrentMap();
|
||||
if (!$map) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$pos_x = $this->maniaControl->settingManager->getSetting($this, 'Widget_PosX', -139.);
|
||||
$pos_y = $this->maniaControl->settingManager->getSetting($this, 'Widget_PosY', 65.);
|
||||
$title = $this->maniaControl->settingManager->getSetting($this, 'Widget_Title', 'Local Records');
|
||||
$width = $this->maniaControl->settingManager->getSetting($this, 'Widget_Width', 40.);
|
||||
$lines = $this->maniaControl->settingManager->getSetting($this, 'Widget_LinesCount', 25);
|
||||
$line_height = $this->maniaControl->settingManager->getSetting($this, 'Widget_LineHeight', 4.);
|
||||
$title = $this->maniaControl->settingManager->getSetting($this, self::SETTING_WIDGET_TITLE);
|
||||
$pos_x = $this->maniaControl->settingManager->getSetting($this, self::SETTING_WIDGET_POSX);
|
||||
$pos_y = $this->maniaControl->settingManager->getSetting($this, self::SETTING_WIDGET_POSY);
|
||||
$width = $this->maniaControl->settingManager->getSetting($this, self::SETTING_WIDGET_WIDTH);
|
||||
$lines = $this->maniaControl->settingManager->getSetting($this, self::SETTING_WIDGET_LINESCOUNT);
|
||||
$lineHeight = $this->maniaControl->settingManager->getSetting($this, self::SETTING_WIDGET_LINEHEIGHT);
|
||||
$labelStyle = $this->maniaControl->manialinkManager->styleManager->getDefaultLabelStyle();
|
||||
$quadStyle = $this->maniaControl->manialinkManager->styleManager->getDefaultQuadStyle();
|
||||
$quadSubstyle = $this->maniaControl->manialinkManager->styleManager->getDefaultQuadSubstyle();
|
||||
|
||||
$records = $this->getLocalRecords($map);
|
||||
if (!is_array($records)) {
|
||||
@ -244,21 +257,21 @@ class LocalRecordsPlugin extends Plugin implements CallbackListener {
|
||||
$backgroundQuad = new Quad();
|
||||
$frame->add($backgroundQuad);
|
||||
$backgroundQuad->setVAlign(Control::TOP);
|
||||
$backgroundQuad->setSize($width * 1.05, 7. + $lines * $line_height);
|
||||
$backgroundQuad->setStyles('Bgs1InRace', 'BgTitleShadow');
|
||||
$backgroundQuad->setSize($width * 1.05, 7. + $lines * $lineHeight);
|
||||
$backgroundQuad->setStyles($quadStyle, $quadSubstyle);
|
||||
|
||||
$titleLabel = new Label();
|
||||
$frame->add($titleLabel);
|
||||
// TODO: set translateable
|
||||
$titleLabel->setPosition(0, $line_height * -0.9);
|
||||
$titleLabel->setPosition(0, $lineHeight * -0.9);
|
||||
$titleLabel->setWidth($width);
|
||||
$titleLabel->setStyle(Label_Text::STYLE_TextTitle1);
|
||||
$titleLabel->setStyle($labelStyle);
|
||||
$titleLabel->setTextSize(2);
|
||||
$titleLabel->setText($title);
|
||||
$titleLabel->setTranslate(true);
|
||||
|
||||
// Times
|
||||
foreach ($records as $index => $record) {
|
||||
$y = -8. - $index * $line_height;
|
||||
$y = -8. - $index * $lineHeight;
|
||||
|
||||
$recordFrame = new Frame();
|
||||
$frame->add($recordFrame);
|
||||
@ -266,14 +279,14 @@ class LocalRecordsPlugin extends Plugin implements CallbackListener {
|
||||
|
||||
$backgroundQuad = new Quad();
|
||||
$recordFrame->add($backgroundQuad);
|
||||
$backgroundQuad->setSize($width, $line_height);
|
||||
$backgroundQuad->setStyles('Bgs1InRace', 'BgTitleGlow');
|
||||
$backgroundQuad->setSize($width, $lineHeight);
|
||||
$backgroundQuad->setStyles($quadStyle, $quadSubstyle);
|
||||
|
||||
$rankLabel = new Label();
|
||||
$recordFrame->add($rankLabel);
|
||||
$rankLabel->setHAlign(Control::LEFT);
|
||||
$rankLabel->setPosition($width * -0.47);
|
||||
$rankLabel->setSize($width * 0.06, $line_height);
|
||||
$rankLabel->setSize($width * 0.06, $lineHeight);
|
||||
$rankLabel->setTextSize(1);
|
||||
$rankLabel->setTextPrefix('$o');
|
||||
$rankLabel->setText($record->rank);
|
||||
@ -282,7 +295,7 @@ class LocalRecordsPlugin extends Plugin implements CallbackListener {
|
||||
$recordFrame->add($nameLabel);
|
||||
$nameLabel->setHAlign(Control::LEFT);
|
||||
$nameLabel->setPosition($width * -0.4);
|
||||
$nameLabel->setSize($width * 0.6, $line_height);
|
||||
$nameLabel->setSize($width * 0.6, $lineHeight);
|
||||
$nameLabel->setTextSize(1);
|
||||
$nameLabel->setText($record->nickname);
|
||||
|
||||
@ -290,7 +303,7 @@ class LocalRecordsPlugin extends Plugin implements CallbackListener {
|
||||
$recordFrame->add($timeLabel);
|
||||
$timeLabel->setHAlign(Control::RIGHT);
|
||||
$timeLabel->setPosition($width * 0.47);
|
||||
$timeLabel->setSize($width * 0.25, $line_height);
|
||||
$timeLabel->setSize($width * 0.25, $lineHeight);
|
||||
$timeLabel->setTextSize(1);
|
||||
$timeLabel->setText(Formatter::formatTime($record->time));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user