KLUIBagPanel.lua 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  1. ---@class KLUIBagPanel:UIKmlLuaPanelBase
  2. ---@field view KLUIBagPanelView
  3. local KLUIBagPanel = class(UIKmlLuaPanelBase)
  4. local this = KLUIBagPanel
  5. ---创建时调用一次
  6. function KLUIBagPanel:Init()
  7. self:InitData(self.args)
  8. local bag_info = string.split(SL:GetConfig("cfg_global", 6).value, '#')
  9. local forbidNum = 0
  10. local increaseRow, needLockRow
  11. self.JumpSelectId = nil
  12. if self.args then
  13. for i, v in pairs(self.args) do
  14. if string.split(i, "_")[1] == "JumpSelectItem" then
  15. if SL:GetBagItemCount(tonumber(v)) > 0 then
  16. self.JumpSelectId = tonumber(v)
  17. end
  18. end
  19. end
  20. end
  21. ---特权暂时没这个功能,先注释,别删
  22. -- if #bag_info >= 5 then
  23. -- increaseRow, needLockRow = PrivilegeCardManager.GetBagCanShowRow(tonumber(bag_info[1]))
  24. -- self.maxHor = tonumber(bag_info[1]) + increaseRow
  25. -- self.maxVet = tonumber(bag_info[2])
  26. -- forbidNum = PrivilegeCardManager.GetBagSiftLockGridNum()
  27. -- else
  28. self.maxHor = tonumber(bag_info[1])
  29. self.maxVet = tonumber(bag_info[2])
  30. -- end
  31. ---@type KLUIBagTileScrollViewItem
  32. GUI:UIPanel_Open("dev/ui/Common/Item/KLUIBagTileScrollView/KLUIBagTileScrollViewItem", self.view.root, self,
  33. {
  34. itemList = SL:GetMetaValue("BAG_DATA")[1],
  35. id = EBagTileScrollViewId.Bag,
  36. forbidCount = SL:GetMetaValue("BAG_FORBID_COUNT") - forbidNum,
  37. hor = self.maxHor,
  38. vet = self.maxVet,
  39. forbidClickCallback = self.forbidClick,
  40. dragEndCallback = self.dragEnd,
  41. JumpSelectId = self.JumpSelectId,
  42. parent = self
  43. },true,function(bagTileScrollView)
  44. self.bagTileScrollView = bagTileScrollView
  45. self.bagTileScrollView:ResetPos()
  46. self.bagTileScrollView:RefreshInfo()
  47. if needLockRow and needLockRow > 0 then
  48. self.bagTileScrollView:RefreshRedGrid(needLockRow * self.maxVet)
  49. end
  50. end)
  51. EquipFunc:ReplaceEquipBagButton({self.view.person_shop_btn,self.view.storage_btn,self.view.recycle_btn,self.view.tidy_btn})
  52. end
  53. ---初始化数据
  54. function KLUIBagPanel:InitData(data)
  55. self.x = (data and tonumber(data.x)) or 0
  56. self.y = (data and tonumber(data.y)) or 0
  57. self.bagType = (data and data.bagType) or EBagShowType.Bag
  58. end
  59. function KLUIBagPanel:Show(...)
  60. SL.HideMainPanel()
  61. if self.bagType == EBagShowType.Bag and not GUI:GetUI("dev/ui/Bag/Panel/KLDepots/KLDepotsPanel") then
  62. GUI:UIPanel_Open("dev/ui/Equip/Panel/KLEquipUI/KLEquipUIPanel", nil, nil, { x = -399, y = 0, relatePanel = self.filePath })
  63. end
  64. end
  65. -- 引导模块高亮特定道具
  66. function this:GuideToShowItem(cfgId)
  67. if self.bagType == EBagShowType.Bag then
  68. self.bagTileScrollView:SelectItem(cfgId)
  69. end
  70. end
  71. ---创建或者刷新界面数据时调用
  72. function KLUIBagPanel:Refresh()
  73. local x = self.x
  74. local y = self.y
  75. GUI:setPosition(self.view.root, x, y)
  76. if self.args and self.args.JumpType then
  77. ---跳转用
  78. if self.args.JumpType == 1 then
  79. self:recycle_btn()
  80. end
  81. end
  82. end
  83. ---注册UI事件和服务器消息
  84. function KLUIBagPanel:RegistEvents()
  85. GUI:AddOnClickEvent(self.view.closeBtn, self, self.closeBtn)
  86. SL:RegisterLUAEvent(Event.BagInfo_Change, self.BagInfo_Change, self)
  87. GUI:AddOnClickEvent(self.view.storage_btn, self, self.storage_btn)
  88. GUI:AddOnClickEvent(self.view.recycle_btn, self, self.recycle_btn)
  89. GUI:AddOnClickEvent(self.view.tidy_btn, self, self.tidy_btn)
  90. GUI:AddOnClickEvent(self.view.person_shop_btn, self, self.person_shop_btn)
  91. SL:RegisterLUAEvent(LUA_EVENT_BAG_UNLOCK, self.LUA_EVENT_BAG_UNLOCK, self)
  92. SL:RegisterLUAEvent(LUA_EVENT_BAG_SORT, self.LUA_EVENT_BAG_SORT, self)
  93. SL:RegisterLUAEvent(LUA_EVENT_PLAYER_EQUIP_CHANGE, self.LUA_EVENT_PLAYER_EQUIP_CHANGE, self)
  94. end
  95. function this:LUA_EVENT_PLAYER_EQUIP_CHANGE()
  96. self.bagTileScrollView:RefreshInfo()
  97. end
  98. function this:person_shop_btn()
  99. if self.bagType == EBagShowType.NPCShop then
  100. SL:MessageTip({id=502})
  101. return
  102. end
  103. if PrivilegeCardManager.iswithStore() then
  104. self:OpenShop()
  105. else
  106. SL:CommonTipsMessage({ stringTblID = 226, ui = self, sureBtnText = "随身买药", cancelBtnText = "传送", cancelCallBack = self.TransferToNpcShop,
  107. callback = self.OpenFirsh, littleTipsTextTable = { text = "<color='#FFFF00'>激活白银特权卡</color>", x = 100, y = -60 },
  108. sureBtnImageData = { src = "button_interface_window6", atlas = "Atlas/Common.spriteatlas" }, cancelBtnImageData = { src = "button_interface_window7", atlas = "Atlas/Common.spriteatlas" },
  109. cancelBtnColor = "#DCE1E5" })
  110. end
  111. end
  112. -- 整理按钮
  113. function this:tidy_btn()
  114. SL:ReqTidyItemMessage()
  115. end
  116. -- 背包格子解锁回包
  117. function this:LUA_EVENT_BAG_UNLOCK(_, count)
  118. count = count - PrivilegeCardManager.GetBagSiftLockGridNum()
  119. if count < 0 then
  120. count = 0
  121. end
  122. self.bagTileScrollView:RefreshForbidGrid(count)
  123. end
  124. -- 整理完成回包
  125. function this:LUA_EVENT_BAG_SORT()
  126. self.bagTileScrollView:ClearBagItem()
  127. self.bagTileScrollView:RefreshItemByItem(SL:GetMetaValue("BAG_DATA")[1])
  128. self.bagTileScrollView:RefreshInfo()
  129. end
  130. -- 仓库按钮
  131. function this:storage_btn()
  132. if GUI:GetUI("dev/ui/Bag/Panel/KLDepots/KLDepotsPanel") then
  133. return
  134. end
  135. if self.bagType == EBagShowType.NPCShop then
  136. SL:MessageTip({id=502})
  137. return
  138. end
  139. if PrivilegeCardManager.iswithWarehouse() then
  140. self:OpenStorage()
  141. else
  142. SL:CommonTipsMessage({ stringTblID = 227, ui = self, sureBtnText = "随身仓库", cancelBtnText = "传送", cancelCallBack = self.TransferToNpcStorage,
  143. callback = self.OpenFirsh, littleTipsTextTable = { text = "<color='#FFFF00'>激活钻石特权卡</color>", x = 100, y = -60 },
  144. sureBtnImageData = { src = "button_interface_window6", atlas = "Atlas/Common.spriteatlas" }, cancelBtnImageData = { src = "button_interface_window7", atlas = "Atlas/Common.spriteatlas" },
  145. cancelBtnColor = "#DCE1E5" })
  146. end
  147. end
  148. -- 仓库打开
  149. function this:OpenStorage()
  150. GUI:UIPanel_Close("dev/ui/Equip/Panel/KLEquipUI/KLEquipUIPanel")
  151. GUI:UIPanel_Open("dev/ui/Bag/Panel/KLDepots/KLDepotsPanel", nil, nil, { x = -415, y = 0 })
  152. end
  153. -- 商城打开
  154. function this:OpenShop()
  155. GUI:UIPanel_Close("dev/ui/Bag/Panel/KLUIBag/KLUIBagPanel")
  156. if GUI:GetUI("dev/ui/Bag/Panel/KLDepots/KLDepotsPanel") then
  157. GUI:UIPanel_Close("dev/ui/Bag/Panel/KLDepots/KLDepotsPanel")
  158. end
  159. local shop_id = SL:GetMetaValue("GET_NPC_SHOPID", 100101)
  160. SL:OpenNPCShop(shop_id)
  161. end
  162. function this:OpenFirsh()
  163. GUI:UIPanel_Close("dev/ui/Bag/Panel/KLUIBag/KLUIBagPanel")
  164. if GUI:GetUI("dev/ui/Bag/Panel/KLDepots/KLDepotsPanel") then
  165. GUI:UIPanel_Close("dev/ui/Bag/Panel/KLDepots/KLDepotsPanel")
  166. end
  167. GUI:UIPanel_Open("dev/outui/ShopMain/Panel/KLShopMain/KLShopMainPanel", nil, nil, { 2 })
  168. end
  169. function this:recycle_btn()
  170. if self.bagType == EBagShowType.NPCShop then
  171. SL:MessageTip({id=502})
  172. return
  173. end
  174. GUI:UIPanel_Close("dev/ui/Equip/Panel/KLEquipUI/KLEquipUIPanel")
  175. GUI:UIPanel_Close("dev/ui/Bag/Panel/KLUIBag/KLUIBagPanel")
  176. GUI:UIPanel_Open("dev/ui/Recover/Panel/KLRecover/KLRecoverPanel")
  177. end
  178. function this:closeBtn()
  179. GUI:UIPanel_Close("dev/ui/Bag/Panel/KLUIBag/KLUIBagPanel")
  180. if GUI:GetUI("dev/ui/Bag/Panel/KLDepots/KLDepotsPanel") then
  181. GUI:UIPanel_Close("dev/ui/Bag/Panel/KLDepots/KLDepotsPanel")
  182. end
  183. SL.ShowMainPanel()
  184. end
  185. function KLUIBagPanel:Close()
  186. GUI:UIPanel_Close("dev/ui/Equip/Panel/KLEquipUI/KLEquipUIPanel")
  187. if GUI:GetUI("dev/ui/Bag/Panel/KLDepots/KLDepotsPanel") then
  188. GUI:UIPanel_Close("dev/ui/Bag/Panel/KLDepots/KLDepotsPanel")
  189. end
  190. if GUI:GetUI("dev/ui/NPC/Panel/KLNPCShop/KLNPCShopPanel") then
  191. GUI:UIPanel_Close("dev/ui/NPC/Panel/KLNPCShop/KLNPCShopPanel")
  192. end
  193. GUI:UIPanel_Close("dev/outui/NPC/Panel/KLSpecialNPCShop/KLSpecialNPCShopPanel")
  194. end
  195. function this:Hide()
  196. self:Close()
  197. end
  198. -- 点击禁用格子
  199. function this:forbidClick()
  200. local bag_unlock_info = SL:GetConfig('cfg_global', 107).value
  201. local bag_unlock_split = string.split(bag_unlock_info, '#')
  202. local itemId = tonumber(bag_unlock_split[1])
  203. local needCount = tonumber(bag_unlock_split[2])
  204. SL:CommonTipsMessage({ stringTblID = 207,
  205. ui = self, cfgId = itemId, needCount = needCount, callback = self.UnlockGrid, callbackData = nil })
  206. end
  207. function this:UnlockGrid()
  208. SL:ReqBagAddCapacityMessage(1)
  209. end
  210. -- 拖拽结束
  211. function this:dragEnd(eventData)
  212. local bagHor = eventData.bagPutHor
  213. local bagVet = eventData.bagPutVet
  214. local raycastObj = eventData.raycastObj
  215. local dragItem = eventData.dragItem
  216. local storageHor = eventData.storageHor
  217. local storageVet = eventData.storageVet
  218. -- 丢弃道具
  219. if raycastObj == nil then
  220. local canDrop = self:GetItemCanDrop(dragItem)
  221. if canDrop then
  222. local article = SL:GetConfig('cfg_item', dragItem.item.cfgId).article
  223. local name = SL:GetConfig('cfg_item', dragItem.item.cfgId).name
  224. local isDestroy = table.contains(article, 3)
  225. if isDestroy then
  226. GUI:UIPanel_Open("dev/ui/Common/Panel/KLUICommonTips/KLUICommonTipsPanel", nil, nil, { showTips = string.format("是否摧毁%s", name), callback = self.DropItem, callbackData = { item = dragItem.item }, ui = self })
  227. else
  228. GUI:UIPanel_Open("dev/ui/Common/Panel/KLUICommonTips/KLUICommonTipsPanel", nil, nil, { showTips = string.format("是否丢弃%s", name), callback = self.DropItem, callbackData = { item = dragItem.item }, ui = self })
  229. end
  230. else
  231. SL:TipMessage(SL:GetConfig('cfg_string', 288).text, 1, NoticeType.NoticeMid)--"该道具不可被丢弃",
  232. end
  233. return
  234. end
  235. if bagHor <= self.maxHor and bagHor > 0 and bagVet <= self.maxVet and bagVet > 0 then
  236. ---@type CommonProtos.Item
  237. --local dragItem = eventData.dragItem
  238. local oldIndex = eventData.index
  239. local newIndex = SL.Bag:GetIndexWithPageHorAndVet(1, bagHor, bagVet)
  240. SL:ReqSwapItemMessage(newIndex, 10000 + oldIndex)
  241. else
  242. local storage_info = string.split(SL:GetConfig("cfg_global", 7).value, '#')
  243. local maxHor = tonumber(storage_info[1])
  244. local maxVet = tonumber(storage_info[2])
  245. if storageHor and storageHor <= maxHor and storageHor > 0 and storageVet <= maxVet and storageVet > 0 then
  246. local oldIndex = eventData.index
  247. local panel = GUI:GetUI("dev/ui/Bag/Panel/KLDepots/KLDepotsPanel")
  248. if panel.bagType == "privilege" then
  249. local newIndex = SL.StoreHouse:GetIndexWithPageHorAndVet(panel.CurPage + panel.maxDepotsPages, storageHor, storageVet)
  250. SL:ReqBagToStoreMessage(10000 + oldIndex, newIndex)
  251. elseif panel.bagType == "depots" then
  252. local newIndex = SL.StoreHouse:GetIndexWithPageHorAndVet(panel.CurPage, storageHor, storageVet)
  253. SL:ReqBagToStoreMessage(10000 + oldIndex, newIndex)
  254. end
  255. end
  256. end
  257. end
  258. function this.DropItem(callbackData)
  259. local item = callbackData.callbackData.item
  260. local index = SL:MeData_GetIndexBaseOnItemId(item.id)
  261. if index then
  262. SL:ReqGiveUpItemMessage(index)
  263. end
  264. end
  265. function this:BagInfo_Change(_, eventData)
  266. local ksItemList = self.bagTileScrollView:Item_Change(eventData)
  267. for _, ksItem in pairs(ksItemList) do
  268. ksItem:RefreshInfo()
  269. end
  270. end
  271. ---@param item KLBagItemItem
  272. function this:GetItemCanDrop(item)
  273. local article = SL:GetConfig('cfg_item', item.item.cfgId).article
  274. local cantDrop = table.contains(article, 2)
  275. if cantDrop then
  276. return false
  277. end
  278. return not item.item.bind
  279. end
  280. --- 传送到NPC商店(NPC商店功能)
  281. function this:TransferToNpcShop()
  282. local mapInfo = SL:GetConfig("cfg_map_info", SL:GetMetaValue("MAP_ID"), "id")
  283. if mapInfo.nopositionmove == 1 then
  284. SL:MessageTip({ id = 116 })
  285. return
  286. end
  287. SL:showTransferAnimation()
  288. SL:ScheduleOnce(0.5, function()
  289. SL:SendTransferToNpcMessage(100101, true)
  290. end)
  291. SL:ScheduleOnce(2, function()
  292. if not GUI:GetUI("dev/ui/NPC/Panel/KLNPCShop/KLNPCShopPanel") then
  293. SL:OpenNPCShop(1)
  294. end
  295. end)
  296. GUI:UIPanel_Close("dev/ui/Bag/Panel/KLUIBag/KLUIBagPanel")
  297. end
  298. function this:checkTigg()
  299. SL:ScheduleOnce(0.2, function()
  300. local uid = SL:GetMetaValue(EMetaVarGetKey.UID)
  301. local me = SL:GetRoleById(uid)
  302. SL:CellTrigger(SL:GetMetaValue(EMetaVarGetKey.MAP_ID), SL:MeData_GetCoord().x, SL:MeData_GetCoord().z, me)
  303. end)
  304. end
  305. --- 传送到NPC仓库
  306. function this.TransferToNpcStorage()
  307. SL:showTransferAnimation()
  308. SL:ScheduleOnce(0.5, function()
  309. -- if SL:GetBattleState() then
  310. -- SL:TipMessage({ "战斗状态下禁止传送", 1, NoticeType.NoticeMid })
  311. -- return
  312. -- end
  313. SL:SendTransferToNpcMessage(100107, true)
  314. end)
  315. GUI:UIPanel_Close("dev/ui/Bag/Panel/KLUIBag/KLUIBagPanel")
  316. end
  317. return KLUIBagPanel