2014-05-03 21:57:38 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace MCTeam;
|
|
|
|
|
|
|
|
use FML\Controls\Control;
|
|
|
|
use FML\Controls\Frame;
|
|
|
|
use FML\Controls\Gauge;
|
|
|
|
use FML\Controls\Label;
|
|
|
|
use FML\Controls\Labels\Label_Button;
|
|
|
|
use FML\Controls\Labels\Label_Text;
|
|
|
|
use FML\Controls\Quad;
|
|
|
|
use FML\Controls\Quads\Quad_BgsPlayerCard;
|
|
|
|
use FML\Controls\Quads\Quad_Icons128x32_1;
|
|
|
|
use FML\Controls\Quads\Quad_Icons64x64_1;
|
|
|
|
use FML\Controls\Quads\Quad_UIConstruction_Buttons;
|
|
|
|
use FML\ManiaLink;
|
2014-05-03 23:49:58 +02:00
|
|
|
use FML\Script\Features\KeyAction;
|
2017-05-07 20:22:59 +02:00
|
|
|
use ManiaControl\Admin\ActionsMenu;
|
2014-05-03 21:57:38 +02:00
|
|
|
use ManiaControl\Callbacks\CallbackListener;
|
|
|
|
use ManiaControl\Callbacks\CallbackManager;
|
2014-07-04 11:34:17 +02:00
|
|
|
use ManiaControl\Callbacks\Callbacks;
|
2014-05-03 21:57:38 +02:00
|
|
|
use ManiaControl\Callbacks\TimerListener;
|
|
|
|
use ManiaControl\Commands\CommandListener;
|
|
|
|
use ManiaControl\ManiaControl;
|
2017-04-11 12:04:37 +02:00
|
|
|
use ManiaControl\Manialinks\ManialinkManager;
|
2014-05-03 21:57:38 +02:00
|
|
|
use ManiaControl\Manialinks\ManialinkPageAnswerListener;
|
2017-05-19 18:36:41 +02:00
|
|
|
use ManiaControl\Manialinks\SidebarMenuEntryListener;
|
2017-05-11 20:02:28 +02:00
|
|
|
use ManiaControl\Manialinks\SidebarMenuManager;
|
2014-05-03 21:57:38 +02:00
|
|
|
use ManiaControl\Players\Player;
|
|
|
|
use ManiaControl\Players\PlayerManager;
|
|
|
|
use ManiaControl\Plugins\Plugin;
|
2017-04-13 20:46:23 +02:00
|
|
|
use ManiaControl\Script\ScriptManager;
|
2014-07-19 23:29:20 +02:00
|
|
|
use ManiaControl\Server\Commands;
|
2014-07-26 16:07:52 +02:00
|
|
|
use ManiaControl\Server\Server;
|
2017-05-07 20:22:59 +02:00
|
|
|
use ManiaControl\Settings\Setting;
|
|
|
|
use ManiaControl\Settings\SettingManager;
|
2014-05-13 16:03:26 +02:00
|
|
|
use ManiaControl\Utils\ColorUtil;
|
2014-05-03 21:57:38 +02:00
|
|
|
use Maniaplanet\DedicatedServer\Structures\VoteRatio;
|
2014-07-04 10:06:07 +02:00
|
|
|
use Maniaplanet\DedicatedServer\Xmlrpc\ChangeInProgressException;
|
2014-05-13 17:59:37 +02:00
|
|
|
use Maniaplanet\DedicatedServer\Xmlrpc\GameModeException;
|
2014-05-03 21:57:38 +02:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ManiaControl Custom-Votes Plugin
|
|
|
|
*
|
2014-05-03 23:49:58 +02:00
|
|
|
* @author ManiaControl Team <mail@maniacontrol.com>
|
2018-03-27 20:11:40 +02:00
|
|
|
* @copyright 2014-2018 ManiaControl Team
|
2014-05-03 23:49:58 +02:00
|
|
|
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
2014-05-03 21:57:38 +02:00
|
|
|
*/
|
2017-05-19 18:36:41 +02:00
|
|
|
class CustomVotesPlugin implements SidebarMenuEntryListener, CommandListener, CallbackListener, ManialinkPageAnswerListener, TimerListener, Plugin {
|
2014-05-03 21:57:38 +02:00
|
|
|
/*
|
|
|
|
* Constants
|
|
|
|
*/
|
|
|
|
const PLUGIN_ID = 5;
|
2017-05-07 20:22:59 +02:00
|
|
|
const PLUGIN_VERSION = 0.2;
|
2014-05-03 21:57:38 +02:00
|
|
|
const PLUGIN_NAME = 'CustomVotesPlugin';
|
|
|
|
const PLUGIN_AUTHOR = 'kremsy';
|
|
|
|
|
|
|
|
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';
|
|
|
|
const SETTING_DEFAULT_PLAYER_RATIO = 'Minimum Player Voters Ratio';
|
|
|
|
const SETTING_DEFAULT_RATIO = 'Default Success Ratio';
|
2014-05-13 01:18:47 +02:00
|
|
|
const SETTING_SPECTATOR_ALLOW_VOTE = 'Allow Spectators to vote';
|
|
|
|
const SETTING_SPECTATOR_ALLOW_START_VOTE = 'Allow Spectators to start a vote';
|
2014-05-03 21:57:38 +02:00
|
|
|
|
2017-05-11 20:02:28 +02:00
|
|
|
const MLID_WIDGET = 'CustomVotesPlugin.WidgetId';
|
|
|
|
const MLID_ICON = 'CustomVotesPlugin.IconWidgetId';
|
|
|
|
const CUSTOMVOTES_MENU_ID = 'CustomVotesPlugin.MenuId';
|
2014-05-03 21:57:38 +02:00
|
|
|
|
|
|
|
const ACTION_POSITIVE_VOTE = 'CustomVotesPlugin.PositiveVote';
|
|
|
|
const ACTION_NEGATIVE_VOTE = 'CustomVotesPlugin.NegativeVote';
|
|
|
|
const ACTION_START_VOTE = 'CustomVotesPlugin.StartVote.';
|
|
|
|
|
|
|
|
|
|
|
|
const CB_CUSTOM_VOTE_FINISHED = 'CustomVotesPlugin.CustomVoteFinished';
|
|
|
|
|
2014-05-03 23:49:58 +02:00
|
|
|
/*
|
2014-08-02 22:31:46 +02:00
|
|
|
* Private properties
|
2014-05-03 21:57:38 +02:00
|
|
|
*/
|
2014-08-02 22:31:46 +02:00
|
|
|
/** @var ManiaControl $maniaControl */
|
2015-08-26 18:06:43 +02:00
|
|
|
private $maniaControl = null;
|
|
|
|
private $voteCommands = array();
|
2014-05-03 21:57:38 +02:00
|
|
|
private $voteMenuItems = array();
|
|
|
|
/** @var CurrentVote $currentVote */
|
|
|
|
private $currentVote = null;
|
|
|
|
|
|
|
|
/**
|
2014-05-03 23:49:58 +02:00
|
|
|
* @see \ManiaControl\Plugins\Plugin::prepare()
|
2014-05-03 21:57:38 +02:00
|
|
|
*/
|
|
|
|
public static function prepare(ManiaControl $maniaControl) {
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-05-03 23:49:58 +02:00
|
|
|
* @see \ManiaControl\Plugins\Plugin::getId()
|
|
|
|
*/
|
|
|
|
public static function getId() {
|
|
|
|
return self::PLUGIN_ID;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @see \ManiaControl\Plugins\Plugin::getName()
|
|
|
|
*/
|
|
|
|
public static function getName() {
|
|
|
|
return self::PLUGIN_NAME;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @see \ManiaControl\Plugins\Plugin::getVersion()
|
|
|
|
*/
|
|
|
|
public static function getVersion() {
|
|
|
|
return self::PLUGIN_VERSION;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @see \ManiaControl\Plugins\Plugin::getAuthor()
|
|
|
|
*/
|
|
|
|
public static function getAuthor() {
|
|
|
|
return self::PLUGIN_AUTHOR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @see \ManiaControl\Plugins\Plugin::getDescription()
|
|
|
|
*/
|
|
|
|
public static function getDescription() {
|
|
|
|
return 'Plugin offers your Custom Votes like Restart, Skip, Balance...';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @see \ManiaControl\Plugins\Plugin::load()
|
2014-05-03 21:57:38 +02:00
|
|
|
*/
|
|
|
|
public function load(ManiaControl $maniaControl) {
|
|
|
|
$this->maniaControl = $maniaControl;
|
|
|
|
|
2014-08-03 01:34:18 +02:00
|
|
|
// Commands
|
2014-08-13 11:14:29 +02:00
|
|
|
$this->maniaControl->getCommandManager()->registerCommandListener('vote', $this, 'chat_vote', false, 'Starts a new vote.');
|
2014-08-03 01:34:18 +02:00
|
|
|
|
|
|
|
// Callbacks
|
2014-08-13 11:14:29 +02:00
|
|
|
$this->maniaControl->getManialinkManager()->registerManialinkPageAnswerListener(self::ACTION_POSITIVE_VOTE, $this, 'handlePositiveVote');
|
|
|
|
$this->maniaControl->getManialinkManager()->registerManialinkPageAnswerListener(self::ACTION_NEGATIVE_VOTE, $this, 'handleNegativeVote');
|
|
|
|
$this->maniaControl->getTimerManager()->registerTimerListening($this, 'handle1Second', 1000);
|
|
|
|
$this->maniaControl->getCallbackManager()->registerCallbackListener(Commands::CB_VOTE_CANCELLED, $this, 'handleVoteCancelled');
|
|
|
|
|
|
|
|
$this->maniaControl->getCallbackManager()->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer');
|
|
|
|
$this->maniaControl->getCallbackManager()->registerCallbackListener(self::CB_CUSTOM_VOTE_FINISHED, $this, 'handleVoteFinished');
|
|
|
|
$this->maniaControl->getCallbackManager()->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerConnect');
|
|
|
|
$this->maniaControl->getCallbackManager()->registerCallbackListener(Server::CB_TEAM_MODE_CHANGED, $this, 'constructMenu');
|
2017-04-13 20:46:23 +02:00
|
|
|
$this->maniaControl->getCallbackManager()->registerCallbackListener(ScriptManager::CB_PAUSE_STATUS_CHANGED, $this, 'constructMenu');
|
2017-05-07 20:22:59 +02:00
|
|
|
$this->maniaControl->getCallbackManager()->registerCallbackListener(SettingManager::CB_SETTING_CHANGED, $this, 'handleSettingChanged');
|
|
|
|
|
2014-08-03 01:34:18 +02:00
|
|
|
// Settings
|
2014-08-13 11:14:29 +02:00
|
|
|
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_WIDGET_POSX, -80); //160 -15
|
|
|
|
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_WIDGET_POSY, 80); //-15
|
|
|
|
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_WIDGET_WIDTH, 50); //30
|
|
|
|
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_WIDGET_HEIGHT, 20); //25
|
|
|
|
|
|
|
|
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_DEFAULT_RATIO, 0.75);
|
|
|
|
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_DEFAULT_PLAYER_RATIO, 0.65);
|
|
|
|
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_SPECTATOR_ALLOW_VOTE, false);
|
|
|
|
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_SPECTATOR_ALLOW_START_VOTE, true);
|
|
|
|
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_VOTE_TIME, 40);
|
2014-05-03 21:57:38 +02:00
|
|
|
|
2017-05-19 18:36:41 +02:00
|
|
|
$this->maniaControl->getManialinkManager()->getSidebarMenuManager()->addMenuEntry(SidebarMenuManager::ORDER_PLAYER_MENU + 5, self::CUSTOMVOTES_MENU_ID,$this,'showIcon');
|
2014-05-03 21:57:38 +02:00
|
|
|
//Define Votes
|
|
|
|
$this->defineVote("teambalance", "Vote for Team Balance");
|
2014-08-13 11:14:29 +02:00
|
|
|
$this->defineVote("skipmap", "Vote for Skip Map")->setStopCallback(Callbacks::ENDMAP);
|
|
|
|
$this->defineVote("nextmap", "Vote for Skip Map")->setStopCallback(Callbacks::ENDMAP);
|
|
|
|
$this->defineVote("skip", "Vote for Skip Map")->setStopCallback(Callbacks::ENDMAP);
|
|
|
|
$this->defineVote("restartmap", "Vote for Restart Map")->setStopCallback(Callbacks::ENDMAP);
|
|
|
|
$this->defineVote("restart", "Vote for Restart Map")->setStopCallback(Callbacks::ENDMAP);
|
2014-05-03 21:57:38 +02:00
|
|
|
$this->defineVote("pausegame", "Vote for Pause Game");
|
|
|
|
$this->defineVote("replay", "Vote to replay current map");
|
|
|
|
|
2014-05-03 23:49:58 +02:00
|
|
|
foreach ($this->voteCommands as $name => $voteCommand) {
|
2014-08-13 11:14:29 +02:00
|
|
|
$this->maniaControl->getCommandManager()->registerCommandListener($name, $this, 'handleChatVote', false, $voteCommand->name);
|
2014-05-03 21:57:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Disable Standard Votes */
|
2014-05-08 19:34:19 +02:00
|
|
|
$ratioArray[] = new VoteRatio(VoteRatio::COMMAND_BAN, -1.);
|
|
|
|
$ratioArray[] = new VoteRatio(VoteRatio::COMMAND_KICK, -1.);
|
|
|
|
$ratioArray[] = new VoteRatio(VoteRatio::COMMAND_RESTART_MAP, -1.);
|
|
|
|
$ratioArray[] = new VoteRatio(VoteRatio::COMMAND_TEAM_BALANCE, -1.);
|
|
|
|
$ratioArray[] = new VoteRatio(VoteRatio::COMMAND_NEXT_MAP, -1.);
|
2014-05-03 21:57:38 +02:00
|
|
|
|
2017-05-14 09:25:52 +02:00
|
|
|
$this->maniaControl->getClient()->setCallVoteRatios($ratioArray, false, true);
|
2014-05-03 21:57:38 +02:00
|
|
|
|
|
|
|
$this->constructMenu();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-05-09 17:31:29 +02:00
|
|
|
* Define a Vote
|
2014-05-03 23:49:58 +02:00
|
|
|
*
|
2014-05-09 17:31:29 +02:00
|
|
|
* @param int $voteIndex
|
|
|
|
* @param string $voteName
|
|
|
|
* @param bool $idBased
|
|
|
|
* @param string $startText
|
|
|
|
* @param float $neededRatio
|
2014-07-04 11:34:17 +02:00
|
|
|
* @return \MCTeam\VoteCommand
|
2014-05-03 23:49:58 +02:00
|
|
|
*/
|
|
|
|
public function defineVote($voteIndex, $voteName, $idBased = false, $startText = '', $neededRatio = -1) {
|
2014-06-14 14:32:29 +02:00
|
|
|
if ($neededRatio < 0) {
|
2014-08-13 11:14:29 +02:00
|
|
|
$neededRatio = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_DEFAULT_RATIO);
|
2014-05-03 23:49:58 +02:00
|
|
|
}
|
|
|
|
$voteCommand = new VoteCommand($voteIndex, $voteName, $idBased, $neededRatio);
|
|
|
|
$voteCommand->startText = $startText;
|
|
|
|
$this->voteCommands[$voteIndex] = $voteCommand;
|
2014-07-04 11:34:17 +02:00
|
|
|
|
|
|
|
return $voteCommand;
|
2014-05-03 23:49:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle ManiaControl OnInit callback
|
|
|
|
*
|
|
|
|
* @internal param array $callback
|
|
|
|
*/
|
|
|
|
public function constructMenu() {
|
|
|
|
// 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');
|
|
|
|
|
2017-04-13 20:46:23 +02:00
|
|
|
if ($this->maniaControl->getServer()->getScriptManager()->modeUsesPause()) {
|
|
|
|
$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');
|
2014-05-03 23:49:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//Menu SkipMap
|
|
|
|
$itemQuad = new Quad_Icons64x64_1();
|
|
|
|
$itemQuad->setSubStyle($itemQuad::SUBSTYLE_ArrowFastNext);
|
|
|
|
$itemQuad->setAction(self::ACTION_START_VOTE . 'skipmap');
|
2014-05-24 20:39:18 +02:00
|
|
|
$this->addVoteMenuItem($itemQuad, 15, 'Vote for a Map Skip');
|
2014-05-03 23:49:58 +02:00
|
|
|
|
2017-04-13 20:46:23 +02:00
|
|
|
if ($this->maniaControl->getServer()->getScriptManager()->modeIsTeamMode()) {
|
2014-05-03 23:49:58 +02:00
|
|
|
//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
|
|
|
|
$this->showIcon();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a new Vote Menu Item
|
|
|
|
*
|
|
|
|
* @param Control $control
|
|
|
|
* @param int $order
|
|
|
|
* @param string $description
|
|
|
|
*/
|
|
|
|
public function addVoteMenuItem(Control $control, $order = 0, $description = null) {
|
|
|
|
if (!isset($this->voteMenuItems[$order])) {
|
|
|
|
$this->voteMenuItems[$order] = array();
|
|
|
|
array_push($this->voteMenuItems[$order], array($control, $description));
|
|
|
|
krsort($this->voteMenuItems);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Shows the Icon Widget
|
|
|
|
*
|
|
|
|
* @param bool $login
|
|
|
|
*/
|
2017-05-19 18:36:41 +02:00
|
|
|
public function showIcon($login = false) {
|
2017-05-11 20:02:28 +02:00
|
|
|
$pos = $this->maniaControl->getManialinkManager()->getSidebarMenuManager()->getEntryPosition(self::CUSTOMVOTES_MENU_ID);
|
2017-05-12 09:37:53 +02:00
|
|
|
$width = $this->maniaControl->getSettingManager()->getSettingValue($this->maniaControl->getManialinkManager()->getSidebarMenuManager(), SidebarMenuManager::SETTING_MENU_ITEMSIZE);
|
2014-08-13 11:14:29 +02:00
|
|
|
$quadStyle = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultQuadStyle();
|
|
|
|
$quadSubstyle = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultQuadSubstyle();
|
2014-05-03 23:49:58 +02:00
|
|
|
$itemMarginFactorX = 1.3;
|
|
|
|
$itemMarginFactorY = 1.2;
|
|
|
|
|
|
|
|
$itemSize = $width;
|
|
|
|
|
|
|
|
$maniaLink = new ManiaLink(self::MLID_ICON);
|
|
|
|
|
|
|
|
//Custom Vote Menu Iconsframe
|
|
|
|
$frame = new Frame();
|
2017-03-25 19:15:50 +01:00
|
|
|
$maniaLink->addChild($frame);
|
2017-05-12 10:27:26 +02:00
|
|
|
$frame->setPosition($pos->getX(), $pos->getY());
|
2017-04-11 12:04:37 +02:00
|
|
|
$frame->setZ(ManialinkManager::MAIN_MANIALINK_Z_VALUE);
|
2014-05-03 23:49:58 +02:00
|
|
|
|
|
|
|
$backgroundQuad = new Quad();
|
2017-03-25 19:15:50 +01:00
|
|
|
$frame->addChild($backgroundQuad);
|
2017-05-11 20:02:28 +02:00
|
|
|
$backgroundQuad->setSize($width * $itemMarginFactorX, $itemSize * $itemMarginFactorY);
|
2014-05-03 23:49:58 +02:00
|
|
|
$backgroundQuad->setStyles($quadStyle, $quadSubstyle);
|
|
|
|
|
|
|
|
$iconFrame = new Frame();
|
2017-03-25 19:15:50 +01:00
|
|
|
$frame->addChild($iconFrame);
|
2014-05-03 23:49:58 +02:00
|
|
|
|
|
|
|
$iconFrame->setSize($itemSize, $itemSize);
|
|
|
|
$itemQuad = new Quad_UIConstruction_Buttons();
|
|
|
|
$itemQuad->setSubStyle($itemQuad::SUBSTYLE_Add);
|
|
|
|
$itemQuad->setSize($itemSize, $itemSize);
|
2017-03-25 19:15:50 +01:00
|
|
|
$iconFrame->addChild($itemQuad);
|
2014-05-03 23:49:58 +02:00
|
|
|
|
|
|
|
//Define Description Label
|
|
|
|
$menuEntries = count($this->voteMenuItems);
|
|
|
|
$descriptionFrame = new Frame();
|
2017-03-25 19:25:20 +01:00
|
|
|
$maniaLink->addChild($descriptionFrame);
|
2017-05-12 10:27:26 +02:00
|
|
|
$descriptionFrame->setPosition($pos->getX() - $menuEntries * $itemSize * 1.05 - 5, $pos->getY());
|
2014-05-03 23:49:58 +02:00
|
|
|
|
|
|
|
$descriptionLabel = new Label();
|
2017-03-25 19:15:50 +01:00
|
|
|
$descriptionFrame->addChild($descriptionLabel);
|
2014-06-22 19:02:18 +02:00
|
|
|
$descriptionLabel->setAlign($descriptionLabel::RIGHT, $descriptionLabel::TOP);
|
2014-05-03 23:49:58 +02:00
|
|
|
$descriptionLabel->setSize(40, 4);
|
|
|
|
$descriptionLabel->setTextSize(1.4);
|
|
|
|
$descriptionLabel->setTextColor('fff');
|
|
|
|
|
|
|
|
//Popout Frame
|
|
|
|
$popoutFrame = new Frame();
|
2017-03-25 19:25:20 +01:00
|
|
|
$maniaLink->addChild($popoutFrame);
|
2017-05-12 10:27:26 +02:00
|
|
|
$popoutFrame->setPosition($pos->getX() - $itemSize * 0.5, $pos->getY());
|
2017-05-17 16:08:51 +02:00
|
|
|
$popoutFrame->setZ(ManialinkManager::MAIN_MANIALINK_Z_VALUE);
|
2017-03-25 19:15:50 +01:00
|
|
|
$popoutFrame->setHorizontalAlign($popoutFrame::RIGHT);
|
2014-05-03 23:49:58 +02:00
|
|
|
$popoutFrame->setSize(4 * $itemSize * $itemMarginFactorX, $itemSize * $itemMarginFactorY);
|
|
|
|
$popoutFrame->setVisible(false);
|
|
|
|
|
2017-03-25 19:15:50 +01:00
|
|
|
|
2014-05-03 23:49:58 +02:00
|
|
|
$backgroundQuad = new Quad();
|
2017-03-25 19:15:50 +01:00
|
|
|
$popoutFrame->addChild($backgroundQuad);
|
|
|
|
$backgroundQuad->setHorizontalAlign($backgroundQuad::RIGHT);
|
2014-05-03 23:49:58 +02:00
|
|
|
$backgroundQuad->setStyles($quadStyle, $quadSubstyle);
|
2017-03-28 16:44:41 +02:00
|
|
|
$backgroundQuad->setSize($menuEntries * $itemSize * 1.05 + 2, $itemSize * $itemMarginFactorY);
|
2014-05-03 23:49:58 +02:00
|
|
|
|
|
|
|
$itemQuad->addToggleFeature($popoutFrame);
|
|
|
|
|
|
|
|
// Add items
|
2014-06-14 15:48:27 +02:00
|
|
|
$posX = -1;
|
2014-05-03 23:49:58 +02:00
|
|
|
foreach ($this->voteMenuItems as $menuItems) {
|
|
|
|
foreach ($menuItems as $menuItem) {
|
2014-06-14 15:48:27 +02:00
|
|
|
/** @var Quad $menuQuad */
|
2014-05-03 23:49:58 +02:00
|
|
|
$menuQuad = $menuItem[0];
|
2017-03-25 19:15:50 +01:00
|
|
|
$popoutFrame->addChild($menuQuad);
|
2014-05-03 23:49:58 +02:00
|
|
|
$menuQuad->setSize($itemSize, $itemSize);
|
2014-06-14 15:48:27 +02:00
|
|
|
$menuQuad->setX($posX);
|
2017-03-25 19:15:50 +01:00
|
|
|
$menuQuad->setHorizontalAlign($menuQuad::RIGHT);
|
2014-06-14 15:48:27 +02:00
|
|
|
$posX -= $itemSize * 1.05;
|
2014-05-03 23:49:58 +02:00
|
|
|
|
|
|
|
if ($menuItem[1]) {
|
2017-03-25 19:15:50 +01:00
|
|
|
$menuQuad->removeAllScriptFeatures();
|
2014-05-03 23:49:58 +02:00
|
|
|
$description = '$s' . $menuItem[1];
|
|
|
|
$menuQuad->addTooltipLabelFeature($descriptionLabel, $description);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Send manialink
|
2014-08-13 11:14:29 +02:00
|
|
|
$this->maniaControl->getManialinkManager()->sendManialink($maniaLink, $login);
|
2014-05-03 23:49:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @see \ManiaControl\Plugins\Plugin::unload()
|
2014-05-03 21:57:38 +02:00
|
|
|
*/
|
|
|
|
public function unload() {
|
|
|
|
//Enable Standard Votes
|
2014-08-13 11:14:29 +02:00
|
|
|
$defaultRatio = $this->maniaControl->getClient()->getCallVoteRatio();
|
2014-05-03 21:57:38 +02:00
|
|
|
|
2014-05-08 19:34:19 +02:00
|
|
|
$ratioArray[] = new VoteRatio(VoteRatio::COMMAND_BAN, $defaultRatio);
|
|
|
|
$ratioArray[] = new VoteRatio(VoteRatio::COMMAND_KICK, $defaultRatio);
|
|
|
|
$ratioArray[] = new VoteRatio(VoteRatio::COMMAND_RESTART_MAP, $defaultRatio);
|
|
|
|
$ratioArray[] = new VoteRatio(VoteRatio::COMMAND_TEAM_BALANCE, $defaultRatio);
|
|
|
|
$ratioArray[] = new VoteRatio(VoteRatio::COMMAND_NEXT_MAP, $defaultRatio);
|
|
|
|
|
2014-08-13 11:14:29 +02:00
|
|
|
$this->maniaControl->getClient()->setCallVoteRatios($ratioArray, false);
|
2014-05-03 21:57:38 +02:00
|
|
|
|
|
|
|
$this->destroyVote();
|
2014-08-13 11:14:29 +02:00
|
|
|
$this->maniaControl->getManialinkManager()->hideManialink(self::MLID_ICON);
|
2014-05-03 21:57:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-05-03 23:49:58 +02:00
|
|
|
* Destroys the current Vote
|
2014-05-03 21:57:38 +02:00
|
|
|
*/
|
2014-05-03 23:49:58 +02:00
|
|
|
private function destroyVote() {
|
|
|
|
$emptyManialink = new ManiaLink(self::MLID_WIDGET);
|
2014-08-13 11:14:29 +02:00
|
|
|
$this->maniaControl->getManialinkManager()->sendManialink($emptyManialink);
|
2014-05-03 23:49:58 +02:00
|
|
|
|
2014-08-03 01:34:18 +02:00
|
|
|
// Remove the Listener for the Stop Callback if a stop callback is defined
|
2014-07-04 11:34:17 +02:00
|
|
|
if ($this->currentVote && $this->currentVote->stopCallback) {
|
2014-08-13 11:14:29 +02:00
|
|
|
$this->maniaControl->getCallbackManager()->unregisterCallbackListening($this->currentVote->stopCallback, $this);
|
2014-07-04 11:34:17 +02:00
|
|
|
}
|
|
|
|
|
2014-07-12 19:20:38 +02:00
|
|
|
$this->currentVote = null;
|
2014-05-03 21:57:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-05-03 23:49:58 +02:00
|
|
|
* Handle PlayerConnect callback
|
2014-05-03 21:57:38 +02:00
|
|
|
*
|
2014-05-03 23:49:58 +02:00
|
|
|
* @param Player $player
|
2014-05-03 21:57:38 +02:00
|
|
|
*/
|
2014-05-03 23:49:58 +02:00
|
|
|
public function handlePlayerConnect(Player $player) {
|
|
|
|
$this->showIcon($player->login);
|
2014-05-03 21:57:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Chat Vote
|
|
|
|
*
|
|
|
|
* @param array $chat
|
|
|
|
* @param Player $player
|
|
|
|
*/
|
|
|
|
public function chat_vote(array $chat, Player $player) {
|
|
|
|
$command = explode(" ", $chat[1][2]);
|
|
|
|
if (isset($command[1])) {
|
|
|
|
if (isset($this->voteCommands[$command[1]])) {
|
|
|
|
$this->startVote($player, strtolower($command[1]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-05-09 17:31:29 +02:00
|
|
|
* Start a vote
|
2014-05-03 21:57:38 +02:00
|
|
|
*
|
2014-05-09 17:31:29 +02:00
|
|
|
* @param Player $player
|
|
|
|
* @param int $voteIndex
|
2014-07-04 11:41:03 +02:00
|
|
|
* @param callable $function calls the given function only if the vote is successful and returns as Parameter the Voting-Results
|
2014-05-03 21:57:38 +02:00
|
|
|
*/
|
2014-05-03 23:49:58 +02:00
|
|
|
public function startVote(Player $player, $voteIndex, $function = null) {
|
2014-08-24 12:28:16 +02:00
|
|
|
// Check if the Player is muted
|
|
|
|
if ($player->isMuted()) {
|
2014-08-13 11:14:29 +02:00
|
|
|
$this->maniaControl->getChat()->sendError('Muted Players are not allowed to start a vote.', $player);
|
2014-05-03 23:49:58 +02:00
|
|
|
return;
|
|
|
|
}
|
2014-05-03 21:57:38 +02:00
|
|
|
|
2014-05-13 01:18:47 +02:00
|
|
|
// Spectators are not allowed to start a vote
|
2014-08-05 02:17:41 +02:00
|
|
|
if ($player->isSpectator
|
2014-08-13 11:14:29 +02:00
|
|
|
&& !$this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_SPECTATOR_ALLOW_START_VOTE)
|
2014-08-05 02:17:41 +02:00
|
|
|
) {
|
2014-08-13 11:14:29 +02:00
|
|
|
$this->maniaControl->getChat()->sendError('Spectators are not allowed to start a vote.', $player);
|
2014-05-03 23:49:58 +02:00
|
|
|
return;
|
|
|
|
}
|
2014-05-03 21:57:38 +02:00
|
|
|
|
2014-05-03 23:49:58 +02:00
|
|
|
//Vote does not exist
|
|
|
|
if (!isset($this->voteCommands[$voteIndex])) {
|
2014-08-13 11:14:29 +02:00
|
|
|
$this->maniaControl->getChat()->sendError('Undefined vote.', $player);
|
2014-05-03 23:49:58 +02:00
|
|
|
return;
|
2014-05-03 21:57:38 +02:00
|
|
|
}
|
|
|
|
|
2014-05-03 23:49:58 +02:00
|
|
|
//A vote is currently running
|
|
|
|
if (isset($this->currentVote)) {
|
2014-08-13 11:14:29 +02:00
|
|
|
$this->maniaControl->getChat()->sendError('There is currently another vote running.', $player);
|
2014-05-03 23:49:58 +02:00
|
|
|
return;
|
|
|
|
}
|
2014-05-03 21:57:38 +02:00
|
|
|
|
2014-08-13 11:14:29 +02:00
|
|
|
$maxTime = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_VOTE_TIME);
|
2014-05-03 23:49:58 +02:00
|
|
|
|
2014-07-04 11:34:17 +02:00
|
|
|
/** @var VoteCommand $voteCommand */
|
|
|
|
$voteCommand = $this->voteCommands[$voteIndex];
|
2014-05-03 23:49:58 +02:00
|
|
|
|
2014-07-04 11:34:17 +02:00
|
|
|
$this->currentVote = new CurrentVote($voteCommand, $player, time() + $maxTime);
|
2014-08-13 11:14:29 +02:00
|
|
|
$this->currentVote->neededRatio = floatval($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_DEFAULT_RATIO));
|
|
|
|
$this->currentVote->neededPlayerRatio = floatval($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_DEFAULT_PLAYER_RATIO));
|
2014-05-03 23:49:58 +02:00
|
|
|
$this->currentVote->function = $function;
|
|
|
|
|
2014-07-04 11:34:17 +02:00
|
|
|
if ($voteCommand->getStopCallback()) {
|
2014-08-13 11:14:29 +02:00
|
|
|
$this->maniaControl->getCallbackManager()->registerCallbackListener($voteCommand->getStopCallback(), $this, 'handleStopCallback');
|
2014-07-04 11:34:17 +02:00
|
|
|
$this->currentVote->stopCallback = $voteCommand->getStopCallback();
|
|
|
|
}
|
|
|
|
|
2014-06-14 14:32:29 +02:00
|
|
|
if ($this->currentVote->voteCommand->startText) {
|
2014-05-03 23:49:58 +02:00
|
|
|
$message = $this->currentVote->voteCommand->startText;
|
|
|
|
} else {
|
2014-08-03 01:34:18 +02:00
|
|
|
$message = '$fff' . $player->getEscapedNickname() . '$s$f8f started a $fff$<' . $this->currentVote->voteCommand->name . '$>$f8f!';
|
2014-05-03 21:57:38 +02:00
|
|
|
}
|
2014-05-03 23:49:58 +02:00
|
|
|
|
2014-08-13 11:14:29 +02:00
|
|
|
$this->maniaControl->getChat()->sendSuccess($message);
|
2014-05-03 21:57:38 +02:00
|
|
|
}
|
|
|
|
|
2014-07-04 11:34:17 +02:00
|
|
|
/**
|
|
|
|
* Destroys the Vote on the Stop Callback
|
|
|
|
*/
|
|
|
|
public function handleStopCallback() {
|
|
|
|
$this->destroyVote();
|
|
|
|
}
|
|
|
|
|
2014-05-03 21:57:38 +02:00
|
|
|
/**
|
2014-07-26 16:07:52 +02:00
|
|
|
* Destroy the Vote on Cancelled Callback
|
2014-05-03 21:57:38 +02:00
|
|
|
*/
|
2014-07-26 16:07:52 +02:00
|
|
|
public function handleVoteCancelled() {
|
2014-05-03 21:57:38 +02:00
|
|
|
$this->destroyVote();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle Standard Votes
|
|
|
|
*
|
2014-05-13 16:40:05 +02:00
|
|
|
* @param string $voteName
|
|
|
|
* @param float $voteResult
|
2014-05-03 21:57:38 +02:00
|
|
|
*/
|
|
|
|
public function handleVoteFinished($voteName, $voteResult) {
|
|
|
|
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-05-03 23:49:58 +02:00
|
|
|
switch ($voteName) {
|
2014-05-03 21:57:38 +02:00
|
|
|
case 'teambalance':
|
2014-08-13 11:14:29 +02:00
|
|
|
$this->maniaControl->getClient()->autoTeamBalance();
|
|
|
|
$this->maniaControl->getChat()->sendInformation('$f8fVote to $fffbalance the Teams$f8f has been successful!');
|
2014-05-03 21:57:38 +02:00
|
|
|
break;
|
|
|
|
case 'skipmap':
|
|
|
|
case 'skip':
|
|
|
|
case 'nextmap':
|
2014-07-04 10:06:07 +02:00
|
|
|
try {
|
2014-08-13 11:14:29 +02:00
|
|
|
$this->maniaControl->getMapManager()->getMapActions()->skipMap();
|
2014-07-04 10:06:07 +02:00
|
|
|
} catch (ChangeInProgressException $e) {
|
|
|
|
}
|
2014-08-13 11:14:29 +02:00
|
|
|
$this->maniaControl->getChat()->sendInformation('$f8fVote to $fffskip the Map$f8f has been successful!');
|
2014-05-03 21:57:38 +02:00
|
|
|
break;
|
|
|
|
case 'restartmap':
|
2014-07-04 10:06:07 +02:00
|
|
|
try {
|
2014-08-13 11:14:29 +02:00
|
|
|
$this->maniaControl->getClient()->restartMap();
|
2014-07-04 10:06:07 +02:00
|
|
|
} catch (ChangeInProgressException $e) {
|
|
|
|
}
|
2014-08-13 11:14:29 +02:00
|
|
|
$this->maniaControl->getChat()->sendInformation('$f8fVote to $fffrestart the Map$f8f has been successful!');
|
2014-05-03 21:57:38 +02:00
|
|
|
break;
|
|
|
|
case 'pausegame':
|
2014-08-03 13:16:37 +02:00
|
|
|
try {
|
2015-08-26 18:06:43 +02:00
|
|
|
//Gamemodes like Elite, Speedball
|
2014-08-13 11:14:29 +02:00
|
|
|
$this->maniaControl->getClient()->sendModeScriptCommands(array('Command_ForceWarmUp' => true));
|
|
|
|
$this->maniaControl->getChat()->sendInformation('$f8fVote to $fffpause the current Game$f8f has been successful!');
|
2014-08-03 13:16:37 +02:00
|
|
|
} catch (GameModeException $ex) {
|
|
|
|
}
|
2015-08-26 18:06:43 +02:00
|
|
|
|
2017-04-13 20:46:23 +02:00
|
|
|
//TODO verify if not everything is replaced through the new pause
|
|
|
|
$this->maniaControl->getModeScriptEventManager()->startPause();
|
|
|
|
$this->maniaControl->getChat()->sendInformation('$f8fVote to $fffpause the current Game$f8f has been successful!');
|
2014-05-03 21:57:38 +02:00
|
|
|
break;
|
|
|
|
case 'replay':
|
2014-08-13 11:14:29 +02:00
|
|
|
$this->maniaControl->getMapManager()->getMapQueue()->addFirstMapToMapQueue($this->currentVote->voter, $this->maniaControl->getMapManager()->getCurrentMap());
|
|
|
|
$this->maniaControl->getChat()->sendInformation('$f8fVote to $fffreplay the Map$f8f has been successful!');
|
2014-05-03 21:57:38 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
2014-07-10 22:23:47 +02:00
|
|
|
//FIXME bugreport, no fail message on vote fail sometimes
|
2014-08-13 11:14:29 +02:00
|
|
|
$this->maniaControl->getChat()->sendError('Vote Failed!');
|
2014-05-03 21:57:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handles the ManialinkPageAnswers and start a vote if a button in the panel got clicked
|
|
|
|
*
|
|
|
|
* @param array $callback
|
|
|
|
*/
|
|
|
|
public function handleManialinkPageAnswer(array $callback) {
|
|
|
|
$actionId = $callback[1][2];
|
|
|
|
$actionArray = explode('.', $actionId);
|
|
|
|
if (count($actionArray) <= 2) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$voteIndex = $actionArray[2];
|
|
|
|
if (isset($this->voteCommands[$voteIndex])) {
|
|
|
|
$login = $callback[1][1];
|
2014-08-13 11:14:29 +02:00
|
|
|
$player = $this->maniaControl->getPlayerManager()->getPlayer($login);
|
2014-05-03 21:57:38 +02:00
|
|
|
$this->startVote($player, $voteIndex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-13 16:03:26 +02:00
|
|
|
/**
|
|
|
|
* Handle a Player Chat Vote
|
|
|
|
*
|
|
|
|
* @param array $chat
|
|
|
|
* @param Player $player
|
|
|
|
*/
|
2014-05-03 21:57:38 +02:00
|
|
|
public function handleChatVote(array $chat, Player $player) {
|
|
|
|
$chatCommand = explode(' ', $chat[1][2]);
|
|
|
|
$chatCommand = $chatCommand[0];
|
|
|
|
$chatCommand = str_replace('/', '', $chatCommand);
|
|
|
|
|
|
|
|
if (isset($this->voteCommands[$chatCommand])) {
|
|
|
|
$this->startVote($player, $chatCommand);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-05-13 16:40:05 +02:00
|
|
|
* Undefine a Vote
|
2014-05-03 21:57:38 +02:00
|
|
|
*
|
2014-05-13 16:40:05 +02:00
|
|
|
* @param int $voteIndex
|
2014-05-03 21:57:38 +02:00
|
|
|
*/
|
|
|
|
public function undefineVote($voteIndex) {
|
|
|
|
unset($this->voteCommands[$voteIndex]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handles a Positive Vote
|
|
|
|
*
|
|
|
|
* @param array $callback
|
|
|
|
* @param Player $player
|
|
|
|
*/
|
|
|
|
public function handlePositiveVote(array $callback, Player $player) {
|
2014-08-05 02:17:41 +02:00
|
|
|
if (!isset($this->currentVote)
|
|
|
|
|| $player->isSpectator
|
2014-08-13 11:14:29 +02:00
|
|
|
&& !$this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_SPECTATOR_ALLOW_VOTE)
|
2014-08-05 02:17:41 +02:00
|
|
|
) {
|
2014-05-03 21:57:38 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->currentVote->votePositive($player->login);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handles a negative Vote
|
|
|
|
*
|
|
|
|
* @param array $callback
|
|
|
|
* @param Player $player
|
|
|
|
*/
|
|
|
|
public function handleNegativeVote(array $callback, Player $player) {
|
2014-08-05 02:17:41 +02:00
|
|
|
if (!isset($this->currentVote)
|
|
|
|
|| $player->isSpectator
|
2014-08-13 11:14:29 +02:00
|
|
|
&& !$this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_SPECTATOR_ALLOW_VOTE)
|
2014-08-05 02:17:41 +02:00
|
|
|
) {
|
2014-05-03 21:57:38 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->currentVote->voteNegative($player->login);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-05-13 16:40:05 +02:00
|
|
|
* Handle ManiaControl 1 Second Callback
|
2014-05-03 21:57:38 +02:00
|
|
|
*/
|
2014-05-13 16:40:05 +02:00
|
|
|
public function handle1Second() {
|
2014-05-03 21:57:38 +02:00
|
|
|
if (!isset($this->currentVote)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-05-15 18:10:01 +02:00
|
|
|
$voteCount = $this->currentVote->getVoteCount();
|
|
|
|
$votePercentage = 0;
|
|
|
|
if ($voteCount > 0) {
|
|
|
|
$votePercentage = $this->currentVote->positiveVotes / floatval($voteCount);
|
|
|
|
}
|
2014-05-03 21:57:38 +02:00
|
|
|
|
|
|
|
$timeUntilExpire = $this->currentVote->expireTime - time();
|
|
|
|
$this->showVoteWidget($timeUntilExpire, $votePercentage);
|
|
|
|
|
2014-08-13 11:14:29 +02:00
|
|
|
$playerCount = $this->maniaControl->getPlayerManager()->getPlayerCount();
|
2014-05-15 18:10:01 +02:00
|
|
|
$playersVoteRatio = 0;
|
|
|
|
if ($playerCount > 0 && $voteCount > 0) {
|
|
|
|
$playersVoteRatio = floatval($voteCount) / floatval($playerCount);
|
|
|
|
}
|
2014-05-03 21:57:38 +02:00
|
|
|
|
|
|
|
//Check if vote is over
|
|
|
|
if ($timeUntilExpire <= 0 || (($playersVoteRatio >= $this->currentVote->neededPlayerRatio) && (($votePercentage >= $this->currentVote->neededRatio) || ($votePercentage <= 1 - $this->currentVote->neededRatio)))) {
|
|
|
|
// Trigger callback
|
2014-08-13 11:14:29 +02:00
|
|
|
$this->maniaControl->getCallbackManager()->triggerCallback(self::CB_CUSTOM_VOTE_FINISHED, $this->currentVote->voteCommand->index, $votePercentage);
|
2014-05-03 21:57:38 +02:00
|
|
|
|
|
|
|
//reset vote
|
|
|
|
$this->destroyVote();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-05-13 16:03:26 +02:00
|
|
|
* Show the vote widget
|
2014-05-03 21:57:38 +02:00
|
|
|
*
|
2014-05-13 16:03:26 +02:00
|
|
|
* @param int $timeUntilExpire
|
|
|
|
* @param float $votePercentage
|
2014-05-03 21:57:38 +02:00
|
|
|
*/
|
|
|
|
private function showVoteWidget($timeUntilExpire, $votePercentage) {
|
2014-08-13 11:14:29 +02:00
|
|
|
$posX = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_WIDGET_POSX);
|
|
|
|
$posY = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_WIDGET_POSY);
|
|
|
|
$width = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_WIDGET_WIDTH);
|
|
|
|
$height = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_WIDGET_HEIGHT);
|
|
|
|
$maxTime = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_VOTE_TIME);
|
|
|
|
|
|
|
|
$quadStyle = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultQuadStyle();
|
|
|
|
$quadSubstyle = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultQuadSubstyle();
|
|
|
|
$labelStyle = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultLabelStyle();
|
2014-05-03 21:57:38 +02:00
|
|
|
|
|
|
|
$maniaLink = new ManiaLink(self::MLID_WIDGET);
|
|
|
|
|
|
|
|
// mainframe
|
|
|
|
$frame = new Frame();
|
2017-03-25 19:15:50 +01:00
|
|
|
$maniaLink->addChild($frame);
|
2014-05-03 21:57:38 +02:00
|
|
|
$frame->setSize($width, $height);
|
2014-06-14 15:48:27 +02:00
|
|
|
$frame->setPosition($posX, $posY, 30);
|
2014-05-03 21:57:38 +02:00
|
|
|
|
|
|
|
// Background Quad
|
|
|
|
$backgroundQuad = new Quad();
|
2017-03-25 19:15:50 +01:00
|
|
|
$frame->addChild($backgroundQuad);
|
2014-05-03 21:57:38 +02:00
|
|
|
$backgroundQuad->setSize($width, $height);
|
|
|
|
$backgroundQuad->setStyles($quadStyle, $quadSubstyle);
|
|
|
|
|
|
|
|
//Vote for label
|
|
|
|
$label = new Label_Text();
|
2017-03-25 19:15:50 +01:00
|
|
|
$frame->addChild($label);
|
2014-05-03 21:57:38 +02:00
|
|
|
$label->setY($height / 2 - 3);
|
|
|
|
$label->setSize($width - 5, $height);
|
|
|
|
$label->setTextSize(1.3);
|
|
|
|
$label->setText('$s ' . $this->currentVote->voteCommand->name);
|
|
|
|
|
|
|
|
//Started by nick
|
|
|
|
$label = new Label_Text();
|
2017-03-25 19:15:50 +01:00
|
|
|
$frame->addChild($label);
|
2014-05-03 21:57:38 +02:00
|
|
|
$label->setY($height / 2 - 6);
|
|
|
|
$label->setSize($width - 5, 2);
|
|
|
|
$label->setTextSize(1);
|
2014-06-14 15:48:27 +02:00
|
|
|
$label->setTextColor('F80');
|
2014-05-03 21:57:38 +02:00
|
|
|
$label->setText('$sStarted by ' . $this->currentVote->voter->nickname);
|
|
|
|
|
2017-05-22 18:12:15 +02:00
|
|
|
|
2014-05-03 21:57:38 +02:00
|
|
|
//Time Gauge
|
|
|
|
$timeGauge = new Gauge();
|
2017-03-25 19:15:50 +01:00
|
|
|
$frame->addChild($timeGauge);
|
2014-05-03 21:57:38 +02:00
|
|
|
$timeGauge->setY(1.5);
|
|
|
|
$timeGauge->setSize($width * 0.95, 6);
|
2017-05-22 18:12:15 +02:00
|
|
|
$timeGauge->setDrawBackground(false);
|
2014-05-03 23:49:58 +02:00
|
|
|
if (!$timeUntilExpire) {
|
|
|
|
$timeUntilExpire = 1;
|
|
|
|
}
|
2014-05-03 21:57:38 +02:00
|
|
|
$timeGaugeRatio = (100 / $maxTime * $timeUntilExpire) / 100;
|
|
|
|
$timeGauge->setRatio($timeGaugeRatio + 0.15 - $timeGaugeRatio * 0.15);
|
|
|
|
$gaugeColor = ColorUtil::floatToStatusColor($timeGaugeRatio);
|
|
|
|
$timeGauge->setColor($gaugeColor . '9');
|
|
|
|
|
|
|
|
//Time Left
|
|
|
|
$label = new Label_Text();
|
2017-03-25 19:15:50 +01:00
|
|
|
$frame->addChild($label);
|
2014-05-03 21:57:38 +02:00
|
|
|
$label->setY(0);
|
|
|
|
$label->setSize($width - 5, $height);
|
|
|
|
$label->setTextSize(1.1);
|
|
|
|
$label->setText('$sTime left: ' . $timeUntilExpire . "s");
|
2014-06-14 15:48:27 +02:00
|
|
|
$label->setTextColor('FFF');
|
2014-05-03 21:57:38 +02:00
|
|
|
|
|
|
|
//Vote Gauge
|
|
|
|
$voteGauge = new Gauge();
|
2017-03-25 19:15:50 +01:00
|
|
|
$frame->addChild($voteGauge);
|
2014-05-03 21:57:38 +02:00
|
|
|
$voteGauge->setY(-4);
|
|
|
|
$voteGauge->setSize($width * 0.65, 12);
|
2017-05-22 18:12:15 +02:00
|
|
|
$voteGauge->setDrawBackground(false);
|
2014-05-03 21:57:38 +02:00
|
|
|
$voteGauge->setRatio($votePercentage + 0.10 - $votePercentage * 0.10);
|
|
|
|
$gaugeColor = ColorUtil::floatToStatusColor($votePercentage);
|
|
|
|
$voteGauge->setColor($gaugeColor . '6');
|
2017-05-17 16:08:51 +02:00
|
|
|
$voteGauge->setZ(-0.1);
|
2014-05-03 21:57:38 +02:00
|
|
|
|
2014-06-14 15:48:27 +02:00
|
|
|
$posY = -4.4;
|
2014-05-03 21:57:38 +02:00
|
|
|
$voteLabel = new Label();
|
2017-03-25 19:15:50 +01:00
|
|
|
$frame->addChild($voteLabel);
|
2014-06-14 15:48:27 +02:00
|
|
|
$voteLabel->setY($posY);
|
2014-05-03 21:57:38 +02:00
|
|
|
$voteLabel->setSize($width * 0.65, 12);
|
|
|
|
$voteLabel->setStyle($labelStyle);
|
|
|
|
$voteLabel->setTextSize(1);
|
|
|
|
$voteLabel->setText(' ' . round($votePercentage * 100.) . '% (' . $this->currentVote->getVoteCount() . ')');
|
|
|
|
|
|
|
|
|
|
|
|
$positiveQuad = new Quad_BgsPlayerCard();
|
2017-03-25 19:15:50 +01:00
|
|
|
$frame->addChild($positiveQuad);
|
2014-06-14 15:48:27 +02:00
|
|
|
$positiveQuad->setPosition(-$width / 2 + 6, $posY);
|
2014-05-03 21:57:38 +02:00
|
|
|
$positiveQuad->setSubStyle($positiveQuad::SUBSTYLE_BgPlayerCardBig);
|
|
|
|
$positiveQuad->setSize(5, 5);
|
|
|
|
|
|
|
|
$positiveLabel = new Label_Button();
|
2017-03-25 19:15:50 +01:00
|
|
|
$frame->addChild($positiveLabel);
|
2014-06-14 15:48:27 +02:00
|
|
|
$positiveLabel->setPosition(-$width / 2 + 6, $posY);
|
2014-05-03 21:57:38 +02:00
|
|
|
$positiveLabel->setStyle($labelStyle);
|
|
|
|
$positiveLabel->setTextSize(1);
|
|
|
|
$positiveLabel->setSize(3, 3);
|
2014-06-14 15:48:27 +02:00
|
|
|
$positiveLabel->setTextColor('0F0');
|
|
|
|
$positiveLabel->setText('F1');
|
2014-05-03 21:57:38 +02:00
|
|
|
|
|
|
|
$negativeQuad = clone $positiveQuad;
|
2017-03-25 19:15:50 +01:00
|
|
|
$frame->addChild($negativeQuad);
|
2014-05-03 21:57:38 +02:00
|
|
|
$negativeQuad->setX($width / 2 - 6);
|
|
|
|
|
|
|
|
$negativeLabel = clone $positiveLabel;
|
2017-03-25 19:15:50 +01:00
|
|
|
$frame->addChild($negativeLabel);
|
2014-05-03 21:57:38 +02:00
|
|
|
$negativeLabel->setX($width / 2 - 6);
|
2014-06-14 15:48:27 +02:00
|
|
|
$negativeLabel->setTextColor('F00');
|
|
|
|
$negativeLabel->setText('F2');
|
2014-05-03 23:49:58 +02:00
|
|
|
|
2014-05-03 21:57:38 +02:00
|
|
|
// Voting Actions
|
|
|
|
$positiveQuad->addActionTriggerFeature(self::ACTION_POSITIVE_VOTE);
|
|
|
|
$negativeQuad->addActionTriggerFeature(self::ACTION_NEGATIVE_VOTE);
|
2014-05-03 23:49:58 +02:00
|
|
|
|
|
|
|
$script = $maniaLink->getScript();
|
2014-05-03 21:57:38 +02:00
|
|
|
$keyActionPositive = new KeyAction(self::ACTION_POSITIVE_VOTE, 'F1');
|
|
|
|
$script->addFeature($keyActionPositive);
|
|
|
|
$keyActionNegative = new KeyAction(self::ACTION_NEGATIVE_VOTE, 'F2');
|
|
|
|
$script->addFeature($keyActionNegative);
|
|
|
|
|
|
|
|
// Send manialink
|
2014-08-13 11:14:29 +02:00
|
|
|
$this->maniaControl->getManialinkManager()->sendManialink($maniaLink);
|
2014-05-03 21:57:38 +02:00
|
|
|
}
|
2017-05-07 20:22:59 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle Setting Changed Callback
|
|
|
|
*
|
|
|
|
* @param Setting $setting
|
|
|
|
*/
|
|
|
|
public function handleSettingChanged(Setting $setting) {
|
|
|
|
if (!$setting->belongsToClass($this)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->constructMenu();
|
|
|
|
}
|
2014-05-03 21:57:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-05-13 16:03:26 +02:00
|
|
|
* Vote Command Model Class
|
2014-05-03 21:57:38 +02:00
|
|
|
*/
|
2014-05-27 08:56:56 +02:00
|
|
|
// TODO: extract classes to own files
|
2014-05-03 21:57:38 +02:00
|
|
|
class VoteCommand {
|
2015-08-26 18:06:43 +02:00
|
|
|
public $index = '';
|
|
|
|
public $name = '';
|
2014-05-03 21:57:38 +02:00
|
|
|
public $neededRatio = 0;
|
2015-08-26 18:06:43 +02:00
|
|
|
public $idBased = false;
|
|
|
|
public $startText = '';
|
2014-05-03 21:57:38 +02:00
|
|
|
|
2014-07-04 11:34:17 +02:00
|
|
|
private $stopCallback = '';
|
|
|
|
|
2014-05-13 16:03:26 +02:00
|
|
|
/**
|
|
|
|
* Construct a new Vote Command
|
|
|
|
*
|
2014-05-13 16:40:05 +02:00
|
|
|
* @param int $index
|
|
|
|
* @param string $name
|
|
|
|
* @param bool $idBased
|
|
|
|
* @param float $neededRatio
|
2014-05-13 16:03:26 +02:00
|
|
|
*/
|
2014-05-03 21:57:38 +02:00
|
|
|
public function __construct($index, $name, $idBased, $neededRatio) {
|
|
|
|
$this->index = $index;
|
|
|
|
$this->name = $name;
|
|
|
|
$this->idBased = $idBased;
|
|
|
|
$this->neededRatio = $neededRatio;
|
|
|
|
}
|
2014-07-04 11:34:17 +02:00
|
|
|
|
|
|
|
/**
|
2014-07-26 16:07:52 +02:00
|
|
|
* Gets the Stop Callback
|
2014-07-04 11:34:17 +02:00
|
|
|
*
|
2014-07-26 16:07:52 +02:00
|
|
|
* @return string
|
2014-07-04 11:34:17 +02:00
|
|
|
*/
|
2014-07-26 16:07:52 +02:00
|
|
|
public function getStopCallback() {
|
|
|
|
return $this->stopCallback;
|
2014-07-04 11:34:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-07-26 16:07:52 +02:00
|
|
|
* Defines a Stop Callback
|
2014-07-04 11:34:17 +02:00
|
|
|
*
|
2014-07-26 16:07:52 +02:00
|
|
|
* @param $stopCallback
|
2014-07-04 11:34:17 +02:00
|
|
|
*/
|
2014-07-26 16:07:52 +02:00
|
|
|
public function setStopCallback($stopCallback) {
|
|
|
|
$this->stopCallback = $stopCallback;
|
2014-07-04 11:34:17 +02:00
|
|
|
}
|
|
|
|
|
2014-05-03 21:57:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-05-13 16:03:26 +02:00
|
|
|
* Current Vote Model Class
|
2014-05-03 21:57:38 +02:00
|
|
|
*/
|
|
|
|
class CurrentVote {
|
|
|
|
const VOTE_FOR_ACTION = '1';
|
|
|
|
const VOTE_AGAINST_ACTION = '-1';
|
|
|
|
|
2015-08-26 18:06:43 +02:00
|
|
|
public $voteCommand = null;
|
|
|
|
public $expireTime = 0;
|
|
|
|
public $positiveVotes = 0;
|
|
|
|
public $neededRatio = 0;
|
2014-05-03 21:57:38 +02:00
|
|
|
public $neededPlayerRatio = 0;
|
2015-08-26 18:06:43 +02:00
|
|
|
public $voter = null;
|
|
|
|
public $map = null;
|
|
|
|
public $player = null;
|
|
|
|
public $function = null;
|
|
|
|
public $stopCallback = "";
|
2014-05-03 21:57:38 +02:00
|
|
|
|
|
|
|
private $playersVoted = array();
|
|
|
|
|
2014-05-13 16:03:26 +02:00
|
|
|
/**
|
|
|
|
* Construct a Current Vote
|
|
|
|
*
|
|
|
|
* @param VoteCommand $voteCommand
|
|
|
|
* @param Player $voter
|
|
|
|
* @param $expireTime
|
|
|
|
*/
|
2014-05-03 21:57:38 +02:00
|
|
|
public function __construct(VoteCommand $voteCommand, Player $voter, $expireTime) {
|
|
|
|
$this->expireTime = $expireTime;
|
|
|
|
$this->voteCommand = $voteCommand;
|
|
|
|
$this->voter = $voter;
|
|
|
|
$this->votePositive($voter->login);
|
|
|
|
}
|
|
|
|
|
2014-05-13 16:03:26 +02:00
|
|
|
/**
|
|
|
|
* Handle a positive Vote
|
|
|
|
*
|
|
|
|
* @param string $login
|
|
|
|
*/
|
2014-05-03 21:57:38 +02:00
|
|
|
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++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-13 16:03:26 +02:00
|
|
|
/**
|
|
|
|
* Handle a negative Vote
|
|
|
|
*
|
|
|
|
* @param string $login
|
|
|
|
*/
|
2014-05-03 21:57:38 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-13 16:03:26 +02:00
|
|
|
/**
|
|
|
|
* Get the Number of Votes
|
|
|
|
*
|
|
|
|
* @return int
|
|
|
|
*/
|
2014-05-03 21:57:38 +02:00
|
|
|
public function getVoteCount() {
|
|
|
|
return count($this->playersVoted);
|
|
|
|
}
|
2014-07-26 16:31:47 +02:00
|
|
|
}
|