2014-01-11 18:51:07 +01:00
|
|
|
<?php
|
2014-01-11 20:01:03 +01:00
|
|
|
|
|
|
|
use FML\Controls\Control;
|
|
|
|
use FML\Controls\Frame;
|
|
|
|
use FML\Controls\Gauge;
|
2014-01-11 20:52:29 +01:00
|
|
|
use FML\Controls\Label;
|
|
|
|
use FML\Controls\Labels\Label_Button;
|
2014-01-11 20:01:03 +01:00
|
|
|
use FML\Controls\Labels\Label_Text;
|
|
|
|
use FML\Controls\Quad;
|
2014-01-11 20:52:29 +01:00
|
|
|
use FML\Controls\Quads\Quad_BgsPlayerCard;
|
2014-01-11 23:36:53 +01:00
|
|
|
use FML\Controls\Quads\Quad_Icons128x32_1;
|
2014-01-11 23:05:13 +01:00
|
|
|
use FML\Controls\Quads\Quad_Icons64x64_1;
|
2014-01-11 23:36:53 +01:00
|
|
|
use FML\Controls\Quads\Quad_UIConstruction_Buttons;
|
2014-01-11 20:01:03 +01:00
|
|
|
use FML\ManiaLink;
|
2014-01-11 23:36:53 +01:00
|
|
|
use FML\Script\Script;
|
2014-01-11 20:01:03 +01:00
|
|
|
use ManiaControl\Callbacks\CallbackListener;
|
|
|
|
use ManiaControl\Callbacks\CallbackManager;
|
2014-01-31 00:04:40 +01:00
|
|
|
use ManiaControl\Callbacks\TimerListener;
|
2014-01-11 20:01:03 +01:00
|
|
|
use ManiaControl\ColorUtil;
|
|
|
|
use ManiaControl\Commands\CommandListener;
|
|
|
|
use ManiaControl\ManiaControl;
|
2014-01-11 20:52:29 +01:00
|
|
|
use ManiaControl\Manialinks\ManialinkPageAnswerListener;
|
2014-01-11 20:01:03 +01:00
|
|
|
use ManiaControl\Players\Player;
|
2014-01-12 00:35:35 +01:00
|
|
|
use ManiaControl\Players\PlayerManager;
|
2014-01-20 20:51:03 +01:00
|
|
|
use ManiaControl\Plugins\Plugin;
|
2014-01-11 23:36:53 +01:00
|
|
|
use ManiaControl\Server\ServerCommands;
|
2014-01-21 19:12:55 +01:00
|
|
|
use Maniaplanet\DedicatedServer\Structures\VoteRatio;
|
2014-01-11 20:01:03 +01:00
|
|
|
|
|
|
|
|
2014-01-11 18:51:07 +01:00
|
|
|
/**
|
2014-01-11 20:01:03 +01:00
|
|
|
* ManiaControl Chat-Message Plugin
|
|
|
|
*
|
|
|
|
* @author kremsy and steeffeen
|
2014-01-11 18:51:07 +01:00
|
|
|
*/
|
2014-01-31 00:04:40 +01:00
|
|
|
class CustomVotesPlugin implements CommandListener, CallbackListener, ManialinkPageAnswerListener, TimerListener, Plugin {
|
2014-01-11 20:01:03 +01:00
|
|
|
/**
|
|
|
|
* Constants
|
|
|
|
*/
|
2014-01-11 23:36:53 +01:00
|
|
|
const PLUGIN_ID = 10;
|
2014-01-11 20:01:03 +01:00
|
|
|
const PLUGIN_VERSION = 0.1;
|
|
|
|
const PLUGIN_NAME = 'CustomVotesPlugin';
|
|
|
|
const PLUGIN_AUTHOR = 'kremsy and steeffeen';
|
2014-01-11 18:51:07 +01:00
|
|
|
|
2014-01-11 23:05:13 +01:00
|
|
|
const SETTING_VOTE_ICON_POSX = 'Vote-Icon-Position: X';
|
|
|
|
const SETTING_VOTE_ICON_POSY = 'Vote-Icon-Position: Y';
|
|
|
|
const SETTING_VOTE_ICON_WIDTH = 'Vote-Icon-Size: Width';
|
|
|
|
const SETTING_VOTE_ICON_HEIGHT = 'Vote-Icon-Size: Height';
|
|
|
|
|
2014-01-11 22:06:52 +01:00
|
|
|
const SETTING_WIDGET_POSX = 'Widget-Position: X';
|
|
|
|
const SETTING_WIDGET_POSY = 'Widget-Position: Y';
|
|
|
|
const SETTING_WIDGET_WIDTH = 'Widget-Size: Width';
|
|
|
|
const SETTING_WIDGET_HEIGHT = 'Widget-Size: Height';
|
|
|
|
const SETTING_VOTE_TIME = 'Voting Time';
|
2014-01-12 17:45:41 +01:00
|
|
|
const SETTING_DEFAULT_PLAYER_RATIO = 'Minimum Player Voters Ratio';
|
2014-01-11 22:06:52 +01:00
|
|
|
const SETTING_DEFAULT_RATIO = 'Default Success Ratio';
|
|
|
|
const SETTING_SPECTATOR_ALLOW_VOTE = 'Allow Specators to vote';
|
|
|
|
const SETTING_SPECTATOR_ALLOW_START_VOTE = 'Allow Specators to start a vote';
|
|
|
|
|
2014-01-11 20:01:03 +01:00
|
|
|
const MLID_WIDGET = 'CustomVotesPlugin.WidgetId';
|
2014-01-11 23:05:13 +01:00
|
|
|
const MLID_ICON = 'CustomVotesPlugin.IconWidgetId';
|
2014-01-11 20:01:03 +01:00
|
|
|
|
|
|
|
|
2014-01-14 19:11:57 +01:00
|
|
|
const ACTION_POSITIVE_VOTE = 'CustomVotesPlugin.PositiveVote';
|
2014-01-11 20:52:29 +01:00
|
|
|
const ACTION_NEGATIVE_VOTE = 'CustomVotesPlugin.NegativeVote';
|
2014-01-11 23:36:53 +01:00
|
|
|
const ACTION_START_VOTE = 'CustomVotesPlugin.StartVote.';
|
|
|
|
|
2014-01-11 20:52:29 +01:00
|
|
|
|
2014-01-11 23:05:13 +01:00
|
|
|
const CB_CUSTOM_VOTE_FINISHED = 'CustomVotesPlugin.CustomVoteFinished';
|
2014-01-11 20:01:03 +01:00
|
|
|
|
|
|
|
/**
|
2014-01-11 23:05:13 +01:00
|
|
|
* Private properties
|
2014-01-11 20:01:03 +01:00
|
|
|
*/
|
2014-01-11 23:05:13 +01:00
|
|
|
/** @var maniaControl $maniaControl */
|
2014-01-11 20:01:03 +01:00
|
|
|
private $maniaControl = null;
|
|
|
|
private $voteCommands = array();
|
2014-01-14 19:11:57 +01:00
|
|
|
private $voteMenuItems = array();
|
2014-02-07 22:57:39 +01:00
|
|
|
/** @var CurrentVote $currentVote */
|
2014-01-11 23:05:13 +01:00
|
|
|
private $currentVote = null;
|
2014-01-11 20:01:03 +01:00
|
|
|
|
2014-01-27 20:39:10 +01:00
|
|
|
/**
|
|
|
|
* Prepares the Plugin
|
|
|
|
*
|
|
|
|
* @param ManiaControl $maniaControl
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public static function prepare(ManiaControl $maniaControl) {
|
2014-01-27 21:05:02 +01:00
|
|
|
//do nothing
|
2014-01-27 20:39:10 +01:00
|
|
|
}
|
|
|
|
|
2014-01-11 20:01:03 +01:00
|
|
|
/**
|
|
|
|
* Load the plugin
|
|
|
|
*
|
|
|
|
* @param \ManiaControl\ManiaControl $maniaControl
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function load(ManiaControl $maniaControl) {
|
|
|
|
$this->maniaControl = $maniaControl;
|
|
|
|
|
|
|
|
$this->maniaControl->commandManager->registerCommandListener('vote', $this, 'chat_vote');
|
2014-01-31 00:04:40 +01:00
|
|
|
$this->maniaControl->timerManager->registerTimerListening($this, 'handle1Second', 1000);
|
2014-01-11 23:36:53 +01:00
|
|
|
$this->maniaControl->callbackManager->registerCallbackListener(ServerCommands::CB_VOTE_CANCELED, $this, 'handleVoteCanceled');
|
2014-01-11 20:52:29 +01:00
|
|
|
$this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_POSITIVE_VOTE, $this, 'handlePositiveVote');
|
|
|
|
$this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_NEGATIVE_VOTE, $this, 'handleNegativeVote');
|
2014-01-11 22:06:52 +01:00
|
|
|
|
|
|
|
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer');
|
2014-01-11 23:05:13 +01:00
|
|
|
$this->maniaControl->callbackManager->registerCallbackListener(self::CB_CUSTOM_VOTE_FINISHED, $this, 'handleVoteFinished');
|
2014-01-12 00:35:35 +01:00
|
|
|
$this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERJOINED, $this, 'handlePlayerConnect');
|
2014-01-11 22:06:52 +01:00
|
|
|
|
2014-01-11 23:05:13 +01:00
|
|
|
//Settings
|
|
|
|
$this->maniaControl->settingManager->initSetting($this, self::SETTING_VOTE_ICON_POSX, 156.);
|
2014-01-14 19:11:57 +01:00
|
|
|
$this->maniaControl->settingManager->initSetting($this, self::SETTING_VOTE_ICON_POSY, -38.6);
|
2014-01-11 23:05:13 +01:00
|
|
|
$this->maniaControl->settingManager->initSetting($this, self::SETTING_VOTE_ICON_WIDTH, 6);
|
|
|
|
$this->maniaControl->settingManager->initSetting($this, self::SETTING_VOTE_ICON_HEIGHT, 6);
|
2014-01-11 22:06:52 +01:00
|
|
|
|
2014-01-14 14:45:40 +01:00
|
|
|
$this->maniaControl->settingManager->initSetting($this, self::SETTING_WIDGET_POSX, -80); //160 -15
|
|
|
|
$this->maniaControl->settingManager->initSetting($this, self::SETTING_WIDGET_POSY, 80); //-15
|
|
|
|
$this->maniaControl->settingManager->initSetting($this, self::SETTING_WIDGET_WIDTH, 50); //30
|
|
|
|
$this->maniaControl->settingManager->initSetting($this, self::SETTING_WIDGET_HEIGHT, 20); //25
|
2014-01-11 23:05:13 +01:00
|
|
|
|
2014-01-12 17:45:41 +01:00
|
|
|
$this->maniaControl->settingManager->initSetting($this, self::SETTING_DEFAULT_RATIO, 0.75);
|
|
|
|
$this->maniaControl->settingManager->initSetting($this, self::SETTING_DEFAULT_PLAYER_RATIO, 0.65);
|
2014-01-11 22:06:52 +01:00
|
|
|
$this->maniaControl->settingManager->initSetting($this, self::SETTING_SPECTATOR_ALLOW_VOTE, false);
|
|
|
|
$this->maniaControl->settingManager->initSetting($this, self::SETTING_SPECTATOR_ALLOW_START_VOTE, false);
|
2014-01-11 23:36:53 +01:00
|
|
|
$this->maniaControl->settingManager->initSetting($this, self::SETTING_VOTE_TIME, 60);
|
2014-01-11 23:05:13 +01:00
|
|
|
|
2014-01-21 19:12:55 +01:00
|
|
|
//Define Votes
|
2014-02-07 22:57:39 +01:00
|
|
|
$this->defineVote("teambalance", "Vote for Team Balance");
|
|
|
|
$this->defineVote("skipmap", "Vote for Skip Map");
|
|
|
|
$this->defineVote("nextmap", "Vote for Skip Map");
|
|
|
|
$this->defineVote("restartmap", "Vote for Restart Map");
|
|
|
|
$this->defineVote("pausegame", "Vote for Pause Game");
|
2014-01-11 22:06:52 +01:00
|
|
|
|
2014-01-21 19:12:55 +01:00
|
|
|
/* Disable Standard Votes */
|
|
|
|
$array["Command"] = VoteRatio::COMMAND_BAN;
|
|
|
|
$array["Param"] = "";
|
|
|
|
$array["Ratio"] = (float)-1;
|
|
|
|
$ratioArray[] = $array;
|
|
|
|
|
|
|
|
$array["Command"] = VoteRatio::COMMAND_KICK;
|
|
|
|
$ratioArray[] = $array;
|
|
|
|
|
|
|
|
$array["Command"] = VoteRatio::COMMAND_RESTART_MAP;
|
|
|
|
$ratioArray[] = $array;
|
|
|
|
|
|
|
|
$array["Command"] = VoteRatio::COMMAND_TEAM_BALANCE;
|
|
|
|
$ratioArray[] = $array;
|
|
|
|
|
|
|
|
$array["Command"] = VoteRatio::COMMAND_NEXT_MAP;
|
|
|
|
$ratioArray[] = $array;
|
|
|
|
|
|
|
|
$this->maniaControl->client->setCallVoteRatiosEx(false, $ratioArray);
|
|
|
|
|
2014-01-18 10:26:32 +01:00
|
|
|
$this->constructMenu();
|
2014-01-11 20:01:03 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Unload the plugin and its resources
|
|
|
|
*/
|
|
|
|
public function unload() {
|
2014-01-21 19:12:55 +01:00
|
|
|
//Enable Standard Votes
|
|
|
|
$defaultRatio = $this->maniaControl->client->getCallVoteRatio();
|
|
|
|
|
|
|
|
$array["Command"] = VoteRatio::COMMAND_BAN;
|
|
|
|
$array["Param"] = "";
|
|
|
|
$array["Ratio"] = (float)$defaultRatio;
|
|
|
|
$ratioArray[] = $array;
|
|
|
|
$array["Command"] = VoteRatio::COMMAND_KICK;
|
|
|
|
$ratioArray[] = $array;
|
|
|
|
$array["Command"] = VoteRatio::COMMAND_RESTART_MAP;
|
|
|
|
$ratioArray[] = $array;
|
|
|
|
$array["Command"] = VoteRatio::COMMAND_TEAM_BALANCE;
|
|
|
|
$ratioArray[] = $array;
|
|
|
|
$array["Command"] = VoteRatio::COMMAND_NEXT_MAP;
|
|
|
|
$ratioArray[] = $array;
|
|
|
|
|
|
|
|
$this->maniaControl->client->setCallVoteRatiosEx(false, $ratioArray);
|
|
|
|
|
2014-01-18 10:32:33 +01:00
|
|
|
$this->destroyVote();
|
|
|
|
$emptyManialink = new ManiaLink(self::MLID_ICON);
|
|
|
|
$manialinkText = $emptyManialink->render()->saveXML();
|
|
|
|
$this->maniaControl->manialinkManager->sendManialink($manialinkText);
|
2014-01-11 20:01:03 +01:00
|
|
|
$this->maniaControl->commandManager->unregisterCommandListener($this);
|
2014-01-19 00:09:15 +01:00
|
|
|
$this->maniaControl->callbackManager->unregisterCallbackListener($this);
|
|
|
|
$this->maniaControl->manialinkManager->unregisterManialinkPageAnswerListener($this);
|
2014-02-01 14:50:24 +01:00
|
|
|
$this->maniaControl->timerManager->unregisterTimerListenings($this);
|
2014-01-11 20:01:03 +01:00
|
|
|
unset($this->maniaControl);
|
|
|
|
}
|
|
|
|
|
2014-01-12 00:35:35 +01:00
|
|
|
/**
|
|
|
|
* Handle PlayerConnect callback
|
|
|
|
*
|
|
|
|
* @param array $callback
|
|
|
|
*/
|
|
|
|
public function handlePlayerConnect(array $callback) {
|
|
|
|
$player = $callback[1];
|
|
|
|
$this->showIcon($player->login);
|
|
|
|
}
|
|
|
|
|
2014-01-14 19:11:57 +01:00
|
|
|
/**
|
|
|
|
* Add a new Vote Menu Item
|
|
|
|
*
|
|
|
|
* @param Control $control
|
|
|
|
* @param int $order
|
|
|
|
* @param string $description
|
|
|
|
*/
|
|
|
|
public function addVoteMenuItem(Control $control, $order = 0, $description = null) {
|
2014-01-31 00:04:40 +01:00
|
|
|
if (!isset($this->voteMenuItems[$order])) {
|
2014-01-14 19:11:57 +01:00
|
|
|
$this->voteMenuItems[$order] = array();
|
|
|
|
}
|
|
|
|
array_push($this->voteMenuItems[$order], array($control, $description));
|
|
|
|
krsort($this->voteMenuItems);
|
|
|
|
}
|
|
|
|
|
2014-01-11 20:01:03 +01:00
|
|
|
/**
|
|
|
|
* Chat Vote
|
|
|
|
*
|
|
|
|
* @param array $chat
|
|
|
|
* @param Player $player
|
|
|
|
*/
|
|
|
|
public function chat_vote(array $chat, Player $player) {
|
|
|
|
$command = explode(" ", $chat[1][2]);
|
2014-01-31 00:04:40 +01:00
|
|
|
if (isset($command[1])) {
|
|
|
|
if (isset($this->voteCommands[$command[1]])) {
|
2014-01-11 23:05:13 +01:00
|
|
|
$this->startVote($player, strtolower($command[1]));
|
|
|
|
}
|
2014-01-11 20:01:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-11 23:05:13 +01:00
|
|
|
/**
|
|
|
|
* Handle ManiaControl OnInit callback
|
|
|
|
*
|
2014-02-07 22:57:39 +01:00
|
|
|
* @internal param array $callback
|
2014-01-11 23:05:13 +01:00
|
|
|
*/
|
2014-01-18 10:26:32 +01:00
|
|
|
private function constructMenu() {
|
2014-01-14 19:11:57 +01:00
|
|
|
// Menu RestartMap
|
|
|
|
$itemQuad = new Quad_UIConstruction_Buttons();
|
|
|
|
$itemQuad->setSubStyle($itemQuad::SUBSTYLE_Reload);
|
|
|
|
$itemQuad->setAction(self::ACTION_START_VOTE . 'restartmap');
|
|
|
|
$this->addVoteMenuItem($itemQuad, 5, 'Vote for Restart-Map');
|
|
|
|
|
|
|
|
//Check if Pause exists in current gamemode
|
2014-01-20 09:24:17 +01:00
|
|
|
$scriptInfos = $this->maniaControl->client->getModeScriptInfo();
|
2014-01-14 19:11:57 +01:00
|
|
|
|
|
|
|
$pauseExists = false;
|
2014-01-20 09:24:17 +01:00
|
|
|
foreach($scriptInfos->commandDescs as $param) {
|
2014-01-31 00:04:40 +01:00
|
|
|
if ($param->name == "Command_ForceWarmUp") {
|
2014-01-14 19:11:57 +01:00
|
|
|
$pauseExists = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Menu Pause
|
2014-01-31 00:04:40 +01:00
|
|
|
if ($pauseExists) {
|
2014-01-14 19:11:57 +01:00
|
|
|
$itemQuad = new Quad_Icons128x32_1();
|
|
|
|
$itemQuad->setSubStyle($itemQuad::SUBSTYLE_ManiaLinkSwitch);
|
|
|
|
$itemQuad->setAction(self::ACTION_START_VOTE . 'pausegame');
|
|
|
|
$this->addVoteMenuItem($itemQuad, 10, 'Vote for a pause of Current Game');
|
|
|
|
}
|
|
|
|
|
|
|
|
//Menu SkipMap
|
|
|
|
$itemQuad = new Quad_Icons64x64_1();
|
|
|
|
$itemQuad->setSubStyle($itemQuad::SUBSTYLE_ArrowFastNext);
|
|
|
|
$itemQuad->setAction(self::ACTION_START_VOTE . 'skipmap');
|
|
|
|
$this->addVoteMenuItem($itemQuad, 15, 'Vote for a Mapskip');
|
|
|
|
|
|
|
|
//Menu TeamBalance
|
|
|
|
$itemQuad = new Quad_Icons128x32_1();
|
|
|
|
$itemQuad->setSubStyle($itemQuad::SUBSTYLE_RT_Team);
|
|
|
|
$itemQuad->setAction(self::ACTION_START_VOTE . 'teambalance');
|
|
|
|
$this->addVoteMenuItem($itemQuad, 20, 'Vote for Team-Balance');
|
|
|
|
|
|
|
|
//Show the Menu's icon
|
2014-01-12 00:35:35 +01:00
|
|
|
$this->showIcon();
|
2014-01-11 23:05:13 +01:00
|
|
|
}
|
|
|
|
|
2014-01-11 23:36:53 +01:00
|
|
|
/**
|
|
|
|
* Destroy the Vote on Canceled Callback
|
|
|
|
*
|
|
|
|
* @param array $callback
|
|
|
|
*/
|
|
|
|
public function handleVoteCanceled(array $callback) {
|
|
|
|
//reset vote
|
|
|
|
$this->destroyVote();
|
|
|
|
}
|
|
|
|
|
2014-01-11 23:05:13 +01:00
|
|
|
/**
|
|
|
|
* Handle Standard Votes
|
|
|
|
*
|
|
|
|
* @param array $callback
|
|
|
|
*/
|
|
|
|
public function handleVoteFinished(array $callback) {
|
2014-01-14 15:02:43 +01:00
|
|
|
$voteName = $callback[1];
|
|
|
|
$voteResult = $callback[2];
|
2014-01-11 23:05:13 +01:00
|
|
|
|
2014-02-07 22:57:39 +01:00
|
|
|
if ($voteResult >= $this->currentVote->neededRatio) {
|
|
|
|
// Call Closure if one exists
|
|
|
|
if (is_callable($this->currentVote->function)) {
|
|
|
|
call_user_func($this->currentVote->function, $voteResult);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-01-11 23:05:13 +01:00
|
|
|
switch($voteName) {
|
|
|
|
case 'teambalance':
|
2014-01-16 18:49:52 +01:00
|
|
|
$this->maniaControl->client->autoTeamBalance();
|
2014-01-14 19:20:03 +01:00
|
|
|
$this->maniaControl->chat->sendInformation('$sVote Successfully -> Teams got Balanced!');
|
2014-01-11 23:05:13 +01:00
|
|
|
break;
|
|
|
|
case 'skipmap':
|
|
|
|
case 'nextmap':
|
2014-01-16 18:49:52 +01:00
|
|
|
$this->maniaControl->client->nextMap();
|
2014-01-14 19:20:03 +01:00
|
|
|
$this->maniaControl->chat->sendInformation('$sVote Successfully -> Map skipped!');
|
2014-01-11 23:05:13 +01:00
|
|
|
break;
|
|
|
|
case 'restartmap':
|
2014-01-16 18:49:52 +01:00
|
|
|
$this->maniaControl->client->restartMap();
|
2014-01-14 19:20:03 +01:00
|
|
|
$this->maniaControl->chat->sendInformation('$sVote Successfully -> Map restarted!');
|
2014-01-11 23:05:13 +01:00
|
|
|
break;
|
|
|
|
case 'pausegame':
|
2014-01-16 18:49:52 +01:00
|
|
|
$this->maniaControl->client->sendModeScriptCommands(array('Command_ForceWarmUp' => True));
|
2014-01-14 19:20:03 +01:00
|
|
|
$this->maniaControl->chat->sendInformation('$sVote Successfully -> Current Game paused!');
|
2014-01-11 23:05:13 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
2014-01-14 19:20:03 +01:00
|
|
|
$this->maniaControl->chat->sendError('Vote Failed!');
|
2014-01-11 23:05:13 +01:00
|
|
|
}
|
|
|
|
}
|
2014-01-11 20:52:29 +01:00
|
|
|
|
2014-01-11 23:05:13 +01:00
|
|
|
/**
|
2014-01-11 23:36:53 +01:00
|
|
|
* Handles the ManialinkPageAnswers and start a vote if a button in the panel got clicked
|
2014-01-11 23:05:13 +01:00
|
|
|
*
|
|
|
|
* @param array $callback
|
|
|
|
*/
|
|
|
|
public function handleManialinkPageAnswer(array $callback) {
|
2014-01-11 23:36:53 +01:00
|
|
|
$actionId = $callback[1][2];
|
|
|
|
$actionArray = explode('.', $actionId);
|
2014-01-31 00:04:40 +01:00
|
|
|
if (count($actionArray) <= 2) {
|
2014-01-11 23:36:53 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$voteIndex = $actionArray[2];
|
2014-01-31 00:04:40 +01:00
|
|
|
if (isset($this->voteCommands[$voteIndex])) {
|
2014-01-11 23:36:53 +01:00
|
|
|
$login = $callback[1][1];
|
|
|
|
$player = $this->maniaControl->playerManager->getPlayer($login);
|
|
|
|
$this->startVote($player, $voteIndex);
|
|
|
|
}
|
2014-01-11 22:06:52 +01:00
|
|
|
}
|
2014-01-11 23:05:13 +01:00
|
|
|
|
2014-01-11 20:01:03 +01:00
|
|
|
/**
|
|
|
|
* Defines a Vote
|
|
|
|
*
|
2014-02-07 22:57:39 +01:00
|
|
|
* @param $voteIndex
|
|
|
|
* @param $voteName
|
|
|
|
* @param bool $idBased
|
|
|
|
* @param $neededRatio
|
2014-01-11 20:01:03 +01:00
|
|
|
*/
|
2014-02-07 22:57:39 +01:00
|
|
|
public function defineVote($voteIndex, $voteName, $idBased = false, $neededRatio = -1) {
|
2014-01-31 00:04:40 +01:00
|
|
|
if ($neededRatio == -1) {
|
2014-01-11 23:05:13 +01:00
|
|
|
$neededRatio = $this->maniaControl->settingManager->getSetting($this, self::SETTING_DEFAULT_RATIO);
|
|
|
|
}
|
2014-02-07 22:57:39 +01:00
|
|
|
$this->voteCommands[$voteIndex] = new VoteCommand($voteIndex, $voteName, $idBased, $neededRatio);
|
2014-01-11 20:01:03 +01:00
|
|
|
}
|
|
|
|
|
2014-02-07 22:57:39 +01:00
|
|
|
/**
|
|
|
|
* Undefines a Vote
|
|
|
|
*
|
|
|
|
* @param $voteIndex
|
|
|
|
*/
|
|
|
|
public function undefineVote($voteIndex) {
|
|
|
|
unset($this->voteCommands[$voteIndex]);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-01-11 20:01:03 +01:00
|
|
|
/**
|
|
|
|
* Starts a vote
|
|
|
|
*
|
2014-01-11 22:06:52 +01:00
|
|
|
* @param \ManiaControl\Players\Player $player
|
2014-01-11 23:05:13 +01:00
|
|
|
* @param $voteIndex
|
2014-02-07 22:57:39 +01:00
|
|
|
* @param $action
|
2014-01-11 20:01:03 +01:00
|
|
|
*/
|
2014-02-07 22:57:39 +01:00
|
|
|
public function startVote(Player $player, $voteIndex, $function = null) {
|
2014-01-11 23:05:13 +01:00
|
|
|
//Player is muted
|
2014-01-31 00:04:40 +01:00
|
|
|
if ($this->maniaControl->playerManager->playerActions->isPlayerMuted($player)) {
|
2014-01-14 15:02:43 +01:00
|
|
|
$this->maniaControl->chat->sendError('Muted Players are not allowed to start a vote.', $player->login);
|
2014-01-11 20:01:03 +01:00
|
|
|
return;
|
|
|
|
}
|
2014-01-11 22:06:52 +01:00
|
|
|
|
2014-01-11 23:05:13 +01:00
|
|
|
//Specators are not allowed to start a vote
|
2014-01-31 00:04:40 +01:00
|
|
|
if ($player->isSpectator && !$this->maniaControl->settingManager->getSetting($this, self::SETTING_SPECTATOR_ALLOW_START_VOTE)) {
|
2014-01-14 15:02:43 +01:00
|
|
|
$this->maniaControl->chat->sendError('Spectators are not allowed to start a vote.', $player->login);
|
2014-01-11 22:06:52 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-01-11 23:05:13 +01:00
|
|
|
//Vote does not exist
|
2014-01-31 00:04:40 +01:00
|
|
|
if (!isset($this->voteCommands[$voteIndex])) {
|
2014-01-14 15:02:43 +01:00
|
|
|
$this->maniaControl->chat->sendError('Undefined vote.', $player->login);
|
2014-01-11 23:05:13 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
//A vote is currently running
|
2014-02-07 22:57:39 +01:00
|
|
|
if (isset($this->currentVote)) {
|
2014-01-14 15:02:43 +01:00
|
|
|
$this->maniaControl->chat->sendError('There is currently another vote running.', $player->login);
|
2014-01-11 23:05:13 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$maxTime = $this->maniaControl->settingManager->getSetting($this, self::SETTING_VOTE_TIME);
|
|
|
|
|
2014-02-07 22:57:39 +01:00
|
|
|
$this->currentVote = $this->voteCommands[$voteIndex];
|
2014-01-11 22:06:52 +01:00
|
|
|
|
2014-02-07 22:57:39 +01:00
|
|
|
$this->currentVote = new CurrentVote($this->voteCommands[$voteIndex], $player, time() + $maxTime);
|
|
|
|
$this->currentVote->neededRatio = floatval($this->maniaControl->settingManager->getSetting($this, self::SETTING_DEFAULT_RATIO));
|
|
|
|
$this->currentVote->neededPlayerRatio = floatval($this->maniaControl->settingManager->getSetting($this, self::SETTING_DEFAULT_PLAYER_RATIO));
|
|
|
|
$this->currentVote->function = $function;
|
2014-01-14 19:20:03 +01:00
|
|
|
|
2014-02-07 22:57:39 +01:00
|
|
|
$this->maniaControl->chat->sendSuccess('$<' . $player->nickname . '$>$s started a $<' . $this->currentVote->voteCommand->name . '$>!');
|
2014-01-11 20:52:29 +01:00
|
|
|
}
|
|
|
|
|
2014-01-11 22:06:52 +01:00
|
|
|
/**
|
|
|
|
* Handles a Positive Vote
|
|
|
|
*
|
|
|
|
* @param array $callback
|
|
|
|
* @param Player $player
|
|
|
|
*/
|
2014-01-11 20:52:29 +01:00
|
|
|
public function handlePositiveVote(array $callback, Player $player) {
|
2014-01-31 00:04:40 +01:00
|
|
|
if ($player->isSpectator && !$this->maniaControl->settingManager->getSetting($this, self::SETTING_SPECTATOR_ALLOW_VOTE)) {
|
2014-01-11 22:06:52 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-02-07 22:57:39 +01:00
|
|
|
$this->currentVote->votePositive($player->login);
|
2014-01-11 20:52:29 +01:00
|
|
|
}
|
|
|
|
|
2014-01-11 22:06:52 +01:00
|
|
|
/**
|
|
|
|
* Handles a negative Vote
|
|
|
|
*
|
|
|
|
* @param array $callback
|
|
|
|
* @param Player $player
|
|
|
|
*/
|
2014-01-11 20:52:29 +01:00
|
|
|
public function handleNegativeVote(array $callback, Player $player) {
|
2014-01-31 00:04:40 +01:00
|
|
|
if ($player->isSpectator && !$this->maniaControl->settingManager->getSetting($this, self::SETTING_SPECTATOR_ALLOW_VOTE)) {
|
2014-01-11 22:06:52 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-02-07 22:57:39 +01:00
|
|
|
$this->currentVote->voteNegative($player->login);
|
2014-01-11 20:01:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle ManiaControl 1 Second callback
|
|
|
|
*
|
2014-01-31 00:04:40 +01:00
|
|
|
* @param $time
|
2014-01-11 20:01:03 +01:00
|
|
|
*/
|
2014-01-31 00:04:40 +01:00
|
|
|
public function handle1Second($time) {
|
2014-02-07 22:57:39 +01:00
|
|
|
if (!isset($this->currentVote)) {
|
2014-01-11 20:01:03 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-02-07 22:57:39 +01:00
|
|
|
$votePercentage = $this->currentVote->positiveVotes / $this->currentVote->getVoteCount();
|
2014-01-11 20:52:29 +01:00
|
|
|
|
2014-02-07 22:57:39 +01:00
|
|
|
$timeUntilExpire = $this->currentVote->expireTime - time();
|
2014-01-11 20:52:29 +01:00
|
|
|
$this->showVoteWidget($timeUntilExpire, $votePercentage);
|
2014-01-11 20:01:03 +01:00
|
|
|
|
2014-01-12 17:45:41 +01:00
|
|
|
$playerCount = count($this->maniaControl->playerManager->getPlayers());
|
2014-02-07 22:57:39 +01:00
|
|
|
$playersVoteRatio = (100 / $playerCount * $this->currentVote->getVoteCount()) / 100;
|
2014-01-12 17:45:41 +01:00
|
|
|
|
2014-01-11 23:05:13 +01:00
|
|
|
//Check if vote is over
|
2014-02-07 22:57:39 +01:00
|
|
|
if ($timeUntilExpire <= 0 || (($playersVoteRatio >= $this->currentVote->neededPlayerRatio) && (($votePercentage >= $this->currentVote->neededRatio) || ($votePercentage <= 1 - $this->currentVote->neededRatio)))) {
|
2014-01-11 23:05:13 +01:00
|
|
|
// Trigger callback
|
2014-02-07 22:57:39 +01:00
|
|
|
$this->maniaControl->callbackManager->triggerCallback(self::CB_CUSTOM_VOTE_FINISHED, array(self::CB_CUSTOM_VOTE_FINISHED, $this->currentVote->voteCommand->index, $votePercentage));
|
2014-01-11 23:05:13 +01:00
|
|
|
|
|
|
|
//reset vote
|
2014-01-11 23:36:53 +01:00
|
|
|
$this->destroyVote();
|
2014-01-11 20:01:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-11 23:36:53 +01:00
|
|
|
/**
|
|
|
|
* Destroys the current Vote
|
|
|
|
*/
|
|
|
|
private function destroyVote() {
|
|
|
|
$emptyManialink = new ManiaLink(self::MLID_WIDGET);
|
|
|
|
$manialinkText = $emptyManialink->render()->saveXML();
|
|
|
|
$this->maniaControl->manialinkManager->sendManialink($manialinkText);
|
|
|
|
|
2014-02-07 22:57:39 +01:00
|
|
|
unset($this->currentVote);
|
2014-01-11 23:36:53 +01:00
|
|
|
}
|
|
|
|
|
2014-01-11 23:05:13 +01:00
|
|
|
/**
|
|
|
|
* Shows the vote widget
|
|
|
|
*
|
|
|
|
* @param $timeUntilExpire
|
|
|
|
* @param $votePercentage
|
|
|
|
*/
|
2014-01-11 20:52:29 +01:00
|
|
|
private function showVoteWidget($timeUntilExpire, $votePercentage) {
|
2014-01-11 23:05:13 +01:00
|
|
|
$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);
|
|
|
|
$maxTime = $this->maniaControl->settingManager->getSetting($this, self::SETTING_VOTE_TIME);
|
2014-01-11 20:01:03 +01:00
|
|
|
|
|
|
|
$quadStyle = $this->maniaControl->manialinkManager->styleManager->getDefaultQuadStyle();
|
|
|
|
$quadSubstyle = $this->maniaControl->manialinkManager->styleManager->getDefaultQuadSubstyle();
|
|
|
|
$labelStyle = $this->maniaControl->manialinkManager->styleManager->getDefaultLabelStyle();
|
|
|
|
|
|
|
|
$maniaLink = new ManiaLink(self::MLID_WIDGET);
|
2014-01-11 22:06:52 +01:00
|
|
|
|
2014-01-11 20:52:29 +01:00
|
|
|
//$script = new Script();
|
|
|
|
//$maniaLink->setScript($script);
|
2014-01-11 20:01:03 +01:00
|
|
|
|
|
|
|
// mainframe
|
|
|
|
$frame = new Frame();
|
|
|
|
$maniaLink->add($frame);
|
|
|
|
$frame->setSize($width, $height);
|
|
|
|
$frame->setPosition($pos_x, $pos_y);
|
|
|
|
|
|
|
|
// Background Quad
|
|
|
|
$backgroundQuad = new Quad();
|
|
|
|
$frame->add($backgroundQuad);
|
|
|
|
$backgroundQuad->setSize($width, $height);
|
|
|
|
$backgroundQuad->setStyles($quadStyle, $quadSubstyle);
|
|
|
|
|
2014-01-12 17:45:41 +01:00
|
|
|
//Vote for label
|
2014-01-11 20:01:03 +01:00
|
|
|
$label = new Label_Text();
|
|
|
|
$frame->add($label);
|
2014-01-14 14:45:40 +01:00
|
|
|
$label->setY($height / 2 - 3);
|
2014-01-11 20:01:03 +01:00
|
|
|
$label->setAlign(Control::CENTER, Control::CENTER);
|
|
|
|
$label->setSize($width - 5, $height);
|
2014-01-11 22:06:52 +01:00
|
|
|
$label->setTextSize(1.3);
|
2014-02-07 22:57:39 +01:00
|
|
|
$label->setText('$s ' . $this->currentVote->voteCommand->name);
|
2014-01-11 20:01:03 +01:00
|
|
|
|
2014-01-11 22:06:52 +01:00
|
|
|
//Started by nick
|
2014-01-11 20:01:03 +01:00
|
|
|
$label = new Label_Text();
|
|
|
|
$frame->add($label);
|
2014-01-14 14:45:40 +01:00
|
|
|
$label->setY($height / 2 - 6);
|
2014-01-11 20:01:03 +01:00
|
|
|
$label->setAlign(Control::CENTER, Control::CENTER);
|
2014-01-11 22:06:52 +01:00
|
|
|
$label->setSize($width - 5, 2);
|
|
|
|
$label->setTextSize(1);
|
|
|
|
$label->setTextColor("F80");
|
2014-02-07 22:57:39 +01:00
|
|
|
$label->setText('$sStarted by ' . $this->currentVote->voter->nickname);
|
2014-01-11 20:01:03 +01:00
|
|
|
|
2014-02-07 22:57:39 +01:00
|
|
|
//Time Gauge
|
2014-01-11 20:52:29 +01:00
|
|
|
$timeGauge = new Gauge();
|
|
|
|
$frame->add($timeGauge);
|
2014-01-14 14:45:40 +01:00
|
|
|
$timeGauge->setY(1.5);
|
2014-01-11 20:52:29 +01:00
|
|
|
$timeGauge->setSize($width * 0.95, 6);
|
|
|
|
$timeGauge->setDrawBg(false);
|
|
|
|
$timeGaugeRatio = (100 / $maxTime * $timeUntilExpire) / 100;
|
|
|
|
$timeGauge->setRatio($timeGaugeRatio + 0.15 - $timeGaugeRatio * 0.15);
|
|
|
|
$gaugeColor = ColorUtil::floatToStatusColor($timeGaugeRatio);
|
|
|
|
$timeGauge->setColor($gaugeColor . '9');
|
2014-01-11 20:01:03 +01:00
|
|
|
|
2014-01-11 22:06:52 +01:00
|
|
|
//Time Left
|
|
|
|
$label = new Label_Text();
|
|
|
|
$frame->add($label);
|
2014-01-14 14:45:40 +01:00
|
|
|
$label->setY(0);
|
2014-01-11 22:06:52 +01:00
|
|
|
$label->setAlign(Control::CENTER, Control::CENTER);
|
|
|
|
$label->setSize($width - 5, $height);
|
2014-01-14 14:45:40 +01:00
|
|
|
$label->setTextSize(1.1);
|
|
|
|
$label->setText('$sTime left: ' . $timeUntilExpire . "s");
|
2014-01-11 22:06:52 +01:00
|
|
|
$label->setTextColor("FFF");
|
|
|
|
|
2014-01-11 20:52:29 +01:00
|
|
|
//Vote Gauge
|
2014-01-11 20:01:03 +01:00
|
|
|
$voteGauge = new Gauge();
|
|
|
|
$frame->add($voteGauge);
|
2014-01-14 14:45:40 +01:00
|
|
|
$voteGauge->setY(-4);
|
2014-01-11 20:52:29 +01:00
|
|
|
$voteGauge->setSize($width * 0.65, 12);
|
2014-01-11 20:01:03 +01:00
|
|
|
$voteGauge->setDrawBg(false);
|
2014-01-14 15:20:28 +01:00
|
|
|
$voteGauge->setRatio($votePercentage + 0.10 - $votePercentage * 0.10);
|
2014-01-11 20:52:29 +01:00
|
|
|
$gaugeColor = ColorUtil::floatToStatusColor($votePercentage);
|
2014-01-14 14:45:40 +01:00
|
|
|
$voteGauge->setColor($gaugeColor . '6');
|
2014-01-11 20:01:03 +01:00
|
|
|
|
2014-01-14 14:45:40 +01:00
|
|
|
$y = -4.4;
|
2014-01-11 20:52:29 +01:00
|
|
|
$voteLabel = new Label();
|
|
|
|
$frame->add($voteLabel);
|
2014-01-14 14:45:40 +01:00
|
|
|
$voteLabel->setY($y);
|
2014-01-11 20:52:29 +01:00
|
|
|
$voteLabel->setSize($width * 0.65, 12);
|
|
|
|
$voteLabel->setStyle($labelStyle);
|
|
|
|
$voteLabel->setTextSize(1);
|
2014-02-07 22:57:39 +01:00
|
|
|
$voteLabel->setText(' ' . round($votePercentage * 100.) . '% (' . $this->currentVote->getVoteCount() . ')');
|
2014-01-11 20:52:29 +01:00
|
|
|
|
2014-01-14 14:45:40 +01:00
|
|
|
|
2014-01-11 20:52:29 +01:00
|
|
|
$quad = new Quad_BgsPlayerCard();
|
|
|
|
$frame->add($quad);
|
2014-01-14 14:45:40 +01:00
|
|
|
$quad->setX(-$width / 2 + 6);
|
2014-01-11 20:52:29 +01:00
|
|
|
$quad->setY($y);
|
|
|
|
$quad->setSubStyle($quad::SUBSTYLE_BgPlayerCardBig);
|
|
|
|
$quad->setSize(5, 5);
|
|
|
|
$quad->setAction(self::ACTION_NEGATIVE_VOTE);
|
2014-01-12 17:15:59 +01:00
|
|
|
$quad->setActionKey($quad::ACTIONKEY_F7);
|
2014-01-11 20:52:29 +01:00
|
|
|
|
|
|
|
$label = new Label_Button();
|
|
|
|
$frame->add($label);
|
2014-01-14 14:45:40 +01:00
|
|
|
$label->setX(-$width / 2 + 6);
|
2014-01-11 20:52:29 +01:00
|
|
|
$label->setAlign(Control::CENTER, Control::CENTER);
|
|
|
|
$label->setY($y);
|
|
|
|
$label->setStyle($labelStyle);
|
|
|
|
$label->setTextSize(1);
|
2014-01-11 22:06:52 +01:00
|
|
|
$label->setSize(3, 3);
|
2014-01-11 20:52:29 +01:00
|
|
|
$label->setTextColor("F00");
|
2014-01-12 17:15:59 +01:00
|
|
|
$label->setText("F7");
|
2014-01-11 20:01:03 +01:00
|
|
|
|
2014-01-11 20:52:29 +01:00
|
|
|
$quad = clone $quad;
|
|
|
|
$frame->add($quad);
|
2014-01-14 14:45:40 +01:00
|
|
|
$quad->setX($width / 2 - 6);
|
2014-01-11 20:52:29 +01:00
|
|
|
$quad->setAction(self::ACTION_POSITIVE_VOTE);
|
2014-01-12 17:15:59 +01:00
|
|
|
$quad->setActionKey($quad::ACTIONKEY_F8);
|
2014-01-11 20:01:03 +01:00
|
|
|
|
2014-01-11 20:52:29 +01:00
|
|
|
$label = clone $label;
|
|
|
|
$frame->add($label);
|
2014-01-14 14:45:40 +01:00
|
|
|
$label->setX($width / 2 - 6);
|
2014-01-11 20:52:29 +01:00
|
|
|
$label->setTextColor("0F0");
|
2014-01-12 17:15:59 +01:00
|
|
|
$label->setText("F8");
|
2014-01-11 20:01:03 +01:00
|
|
|
|
|
|
|
// Send manialink
|
|
|
|
$manialinkText = $maniaLink->render()->saveXML();
|
|
|
|
$this->maniaControl->manialinkManager->sendManialink($manialinkText);
|
|
|
|
}
|
|
|
|
|
2014-01-12 00:35:35 +01:00
|
|
|
/**
|
|
|
|
* Shows the Icon Widget
|
|
|
|
*
|
|
|
|
* @param bool $login
|
|
|
|
*/
|
|
|
|
private function showIcon($login = false) {
|
|
|
|
$posX = $this->maniaControl->settingManager->getSetting($this, self::SETTING_VOTE_ICON_POSX);
|
|
|
|
$posY = $this->maniaControl->settingManager->getSetting($this, self::SETTING_VOTE_ICON_POSY);
|
|
|
|
$width = $this->maniaControl->settingManager->getSetting($this, self::SETTING_VOTE_ICON_WIDTH);
|
|
|
|
$height = $this->maniaControl->settingManager->getSetting($this, self::SETTING_VOTE_ICON_HEIGHT);
|
2014-01-15 22:07:09 +01:00
|
|
|
$shootManiaOffset = $this->maniaControl->manialinkManager->styleManager->getDefaultIconOffsetSM();
|
2014-01-12 00:35:35 +01:00
|
|
|
$quadStyle = $this->maniaControl->manialinkManager->styleManager->getDefaultQuadStyle();
|
|
|
|
$quadSubstyle = $this->maniaControl->manialinkManager->styleManager->getDefaultQuadSubstyle();
|
|
|
|
$itemMarginFactorX = 1.3;
|
|
|
|
$itemMarginFactorY = 1.2;
|
|
|
|
|
2014-01-15 22:07:09 +01:00
|
|
|
// Get Title Id
|
|
|
|
$titleId = $this->maniaControl->server->titleId;
|
|
|
|
$titlePrefix = strtoupper(substr($titleId, 0, 2));
|
|
|
|
|
|
|
|
//If game is shootmania lower the icons position by 20
|
2014-01-31 00:04:40 +01:00
|
|
|
if ($titlePrefix == 'SM') {
|
2014-01-15 22:07:09 +01:00
|
|
|
$posY -= $shootManiaOffset;
|
|
|
|
}
|
|
|
|
|
2014-01-12 00:35:35 +01:00
|
|
|
$itemSize = $width;
|
|
|
|
|
|
|
|
$maniaLink = new ManiaLink(self::MLID_ICON);
|
|
|
|
$script = $maniaLink->getScript();
|
|
|
|
|
|
|
|
//Custom Vote Menu Iconsframe
|
|
|
|
$frame = new Frame();
|
|
|
|
$maniaLink->add($frame);
|
|
|
|
$frame->setPosition($posX, $posY);
|
|
|
|
|
|
|
|
$backgroundQuad = new Quad();
|
|
|
|
$frame->add($backgroundQuad);
|
|
|
|
$backgroundQuad->setSize($width * $itemMarginFactorX, $height * $itemMarginFactorY);
|
|
|
|
$backgroundQuad->setStyles($quadStyle, $quadSubstyle);
|
|
|
|
|
|
|
|
$iconFrame = new Frame();
|
|
|
|
$frame->add($iconFrame);
|
|
|
|
|
|
|
|
$iconFrame->setSize($itemSize, $itemSize);
|
2014-01-12 13:32:19 +01:00
|
|
|
$itemQuad = new Quad_UIConstruction_Buttons();
|
|
|
|
$itemQuad->setSubStyle($itemQuad::SUBSTYLE_Add);
|
2014-01-12 00:35:35 +01:00
|
|
|
$itemQuad->setSize($itemSize, $itemSize);
|
|
|
|
$iconFrame->add($itemQuad);
|
|
|
|
|
|
|
|
//Define Description Label
|
2014-01-14 19:11:57 +01:00
|
|
|
$menuEntries = count($this->voteMenuItems);
|
2014-01-12 00:35:35 +01:00
|
|
|
$descriptionFrame = new Frame();
|
|
|
|
$maniaLink->add($descriptionFrame);
|
|
|
|
$descriptionFrame->setPosition($posX - $menuEntries * $itemSize * 1.15 - 6, $posY);
|
|
|
|
|
|
|
|
$descriptionLabel = new Label();
|
|
|
|
$descriptionFrame->add($descriptionLabel);
|
|
|
|
$descriptionLabel->setAlign(Control::RIGHT, Control::TOP);
|
|
|
|
$descriptionLabel->setSize(40, 4);
|
|
|
|
$descriptionLabel->setTextSize(1.4);
|
|
|
|
$descriptionLabel->setTextColor('fff');
|
|
|
|
|
|
|
|
//Popout Frame
|
|
|
|
$popoutFrame = new Frame();
|
|
|
|
$maniaLink->add($popoutFrame);
|
|
|
|
$popoutFrame->setPosition($posX - $itemSize * 0.5, $posY);
|
|
|
|
$popoutFrame->setHAlign(Control::RIGHT);
|
|
|
|
$popoutFrame->setSize(4 * $itemSize * $itemMarginFactorX, $itemSize * $itemMarginFactorY);
|
2014-01-12 01:59:23 +01:00
|
|
|
$popoutFrame->setVisible(false);
|
2014-01-12 00:35:35 +01:00
|
|
|
|
|
|
|
$backgroundQuad = new Quad();
|
|
|
|
$popoutFrame->add($backgroundQuad);
|
|
|
|
$backgroundQuad->setHAlign(Control::RIGHT);
|
|
|
|
$backgroundQuad->setStyles($quadStyle, $quadSubstyle);
|
|
|
|
$backgroundQuad->setSize($menuEntries * $itemSize * 1.15 + 2, $itemSize * $itemMarginFactorY);
|
|
|
|
|
|
|
|
$script->addToggle($itemQuad, $popoutFrame);
|
|
|
|
|
2014-01-14 19:11:57 +01:00
|
|
|
// Add items
|
2014-01-12 00:35:35 +01:00
|
|
|
$x = -1;
|
2014-01-14 19:11:57 +01:00
|
|
|
foreach($this->voteMenuItems as $menuItems) {
|
|
|
|
foreach($menuItems as $menuItem) {
|
|
|
|
$menuQuad = $menuItem[0];
|
|
|
|
/**
|
|
|
|
* @var Quad $menuQuad
|
|
|
|
*/
|
|
|
|
$popoutFrame->add($menuQuad);
|
|
|
|
$menuQuad->setSize($itemSize, $itemSize);
|
|
|
|
$menuQuad->setX($x);
|
|
|
|
$menuQuad->setHAlign(Control::RIGHT);
|
|
|
|
$x -= $itemSize * 1.05;
|
|
|
|
|
2014-01-31 00:04:40 +01:00
|
|
|
if ($menuItem[1]) {
|
2014-01-14 19:11:57 +01:00
|
|
|
$description = '$s' . $menuItem[1];
|
|
|
|
$script->addTooltip($menuQuad, $descriptionLabel, array(Script::OPTION_TOOLTIP_TEXT => $description));
|
|
|
|
}
|
2014-01-14 18:40:45 +01:00
|
|
|
}
|
|
|
|
}
|
2014-01-12 00:35:35 +01:00
|
|
|
|
|
|
|
|
|
|
|
// Send manialink
|
|
|
|
$manialinkText = $maniaLink->render()->saveXML();
|
|
|
|
$this->maniaControl->manialinkManager->sendManialink($manialinkText, $login);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-01-11 20:01:03 +01:00
|
|
|
/**
|
|
|
|
* Get plugin id
|
|
|
|
*
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
public static function getId() {
|
|
|
|
return self::PLUGIN_ID;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get Plugin Name
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public static function getName() {
|
|
|
|
return self::PLUGIN_NAME;
|
|
|
|
}
|
2014-01-11 18:51:07 +01:00
|
|
|
|
2014-01-11 20:01:03 +01:00
|
|
|
/**
|
|
|
|
* Get Plugin Version
|
|
|
|
*
|
|
|
|
* @return float,,
|
|
|
|
*/
|
|
|
|
public static function getVersion() {
|
|
|
|
return self::PLUGIN_VERSION;
|
|
|
|
}
|
2014-01-11 18:51:07 +01:00
|
|
|
|
2014-01-11 20:01:03 +01:00
|
|
|
/**
|
|
|
|
* Get Plugin Author
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public static function getAuthor() {
|
|
|
|
return self::PLUGIN_AUTHOR;
|
|
|
|
}
|
2014-01-11 18:51:07 +01:00
|
|
|
|
2014-01-11 20:01:03 +01:00
|
|
|
/**
|
|
|
|
* Get Plugin Description
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public static function getDescription() {
|
2014-01-18 10:32:33 +01:00
|
|
|
return 'Plugin offers your Custom Votes like Restart, Skip, Balance...';
|
2014-01-11 20:01:03 +01:00
|
|
|
}
|
2014-02-07 22:57:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Vote Command Structure
|
|
|
|
*/
|
|
|
|
class VoteCommand {
|
|
|
|
public $index;
|
|
|
|
public $name;
|
|
|
|
public $neededRatio;
|
|
|
|
public $idBased;
|
|
|
|
|
|
|
|
public function __construct($index, $name, $idBased, $neededRatio) {
|
|
|
|
$this->index = $index;
|
|
|
|
$this->name = $name;
|
|
|
|
$this->idBased = $idBased;
|
|
|
|
$this->neededRatio = $neededRatio;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Current Vote Structure
|
|
|
|
*/
|
|
|
|
class CurrentVote {
|
|
|
|
const VOTE_FOR_ACTION = '1';
|
|
|
|
const VOTE_AGAINST_ACTION = '-1';
|
|
|
|
|
|
|
|
public $voteCommand = null;
|
|
|
|
public $expireTime = 0;
|
|
|
|
public $positiveVotes = 0;
|
|
|
|
public $neededRatio = 0;
|
|
|
|
public $neededPlayerRatio = 0;
|
|
|
|
public $voter = null;
|
|
|
|
public $map = null;
|
|
|
|
public $player = null;
|
|
|
|
public $function = null;
|
|
|
|
|
|
|
|
private $playersVoted = array();
|
|
|
|
|
|
|
|
public function __construct(VoteCommand $voteCommand, Player $voter, $expireTime) {
|
|
|
|
$this->expireTime = $expireTime;
|
|
|
|
$this->voteCommand = $voteCommand;
|
|
|
|
$this->voter = $voter;
|
|
|
|
$this->votePositive($voter->login);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function votePositive($login) {
|
|
|
|
if (isset($this->playersVoted[$login])) {
|
|
|
|
if ($this->playersVoted[$login] == self::VOTE_AGAINST_ACTION) {
|
|
|
|
$this->playersVoted[$login] = self::VOTE_FOR_ACTION;
|
|
|
|
$this->positiveVotes++;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$this->playersVoted[$login] = self::VOTE_FOR_ACTION;
|
|
|
|
$this->positiveVotes++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function voteNegative($login) {
|
|
|
|
if (isset($this->playersVoted[$login])) {
|
|
|
|
if ($this->playersVoted[$login] == self::VOTE_FOR_ACTION) {
|
|
|
|
$this->playersVoted[$login] = self::VOTE_AGAINST_ACTION;
|
|
|
|
$this->positiveVotes--;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$this->playersVoted[$login] = self::VOTE_AGAINST_ACTION;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getVoteCount() {
|
|
|
|
return count($this->playersVoted);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|