Daemonion

dynamic ui_main_menu.script

Apr 19th, 2014
305
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.82 KB | None | 0 0
  1. --------------------------------------------------------------
  2. -- Mod:     LURK 1.2 with RMA and ZRP
  3. -- Last edit:   2014.04.04
  4. -- Author:      Daemonion
  5. -- Thanks:      KamikaZze (OGSE), Tlar, NatVac, Alundaio and GSC forums <3
  6. -- Notes:       Dynamic Menu by Daemonion for LURK 1.2
  7. --------------------------------------------------------------
  8.  
  9. class "main_menu" (CUIScriptWnd)
  10.  
  11. --------------------------------------------------------------
  12. -- BEGIN LURK 1.2 UTILITIES
  13. --------------------------------------------------------------
  14. -- determine whether it is day or night on the current level
  15. local function is_night()
  16.     local gth = level.get_time_hours()
  17.     return gth <= 5 or gth >= 19
  18. end
  19.  
  20. -- this starts by looking in gamedata\sounds\daemonion\menu\
  21. -- looks for a file name which begins with "mm_"
  22. -- then determines if it is day or night, then looks for a file name of "mm_night" or "mm_day"
  23. -- then expands the search to "mm_night_audio_" or "mm_day_audio_"
  24. -- then adds the name of the current level to become "mm_night_audio_l01_escape"
  25. -- then adds the final postfix "_l" or "_r" for stereo audio playback
  26. function play_daemonion_audio()
  27.     local con = get_console()
  28.     local actor = db.actor
  29.     local sound = "daemonion\\menu\\mm_"
  30.    
  31.     if (is_night() == true) then
  32.         sound = sound .. "night"
  33.     else
  34.         sound = sound .. "day"
  35.     end
  36.    
  37.     sound = sound .. "_audio_"..level.name()
  38.  
  39.     audio_left_channel = xr_sound.get_safe_sound_object(sound.."_l")
  40.     audio_right_channel = xr_sound.get_safe_sound_object(sound.."_r")
  41.    
  42.     con:execute("daemonion_audio:executing_play_daemonion_audio...")
  43.     if audio_left_channel:playing() == false then
  44.         audio_left_channel:play_at_pos (actor, vector():set(-5, 0, 1), 1, sound_object.s2d)
  45.         audio_right_channel:play_at_pos (actor, vector():set(5, 0, 1), 1, sound_object.s2d)
  46.     end
  47. end
  48.  
  49. -- stops audio from playing in the main menu when the player hits ESC or clicks "return to game" button
  50. function stop_daemonion_audio()
  51.     local con = get_console()
  52.     if audio_left_channel:playing() == true then
  53.         con:execute("daemonion_audio:stopping_daemonion_audio...")
  54.         audio_left_channel:stop()
  55.         audio_right_channel:stop()
  56.     end
  57. end
  58.  
  59. -- create global variables for menu sound (they will get over-written) /dae
  60. audio_left_channel = xr_sound.get_safe_sound_object("daemonion\\misc\\silence")
  61. audio_right_channel = xr_sound.get_safe_sound_object("daemonion\\misc\\silence")
  62. --------------------------------------------------------------
  63. -- END LURK 1.2 UTILITIES
  64. --------------------------------------------------------------
  65.  
  66. -- runs when main menu is first loaded /dae
  67. function main_menu:__init() super()    
  68.     self.mbox_mode = 0
  69.     self:InitControls()
  70.     self:InitCallBacks()
  71.        
  72.     -- if the main menu is brought up after a game or save is loaded, do this: /dae
  73.     local con = get_console()
  74.     if (level.present() and db.actor) and audio_left_channel:playing() == false then
  75.         con:execute("daemonion_audio:attempting_to_execute_daemonion_audio_function ...")
  76.         play_daemonion_audio()
  77.     end
  78. end
  79.  
  80. -- runs when main menu is closed, supposedly, but doesn't work well for me /dae
  81. function main_menu:__finalize()        
  82. end
  83.  
  84. _ver_static = nil
  85.  
  86. function main_menu:InitControls()
  87.     -- testing widescreen support /dae
  88.     local screen = device()
  89.     local scr_width = screen.width
  90.     local scr_height = screen.height   
  91.     local screen_aspect_ratio = 1.34
  92.     -- 1024x768,1280x1024,1600x1200         = 1.33
  93.     -- 1280x800,1440x900,1680x1050,1920x1200    = 1.6
  94.     -- 1280x720,1920x1080               = 1.77
  95.    
  96.     if scr_width > 0 and scr_height > 0 then
  97.         screen_aspect_ratio = scr_width / scr_height
  98.     end
  99.    
  100.     self:Init(0,0,1024,768) -- not sure what the first two numbers are for /dae  
  101.    
  102.     local xml = CScriptXmlInit()
  103.  
  104.         -- lurk_main_menu.xml refers to gamedata\config\ui
  105.     -- it is a modified main menu xml I made for compatibility (no need to change the old one!)
  106.     xml:ParseFile("lurk_main_menu.xml") -- non-vanilla file must be created (added for compatibility)
  107.    
  108.     -- determines which video/texture to use at launch (before a new or saved game begins)
  109.     if (screen_aspect_ratio == 1.6) then xml:InitStatic("start_movie_1.6", self)
  110.     elseif (screen_aspect_ratio > 1.6) then xml:InitStatic("start_movie_1.77", self)
  111.     else xml:InitStatic("start_movie_1.33", self) end
  112.  
  113.  
  114.     local flist = getFS():file_list_open_ex("$game_saves$",bit_or(bit_or(FS.FS_ListFiles,FS.FS_RootOnly), FS.FS_ClampExt) , "*.sav")
  115.     local f_cnt = flist:Size()
  116.     local con = get_console()
  117.     local y,m,d,h,min,sec,ms = nil,nil,nil,nil,nil,nil,nil
  118.    
  119.     flist:Sort(5)
  120.    
  121.     if f_cnt > 0 then
  122.         local file = flist:GetAt(0)
  123.         local sg = CSavedGameWrapper(file:NameFull())
  124.        
  125.         y,m,d,h,min,sec,ms = sg:game_time():get()
  126.        
  127.         -- little fixin's from OGSE to display data in main menu console; we could add other things /daemonion
  128.         local ar = screen_aspect_ratio
  129.         con:execute("aspect_ratio="..ar)
  130.         local level_name = sg:level_name()
  131.         con:execute("level_name="..level_name)
  132.         local level_id = sg:level_id()
  133.         con:execute("level_id="..level_id)
  134.         local actor_health = sg:actor_health()
  135.         con:execute("actor_health="..actor_health)
  136.     end
  137.    
  138.     -- reads level and time of day
  139.     -- then picks proper texture from lurk_main_menu.xml
  140.     if level and level.present() then
  141.         local htime = level.get_time_hours()
  142.         if (screen_aspect_ratio > 1.4) then
  143.         -- player using widescreen resolution
  144.             if (is_night() == true) then
  145.                 -- it is night time; use night and widescreen resolution version
  146.                 xml:InitStatic("mm_night_wide_"..level.name(), self)
  147.             else
  148.                 -- it is day time; use day and widescreen resolution version
  149.                 xml:InitStatic("mm_day_wide_"..level.name(), self)
  150.             end
  151.         else
  152.         -- player using a super lame resolution
  153.             if (is_night() == true) then
  154.                 -- it is night time; use night and super lame resolution version
  155.                 xml:InitStatic("mm_night_"..level.name(), self)
  156.             else
  157.                 -- it is day time; use day and super lame resolution version
  158.                 xml:InitStatic("mm_day_"..level.name(), self)
  159.             end
  160.         end
  161.     end
  162.    
  163.     self.shniaga = xml:InitMMShniaga("shniaga_wnd",self);  
  164.     self.message_box = CUIMessageBoxEx()
  165.     self:Register(self.message_box, "msg_box") 
  166.    
  167.     local _ver = xml:InitStatic     ("lurk_version",self)
  168.     local mm                        = _G.main_menu.get_main_menu()
  169.     if type(mm.GetGSVer) ~= "function" then
  170.         _ver:SetText("ver. 1.0 - NOT COMPATIBLE with " .. _z.mod_version_str)
  171.     else
  172.         _ver:SetText("ver. " .. mm:GetGSVer() .. " - " .. _z.mod_version_str)
  173.     end
  174.     _ver_static = _ver
  175.     save_made = false
  176.    
  177. end
  178.  
  179. -- stops audio when "return to game" is clocked
  180. function main_menu:OnButton_return_game()
  181.     local console = get_console()
  182.     console:execute("main_menu off")
  183.     stop_daemonion_audio()      -- /daemonion
  184. end
  185.  
  186. -- to stop audio when ESC Key is pressed:
  187. -- find the following line:
  188. if dik == DIK_keys.DIK_ESCAPE and alive_on_level then
  189.  
  190. -- and add a call to this function:
  191. stop_daemonion_audio()          -- /daemonion
Advertisement
Add Comment
Please, Sign In to add comment