FML Update

This commit is contained in:
Steffen Schröder
2013-11-28 07:30:00 +01:00
parent c39d35d1fe
commit fed96b36d0
12 changed files with 419 additions and 15 deletions

View File

@ -0,0 +1,103 @@
<?php
namespace FML\Script;
use FML\Controls\Control;
use FML\Script\Sections\Constants;
use FML\Script\Sections\Labels;
use FML\Types\Scriptable;
/**
* ScriptFeature class offering menu behaviors
*
* @author steeffeen
*/
class Menus implements Constants, Labels, ScriptFeature {
/**
* Constants
*/
const C_MENUIDS = 'C_FML_MenuIds';
/**
* Protected properties
*/
protected $menus = array();
/**
* Add menu behavior defined by the given relationships
*
* @param array $menuRelationships
* @return \FML\Script\Menus
*/
public function add(array $menuRelationships) {
$menuIndex = count($this->menus);
$menus = array();
$submenus = array();
foreach ($menuRelationships as $relationship) {
$menuItemControl = $relationship[0];
$subMenuControl = $relationship[1];
if (!($menuItemControl instanceof Scriptable)) {
trigger_error('No Scriptable instance given as menu item.', E_USER_ERROR);
}
if (!($subMenuControl instanceof Control)) {
trigger_error('No Control instance given as submenu.', E_USER_ERROR);
}
$menuItemControl->assignId();
$menuItemControl->setScriptEvents(true);
$subMenuControl->assignId();
array_push($menus, array($menuItemControl->getId(), $subMenuControl->getId()));
array_push($submenus, $subMenuControl->getId());
}
array_push($this->menus, array($menus, $submenus));
return $this;
}
/**
*
* @see \FML\Script\Sections\Constants::getConstants()
*/
public function getConstants() {
$constant = '[';
$index = 0;
foreach ($this->menus as $menu) {
$constant .= '[';
foreach ($menu[0] as $menuRel) {
$constant .= '"' . $menuRel[0] . '" => ["' . $menuRel[1] . '"], ';
}
$constant .= '"__FML__Sub__Menus__" => [';
$subIndex = 0;
foreach ($menu[1] as $subMenu) {
$constant .= '"' . $subMenu . '"';
if ($subIndex < count($menu[1]) - 1) {
$constant .= ', ';
}
$subIndex++;
}
$constant .= ']]';
if ($index < count($this->menus) - 1) {
$constant .= ', ';
}
$index++;
}
$constant .= ']';
$constants = array();
$constants[self::C_MENUIDS] = $constant;
return $constants;
}
/**
*
* @see \FML\Script\Sections\Labels::getLabels()
*/
public function getLabels() {
$labels = array();
$labelMouseClick = file_get_contents(__DIR__ . '/Templates/MenuMouseClick.txt');
$labels[Labels::MOUSECLICK] = $labelMouseClick;
return $labels;
}
}
?>

View File

@ -0,0 +1,144 @@
<?php
namespace FML\Script;
use FML\Controls\Control;
use FML\Script\Sections\Constants;
use FML\Script\Sections\Globals;
use FML\Script\Sections\Includes;
use FML\Script\Sections\Labels;
use FML\Types\Scriptable;
use FML\Controls\Label;
/**
* ScriptFeature class offering paging
*
* @author steeffeen
*/
class Pages implements Constants, Globals, Includes, Labels, ScriptFeature {
/**
* Constants
*/
const C_PAGEIDS = 'C_FML_PageIds';
/**
* Protected properties
*/
protected $pages = array();
/**
* Add paging behavior
*
* @param array $pageButtons
* @param array $pages
* @param Label $counterLabel
* @return \FML\Script\Pages
*/
public function add(array $pageButtons, array $pages, Label $counterLabel = null) {
$actionIds = array();
foreach ($pageButtons as $action => $pageButton) {
if (!($pageButton instanceof Control)) {
trigger_error('No Control instance given.', E_USER_ERROR);
}
$pageButton->assignId();
if (!($pageButton instanceof Scriptable)) {
trigger_error('No Scriptable instance given.', E_USER_ERROR);
}
$pageButton->setScriptEvents(true);
$actionIds[$pageButton->getId()] = $action;
}
$pageIds = array();
foreach ($pages as $page) {
if (!($page instanceof Control)) {
trigger_error('No Control instance given.', E_USER_ERROR);
}
$page->assignId();
if (!empty($pageIds)) {
$page->setVisible(false);
}
array_push($pageIds, $page->getId());
}
if ($counterLabel) {
$counterLabel->assignId();
$counterId = $counterLabel->getId();
}
else {
$counterId = uniqid();
}
array_push($this->pages, array($actionIds, $pageIds, $counterId));
}
/**
*
* @see \FML\Script\Sections\Includes::getIncludes()
*/
public function getIncludes() {
$includes = array();
$includes["TextLib"] = "TextLib";
return $includes;
}
/**
*
* @see \FML\Script\Sections\Constants::getConstants()
*/
public function getConstants() {
$constant = '[';
$index = 0;
foreach ($this->pages as $page) {
$constant .= '[';
$actionIds = $page[0];
foreach ($actionIds as $actionId => $action) {
$constant .= '"' . $actionId . '" => ["' . $action . '"], ';
}
$constant .= '"__FML__Pages__Id__" => ["' . $page[2] . '"], ';
$constant .= '"__FML__Pages__Ids__" => [';
$subIndex = 0;
foreach ($page[1] as $pageId) {
$constant .= '"' . $pageId . '"';
if ($subIndex < count($page[1]) - 1) {
$constant .= ', ';
}
$subIndex++;
}
$constant .= ']]';
if ($index < count($this->pages) - 1) {
$constant .= ', ';
}
$index++;
}
$constant .= ']';
$constants = array();
$constants[self::C_PAGEIDS] = $constant;
return $constants;
}
/**
*
* @see \FML\Script\Sections\Globals::getGlobals()
*/
public function getGlobals() {
$globals = array();
$globals['G_FML_PageIndexes'] = 'Integer[Text]';
return $globals;
}
/**
*
* @see \FML\Script\Sections\Labels::getLabels()
*/
public function getLabels() {
$labels = array();
$labelOnInit = file_get_contents(__DIR__ . '/Templates/PageOnInit.txt');
$labels[Labels::ONINIT] = $labelOnInit;
$labelMouseClick = file_get_contents(__DIR__ . '/Templates/PageMouseClick.txt');
$labels[Labels::MOUSECLICK] = $labelMouseClick;
return $labels;
}
}
?>

View File

@ -62,14 +62,27 @@ class Script {
*/
private function buildScriptText() {
$scriptText = "";
$scriptText = $this->addHeaderPart($scriptText);
$scriptText = $this->addIncludesPart($scriptText);
$scriptText = $this->addConstantsPart($scriptText);
$scriptText = $this->addGlobalsPart($scriptText);
$scriptText = $this->addLabelsPart($scriptText);
$scriptText = $this->addFunctionsPart($scriptText);
$scriptText = $this->addMainPart($scriptText);
return $scriptText;
}
/**
* Add the header comment to the script
*
* @param script $scriptText
* @return string
*/
private function addHeaderPart($scriptText) {
$headerPart = file_get_contents(__DIR__ . '/Templates/Header.txt');
return $scriptText . $headerPart;
}
/**
* Add the includes to the script
*

View File

@ -0,0 +1,4 @@
/*********************************
* FancyManiaLinks by steeffeen *
* http://fml.steeffeen.com *
*********************************/

View File

@ -1,3 +1,4 @@
Void Dummy() {}
main() {
+++OnInit+++

View File

@ -0,0 +1,12 @@
foreach (MenuIds in C_FML_MenuIds) {
if (!MenuIds.existskey(Event.ControlId)) continue;
declare MenuId = MenuIds[Event.ControlId][0];
declare SubMenuIds = MenuIds["__FML__Sub__Menus__"];
foreach (SubMenuId in SubMenuIds) {
declare SubMenu <=> Page.GetFirstChild(SubMenuId);
if (SubMenu == Null) continue;
SubMenu.Visible = (SubMenu.ControlId == MenuId);
}
}

View File

@ -0,0 +1,27 @@
foreach (PageIds in C_FML_PageIds) {
if (!PageIds.existskey(Event.ControlId)) continue;
declare Action = TextLib::ToInteger(PageIds[Event.ControlId][0]);
declare PagesId = PageIds["__FML__Pages__Id__"][0];
declare PagesIds = PageIds["__FML__Pages__Ids__"];
if (!G_FML_PageIndexes.existskey(PagesId)) {
G_FML_PageIndexes[PagesId] = 0;
}
G_FML_PageIndexes[PagesId] += Action;
if (G_FML_PageIndexes[PagesId] < 0) {
G_FML_PageIndexes[PagesId] = 0;
} else if (G_FML_PageIndexes[PagesId] >= PagesIds.count) {
G_FML_PageIndexes[PagesId] = PagesIds.count - 1;
}
foreach (PageIndex => PageId in PagesIds) {
declare Control <=> Page.GetFirstChild(PageId);
if (Control == Null) continue;
Control.Visible = (PageIndex == G_FML_PageIndexes[PagesId]);
}
declare Label_Counter <=> (Page.GetFirstChild(PagesId) as CMlLabel);
if (Label_Counter == Null) continue;
Label_Counter.Value = (G_FML_PageIndexes[PagesId]+1)^"/"^PagesIds.count;
}

View File

@ -0,0 +1,18 @@
foreach (PageIds in C_FML_PageIds) {
declare PagesId = PageIds["__FML__Pages__Id__"][0];
declare PagesIds = PageIds["__FML__Pages__Ids__"];
if (!G_FML_PageIndexes.existskey(PagesId)) {
G_FML_PageIndexes[PagesId] = 0;
}
foreach (PageIndex => PageId in PagesIds) {
declare Control <=> Page.GetFirstChild(PageId);
if (Control == Null) continue;
Control.Visible = (PageIndex == G_FML_PageIndexes[PagesId]);
}
declare Label_Counter <=> (Page.GetFirstChild(PagesId) as CMlLabel);
if (Label_Counter == Null) continue;
Label_Counter.Value = (G_FML_PageIndexes[PagesId]+1)^"/"^PagesIds.count;
}

View File

@ -3,4 +3,4 @@ if (C_FML_TooltipIds.existskey(Event.ControlId)) {
if (TooltipControl != Null) {
TooltipControl.Hide();
}
}
}

View File

@ -3,4 +3,4 @@ if (C_FML_TooltipIds.existskey(Event.ControlId)) {
if (TooltipControl != Null) {
TooltipControl.Show();
}
}
}

View File

@ -5,6 +5,7 @@ namespace FML\Script;
use FML\Controls\Control;
use FML\Script\Sections\Constants;
use FML\Script\Sections\Labels;
use FML\Types\Scriptable;
/**
* ScriptFeature class offering tooltip behaviors
@ -25,13 +26,17 @@ class Tooltips implements Constants, Labels, ScriptFeature {
/**
* Add a tooltip behavior showing the tooltipControl while hovering over the hoverControl
*
* @param Control $hoverControl
* @param Scriptable $hoverControl
* @param Control $tooltipControl
* @return \FML\Script\Tooltips
*/
public function add(Control $hoverControl, Control $tooltipControl) {
$hoverControl->assignId();
public function add(Scriptable $hoverControl, Control $tooltipControl) {
if ($hoverControl instanceof Control) {
$hoverControl->assignId();
}
$hoverControl->setScriptEvents(true);
$tooltipControl->assignId();
$tooltipControl->setVisible(false);
$this->tooltips[$hoverControl->getId()] = $tooltipControl->getId();
return $this;
}
@ -42,11 +47,13 @@ class Tooltips implements Constants, Labels, ScriptFeature {
*/
public function getConstants() {
$constant = '[';
$index = 0;
foreach ($this->tooltips as $hoverId => $tooltipId) {
$constant .= '"' . $hoverId . '" => "' . $tooltipId . '"';
if ($index < count($this->tooltips) - 1) {
$constant .= ',';
}
$index++;
}
$constant .= ']';
$constants = array();