CodeDOMUIProxy.lua 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. local RemoteProxy = requireProxy("remote/RemoteProxy")
  2. local CodeDOMUIProxy = class("CodeDOMUIProxy", RemoteProxy)
  3. CodeDOMUIProxy.NAME = global.ProxyTable.CodeDOMUIProxy
  4. local cjson = require("cjson")
  5. function CodeDOMUIProxy:ctor()
  6. CodeDOMUIProxy.super.ctor(self)
  7. self._txtUIData = {}
  8. self._txtWinConfig = {}
  9. self:LoadConfig()
  10. end
  11. function CodeDOMUIProxy:LoadConfig()
  12. if SL:IsFileExist("scripts/game_config/cfg_win_export.lua") then
  13. self._txtWinConfig = SL:Require("game_config/cfg_win_export")
  14. end
  15. end
  16. function CodeDOMUIProxy:InitTXTUI(GUINetworkUtil)
  17. GUINetworkUtil:RegisterNetworkHandler(9999, function (msgID, msgData) self:OpenTxtUI(msgData, true) end)
  18. GUINetworkUtil:RegisterNetworkHandler(9998, function (msgID, msgData) self:Hander_TxtUIData(msgData, true) end)
  19. GUINetworkUtil:RegisterNetworkHandler(8888, function (msgID, msgData) self:OpenGUIUI(msgData, true) end)
  20. SL:RegisterLUAEvent(LUA_EVENT_CLOSEWIN, "CodeDOMUI_TXT", function(ID) self:Hander_CloseWin(ID) end)
  21. end
  22. function CodeDOMUIProxy:OpenTxtUI(data, json)
  23. if not data then
  24. return false
  25. end
  26. if json then
  27. data = cjson.decode(data)
  28. end
  29. local GUI_ID = data.GUI_ID
  30. local exportID = data.exportID
  31. local page = data.page or 1
  32. data.page = page
  33. local close = data.close
  34. -- 关闭界面
  35. if close then
  36. if GUI_ID then
  37. return GUI:Win_CloseAll()
  38. end
  39. return GUI:Win_CloseByID(GUI_ID)
  40. end
  41. if not GUI_ID then
  42. return false
  43. end
  44. if not exportID then
  45. return false
  46. end
  47. self._curUpdateData = self._txtUIData[tostring(GUI_ID)]
  48. if self._GUI_ID == GUI_ID and self._exportID == exportID and self._page == page then
  49. -- 更新UI
  50. local window = GUI:GetWindow(nil, GUI_ID)
  51. if window then
  52. data.parent = window
  53. return CodeDOMMainUI.update(data)
  54. end
  55. end
  56. self._GUI_ID = GUI_ID
  57. self._exportID = exportID
  58. self._page = page
  59. SL:RequireFile("GUILayout/CodeDOMMainUI")
  60. CodeDOMMainUI.main(data)
  61. end
  62. function CodeDOMUIProxy:SkipPage(data, key)
  63. data.page = key
  64. self:OpenTxtUI(data)
  65. end
  66. function CodeDOMUIProxy:GetCurTxtUIData()
  67. return self._curUpdateData
  68. end
  69. function CodeDOMUIProxy:Hander_TxtUIData(msgData, isJson)
  70. if not msgData then
  71. return false
  72. end
  73. local data = {}
  74. if isJson then
  75. data = cjson.decode(msgData)
  76. end
  77. local ID = data.GUI_ID
  78. local uiData = data.uiData
  79. local exportID = self._txtWinConfig[ID] and self._txtWinConfig[ID].file
  80. local window = GUI:GetWindow(nil, ID)
  81. if not window then
  82. self._txtUIData[tostring(ID)] = uiData
  83. elseif exportID then
  84. -- 更新UI
  85. local param = {}
  86. param.parent = window
  87. param.exportID = exportID
  88. self._curUpdateData = uiData
  89. return CodeDOMMainUI.update(param)
  90. end
  91. end
  92. function CodeDOMUIProxy:Hander_CloseWin(ID)
  93. if ID and self._txtUIData[tostring(ID)] then
  94. self._txtUIData[tostring(ID)] = nil
  95. end
  96. end
  97. function CodeDOMUIProxy:GetSplitList(data)
  98. local addTab = {}
  99. for k, v in pairs(data) do
  100. if type(v) == "string" and k ~= "GUI_ID" and k ~= "exportID" and k ~= "close" then
  101. if string.find(v, "|") then
  102. local tab1 = {}
  103. tab1 = string.split(v, "|")
  104. addTab[k.."|tab_temp"] = tab1
  105. for k2, v2 in pairs(tab1) do
  106. if string.find(v2, "#") then
  107. tab1[k2] = string.split(v2, "#")
  108. for k3, v3 in pairs(tab1[k2]) do
  109. if string.find(v3, "&") then
  110. tab1[k2][k3] = string.split(v3, "&")
  111. end
  112. end
  113. end
  114. end
  115. end
  116. end
  117. end
  118. for k, v in pairs(addTab) do
  119. data[k] = v
  120. end
  121. end
  122. function CodeDOMUIProxy:OpenGUIUI(data, json)
  123. if not data then
  124. return false
  125. end
  126. if json then
  127. data = cjson.decode(data)
  128. end
  129. self:GetSplitList(data)
  130. dump(data)
  131. local GUI_ID = data.GUI_ID
  132. local exportID = data.exportID
  133. local close = data.close
  134. -- 关闭界面
  135. if close then
  136. if GUI_ID then
  137. return GUI:Win_CloseByID(GUI_ID)
  138. end
  139. return GUI:Win_CloseAll()
  140. end
  141. if not GUI_ID then
  142. return false
  143. end
  144. if not exportID then
  145. return false
  146. end
  147. self._curUpdateData = self._txtUIData[tostring(GUI_ID)]
  148. if self._GUI_ID == GUI_ID and self._exportID == exportID then
  149. -- 更新UI
  150. local window = GUI:GetWindow(nil, GUI_ID)
  151. if window then
  152. data.parent = window
  153. return CodeDOMMainUI.UpdateGUIUI(data)
  154. end
  155. end
  156. self._GUI_ID = GUI_ID
  157. self._exportID = exportID
  158. SL:RequireFile("GUILayout/CodeDOMMainUI")
  159. CodeDOMMainUI.OpenGUIUI(data)
  160. end
  161. return CodeDOMUIProxy