1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace eXpansion\Framework\Gui\Components; |
4
|
|
|
|
5
|
|
|
use FML\Controls\Control; |
6
|
|
|
use FML\Controls\Frame; |
7
|
|
|
use FML\Controls\Label; |
|
|
|
|
8
|
|
|
use FML\Controls\Quad; |
9
|
|
|
use FML\Script\Features\ScriptFeature; |
10
|
|
|
use FML\Script\Script; |
11
|
|
|
use FML\Types\ScriptFeatureable; |
12
|
|
|
|
13
|
|
|
class Tooltip extends AbstractUiElement implements ScriptFeatureable |
14
|
|
|
{ |
15
|
|
|
protected $element; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @param AbstractUiElement|Control $control |
19
|
|
|
* @param string $text |
20
|
|
|
*/ |
21
|
|
|
public function addTooltip($control, $text) |
22
|
|
|
{ |
23
|
|
|
if ($control instanceof Control) { |
24
|
|
|
$control->addDataAttribute("tooltip", $text); |
25
|
|
|
$control->addClass("uiTooltip"); |
26
|
|
|
$control->setScriptEvents(true); |
|
|
|
|
27
|
|
|
|
28
|
|
|
return; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
if ($control instanceof AbstractUiElement) { |
32
|
|
|
$control->addDataAttribute("tooltip", $text); |
33
|
|
|
$control->addClass("uiTooltip"); |
34
|
|
|
|
35
|
|
|
return; |
36
|
|
|
} |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Prepare the given Script for rendering by adding the needed Labels, etc. |
41
|
|
|
* |
42
|
|
|
* @param Script $script Script to prepare |
43
|
|
|
* @return void |
44
|
|
|
* |
45
|
|
|
*/ |
46
|
|
|
public function prepare(Script $script) |
47
|
|
|
{ |
48
|
|
|
$script->addScriptFunction("exp_tooltipFunctions", $this->getFunctions()); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
|
52
|
|
|
public function getFunctions() |
53
|
|
|
{ |
54
|
|
|
|
55
|
|
|
return /** @lang textmate */ |
56
|
|
|
<<<EOL |
57
|
|
|
|
58
|
|
|
***FML_OnInit*** |
59
|
|
|
*** |
60
|
|
|
declare CMlFrame exp_tooltip = (Page.GetFirstChild("exp_tooltip") as CMlFrame); |
61
|
|
|
declare Boolean exp_tooltip_move = False; |
62
|
|
|
declare Boolean exp_tooltip_toggle = True; |
63
|
|
|
declare Integer exp_tooltip_delay = 0; |
64
|
|
|
declare Vec2 mouse_pos = <0., 0.>; |
65
|
|
|
declare Vec2 exp_tooltip_rel = <0., 0.>; |
66
|
|
|
*** |
67
|
|
|
|
68
|
|
|
***FML_Loop*** |
69
|
|
|
*** |
70
|
|
|
if (exp_tooltip_move) { |
71
|
|
|
exp_tooltip.RelativePosition_V3 = <MouseX, MouseY> - mouse_pos + exp_tooltip_rel; |
72
|
|
|
|
73
|
|
|
/* if (exp_tooltip_rel.Y > -10.) { |
74
|
|
|
exp_tooltip.RelativePosition_V3 = exp_tooltip_rel + <4., 0.>; |
75
|
|
|
} else { |
76
|
|
|
exp_tooltip.RelativePosition_V3 = exp_tooltip_rel + <4., 4.>; |
77
|
|
|
} */ |
78
|
|
|
|
79
|
|
|
if (exp_tooltip_delay + 350 < Now) { |
80
|
|
|
if (exp_tooltip_toggle) { |
81
|
|
|
AnimMgr.Add(exp_tooltip.Controls[0], "<elem scale=\"1\" />", 450, CAnimManager::EAnimManagerEasing::ElasticOut); |
82
|
|
|
AnimMgr.Add(exp_tooltip.Controls[1], "<elem scale=\"1\" />", 450, CAnimManager::EAnimManagerEasing::ElasticOut); |
83
|
|
|
exp_tooltip_toggle = False; |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
if (MouseLeftButton) { |
89
|
|
|
(exp_tooltip.Controls[0] as CMlLabel).RelativeScale = 0.; |
90
|
|
|
(exp_tooltip.Controls[1] as CMlQuad).RelativeScale = 0.; |
91
|
|
|
} |
92
|
|
|
*** |
93
|
|
|
|
94
|
|
|
***FML_MouseOver*** |
95
|
|
|
*** |
96
|
|
|
if (Event.Control != Null) { |
97
|
|
|
if (Event.Control.HasClass("uiTooltip") ) { |
98
|
|
|
declare tooltipLabel = (exp_tooltip.Controls[0] as CMlLabel); |
99
|
|
|
declare text = Event.Control.DataAttributeGet("tooltip"); |
100
|
|
|
declare sizeX = tooltipLabel.ComputeWidth(text); |
101
|
|
|
tooltipLabel.Value = text; |
102
|
|
|
tooltipLabel.Size.X = sizeX; |
103
|
|
|
(exp_tooltip.Controls[1] as CMlQuad).Size.X = sizeX; |
104
|
|
|
exp_tooltip_move = True; |
105
|
|
|
exp_tooltip_delay = Now; |
106
|
|
|
exp_tooltip_toggle = True; |
107
|
|
|
mouse_pos = <MouseX, MouseY>; |
108
|
|
|
// exp_tooltip_rel = Event.Control.AbsolutePosition_V3 + Exp_Window.RelativePosition_V3; |
109
|
|
|
exp_tooltip_rel = Event.Control.AbsolutePosition_V3 - Exp_Window.RelativePosition_V3; |
110
|
|
|
} |
111
|
|
|
} |
112
|
|
|
*** |
113
|
|
|
|
114
|
|
|
***FML_MouseOut*** |
115
|
|
|
*** |
116
|
|
|
if (Event.Control != Null) { |
117
|
|
|
if (Event.Control.HasClass("uiTooltip") ) { |
118
|
|
|
exp_tooltip_move = False; |
119
|
|
|
exp_tooltip_delay = 0; |
120
|
|
|
exp_tooltip_toggle = True; |
121
|
|
|
(exp_tooltip.Controls[0] as CMlLabel).RelativeScale = 0.; |
122
|
|
|
(exp_tooltip.Controls[1] as CMlQuad).RelativeScale = 0.; |
123
|
|
|
} |
124
|
|
|
} |
125
|
|
|
*** |
126
|
|
|
|
127
|
|
|
EOL; |
128
|
|
|
|
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* Get the Script Features |
134
|
|
|
* |
135
|
|
|
* @return ScriptFeature[] |
136
|
|
|
*/ |
137
|
|
|
public function getScriptFeatures() |
138
|
|
|
{ |
139
|
|
|
return ScriptFeature::collect($this); |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* Render the XML element |
144
|
|
|
* |
145
|
|
|
* @param \DOMDocument $domDocument DOMDocument for which the XML element should be rendered |
146
|
|
|
* @return \DOMElement |
147
|
|
|
*/ |
148
|
|
|
public function render(\DOMDocument $domDocument) |
149
|
|
|
{ |
150
|
|
|
$frame = new Frame("exp_tooltip"); |
151
|
|
|
$frame->setZ(100)->setAlign("left", "center"); |
152
|
|
|
|
153
|
|
|
$label = new Label(); |
154
|
|
|
$label->setSize(36, 5) |
155
|
|
|
->setAlign("left", "center2") |
156
|
|
|
->setTextFont('file://Media/Font/BiryaniDemiBold.Font.gbx') |
157
|
|
|
->setTextSize(2) |
158
|
|
|
->setTextColor("eee") |
159
|
|
|
->setOpacity(1) |
160
|
|
|
->setAreaFocusColor("0000") |
161
|
|
|
->setAreaColor("0000") |
162
|
|
|
->setScriptEvents(true) |
163
|
|
|
->setScale(0); |
164
|
|
|
|
165
|
|
|
$quad = new Quad(); |
166
|
|
|
$quad->setAlign("left", "center2")->setScale(0); |
167
|
|
|
$quad->setSize(36, 5)->setBackgroundColor('000')->setOpacity(1)->setScriptEvents(true); |
168
|
|
|
|
169
|
|
|
|
170
|
|
|
$frame->addChild($label); |
171
|
|
|
$frame->addChild($quad); |
172
|
|
|
|
173
|
|
|
return $frame->render($domDocument); |
174
|
|
|
} |
175
|
|
|
} |
176
|
|
|
|
Let’s assume that you have a directory layout like this:
and let’s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: