KLEfficiencyNewPanel.lua 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. ---@class KLEfficiencyNewPanel:UIKmlLuaPanelBase
  2. ---@field view KLEfficiencyNewPanelView
  3. ---@field showTbls table<number,{group:number,name:string,bgImg:string,ids:table<number,number>}>
  4. ---@field nowData {group:number,name:string,bgImg:string,ids:table<number,number>}
  5. ---@field nowRewardCfgData cfg_efficiency_level_column
  6. local KLEfficiencyNewPanel = class(UIKmlLuaPanelBase)
  7. local this =KLEfficiencyNewPanel
  8. function this:AsyncLoadUI()
  9. end
  10. ---创建时调用一次
  11. function this:Init()
  12. self.isFirstOpenUI = false
  13. ---当前选中的数据
  14. self.nowData = nil
  15. ---所有页签的红点
  16. self.toggleRedPointList = {}
  17. self.toggleLevelList = {}
  18. SL.HideMainPanel()
  19. local tbl = SL:GetConfigTable("cfg_efficiency")
  20. self.showTbls = {}
  21. self.togIndex = nil
  22. local myLv = SL:GetMetaValue("LEVEL")
  23. local tempList = {}
  24. ---@param v cfg_efficiency_column
  25. for _, v in pairs(tbl) do
  26. if not tempList[v.group] then
  27. tempList[v.group] = {
  28. group = v.group,
  29. name = v.name,
  30. bgImg = v.backgroundImg,
  31. lv = v.level,
  32. ids = {v.id}
  33. }
  34. table.insert(self.showTbls, tempList[v.group])
  35. else
  36. table.insert(tempList[v.group].ids, v.id)
  37. end
  38. table.insert(self.toggleLevelList,v.level)
  39. end
  40. --跳转到指定页签
  41. if self.args and tempList[self.args] and myLv >= tempList[self.args].lv then
  42. self.isFirstOpenUI = true
  43. self.togIndex = self.args
  44. end
  45. GUI:DataListInitData(self.view.datalist, function()
  46. return table.count(self.showTbls)
  47. end,function()
  48. end,function()
  49. end,function(realIndex)
  50. local info = self.showTbls[realIndex+1]
  51. local rootCtrl = GUI:GetChildControl(self.view.datalist,realIndex,'root')
  52. GUI:SetActive(rootCtrl,myLv >= info.lv)
  53. local nameCtrl = GUI:GetChildControl(self.view.datalist,realIndex,'text_name')
  54. local togCtrl = GUI:GetChildControl(self.view.datalist,realIndex,'toggle')
  55. local togRed = GUI:GetChildControl(self.view.datalist,realIndex,'toggle_red')
  56. if not self.toggleRedPointList[info.group] then
  57. self.toggleRedPointList[info.group] = {info=info,image=togRed}
  58. end
  59. if self.togIndex and self.togIndex == info.group then
  60. self.nowData = info
  61. end
  62. GUI:Text_setString(nameCtrl, info.name)
  63. GUI:SetToggleGroup(togCtrl, self.view.togglegroup8)
  64. GUI:SetToggleOnValueChange(togCtrl, self, self.OnPageChange, info)
  65. if realIndex == 0 and not self.isFirstOpenUI then--第一次打开界面时默认选中第一个页签
  66. GUI:Toggle_setIsOn(togCtrl,true)
  67. self.isFirstOpenUI = true
  68. else
  69. if self.nowData and self.nowData.group == info.group then
  70. GUI:Toggle_setIsOn(togCtrl,true)
  71. end
  72. end
  73. end)
  74. GUI:DataListUpdateData(self.view.datalist)
  75. self:UpdateReward()
  76. end
  77. function this:OnPageChange(control, eventData, callBack)
  78. if callBack[1] then
  79. self.nowData = eventData
  80. ---是否需要点击发送保存红点消息给服务器
  81. local isReqSaveRed = InfoManager.uiEfficiencyNewInfo:GetToggleIsEfficiencyRedDot(self.nowData.group)
  82. if isReqSaveRed then
  83. SL:SendLuaNetMsg(LuaMessageIdToSever.REQ_SAVE_EFFECIENCY_RED_DOT,{type=1,group = self.nowData.group})
  84. end
  85. SL:SendLuaNetMsg(LuaMessageIdToSever.REQ_CHECK_EFFECIENCY_ACTIVE,self.nowData.ids)
  86. if eventData.group == 1 then
  87. GUI:setVisible(self.view.Multiplier, true)
  88. GUI:setVisible(self.view.Single, false)
  89. ---@type cfg_efficiency_column
  90. local left = SL:GetConfig("cfg_efficiency", eventData.ids[1])
  91. GUI:AddOnClickEvent(self.view.btn_left, self, function()
  92. GUI:UIPanel_Close(self.filePath)
  93. self:JumpUIPanel(left)
  94. end)
  95. if left.item[1] and left.item[1][1] then
  96. GUI:setVisible(self.view.model_left,true)
  97. GUI:Item_setItemId(self.view.model_left, left.item[1][1])
  98. GUI:Item_Scale(self.view.model_left,left.Scale)
  99. else
  100. GUI:setVisible(self.view.model_left,false)
  101. end
  102. GUI:Text_setString(self.view.text_left_num,left.text.."%")
  103. ---@type cfg_efficiency_column
  104. local up = SL:GetConfig("cfg_efficiency", eventData.ids[2])
  105. GUI:AddOnClickEvent(self.view.btn_up, self, function()
  106. GUI:UIPanel_Close(self.filePath)
  107. self:JumpUIPanel(up)
  108. end)
  109. if up.item[1] and up.item[1][1] then
  110. GUI:setVisible(self.view.model_up,true)
  111. GUI:Item_setItemId(self.view.model_up, up.item[1][1])
  112. GUI:Item_Scale(self.view.model_up,up.Scale)
  113. else
  114. GUI:setVisible(self.view.model_up,false)
  115. end
  116. GUI:Text_setString(self.view.text_up_num,up.text.."%")
  117. ---@type cfg_efficiency_column
  118. --[[local down = SL:GetConfig("cfg_efficiency", eventData.ids[3])
  119. GUI:AddOnClickEvent(self.view.btn_down, self, function()
  120. GUI:UIPanel_Close(self.filePath)
  121. self:JumpUIPanel(down)
  122. end)
  123. GUI:Item_UpdataData(self.view.model_down,
  124. {
  125. mfixsize = tostring(down.Scale)..","..tostring(down.Scale),
  126. itemid = down.item[1][1]
  127. })
  128. GUI:Text_setString(self.view.text_down_num,down.text.."%")--]]
  129. else
  130. GUI:setVisible(self.view.Multiplier, false)
  131. GUI:setVisible(self.view.Single, true)
  132. ---@type cfg_efficiency_column
  133. local tbl = SL:GetConfig("cfg_efficiency", eventData.ids[1])
  134. GUI:Image_loadTexture(self.view.img_info,"Texture/"..tbl.backgroundImg..".png","")
  135. end
  136. end
  137. end
  138. ---注册UI事件和服务器消息
  139. function this:RegistEvents()
  140. GUI:AddOnClickEvent(self.view.btn_go, self, self.OnGoClick)
  141. GUI:AddOnClickEvent(self.view.btn_close, self, self.CLoseSelf)
  142. GUI:AddOnClickEvent(self.view.item_reward, self, self.ReceiveReward)
  143. SL:RegisterLUAEvent(LUA_EFFICIENCY_RED_DOT_CHANGE, self.RefreshToggleRed, self)
  144. SL:RegisterLUAEvent(LUA_EFFICIENCY_TAB_ACTIVE_CHANGE, self.LUA_EFFICIENCY_TAB_ACTIVE_CHANGE, self)
  145. SL:RegisterLUAEvent(LUA_EVENT_LEVELCHANGE, self.LUA_EVENT_LEVELCHANGE, self)
  146. end
  147. function this:OnGoClick()
  148. if self.nowData then
  149. GUI:UIPanel_Close(self.filePath)
  150. ---@type cfg_efficiency_column
  151. local tbl = SL:GetConfig("cfg_efficiency", self.nowData.ids[1])
  152. self:JumpUIPanel(tbl)
  153. end
  154. end
  155. ---跳转界面
  156. ---@param tbl cfg_efficiency_column
  157. function this:JumpUIPanel(tbl)
  158. if not tbl.jumpCondition or tbl.jumpCondition == "" then--未配置的情况下直接跳转第一个配置的界面即可
  159. shortcutOutMgr.DO(tbl.Jump[1])
  160. SL.HideMainPanel()
  161. return
  162. end
  163. local jumpConditionList = string.split(tbl.jumpCondition,"|")
  164. local listCount = table.count(jumpConditionList)
  165. for i = 1, listCount do
  166. if ConditionManager.Check4D(jumpConditionList[i]) or jumpConditionList[i] == "" then--配置条件满足或者未配置即跳转对应配置的界面
  167. shortcutOutMgr.DO(tbl.Jump[i])
  168. SL.HideMainPanel()
  169. return
  170. end
  171. end
  172. if listCount > 0 and tbl.Jump[listCount + 1] then--前置条件都未满足且下一个条件未配置跳下个界面(例如配置的是:"103#100" 然后Jump配了2个跳转)
  173. shortcutOutMgr.DO(tbl.Jump[listCount + 1])
  174. SL.HideMainPanel()
  175. end
  176. end
  177. function this:CLoseSelf()
  178. GUI:UIPanel_Close(self.filePath)
  179. SL.ShowMainPanel()
  180. end
  181. function this:ReceiveReward()
  182. if not self.nowRewardCfgData then
  183. return
  184. end
  185. local myLv = SL:GetMetaValue("LEVEL")
  186. if self.nowRewardCfgData.level > myLv then
  187. SL:TipMessage( SL:GetConfig('cfg_string',249).text, 1, NoticeType.NoticeMid )--"等级不足",
  188. return
  189. end
  190. --TODO: 领取奖励协议
  191. SL:SendLuaNetMsg(LuaMessageIdToSever.REQ_GET_EFFECIENCY_REWARD,{id=self.nowRewardCfgData.id,type=2})
  192. end
  193. function this:UpdateReward()
  194. self.nowRewardCfgData = nil
  195. local nowId = InfoManager.uiEfficiencyNewInfo:GetNowRewardCfgId()
  196. --有服务器数据的时候直接拿服务器id获取表数据
  197. if nowId and SL:HasConfig("cfg_efficiency_level",nowId) then
  198. self.nowRewardCfgData = SL:GetConfig("cfg_efficiency_level",nowId)
  199. end
  200. self:ShowRewardInfo()
  201. end
  202. ---显示奖励信息
  203. function this:ShowRewardInfo()
  204. if not self.nowRewardCfgData then
  205. GUI:setVisible(self.view.item_reward, false)
  206. return
  207. end
  208. local myLv = SL:GetMetaValue("LEVEL")
  209. local myCareer = SL:GetMetaValue(EMetaVarGetKey.JOB)
  210. local v = self.nowRewardCfgData
  211. GUI:setVisible(self.view.item_reward, true)
  212. GUI:Text_setString(self.view.text_limit, string.format("达到%d级可领", v.level))
  213. GUI:Text_setTextColor(self.view.text_limit,v.level <= myLv and EColor[EGradColor.green] or EColor[EGradColor.red])
  214. GUI:SetActive(self.view.item_reward_red,v.level <= myLv)
  215. for _, d in pairs(v.item) do
  216. if d[1] == myCareer then
  217. GUI:Item_UpdataData(self.view.item_reward, {itemid = d[2], itemcount=d[3]})
  218. break
  219. end
  220. end
  221. end
  222. ---刷新页签红点
  223. function this:RefreshToggleRed()
  224. for i, v in ipairs(self.toggleRedPointList) do
  225. local isShow = InfoManager.uiEfficiencyNewInfo:GetToggleIsEfficiencyRedDot(v.info.group)
  226. GUI:SetActive(v.image,isShow)
  227. end
  228. self:UpdateReward()
  229. end
  230. ---激活信息刷新
  231. function this:LUA_EFFICIENCY_TAB_ACTIVE_CHANGE(_,message)
  232. if self.nowData then
  233. self:RefreshTabActiveInfo()
  234. end
  235. end
  236. ---刷新激活信息页面
  237. function this:RefreshTabActiveInfo()
  238. local list = InfoManager.uiEfficiencyNewInfo:GetEfficiencyTabActiveInfo()
  239. if self.nowData.group == 1 then
  240. local leftIsActive = table.contains(list,self.nowData.ids[1])
  241. GUI:SetActive(self.view.btn_left,not leftIsActive)
  242. GUI:SetActive(self.view.img_state_left,leftIsActive)
  243. local upIsActive = table.contains(list,self.nowData.ids[2])
  244. GUI:SetActive(self.view.btn_up,not upIsActive)
  245. GUI:SetActive(self.view.img_state_up,upIsActive)
  246. local downIsActive = table.contains(list,self.nowData.ids[3])
  247. GUI:SetActive(self.view.btn_down,not downIsActive)
  248. GUI:SetActive(self.view.img_state_down,downIsActive)
  249. else
  250. local isActive = table.contains(list,self.nowData.ids[1])
  251. GUI:SetActive(self.view.btn_go,not isActive)
  252. GUI:SetActive(self.view.Single_active,isActive)
  253. end
  254. end
  255. ---等级改变
  256. function this:LUA_EVENT_LEVELCHANGE(id,level)
  257. GUI:DataListUpdateData(self.view.datalist)
  258. end
  259. ---界面显示时调用一次
  260. function this:Show()
  261. end
  262. ---创建或者刷新界面数据时调用
  263. function this:Refresh()
  264. self:RefreshToggleRed()
  265. end
  266. function this:Close()
  267. end
  268. return this