Completed
Pull Request — master (#210)
by
unknown
03:50
created

CustomUi::onApplicationInit()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
ccs 0
cts 2
cp 0
cc 1
eloc 1
nc 1
nop 0
crap 2
1
<?php
2
3
namespace eXpansion\Bundle\CustomUi\Plugins;
4
5
use eXpansion\Bundle\CustomUi\Plugins\Gui\CustomCheckpointWidget;
6
use eXpansion\Bundle\CustomUi\Plugins\Gui\CustomScoreboardWidget;
7
use eXpansion\Bundle\CustomUi\Plugins\Gui\CustomSpeedWidget;
8
use eXpansion\Framework\Core\DataProviders\Listener\ListenerInterfaceExpApplication;
9
use eXpansion\Framework\Core\Model\UserGroups\Group;
10
use eXpansion\Framework\Core\Plugins\StatusAwarePluginInterface;
11
use eXpansion\Framework\Core\Storage\Data\Player;
12
use eXpansion\Framework\Core\Storage\GameDataStorage;
13
use eXpansion\Framework\Core\Storage\PlayerStorage;
14
use eXpansion\Framework\GameManiaplanet\DataProviders\Listener\ListenerInterfaceMpLegacyPlayer;
15
use Maniaplanet\DedicatedServer\Connection;
16
17
18
class CustomUi implements ListenerInterfaceExpApplication, StatusAwarePluginInterface, ListenerInterfaceMpLegacyPlayer
19
{
20
    /** @var Connection */
21
    protected $connection;
22
    /**
23
     * @var PlayerStorage
24
     */
25
    private $playerStorage;
26
    /**
27
     * @var Group
28
     */
29
    private $allPlayers;
30
    /**
31
     * @var CustomSpeedWidget
32
     */
33
    private $customSpeedWidget;
34
    /**
35
     * @var CustomCheckpointWidget
36
     */
37
    private $customCheckpointWidget;
38
    /**
39
     * @var CustomScoreboardWidget
40
     */
41
    private $customScoreboardWidget;
42
43
    /**
44
     * @var Group
45
     */
46
    private $players;
47
    /**
48
     * @var GameDataStorage
49
     */
50
    private $gameDataStorage;
51
52
    /**
53
     * CustomUi constructor.
54
     *
55
     * @param Connection             $connection
56
     * @param PlayerStorage          $playerStorage
57
     * @param Group                  $allPlayers
58
     * @param Group                  $players
59
     * @param CustomSpeedWidget      $customSpeedWidget
60
     * @param CustomCheckpointWidget $customCheckpointWidget
61
     * @param CustomScoreboardWidget $customScoreboardWidget
62
     * @param GameDataStorage        $gameDataStorage
63
     */
64
    public function __construct(
65
        Connection $connection,
66
        PlayerStorage $playerStorage,
67
        Group $allPlayers,
68
        Group $players,
69
        CustomSpeedWidget $customSpeedWidget,
70
        CustomCheckpointWidget $customCheckpointWidget,
71
        CustomScoreboardWidget $customScoreboardWidget,
72
        GameDataStorage $gameDataStorage
73
74
    ) {
75
        $this->connection = $connection;
76
        $this->playerStorage = $playerStorage;
77
        $this->allPlayers = $allPlayers;
78
        $this->customSpeedWidget = $customSpeedWidget;
79
        $this->customCheckpointWidget = $customCheckpointWidget;
80
        $this->customScoreboardWidget = $customScoreboardWidget;
81
        $this->players = $players;
82
        $this->gameDataStorage = $gameDataStorage;
83
    }
84
85
    /**
86
     * Set the status of the plugin
87
     *
88
     * @param boolean $status
89
     *
90
     * @return void
91
     */
92
    public function setStatus($status)
93
    {
94
        if ($status) {
95
            $properties = /** @lang XML */
96
                <<<EOL
97
    <ui_properties>
98
 		<!-- The map name and author displayed in the top right of the screen when viewing the scores table -->
99
 		<map_info visible="false" pos="-160. 80. 150." />
100
 
101
 		<!-- Information about live envent displayed in the top right of the screen -->
102
 		<live_info visible="false" pos="-159. 84. 5." />
103
 
104
 		<!-- Information about the spectated player displayed in the bottom of the screen -->
105
 		<spectator_info visible="true" pos="-135. 80. 5." />
106
 
107
 		<!-- Only visible in solo modes, it hides the medal/ghost selection UI -->
108
 		<opponents_info visible="true" />
109
 		<!--
110
 			The server chat displayed on the bottom left of the screen
111
 			The offset values range from 0. to -3.2 for x and from 0. to 1.8 for y
112
 			The linecount property must be between 0 and 40
113
 			use offset 0 1.55 for upper corner 
114
 		-->
115
 		<chat visible="true" offset="0. 0." linecount="7" />
116
 		
117
 		<!-- Time of the players at the current checkpoint displayed at the bottom of the screen -->
118
 		<checkpoint_list visible="true" pos="48. -52. 5." />
119
 		
120
 		<!-- Small scores table displayed at the end of race of the round based modes (Rounds, Cup, ...) on the right of the screen -->
121
 		<round_scores visible="true" pos="-158.5 40. 5." />
122
 		
123
 		<!-- Race time left displayed at the bottom right of the screen -->
124
 		<countdown visible="false" pos="81. -63. 5." />
125
 		
126
 		<!-- 3, 2, 1, Go! message displayed on the middle of the screen when spawning --> 		
127
 		<go visible="true" />
128
 		
129
 		<!-- Current race chrono displayed at the bottom center of the screen -->
130
 		<chrono visible="true" pos="0. -80. -5." />
131
 		
132
 		<!-- Speed and distance raced displayed in the bottom right of the screen -->
133
 		<speed_and_distance visible="false" pos="137. -69. 5." />
134
 		
135
 		<!-- Previous and best times displayed at the bottom right of the screen -->
136
 		<personal_best_and_rank visible="false" pos="157. -24. 5." />
137
 		
138
 		<!-- Current position in the map ranking displayed at the bottom right of the screen -->
139
 		<position visible="false" pos="150.5 -28. 5." />
140
 		
141
 		<!-- Checkpoint time information displayed in the middle of the screen when crossing a checkpoint -->
142
 		<checkpoint_time visible="false" pos="0. 3. -10." />
143
 		
144
 		<!-- The avatar of the last player speaking in the chat displayed above the chat -->
145
 		<chat_avatar visible="false" />
146
 		
147
 		<!-- Warm-up progression displayed on the right of the screen during warm-up -->
148
  		<warmup visible="true" pos="153. 13. 0." /> 		
149
 		
150
 		<!-- Ladder progression box displayed on the top of the screen at the end of the map --> 		
151
 		<endmap_ladder_recap visible="false" /> 		
152
 		
153
 		<!-- Laps count displayed on the right of the screen on multilaps map --> 		
154
 		<multilap_info visible="true" pos="140. 84. 5." />
155
 		
156
 		<!-- Player's ranking at the latest checkpoint --> 		
157
 		<checkpoint_ranking visible="false" pos="0. 84. 5." />
158
 		
159
 		<!-- Scores table displayed in the middle of the screen --> 		
160
 		<scorestable alt_visible="false" />
161
 		
162
 		<!-- Number of players spectating us displayed at the bottom right of the screen --> 		
163
 		<viewers_count visible="true" pos="157. -40. 5." /> 	
164
 	</ui_properties>
165
EOL;
166
167
            $this->connection->triggerModeScriptEvent('Trackmania.UI.SetProperties', [$properties]);
168
            $this->connection->triggerModeScriptEvent('Shootmania.UI.SetProperties', [$properties]);
169
170
            $this->customScoreboardWidget->create($this->allPlayers);
171
172
            if ($this->gameDataStorage->getTitle() == "TM") {
173
                $this->customSpeedWidget->create($this->allPlayers);
174
                $this->customCheckpointWidget->create($this->allPlayers);
175
            }
176
177
        } else {
178
            $this->customSpeedWidget->destroy($this->allPlayers);
179
            $this->customCheckpointWidget->destroy($this->allPlayers);
180
        }
181
    }
182
183
    /**
184
     * called at eXpansion init
185
     *
186
     * @return void
187
     */
188
    public function onApplicationInit()
189
    {
190
        // do nothing
191
    }
192
193
    /**
194
     * called when init is done and callbacks are enabled
195
     *
196
     * @return void
197
     * @throws \Maniaplanet\DedicatedServer\InvalidArgumentException
198
     */
199
    public function onApplicationReady()
200
    {
201
202
203
    }
204
205
    /**
206
     * called when requesting application stop
207
     *
208
     * @return void
209
     */
210
    public function onApplicationStop()
211
    {
212
        // do nothing
213
    }
214
215
    public function onPlayerConnect(Player $player)
216
    {
217
        // do nothing
218
    }
219
220
    public function onPlayerDisconnect(Player $player, $disconnectionReason)
221
    {
222
        // do nothing
223
    }
224
225
    public function onPlayerInfoChanged(Player $oldPlayer, Player $player)
226
    {
227
        // do nothing
228
    }
229
230
    public function onPlayerAlliesChanged(Player $oldPlayer, Player $player)
231
    {
232
        // do nothing
233
    }
234
}
235