forked from Azurency/Civ6-UIFiles
-
Notifications
You must be signed in to change notification settings - Fork 1
/
MinimapPanel.lua
1124 lines (981 loc) · 44.8 KB
/
MinimapPanel.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 2016-2018, Firaxis Games
include( "InstanceManager" );
include("GameCapabilities");
-- ===========================================================================
-- CONSTANTS
-- ===========================================================================
local MINIMAP_COLLAPSED_OFFSETY :number = -180;
local LENS_PANEL_OFFSET :number = 50;
local MINIMAP_BACKING_PADDING_SIZEY :number = 54;
local MAP_OPTIONS_PADDING :number = 80;
-- ===========================================================================
-- GLOBALS
-- ===========================================================================
g_shouldCloseLensMenu = true; -- Controls when the Lens menu should be closed.
g_ContinentsCache = {};
g_HexColoringContinent = UILens.CreateLensLayerHash("Hex_Coloring_Continent");
-- ===========================================================================
-- MEMBERS
-- ===========================================================================
--local m_OptionsButtonManager= InstanceManager:new( "MiniMapOptionButtonInstance", "Top", Controls.OptionsStack );
local m_LensButtonIM :table = InstanceManager:new("LensButtonInstance", "LensButton", Controls.LensToggleStack);
local m_MapOptionIM :table = InstanceManager:new("MapOptionInstance", "ToggleButton", Controls.MapOptionsStack);
local m_OptionButtons :table = {}; -- option buttons indexed by buttonName.
local iZoomIncrement :number = 2;
local m_isCollapsed :boolean= false;
local m_ContinentsCreated :boolean=false;
local m_MiniMap_xmloffsety :number = 0;
local m_kFlyoutControlIds :table = { "MapOptions", "Lens", "MapPinList", "MapSearch" }; -- Name of controls that are the backing for "flyout" menus.
local m_ToggleReligionLensId = -1;
local m_ToggleContinentLensId = -1;
local m_ToggleAppealLensId = -1;
local m_ToggleSettlerLensId = -1;
local m_ToggleGovernmentLensId = -1;
local m_TogglePoliticalLensId = -1;
local m_ToggleTourismLensId = -1;
local m_ToggleEmpireLensId = -1;
local m_Toggle2DViewId = Input.GetActionId("Toggle2DView");
local m_OpenMapSearchId = -1;
local m_isMouseDragEnabled :boolean = true; -- Can the camera be moved by dragging on the minimap?
local m_isMouseDragging :boolean = false; -- Was LMB clicked inside the minimap, and has not been released yet?
local m_hasMouseDragged :boolean = false; -- Has there been any movements since m_isMouseDragging became true?
local m_wasMouseInMinimap :boolean = false; -- Was the mouse over the minimap the last time we checked?
local m_HexColoringReligion : number = UILens.CreateLensLayerHash("Hex_Coloring_Religion");
local m_HexColoringAppeal : number = UILens.CreateLensLayerHash("Hex_Coloring_Appeal_Level");
local m_HexColoringGovernment : number = UILens.CreateLensLayerHash("Hex_Coloring_Government");
local m_HexColoringOwningCiv : number = UILens.CreateLensLayerHash("Hex_Coloring_Owning_Civ");
local m_HexColoringWaterAvail : number = UILens.CreateLensLayerHash("Hex_Coloring_Water_Availablity");
local m_TouristTokens : number = UILens.CreateLensLayerHash("Tourist_Tokens");
-- ===========================================================================
-- FUNCTIONS
-- ===========================================================================
-- ===========================================================================
function GetContinentsCache()
if g_ContinentsCache == nil then
g_ContinentsCache = Map.GetContinentsInUse();
end
end
-- ===========================================================================
function OnZoomIn()
UI.ZoomMap( iZoomIncrement );
end
-- ===========================================================================
function OnZoomOut()
UI.ZoomMap( -iZoomIncrement );
end
-- ===========================================================================
function CloseAllFlyouts()
for _,id in ipairs(m_kFlyoutControlIds) do
local panelId = id.."Panel"; -- e.g LenPanel, MapOptionPanel, etc...
local buttonId = id.."Button";
if Controls[panelId] ~= nil then
Controls[panelId]:SetHide( true );
else
UI.DataError("Minimap's CloseAllFlyouts() attempted to close '"..panelId.."' but the control doesn't exist in the XML.");
end
if Controls[buttonId] ~= nil then
Controls[buttonId]:SetSelected( false );
else
UI.DataError("Minimap's CloseAllFlyouts() attempted to unselect'"..buttonId.."' but the control doesn't exist in the XML.");
end
end
end
-- ===========================================================================
-- Only show one "flyout" control at a time.
-- ===========================================================================
function RealizeFlyouts( pControl:table )
if pControl:IsHidden() then
return; -- If target control is hidden, ignore the rest.
end
for _,id in ipairs(m_kFlyoutControlIds) do
local panelId = id.."Panel"; -- e.g LenPanel, MapOptionPanel, etc...
local buttonId = id.."Button";
if Controls[panelId] ~= nil then
if Controls[panelId] ~= pControl and Controls[panelId]:IsHidden()==false then
Controls[panelId]:SetHide( true );
end
if Controls[panelId] ~= pControl then
if Controls[buttonId]:IsSelected() then
Controls[buttonId]:SetSelected( false );
end
else
if not Controls[buttonId]:IsSelected() then
Controls[buttonId]:SetSelected( true );
end
end
else
UI.DataError("Minimap's RealizeFlyouts() attempted to close '"..panelId.."' but the control doesn't exist in the XML.");
end
end
end
-- ===========================================================================
function CreateLensToggleButton(szText, szToolTip, pCallback, bChecked)
local szLocalizedText = Locale.Lookup(szText);
local szLocalizedToolTip = Locale.Lookup(szToolTip);
local pInstance = m_LensButtonIM:GetInstance();
pInstance.LensButton:GetTextButton():SetText(szLocalizedText);
pInstance.LensButton:SetToolTipString(szLocalizedToolTip);
pInstance.LensButton:RegisterCallback(Mouse.eLClick, pCallback);
pInstance.LensButton:SetCheck(bChecked);
return pInstance;
end
-- ===========================================================================
function CreateMapOptionButton(szText, szToolTip, pCallback, bChecked)
local szLocalizedText = Locale.Lookup(szText);
local szLocalizedToolTip = Locale.Lookup(szToolTip);
local pInstance = m_MapOptionIM:GetInstance();
pInstance.ToggleButton:GetTextButton():SetText(szLocalizedText);
pInstance.ToggleButton:SetToolTipString(szLocalizedToolTip);
pInstance.ToggleButton:RegisterCallback(Mouse.eLClick, pCallback);
pInstance.ToggleButton:SetCheck(bChecked);
return pInstance;
end
-- ===========================================================================
function RefreshMinimapOptions()
if GameCapabilities.HasCapability("CAPABILITY_DISPLAY_MINIMAP_YIELDS") then
Controls.ToggleYieldsButton:SetCheck(UserConfiguration.ShowMapYield());
else
Controls.ToggleYieldsButton:SetHide(true);
end
if GameCapabilities.HasCapability("CAPABILITY_DISPLAY_MINIMAP_RESOURCES") then
Controls.ToggleResourcesButton:SetCheck(UserConfiguration.ShowMapResources());
else
Controls.ToggleResourcesButton:SetHide(true);
end
Controls.ToggleGridButton:SetCheck(UserConfiguration.ShowMapGrid());
end
-- ===========================================================================
function ToggleMapOptionsList()
if Controls.MapOptionsPanel:IsHidden() then
RefreshMinimapOptions();
end
Controls.MapOptionsPanel:SetHide( not Controls.MapOptionsPanel:IsHidden() );
Controls.MapOptionsPanel:SetSizeY(Controls.MapOptionsStack:GetSizeY() + MAP_OPTIONS_PADDING);
RealizeFlyouts(Controls.MapOptionsPanel);
Controls.MapOptionsButton:SetSelected( not Controls.MapOptionsPanel:IsHidden() );
end
-- ===========================================================================
function OnToggleLensList()
Controls.LensPanel:SetHide( not Controls.LensPanel:IsHidden() );
RealizeFlyouts(Controls.LensPanel);
Controls.LensButton:SetSelected( not Controls.LensPanel:IsHidden() );
if Controls.LensPanel:IsHidden() then
CloseLensList();
end
end
function CloseLensList()
g_shouldCloseLensMenu = true;
Controls.ReligionLensButton:SetCheck(false);
Controls.ContinentLensButton:SetCheck(false);
Controls.AppealLensButton:SetCheck(false);
Controls.GovernmentLensButton:SetCheck(false);
Controls.WaterLensButton:SetCheck(false);
Controls.OwnerLensButton:SetCheck(false);
Controls.TourismLensButton:SetCheck(false);
Controls.EmpireLensButton:SetCheck(false);
local uiCurrInterfaceMode:number = UI.GetInterfaceMode();
if uiCurrInterfaceMode == InterfaceModeTypes.VIEW_MODAL_LENS then
UI.SetInterfaceMode(InterfaceModeTypes.SELECTION);
end
end
------------------------------------------------------------------------------
function ToggleMapPinMode()
Controls.MapPinListPanel:SetHide( not Controls.MapPinListPanel:IsHidden() );
RealizeFlyouts(Controls.MapPinListPanel);
Controls.MapPinListButton:SetSelected( not Controls.MapPinListPanel:IsHidden() );
end
-- ===========================================================================
function ToggleMapSearchPanel()
Controls.MapSearchPanel:SetHide( not Controls.MapSearchPanel:IsHidden() );
RealizeFlyouts(Controls.MapSearchPanel);
Controls.MapSearchButton:SetSelected( not Controls.MapSearchPanel:IsHidden() );
end
-- ===========================================================================
function OnMapSearchPanelVisibilityChanged()
if (Controls.MapSearchPanel:IsHidden()) then
LuaEvents.MapSearch_PanelClosed();
else
LuaEvents.MapSearch_PanelOpened();
end
end
-- ===========================================================================
function ToggleResourceIcons()
local bOldValue :boolean = UserConfiguration.ShowMapResources();
UserConfiguration.ShowMapResources( not bOldValue );
end
-- ===========================================================================
function RestoreYieldIcons()
if UserConfiguration.ShowMapYield() then
LuaEvents.PlotInfo_ShowYieldIcons();
else
LuaEvents.PlotInfo_HideYieldIcons();
end
end
-- ===========================================================================
function ToggleYieldIcons()
local showMapYield:boolean = not UserConfiguration.ShowMapYield();
UserConfiguration.ShowMapYield( showMapYield );
RestoreYieldIcons();
end
-- ===========================================================================
function ToggleReligionLens()
if Controls.ReligionLensButton:IsChecked() then
UILens.SetActive("Religion");
RefreshInterfaceMode();
else
g_shouldCloseLensMenu = false; --When toggling the lens off, shouldn't close the menu.
if UI.GetInterfaceMode() == InterfaceModeTypes.VIEW_MODAL_LENS then
UI.SetInterfaceMode(InterfaceModeTypes.SELECTION);
end
end
end
-- ===========================================================================
function ToggleContinentLens()
if Controls.ContinentLensButton:IsChecked() then
UILens.SetActive("Continent");
RefreshInterfaceMode();
else
g_shouldCloseLensMenu = false;
if UI.GetInterfaceMode() == InterfaceModeTypes.VIEW_MODAL_LENS then
UI.SetInterfaceMode(InterfaceModeTypes.SELECTION);
end
end
end
-- ===========================================================================
function ToggleAppealLens()
if Controls.AppealLensButton:IsChecked() then
UILens.SetActive("Appeal");
RefreshInterfaceMode();
else
g_shouldCloseLensMenu = false;
if UI.GetInterfaceMode() == InterfaceModeTypes.VIEW_MODAL_LENS then
UI.SetInterfaceMode(InterfaceModeTypes.SELECTION);
end
end
end
-- ===========================================================================
function ToggleWaterLens()
if Controls.WaterLensButton:IsChecked() then
UILens.SetActive("WaterAvailability");
RefreshInterfaceMode();
else
g_shouldCloseLensMenu = false;
if UI.GetInterfaceMode() == InterfaceModeTypes.VIEW_MODAL_LENS then
UI.SetInterfaceMode(InterfaceModeTypes.SELECTION);
end
end
end
-- ===========================================================================
function ToggleGovernmentLens()
if Controls.GovernmentLensButton:IsChecked() then
UILens.SetActive("Government");
RefreshInterfaceMode();
else
g_shouldCloseLensMenu = false;
if UI.GetInterfaceMode() == InterfaceModeTypes.VIEW_MODAL_LENS then
UI.SetInterfaceMode(InterfaceModeTypes.SELECTION);
end
end
end
-- ===========================================================================
function ToggleOwnerLens()
if Controls.OwnerLensButton:IsChecked() then
UILens.SetActive("OwningCiv");
RefreshInterfaceMode();
else
g_shouldCloseLensMenu = false;
if UI.GetInterfaceMode() == InterfaceModeTypes.VIEW_MODAL_LENS then
UI.SetInterfaceMode(InterfaceModeTypes.SELECTION);
end
end
end
-- ===========================================================================
function ToggleTourismLens()
if Controls.TourismLensButton:IsChecked() then
UILens.SetActive("Tourism");
RefreshInterfaceMode();
else
g_shouldCloseLensMenu = false;
if UI.GetInterfaceMode() == InterfaceModeTypes.VIEW_MODAL_LENS then
UI.SetInterfaceMode(InterfaceModeTypes.SELECTION);
end
end
end
-- ===========================================================================
function ToggleEmpireLens()
if Controls.EmpireLensButton:IsChecked() then
UILens.SetActive("EmpireDetails");
RefreshInterfaceMode();
else
g_shouldCloseLensMenu = false;
if UI.GetInterfaceMode() == InterfaceModeTypes.VIEW_MODAL_LENS then
UI.SetInterfaceMode(InterfaceModeTypes.SELECTION);
end
end
end
-- ===========================================================================
function ToggleGrid()
local bShouldShowGrid = not UserConfiguration.ShowMapGrid();
UserConfiguration.ShowMapGrid( bShouldShowGrid );
UI.ToggleGrid( bShouldShowGrid );
end
-- ===========================================================================
function Toggle2DView()
if (UserConfiguration.GetValue("RenderViewIsLocked") ~= true) then
if (UI.GetWorldRenderView() == WorldRenderView.VIEW_2D) then
UI.SetWorldRenderView( WorldRenderView.VIEW_3D );
Controls.SwitcherImage:SetTextureOffsetVal(0,0);
UI.PlaySound("Set_View_3D");
else
UI.SetWorldRenderView( WorldRenderView.VIEW_2D );
Controls.SwitcherImage:SetTextureOffsetVal(0,24);
UI.PlaySound("Set_View_2D");
end
UI.PlaySound("Stop_Unit_Movement_Master");
end
end
-- ===========================================================================
function ShowFullscreenMap()
UI.PlaySound("Play_UI_Click");
UI.SetInterfaceMode(InterfaceModeTypes.FULLSCREEN_MAP);
end
-- ===========================================================================
function OnPauseEnd()
Controls.ExpandAnim:SetToBeginning();
end
-- ===========================================================================
function OnCollapseToggle()
if ( m_isCollapsed ) then
UI.PlaySound("Minimap_Open");
Controls.ExpandButton:SetHide( true );
Controls.ExpandAnim:SetEndVal(0, -Controls.MinimapContainer:GetOffsetY() - Controls.MinimapContainer:GetSizeY());
Controls.ExpandAnim:SetToBeginning();
Controls.ExpandAnim:Play();
Controls.CompassArm:SetPercent(.25);
else
UI.PlaySound("Minimap_Closed");
Controls.ExpandButton:SetHide( false );
Controls.Pause:Play();
Controls.CollapseAnim:SetEndVal(0, Controls.MinimapContainer:GetOffsetY() + Controls.MinimapContainer:GetSizeY());
Controls.CollapseAnim:SetToBeginning();
Controls.CollapseAnim:Play();
Controls.CompassArm:SetPercent(.5);
end
m_isCollapsed = not m_isCollapsed;
LuaEvents.WorldTracker_OnSetMinimapCollapsed(m_isCollapsed);
LuaEvents.ChatPanel_OnChatPanelRefresh();
end
-- ===========================================================================
function SetMinimapForChat()
LuaEvents.WorldTracker_SetMinimapSize(Controls.MinimapContainer:GetSizeY() + 110); -- sets the state of the minimap in WorldTracker to be used for chat resizing
end
-- ===========================================================================
function OnMinimapImageSizeChanged()
ResizeBacking();
end
-- ===========================================================================
function ResizeBacking()
Controls.MinimapBacking:SetSizeY(Controls.MinimapImage:GetSizeY() + MINIMAP_BACKING_PADDING_SIZEY);
-- if the minimap is collapsed, shift it accordingly
if ( m_isCollapsed ) then
Controls.Pause:Play();
Controls.CollapseAnim:SetEndVal(0, Controls.MinimapContainer:GetOffsetY() + Controls.MinimapContainer:GetSizeY());
Controls.CollapseAnim:SetToEnd();
end
end
-- ===========================================================================
function RefreshInterfaceMode()
if UI.GetInterfaceMode() ~= InterfaceModeTypes.VIEW_MODAL_LENS then
UI.SetInterfaceMode(InterfaceModeTypes.VIEW_MODAL_LENS);
end
end
-- ===========================================================================
function OnLensLayerOn( layerNum:number )
if layerNum == m_HexColoringReligion then
UI.PlaySound("UI_Lens_Overlay_On");
UILens.SetDesaturation(1.0);
elseif layerNum == m_HexColoringAppeal then
SetAppealHexes();
UI.PlaySound("UI_Lens_Overlay_On");
elseif layerNum == m_HexColoringGovernment then
SetGovernmentHexes();
UI.PlaySound("UI_Lens_Overlay_On");
elseif layerNum == m_HexColoringOwningCiv then
SetOwningCivHexes();
UI.PlaySound("UI_Lens_Overlay_On");
elseif layerNum == g_HexColoringContinent then
SetContinentHexes();
UI.PlaySound("UI_Lens_Overlay_On");
elseif layerNum == m_HexColoringWaterAvail then
SetWaterHexes();
UI.PlaySound("UI_Lens_Overlay_On");
elseif layerNum == m_TouristTokens then
UI.PlaySound("UI_Lens_Overlay_On");
end
end
-- ===========================================================================
function OnLensLayerOff( layerNum:number )
if (layerNum == m_HexColoringReligion or
layerNum == g_HexColoringContinent or
layerNum == m_HexColoringAppeal or
layerNum == m_HexColoringGovernment or
layerNum == m_HexColoringOwningCiv) then
UI.PlaySound("UI_Lens_Overlay_Off");
elseif layerNum == m_HexColoringWaterAvail then
-- Only clear the water lens if we're turning off lenses altogether, but not if switching to another modal lens (Turning on another modal lens clears it already).
if UI.GetInterfaceMode() ~= InterfaceModeTypes.VIEW_MODAL_LENS or (UI.GetHeadSelectedUnit() == nil) then
UILens.ClearLayerHexes(m_HexColoringWaterAvail);
end
UI.PlaySound("UI_Lens_Overlay_Off");
end
if (layerNum == m_HexColoringReligion) then
UILens.SetDesaturation(0.0);
end
end
-- ===========================================================================
function OnToggleContinentLensExternal()
if Controls.LensPanel:IsHidden() then
Controls.LensPanel:SetHide(false);
RealizeFlyouts(Controls.LensPanel);
Controls.LensButton:SetSelected(true);
end
if not Controls.ContinentLensButton:IsChecked() then
Controls.ContinentLensButton:SetCheck(true);
UILens.SetActive("Continent");
RefreshInterfaceMode();
end
end
-- ===========================================================================
-- Engine EVENT
-- Local player changed; likely a hotseat game
-- ===========================================================================
function OnLocalPlayerChanged( eLocalPlayer:number , ePrevLocalPlayer:number )
if eLocalPlayer == -1 then
return;
end
CloseAllFlyouts();
end
-- ===========================================================================
function OnUserOptionsActivated()
RestoreYieldIcons();
end
-- ===========================================================================
function SetOwningCivHexes()
local localPlayer : number = Game.GetLocalPlayer();
local localPlayerVis:table = PlayersVisibility[localPlayer];
if (localPlayerVis ~= nil) then
local players = Game.GetPlayers();
for i, player in ipairs(players) do
local cities = players[i]:GetCities();
local primaryColor, secondaryColor = UI.GetPlayerColors( player:GetID() );
for _, pCity in cities:Members() do
local plots :table = Map.GetCityPlots():GetPurchasedPlots(pCity);
if(table.count(plots) > 0) then
UILens.SetLayerHexesColoredArea( m_HexColoringOwningCiv, localPlayer, plots, primaryColor );
end
end
end
end
end
-- ===========================================================================
function SetWaterHexes()
local FullWaterPlots:table = {};
local CoastalWaterPlots:table = {};
local NoWaterPlots:table = {};
local NoSettlePlots:table = {};
UILens.ClearLayerHexes(m_HexColoringWaterAvail);
FullWaterPlots, CoastalWaterPlots, NoWaterPlots, NoSettlePlots = Map.GetContinentPlotsWaterAvailability();
local BreathtakingColor :number = UI.GetColorValue("COLOR_BREATHTAKING_APPEAL");
local CharmingColor :number = UI.GetColorValue("COLOR_CHARMING_APPEAL");
local AverageColor :number = UI.GetColorValue("COLOR_AVERAGE_APPEAL");
local DisgustingColor :number = UI.GetColorValue("COLOR_DISGUSTING_APPEAL");
local localPlayer :number = Game.GetLocalPlayer();
if HasTrait("TRAIT_CIVILIZATION_MAYAB", Game.GetLocalPlayer())then
BreathtakingColor = AverageColor;
CharmingColor = AverageColor;
end
if(table.count(FullWaterPlots) > 0) then
UILens.SetLayerHexesColoredArea( m_HexColoringWaterAvail, localPlayer, FullWaterPlots, BreathtakingColor );
end
if(table.count(CoastalWaterPlots) > 0) then
UILens.SetLayerHexesColoredArea( m_HexColoringWaterAvail, localPlayer, CoastalWaterPlots, CharmingColor );
end
if(table.count(NoWaterPlots) > 0) then
UILens.SetLayerHexesColoredArea( m_HexColoringWaterAvail, localPlayer, NoWaterPlots, AverageColor );
end
if(table.count(NoSettlePlots) > 0) then
UILens.SetLayerHexesColoredArea( m_HexColoringWaterAvail, localPlayer, NoSettlePlots, DisgustingColor );
end
end
-- ===========================================================================
function SetGovernmentHexes()
local localPlayer : number = Game.GetLocalPlayer();
local localPlayerVis:table = PlayersVisibility[localPlayer];
if (localPlayerVis ~= nil) then
local players = Game.GetPlayers();
for i, player in ipairs(players) do
local pCities :table = players[i]:GetCities();
local pCulture :table = player:GetCulture();
local governmentId :number = pCulture:GetCurrentGovernment();
local governmentColor :number;
if pCulture:IsInAnarchy() then
governmentColor = UI.GetColorValue("COLOR_CLEAR");
else
if(governmentId < 0) then
governmentColor = UI.GetColorValue("COLOR_GOVERNMENT_CITYSTATE");
else
local GovType:string = GameInfo.Governments[governmentId].GovernmentType;
governmentColor = UI.GetColorValue("COLOR_"..GovType);
end
end
for _, pCity in pCities:Members() do
local plots:table = Map.GetCityPlots():GetPurchasedPlots(pCity);
if(table.count(plots) > 0) then
UILens.SetLayerHexesColoredArea( m_HexColoringGovernment, localPlayer, plots, governmentColor );
end
end
end
end
end
-- ===========================================================================
function SetAppealHexes()
local BreathtakingPlots:table = {};
local CharmingPlots:table = {};
local AveragePlots:table = {};
local UninvitingPlots:table = {};
local DisgustingPlots:table = {};
BreathtakingPlots, CharmingPlots, AveragePlots, UninvitingPlots, DisgustingPlots = Map.GetContinentPlotsAppeal();
local BreathtakingColor :number = UI.GetColorValue("COLOR_BREATHTAKING_APPEAL");
local CharmingColor :number = UI.GetColorValue("COLOR_CHARMING_APPEAL");
local AverageColor :number = UI.GetColorValue("COLOR_AVERAGE_APPEAL");
local UninvitingColor :number = UI.GetColorValue("COLOR_UNINVITING_APPEAL");
local DisgustingColor :number = UI.GetColorValue("COLOR_DISGUSTING_APPEAL");
local localPlayer :number = Game.GetLocalPlayer();
if(table.count(BreathtakingPlots) > 0) then
UILens.SetLayerHexesColoredArea( m_HexColoringAppeal, localPlayer, BreathtakingPlots, BreathtakingColor );
end
if(table.count(CharmingPlots) > 0) then
UILens.SetLayerHexesColoredArea( m_HexColoringAppeal, localPlayer, CharmingPlots, CharmingColor );
end
if(table.count(AveragePlots) > 0) then
UILens.SetLayerHexesColoredArea( m_HexColoringAppeal, localPlayer, AveragePlots, AverageColor );
end
if(table.count(UninvitingPlots) > 0) then
UILens.SetLayerHexesColoredArea( m_HexColoringAppeal, localPlayer, UninvitingPlots, UninvitingColor );
end
if(table.count(DisgustingPlots) > 0) then
UILens.SetLayerHexesColoredArea( m_HexColoringAppeal, localPlayer, DisgustingPlots, DisgustingColor );
end
end
-- ===========================================================================
function SetContinentHexes()
local ContinentColor:number = UI.GetColorValueFromHexLiteral(0x02000000);
GetContinentsCache();
local localPlayerVis:table = PlayersVisibility[Game.GetLocalPlayer()];
if (localPlayerVis ~= nil) then
local kContinentColors:table = {};
for loopNum, ContinentID in ipairs(g_ContinentsCache) do
local visibleContinentPlots:table = Map.GetVisibleContinentPlots(ContinentID);
ContinentColor = UI.GetColorValue("COLOR_" .. GameInfo.Continents[ loopNum-1 ].ContinentType);
if(table.count(visibleContinentPlots) > 0) then
UILens.SetLayerHexesColoredArea( g_HexColoringContinent, loopNum-1, visibleContinentPlots, ContinentColor );
kContinentColors[ContinentID] = ContinentColor;
end
end
LuaEvents.MinimapPanel_AddContinentColorPair( kContinentColors );
end
end
-- ===========================================================================
-- Support function for Hotkey Event
-- ===========================================================================
function LensPanelHotkeyControl( pControl:table )
if Controls.LensPanel:IsHidden() then
Controls.LensPanel:SetHide(false);
RealizeFlyouts(Controls.LensPanel);
Controls.LensButton:SetSelected(true);
elseif (not Controls.LensPanel:IsHidden()) and pControl:IsChecked() then
Controls.LensPanel:SetHide(true);
Controls.LensButton:SetSelected(false);
end
pControl:SetCheck( not pControl:IsChecked() );
end
-- ===========================================================================
-- Input Hotkey Event
-- ===========================================================================
function OnInputActionTriggered( actionId )
-- dont show panel if there is no local player
if (Game.GetLocalPlayer() == -1) then
return;
end
if UI.GetInterfaceMode() == InterfaceModeTypes.DISTRICT_PLACEMENT then
return;
end
if GameConfiguration.IsWorldBuilderEditor() then
return;
end
if m_ToggleReligionLensId ~= nil and (actionId == m_ToggleReligionLensId) and GameCapabilities.HasCapability("CAPABILITY_LENS_RELIGION") then
LensPanelHotkeyControl( Controls.ReligionLensButton );
ToggleReligionLens();
UI.PlaySound("Play_UI_Click");
end
if m_ToggleContinentLensId ~= nil and (actionId == m_ToggleContinentLensId) and GameCapabilities.HasCapability("CAPABILITY_LENS_CONTINENT") then
LensPanelHotkeyControl( Controls.ContinentLensButton );
ToggleContinentLens();
UI.PlaySound("Play_UI_Click");
end
if m_ToggleAppealLensId ~= nil and (actionId == m_ToggleAppealLensId) and GameCapabilities.HasCapability("CAPABILITY_LENS_APPEAL") then
LensPanelHotkeyControl( Controls.AppealLensButton );
ToggleAppealLens();
UI.PlaySound("Play_UI_Click");
end
if m_ToggleSettlerLensId ~= nil and (actionId == m_ToggleSettlerLensId) and GameCapabilities.HasCapability("CAPABILITY_LENS_SETTLER") then
LensPanelHotkeyControl( Controls.WaterLensButton );
ToggleWaterLens();
UI.PlaySound("Play_UI_Click");
end
if m_ToggleGovernmentLensId ~= nil and (actionId == m_ToggleGovernmentLensId) and GameCapabilities.HasCapability("CAPABILITY_LENS_GOVERNMENT") then
LensPanelHotkeyControl( Controls.GovernmentLensButton );
ToggleGovernmentLens();
UI.PlaySound("Play_UI_Click");
end
if m_TogglePoliticalLensId ~= nil and (actionId == m_TogglePoliticalLensId) then
LensPanelHotkeyControl( Controls.OwnerLensButton );
ToggleOwnerLens();
UI.PlaySound("Play_UI_Click");
end
if m_ToggleTourismLensId ~= nil and (actionId == m_ToggleTourismLensId) and GameCapabilities.HasCapability("CAPABILITY_LENS_TOURISM") then
LensPanelHotkeyControl( Controls.TourismLensButton );
ToggleTourismLens();
UI.PlaySound("Play_UI_Click");
end
if m_ToggleEmpireLensId ~= nil and (actionId == m_ToggleEmpireLensId) and GameCapabilities.HasCapability("CAPABILITY_LENS_EMPIRE") then
LensPanelHotkeyControl( Controls.EmpireLensButton );
ToggleEmpireLens();
UI.PlaySound("Play_UI_Click");
end
if m_Toggle2DViewId ~= nil and (actionId == m_Toggle2DViewId) then
UI.PlaySound("Play_UI_Click");
Toggle2DView();
end
if m_OpenMapSearchId ~= nil and (actionId == m_OpenMapSearchId) then
UI.PlaySound("Play_UI_Click");
if Controls.MapSearchPanel:IsHidden() then
Controls.MapSearchPanel:SetHide(false);
RealizeFlyouts(Controls.MapSearchPanel);
end
-- Take focus
LuaEvents.MapSearch_PanelOpened();
end
end
-- ===========================================================================
-- Game Engine Event
-- ===========================================================================
function OnInterfaceModeChanged(eOldMode:number, eNewMode:number)
--and eNewMode ~= InterfaceModeTypes.VIEW_MODAL_LENS
if eOldMode == InterfaceModeTypes.VIEW_MODAL_LENS then
if not Controls.LensPanel:IsHidden() then
if g_shouldCloseLensMenu then --If player turns off the lens from the menu, do not close the menu
Controls.LensPanel:SetHide( true );
RealizeFlyouts(Controls.LensPanel);
Controls.LensButton:SetSelected( false );
end
g_shouldCloseLensMenu = true; --Reset variable so the menu can be closed by selecting a unit/city
Controls.ReligionLensButton:SetCheck(false);
Controls.ContinentLensButton:SetCheck(false);
Controls.AppealLensButton:SetCheck(false);
Controls.GovernmentLensButton:SetCheck(false);
Controls.WaterLensButton:SetCheck(false);
Controls.OwnerLensButton:SetCheck(false);
Controls.TourismLensButton:SetCheck(false);
Controls.EmpireLensButton:SetCheck(false);
end
end
end
function GetMinimapMouseCoords( mousex:number, mousey:number )
local topLeftX, topLeftY = Controls.MinimapImage:GetScreenOffset();
-- normalized 0-1, relative to map
local minix = mousex - topLeftX;
local miniy = mousey - topLeftY;
minix = minix / Controls.MinimapImage:GetSizeX();
miniy = miniy / Controls.MinimapImage:GetSizeY();
return minix, miniy;
end
function IsMouseInMinimap( minix:number, miniy:number )
return minix >= 0 and minix <= 1 and miniy >= 0 and miniy <= 1;
end
function TranslateMinimapToWorld( minix:number, miniy:number )
local mapMinX, mapMinY, mapMaxX, mapMaxY = UI.GetMinimapWorldRect();
-- Clamp coords to minimap.
minix = math.min( 1, math.max( 0, minix ) );
miniy = math.min( 1, math.max( 0, miniy ) );
--TODO: max-min probably wont work for rects that cross world wrap! -KS
local wx = mapMinX + (mapMaxX-mapMinX) * minix;
local wy = mapMinY + (mapMaxY-mapMinY) * (1 - miniy);
return wx, wy;
end
function OnInputHandler( pInputStruct:table )
-- Skip all handling when dragging is disabled or the minimap is collapsed
if m_isMouseDragEnabled and not m_isCollapsed then
local msg = pInputStruct:GetMessageType( );
-- Enable drag on LMB down
if (msg == MouseEvents.LButtonDown or msg == MouseEvents.PointerDown) then
local minix, miniy = GetMinimapMouseCoords( pInputStruct:GetX(), pInputStruct:GetY() );
if IsMouseInMinimap( minix, miniy ) then
m_isMouseDragging = true; -- Potential drag is in process
m_hasMouseDragged = false; -- There has been no actual dragging yet
LuaEvents.WorldInput_DragMapBegin(); -- Alert luathings that a drag is about to go down
return true; -- Consume event
end
-- Disable drag on LMB up (but only if mouse was previously dragging)
elseif m_isMouseDragging and (msg == MouseEvents.LButtonUp or msg == MouseEvents.PointerUp) then
m_isMouseDragging = false;
-- In case of no actual drag occurring, perform camera jump.
if not m_hasMouseDragged then
local minix, miniy = GetMinimapMouseCoords( pInputStruct:GetX(), pInputStruct:GetY() );
local wx, wy = TranslateMinimapToWorld( minix, miniy );
UI.LookAtPosition( wx, wy );
end
LuaEvents.WorldInput_DragMapEnd(); -- Alert luathings that the drag has stopped
return true;
-- Move camera if dragging, mouse moves, and mouse is over minimap.
elseif m_isMouseDragging and (msg == MouseEvents.MouseMove or msg == MouseEvents.PointerUpdate) then
local minix, miniy = GetMinimapMouseCoords( pInputStruct:GetX(), pInputStruct:GetY() );
local isMouseInMinimap = IsMouseInMinimap( minix, miniy );
-- Catches entering, exiting, and moving within the minimap.
-- Clamping in TranslateMinimapToWorld guarantees OOB input is treated correctly.
if m_wasMouseInMinimap or isMouseInMinimap then
m_hasMouseDragged = true;
local wx, wy = TranslateMinimapToWorld( minix, miniy );
UI.FocusMap( wx, wy );
end
m_wasMouseInMinimap = isMouseInMinimap
return isMouseInMinimap; -- Only consume event if it's inside the minimap.
-- Update tooltip as the mouse is moved over the minimap
elseif (msg == MouseEvents.MouseMove or msg == MouseEvents.PointerUpdate) and not UI.IsFullscreenMapEnabled() then
ShowMinimapTooltips(pInputStruct:GetX(), pInputStruct:GetY())
end
-- TODO the letterbox background should block mouse input
end
local uiMsg = pInputStruct:GetMessageType();
if uiMsg == KeyEvents.KeyUp and pInputStruct:GetKey() == Keys.VK_ESCAPE and not Controls.LensPanel:IsHidden() then
OnToggleLensList();
return true;
end
return false;
end
function ShowMinimapTooltips(inputX:number, inputY:number)
local ePlayer : number = Game.GetLocalPlayer();
local pPlayerVis:table = PlayersVisibility[ePlayer];
local minix, miniy = GetMinimapMouseCoords( inputX, inputY );
if (pPlayerVis ~= nil and IsMouseInMinimap(minix, miniy)) then
local wx, wy = TranslateMinimapToWorld(minix, miniy);
local plotX, plotY = UI.GetPlotCoordFromWorld(wx, wy);
local pPlot = Map.GetPlot(plotX, plotY);
if (pPlot ~= nil) then
local plotID = Map.GetPlotIndex(plotX, plotY);
if pPlayerVis:IsRevealed(plotID) then
local eOwner = pPlot:GetOwner();
local pPlayerConfig = PlayerConfigurations[eOwner];
if (pPlayerConfig ~= nil) then
local szOwnerString = Locale.Lookup(pPlayerConfig:GetCivilizationShortDescription());
if (szOwnerString == nil or string.len(szOwnerString) == 0) then
szOwnerString = Locale.Lookup("LOC_TOOLTIP_PLAYER_ID", eOwner);
end
local pPlayer = Players[eOwner];
if(GameConfiguration:IsAnyMultiplayer() and pPlayer:IsHuman()) then
szOwnerString = szOwnerString .. " (" .. Locale.Lookup(pPlayerConfig:GetPlayerName()) .. ")";
end
local szOwner = Locale.Lookup("LOC_HUD_MINIMAP_OWNER_TOOLTIP", szOwnerString);
Controls.MinimapImage:SetToolTipString(szOwner);
else
local pTooltipString = Locale.Lookup("LOC_MINIMAP_UNCLAIMED_TOOLTIP");
Controls.MinimapImage:SetToolTipString(pTooltipString);
end
else
local pTooltipString = Locale.Lookup("LOC_MINIMAP_FOG_OF_WAR_TOOLTIP");
Controls.MinimapImage:SetToolTipString(pTooltipString);
end
end
end
end
function OnTutorial_DisableMapDrag( isDisabled:boolean )
m_isMouseDragEnabled = not isDisabled;
if isDisabled then
m_isMouseDragging = false;
m_hasMouseDragged = false;
m_wasMouseInMinimap = false;
end
end
function OnTutorial_SwitchToWorldView()
Controls.SwitcherImage:SetTextureOffsetVal(0,0);
end
function OnShutdown()
-- Game Events
Events.CityAddedToMap.Remove( OnCityAddedToMap );
Events.InputActionTriggered.Remove( OnInputActionTriggered );
Events.InterfaceModeChanged.Remove( OnInterfaceModeChanged );
Events.LensLayerOn.Remove( OnLensLayerOn );
Events.LensLayerOff.Remove( OnLensLayerOff );
Events.LocalPlayerChanged.Remove( OnLocalPlayerChanged );
Events.UserOptionsActivated.Remove( OnUserOptionsActivated );
LuaEvents.MinimapPanel_CloseAllLenses.Remove( CloseAllLenses );
LuaEvents.MinimapPanel_RefreshMinimapOptions.Remove( RefreshMinimapOptions );
LuaEvents.MinimapPanel_ToggleGrid.Remove( ToggleGrid );
LuaEvents.NotificationPanel_ShowContinentLens.Remove(OnToggleContinentLensExternal);
LuaEvents.Tutorial_DisableMapDrag.Remove( OnTutorial_DisableMapDrag )
LuaEvents.Tutorial_SwitchToWorldView.Remove( OnTutorial_SwitchToWorldView );
LuaEvents.CityPanelOverview_Opened.Remove( function()
if not Controls.LensPanel:IsHidden() then
OnToggleLensList();
end
end );
m_LensButtonIM:ResetInstances();
m_MapOptionIM:ResetInstances();
end
-- force the settler lens off when a city is added (this shouldn't happen, but it's a failsafe)
function OnCityAddedToMap(playerID, cityID, x, y)
if UI.GetInterfaceMode() == InterfaceModeTypes.VIEW_MODAL_LENS then
UI.SetInterfaceMode(InterfaceModeTypes.SELECTION);
end
UILens.ClearLayerHexes(m_HexColoringWaterAvail);
end
-- ===========================================================================
function LateInitialize( isReload:boolean )
m_MiniMap_xmloffsety = Controls.MiniMap:GetOffsetY();
g_ContinentsCache = Map.GetContinentsInUse();
if GameCapabilities.HasCapability("CAPABILITY_LENS_TOGGLING_UI") then
m_ToggleReligionLensId = Input.GetActionId("LensReligion");
m_ToggleContinentLensId = Input.GetActionId("LensContinent");
m_ToggleAppealLensId = Input.GetActionId("LensAppeal");
m_ToggleSettlerLensId = Input.GetActionId("LensSettler");
m_ToggleGovernmentLensId= Input.GetActionId("LensGovernment");
m_TogglePoliticalLensId = Input.GetActionId("LensPolitical");
m_ToggleTourismLensId = Input.GetActionId("LensTourism");
m_ToggleEmpireLensId = Input.GetActionId("LensEmpire");
end
Controls.ReligionLensButton:SetHide(not GameCapabilities.HasCapability("CAPABILITY_LENS_RELIGION"));
Controls.AppealLensButton:SetHide(not GameCapabilities.HasCapability("CAPABILITY_LENS_APPEAL"));
Controls.GovernmentLensButton:SetHide(not GameCapabilities.HasCapability("CAPABILITY_LENS_GOVERNMENT"));
Controls.WaterLensButton:SetHide(not GameCapabilities.HasCapability("CAPABILITY_LENS_SETTLER"));
Controls.TourismLensButton:SetHide(not GameCapabilities.HasCapability("CAPABILITY_LENS_TOURISM"));
Controls.ContinentLensButton:SetHide(not GameCapabilities.HasCapability("CAPABILITY_LENS_CONTINENT"));
Controls.EmpireLensButton:SetHide(not GameCapabilities.HasCapability("CAPABILITY_LENS_EMPIRE"));
Controls.LensToggleStack:CalculateSize();
Controls.LensPanel:SetSizeY(Controls.LensToggleStack:GetSizeY() + LENS_PANEL_OFFSET);
if GameCapabilities.HasCapability("CAPABILITY_SEARCH_GAME_MAP") then
m_OpenMapSearchId = Input.GetActionId("OpenMapSearch");
end
Controls.MinimapImage:RegisterSizeChanged( OnMinimapImageSizeChanged );
UI.SetMinimapImageControl( Controls.MinimapImage );
-- Context / Control callbacks
ContextPtr:SetShutdown( OnShutdown );
Controls.MapSearchPanel:RegisterWhenHidden( OnMapSearchPanelVisibilityChanged );