1
1
local storage = minetest .get_mod_storage ()
2
2
local prev_match_summary = storage :get_string (" prev_match_summary" )
3
3
4
- local function render_per_team_stats (red , blue , stat , round )
4
+ -- Formspec element that governs table columns and their attributes
5
+ local tablecolumns = {
6
+ " tablecolumns[color;" ,
7
+ " text;" ,
8
+ " text,width=20;" ,
9
+ " text,width=4;" ,
10
+ " text,width=4;" ,
11
+ " text,width=4;" ,
12
+ " text,width=6;" ,
13
+ " text,width=6;" ,
14
+ " text,width=6;" ,
15
+ " text,width=6]"
16
+ }
17
+ tablecolumns = table.concat (tablecolumns , " " )
18
+
19
+ local function render_team_stats (red , blue , stat , round )
5
20
local red_stat , blue_stat = red [stat ], blue [stat ]
6
21
if round then
7
- red_stat = math.floor (red_stat * 10 )/ 10
8
- blue_stat = math.floor (blue_stat * 10 )/ 10
22
+ red_stat = math.floor (red_stat * 10 ) / 10
23
+ blue_stat = math.floor (blue_stat * 10 ) / 10
9
24
end
10
- return red_stat + blue_stat .. " (" .. minetest .colorize (red .color , tostring (red_stat )) .. " - " .. minetest .colorize (blue .color , tostring (blue_stat )) .. " )"
25
+ return red_stat + blue_stat .. " (" ..
26
+ minetest .colorize (red .color , tostring (red_stat )) .. " - " ..
27
+ minetest .colorize (blue .color , tostring (blue_stat )) .. " )"
11
28
end
12
29
13
30
function ctf_stats .get_formspec_match_summary (stats , winner_team , winner_player , time )
@@ -42,30 +59,32 @@ function ctf_stats.get_formspec_match_summary(stats, winner_team, winner_player,
42
59
end
43
60
44
61
local match_length = string.format (" %02d:%02d:%02d" ,
45
- math.floor (time / 3600 ), -- hours
46
- math.floor ((time % 3600 ) / 60 ), -- minutes
47
- math.floor (time % 60 )) -- seconds
62
+ math.floor (time / 3600 ), -- hours
63
+ math.floor ((time % 3600 ) / 60 ), -- minutes
64
+ math.floor (time % 60 )) -- seconds
48
65
49
66
local ret = ctf_stats .get_formspec (" Match Summary" , players , 1 )
50
67
51
68
if stats [winner_team ] then
52
69
local winner_color = ctf .flag_colors [winner_team ]:gsub (" 0x" , " #" )
53
70
ret = ret .. " item_image[0,0;1,1;ctf_flag:flag_top_" .. winner_team .. " ]"
54
- ret = ret .. " label[1,0;" .. minetest .colorize (winner_color , " TEAM " .. winner_team :upper () .. " WON!" ) .. " ]"
55
- ret = ret .. " label[1,0.5;Flag captured by " .. winner_player .. " ]"
71
+ ret = ret .. " label[1,0;" .. minetest .colorize (winner_color ,
72
+ " TEAM " .. winner_team :upper () .. " WON!" ) .. " ]"
73
+ ret = ret .. " label[1,0.5;Flag captured by " ..
74
+ minetest .colorize (winner_color , winner_player ) .. " ]"
56
75
else
57
76
ret = ret .. " label[1,0;NO WINNER]"
58
77
end
59
78
60
79
ret = ret .. " label[6.5,0;Kills]"
61
- ret = ret .. " label[8,0;" .. render_per_team_stats (red , blue , " kills" ) .. " ]"
80
+ ret = ret .. " label[8,0;" .. render_team_stats (red , blue , " kills" ) .. " ]"
62
81
ret = ret .. " label[6.5,0.5;Attempts]"
63
- ret = ret .. " label[8,0.5;" .. render_per_team_stats (red , blue , " attempts" ) .. " ]"
64
- ret = ret .. " label[9 .5,0;Duration]"
65
- ret = ret .. " label[11 ,0;" .. match_length .. " ]"
66
- ret = ret .. " label[9 .5,0.5;Total score]"
67
- ret = ret .. " label[11 ,0.5;" .. render_per_team_stats (red , blue , " score" , true ) .. " ]"
68
- ret = ret .. " label[3.5 ,7.2 ;Tip: type /rankings for league tables]"
82
+ ret = ret .. " label[8,0.5;" .. render_team_stats (red , blue , " attempts" ) .. " ]"
83
+ ret = ret .. " label[10 .5,0;Duration]"
84
+ ret = ret .. " label[12 ,0;" .. match_length .. " ]"
85
+ ret = ret .. " label[10 .5,0.5;Total score]"
86
+ ret = ret .. " label[12 ,0.5;" .. render_team_stats (red , blue , " score" , true ) .. " ]"
87
+ ret = ret .. " label[2 ,7.75 ;Tip: type /rankings for league tables]"
69
88
70
89
-- Set prev_match_summary and write to mod_storage
71
90
prev_match_summary = ret
@@ -79,15 +98,15 @@ function ctf_stats.get_formspec(title, players, header, hlt_name)
79
98
return one .score > two .score
80
99
end )
81
100
82
- local ret = " size[13, " .. 6.5 + header .. " ]"
101
+ local ret = " size[14, " .. 7 + header .. " ]"
83
102
ret = ret .. default .gui_bg .. default .gui_bg_img
84
103
ret = ret .. " container[0," .. header .. " ]"
85
104
86
- ret = ret .. " vertlabel[0,0 ;" .. title .. " ]"
87
- ret = ret .. " tablecolumns[color;text;text;text;text;text;text;text;text;text] "
105
+ ret = ret .. " vertlabel[0,1 ;" .. title .. " ]"
106
+ ret = ret .. tablecolumns
88
107
ret = ret .. " tableoptions[highlight=#00000000]"
89
- ret = ret .. " table[0.5,0;12 .25,6;scores;"
90
- ret = ret .. " #ffffff,,Player,Kills,Deaths,K/D ratio ,Bounty kills ,Captures,Attempts,Score"
108
+ ret = ret .. " table[0.5,0;13 .25,6.1 ;scores;"
109
+ ret = ret .. " #ffffff,,Player,Kills,Deaths,K/D,Bounty Kills ,Captures,Attempts,Score"
91
110
92
111
local player_in_top_50 = false
93
112
@@ -116,7 +135,11 @@ function ctf_stats.get_formspec(title, players, header, hlt_name)
116
135
" ," .. pstat .attempts ..
117
136
" ," .. math.floor (pstat .score * 10 ) / 10
118
137
end
138
+ ret = ret .. " ;-1]"
119
139
140
+ -- If hlt_name not in top 50, add a separate table
141
+ -- This would result in the player's score displayed at the bottom
142
+ -- of the list but yet be visible without having to scroll
120
143
if hlt_name and not player_in_top_50 then
121
144
local hlt_player , hlt_rank , hlt_kd
122
145
@@ -128,25 +151,34 @@ function ctf_stats.get_formspec(title, players, header, hlt_name)
128
151
end
129
152
end
130
153
131
- hlt_kd = hlt_player .kills
132
- if hlt_player .deaths > 1 then
133
- hlt_kd = hlt_kd / hlt_player .deaths
154
+ if hlt_player then
155
+ hlt_kd = hlt_player .kills
156
+ if hlt_player .deaths > 1 then
157
+ hlt_kd = hlt_kd / hlt_player .deaths
158
+ end
159
+
160
+ ret = ret .. tablecolumns
161
+ ret = ret .. " tableoptions[highlight=#00000000]"
162
+ ret = ret .. " table[0.5,6.1;13.25,0.4;hlt_score;"
163
+ ret = ret .. " #ffff00" ..
164
+ " ," .. hlt_rank ..
165
+ " ," .. hlt_player .name ..
166
+ " ," .. hlt_player .kills ..
167
+ " ," .. hlt_player .deaths ..
168
+ " ," .. math.floor (hlt_kd * 10 ) / 10 ..
169
+ " ," .. hlt_player .bounty_kills ..
170
+ " ," .. hlt_player .captures ..
171
+ " ," .. hlt_player .attempts ..
172
+ " ," .. math.floor (hlt_player .score * 10 ) / 10 .. " ;-1]"
134
173
end
135
- ret = ret ..
136
- " ," .. " #ffff00" ..
137
- " ," .. hlt_rank ..
138
- " ," .. hlt_player .name ..
139
- " ," .. hlt_player .kills ..
140
- " ," .. hlt_player .deaths ..
141
- " ," .. math.floor (hlt_kd * 10 ) / 10 ..
142
- " ," .. hlt_player .bounty_kills ..
143
- " ," .. hlt_player .captures ..
144
- " ," .. hlt_player .attempts ..
145
- " ," .. math.floor (hlt_player .score * 10 ) / 10
174
+ -- else
175
+ -- ret = ret .. "box[0.5,6.1;13.25,0.4;#101010]"
176
+ -- Adds a box where the extra table should be, in order to make it
177
+ -- appear as an extension of the main table, but the color can't be
178
+ -- matched, and looks slightly brighter or slightly darker than the table
146
179
end
147
180
148
- ret = ret .. " ;-1]"
149
- ret = ret .. " button_exit[0.5,6;3,1;close;Close]"
181
+ ret = ret .. " button_exit[10,6.5;3,1;close;Close]"
150
182
ret = ret .. " container_end[]"
151
183
return ret
152
184
end
0 commit comments