fml update

This commit is contained in:
Steffen Schröder 2014-01-05 17:19:44 +01:00
parent b10575d4f2
commit 3c784505d2
2 changed files with 99 additions and 68 deletions

View File

@ -7,7 +7,7 @@ namespace FML\Script;
* *
* @author steeffeen * @author steeffeen
*/ */
class UISound { abstract class EUISound {
/** /**
* Constants * Constants
*/ */
@ -40,24 +40,4 @@ class UISound {
const SOUND_TimeOut = 'TimeOut'; const SOUND_TimeOut = 'TimeOut';
const SOUND_VictoryPoint = 'VictoryPoint'; const SOUND_VictoryPoint = 'VictoryPoint';
const SOUND_Warning = 'Warning'; 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;
}
} }

View File

@ -24,7 +24,9 @@ class Script {
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 CLASS_SOUND = 'FML_Sound';
const OPTION_TOOLTIP_ONCLICK = 'FML_Tooltip_OnClick'; const CLASS_TOGGLE = 'FML_Toggle';
const CLASS_SHOW = 'FML_Show';
const CLASS_HIDE = 'FML_Hide';
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';
const OPTION_TOOLTIP_TEXT = 'FML_Tooltip_Text'; const OPTION_TOOLTIP_TEXT = 'FML_Tooltip_Text';
@ -37,6 +39,7 @@ class Script {
const LABEL_MOUSEOVER = 'MouseOver'; const LABEL_MOUSEOVER = 'MouseOver';
const CONSTANT_TOOLTIPTEXTS = 'C_FML_TooltipTexts'; const CONSTANT_TOOLTIPTEXTS = 'C_FML_TooltipTexts';
const FUNCTION_SETTOOLTIPTEXT = 'FML_SetTooltipText'; const FUNCTION_SETTOOLTIPTEXT = 'FML_SetTooltipText';
const FUNCTION_TOGGLE = 'FML_Toggle';
/** /**
* Protected Properties * Protected Properties
@ -52,6 +55,7 @@ class Script {
protected $profile = false; protected $profile = false;
protected $mapInfo = false; protected $mapInfo = false;
protected $sounds = array(); protected $sounds = array();
protected $toggles = false;
/** /**
* Set an Include of the Script * Set an Include of the Script
@ -255,11 +259,13 @@ class Script {
* Add a Sound Playing for the Control * Add a Sound Playing for the Control
* *
* @param Control $control * @param Control $control
* @param UISound $sound * @param string $soundName
* @param int $soundVariant
* @param float $soundVolume
* @param string $eventLabel * @param string $eventLabel
* @return \FML\Script\Script * @return \FML\Script\Script
*/ */
public function addSound(Control $control, UISound $sound, $eventLabel = self::LABEL_MOUSECLICK) { public function addSound(Control $control, $soundName, $soundVariant = 0, $soundVolume = 1., $eventLabel = self::LABEL_MOUSECLICK) {
if (!($control instanceof Scriptable)) { if (!($control instanceof Scriptable)) {
trigger_error('Scriptable Control needed as ClickControl for Sounds!'); trigger_error('Scriptable Control needed as ClickControl for Sounds!');
return $this; return $this;
@ -268,13 +274,37 @@ class Script {
$control->checkId(); $control->checkId();
$control->addClass(self::CLASS_SOUND); $control->addClass(self::CLASS_SOUND);
$soundData = array(); $soundData = array();
$soundData['sound'] = $sound; $soundData['soundName'] = $soundName;
$soundData['id'] = $control->getId(); $soundData['soundVariant'] = $soundVariant;
$soundData['label'] = $eventLabel; $soundData['soundVolume'] = $soundVolume;
$soundData['controlId'] = $control->getId();
$soundData['eventLabel'] = $eventLabel;
array_push($this->sounds, $soundData); array_push($this->sounds, $soundData);
return $this; return $this;
} }
/**
* Add a Toggling Behavior
*
* @param Control $clickControl
* @param Control $toggleControl
* @param string $mode
* @return \FML\Script\Script
*/
public function addToggle(Control $clickControl, Control $toggleControl, $mode = self::CLASS_TOGGLE) {
if (!($clickControl instanceof Scriptable)) {
trigger_error('Scriptable Control needed as ClickControl for Toggles!');
return $this;
}
$toggleControl->checkId();
$clickControl->setScriptEvents(true);
$clickControl->addClass(self::CLASS_TOGGLE);
$clickControl->addClass($mode);
$clickControl->addClass($toggleControl->getId());
$this->toggles = true;
return $this;
}
/** /**
* Create the Script XML Tag * Create the Script XML Tag
* *
@ -306,6 +336,7 @@ class Script {
$scriptText .= $this->getProfileLabels(); $scriptText .= $this->getProfileLabels();
$scriptText .= $this->getMapInfoLabels(); $scriptText .= $this->getMapInfoLabels();
$scriptText .= $this->getSoundLabels(); $scriptText .= $this->getSoundLabels();
$scriptText .= $this->getToggleLabels();
$scriptText .= $this->getMainFunction(); $scriptText .= $this->getMainFunction();
return $scriptText; return $scriptText;
} }
@ -423,29 +454,25 @@ Void " . self::FUNCTION_SETTOOLTIPTEXT . "(CMlControl _TooltipControl, CMlContro
if (!$this->tooltips) return ""; if (!$this->tooltips) return "";
$mouseOverScript = " $mouseOverScript = "
if (Event.Control.HasClass(\"" . self::CLASS_TOOLTIPS . "\")) { if (Event.Control.HasClass(\"" . self::CLASS_TOOLTIPS . "\")) {
if (!Event.Control.HasClass(\"" . self::OPTION_TOOLTIP_ONCLICK . "\")) { declare Invert = Event.Control.HasClass(\"" . self::OPTION_TOOLTIP_INVERT . "\");
declare Invert = Event.Control.HasClass(\"" . self::OPTION_TOOLTIP_INVERT . "\"); foreach (ControlClass in Event.Control.ControlClasses) {
foreach (ControlClass in Event.Control.ControlClasses) { declare TooltipControl <=> Page.GetFirstChild(ControlClass);
declare TooltipControl <=> Page.GetFirstChild(ControlClass); if (TooltipControl == Null) continue;
if (TooltipControl == Null) continue; TooltipControl.Visible = !Invert;
TooltipControl.Visible = !Invert; " . self::FUNCTION_SETTOOLTIPTEXT . "(TooltipControl, Event.Control);
" . self::FUNCTION_SETTOOLTIPTEXT . "(TooltipControl, Event.Control);
}
} }
}"; }";
$mouseOutScript = " $mouseOutScript = "
if (Event.Control.HasClass(\"" . self::CLASS_TOOLTIPS . "\")) { if (Event.Control.HasClass(\"" . self::CLASS_TOOLTIPS . "\")) {
if (!Event.Control.HasClass(\"" . self::OPTION_TOOLTIP_ONCLICK . "\")) { declare FML_Clicked for Event.Control = False;
declare FML_Clicked for Event.Control = False; declare StayOnClick = Event.Control.HasClass(\"" . self::OPTION_TOOLTIP_STAYONCLICK . "\");
declare StayOnClick = Event.Control.HasClass(\"" . self::OPTION_TOOLTIP_STAYONCLICK . "\"); if (!StayOnClick || !FML_Clicked) {
if (!StayOnClick || !FML_Clicked) { declare Invert = Event.Control.HasClass(\"" . self::OPTION_TOOLTIP_INVERT . "\");
declare Invert = Event.Control.HasClass(\"" . self::OPTION_TOOLTIP_INVERT . "\"); foreach (ControlClass in Event.Control.ControlClasses) {
foreach (ControlClass in Event.Control.ControlClasses) { declare TooltipControl <=> Page.GetFirstChild(ControlClass);
declare TooltipControl <=> Page.GetFirstChild(ControlClass); if (TooltipControl == Null) continue;
if (TooltipControl == Null) continue; TooltipControl.Visible = Invert;
TooltipControl.Visible = Invert; " . self::FUNCTION_SETTOOLTIPTEXT . "(TooltipControl, Event.Control);
" . self::FUNCTION_SETTOOLTIPTEXT . "(TooltipControl, Event.Control);
}
} }
} }
}"; }";
@ -453,27 +480,23 @@ if (Event.Control.HasClass(\"" . self::CLASS_TOOLTIPS . "\")) {
if (Event.Control.HasClass(\"" . self::CLASS_TOOLTIPS . "\")) { if (Event.Control.HasClass(\"" . self::CLASS_TOOLTIPS . "\")) {
declare Handle = True; declare Handle = True;
declare Show = False; declare Show = False;
declare OnClick = Event.Control.HasClass(\"" . self::OPTION_TOOLTIP_ONCLICK . "\"); declare StayOnClick = Event.Control.HasClass(\"" . self::OPTION_TOOLTIP_STAYONCLICK . "\");
if (!OnClick) { if (StayOnClick) {
declare StayOnClick = Event.Control.HasClass(\"" . self::OPTION_TOOLTIP_STAYONCLICK . "\"); declare FML_Clicked for Event.Control = False;
if (StayOnClick) { FML_Clicked = !FML_Clicked;
declare FML_Clicked for Event.Control = False; if (FML_Clicked) {
FML_Clicked = !FML_Clicked;
if (FML_Clicked) {
Handle = False;
} else {
Show = False;
}
} else {
Handle = False; Handle = False;
} else {
Show = False;
} }
} else {
Handle = False;
} }
if (Handle) { if (Handle) {
declare Invert = Event.Control.HasClass(\"" . self::OPTION_TOOLTIP_INVERT . "\"); declare Invert = Event.Control.HasClass(\"" . self::OPTION_TOOLTIP_INVERT . "\");
foreach (ControlClass in Event.Control.ControlClasses) { foreach (ControlClass in Event.Control.ControlClasses) {
declare TooltipControl <=> Page.GetFirstChild(ControlClass); declare TooltipControl <=> Page.GetFirstChild(ControlClass);
if (TooltipControl == Null) continue; if (TooltipControl == Null) continue;
if (OnClick) Show = !TooltipControl.Visible;
TooltipControl.Visible = Show && !Invert; TooltipControl.Visible = Show && !Invert;
" . self::FUNCTION_SETTOOLTIPTEXT . "(TooltipControl, Event.Control); " . self::FUNCTION_SETTOOLTIPTEXT . "(TooltipControl, Event.Control);
} }
@ -638,18 +661,15 @@ if (Event.Control.HasClass(\"" . self::CLASS_MAPINFO . "\")) {
if (!$this->sounds) return ''; if (!$this->sounds) return '';
$labelScripts = array(); $labelScripts = array();
foreach ($this->sounds as $soundData) { foreach ($this->sounds as $soundData) {
$controlId = $soundData['id']; $volume = Builder::getReal($soundData['soundVolume']);
$label = $soundData['label'];
$sound = $soundData['sound'];
$volume = Builder::getReal($sound->volume);
$labelScript = " $labelScript = "
case \"{$controlId}\": { case \"{$soundData['controlId']}\": {
PlayUiSound(CMlScriptIngame::EUISound::{$sound->name}, {$sound->variant}, {$volume}); PlayUiSound(CMlScriptIngame::EUISound::{$soundData['soundName']}, {$soundData['soundVariant']}, {$volume});
}"; }";
if (!isset($labelScripts[$label])) { if (!isset($labelScripts[$soundData['eventLabel']])) {
$labelScripts[$label] = ''; $labelScripts[$soundData['eventLabel']] = '';
} }
$labelScripts[$label] .= $labelScript; $labelScripts[$soundData['eventLabel']] .= $labelScript;
} }
$soundScript = ''; $soundScript = '';
@ -665,6 +685,37 @@ if (Event.Control.HasClass(\"" . self::CLASS_SOUND . "\")) {
return $soundScript; return $soundScript;
} }
/**
* Get the Toggle Labels
*
* @return string
*/
private function getToggleLabels() {
if (!$this->toggles) return '';
$toggleScript = "
if (Event.Control.HasClass(\"" . self::CLASS_TOGGLE . "\")) {
declare HasShow = Event.Control.HasClass(\"" . self::CLASS_SHOW . "\");
declare HasHide = Event.Control.HasClass(\"" . self::CLASS_HIDE . "\");
declare Toggle = True;
declare Show = True;
if (HasShow || HasHide) {
Toggle = False;
Show = HasShow;
}
foreach (ControlClass in Event.Control.ControlClasses) {
declare ToggleControl <=> Page.GetFirstChild(ControlClass);
if (ToggleControl == Null) continue;
if (Toggle) {
ToggleControl.Visible = !ToggleControl.Visible;
} else {
ToggleControl.Visible = Show;
}
}
}";
$toggleScript = Builder::getLabelImplementationBlock(self::LABEL_MOUSECLICK, $toggleScript);
return $toggleScript;
}
/** /**
* Get the Main Function * Get the Main Function
* *