forked from civfanatics/Civ6-UIFiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FullscreenMapPopup.lua
192 lines (163 loc) · 7 KB
/
FullscreenMapPopup.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
-- ===========================================================================
-- Copyright 2018, Firaxis Games
-- ===========================================================================
local m_toggleFullScreenMapId :number = Input.GetActionId("ToggleFSMap");
-- ===========================================================================
function GetMinimapMouseCoords( mousex:number, mousey:number )
-- normalized 0-1, relative to screen
local width, height = UIManager:GetScreenSizeVal();
local mapx = mousex / width;
local mapy = mousey / height;
return mapx, mapy;
end
-- ===========================================================================
function TranslateMinimapToWorld( mapx:number, mapy:number )
local mapMinX, mapMinY, mapMaxX, mapMaxY = UI.GetMinimapWorldRect();
-- Clamp coords to minimap.
mapx = math.min( 1, math.max( 0, mapx ) );
mapy = math.min( 1, math.max( 0, mapy ) );
--TODO: max-min probably wont work for rects that cross world wrap! -KS
local wx = mapMinX + (mapMaxX-mapMinX) * mapx;
local wy = mapMinY + (mapMaxY-mapMinY) * (1 - mapy);
return wx, wy;
end
-- ===========================================================================
function OnInputHandler( pInputStruct:table )
local uiMsg = pInputStruct:GetMessageType();
if uiMsg == KeyEvents.KeyUp then
local uiKey = pInputStruct:GetKey();
if uiKey == Keys.VK_ESCAPE then
Close();
return true; -- we did eat the keystroke here
end
end
-- Update tooltip as the mouse is moved over the minimap
if (uiMsg == MouseEvents.MouseMove or uiMsg == MouseEvents.PointerUpdate) and UI.IsFullscreenMapEnabled() then
ShowMinimapTooltips(pInputStruct:GetX(), pInputStruct:GetY())
end
return false; -- don't eat it here though, or it causes the input actions to break
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) 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.MapProxy:SetToolTipString(szOwner);
else
local pTooltipString = Locale.Lookup("LOC_MINIMAP_UNCLAIMED_TOOLTIP");
Controls.MapProxy:SetToolTipString(pTooltipString);
end
else
local pTooltipString = Locale.Lookup("LOC_MINIMAP_FOG_OF_WAR_TOOLTIP");
Controls.MapProxy:SetToolTipString(pTooltipString);
end
end
end
end
-- ===========================================================================
function Close()
-- Close may be in response to an event which others are listening too as
-- well. To be safe only switch back the interface mode if it's in the
-- mode it was switched to at startup.
if UI.GetInterfaceMode() == InterfaceModeTypes.FULLSCREEN_MAP then
if GameConfiguration.IsWorldBuilderEditor() then
LuaEvents.WorldBuilder_ExitFSMap();
else
UI.SetInterfaceMode(InterfaceModeTypes.SELECTION);
end
end
end
-- ===========================================================================
function GetPercentMapRevealed()
local gridWidth, gridHeight = Map.GetGridSize();
local mapMinX, mapMinY, mapMaxX, mapMaxY = UI.GetMinimapWorldRect();
local plotMinX, plotMinY = UI.GetPlotCoordFromWorld(mapMinX, mapMinY);
local plotMaxX, plotMaxY = UI.GetPlotCoordFromWorld(mapMaxX, mapMaxY);
-- Early out (full exposure).
if (plotMinX == -1 and plotMaxX == -1) then
return 1;
end
-- Account for horizontal wrap
if plotMaxX < plotMinX then
local swapTemp:number = plotMinX;
plotMinX = plotMaxX;
plotMaxX = swapTemp;
end
-- Compute percent
local minimapArea :number = (plotMaxX-plotMinX) * (plotMaxY-plotMinY);
local fullArea :number = gridWidth * gridHeight;
local percent :number = math.clamp( minimapArea / fullArea, 0, 1);
return percent;
end
-- ===========================================================================
function OnShow()
-- Some math to force edge gradient to be visible when the map isn't
-- revealed by much but will quickly fade out as world is explored.
local revealedPercent:number = GetPercentMapRevealed();
local alpha:number = math.clamp( 1.2 - (revealedPercent*2),0,1);
Controls.EdgeGradient:SetAlpha( alpha );
end
-- ===========================================================================
-- Hotkey Event
-- ===========================================================================
function OnInputActionTriggered( actionId:number )
if (m_toggleFullScreenMapId ~= nil and (actionId == m_toggleFullScreenMapId)) then
UI.PlaySound("Play_UI_Click");
if UI.GetInterfaceMode() == InterfaceModeTypes.FULLSCREEN_MAP then
Close();
else
UI.SetInterfaceMode(InterfaceModeTypes.FULLSCREEN_MAP);
end
end
end
-- ===========================================================================
-- Game Engine Event
-- ===========================================================================
function OnInterfaceModeChanged(eOldMode:number, eNewMode:number)
if eOldMode == InterfaceModeTypes.FULLSCREEN_MAP then
UIManager:DequeuePopup( ContextPtr );
UI.ShowFullscreenMap( false );
LuaEvents.FullscreenMap_Closed();
end
if eNewMode == InterfaceModeTypes.FULLSCREEN_MAP then
UIManager:QueuePopup( ContextPtr, PopupPriority.MediumHigh, { AlwaysVisibleInQueue = true, AlwaysInputInQueue = true } ); -- Parameters to allow interaction during MP pausing
UI.ShowFullscreenMap( true );
LuaEvents.FullscreenMap_Shown();
end
end
-- ===========================================================================
function LateInitialize()
end
-- ===========================================================================
function OnInit( isReload:boolean )
LateInitialize();
end
-- ===========================================================================
function Initialize()
ContextPtr:SetInitHandler( OnInit );
ContextPtr:SetShowHandler( OnShow );
ContextPtr:SetInputHandler(OnInputHandler, true);
Controls.CloseButton:RegisterCallback(Mouse.eLClick, Close);
Events.InputActionTriggered.Add( OnInputActionTriggered );
Events.InterfaceModeChanged.Add( OnInterfaceModeChanged );
end
Initialize();