small fix

This commit is contained in:
kremsy 2014-01-03 21:16:20 +01:00
parent e250e939de
commit 8b4b6b4559
2 changed files with 9 additions and 207 deletions

View File

@ -1,189 +0,0 @@
<?php
namespace ManiaControl\Maps;
use ManiaControl\Callbacks\CallbackListener;
use ManiaControl\Callbacks\CallbackManager;
use ManiaControl\Commands\CommandListener;
use ManiaControl\Formatter;
use ManiaControl\ManiaControl;
use ManiaControl\Players\Player;
/**
* Jukebox Class
*
* @author steeffeen & kremsy
*/
class MapQueue implements CallbackListener, CommandListener {
/**
* Constants
*/
const CB_MAPQUEUE_CHANGED = 'MapQueue.MapQueueBoxChanged';
const SETTING_SKIP_MAP_ON_LEAVE = 'Skip Map when the requester leaves';
const SETTING_SKIP_MAPQUEUE_ADMIN = 'Skip Map when admin leaves';
const ADMIN_COMMAND_CLEAR_MAPQUEUE = 'clearmapqueue';
const ADMIN_COMMAND_CLEAR_JUKEBOX = 'clearjukebox';
/**
* Private properties
*/
private $maniaControl = null;
private $queuedMaps = array();
private $nextMap = null;
/**
* Create a new server jukebox
*
* @param ManiaControl $maniaControl
*/
public function __construct(ManiaControl $maniaControl) {
$this->maniaControl = $maniaControl;
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MC_ENDMAP, $this,'endMap');
// Init settings
$this->maniaControl->settingManager->initSetting($this, self::SETTING_SKIP_MAP_ON_LEAVE, true);
$this->maniaControl->settingManager->initSetting($this, self::SETTING_SKIP_MAPQUEUE_ADMIN, false);
//Register Admin Commands
$this->maniaControl->commandManager->registerCommandListener(self::ADMIN_COMMAND_CLEAR_JUKEBOX, $this, 'command_ClearJukebox', true);
$this->maniaControl->commandManager->registerCommandListener(self::ADMIN_COMMAND_CLEAR_MAPQUEUE, $this, 'command_ClearJukebox', true);
}
/**
* Clears the map-queue via admin command clearjukebox
* @param array $chat
* @param Player $player
*/
public function command_ClearQueuedMaps(array $chat, Player $admin){
$title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel);
//Destroy jukebox list
$this->queuedMaps = array();
$this->maniaControl->chat->sendInformation($title . ' $<' . $admin->nickname . '$> cleared the Queued-Map list!');
$this->maniaControl->log($title .' ' . Formatter::stripCodes($admin->nickname) . ' cleared the Queued-Map list!');
// Trigger callback
$this->maniaControl->callbackManager->triggerCallback(self::CB_MAPQUEUE_CHANGED, array('clear'));
}
/**
* Adds a Map to the map-queue
* @param $login
* @param $uid
*/
public function addMapToMapQueue($login, $uid){ //TODO if from MX other message
$player = $this->maniaControl->playerManager->getPlayer($login);
//Check if the map is already juked
if(array_key_exists($uid, $this->queuedMaps)){
$this->maniaControl->chat->sendError('Map is already in the Map-Queue', $login);
return;
}
//TODO recently maps not able to add to queue-amps setting, and management
$map = $this->maniaControl->mapManager->getMapByUid($uid);
$this->queuedMaps[$uid] = array($player, $map);
$this->maniaControl->chat->sendInformation('$<' . $player->nickname . '$> added $<' . $map->name . '$> to the Map-Queue');
// Trigger callback
$this->maniaControl->callbackManager->triggerCallback(self::CB_MAPQUEUE_CHANGED, array('add', $this->queuedMaps[$uid]));
}
/**
* Revmoes a Map from the Map queue
* @param $login
* @param $uid
*/
public function removeFromMapQueue($login, $uid){
unset($this->queuedMaps[$uid]);
}
/**
* Called on endmap
* @param array $callback
*/
public function endMap(array $callback){
$this->nextMap = null;
if($this->maniaControl->settingManager->getSetting($this, self::SETTING_SKIP_MAP_ON_LEAVE) == TRUE){
//Skip Map if requester has left
foreach($this->queuedMaps as $queuedMap){
$player = $queuedMap[0];
//found player, so play this map
if($this->maniaControl->playerManager->getPlayer($player->login) != null){
break;
}
if($this->maniaControl->settingManager->getSetting($this, self::SETTING_SKIP_MAPQUEUE_ADMIN) == FALSE){
//Check if the juker is a admin
if($player->authLevel > 0){
break;
}
}
// Trigger callback
$this->maniaControl->callbackManager->triggerCallback(self::CB_MAPQUEUE_CHANGED, array('skip', $queuedMap[0]));
//Player not found, so remove the map from the jukebox
array_shift($this->queuedMaps);
$this->maniaControl->chat->sendInformation('Requested Map skipped because $<' . $player->nickname . '$> left!');
}
}
$this->nextMap = array_shift($this->queuedMaps);
//Check if Jukebox is empty
if($this->nextMap == null)
return;
$map = $this->nextMap[1];
$success = $this->maniaControl->client->query('ChooseNextMap', $map->fileName);
if (!$success) {
trigger_error('[' . $this->maniaControl->client->getErrorCode() . '] ChooseNextMap - ' . $this->maniaControl->client->getErrorCode(), E_USER_WARNING);
return;
}
}
/**
* Returns the next Map if the next map is a juked map or null if it's not
* @return null
*/
public function getNextMap(){
return $this->nextMap;
}
/**
* Returns a list with the indexes of the juked maps
* @return array
*/
public function getQueuedMapsRanking(){
$i = 1;
$queuedMaps = array();
foreach($this->queuedMaps as $map){
$map = $map[1];
$queuedMaps[$map->uid] = $i;
$i++;
}
return $queuedMaps;
}
/**
* Dummy Function for testing
*/
public function printAllMaps(){
foreach($this->queuedMaps as $map){
$map = $map[1];
var_dump($map->name);
}
}
}

View File

@ -1,6 +1,7 @@
<?php
namespace ManiaControl\Players;
use FML\Controls\Control;
use FML\Controls\Frame;
use FML\Controls\Labels\Label_Text;
@ -35,16 +36,6 @@ class PlayerDetailed {
public function __construct(ManiaControl $maniaControl) {
$this->maniaControl = $maniaControl;
/* $this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_CLOSE_PLAYER_ADV, $this, 'closePlayerAdvancedWidget');
$this->maniaControl->callbackManager->registerCallbackListener(ManialinkManager::CB_MAIN_WINDOW_CLOSED, $this, 'closeWidget');
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer');
// Update Widget Events
$this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERINFOCHANGED, $this, 'updateWidget');
$this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERDISCONNECTED, $this, 'updateWidget');
$this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERJOINED, $this, 'updateWidget');
$this->maniaControl->callbackManager->registerCallbackListener(AuthenticationManager::CB_AUTH_LEVEL_CHANGED, $this, 'updateWidget'); */
// settings
$this->width = $this->maniaControl->manialinkManager->styleManager->getListWidgetsWidth();
$this->height = $this->maniaControl->manialinkManager->styleManager->getListWidgetsHeight();
@ -55,7 +46,7 @@ class PlayerDetailed {
public function showPlayerDetailed(Player $player, $targetLogin) {
$target = $this->maniaControl->playerManager->getPlayer($targetLogin);
$target = $this->maniaControl->playerManager->getPlayer($targetLogin);
$maniaLink = new ManiaLink(ManialinkManager::MAIN_MLID);
// Create script and features
@ -150,7 +141,7 @@ class PlayerDetailed {
$label->setText("Plays since:");
//Login
$y = $this->height / 2 - 15;
$y = $this->height / 2 - 15;
$mainLabel = new Label_Text();
$frame->add($mainLabel);
$mainLabel->setPosition(-$this->width / 2 + 30, $y);
@ -191,7 +182,7 @@ class PlayerDetailed {
$label = clone $mainLabel;
$frame->add($label);
$label->setY($y);
$label->setText(round($target->ladderScore,2));
$label->setText(round($target->ladderScore, 2));
//Played Since
$y -= 5;
@ -223,7 +214,7 @@ class PlayerDetailed {
$this->maniaControl->manialinkManager->displayWidget($maniaLink, $player);
}
public function statisticsFrame($player){
public function statisticsFrame($player) {
$frame = new Frame();
/*$mainLabel = new Label_Text();
@ -235,13 +226,13 @@ class PlayerDetailed {
$playerStats = $this->maniaControl->statisticManager->getAllPlayerStats($player);
$y = $this->height / 2 - 15;
$y = $this->height / 2 - 15;
$id = 1;
foreach($playerStats as $stat){
foreach($playerStats as $stat) {
$statProperties = $stat[0];
$value = $stat[1];
$value = $stat[1];
if($statProperties->type == StatisticManager::STAT_TYPE_TIME){
if($statProperties->type == StatisticManager::STAT_TYPE_TIME) {
$value = Formatter::formatTimeH($value);
}