-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathInGame.lua
219 lines (185 loc) · 8.4 KB
/
InGame.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
-- ===========================================================================
-- Civ6
-- Root context for ingame (aka: All-the-things)
-- ===========================================================================
include( "LocalPlayerActionSupport" );
include( "InputSupport" );
-- ===========================================================================
-- VARIABLES
-- ===========================================================================
local DefaultMessageHandler = {};
local m_bulkHideTracker :number = 0;
local m_lastBulkHider:string = "first call";
g_uiAddins = {};
local m_PauseId;
local m_QuicksaveId;
-- ===========================================================================
-- FUNCTIONS
-- ===========================================================================
-- ===========================================================================
-- Open up the TopOptionsMenu with the utmost priority.
-- ===========================================================================
function OpenInGameOptionsMenu()
LuaEvents.InGame_OpenInGameOptionsMenu();
end
-- ===========================================================================
-- LUA Event
-- ===========================================================================
function OnTutorialToggleInGameOptionsMenu()
if Controls.TopOptionsMenu:IsHidden() then
OpenInGameOptionsMenu();
else
LuaEvents.InGame_CloseInGameOptionsMenu();
end
end
-- ===========================================================================
DefaultMessageHandler[KeyEvents.KeyUp] =
function( pInputStruct:table )
local uiKey = pInputStruct:GetKey();
if( uiKey == Keys.VK_ESCAPE ) then
if( Controls.TopOptionsMenu:IsHidden() ) then
OpenInGameOptionsMenu();
return true;
end
return false; -- Already open, let it handle it.
elseif( uiKey == Keys.B and pInputStruct:IsShiftDown() and pInputStruct:IsAltDown() and (not UI.IsFinalRelease()) ) then
-- DEBUG: Force unhiding
local msg:string = "***PLAYER Force Bulk unhiding SHIFT+ALT+B ***";
UI.DataError(msg);
m_bulkHideTracker = 1;
BulkHide(false, msg);
elseif( uiKey == Keys.J and pInputStruct:IsShiftDown() and pInputStruct:IsAltDown() and (not UI.IsFinalRelease()) ) then
if m_bulkHideTracker < 1 then
BulkHide(true, "Forced" );
else
BulkHide(false, "Forced" );
end
end
return false;
end
----------------------------------------------------------------
-- LoadGameViewStateDone Event Handler
----------------------------------------------------------------
function OnLoadGameViewStateDone()
-- show HUD elements that relay on the gamecache being fully initialized.
if(GameConfiguration.IsNetworkMultiplayer()) then
Controls.MultiplayerTurnManager:SetHide(false);
end
end
----------------------------------------------------------------
-- Input handling
----------------------------------------------------------------
function OnInputHandler( pInputStruct )
local uiMsg = pInputStruct:GetMessageType();
if DefaultMessageHandler[uiMsg] ~= nil then
return DefaultMessageHandler[uiMsg]( pInputStruct );
end
return false;
end
----------------------------------------------------------------
function OnShow()
Controls.WorldViewControls:SetHide( false );
if (Steam ~= nil) then
if (GameConfiguration.IsAnyMultiplayer()) then
if GameConfiguration.IsHotseat() then
Steam.SetRichPresence("civPresence", "LOC_PRESENCE_IN_GAME_HOTSEAT");
elseif GameConfiguration.IsLANMultiplayer() then
Steam.SetRichPresence("civPresence", "LOC_PRESENCE_IN_GAME_LAN");
else
Steam.SetRichPresence("civPresence", "LOC_PRESENCE_IN_GAME_ONLINE");
end
else
Steam.SetRichPresence("civPresence", "LOC_PRESENCE_IN_GAME_SP");
end
end
end
-- ===========================================================================
-- Hide (or Show) all the contexts part of the BULK group.
-- ===========================================================================
function BulkHide( isHide:boolean, debugWho:string )
-- Tracking for debugging:
m_bulkHideTracker = m_bulkHideTracker + (isHide and 1 or -1);
print("Request to BulkHide( "..tostring(isHide)..", "..debugWho.." ), Show on 0 = "..tostring(m_bulkHideTracker));
if m_bulkHideTracker < 0 then
UI.DataError("Request to bulk show past limit by "..debugWho..". Last bulk shown by "..m_lastBulkHider);
m_bulkHideTracker = 0;
end
m_lastBulkHider = debugWho;
-- Do the bulk hiding/showing
local kGroups:table = {"WorldViewControls", "HUD", "PartialScreens", "Screens", "TopLevelHUD" };
for i,group in ipairs(kGroups) do
local pContext :table = ContextPtr:LookUpControl("/InGame/"..group);
if pContext == nil then
UI.DataError("InGame is unable to BulkHide("..isHide..") '/InGame/"..group.."' because the Context doesn't exist.");
else
if m_bulkHideTracker == 1 and isHide then
pContext:SetHide(true);
elseif m_bulkHideTracker == 0 and isHide==false then
pContext:SetHide(false);
else
-- Do nothing
end
end
end
end
-- ===========================================================================
-- Hotkey Event
-- ===========================================================================
function OnInputActionTriggered( actionId )
if actionId == m_PauseId then
if( Controls.TopOptionsMenu:IsHidden() ) then
OpenInGameOptionsMenu();
return true;
end
elseif actionId == m_QuicksaveId then
-- Quick save
if CanLocalPlayerSaveGame() then
local gameFile = {};
gameFile.Name = "quicksave";
gameFile.Location = SaveLocations.LOCAL_STORAGE;
gameFile.Type= SaveTypes.SINGLE_PLAYER;
gameFile.IsAutosave = false;
gameFile.IsQuicksave = true;
Network.SaveGame(gameFile);
UI.PlaySound("Confirm_Bed_Positive");
end
end
end
-- ===========================================================================
function OnWonderRevealPopupShown() BulkHide( true, "Wonder" ); end -- Game Engine Event
function OnWonderRevealPopupClosed() BulkHide(false, "Wonder" ); end -- Game Engine Event
function OnNaturalWonderPopupShown() BulkHide( true, "NaturalWonder" ); end -- LUA Event
function OnNaturalWonderPopupClosed() BulkHide(false, "NaturalWonder" ); end -- LUA Event
function OnEndGameMenuShown() BulkHide( true, "EndGame" ); Input.PushActiveContext(InputContext.EndGame); end -- LUA Event
function OnEndGameMenuClosed() BulkHide(false, "EndGame" ); Input.PopContext(); end -- LUA Event
function OnDiplomacyHideIngameUI() BulkHide( true, "Diplomacy" ); Input.PushActiveContext(InputContext.Diplomacy); end -- LUA Event
function OnDiplomacyShowIngameUI() BulkHide(false, "Diplomacy" ); Input.PopContext(); end -- LUA Event
function OnTutorialEndHide() BulkHide( true, "TutorialEnd" ); end -- LUA Event
-- ===========================================================================
function Initialize()
-- Support for Modded Add-in UI's
for i, addin in ipairs(Modding.GetUserInterfaces("InGame")) do
print("Loading InGame UI - " .. addin.ContextPath);
table.insert(g_uiAddins, ContextPtr:LoadNewContext(addin.ContextPath));
end
ContextPtr:SetInputHandler( OnInputHandler, true );
ContextPtr:SetShowHandler( OnShow );
Events.LoadGameViewStateDone.Add( OnLoadGameViewStateDone );
m_PauseId = Input.GetActionId("PauseMenu");
m_QuicksaveId = Input.GetActionId("QuickSave");
Events.InputActionTriggered.Add( OnInputActionTriggered );
-- NOTE: Using UI open/closed pairs in the case of end game; where
-- the same player receives both a victory and defeat messages
-- across the wire.
LuaEvents.EndGameMenu_Shown.Add( OnEndGameMenuShown );
LuaEvents.EndGameMenu_Closed.Add( OnEndGameMenuClosed );
LuaEvents.DiplomacyActionView_HideIngameUI.Add( OnDiplomacyHideIngameUI );
LuaEvents.DiplomacyActionView_ShowIngameUI.Add( OnDiplomacyShowIngameUI );
LuaEvents.WonderRevealPopup_Shown.Add( OnWonderRevealPopupShown );
LuaEvents.WonderRevealPopup_Closed.Add( OnWonderRevealPopupClosed );
LuaEvents.NaturalWonderPopup_Shown.Add( OnNaturalWonderPopupShown );
LuaEvents.NaturalWonderPopup_Closed.Add( OnNaturalWonderPopupClosed );
LuaEvents.Tutorial_ToggleInGameOptionsMenu.Add( OnTutorialToggleInGameOptionsMenu );
LuaEvents.Tutorial_TutorialEndHideBulkUI.Add( OnTutorialEndHide );
end
Initialize();