KLBoxPrivilegePanel.lua 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. ---@class KLBoxPrivilegePanel:UIKmlLuaPanelBase
  2. ---@field view KLBoxPrivilegePanelView
  3. ---@field cfgId
  4. ---@field currentTab
  5. local KLBoxPrivilegePanel = class(UIKmlLuaPanelBase)
  6. local this = KLBoxPrivilegePanel
  7. BoxPrivilegeBtnType = {
  8. Activate = enum(),
  9. Receive = enum(),
  10. Gray = enum()
  11. }
  12. function this:AsyncLoadUI()
  13. end
  14. ---创建时调用一次
  15. function this:Init()
  16. SL.HideMainPanel()
  17. self.tbl = self:LoadData()
  18. self.toggleList = {}
  19. --table.sort(self.tbl, function(a, b)
  20. -- return a.tab < b.tab
  21. --end)
  22. self.currentTab = EBoxPrivilege.Privilege
  23. end
  24. ---注册UI事件和服务器消息
  25. function this:RegistEvents()
  26. GUI:AddOnClickEvent(self.view.close, self, self.ClosePanel)
  27. GUI:AddOnClickEvent(self.view.privilege_btn, self, self.PrivilegeBtn)
  28. GUI:AddOnClickEvent(self.view.DownLoad, self, self.DownLoadBtn)
  29. SL:RegisterLUAEvent(LUA_EVENT_MUBOX_INFO,self.ResMuBoxInfoMessage,self)
  30. end
  31. ---界面显示时调用一次
  32. function this:Show()
  33. end
  34. ---创建或者刷新界面数据时调用
  35. function this:Refresh()
  36. self.dataList = {}
  37. self.btnType = BoxPrivilegeBtnType.Activate
  38. GUI:DataListInitData(self.view.toggle_list, function()
  39. return #self.tbl
  40. end, function(realIndex)
  41. return self:ItemGet(realIndex)
  42. end, function(realIndex, kmlCtrl)
  43. end, function(realIndex, kmlCtrl)
  44. return self:ToggleListUpdateFunc(realIndex, kmlCtrl)
  45. end)
  46. GUI:DataListUpdateData(self.view.toggle_list)
  47. GUI:DataListInitData(self.view.att_list, function()
  48. return #self.dataList
  49. end, function(realIndex)
  50. end, function(realIndex, kmlCtrl)
  51. end, function(realIndex, kmlCtrl)
  52. return self:AttListUpdateFunc(realIndex, kmlCtrl)
  53. end)
  54. GUI:DataListInitData(self.view.item_list, function()
  55. return #self.dataList
  56. end, function(realIndex)
  57. end, function(realIndex, kmlCtrl)
  58. end, function(realIndex, kmlCtrl)
  59. return self:ItemListUpdateFunc(realIndex, kmlCtrl)
  60. end)
  61. GUI:DataListInitData(self.view.appellation_list, function()
  62. return #self.appellation
  63. end, function(realIndex)
  64. end, function(realIndex, kmlCtrl)
  65. end, function(realIndex, kmlCtrl)
  66. return self:AppellationItem(realIndex, kmlCtrl)
  67. end)
  68. for _, v in pairs(self.toggleList) do
  69. v:InitUI(self.currentTab)
  70. end
  71. end
  72. function this:TogglePrivilegeOnValueChange(c, control)
  73. if c[1] then
  74. self.dataList = {}
  75. local tbls = self.tbl[EBoxPrivilege.Privilege]
  76. --local tbl = tbls[1]
  77. self.cfgId = tbls[1].id
  78. self.currentTab = EBoxPrivilege.Privilege
  79. GUI:Text_setString(self.view.tip, tbls[1].text)
  80. for i, tbl in pairs(tbls) do
  81. if tbl.type == 1 then
  82. for _, v in pairs(tbl.param) do
  83. for _, k in pairs(v) do
  84. local buffName = SL:GetConfig("cfg_buff", k, "id").buffName
  85. buffName = string.split(buffName, "+")
  86. buffName = buffName[1] .. "<color='#24FF00'>+" .. buffName[2] .. "</color>"
  87. table.insert(self.dataList, buffName)
  88. end
  89. end
  90. elseif tbl.type == 3 then
  91. self.appellation = tbl.param
  92. GUI:DataListUpdateData(self.view.appellation_list)
  93. end
  94. end
  95. --for _, v in pairs(tbl.param) do
  96. -- for _, k in pairs(v) do
  97. -- local buffName = SL:GetConfig("cfg_buff", k, "id").buffName
  98. -- buffName = string.split(buffName, "+")
  99. -- buffName = buffName[1] .. "<color='#24FF00'>+" .. buffName[2] .. "</color>"
  100. -- table.insert(self.dataList, buffName)
  101. -- end
  102. --end
  103. if not SL:GetMetaValue(EMetaVarGetKey.GET_BOX_PRIVILEGE) then
  104. GUI:setVisible(self.view.privilege_btn)
  105. GUI:Button_setGrey(self.view.privilege_btn, false)
  106. GUI:Button_setTitleText(self.view.privilege_btn, "获取特权")
  107. self.btnType = BoxPrivilegeBtnType.Activate
  108. GUI:Text_setString(self.view.activate_text, "<color=#FF0000>未激活</color>")
  109. else
  110. GUI:setVisible(self.view.privilege_btn, false)
  111. GUI:Text_setString(self.view.activate_text, "<color=#00FF00>已激活</color>")
  112. end
  113. GUI:DataListUpdateData(self.view.att_list)
  114. end
  115. GUI:setVisible(control, c[1])
  116. GUI:setVisible(self.view.panel_1, c[1])
  117. end
  118. function this:ToggleItemsOnValueChange(c, control)
  119. if c[1] then
  120. self.dataList = {}
  121. local tbl = self.tbl[EBoxPrivilege.DayGift][1]
  122. self.currentTab = EBoxPrivilege.DayGift
  123. self.cfgId = tbl.id
  124. GUI:Text_setString(self.view.tip, tbl.text)
  125. for i, v in pairs(tbl.param) do
  126. table.insert(self.dataList, v)
  127. end
  128. if not SL:GetMetaValue(EMetaVarGetKey.GET_BOX_PRIVILEGE) then
  129. GUI:setVisible(self.view.privilege_btn)
  130. GUI:Button_setGrey(self.view.privilege_btn, false)
  131. GUI:Button_setTitleText(self.view.privilege_btn, "获取特权")
  132. self.btnType = BoxPrivilegeBtnType.Activate
  133. elseif SL:GetMetaValue(EMetaVarGetKey.GET_BOX_DAILY_GIFT) then
  134. GUI:setVisible(self.view.privilege_btn, true)
  135. GUI:Button_setTitleText(self.view.privilege_btn, "已领取")
  136. GUI:Button_setGrey(self.view.privilege_btn, true)
  137. self.btnType = BoxPrivilegeBtnType.Gray
  138. else
  139. GUI:setVisible(self.view.privilege_btn, true)
  140. GUI:Button_setGrey(self.view.privilege_btn, false)
  141. GUI:Button_setTitleText(self.view.privilege_btn, "领取奖励")
  142. self.btnType = BoxPrivilegeBtnType.Receive
  143. end
  144. GUI:DataListUpdateData(self.view.item_list)
  145. end
  146. GUI:setVisible(control, c[1])
  147. GUI:setVisible(self.view.panel_2, c[1])
  148. end
  149. function this:AttListUpdateFunc(realIndex, kmlCtrl)
  150. --local att_text = self.view.att_list:GetChildControl(realIndex, "att_text")
  151. local att_text = GUI:GetChildControl(self.view.att_list,realIndex, "att_text")
  152. GUI:Text_setString(att_text, self.dataList[realIndex + 1])
  153. end
  154. function this:ItemListUpdateFunc(realIndex, kmlCtrl)
  155. --local item_show = self.view.item_list:GetChildControl(realIndex, "item_show")
  156. local item_show = GUI:GetChildControl(self.view.item_list,realIndex, "item_show")
  157. GUI:Item_UpdataData(item_show, {
  158. itemid = self.dataList[realIndex + 1][1],
  159. itemcount = self.dataList[realIndex + 1][2]
  160. })
  161. GUI:AddOnClickEvent(item_show, self, function()
  162. SL:OpenTips(_, self.dataList[realIndex + 1][1])
  163. end)
  164. end
  165. function this:ItemGet(realIndex)
  166. local item = GUI:UIPanel_Open("dev/ui/MiracleBox/Item/KLBoxPrivilege/KLBoxPrivilegeItem", self.view.toggle_list, self, { tbl = self.tbl[realIndex + 1], toggle_group = self.view.toggle_group })
  167. table.insert(self.toggleList, item)
  168. end
  169. function this:ToggleListUpdateFunc(realIndex, kmlCtrl)
  170. --local toggle = self.view.toggle_list:GetChildControl(realIndex, "toggle_privilege")
  171. local toggle = GUI:GetChildControl(self.view.toggle_list,realIndex, "toggle_privilege")
  172. GUI:SetToggleGroup(toggle, self.view.toggle_group)
  173. end
  174. function this:AppellationItem(realIndex, kmlCtrl)
  175. local data = self.appellation[realIndex + 1]
  176. --local img = self.view.appellation_list:GetChildControl(realIndex, "appellation_item")
  177. local img = GUI:GetChildControl(self.view.appellation_list,realIndex, "appellation_item")
  178. local itemTbl = SL:GetConfig("cfg_item", data[1],"id")
  179. local modelTbl = SL:GetConfig('cfg_model_charactor', itemTbl.shape[1])
  180. GUI:Image_loadTexture(img, modelTbl.path ..".png")
  181. end
  182. function this:PrivilegeBtn()
  183. if self.btnType == BoxPrivilegeBtnType.Activate then
  184. self:DownLoadBtn()
  185. elseif self.btnType == BoxPrivilegeBtnType.Receive then
  186. SL:ReqReceivePrivilegeGiftMessage(self.cfgId)
  187. end
  188. end
  189. function this:ResMuBoxInfoMessage()
  190. self:Refresh()
  191. end
  192. --[[ "eventCode": "promotion_click",
  193. "accountId":3,//用户ID选传
  194. "deviceId": "64b95elc-1fb8-448d-9753-00e9f42f3c1c"
  195. "appVersion": "3.0",
  196. "channelCode": "CHL16312522075640003",
  197. channelName":
  198. "deviceType":"
  199. "华为",
  200. "eventTime": 1729667795000,
  201. "moduleId": "download_app_button",
  202. "moduleName":"游戏中下载app按钮",
  203. "eventAttribute": {
  204. "deviceVersion": "17406"
  205. ]]--
  206. function this:DownLoadBtn()
  207. local appId = 3
  208. if SL:GetMetaValue(EMetaVarGetKey.PLATFORM_ANDROID) then
  209. appId = 1
  210. elseif SL:GetMetaValue(EMetaVarGetKey.PLATFORM_IOS) then
  211. appId = 2
  212. end
  213. local channelCode = SL:GetMetaValue(EMetaVarGetKey.GAME_ID)
  214. if string.isNullOrEmpty(channelCode) then
  215. channelCode = "TEST712712712712TEST"
  216. end
  217. local verData = SL:GetMetaValue("CS_MAIN_VERSION_DATA")
  218. local data = {
  219. eventCode = "promotion_click", -- 事件ID,固定写死
  220. accountId = SL:GetMetaValue(EMetaVarGetKey.MAIN_ACTOR_ID), -- 用户ID 可为空
  221. deviceId = SL:GetMetaValue(EMetaVarGetKey.DEVICE_ID), -- 设备标识/设备唯一编号
  222. appVersion = tostring(verData and verData.clientVersion or "1"), --版本名称 PACKAGE_NAME
  223. appId = appId,
  224. channelCode = channelCode, -- 游戏ID
  225. channelName = "玄武奇迹", --渠道名/游戏名称
  226. deviceType = SL:GetMetaValue(EMetaVarGetKey.DEVICE_TYPE), --设备类型 如:SM_G9730
  227. eventTime = SL:GetMetaValue(EMetaVarGetKey.SERVER_TIME) / 1000, --时间戳
  228. deviceVersion = SL:GetMetaValue(EMetaVarGetKey.DEVICE_VERSION), --设备版本 SystemInfo.operatingSystem
  229. moduleId = "download_app_button", --游戏中下载按钮id 固定写死
  230. moduleName = "游戏中下载app按钮"--游戏中下载按钮名称 固定写死
  231. }
  232. local json = SL:JsonEncode(data, false)
  233. local head = SL:CreateCSDictionary()
  234. head:Add("Content-Type", "application/json")
  235. SL:HTTPRequestPost("http://api712.hzpt712.chenjwl.com/api/analyticApp/appApi/event/single/event/report", function(_, message)
  236. if message then
  237. if SL:GetMetaValue(EMetaVarGetKey.PLATFORM_ANDROID) then
  238. SL:OpenURL(SL:GetConfig("cfg_global", 900, "id").value)
  239. elseif SL:GetMetaValue(EMetaVarGetKey.PLATFORM_IOS) then
  240. SL:OpenURL(SL:GetConfig("cfg_global", 901, "id").value)
  241. else
  242. SL:OpenURL(SL:GetConfig("cfg_global", 900, "id").value)
  243. end
  244. end
  245. end, json, head)
  246. end
  247. function this:ClosePanel()
  248. GUI:UIPanel_Close("dev/ui/MiracleBox/Panel/KLBoxPrivilege/KLBoxPrivilegePanel")
  249. end
  250. function this:Close()
  251. SL.ShowMainPanel()
  252. end
  253. function this:LoadData()
  254. local info = {}
  255. local data = SL:GetConfigTable("cfg_box")
  256. for i, v in pairs(data) do
  257. if not info[v.tab] then
  258. info[v.tab] = {}
  259. end
  260. table.insert(info[v.tab], v)
  261. end
  262. return info
  263. end
  264. return this