1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
|
4
|
|
|
namespace eXpansion\Bundle\Maps\Plugins\Gui; |
5
|
|
|
|
6
|
|
|
|
7
|
|
|
use eXpansion\Bundle\Maps\Plugins\Jukebox; |
8
|
|
|
use eXpansion\Bundle\Maps\Plugins\Maps; |
9
|
|
|
use eXpansion\Framework\AdminGroups\Helpers\AdminGroups; |
10
|
|
|
use eXpansion\Framework\Core\Helpers\Time; |
11
|
|
|
use eXpansion\Framework\Core\Helpers\TMString; |
12
|
|
|
use eXpansion\Framework\Core\Model\Gui\Grid\DataCollectionFactory; |
13
|
|
|
use eXpansion\Framework\Core\Model\Gui\Grid\GridBuilderFactory; |
14
|
|
|
use eXpansion\Framework\Core\Model\Gui\ManialinkInterface; |
15
|
|
|
use eXpansion\Framework\Core\Model\Gui\WindowFactoryContext; |
16
|
|
|
use eXpansion\Framework\Core\Plugins\Gui\GridWindowFactory; |
17
|
|
|
use eXpansion\Framework\Gui\Components\Button; |
18
|
|
|
use Maniaplanet\DedicatedServer\Structures\Map; |
19
|
|
|
|
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Class RecordsWindowFactory |
23
|
|
|
* |
24
|
|
|
* @package eXpansion\Bundle\LocalRecords\Plugins\Gui; |
25
|
|
|
* @author reaby |
26
|
|
|
*/ |
27
|
|
|
class MapsWindowFactory extends GridWindowFactory |
28
|
|
|
{ |
29
|
|
|
/** @var GridBuilderFactory */ |
30
|
|
|
protected $gridBuilderFactory; |
31
|
|
|
|
32
|
|
|
/** @var DataCollectionFactory */ |
33
|
|
|
protected $dataCollectionFactory; |
34
|
|
|
|
35
|
|
|
/** @var Time */ |
36
|
|
|
protected $timeFormatter; |
37
|
|
|
/** |
38
|
|
|
* @var Jukebox |
39
|
|
|
*/ |
40
|
|
|
private $jukeboxPlugin; |
41
|
|
|
/** |
42
|
|
|
* @var AdminGroups |
43
|
|
|
*/ |
44
|
|
|
private $adminGroups; |
45
|
|
|
/** |
46
|
|
|
* @var Maps |
47
|
|
|
*/ |
48
|
|
|
private $mapsPlugin; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* MapsWindowFactory constructor. |
52
|
|
|
* @param $name |
53
|
|
|
* @param $sizeX |
54
|
|
|
* @param $sizeY |
55
|
|
|
* @param null $posX |
56
|
|
|
* @param null $posY |
57
|
|
|
* @param WindowFactoryContext $context |
58
|
|
|
* @param GridBuilderFactory $gridBuilderFactory |
59
|
|
|
* @param DataCollectionFactory $dataCollectionFactory |
60
|
|
|
* @param Time $time |
61
|
|
|
* @param Jukebox $jukeboxPlugin |
62
|
|
|
* @param Maps $mapsPlugin |
63
|
|
|
* @param AdminGroups $adminGroups |
64
|
|
|
*/ |
65
|
|
View Code Duplication |
public function __construct( |
|
|
|
|
66
|
|
|
$name, |
67
|
|
|
$sizeX, |
68
|
|
|
$sizeY, |
69
|
|
|
$posX, |
70
|
|
|
$posY, |
71
|
|
|
WindowFactoryContext $context, |
72
|
|
|
GridBuilderFactory $gridBuilderFactory, |
73
|
|
|
DataCollectionFactory $dataCollectionFactory, |
74
|
|
|
Time $time, |
75
|
|
|
Jukebox $jukeboxPlugin, |
76
|
|
|
Maps $mapsPlugin, |
77
|
|
|
AdminGroups $adminGroups |
78
|
|
|
) { |
79
|
|
|
parent::__construct($name, $sizeX, $sizeY, $posX, $posY, $context); |
80
|
|
|
|
81
|
|
|
$this->gridBuilderFactory = $gridBuilderFactory; |
82
|
|
|
$this->dataCollectionFactory = $dataCollectionFactory; |
83
|
|
|
$this->timeFormatter = $time; |
84
|
|
|
$this->jukeboxPlugin = $jukeboxPlugin; |
85
|
|
|
$this->adminGroups = $adminGroups; |
86
|
|
|
$this->mapsPlugin = $mapsPlugin; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
public function callbackRemove(ManialinkInterface $manialink, $login, $params, $args) |
90
|
|
|
{ |
91
|
|
|
$this->mapsPlugin->removeMap($login, $args['wish']->uId); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
public function callbackWish(ManialinkInterface $manialink, $login, $params, $args) |
95
|
|
|
{ |
96
|
|
|
$this->jukeboxPlugin->add($login, $args['wish']->uId); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
public function setMaps($maps) |
100
|
|
|
{ |
101
|
|
|
$this->genericData = []; |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* @var string $i |
105
|
|
|
* @var Map $map |
106
|
|
|
*/ |
107
|
|
|
$i = 1; |
108
|
|
|
foreach ($maps as $uid => $map) { |
109
|
|
|
$this->genericData[] = [ |
110
|
|
|
'index' => $i++, |
111
|
|
|
'name' => TMString::trimControls($map->name), |
112
|
|
|
'author' => $map->author, |
113
|
|
|
'time' => $this->timeFormatter->timeToText($map->goldTime, true), |
114
|
|
|
'wish' => $map |
115
|
|
|
]; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* @param ManialinkInterface $manialink |
122
|
|
|
* @return void |
123
|
|
|
*/ |
124
|
|
|
protected function createGrid(ManialinkInterface $manialink) |
125
|
|
|
{ |
126
|
|
|
$this->setData($manialink, $this->genericData); |
127
|
|
|
|
128
|
|
|
$tooltip = $this->uiFactory->createTooltip(); |
129
|
|
|
$manialink->addChild($tooltip); |
130
|
|
|
|
131
|
|
|
$queueButton = $this->uiFactory->createButton('+', Button::TYPE_DECORATED); |
132
|
|
|
$queueButton->setTextColor("fff")->setSize(5, 5); |
133
|
|
|
$tooltip->addTooltip($queueButton, 'Adds map to jukebox'); |
134
|
|
|
|
135
|
|
|
$removeButton = $this->uiFactory->createButton('x', Button::TYPE_DECORATED); |
136
|
|
|
$removeButton->setBorderColor("f00")->setTextColor("fff")->setSize(5, 5); |
137
|
|
|
$tooltip->addTooltip($removeButton, 'Removes map from playlist'); |
138
|
|
|
|
139
|
|
|
$gridBuilder = $this->gridBuilderFactory->create(); |
140
|
|
|
$gridBuilder->setManialink($manialink) |
141
|
|
|
->setDataCollection($manialink->getData('dataCollection')) |
142
|
|
|
->setManialinkFactory($this) |
143
|
|
|
->addTextColumn( |
144
|
|
|
'index', |
145
|
|
|
'expansion_maps.gui.window.column.index', |
146
|
|
|
1, |
147
|
|
|
true, |
148
|
|
|
false |
149
|
|
|
)->addTextColumn( |
150
|
|
|
'name', |
151
|
|
|
'expansion_maps.gui.window.column.name', |
152
|
|
|
5, |
153
|
|
|
true, |
154
|
|
|
false |
155
|
|
|
)->addTextColumn( |
156
|
|
|
'author', |
157
|
|
|
'expansion_maps.gui.window.column.author', |
158
|
|
|
3, |
159
|
|
|
false |
160
|
|
|
)->addTextColumn( |
161
|
|
|
'time', |
162
|
|
|
'expansion_maps.gui.window.column.goldtime', |
163
|
|
|
2, |
164
|
|
|
true, |
165
|
|
|
false |
166
|
|
|
|
167
|
|
|
)->addActionColumn('wish', 'expansion_maps.gui.window.column.wish', 1, |
168
|
|
|
[$this, 'callbackWish'], $queueButton); |
169
|
|
|
|
170
|
|
|
if ($this->adminGroups->hasPermission($manialink->getUserGroup(), "admin")) { |
171
|
|
|
$gridBuilder->addActionColumn('index', 'expansion_maps.gui.window.column.remove', |
172
|
|
|
1, [$this, 'callbackRemove'], $removeButton); |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
$manialink->setData('grid', $gridBuilder); |
176
|
|
|
|
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
} |
180
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.