---@class KLUIBagPanel:UIKmlLuaPanelBase ---@field view KLUIBagPanelView local KLUIBagPanel = class(UIKmlLuaPanelBase) local this = KLUIBagPanel ---创建时调用一次 function KLUIBagPanel:Init() self:InitData(self.args) local bag_info = string.split(SL:GetConfig("cfg_global", 6).value, '#') local forbidNum = 0 local increaseRow, needLockRow self.JumpSelectId = nil if self.args then for i, v in pairs(self.args) do if string.split(i, "_")[1] == "JumpSelectItem" then if SL:GetBagItemCount(tonumber(v)) > 0 then self.JumpSelectId = tonumber(v) end end end end ---特权暂时没这个功能,先注释,别删 -- if #bag_info >= 5 then -- increaseRow, needLockRow = PrivilegeCardManager.GetBagCanShowRow(tonumber(bag_info[1])) -- self.maxHor = tonumber(bag_info[1]) + increaseRow -- self.maxVet = tonumber(bag_info[2]) -- forbidNum = PrivilegeCardManager.GetBagSiftLockGridNum() -- else self.maxHor = tonumber(bag_info[1]) self.maxVet = tonumber(bag_info[2]) -- end ---@type KLUIBagTileScrollViewItem GUI:UIPanel_Open("dev/ui/Common/Item/KLUIBagTileScrollView/KLUIBagTileScrollViewItem", self.view.root, self, { itemList = SL:GetMetaValue("BAG_DATA")[1], id = EBagTileScrollViewId.Bag, forbidCount = SL:GetMetaValue("BAG_FORBID_COUNT") - forbidNum, hor = self.maxHor, vet = self.maxVet, forbidClickCallback = self.forbidClick, dragEndCallback = self.dragEnd, JumpSelectId = self.JumpSelectId, parent = self },true,function(bagTileScrollView) self.bagTileScrollView = bagTileScrollView self.bagTileScrollView:ResetPos() self.bagTileScrollView:RefreshInfo() if needLockRow and needLockRow > 0 then self.bagTileScrollView:RefreshRedGrid(needLockRow * self.maxVet) end end) EquipFunc:ReplaceEquipBagButton({self.view.person_shop_btn,self.view.storage_btn,self.view.recycle_btn,self.view.tidy_btn}) end ---初始化数据 function KLUIBagPanel:InitData(data) self.x = (data and tonumber(data.x)) or 0 self.y = (data and tonumber(data.y)) or 0 self.bagType = (data and data.bagType) or EBagShowType.Bag end function KLUIBagPanel:Show(...) SL.HideMainPanel() if self.bagType == EBagShowType.Bag and not GUI:GetUI("dev/ui/Bag/Panel/KLDepots/KLDepotsPanel") then GUI:UIPanel_Open("dev/ui/Equip/Panel/KLEquipUI/KLEquipUIPanel", nil, nil, { x = -399, y = 0, relatePanel = self.filePath }) end end -- 引导模块高亮特定道具 function this:GuideToShowItem(cfgId) if self.bagType == EBagShowType.Bag then self.bagTileScrollView:SelectItem(cfgId) end end ---创建或者刷新界面数据时调用 function KLUIBagPanel:Refresh() local x = self.x local y = self.y GUI:setPosition(self.view.root, x, y) if self.args and self.args.JumpType then ---跳转用 if self.args.JumpType == 1 then self:recycle_btn() end end end ---注册UI事件和服务器消息 function KLUIBagPanel:RegistEvents() GUI:AddOnClickEvent(self.view.closeBtn, self, self.closeBtn) SL:RegisterLUAEvent(Event.BagInfo_Change, self.BagInfo_Change, self) GUI:AddOnClickEvent(self.view.storage_btn, self, self.storage_btn) GUI:AddOnClickEvent(self.view.recycle_btn, self, self.recycle_btn) GUI:AddOnClickEvent(self.view.tidy_btn, self, self.tidy_btn) GUI:AddOnClickEvent(self.view.person_shop_btn, self, self.person_shop_btn) SL:RegisterLUAEvent(LUA_EVENT_BAG_UNLOCK, self.LUA_EVENT_BAG_UNLOCK, self) SL:RegisterLUAEvent(LUA_EVENT_BAG_SORT, self.LUA_EVENT_BAG_SORT, self) SL:RegisterLUAEvent(LUA_EVENT_PLAYER_EQUIP_CHANGE, self.LUA_EVENT_PLAYER_EQUIP_CHANGE, self) end function this:LUA_EVENT_PLAYER_EQUIP_CHANGE() self.bagTileScrollView:RefreshInfo() end function this:person_shop_btn() if self.bagType == EBagShowType.NPCShop then SL:MessageTip({id=502}) return end if PrivilegeCardManager.iswithStore() then self:OpenShop() else SL:CommonTipsMessage({ stringTblID = 226, ui = self, sureBtnText = "随身买药", cancelBtnText = "传送", cancelCallBack = self.TransferToNpcShop, callback = self.OpenFirsh, littleTipsTextTable = { text = "激活白银特权卡", x = 100, y = -60 }, sureBtnImageData = { src = "button_interface_window6", atlas = "Atlas/Common.spriteatlas" }, cancelBtnImageData = { src = "button_interface_window7", atlas = "Atlas/Common.spriteatlas" }, cancelBtnColor = "#DCE1E5" }) end end -- 整理按钮 function this:tidy_btn() SL:ReqTidyItemMessage() end -- 背包格子解锁回包 function this:LUA_EVENT_BAG_UNLOCK(_, count) count = count - PrivilegeCardManager.GetBagSiftLockGridNum() if count < 0 then count = 0 end self.bagTileScrollView:RefreshForbidGrid(count) end -- 整理完成回包 function this:LUA_EVENT_BAG_SORT() self.bagTileScrollView:ClearBagItem() self.bagTileScrollView:RefreshItemByItem(SL:GetMetaValue("BAG_DATA")[1]) self.bagTileScrollView:RefreshInfo() end -- 仓库按钮 function this:storage_btn() if GUI:GetUI("dev/ui/Bag/Panel/KLDepots/KLDepotsPanel") then return end if self.bagType == EBagShowType.NPCShop then SL:MessageTip({id=502}) return end if PrivilegeCardManager.iswithWarehouse() then self:OpenStorage() else SL:CommonTipsMessage({ stringTblID = 227, ui = self, sureBtnText = "随身仓库", cancelBtnText = "传送", cancelCallBack = self.TransferToNpcStorage, callback = self.OpenFirsh, littleTipsTextTable = { text = "激活钻石特权卡", x = 100, y = -60 }, sureBtnImageData = { src = "button_interface_window6", atlas = "Atlas/Common.spriteatlas" }, cancelBtnImageData = { src = "button_interface_window7", atlas = "Atlas/Common.spriteatlas" }, cancelBtnColor = "#DCE1E5" }) end end -- 仓库打开 function this:OpenStorage() GUI:UIPanel_Close("dev/ui/Equip/Panel/KLEquipUI/KLEquipUIPanel") GUI:UIPanel_Open("dev/ui/Bag/Panel/KLDepots/KLDepotsPanel", nil, nil, { x = -415, y = 0 }) end -- 商城打开 function this:OpenShop() GUI:UIPanel_Close("dev/ui/Bag/Panel/KLUIBag/KLUIBagPanel") if GUI:GetUI("dev/ui/Bag/Panel/KLDepots/KLDepotsPanel") then GUI:UIPanel_Close("dev/ui/Bag/Panel/KLDepots/KLDepotsPanel") end local shop_id = SL:GetMetaValue("GET_NPC_SHOPID", 100101) SL:OpenNPCShop(shop_id) end function this:OpenFirsh() GUI:UIPanel_Close("dev/ui/Bag/Panel/KLUIBag/KLUIBagPanel") if GUI:GetUI("dev/ui/Bag/Panel/KLDepots/KLDepotsPanel") then GUI:UIPanel_Close("dev/ui/Bag/Panel/KLDepots/KLDepotsPanel") end GUI:UIPanel_Open("dev/outui/ShopMain/Panel/KLShopMain/KLShopMainPanel", nil, nil, { 2 }) end function this:recycle_btn() if self.bagType == EBagShowType.NPCShop then SL:MessageTip({id=502}) return end GUI:UIPanel_Close("dev/ui/Equip/Panel/KLEquipUI/KLEquipUIPanel") GUI:UIPanel_Close("dev/ui/Bag/Panel/KLUIBag/KLUIBagPanel") GUI:UIPanel_Open("dev/ui/Recover/Panel/KLRecover/KLRecoverPanel") end function this:closeBtn() GUI:UIPanel_Close("dev/ui/Bag/Panel/KLUIBag/KLUIBagPanel") if GUI:GetUI("dev/ui/Bag/Panel/KLDepots/KLDepotsPanel") then GUI:UIPanel_Close("dev/ui/Bag/Panel/KLDepots/KLDepotsPanel") end SL.ShowMainPanel() end function KLUIBagPanel:Close() GUI:UIPanel_Close("dev/ui/Equip/Panel/KLEquipUI/KLEquipUIPanel") if GUI:GetUI("dev/ui/Bag/Panel/KLDepots/KLDepotsPanel") then GUI:UIPanel_Close("dev/ui/Bag/Panel/KLDepots/KLDepotsPanel") end if GUI:GetUI("dev/ui/NPC/Panel/KLNPCShop/KLNPCShopPanel") then GUI:UIPanel_Close("dev/ui/NPC/Panel/KLNPCShop/KLNPCShopPanel") end GUI:UIPanel_Close("dev/outui/NPC/Panel/KLSpecialNPCShop/KLSpecialNPCShopPanel") end function this:Hide() self:Close() end -- 点击禁用格子 function this:forbidClick() local bag_unlock_info = SL:GetConfig('cfg_global', 107).value local bag_unlock_split = string.split(bag_unlock_info, '#') local itemId = tonumber(bag_unlock_split[1]) local needCount = tonumber(bag_unlock_split[2]) SL:CommonTipsMessage({ stringTblID = 207, ui = self, cfgId = itemId, needCount = needCount, callback = self.UnlockGrid, callbackData = nil }) end function this:UnlockGrid() SL:ReqBagAddCapacityMessage(1) end -- 拖拽结束 function this:dragEnd(eventData) local bagHor = eventData.bagPutHor local bagVet = eventData.bagPutVet local raycastObj = eventData.raycastObj local dragItem = eventData.dragItem local storageHor = eventData.storageHor local storageVet = eventData.storageVet -- 丢弃道具 if raycastObj == nil then local canDrop = self:GetItemCanDrop(dragItem) if canDrop then local article = SL:GetConfig('cfg_item', dragItem.item.cfgId).article local name = SL:GetConfig('cfg_item', dragItem.item.cfgId).name local isDestroy = table.contains(article, 3) if isDestroy then 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 }) else 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 }) end else SL:TipMessage(SL:GetConfig('cfg_string', 288).text, 1, NoticeType.NoticeMid)--"该道具不可被丢弃", end return end if bagHor <= self.maxHor and bagHor > 0 and bagVet <= self.maxVet and bagVet > 0 then ---@type CommonProtos.Item --local dragItem = eventData.dragItem local oldIndex = eventData.index local newIndex = SL.Bag:GetIndexWithPageHorAndVet(1, bagHor, bagVet) SL:ReqSwapItemMessage(newIndex, 10000 + oldIndex) else local storage_info = string.split(SL:GetConfig("cfg_global", 7).value, '#') local maxHor = tonumber(storage_info[1]) local maxVet = tonumber(storage_info[2]) if storageHor and storageHor <= maxHor and storageHor > 0 and storageVet <= maxVet and storageVet > 0 then local oldIndex = eventData.index local panel = GUI:GetUI("dev/ui/Bag/Panel/KLDepots/KLDepotsPanel") if panel.bagType == "privilege" then local newIndex = SL.StoreHouse:GetIndexWithPageHorAndVet(panel.CurPage + panel.maxDepotsPages, storageHor, storageVet) SL:ReqBagToStoreMessage(10000 + oldIndex, newIndex) elseif panel.bagType == "depots" then local newIndex = SL.StoreHouse:GetIndexWithPageHorAndVet(panel.CurPage, storageHor, storageVet) SL:ReqBagToStoreMessage(10000 + oldIndex, newIndex) end end end end function this.DropItem(callbackData) local item = callbackData.callbackData.item local index = SL:MeData_GetIndexBaseOnItemId(item.id) if index then SL:ReqGiveUpItemMessage(index) end end function this:BagInfo_Change(_, eventData) local ksItemList = self.bagTileScrollView:Item_Change(eventData) for _, ksItem in pairs(ksItemList) do ksItem:RefreshInfo() end end ---@param item KLBagItemItem function this:GetItemCanDrop(item) local article = SL:GetConfig('cfg_item', item.item.cfgId).article local cantDrop = table.contains(article, 2) if cantDrop then return false end return not item.item.bind end --- 传送到NPC商店(NPC商店功能) function this:TransferToNpcShop() local mapInfo = SL:GetConfig("cfg_map_info", SL:GetMetaValue("MAP_ID"), "id") if mapInfo.nopositionmove == 1 then SL:MessageTip({ id = 116 }) return end SL:showTransferAnimation() SL:ScheduleOnce(0.5, function() SL:SendTransferToNpcMessage(100101, true) end) SL:ScheduleOnce(2, function() if not GUI:GetUI("dev/ui/NPC/Panel/KLNPCShop/KLNPCShopPanel") then SL:OpenNPCShop(1) end end) GUI:UIPanel_Close("dev/ui/Bag/Panel/KLUIBag/KLUIBagPanel") end function this:checkTigg() SL:ScheduleOnce(0.2, function() local uid = SL:GetMetaValue(EMetaVarGetKey.UID) local me = SL:GetRoleById(uid) SL:CellTrigger(SL:GetMetaValue(EMetaVarGetKey.MAP_ID), SL:MeData_GetCoord().x, SL:MeData_GetCoord().z, me) end) end --- 传送到NPC仓库 function this.TransferToNpcStorage() SL:showTransferAnimation() SL:ScheduleOnce(0.5, function() -- if SL:GetBattleState() then -- SL:TipMessage({ "战斗状态下禁止传送", 1, NoticeType.NoticeMid }) -- return -- end SL:SendTransferToNpcMessage(100107, true) end) GUI:UIPanel_Close("dev/ui/Bag/Panel/KLUIBag/KLUIBagPanel") end return KLUIBagPanel