|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace eXpansion\Framework\Gui\Components; |
|
4
|
|
|
|
|
5
|
|
|
use eXpansion\Framework\Core\Helpers\ColorConversion; |
|
6
|
|
|
use FML\Controls\Frame; |
|
7
|
|
|
use FML\Controls\Quad; |
|
8
|
|
|
use FML\Script\Features\ScriptFeature; |
|
9
|
|
|
use FML\Script\Script; |
|
10
|
|
|
use FML\Script\ScriptLabel; |
|
11
|
|
|
use FML\Types\Renderable; |
|
12
|
|
|
use FML\Types\ScriptFeatureable; |
|
13
|
|
|
|
|
14
|
|
|
class uiButton extends abstractUiElement implements ScriptFeatureable |
|
15
|
|
|
{ |
|
16
|
|
|
private $type; |
|
17
|
|
|
|
|
18
|
|
|
private $textColor = "eee"; |
|
19
|
|
|
private $backColor = self::COLOR_DEFAULT; |
|
20
|
|
|
private $focusColor = "bbb"; |
|
21
|
|
|
private $borderColor = "fff"; |
|
22
|
|
|
|
|
23
|
|
|
private $action = null; |
|
24
|
|
|
private $text = "button"; |
|
25
|
|
|
|
|
26
|
|
|
const TYPE_DECORATED = "decorated"; |
|
27
|
|
|
const TYPE_DEFAULT = "default"; |
|
28
|
|
|
|
|
29
|
|
|
const COLOR_DEFAULT = "aaa"; |
|
30
|
|
|
const COLOR_SUCCESS = "0d0"; |
|
31
|
|
|
const COLOR_WARNING = "d00"; |
|
32
|
|
|
const COLOR_PRIMARY = "3af"; |
|
33
|
|
|
const COLOR_SECONDARY = "000"; |
|
34
|
|
|
|
|
35
|
|
|
private $sizeX = 26; |
|
36
|
|
|
private $sizeY = 9; |
|
37
|
|
|
|
|
38
|
|
|
public function __construct($text = "button", $type = self::TYPE_DEFAULT) |
|
39
|
|
|
{ |
|
40
|
|
|
$this->text = $text; |
|
41
|
|
|
$this->type = $type; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Render the XML element |
|
47
|
|
|
* |
|
48
|
|
|
* @param \DOMDocument $domDocument DOMDocument for which the XML element should be rendered |
|
49
|
|
|
* @return \DOMElement |
|
50
|
|
|
* |
|
51
|
|
|
* <frame pos="64 -35" class="uiContainer uiButton"> |
|
52
|
|
|
* <label size="26 9" data-color="fff" text="Cancel" class="button noAnim" textprefix=" " opacity="1" halign="center" valign="center" focusareacolor1="0000" focusareacolor2="d00" scriptevents="1" translate="0" textsize="2"/> |
|
53
|
|
|
* <quad size="26 9" style="Bgs1" colorize="d00" substyle="BgColorContour" class="button" halign="center" valign="center" pos="0 0"/> |
|
54
|
|
|
* </frame> |
|
55
|
|
|
*/ |
|
56
|
|
|
public function render(\DOMDocument $domDocument) |
|
57
|
|
|
{ |
|
58
|
|
|
$buttonFrame = new Frame(); |
|
59
|
|
|
$buttonFrame->setAlign("center", "center") |
|
60
|
|
|
->setPosition($this->posX + ($this->sizeX / 2), $this->posY - ($this->sizeY / 2), $this->posZ) |
|
61
|
|
|
->addClasses(['uiContainer', 'uiButton']) |
|
62
|
|
|
->addDataAttribute("action", $this->action); |
|
63
|
|
|
|
|
64
|
|
|
if ($this->type == self::TYPE_DECORATED) { |
|
65
|
|
|
$quad = new Quad(); |
|
66
|
|
|
$this->backColor = null; |
|
67
|
|
|
$quad->setStyles("Bgs1", "BgColorContour") |
|
68
|
|
|
->setColorize($this->borderColor) |
|
69
|
|
|
->setSize($this->sizeX, $this->sizeY) |
|
70
|
|
|
//->setPosition(-$this->sizeX / 2, $this->sizeY / 2) |
|
|
|
|
|
|
71
|
|
|
->setAlign("center", "center2"); |
|
72
|
|
|
$buttonFrame->addChild($quad); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
$label = new uiLabel($this->getText(), uiLabel::TYPE_TITLE); |
|
76
|
|
|
$label->setSize($this->sizeX, $this->sizeY) |
|
77
|
|
|
->setScriptEvents(true) |
|
78
|
|
|
->setAreaColor($this->backColor) |
|
79
|
|
|
->setAreaFocusColor($this->focusColor) |
|
80
|
|
|
->setTextColor($this->textColor) |
|
81
|
|
|
->addClass('uiButtonElement') |
|
82
|
|
|
->setAlign("center", "center2"); |
|
83
|
|
|
//->setPosition(-$this->sizeX / 2, $this->sizeY / 2); |
|
|
|
|
|
|
84
|
|
|
|
|
85
|
|
|
$buttonFrame->addChild($label); |
|
86
|
|
|
|
|
87
|
|
|
|
|
88
|
|
|
return $buttonFrame->render($domDocument); |
|
89
|
|
|
|
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* Get the Script Features |
|
94
|
|
|
* |
|
95
|
|
|
* @return ScriptFeature[] |
|
96
|
|
|
*/ |
|
97
|
|
|
public function getScriptFeatures() |
|
98
|
|
|
{ |
|
99
|
|
|
return ScriptFeature::collect($this); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* Prepare the given Script for rendering by adding the needed Labels, etc. |
|
104
|
|
|
* |
|
105
|
|
|
* @param Script $script Script to prepar |
|
106
|
|
|
* @return void |
|
107
|
|
|
*/ |
|
108
|
|
|
public function prepare(Script $script) |
|
109
|
|
|
{ |
|
110
|
|
|
$script->addCustomScriptLabel(ScriptLabel::MouseClick, $this->getScriptMouseClick()); |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
private function getScriptMouseClick() |
|
114
|
|
|
{ |
|
115
|
|
|
return /** language=textmate prefix=#RequireContext\n */ |
|
116
|
|
|
<<<'EOD' |
|
117
|
|
|
if (Event.Control.HasClass("uiButtonElement") ) { |
|
118
|
|
|
if (Event.Control.Parent.HasClass("uiButton")) { |
|
119
|
|
|
Event.Control.Parent.RelativeScale = 0.75; |
|
120
|
|
|
AnimMgr.Add(Event.Control.Parent, "<elem scale=\"1.\" />", 200, CAnimManager::EAnimManagerEasing::QuadIn); |
|
121
|
|
|
TriggerPageAction(Event.Control.Parent.DataAttributeGet("action")); |
|
122
|
|
|
} |
|
123
|
|
|
} |
|
124
|
|
|
EOD; |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
/** |
|
128
|
|
|
* @return string |
|
129
|
|
|
*/ |
|
130
|
|
|
public function getType() |
|
131
|
|
|
{ |
|
132
|
|
|
return $this->type; |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
/** |
|
136
|
|
|
* @param string $type |
|
137
|
|
|
*/ |
|
138
|
|
|
public function setType($type) |
|
139
|
|
|
{ |
|
140
|
|
|
$this->type = $type; |
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
|
|
/** |
|
144
|
|
|
* @return string |
|
145
|
|
|
*/ |
|
146
|
|
|
public function getTextColor() |
|
147
|
|
|
{ |
|
148
|
|
|
return $this->textColor; |
|
149
|
|
|
} |
|
150
|
|
|
|
|
151
|
|
|
/** |
|
152
|
|
|
* @param string $textColor |
|
153
|
|
|
*/ |
|
154
|
|
|
public function setTextColor($textColor) |
|
155
|
|
|
{ |
|
156
|
|
|
$this->textColor = $textColor; |
|
157
|
|
|
} |
|
158
|
|
|
|
|
159
|
|
|
/** |
|
160
|
|
|
* @return string |
|
161
|
|
|
*/ |
|
162
|
|
|
public function getBackgroundColor() |
|
163
|
|
|
{ |
|
164
|
|
|
return $this->backColor; |
|
165
|
|
|
} |
|
166
|
|
|
|
|
167
|
|
|
/** |
|
168
|
|
|
* @param string $backColor |
|
169
|
|
|
*/ |
|
170
|
|
|
public function setBackgroundColor($backColor) |
|
171
|
|
|
{ |
|
172
|
|
|
$this->backColor = $backColor; |
|
173
|
|
|
} |
|
174
|
|
|
|
|
175
|
|
|
/** |
|
176
|
|
|
* @return string |
|
177
|
|
|
*/ |
|
178
|
|
|
public function getBorderColor() |
|
179
|
|
|
{ |
|
180
|
|
|
return $this->borderColor; |
|
181
|
|
|
} |
|
182
|
|
|
|
|
183
|
|
|
/** |
|
184
|
|
|
* @param string $borderColor |
|
185
|
|
|
*/ |
|
186
|
|
|
public function setBorderColor($borderColor) |
|
187
|
|
|
{ |
|
188
|
|
|
$this->borderColor = $borderColor; |
|
189
|
|
|
} |
|
190
|
|
|
|
|
191
|
|
|
/** |
|
192
|
|
|
* @return null |
|
193
|
|
|
*/ |
|
194
|
|
|
public function getAction() |
|
195
|
|
|
{ |
|
196
|
|
|
return $this->action; |
|
197
|
|
|
} |
|
198
|
|
|
|
|
199
|
|
|
/** |
|
200
|
|
|
* @param null $action |
|
201
|
|
|
*/ |
|
202
|
|
|
public function setAction($action) |
|
203
|
|
|
{ |
|
204
|
|
|
$this->action = $action; |
|
205
|
|
|
} |
|
206
|
|
|
|
|
207
|
|
|
/** |
|
208
|
|
|
* @return string |
|
209
|
|
|
*/ |
|
210
|
|
|
public function getFocusColor() |
|
211
|
|
|
{ |
|
212
|
|
|
return $this->focusColor; |
|
213
|
|
|
} |
|
214
|
|
|
|
|
215
|
|
|
/** |
|
216
|
|
|
* @param string $focusColor |
|
217
|
|
|
*/ |
|
218
|
|
|
public function setFocusColor($focusColor) |
|
219
|
|
|
{ |
|
220
|
|
|
$this->focusColor = $focusColor; |
|
221
|
|
|
} |
|
222
|
|
|
|
|
223
|
|
|
/** |
|
224
|
|
|
* @return string |
|
225
|
|
|
*/ |
|
226
|
|
|
public function getText() |
|
227
|
|
|
{ |
|
228
|
|
|
return $this->text; |
|
229
|
|
|
} |
|
230
|
|
|
|
|
231
|
|
|
/** |
|
232
|
|
|
* @param string $text |
|
233
|
|
|
*/ |
|
234
|
|
|
public function setText($text) |
|
235
|
|
|
{ |
|
236
|
|
|
$this->text = $text; |
|
237
|
|
|
} |
|
238
|
|
|
|
|
239
|
|
|
/** |
|
240
|
|
|
* @return int |
|
241
|
|
|
*/ |
|
242
|
|
|
public function getSizeX() |
|
243
|
|
|
{ |
|
244
|
|
|
return $this->sizeX; |
|
245
|
|
|
} |
|
246
|
|
|
|
|
247
|
|
|
/** |
|
248
|
|
|
* @param int $sizeX |
|
249
|
|
|
*/ |
|
250
|
|
|
public function setSizeX($sizeX) |
|
251
|
|
|
{ |
|
252
|
|
|
$this->sizeX = $sizeX; |
|
253
|
|
|
} |
|
254
|
|
|
|
|
255
|
|
|
/** |
|
256
|
|
|
* @return int |
|
257
|
|
|
*/ |
|
258
|
|
|
public function getSizeY() |
|
259
|
|
|
{ |
|
260
|
|
|
return $this->sizeY; |
|
261
|
|
|
} |
|
262
|
|
|
|
|
263
|
|
|
/** |
|
264
|
|
|
* @param int $sizeY |
|
265
|
|
|
*/ |
|
266
|
|
|
public function setSizeY($sizeY) |
|
267
|
|
|
{ |
|
268
|
|
|
$this->sizeY = $sizeY; |
|
269
|
|
|
} |
|
270
|
|
|
|
|
271
|
|
|
/** |
|
272
|
|
|
* sets control size |
|
273
|
|
|
* @param int $x |
|
274
|
|
|
* @param int $y |
|
275
|
|
|
*/ |
|
276
|
|
|
public function setSize($x, $y) |
|
277
|
|
|
{ |
|
278
|
|
|
$this->sizeX = $x; |
|
279
|
|
|
$this->sizeY = $y; |
|
280
|
|
|
} |
|
281
|
|
|
|
|
282
|
|
|
public function getHeight() |
|
283
|
|
|
{ |
|
284
|
|
|
return $this->sizeY; |
|
285
|
|
|
} |
|
286
|
|
|
|
|
287
|
|
|
public function getWidth() |
|
288
|
|
|
{ |
|
289
|
|
|
return $this->sizeX; |
|
290
|
|
|
} |
|
291
|
|
|
|
|
292
|
|
|
|
|
293
|
|
|
} |
|
294
|
|
|
|
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.