forked from civfanatics/Civ6-UIFiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
LaunchBar.lua
859 lines (750 loc) · 30 KB
/
LaunchBar.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
-- ===========================================================================
-- HUD's "Launch Bar"
-- Copyright (c) 2017-2019 Firaxis Games
--
-- Controls raising full-screen and "choosers" found in upper-left of HUD.
-- ===========================================================================
include( "GameCapabilities" );
-- ===========================================================================
-- MEMBERS
-- ===========================================================================
local m_numOpen :number = 0;
local m_isAutoUnitCycle :boolean = false;
local isTechTreeOpen :boolean = false;
local isCivicsTreeOpen :boolean = false;
local isGreatPeopleOpen :boolean = false;
local isGreatWorksOpen :boolean = false;
local isHistoricMomentsOpen :boolean = false;
local isReligionOpen :boolean = false;
local isGovernmentOpen :boolean = false;
local isGovernorPanelOpen :boolean = false;
local m_isGreatPeopleUnlocked :boolean = false;
local m_isGreatWorksUnlocked :boolean = false;
local m_isReligionUnlocked :boolean = false;
local m_isGovernmentUnlocked :boolean = false;
local m_isTechTreeAvailable :boolean = false;
local m_isCivicsTreeAvailable :boolean = false;
local m_isGovernmentAvailable :boolean = false;
local m_isReligionAvailable :boolean = false;
local m_isGreatPeopleAvailable :boolean = false;
local m_isGreatWorksAvailable :boolean = false;
local isDebug :boolean = false; -- Set to true to force all hook buttons to show on game start
-- ===========================================================================
-- Callbacks
-- ===========================================================================
-- ===========================================================================
function OnOpenGovernment()
local ePlayer :number = Game.GetLocalPlayer();
if ePlayer == -1 then
return; -- Probably autoplay
end
local localPlayer:table = Players[ePlayer];
if localPlayer == nil then
return;
end
local kCulture:table = localPlayer:GetCulture();
if ( kCulture:IsInAnarchy() ) then -- Anarchy? No gov't for you.
if isGovernmentOpen then
LuaEvents.LaunchBar_CloseGovernmentPanel()
end
return;
end
if isGovernmentOpen then
LuaEvents.LaunchBar_CloseGovernmentPanel()
else
CloseAllPopups();
if (kCulture:CivicCompletedThisTurn() and kCulture:CivicUnlocksGovernment(kCulture:GetCivicCompletedThisTurn()) and not kCulture:GovernmentChangeConsidered()) then
-- Blocking notification that NEW GOVERNMENT is available, make sure player takes a look
LuaEvents.LaunchBar_GovernmentOpenGovernments();
else
-- Normal entry to my Government
LuaEvents.LaunchBar_GovernmentOpenMyGovernment();
end
end
end
-- ===========================================================================
function CloseAllPopups()
LuaEvents.LaunchBar_CloseGreatPeoplePopup();
LuaEvents.LaunchBar_CloseGreatWorksOverview();
LuaEvents.LaunchBar_CloseReligionPanel();
if isGovernmentOpen then
LuaEvents.LaunchBar_CloseGovernmentPanel();
end
LuaEvents.LaunchBar_CloseTechTree();
LuaEvents.LaunchBar_CloseCivicsTree();
end
-- ===========================================================================
function OnGetPopupsOpen()
if isGovernmentOpen or isTechTreeOpen or isCivicsTreeOpen or isGreatPeopleOpen or isGreatWorksOpen or isReligionOpen or isHistoricMomentsOpen or isGovernorPanelOpen then
LuaEvents.TradeRouteChooser_CloseIfPopups();
m_isAutoUnitCycle = false;
if UserConfiguration.IsAutoUnitCycle() then
m_isAutoUnitCycle = true; -- set to true so we know we need to open it after the currently open popup is closed.
end
end
end
-- ===========================================================================
function OnOpenTradeRouteDueToAutoCycle()
--if another popup was open, trade route needs to open after it has been closed (when auto unit cycle is enabled)
if m_isAutoUnitCycle then
LuaEvents.TradeRouteChooser_ReOpen();
end
end
-- ===========================================================================
function OnOpenGreatPeople()
if isGreatPeopleOpen then
LuaEvents.LaunchBar_CloseGreatPeoplePopup();
else
CloseAllPopups();
LuaEvents.LaunchBar_OpenGreatPeoplePopup();
end
end
-- ===========================================================================
function OnOpenGreatWorks()
if isGreatWorksOpen then
LuaEvents.LaunchBar_CloseGreatWorksOverview();
else
CloseAllPopups();
LuaEvents.LaunchBar_OpenGreatWorksOverview();
end
end
-- ===========================================================================
function OnOpenReligion()
if isReligionOpen then
LuaEvents.LaunchBar_CloseReligionPanel();
LuaEvents.LaunchBar_ClosePantheonChooser();
else
-- If we're able to but have yet to found a pantheon then open the pantheon chooser instead
local pLocalPlayerReligion:table = Players[Game.GetLocalPlayer()]:GetReligion();
if pLocalPlayerReligion and pLocalPlayerReligion:GetPantheon() < 0 and pLocalPlayerReligion:CanCreatePantheon() then
LuaEvents.LaunchBar_OpenPantheonChooser();
else
CloseAllPopups();
LuaEvents.LaunchBar_OpenReligionPanel();
end
end
end
-- ===========================================================================
function OnOpenResearch()
if isTechTreeOpen then
LuaEvents.LaunchBar_CloseTechTree();
else
CloseAllPopups();
LuaEvents.LaunchBar_RaiseTechTree();
end
end
-- ===========================================================================
function OnOpenCulture()
if isCivicsTreeOpen then
LuaEvents.LaunchBar_CloseCivicsTree();
else
CloseAllPopups();
LuaEvents.LaunchBar_RaiseCivicsTree();
end
end
-- ===========================================================================
function OnOpenGovernors()
if isGovernorPanelOpen then
LuaEvents.GovernorPanel_Close();
else
CloseAllPopups();
LuaEvents.GovernorPanel_Open();
end
end
-- ===========================================================================
function SetCivicsTreeOpen()
isCivicsTreeOpen = true;
OnOpen();
end
-- ===========================================================================
function SetTechTreeOpen()
isTechTreeOpen = true;
OnOpen();
end
-- ===========================================================================
function SetGreatPeopleOpen()
isGreatPeopleOpen = true;
OnOpen();
end
-- ===========================================================================
function SetGreatWorksOpen()
isGreatWorksOpen = true;
OnOpen();
end
-- ===========================================================================
function SetReligionOpen()
isReligionOpen = true;
OnOpen();
end
-- ===========================================================================
function SetGovernmentOpen()
isGovernmentOpen = true;
OnOpen();
end
-- ===========================================================================
function SetGovernorPanelOpen()
isGovernorPanelOpen = true;
OnOpen();
end
-- ===========================================================================
function SetHistoricMomentsOpened()
isHistoricMomentsOpen = true;
OnOpen();
end
-- ===========================================================================
function SetCivicsTreeClosed()
isCivicsTreeOpen = false;
OnClose();
end
-- ===========================================================================
function SetTechTreeClosed()
isTechTreeOpen = false;
OnClose();
end
-- ===========================================================================
function SetGreatPeopleClosed()
isGreatPeopleOpen = false;
OnClose();
end
-- ===========================================================================
function SetGreatWorksClosed()
isGreatWorksOpen = false;
OnClose();
end
-- ===========================================================================
function SetReligionClosed()
isReligionOpen = false;
OnClose();
end
-- ===========================================================================
function SetGovernmentClosed()
isGovernmentOpen = false;
OnClose();
end
-- ===========================================================================
function SetGovernorPanelClosed()
isGovernorPanelOpen = false;
OnClose();
end
-- ===========================================================================
function SetHistoricMomentsClosed()
isHistoricMomentsOpen = false;
OnClose();
end
-- ===========================================================================
-- Lua Event
-- Tutorial system is requesting any screen openned, to be closed.
-- ===========================================================================
function OnTutorialCloseAll()
CloseAllPopups();
end
-- ===========================================================================
-- Game Engine Event
-- ===========================================================================
function OnInterfaceModeChanged(eOldMode:number, eNewMode:number)
if eNewMode == InterfaceModeTypes.VIEW_MODAL_LENS then
ContextPtr:SetHide(true);
end
if eNewMode == InterfaceModeTypes.CINEMATIC then
CloseAllPopups(); -- TODO: Remove this and instead change Popup behavior via new parameter. (TTP 43933)
end
if eOldMode == InterfaceModeTypes.VIEW_MODAL_LENS then
ContextPtr:SetHide(false);
end
end
-- ===========================================================================
-- Refresh Data and View
-- ===========================================================================
function RealizeHookVisibility()
m_isTechTreeAvailable = isDebug or HasCapability("CAPABILITY_TECH_TREE");
Controls.ScienceButton:SetShow(m_isTechTreeAvailable);
Controls.ScienceBolt:SetShow(m_isTechTreeAvailable);
m_isCivicsTreeAvailable = isDebug or HasCapability("CAPABILITY_CIVICS_TREE");
Controls.CultureButton:SetShow(m_isCivicsTreeAvailable);
Controls.CultureBolt:SetShow(m_isCivicsTreeAvailable);
m_isGreatPeopleAvailable = isDebug or (m_isGreatPeopleUnlocked and HasCapability("CAPABILITY_GREAT_PEOPLE_VIEW"));
Controls.GreatPeopleButton:SetShow(m_isGreatPeopleAvailable);
Controls.GreatPeopleBolt:SetShow(m_isGreatPeopleAvailable);
m_isReligionAvailable = isDebug or (m_isReligionUnlocked and HasCapability("CAPABILITY_RELIGION_VIEW"));
Controls.ReligionButton:SetShow(m_isReligionAvailable);
Controls.ReligionBolt:SetShow(m_isReligionAvailable);
m_isGreatWorksAvailable = isDebug or (m_isGreatWorksUnlocked and HasCapability("CAPABILITY_GREAT_WORKS_VIEW"));
Controls.GreatWorksButton:SetShow(m_isGreatWorksAvailable);
Controls.GreatWorksBolt:SetShow(m_isGreatWorksAvailable);
m_isGovernmentAvailable = isDebug or (m_isGovernmentUnlocked and HasCapability("CAPABILITY_GOVERNMENTS_VIEW"));
Controls.GovernmentButton:SetShow(m_isGovernmentAvailable);
Controls.GovernmentBolt:SetShow(m_isGovernmentAvailable);
RealizeBacking();
end
-- ===========================================================================
function OnFaithChanged()
if (m_isReligionUnlocked) then
return;
end
m_isReligionUnlocked = true;
RealizeHookVisibility();
end
-- ===========================================================================
function RefreshReligion()
local ePlayer:number = Game.GetLocalPlayer();
if ePlayer == -1 then
-- Likely auto playing.
return;
end
if m_isReligionUnlocked then
return;
end
local localPlayer :table = Players[ePlayer];
local playerReligion :table = localPlayer:GetReligion();
local hasFaithYield :boolean = playerReligion:GetFaithYield() > 0;
local hasFaithBalance :boolean = playerReligion:GetFaithBalance() > 0;
if (hasFaithYield or hasFaithBalance) then
m_isReligionUnlocked = true;
end
RealizeHookVisibility();
end
-- ===========================================================================
function OnGreatWorkCreated()
if (m_isGreatWorksUnlocked) then
return;
end
m_isGreatWorksUnlocked = true;
RealizeHookVisibility();
end
-- ===========================================================================
function OnDiplomacyDealEnacted()
if (not m_isGreatWorksUnlocked) then
RefreshGreatWorks();
end
end
-- ===========================================================================
-- Capturing a city can also net us pretty great works
function OnCityCaptured()
if (not m_isGreatWorksUnlocked) then
RefreshGreatWorks();
end
end
-- ===========================================================================
function RefreshGreatWorks()
local ePlayer:number = Game.GetLocalPlayer();
if ePlayer == -1 then
-- Likely auto playing.
return;
end
if m_isGreatWorksUnlocked then
return;
end
local localPlayer :table = Players[ePlayer];
local pCities :table = localPlayer:GetCities();
for i, pCity in pCities:Members() do
if pCity ~= nil and pCity:GetOwner() == ePlayer then
local pCityBldgs:table = pCity:GetBuildings();
for buildingInfo in GameInfo.Buildings() do
local buildingIndex:number = buildingInfo.Index;
if(pCityBldgs:HasBuilding(buildingIndex)) then
local numSlots:number = pCityBldgs:GetNumGreatWorkSlots(buildingIndex);
if (numSlots ~= nil and numSlots > 0) then
for slotIndex=0, numSlots - 1 do
local greatWorkIndex:number = pCityBldgs:GetGreatWorkInSlot(buildingIndex, slotIndex);
if (greatWorkIndex ~= -1) then
m_isGreatWorksUnlocked = true;
break;
end
end
end
end
end
if m_isGreatWorksUnlocked then
break;
end
end
end
RealizeHookVisibility();
end
-- ===========================================================================
function RefreshGreatPeople()
local ePlayer:number = Game.GetLocalPlayer();
if ePlayer == -1 then
-- Likely auto playing.
return;
end
if m_isGreatPeopleUnlocked then
return;
end
-- Show button if we have any great people in the game
for greatPerson in GameInfo.GreatPersonIndividuals() do
m_isGreatPeopleUnlocked = true;
break;
end
RealizeHookVisibility();
end
-- ===========================================================================
function ShowFreePolicyFlag( isFree:boolean )
Controls.PoliciesAvailableIndicator:SetShow( isFree );
Controls.PoliciesAvailableIndicator:SetToolTipString( isFree and Locale.Lookup("LOC_HUD_GOVT_FREE_CHANGES") or nil );
end
-- ===========================================================================
-- Game Event
-- ===========================================================================
function OnCivicCompleted(player:number, civic:number, isCanceled:boolean)
local ePlayer:number = Game.GetLocalPlayer();
if ePlayer == -1 then
return;
end
if(not m_isGovernmentUnlocked) then
local playerCulture:table = Players[ePlayer]:GetCulture();
if (playerCulture:GetNumPoliciesUnlocked() > 0) then
m_isGovernmentUnlocked = true;
end
end
RealizeHookVisibility();
end
-- ===========================================================================
function RefreshGovernment()
local playerID:number = Game.GetLocalPlayer();
if playerID == -1 then return; end
local kCulture:table = Players[playerID]:GetCulture();
if ( kCulture:GetNumPoliciesUnlocked() <= 0 ) then
Controls.GovernmentButton:SetToolTipString(Locale.Lookup("LOC_GOVERNMENT_DOESNT_UNLOCK"));
Controls.GovernmentButton:GetTextControl():SetColor(UI.GetColorValueFromHexLiteral(0xFF666666));
else
m_isGovernmentUnlocked = true;
Controls.GovernmentButton:SetHide(false);
Controls.GovernmentBolt:SetHide(false);
if ( kCulture:IsInAnarchy() ) then
local iAnarchyTurns = kCulture:GetAnarchyEndTurn() - Game.GetCurrentGameTurn();
Controls.GovernmentButton:SetDisabled(true);
Controls.GovernmentIcon:SetColorByName("Civ6Red");
Controls.GovernmentButton:SetToolTipString("[COLOR_RED]".. Locale.Lookup("LOC_GOVERNMENT_ANARCHY_TURNS", iAnarchyTurns) .. "[ENDCOLOR]");
ShowFreePolicyFlag( false );
else
Controls.GovernmentButton:SetDisabled(false);
Controls.GovernmentIcon:SetColorByName("White");
Controls.GovernmentButton:SetToolTipString(Locale.Lookup("LOC_GOVERNMENT_MANAGE_GOVERNMENT_AND_POLICIES"));
ShowFreePolicyFlag( kCulture:GetCostToUnlockPolicies() == 0 and kCulture:PolicyChangeMade() == false);
end
end
RealizeHookVisibility();
end
-- ===========================================================================
-- Update the background and size of the launchbar itself.
-- ===========================================================================
function RealizeBacking()
Controls.ButtonStack:CalculateSize();
local stackWidth:number = Controls.ButtonStack:GetSizeX();
Controls.LaunchBacking:SetSizeX(stackWidth+116);
Controls.LaunchBackingTile:SetSizeX(stackWidth-20);
Controls.LaunchBarDropShadow:SetSizeX(stackWidth);
-- If the stack is less than a pip (at this writing 7) then there is nothing in it... hide the launchbar
if stackWidth < 10 then
stackWidth = 0;
ContextPtr:SetHide(true);
Unsubscribe();
else
if ContextPtr:IsHidden() then
ContextPtr:SetHide(false);
end
end
-- Signal to other contexts (e.g., DiploRibbon) when size has changed.
LuaEvents.LaunchBar_Resize( stackWidth );
end
-- ===========================================================================
function UpdateTechMeter( localPlayer:table )
if ( localPlayer ~= nil and Controls.ScienceHookWithMeter:IsVisible() ) then
local playerTechs :table = localPlayer:GetTechs();
local currentTechID :number = playerTechs:GetResearchingTech();
if(currentTechID >= 0) then
local progress :number = playerTechs:GetResearchProgress(currentTechID);
local cost :number = playerTechs:GetResearchCost(currentTechID);
Controls.ScienceMeter:SetPercent(progress/cost);
else
Controls.ScienceMeter:SetPercent(0);
end
local techInfo:table = GameInfo.Technologies[currentTechID];
if (techInfo ~= nil) then
local textureString = "ICON_" .. techInfo.TechnologyType;
local textureOffsetX, textureOffsetY, textureSheet = IconManager:FindIconAtlas(textureString,38);
if textureSheet ~= nil then
Controls.ResearchIcon:SetTexture(textureOffsetX, textureOffsetY, textureSheet);
end
end
else
Controls.ResearchIcon:SetTexture(0, 0, "LaunchBar_Hook_TechTree");
end
end
-- ===========================================================================
function UpdateCivicMeter( localPlayer:table)
if ( localPlayer ~= nil and Controls.CultureHookWithMeter:IsVisible() ) then
local pPlayerCulture :table = localPlayer:GetCulture();
local currentCivicID :number = pPlayerCulture:GetProgressingCivic();
if(currentCivicID >= 0) then
local civicProgress :number = pPlayerCulture:GetCulturalProgress(currentCivicID);
local civicCost :number = pPlayerCulture:GetCultureCost(currentCivicID);
Controls.CultureMeter:SetPercent(civicProgress/civicCost);
else
Controls.CultureMeter:SetPercent(0);
end
local CivicInfo:table = GameInfo.Civics[currentCivicID];
if (CivicInfo ~= nil) then
local civictextureString = "ICON_" .. CivicInfo.CivicType;
local civictextureOffsetX, civictextureOffsetY, civictextureSheet = IconManager:FindIconAtlas(civictextureString,38);
if civictextureSheet ~= nil then
Controls.CultureIcon:SetTexture(civictextureOffsetX, civictextureOffsetY, civictextureSheet);
end
end
else
Controls.CultureIcon:SetTexture(0, 0, "LaunchBar_Hook_CivicsTree");
end
end
-- ===========================================================================
-- Main Refresh
-- ===========================================================================
function RefreshView()
local localPlayerID :number = Game.GetLocalPlayer();
if localPlayerID == -1 then
return;
end
local localPlayer = Players[localPlayerID];
if (localPlayer == nil) then
return;
end
UpdateTechMeter(localPlayer);
UpdateCivicMeter(localPlayer);
RefreshGovernment();
RefreshGreatWorks();
RefreshGreatPeople();
RefreshReligion();
if BASE_RefreshView == nil then -- No MODs/Expansions defining this function so its safe to call Realize now.
RealizeBacking();
end
end
-- ===========================================================================
-- EVENT
function OnLocalPlayerTurnBegin()
RefreshView();
end
-- ===========================================================================
-- EVENT
function OnVisualStateRestored()
RefreshView();
end
-- ===========================================================================
-- EVENT
function OnCivicChanged()
RefreshView();
end
-- ===========================================================================
-- EVENT
function OnResearchChanged()
RefreshView();
end
-- ===========================================================================
-- EVENT
function OnGovernmentRefresh()
RefreshGovernment();
end
-- ===========================================================================
function OnOpen()
m_isAutoUnitCycle = false;
m_numOpen = m_numOpen+1;
local screenX, screenY:number = UIManager:GetScreenSizeVal();
if screenY <= 850 then
Controls.LaunchContainer:SetOffsetY(-35);
end
LuaEvents.TradeRouteChooser_CloseIfPopups();
LuaEvents.LaunchBar_CloseChoosers();
end
-- ===========================================================================
function OnClose()
m_numOpen = m_numOpen-1;
if(m_numOpen < 0 )then
m_numOpen = 0;
end
if m_numOpen == 0 then
Controls.LaunchContainer:SetOffsetY(-5);
end
OnOpenTradeRouteDueToAutoCycle(); --open if this popup blocked traderoute from opening
end
-- ===========================================================================
function OnToggleResearchPanel(hideResearch)
Controls.ScienceHookWithMeter:SetHide(not hideResearch);
UpdateTechMeter(Players[Game.GetLocalPlayer()]);
end
-- ===========================================================================
function OnToggleCivicPanel(hideResearch)
Controls.CultureHookWithMeter:SetHide(not hideResearch);
UpdateCivicMeter(Players[Game.GetLocalPlayer()]);
end
-- ===========================================================================
-- Reset the hooks when the player changes for hotseat.
function OnLocalPlayerChanged()
m_isGreatPeopleUnlocked = false;
m_isGreatWorksUnlocked = false;
m_isReligionUnlocked = false;
m_isGovernmentUnlocked = false;
RefreshGovernment();
RefreshGreatPeople();
RefreshGreatWorks();
RefreshReligion();
end
-- ===========================================================================
-- Input Hotkey Event (Extended in XP1 to hook extra panels)
-- ===========================================================================
function OnInputActionTriggered( actionId )
if ( m_isTechTreeAvailable ) then
if ( actionId == Input.GetActionId("ToggleTechTree") ) then
OnOpenResearch();
end
end
if ( m_isCivicsTreeAvailable ) then
if ( actionId == Input.GetActionId("ToggleCivicsTree") ) then
OnOpenCulture();
end
end
if ( m_isGovernmentAvailable ) then
if ( actionId == Input.GetActionId("ToggleGovernment") ) then
OnOpenGovernment();
end
end
if ( m_isReligionAvailable ) then
if ( actionId == Input.GetActionId("ToggleReligion") ) then
OnOpenReligion();
end
end
if ( m_isGreatPeopleAvailable ) then
if ( actionId == Input.GetActionId("ToggleGreatPeople") and UI.QueryGlobalParameterInt("DISABLE_GREAT_PEOPLE_HOTKEY") ~= 1 ) then
OnOpenGreatPeople();
end
end
if ( m_isGreatWorksAvailable ) then
if ( actionId == Input.GetActionId("ToggleGreatWorks") and UI.QueryGlobalParameterInt("DISABLE_GREAT_WORKS_HOTKEY") ~= 1 ) then
OnOpenGreatWorks();
end
end
end
-- ===========================================================================
function PlayMouseoverSound()
UI.PlaySound("Main_Menu_Mouse_Over");
end
-- ===========================================================================
function Unsubscribe()
Events.AnarchyBegins.Remove( OnGovernmentRefresh );
Events.AnarchyEnds.Remove( OnGovernmentRefresh );
Events.CityOccupationChanged.Remove( OnCityCaptured ); -- HACK: Detect GreatWorks acquired via city capture, by hooking this event
Events.CivicCompleted.Remove( OnCivicCompleted ); -- To capture when we complete Code of Laws
Events.CivicChanged.Remove( OnCivicChanged );
Events.DiplomacyDealEnacted.Remove( OnDiplomacyDealEnacted );
Events.FaithChanged.Remove( OnFaithChanged );
Events.GovernmentChanged.Remove( OnGovernmentRefresh );
Events.GovernmentPolicyChanged.Remove( OnGovernmentRefresh );
Events.GovernmentPolicyObsoleted.Remove( OnGovernmentRefresh );
Events.GreatWorkCreated.Remove( OnGreatWorkCreated );
Events.InputActionTriggered.Remove( OnInputActionTriggered );
Events.InterfaceModeChanged.Remove( OnInterfaceModeChanged );
Events.LocalPlayerChanged.Remove( OnLocalPlayerChanged );
Events.LocalPlayerTurnBegin.Remove( OnLocalPlayerTurnBegin );
Events.ResearchChanged.Remove(OnResearchChanged);
Events.TreasuryChanged.Remove( OnGovernmentRefresh );
Events.VisualStateRestored.Remove( OnVisualStateRestored );
LuaEvents.CivicsTree_CloseCivicsTree.Remove( SetCivicsTreeClosed );
LuaEvents.CivicsTree_OpenCivicsTree.Remove( SetCivicsTreeOpen );
LuaEvents.Government_CloseGovernment.Remove( SetGovernmentClosed );
LuaEvents.Government_OpenGovernment.Remove( SetGovernmentOpen );
LuaEvents.GovernorPanel_Closed.Remove( SetGovernorPanelClosed );
LuaEvents.GovernorPanel_Opened.Remove( SetGovernorPanelOpen );
LuaEvents.GreatPeople_CloseGreatPeople.Remove( SetGreatPeopleClosed );
LuaEvents.GreatPeople_OpenGreatPeople.Remove( SetGreatPeopleOpen );
LuaEvents.GreatWorks_CloseGreatWorks.Remove( SetGreatWorksClosed );
LuaEvents.GreatWorks_OpenGreatWorks.Remove( SetGreatWorksOpen );
LuaEvents.HistoricMoments_Closed.Remove( SetHistoricMomentsClosed );
LuaEvents.HistoricMoments_Opened.Remove( SetHistoricMomentsOpened );
LuaEvents.LaunchBar_CheckPopupsOpen.Remove( OnGetPopupsOpen );
LuaEvents.Religion_CloseReligion.Remove( SetReligionClosed );
LuaEvents.Religion_OpenReligion.Remove( SetReligionOpen );
LuaEvents.PantheonChooser_CloseReligion.Remove( SetReligionClosed );
LuaEvents.PantheonChooser_OpenReligion.Remove( SetReligionOpen );
LuaEvents.TechTree_CloseTechTree.Remove(SetTechTreeClosed);
LuaEvents.TechTree_OpenTechTree.Remove( SetTechTreeOpen );
LuaEvents.Tutorial_CloseAllLaunchBarScreens.Remove( OnTutorialCloseAll );
if HasCapability("CAPABILITY_TECH_TREE") then
LuaEvents.WorldTracker_ToggleResearchPanel.Remove( OnToggleResearchPanel );
end
if HasCapability("CAPABILITY_CIVICS_TREE") then
LuaEvents.WorldTracker_ToggleCivicPanel.Remove( OnToggleCivicPanel );
end
end
-- ===========================================================================
function Subscribe()
Events.AnarchyBegins.Add( OnGovernmentRefresh );
Events.AnarchyEnds.Add( OnGovernmentRefresh );
Events.CityOccupationChanged.Add( OnCityCaptured ); -- HACK: Detect GreatWorks acquired via city capture, by hooking this event
Events.CivicCompleted.Add( OnCivicCompleted ); -- To capture when we complete Code of Laws
Events.CivicChanged.Add( OnCivicChanged );
Events.DiplomacyDealEnacted.Add( OnDiplomacyDealEnacted );
Events.FaithChanged.Add( OnFaithChanged );
Events.GovernmentChanged.Add( OnGovernmentRefresh );
Events.GovernmentPolicyChanged.Add( OnGovernmentRefresh );
Events.GovernmentPolicyObsoleted.Add( OnGovernmentRefresh );
Events.GreatWorkCreated.Add( OnGreatWorkCreated );
Events.InputActionTriggered.Add( OnInputActionTriggered );
Events.InterfaceModeChanged.Add( OnInterfaceModeChanged );
Events.LocalPlayerChanged.Add( OnLocalPlayerChanged );
Events.LocalPlayerTurnBegin.Add( OnLocalPlayerTurnBegin );
Events.ResearchChanged.Add(OnResearchChanged);
Events.TreasuryChanged.Add( OnGovernmentRefresh );
Events.VisualStateRestored.Add( OnVisualStateRestored );
LuaEvents.CivicsTree_CloseCivicsTree.Add( SetCivicsTreeClosed );
LuaEvents.CivicsTree_OpenCivicsTree.Add( SetCivicsTreeOpen );
LuaEvents.Government_CloseGovernment.Add( SetGovernmentClosed );
LuaEvents.Government_OpenGovernment.Add( SetGovernmentOpen );
LuaEvents.GovernorPanel_Closed.Add( SetGovernorPanelClosed );
LuaEvents.GovernorPanel_Opened.Add( SetGovernorPanelOpen );
LuaEvents.GreatPeople_CloseGreatPeople.Add( SetGreatPeopleClosed );
LuaEvents.GreatPeople_OpenGreatPeople.Add( SetGreatPeopleOpen );
LuaEvents.GreatWorks_CloseGreatWorks.Add( SetGreatWorksClosed );
LuaEvents.GreatWorks_OpenGreatWorks.Add( SetGreatWorksOpen );
LuaEvents.HistoricMoments_Closed.Add( SetHistoricMomentsClosed );
LuaEvents.HistoricMoments_Opened.Add( SetHistoricMomentsOpened );
LuaEvents.LaunchBar_CheckPopupsOpen.Add( OnGetPopupsOpen );
LuaEvents.Religion_CloseReligion.Add( SetReligionClosed );
LuaEvents.Religion_OpenReligion.Add( SetReligionOpen );
LuaEvents.PantheonChooser_CloseReligion.Add( SetReligionClosed );
LuaEvents.PantheonChooser_OpenReligion.Add( SetReligionOpen );
LuaEvents.TechTree_CloseTechTree.Add(SetTechTreeClosed);
LuaEvents.TechTree_OpenTechTree.Add( SetTechTreeOpen );
LuaEvents.Tutorial_CloseAllLaunchBarScreens.Add( OnTutorialCloseAll );
if HasCapability("CAPABILITY_TECH_TREE") then
LuaEvents.WorldTracker_ToggleResearchPanel.Add( OnToggleResearchPanel );
end
if HasCapability("CAPABILITY_CIVICS_TREE") then
LuaEvents.WorldTracker_ToggleCivicPanel.Add( OnToggleCivicPanel );
end
end
-- ===========================================================================
function LateInitialize()
Subscribe();
RefreshView();
end
-- ===========================================================================
-- Called after all contexts (this and replacement contexts) are loaded.
-- ===========================================================================
function OnInit( isReload:boolean )
LateInitialize();
end
-- ===========================================================================
function Initialize()
ContextPtr:SetInitHandler( OnInit );
Controls.CultureButton:RegisterCallback(Mouse.eLClick, OnOpenCulture);
Controls.CultureButton:RegisterCallback( Mouse.eMouseEnter, PlayMouseoverSound);
Controls.GovernmentButton:RegisterCallback( Mouse.eLClick, OnOpenGovernment );
Controls.GovernmentButton:RegisterCallback( Mouse.eMouseEnter, PlayMouseoverSound);
Controls.GreatPeopleButton:RegisterCallback( Mouse.eLClick, OnOpenGreatPeople );
Controls.GreatPeopleButton:RegisterCallback( Mouse.eMouseEnter, PlayMouseoverSound);
Controls.GreatWorksButton:RegisterCallback( Mouse.eLClick, OnOpenGreatWorks );
Controls.GreatWorksButton:RegisterCallback( Mouse.eMouseEnter, PlayMouseoverSound);
Controls.ReligionButton:RegisterCallback( Mouse.eLClick, OnOpenReligion );
Controls.ReligionButton:RegisterCallback( Mouse.eMouseEnter, PlayMouseoverSound);
Controls.ScienceButton:RegisterCallback(Mouse.eLClick, OnOpenResearch);
Controls.ScienceButton:RegisterCallback( Mouse.eMouseEnter, PlayMouseoverSound);
end
Initialize();