|
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\Script; |
|
9
|
|
|
use FML\Types\Renderable; |
|
10
|
|
|
|
|
11
|
|
|
class uiButton extends abstractUiElement |
|
12
|
|
|
{ |
|
13
|
|
|
private $type; |
|
14
|
|
|
|
|
15
|
|
|
private $textColor = "eee"; |
|
16
|
|
|
private $backColor = self::COLOR_DEFAULT; |
|
17
|
|
|
private $focusColor = "bbb"; |
|
18
|
|
|
private $borderColor = "fff"; |
|
19
|
|
|
|
|
20
|
|
|
private $action = null; |
|
21
|
|
|
private $text = "button"; |
|
22
|
|
|
|
|
23
|
|
|
const TYPE_DECORATED = "decorated"; |
|
24
|
|
|
const TYPE_DEFAULT = "default"; |
|
25
|
|
|
|
|
26
|
|
|
const COLOR_DEFAULT = "aaa"; |
|
27
|
|
|
const COLOR_SUCCESS = "0d0"; |
|
28
|
|
|
const COLOR_WARNING = "d00"; |
|
29
|
|
|
const COLOR_PRIMARY = "3af"; |
|
30
|
|
|
const COLOR_SECONDARY = "000"; |
|
31
|
|
|
|
|
32
|
|
|
private $sizeX = 26; |
|
33
|
|
|
private $sizeY = 9; |
|
34
|
|
|
|
|
35
|
|
|
public function __construct($text = "button", $type = self::TYPE_DEFAULT) |
|
36
|
|
|
{ |
|
37
|
|
|
$this->text = $text; |
|
38
|
|
|
$this->type = $type; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Render the XML element |
|
44
|
|
|
* |
|
45
|
|
|
* @param \DOMDocument $domDocument DOMDocument for which the XML element should be rendered |
|
46
|
|
|
* @return \DOMElement |
|
47
|
|
|
* |
|
48
|
|
|
* <frame pos="64 -35" class="uiContainer uiButton"> |
|
49
|
|
|
* <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"/> |
|
50
|
|
|
* <quad size="26 9" style="Bgs1" colorize="d00" substyle="BgColorContour" class="button" halign="center" valign="center" pos="0 0"/> |
|
51
|
|
|
* </frame> |
|
52
|
|
|
*/ |
|
53
|
|
|
public function render(\DOMDocument $domDocument) |
|
54
|
|
|
{ |
|
55
|
|
|
$buttonFrame = new Frame(); |
|
56
|
|
|
$buttonFrame->setPosition($this->posX, $this->posY, $this->posZ) |
|
57
|
|
|
->addClasses(['uiContainer', 'uiButton']); |
|
58
|
|
|
|
|
59
|
|
|
if ($this->type == self::TYPE_DECORATED) { |
|
60
|
|
|
echo "decorated!"; |
|
61
|
|
|
//<quad size="26 9" style="Bgs1" colorize="d00" substyle="BgColorContour" |
|
62
|
|
|
$quad = new Quad(); |
|
63
|
|
|
$this->backColor = null; |
|
64
|
|
|
$quad->setStyles("Bgs1", "BgColorContour") |
|
65
|
|
|
->setColorize($this->borderColor) |
|
66
|
|
|
->setSize($this->sizeX, $this->sizeY) |
|
67
|
|
|
->setPosition($this->sizeX / 2, -$this->sizeY / 2) |
|
68
|
|
|
->setAlign("center", "center2"); |
|
69
|
|
|
$buttonFrame->addChild($quad); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
$label = new uiLabel($this->getText(), uiLabel::TYPE_TITLE); |
|
73
|
|
|
$label->setSize($this->sizeX, $this->sizeY) |
|
74
|
|
|
->setScriptEvents(true) |
|
75
|
|
|
->setAreaColor($this->backColor) |
|
76
|
|
|
->setAreaFocusColor($this->focusColor) |
|
77
|
|
|
->setTextColor($this->textColor) |
|
78
|
|
|
->setAlign("center", "center2") |
|
79
|
|
|
->setPosition($this->sizeX / 2, -$this->sizeY / 2); |
|
80
|
|
|
|
|
81
|
|
|
if ($this->action !== null) { |
|
82
|
|
|
$label->setAction($this->action); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
$buttonFrame->addChild($label); |
|
86
|
|
|
|
|
87
|
|
|
|
|
88
|
|
|
return $buttonFrame->render($domDocument); |
|
89
|
|
|
|
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* Prepare the given Script for rendering by adding the needed Labels, etc. |
|
94
|
|
|
* |
|
95
|
|
|
* @param Script $script Script to prepare |
|
96
|
|
|
* @return static |
|
97
|
|
|
* |
|
98
|
|
|
*/ |
|
99
|
|
|
public function prepare(Script $script) |
|
100
|
|
|
{ |
|
101
|
|
|
// TODO: Implement prepare() method. |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* @return string |
|
106
|
|
|
*/ |
|
107
|
|
|
public function getType() |
|
108
|
|
|
{ |
|
109
|
|
|
return $this->type; |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* @param string $type |
|
114
|
|
|
*/ |
|
115
|
|
|
public function setType($type) |
|
116
|
|
|
{ |
|
117
|
|
|
$this->type = $type; |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* @return string |
|
122
|
|
|
*/ |
|
123
|
|
|
public function getTextColor() |
|
124
|
|
|
{ |
|
125
|
|
|
return $this->textColor; |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
/** |
|
129
|
|
|
* @param string $textColor |
|
130
|
|
|
*/ |
|
131
|
|
|
public function setTextColor($textColor) |
|
132
|
|
|
{ |
|
133
|
|
|
$this->textColor = $textColor; |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
/** |
|
137
|
|
|
* @return string |
|
138
|
|
|
*/ |
|
139
|
|
|
public function getBackgroundColor() |
|
140
|
|
|
{ |
|
141
|
|
|
return $this->backColor; |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
/** |
|
145
|
|
|
* @param string $backColor |
|
146
|
|
|
*/ |
|
147
|
|
|
public function setBackgroundColor($backColor) |
|
148
|
|
|
{ |
|
149
|
|
|
$this->backColor = $backColor; |
|
150
|
|
|
} |
|
151
|
|
|
|
|
152
|
|
|
/** |
|
153
|
|
|
* @return string |
|
154
|
|
|
*/ |
|
155
|
|
|
public function getBorderColor() |
|
156
|
|
|
{ |
|
157
|
|
|
return $this->borderColor; |
|
158
|
|
|
} |
|
159
|
|
|
|
|
160
|
|
|
/** |
|
161
|
|
|
* @param string $borderColor |
|
162
|
|
|
*/ |
|
163
|
|
|
public function setBorderColor($borderColor) |
|
164
|
|
|
{ |
|
165
|
|
|
$this->borderColor = $borderColor; |
|
166
|
|
|
} |
|
167
|
|
|
|
|
168
|
|
|
/** |
|
169
|
|
|
* @return null |
|
170
|
|
|
*/ |
|
171
|
|
|
public function getAction() |
|
172
|
|
|
{ |
|
173
|
|
|
return $this->action; |
|
174
|
|
|
} |
|
175
|
|
|
|
|
176
|
|
|
/** |
|
177
|
|
|
* @param null $action |
|
178
|
|
|
*/ |
|
179
|
|
|
public function setAction($action) |
|
180
|
|
|
{ |
|
181
|
|
|
$this->action = $action; |
|
182
|
|
|
} |
|
183
|
|
|
|
|
184
|
|
|
/** |
|
185
|
|
|
* @return string |
|
186
|
|
|
*/ |
|
187
|
|
|
public function getFocusColor() |
|
188
|
|
|
{ |
|
189
|
|
|
return $this->focusColor; |
|
190
|
|
|
} |
|
191
|
|
|
|
|
192
|
|
|
/** |
|
193
|
|
|
* @param string $focusColor |
|
194
|
|
|
*/ |
|
195
|
|
|
public function setFocusColor($focusColor) |
|
196
|
|
|
{ |
|
197
|
|
|
$this->focusColor = $focusColor; |
|
198
|
|
|
} |
|
199
|
|
|
|
|
200
|
|
|
/** |
|
201
|
|
|
* @return string |
|
202
|
|
|
*/ |
|
203
|
|
|
public function getText() |
|
204
|
|
|
{ |
|
205
|
|
|
return $this->text; |
|
206
|
|
|
} |
|
207
|
|
|
|
|
208
|
|
|
/** |
|
209
|
|
|
* @param string $text |
|
210
|
|
|
*/ |
|
211
|
|
|
public function setText($text) |
|
212
|
|
|
{ |
|
213
|
|
|
$this->text = $text; |
|
214
|
|
|
} |
|
215
|
|
|
|
|
216
|
|
|
/** |
|
217
|
|
|
* @return int |
|
218
|
|
|
*/ |
|
219
|
|
|
public function getSizeX() |
|
220
|
|
|
{ |
|
221
|
|
|
return $this->sizeX; |
|
222
|
|
|
} |
|
223
|
|
|
|
|
224
|
|
|
/** |
|
225
|
|
|
* @param int $sizeX |
|
226
|
|
|
*/ |
|
227
|
|
|
public function setSizeX($sizeX) |
|
228
|
|
|
{ |
|
229
|
|
|
$this->sizeX = $sizeX; |
|
230
|
|
|
} |
|
231
|
|
|
|
|
232
|
|
|
/** |
|
233
|
|
|
* @return int |
|
234
|
|
|
*/ |
|
235
|
|
|
public function getSizeY() |
|
236
|
|
|
{ |
|
237
|
|
|
return $this->sizeY; |
|
238
|
|
|
} |
|
239
|
|
|
|
|
240
|
|
|
/** |
|
241
|
|
|
* @param int $sizeY |
|
242
|
|
|
*/ |
|
243
|
|
|
public function setSizeY($sizeY) |
|
244
|
|
|
{ |
|
245
|
|
|
$this->sizeY = $sizeY; |
|
246
|
|
|
} |
|
247
|
|
|
|
|
248
|
|
|
/** |
|
249
|
|
|
* sets control size |
|
250
|
|
|
* @param int $x |
|
251
|
|
|
* @param int $y |
|
252
|
|
|
*/ |
|
253
|
|
|
public function setSize($x, $y) |
|
254
|
|
|
{ |
|
255
|
|
|
$this->sizeX = $x; |
|
256
|
|
|
$this->sizeY = $y; |
|
257
|
|
|
} |
|
258
|
|
|
} |
|
259
|
|
|
|