-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathMinimapPanel.lua
808 lines (715 loc) · 32.6 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
-- ===========================================================================
-- MINIMAP PANEL
-- ===========================================================================
include( "InstanceManager" );
-- ===========================================================================
-- CONSTANTS
-- ===========================================================================
local MINIMAP_COLLAPSED_OFFSETY :number = -180;
local LENS_PANEL_OFFSET :number = 50;
local MINIMAP_BACKING_PADDING_SIZEY :number = 54;
-- ===========================================================================
-- MEMBERS
-- ===========================================================================
--local m_OptionsButtonManager= InstanceManager:new( "MiniMapOptionButtonInstance", "Top", Controls.OptionsStack );
local m_OptionButtons :table = {}; -- option buttons indexed by buttonName.
local iZoomIncrement :number = 2;
local m_isCollapsed :boolean= false;
local bGridOn :boolean= true;
local m_ContinentsCreated :boolean=false;
local m_MiniMap_xmloffsety :number = 0;
local m_ContinentsCache :table = {};
local m_kFlyoutControlIds :table = { "MapOptions", "Lens", "MapPinList"}; -- Name of controls that are the backing for "flyout" menus.
local m_shouldCloseLensMenu :boolean = true; -- Controls when the Lens menu should be closed.
local m_LensLayers :table = { LensLayers.HEX_COLORING_RELIGION,
LensLayers.HEX_COLORING_CONTINENT,
LensLayers.HEX_COLORING_APPEAL_LEVEL,
LensLayers.HEX_COLORING_GOVERNMENT,
LensLayers.HEX_COLORING_OWING_CIV,
LensLayers.HEX_COLORING_WATER_AVAILABLITY };
local m_ToggleReligionLensId = Input.GetActionId("LensReligion");
local m_ToggleContinentLensId = Input.GetActionId("LensContinent");
local m_ToggleAppealLensId = Input.GetActionId("LensAppeal");
local m_ToggleSettlerLensId = Input.GetActionId("LensSettler");
local m_ToggleGovernmentLensId = Input.GetActionId("LensGovernment");
local m_TogglePoliticalLensId = Input.GetActionId("LensPolitical");
local m_ToggleTourismLensId = Input.GetActionId("LensTourism");
local m_Toggle2DViewId = Input.GetActionId("Toggle2DView");
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?
-- ===========================================================================
-- FUNCTIONS
-- ===========================================================================
-- ===========================================================================
function GetContinentsCache()
if m_ContinentsCache == nil then
m_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 RefreshMinimapOptions()
Controls.ToggleYieldsButton:SetCheck(UserConfiguration.ShowMapYield());
Controls.ToggleGridButton:SetCheck(bGridOn);
Controls.ToggleResourcesButton:SetCheck(UserConfiguration.ShowMapResources());
end
-- ===========================================================================
function ToggleMapOptionsList()
if Controls.MapOptionsPanel:IsHidden() then
RefreshMinimapOptions();
end
Controls.MapOptionsPanel:SetHide( not Controls.MapOptionsPanel:IsHidden() );
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
m_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);
if UI.GetInterfaceMode() == InterfaceModeTypes.VIEW_MODAL_LENS then
UI.SetInterfaceMode(InterfaceModeTypes.SELECTION);
end
else
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.LensToggleStack:CalculateSize();
Controls.LensPanel:SetSizeY(Controls.LensToggleStack:GetSizeY() + LENS_PANEL_OFFSET);
end
end
------------------------------------------------------------------------------
function ToggleMapPinMode()
Controls.MapPinListPanel:SetHide( not Controls.MapPinListPanel:IsHidden() );
RealizeFlyouts(Controls.MapPinListPanel);
Controls.MapPinListButton:SetSelected( not Controls.MapPinListPanel:IsHidden() );
end
-- ===========================================================================
function ToggleResourceIcons()
UserConfiguration.ShowMapResources( not UserConfiguration.ShowMapResources() );
end
-- ===========================================================================
function ToggleYieldIcons()
local showMapYield:boolean = not UserConfiguration.ShowMapYield();
UserConfiguration.ShowMapYield( showMapYield );
if showMapYield then
LuaEvents.MinimapPanel_ShowYieldIcons();
else
LuaEvents.MinimapPanel_HideYieldIcons();
end
end
-- ===========================================================================
function ToggleReligionLens()
if Controls.ReligionLensButton:IsChecked() then
UILens.SetActive("Religion");
RefreshInterfaceMode();
else
m_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
m_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
m_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
m_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
m_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
m_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
m_shouldCloseLensMenu = false;
if UI.GetInterfaceMode() == InterfaceModeTypes.VIEW_MODAL_LENS then
UI.SetInterfaceMode(InterfaceModeTypes.SELECTION);
end
end
end
-- ===========================================================================
function ToggleGrid()
bGridOn = not bGridOn;
UI.ToggleGrid( bGridOn );
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 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;
end
-- ===========================================================================
function OnMinimapImageSizeChanged()
ResizeBacking();
end
-- ===========================================================================
function ResizeBacking()
Controls.MinimapBacking:SetSizeY(Controls.MinimapImage:GetSizeY() + MINIMAP_BACKING_PADDING_SIZEY);
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 == LensLayers.HEX_COLORING_RELIGION then
UI.PlaySound("UI_Lens_Overlay_On");
elseif layerNum == LensLayers.HEX_COLORING_APPEAL_LEVEL then
SetAppealHexes();
UI.PlaySound("UI_Lens_Overlay_On");
elseif layerNum == LensLayers.HEX_COLORING_GOVERNMENT then
SetGovernmentHexes();
UI.PlaySound("UI_Lens_Overlay_On");
elseif layerNum == LensLayers.HEX_COLORING_OWING_CIV then
SetOwingCivHexes();
UI.PlaySound("UI_Lens_Overlay_On");
elseif layerNum == LensLayers.HEX_COLORING_CONTINENT then
SetContinentHexes();
UI.PlaySound("UI_Lens_Overlay_On");
elseif layerNum == LensLayers.HEX_COLORING_WATER_AVAILABLITY then
SetWaterHexes();
UI.PlaySound("UI_Lens_Overlay_On");
elseif layerNum == LensLayers.TOURIST_TOKENS then
UI.PlaySound("UI_Lens_Overlay_On");
end
end
-- ===========================================================================
function OnLensLayerOff( layerNum:number )
if (layerNum == LensLayers.HEX_COLORING_RELIGION or
layerNum == LensLayers.HEX_COLORING_CONTINENT or
layerNum == LensLayers.HEX_COLORING_APPEAL_LEVEL or
layerNum == LensLayers.HEX_COLORING_GOVERNMENT or
layerNum == LensLayers.HEX_COLORING_OWING_CIV) then
UI.PlaySound("UI_Lens_Overlay_Off");
elseif layerNum == LensLayers.HEX_COLORING_WATER_AVAILABLITY 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(LensLayers.HEX_COLORING_WATER_AVAILABLITY);
end
UI.PlaySound("UI_Lens_Overlay_Off");
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 SetOwingCivHexes()
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 visibleCityPlots :table = Map.GetCityPlots():GetVisiblePurchasedPlots(pCity);
if(table.count(visibleCityPlots) > 0) then
UILens.SetLayerHexesColoredArea( LensLayers.HEX_COLORING_OWING_CIV, localPlayer, visibleCityPlots, primaryColor );
end
end
end
end
end
-- ===========================================================================
function SetWaterHexes()
local FullWaterPlots:table = {};
local CoastalWaterPlots:table = {};
local NoWaterPlots:table = {};
local NoSettlePlots:table = {};
UILens.ClearLayerHexes(LensLayers.HEX_COLORING_WATER_AVAILABLITY);
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(table.count(FullWaterPlots) > 0) then
UILens.SetLayerHexesColoredArea( LensLayers.HEX_COLORING_WATER_AVAILABLITY, localPlayer, FullWaterPlots, BreathtakingColor );
end
if(table.count(CoastalWaterPlots) > 0) then
UILens.SetLayerHexesColoredArea( LensLayers.HEX_COLORING_WATER_AVAILABLITY, localPlayer, CoastalWaterPlots, CharmingColor );
end
if(table.count(NoWaterPlots) > 0) then
UILens.SetLayerHexesColoredArea( LensLayers.HEX_COLORING_WATER_AVAILABLITY, localPlayer, NoWaterPlots, AverageColor );
end
if(table.count(NoSettlePlots) > 0) then
UILens.SetLayerHexesColoredArea( LensLayers.HEX_COLORING_WATER_AVAILABLITY, 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 cities = players[i]:GetCities();
local culture = player:GetCulture();
local governmentId :number = culture:GetCurrentGovernment();
local GovernmentColor;
if culture:IsInAnarchy() then
GovernmentColor = UI.GetColorValue("COLOR_CLEAR");
else
if(governmentId < 0) then
GovernmentColor = UI.GetColorValue("COLOR_GOVERNMENT_CITYSTATE");
else
GovernmentColor = UI.GetColorValue("COLOR_" .. GameInfo.Governments[governmentId].GovernmentType);
end
end
for _, pCity in cities:Members() do
local visibleCityPlots:table = Map.GetCityPlots():GetVisiblePurchasedPlots(pCity);
if(table.count(visibleCityPlots) > 0) then
UILens.SetLayerHexesColoredArea( LensLayers.HEX_COLORING_GOVERNMENT, localPlayer, visibleCityPlots, 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( LensLayers.HEX_COLORING_APPEAL_LEVEL, localPlayer, BreathtakingPlots, BreathtakingColor );
end
if(table.count(CharmingPlots) > 0) then
UILens.SetLayerHexesColoredArea( LensLayers.HEX_COLORING_APPEAL_LEVEL, localPlayer, CharmingPlots, CharmingColor );
end
if(table.count(AveragePlots) > 0) then
UILens.SetLayerHexesColoredArea( LensLayers.HEX_COLORING_APPEAL_LEVEL, localPlayer, AveragePlots, AverageColor );
end
if(table.count(UninvitingPlots) > 0) then
UILens.SetLayerHexesColoredArea( LensLayers.HEX_COLORING_APPEAL_LEVEL, localPlayer, UninvitingPlots, UninvitingColor );
end
if(table.count(DisgustingPlots) > 0) then
UILens.SetLayerHexesColoredArea( LensLayers.HEX_COLORING_APPEAL_LEVEL, localPlayer, DisgustingPlots, DisgustingColor );
end
end
-- ===========================================================================
function SetContinentHexes()
local ContinentColor:number = 0x02000000;
GetContinentsCache();
local localPlayerVis:table = PlayersVisibility[Game.GetLocalPlayer()];
if (localPlayerVis ~= nil) then
local kContinentColors:table = {};
for loopNum, ContinentID in ipairs(m_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( LensLayers.HEX_COLORING_CONTINENT, 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 m_ToggleReligionLensId ~= nil and (actionId == m_ToggleReligionLensId) then
LensPanelHotkeyControl( Controls.ReligionLensButton );
ToggleReligionLens();
UI.PlaySound("Play_UI_Click");
end
if m_ToggleContinentLensId ~= nil and (actionId == m_ToggleContinentLensId) then
LensPanelHotkeyControl( Controls.ContinentLensButton );
ToggleContinentLens();
UI.PlaySound("Play_UI_Click");
end
if m_ToggleAppealLensId ~= nil and (actionId == m_ToggleAppealLensId) then
LensPanelHotkeyControl( Controls.AppealLensButton );
ToggleAppealLens();
UI.PlaySound("Play_UI_Click");
end
if m_ToggleSettlerLensId ~= nil and (actionId == m_ToggleSettlerLensId) then
LensPanelHotkeyControl( Controls.WaterLensButton );
ToggleWaterLens();
UI.PlaySound("Play_UI_Click");
end
if m_ToggleGovernmentLensId ~= nil and (actionId == m_ToggleGovernmentLensId) 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) then
LensPanelHotkeyControl( Controls.TourismLensButton );
ToggleTourismLens();
UI.PlaySound("Play_UI_Click");
end
if m_Toggle2DViewId ~= nil and (actionId == m_Toggle2DViewId) then
UI.PlaySound("Play_UI_Click");
Toggle2DView();
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 m_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
m_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);
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 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 msg == MouseEvents.LButtonUp and m_isMouseDragging 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 msg == MouseEvents.MouseMove and m_isMouseDragging 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.
end
-- TODO the letterbox background should block mouse input
end
return false;
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()
LuaEvents.Tutorial_SwitchToWorldView.Remove( OnTutorial_SwitchToWorldView );
LuaEvents.Tutorial_DisableMapDrag.Remove( OnTutorial_DisableMapDrag );
LuaEvents.NotificationPanel_ShowContinentLens.Remove(OnToggleContinentLensExternal);
end
-- ===========================================================================
-- INITIALIZATION
-- ===========================================================================
function Initialize()
m_MiniMap_xmloffsety = Controls.MiniMap:GetOffsetY();
m_ContinentsCache = Map.GetContinentsInUse();
Controls.MinimapImage:RegisterSizeChanged( OnMinimapImageSizeChanged );
UI.SetMinimapImageControl( Controls.MinimapImage );
ContextPtr:SetInputHandler( OnInputHandler, true );
ContextPtr:SetShutdown( OnShutdown );
Controls.LensPanel:ChangeParent(Controls.LensButton);
Controls.MapOptionsPanel:ChangeParent(Controls.MapOptionsButton);
Controls.ToggleResourcesButton:SetCheck( UserConfiguration.ShowMapResources() );
Controls.ToggleYieldsButton:SetCheck( UserConfiguration.ShowMapYield() );
Controls.AppealLensButton:RegisterCallback( Mouse.eLClick, ToggleAppealLens );
Controls.ContinentLensButton:RegisterCallback( Mouse.eLClick, ToggleContinentLens );
Controls.CollapseButton:RegisterCallback( Mouse.eLClick, OnCollapseToggle );
Controls.CollapseButton:RegisterCallback( Mouse.eMouseEnter, function() UI.PlaySound("Main_Menu_Mouse_Over"); end);
Controls.ExpandButton:RegisterCallback( Mouse.eLClick, OnCollapseToggle );
Controls.ExpandButton:RegisterCallback( Mouse.eMouseEnter, function() UI.PlaySound("Main_Menu_Mouse_Over"); end);
Controls.GovernmentLensButton:RegisterCallback( Mouse.eLClick, ToggleGovernmentLens );
Controls.LensButton:RegisterCallback( Mouse.eLClick, OnToggleLensList );
Controls.LensButton:RegisterCallback( Mouse.eMouseEnter, function() UI.PlaySound("Main_Menu_Mouse_Over"); end);
Controls.MapOptionsButton:RegisterCallback( Mouse.eLClick, ToggleMapOptionsList );
Controls.MapOptionsButton:RegisterCallback( Mouse.eMouseEnter, function() UI.PlaySound("Main_Menu_Mouse_Over"); end);
Controls.MapPinListButton:RegisterCallback( Mouse.eLClick, ToggleMapPinMode );
Controls.MapPinListButton:RegisterCallback( Mouse.eMouseEnter, function() UI.PlaySound("Main_Menu_Mouse_Over"); end);
Controls.OwnerLensButton:RegisterCallback( Mouse.eLClick, ToggleOwnerLens );
Controls.TourismLensButton:RegisterCallback( Mouse.eLClick, ToggleTourismLens );
Controls.Pause:RegisterEndCallback( OnPauseEnd );
Controls.ReligionLensButton:RegisterCallback( Mouse.eLClick, ToggleReligionLens );
Controls.StrategicSwitcherButton:RegisterCallback( Mouse.eLClick, Toggle2DView );
Controls.StrategicSwitcherButton:RegisterCallback( Mouse.eMouseEnter, function() UI.PlaySound("Main_Menu_Mouse_Over"); end);
Controls.ToggleGridButton:RegisterCallback( Mouse.eLClick, ToggleGrid );
Controls.ToggleResourcesButton:RegisterCallback( Mouse.eLClick, ToggleResourceIcons );
Controls.ToggleYieldsButton:RegisterCallback( Mouse.eLClick, ToggleYieldIcons );
Controls.WaterLensButton:RegisterCallback( Mouse.eLClick, ToggleWaterLens );
-- Hide buttons not needed for the world builder
if GameConfiguration.IsWorldBuilderEditor() then
Controls.LensButton:SetHide(true);
Controls.MapPinListButton:SetHide(true);
Controls.StrategicSwitcherButton:SetHide(true);
Controls.OptionsStack:ReprocessAnchoring();
end
-- Make sure the StrategicSwitcherButton has the correct image when the game starts in StrategicView
if UI.GetWorldRenderView() == WorldRenderView.VIEW_2D then
Controls.SwitcherImage:SetTextureOffsetVal(0,24);
end
Events.InputActionTriggered.Add( OnInputActionTriggered );
Events.InterfaceModeChanged.Add( OnInterfaceModeChanged );
Events.LensLayerOn.Add( OnLensLayerOn );
Events.LensLayerOff.Add( OnLensLayerOff );
Events.LocalPlayerChanged.Add( OnLocalPlayerChanged );
LuaEvents.NotificationPanel_ShowContinentLens.Add(OnToggleContinentLensExternal);
LuaEvents.Tutorial_DisableMapDrag.Add( OnTutorial_DisableMapDrag );
LuaEvents.Tutorial_SwitchToWorldView.Add( OnTutorial_SwitchToWorldView );
LuaEvents.MinimapPanel_ToggleGrid.Add( ToggleGrid );
LuaEvents.MinimapPanel_RefreshMinimapOptions.Add( RefreshMinimapOptions );
end
Initialize();