|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace eXpansion\Framework\Core\Model\Gui\Factory; |
|
4
|
|
|
|
|
5
|
|
|
use eXpansion\Framework\Core\Model\Gui\ManialinkInterface; |
|
6
|
|
|
use eXpansion\Framework\Core\Model\Gui\ManiaScriptFactory; |
|
7
|
|
|
use FML\Controls\Control; |
|
8
|
|
|
use FML\Controls\Frame; |
|
9
|
|
|
use FML\Controls\Label; |
|
10
|
|
|
use FML\Controls\Quad; |
|
11
|
|
|
use FML\ManiaLink; |
|
12
|
|
|
use FML\Types\Container; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Class WindowFrameFactory |
|
16
|
|
|
* |
|
17
|
|
|
* @author de Cramer Oliver<[email protected]> |
|
18
|
|
|
* @copyright 2017 Smile |
|
19
|
|
|
* @package eXpansion\Framework\Core\Model\Gui\Factory |
|
20
|
|
|
*/ |
|
21
|
|
|
class WindowFrameFactory |
|
22
|
|
|
{ |
|
23
|
|
|
/** @var ManiaScriptFactory */ |
|
24
|
|
|
protected $windowManiaScriptFactory; |
|
25
|
|
|
|
|
26
|
|
|
/** @var ManialinkInterface */ |
|
27
|
|
|
protected $manialinkInterface; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* WindowFrameFactory constructor. |
|
31
|
|
|
* |
|
32
|
|
|
* @param ManiaScriptFactory $maniaScriptFactory |
|
33
|
|
|
*/ |
|
34
|
|
|
public function __construct(ManiaScriptFactory $maniaScriptFactory) |
|
35
|
|
|
{ |
|
36
|
|
|
$this->windowManiaScriptFactory = $maniaScriptFactory; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Build the window frame content. |
|
41
|
|
|
* |
|
42
|
|
|
* @param ManiaLink $manialink |
|
43
|
|
|
* @param Frame|Container $mainFrame to build into |
|
44
|
|
|
* @param $name |
|
45
|
|
|
* @param float $sizeX Size of the inner frame to build the window frame around |
|
46
|
|
|
* @param float $sizeY Size of the inner frame to build the window frame around |
|
47
|
|
|
* @return Control |
|
48
|
|
|
*/ |
|
49
|
|
|
public function build(ManiaLink $manialink, Frame $mainFrame, $name, $sizeX, $sizeY) |
|
50
|
|
|
{ |
|
51
|
|
|
$titleHeight = 5.5; |
|
52
|
|
|
$closeButtonWidth = 9.5; |
|
53
|
|
|
$titlebarColor = "000e"; |
|
54
|
|
|
$titleTextColor = "eff"; |
|
55
|
|
|
|
|
56
|
|
|
// Creating sub frame to keep all the pieces together. |
|
57
|
|
|
$frame = new Frame(); |
|
58
|
|
|
$frame->setPosition(-2, ($titleHeight) + 2); |
|
59
|
|
|
$mainFrame->addChild($frame); |
|
60
|
|
|
|
|
61
|
|
|
// Size of the actual window. |
|
62
|
|
|
$sizeX += 4; |
|
63
|
|
|
$sizeY += $titleHeight + 2; |
|
64
|
|
|
|
|
65
|
|
|
// Title bar & title. |
|
66
|
|
|
$titleLabel = new Label(); |
|
67
|
|
|
$titleLabel->setPosition(3, -$titleHeight / 3 - 1) |
|
68
|
|
|
->setAlign(Label::LEFT, Label::CENTER2) |
|
69
|
|
|
->setTextId($name) |
|
70
|
|
|
->setTextColor($titleTextColor) |
|
71
|
|
|
->setTextSize(2) |
|
72
|
|
|
->setTranslate(true) |
|
73
|
|
|
->setTextFont('RajdhaniMono') |
|
74
|
|
|
->setId("TitleText"); |
|
75
|
|
|
$frame->addChild($titleLabel); |
|
76
|
|
|
|
|
77
|
|
|
$titleBar = new Quad(); |
|
78
|
|
|
$titleBar->setSize($sizeX, 0.33) |
|
79
|
|
|
->setPosition(0, -$titleHeight) |
|
80
|
|
|
->setBackgroundColor('fff'); |
|
81
|
|
|
$frame->addChild($titleBar); |
|
82
|
|
|
|
|
83
|
|
|
$titleBar = new Quad(); |
|
84
|
|
|
$titleBar->setSize($sizeX / 4, 0.5) |
|
85
|
|
|
->setPosition(0, -$titleHeight) |
|
86
|
|
|
->setBackgroundColor('fff'); |
|
87
|
|
|
$frame->addChild($titleBar); |
|
88
|
|
|
|
|
89
|
|
|
$titleBar = new Quad('Title'); |
|
90
|
|
|
$titleBar->setSize($sizeX - $closeButtonWidth, $titleHeight) |
|
91
|
|
|
->setBackgroundColor($titlebarColor) |
|
92
|
|
|
->setScriptEvents(true); |
|
93
|
|
|
$frame->addChild($titleBar); |
|
94
|
|
|
|
|
95
|
|
|
$closeButton = new Label('Close'); |
|
96
|
|
|
$closeButton->setSize($closeButtonWidth, $titleHeight) |
|
97
|
|
|
->setPosition($sizeX - $closeButtonWidth + ($closeButtonWidth / 2), -$titleHeight / 2) |
|
98
|
|
|
->setAlign(Label::CENTER, Label::CENTER2) |
|
99
|
|
|
->setText("✖") |
|
100
|
|
|
->setTextColor('fff') |
|
101
|
|
|
->setTextSize(2) |
|
102
|
|
|
->setTextFont('OswaldMono') |
|
103
|
|
|
->setScriptEvents(true) |
|
104
|
|
|
->setAreaColor($titlebarColor) |
|
105
|
|
|
->setAreaFocusColor('f22'); |
|
106
|
|
|
$frame->addChild($closeButton); |
|
107
|
|
|
|
|
108
|
|
|
//body |
|
109
|
|
|
$body = new Quad(); |
|
110
|
|
|
$body->setSize($sizeX, $sizeY - $titleHeight) |
|
111
|
|
|
->setPosition(0, -$titleHeight) |
|
112
|
|
|
->setBackgroundColor("222") |
|
113
|
|
|
->setOpacity(0.8); |
|
114
|
|
|
$frame->addChild($body); |
|
115
|
|
|
|
|
116
|
|
|
$body = new Quad(); |
|
117
|
|
|
$body->setSize($sizeX, $sizeY - $titleHeight) |
|
|
|
|
|
|
118
|
|
|
->setPosition(0, -$titleHeight) |
|
119
|
|
|
->setStyles('Bgs1', 'BgDialogBlur') |
|
120
|
|
|
->setId('WindowBg') |
|
121
|
|
|
->setScriptEvents(true); |
|
122
|
|
|
$frame->addChild($body); |
|
123
|
|
|
|
|
124
|
|
|
$body = new Quad(); |
|
125
|
|
|
$body->setSize($sizeX + 10, $sizeY + 10) |
|
126
|
|
|
->setPosition(-5, 5) |
|
127
|
|
|
->setStyles('Bgs1InRace', 'BgButtonShadow'); |
|
128
|
|
|
$frame->addChild($body); |
|
129
|
|
|
|
|
130
|
|
|
// Add maniascript for window handling. |
|
131
|
|
|
$manialink->addChild($this->windowManiaScriptFactory->createScript([''])); |
|
132
|
|
|
|
|
133
|
|
|
return $closeButton; |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
/** |
|
137
|
|
|
* @param ManialinkInterface $manialinkInterface |
|
138
|
|
|
*/ |
|
139
|
|
|
public function setManialinkInterface(ManialinkInterface $manialinkInterface) |
|
140
|
|
|
{ |
|
141
|
|
|
$this->manialinkInterface = $manialinkInterface; |
|
142
|
|
|
} |
|
143
|
|
|
} |
|
144
|
|
|
|
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: