---@class KLShapeShiftCardHousePanel:UIKmlLuaPanelBase ---@field view KLShapeShiftCardHousePanelView local KLShapeShiftCardHousePanel = class(UIKmlLuaPanelBase) local this = KLShapeShiftCardHousePanel function this:AsyncLoadUI() end local E_CardQuality = { Blue = enum(1), Gold = enum(2), Red = enum(3), } ---创建时调用一次 function this:Init() self.cardItemList = {} GUI:DataListInitData(self.view.datalist_card, function() return self:ItemCountFunc() end, function(realIndex) return self:ItemGetFunc(realIndex) end, nil, function(realIndex, kmlCtrl) return self:ItemUpdateFunc(realIndex, kmlCtrl) end ) self.recoveryIsShow = false self.toggleIndex = 0 self.allCardInfo = {} GUI:OSAScrollView_Initialized(self.view.osa_item_list, nil, self.RecoveryItemUpdateFun, self) end function this:ItemCountFunc() return #self.selectCardInfo end function this:ItemGetFunc() ---@type KLShapeShiftCardItem local item = GUI:UIPanel_Open("dev/outui/ShapeShiftCard/Item/KLShapeShiftCard/KLShapeShiftCardItem", self.view.datalist_card, self, { type = E_ShapeShiftCardFuncType.House }, true) local kmlCtrl = item.view.root self.cardItemList[kmlCtrl] = item return kmlCtrl end ---@param realIndex number ---@param kmlCtrl KingML.KmlControl function this:ItemUpdateFunc(realIndex, kmlCtrl) ---@type KLShapeShiftCardItem local item = self.cardItemList[kmlCtrl] item:RefreshBagItem(self.selectCardInfo[realIndex + 1], realIndex + 1) end function this:RecoveryItemUpdateFun(item, index) local item_recovery = GUI:GetChildById(item, "item_recovery") local item_count = GUI:GetChildById(item, "item_count") local info = self.recoveryAward[index + 1] GUI:Item_setItemId(item_recovery, info.id) if info.max == info.min then GUI:Text_setString(item_count, tostring(info.max)) else GUI:Text_setString(item_count, info.min .. "-" .. info.max) end end ---注册UI事件和服务器消息 function this:RegistEvents() GUI:AddOnClickEvent(self.view.btn_recovery_up, self, self.RefreshRecoveryPanel) GUI:AddOnClickEvent(self.view.btn_go, self, self.SwitchCardShop) GUI:AddOnClickEvent(self.view.btn_recovery, self, self.RecoveryFunc) GUI:AddOnClickEvent(self.view.btn_tips, self, self.FuncTips) GUI:SetToggleOnValueChange(self.view.toggle_all, self, self.ToggleAllOnChange) GUI:SetToggleOnValueChange(self.view.toggle_shift, self, self.ToggleShiftOnChange) GUI:SetToggleOnValueChange(self.view.toggle_attr, self, self.ToggleAttrOnChange) GUI:SetToggleOnValueChange(self.view.toggle_god_attr, self, self.ToggleGodAttrOnChange) for i = 1, 3 do GUI:SetToggleOnValueChange(self.view["toggle_" .. i], self, self.ToggleRecoveryOnChange, i) end --SL:RegisterLuaNetMsg(LuaMessageIdToClient.RES_TRANSFER_CARD_BAG, self.RES_TRANSFER_CARD_BAG, self) SL:RegisterLUAEvent(LUA_SHAPE_CARD_BAG_CHANGE, self.RES_TRANSFER_CARD_BAG, self) end ---界面显示时调用一次 function this:Show() SL:SendLuaNetMsg(LuaMessageIdToSever.REQ_TRANSFER_CARD_BAG) end ---创建或者刷新界面数据时调用 function this:Refresh() end function this:RefreshRecoveryPanel() if self.recoveryIsShow then self:HideRecoveryPanel() else self:ShowRecoveryPanel() end self.recoveryIsShow = not self.recoveryIsShow end function this:ShowRecoveryPanel() GUI:setVisible(self.view.panel_recovery, true) GUI:setPositionY(self.view.btn_recovery_up, 152) GUI:setContentSize(self.view.loopscrollview_card, 825, 300) GUI:Image_loadTexture(self.view.img_btn_icon, "house_down", "Atlas/KLShapeShiftCard.spriteatlas") if #self.selectCardInfo == 0 then GUI:setVisible(self.view.panel_no_card, false) end self.allTypeCardCount = {} self.selectTypeCardCount = {} for _, v in pairs(self.selectCardInfo) do if v.quality == E_CardQuality.Blue then if self.allTypeCardCount[v.quality] then self.allTypeCardCount[v.quality] = self.allTypeCardCount[v.quality] + 1 else self.allTypeCardCount[v.quality] = 1 end self.selectTypeCardCount[v.quality] = 0 end if v.quality == E_CardQuality.Gold then if self.allTypeCardCount[v.quality] then self.allTypeCardCount[v.quality] = self.allTypeCardCount[v.quality] + 1 else self.allTypeCardCount[v.quality] = 1 end self.selectTypeCardCount[v.quality] = 0 end if v.quality == E_CardQuality.Red then if self.allTypeCardCount[v.quality] then self.allTypeCardCount[v.quality] = self.allTypeCardCount[v.quality] + 1 else self.allTypeCardCount[v.quality] = 1 end self.selectTypeCardCount[v.quality] = 0 end end for i = 1, 3 do GUI:Toggle_setIsOn(self.view["toggle_" .. i], false) end end function this:HideRecoveryPanel() GUI:setVisible(self.view.panel_recovery, false) GUI:setPositionY(self.view.btn_recovery_up, -22) GUI:setContentSize(self.view.loopscrollview_card, 825, 463) GUI:Image_loadTexture(self.view.img_btn_icon, "house_up", "Atlas/KLShapeShiftCard.spriteatlas") if #self.selectCardInfo == 0 then GUI:setVisible(self.view.panel_no_card, true) end end function this:SwitchCardShop() local ui = GUI:GetUI("dev/outui/ShapeShiftCard/Panel/KLShapeShiftCardMain/KLShapeShiftCardMainPanel") if ui then GUI:Toggle_setIsOn(ui.view.toggle_shop, true) end end function this:RecoveryFunc() local tbl = {} for i, v in pairs(self.selectRecoveryTbl) do if v.select then tbl[#tbl + 1] = i end end if table.count(tbl) > 0 then SL:SendLuaNetMsg(LuaMessageIdToSever.REQ_TRANSFER_CARD_RECOVER, tbl) end end function this:FuncTips() local helpCfg = SL:GetConfig("cfg_rule_text", 102) if helpCfg then SL:CommonStrTipsMessage({ title = helpCfg.menutxt, str = helpCfg.location }) end end function this:ToggleAllOnChange(_, _, eventData) if eventData[1] then self:RefreshScrollView(0) end end function this:ToggleShiftOnChange(_, _, eventData) if eventData[1] then self:RefreshScrollView(1) end end function this:ToggleAttrOnChange(_, _, eventData) if eventData[1] then self:RefreshScrollView(2) end end function this:ToggleGodAttrOnChange(_, _, eventData) if eventData[1] then self:RefreshScrollView(3) end end function this:ToggleRecoveryOnChange(_, data, eventData) if self.noRefresh then self.noRefresh = false return end local refresh = false for _, v in pairs(self.selectCardInfo) do if v.quality == data and v.select ~= eventData[1] then v.select = eventData[1] self:SetRecoveryInfo(v, eventData[1], nil, v.quality) refresh = true end end if refresh then self:RefreshScrollView(self.toggleIndex, true) self:RefreshRecoveryAward() end end function this:RES_TRANSFER_CARD_BAG() self.allCardInfo = InfoManager.shapeShiftCardInfo.allCardInfo self:RefreshScrollView(self.toggleIndex) self:HideRecoveryPanel() end function this:RefreshScrollView(type, noReset) self.selectCardInfo = {} self.toggleIndex = type if type == 0 then if not noReset then for _, v in pairs(self.allCardInfo) do v.select = false end end self.selectCardInfo = self.allCardInfo else for _, v in pairs(self.allCardInfo) do if not noReset then v.select = false end if v.type == type then self.selectCardInfo[#self.selectCardInfo + 1] = v end end end GUI:DataListUpdateData(self.view.datalist_card) if not noReset then self.selectRecoveryTbl = {} if self.recoveryIsShow then self:ShowRecoveryPanel() self:RefreshRecoveryAward() end end if #self.selectCardInfo > 0 then GUI:setVisible(self.view.panel_no_card, false) else if not self.recoveryIsShow then GUI:setVisible(self.view.panel_no_card, true) end end end function this:SetRecoveryInfo(info, isSelect, tblIndex, quality) if not self.selectRecoveryTbl then self.selectRecoveryTbl = {} end self.selectRecoveryTbl[info.id] = { cfgid = info.cfgid, select = isSelect } if tblIndex then quality = self.selectCardInfo[tblIndex].quality end if isSelect then self.selectTypeCardCount[quality] = self.selectTypeCardCount[quality] + 1 if self.selectTypeCardCount[quality] == self.allTypeCardCount[quality] and tblIndex then self.noRefresh = true GUI:Toggle_setIsOn(self.view["toggle_" .. quality], true) end else self.selectTypeCardCount[quality] = self.selectTypeCardCount[quality] - 1 if GUI:Toggle_getIsOn(self.view["toggle_" .. quality]) == "1" and tblIndex then self.noRefresh = true GUI:Toggle_setIsOn(self.view["toggle_" .. quality], false) end end if tblIndex then self.selectCardInfo[tblIndex].select = isSelect self:RefreshRecoveryAward() end end function this:RefreshRecoveryAward() local recoveryAward = {} for _, v in pairs(self.selectRecoveryTbl) do if v.select then local group = SL:GetConfig("cfg_item", v.cfgid).recoveryGroup local material = SL:GetConfig("cfg_recovery", group).material for _, k in pairs(material) do if recoveryAward[k[1]] then recoveryAward[k[1]].min = recoveryAward[k[1]].min + k[2] recoveryAward[k[1]].max = recoveryAward[k[1]].max + k[3] else local tbl = {} tbl.id = k[1] tbl.min = k[2] tbl.max = k[3] recoveryAward[k[1]] = tbl end end end end self.recoveryAward = {} for _, v in pairs(recoveryAward) do self.recoveryAward[#self.recoveryAward + 1] = v end GUI:OSAScrollView_RefreshList(self.view.osa_item_list, #self.recoveryAward) end function this:Close() self.cardItemList = nil self.recoveryAward = nil self.selectRecoveryTbl = nil self.allCardInfo = nil self.selectCardInfo = nil end return this