KLMountEquipPanel.lua 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. ---@class KLMountEquipPanel:UIKmlLuaPanelBase
  2. ---@field view KLMountEquipPanelView
  3. local KLMountEquipPanel = class(UIKmlLuaPanelBase)
  4. local this =KLMountEquipPanel
  5. ---创建时调用一次
  6. function this:Init()
  7. self.equipItemData = {}
  8. self.selectEquipPos = nil
  9. end
  10. ---注册UI事件和服务器消息
  11. function this:RegistEvents()
  12. GUI:AddOnClickEvent(self.view.closeBtn,self,self.OnClickCloseBtn)
  13. GUI:AddOnClickEvent(self.view.closeBtn2,self,self.OnClickClose2Btn)
  14. GUI:AddOnClickEvent(self.view.desBtn,self,self.OnClickDesBtn)
  15. GUI:AddOnClickEvent(self.view.pos51,self,self.OnClickEquipPosBtn,EMountEquipPos.HeadPos)
  16. GUI:AddOnClickEvent(self.view.pos52,self,self.OnClickEquipPosBtn,EMountEquipPos.NecklancePos)
  17. GUI:AddOnClickEvent(self.view.pos53,self,self.OnClickEquipPosBtn,EMountEquipPos.FrontLegPos)
  18. GUI:AddOnClickEvent(self.view.pos54,self,self.OnClickEquipPosBtn,EMountEquipPos.HindLegPos)
  19. GUI:AddOnClickEvent(self.view.pos55,self,self.OnClickEquipPosBtn,EMountEquipPos.TailPos)
  20. GUI:SetToggleOnValueChange(self.view.mountInfoToggle,self,self.OnValueChangeMountInfoToggle)
  21. GUI:SetToggleOnValueChange(self.view.mountEquipToggle,self,self.OnValueChangeMountEquipToggle)
  22. SL:RegisterLuaNetMsg(LuaMessageIdToClient.RES_MOUNT_DETAIL_INFO,self.RES_MOUNT_DETAIL_INFO,self)
  23. SL:RegisterLuaNetMsg(LuaMessageIdToClient.RES_MOUNT_TAKE_OFF_ITEM,self.RES_MOUNT_TAKE_OFF_ITEM,self)
  24. end
  25. function this:OnClickCloseBtn()
  26. GUI:UIPanel_Close("dev/outui/Mount/Panel/KLMountEquip/KLMountEquipPanel")
  27. GUI:UIPanel_Close("dev/outui/Mount/Panel/KLMountStore/KLMountStorePanel")
  28. GUI:UIPanel_Close("dev/outui/Mount/Panel/KLMountDisplay/KLMountDisplayPanel")
  29. end
  30. function this:OnClickClose2Btn()
  31. ---@type KLMountStorePanel
  32. local panel = GUI:GetUI("dev/outui/Mount/Panel/KLMountStore/KLMountStorePanel")
  33. if panel then
  34. panel:SetVisible(true)
  35. end
  36. GUI:setVisible(self.view.bagItemRoot,false)
  37. end
  38. function this:OnClickDesBtn()
  39. GUI:UIPanel_Open("dev/outui/Mount/Panel/KLMountDes/KLMountDesPanel")
  40. end
  41. function this:OnClickEquipPosBtn(control,pos)
  42. self.selectEquipPos = pos
  43. if not self.equipItemData[pos] then
  44. self:ShowItem()
  45. ---@type KLMountStorePanel
  46. local panel = GUI:GetUI("dev/outui/Mount/Panel/KLMountStore/KLMountStorePanel")
  47. if panel then
  48. panel:SetVisible(false)
  49. end
  50. SL.HideMainPanel()
  51. else
  52. GUI:UIPanel_Open("dev/ui/Tips/Panel/KLUIEquipTips/KLUIEquipTipsPanel", nil, nil, { mountId = self.args.mountId,equip_pos = "equip", cfgId = self.equipItemData[pos].itemcfgid, id = self.equipItemData[pos].itemid })
  53. end
  54. end
  55. function this:OnValueChangeMountInfoToggle(_,_,data)
  56. local isToggle = data[1]
  57. if isToggle then
  58. ---@type KLMountDisplayPanel
  59. local panel = GUI:GetUI("dev/outui/Mount/Panel/KLMountDisplay/KLMountDisplayPanel")
  60. if panel then
  61. panel:SetVisible(true)
  62. end
  63. ---@type KLMountStorePanel
  64. panel = GUI:GetUI("dev/outui/Mount/Panel/KLMountStore/KLMountStorePanel")
  65. if panel then
  66. panel:SetVisible(true)
  67. end
  68. self:SetVisible(false)
  69. end
  70. end
  71. function this:OnValueChangeMountEquipToggle(_,_,data)
  72. end
  73. function this:RES_MOUNT_DETAIL_INFO(id,message)
  74. local isVisible = GUI:getVisible(self.view.bagItemRoot)
  75. if isVisible then
  76. self:ShowItem()
  77. end
  78. self:ShowMountEquip(message.item)
  79. end
  80. function this:RES_MOUNT_TAKE_OFF_ITEM(id,message)
  81. local isVisible = GUI:getVisible(self.view.bagItemRoot)
  82. if isVisible then
  83. self:ShowItem()
  84. end
  85. end
  86. ---创建或者刷新界面数据时调用
  87. function this:Refresh()
  88. SL.HideMainPanel()
  89. SL:SendLuaNetMsg(LuaMessageIdToSever.REQ_MOUNT_DETAIL_INFO,{self.args.mountId})
  90. GUI:setVisible(self.view.ownerMountRoot,self.args.mountId~=-1)
  91. GUI:setVisible(self.view.bagItemRoot,false)
  92. if self.args.mountId~=-1 then
  93. ---@type cfg_mount_column
  94. local tbl = SL:GetConfig("cfg_mount",self.args.mountId,"id")
  95. ---@type cfg_mount_model_column
  96. local mount_model_tbl = SL:GetConfig("cfg_mount_model",tbl.mountId,"id")
  97. ---@type cfg_mount_behaviour_column
  98. local behaviour_tbl = SL:GetConfigMultiKeys("cfg_mount_behaviour",tbl.motion,1,"id","state")
  99. self.view.model.kmlControl:HideAllChilds()
  100. self.cur_mount_model = GUI:Model_Create(self.view.model,{
  101. id="cur_mount_model",
  102. mscale=tbl.scale2.. ",".. tbl.scale2 ..",".. tbl.scale2,
  103. mrotate="0,200,0",
  104. x="0",
  105. y="-120",
  106. z="-1000",
  107. a="00",
  108. src=mount_model_tbl.path,
  109. ani=behaviour_tbl.name,
  110. })
  111. GUI:SetIsOnWithoutNotify(self.view.mountInfoToggle,false)
  112. GUI:SetIsOnWithoutNotify(self.view.mountEquipToggle,true)
  113. self:ShowSkillInfo(tbl.skillID,tbl.skillLevel)
  114. end
  115. end
  116. function this:ShowMountEquip(equipList)
  117. for i = 51, 55 do
  118. ---@type UIKmlLuaControl
  119. local control = self.view["pos"..i]
  120. if control then
  121. control.kmlControl:HideAllChilds()
  122. end
  123. end
  124. table.clear(self.equipItemData)
  125. for i, v in pairs(equipList) do
  126. local pos = tonumber(v.pos)
  127. local itemCfgId = tonumber(v.itemcfgid)
  128. self.equipItemData[pos] = v
  129. self:RefreshOneEquipPos(pos,itemCfgId)
  130. end
  131. end
  132. function this:RefreshOneEquipPos(pos,itemCfgId)
  133. GUI:Item_Create(self.view["pos"..pos], {
  134. width = "53",
  135. height = "56",
  136. itemid = itemCfgId,
  137. tips = "1",
  138. noclip = "1",
  139. bgtype = "0",
  140. mfixsize = "53,56"
  141. })
  142. end
  143. function this:ShowSkillInfo(skillId,level)
  144. GUI:setVisible(self.view.skillBg,skillId ~= 0)
  145. if skillId ~= 0 then
  146. ---@type cfg_skill_info_column
  147. local tbl = SL:GetConfigMultiKeys("cfg_skill_info",skillId,level,"skillID","skillLevel")
  148. GUI:Image_loadTexture(self.view.skillIcon,tbl.icon,"Atlas/Skill_icon.spriteatlas")
  149. GUI:Text_setString(self.view.skillName,tbl.name.." Lv."..level)
  150. GUI:Text_setString(self.view.skillDes,tbl.tips)
  151. end
  152. end
  153. function this:ShowItem()
  154. GUI:setVisible(self.view.bagItemRoot,true)
  155. local bag_info = string.split(SL:GetConfig("cfg_global",6).value,'#')
  156. self.maxHor = tonumber(bag_info[1])
  157. self.maxVet = tonumber(bag_info[2])
  158. local itemList_ = {}
  159. local show_id = EBagTileScrollViewId.Bag
  160. local itemList_1 = SL:GetMetaValue("BAG_DATA")[1]
  161. ---@param item CommonProtos.Item
  162. for _, item in pairs(itemList_1 or {}) do
  163. ---@type cfg_item_column
  164. local tbl = SL:GetConfig("cfg_item",item.cfgId,"id")
  165. if tbl and tbl.type == 2 and tbl.subType >=51 and tbl.subType<=55 then
  166. table.insert(itemList_, item)
  167. end
  168. end
  169. itemList_ = BagCellUtil.SortItemList(itemList_)
  170. if not self.bagTileScrollView then
  171. ---@type KLUIBagTileScrollViewItem
  172. self.bagTileScrollView = GUI:UIPanel_Open("dev/ui/Common/Item/KLUIBagTileScrollView/KLUIBagTileScrollViewItem", self.view.bagGrid, self,
  173. {
  174. itemList = itemList_,
  175. id = show_id,
  176. --forbidCount = SL:GetMetaValue("BAG_FORBID_COUNT"),
  177. hor = self.maxHor,
  178. vet = self.maxVet,
  179. canDrag = false,
  180. --forbidClickCallback = self.forbidClick,
  181. itemClick = self.ClickItemCallBack,
  182. parent = self,
  183. callBackUI = self,
  184. })
  185. self.bagTileScrollView:RefreshInfo()
  186. else
  187. self.bagTileScrollView:ClearBagItem()
  188. self.bagTileScrollView:RefreshItemByItem(itemList_)
  189. end
  190. end
  191. ---点击背包item回调
  192. ---@param itemControl KLBagItemItemView
  193. ---@param itemData CommonProtos.Item
  194. function this:ClickItemCallBack(itemControl,itemData)
  195. GUI:UIPanel_Open("dev/ui/Tips/Panel/KLUIEquipTips/KLUIEquipTipsPanel", nil, nil, { mountId = self.args.mountId,equip_pos = "bag", cfgId = itemData.cfgId, id = itemData.id })
  196. end
  197. function this:SetVisible(isVisible)
  198. GUI:setVisible(self.view.root,isVisible)
  199. end
  200. function this:GetVisible()
  201. return GUI:getVisible(self.view.root)
  202. end
  203. function this:Close()
  204. self.selectEquipPos = nil
  205. SL.ShowMainPanel()
  206. end
  207. return this