fml sound feature

This commit is contained in:
Steffen Schröder 2014-01-05 16:04:55 +01:00
parent 417e460588
commit b10575d4f2
5 changed files with 168 additions and 23 deletions

View File

@ -28,8 +28,7 @@ class ManiaLink implements Container {
/** /**
* Construct a new Manialink * Construct a new Manialink
* *
* @param string $id * @param string $id Manialink Id
* Manialink Id
*/ */
public function __construct($id = null) { public function __construct($id = null) {
if ($id !== null) { if ($id !== null) {
@ -40,8 +39,7 @@ class ManiaLink implements Container {
/** /**
* Set XML Encoding * Set XML Encoding
* *
* @param string $encoding * @param string $encoding XML Encoding
* XML Encoding
* @return \FML\ManiaLink * @return \FML\ManiaLink
*/ */
public function setXmlEncoding($encoding) { public function setXmlEncoding($encoding) {
@ -52,8 +50,7 @@ class ManiaLink implements Container {
/** /**
* Set Manialink Id * Set Manialink Id
* *
* @param string $id * @param string $id Manialink Id
* Manialink Id
* @return \FML\ManiaLink * @return \FML\ManiaLink
*/ */
public function setId($id) { public function setId($id) {
@ -64,8 +61,7 @@ class ManiaLink implements Container {
/** /**
* Set Background * Set Background
* *
* @param string $background * @param string $background Background Value
* Background Value
* @return \FML\ManiaLink * @return \FML\ManiaLink
*/ */
public function setBackground($background) { public function setBackground($background) {
@ -76,8 +72,7 @@ class ManiaLink implements Container {
/** /**
* Set Navigable3d * Set Navigable3d
* *
* @param bool $navigable3d * @param bool $navigable3d If the manialink is 3d navigable
* If the manialink is 3d navigable
* @return \FML\ManiaLink * @return \FML\ManiaLink
*/ */
public function setNavigable3d($navigable3d) { public function setNavigable3d($navigable3d) {
@ -88,8 +83,7 @@ class ManiaLink implements Container {
/** /**
* Set Timeout * Set Timeout
* *
* @param int $timeout * @param int $timeout Timeout Duration
* Timeout Duration
* @return \FML\ManiaLink * @return \FML\ManiaLink
*/ */
public function setTimeout($timeout) { public function setTimeout($timeout) {
@ -118,7 +112,7 @@ 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 * @return \FML\ManiaLink
@ -128,11 +122,23 @@ class ManiaLink implements Container {
return $this; 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 * Render the XML Document
* *
* @param bool $echo * @param bool $echo If the xml should be echoed and the content-type header should be set
* If the xml should be echoed and the content-type header should be set
* @param \DOMDocument $domDocument * @param \DOMDocument $domDocument
* @return \DOMDocument * @return \DOMDocument
*/ */

View File

@ -20,4 +20,17 @@ abstract class Builder {
$labelText = PHP_EOL . "***{$labelName}***" . PHP_EOL . "***{$implementationCode}***" . PHP_EOL; $labelText = PHP_EOL . "***{$labelName}***" . PHP_EOL . "***{$implementationCode}***" . PHP_EOL;
return $labelText; 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;
}
} }

View File

@ -23,6 +23,7 @@ class Script {
const CLASS_PAGELABEL = 'FML_PageLabel'; const CLASS_PAGELABEL = 'FML_PageLabel';
const CLASS_PROFILE = 'FML_Profile'; const CLASS_PROFILE = 'FML_Profile';
const CLASS_MAPINFO = 'FML_MapInfo'; const CLASS_MAPINFO = 'FML_MapInfo';
const CLASS_SOUND = 'FML_Sound';
const OPTION_TOOLTIP_ONCLICK = 'FML_Tooltip_OnClick'; const OPTION_TOOLTIP_ONCLICK = 'FML_Tooltip_OnClick';
const OPTION_TOOLTIP_STAYONCLICK = 'FML_Tooltip_StayOnClick'; const OPTION_TOOLTIP_STAYONCLICK = 'FML_Tooltip_StayOnClick';
const OPTION_TOOLTIP_INVERT = 'FML_Tooltip_Invert'; const OPTION_TOOLTIP_INVERT = 'FML_Tooltip_Invert';
@ -50,6 +51,7 @@ class Script {
protected $pages = false; protected $pages = false;
protected $profile = false; protected $profile = false;
protected $mapInfo = false; protected $mapInfo = false;
protected $sounds = array();
/** /**
* Set an Include of the Script * Set an Include of the Script
@ -249,6 +251,30 @@ class Script {
return $this; 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 * Create the Script XML Tag
* *
@ -279,6 +305,7 @@ class Script {
$scriptText .= $this->getPagesLabels(); $scriptText .= $this->getPagesLabels();
$scriptText .= $this->getProfileLabels(); $scriptText .= $this->getProfileLabels();
$scriptText .= $this->getMapInfoLabels(); $scriptText .= $this->getMapInfoLabels();
$scriptText .= $this->getSoundLabels();
$scriptText .= $this->getMainFunction(); $scriptText .= $this->getMainFunction();
return $scriptText; return $scriptText;
} }
@ -602,6 +629,42 @@ if (Event.Control.HasClass(\"" . self::CLASS_MAPINFO . "\")) {
return $mapInfoLabels; 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 * Get the Main Function
* *

View File

@ -0,0 +1,63 @@
<?php
namespace FML\Script;
/**
* Class for EUISound Variants
*
* @author steeffeen
*/
class UISound {
/**
* Constants
*/
const SOUND_Bonus = 'Bonus';
const SOUND_Capture = 'Capture';
const SOUND_Checkpoint = 'Checkpoint';
const SOUND_Combo = 'Combo';
const SOUND_Custom1 = 'Custom1';
const SOUND_Custom2 = 'Custom2';
const SOUND_Custom3 = 'Custom3';
const SOUND_Custom4 = 'Custom4';
const SOUND_Default = 'Default';
const SOUND_EndMatch = 'EndMatch';
const SOUND_EndRound = 'EndRound';
const SOUND_Finish = 'Finish';
const SOUND_FirstHit = 'FirstHit';
const SOUND_Notice = 'Notice';
const SOUND_PhaseChange = 'PhaseChange';
const SOUND_PlayerEliminated = 'PlayerEliminated';
const SOUND_PlayerHit = 'PlayerHit';
const SOUND_PlayersRemaining = 'PlayersRemaining';
const SOUND_RankChange = 'RankChange';
const SOUND_Record = 'Record';
const SOUND_ScoreProgress = 'ScoreProgress';
const SOUND_Silence = 'Silence';
const SOUND_StartMatch = 'StartMatch';
const SOUND_StartRound = 'StartRound';
const SOUND_TieBreakPoint = 'TieBreakPoint';
const SOUND_TiePoint = 'TiePoint';
const SOUND_TimeOut = 'TimeOut';
const SOUND_VictoryPoint = 'VictoryPoint';
const SOUND_Warning = 'Warning';
/**
* Public Properties
*/
public $name = self::SOUND_Default;
public $variant = 0;
public $volume = 1.;
/**
* Create a new EUISound Instance
*
* @param string $name
* @param int $variant
* @param real $volume
*/
public function __construct($name = self::SOUND_Default, $variant = 0, $volume = 1.) {
$this->name = $name;
$this->variant = $variant;
$this->volume = $volume;
}
}