forked from chaorace/Civ6-UIFiles
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathReligionScreen.lua
1609 lines (1386 loc) · 65 KB
/
ReligionScreen.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
-- Copyright 2017-2019, Firaxis Games
include("TabSupport");
include("InstanceManager");
include("ModalScreen_PlayerYieldsHelper");
include("GameCapabilities");
-- ===========================================================================
-- CONSTANTS
-- ===========================================================================
local PADDING_ICON:number = 5;
local PADDING_TABS:number = 10;
local NUM_MAX_BELIEFS:number = 4;
local NUM_CUSTOM_ICONS:number = 36;
local PADDING_RELIGION_ICON:number = 8;
local PADDING_RELIGION_ICON_SMALL:number = 4;
local PADDING_RELIGION_ICON_SELECTION:number = 8;
local PADDING_RELIGION_ICON_SELECTION_SMALL:number = 4;
local PADDING_TAB_BUTTON_TEXT:number = 55;
local SIZE_BELIEF_ICON_SMALL:number = 32;
local SIZE_BELIEF_ICON_LARGE:number = 64;
local SIZE_RELIGION_ICON_SMALL:number = 22;
local SIZE_RELIGION_ICON_MEDIUM:number = 50;
local SIZE_RELIGION_ICON_LARGE:number = 100;
local SIZE_RELIGION_ICON_HUGE:number = 270;
local SIZE_UNIT_ICON_NONE_ALPHA:number = 0.3;
local OFFSET_WORKING_TOWARDS_PANTHEON:number = 405;
local OFFSET_CHOOSING_PANTHEON_BELIEFS:number = -10;
local OFFSET_CHOOSING_RELIGION_BELIEFS:number = -10;
local TXT_SCREEN_TITLE:string = Locale.Lookup("LOC_UI_RELIGION_TITLE");
local TXT_MY_RELIGION:string = Locale.Lookup("LOC_UI_RELIGION_MY_RELIGION");
local TXT_MY_PANTHEON:string = Locale.Lookup("LOC_UI_RELIGION_MY_PANTHEON");
local DATA_FIELD_FOLLOWERS_IM:string = "FollowersIM";
local DATA_FIELD_BELIEFS_IM:string = "BeliefsIM";
local DATA_FIELD_SELECTION:string = "Selection";
local DATA_FIELD_INDEX:string = "Index";
local DATA_FIELD_ICONS:string = "Icons";
local CITIES_FILTER:table = { FOLLOWING_RELIGION = 1, RELIGION_PRESENT = 2 };
-- Table of localized strings used for when religion units can and cannot be produced
local UNIT_ICON_TOOLTIPS:table = {};
UNIT_ICON_TOOLTIPS["UNIT_MISSIONARY"] = {
canProduce = "LOC_UI_RELIGION_MISSIONARY_TT",
cannotProduce = "LOC_UI_RELIGION_HOW_TO_MAKE_MISSIONARY_TT"
};
UNIT_ICON_TOOLTIPS["UNIT_APOSTLE"] = {
canProduce = "LOC_UI_RELIGION_APOSTLE_TT",
cannotProduce = "LOC_UI_RELIGION_HOW_TO_MAKE_APOSTLE_TT"
};
UNIT_ICON_TOOLTIPS["UNIT_INQUISITOR"] = {
canProduce = "LOC_UI_RELIGION_INQUISITOR_TT",
cannotProduce = "LOC_UI_RELIGION_HOW_TO_MAKE_INQUISITOR_TT"
};
UNIT_ICON_TOOLTIPS["UNIT_GURU"] = {
canProduce = "LOC_UI_RELIGION_GURU_TT",
cannotProduce = "LOC_UI_RELIGION_HOW_TO_MAKE_GURU_TT"
};
-- ===========================================================================
-- SCREEN VARIABLES
-- ===========================================================================
local m_TopPanelConsideredHeight:number = 0;
local m_Beliefs:table;
local m_PendingBeliefs:table;
local m_ReligionTabs:table; -- TabSupport
local m_MyReligionTab:table;
local m_AllReligionsTab:table;
local m_ReligionIcons:table;
local m_SelectedReligion:table;
local m_CanCreatePantheon:boolean = false;
local m_isConfirmedBeliefs:boolean = false;
local m_isConfirmingBeliefs:boolean = false;
local m_pGameReligion:table = Game.GetReligion();
local m_CitiesFilter:number = CITIES_FILTER.FOLLOWING_RELIGION;
local m_CitiesIM:table = InstanceManager:new("City", "CityBG", Controls.Cities);
local m_ReligionsIM:table = InstanceManager:new("Religion", "ReligionBG", Controls.Religions);
local m_ReligionTabsIM:table = InstanceManager:new("ReligionTab", "Button", Controls.TabContainer);
local m_ReligionIconsIM:table = InstanceManager:new("ReligionIcon", "ReligionIcon", Controls.ReligionIcons);
local m_AddAvailableBeliefsIM:table = InstanceManager:new("BeliefSlot", "BeliefButton", Controls.AddAvailableBeliefs);
local m_AddSelectedBeliefsIM:table = InstanceManager:new("BeliefSlot", "BeliefButton", Controls.AddBeliefsReligionBeliefs);
local m_ExistingReligionBeliefsIM:table = InstanceManager:new("ReligionBelief", "BeliefBG", Controls.AddBeliefsReligionBeliefs);
local m_SelectBeliefsIM:table = InstanceManager:new("BeliefSlot", "BeliefButton", Controls.AvailableBeliefs);
local m_SelectedBeliefsIM:table = InstanceManager:new("BeliefSlot", "BeliefButton", Controls.SelectedBeliefs);
local m_ReligionBeliefsIM:table = InstanceManager:new("ReligionBelief", "BeliefBG", Controls.ViewReligionBeliefs);
local m_ReligionSelections:table = InstanceManager:new("ReligionOption", "ReligionButton", Controls.ChooseReligionItems);
local m_UnitIconIM:table = InstanceManager:new("UnitIconInstance", "UnitIconBacking", Controls.IconStack);
-- ===========================================================================
-- PLAYER VARIABLES
-- ===========================================================================
local m_LocalPlayer :table;
local m_PlayerReligionType :number;
local m_PantheonBelief :number;
local m_TurnBlockingType :number;
local m_NumBeliefsEarned :number;
local m_NumBeliefsEquipped :number;
local m_isHasProphet :boolean;
local m_SelectedBeliefs :table;
-- ===========================================================================
function GetDisplayPlayerID()
if Game.GetLocalObserver() == PlayerTypes.OBSERVER then
-- Use the first alive player
local aPlayers = PlayerManager.GetAliveMajors();
if (#aPlayers > 0) then
return aPlayers[1]:GetID();
end
end
return Game.GetLocalPlayer();
end
-- ===========================================================================
-- Called every time screen is shown
-- ===========================================================================
function UpdatePlayerData()
local displayPlayerID = GetDisplayPlayerID();
if (displayPlayerID ~= -1) then
m_LocalPlayer = Players[displayPlayerID];
local pPlayerReligion:table = m_LocalPlayer:GetReligion();
m_PantheonBelief = pPlayerReligion:GetPantheon();
m_CanCreatePantheon = pPlayerReligion:CanCreatePantheon();
m_PlayerReligionType = pPlayerReligion:GetReligionTypeCreated();
m_TurnBlockingType = NotificationManager.GetFirstEndTurnBlocking(displayPlayerID);
m_NumBeliefsEarned = pPlayerReligion:GetNumBeliefsEarned();
m_isHasProphet = pPlayerReligion:HasReligiousFoundingUnit();
m_NumBeliefsEquipped = 0;
local religions = m_pGameReligion:GetReligions();
for _, religion in ipairs(religions) do
if (religion.Founder == displayPlayerID) then
m_NumBeliefsEquipped = table.count(religion.Beliefs);
break;
end
end
end
end
-- ===========================================================================
-- Called every time screen is shown
-- ===========================================================================
function UpdateTabs()
if (m_LocalPlayer == nil) then
return;
end
-- Clean up previous data
m_MyReligionTab = nil
m_AllReligionsTab = nil;
m_ReligionTabsIM:ResetInstances();
-- Deselect previously selected tab
if(m_ReligionTabs ~= nil) then
m_ReligionTabs.SelectTab(nil);
if(m_ReligionTabs.prevSelectedControl ~= nil) then
m_ReligionTabs.prevSelectedControl[DATA_FIELD_SELECTION]:SetHide(true);
end
end
-- Create TabSupport object
m_ReligionTabs = CreateTabs( Controls.TabContainer, 42, 34, UI.GetColorValueFromHexLiteral(0xFF331D05) );
-- Create my pantheon/religion tab
local religionData:table;
local playerReligionName:string;
if (m_PlayerReligionType >= 0) then
religionData = GameInfo.Religions[m_PlayerReligionType];
playerReligionName = TXT_MY_RELIGION;
elseif (m_NumBeliefsEarned > 0) then
playerReligionName = TXT_MY_RELIGION;
else
playerReligionName = TXT_MY_PANTHEON;
end
if(religionData == nil) then
m_MyReligionTab = AddTab(playerReligionName, nil, ViewMyReligion);
else
m_MyReligionTab = AddTab(playerReligionName, religionData, ViewMyReligion);
end
-- Create other religion tabs
local numFoundedReligions :number = 0;
local pAllReligions :table = m_pGameReligion:GetReligions();
for _, religionInfo in ipairs(pAllReligions) do
local religionType:number = religionInfo.Religion;
religionData = GameInfo.Religions[religionType];
if(religionData.Pantheon == false and m_pGameReligion:HasBeenFounded(religionType)) then
numFoundedReligions = numFoundedReligions + 1;
if(religionType ~= m_PlayerReligionType) then
AddTab(Game.GetReligion():GetName(religionType), religionData, function() ViewReligion(religionType); end);
end
end
end
--[[ DEBUG
for i=1,1 do
AddTab("Religion " .. i, "RELIGION_CATHOLICISM", function() ViewReligion(i); end);
numFoundedReligions = numFoundedReligions + 1;
end
--]]
-- Create "View All Religions" Tab
if(numFoundedReligions > 0) then
local maxReligions;
local mapSizeIndex = Map.GetMapSize();
local mapSize = GameInfo.Maps[mapSizeIndex];
local mapSizeType = mapSize and mapSize.MapSizeType;
if(mapSizeType) then
for row in GameInfo.Map_GreatPersonClasses() do
if(row.MapSizeType == mapSizeType and row.GreatPersonClassType == "GREAT_PERSON_CLASS_PROPHET") then
maxReligions = row.MaxWorldInstances;
end
end
end
if(maxReligions == nil) then
maxReligions = 0;
end
m_AllReligionsTab = AddTab(Locale.Lookup("LOC_UI_RELIGION_ALL_RELIGIONS", numFoundedReligions .. "/" .. maxReligions), nil, ViewAllReligions);
end
-- Determine size of all tabs, to ensure they fit
local totalSize:number = 0;
for _, tabButton in ipairs(m_ReligionTabs.tabControls) do
totalSize = totalSize + tabButton:GetSizeX() + PADDING_ICON + PADDING_TABS;
end
local numTabs:number = table.count(m_ReligionTabs.tabControls);
local smallSize:number = SIZE_RELIGION_ICON_SMALL + (PADDING_ICON * 2);
local bSmallTabs:boolean = totalSize > Controls.TabContainer:GetSizeX();
for i, tabButton in ipairs(m_ReligionTabs.tabControls) do
if(i ~= 1 and i ~= numTabs ) then
local tabIcons:table = tabButton[DATA_FIELD_ICONS];
if bSmallTabs then
tabButton:SetText("");
tabButton:SetSizeX(smallSize);
tabButton[DATA_FIELD_SELECTION]:SetSizeX(smallSize + 4);
tabIcons.Icon:SetOffsetX(PADDING_RELIGION_ICON_SMALL);
tabIcons.SelectionIcon:SetOffsetX(PADDING_RELIGION_ICON_SELECTION_SMALL);
tabButton:SetToolTipString(Game.GetReligion():GetName(tabButton[DATA_FIELD_INDEX]));
else
tabIcons.Icon:SetOffsetX(PADDING_RELIGION_ICON);
tabIcons.SelectionIcon:SetOffsetX(PADDING_RELIGION_ICON_SELECTION);
end
end
end
m_ReligionTabs.EvenlySpreadTabs();
end
function AddTab(label:string, religionData:table, onClickCallback:ifunction)
local tabInst:table = m_ReligionTabsIM:GetInstance();
-- Store Selection and Icon children on the Button, so we can access it in the callback function below
tabInst.Button[DATA_FIELD_SELECTION] = tabInst.Selection;
tabInst.Button[DATA_FIELD_ICONS] = { Icon = tabInst.Icon, SelectionIcon = tabInst.SelectionIcon };
tabInst.Button:SetText(label);
local textControl = tabInst.Button:GetTextControl();
textControl:SetHide(false);
local textSize:number = textControl:GetSizeX();
tabInst.Button:SetSizeX(textSize + PADDING_TAB_BUTTON_TEXT);
tabInst.Button:RegisterCallback(Mouse.eMouseEnter, function() UI.PlaySound("Main_Menu_Mouse_Over"); end);
tabInst.Selection:SetSizeX(textSize + PADDING_TAB_BUTTON_TEXT + 4);
if(religionData ~= nil) then
tabInst.Button[DATA_FIELD_INDEX] = religionData.Index;
local religionColor:number = UI.GetColorValue(religionData.Color);
local textureOffsetX:number, textureOffsetY:number, textureSheet:string = IconManager:FindIconAtlas("ICON_" .. religionData.ReligionType, SIZE_RELIGION_ICON_SMALL);
if(textureSheet == nil or textureSheet == "") then
error("Could not find icon in AddTab: icon=\""..icon.."\", iconSize="..tostring(SIZE_RELIGION_ICON_SMALL) );
else
tabInst.Icon:SetColor(religionColor);
tabInst.Icon:SetTexture(textureOffsetX, textureOffsetY, textureSheet);
tabInst.SelectionIcon:SetColor(religionColor);
tabInst.SelectionIcon:SetTexture(textureOffsetX, textureOffsetY, textureSheet);
tabInst.Icon:SetHide(false);
tabInst.SelectionIcon:SetHide(true);
end
else
tabInst.Icon:SetHide(true);
tabInst.SelectionIcon:SetHide(true);
end
local callback = function()
if(m_ReligionTabs.prevSelectedControl ~= nil) then
m_ReligionTabs.prevSelectedControl[DATA_FIELD_SELECTION]:SetHide(true);
m_ReligionTabs.prevSelectedControl[DATA_FIELD_ICONS].SelectionIcon:SetHide(true);
end
tabInst.Selection:SetHide(false);
tabInst.SelectionIcon:SetHide(false);
onClickCallback();
end
m_ReligionTabs.AddTab(tabInst.Button, callback);
return tabInst.Button;
end
-- ===========================================================================
-- Called when user clicks on "My Religion / Patheon" Tab
-- ===========================================================================
function ViewMyReligion()
-- Tell the player what the next step is (cases organized in order they should appear to player
if (m_PantheonBelief < 0) then
if (m_CanCreatePantheon) then
SelectPantheonBeliefs();
else
WorkingTowardsPantheon();
end
else
if (m_NumBeliefsEarned == 0) then
WorkingTowardsReligion();
else
if (m_PlayerReligionType < 0) then
ChooseReligion();
elseif (m_NumBeliefsEarned > m_NumBeliefsEquipped) then
m_SelectedBeliefs = {};
m_AddSelectedBeliefsIM:ResetInstances();
m_SelectedReligion = { ID = m_PlayerReligionType };
SelectReligionBeliefs();
else
ViewReligion(m_PlayerReligionType);
end
end
end
end
-- ===========================================================================
-- Called anytime screen switches state
-- ===========================================================================
function ResetState()
Controls.ViewReligion:SetHide(true);
Controls.ChooseReligion:SetHide(true);
Controls.AddBeliefs:SetHide(true);
Controls.AddConfirmBeliefs:SetHide(true);
Controls.AddReselectBeliefs:SetHide(true);
Controls.AddReselectReligion:SetHide(true);
Controls.SelectBeliefs:SetHide(true);
Controls.ConfirmBeliefs:SetHide(true);
Controls.ReselectBeliefs:SetHide(true);
Controls.ReselectReligion:SetHide(true);
Controls.SelectBeliefsPantheonIcon:SetHide(true);
Controls.SelectBeliefsPantheonImage:SetHide(true);
Controls.SelectBeliefsPantheonTitle:SetHide(true);
Controls.SelectBeliefsPantheonDescription:SetHide(true);
Controls.WorkingTowards:SetHide(true);
Controls.WorkingTowardsReligion:SetHide(true);
Controls.ViewAllReligions:SetHide(true);
end
-- ===========================================================================
-- Called if player does not yet have a Patheon
-- ===========================================================================
function WorkingTowardsPantheon()
ResetState();
Controls.WorkingTowards:SetHide(false);
Controls.WorkingTowardsPantheon:SetOffsetY(0);
Controls.WorkingTowardsPantheonTitle:LocalizeAndSetText("LOC_UI_RELIGION_NO_PANTHEON");
local iPantheonFaith = m_pGameReligion:GetMinimumFaithNextPantheon();
Controls.WorkingTowardsPantheonEffect:LocalizeAndSetText("LOC_RELIGIONPANEL_NEXT_STEP_FOUND_PANTHEON", iPantheonFaith);
Controls.WorkingTowardsPantheonStatus:SetText(Locale.ToUpper(Locale.Lookup("LOC_UI_RELIGION_WORKING_TOWARDS_PANTHEON")));
RealizeStack(Controls.WorkingTowardsPantheonStack);
end
-- ===========================================================================
-- Called if player has a Pantheon, but does not yet have a Religion
-- ===========================================================================
function WorkingTowardsReligion()
ResetState();
Controls.WorkingTowards:SetHide(false);
Controls.WorkingTowardsReligion:SetHide(false);
Controls.WorkingTowardsPantheon:SetOffsetY(OFFSET_WORKING_TOWARDS_PANTHEON);
Controls.WorkingTowardsReligionTitle:SetText(Locale.ToUpper(Locale.Lookup("LOC_UI_RELIGION_WORKING_TOWARDS_RELIGION")));
if (m_isHasProphet == false) then
Controls.WorkingTowardsReligionDesc:LocalizeAndSetText("LOC_RELIGIONPANEL_NEXT_STEP_EARN_PROPHET");
else
Controls.WorkingTowardsReligionDesc:LocalizeAndSetText("LOC_RELIGIONPANEL_NEXT_STEP_USE_PROPHET");
end
local beliefName:string = "";
local beliefDesc:string = "";
if(m_PantheonBelief >= 0) then
beliefName = Locale.Lookup(GameInfo.Beliefs[m_PantheonBelief].Name);
beliefDesc = Locale.Lookup(GameInfo.Beliefs[m_PantheonBelief].Description);
end
Controls.WorkingTowardsPantheonTitle:SetText(Locale.ToUpper(Locale.Lookup("LOC_UI_RELIGION_PANTHEON_NAME", beliefName)));
Controls.WorkingTowardsPantheonStatus:SetText(Locale.ToUpper(Locale.Lookup("LOC_UI_RELIGION_PANTHEON_EFFECT")));
Controls.WorkingTowardsPantheonEffect:LocalizeAndSetText(beliefDesc);
RealizeStack(Controls.WorkingTowardsReligionStack);
RealizeStack(Controls.WorkingTowardsPantheonStack);
end
-- ===========================================================================
-- Called if player is creating a new Patheon / Religion
-- ===========================================================================
function RealizeStack(stackControl:table, scrollControl:table, jumpToEnd:boolean)
local instanceHeight = 0;
if(stackControl ~= nil) then
local prevHeight = stackControl:GetSizeY();
stackControl:CalculateSize();
stackControl:ReprocessAnchoring();
instanceHeight = math.abs(stackControl:GetSizeY() - prevHeight);
end
if(scrollControl ~= nil) then
scrollControl:CalculateSize();
scrollControl:ReprocessAnchoring();
if(jumpToEnd ~= nil) then
if(jumpToEnd) then
if(stackControl:GetSizeY() > scrollControl:GetSizeY()) then
scrollControl:SetScrollValue(scrollControl:GetSizeY() + instanceHeight);
else
scrollControl:SetScrollValue(0);
end
end
else
scrollControl:SetScrollValue(0);
end
end
end
function SetBeliefSlotDisabled(beliefInst:table, bDisable:boolean)
beliefInst.BeliefButton:SetDisabled(bDisable);
if(bDisable) then
beliefInst.BeliefIcon:SetColor(UI.GetColorValueFromHexLiteral(0xFF808080));
beliefInst.BeliefLabel:SetColor(UI.GetColorValueFromHexLiteral(0xFF808080));
beliefInst.BeliefDescription:SetColor(UI.GetColorValueFromHexLiteral(0xFF808080));
else
beliefInst.BeliefIcon:SetColor(UI.GetColorValue("COLOR_WHITE"));
beliefInst.BeliefLabel:SetColor(UI.GetColorValueFromHexLiteral(0xFFB2A797));
beliefInst.BeliefDescription:SetColor(UI.GetColorValueFromHexLiteral(0xFFB2A797));
end
end
function PopulateAvailableBeliefs(beliefType:string)
m_Beliefs.IM:ResetInstances();
for row in GameInfo.Beliefs() do
local bBeliefTypeAlreadySelected:boolean = false;
for _, beliefID in ipairs(m_SelectedBeliefs) do
if row.BeliefClassType == GameInfo.Beliefs[beliefID].BeliefClassType then
bBeliefTypeAlreadySelected = true;
break;
end
end
if (not bBeliefTypeAlreadySelected and
not m_pGameReligion:IsInSomePantheon(row.Index) and
not m_pGameReligion:IsInSomeReligion(row.Index) and
not m_pGameReligion:IsTooManyForReligion(row.Index, m_PlayerReligionType) and
((beliefType ~= nil and row.BeliefClassType == beliefType) or
(beliefType == nil and row.BeliefClassType ~= "BELIEF_CLASS_PANTHEON"))) then
local beliefInst:table = m_Beliefs.IM:GetInstance();
beliefInst.BeliefLabel:LocalizeAndSetText(Locale.ToUpper(row.Name));
beliefInst.BeliefDescription:LocalizeAndSetText(row.Description);
beliefInst.BeliefButton:RegisterCallback(Mouse.eMouseEnter, function() UI.PlaySound("Main_Menu_Mouse_Over"); end);
beliefInst.BeliefButton:RegisterCallback(Mouse.eLClick, function() OnBeliefSelected(row.Index, beliefInst) end);
SetBeliefIcon(beliefInst.BeliefIcon, row.BeliefType, SIZE_BELIEF_ICON_LARGE);
SetBeliefSlotDisabled(beliefInst, false);
end
end
RealizeStack(m_Beliefs.Stack, m_Beliefs.Scrollbar);
end
function OnBeliefSelected(beliefID:number, availableBeliefInst:table)
SetBeliefSlotDisabled(availableBeliefInst, true);
AddSelectedBelief(beliefID);
RealizeStack(m_PendingBeliefs.Stack, m_PendingBeliefs.Scrollbar, true);
table.insert(m_SelectedBeliefs, beliefID);
if (m_PantheonBelief < 0) then
ConfirmPantheonBeliefs();
elseif(table.count(m_SelectedBeliefs) + m_NumBeliefsEquipped >= m_NumBeliefsEarned) then
ConfirmReligionBeliefs();
else
PopulateAvailableBeliefs();
end
end
function AddSelectedBelief(beliefID:number)
local beliefInst:table = m_PendingBeliefs.IM:GetInstance();
local beliefData:table = GameInfo.Beliefs[beliefID];
beliefInst.BeliefLabel:LocalizeAndSetText(Locale.ToUpper(beliefData.Name));
beliefInst.BeliefDescription:LocalizeAndSetText(beliefData.Description);
beliefInst.BeliefButton:RegisterCallback(Mouse.eLClick, function() OnBeliefUnSelected(beliefID, beliefInst, availableBeliefInst) end);
beliefInst.BeliefButton:RegisterCallback(Mouse.eMouseEnter, function() UI.PlaySound("Main_Menu_Mouse_Over"); end);
SetBeliefIcon(beliefInst.BeliefIcon, beliefData.BeliefType, SIZE_BELIEF_ICON_LARGE);
end
function OnBeliefUnSelected(beliefID:number, selectedBeliefInst:table, availableBeliefInst:table)
-- Is this even necessary anymore? -sbatista
if availableBeliefInst then
SetBeliefSlotDisabled(availableBeliefInst, false);
end
m_PendingBeliefs.IM:ReleaseInstance(selectedBeliefInst);
RealizeStack(m_PendingBeliefs.Stack, m_PendingBeliefs.Scrollbar, true);
local beliefClass:string = GameInfo.Beliefs[beliefID].BeliefClassType;
if beliefClass == "BELIEF_CLASS_FOLLOWER" then
m_PendingBeliefs.IM:ResetInstances();
else
m_PendingBeliefs.IM:ReleaseInstance(selectedBeliefInst);
end
for i = table.count(m_SelectedBeliefs), 1, -1 do
if beliefID == m_SelectedBeliefs[i] or beliefClass == "BELIEF_CLASS_FOLLOWER" then
table.remove(m_SelectedBeliefs, i);
end
end
if(m_isConfirmingBeliefs) then
if (m_PantheonBelief < 0) then
SelectPantheonBeliefs();
else
SelectReligionBeliefs();
end
elseif(m_PantheonBelief >= 0) then
if(table.count(m_SelectedBeliefs) + m_NumBeliefsEquipped >= 1) then
PopulateAvailableBeliefs();
else
PopulateAvailableBeliefs("BELIEF_CLASS_FOLLOWER");
end
end
end
function SelectPantheonBeliefs()
ResetState();
m_SelectedBeliefs = {};
m_isConfirmingBeliefs = false;
m_Beliefs = { IM = m_SelectBeliefsIM, Stack = Controls.AvailableBeliefs, Scrollbar = Controls.AvailableBeliefsScrollbar };
m_PendingBeliefs = { IM = m_SelectedBeliefsIM, Stack = Controls.SelectedBeliefs, Scrollbar = SelectedBeliefsScrollbar };
m_PendingBeliefs.IM:ResetInstances();
Controls.ChooseBelief:SetHide(false);
Controls.SelectBeliefs:SetHide(false);
Controls.ChooseBeliefTitle:SetText(Locale.ToUpper(Locale.Lookup("LOC_UI_RELIGION_CHOOSE_PANTHEON_BELIEF")));
Controls.ReligionOrPatheonTitle:SetText(Locale.ToUpper(Locale.Lookup("LOC_UI_RELIGION_CHOOSING_PANTHEON")));
Controls.ReligionOrPatheonImage:SetOffsetY(OFFSET_CHOOSING_PANTHEON_BELIEFS);
SetReligionIcon(Controls.ReligionOrPatheonImage);
PopulateAvailableBeliefs("BELIEF_CLASS_PANTHEON");
end
function ConfirmPantheonBeliefs()
ResetState();
m_isConfirmingBeliefs = true;
m_isConfirmedBeliefs = false;
Controls.ChooseBelief:SetHide(true);
Controls.SelectBeliefs:SetHide(false);
Controls.ConfirmBeliefs:SetHide(false);
Controls.ReselectBeliefs:SetHide(false);
local beliefName:string = "";
if(m_SelectedBeliefs[1] >= 0) then
beliefName = Locale.Lookup(GameInfo.Beliefs[m_SelectedBeliefs[1]].Name);
end
Controls.ReligionOrPatheonTitle:SetText(Locale.ToUpper(Locale.Lookup("LOC_UI_RELIGION_PANTHEON_NAME", beliefName)));
Controls.ReselectBeliefs:LocalizeAndSetText("LOC_UI_RELIGION_RESELECT_BELIEFS");
Controls.ReselectBeliefs:RegisterCallback(Mouse.eLClick, SelectPantheonBeliefs);
Controls.ReselectBeliefs:RegisterCallback(Mouse.eMouseEnter, function() UI.PlaySound("Main_Menu_Mouse_Over"); end);
Controls.ConfirmBeliefs:LocalizeAndSetText("LOC_UI_RELIGION_FOUND_PANTHEON");
Controls.ConfirmBeliefs:RegisterCallback(Mouse.eMouseEnter, function() UI.PlaySound("Main_Menu_Mouse_Over"); end);
Controls.ConfirmBeliefs:RegisterCallback(Mouse.eLClick, function()
if not m_isConfirmedBeliefs then
m_isConfirmedBeliefs = true;
local tParameters:table = {};
tParameters[PlayerOperations.PARAM_BELIEF_TYPE] = GameInfo.Beliefs[m_SelectedBeliefs[1]].Hash;
tParameters[PlayerOperations.PARAM_INSERT_MODE] = PlayerOperations.VALUE_EXCLUSIVE;
UI.RequestPlayerOperation(Game.GetLocalPlayer(), PlayerOperations.FOUND_PANTHEON, tParameters);
UI.PlaySound("Confirm_Religion");
end
end);
end
function ChooseReligion()
ResetState();
m_SelectedBeliefs = {};
if(m_PendingBeliefs ~= nil) then
m_PendingBeliefs.IM:ResetInstances();
end
if(m_SelectedReligion ~= nil) then
if(m_SelectedReligion.Instance ~= nil) then
m_SelectedReligion.Instance.ReligionButton:SetSelected(false);
end
m_SelectedReligion = nil;
end
m_ReligionSelections:ResetInstances();
Controls.ChooseReligion:SetHide(false);
Controls.ConfirmReligion:LocalizeAndSetText("LOC_UI_RELIGION_CONFIRM_RELIGION");
Controls.ChooseReligionName:LocalizeAndSetText("LOC_UI_RELIGION_CHOOSE_RELIGION_NAME");
Controls.ChooseReligionTitle:LocalizeAndSetText(Locale.ToUpper("LOC_UI_RELIGION_CHOOSE_RELIGION"));
Controls.PendingReligionTitle:LocalizeAndSetText(Locale.ToUpper("LOC_UI_RELIGION_NO_RELIGION_CHOSEN"));
Controls.PendingReligionStatus:LocalizeAndSetText(Locale.ToUpper("LOC_UI_RELIGION_FOUNDING_RELIGION"));
Controls.PendingReligionEffect:LocalizeAndSetText("LOC_UI_RELIGION_FOUNDING_RELIGION_INSTRUCTIONS");
Controls.ChooseReligionName:RegisterStringChangedCallback(function(editBox)
local userInput:string = editBox:GetText();
if IsReligionNameValid(userInput) then
Controls.ConfirmReligion:SetDisabled(m_SelectedReligion == nil);
Controls.PendingReligionTitle:SetText(Locale.ToUpper(userInput));
else
Controls.ConfirmReligion:SetDisabled(true);
Controls.PendingReligionTitle:LocalizeAndSetText(Locale.ToUpper("LOC_UI_RELIGION_REQUIRES_NAME"));
end
end);
Controls.ConfirmReligion:RegisterCallback(Mouse.eMouseEnter, function() UI.PlaySound("Main_Menu_Mouse_Over"); end);
Controls.ConfirmReligion:RegisterCallback(Mouse.eLClick, SelectReligionBeliefs);
for row in GameInfo.Religions() do
if (row.Pantheon == false and not m_pGameReligion:HasBeenFounded(row.Index)) then
local religionInst = m_ReligionSelections:GetInstance();
SetReligionIcon(religionInst.ReligionImage, row.ReligionType, SIZE_RELIGION_ICON_LARGE, row.Color);
local religionName:string = Locale.Lookup(row.Name);
religionInst.ReligionButton:SetToolTipString(religionName);
religionInst.ReligionButton:RegisterCallback(Mouse.eMouseEnter, function() UI.PlaySound("Main_Menu_Mouse_Over"); end);
religionInst.ReligionButton:RegisterCallback(Mouse.eLClick, function()
if(m_SelectedReligion ~= nil) then
if(m_SelectedReligion.Instance ~= religionInst) then
m_SelectedReligion.Instance.ReligionButton:SetSelected(false);
m_SelectedReligion.Instance = religionInst;
m_SelectedReligion.ID = row.Index;
end
else
m_SelectedReligion = { ID = row.Index, Instance = religionInst };
end
religionInst.ReligionButton:SetSelected(true);
SetReligionIcon(Controls.PendingReligionImage, row.ReligionType, SIZE_RELIGION_ICON_HUGE, row.Color);
local canChangeName = GameCapabilities.HasCapability("CAPABILITY_RENAME");
if(row.RequiresCustomName and canChangeName) then
Controls.ConfirmReligion:SetDisabled(true);
Controls.PendingReligionTitle:LocalizeAndSetText("LOC_UI_RELIGION_REQUIRES_NAME");
Controls.ChooseReligionName:SetDisabled(false);
Controls.ChooseReligionNameButton:SetDisabled(false);
Controls.ChooseReligionName:SetText("");
Controls.ChooseReligionName:TakeFocus();
else
Controls.ChooseReligionName:SetDisabled(true);
Controls.ChooseReligionNameButton:SetDisabled(true);
Controls.ChooseReligionName:SetText(religionName);
Controls.PendingReligionTitle:SetText(Locale.ToUpper(religionName));
Controls.ConfirmReligion:SetDisabled(m_SelectedReligion == nil);
end
end);
end
end
SetReligionIcon(Controls.PendingReligionImage);
RealizeStack(Controls.ChooseReligionItems, Controls.ChooseReligionScrollbar);
end
-- ===========================================================================
function IsReligionNameValid(name:string)
if name ~= nil then
-- If it's really just the label in the customize name edit box, mark it as not being valid.
if Locale.ToUpper(name) == Locale.ToUpper(Locale.Lookup("LOC_UI_RELIGION_CHOOSE_RELIGION_NAME")) then
return false;
end
for i = 1, #name do
local c = name:sub(i,i)
if(c ~= " ") then return true; end
end
end
return false;
end
function SelectReligionBeliefs()
ResetState();
if(m_PendingBeliefs ~= nil) then
--Likely in hotseat mode, previous player's choices were still presesnt.
m_PendingBeliefs.IM:ResetInstances();
if table.count(m_SelectedBeliefs) > 0 then
for _, beliefIndex in ipairs(m_SelectedBeliefs) do
AddSelectedBelief(beliefIndex);
end
RealizeStack(m_PendingBeliefs.Stack, m_PendingBeliefs.Scrollbar, true);
end
end
m_isConfirmingBeliefs = false;
local pantheonBelief:table = GameInfo.Beliefs[m_PantheonBelief];
local religionData:table = GameInfo.Religions[m_SelectedReligion.ID];
if(m_NumBeliefsEquipped == 0) then
m_Beliefs = { IM = m_SelectBeliefsIM, Stack = Controls.AvailableBeliefs, Scrollbar = Controls.AvailableBeliefsScrollbar };
m_PendingBeliefs = { IM = m_SelectedBeliefsIM, Stack = Controls.SelectedBeliefs, Scrollbar = SelectedBeliefsScrollbar };
Controls.ChooseBelief:SetHide(false);
Controls.SelectBeliefs:SetHide(false);
Controls.SelectBeliefsPantheonIcon:SetHide(false);
Controls.SelectBeliefsPantheonImage:SetHide(false);
Controls.SelectBeliefsPantheonTitle:SetHide(false);
Controls.SelectBeliefsPantheonDescription:SetHide(false);
Controls.ReligionOrPatheonImage:SetOffsetX(OFFSET_CHOOSING_RELIGION_BELIEFS);
Controls.SelectBeliefsPantheonTitle:SetOffsetX(OFFSET_CHOOSING_RELIGION_BELIEFS);
Controls.SelectBeliefsPantheonTitle:SetText(Locale.ToUpper(Locale.Lookup("LOC_UI_RELIGION_PANTHEON_NAME", pantheonBelief.Name)));
Controls.SelectBeliefsPantheonDescription:LocalizeAndSetText(pantheonBelief.Description);
SetBeliefIcon(Controls.SelectBeliefsPantheonIcon, pantheonBelief.BeliefType, SIZE_BELIEF_ICON_LARGE);
local szPendingTitle = Controls.PendingReligionTitle:GetText();
if szPendingTitle then
Controls.ReligionOrPatheonTitle:LocalizeAndSetText(szPendingTitle);
elseif m_PlayerReligionType >= 0 then
Controls.ReligionOrPatheonTitle:LocalizeAndSetText(GameInfo.Religions[m_PlayerReligionType].Name);
else
UI.DataError("Failed to set text on ReligionOrPatheonTitle");
end
Controls.ChooseBeliefTitle:LocalizeAndSetText(Locale.ToUpper("LOC_UI_RELIGION_CHOOSE_RELIGION_BELIEF"));
SetReligionIcon(Controls.ReligionOrPatheonImage, religionData.ReligionType, SIZE_RELIGION_ICON_HUGE, religionData.Color);
else
m_Beliefs = { IM = m_AddAvailableBeliefsIM, Stack = Controls.AddAvailableBeliefs, Scrollbar = Controls.AddAvailableBeliefsScrollbar };
m_PendingBeliefs = { IM = m_AddSelectedBeliefsIM, Stack = Controls.AddBeliefsReligionBeliefs, Scrollbar = Controls.AddBeliefsReligionScroll };
Controls.AddBelief:SetHide(false);
Controls.AddBeliefs:SetHide(false);
Controls.AddBeliefsPantheonTitle:SetText(Locale.ToUpper(Locale.Lookup("LOC_UI_RELIGION_PANTHEON_NAME", pantheonBelief.Name)));
Controls.AddBeliefsPantheonDescription:LocalizeAndSetText(pantheonBelief.Description);
SetBeliefIcon(Controls.AddBeliefsPantheonIcon, pantheonBelief.BeliefType, SIZE_BELIEF_ICON_LARGE);
Controls.AddBeliefsReligionTitle:LocalizeAndSetText(Locale.ToUpper(religionData.Name));
Controls.AddBeliefTitle:LocalizeAndSetText(Locale.ToUpper("LOC_UI_RELIGION_CHOOSE_A_BELIEF"));
SetReligionIcon(Controls.AddBeliefsReligionImage, religionData.ReligionType, SIZE_RELIGION_ICON_HUGE, religionData.Color);
local religion:table = nil;
for _, tmp in ipairs(m_pGameReligion:GetReligions()) do
if (tmp.Religion == m_PlayerReligionType) then
religion = tmp;
break;
end
end
m_ExistingReligionBeliefsIM:ResetInstances();
for _, beliefIndex in ipairs(religion.Beliefs) do
belief = GameInfo.Beliefs[beliefIndex];
local beliefInst:table = m_ExistingReligionBeliefsIM:GetInstance();
beliefInst.BeliefBG:SetColor(UI.GetColorValue("COLOR_WHITE"));
beliefInst.BeliefLabel:LocalizeAndSetText(Locale.ToUpper(belief.Name));
beliefInst.BeliefDescription:LocalizeAndSetText(belief.Description);
SetBeliefIcon(beliefInst.BeliefIcon, belief.BeliefType, SIZE_BELIEF_ICON_LARGE);
beliefInst.BeliefIcon:SetHide(false);
end
Controls.AddBeliefsReligionScroll:CalculateSize();
local ownerPlayer:table = Players[religion.Founder];
local playerReligion:table = ownerPlayer:GetReligion();
local religionData:table = GameInfo.Religions[m_PlayerReligionType];
local civID:number = PlayerConfigurations[religion.Founder]:GetCivilizationTypeID();
local civName:string = Locale.Lookup(GameInfo.Civilizations[civID].Name);
local holyCity:table = CityManager.GetCity(playerReligion:GetHolyCityID());
Controls.AddBeliefsReligionHolyCity:SetText(Locale.ToUpper(Locale.Lookup("LOC_UI_RELIGION_HOLY_CITY", holyCity:GetName())));
Controls.AddBeliefsReligionTitle:LocalizeAndSetText(Locale.ToUpper(religionData.Name));
Controls.AddBeliefsReligionFounder:SetText(Locale.ToUpper(Locale.Lookup("LOC_UI_RELIGION_FOUNDER_NAME", civName)));
Controls.AddBeliefsReligionBeliefsHeader:SetText(Locale.ToUpper(Locale.Lookup("LOC_UI_RELIGION_BELIEFS_OF_RELIGION", religionData.Name)))
RealizeStack(Controls.AddBeliefsReligionStack, Controls.AddBeliefsReligionScroll);
if table.count(m_SelectedBeliefs) > 0 then
for _, beliefIndex in ipairs(m_SelectedBeliefs) do
AddSelectedBelief(beliefIndex);
end
RealizeStack(m_PendingBeliefs.Stack, m_PendingBeliefs.Scrollbar, true);
end
-- Gather data necessary for cities panel
local numDominantCities:number = 0;
local majorPlayers:table = PlayerManager.GetAlive();
for _, player in ipairs(majorPlayers) do
local playerCities:table = player:GetCities();
for _, city in playerCities:Members() do
local cityReligion:table = city:GetReligion();
if(cityReligion:GetMajorityReligion() == m_PlayerReligionType) then
numDominantCities = numDominantCities + 1;
end
end
end
-- Update dominant city text
if(numDominantCities > 1) then
Controls.AddBeliefsReligionDominance:SetText(Locale.ToUpper(Locale.Lookup("LOC_UI_RELIGION_RELIGION_DOMINANCE_PLURAL", numDominantCities)));
else
Controls.AddBeliefsReligionDominance:SetText(Locale.ToUpper(Locale.Lookup("LOC_UI_RELIGION_RELIGION_DOMINANCE", numDominantCities)));
end
end
if(table.count(m_SelectedBeliefs) + m_NumBeliefsEquipped >= 1) then
PopulateAvailableBeliefs();
else
PopulateAvailableBeliefs("BELIEF_CLASS_FOLLOWER");
end
end
function ConfirmReligionBeliefs()
ResetState();
m_isConfirmedBeliefs = false;
m_isConfirmingBeliefs = true;
local confirmBeliefsButton:table;
local reselectBeliefsButton:table;
local reselectReligionButton:table;
if(m_NumBeliefsEquipped == 0) then
Controls.SelectBeliefs:SetHide(false);
confirmBeliefsButton = Controls.ConfirmBeliefs;
reselectBeliefsButton = Controls.ReselectBeliefs;
reselectReligionButton = Controls.ReselectReligion;
else
Controls.AddBeliefs:SetHide(false);
confirmBeliefsButton = Controls.AddConfirmBeliefs;
reselectBeliefsButton = Controls.AddReselectBeliefs;
reselectReligionButton = Controls.AddReselectReligion;
end
Controls.AddBelief:SetHide(true);
Controls.ChooseBelief:SetHide(true);
confirmBeliefsButton:SetHide(false);
reselectBeliefsButton:SetHide(false);
Controls.SelectBeliefsPantheonIcon:SetHide(false);
Controls.SelectBeliefsPantheonImage:SetHide(false);
Controls.SelectBeliefsPantheonTitle:SetHide(false);
Controls.SelectBeliefsPantheonDescription:SetHide(false);
local pantheonBelief:table = GameInfo.Beliefs[m_PantheonBelief];
Controls.SelectBeliefsPantheonTitle:SetText(Locale.ToUpper(Locale.Lookup("LOC_UI_RELIGION_PANTHEON_NAME", pantheonBelief.Name)));
Controls.SelectBeliefsPantheonDescription:LocalizeAndSetText(pantheonBelief.Description);
if (m_PlayerReligionType >= 0) then
reselectReligionButton:SetHide(true);
confirmBeliefsButton:SetText(Locale.Lookup("LOC_UI_RELIGION_CONFIRM_RELIGION"));
reselectBeliefsButton:SetText(Locale.Lookup("LOC_UI_RELIGION_RESELECT_BELIEF"));
else
reselectReligionButton:SetHide(false);
confirmBeliefsButton:SetText(Locale.Lookup("LOC_UI_RELIGION_FOUND_RELIGION"));
reselectBeliefsButton:SetText(Locale.Lookup("LOC_UI_RELIGION_RESELECT_BELIEFS"));
end
reselectBeliefsButton:RegisterCallback(Mouse.eMouseEnter, function() UI.PlaySound("Main_Menu_Mouse_Over"); end);
reselectBeliefsButton:RegisterCallback(Mouse.eLClick, function()
m_SelectedBeliefs = {};
if(m_PendingBeliefs ~= nil) then
m_PendingBeliefs.IM:ResetInstances();
RealizeStack(m_PendingBeliefs.Stack, m_PendingBeliefs.Scrollbar);
end
SelectReligionBeliefs();
end);
reselectReligionButton:LocalizeAndSetText("LOC_UI_RELIGION_RESELECT_RELIGION");
reselectReligionButton:RegisterCallback(Mouse.eLClick, ChooseReligion);
reselectReligionButton:RegisterCallback(Mouse.eMouseEnter, function() UI.PlaySound("Main_Menu_Mouse_Over"); end);
confirmBeliefsButton:RegisterCallback(Mouse.eLClick, function()
confirmBeliefsButton:RegisterCallback(Mouse.eMouseEnter, function() UI.PlaySound("Main_Menu_Mouse_Over"); end);
if not m_isConfirmedBeliefs then
m_isConfirmedBeliefs = true;
if (m_PlayerReligionType < 0) then
local tParameters = {};
tParameters[PlayerOperations.PARAM_INSERT_MODE] = PlayerOperations.VALUE_EXCLUSIVE;
tParameters[PlayerOperations.PARAM_RELIGION_TYPE] = GameInfo.Religions[m_SelectedReligion.ID].Hash;
if(GameInfo.Religions[m_SelectedReligion.ID].RequiresCustomName) then
tParameters[PlayerOperations.PARAM_RELIGION_CUSTOM_NAME] = Controls.ChooseReligionName:GetText();
end
UI.RequestPlayerOperation(Game.GetLocalPlayer(), PlayerOperations.FOUND_RELIGION, tParameters);
end
for _, belief in ipairs(m_SelectedBeliefs) do
local tParameters = {};
tParameters[PlayerOperations.PARAM_BELIEF_TYPE] = GameInfo.Beliefs[belief].Hash;
tParameters[PlayerOperations.PARAM_INSERT_MODE] = PlayerOperations.VALUE_EXCLUSIVE;
UI.RequestPlayerOperation(Game.GetLocalPlayer(), PlayerOperations.ADD_BELIEF, tParameters);
end
UI.PlaySound("Confirm_Religion");
if (m_PlayerReligionType >= 0) then
Close();
end
end
end);
end
function SetReligionIcon(targetControl:table, religionType:string, iconSize:number, religionColor:string)
if(religionType ~= nil) then
local textureOffsetX:number, textureOffsetY:number, textureSheet:string = IconManager:FindIconAtlas("ICON_" .. religionType, iconSize);
if(textureSheet == nil or textureSheet == "") then
error("Could not find icon in SetReligionIcon: religionType=\""..religionType.."\", iconSize="..tostring(iconSize) );
else
targetControl:SetTexture(textureOffsetX, textureOffsetY, textureSheet);
targetControl:SetSizeVal(iconSize, iconSize);
end
else
Controls.PendingReligionImage:SetTexture(0,0,"Religion_Generic");
Controls.PendingReligionImage:SetSizeVal(SIZE_RELIGION_ICON_HUGE, SIZE_RELIGION_ICON_HUGE);
end
if(religionColor == nil) then
targetControl:SetColor(UI.GetColorValue("COLOR_WHITE"));
Controls.PendingReligionImage:SetColor(UI.GetColorValue("COLOR_WHITE"));
else
targetControl:SetColor(UI.GetColorValue(religionColor));
Controls.PendingReligionImage:SetColor(UI.GetColorValue(religionColor));
end
end
function SetBeliefIcon(targetControl:table, beliefType:string, iconSize:number)
local textureOffsetX:number, textureOffsetY:number, textureSheet:string = IconManager:FindIconAtlas("ICON_" .. beliefType, iconSize);
if(textureSheet == nil or textureSheet == "") then
error("Could not find icon in SetBeliefIcon: beliefType=\""..beliefType.."\", iconSize="..tostring(iconSize) );
else
targetControl:SetTexture(textureOffsetX, textureOffsetY, textureSheet);
targetControl:SetSizeVal(iconSize, iconSize);
end
end
-- ===========================================================================
-- Called if player selects any religion tab
-- ===========================================================================
function ViewReligion(religionType:number)
ResetState();
-- Ensure we are trying to view a valid religion
local religion:table = nil;
for _, tmp in ipairs(m_pGameReligion:GetReligions()) do
if (tmp.Religion == religionType) then
religion = tmp;
break;
end
end
if(religion == nil or not m_pGameReligion:HasBeenFounded(religionType)) then
print("Error, attempting to view 'nil' or 'unfounded' religion, religionType=" .. religionType);
return;
end
Controls.ViewReligion:SetHide(false);
if(m_SelectedReligion ~= nil and m_SelectedReligion.Instance ~= nil) then
m_SelectedReligion.Instance.ReligionButton:SetSelected(false);
end
m_SelectedReligion = { ID = religionType };
-- Gather player data
local ownerPlayer:table = Players[religion.Founder];
local localPlayerID:number = GetDisplayPlayerID();
local localPlayer:table = Players[localPlayerID];
local localDiplomacy:table = localPlayer:GetDiplomacy();
local playerReligion:table = ownerPlayer:GetReligion();
local religionData:table = GameInfo.Religions[religionType];
local pantheonBelief:number = playerReligion:GetPantheon();
local belief:table= GameInfo.Beliefs[pantheonBelief];
local civID:number = PlayerConfigurations[religion.Founder]:GetCivilizationTypeID();
if religion.Founder == localPlayerID or localDiplomacy:HasMet(religion.Founder) or Game.GetLocalObserver() == PlayerTypes.OBSERVER then
local civName:string = Locale.Lookup(GameInfo.Civilizations[civID].Name);
Controls.ViewReligionFounder:SetText(Locale.ToUpper(Locale.Lookup("LOC_UI_RELIGION_FOUNDER_NAME", civName)));
local holyCity:table = CityManager.GetCity(playerReligion:GetHolyCityID());
if holyCity ~= nil then
Controls.ViewReligionHolyCity:SetText(Locale.ToUpper(Locale.Lookup("LOC_UI_RELIGION_HOLY_CITY", holyCity:GetName())));
else
Controls.ViewReligionHolyCity:LocalizeAndSetText(Locale.ToUpper("LOC_UI_RELIGION_HOLY_CITY_NONE"));
end
else
Controls.ViewReligionFounder:SetText(Locale.ToUpper(Locale.Lookup("LOC_UI_RELIGION_FOUNDER_NAME", Locale.Lookup("LOC_DIPLOPANEL_UNMET_PLAYER"))));