added karmabar in maplist
This commit is contained in:
parent
cdda23cb60
commit
321eb11385
@ -46,7 +46,7 @@ class AdminMenu implements CallbackListener, ManialinkPageAnswerListener { //TOD
|
|||||||
$this->maniaControl = $maniaControl;
|
$this->maniaControl = $maniaControl;
|
||||||
|
|
||||||
// Init settings
|
// Init settings
|
||||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_MENU_POSX, 155.);
|
$this->maniaControl->settingManager->initSetting($this, self::SETTING_MENU_POSX, 156.);
|
||||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_MENU_POSY, -60.);
|
$this->maniaControl->settingManager->initSetting($this, self::SETTING_MENU_POSY, -60.);
|
||||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_MENU_ITEMSIZE, 6.);
|
$this->maniaControl->settingManager->initSetting($this, self::SETTING_MENU_ITEMSIZE, 6.);
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace ManiaControl\Maps;
|
namespace ManiaControl\Maps;
|
||||||
use FML\Controls\Control;
|
use FML\Controls\Control;
|
||||||
|
use FML\Controls\Gauge;
|
||||||
use FML\Controls\Label;
|
use FML\Controls\Label;
|
||||||
use FML\Controls\Labels\Label_Text;
|
use FML\Controls\Labels\Label_Text;
|
||||||
use FML\Controls\Quads\Quad_Icons128x128_1;
|
use FML\Controls\Quads\Quad_Icons128x128_1;
|
||||||
@ -12,6 +13,7 @@ use FML\Script\Tooltips;
|
|||||||
use ManiaControl\Admin\AuthenticationManager;
|
use ManiaControl\Admin\AuthenticationManager;
|
||||||
use ManiaControl\Callbacks\CallbackListener;
|
use ManiaControl\Callbacks\CallbackListener;
|
||||||
use ManiaControl\Callbacks\CallbackManager;
|
use ManiaControl\Callbacks\CallbackManager;
|
||||||
|
use ManiaControl\ColorUtil;
|
||||||
use ManiaControl\Manialinks\ManialinkManager;
|
use ManiaControl\Manialinks\ManialinkManager;
|
||||||
use ManiaControl\Manialinks\ManialinkPageAnswerListener;
|
use ManiaControl\Manialinks\ManialinkPageAnswerListener;
|
||||||
use FML\Controls\Frame;
|
use FML\Controls\Frame;
|
||||||
@ -41,6 +43,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
|
|||||||
const SHOW_MX_LIST = 1;
|
const SHOW_MX_LIST = 1;
|
||||||
const SHOW_MAP_LIST = 2;
|
const SHOW_MAP_LIST = 2;
|
||||||
|
|
||||||
|
const DEFAULT_KARMA_PLUGIN = 'KarmaPlugin';
|
||||||
/**
|
/**
|
||||||
* Private properties
|
* Private properties
|
||||||
*/
|
*/
|
||||||
@ -64,9 +67,11 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
|
|||||||
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this,
|
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this,
|
||||||
'handleManialinkPageAnswer');
|
'handleManialinkPageAnswer');
|
||||||
|
|
||||||
|
//Update Widget actions
|
||||||
$this->maniaControl->callbackManager->registerCallbackListener(Jukebox::CB_JUKEBOX_CHANGED, $this, 'updateWidget');
|
$this->maniaControl->callbackManager->registerCallbackListener(Jukebox::CB_JUKEBOX_CHANGED, $this, 'updateWidget');
|
||||||
$this->maniaControl->callbackManager->registerCallbackListener(MapManager::CB_MAPLIST_UPDATED, $this, 'updateWidget');
|
$this->maniaControl->callbackManager->registerCallbackListener(MapManager::CB_MAPLIST_UPDATED, $this, 'updateWidget');
|
||||||
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MC_BEGINMAP, $this, 'updateWidget'); //TODO not working yet
|
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MC_BEGINMAP, $this, 'updateWidget'); //TODO not working yet
|
||||||
|
//TODO update on Karma Update
|
||||||
|
|
||||||
//settings
|
//settings
|
||||||
$this->width = $this->maniaControl->manialinkManager->styleManager->getListWidgetsWidth();
|
$this->width = $this->maniaControl->manialinkManager->styleManager->getListWidgetsWidth();
|
||||||
@ -130,6 +135,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$maniaLink = new ManiaLink(ManialinkManager::MAIN_MLID);
|
$maniaLink = new ManiaLink(ManialinkManager::MAIN_MLID);
|
||||||
$frame = $this->buildMainFrame();
|
$frame = $this->buildMainFrame();
|
||||||
$maniaLink->add($frame);
|
$maniaLink->add($frame);
|
||||||
@ -246,7 +252,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
|
|||||||
$frame->add($headFrame);
|
$frame->add($headFrame);
|
||||||
$headFrame->setY($this->height / 2 - 5);
|
$headFrame->setY($this->height / 2 - 5);
|
||||||
$x = -$this->width / 2;
|
$x = -$this->width / 2;
|
||||||
$array = array("Id" => $x + 5, "Mx ID" => $x + 10, "MapName" => $x + 20, "Author" => $x + 70);
|
$array = array("Id" => $x + 5, "Mx ID" => $x + 10, "MapName" => $x + 20, "Author" => $x + 73, "Karma" => $x + 105, "Actions" => $this->width / 2 - 15);
|
||||||
$this->maniaControl->manialinkManager->labelLine($headFrame,$array);
|
$this->maniaControl->manialinkManager->labelLine($headFrame,$array);
|
||||||
|
|
||||||
//Get Maplist
|
//Get Maplist
|
||||||
@ -255,6 +261,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
|
|||||||
//TODO add pages
|
//TODO add pages
|
||||||
|
|
||||||
$jukedMaps = $this->maniaControl->mapManager->jukebox->getJukeBoxRanking();
|
$jukedMaps = $this->maniaControl->mapManager->jukebox->getJukeBoxRanking();
|
||||||
|
$karmaPlugin = $this->maniaControl->pluginManager->getPlugin(self::DEFAULT_KARMA_PLUGIN);
|
||||||
|
|
||||||
$id = 1;
|
$id = 1;
|
||||||
$y = $this->height / 2 - 10;
|
$y = $this->height / 2 - 10;
|
||||||
@ -343,10 +350,32 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
|
|||||||
$tooltips->add($switchToQuad, $descriptionLabel);
|
$tooltips->add($switchToQuad, $descriptionLabel);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*$descriptionLabel2 = clone $descriptionLabel;
|
|
||||||
$descriptionLabel2->setText("test1");
|
|
||||||
$tooltips->add($eraseQuad, $descriptionLabel2); */
|
|
||||||
|
|
||||||
|
//Display Karma bar
|
||||||
|
if($karmaPlugin != null){
|
||||||
|
$karma = $karmaPlugin->getMapKarma($map);
|
||||||
|
$votes = $karmaPlugin->getMapVotes($map);
|
||||||
|
if(is_numeric($karma)){
|
||||||
|
$karmaGauge = new Gauge();
|
||||||
|
$mapFrame->add($karmaGauge);
|
||||||
|
$karmaGauge->setX($x + 110);
|
||||||
|
$karmaGauge->setSize(20, 9);
|
||||||
|
$karmaGauge->setDrawBg(false);
|
||||||
|
$karma = floatval($karma);
|
||||||
|
$karmaGauge->setRatio($karma + 0.15 - $karma * 0.15);
|
||||||
|
$karmaColor = ColorUtil::floatToStatusColor($karma);
|
||||||
|
$karmaGauge->setColor($karmaColor . '9');
|
||||||
|
|
||||||
|
$karmaLabel = new Label();
|
||||||
|
$mapFrame->add($karmaLabel);
|
||||||
|
$karmaLabel->setX($x + 110);
|
||||||
|
$karmaLabel->setSize(20 * 0.9, 5);
|
||||||
|
$karmaLabel->setTextSize(0.9);
|
||||||
|
$karmaLabel->setTextColor("000");
|
||||||
|
$karmaLabel->setAlign(Control::CENTER, Control::CENTER);
|
||||||
|
$karmaLabel->setText(' ' . round($karma * 100.) . '% (' . $votes['count'] . ')');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$y -= 4;
|
$y -= 4;
|
||||||
$id++;
|
$id++;
|
||||||
@ -387,13 +416,11 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
|
|||||||
$mxId = $map->mx->id;
|
$mxId = $map->mx->id;
|
||||||
|
|
||||||
//Display Maps
|
//Display Maps
|
||||||
$array = array($id => $x + 5, $mxId => $x + 10, $map->name => $x + 20, $map->authorNick => $x + 70);
|
$array = array($id => $x + 5, $mxId => $x + 10, $map->name => $x + 20, $map->authorNick => $x + 73);
|
||||||
$this->maniaControl->manialinkManager->labelLine($frame,$array);
|
$this->maniaControl->manialinkManager->labelLine($frame,$array);
|
||||||
//TODO detailed mx info page with link to mxo
|
//TODO detailed mx info page with link to mxo
|
||||||
//TODO action detailed map info
|
//TODO action detailed map info
|
||||||
//TODO side switch
|
//TODO side switch
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -203,6 +203,19 @@ class PluginManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns an Plugin if it is aktivated
|
||||||
|
* @param $pluginClass
|
||||||
|
* @return null
|
||||||
|
*/
|
||||||
|
public function getPlugin($pluginClass) {
|
||||||
|
if($this->isPluginActive($pluginClass)){
|
||||||
|
return $this->activePlugins[$pluginClass];
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get all declared plugin class names
|
* Get all declared plugin class names
|
||||||
*
|
*
|
||||||
|
@ -365,7 +365,7 @@ class KarmaPlugin implements CallbackListener, Plugin {
|
|||||||
* @param Map $map
|
* @param Map $map
|
||||||
* @return float | bool
|
* @return float | bool
|
||||||
*/
|
*/
|
||||||
private function getMapKarma(Map $map) {
|
public function getMapKarma(Map $map) {
|
||||||
$mysqli = $this->maniaControl->database->mysqli;
|
$mysqli = $this->maniaControl->database->mysqli;
|
||||||
$query = "SELECT AVG(`vote`) AS `karma` FROM `" . self::TABLE_KARMA . "`
|
$query = "SELECT AVG(`vote`) AS `karma` FROM `" . self::TABLE_KARMA . "`
|
||||||
WHERE `mapIndex` = {$map->index}
|
WHERE `mapIndex` = {$map->index}
|
||||||
@ -394,7 +394,7 @@ class KarmaPlugin implements CallbackListener, Plugin {
|
|||||||
* @param Map $map
|
* @param Map $map
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
private function getMapVotes(Map $map) {
|
public function getMapVotes(Map $map) {
|
||||||
$mysqli = $this->maniaControl->database->mysqli;
|
$mysqli = $this->maniaControl->database->mysqli;
|
||||||
$query = "SELECT `vote`, COUNT(`vote`) AS `count` FROM `" . self::TABLE_KARMA . "`
|
$query = "SELECT `vote`, COUNT(`vote`) AS `count` FROM `" . self::TABLE_KARMA . "`
|
||||||
WHERE `mapIndex` = {$map->index}
|
WHERE `mapIndex` = {$map->index}
|
||||||
|
Loading…
Reference in New Issue
Block a user