KLMountStorePanel.lua 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. ---@class KLMountStorePanel:UIKmlLuaPanelBase
  2. ---@field view KLMountStorePanelView
  3. local KLMountStorePanel = class(UIKmlLuaPanelBase)
  4. local this =KLMountStorePanel
  5. ---创建时调用一次
  6. function this:Init()
  7. self.mountAttItemList = {}
  8. self.mountInfo_all_item = {}
  9. self.mountInfoData = {}
  10. GUI:DataListInitData(self.view.mount_all_info_list,function()
  11. return self:MountDataListItemCountFunc()
  12. end,function(realIndex)
  13. return self:MountDataListItemGetFunc(realIndex)
  14. end,function(realIndex, kmlcontrol)
  15. return self:MountDataListItemInitFunc(realIndex, kmlcontrol)
  16. end, function(realIndex, kmlcontrol)
  17. return self:MountDataListItemUpdateFunc(realIndex, kmlcontrol)
  18. end)
  19. end
  20. ---创建或者刷新界面数据时调用
  21. function this:Refresh()
  22. SL.HideMainPanel()
  23. SL:SendLuaNetMsg(LuaMessageIdToSever.REQ_ALL_MOUNT_INFO)
  24. end
  25. ---注册UI事件和服务器消息
  26. function this:RegistEvents()
  27. GUI:AddOnClickEvent(self.view.closeBtn,self,self.OnClickCloseBtn)
  28. --GUI:AddOnClickEvent(self.view.expandBtn,self,self.OnClickExpandBtn)
  29. --GUI:AddOnClickEvent(self.view.foldBtn,self,self.OnClickFoldBtn)
  30. SL:RegisterLuaNetMsg(LuaMessageIdToClient.RES_ALL_MOUNT_INFO,self.RES_ALL_MOUNT_INFO,self)
  31. SL:RegisterLuaNetMsg(LuaMessageIdToClient.RES_ALL_MOUNT_ATT_INFO,self.RES_ALL_MOUNT_ATT_INFO,self)
  32. SL:RegisterLuaNetMsg(LuaMessageIdToClient.RES_RIDING_MOUNT,self.RES_RIDING_MOUNT,self)
  33. SL:RegisterLuaNetMsg(LuaMessageIdToClient.RES_CANCEL_RIDING_MOUNT,self.RES_CANCEL_RIDING_MOUNT,self)
  34. end
  35. function this:OnClickCloseBtn()
  36. GUI:UIPanel_Close("dev/outui/Mount/Panel/KLMountEquip/KLMountEquipPanel")
  37. GUI:UIPanel_Close("dev/outui/Mount/Panel/KLMountStore/KLMountStorePanel")
  38. GUI:UIPanel_Close("dev/outui/Mount/Panel/KLMountDisplay/KLMountDisplayPanel")
  39. end
  40. function this:OnClickExpandBtn()
  41. GUI:setVisible(self.view.attInfoRoot,true)
  42. GUI:setVisible(self.view.expandBtn,false)
  43. GUI:setVisible(self.view.foldBtn,true)
  44. local y = 50 - #self.attTxtList*38
  45. GUI:setPositionY(self.view.btnRoot,y)
  46. y = -130 - #self.attTxtList*38
  47. GUI:setPositionY(self.view.mountInfoRoot,y)
  48. local h = 600 - #self.attTxtList*38
  49. GUI:setContentSize(self.view.mount_info_scrollview,256,h)
  50. end
  51. function this:OnClickFoldBtn()
  52. GUI:setVisible(self.view.attInfoRoot,false)
  53. GUI:setVisible(self.view.expandBtn,true)
  54. GUI:setVisible(self.view.foldBtn,false)
  55. GUI:setPositionY(self.view.btnRoot,50)
  56. GUI:setPositionY(self.view.mountInfoRoot,-120)
  57. GUI:setContentSize(self.view.mount_info_scrollview,256,600)
  58. end
  59. function this:RES_ALL_MOUNT_INFO(id,message)
  60. self:RefreshMountInfoList(message)
  61. end
  62. function this:RES_ALL_MOUNT_ATT_INFO(id,message)
  63. self:RefreshAttInfoList(message)
  64. --local isVisible = GUI:getVisible(self.view.attInfoRoot)
  65. --local y = isVisible and (50 - #self.attTxtList*38) or 50
  66. --GUI:setPositionY(self.view.btnRoot,y)
  67. --y = isVisible and (-130 - #self.attTxtList*38) or -130
  68. --GUI:setPositionY(self.view.mountInfoRoot,y)
  69. --local h = isVisible and (600 - #self.attTxtList*38) or 600
  70. --GUI:setContentSize(self.view.mount_info_scrollview,256,h)
  71. end
  72. function this:RES_RIDING_MOUNT(id,message)
  73. for i, v in pairs(self.mountInfoData) do
  74. v.isWear = self.curSelectIndex == i
  75. end
  76. self.wearIndex = self.curSelectIndex
  77. GUI:DataListUpdateData(self.view.mount_all_info_list)
  78. end
  79. function this:RES_CANCEL_RIDING_MOUNT(id,message)
  80. for i, v in pairs(self.mountInfoData) do
  81. v.isWear = false
  82. end
  83. self.wearIndex = -1
  84. GUI:DataListUpdateData(self.view.mount_all_info_list)
  85. end
  86. function this:SelectMount(mountId,index)
  87. if self.curSelectIndex == index then return end
  88. self.curSelectMount = mountId
  89. self.curSelectIndex = index
  90. ---@type cfg_mount_column
  91. local tbl = SL:GetConfig("cfg_mount",mountId,"id")
  92. ---@type KLMountDisplayPanel
  93. local panel = GUI:GetUI("dev/outui/Mount/Panel/KLMountDisplay/KLMountDisplayPanel")
  94. if panel and panel:GetVisible() then
  95. panel.args.mountId = self.curSelectMount
  96. panel.args.isWear = self.wearIndex == self.curSelectIndex
  97. panel.args.auto = self.mountInfoData[index].auto
  98. panel:Refresh()
  99. elseif tbl.mountEquip == 1 then
  100. panel = GUI:GetUI("dev/outui/Mount/Panel/KLMountEquip/KLMountEquipPanel")
  101. if panel and panel:GetVisible() then
  102. panel.args.mountId = self.curSelectMount
  103. panel:Refresh()
  104. end
  105. end
  106. end
  107. function this:RefreshAttInfoList(attribute)
  108. local attInfo = {}
  109. self.attTxtList = {}
  110. for i, v in pairs(self.mountAttItemList) do
  111. GUI:UIPanel_Close(nil,v)
  112. end
  113. table.clear(self.mountAttItemList)
  114. for i, v in pairs(attribute) do
  115. local isSkip = false
  116. local attId = tonumber(i)
  117. local attNum = v
  118. ---@type cfg_att_info_column
  119. local tbl = SL:GetConfig("cfg_att_info",attId,"id")
  120. local attTxt
  121. if tbl.remarks ~= EAttrRemarkType.Number then
  122. attTxt = attNum/100 .."%"
  123. else
  124. attTxt = attNum
  125. end
  126. if attId == 200011 then--最小
  127. attInfo[1] = "攻击力#"..attTxt.."~"
  128. elseif attId == 200021 then--最大
  129. attInfo[2] = attTxt
  130. elseif attId == 202021 then--最小
  131. attInfo[3] = "魔法攻击力#"..attTxt.."~"
  132. elseif attId == 202011 then--最大
  133. attInfo[4] = attTxt
  134. elseif attId == 205011 then--最小
  135. attInfo[5] = "诅咒攻击力#"..attTxt.."~"
  136. elseif attId == 205021 then--最大
  137. attInfo[6] = attTxt
  138. else
  139. attTxt = tbl.name.."#" ..attTxt
  140. table.insert(self.attTxtList,attTxt)
  141. isSkip = true
  142. end
  143. if not isSkip then
  144. if attInfo[1] and attInfo[2] then
  145. table.insert(self.attTxtList,attInfo[1]..attInfo[2])
  146. attInfo[1] = nil
  147. attInfo[2] = nil
  148. elseif attInfo[3] and attInfo[4] then
  149. table.insert(self.attTxtList,attInfo[3]..attInfo[4])
  150. attInfo[3] = nil
  151. attInfo[4] = nil
  152. elseif attInfo[5] and attInfo[6] then
  153. table.insert(self.attTxtList,attInfo[5]..attInfo[6])
  154. attInfo[5] = nil
  155. attInfo[6] = nil
  156. end
  157. end
  158. end
  159. for i = 1, #self.attTxtList do
  160. local panel = GUI:UIPanel_Open("dev/outui/Mount/Item/KLMountAttInfo/KLMountAttInfoItem",self.view.att_list,self,{width=250,attInfo=self.attTxtList[i]},true)
  161. table.insert(self.mountAttItemList,panel)
  162. end
  163. end
  164. function this:RefreshMountInfoList(mountInfoList)
  165. self.mountInfoData = {}
  166. self.curSelectMount = -1
  167. self.curSelectIndex = -1
  168. local index = 1
  169. local mountEquipList = {}
  170. for i, v in pairs(mountInfoList) do
  171. local isWear = v.wear == 1
  172. local mountId = v.mountcfgid
  173. ---@type cfg_mount_column
  174. local tbl = SL:GetConfig("cfg_mount",mountId,"id")
  175. if isWear then
  176. self.wearIndex = index
  177. end
  178. if index == 1 then
  179. self.curSelectMount = mountId
  180. self.curSelectIndex = 1
  181. end
  182. local data = {index=index,mountId=mountId,mountName=tbl.name,itemCfgId=tbl.itemId,isWear=isWear,auto = v.auto == 1,endTime= v.time and tonumber(v.time) or 0}
  183. if tbl.mountEquip == 1 then
  184. table.insert(mountEquipList,data)
  185. end
  186. table.insert(self.mountInfoData,data)
  187. index = index + 1
  188. end
  189. local panel = GUI:GetUI("dev/outui/Mount/Panel/KLMountEquip/KLMountEquipPanel")
  190. if panel and panel:GetVisible() and #mountEquipList>0 then
  191. self.mountInfoData = mountEquipList
  192. for i, v in pairs(mountEquipList) do
  193. if v.isWear then
  194. self.wearIndex = i
  195. end
  196. if i == 1 then
  197. self.curSelectMount = v.mountId
  198. self.curSelectIndex = 1
  199. end
  200. end
  201. end
  202. local panel = GUI:GetUI("dev/outui/Mount/Panel/KLMountEquip/KLMountEquipPanel")
  203. if panel and panel:GetVisible() and #mountEquipList > 0 then
  204. panel.args.mountId = self.curSelectMount
  205. panel:Refresh()
  206. else
  207. local isSkip = false
  208. if panel then
  209. GUI:UIPanel_Close("dev/outui/Mount/Panel/KLMountEquip/KLMountEquipPanel")
  210. SL.ShowMainPanel()
  211. isSkip = true
  212. end
  213. local data = {mountId=self.curSelectMount,isWear = self.wearIndex == self.curSelectIndex}
  214. data.auto = self.mountInfoData[self.curSelectIndex] and self.mountInfoData[self.curSelectIndex].auto or false
  215. ---@type KLMountDisplayPanel
  216. panel = GUI:GetUI("dev/outui/Mount/Panel/KLMountDisplay/KLMountDisplayPanel")
  217. if not panel then
  218. GUI:UIPanel_Open("dev/outui/Mount/Panel/KLMountDisplay/KLMountDisplayPanel",nil,nil,data)
  219. elseif panel:GetVisible() or isSkip then
  220. panel.args = data
  221. panel:SetVisible(true)
  222. panel:Refresh()
  223. end
  224. end
  225. local count = #self.mountInfoData
  226. GUI:DataListUpdateData(self.view.mount_all_info_list)
  227. GUI:setVisible(self.view.attInfoRoot,count > 0)
  228. --GUI:setVisible(self.view.btnRoot,count > 0)
  229. GUI:setVisible(self.view.onMount,count == 0)
  230. GUI:setVisible(self.view.mountInfoRoot,count > 0)
  231. end
  232. function this:MountDataListItemCountFunc()
  233. return #self.mountInfoData
  234. end
  235. function this:MountDataListItemGetFunc(realIndex)
  236. local data = self.mountInfoData[realIndex + 1]
  237. data.index = realIndex + 1
  238. local item = GUI:UIPanel_Open("dev/outui/Mount/Item/KLMountInfo/KLMountInfoItem",self.view.mount_all_info_list,self,data,true)
  239. self.mountInfo_all_item[item.view.root] = item
  240. return item.view.root
  241. end
  242. function this:MountDataListItemInitFunc(realIndex, kmlcontrol)
  243. end
  244. function this:MountDataListItemUpdateFunc(realIndex, kmlcontrol)
  245. local data = self.mountInfoData[realIndex + 1]
  246. self.mountInfo_all_item[kmlcontrol].args = data
  247. self.mountInfo_all_item[kmlcontrol]:Refresh()
  248. end
  249. function this:SetVisible(isVisible)
  250. if isVisible then
  251. SL:SendLuaNetMsg(LuaMessageIdToSever.REQ_ALL_MOUNT_INFO)
  252. end
  253. GUI:setVisible(self.view.root,isVisible)
  254. end
  255. function this:Close()
  256. self.mountAttItemList = {}
  257. SL.ShowMainPanel()
  258. end
  259. return this