diff --git a/application/core/Libs/FML/Script/Features/KeyAction.php b/application/core/Libs/FML/Script/Features/KeyAction.php new file mode 100644 index 00000000..c45b1d61 --- /dev/null +++ b/application/core/Libs/FML/Script/Features/KeyAction.php @@ -0,0 +1,118 @@ +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; + } +} diff --git a/application/plugins/CustomVotes.php b/application/plugins/CustomVotes.php index 5e62b95a..22cdc078 100644 --- a/application/plugins/CustomVotes.php +++ b/application/plugins/CustomVotes.php @@ -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); }