setSoundName($soundName); $this->setControl($control); $this->setVariant($variant); $this->setLabelName($labelName); } /** * Set the Sound to play * * @param string $soundName Sound Name * @return \FML\Script\Features\UISound */ public function setSoundName($soundName) { $this->soundName = (string) $soundName; return $this; } /** * Set the Control * * @param Control $control Action Control * @return \FML\Script\Features\UISound */ public function setControl(Control $control) { $control->checkId(); $control->setScriptEvents(true); $this->control = $control; return $this; } /** * Set the Sound Variant * * @param int $variant Sound Variant * @return \FML\Script\Features\UISound */ public function setVariant($variant) { $this->variant = (int) $variant; return $this; } /** * Set the Volume * * @param float $volume Sound Volume * @return \FML\Script\Features\UISound */ public function setVolume($volume) { $this->volume = (float) $volume; return $this; } /** * Set the Label Name * * @param string $labelName Script Label Name * @return \FML\Script\Features\UISound */ public function setLabelName($labelName) { $this->labelName = (string) $labelName; return $this; } /** * * @see \FML\Script\Features\ScriptFeature::prepare() */ public function prepare(Script $script) { $script->appendGenericScriptLabel($this->labelName, $this->getScriptText()); return $this; } /** * Get the Script Text * * @return string */ protected function getScriptText() { if ($this->control) { // Control event $controlId = Builder::escapeText($this->control->getId()); $scriptText = " if (Event.Control.ControlId == \"{$controlId}\") { PlayUiSound(CMlScriptIngame::EUISound::{$this->soundName}, {$this->variant}, {$this->volume}); }"; } else { // Other $scriptText = " PlayUiSound(CMlScriptIngame::EUISound::{$this->soundName}, {$this->variant}, {$this->volume});"; } return $scriptText; } }