1+ class "options_dialog" (CUIScriptWnd)
2+
3+ function options_dialog:__init() super()
4+
5+ self.m_preconditions = {}
6+ self:InitControls()
7+ self:InitCallBacks()
8+ self.tab:SetActiveTab ("video")
9+ end
10+
11+ function options_dialog:__finalize()
12+
13+ end
14+
15+ function options_dialog:InitControls()
16+ self:SetWndRect (Frect():set(0,0,1024,768))
17+ self:Enable (true)
18+
19+ local xml = CScriptXmlInit()
20+ xml:ParseFile ("ui_mm_opt.xml")
21+
22+ xml:InitStatic ("background", self)
23+ self.dialog = xml:InitStatic("main_dialog:dialog", self)
24+
25+ -- xml:InitStatic ("main_dialog:cap_options", self.dialog)
26+
27+ self.dlg_video = ui_mm_opt_video.opt_video()
28+ self.dlg_video:InitControls (0,0, xml, self)
29+ self.dlg_video:Show (false)
30+ self.dialog:AttachChild (self.dlg_video)
31+ xml:InitWindow ("tab_size", 0, self.dlg_video)
32+
33+ self.dlg_sound = ui_mm_opt_sound.opt_sound()
34+ self.dlg_sound:InitControls (0,0, xml, self)
35+ self.dlg_sound:Show (false)
36+ self.dialog:AttachChild (self.dlg_sound)
37+ xml:InitWindow ("tab_size", 0, self.dlg_sound)
38+
39+ self.dlg_gameplay = ui_mm_opt_gameplay.opt_gameplay()
40+ self.dlg_gameplay:InitControls(0,0, xml, self)
41+ self.dlg_gameplay:Show (false)
42+ self.dialog:AttachChild (self.dlg_gameplay)
43+ xml:InitWindow ("tab_size", 0, self.dlg_gameplay)
44+
45+ self.dlg_controls = ui_mm_opt_controls.opt_controls()
46+ self.dlg_controls:InitControls(0,0, xml, self)
47+ self.dlg_controls:Show (false)
48+ self.dialog:AttachChild (self.dlg_controls)
49+ xml:InitWindow ("tab_size", 0, self.dlg_controls)
50+ --[[
51+ self.dlg_con_cmd = ui_mm_opt_con_cmd.opt_con_cmd()
52+ self.dlg_con_cmd:InitControls(0,0, xml, self)
53+ self.dlg_con_cmd:Show (false)
54+ self.dialog:AttachChild (self.dlg_con_cmd)
55+ xml:InitWindow ("tab_size", 0, self.dlg_con_cmd)
56+ ]]
57+ self.dlg_video_adv = ui_mm_opt_video_adv.opt_video_adv()
58+ self.dlg_video_adv:InitControls(0,0, xml, self)
59+ self.dlg_video_adv:Show (false)
60+ self.dialog:AttachChild (self.dlg_video_adv)
61+ xml:InitWindow ("tab_size", 0, self.dlg_video_adv)
62+
63+ local btn
64+ btn = xml:Init3tButton ("main_dialog:btn_accept", self.dialog)
65+ self:Register (btn, "btn_accept")
66+ btn = xml:Init3tButton ("main_dialog:btn_cancel", self.dialog)
67+ self:Register (btn, "btn_cancel")
68+
69+ self.tab = xml:InitTab("main_dialog:tab", self.dialog)
70+ self:Register (self.tab, "tab")
71+
72+
73+ self.message_box = CUIMessageBoxEx()
74+ self:Register (self.message_box, "mb")
75+
76+ self.b_restart_system_shown = false
77+ self.timer = nil
78+
79+ self.cap_download = xml:InitStatic ("download_static",self)
80+ self.text_download = xml:InitStatic ("download_text",self)
81+ self.download_progress = xml:InitProgressBar ("progress_download", self)
82+ self.btn_cancel_download = xml:Init3tButton ("btn_cancel_download", self)
83+ self:Register (self.btn_cancel_download, "btn_cancel_download")
84+
85+ end
86+
87+ function options_dialog:SetCurrentValues()
88+ local opt = COptionsManager()
89+
90+ opt:SetCurrentValues("mm_opt_video_preset")
91+ opt:SaveBackupValues("mm_opt_video_preset")
92+
93+ opt:SetCurrentValues("mm_opt_video")
94+ opt:SaveBackupValues("mm_opt_video")
95+
96+ opt:SetCurrentValues("mm_opt_video_adv")
97+ opt:SaveBackupValues("mm_opt_video_adv")
98+
99+ opt:SetCurrentValues("mm_opt_gameplay")
100+ opt:SaveBackupValues("mm_opt_gameplay")
101+
102+ opt:SetCurrentValues("mm_opt_sound")
103+ opt:SaveBackupValues("mm_opt_sound")
104+
105+ opt:SetCurrentValues("mm_opt_controls")
106+ opt:SaveBackupValues("mm_opt_controls")
107+
108+ opt:SetCurrentValues("key_binding")
109+ opt:SaveBackupValues("key_binding")
110+
111+ self:UpdateDependControls()
112+ end
113+
114+ function options_dialog:UpdateDependControls()
115+ self.scroll_v:Clear()
116+ local _current_id = self.combo_renderer:CurrentID()
117+
118+ for i,j in pairs(self.m_preconditions) do
119+ if(j.func(_current_id)) then
120+ self.scroll_v:AddWindow(j.control, true)
121+ j.control:SetAutoDelete(false)
122+ end
123+ end
124+
125+ local max_texture_lod = 4
126+ local min_texture_lod = 0
127+
128+ if _current_id ~= 0 then
129+ if not is_enough_address_space_available() then
130+ min_texture_lod = 1
131+ end
132+ end
133+
134+ self.texture_lod_track:SetOptIBounds(min_texture_lod, max_texture_lod)
135+ self:OnAOOptionChange()
136+ end
137+
138+ function options_dialog:InitCallBacks()
139+ self:AddCallback("tab", ui_events.TAB_CHANGED, self.OnTabChange, self)
140+ self:AddCallback("btn_advanced_graphic",ui_events.BUTTON_CLICKED, self.OnBtnAdvGraphic, self)
141+ self:AddCallback("btn_accept", ui_events.BUTTON_CLICKED, self.OnBtnAccept, self)
142+ self:AddCallback("btn_cancel", ui_events.BUTTON_CLICKED, self.OnBtnCancel, self)
143+ self:AddCallback("btn_default_graphic", ui_events.BUTTON_CLICKED, self.OnBtnDefGraph, self)
144+ self:AddCallback("btn_default_sound", ui_events.BUTTON_CLICKED, self.OnBtnDefSound, self)
145+ self:AddCallback("combo_preset", ui_events.LIST_ITEM_SELECT, self.OnPresetChanged, self)
146+ self:AddCallback("btn_simply_graphic", ui_events.BUTTON_CLICKED, self.OnSimplyGraphic, self)
147+ self:AddCallback("btn_keyb_default", ui_events.BUTTON_CLICKED, self.OnBtnKeybDefault, self)
148+ self:AddCallback("btn_check_updates", ui_events.BUTTON_CLICKED, self.OnBtnCheckUpdates, self)
149+ self:AddCallback("combo_renderer", ui_events.LIST_ITEM_SELECT, self.UpdateDependControls, self)
150+ self:AddCallback("btn_cancel_download", ui_events.BUTTON_CLICKED, self.OnBtn_CancelDownload, self)
151+ self:AddCallback("tab_ao_opt", ui_events.TAB_CHANGED, self.OnAOOptionChange, self)
152+
153+ self:AddCallback("mb", ui_events.MESSAGE_BOX_YES_CLICKED, self.OnApplyChanges, self)
154+ self:AddCallback("mb", ui_events.MESSAGE_BOX_NO_CLICKED, self.OnDiscardChanges,self)
155+ -- self:AddCallback("trb_ssample", ui_events.BUTTON_CLICKED, self.UpdateDependControls, self)
156+ -- self:AddCallback("cb_ssample", ui_events.LIST_ITEM_SELECT, self.UpdateDependControls, self)
157+
158+ end
159+
160+ function options_dialog:OnBtnCheckUpdates()
161+ local console = get_console()
162+ console:execute ("check_for_updates 1")
163+ end
164+
165+ function options_dialog:OnBtnKeybDefault()
166+ local console = get_console()
167+ console:execute ("default_controls")
168+
169+ local opt = COptionsManager()
170+ opt:SetCurrentValues ("mm_opt_controls")
171+ opt:SetCurrentValues ("key_binding")
172+ end
173+
174+ function options_dialog:OnPresetChanged()
175+ local opt = COptionsManager()
176+ opt:SetCurrentValues ("mm_opt_video_adv")
177+ end
178+
179+
180+ function options_dialog:OnBtnDefGraph()
181+ local opt = COptionsManager()
182+ opt:SendMessage2Group("mm_opt_video","set_default_value")
183+ end
184+
185+ function options_dialog:OnBtnDefSound()
186+ local opt = COptionsManager()
187+ opt:SendMessage2Group("mm_opt_sound","set_default_value")
188+ end
189+
190+ function options_dialog:OnBtnAccept()
191+
192+ local opt = COptionsManager()
193+ local console = get_console()
194+
195+ console:execute("cfg_save tmp")
196+
197+ opt:SaveValues("mm_opt_video_preset")
198+ opt:SaveValues("key_binding")
199+ opt:SaveValues("mm_opt_video")
200+ opt:SaveValues("mm_opt_video_adv")
201+ opt:SaveValues("mm_opt_gameplay")
202+ opt:SaveValues("mm_opt_sound")
203+ opt:SaveValues("mm_opt_controls")
204+
205+ if opt:NeedVidRestart() then
206+ _G.b_discard_settings_shown = true
207+ self.message_box:InitMessageBox("message_box_yes_no")
208+ self.message_box:SetText(string.format("%s %d% s", game.translate_string("ui_mm_confirm_changes"), 15, game.translate_string("mp_si_sec")))
209+ self.message_box:ShowDialog(true)
210+ else
211+ self:OnApplyChanges()
212+ end
213+
214+ opt:OptionsPostAccept()
215+
216+ console:execute("cfg_save")
217+ end
218+
219+ function options_dialog:OnBtnCancel()
220+ local opt = COptionsManager()
221+ opt:UndoGroup ("mm_opt_video_preset")
222+ opt:UndoGroup ("mm_opt_video")
223+ opt:UndoGroup ("mm_opt_video_adv")
224+ opt:UndoGroup ("mm_opt_sound")
225+ opt:OptionsPostAccept ()
226+
227+ self.owner:ShowDialog(true)
228+ self:HideDialog()
229+ self.owner:Show(true)
230+ end
231+
232+ function options_dialog:OnTabChange()
233+ self.dlg_video:Show (false)
234+ self.dlg_sound:Show (false)
235+ self.dlg_gameplay:Show (false)
236+ self.dlg_controls:Show (false)
237+ self.dlg_video_adv:Show (false)
238+
239+ local ids = self.tab:GetActiveId()
240+ if ids == "video" then
241+ self.dlg_video:Show(true)
242+ elseif ids == "sound" then
243+ self.dlg_sound:Show(true)
244+ elseif ids == "gameplay" then
245+ self.dlg_gameplay:Show(true)
246+ elseif ids == "controls" then
247+ self.dlg_controls:Show(true)
248+ end
249+
250+ end
251+
252+ function options_dialog:OnAOOptionChange()
253+ local ao_opt_id = self.tab_ao_opt:GetActiveId()
254+ local render_id = self.combo_renderer:CurrentID()
255+ if(render_id>=4) and (ao_opt_id=="hdao") then
256+ self.combo_ssao:enable_id(4)
257+ else
258+ self.combo_ssao:disable_id(4)
259+ end
260+ self.combo_ssao:SetCurrentOptValue()
261+ end
262+
263+ function options_dialog:OnBtnAdvGraphic()
264+ self.dlg_video:Show (false)
265+ self.dlg_video_adv:Show (true)
266+ end
267+
268+ function options_dialog:OnSimplyGraphic()
269+ self.dlg_video:Show (true)
270+ self.dlg_video_adv:Show (false)
271+ end
272+
273+ function options_dialog:OnKeyboard(dik, keyboard_action)
274+ local res = CUIScriptWnd.OnKeyboard(self,dik,keyboard_action)
275+
276+ if res==false then
277+
278+ local bind = dik_to_bind(dik)
279+
280+ if keyboard_action == ui_events.WINDOW_KEY_PRESSED then
281+ if dik == DIK_keys.DIK_ESCAPE then
282+ if self.dlg_video_adv:IsShown() then
283+ self.dlg_video_adv:Show (false)
284+ self.dlg_video:Show (true)
285+ else
286+ self.owner:ShowDialog(true)
287+ self:HideDialog()
288+ self.owner:Show(true)
289+ end
290+ end
291+
292+ end
293+ end
294+
295+ return res
296+ end
297+
298+ function options_dialog:Update()
299+ CUIScriptWnd.Update(self)
300+
301+ local mm = main_menu.get_main_menu()
302+ local sss = mm:GetPatchProgress()
303+
304+ if sss:GetInProgress() then
305+ self.text_download:Show (true)
306+ self.cap_download:Show (true)
307+ self.download_progress:Show (true)
308+ local _progr = sss:GetProgress()
309+ self.download_progress:SetProgressPos (_progr)
310+ local str = string.format("%.0f%%(%s)",_progr,sss:GetFlieName())
311+ self.text_download:TextControl():SetText (str)
312+ self.btn_cancel_download:Show (true)
313+ else
314+ self.text_download:Show (false)
315+ self.cap_download:Show (false)
316+ self.download_progress:Show (false)
317+ self.btn_cancel_download:Show (false)
318+ end
319+ if(_G.b_discard_settings_shown) then
320+ local tg = math.floor(time_global_async()/1000)
321+ if(self.timer==nil) then
322+ self.timer = tg
323+ end
324+ self.message_box:SetText(string.format("%s %d %s", game.translate_string("ui_mm_confirm_changes"), 15-(tg-self.timer), game.translate_string("mp_si_sec")))
325+ if(tg-self.timer>=15) then
326+ self.message_box:HideDialog()
327+ self:OnDiscardChanges()
328+ end
329+ end
330+ end
331+
332+ function options_dialog:OnBtn_CancelDownload()
333+ local mm = main_menu.get_main_menu()
334+ mm:CancelDownload()
335+ end
336+
337+ function options_dialog:OnApplyChanges()
338+ self.timer = nil
339+ _G.b_discard_settings_shown = false
340+
341+ self.owner:ShowDialog(true)
342+ self:HideDialog()
343+ self.owner:Show(true)
344+
345+ if false==self.b_restart_system_shown then
346+ local opt = COptionsManager()
347+ if opt:NeedSystemRestart() then
348+ self.b_restart_system_shown = true
349+ self.message_box:InitMessageBox("message_box_restart_game")
350+ self.message_box:ShowDialog(true)
351+ end
352+ end
353+ end
354+
355+ function options_dialog:OnDiscardChanges()
356+ self.timer = nil
357+ _G.b_discard_settings_shown = false
358+
359+ local c = get_console()
360+ c:execute("cfg_load tmp")
361+
362+ self:SetCurrentValues()
363+
364+ c:execute("vid_restart")
365+ c:execute("cfg_save")
366+ end
367+
368+ function options_dialog:OnMenuReloaded()
369+ if(_G.b_discard_settings_shown) then
370+ self.message_box:InitMessageBox("message_box_yes_no")
371+ self.message_box:SetText(string.format("%s %d% s", game.translate_string("ui_mm_confirm_changes"), 15, game.translate_string("mp_si_sec")))
372+ self.message_box:ShowDialog(true)
373+ end
374+ end
0 commit comments