---@class KLNPCShopPanel:UIKmlLuaPanelBase ---@field view KLNPCShopPanelView ---@field goods NpcShopProto.NpcShopGoodsInfoRes local KLNPCShopPanel = class(UIKmlLuaPanelBase) local this = KLNPCShopPanel ---创建时调用一次 function this:Init() SL:HideMainPanel() end ---创建或者刷新界面数据时调用 function this:Refresh() --self.goods = SL:FindConfigs("cfg_npcShop", "shopId", self.args) SL.NpcShop:ReqNpcShopInfo(tonumber(self.args), self.ResNpcShopGoodsInfoMessage, self) --table.sort(self.goods, function(a, b) -- return a.id < b.id --end) end ---@param message NpcShopProto.NpcShopGoodsInfoRes @商品信息响应 function this:ResNpcShopGoodsInfoMessage(_, message) self.goods = message["goodsList"] table.sort(self.goods, function(a, b) return a.id < b.id end) self:RefreshGoodsUI() self:UpdateMoney() end function this:RefreshGoodsUI() if not self.bagUI then GUI:UIPanel_Open("dev/ui/Bag/Panel/KLUIBag/KLUIBagPanel", nil, nil, { x = -415, y = 0, bagType = EBagShowType.NPCShop }, false, function(bagUI) self.bagUI = bagUI end) end if PrivilegeCardManager.AutoBuyIsOpen() then GUI:SetActive(self.view.autoBuyToggleCheck, true) else GUI:SetActive(self.view.autoBuyToggleCheck, false) end GUI:DataListInitData(self.view.goods, function() return table.count(self.goods) end, function(realIndex) --return self:DataListGoodsItemGetFunc(realIndex) end, function(realIndex, kmlcontrol) --return self:DataListGoodsItemInitFunc(realIndex, kmlcontrol) end, function(realIndex, kmlcontrol) return self:DataListGoodsItemUpdateFunc(realIndex, kmlcontrol) end) GUI:DataListUpdateData(self.view.goods) end function this:DataListGoodsItemUpdateFunc(realIndex, kmlcontrol) local data = self.goods[realIndex + 1] --local showItem_ = self.view.goods:GetChildControl(realIndex, "showItem_") local showItem_ = GUI:GetChildControl(self.view.goods, realIndex, "showItem_") local gooditem = SL:GetConfig("cfg_npcShop", data.id, "id") GUI:Item_UpdataData(showItem_, { itemid = gooditem.itemId[1], itemcount = gooditem.itemId[2] }) --local itemclick = self.view.goods:GetChildControl(realIndex, "itemclick") local itemclick = GUI:GetChildControl(self.view.goods, realIndex, "itemclick") GUI:AddOnClickEvent(itemclick, self, function() SL:OpenTips(nil, gooditem.itemId[1]) end) --local title_ = self.view.goods:GetChildControl(realIndex, "title_") local title_ = GUI:GetChildControl(self.view.goods, realIndex, "title_") GUI:Text_setString(title_, gooditem.itemName) --local coinitem = self.view.goods:GetChildControl(realIndex, "coinitem") local coinitem = GUI:GetChildControl(self.view.goods, realIndex, "coinitem") GUI:Item_setItemId(coinitem, data.coinType) --local coinClick = self.view.goods:GetChildControl(realIndex, "coinClick") local coinClick = GUI:GetChildControl(self.view.goods, realIndex, "coinClick") GUI:AddOnClickEvent(coinClick, self, function() SL:OpenTips(nil, data.coinType) end) --local coinnum = self.view.goods:GetChildControl(realIndex, "coinnum") local coinnum = GUI:GetChildControl(self.view.goods, realIndex, "coinnum") GUI:Text_setString(coinnum, tostring(data.unitPrice * data.count)) --local buy = self.view.goods:GetChildControl(realIndex, "buy") local buy = GUI:GetChildControl(self.view.goods, realIndex, "buy") GUI:AddOnClickEvent(buy, self, function() SL.NpcShop:ReqBuyShopGoods(self.args, data.goodsId, data.count, self.ResBuyShopGoodsMessage, self) end) end --自动购买 function this:AutoBuy() if not PrivilegeCardManager.isautoPotion() then self:TipCard() return end PrivilegeCardManager.ReqAutoBuyDrug() end function this:TipCard() local text = SL:GetConfig("cfg_string", 229, "id").text SL:CommonTipsMessage({ stringTblID = 229, showTips = text, ui = self, sureBtnText = "确定", cancelBtnText = "取消", callback = self.OpenFirsh }) end function this:UpdateAutoBuy() if PrivilegeCardManager.AutoBuyIsOpen() then GUI:SetActive(self.view.autoBuyToggleCheck, true) else GUI:SetActive(self.view.autoBuyToggleCheck, false) end end function this:OpenFirsh() --SL:TipMessage({ "首充还未开通", 1, NoticeType.NoticeMid }) this:ClosePanel() --GUI:UIPanel_Open("dev/ui/ShopMall/Panel/KLShopMall/KLShopMallPanel") --if InfoManager.monthCardInfo:IsHaveMonthCardRights("privilege") then -- GUI:UIPanel_Open("dev/outui/MonthCard/Panel/KLUIMonthCardMain/KLUIMonthCardMainPanel", nil, nil, { type = "privilege" }) --else -- GUI:UIPanel_Open("dev/outui/MonthCard/Panel/KLUIMonthCardMain/KLUIMonthCardMainPanel") --end GUI:UIPanel_Open("dev/outui/ShopMain/Panel/KLShopMain/KLShopMainPanel", nil, nil, { 2 }) end function this:DesBtn() local helpCfg = SL:GetConfig("cfg_rule_text", 13, "id") if helpCfg then SL:CommonStrTipsMessage({ title = helpCfg.menutxt, str = helpCfg.location }) end --GUI:UIPanel_Open("dev/ui/NPC/Panel/KLNPCShopTip/KLNPCShopTipPanel") end ---注册UI事件和服务器消息 function this:RegistEvents() GUI:AddOnClickEvent(self.view.CloseButton, self, self.ClosePanel) GUI:AddOnClickEvent(self.view.autoBuyBackground, self, self.AutoBuy) GUI:AddOnClickEvent(self.view.desButton, self, self.DesBtn) GUI:AddOnClickEvent(self.view.moneyBackground, self, function() SL:OpenTips(nil, 10010001) end) GUI:AddOnClickEvent(self.view.MUCoinBackground, self, function() SL:OpenTips(nil, 10020001) end) GUI:AddOnClickEvent(self.view.MUBindCoinBackground, self, function() SL:OpenTips(nil, 10050001) end) GUI:AddOnClickEvent(self.view.diamondBackground, self, function() SL:OpenTips(nil, 10040001) end) SL:RegisterLUAEvent(LUA_EVENT_MONEYCHANGE, self.UpdateMoney, self) SL:RegisterLUAEvent(LUA_EVENT_AUTO_BUY_POTION_RESULT, self.UpdateAutoBuy, self) --SL:RegisterLuaNetMsg(MessageDef.ResBuyShopGoodsMessage, self.ResBuyShopGoodsMessage, self) --SL:RegisterLuaNetMsg(MessageDef.ResNpcShopGoodsInfoMessage, self.ResNpcShopGoodsInfoMessage, self) end ---@param message NpcShopProto.BuyShopGoodsReq @购买成功回调 function this:ResBuyShopGoodsMessage(_, message) local data = {} local tbl = SL:GetConfig("cfg_npcShop", message.goodsId, "id") local canputbag = SL:CanPutToBag(tbl.itemId[1], message.count) if canputbag then data[tbl.itemId[1]] = message.count SL:OpenRewardTips(data, 0) end end --刷新货币数据 function this:UpdateMoney() GUI:Image_loadTexture(self.view.MUBindCoinIcon, "10050001", "Atlas/TS_Common.spriteatlas") GUI:Text_setString(self.view.moneyText, tostring(SL:GetMetaValue(EMetaVarGetKey.MONEY, MUEResourceType.GoldMoney))) GUI:Text_setString(self.view.muCoinText, tostring(SL:GetMetaValue(EMetaVarGetKey.MONEY, MUEResourceType.MiracleCurrency))) GUI:Text_setString(self.view.muBindCoinText, tostring(SL:GetMetaValue(EMetaVarGetKey.MONEY, MUEResourceType.BindDiaMond))) GUI:Text_setString(self.view.diamondText, tostring(SL:GetMetaValue(EMetaVarGetKey.MONEY, MUEResourceType.DiaMond))) end function this:ClosePanel() GUI:UIPanel_Close("dev/ui/NPC/Panel/KLNPCShop/KLNPCShopPanel") end function this:Close() SL:UnRegisterLUAEvent(LUA_EVENT_MONEYCHANGE, self.UpdateMoney, self) GUI:UIPanel_Close("dev/ui/Bag/Panel/KLUIBag/KLUIBagPanel") SL:ShowMainPanel() end return this