-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathTechAndCivicSupport.lua
748 lines (622 loc) · 25.6 KB
/
TechAndCivicSupport.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
-- ===========================================================================
-- Support functions for formatting of Tech and Civic areas which are used
-- within their "Choosers" and their panel version within the "World Tracker"
-- ===========================================================================
include("InstanceManager");
include("SupportFunctions");
include("Civ6Common");
-- ===========================================================================
-- CONSTANTS
-- ===========================================================================
local DATA_FIELD_UNLOCK_IM :string = "_UnlockIM";
local MAX_BEFORE_TRUNC_BOOST_MSG:number = 220; -- Size in which boost messages will be truncated and tooltipified
local SIZE_ICON_CIVIC_LARGE :number = 38;
local SIZE_ICON_RESEARCH_LARGE :number = 38;
local MAX_ICONS_BEFORE_OVERFLOW :number = 6;
-- ===========================================================================
-- MEMBERS
-- These are instanced for each file that adds this support file.
-- ===========================================================================
local m_kGovernmentData :table; -- Used to cache government info.
local m_kCivicsData :table; -- Used to cache civics info.
local m_kTechsData :table; -- Used to cache tech info.
-- Utility Methods
function GetUnlockablesForCivic_Cached(civicType, playerId)
--Set player ID to -1 if it is invalid in any way.
local playerIndex = playerId;
if playerIndex == nil then
playerIndex = -1;
end
if m_kCivicsData == nil or table.count(m_kCivicsData)==0 then
m_kCivicsData = {};
for i = 0, GameDefines.MAX_PLAYERS, 1 do
m_kCivicsData[i] = {};
end
end
if m_kCivicsData[playerIndex][civicType] ~= nil then
return m_kCivicsData[playerIndex][civicType];
end
local results:table = GetUnlockablesForCivic(civicType, playerId);
m_kCivicsData[playerIndex][civicType] = results;
return results;
end
function GetUnlockablesForTech_Cached(techType, playerId)
--Set player ID to -1 if it is invalid in any way.
local playerIndex = playerId;
if playerIndex == nil then
playerIndex = -1;
end
if m_kTechsData == nil or table.count(m_kTechsData)==0 then
m_kTechsData = {};
for i = 0, GameDefines.MAX_PLAYERS-1, 1 do
m_kTechsData[i] = {};
end
end
if m_kTechsData[playerIndex][techType] ~= nil then
return m_kTechsData[playerIndex][techType];
end
local results:table = GetUnlockablesForTech(techType, playerId);
m_kTechsData[playerIndex][techType] = results;
return results;
end
function GetUnlockIcon(typeName)
local icon = "ICON_TECHUNLOCK_0";
local typeInfo = GameInfo.Types[typeName];
if(typeInfo) then
local icons_by_kind = {
KIND_PROJECT = "ICON_TECHUNLOCK_0",
KIND_WONDER = "ICON_TECHUNLOCK_0",
KIND_BUILDING = "ICON_TECHUNLOCK_1",
KIND_DISTRICT = "ICON_TECHUNLOCK_2",
KIND_IMPROVEMENT = "ICON_TECHUNLOCK_3",
KIND_UNIT = "ICON_TECHUNLOCK_4",
KIND_RESOURCE = "ICON_TECHUNLOCK_5",
KIND_GOVERNMENT = "ICON_TECHUNLOCK_6",
KIND_ROUTE = "ICON_TECHUNLOCK_7",
KIND_AGREEMENT = "ICON_TECHUNLOCK_8",
KIND_POLICY = "ICON_TECHUNLOCK_9",
};
if(typeInfo.Kind == "KIND_POLICY") then
local policy = GameInfo.Policies[typeName];
local slotType = policy and policy.GovernmentSlotType or nil;
if(slotType == "SLOT_MILITARY" ) then
icon = "ICON_TECHUNLOCK_10";
elseif(slotType == "SLOT_DIPLOMATIC" ) then
icon = "ICON_TECHUNLOCK_11";
elseif(slotType == "SLOT_ECONOMIC" ) then
icon = "ICON_TECHUNLOCK_12";
elseif(slotType == "SLOT_WILDCARD" or slotType == "SLOT_GREAT_PERSON") then
icon = "ICON_TECHUNLOCK_9";
else
icon = icons_by_kind["KIND_POLICY"];
end
else
if typeInfo.Kind == "KIND_BUILDING" then
for row in GameInfo.Buildings() do
if row.BuildingType == typeInfo.Type then
if row.IsWonder ~= nil and row.IsWonder == true then
return icons_by_kind["KIND_WONDER"];
else
return icons_by_kind[typeInfo.Kind]
end
end
end
else
if(typeInfo.Kind == "KIND_DIPLOMATIC_ACTION") then
icon = "ICON_TECHUNLOCK_8";
else
icon = icons_by_kind[typeInfo.Kind];
end
end
end
end
return icon;
end
-- ===========================================================================
--
-- ===========================================================================
function GetGovernmentData()
if m_kGovernmentData == nil or table.count(m_kGovernmentData)==0 then
m_kGovernmentData = {};
for row in GameInfo.Governments() do
local governmentType :string = row.GovernmentType;
local slotMilitary :number = 0;
local slotEconomic :number = 0;
local slotDiplomatic :number = 0;
local slotWildcard :number = 0;
for entry in GameInfo.Government_SlotCounts() do
if (governmentType == entry.GovernmentType) then
local slotType = entry.GovernmentSlotType;
if(slotType == "SLOT_MILITARY") then slotMilitary = slotMilitary + entry.NumSlots;
elseif(slotType == "SLOT_ECONOMIC") then slotEconomic = slotEconomic + entry.NumSlots;
elseif(slotType == "SLOT_DIPLOMATIC") then slotDiplomatic = slotDiplomatic + entry.NumSlots;
elseif(slotType == "SLOT_WILDCARD" or slotType =="SLOT_GREAT_PERSON") then slotWildcard = slotWildcard + entry.NumSlots;
end
end
end
m_kGovernmentData[governmentType] = {
Name = row.Name,
NumSlotMilitary = slotMilitary,
NumSlotEconomic = slotEconomic,
NumSlotDiplomatic = slotDiplomatic,
NumSlotWildcard = slotWildcard
}
end
end
return m_kGovernmentData;
end
function ResetOverflowArrow( kItemInstance:table )
if kItemInstance == nil then
return;
end
if kItemInstance.PageTurnerImage == nil then
return;
end
kItemInstance.PageTurnerImage:FlipX(false);
kItemInstance.UnlockPageTurner:SetHide(true);
kItemInstance.UnlockPageTurner:ClearCallback(Mouse.eLClick);
end
function OnOverflowArrowPressed( kItemInstance:table )
local unlockables :table = kItemInstance.UnlockStack:GetChildren();
local overflowPage :boolean = kItemInstance.PageTurnerImage:IsFlippedHorizontal();
kItemInstance.PageTurnerImage:FlipX(not overflowPage);
for i=1, table.count(unlockables), 1 do
unlockables[i]:SetHide(not unlockables[i]:IsHidden());
end
kItemInstance.UnlockStack:ReprocessAnchoring();
end
function HandleOverflow( numUnlockables:number, kItemInstance:table )
if kItemInstance == nil then
return nil;
end
kItemInstance.UnlockPageTurner:SetHide(true);
if numUnlockables <= MAX_ICONS_BEFORE_OVERFLOW then
return;
end
local unlockables :table = kItemInstance.UnlockStack:GetChildren();
kItemInstance.UnlockPageTurner:SetHide(false);
kItemInstance.UnlockPageTurner:RegisterCallback( Mouse.eLClick, function() OnOverflowArrowPressed(kItemInstance); end);
for i=MAX_ICONS_BEFORE_OVERFLOW, numUnlockables, 1 do
unlockables[i]:SetHide(true);
end
kItemInstance.UnlockStack:ReprocessAnchoring();
end
-- ===========================================================================
--
-- ===========================================================================
function PopulateUnlockablesForCivic(playerID:number, civicID:number, kItemIM:table, kGovernmentIM:table, callback:ifunction, hideDescriptionIcon:boolean )
local civicData:table = GameInfo.Civics[civicID];
if civicData == nil then
UI.DataError("Unable to find a civic type in the database with an ID value of #"..tostring(civicID));
return;
end
local governmentData = GetGovernmentData();
local civicType:string = civicData.CivicType;
-- Unlockables is an array of {type, name}
local numIcons:number = 0;
local unlockables = GetUnlockablesForCivic_Cached(civicType, playerID);
if(unlockables and #unlockables > 0) then
for i,v in ipairs(unlockables) do
local typeName = v[1];
local civilopediaKey = v[3];
local typeInfo = GameInfo.Types[typeName];
if(kGovernmentIM and typeInfo and typeInfo.Kind == "KIND_GOVERNMENT") then
local unlock = kGovernmentIM:GetInstance();
local government = governmentData[typeName];
if(government) then
unlock.MilitaryPolicyLabel:SetText(tostring(government.NumSlotMilitary));
unlock.EconomicPolicyLabel:SetText(tostring(government.NumSlotEconomic));
unlock.DiplomaticPolicyLabel:SetText(tostring(government.NumSlotDiplomatic));
unlock.WildcardPolicyLabel:SetText(tostring(government.NumSlotWildcard));
unlock.GovernmentName:SetText(Locale.Lookup(government.Name));
end
local toolTip = ToolTipHelper.GetToolTip(typeName, playerID);
unlock.GovernmentInstanceGrid:LocalizeAndSetToolTip(toolTip);
unlock.GovernmentInstanceGrid:RegisterCallback(Mouse.eLClick, callback);
if(not IsTutorialRunning()) then
unlock.GovernmentInstanceGrid:RegisterCallback(Mouse.eRClick, function()
LuaEvents.OpenCivilopedia(civilopediaKey);
end);
end
else
local unlockIcon = kItemIM:GetInstance();
local icon = GetUnlockIcon(typeName);
unlockIcon.Icon:SetIcon("ICON_"..typeName);
unlockIcon.Icon:SetHide(false);
local textureOffsetX, textureOffsetY, textureSheet = IconManager:FindIconAtlas(icon,38);
if textureSheet ~= nil then
unlockIcon.UnlockIcon:SetTexture(textureOffsetX, textureOffsetY, textureSheet);
end
local toolTip = ToolTipHelper.GetToolTip(typeName, playerID);
unlockIcon.UnlockIcon:LocalizeAndSetToolTip(toolTip);
if callback ~= nil then
unlockIcon.UnlockIcon:RegisterCallback(Mouse.eLClick, callback);
else
unlockIcon.UnlockIcon:ClearCallback(Mouse.eLClick);
end
if(not IsTutorialRunning()) then
unlockIcon.UnlockIcon:RegisterCallback(Mouse.eRClick, function()
LuaEvents.OpenCivilopedia(civilopediaKey);
end);
end
end
numIcons = numIcons + 1;
end
end
if (civicData.Description and hideDescriptionIcon ~= true) then
local unlockIcon:table = kItemIM:GetInstance();
unlockIcon.Icon:SetHide(true); -- foreground icon unnecessary in this case
local textureOffsetX, textureOffsetY, textureSheet = IconManager:FindIconAtlas("ICON_TECHUNLOCK_13",38);
if textureSheet ~= nil then
unlockIcon.UnlockIcon:SetTexture(textureOffsetX, textureOffsetY, textureSheet);
end
unlockIcon.UnlockIcon:LocalizeAndSetToolTip(GameInfo.Civics[civicID].Description);
if callback ~= nil then
unlockIcon.UnlockIcon:RegisterCallback(Mouse.eLClick, callback);
else
unlockIcon.UnlockIcon:ClearCallback(Mouse.eLClick);
end
if(not IsTutorialRunning()) then
unlockIcon.UnlockIcon:RegisterCallback(Mouse.eRClick, function()
LuaEvents.OpenCivilopedia(civicType);
end);
end
numIcons = numIcons + 1;
end
kItemIM.m_ParentControl:CalculateSize();
return numIcons;
end
-- ===========================================================================
--
-- ===========================================================================
function PopulateUnlockablesForTech(playerID:number, techID:number, instanceManager:table, callback:ifunction )
local techType:string = GameInfo.Technologies[techID].TechnologyType;
if techType == nil then
UI.DataError("Unable to find a tech type in the database with an ID value of #"..tostring(techID));
return;
end
-- Unlockables is an array of {type, name}
local numIcons:number = 0;
local unlockables:table = GetUnlockablesForTech_Cached(techType, playerID);
-- Hard-coded goodness.
if unlockables and table.count(unlockables) > 0 then
for i,v in ipairs(unlockables) do
local typeName :string = v[1];
local civilopediaKey = v[3];
local unlockIcon:table = instanceManager:GetInstance();
local icon = GetUnlockIcon(typeName);
unlockIcon.Icon:SetIcon("ICON_"..typeName);
unlockIcon.Icon:SetHide(false);
local textureOffsetX, textureOffsetY, textureSheet = IconManager:FindIconAtlas(icon,38);
if textureSheet ~= nil then
unlockIcon.UnlockIcon:SetTexture(textureOffsetX, textureOffsetY, textureSheet);
end
local toolTip :string = ToolTipHelper.GetToolTip(typeName, playerID);
unlockIcon.UnlockIcon:LocalizeAndSetToolTip(toolTip);
if callback ~= nil then
unlockIcon.UnlockIcon:RegisterCallback(Mouse.eLClick, callback);
else
unlockIcon.UnlockIcon:ClearCallback(Mouse.eLClick);
end
if(not IsTutorialRunning()) then
unlockIcon.UnlockIcon:RegisterCallback(Mouse.eRClick, function()
LuaEvents.OpenCivilopedia(civilopediaKey);
end);
end
end
numIcons = numIcons + 1;
end
if (GameInfo.Technologies[techID].Description) then
local unlockIcon:table = instanceManager:GetInstance();
unlockIcon.Icon:SetHide(true); -- foreground icon unnecessary in this case
local textureOffsetX, textureOffsetY, textureSheet = IconManager:FindIconAtlas("ICON_TECHUNLOCK_13",38);
if textureSheet ~= nil then
unlockIcon.UnlockIcon:SetTexture(textureOffsetX, textureOffsetY, textureSheet);
end
unlockIcon.UnlockIcon:LocalizeAndSetToolTip(GameInfo.Technologies[techID].Description);
if callback ~= nil then
unlockIcon.UnlockIcon:RegisterCallback(Mouse.eLClick, callback);
else
unlockIcon.UnlockIcon:ClearCallback(Mouse.eLClick);
end
if(not IsTutorialRunning()) then
unlockIcon.UnlockIcon:RegisterCallback(Mouse.eRClick, function()
LuaEvents.OpenCivilopedia(GameInfo.Technologies[techID].TechnologyType);
end);
end
numIcons = numIcons + 1;
end
return numIcons;
end
-- ===========================================================================
-- Obtain the "active" data, either what is currently being worked on or
-- what just completed.
-- RETURN: active data or NIL
-- ===========================================================================
function GetActiveData( kData:table )
for _, data in ipairs(kData) do
if data.IsCurrent or data.IsLastCompleted then
return data;
end
end
return nil;
end
-- ===========================================================================
-- Returns a custom instance manager for unlocks that will exist in a control.
-- ===========================================================================
function GetUnlockIM( kControl:table )
local unlockIM :table = kControl[DATA_FIELD_UNLOCK_IM];
if unlockIM ~= nil then
-- Reset prior
unlockIM:ResetInstances();
else
-- Create
unlockIM = InstanceManager:new("UnlockIconInstance", "UnlockIcon", kControl.UnlockStack);
kControl[DATA_FIELD_UNLOCK_IM] = unlockIM;
end
return unlockIM;
end
-- ===========================================================================
-- Show the meters and boost information for a given tech.
-- ===========================================================================
function RealizeMeterAndBoosts( kControl:table, kData:table )
local progress:number = kData.Progress;
if kData.Boostable then
local boostString :string = "[NEWLINE]" .. Locale.Lookup(kData.TriggerDesc);
if kData.BoostTriggered then
boostString = Locale.Lookup("LOC_TECH_HAS_BEEN_BOOSTED") .. boostString; -- Same whether tech/civic
kControl.IconHasBeenBoosted:SetToolTipString(boostString);
progress = math.clamp( progress, 0, 1.0 );
else
boostString = Locale.Lookup("LOC_TECH_CAN_BE_BOOSTED") .. boostString; -- Same whether tech/civic
kControl.IconCanBeBoosted:SetToolTipString( boostString );
local boostAmount = math.min( (kData.Progress + kData.BoostAmount ), 1.0 );
kControl.BoostMeter:SetPercent( boostAmount );
end
TruncateStringWithTooltip(kControl.BoostLabel, MAX_BEFORE_TRUNC_BOOST_MSG, Locale.Lookup(kData.TriggerDesc) )
end
if kData.IsLastCompleted then
progress = 1.0;
end
kControl.IconCanBeBoosted:SetHide( (not ( kData.Boostable and not kData.BoostTrigger)) or kData.IsLastCompleted );
kControl.IconHasBeenBoosted:SetHide( (not kData.BoostTriggered) or kData.IsLastCompleted );
kControl.ProgressMeter:SetPercent( progress );
kControl.BoostLabel:SetHide( (not kData.Boostable) or kData.IsLastCompleted );
kControl.BoostMeter:SetHide( (not kData.Boostable) or kData.IsLastCompleted or (kData.BoostTriggered) );
end
-- ===========================================================================
--
-- ===========================================================================
function RealizeIcon( kIconControl:table, typeName:string, size:number )
local textureString :string = "ICON_" .. typeName;
local textureOffsetX, textureOffsetY, textureSheet = IconManager:FindIconAtlas(textureString, size);
if textureSheet ~= nil then
kIconControl:SetTexture(textureOffsetX, textureOffsetY, textureSheet);
else
UI.DataError("Missing icon '"..tostring(textureString).."' at size "..tostring(size));
end
end
-- ===========================================================================
--
-- ===========================================================================
function RealizeTurnsLeft( kControl:table, kData:table)
local turnsLeft :number = (kData == nil) and -1 or kData.TurnsLeft;
-- The UI was only designed to show up to 3 characters in this label
if turnsLeft > 999 then turnsLeft = 999; end
local isLastCompleted :boolean = false;
local isRepeatable :boolean = false;
if kData ~= nil then
isLastCompleted = kData.IsLastCompleted;
isRepeatable = kData.Repeatable;
if isLastCompleted and not isRepeatable then
kControl.TurnsLeft:SetText( Locale.Lookup("LOC_RESEARCH_CHOOSER_JUST_COMPLETED") );
else
if kData.TurnsLeft ~= -1 then
kControl.TurnsLeft:SetText("[ICON_Turn]" .. tostring(turnsLeft));
else
kControl.TurnsLeft:SetText("");
end
end
else
kControl.TurnsLeft:SetText("");
end
-- Label only exists in the big version:
if kControl.TurnsLeftLabel ~= nil then
kControl.TurnsLeftLabel:SetHide( isLastCompleted or turnsLeft < 0 );
end
end
-- ===========================================================================
-- Obtain a single research/tech item.
-- ===========================================================================
function GetResearchData( localPlayer:number, pPlayerTechs:table, kTech:table )
if kTech == nil then -- Immediate return if there is no tech to inspect; likely first turn.
return nil;
end
local iTech :number = kTech.Index;
local isBoostable :boolean = false;
local boostAmount :number = 0;
local isRepeatable :boolean = kTech.Repeatable;
local researchCost :number = pPlayerTechs:GetResearchCost(iTech);
local techType :string = kTech.TechnologyType;
local triggerDesc :string = "";
for row in GameInfo.Boosts() do
if row.TechnologyType == techType then
isBoostable = true;
boostAmount = (row.Boost *.01 ) * researchCost; --Convert the boost value to decimal and determine the actual boost amount.
triggerDesc = row.TriggerDescription;
break;
end
end
local kData :table = {
ID = iTech,
Boostable = isBoostable,
BoostAmount = boostAmount / researchCost,
BoostTriggered = pPlayerTechs:HasBoostBeenTriggered(iTech),
Hash = kTech.Hash,
Name = Locale.Lookup( kTech.Name ),
IsCurrent = false, -- caller needs to update upon return
IsLastCompleted = false, -- caller needs to update upon return
Repeatable = isRepeatable,
ResearchCost = researchCost,
Progress = pPlayerTechs:GetResearchProgress(iTech) / researchCost,
TechType = techType,
ToolTip = ToolTipHelper.GetToolTip( techType, localPlayer ),
TriggerDesc = triggerDesc,
TurnsLeft = pPlayerTechs:GetTurnsToResearch(iTech)
};
return kData;
end
-- ===========================================================================
-- Realize content at the top of a list which is one of the following:
-- the current research, the recently completed research or NIL if player
-- has just started the game.
-- ===========================================================================
function RealizeCurrentResearch( playerID:number, kData:table, kControl:table )
-- If a control instance is passed in, use that for the controls, otherwise
-- assume the control exists off of the main control set of the context.
if kControl == nil then
kControl = Controls;
end
kControl.MainPanel:ClearMouseEnterCallback();
kControl.MainPanel:ClearMouseExitCallback();
local isNonActive:boolean = false;
local techUnlockIM:table = GetUnlockIM( kControl ); -- Use this context's "Controls" table for the currnet IM
if kData ~= nil then
local techType:string = kData.TechType;
local numUnlockables:number;
kControl.TitleButton:SetText(Locale.ToUpper(kData.Name));
if(not IsTutorialRunning()) then
kControl.TitleButton:RegisterCallback(Mouse.eRClick, function() LuaEvents.OpenCivilopedia(techType); end);
end
kControl.MainPanel:RegisterMouseEnterCallback( function() kControl.MainGearAnim:Play(); end);
kControl.MainPanel:RegisterMouseExitCallback( function() kControl.MainGearAnim:Stop(); end);
RealizeMeterAndBoosts( kControl, kData );
RealizeIcon( kControl.Icon, kData.TechType, SIZE_ICON_RESEARCH_LARGE );
numUnlockables = PopulateUnlockablesForTech( playerID, kData.ID, techUnlockIM, nil );
if numUnlockables ~= nil and kControl ~= nil then
HandleOverflow(numUnlockables, kControl);
end
-- Show/Hide Recommended Icon
if kControl.RecommendedIcon then
if kData.IsRecommended and kData.AdvisorType then
kControl.RecommendedIcon:SetIcon(kData.AdvisorType);
kControl.RecommendedIcon:SetHide(false);
kControl.TitleStack:ReprocessAnchoring();
else
kControl.RecommendedIcon:SetHide(true);
end
end
else
-- Nothing has been researched yet.
kControl.TitleButton:ClearCallback(Mouse.eRClick);
kControl.BoostMeter:SetPercent(0);
kControl.ProgressMeter:SetPercent(0);
kControl.BoostLabel:SetHide( true );
kControl.IconCanBeBoosted:SetHide( true );
kControl.IconHasBeenBoosted:SetHide( true );
if kControl.RecommendedIcon then
kControl.RecommendedIcon:SetHide( true );
end
isNonActive = true;
end
RealizeTurnsLeft( kControl, kData );
kControl.TitleButton:SetHide( isNonActive );
kControl.Icon:SetHide( isNonActive );
end
-- ===========================================================================
-- Determine the current data.
-- ===========================================================================
function GetCivicData( localPlayer:number, pPlayerCulture:table, kCivic:table )
if kCivic == nil then -- Immediate return if there is no tech to inspect; likely first turn.
return nil;
end
local iCivic :number = kCivic.Index;
local isBoostable :boolean = false;
local boostAmount :number = 0;
local isRepeatable :boolean = kCivic.Repeatable;
local progressCost :number = pPlayerCulture:GetCultureCost(iCivic)
local civicType :string = kCivic.CivicType;
local triggerDesc :string = "";
for row in GameInfo.Boosts() do
if row.CivicType == civicType then
isBoostable = true;
boostAmount = (row.Boost *.01 ) * progressCost; --Convert the boost value to decimal and determine the actual boost amount.
triggerDesc = row.TriggerDescription;
break;
end
end
local kData :table = {
ID = iCivic,
Boostable = isBoostable,
BoostAmount = boostAmount / progressCost,
BoostTriggered = pPlayerCulture:HasBoostBeenTriggered(iCivic),
Cost = progressCost,
Hash = kCivic.Hash,
Name = Locale.Lookup( kCivic.Name ),
IsCurrent = false, -- caller needs to update upon return
IsLastCompleted = false, -- caller needs to update upon return
Repeatable = isRepeatable,
Progress = (pPlayerCulture:GetCulturalProgress(iCivic) / progressCost),
CivicType = civicType,
ToolTip = ToolTipHelper.GetToolTip( civicType, localPlayer ),
TriggerDesc = triggerDesc,
TurnsLeft = pPlayerCulture:GetTurnsToProgressCivic(iCivic)
};
return kData;
end
-- ===========================================================================
-- Realize content at the top of a list which is one of the following:
-- the current research, the recently completed research or NIL if player
-- has just started the game.
-- ===========================================================================
function RealizeCurrentCivic( playerID:number, kData:table, kControl:table )
-- If a control instance is passed in, use that for the controls, otherwise
-- assume the control exists off of the main control set of the context.
if kControl == nil then
kControl = Controls;
end
kControl.MainPanel:ClearMouseEnterCallback();
kControl.MainPanel:ClearMouseExitCallback();
local isNonActive:boolean = false;
local techUnlockIM:table = GetUnlockIM( kControl ); -- Use this context's "Controls" table for the currnet IM
techUnlockIM:ResetInstances();
if kData ~= nil then
local techType:string = kData.CivicType;
local numUnlockables:number;
kControl.TitleButton:SetText( Locale.ToUpper(kData.Name) );
if(not IsTutorialRunning()) then
kControl.TitleButton:RegisterCallback(Mouse.eRClick, function() LuaEvents.OpenCivilopedia(techType); end);
end
kControl.MainPanel:RegisterMouseEnterCallback( function() kControl.MainGearAnim:Play(); end);
kControl.MainPanel:RegisterMouseExitCallback( function() kControl.MainGearAnim:Stop(); end);
RealizeMeterAndBoosts( kControl, kData );
RealizeIcon( kControl.Icon, kData.CivicType, SIZE_ICON_CIVIC_LARGE );
numUnlockables = PopulateUnlockablesForCivic( playerID, kData.ID, techUnlockIM, nil );
if numUnlockables ~= nil then
HandleOverflow(numUnlockables, kControl);
end
-- Show/Hide Recommended Icon
if kControl.RecommendedIcon then
if kData.IsRecommended and kData.AdvisorType then
kControl.RecommendedIcon:SetIcon(kData.AdvisorType);
kControl.RecommendedIcon:SetHide(false);
kControl.TitleStack:ReprocessAnchoring();
else
kControl.RecommendedIcon:SetHide(true);
end
end
else
-- Nothing has been researched yet.
kControl.TitleButton:ClearCallback(Mouse.eRClick);
kControl.BoostMeter:SetPercent(0);
kControl.ProgressMeter:SetPercent(0);
kControl.BoostLabel:SetHide( true );
kControl.IconCanBeBoosted:SetHide( true );
kControl.IconHasBeenBoosted:SetHide( true );
kControl.TurnsLeftLabel:SetHide( true );
isNonActive = true;
end
RealizeTurnsLeft( kControl, kData );
kControl.TitleButton:SetHide( isNonActive );
kControl.Icon:SetHide( isNonActive );
end