|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace eXpansion\Framework\Core\Model\Gui; |
|
4
|
|
|
|
|
5
|
|
|
use eXpansion\Framework\Core\Exceptions\Gui\MissingCloseActionException; |
|
6
|
|
|
use eXpansion\Framework\Core\Helpers\Translations; |
|
7
|
|
|
use eXpansion\Framework\Core\Model\UserGroups\Group; |
|
8
|
|
|
use FML\Controls\Frame; |
|
9
|
|
|
use FML\Controls\Label; |
|
10
|
|
|
use FML\Controls\Quad; |
|
11
|
|
|
use FML\Controls\Quads\Quad_Bgs1; |
|
12
|
|
|
use FML\Controls\Quads\Quad_Bgs1InRace; |
|
13
|
|
|
use FML\Elements\Dico; |
|
14
|
|
|
use FML\Elements\Format; |
|
15
|
|
|
use FML\Types\Container; |
|
16
|
|
|
use FML\Types\Renderable; |
|
17
|
|
|
|
|
18
|
|
|
class Window extends Widget implements Container |
|
19
|
|
|
{ |
|
20
|
3 |
|
public function __construct( |
|
21
|
|
|
Group $group, |
|
22
|
|
|
ManiaScriptFactory $windowManiaScriptFactory, |
|
23
|
|
|
Translations $translationHelper, |
|
24
|
|
|
$name, |
|
25
|
|
|
$sizeX, |
|
26
|
|
|
$sizeY, |
|
27
|
|
|
$posX = null, |
|
28
|
|
|
$posY = null |
|
29
|
|
|
) |
|
30
|
|
|
{ |
|
31
|
3 |
|
parent::__construct($group, $translationHelper, $name, $sizeX, $sizeY, $posX, $posY); |
|
32
|
|
|
|
|
33
|
3 |
|
$this->translationHelper = $translationHelper; |
|
34
|
3 |
|
$windowFrame = $this->windowFrame; |
|
35
|
|
|
|
|
36
|
3 |
|
$titleHeight = 5.5; |
|
37
|
3 |
|
$closeButtonWidth = 9.5; |
|
38
|
3 |
|
$titlebarColor = "3afe"; |
|
39
|
|
|
|
|
40
|
|
|
// Frame to handle the content of the window. |
|
41
|
3 |
|
$this->contentFrame->setPosition(2, -$titleHeight - 2); |
|
42
|
3 |
|
$this->contentFrame->setSize($sizeX - 4, $sizeY - $titleHeight - 4); |
|
43
|
3 |
|
$windowFrame->addChild($this->contentFrame); |
|
44
|
|
|
|
|
45
|
|
|
// Title bar & title. |
|
46
|
3 |
|
$titleLabel = new Label(); |
|
47
|
3 |
|
$titleLabel->setPosition(3, -$titleHeight / 3 - 1) |
|
48
|
3 |
|
->setAlign(Label::LEFT, Label::CENTER2) |
|
49
|
3 |
|
->setTextId($name) |
|
50
|
3 |
|
->setTextColor('fff') |
|
51
|
3 |
|
->setTextSize(2) |
|
52
|
3 |
|
->setTranslate(true) |
|
53
|
3 |
|
->setTextFont('RajdhaniMono') |
|
54
|
3 |
|
->setId("TitleText"); |
|
55
|
3 |
|
$windowFrame->addChild($titleLabel); |
|
56
|
|
|
|
|
57
|
3 |
|
$titleBar = new Quad(); |
|
58
|
3 |
|
$titleBar->setSize($sizeX, 0.33) |
|
59
|
3 |
|
->setPosition(0, -$titleHeight) |
|
60
|
3 |
|
->setBackgroundColor('fff'); |
|
61
|
3 |
|
$windowFrame->addChild($titleBar); |
|
62
|
|
|
|
|
63
|
3 |
|
$titleBar = new Quad(); |
|
64
|
3 |
|
$titleBar->setSize($sizeX / 4, 0.5) |
|
65
|
3 |
|
->setPosition(0, -$titleHeight) |
|
66
|
3 |
|
->setBackgroundColor('fff'); |
|
67
|
3 |
|
$windowFrame->addChild($titleBar); |
|
68
|
|
|
|
|
69
|
3 |
|
$titleBar = new Quad('Title'); |
|
70
|
3 |
|
$titleBar->setSize($sizeX - $closeButtonWidth, $titleHeight) |
|
71
|
3 |
|
->setBackgroundColor($titlebarColor) |
|
72
|
3 |
|
->setScriptEvents(true); |
|
73
|
3 |
|
$windowFrame->addChild($titleBar); |
|
74
|
|
|
|
|
75
|
3 |
|
$this->closeButton = new Label('Close'); |
|
76
|
3 |
|
$this->closeButton->setSize($closeButtonWidth, $titleHeight) |
|
77
|
3 |
|
->setPosition($sizeX - $closeButtonWidth + ($closeButtonWidth / 2), -$titleHeight / 2) |
|
78
|
3 |
|
->setAlign(Label::CENTER, Label::CENTER2) |
|
79
|
3 |
|
->setText("✖") |
|
80
|
3 |
|
->setTextColor('fff') |
|
81
|
3 |
|
->setTextSize(2) |
|
82
|
3 |
|
->setTextFont('OswaldMono') |
|
83
|
3 |
|
->setScriptEvents(true) |
|
84
|
3 |
|
->setAreaColor('d00') |
|
85
|
3 |
|
->setAreaFocusColor('f22'); |
|
86
|
3 |
|
$windowFrame->addChild($this->closeButton); |
|
87
|
|
|
|
|
88
|
|
|
//body |
|
89
|
3 |
|
$body = new Quad_Bgs1(); |
|
90
|
3 |
|
$body->setSize($sizeX, $sizeY - $titleHeight) |
|
|
|
|
|
|
91
|
3 |
|
->setPosition(0, -$titleHeight) |
|
92
|
3 |
|
->setSubStyle(Quad_Bgs1::SUBSTYLE_BgWindow3) |
|
93
|
3 |
|
->setId('WindowBg') |
|
94
|
3 |
|
->setScriptEvents(true); |
|
95
|
3 |
|
$windowFrame->addChild($body); |
|
96
|
|
|
|
|
97
|
3 |
|
$body = new Quad_Bgs1InRace(); |
|
98
|
3 |
|
$body->setSize($sizeX + 10, $sizeY + 10) |
|
99
|
3 |
|
->setPosition(-5, 5) |
|
100
|
3 |
|
->setSubStyle(Quad_Bgs1InRace::SUBSTYLE_BgButtonShadow); |
|
101
|
3 |
|
$windowFrame->addChild($body); |
|
102
|
|
|
|
|
103
|
|
|
// Add maniascript for window handling. |
|
104
|
3 |
|
$this->manialink->addChild($windowManiaScriptFactory->createScript([''])); |
|
105
|
3 |
|
} |
|
106
|
|
|
|
|
107
|
|
|
/** |
|
108
|
|
|
* Set action to close the window. |
|
109
|
|
|
* |
|
110
|
|
|
* @param $actionId |
|
111
|
|
|
*/ |
|
112
|
1 |
|
public function setCloseAction($actionId) |
|
113
|
|
|
{ |
|
114
|
1 |
|
$this->closeButton->setDataAttributes(['action' => $actionId]); |
|
115
|
1 |
|
} |
|
116
|
|
|
|
|
117
|
2 |
|
public function getXml() |
|
118
|
|
|
{ |
|
119
|
2 |
|
if (empty($this->closeButton->getDataAttribute('action'))) { |
|
120
|
1 |
|
throw new MissingCloseActionException("Close action is missing for window. Check if you are using the proper factory."); |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
1 |
|
return parent::getXml(); |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
|
|
127
|
|
|
} |
|
128
|
|
|
|
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the parent class: