From b10575d4f29a91a47c2a4d604485cde65a2072be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steffen=20Schro=CC=88der?= Date: Sun, 5 Jan 2014 16:04:55 +0100 Subject: [PATCH] fml sound feature --- .../core/Configurators/Configurator.php | 2 +- application/core/FML/ManiaLink.php | 40 +++++----- application/core/FML/Script/Builder.php | 13 ++++ application/core/FML/Script/Script.php | 73 +++++++++++++++++-- application/core/FML/Script/UISound.php | 63 ++++++++++++++++ 5 files changed, 168 insertions(+), 23 deletions(-) create mode 100644 application/core/FML/Script/UISound.php diff --git a/application/core/Configurators/Configurator.php b/application/core/Configurators/Configurator.php index bc23186d..204f8080 100644 --- a/application/core/Configurators/Configurator.php +++ b/application/core/Configurators/Configurator.php @@ -307,6 +307,6 @@ class Configurator implements CallbackListener, CommandListener, ManialinkPageAn $itemQuad = new Quad_UIConstruction_Buttons(); $itemQuad->setSubStyle($itemQuad::SUBSTYLE_Tools); $itemQuad->setAction(self::ACTION_TOGGLEMENU); - $this->maniaControl->actionsMenu->addAdminMenuItem($itemQuad,20,'Settings'); + $this->maniaControl->actionsMenu->addAdminMenuItem($itemQuad, 20, 'Settings'); } } diff --git a/application/core/FML/ManiaLink.php b/application/core/FML/ManiaLink.php index bb34ced3..a25f1fb2 100644 --- a/application/core/FML/ManiaLink.php +++ b/application/core/FML/ManiaLink.php @@ -28,8 +28,7 @@ class ManiaLink implements Container { /** * Construct a new Manialink * - * @param string $id - * Manialink Id + * @param string $id Manialink Id */ public function __construct($id = null) { if ($id !== null) { @@ -40,8 +39,7 @@ class ManiaLink implements Container { /** * Set XML Encoding * - * @param string $encoding - * XML Encoding + * @param string $encoding XML Encoding * @return \FML\ManiaLink */ public function setXmlEncoding($encoding) { @@ -52,8 +50,7 @@ class ManiaLink implements Container { /** * Set Manialink Id * - * @param string $id - * Manialink Id + * @param string $id Manialink Id * @return \FML\ManiaLink */ public function setId($id) { @@ -64,8 +61,7 @@ class ManiaLink implements Container { /** * Set Background * - * @param string $background - * Background Value + * @param string $background Background Value * @return \FML\ManiaLink */ public function setBackground($background) { @@ -76,8 +72,7 @@ class ManiaLink implements Container { /** * Set Navigable3d * - * @param bool $navigable3d - * If the manialink is 3d navigable + * @param bool $navigable3d If the manialink is 3d navigable * @return \FML\ManiaLink */ public function setNavigable3d($navigable3d) { @@ -88,8 +83,7 @@ class ManiaLink implements Container { /** * Set Timeout * - * @param int $timeout - * Timeout Duration + * @param int $timeout Timeout Duration * @return \FML\ManiaLink */ public function setTimeout($timeout) { @@ -118,9 +112,9 @@ class ManiaLink implements Container { } /** - * Set the script object of the Manialink + * Set the Script of the ManiaLink * - * @param Script $script + * @param Script $script * @return \FML\ManiaLink */ public function setScript(Script $script) { @@ -128,12 +122,24 @@ class ManiaLink implements Container { return $this; } + /** + * Get the current Script of the ManiaLink + * + * @param string $createIfEmpty + * @return \FML\Script\Script + */ + public function getScript($createIfEmpty = true) { + if (!$this->script && $createIfEmpty) { + $this->script = new Script(); + } + return $this->script; + } + /** * Render the XML Document * - * @param bool $echo - * If the xml should be echoed and the content-type header should be set - * @param \DOMDocument $domDocument + * @param bool $echo If the xml should be echoed and the content-type header should be set + * @param \DOMDocument $domDocument * @return \DOMDocument */ public function render($echo = false, $domDocument = null) { diff --git a/application/core/FML/Script/Builder.php b/application/core/FML/Script/Builder.php index d96f7bcb..57c4245b 100644 --- a/application/core/FML/Script/Builder.php +++ b/application/core/FML/Script/Builder.php @@ -20,4 +20,17 @@ abstract class Builder { $labelText = PHP_EOL . "***{$labelName}***" . PHP_EOL . "***{$implementationCode}***" . PHP_EOL; return $labelText; } + + /** + * Get the Real String-Representation of the given Value + * + * @param float $value + * @return string + */ + public static function getReal($value) { + $value = (float) $value; + $stringVal = (string) $value; + if (!fmod($value, 1)) $stringVal .= '.'; + return $stringVal; + } } diff --git a/application/core/FML/Script/Script.php b/application/core/FML/Script/Script.php index 74b25ef8..283aa87b 100644 --- a/application/core/FML/Script/Script.php +++ b/application/core/FML/Script/Script.php @@ -23,6 +23,7 @@ class Script { const CLASS_PAGELABEL = 'FML_PageLabel'; const CLASS_PROFILE = 'FML_Profile'; const CLASS_MAPINFO = 'FML_MapInfo'; + const CLASS_SOUND = 'FML_Sound'; const OPTION_TOOLTIP_ONCLICK = 'FML_Tooltip_OnClick'; const OPTION_TOOLTIP_STAYONCLICK = 'FML_Tooltip_StayOnClick'; const OPTION_TOOLTIP_INVERT = 'FML_Tooltip_Invert'; @@ -50,6 +51,7 @@ class Script { protected $pages = false; protected $profile = false; protected $mapInfo = false; + protected $sounds = array(); /** * Set an Include of the Script @@ -249,6 +251,30 @@ class Script { return $this; } + /** + * Add a Sound Playing for the Control + * + * @param Control $control + * @param UISound $sound + * @param string $eventLabel + * @return \FML\Script\Script + */ + public function addSound(Control $control, UISound $sound, $eventLabel = self::LABEL_MOUSECLICK) { + if (!($control instanceof Scriptable)) { + trigger_error('Scriptable Control needed as ClickControl for Sounds!'); + return $this; + } + $control->setScriptEvents(true); + $control->checkId(); + $control->addClass(self::CLASS_SOUND); + $soundData = array(); + $soundData['sound'] = $sound; + $soundData['id'] = $control->getId(); + $soundData['label'] = $eventLabel; + array_push($this->sounds, $soundData); + return $this; + } + /** * Create the Script XML Tag * @@ -279,6 +305,7 @@ class Script { $scriptText .= $this->getPagesLabels(); $scriptText .= $this->getProfileLabels(); $scriptText .= $this->getMapInfoLabels(); + $scriptText .= $this->getSoundLabels(); $scriptText .= $this->getMainFunction(); return $scriptText; } @@ -330,13 +357,13 @@ class Script { $count = count($this->tooltipTexts); if ($count > 0) { foreach ($this->tooltipTexts as $tooltipId => $tooltipTexts) { - $constantText .= '"' . $tooltipId . '"=>['; + $constantText .= '"' . $tooltipId . '" => ['; $subIndex = 0; $subCount = count($tooltipTexts); if ($subCount > 0) { foreach ($tooltipTexts as $hoverId => $text) { - $constantText .= '"' . $hoverId . '"=>"' . $text . '"'; - if ($subIndex < $subCount - 1) $constantText .= ','; + $constantText .= '"' . $hoverId . '" => "' . $text . '"'; + if ($subIndex < $subCount - 1) $constantText .= ', '; $subIndex++; } } @@ -344,12 +371,12 @@ class Script { $constantText .= '""'; } $constantText .= ']'; - if ($index < $count - 1) $constantText .= ','; + if ($index < $count - 1) $constantText .= ', '; $index++; } } else { - $constantText .= '""=>[""=>""]'; + $constantText .= '"" => ["" => ""]'; } $constantText .= ']'; $this->setConstant(self::CONSTANT_TOOLTIPTEXTS, $constantText); @@ -602,6 +629,42 @@ if (Event.Control.HasClass(\"" . self::CLASS_MAPINFO . "\")) { return $mapInfoLabels; } + /** + * Get the Sound Labels + * + * @return string + */ + private function getSoundLabels() { + if (!$this->sounds) return ''; + $labelScripts = array(); + foreach ($this->sounds as $soundData) { + $controlId = $soundData['id']; + $label = $soundData['label']; + $sound = $soundData['sound']; + $volume = Builder::getReal($sound->volume); + $labelScript = " + case \"{$controlId}\": { + PlayUiSound(CMlScriptIngame::EUISound::{$sound->name}, {$sound->variant}, {$volume}); + }"; + if (!isset($labelScripts[$label])) { + $labelScripts[$label] = ''; + } + $labelScripts[$label] .= $labelScript; + } + + $soundScript = ''; + foreach ($labelScripts as $label => $scriptPart) { + $labelScript = " +if (Event.Control.HasClass(\"" . self::CLASS_SOUND . "\")) { + switch (Event.Control.ControlId) { + {$scriptPart} + } +}"; + $soundScript .= Builder::getLabelImplementationBlock($label, $labelScript); + } + return $soundScript; + } + /** * Get the Main Function * diff --git a/application/core/FML/Script/UISound.php b/application/core/FML/Script/UISound.php new file mode 100644 index 00000000..349969bf --- /dev/null +++ b/application/core/FML/Script/UISound.php @@ -0,0 +1,63 @@ +name = $name; + $this->variant = $variant; + $this->volume = $volume; + } +}