KLSkillBagPanel.lua 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. ---@class KLSkillBagPanel:UIKmlLuaPanelBase
  2. ---@field view KLSkillBagPanelView
  3. local KLSkillBagPanel = class(UIKmlLuaPanelBase)
  4. local this = KLSkillBagPanel
  5. ---创建时调用一次
  6. function this:Init()
  7. local bag_info = string.split(SL:GetConfig("cfg_global", 6).value, '#')
  8. self.maxHor = tonumber(bag_info[1])
  9. self.maxVet = tonumber(bag_info[2])
  10. local itemList_ = SL:GetIsFastItemList()
  11. local _itemList = SL.Bag:SortItemList(itemList_)
  12. ---@type KLUIBagTileScrollViewItem
  13. self.bagTileScrollView = GUI:UIPanel_Open("dev/ui/Common/Item/KLUIBagTileScrollView/KLUIBagTileScrollViewItem", self.view.bgGridRoot, self,
  14. {
  15. itemList = _itemList,
  16. id = EBagTileScrollViewId.Bag,
  17. hor = self.maxHor,
  18. vet = self.maxVet,
  19. canDrag = false,
  20. forbidClickCallback = self.forbidClick,
  21. itemClick = self.ClickItemCallBack,
  22. callBackUI = self
  23. })
  24. self:RefreshFastItemTip()
  25. EquipFunc:ReplaceEquipBagButton({self.view.person_shop_btn,self.view.storage_btn,self.view.recycle_btn,self.view.tidy_btn})
  26. end
  27. ---创建或者刷新界面数据时调用
  28. function this:Refresh()
  29. end
  30. ---注册UI事件和服务器消息
  31. function this:RegistEvents()
  32. GUI:AddOnClickEvent(self.view.closeBtn, self, self.closeBtn)
  33. SL:RegisterLUAEvent(Event.BagInfo_Change, self.BagInfo_Change, self)
  34. GUI:AddOnClickEvent(self.view.storage_btn, self, self.storage_btn)
  35. GUI:AddOnClickEvent(self.view.recycle_btn, self, self.recycle_btn)
  36. GUI:AddOnClickEvent(self.view.tidy_btn, self, self.tidy_btn)
  37. GUI:AddOnClickEvent(self.view.person_shop_btn, self, self.person_shop_btn)
  38. SL:RegisterLUAEvent(LUA_EVENT_BAG_UNLOCK, self.LUA_EVENT_BAG_UNLOCK, self)
  39. end
  40. function this:LUA_EVENT_BAG_UNLOCK(_, count)
  41. self.bagTileScrollView:RefreshForbidGrid(count)
  42. end
  43. function this:person_shop_btn()
  44. if PrivilegeCardManager.iswithStore() then
  45. self:OpenShop()
  46. else
  47. SL:CommonTipsMessage({ stringTblID = 226, ui = self, sureBtnText = "随身买药", cancelBtnText = "传送", cancelCallBack = self.TransferToNpcShop,
  48. callback = self.OpenFirsh, littleTipsTextTable = { text = "<color='#FFFF00'>激活白银特权卡</color>", x = 100, y = -60 },
  49. sureBtnImageData = { src = "button_interface_window6", atlas = "Atlas/Common.spriteatlas" }, cancelBtnImageData = { src = "button_interface_window7", atlas = "Atlas/Common.spriteatlas" },
  50. cancelBtnColor = "#DCE1E5" })
  51. end
  52. end
  53. function this:tidy_btn()
  54. GUI:UIPanel_Close("dev/ui/Common/Item/KLUIBagTileScrollView/KLUIBagTileScrollViewItem")
  55. self:Init()
  56. end
  57. function this:storage_btn()
  58. if PrivilegeCardManager.iswithWarehouse() then
  59. self:OpenStorage()
  60. else
  61. SL:CommonTipsMessage({ stringTblID = 227, ui = self, sureBtnText = "随身仓库", cancelBtnText = "传送", cancelCallBack = self.TransferToNpcStorage,
  62. callback = self.OpenFirsh, littleTipsTextTable = { text = "<color='#FFFF00'>激活钻石特权卡</color>", x = 100, y = -60 },
  63. sureBtnImageData = { src = "button_interface_window6", atlas = "Atlas/Common.spriteatlas" }, cancelBtnImageData = { src = "button_interface_window7", atlas = "Atlas/Common.spriteatlas" },
  64. cancelBtnColor = "#DCE1E5" })
  65. end
  66. end
  67. function this:recycle_btn()
  68. self:CloseSkillPanel()
  69. GUI:UIPanel_Open("dev/ui/Recover/Panel/KLRecover/KLRecoverPanel")
  70. end
  71. function this:BagInfo_Change(_, eventData)
  72. local is_refresh = false
  73. for _, v in ipairs(eventData) do
  74. if v.item then
  75. local cfgId = v.item.cfgId
  76. if SL:HasConfig("cfg_item", cfgId) then
  77. local item = SL:GetConfig("cfg_item", cfgId)
  78. if item.isFast and item.isFast == 1 then
  79. is_refresh = true
  80. end
  81. end
  82. else
  83. is_refresh = true
  84. end
  85. end
  86. if is_refresh then
  87. self.bagTileScrollView:ClearBagItem()
  88. local itemList_ = SL:GetIsFastItemList()
  89. local _itemList = BagCellUtil.SortItemList(itemList_)
  90. self.bagTileScrollView:RefreshItemByItem(_itemList)
  91. self.bagTileScrollView:RefreshInfo()
  92. end
  93. self:RefreshFastItemTip()
  94. end
  95. function this:RefreshFastItemTip()
  96. local isShow = false
  97. ---@type number[]
  98. local fastItems = SL:GetMetaValue(EMetaVarGetKey.FAST_ITEM_ID_LIST)
  99. if SL:HasConfig("cfg_item", fastItems[1]) then
  100. local ownerCount = SL:GetBagItemCount(fastItems[1])
  101. if ownerCount <= 0 then
  102. isShow = true
  103. end
  104. else
  105. isShow = true
  106. end
  107. if SL:HasConfig("cfg_item", fastItems[2]) then
  108. local ownerCount = SL:GetBagItemCount(fastItems[2])
  109. if ownerCount <= 0 then
  110. isShow = true
  111. end
  112. else
  113. isShow = true
  114. end
  115. GUI:setVisible(self.view.fastItemTip, isShow)
  116. end
  117. function this:closeBtn()
  118. self:CloseSkillPanel()
  119. end
  120. function this:Close()
  121. end
  122. function this:forbidClick()
  123. local bag_unlock_info = SL:GetConfig('cfg_global', 107).value
  124. local bag_unlock_split = string.split(bag_unlock_info, '#')
  125. local itemId = tonumber(bag_unlock_split[1])
  126. local needCount = tonumber(bag_unlock_split[2])
  127. GUI:UIPanel_Open("dev/ui/Common/Panel/KLCommonItemTips/KLCommonItemTipsPanel", nil, nil,
  128. {
  129. showTips = string.format("是否消耗%s扩充背包空间?", "背包石"),
  130. ui = self,
  131. cfgId = itemId,
  132. needCount = needCount,
  133. callback = self.UnlockGrid,
  134. })
  135. end
  136. function this:UnlockGrid()
  137. SL:ReqBagAddCapacityMessage(1)
  138. end
  139. ---点击背包item回调
  140. ---@param itemData CommonProtos.Item
  141. function this:ClickItemCallBack(_, itemData)
  142. SL:onLUAEvent(LUA_EVENT_FASTITEM_SET_SELECT, itemData.cfgId)
  143. end
  144. function this:CloseSkillPanel()
  145. GUI:UIPanel_Close("dev/ui/Bag/Panel/KLSkillBag/KLSkillBagPanel")
  146. GUI:UIPanel_Close("dev/ui/Skill/Panel/KLUISkillInfo/KLUISkillInfoPanel")
  147. GUI:UIPanel_Close("dev/ui/Skill/Panel/KLUISkillDescribe/KLUISkillDescribePanel")
  148. GUI:UIPanel_Close("dev/ui/Skill/Panel/KLUISkillSetting/KLUISkillSettingPanel")
  149. end
  150. function this:OpenFirsh()
  151. this:CloseSkillPanel()
  152. GUI:UIPanel_Open("dev/outui/ShopMain/Panel/KLShopMain/KLShopMainPanel", nil, nil, { 2 })
  153. end
  154. --- 传送到NPC商店(NPC商店功能)
  155. function this:TransferToNpcShop()
  156. local mapInfo = SL:GetConfig("cfg_map_info", SL:GetMetaValue("MAP_ID"), "id")
  157. if mapInfo.nopositionmove == 1 then
  158. SL:MessageTip({ id = 116 })
  159. return
  160. end
  161. SL:showTransferAnimation()
  162. SL:ScheduleOnce(0.5, function()
  163. SL:SendTransferToNpcMessage(100101, true)
  164. end)
  165. SL:ScheduleOnce(2, function()
  166. if not GUI:GetUI("dev/ui/NPC/Panel/KLNPCShop/KLNPCShopPanel") then
  167. SL:OpenNPCShop(1)
  168. end
  169. end)
  170. GUI:UIPanel_Close("dev/ui/Bag/Panel/KLUIBag/KLUIBagPanel")
  171. this:CloseSkillPanel()
  172. end
  173. function this:OpenShop()
  174. this:CloseSkillPanel()
  175. local shop_id = SL:GetMetaValue("GET_NPC_SHOPID", 100101)
  176. SL:OpenNPCShop(shop_id)
  177. end
  178. --- 传送到NPC仓库
  179. function this:TransferToNpcStorage()
  180. SL:showTransferAnimation()
  181. SL:ScheduleOnce(0.5, function()
  182. -- if SL:GetBattleState() then
  183. -- SL:TipMessage({ "战斗状态下禁止传送", 1, NoticeType.NoticeMid })
  184. -- return
  185. -- end
  186. SL:SendTransferToNpcMessage(100107, true)
  187. end)
  188. GUI:UIPanel_Close("dev/ui/Bag/Panel/KLUIBag/KLUIBagPanel")
  189. this:CloseSkillPanel()
  190. end
  191. function this:OpenStorage()
  192. this:CloseSkillPanel()
  193. GUI:UIPanel_Open("dev/ui/Bag/Panel/KLDepots/KLDepotsPanel", nil, nil, { x = -415, y = 0 })
  194. GUI:UIPanel_Open("dev/ui/Bag/Panel/KLUIBag/KLUIBagPanel")
  195. SL:HideMainPanel()
  196. end
  197. return this