added custom voting with f1 & f2
Conflicts: application/plugins/CustomVotes.php
This commit is contained in:
		
							
								
								
									
										118
									
								
								application/core/Libs/FML/Script/Features/KeyAction.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										118
									
								
								application/core/Libs/FML/Script/Features/KeyAction.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,118 @@ | ||||
| <?php | ||||
|  | ||||
| namespace FML\Script\Features; | ||||
|  | ||||
| use FML\Controls\Control; | ||||
| use FML\Script\Script; | ||||
| use FML\Script\ScriptLabel; | ||||
| use FML\Script\Builder; | ||||
|  | ||||
| /** | ||||
|  * Script Feature for triggering a Page Action on Key Press | ||||
|  *  | ||||
|  * @author steeffeen | ||||
|  * @link http://destroflyer.mania-community.de/maniascript/keycharid_table.php | ||||
|  * @copyright FancyManiaLinks Copyright © 2014 Steffen Schröder | ||||
|  * @license http://www.gnu.org/licenses/ GNU General Public License, Version 3 | ||||
|  */ | ||||
| class KeyAction extends ScriptFeature { | ||||
| 	/* | ||||
| 	 * Protected Properties | ||||
| 	 */ | ||||
| 	protected $actionName = null; | ||||
| 	protected $keyName = null; | ||||
| 	protected $keyCode = null; | ||||
| 	protected $charPressed = null; | ||||
|  | ||||
| 	/** | ||||
| 	 * Construct a new Key Action Feature | ||||
| 	 *  | ||||
| 	 * @param string $actionName (optional) Triggered Action | ||||
| 	 * @param string $keyName (optional) Key Name | ||||
| 	 * @param int $keyCode (optional) Key Code | ||||
| 	 * @param string $charPressed (optional) Pressed Char | ||||
| 	 */ | ||||
| 	public function __construct($actionName = null, $keyName = null, $keyCode = null, $charPressed = null) { | ||||
| 		$this->setActionName($actionName); | ||||
| 		$this->setKeyName($keyName); | ||||
| 		$this->setKeyCode($keyCode); | ||||
| 		$this->setCharPressed($charPressed); | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * Set the Action to trigger | ||||
| 	 *  | ||||
| 	 * @param string $actionName Triggered Action | ||||
| 	 * @return \FML\Script\Features\KeyAction | ||||
| 	 */ | ||||
| 	public function setActionName($actionName) { | ||||
| 		$this->actionName = (string) $actionName; | ||||
| 		return $this; | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * Set the Key Name for triggering the Action | ||||
| 	 *  | ||||
| 	 * @param string $keyName Key Name | ||||
| 	 * @return \FML\Script\Features\KeyAction | ||||
| 	 */ | ||||
| 	public function setKeyName($keyName) { | ||||
| 		$this->keyName = (string) $keyName; | ||||
| 		return $this; | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * Set the Key Code for triggering the Action | ||||
| 	 *  | ||||
| 	 * @param int $keyCode Key Code | ||||
| 	 * @return \FML\Script\Features\KeyAction | ||||
| 	 */ | ||||
| 	public function setKeyCode($keyCode) { | ||||
| 		$this->keyCode = $keyCode; | ||||
| 		return $this; | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * Set the Char to press for triggering the Action | ||||
| 	 *  | ||||
| 	 * @param string $charPressed Pressed Char | ||||
| 	 * @return \FML\Script\Features\KeyAction | ||||
| 	 */ | ||||
| 	public function setCharPressed($charPressed) { | ||||
| 		$this->charPressed = $charPressed; | ||||
| 		return $this; | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * | ||||
| 	 * @see \FML\Script\Features\ScriptFeature::prepare() | ||||
| 	 */ | ||||
| 	public function prepare(Script $script) { | ||||
| 		$script->appendGenericScriptLabel(ScriptLabel::KEYPRESS, $this->getScriptText()); | ||||
| 		return $this; | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * Get the Script Text | ||||
| 	 *  | ||||
| 	 * @return string | ||||
| 	 */ | ||||
| 	protected function getScriptText() { | ||||
| 		$actionName = Builder::escapeText($this->actionName); | ||||
| 		$key = 'KeyName'; | ||||
| 		$value = $this->keyName; | ||||
| 		if ($this->keyCode !== null) { | ||||
| 			$key = 'KeyCode'; | ||||
| 			$value = (int) $this->keyCode; | ||||
| 		} | ||||
| 		else if ($this->charPressed !== null) { | ||||
| 			$key = 'CharPressed'; | ||||
| 			$value = (string) $this->charPressed; | ||||
| 		} | ||||
| 		$scriptText = " | ||||
| if (Event.{$key} == \"{$value}\") { | ||||
| 	TriggerPageAction(\"{$actionName}\"); | ||||
| }"; | ||||
| 		return $scriptText; | ||||
| 	} | ||||
| } | ||||
| @@ -26,6 +26,7 @@ use ManiaControl\Server\Server; | ||||
| use ManiaControl\Server\ServerCommands; | ||||
| use Maniaplanet\DedicatedServer\Structures\VoteRatio; | ||||
| use Maniaplanet\DedicatedServer\Xmlrpc\NotInScriptModeException; | ||||
| use FML\Script\Features\KeyAction; | ||||
|  | ||||
|  | ||||
| /** | ||||
| @@ -314,12 +315,17 @@ class CustomVotesPlugin implements CommandListener, CallbackListener, ManialinkP | ||||
| 			switch($voteName) { | ||||
| 				case 'teambalance': | ||||
| 					$this->maniaControl->client->autoTeamBalance(); | ||||
| <<<<<<< HEAD | ||||
| 					$this->maniaControl->chat->sendInformation('$f8fVote to $fffbalance the teams$f8f has been successfull!'); | ||||
| ======= | ||||
| 					$this->maniaControl->chat->sendInformation('$s$f8fVote to $fffbalance the teams$f8f was successful!'); | ||||
| >>>>>>> aa6357d... added custom voting with f1 & f2 | ||||
| 					break; | ||||
| 				case 'skipmap': | ||||
| 				case 'skip': | ||||
| 				case 'nextmap': | ||||
| 					$this->maniaControl->client->nextMap(); | ||||
| <<<<<<< HEAD | ||||
| 					$this->maniaControl->chat->sendInformation('$f8fVote to $fffskip the map$f8f has been successfull!'); | ||||
| 					break; | ||||
| 				case 'restartmap': | ||||
| @@ -333,6 +339,21 @@ class CustomVotesPlugin implements CommandListener, CallbackListener, ManialinkP | ||||
| 				case 'replay': | ||||
| 					$this->maniaControl->mapManager->mapQueue->addFirstMapToMapQueue($this->currentVote->voter, $this->maniaControl->mapManager->getCurrentMap()); | ||||
| 					$this->maniaControl->chat->sendInformation('$f8fVote to $fffreplay the map$f8f has been successfull!'); | ||||
| ======= | ||||
| 					$this->maniaControl->chat->sendInformation('$s$f8fVote to $fffskip the map$f8f was successful!'); | ||||
| 					break; | ||||
| 				case 'restartmap': | ||||
| 					$this->maniaControl->client->restartMap(); | ||||
| 					$this->maniaControl->chat->sendInformation('$s$f8fVote to $fffrestart the map$f8f was successful!'); | ||||
| 					break; | ||||
| 				case 'pausegame': | ||||
| 					$this->maniaControl->client->sendModeScriptCommands(array('Command_ForceWarmUp' => True)); | ||||
| 					$this->maniaControl->chat->sendInformation('$s$f8fVote to $fffpause the current game$f8f was successful!'); | ||||
| 					break; | ||||
| 				case 'replay': | ||||
| 					$this->maniaControl->mapManager->mapQueue->addFirstMapToMapQueue($this->currentVote->voter, $this->maniaControl->mapManager->getCurrentMap()); | ||||
| 					$this->maniaControl->chat->sendInformation('$s$f8fVote to $fffreplay the map$f8f was successful!'); | ||||
| >>>>>>> aa6357d... added custom voting with f1 & f2 | ||||
| 					break; | ||||
| 			} | ||||
| 		} else { | ||||
| @@ -532,9 +553,6 @@ class CustomVotesPlugin implements CommandListener, CallbackListener, ManialinkP | ||||
|  | ||||
| 		$maniaLink = new ManiaLink(self::MLID_WIDGET); | ||||
|  | ||||
| 		//$script    = new Script(); | ||||
| 		//$maniaLink->setScript($script); | ||||
|  | ||||
| 		// mainframe | ||||
| 		$frame = new Frame(); | ||||
| 		$maniaLink->add($frame); | ||||
| @@ -638,6 +656,13 @@ class CustomVotesPlugin implements CommandListener, CallbackListener, ManialinkP | ||||
| 		$label->setX($width / 2 - 6); | ||||
| 		$label->setTextColor("F00"); | ||||
| 		$label->setText("F6"); | ||||
| 		 | ||||
| 		// Key Action | ||||
| 		$script = $maniaLink->getScript(); | ||||
| 		$keyActionPositive = new KeyAction(self::ACTION_POSITIVE_VOTE, 'F1'); | ||||
| 		$script->addFeature($keyActionPositive); | ||||
| 		$keyActionNegative = new KeyAction(self::ACTION_NEGATIVE_VOTE, 'F2'); | ||||
| 		$script->addFeature($keyActionNegative); | ||||
|  | ||||
| 		// Send manialink | ||||
| 		$this->maniaControl->manialinkManager->sendManialink($maniaLink); | ||||
| @@ -731,6 +756,7 @@ class CustomVotesPlugin implements CommandListener, CallbackListener, ManialinkP | ||||
| 				$x -= $itemSize * 1.05; | ||||
|  | ||||
| 				if ($menuItem[1]) { | ||||
| 						$menuQuad->removeScriptFeatures(); | ||||
| 					$description = '$s' . $menuItem[1]; | ||||
|                     $menuQuad->addTooltipLabelFeature($descriptionLabel, $description); | ||||
| 				} | ||||
|   | ||||
		Reference in New Issue
	
	Block a user