FML Update

This commit is contained in:
Steffen Schröder 2014-01-03 17:18:14 +01:00
parent ad1455bf5a
commit 985feb398e
8 changed files with 1057 additions and 862 deletions

View File

@ -62,7 +62,7 @@ class Label extends Control implements Actionable, Linkable, NewLineable, Script
* Set Text Prefix * Set Text Prefix
* *
* @param string $textPrefix * @param string $textPrefix
* Text Pefix * Text Prefix
* @return \FML\Controls\Label * @return \FML\Controls\Label
*/ */
public function setTextPrefix($textPrefix) { public function setTextPrefix($textPrefix) {

View File

@ -14,12 +14,12 @@ class ManiaLinks {
protected $encoding = 'utf-8'; protected $encoding = 'utf-8';
protected $tagName = 'manialinks'; protected $tagName = 'manialinks';
protected $children = array(); protected $children = array();
protected $customUI = null;
/** /**
* Set XML Encoding * Set XML Encoding
* *
* @param string $encoding * @param string $encoding XML Encoding
* XML Encoding
* @return \FML\ManiaLinks * @return \FML\ManiaLinks
*/ */
public function setXmlEncoding($encoding) { public function setXmlEncoding($encoding) {
@ -30,8 +30,7 @@ class ManiaLinks {
/** /**
* Add a Child Manialink * Add a Child Manialink
* *
* @param ManiaLink $child * @param ManiaLink $child Child Manialink
* Child Manialink
* @return \FML\ManiaLinks * @return \FML\ManiaLinks
*/ */
public function add(ManiaLink $child) { public function add(ManiaLink $child) {
@ -51,11 +50,21 @@ class ManiaLinks {
return $this; return $this;
} }
/**
* Set the CustomUI
*
* @param CustomUI $customUI The CustomUI Object
* @return \FML\ManiaLinks
*/
public function setCustomUI(CustomUI $customUI) {
$this->customUI = $customUI;
return $this;
}
/** /**
* 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
* @return \DOMDocument * @return \DOMDocument
*/ */
public function render($echo = false) { public function render($echo = false) {
@ -66,6 +75,10 @@ class ManiaLinks {
$childXml = $child->render(false, $domDocument); $childXml = $child->render(false, $domDocument);
$manialinks->appendChild($childXml); $manialinks->appendChild($childXml);
} }
if ($this->customUI) {
$customUIXml = $this->customUI->render($domDocument);
$manialinks->appendChild($customUIXml);
}
if ($echo) { if ($echo) {
header('Content-Type: application/xml'); header('Content-Type: application/xml');
echo $domDocument->saveXML(); echo $domDocument->saveXML();

View File

@ -15,50 +15,84 @@ class Script {
/** /**
* Constants * Constants
*/ */
const CLASS_TOOLTIPS = "FML_Tooltips"; const CLASS_TOOLTIPS = 'FML_Tooltips';
const CLASS_MENU = "FML_Menu"; const CLASS_MENU = 'FML_Menu';
const CLASS_MENUBUTTON = "FML_MenuButton"; const CLASS_MENUBUTTON = 'FML_MenuButton';
const CLASS_PAGE = "FML_Page"; const CLASS_PAGE = 'FML_Page';
const CLASS_PAGER = "FML_Pager"; const CLASS_PAGER = 'FML_Pager';
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 LABEL_ONINIT = "OnInit"; const OPTION_TOOLTIP_ONCLICK = 'FML_Tooltip_OnClick';
const LABEL_LOOP = "Loop"; const OPTION_TOOLTIP_STAYONCLICK = 'FML_Tooltip_StayOnClick';
const LABEL_ENTRYSUBMIT = "EntrySubmit"; const OPTION_TOOLTIP_INVERT = 'FML_Tooltip_Invert';
const LABEL_KEYPRESS = "KeyPress"; const OPTION_TOOLTIP_TEXT = 'FML_Tooltip_Text';
const LABEL_MOUSECLICK = "MouseClick"; const LABEL_ONINIT = 'OnInit';
const LABEL_MOUSEOUT = "MouseOut"; const LABEL_LOOP = 'Loop';
const LABEL_MOUSEOVER = "MouseOver"; const LABEL_ENTRYSUBMIT = 'EntrySubmit';
const LABEL_KEYPRESS = 'KeyPress';
const LABEL_MOUSECLICK = 'MouseClick';
const LABEL_MOUSEOUT = 'MouseOut';
const LABEL_MOUSEOVER = 'MouseOver';
const CONSTANT_TOOLTIPTEXTS = 'C_FML_TooltipTexts';
const FUNCTION_SETTOOLTIPTEXT = 'FML_SetTooltipText';
/** /**
* Protected Properties * Protected Properties
*/ */
protected $tagName = 'script'; protected $tagName = 'script';
protected $includes = array(); protected $includes = array();
protected $constants = array();
protected $functions = array();
protected $tooltips = false; protected $tooltips = false;
protected $tooltipTexts = array();
protected $menus = false; protected $menus = false;
protected $pages = false; protected $pages = false;
protected $profile = false; protected $profile = false;
protected $mapInfo = false; protected $mapInfo = false;
/** /**
* Add an Include to the Script * Set an Include of the Script
* *
* @param string $namespace * @param string $namespace
* @param string $file * @param string $file
* @return \FML\Script\Script * @return \FML\Script\Script
*/ */
public function addInclude($namespace, $file) { public function setInclude($namespace, $file) {
$this->includes[$namespace] = $file; $this->includes[$namespace] = $file;
return $this; return $this;
} }
/**
* Set a Constant of the Script
*
* @param string $name
* @param string $value
* @return \FML\Script\Script
*/
public function setConstant($name, $value) {
$this->constants[$name] = $value;
return $this;
}
/**
* Set a Function of the Script
*
* @param string $name
* @param string $coding
* @return \FML\Script\Script
*/
public function setFunction($name, $coding) {
$this->functions[$name] = $coding;
return $this;
}
/** /**
* Add a Tooltip Behavior * Add a Tooltip Behavior
* *
* @param Control $hoverControl * @param Control $hoverControl The Control that shows the Tooltip
* @param Control $tooltipControl * @param Control $tooltipControl The Tooltip to display
* @param string $options,... (optional) Unlimited Number of Tooltip Options
* @return \FML\Script\Script * @return \FML\Script\Script
*/ */
public function addTooltip(Control $hoverControl, Control $tooltipControl) { public function addTooltip(Control $hoverControl, Control $tooltipControl) {
@ -68,9 +102,30 @@ class Script {
} }
$tooltipControl->checkId(); $tooltipControl->checkId();
$tooltipControl->setVisible(false); $tooltipControl->setVisible(false);
$hoverControl->checkId();
$hoverControl->setScriptEvents(true); $hoverControl->setScriptEvents(true);
$hoverControl->addClass(self::CLASS_TOOLTIPS); $hoverControl->addClass(self::CLASS_TOOLTIPS);
$hoverControl->addClass($tooltipControl->getId()); $hoverControl->addClass($tooltipControl->getId());
$options = $this->spliceParameters(func_get_args(), 2);
foreach ($options as $option => $value) {
if ($option == self::OPTION_TOOLTIP_TEXT) {
if (!($tooltipControl instanceof Label)) {
trigger_error('Label needed for Tooltip Text Option!');
continue;
}
$hoverId = $hoverControl->getId();
$tooltipId = $tooltipControl->getId();
if (!isset($this->tooltipTexts[$tooltipId])) {
$this->tooltipTexts[$tooltipId] = array();
}
$this->tooltipTexts[$tooltipId][$hoverId] = $value;
continue;
}
if ($option == self::OPTION_TOOLTIP_INVERT) {
$tooltipControl->setVisible(true);
}
$hoverControl->addClass($option);
}
$this->tooltips = true; $this->tooltips = true;
return $this; return $this;
} }
@ -95,7 +150,7 @@ class Script {
$clickControl->setScriptEvents(true); $clickControl->setScriptEvents(true);
$clickControl->addClass(self::CLASS_MENUBUTTON); $clickControl->addClass(self::CLASS_MENUBUTTON);
$clickControl->addClass($menuId . '-' . $menuControl->getId()); $clickControl->addClass($menuId . '-' . $menuControl->getId());
$this->addInclude('TextLib', 'TextLib'); $this->setInclude('TextLib', 'TextLib');
$this->menus = true; $this->menus = true;
return $this; return $this;
} }
@ -136,7 +191,7 @@ class Script {
$pagerControl->addClass(self::CLASS_PAGER); $pagerControl->addClass(self::CLASS_PAGER);
$pagerControl->addClass(self::CLASS_PAGER . '-I' . $pagesId); $pagerControl->addClass(self::CLASS_PAGER . '-I' . $pagesId);
$pagerControl->addClass(self::CLASS_PAGER . '-A' . $pagingAction); $pagerControl->addClass(self::CLASS_PAGER . '-A' . $pagingAction);
$this->addInclude('TextLib', 'TextLib'); $this->setInclude('TextLib', 'TextLib');
$this->pages = true; $this->pages = true;
return $this; return $this;
} }
@ -172,7 +227,7 @@ class Script {
if ($playerLogin) { if ($playerLogin) {
$profileControl->addClass(self::CLASS_PROFILE . '-' . $playerLogin); $profileControl->addClass(self::CLASS_PROFILE . '-' . $playerLogin);
} }
$this->addInclude('TextLib', 'TextLib'); $this->setInclude('TextLib', 'TextLib');
$this->profile = true; $this->profile = true;
return $this; return $this;
} }
@ -217,21 +272,13 @@ class Script {
$scriptText = ""; $scriptText = "";
$scriptText .= $this->getHeaderComment(); $scriptText .= $this->getHeaderComment();
$scriptText .= $this->getIncludes(); $scriptText .= $this->getIncludes();
if ($this->tooltips) { $scriptText .= $this->getConstants();
$scriptText .= $this->getFunctions();
$scriptText .= $this->getTooltipLabels(); $scriptText .= $this->getTooltipLabels();
}
if ($this->menus) {
$scriptText .= $this->getMenuLabels(); $scriptText .= $this->getMenuLabels();
}
if ($this->pages) {
$scriptText .= $this->getPagesLabels(); $scriptText .= $this->getPagesLabels();
}
if ($this->profile) {
$scriptText .= $this->getProfileLabels(); $scriptText .= $this->getProfileLabels();
}
if ($this->mapInfo) {
$scriptText .= $this->getMapInfoLabels(); $scriptText .= $this->getMapInfoLabels();
}
$scriptText .= $this->getMainFunction(); $scriptText .= $this->getMainFunction();
return $scriptText; return $scriptText;
} }
@ -259,30 +306,133 @@ class Script {
return $includesText; return $includesText;
} }
/**
* Get the Constants
*
* @return string
*/
private function getConstants() {
$this->buildTooltipConstants();
$constantsText = PHP_EOL;
foreach ($this->constants as $name => $value) {
$constantsText .= "#Const {$name} {$value}" . PHP_EOL;
}
return $constantsText;
}
/**
* Build the Constants needed for tooltips
*/
private function buildTooltipConstants() {
if (!$this->tooltips) return;
$constantText = "[";
$index = 0;
$count = count($this->tooltipTexts);
foreach ($this->tooltipTexts as $tooltipId => $tooltipTexts) {
$constantText .= "\"{$tooltipId}\" => [";
$subIndex = 0;
$subCount = count($tooltipTexts);
foreach ($tooltipTexts as $hoverId => $text) {
$constantText .= "\"{$hoverId}\" => \"{$text}\"";
if ($subIndex < $subCount - 1) $constantText .= ", ";
$subIndex++;
}
$constantText .= "]";
if ($index < $count - 1) $constantText .= ", ";
$index++;
}
$constantText .= "]";
$this->setConstant(self::CONSTANT_TOOLTIPTEXTS, $constantText);
}
/**
* Get the Functions
*
* @return string
*/
private function getFunctions() {
$this->buildTooltipFunctions();
$functionsText = PHP_EOL;
foreach ($this->functions as $name => $coding) {
$functionsText .= $coding;
}
return $functionsText;
}
/**
* Build the Functions needed for Tooltips
*/
private function buildTooltipFunctions() {
if (!$this->tooltips) return;
$setFunctionText = "
Void " . self::FUNCTION_SETTOOLTIPTEXT . "(CMlControl _TooltipControl, CMlControl _HoverControl) {
if (!_TooltipControl.Visible) return;
declare TooltipId = _TooltipControl.ControlId;
declare HoverId = _HoverControl.ControlId;
if (!" . self::CONSTANT_TOOLTIPTEXTS . ".existskey(TooltipId)) return;
if (!" . self::CONSTANT_TOOLTIPTEXTS . "[TooltipId].existskey(HoverId)) return;
declare Label = (_TooltipControl as CMlLabel);
Label.Value = " . self::CONSTANT_TOOLTIPTEXTS . "[TooltipId][HoverId];
}";
$this->setFunction(self::FUNCTION_SETTOOLTIPTEXT, $setFunctionText);
}
/** /**
* Get the Tooltip Labels * Get the Tooltip Labels
* *
* @return string * @return string
*/ */
private function getTooltipLabels() { private function getTooltipLabels() {
if (!$this->tooltips) return "";
$mouseOverScript = " $mouseOverScript = "
if (Event.Control.HasClass(\"" . self::CLASS_TOOLTIPS . "\")) { if (!Event.Control.HasClass(\"" . self::CLASS_TOOLTIPS . "\")) break;
if (Event.Control.HasClass(\"" . self::OPTION_TOOLTIP_ONCLICK . "\")) break;
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.Show(); TooltipControl.Visible = !Invert;
} " . self::FUNCTION_SETTOOLTIPTEXT . "(TooltipControl, Event.Control);
}"; }";
$mouseOutScript = " $mouseOutScript = "
if (Event.Control.HasClass(\"" . self::CLASS_TOOLTIPS . "\")) { if (!Event.Control.HasClass(\"" . self::CLASS_TOOLTIPS . "\")) break;
declare FML_Clicked for Event.Control = False;
declare StayOnClick = Event.Control.HasClass(\"" . self::OPTION_TOOLTIP_STAYONCLICK . "\");
if (StayOnClick && FML_Clicked) break;
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.Hide(); TooltipControl.Visible = Invert;
" . self::FUNCTION_SETTOOLTIPTEXT . "(TooltipControl, Event.Control);
}";
$mouseClickScript = "
if (!Event.Control.HasClass(\"" . self::CLASS_TOOLTIPS . "\")) break;
declare Show = False;
declare OnClick = Event.Control.HasClass(\"" . self::OPTION_TOOLTIP_ONCLICK . "\");
if (OnClick) {
Show = !Event.Control.Visible;
} else {
declare StayOnClick = Event.Control.HasClass(\"" . self::OPTION_TOOLTIP_STAYONCLICK . "\");
if (StayOnClick) {
declare FML_Clicked for Event.Control = False;
FML_Clicked = !FML_Clicked;
if (FML_Clicked) break;
Show = False;
} else {
break;
} }
}
declare Invert = Event.Control.HasClass(\"" . self::OPTION_TOOLTIP_INVERT . "\");
foreach (ControlClass in Event.Control.ControlClasses) {
declare TooltipControl <=> Page.GetFirstChild(ControlClass);
if (TooltipControl == Null) continue;
TooltipControl.Visible = Show && !Invert;
" . self::FUNCTION_SETTOOLTIPTEXT . "(TooltipControl, Event.Control);
}"; }";
$tooltipsLabels = Builder::getLabelImplementationBlock(self::LABEL_MOUSEOVER, $mouseOverScript); $tooltipsLabels = Builder::getLabelImplementationBlock(self::LABEL_MOUSEOVER, $mouseOverScript);
$tooltipsLabels .= Builder::getLabelImplementationBlock(self::LABEL_MOUSEOUT, $mouseOutScript); $tooltipsLabels .= Builder::getLabelImplementationBlock(self::LABEL_MOUSEOUT, $mouseOutScript);
$tooltipsLabels .= Builder::getLabelImplementationBlock(self::LABEL_MOUSECLICK, $mouseClickScript);
return $tooltipsLabels; return $tooltipsLabels;
} }
@ -292,6 +442,7 @@ if (Event.Control.HasClass(\"" . self::CLASS_TOOLTIPS . "\")) {
* @return string * @return string
*/ */
private function getMenuLabels() { private function getMenuLabels() {
if (!$this->menus) return "";
$mouseClickScript = " $mouseClickScript = "
if (Event.Control.HasClass(\"" . self::CLASS_MENUBUTTON . "\")) { if (Event.Control.HasClass(\"" . self::CLASS_MENUBUTTON . "\")) {
declare Text MenuIdClass; declare Text MenuIdClass;
@ -323,6 +474,7 @@ if (Event.Control.HasClass(\"" . self::CLASS_MENUBUTTON . "\")) {
* @return string * @return string
*/ */
private function getPagesLabels() { private function getPagesLabels() {
if (!$this->pages) return "";
$pagesNumberPrefix = self::CLASS_PAGE . '-P'; $pagesNumberPrefix = self::CLASS_PAGE . '-P';
$pagesNumberPrefixLength = strlen($pagesNumberPrefix); $pagesNumberPrefixLength = strlen($pagesNumberPrefix);
$pagesScript = " $pagesScript = "
@ -404,6 +556,7 @@ if (Event.Control.HasClass(\"" . self::CLASS_PAGER . "\")) {
* @return string * @return string
*/ */
private function getProfileLabels() { private function getProfileLabels() {
if (!$this->profile) return "";
$profileScript = " $profileScript = "
if (Event.Control.HasClass(\"" . self::CLASS_PROFILE . "\")) { if (Event.Control.HasClass(\"" . self::CLASS_PROFILE . "\")) {
declare Login = LocalUser.Login; declare Login = LocalUser.Login;
@ -426,6 +579,7 @@ if (Event.Control.HasClass(\"" . self::CLASS_PROFILE . "\")) {
* @return string * @return string
*/ */
private function getMapInfoLabels() { private function getMapInfoLabels() {
if (!$this->mapInfo) return "";
$mapInfoScript = " $mapInfoScript = "
if (Event.Control.HasClass(\"" . self::CLASS_MAPINFO . "\")) { if (Event.Control.HasClass(\"" . self::CLASS_MAPINFO . "\")) {
ShowCurChallengeCard(); ShowCurChallengeCard();
@ -443,4 +597,28 @@ if (Event.Control.HasClass(\"" . self::CLASS_MAPINFO . "\")) {
$mainFunction = file_get_contents(__DIR__ . '/Parts/Main.txt'); $mainFunction = file_get_contents(__DIR__ . '/Parts/Main.txt');
return $mainFunction; return $mainFunction;
} }
/**
* Return the Array of additional optional Parameters
*
* @param array $args
* @param int $offset
* @return array
*/
private function spliceParameters(array $params, $offset) {
$args = array_splice($params, $offset);
if (!$args) return $args;
$parameters = array();
foreach ($args as $arg) {
if (is_array($arg)) {
foreach ($arg as $key => $value) {
$parameters[$key] = $value;
}
}
else {
$parameters[$arg] = true;
}
}
return $parameters;
}
} }

View File

@ -9,7 +9,11 @@
if (!defined('FML_PATH')) { if (!defined('FML_PATH')) {
define('FML_PATH', __DIR__ . '/../'); define('FML_PATH', __DIR__ . '/../');
} }
if (!defined('FML_VERSION')) {
define('FML_VERSION', 1.0);
}
// Register Autoload Function that loads FML Class Files on Demand
spl_autoload_register( spl_autoload_register(
function ($className) { function ($className) {
$classPath = str_replace('\\', DIRECTORY_SEPARATOR, $className); $classPath = str_replace('\\', DIRECTORY_SEPARATOR, $className);