File size: 4,635 Bytes
b6a38d7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
function OnMsg.Autorun()
	InGameInterface.InitialMode = config.InitialInGameInterfaceMode or config.InGameSelectionMode
end

DefineClass.InGameInterface = {
	__parents = { "XDialog" }, 
	mode = false,
	mode_dialog = false,
	Dock = "box",
}

function InGameInterface:Open(...)
	XDialog.Open(self, ...)
	self:SetFocus()
	ShowMouseCursor("InGameInterface")
	Msg("InGameInterfaceCreated", self)
end

function InGameInterface:Close(...)
	XDialog.Close(self, ...)
	HideMouseCursor("InGameInterface")
end

function InGameInterface:OnXButtonDown(button, controller_id)
	if self.desktop:GetModalWindow() == self.desktop and self.mode_dialog then
		return self.mode_dialog:OnXButtonDown(button, controller_id)
	end
end

function InGameInterface:OnXButtonUp(button, controller_id)
	if self.desktop:GetModalWindow() == self.desktop and self.mode_dialog then
		return self.mode_dialog:OnXButtonUp(button, controller_id)
	end
end

function InGameInterface:OnShortcut(shortcut, source, ...)
	local desktop = self.desktop
	if desktop:GetModalWindow() == desktop and self.mode_dialog and self.mode_dialog:GetVisible() and desktop.keyboard_focus and not desktop.keyboard_focus:IsWithin(self.mode_dialog) then
		return self.mode_dialog:OnShortcut(shortcut, source, ...)
	end
end

function InGameInterface:SetMode(mode_or_dialog, context)
	if self.mode_dialog then
		self.mode_dialog:Close()
	end
	local mode = mode_or_dialog
	if type(mode) == "string" then
		local class = mode and g_Classes[mode]
		assert(class)
		self.mode_dialog = class and OpenDialog(mode, self, context)
	else
		assert(IsKindOf(mode, "XDialog"))
		mode:SetParent(self)
		mode:SetContext(context)
		mode:Open()
		self.mode_dialog = mode
		mode = mode_or_dialog.class
	end
	Msg("IGIModeChanging", self.Mode, mode)
	self.mode_log[#self.mode_log + 1] = { self.Mode, self.mode_param }
	self.Mode = mode
	self.mode_param = context
	Msg("IGIModeChanged", mode)
	self:CallOnModeChange()
end

function GetInGameInterface()
	return GetDialog("InGameInterface")
end

function GetTopInGameInterfaceParent()
	return GetInGameInterface()
end

function GetInGameInterfaceMode()
	return GetDialogMode("InGameInterface")
end

function SyncCheck_InGameInterfaceMode()
	if config.IgnoreSyncCheckErrors then
		return true
	end
	return IsAsyncCode()
end

function SetInGameInterfaceMode(mode, context)
	assert(SyncCheck_InGameInterfaceMode())
	SetDialogMode("InGameInterface", mode, context)
end

function GetInGameInterfaceModeDlg(mode)
	local igi = GetInGameInterface()
	if igi and (not mode or mode == igi:GetMode()) then
		return igi.mode_dialog
	end
end

function ShowInGameInterface(bShow, instant, context)
	if not mapdata.GameLogic and not GetInGameInterface() then
		return
	end
	if not bShow and not GetInGameInterface() then 
		return
	end
	local dlg = OpenDialog("InGameInterface", nil, context)
	dlg:SetVisible(bShow, instant)
	dlg.desktop:RestoreFocus()
end

-- deactivate mode dialog and set it to select
function CloseInGameInterfaceMode(mode)
	local igi = GetInGameInterface()
	if igi and (not mode or (igi:GetMode() == mode and igi.mode_dialog.window_state ~= "destroying")) then
		if igi:GetMode() ~= igi.InitialMode then
			igi:SetMode(igi.InitialMode)
		end
	end
end

function OnMsg.GameEnterEditor()
	ShowInGameInterface(false)
	ShowPauseDialog(false, "force")
end

function OnMsg.GameExitEditor()
	if GetInGameInterface() then
		ShowInGameInterface(true)
	end
	if GetTimeFactor() == 0 then
		ShowPauseDialog(true)
	end
end

function OnMsg.StoreSaveGame(storing)
	local igi = GetInGameInterface()
	if not igi or not XTemplates["LoadingAnim"] then return end
	if storing then
		OpenDialog("LoadingAnim", igi:ResolveId("idLoadingContainer") or igi, nil, "StoreSaveGame")
	else
		CloseDialog("LoadingAnim", nil, "StoreSaveGame")
	end
end

local highlight_thread, highlight_obj, highlight_oldcolor
function ViewAndHighlightObject(obj)
	if highlight_obj then
		highlight_obj:SetColorModifier(highlight_oldcolor)
		DeleteThread(highlight_thread)
	end
	highlight_obj = obj
	highlight_oldcolor = obj:GetColorModifier()
	highlight_thread = CreateRealTimeThread(function()
		if IsValid(obj) then
			ViewObject(obj)
			Sleep(200)
			for i = 1, 5 do
				if not IsValid(obj) then break end
				obj:SetColorModifier(RGB(255, 255, 255))
				Sleep(75)
				if not IsValid(obj) then break end
				obj:SetColorModifier(highlight_oldcolor)
				Sleep(75)
			end
		end
		highlight_obj = nil
		highlight_thread = nil
		highlight_oldcolor = nil
	end)
end

function OnMsg.ChangeMapDone()
	HideMouseCursor("system")
	if Platform.developer and not mapdata.GameLogic then
		ShowMouseCursor("system")
	end
end