-
Notifications
You must be signed in to change notification settings - Fork 2
/
hud_tournament_leaderboard.lua
263 lines (199 loc) · 7.96 KB
/
hud_tournament_leaderboard.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
local hudTimer = 0
local fade = 0
local addedStats = false
local function update()
if hudTimer > 0 then
hudTimer = hudTimer - 1
end
end
local function hud_black_bg()
local theme = get_selected_theme()
local screenWidth = djui_hud_get_screen_width()
local screenHeight = djui_hud_get_screen_height()
djui_hud_set_color(theme.background.r, theme.background.g, theme.background.b, fade)
djui_hud_render_rect(0, 0, screenWidth, screenHeight)
end
local function hud_tournament_leaderboard_text_render()
local theme = get_selected_theme()
local text = "Tournament Leaderboard"
if gGlobalSyncTable.tournamentPointSystem == TOURNAMENT_SYSTEM_POINT_LIMIT then
text = "Points needed to win: " .. gGlobalSyncTable.tournamentPointsReq
elseif gGlobalSyncTable.tournamentPointSystem == TOURNAMENT_SYSTEM_ROUND_LIMIT then
text = "Round's Remaining: " .. gGlobalSyncTable.tournamentRoundLimit - gGlobalSyncTable.tournamentRound
end
local screenWidth = djui_hud_get_screen_width()
local width = djui_hud_measure_text(text)
local x = (screenWidth - width) / 2
local y = 20
djui_hud_set_color(theme.text.r, theme.text.g, theme.text.b, fade)
djui_hud_print_text(text, x, y, 1)
end
local function hud_leaderboard()
local theme = get_selected_theme()
if hudTimer > 5 * 30 then
local winners = {}
local topPoints = 0
for i = 0, MAX_PLAYERS - 1 do
local np = gNetworkPlayers[i]
local s = gPlayerSyncTable[i]
if np.connected then
if s.tournamentPoints >= topPoints then
topPoints = s.tournamentPoints
end
end
end
for i = 0, MAX_PLAYERS - 1 do
local np = gNetworkPlayers[i]
local s = gPlayerSyncTable[i]
if np.connected and s.tournamentPoints >= topPoints then
table.insert(winners, i)
end
end
local winnerText = ""
for w = 1, #winners do
local i = winners[w]
winnerText = winnerText .. get_player_name(i) .. "\\#FFD700\\, and "
end
if not addedStats then
addedStats = true
if table.contains(winners, 0) then
stats.globalStats.totalTournamentWins = stats.globalStats.totalTournamentWins + 1
save_int("stats_global_totalTournamentWins", stats.globalStats.totalTournamentWins)
end
end
winnerText = winnerText:sub(1, #winnerText - 6) .. " won the Tournament!"
local textWidth = djui_hud_measure_text(strip_hex(winnerText))
djui_hud_set_color(theme.background.r, theme.background.g, theme.background.b, fade)
djui_hud_print_colored_text(winnerText, (djui_hud_get_screen_width() - textWidth) / 2 / 1.5, djui_hud_get_screen_height() / 2, 1.5, fade)
return
end
local renderedIndex = 0
local sortedPlayers = {}
for i = 0, MAX_PLAYERS - 1 do
if gNetworkPlayers[i].connected then
table.insert(sortedPlayers, i)
end
end
-- sort
table.sort(sortedPlayers, function (a, b)
return gPlayerSyncTable[a].tournamentPoints > gPlayerSyncTable[b].tournamentPoints
end)
local position = 1
for sp = 1, #sortedPlayers do
local i = sortedPlayers[sp]
if gNetworkPlayers[i].connected then
local screenWidth = djui_hud_get_screen_width()
local width = 1000
local x = (screenWidth - width) / 2
local y = 110 + (renderedIndex * 50)
djui_hud_set_color(theme.rect.r, theme.rect.g, theme.rect.b, fade)
djui_hud_render_rect_rounded_outlined(x, y - 5, width, 42, theme.rectOutline.r, theme.rectOutline.g, theme.rectOutline.b, 3, fade)
x = screenWidth / 2 - width / 2 + 10
render_player_head(i, x, y, 1.9, 1.9, fade)
x = x + 40
-- check the previous index and see if they tie, if they don't, increase position
if sortedPlayers[sp - 1] ~= nil and gPlayerSyncTable[i].tournamentPoints ~= gPlayerSyncTable[sortedPlayers[sp - 1]].tournamentPoints then
position = position + 1
end
local text = "#" .. position
if position == 1 then
djui_hud_set_color(255, 215, 0, fade)
elseif position == 2 then
djui_hud_set_color(169, 169, 169, fade)
elseif position == 3 then
djui_hud_set_color(205, 127, 50, fade)
else
djui_hud_set_color(theme.text.r, theme.text.g, theme.text.b, fade)
end
djui_hud_print_text(text, x, y, 1)
x = x + djui_hud_measure_text(text) + 10
text = get_player_name(i)
djui_hud_set_color(theme.text.r, theme.text.g, theme.text.b, fade)
djui_hud_print_colored_text(text, x, y, 1, fade)
text = "Points: " .. gPlayerSyncTable[i].tournamentPoints
local textWidth = djui_hud_measure_text(text)
x = screenWidth / 2 + width / 2 - textWidth - 10
djui_hud_set_color(theme.text.r, theme.text.g, theme.text.b, fade)
djui_hud_print_text(text, x, y, 1)
renderedIndex = renderedIndex + 1
end
end
end
local function hud_voting_begins_in()
local theme = get_selected_theme()
local text = tostring(math.floor(gGlobalSyncTable.displayTimer / 30) + 1) .. " seconds"
if gGlobalSyncTable.doVoting and gGlobalSyncTable.autoMode then
text = "Voting begins in " .. text
elseif gGlobalSyncTable.autoMode then
text = "Next round in " .. text
else
text = "Returning to lobby in " .. text
end
local x = 40
local y = 20
djui_hud_set_color(theme.text.r, theme.text.g, theme.text.b, fade)
djui_hud_print_text(text, x, y, 1)
end
local function hud_gamemode()
local theme = get_selected_theme()
local text = "Gamemode is set to " .. get_gamemode_including_random(gGlobalSyncTable.gamemode)
local screenWidth = djui_hud_get_screen_width()
local width = djui_hud_measure_text(strip_hex(text))
local x = screenWidth - width - 40
local y = 60
djui_hud_set_color(theme.text.r, theme.text.g, theme.text.b, fade)
djui_hud_print_colored_text(text, x, y, 1, fade)
end
local function hud_modifier()
local theme = get_selected_theme()
local text = "Modifier is set to " .. get_modifier_including_random()
local screenWidth = djui_hud_get_screen_width()
local width = djui_hud_measure_text(strip_hex(text))
local x = screenWidth - width - 40
local y = 20
djui_hud_set_color(theme.text.r, theme.text.g, theme.text.b, fade)
djui_hud_print_colored_text(text, x, y, 1, fade)
end
local function hud_render()
if gGlobalSyncTable.roundState ~= ROUND_TOURNAMENT_LEADERBOARD then
fade = 0
hudTimer = 5 * 30
-- see if someone has won
if has_tournament_ended() then
hudTimer = 10 * 30
end
return
end
-- set djui font and resolution
djui_hud_set_font(djui_menu_get_font())
djui_hud_set_resolution(RESOLUTION_DJUI)
-- render stuff
if hudTimer > 0.5 * 30 then
if fade < 255 then
fade = fade + 20
end
else
fade = fade - 20
if has_tournament_ended() then
gPlayerSyncTable[0].tournamentPoints = 0
gGlobalSyncTable.tournamentRound = 0
end
end
fade = clamp(fade, 0, 255)
hud_black_bg()
hud_tournament_leaderboard_text_render()
hud_leaderboard()
hud_voting_begins_in()
hud_gamemode()
hud_modifier()
end
---@param m MarioState
local function mario_update(m)
if m.playerIndex ~= 0 then return end
if gGlobalSyncTable.roundState ~= ROUND_TOURNAMENT_LEADERBOARD then return end
m.freeze = 1
set_mario_action(m, ACT_NOTHING, 0)
end
hook_event(HOOK_UPDATE, update)
hook_event(HOOK_ON_HUD_RENDER, hud_render)
hook_event(HOOK_MARIO_UPDATE, mario_update)