|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace eXpansion\Bundle\WidgetBestRecords\Plugins\Gui; |
|
4
|
|
|
|
|
5
|
|
|
use eXpansion\Bundle\LocalRecords\Model\Record; |
|
6
|
|
|
use eXpansion\Framework\Core\Helpers\Time; |
|
7
|
|
|
use eXpansion\Framework\Core\Model\Gui\ManialinkInterface; |
|
8
|
|
|
use eXpansion\Framework\Core\Model\Gui\Widget; |
|
9
|
|
|
use eXpansion\Framework\Core\Model\Gui\WidgetFactoryContext; |
|
10
|
|
|
use eXpansion\Framework\Core\Plugins\Gui\WidgetFactory; |
|
11
|
|
|
use eXpansion\Framework\Gui\Components\uiLabel; |
|
12
|
|
|
|
|
13
|
|
|
class BestRecordsWidgetFactory extends WidgetFactory |
|
14
|
|
|
{ |
|
15
|
|
|
/** @var string */ |
|
16
|
|
|
private $authorName; |
|
17
|
|
|
/** @var int */ |
|
18
|
|
|
private $authorTime; |
|
19
|
|
|
|
|
20
|
|
|
/** @var UiLabel */ |
|
21
|
|
|
private $lblDediNick; |
|
22
|
|
|
/** @var UiLabel */ |
|
23
|
|
|
private $lblDediTime; |
|
24
|
|
|
|
|
25
|
|
|
/** @var UiLabel */ |
|
26
|
|
|
private $lblAuthorNick; |
|
27
|
|
|
/** @var UiLabel */ |
|
28
|
|
|
private $lblAuthorTime; |
|
29
|
|
|
|
|
30
|
|
|
/** @var UiLabel */ |
|
31
|
|
|
private $lblLocalNick; |
|
32
|
|
|
/** @var UiLabel */ |
|
33
|
|
|
private $lblLocalTime; |
|
34
|
|
|
/** |
|
35
|
|
|
* @var Time |
|
36
|
|
|
*/ |
|
37
|
|
|
private $time; |
|
38
|
|
|
|
|
39
|
|
|
|
|
40
|
|
|
/*** |
|
41
|
|
|
* MenuFactory constructor. |
|
42
|
|
|
* |
|
43
|
|
|
* @param $name |
|
44
|
|
|
* @param $sizeX |
|
45
|
|
|
* @param $sizeY |
|
46
|
|
|
* @param null $posX |
|
47
|
|
|
* @param null $posY |
|
48
|
|
|
* @param WidgetFactoryContext $context |
|
49
|
|
|
* @param Time $time |
|
50
|
|
|
*/ |
|
51
|
|
|
public function __construct( |
|
52
|
|
|
$name, |
|
53
|
|
|
$sizeX, |
|
54
|
|
|
$sizeY, |
|
55
|
|
|
$posX, |
|
56
|
|
|
$posY, |
|
57
|
|
|
WidgetFactoryContext $context, |
|
58
|
|
|
Time $time |
|
59
|
|
|
|
|
60
|
|
|
) { |
|
61
|
|
|
parent::__construct($name, $sizeX, $sizeY, $posX, $posY, $context); |
|
62
|
|
|
$this->time = $time; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* @param int $authorTime |
|
67
|
|
|
*/ |
|
68
|
|
|
public function setAuthorTime($author, int $authorTime) |
|
69
|
|
|
{ |
|
70
|
|
|
$this->authorName = $author; |
|
71
|
|
|
$this->authorTime = $authorTime; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* @param Widget|ManialinkInterface $manialink |
|
76
|
|
|
*/ |
|
77
|
|
|
protected function createContent(ManialinkInterface $manialink) |
|
78
|
|
|
{ |
|
79
|
|
|
parent::createContent($manialink); |
|
80
|
|
|
|
|
81
|
|
|
$line = $this->uiFactory->createLayoutLine(0, 0, [], 0.5); |
|
82
|
|
|
$lbl = $this->createLabel("Author", "0017")->setSize(15, 4); |
|
83
|
|
|
$line->addChild($lbl); |
|
84
|
|
|
|
|
85
|
|
|
$this->lblAuthorNick = $this->createLabel("n/a", "0023")->setSize(33, 4); |
|
|
|
|
|
|
86
|
|
|
$line->addChild($this->lblAuthorNick); |
|
87
|
|
|
|
|
88
|
|
|
$this->lblAuthorTime = $this->createLabel("-:--:---", "0015")->setSize(12, 4); |
|
|
|
|
|
|
89
|
|
|
|
|
90
|
|
|
$line->addChild($this->lblAuthorTime); |
|
91
|
|
|
$manialink->addChild($line); |
|
92
|
|
|
|
|
93
|
|
|
$line2 = $this->uiFactory->createLayoutLine(0, -4.45, [], 0.5); |
|
94
|
|
|
|
|
95
|
|
|
$lbl = $this->createLabel("Record", "0017")->setSize(15, 4); |
|
96
|
|
|
$line2->addChild($lbl); |
|
97
|
|
|
|
|
98
|
|
|
$this->lblLocalNick = $this->createLabel("n/a", "0023")->setSize(33, 4); |
|
|
|
|
|
|
99
|
|
|
$line2->addChild($this->lblLocalNick); |
|
100
|
|
|
|
|
101
|
|
|
$this->lblLocalTime = $this->createLabel("-:--:---", "0015")->setSize(12, 4); |
|
|
|
|
|
|
102
|
|
|
$line2->addChild($this->lblLocalTime); |
|
103
|
|
|
$manialink->addChild($line2); |
|
104
|
|
|
|
|
105
|
|
|
$line3 = $this->uiFactory->createLayoutLine(0, -9.0, [], 0.5); |
|
106
|
|
|
|
|
107
|
|
|
$lbl = $this->createLabel("Dedimania", "0017")->setSize(15, 4); |
|
108
|
|
|
$line3->addChild($lbl); |
|
109
|
|
|
|
|
110
|
|
|
$this->lblDediNick = $this->createLabel("n/a", "0023")->setSize(33, 4); |
|
|
|
|
|
|
111
|
|
|
$line3->addChild($this->lblDediNick); |
|
112
|
|
|
|
|
113
|
|
|
$this->lblDediTime = $this->createLabel("-:--:---", "0015")->setSize(12, 4); |
|
|
|
|
|
|
114
|
|
|
$line3->addChild($this->lblDediTime); |
|
115
|
|
|
$manialink->addChild($line3); |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
private function createLabel($text, $color) |
|
119
|
|
|
{ |
|
120
|
|
|
return $this->uiFactory->createLabel($text, UiLabel::TYPE_NORMAL)->setTranslate(false) |
|
121
|
|
|
->setAlign("left", "center2")->setTextSize(1)->setScriptEvents(true) |
|
122
|
|
|
->setAreaColor($color)->setAreaFocusColor($color)->setTextColor("eff")->setTextPrefix(" "); |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
|
|
126
|
|
|
public function setLocalRecord($record) |
|
127
|
|
|
{ |
|
128
|
|
|
if ($record instanceof Record) { |
|
|
|
|
|
|
129
|
|
|
try { |
|
130
|
|
|
$this->lblLocalNick->setText($record->getPlayer()->getNicknameStripped()); |
|
131
|
|
|
$this->lblLocalTime->setText($this->time->timeToText($record->getScore(), true)); |
|
132
|
|
|
} catch (\Exception $e) { |
|
|
|
|
|
|
133
|
|
|
|
|
134
|
|
|
} |
|
135
|
|
|
} else { |
|
136
|
|
|
$this->lblLocalNick->setText(""); |
|
137
|
|
|
$this->lblLocalTime->setText("-:--.---"); |
|
138
|
|
|
} |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
protected function updateContent(ManialinkInterface $manialink) |
|
142
|
|
|
{ |
|
143
|
|
|
$this->lblAuthorTime->setText($this->time->timeToText($this->authorTime, true)); |
|
144
|
|
|
$this->lblAuthorNick->setText($this->authorName); |
|
145
|
|
|
} |
|
146
|
|
|
|
|
147
|
|
|
|
|
148
|
|
|
} |
|
149
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..