forked from Azurency/Civ6-UIFiles
-
Notifications
You must be signed in to change notification settings - Fork 1
/
GameSummaries_GameDetails.lua
1461 lines (1223 loc) · 39.8 KB
/
GameSummaries_GameDetails.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
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
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
-------------------------------------------------
-- Game Summaries Screen
-------------------------------------------------
include( "InstanceManager" );
include( "SupportFunctions" );
include( "PopupDialog" );
----------------------------------------------------------------
-- Utilities
----------------------------------------------------------------
function remove_if(arr, f)
local n = #arr;
local ni = 1;
for i = 1,n do
local v = arr[i];
if(f(v)) then
arr[i] = nil;
else
if(ni ~= i) then
arr[i] = nil;
arr[ni] = v;
end
ni = ni + 1;
end
end
end
-- Attempt to set a control's icon by enumerating an array.
function SetControlIcon(control, icons)
if(icons) then
local s = #icons;
for i = s, 1, -1 do
local v = icons[i];
if(control:TrySetIcon(v)) then
return true;
end
end
end
return false;
end
-- v[0]=Control, v[1]=Selected Control, v[2]=area to show when selected
g_TabControls = {
{Controls.OverviewTab, Controls.SelectedOverviewTab, Controls.OverviewTabPanel},
{Controls.GraphsTab, Controls.SelectedGraphsTab, Controls.GraphsTabPanel},
{Controls.ReportsTab, Controls.SelectedReportsTab, Controls.ReportsTabPanel}
};
g_HighlightsManager = InstanceManager:new("StatInstance", "Root", Controls.HighlightsStack);
g_StatisticsBlockManager = InstanceManager:new("StatBlockInstance", "RootStack", Controls.StatisticsStack);
g_PlayerManager = InstanceManager:new("PlayerInstance", "Button", Controls.PlayersStack);
g_GraphLegendManager = InstanceManager:new("GraphLegendInstance", "Root", Controls.GraphLegendStack);
g_ReportHeaderManager = InstanceManager:new("ReportHeaderInstance", "Root", Controls.ReportHeaderStack);
g_ReportRowManager = InstanceManager:new("ReportRowInstance", "Root", Controls.ReportStack);
g_ReportCellManagers ={}
g_StatisticsManagers = {};
g_GameId = nil; -- Hall of Fame Game Id for getting details and graphs.
g_GameData = nil;
g_GameObjects = nil; -- Map of game objects by object id.
g_GamePlayers = nil; -- Map of game players by object id.
g_AvailableContexts = nil; -- The available overview contexts.
g_OverviewContext = nil; -- The current overview context.
g_RulesetPlayers = nil; -- Map of all ruleset playable leaders
g_RulesetTypes = nil; -- Map of all ruleset types.
g_RulesetVictories = nil; -- Map/Array of all ruleset victories.
g_Categories = nil; -- Sorted array of all statistics categories.
g_Statistics = nil; -- Sorted array of all statistics.
g_Graphs = nil; -- All graph data for the game, organized by groups.
g_GraphGroup = nil; -- The currently selected group.
g_Graph = nil; -- The currently selected graph.
g_GraphLegendColors = nil; -- The currently chosen colors for graph legends.
g_GraphDataSets = nil; -- Currently allocated datasets.
g_Reports = nil; -- All reports for the game, organized by groups.
g_ReportsGroup = nil; -- The currently selected report group.
g_Report = nil; -- The currently selected report.
REPORT_CELL_WIDTH = 136;
-- Release global cache to free up memory.
function DumpGlobalCache()
g_GameId = nil;
g_GameData = nil;
g_GameObjects = nil;
g_GamePlayers = nil;
g_GameStatistics = nil;
g_AvailableContexts = nil;
g_OverviewContext = nil;
g_RulesetPlayers = nil;
g_RulesetTypes = nil;
g_RulesetVictories = nil;
g_Categories = nil;
g_Statistics = nil;
g_Graphs = nil;
g_GraphGroup = nil;
g_Graph = nil;
g_GraphLegendColors = nil;
g_GraphDataSets = nil;
g_Reports = nil;
g_ReportsGroup = nil;
g_Report = nil;
end
function DumpInstances()
for i,v in ipairs(g_StatisticsManagers) do
v:ResetInstances();
end
for i,v in ipairs(g_ReportCellManagers) do
v:ResetInstances();
end
g_HighlightsManager:ResetInstances();
g_StatisticsBlockManager:ResetInstances();
g_PlayerManager:ResetInstances();
g_GraphLegendManager:ResetInstances();
g_ReportHeaderManager:ResetInstances();
g_ReportRowManager:ResetInstances();
-- TODO: Reset instances in pulldowns.
g_StatisticsManagers = {};
end
-- Much of hall of fame is read-only and static so it can be cached.
function UpdateGlobalCache()
DumpGlobalCache();
local params = ContextPtr:GetPopupParameters();
if (params) then
g_GameId = params:GetValue("GameId");
end
g_GameId = g_GameId or 1;
g_GameData = HallofFame.GetGameData(g_GameId);
local gameObjects = HallofFame.GetGameObjects(g_GameId);
g_GameObjects = {};
for i,v in ipairs(gameObjects) do
g_GameObjects[v.ObjectId] = v;
end
g_GamePlayers = {};
for i,v in ipairs(g_GameData.Players) do
g_GamePlayers[v.PlayerObjectId] = v;
end
local ruleset = g_GameData.Ruleset;
local players = HallofFame.GetRulesetPlayableLeaders(ruleset);
g_RulesetPlayers = {};
for i,v in ipairs(players) do
g_RulesetPlayers[v.LeaderType] = v;
end
g_RulesetTypes = HallofFame.GetRulesetTypes(ruleset);
local victoryProgress = HallofFame.GetVictoryProgress(ruleset);
g_RulesetVictories = {};
for k,v in pairs(victoryProgress) do
-- Localize Name
v.Name = Locale.Lookup(v.Name);
v.Icons = {"ICON_VICTORY_UNIVERSAL"};
table.insert(v.Icons, "ICON_" .. v.Type);
table.insert(v.Icons, v.Icon);
-- Store in an array to be sorted.
table.insert(g_RulesetVictories, v);
-- Store as id lookup as well.
g_RulesetVictories[v.Type] = v;
end
table.sort(g_RulesetVictories, function(a,b)
return Locale.Compare(a.Name, b.Name) == -1;
end);
local indexed_categories = {};
g_Categories = HallofFame.GetStatisticsCategories();
for i,v in ipairs(g_Categories) do
indexed_categories[v.Category] = v;
v.Name = v.Name and Locale.Lookup(v.Name) or "";
end
table.sort(g_Categories, function(a,b)
if(a.SortIndex ~= b.SortIndex) then
return a.SortIndex < b.SortIndex;
else
return Locale.Compare(a.Name,b.Name) == -1;
end
end);
g_Statistics = {};
local statistics = HallofFame.GetStatistics();
for i,stat in ipairs(statistics) do
local cat = indexed_categories[stat.Category];
if(cat and not cat.IsHidden) then
stat.Name = Locale.Lookup(stat.Name);
table.insert(g_Statistics, stat);
end
end
table.sort(g_Statistics, function(a,b)
if(a.Importance ~= b.Importance) then
return a.Importance > b.Importance;
else
return Locale.Compare(a.Name, b.Name) == -1;
end
end);
g_AvailableContexts = Overview_GetContexts(g_GameData);
-- Graphs are not grouped. Group them by Object Id. using AvailableContexts.
local graphs = HallofFame.GetGraphs(g_GameId);
-- Massage data, add data set names etc.
for i,g in ipairs(graphs) do
local minX = g.MinX;
local maxX = g.MaxX;
-- for each data set in the graph.
for _ , ds in ipairs(g) do
local objectId = ds.ObjectId;
if(ds.Type) then
local t = g_RulesetTypes[ds.Type];
if(t) then
ds.Name = t.Name;
end
elseif(ds.ObjectId) then
local p = g_GamePlayers[ds.ObjectId];
if(p) then
ds.Name = p.LeaderName;
ds.Hidden = not p.IsMajor;
else
local o = g_GameObjects[ds.ObjectId];
if(o) then
ds.Name = o.Name;
end
end
end
if(ds.Name == nil) then
ds.Name = "LOC_GAMESUMMARY_UNKNOWN";
end
if(not ds.Hidden) then
-- Mark as empty if no data found or all 0.
local count = 0;
local empty = true;
for i = minX, maxX, 1 do
local value = ds[i];
if(value ~= nil) then
count = count + 1;
if( value ~= 0) then
empty = false;
end
end
end
ds.Count = count;
if(empty) then
ds.Empty = true;
end
end
end
-- Filter hidden and empty groups.
-- Also filter graphs that are not delta (or continuous) and contain only 1 vertex.
remove_if(g, function(ds) return ds.Hidden or ds.Empty or (not ds.IsDelta and ds.Count == 1); end);
-- Sort groups by name.
table.sort(g, function(a,b) return Locale.Compare(a.Name, b.Name) == -1; end);
end
-- Filter graphs that contain 0 data sets.
-- TODO: Remove graphs where minX == maxX or minY == maxY??
remove_if(graphs, function(g) return #g == 0; end);
local sortByImportance = function(a,b)
if(a.Importance == b.Importance) then
return Locale.Compare(a.Name, b.Name) == -1;
else
return a.Importance > b.Importance;
end
end
local sortRowsByName = function(a,b)
return Locale.Compare(a.Name, b.Name) == -1;
end
g_Graphs = {}
for i,v in ipairs(g_AvailableContexts) do
local group = {};
local contextId = v.ObjectId;
for _, g in ipairs(graphs) do
if(contextId == g.ObjectId) then
table.insert(group, g);
end
end
if(#group > 0) then
for _,graph in ipairs(group) do
graph.Name = Locale.Lookup(graph.Name);
graph.Importance = graph.Importance or 0;
end
table.sort(group, sortByImportance);
group.Name = Locale.Lookup(v.Name);
group.Importance = group.Importance or 0;
table.insert(g_Graphs, group);
end
end
-- Massage the data, filter out empty groups, localize and sort groups.
local reports = HallofFame.GetReports(g_GameId);
g_Reports = {};
for _, report in ipairs(reports) do
-- Gather data before populating
-- (This way we can cull-out empty columns/rows.)
-- Mark all columns as empty (will update as rows are processed).
for _, column in ipairs(report.Columns) do
column.Empty = true;
end
-- Resolve the initial column name and localize it.
-- This will be used for sorting purposes.
for _,row in ipairs(report) do
local row_object = row.ObjectId;
local row_type = row.Type;
-- OPTIMIZATION (This could be cached/shared amongst multiple reports that have the same object.);
-- Collect data points.
local indexed_datapoints = {};
local type_indexed_datapoints = {};
local datapoints = HallofFame.GetObjectDataPoints(row_object);
-- Index data points
for i,v in ipairs(datapoints) do
if(v.ValueType == nil) then
indexed_datapoints[v.DataPoint] = v;
else
local t = type_indexed_datapoints[v.DataPoint];
if(t == nil) then
t = {};
type_indexed_datapoints[v.DataPoint] = t;
end
t[v.ValueType] = v;
end
end
-- Populate Additional Columns
row.Empty = true;
for column_index, column in ipairs(report.Columns) do
local dp;
if(row_type) then
local t = type_indexed_datapoints[column.DataPoint];
if(t) then
dp = t[row_type];
end
else
dp = indexed_datapoints[column.DataPoint];
end
if(dp) then
local value;
local icons = {column.ValueIconDefault};
value, icons = GetDataPointValue(dp, icons, column.UxHint);
if(value ~= nil and (tostring(value) ~= tostring(column.EmptyValue))) then
table.insert(icons, column.ValueIconOverride);
local cell = {
Icons = icons,
Value = value
};
row[column_index] = cell;
column.Empty = false;
-- If column is not a minotr one, mark row as not empty.
if(column.Minor ~= true) then
row.Empty = false;
end
end
end
end
-- Only perform this work if the row has data to be shown.
if(not row.Empty) then
-- Determine the name of the row.
local row_name = "LOC_GAMESUMMARY_UNKNOWN";
if(row_type) then
local r = g_RulesetTypes[row_type];
if(r) then
row_name = r.Name;
end
elseif(row_object) then
local o = g_GameObjects[row_object];
if(o) then
local p = g_GamePlayers[row_object];
if(p) then
row_name = p.LeaderName;
else
row_name = o.Name;
end
end
end
row.Name = row_name and Locale.Lookup(row_name) or "LOC_GAMESUMMARY_UNKNOWN";
-- Populate initial column data.
local icons = {row.InitialColumnValueIconDefault};
if(row_type) then
local r = g_RulesetTypes[row_type];
if(r) then
table.insert(icons, r.Icon);
end
elseif(row_object) then
local o = g_GameObjects[row_object];
if(o) then
table.insert(icons, o.Icon);
end
end
table.insert(icons, row.InitialColumnValueIconOverride);
row[0] = {
Icons = icons,
Value = row.Name
};
end
end
-- Filter out empty rows.
remove_if(report, function(r) return r.Empty; end);
-- Sort rows by name.
table.sort(report, sortRowsByName);
-- Perform any processing that can be skipped if there are no rows.
if(#report > 0) then
report.Name = Locale.Lookup(report.Name or "LOC_GAMESUMMARY_UNKNOWN");
report.Importance = report.Importance or 0;
end
end
-- Filter out reports w/ no rows.
remove_if(reports, function(r) return #r == 0; end);
for i,v in ipairs(g_AvailableContexts) do
local group = {};
local contextId = v.ObjectId;
for _, g in ipairs(reports) do
if(contextId == g.ObjectId) then
table.insert(group, g);
end
end
if(#group > 0) then
table.sort(group, sortByImportance);
group.Name = Locale.Lookup(v.Name);
group.Importance = group.Importance or 0;
table.insert(g_Reports, group);
end
end
-- Older games are missing the starting turn making it difficult to show the entire game graph.
-- In this situation, scrub all "GameTurn" graphs to determine the largest range.
local startTurn;
local endTurn;
if(g_GameData.StartTurn == nil or g_GameData.StartTurn == -1) then
for _, graphCategories in ipairs(g_Graphs) do
for _, graph in ipairs(graphCategories) do
if(graph.XUnit == "GameTurn") then
if(startTurn == nil or startTurn > graph.MinX) then
startTurn = graph.MinX;
end
if(endTurn == nil or endTurn < graph.MaxX) then
endTurn = graph.MaxX;
end
end
end
end
else
startTurn = g_GameData.StartTurn;
endTurn = startTurn + g_GameData.TurnCount;
end
-- TODO Edge Case: If the game is 0-1 turns long, pad out the range!
-- Once again enumerate all "GameTurn" graphs and adjust their MinX,MaxX to fix the total GameTurn range.
-- For Delta datasets, fill in the missing values.
for _, graphCategories in ipairs(g_Graphs) do
for _, graph in ipairs(graphCategories) do
if(graph.XUnit == "GameTurn") then
if(graph.MinX ~= startTurn or graph.MaxX ~= endTurn) then
graph.MinX = startTurn;
graph.MaxX = endTurn;
for _, ds in ipairs(graph) do
if(ds.IsDelta) then
local value = 0;
for i = graph.MinX, graph.MaxX, 1 do
value = ds[i] or value;
ds[i] = value;
end
end
end
end
end
end
end
end
function GetVictoryDetails(victoryType)
local name = "LOC_GAMESUMMARY_VICTORY";
local icons = {"ICON_VICTORY_UNIVERSAL"};
local victory = g_RulesetVictories[g_GameData.VictoryType];
if(victory) then
name = victory.Name;
icons = victory.Icons;
else
victory = g_RulesetTypes[g_GameData.VictoryType];
if(victory) then
table.insert(icons, "ICON_" .. victory.Type);
table.insert(icons, victory.Icon);
name = victory.Name;
end
end
return name, icons;
end
local colorDistances = {};
local pow = math.pow;
function ColorDistance(color1, color2)
local color1Type = color1[1];
local color1Value = color1[2];
local color2Type = color2[1];
local color2Value = color2[2];
local distance = nil;
local colorDistanceTable = colorDistances[color1Type];
if(colorDistanceTable == nil) then
colorDistanceTable = {
[color1Type] = 0; --We can assume the distance of a color to itself is 0.
};
colorDistances[color1Type] = colorDistanceTable
end
local distance = colorDistanceTable[color2Type];
if(distance == nil) then
local c1 = {UI.GetColorChannels(color1Value)};
local c2 = {UI.GetColorChannels(color2Value)};
local r2 = pow(c1[1] - c2[1], 2);
local g2 = pow(c1[2] - c2[2], 2);
local b2 = pow(c1[3] - c2[3], 2);
distance = r2 + g2 + b2;
colorDistanceTable[color2Type] = distance;
end
return distance;
end
local colorBlack;
function IsUniqueColor(color, unique_cache)
local id = color[1];
if(unique_cache[id]) then
return false;
end
if(colorBlack == nil) then
colorBlack = {DB.MakeHash("COLOR_BLACK"), UI.GetColorValue("COLOR_BLACK")};
end
local blackThreshold = 5000;
local differenceThreshold = 3000;
local distanceAgainstBlack = ColorDistance(color, colorBlack);
if(distanceAgainstBlack > blackThreshold) then
for i, v in pairs(g_GraphLegendColors) do
local distanceAgainstOtherPlayer = ColorDistance(color, v);
if(distanceAgainstOtherPlayer < differenceThreshold) then
-- Return false if the color is too close to a color that's already being used
unique_cache[id] = true;
return false;
end
end
-- Return true if the color is far enough away from black and other colors being used
unique_cache[id] = true;
return true;
end
-- Return false if color is too close to black
unique_cache[id] = true;
return false;
end
function DetermineGraphColor(unique_cache)
local colors = UI.GetColors();
for i, color in ipairs(colors) do
local id = color[1];
local value = color[2];
local r,g,b,a = UI.GetColorChannels(value);
if a == 255 then
-- Ensure we only use unique and opaque colors
if(IsUniqueColor(color, unique_cache)) then
return color;
end
end
end
--error("Could not find a unique color");
-- return the last entry.
return colors[#colors];
end
function GetDataPointValue(dp, icons, uxHint)
icons = icons or {};
local value;
if(uxHint == "Numeric") then
value = tonumber(dp.ValueNumeric);
else
if(dp.ValueType) then
value = "[COLOR_RED]" .. dp.ValueType .. "[ENDCOLOR]"; -- DEBUG
local t = g_RulesetTypes[dp.ValueType];
if(t) then
table.insert(icons, t.Icon);
value = Locale.Lookup(t.Name);
end
elseif(dp.ValueObjectId) then
local o = g_GameObjects[dp.ValueObjectId];
value ="[COLOR_RED]" .. dp.ValueObjectId .. "[ENDCOLOR]"; -- DEBUG
if(o) then
table.insert(icons, o.Icon);
local p = g_GamePlayers[dp.ValueObjectId];
if(p) then
table.insert(icons, "ICON_" .. p.LeaderType);
table.insert(icons, "ICON_" .. p.CivilizationType);
value = p.LeaderName;
elseif(o.Name) then
value = Locale.Lookup(o.Name);
end
end
elseif(dp.ValueString) then
value = Locale.Lookup(dp.ValueString);
elseif(dp.ValueNumeric) then
value = tonumber(dp.ValueNumeric);
end
end
return value, icons;
end
function SelectTab(index)
for i,v in ipairs(g_TabControls) do
if(i ~= index) then
v[1]:SetSelected(false);
v[2]:SetHide(true);
v[3]:SetHide(true);
end
end
g_TabControls[index][3]:SetHide(false);
g_TabControls[index][2]:SetHide(false);
g_TabControls[index][1]:SetSelected(true);
end
function SelectOverviewContext(index)
g_OverviewContext = g_AvailableContexts[index];
local button = Controls.OverviewContextPulldown:GetButton();
TruncateStringWithTooltip(button, button:GetSizeX() - 50, g_OverviewContext.Name);
Overview_UpdateMajorCivs(g_OverviewContext);
Overview_UpdateVictoryBanner(g_OverviewContext.ObjectId);
Overview_PopulateHighlightsForContext();
Overview_PopulateStatisticsForContext();
Controls.OverviewStack:CalculateSize();
Controls.OverviewStack:ReprocessAnchoring();
Controls.OverviewScrollPanel:CalculateInternalSize();
end
function SelectGraphGroup(index)
local comboBox = Controls.GraphDataContextPulldown;
local button = comboBox:GetButton();
g_GraphGroup = g_Graphs and g_Graphs[index];
if(g_GraphGroup) then
TruncateStringWithTooltip(button, button:GetSizeX() - 50, g_GraphGroup.Name);
else
comboBox:GetButton():SetText("");
end
Graphs_PopulateGraphs();
SelectGraph(1);
end
function SelectGraph(index)
local comboBox = Controls.GraphDataSetPulldown;
g_Graph = g_GraphGroup and g_GraphGroup[index];
if(g_Graph) then
comboBox:GetButton():SetText(g_Graph.Name);
else
comboBox:GetButton():SetText("");
end
Graphs_RefreshGraph(g_Graph);
end
function SelectReportGroup(index)
local comboBox = Controls.ReportDataContextPulldown;
local button = comboBox:GetButton();
g_ReportsGroup = g_Reports and g_Reports[index];
if(g_ReportsGroup) then
TruncateStringWithTooltip(button, button:GetSizeX() - 50, g_ReportsGroup.Name);
else
button:SetText("");
end
Reports_PopulateReports();
SelectReport(1);
end
function SelectReport(index)
local comboBox = Controls.ReportPulldown;
g_Report = g_ReportsGroup and g_ReportsGroup[index];
if(g_Report) then
Controls.ReportPulldown:GetButton():SetText(g_Report.Name);
else
Controls.ReportPulldown:GetButton():SetText("");
end
Reports_RefreshReport(g_Report);
end
----------------------------------------------------------------
-- Populate Methods
----------------------------------------------------------------
function Overview_GetContexts(data)
-- Return an array of contexts.
-- First entry is "Global"
-- Followed by each player in the game sorted by PlayerId.
-- Winner/You is denoted.
local contexts = {};
for i,v in ipairs(data.Players) do
if(v.IsMajor) then
local leaderName = v.LeaderName;
local name;
if(v.IsLocal and data.VictorTeamId == v.TeamId) then
name = Locale.Lookup("LOC_GAMESUMMARY_CONTEXT_LOCAL_WINNER", leaderName);
elseif(data.IsLocal) then
name = Locale.Lookup("LOC_GAMESUMMARY_CONTEXT_LOCAL", leaderName);
elseif(data.VictorTeamId == v.TeamId) then
name = Locale.Lookup("LOC_GAMESUMMARY_CONTEXT_WINNER", leaderName);
else
name = Locale.Lookup("LOC_GAMESUMMARY_CONTEXT", leaderName);
end
table.insert(contexts,{
Name = name,
ObjectId = v.PlayerObjectId,
PlayerId = v.PlayerId
});
end
end
table.sort(contexts, function(a,b)
return a.PlayerId < b.PlayerId;
end);
table.insert(contexts, 1, {Name = Locale.Lookup("LOC_GAMESUMMARY_CONTEXT_GLOBAL")});
return contexts;
end
function Overview_PopulateContexts()
local contexts = g_AvailableContexts;
local comboBox = Controls.OverviewContextPulldown;
comboBox:ClearEntries();
for i, v in ipairs(contexts) do
local controlTable = {};
comboBox:BuildEntry( "InstanceOne", controlTable );
TruncateStringWithTooltip(controlTable.Button, controlTable.Button:GetSizeX() - 12, v.Name);
controlTable.Button:RegisterCallback(Mouse.eLClick, function()
SelectOverviewContext(i);
end);
end
comboBox:CalculateInternals();
end
function Overview_UpdateMajorCivs()
g_PlayerManager:ResetInstances();
if(g_OverviewContext.ObjectId == nil and g_GameData) then
-- Sort players by PlayerId.
local players = {};
for i,p in ipairs(g_GameData.Players) do
table.insert(players,p);
end
table.sort(players, function(a,b) return a.PlayerId < b.PlayerId end);
for i,p in ipairs(players) do
if(p.IsMajor) then
local civilizationName = p.CivilizationName;
local leaderName = p.LeaderName;
local civilizationIcons = {"ICON_CIVILIZATION_UNKNOWN"};
local leaderIcons = {"ICON_LEADER_DEFAULT"};
if(p.CivilizationType) then
table.insert(civilizationIcons, "ICON_" .. p.CivilizationType);
end
if(p.LeaderType) then
table.insert(leaderIcons, "ICON_" .. p.LeaderType);
end
local player = g_RulesetPlayers[p.LeaderType];
if(player) then
civilizationName = player.CivilizationName or civilizationName;
leaderName = player.LeaderName or leaderName;
table.insert(civilizationIcons, player.CivilizationIcon);
table.insert(leaderIcons, player.LeaderIcon);
end
if(p.IsLocal) then
leaderName = Locale.Lookup("LOC_GAMESUMMARY_CONTEXT_LOCAL", leaderName);
else
leaderName = Locale.Lookup(leaderName);
end
local instance = g_PlayerManager:GetInstance();
instance.Score:SetText(p.Score);
instance.PlayerLeaderIcon:SetHide(not SetControlIcon(instance.PlayerLeaderIcon, leaderIcons));
instance.PlayerCivilizationIcon:SetHide(not SetControlIcon(instance.PlayerCivilizationIcon, civilizationIcons));
local fgColor, bgColor = UI.GetPlayerColorValues(p.LeaderType, 0);
instance.PlayerCivilizationIcon:SetColor(bgColor);
instance.PlayerCivilizationIconBG:SetColor(fgColor);
instance.PlayerLeaderName:LocalizeAndSetText(leaderName);
instance.PlayerCivilizationName:LocalizeAndSetText(civilizationName);
if(g_GameData.VictorTeamId == p.TeamId) then
local name, icons = GetVictoryDetails(g_GameData.VictoryType);
instance.VictoryName:LocalizeAndSetText(name);
SetControlIcon(instance.VictoryIcon, icons);
else
instance.VictoryIcon:SetIcon("ICON_DEFEAT_GENERIC");
instance.VictoryName:LocalizeAndSetText("LOC_GAMESUMMARY_DEFEAT");
end
end
end
Controls.Players:SetHide(false);
Controls.PlayersStack:CalculateSize();
Controls.PlayersStack:ReprocessAnchoring();
else
Controls.Players:SetHide(true);
end
end
function Overview_UpdateVictoryBanner(playerObjectId)
local victoryName, victoryIcons;
if(playerObjectId) then
local player;
for i,v in ipairs(g_GameData.Players) do
if(v.PlayerObjectId == playerObjectId) then
player = v;
break;
end
end
if(player) then
if(player.TeamId == g_GameData.VictorTeamId) then
victoryName, victoryIcons = GetVictoryDetails(g_GameData.VictoryType);
end
end
end
if(victoryName and victoryIcons) then
SetControlIcon(Controls.RibbonIcon, victoryIcons);
Controls.RibbonTile:SetTexture("EndGame_RibbonTile_Time");
Controls.Ribbon:SetTexture("EndGame_Ribbon_Time");
Controls.RibbonLabel:LocalizeAndSetText(victoryName);
Controls.RibbonContainer:SetHide(false);
elseif(playerObjectId) then
Controls.RibbonIcon:SetIcon("ICON_DEFEAT_GENERIC");
Controls.RibbonTile:SetTexture("EndGame_RibbonTile_Defeat");
Controls.Ribbon:SetTexture("EndGame_Ribbon_Defeat");
Controls.RibbonLabel:LocalizeAndSetText("LOC_DEFEAT_DEFAULT_NAME");
Controls.RibbonContainer:SetHide(false);
else
Controls.RibbonContainer:SetHide(true);
end
end
function Overview_PopulateHighlightsForContext()
-- Clear instances.
g_HighlightsManager:ResetInstances();
--local stats;
--if(g_OverviewContext.ObjectId) then
--stats = HallofFame.GetObjectHighlights(g_OverviewContext.ObjectId, 10) or {};
--else
--stats = HallofFame.GetGameHighlights(g_GameData.GameId, 10) or {};
--end
--
--if(#stats == 0) then
--Controls.Highlights:SetHide(true);
--return;
--end
--
--Controls.Highlights:SetHide(false);
--
--
---- Process Data
--for i,v in ipairs(stats) do
--v.Name = Locale.Lookup(v.Name);
--if(v.ValueType) then
--local t = g_RulesetTypes[v.ValueType];
--if(t) then
--v.ValueIcon = t.Icon or ("ICON_" .. t.Type);
--v.DisplayValue = Locale.Lookup(t.Name);
--end
--elseif(v.ValueObjectId) then
--local o = g_GameObjects[v.ValueObjectId];
--if(o) then
--v.ValueIcon = o.Icon or v.ValueIcon;
--v.DisplayValue = Locale.Lookup(o.Name);
--end
--elseif(v.ValueString) then
--v.DisplayValue = Locale.Lookup(v.ValueString);
--elseif(v.ValueNumeric) then
--v.DisplayValue = Locale.ToNumber(v.ValueNumeric, "###,###");
--end
--
--if(v.Annotation) then
--v.Annotation = Locale.Lookup(v.Annotation, {Name = "Amount", Value = v.ValueNumeric});
--end
--end
--
---- sort stats (Importance Desc, Name)
--table.sort(stats, function(a,b)
--if(a.Importance ~= b.Importance) then
--return a.Importance > b.Importance;
--else
--return Locale.Compare(a.Name, b.Name) == -1;
--end
--end);
--
--for _,stat in ipairs(stats) do
--if(stat.DisplayValue) then
--local instance = g_HighlightsManager:GetInstance();
--
--if(stat.Icon and instance.TitleIcon:TrySetIcon(stat.Icon)) then
--instance.TitleIcon:SetHide(false);
--else
--instance.TitleIcon:SetHide(true);
--end
--instance.TitleCaption:LocalizeAndSetText(stat.Name);