|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace eXpansion\Core\Model\Gui; |
|
4
|
|
|
|
|
5
|
|
|
use eXpansion\Core\Exceptions\Gui\MissingCloseActionException; |
|
6
|
|
|
use eXpansion\Core\Model\UserGroups\Group; |
|
7
|
|
|
use Manialib\Manialink\Elements\Frame; |
|
8
|
|
|
use Manialib\Manialink\Elements\Label; |
|
9
|
|
|
use Manialib\Manialink\Elements\Quad; |
|
10
|
|
|
use Manialib\Manialink\Elements\Script; |
|
11
|
|
|
use Manialib\XML\Rendering\Renderer; |
|
12
|
|
|
|
|
13
|
|
|
class Window extends Manialink |
|
14
|
|
|
{ |
|
15
|
|
|
protected $manialink; |
|
16
|
|
|
|
|
17
|
|
|
protected $closeButton; |
|
18
|
|
|
|
|
19
|
|
|
public function __construct( |
|
20
|
|
|
Group $group, |
|
21
|
|
|
$name, |
|
22
|
|
|
$sizeX, |
|
23
|
|
|
$sizeY, |
|
24
|
|
|
$posX = null, |
|
25
|
|
|
$posY = null |
|
26
|
|
|
) { |
|
27
|
|
|
parent::__construct($group, $name, $sizeX, $sizeY, $posX, $posY); |
|
28
|
|
|
|
|
29
|
|
|
$titleHeight = 5.5; |
|
30
|
|
|
$closeButtonWidth = 9.5; |
|
31
|
|
|
$closeButtonHighliteColor = "D30707ee"; |
|
32
|
|
|
$titlebarColor = "3afe"; |
|
33
|
|
|
|
|
34
|
|
|
$ml = new \Manialib\Manialink\Elements\Manialink(); |
|
35
|
|
|
$ml->setVersion(3); |
|
36
|
|
|
$ml->setAttribute('id', $this->getId()); |
|
37
|
|
|
$ml->setName($name); |
|
38
|
|
|
$window = Frame::create()->setId("Window")->setPosn($posX, $posY)->appendTo($ml); |
|
39
|
|
|
|
|
40
|
|
|
// titlebar text |
|
41
|
|
|
Label::create() |
|
42
|
|
|
->setPosn(3, -$titleHeight / 2) |
|
43
|
|
|
->setAlign("left", "center2") |
|
44
|
|
|
->setText($name) |
|
45
|
|
|
->setTextcolor("fff") |
|
46
|
|
|
->setTextsize(2) |
|
47
|
|
|
->setAttribute("textfont", "RajdhaniMono") |
|
48
|
|
|
->appendTo($window); |
|
49
|
|
|
|
|
50
|
|
|
|
|
51
|
|
|
// titlebar |
|
52
|
|
|
Quad::create() |
|
53
|
|
|
->setSizen($sizeX, 0.33) |
|
54
|
|
|
->setPosn(0, -$titleHeight) |
|
55
|
|
|
->setBgcolor("fff") |
|
56
|
|
|
->appendTo($window); |
|
57
|
|
|
|
|
58
|
|
|
Quad::create() |
|
59
|
|
|
->setSizen($sizeX / 4, 0.5) |
|
60
|
|
|
->setAlign("left", "bottom") |
|
61
|
|
|
->setPosn(0, -$titleHeight) |
|
62
|
|
|
->setBgcolor("fff") |
|
63
|
|
|
->appendTo($window); |
|
64
|
|
|
|
|
65
|
|
|
Quad::create() |
|
66
|
|
|
->setSizen($sizeX - $closeButtonWidth, $titleHeight) |
|
67
|
|
|
->setBgcolor($titlebarColor) |
|
68
|
|
|
->setId("Title") |
|
69
|
|
|
->setScriptevents() |
|
70
|
|
|
->appendTo($window); |
|
71
|
|
|
|
|
72
|
|
|
$this->closeButton = Label::create() |
|
73
|
|
|
->setId("Close") |
|
74
|
|
|
->setSizen($closeButtonWidth, $titleHeight) |
|
75
|
|
|
->setPosn($sizeX - $closeButtonWidth + ($closeButtonWidth / 2), -$titleHeight / 2) |
|
76
|
|
|
->setAlign("center", "center2") |
|
77
|
|
|
->setText("✖") |
|
78
|
|
|
->setScriptevents() |
|
79
|
|
|
->setTextcolor("fff") |
|
80
|
|
|
->setFocusareacolor1($titlebarColor) |
|
81
|
|
|
->setFocusareacolor2($closeButtonHighliteColor) |
|
82
|
|
|
->setTextSize(2) |
|
83
|
|
|
->setAttribute("textfont", "OswaldMono") |
|
84
|
|
|
->appendTo($window); |
|
85
|
|
|
|
|
86
|
|
|
//body |
|
87
|
|
|
Quad::create() |
|
88
|
|
|
->setSizen($sizeX, ($sizeY - $titleHeight)) |
|
89
|
|
|
->setPosn(0, -$titleHeight) |
|
90
|
|
|
->setStyle("Bgs1:BgWindow3") |
|
91
|
|
|
->appendTo($window); |
|
92
|
|
|
|
|
93
|
|
|
Quad::create() |
|
94
|
|
|
->setStyle("Bgs1InRace:BgButtonShadow") |
|
95
|
|
|
->setSizen($sizeX + 10, $sizeY + 10) |
|
96
|
|
|
->setPosn(-5, 5) |
|
97
|
|
|
->appendTo($window); |
|
98
|
|
|
|
|
99
|
|
|
|
|
100
|
|
|
$script = /** @lang textmate */ |
|
101
|
|
|
<<<'EOD' |
|
102
|
|
|
|
|
103
|
|
|
#Include "AnimLib" as AL |
|
104
|
|
|
|
|
105
|
|
|
main () { |
|
106
|
|
|
|
|
107
|
|
|
declare CMlFrame Window <=> (Page.GetFirstChild("Window") as CMlFrame); |
|
108
|
|
|
declare CMlQuad Titlebar <=> (Page.GetFirstChild("Title") as CMlQuad); |
|
109
|
|
|
declare CMlLabel CloseButton <=> (Page.GetFirstChild("Close") as CMlLabel); |
|
110
|
|
|
declare moveWindow = False; |
|
111
|
|
|
declare closeWindow = False; |
|
112
|
|
|
declare openWindow = False; |
|
113
|
|
|
declare Vec2 Offset = <0.0, 0.0 >; |
|
114
|
|
|
declare Real zIndex = 0.; |
|
115
|
|
|
declare Boolean MoveWindow = False; |
|
116
|
|
|
declare Integer lastAction = Now; |
|
117
|
|
|
|
|
118
|
|
|
while(True) { |
|
119
|
|
|
yield; |
|
120
|
|
|
|
|
121
|
|
|
if (openWindow) { |
|
122
|
|
|
AnimMgr.Add(Window, "<frame scale=\"1.\" />", 200, CAnimManager::EAnimManagerEasing::SineIn); |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
if (closeWindow) { |
|
126
|
|
|
AnimMgr.Add(Window, "<frame scale=\"0.\" />", 200, CAnimManager::EAnimManagerEasing::SineOut); |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
if (openWindow && lastAction + 200 <= Now ) { |
|
130
|
|
|
openWindow = False; |
|
131
|
|
|
lastAction = 0; |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
if (closeWindow && lastAction + 200 <= Now ) { |
|
135
|
|
|
closeWindow = False; |
|
136
|
|
|
TriggerPageAction(CloseButton.DataAttributeGet("action")); |
|
137
|
|
|
continue; |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
if (MoveWindow) { |
|
141
|
|
|
Window.RelativePosition_V3.X = MouseX + Offset.X; |
|
142
|
|
|
Window.RelativePosition_V3.Y = MouseY + Offset.Y; |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
if (PendingEvents.count != 0) { |
|
146
|
|
|
foreach (Event in PendingEvents) { |
|
147
|
|
|
if ( (Event.Type == CMlEvent::Type::MouseClick && Event.ControlId == "Close") || |
|
148
|
|
|
(Event.Type == CMlEvent::Type::KeyPress && Event.KeyCode == 35) ) { |
|
149
|
|
|
closeWindow = True; |
|
150
|
|
|
lastAction = Now; |
|
151
|
|
|
} |
|
152
|
|
|
|
|
153
|
|
|
if ( (Event.Type == CMlEvent::Type::MouseClick && Event.ControlId == "Open") ) { |
|
154
|
|
|
lastAction = Now; |
|
155
|
|
|
openWindow = True; |
|
156
|
|
|
} |
|
157
|
|
|
} |
|
158
|
|
|
} |
|
159
|
|
|
|
|
160
|
|
|
if (MouseLeftButton == True) { |
|
161
|
|
|
foreach (Event in PendingEvents) { |
|
162
|
|
|
if (Event.Type == CMlEvent::Type::MouseClick && Event.ControlId == "Title") { |
|
163
|
|
|
Offset = <Window.RelativePosition_V3.X - MouseX, Window.RelativePosition_V3.Y - MouseY>; |
|
164
|
|
|
MoveWindow = True; |
|
165
|
|
|
} |
|
166
|
|
|
} |
|
167
|
|
|
} else { |
|
168
|
|
|
MoveWindow = False; |
|
169
|
|
|
} |
|
170
|
|
|
|
|
171
|
|
|
} |
|
172
|
|
|
|
|
173
|
|
|
} |
|
174
|
|
|
EOD; |
|
175
|
|
|
Script::create()->setNodeValue($script)->appendTo($ml); |
|
176
|
|
|
$this->manialink = $ml; |
|
177
|
|
|
} |
|
178
|
|
|
|
|
179
|
|
|
public function setCloseAction($actionId) |
|
180
|
|
|
{ |
|
181
|
|
|
$this->closeButton->setAttribute('data-action', $actionId); |
|
182
|
|
|
} |
|
183
|
|
|
|
|
184
|
|
|
public function getXml() |
|
185
|
|
|
{ |
|
186
|
|
|
if (empty($this->closeButton->getAttribute('data-action'))) |
|
187
|
|
|
{ |
|
188
|
|
|
throw new MissingCloseActionException("Close action is missing for window. Check if you are using the proper factory."); |
|
189
|
|
|
} |
|
190
|
|
|
|
|
191
|
|
|
$renderer = new Renderer(); |
|
192
|
|
|
return $renderer->getXML($this->manialink); |
|
193
|
|
|
} |
|
194
|
|
|
|
|
195
|
|
|
} |
|
196
|
|
|
|