123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164 |
- ---@class KLFusionBagPanel:UIKmlLuaPanelBase
- ---@field view KLFusionBagPanelView
- local KLFusionBagPanel = class(UIKmlLuaPanelBase)
- local this = KLFusionBagPanel
- function this:AsyncLoadUI()
- end
- ---创建时调用一次
- function this:Init()
- self:InitData(self.args)
- local bag_info = string.split(SL:GetConfig("cfg_global", 6).value, '#')
- self.maxHor = tonumber(bag_info[1]) + 20
- self.maxVet = tonumber(bag_info[2])
- GUI:UIPanel_Open("dev/ui/Common/Item/KLUIBagTileScrollView/KLUIBagTileScrollViewItem", self.view.root, self,
- {
- hor = self.maxHor,
- vet = self.maxVet,
- canDrag = false,
- forbidClickCallback = self.forbidClick,
- itemClick = self.args and self.args.itemClick,
- selectList = {},
- callBackUI = self.args and self.args.callBackUI,
- isShowEffect = true
- }, false, function(bagTileScrollView)
- ---@type KLUIBagTileScrollViewItem
- self.bagTileScrollView = bagTileScrollView
- if self.itemList then
- self.bagTileScrollView:ClearBagItem()
- self.bagTileScrollView:RefreshItemByItem(self.itemList)
- self.itemList = nil
- end
- end)
- end
- ---初始化数据
- function this:InitData(data)
- self.x = (data and data.x) or 0
- self.y = (data and data.y) or 0
- end
- ---注册UI事件和服务器消息
- function this:RegistEvents()
- GUI:AddOnClickEvent(self.view.closeBtn, self, self.ClosePanel)
- GUI:AddOnClickEvent(self.view.person_shop_btn, self, self.personBtn)
- GUI:AddOnClickEvent(self.view.storage_btn, self, self.personBtn)
- GUI:AddOnClickEvent(self.view.recycle_btn, self, self.personBtn)
- GUI:AddOnClickEvent(self.view.tidy_btn, self, self.personBtn)
- end
- ---界面显示时调用一次
- function this:Show()
- end
- ---创建或者刷新界面数据时调用
- function this:Refresh()
- local x = self.x
- local y = self.y
- GUI:setPosition(self.view.root, x, y)
- end
- function this:RefreshItem(itemlist)
- if self.bagTileScrollView and itemlist then
- itemlist = self:SortItemList(itemlist)
- self.bagTileScrollView:ClearBagItem()
- self.bagTileScrollView:RefreshItemByItem(itemlist)
- self.itemList = nil
- else
- self.itemList = self:SortItemList(itemlist)
- end
- end
- function this:RefreshGrailSelect(itemList)
- self.bagTileScrollView:RefreshSelect(itemList)
- end
- function this:personBtn()
- SL:TipMessage(SL:GetConfig('cfg_string', 286).text, 1, NoticeType.NoticeLeftBottom) --"锻造中无法使用",
- end
- function this:Hide()
- end
- function this:ClosePanel()
- self.args.callBackUI:ClosePanel()
- end
- function this:Close()
- end
- ---@param itemList CommonProtos.Item[]
- ---@return CommonProtos.Item[]
- function this:SortItemList(itemList)
- local bag_str = SL:GetConfig("cfg_global", 6).value
- local bag_tbl = string.split(bag_str, '#')
- local bag_hor = tonumber(bag_tbl[1])
- local bag_vet = tonumber(bag_tbl[2])
- local use_cell_dict = {}
- local sortItemList = {}
- local cfg_id, now_hor, now_vet, is_put, hold_vet, hole_hor, item, now_hold_hor, now_judge_hor, now_hold_vet, now_judge_vet, now_cell_index
- local max_hor = bag_hor + 20
- for _, v in pairs(itemList) do
- cfg_id = v.cfgId
- now_hor = 1
- while now_hor <= max_hor do
- now_vet = 1
- while now_vet <= bag_vet do
- is_put = true
- ---@type cfg_item_column
- item = SL:GetConfig("cfg_item", cfg_id)
- hold_vet = item.holdGrid[1]
- hole_hor = item.holdGrid[2]
- now_hold_hor = 0
- while now_hold_hor < hole_hor do
- now_judge_hor = now_hor + now_hold_hor
- now_hold_vet = 0
- while now_hold_vet < hold_vet do
- now_judge_vet = now_vet + now_hold_vet
- now_cell_index = now_judge_hor * 100 + now_judge_vet
- if use_cell_dict[now_cell_index] or now_judge_vet > bag_vet then
- is_put = false
- break
- end
- now_hold_vet = now_hold_vet + 1
- end
- if not is_put then
- break
- end
- now_hold_hor = now_hold_hor + 1
- end
- if is_put then
- break
- end
- now_vet = now_vet + 1
- end
- if is_put then
- break
- end
- now_hor = now_hor + 1
- end
- local now_index = now_hor * 100 + now_vet
- sortItemList[now_index] = v
- now_hold_hor = 0
- while now_hold_hor < hole_hor do
- now_hold_vet = 0
- local now_hold_judge_hor = now_hor + now_hold_hor
- while now_hold_vet < hold_vet do
- local now_hold_judge_vet = now_vet + now_hold_vet
- now_cell_index = now_hold_judge_hor * 100 + now_hold_judge_vet
- use_cell_dict[now_cell_index] = true
- now_hold_vet = now_hold_vet + 1
- end
- now_hold_hor = now_hold_hor + 1
- end
- end
- return sortItemList
- end
- return this
|