forked from zeph-yr/PartyExtensions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ButtonViewController.cs
408 lines (326 loc) · 14.9 KB
/
ButtonViewController.cs
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
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
using BeatSaberMarkupLanguage.Attributes;
using BeatSaberMarkupLanguage.Components;
using BeatSaberMarkupLanguage.Parser;
using BeatSaberMarkupLanguage.ViewControllers;
using HMUI;
using System;
namespace PartyExtensions
{
[HotReload(@"ButtonViewController.bsml")]
public partial class ButtonViewController : BSMLAutomaticViewController
{
//***********************************
// Leaderboard Buttons
//***********************************
[UIComponent("button_list")]
private CustomListTableData Button_List;
[UIAction("button_clicked")]
private void Button_Clicked(TableView tableView, int row)
{
Plugin.Log.Debug("button clicked: " + row);
// Order really matters as to when the hover hint is drawn
// Without this hover hints sometimes appear behind modal with contents are out of sync
parserParams.EmitEvent("close-modal");
Set_Modal_Content(row);
//Fill_Modal_Test();
parserParams.EmitEvent("open-modal"); // This is absolutely critical!! Not sure why but "button_clicked" doesn't work as show-event
Button_List.tableView.ClearSelection(); // Otherwise user has to click away and back if they want to open the same score again
}
private void Fill_Button_List()
{
Button_List.data.Clear();
for (int i = 0; i < 10; i++)
{
Button_List.data.Add(new CustomListTableData.CustomCellInfo("<#cc99ff>💟"));
}
Button_List.tableView.ReloadData();
Button_List.tableView.ClearSelection();
}
[UIAction("#post-parse")]
private void PostParse()
{
Fill_Button_List();
}
//***********************************
// Modal Panel
//***********************************
[UIParams]
private BSMLParserParams parserParams;
[UIComponent("modal")]
private ModalView Modal;
/*[UIComponent("modal_list")]
private CustomListTableData Modal_List;
private void Set_Modal_Content(int row)
{
Modal_List.data.Clear();
CustomLeaderboard temp;
// Possible scenario where scores exist on one leaderboard but not the other
// E.g. No score on daily (because new day) but exists in alltime
if (ButtonController.leaderboardType == LocalLeaderboardsModel.LeaderboardType.Daily)
{
if (PartyData.daily_scores.TryGetValue(ButtonController.current_leaderboard, out temp) == false)
{
Modal_List.data.Add(new CustomListTableData.CustomCellInfo($"No data for this score"));
Modal_List.tableView.ReloadData();
Modal_List.tableView.ClearSelection();
Set_Empty_Fields();
return;
}
}
else
{
if (PartyData.all_scores.TryGetValue(ButtonController.current_leaderboard, out temp) == false)
{
Modal_List.data.Add(new CustomListTableData.CustomCellInfo($"No data for this score"));
Modal_List.tableView.ReloadData();
Modal_List.tableView.ClearSelection();
Set_Empty_Fields();
return;
}
}
// For the dummy placeholder scores in data files
if (temp.map_scores[row].playername == "")
{
Modal_List.data.Add(new CustomListTableData.CustomCellInfo($"No data for this score"));
Set_Empty_Fields();
}
else
{
temp_playername = temp.map_scores[row].playername;
Playername = "changed";
temp_raw_score =temp.map_scores[row].raw_score.ToString("N0");
Raw_Score = "changed";
if (temp.map_scores[row].fc)
{
temp_rank = temp.map_scores[row].rank + " - FC";
}
else
{
temp_rank = temp.map_scores[row].rank;
}
Rank = "changed";
temp_acc = String.Format("{0:0.00}", temp.map_scores[row].acc) + "%";
Acc = "changed";
// Display only if GPM used
if (CustomScoreData.Read_Custom_Gameplaymodifiers(temp.map_scores[row].custom_gameplaymodifiers) == "None")
{
temp_mod_score = "<#b3b3cc>Mod: <#ffffff>---";
temp_mod_acc = "<#b3b3cc>Mod: <#ffffff>---";
}
else
{
temp_mod_score = "<#b3b3cc>Mod: <#ffffff>" + temp.map_scores[row].mod_score.ToString("N0");
temp_mod_acc = "<#b3b3cc>Mod: <#ffffff>" + String.Format("{0:0.00}", temp.map_scores[row].mod_acc) + "%";
}
Mod_Score = "changed";
Mod_Acc = "changed";
//Modal_List.data.Add(new CustomListTableData.CustomCellInfo($"<#ffff00ff>{temp.map_scores[row].playername}"));
//Modal_List.data.Add(new CustomListTableData.CustomCellInfo($""));
//Modal_List.data.Add(new CustomListTableData.CustomCellInfo($"Rank: {temp.map_scores[row].rank}"));
// Avg Acc
//Modal_List.data.Add(new CustomListTableData.CustomCellInfo($"Accuracy: " + String.Format("{0:0.00}", temp.map_scores[row].acc) + " - " + String.Format("{0:0.00}", temp.map_scores[row].acc / 115 * 100) + "%"));
//Modal_List.data.Add(new CustomListTableData.CustomCellInfo($"Accuracy: " + String.Format("{0:0.00}", temp.map_scores[row].acc) + "%"));
Modal_List.data.Add(new CustomListTableData.CustomCellInfo($"<#b3b3cc>Date Set: <#ffffff>{Convert_Timestamp(temp.map_scores[row].timestamp)}"));
Modal_List.data.Add(new CustomListTableData.CustomCellInfo($"<#b3b3cc>Accuracy: <#ff0000>" + String.Format("{0:0.00}", temp.map_scores[row].left_acc) + " <#ffffff>- <#1a53ff>" + String.Format("{0:0.00}", temp.map_scores[row].right_acc)));
Modal_List.data.Add(new CustomListTableData.CustomCellInfo($"<#b3b3cc>Max Combo: <#ffffff>{temp.map_scores[row].longest_combo}"));
Modal_List.data.Add(new CustomListTableData.CustomCellInfo($"<#b3b3cc>Good Cuts: <#ffffff>{temp.map_scores[row].longest_combo}"));
Modal_List.data.Add(new CustomListTableData.CustomCellInfo($"<#b3b3cc>Bad Cuts: <#ffffff>{temp.map_scores[row].bad_cuts}"));
Modal_List.data.Add(new CustomListTableData.CustomCellInfo($"<#b3b3cc>Missed: <#ffffff>{temp.map_scores[row].missed}"));
Modal_List.data.Add(new CustomListTableData.CustomCellInfo($"<#b3b3cc>Bomb Hits: <#ffffff>{temp.map_scores[row].bombs}"));
Modal_List.data.Add(new CustomListTableData.CustomCellInfo($"<#b3b3cc>Modifiers: <#ffffff>{CustomScoreData.Read_Custom_Gameplaymodifiers(temp.map_scores[row].custom_gameplaymodifiers)}"));
}
Modal_List.tableView.ReloadData();
Modal_List.tableView.ClearSelection();
}*/
private void Set_Modal_Content(int row)
{
Set_Empty_Fields();
CustomLeaderboard temp;
// Possible scenario where scores exist on one leaderboard but not the other
// E.g. No score on daily (because new day) but exists in alltime
if (ButtonController.leaderboardType == LocalLeaderboardsModel.LeaderboardType.Daily)
{
if (PartyData.daily_scores.TryGetValue(ButtonController.current_leaderboard, out temp) == false)
{
return;
}
}
else
{
if (PartyData.all_scores.TryGetValue(ButtonController.current_leaderboard, out temp) == false)
{
return;
}
}
// A real score and not a dummy placeholder scores in data files
if (temp.map_scores[row].playername == "")
{
return;
}
temp_playername = temp.map_scores[row].playername;
Playername = "changed";
temp_raw_score = temp.map_scores[row].raw_score.ToString("N0");
Raw_Score = "changed";
if (temp.map_scores[row].fc)
{
temp_rank = temp.map_scores[row].rank + " - FC";
}
else
{
temp_rank = temp.map_scores[row].rank;
}
Rank = "changed";
temp_acc = String.Format("{0:0.00}", temp.map_scores[row].acc) + "%";
Acc = "changed";
// Display only if GPM used
if (CustomScoreData.Read_Custom_Gameplaymodifiers(temp.map_scores[row].custom_gameplaymodifiers) == "None")
{
temp_mod_score = "<#b3b3cc>Mod: <#ffffff>---";
temp_mod_acc = "<#b3b3cc>Mod: <#ffffff>---";
}
else
{
temp_mod_score = "<#b3b3cc>Mod: <#ffffff>" + temp.map_scores[row].mod_score.ToString("N0");
temp_mod_acc = "<#b3b3cc>Mod: <#ffffff>" + String.Format("{0:0.00}", temp.map_scores[row].mod_acc) + "%";
}
Mod_Score = "changed";
Mod_Acc = "changed";
temp_stats = "<#b3b3cc>Date Set: <#ffffff>" + Convert_Timestamp(temp.map_scores[row].timestamp) + "\n" +
"<#b3b3cc>Accuracy: <#ff0000>" + String.Format("{0:0.00}", temp.map_scores[row].left_acc) + " <#ffffff>- <#1a53ff>" + String.Format("{0:0.00}", temp.map_scores[row].right_acc) + "<#ffffff>, " + "<#ff0000>" + String.Format("{0:0.00}", temp.map_scores[row].left_mixed_acc) + " <#ffffff>- <#1a53ff>" + String.Format("{0:0.00}", temp.map_scores[row].right_mixed_acc) + "\n" +
"<#b3b3cc>Max Combo: <#ffffff>" + temp.map_scores[row].longest_combo + "\n" +
"<#b3b3cc>Good Cuts: <#ffffff>" + temp.map_scores[row].good_cuts + "\n" +
"<#b3b3cc>Bad Cuts: <#ffffff>" + temp.map_scores[row].bad_cuts + "\n" +
"<#b3b3cc>Missed: <#ffffff>" + temp.map_scores[row].missed + "\n" +
"<#b3b3cc>Bomb Hits: <#ffffff>" + temp.map_scores[row].bombs + "\n" +
"<#b3b3cc>Modifiers: <#ffffff>" + CustomScoreData.Read_Custom_Gameplaymodifiers(temp.map_scores[row].custom_gameplaymodifiers);
Stats = "changed";
//Plugin.Log.Debug(temp_stats);
temp_mod_hints = temp.map_scores[row].modifier_hints;
Mod_Hints = temp_mod_hints;
}
private string temp_playername = "";
private string temp_raw_score = "";
private string temp_mod_score = "";
private string temp_rank = "";
private string temp_acc = "";
private string temp_mod_acc = "";
private static string temp_stats = "";
private static string temp_mod_hints = "";
[UIValue("playername")]
private string Playername
{
get => temp_playername;
set
{
NotifyPropertyChanged();
}
}
[UIValue("raw_score")]
private string Raw_Score
{
get => temp_raw_score;
set
{
NotifyPropertyChanged();
}
}
[UIValue("mod_score")]
private string Mod_Score
{
get => temp_mod_score;
set
{
NotifyPropertyChanged();
}
}
[UIValue("rank")]
private string Rank
{
get => temp_rank;
set
{
NotifyPropertyChanged();
}
}
[UIValue("acc")]
private string Acc
{
get => temp_acc;
set
{
NotifyPropertyChanged();
}
}
[UIValue("mod_acc")]
private string Mod_Acc
{
get => temp_mod_acc;
set
{
NotifyPropertyChanged();
}
}
[UIValue("stats")]
private string Stats
{
get => temp_stats;
set
{
NotifyPropertyChanged();
}
}
[UIValue("mod_hints")]
private string Mod_Hints
{
get => temp_mod_hints;
set
{
temp_mod_hints = value;
NotifyPropertyChanged(nameof(Mod_Hints));
}
}
private void Set_Empty_Fields()
{
temp_playername = "";
Playername = "changed";
temp_raw_score = "";
temp_mod_score = "";
Raw_Score = "changed";
Mod_Score = "changed";
temp_rank = "";
Rank = "changed";
temp_acc = "";
Acc = "changed";
temp_mod_acc = "";
Mod_Acc = "changed";
temp_stats = "\nNo data for this score.\nPlay this map and set one now!\n\n\n\n<size=3><#ffff00>Special request for Aroc. Thanks!\n\n<size=2.5><#ff0080>http://github.com/zeph-yr/PartyExtensions \nZephyr#9125";
Stats = "changed";
temp_mod_hints = "This hasn't been played yet."; //Should never see this, but just in case
Mod_Hints = temp_mod_hints;
}
private static string Convert_Timestamp(long unix_timestamp)
{
// Unix timestamp is seconds past epoch
DateTime dateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
return dateTime.AddSeconds(unix_timestamp).ToLocalTime().ToString();
}
// Keep this note:
// Using the basegame gpm works right after playing a map, but the data file will randomly change to all false.
// For example, the LocalScores will have the correct set of gpm but DailyLocalScores will be all false, or vice versa.
// Maybe this is a reference and there is a race condition? Not sure so went the enum hardcode route to save time. Not worth figuring out.
// Modal_List.data.Add(new CustomListTableData.CustomCellInfo($"Modifiers: {Convert_GPM(temp.map_scores[row].modifiers)}"));
// Update: Convert_GPM used to be here. Moved to CustomScoreData for reuse
/*private void Fill_Modal_Test()
{
Plugin.Log.Debug("Fill Modal");
Modal_List.data.Clear();
for (int i = 0; i < 10; i++)
{
Modal_List.data.Add(new CustomListTableData.CustomCellInfo("-------"));
Plugin.Log.Debug("+++++++++++++++++");
}
Modal_List.tableView.ReloadData();
Modal_List.tableView.ClearSelection();
}*/
}
}