Advertisement
Guest User

Untitled

a guest
Feb 3rd, 2015
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.73 KB | None | 0 0
  1. --[[ ----------------------------------------------------------------------------------------------
  2. File : ui_pda_base.script
  3. Description: PDA
  4. Copyright : 2009 © LA-team
  5. Author : barin(19.04.2009)
  6. Editors : barin(18.09.2009), SkyLoader(06.05.2013)
  7. Last edit : 06.05.2013 [...]
  8. --]] ----------------------------------------------------------------------------------------------
  9.  
  10. --/ -----------------------------------------------------------------
  11. --/ VARIABLEs
  12. --/ -----------------------------------------------------------------
  13. local pda_menu = nil
  14.  
  15. local data_tabs = { --/ button, window and handler dependency
  16. [1] = {btn = "btn_comm", wnd = "pda_comm", handler = ui_pda_comm and ui_pda_comm.uiPdaComm},
  17. [2] = {btn = "btn_skills", wnd = "pda_skills", handler = ui_pda_skills and ui_pda_skills.uiPdaSkills},
  18. [3] = {btn = "btn_downloads", wnd = "pda_downloads", handler = ui_pda_downs and ui_pda_downs.uiPdaDownloads},
  19. [4] = {btn = "btn_games", wnd = "pda_games", handler = ui_pda_games and ui_pda_games.uiPdaGames},
  20. [5] = {btn = "btn_mplayer", wnd = "pda_mplayer", handler = ui_pda_mplayer and ui_pda_mplayer.uiPdaMusicPlayer}
  21. }
  22. local data_leds = {
  23. color = {
  24. "ui_dlg_elem_pda_led_yellow",
  25. "ui_dlg_elem_pda_led_blue",
  26. "ui_dlg_elem_pda_led_red",
  27. "ui_dlg_elem_pda_led_green",
  28. "ui_dlg_elem_pda_led_orange"
  29. },
  30. pos = {
  31. {936, 334, 11, 5},
  32. {936, 354, 11, 5},
  33. {936, 375, 11, 5},
  34. {936, 395, 11, 5},
  35. {936, 416, 11, 5}
  36. }
  37. }
  38. --/ --------------------------
  39. local sModule = script_name()
  40. --/ -----------------------------------------------------------------
  41. local log = function(fmt,...) _G.log(sModule, tostring(fmt),...) end
  42. --/ -----------------------------------------------------------------
  43. --/ CLASS CONSTRUCTOR
  44. --/ -----------------------------------------------------------------------------------------------
  45. class "uiPdaBase" (CUIScriptWnd)
  46. --/ -----------------------------------------------------------------------------------------------
  47. function uiPdaBase:__init() super()
  48. la_utils.custom_ui_usage("show", sModule)
  49.  
  50. self.is_open = true --/#!# flag
  51. self.wnds = {} --/ array of working child windows
  52.  
  53. self:InitControls( {135, 119, 761, 475} ) --/< common position and size of the windows for PDA (SetWndRect)
  54. self:InitCallBacks()
  55.  
  56. self:SelectTab(1) --/ activate the first child window
  57.  
  58. self.led_show = false
  59. self.led_timer = time_global() + 5000
  60. end
  61.  
  62. function uiPdaBase:__finalize()
  63. self.is_open = false
  64. end
  65.  
  66. function uiPdaBase:InitControls(pos)
  67. self:Init(0, 0, device().width, device().height)
  68.  
  69. local xml = CScriptXmlInit()
  70. xml:ParseFile("ui_wnd\\ui_pda_base.xml")
  71.  
  72. xml:InitStatic("pda_base:background", self)
  73. xml:InitFrameLine("pda_base:bottom_frame_line", self)
  74. --xml:InitFrameLine("pda_base:time_frame_line", self)
  75. xml:InitStatic("pda_base:time_static", self)
  76.  
  77. self.current_time = xml:InitStatic("pda_base:time_update", self)
  78.  
  79. self.led_wnd = CUIStatic()
  80. self.led_wnd:SetAutoDelete(true)
  81. self.led_wnd:SetWindowName("pda_led")
  82. self:AttachChild(self.led_wnd)
  83.  
  84. for idx,v in ipairs(data_tabs) do
  85. if v.handler then --/ insurance
  86. local wnd = v.handler(xml,pos)
  87. wnd:SetAutoDelete(true)
  88. self:AttachChild(wnd)
  89. self.wnds[idx] = wnd --/ store
  90. self:Register(xml:Init3tButton("pda_base:"..v.btn, self), v.btn)
  91. else
  92. log("uiPdaBase:InitControls: handler for '%s' not exist! <%s>", tostring(v.wnd), "Warning!")
  93. data_tabs[idx] = nil
  94. end
  95. end
  96. self:Register(xml:Init3tButton("pda_base:btn_close", self), "btn_close")
  97. end
  98.  
  99. function uiPdaBase:InitCallBacks()
  100. for idx,v in pairs(data_tabs) do
  101. self["OnBtnAct_"..idx] = function() self:SelectTab(idx) end
  102. self:AddCallback(v.btn, ui_events.BUTTON_CLICKED, self["OnBtnAct_"..idx], self)
  103. end
  104. self:AddCallback("btn_close", ui_events.BUTTON_CLICKED, self.OnExit, self)
  105. end
  106.  
  107. function uiPdaBase:SelectTab(idx)
  108. local child_wnd = self:GetDialogWnd(data_tabs[idx].wnd)
  109. if not (child_wnd and child_wnd:IsShown()) then
  110. if self.prev_idx and self.prev_idx ~= idx then
  111. --/ hide previous tab, deactivate the previous window, activate the previous button
  112. self.wnds[self.prev_idx]:OnWindowHide()
  113. self:GetDialogWnd(data_tabs[self.prev_idx].wnd):Show(false)
  114. self:GetButton(data_tabs[self.prev_idx].btn):Enable(true)
  115. --self:GetButton(data_tabs[self.prev_idx].btn):SetTextColor(pcTextViewer.get_colour("yellow"))
  116. end
  117. --/ activate the window, deactivate the button
  118. self.wnds[idx]:OnWindowShow()
  119. child_wnd:Show(true)
  120. self:GetButton(data_tabs[idx].btn):Enable(false)
  121. --self:GetButton(btn_name):SetTextColor(pcTextViewer.get_colour("full_white"))
  122. end
  123. self.prev_idx = idx --/ remember!
  124. end
  125.  
  126. function uiPdaBase:Update()
  127. CUIScriptWnd.Update(self)
  128.  
  129. self.is_open = true --/#!#
  130. local time = time_global()
  131. if time < (self.time or 0) then return end --/> 1 every half-second
  132. self.time = time + 500
  133.  
  134. self.current_time:SetText(game.get_game_time():timeToString(game.CTime.TimeToMinutes))
  135.  
  136. if not self.led_show then
  137. if self.led_timer < time then
  138. if math.random(1000) % 3 == 2 then
  139. self.led_timer = time + 3000
  140. self.led_wnd:Init(data_leds.color[math.random(#data_leds.color)], unpack(data_leds.pos[math.random(#data_leds.pos)]))
  141. self.led_show = true
  142. else
  143. self.led_timer = time + 5000
  144. end
  145. end
  146. elseif self.led_timer < time then
  147. self.led_timer = time + 5000
  148. self.led_wnd:Show(false)
  149. self.led_show = false
  150. else
  151. self.led_wnd:Show(not self.led_wnd:IsShown())
  152. end
  153. end
  154.  
  155. function uiPdaBase:OnExit()
  156. la_utils.custom_ui_usage("hide", sModule)
  157. self.is_open = false --/#!#
  158. self:GetHolder():start_stop_menu(self, true)
  159. end
  160.  
  161. function uiPdaBase:OnKeyboard(dik, keyboard_action)
  162. CUIScriptWnd.OnKeyboard(self, dik, keyboard_action)
  163. if keyboard_action == ui_events.WINDOW_KEY_PRESSED then
  164. if dik == DIK_keys.DIK_ESCAPE then
  165. self:OnExit()
  166. end
  167. end
  168. return true
  169. end
  170.  
  171. --/ ------------------------------------------------------------------
  172. --/ HELPERs
  173. --/ ------------------------------------------------------------------
  174. function get_menu()
  175. if not pda_menu then
  176. pda_menu = uiPdaBase()
  177. end
  178. return pda_menu --/>
  179. end
  180. function clear_menu()
  181. pda_menu = nil
  182. end
  183. function is_open()
  184. if pda_menu then
  185. return pda_menu.is_open --/>
  186. end
  187. return false --/>
  188. end
  189. function open_pda()
  190. level.start_stop_menu(get_menu(), true)
  191. end
  192. --/ ------------------------------------------------------------------
  193. --/#x# rudiments (later delete)
  194. function is_pda_ext_displayed()
  195. return is_open() --/> redirect
  196. end
  197.  
  198. function display_pda_ext()
  199. open_pda() --/< redirect
  200. end
  201.  
  202. function display_xray_pda()
  203. open_pda() --/< redirect
  204. la_utils.spawn_items(db.actor, "xray_pda", 1, false) --/#?# respawn a need where there used!
  205. end
  206. --/ ------------------------------------------------------------------
  207. --/#+?# calls from the engine
  208. local tab_handler = {
  209. ["comm"] = ui_pda_comm and ui_pda_comm.uiPdaComm,
  210. ["skills"] = ui_pda_skills and ui_pda_skills.uiPdaSkills,
  211. ["downloads"] = ui_pda_downs and ui_pda_downs.uiPdaDownloads,
  212. ["games"] = ui_pda_games and ui_pda_games.uiPdaGames,
  213. ["mplayer"] = ui_pda_mplayer and ui_pda_mplayer.uiPdaMusicPlayer
  214. }
  215. function get_script_pda_window(tab_name)
  216. if type(tab_name) == 'string' and tab_handler[tab_name] then
  217. local xml = CScriptXmlInit()
  218. xml:ParseFile("ui_wnd\\ui_pda_base.xml")
  219. local pos = {77, 62, 761, 475} --/#+# new(!) common position and size of the windows for PDA (SetWndRect)
  220. return tab_handler[tab_name](xml,pos)--/>
  221. end
  222. abort("%s:get_script_pda_window: unknown argument=[%s]", sModule, tostring(tab_name))
  223. return nil --/>
  224. end
  225. --/ ------------------------------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement