Daemonion

ui_main_menu.script

Oct 15th, 2012
121
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- File: UI_MAIN_MENU.SCRIPT
  2. -- Description: Load Dialog for STALKER
  3. -- Created: 28.10.2004
  4. -- Lasd edit: 18.01.2006
  5. -- Copyright: 2004 GSC Game World
  6. -- Author: Serhiy Vynnychenko (narrator@gsc-game.kiev.ua)
  7. -- Additions: Dynamic Menu by Daemonion for LURK 1.2
  8. -- Version: 0.9
  9. -- Thanks: OGSE team for some of their code, CrommCruac for syntax help
  10. --------------------------------------------------------------
  11. -- ZRP revisions
  12. -- 070803 - OnButton_quit_clicked change to skip confirmation
  13. -- 070924 - OnButton_save_level_clicked added
  14. -- 080202 - animation conditionals, mod_version, _z.process_key()
  15. -- 080404 - support for teleport and jump dialogs, re-enabled quit hotkey
  16. -- 090825 - save prefix, Esc F5/F6 quick named saves
  17. -- 091218 - ZRP Support Utilities interface, Enter key fix
  18. -- 100323 - save prefix now lowercased, filtered for valid characters
  19. -- 120303 - some code cleanup; made TZIO and intra-level jump menus optional
  20. -- 120325 - removed " - start" named quicksave; now part of named autosaves
  21.  
  22. -- set this variable to false if you want the old prompt-to-quit behavior
  23. local quit_without_asking = true
  24.  
  25. -- set this to false if you don't want the Q key to quit
  26. local use_quit_hotkey = true
  27.  
  28. -- set this true if you want additional fixes, capabilities and cheats on the Z key
  29. allow_zrp_utilities = true
  30.  
  31. -- set this true if you want the ability to fast travel on a level
  32. allow_level_jump = true
  33.  
  34. -- set this true if you want TZIO chapter selection (see docs)
  35. allow_TZIO = true
  36.  
  37. -- set this filename prefix to identify unique sets of savegames
  38. -- for named saves made via save dialog, and Esc S, Esc F5/F6 saves
  39. -- must be valid filename characters in doublequotes, should be kept short
  40. save_prefix = ""
  41.  
  42. save_made = false
  43.  
  44. class "main_menu" (CUIScriptWnd)
  45.  
  46. function main_menu:__init() super()
  47. self.mbox_mode = 0
  48. self:InitControls()
  49. self:InitCallBacks()
  50. -- some protection
  51. if type(save_prefix) == "string" then
  52. local new_save_prefix = string.gsub(save_prefix, "%%", "_")
  53. new_save_prefix = string.lower(new_save_prefix)
  54. save_prefix = string.gsub(new_save_prefix, "[:<=>?%*\\/;|,]", "_")
  55. if save_prefix ~= new_save_prefix then
  56. dbglog("Invalid filename char(s) in save_prefix - using \""..save_prefix.."\"")
  57. end
  58. else
  59. dbglog("Error in save prefix")
  60. save_prefix = ""
  61. end
  62. end
  63.  
  64. function main_menu:__finalize()
  65.  
  66. end
  67.  
  68. _ver_static = nil
  69.  
  70. ------------------------------------------------------------------
  71. ------------------------------------------------------------------
  72. -- BEGIN Dynamic Menu changes by Daemonion for LURK 1.2
  73. ------------------------------------------------------------------
  74. ------------------------------------------------------------------
  75. function main_menu:InitControls()
  76.  
  77. self:Init(0,0,1024,768)
  78.  
  79. local xml = CScriptXmlInit()
  80. xml:ParseFile("ui_mm_main.xml")
  81.  
  82. local flist = getFS():file_list_open_ex("$game_saves$",bit_or(bit_or(FS.FS_ListFiles,FS.FS_RootOnly), FS.FS_ClampExt) , "*.sav")
  83. local f_cnt = flist:Size()
  84. local con = get_console()
  85. local y,m,d,h,min,sec,ms = nil,nil,nil,nil,nil,nil,nil
  86.  
  87. flist:Sort(5)
  88.  
  89. if f_cnt > 0 then
  90. local file = flist:GetAt(0)
  91. local sg = CSavedGameWrapper(file:NameFull())
  92.  
  93. y,m,d,h,min,sec,ms = sg:game_time():get()
  94.  
  95. ----- from OGSE
  96. -- local level_name = sg:level_name()
  97. -- con:execute("level_name="..level_name)
  98. -- local level_id = sg:level_id()
  99. -- con:execute("level_id="..level_id)
  100. -- local actor_health = sg:actor_health()
  101. -- con:execute("actor_health="..actor_health)
  102. -----
  103. end
  104.  
  105. -- picks proper texture from ui_mm_main based on the level
  106. if level and level.present() then
  107. -- level AND time of day dependent; haven't tested yet; just wrote it
  108. -- local htime = level.get_time_hours()
  109. -- if htime <= 5 or htime >= 20 then
  110. -- night level menu
  111. -- xml:InitStatic("mm_night"..level.name(), self)
  112. -- else
  113. -- day level menu
  114. -- xml:InitStatic("mm_day"..level.name(), self)
  115. xml:InitStatic("mm_"..level.name(), self)
  116. else
  117. -- shows at start of game before a save is loaded
  118. xml:InitStatic("mm_start", self)
  119. end
  120.  
  121. self.shniaga = xml:InitMMShniaga("shniaga_wnd",self);
  122.  
  123. self.message_box = CUIMessageBoxEx()
  124. self:Register(self.message_box, "msg_box")
  125.  
  126. local _ver = xml:InitStatic ("static_version",self)
  127. local mm = _G.main_menu.get_main_menu()
  128. if type(mm.GetGSVer) ~= "function" then
  129. _ver:SetText("ver. 1.0 - NOT COMPATIBLE with " .. _z.mod_version_str)
  130. else
  131. _ver:SetText("ver. " .. mm:GetGSVer() .. " - " .. _z.mod_version_str)
  132. end
  133. _ver_static = _ver
  134. save_made = false
  135.  
  136. end
  137. ------------------------------------------------------------------
  138. ------------------------------------------------------------------
  139. -- END Dynamic Menu changes by Daemonion for LURK 1.2
  140. ------------------------------------------------------------------
  141. ------------------------------------------------------------------
  142.  
  143. function main_menu:Show(f)
  144. self.shniaga:SetVisibleMagnifier(f)
  145. end
  146.  
  147.  
  148. function main_menu:InitCallBacks()
  149. -- new game
  150. self:AddCallback("btn_novice", ui_events.BUTTON_CLICKED, self.OnButton_new_novice_game, self)
  151. self:AddCallback("btn_stalker", ui_events.BUTTON_CLICKED, self.OnButton_new_stalker_game, self)
  152. self:AddCallback("btn_veteran", ui_events.BUTTON_CLICKED, self.OnButton_new_veteran_game, self)
  153. self:AddCallback("btn_master", ui_events.BUTTON_CLICKED, self.OnButton_new_master_game, self)
  154. self:AddCallback("btn_spawn", ui_events.BUTTON_CLICKED, self.OnButton_load_spawn, self)
  155. -- options
  156. self:AddCallback("btn_options", ui_events.BUTTON_CLICKED, self.OnButton_options_clicked, self)
  157. -- load
  158. self:AddCallback("btn_load", ui_events.BUTTON_CLICKED, self.OnButton_load_clicked, self)
  159. -- save
  160. self:AddCallback("btn_save", ui_events.BUTTON_CLICKED, self.OnButton_save_clicked, self)
  161. self:AddCallback("btn_save_level", ui_events.BUTTON_CLICKED, self.OnButton_save_level_clicked, self)
  162. -- multiplayer
  163. self:AddCallback("btn_multiplayer", ui_events.BUTTON_CLICKED, self.OnButton_multiplayer_clicked, self)
  164. -- quit
  165. self:AddCallback("btn_quit", ui_events.BUTTON_CLICKED, self.OnButton_quit_clicked, self)
  166. self:AddCallback("btn_quit_to_mm", ui_events.BUTTON_CLICKED, self.OnButton_disconnect_clicked, self)
  167. self:AddCallback("btn_ret", ui_events.BUTTON_CLICKED, self.OnButton_return_game, self)
  168. self:AddCallback("btn_lastsave", ui_events.BUTTON_CLICKED, self.OnButton_last_save, self)
  169. self:AddCallback("btn_credits", ui_events.BUTTON_CLICKED, self.OnButton_credits_clicked, self)
  170. -- message box
  171. self:AddCallback("msg_box", ui_events.MESSAGE_BOX_OK_CLICKED, self.OnMsgOk, self)
  172. self:AddCallback("msg_box", ui_events.MESSAGE_BOX_CANCEL_CLICKED, self.OnMsgCancel, self)
  173. self:AddCallback("msg_box", ui_events.MESSAGE_BOX_YES_CLICKED, self.OnMsgYes, self)
  174. self:AddCallback("msg_box", ui_events.MESSAGE_BOX_NO_CLICKED, self.OnMsgNo, self)
  175. self:AddCallback("msg_box", ui_events.MESSAGE_BOX_QUIT_GAME_CLICKED,self.OnMessageQuitGame, self)
  176. self:AddCallback("msg_box", ui_events.MESSAGE_BOX_QUIT_WIN_CLICKED, self.OnMessageQuitWin, self)
  177. end
  178. function main_menu:OnMsgOk()
  179. self.mbox_mode = 0
  180. end
  181.  
  182. function main_menu:OnMsgCancel()
  183. self.mbox_mode = 0
  184. end
  185.  
  186. function main_menu:OnMsgYes()
  187.  
  188. if self.mbox_mode == 1 then
  189. self:LoadLastSave()
  190. end
  191.  
  192. self.mbox_mode = 0
  193. end
  194.  
  195. function main_menu:OnMsgNo()
  196. self.mbox_mode = 0
  197. end
  198.  
  199. function main_menu:LoadLastSave()
  200. local console = get_console()
  201. console:execute ("main_menu off")
  202. console:execute ("load_last_save")
  203. end
  204.  
  205. function main_menu:OnButton_last_save()
  206. if (alife() == nil) then
  207. self:LoadLastSave();
  208. return
  209. end
  210.  
  211. if db.actor ~= nil and not db.actor:alive() then
  212. self:LoadLastSave();
  213. return
  214. end
  215.  
  216. self.mbox_mode = 1
  217. self.message_box:Init ("message_box_confirm_load_save")
  218. self:GetHolder():start_stop_menu(self.message_box, true)
  219. end
  220.  
  221. function main_menu:OnButton_credits_clicked()
  222. -- local console = get_console()
  223. -- console:execute("main_menu off")
  224. game.start_tutorial("credits_seq")
  225. end
  226.  
  227. function main_menu:OnButton_quit_clicked()
  228. if quit_without_asking then
  229. _ver_static:SetText(" Quitting...")
  230. self.OnMessageQuitWin()
  231. else
  232. self.message_box:Init("message_box_quit_windows")
  233. self:GetHolder():start_stop_menu(self.message_box, true)
  234. end
  235. end
  236.  
  237.  
  238. function main_menu:OnButton_disconnect_clicked()
  239. self.message_box:Init("message_box_quit_game")
  240.  
  241. if (level.game_id() ~= 1) then
  242. self.message_box:SetText("ui_mm_disconnect_message") -- MultiPlayer
  243. else
  244. self.message_box:SetText("ui_mm_quit_game_message") -- SinglePlayer
  245. end
  246. self:GetHolder():start_stop_menu(self.message_box, true)
  247. end
  248.  
  249. function main_menu:OnMessageQuitGame()
  250. local console = get_console()
  251. console:execute("disconnect")
  252. end
  253.  
  254. function main_menu:OnMessageQuitWin()
  255. local console = get_console()
  256. console:execute("quit")
  257. end
  258.  
  259. function main_menu:OnButton_return_game()
  260. local console = get_console()
  261. console:execute("main_menu off")
  262. end
  263.  
  264. function main_menu:OnButton_new_novice_game()
  265. local console = get_console()
  266. console:execute("g_game_difficulty gd_novice")
  267. self:StartGame()
  268. end
  269.  
  270. function main_menu:OnButton_new_stalker_game()
  271. local console = get_console()
  272. console:execute("g_game_difficulty gd_stalker")
  273. self:StartGame()
  274. end
  275.  
  276. function main_menu:OnButton_new_veteran_game()
  277. local console = get_console()
  278. console:execute("g_game_difficulty gd_veteran")
  279. self:StartGame()
  280. end
  281.  
  282. function main_menu:OnButton_new_master_game()
  283. local console = get_console()
  284. console:execute("g_game_difficulty gd_master")
  285. self:StartGame()
  286. end
  287.  
  288. function main_menu:StartGame()
  289. local console = get_console()
  290.  
  291. if (alife() ~= nil) then
  292. console:execute ("disconnect")
  293. end
  294.  
  295. console:execute("start server(all/single/alife/new) client(localhost)")
  296. console:execute("main_menu off")
  297. end
  298.  
  299. function main_menu:OnButton_load_spawn()
  300. if self.spawn_dlg == nil then
  301. self.spawn_dlg = ui_spawn_dialog.spawn_dialog()
  302. self.spawn_dlg.owner = self
  303. end
  304.  
  305. self:GetHolder():start_stop_menu(self.spawn_dlg, true)
  306. self:GetHolder():start_stop_menu(self, true) --new
  307. self:Show(false)
  308. end
  309.  
  310. function main_menu:OnButton_save_clicked()
  311. if self.save_dlg == nil then
  312. self.save_dlg = ui_save_dialog.save_dialog()
  313. self.save_dlg.owner = self
  314. end
  315.  
  316. self:GetHolder():start_stop_menu(self.save_dlg, true)
  317. self:GetHolder():start_stop_menu(self, true) --new
  318. self:Show(false)
  319. if save_prefix ~= "" then
  320. local edit_box = self.save_dlg:GetEditBox("edit_filename")
  321. edit_box:SetText(save_prefix)
  322. end
  323. end
  324.  
  325. function main_menu:OnButton_options_clicked()
  326. if self.opt_dlg == nil then
  327. self.opt_dlg = ui_mm_opt_main.options_dialog()
  328. self.opt_dlg.owner = self
  329. end
  330.  
  331. self.opt_dlg:UpdateControls()
  332. self:GetHolder():start_stop_menu(self.opt_dlg, true)
  333. self:GetHolder():start_stop_menu(self, true) --new
  334. self:Show(false)
  335. end
  336.  
  337. function main_menu:OnButton_load_clicked()
  338. if self.load_dlg ==nil then
  339. self.load_dlg = ui_load_dialog.load_dialog()
  340. self.load_dlg.owner = self
  341. end
  342.  
  343. self:GetHolder():start_stop_menu(self.load_dlg, true)
  344. self:GetHolder():start_stop_menu(self, true) --new
  345. self:Show(false)
  346. end
  347.  
  348. function main_menu:OnButton_multiplayer_clicked()
  349. if self.mp_dlg ==nil then
  350. self.mp_dlg = ui_mp_main.mp_main()
  351. self.mp_dlg.owner = self
  352. end
  353. self.mp_dlg:UpdateControls()
  354. self:GetHolder():start_stop_menu(self.mp_dlg, true)
  355. self:GetHolder():start_stop_menu(self, true) --new
  356. self:Show(false)
  357.  
  358. -- self.mp_dlg:OnBtn_Refresh()
  359.  
  360. local console = get_console()
  361. console:execute ("check_for_updates 0")
  362.  
  363. self.mp_dlg:OnRadio_NetChanged()
  364. end
  365.  
  366. -- ZRP functions
  367. function AddTimeDigits(str, dig)
  368. if (dig > 9) then
  369. str = str .. dig
  370. else
  371. str = str .. "0" .. dig
  372. end
  373. return str
  374. end
  375.  
  376. function main_menu:OnButton_save_level_clicked()
  377. local console = get_console()
  378. local y,m,d,h,min,sec,ms = 0,0,0,0,0,0,0
  379.  
  380. y,m,d,h,min,sec,ms = game.get_game_time():get(y,m,d,h,min,sec,ms)
  381.  
  382. local date_time = "_"
  383.  
  384. date_time = date_time .. y
  385. date_time = date_time .. "-"
  386. date_time = AddTimeDigits(date_time, m)
  387. date_time = date_time .. "-"
  388. date_time = AddTimeDigits(date_time, d)
  389. date_time = date_time .. "_"
  390. date_time = AddTimeDigits(date_time, h)
  391. date_time = AddTimeDigits(date_time, min)
  392. -- date_time = AddTimeDigits(date_time, sec)
  393.  
  394. console:execute("main_menu off")
  395. console:execute("save " .. save_prefix .. level.name() .. date_time)
  396. end
  397.  
  398. function main_menu:teleport_dialog()
  399. if self.teleport_dlg ==nil then
  400. self.teleport_dlg = ui_teleport_dialog.teleport_dialog()
  401. self.teleport_dlg.owner = self
  402. end
  403.  
  404. if level.name() ~= "l01_escape" then
  405. self.teleport_dlg.check_equiponly:SetCheck(true)
  406. end
  407. self:GetHolder():start_stop_menu(self.teleport_dlg, true)
  408. self:GetHolder():start_stop_menu(self, true) --new
  409. self:Show(false)
  410. end
  411.  
  412. function main_menu:zrp_level_zip_dialog()
  413. if self.level_zip_dlg ==nil then
  414. self.level_zip_dlg = ui_level_zip_dialog.level_zip_dialog()
  415. self.level_zip_dlg.owner = self
  416. end
  417.  
  418. self.level_zip_dlg:FillList() -- init for each level invocation
  419.  
  420. self:GetHolder():start_stop_menu(self.level_zip_dlg, true)
  421. self:GetHolder():start_stop_menu(self, true) --new
  422. self:Show(false)
  423. end
  424.  
  425. function main_menu:zrp_utils_dialog()
  426. if self.zrp_utils_dlg == nil then
  427. self.zrp_utils_dlg = ui_zrp_utils_dialog.zrp_utils_dialog()
  428. self.zrp_utils_dlg.owner = self
  429. end
  430.  
  431. self:GetHolder():start_stop_menu(self.zrp_utils_dlg, true)
  432. self:GetHolder():start_stop_menu(self, true) --new
  433. self:Show(false)
  434. end
  435. -- end ZRP functions
  436.  
  437. function main_menu:Dispatch(cmd, param) --virtual function
  438. if cmd == 2 then
  439. self:OnButton_multiplayer_clicked()
  440. end
  441. return true
  442. end
  443.  
  444. function main_menu:OnKeyboard(dik, keyboard_action) --virtual function
  445. CUIScriptWnd.OnKeyboard(self,dik,keyboard_action)
  446. local bind = dik_to_bind(dik)
  447. local console = get_console()
  448.  
  449. if keyboard_action == ui_events.WINDOW_KEY_PRESSED then
  450. local alive_on_level = level.present() and (db.actor ~= nil) and db.actor:alive()
  451. if dik == DIK_keys.DIK_ESCAPE and alive_on_level then
  452. console:execute("main_menu off")
  453. elseif dik == DIK_keys.DIK_Q and use_quit_hotkey then
  454. self:OnMessageQuitWin()
  455. elseif dik == DIK_keys.DIK_RETURN then
  456. if save_made then
  457. save_made = false
  458. self:OnButton_return_game()
  459. else
  460. return false --let the original functionality have it
  461. end
  462. elseif (dik == DIK_keys.DIK_F5 or dik == DIK_keys.DIK_F6) and alive_on_level then
  463. console:execute("main_menu off")
  464. console:execute("save " .. save_prefix..level.name().."_snapshot")
  465. elseif dik == DIK_keys.DIK_S and alive_on_level then
  466. self:OnButton_save_level_clicked()
  467. elseif dik == DIK_keys.DIK_T and allow_TZIO and ui_teleport_dialog and alive_on_level then
  468. self:teleport_dialog()
  469. elseif dik == DIK_keys.DIK_J and allow_level_jump and ui_level_zip_dialog and alive_on_level then
  470. self:zrp_level_zip_dialog()
  471. elseif dik == DIK_keys.DIK_Z and allow_zrp_utilities and ui_zrp_utils_dialog and alive_on_level then
  472. self:zrp_utils_dialog()
  473. elseif _z then
  474. return _z.process_key(self, dik, keyboard_action)
  475. end
  476. end
  477.  
  478. return true
  479. end
RAW Paste Data