UpView = {} local ArenaSetting = ConfigManager.GetConfig(ConfigName.ArenaSetting) local StoreTypeConfig = ConfigManager.GetConfig(ConfigName.StoreTypeConfig) local _ItemMaxNum = 3 local itemShowId=0 function UpView:New(gameObject) local u = {} u.gameObject = gameObject u.transform = gameObject.transform setmetatable(u, { __index = UpView }) return u end local panelList = { [PanelType.Main] = { 14, 16, 15 }, -- 体力 2 [PanelType.RoleInfo] = { 14, 3, 4 }, -- 成长护符 [PanelType.FightPointPass] = { 14, 3, 16 }, -- 新关卡 [PanelType.SoulCrystal] = { 14, 16, 15 }, -- 魂晶 [PanelType.Recruit] = { 14, 16, 19 }, -- 聚灵神戒(群英征募) [PanelType.ElementDrawCard] = { 14, 74, 20}, -- 元素神戒(元素招募) [PanelType.SecretBox] = { 16, 22, 21 }, -- 妖魂魔戒(秘盒开启) [PanelType.Arena] = { 14, 16, 23 }, -- 竞技场挑战券 [PanelType.HeartFireStone] = { 14, 16, 26 }, -- 心火明晶 [PanelType.Carbon] = { 14, 16, 27 }, -- 普通副本挑战券 [PanelType.EliteCarbon] = { 14, 16, 28 }, -- 精英副本挑战券 [PanelType.AdventureTimes] = { 14, 16, 44 }, -- 外敌挑战券 [PanelType.TrialCoin] = { 14, 16, 45 }, -- 试炼币 [PanelType.LightRing] = { 15, 46 }, -- 光辉灵界 [PanelType.IronResource] = { 14, 16, 1001 }, -- 铁矿石 [PanelType.FixforDan] = { 14, 16, 1002 }, -- 修为丹 [PanelType.StarSoul] = { 14, 16, 66 }, -- 星魂 [PanelType.DiffMonster] = { 16, 6, 5 }, -- 异妖 [PanelType.SoulContractShop] = StoreTypeConfig[1].ResourcesBar, -- 契魂商店 [PanelType.GeneralShop] = StoreTypeConfig[2].ResourcesBar, -- 杂货商店 [PanelType.RoamShop] = StoreTypeConfig[3].ResourcesBar, -- 云游商店 [PanelType.ArenaShop] = StoreTypeConfig[4].ResourcesBar, -- 竞技场商店 [PanelType.SecretBoxShop] = StoreTypeConfig[6].ResourcesBar, -- 秘盒商店 [PanelType.TrialShop] = StoreTypeConfig[8].ResourcesBar, -- 试炼商店 [PanelType.ActivityShop] = StoreTypeConfig[11].ResourcesBar, -- 活动商店 [PanelType.GuildShop] = StoreTypeConfig[12].ResourcesBar, -- 公会商店 [PanelType.EndLessShop] = StoreTypeConfig[13].ResourcesBar, -- 无尽商店 [PanelType.SoulPrintShop] = StoreTypeConfig[14].ResourcesBar, -- 魂印商店 [PanelType.FriendShop] = StoreTypeConfig[17].ResourcesBar, -- 友情商店 [PanelType.ChoasShop] = StoreTypeConfig[19].ResourcesBar, -- 混沌商店 [PanelType.TopMatchShop] = StoreTypeConfig[21].ResourcesBar, -- 巅峰赛商店 [PanelType.MonsterCamp] = { 14, 16, 53}, -- 兽潮 [PanelType.HeroReturn] = { 14, 16}, -- 回溯{ 14, 16, 70}, [PanelType.LuckyTreasure] = { 14, 16, 60}, -- 幸运探宝 [PanelType.AdvancedTreasure] = { 14, 16, 61}, -- 高级探宝 [PanelType.ExChange] = { 14, 16, 67}, -- 显示兑换 [PanelType.GoodFriend]={14,16, 69}, --好友 [PanelType.SoulPritResolve] = { 14, 16}, -- 魂印分解 [PanelType.TopMatch] = { 14, 16, 86}, -- 巅峰赛界面 [PanelType.FindFairy] = { 87, 16, 15}, -- 东海寻仙 [PanelType.Talisman] = {14}, -- 新法宝 } --- 要显示加号的类型,有购买功能的物品要配置在这里显示 加号 local _ShowPlusType = { UpViewRechargeType.Energy, UpViewRechargeType.Gold, UpViewRechargeType.Yaoh, UpViewRechargeType.ChallengeTicket, UpViewRechargeType.SpiritTicket, UpViewRechargeType.GhostRing, UpViewRechargeType.EliteCarbonTicket, UpViewRechargeType.AdventureAlianInvasionTicket, UpViewRechargeType.SoulCrystal, UpViewRechargeType.DemonCrystal, UpViewRechargeType.GrowthAmulet, UpViewRechargeType.LightRing, UpViewRechargeType.MonsterCampTicket, UpViewRechargeType.StarFireBuLingStone, UpViewRechargeType.SpiritJade, UpViewRechargeType.BadgeGlory, UpViewRechargeType.GuildToken, UpViewRechargeType.StarSoul, UpViewRechargeType.FriendPoint, UpViewRechargeType.ChoasCoin, UpViewRechargeType.LuckyTreasure, UpViewRechargeType.AdvancedTreasure, UpViewRechargeType.Panacea, UpViewRechargeType.JYD, UpViewRechargeType.TopMatchCoin, UpViewRechargeType.FindFairy, UpViewRechargeType.FixforDan, UpViewRechargeType.ChinaHas, UpViewRechargeType.Iron, } -- 判断是否显示加号 local function _IsShowPlus(_type) -- 魂晶特殊处理,在地图中不显示 + 号 if _type == UpViewRechargeType.SoulCrystal and MapManager.isInMap then return false end -- 判断是否是可购买的类型 for _, type in ipairs(_ShowPlusType) do if type == _type then return true end end return false end --- 红点类型注册 local _ViewRPType = { [UpViewRechargeType.Gold] = RedPointType.UpView_Gold } function UpView:_BindRP(rcType, redpot) local rpType = _ViewRPType[rcType] if not rpType then return end BindRedPointObject(rpType, redpot) if not self._BindData then self._BindData = {} end self._BindData[rpType] = redpot end function UpView:_ClearRP() if not self._BindData then return end for rpType, redpot in pairs(self._BindData) do ClearRedPointObject(rpType, redpot) end self._BindData = nil end --初始化组件(用于子类重写) function UpView:InitComponent() self.leftRoot = Util.GetGameObject(self.gameObject, "LeftUp") self.rightRoot = Util.GetGameObject(self.gameObject, "RightUp") self.cnyList = {} self.cnyTime = {} -- 麻蛋的左边一个右边一个 self.cnyLeft = {} self.timeLeft = {} self.cnyRight = {} self.timeRight = {} self.leftBtnList = {} self.rightBtnList = {} self.cnyListClick = {} for i = 1, _ItemMaxNum do self.cnyRight[i] = Util.GetGameObject(self.rightRoot, "cnyGrid/cny" .. i) self.rightBtnList[i] = Util.GetGameObject( self.rightRoot, "cnyGrid/cny" .. i .. "/btn") self.timeRight[i] = Util.GetGameObject(self.cnyRight[i], "time"):GetComponent("Text") self.cnyLeft[i] = Util.GetGameObject( self.leftRoot, "cnyGrid/cny" .. i) self.leftBtnList[i] = Util.GetGameObject( self.leftRoot, "cnyGrid/cny" .. i .. "/btn") self.timeLeft[i] = Util.GetGameObject(self.cnyLeft[i], "time"):GetComponent("Text") end self.panelType = PanelType.Main end --绑定事件(用于子类重写) function UpView:BindEvent() for idx, clickItem in ipairs(self.rightBtnList) do Util.AddOnceClick(clickItem, function() self:OnClick(idx) end) end for idx, clickItem in ipairs(self.leftBtnList) do Util.AddOnceClick(clickItem, function() self:OnClick(idx) end) end end --添加事件监听(用于子类重写) function UpView:AddListener() Game.GlobalEvent:AddEvent(GameEvent.Bag.BagGold, self.UpdateGoldVal, self) end --移除事件监听(用于子类重写) function UpView:RemoveListener() Game.GlobalEvent:RemoveEvent(GameEvent.Bag.BagGold, self.UpdateGoldVal, self) end ---@param args table -- args: { -- showType = int, -- panelType = int, -- } --界面打开时调用(用于子类重写) function UpView:OnOpen(args) self.Pname = self.transform.parent.name --方便调试 if args and args.panelType then self.panelType = args.panelType itemShowId=args.itemIdShow if(itemShowId==16) then itemShowId=15 end end self:SetShowType(args) self:UpdateGoldVal() self:RefreshCountDown() end -- 关闭界面时调用 function UpView:OnClose() self:_ClearRP() if self.timer then self.timer:Stop() self.timer = nil end end function UpView:SetShowType(context) if context and context.showType then self.leftRoot:SetActive(context.showType == UpViewOpenType.ShowLeft) self.rightRoot:SetActive(context.showType == UpViewOpenType.ShowRight) else self.leftRoot:SetActive(true) self.rightRoot:SetActive(false) end if context and context.showType then if context.showType == UpViewOpenType.ShowLeft then self.cnyList = self.cnyLeft self.cnyTime = self.timeLeft else self.cnyList = self.cnyRight self.cnyTime = self.timeRight end else self.cnyList = self.cnyLeft self.cnyTime = self.timeLeft end end function UpView:UpdateGoldVal() -- 先清一遍红点 self:_ClearRP() local panelShowItemList={} if(self.panelType==100) then panelShowItemList={14,16,itemShowId} else panelShowItemList = panelList[self.panelType] end for i = 1, _ItemMaxNum do if panelShowItemList[i] then if self.cnyList[i].gameObject then self.cnyList[i]:SetActive(true) Util.GetGameObject(self.cnyList[i], "icon"):GetComponent("Image").sprite = SetIcon(panelShowItemList[i]) Util.GetGameObject(self.cnyList[i], "addFlag"):SetActive(_IsShowPlus(panelShowItemList[i])) if panelShowItemList[i] == 20 then Util.GetGameObject(self.cnyList[i], "addFlag"):SetActive(true) end if panelShowItemList[i] == 2 then Util.GetGameObject(self.cnyList[i], "value"):GetComponent("Text").text = PrintWanNum(BagManager.GetTotalItemNum(panelShowItemList[i])) .. "/" .. PlayerManager.maxEnergy elseif panelShowItemList[i] == 44 then Util.GetGameObject(self.cnyList[i], "value"):GetComponent("Text").text = PrintWanNum(BagManager.GetTotalItemNum(panelShowItemList[i])).."/"..PrivilegeManager.GetPrivilegeNumber(9) elseif panelShowItemList[i] == 53 then Util.GetGameObject(self.cnyList[i], "value"):GetComponent("Text").text = PrintWanNum(BagManager.GetTotalItemNum(panelShowItemList[i])).."/"..MonsterCampManager.GetMaxCostItem() elseif panelShowItemList[i] == 87 then Util.GetGameObject(self.cnyList[i], "icon"):GetComponent("RectTransform").sizeDelta=Vector2.New(85,85) Util.GetGameObject(self.cnyList[i], "value"):GetComponent("Text").text = PrintWanNum(BagManager.GetTotalItemNum(panelShowItemList[i])) else Util.GetGameObject(self.cnyList[i], "value"):GetComponent("Text").text = PrintWanNum(BagManager.GetTotalItemNum(panelShowItemList[i])) end -- 绑定红点 local redpot = Util.GetGameObject(self.cnyList[i], "redpot") redpot:SetActive(false) self:_BindRP(panelShowItemList[i], redpot) end else self.cnyList[i]:SetActive(false) end end end -- 刷新倒计时显示 function UpView:RefreshCountDown() local isCD = false for i = 1, _ItemMaxNum do local panelShowItemList={} local itemId=0 if(self.panelType==100) then panelShowItemList={14,16,itemShowId} itemId=panelShowItemList[i] else itemId = panelList[self.panelType][i] end if itemId then local isRecover = AutoRecoverManager.IsAutoRecover(itemId) -- 是一个恢复型道具 local isNotFull = isRecover and AutoRecoverManager.GetRecoverTime(itemId) > 0 -- 没有恢复满 self.cnyTime[i].gameObject:SetActive(isRecover and isNotFull) if isRecover and isNotFull then isCD = true end end end -- 判断是否需要倒计时 if isCD then if not self.timer then self.timer = Timer.New(function() self:UpdateTime() end, 1, -1, true) self.timer:Start() end self:UpdateTime() else if self.timer then self.timer:Stop() self.timer = nil end end end -- 计时器回调方法 function UpView:UpdateTime() for i = 1, _ItemMaxNum do local panelShowItemList={} local itemId=0 if(self.panelType==100) then panelShowItemList={14,16,itemShowId} itemId=panelShowItemList[i] else itemId = panelList[self.panelType][i] end if itemId then local isRecover = AutoRecoverManager.IsAutoRecover(itemId) -- 是一个恢复型道具 if isRecover then local RemainTime = AutoRecoverManager.GetRecoverTime(itemId) if RemainTime >= 0 then local _, _hour, _min, _sec = TimeToHMS(RemainTime) local timeStr = string.format("%02d:%02d:%02d", _hour, _min, _sec) --RemainTime > 3600 and string.format("%02d:%02d", _hour, _min) or string.format("%02d:%02d", _min, _sec) self.cnyTime[i].text = timeStr else self.cnyTime[i].text = "" end end end end end function UpView:OnClick(index) local panelShowItemList={} local reChargeType=0 if(self.panelType==100) then panelShowItemList={14,16,itemShowId} reChargeType=panelShowItemList[index] else reChargeType = panelList[self.panelType][index] end --local reChargeType = panelList[self.panelType][index] if(reChargeType==20) then --UIManager.OpenPanel(UIName.OperatingPanel,{tabIndex =1,extraParam =2}) UIManager.OpenPanel(UIName.RewardItemSingleShowPopup, 20)--元素神符 end self:RechargeType(reChargeType) end function UpView:RechargeType(_type) if _type == UpViewRechargeType.Energy or _type == UpViewRechargeType.Gold or _type == UpViewRechargeType.ChallengeTicket or _type == UpViewRechargeType.SpiritTicket or _type == UpViewRechargeType.GhostRing or _type == UpViewRechargeType.EliteCarbonTicket or _type == UpViewRechargeType.LightRing or _type == UpViewRechargeType.AdventureAlianInvasionTicket or _type == UpViewRechargeType.MonsterCampTicket then --功能快捷购买 UIManager.OpenPanel(UIName.QuickPurchasePanel, { type = _type }) elseif _type == UpViewRechargeType.DemonCrystal then -- 妖晶兑换 UIManager.OpenPanel(UIName.ShopExchangePopup, SHOP_TYPE.FUNCTION_SHOP, 10013, "兑换妖晶") elseif _type == UpViewRechargeType.SoulCrystal then -- 充值商店 if not MapManager.isInMap then if not ShopManager.IsActive(SHOP_TYPE.SOUL_STONE_SHOP) then PopupTipPanel.ShowTip("商店暂未开放") return end UIManager.OpenPanel(UIName.MainShopPanel, SHOP_TYPE.SOUL_STONE_SHOP) end elseif _type == UpViewRechargeType.GrowthAmulet or _type == UpViewRechargeType.Yaoh or _type == UpViewRechargeType.Panacea or _type == UpViewRechargeType.JYD or _type==UpViewRechargeType.LuckyTreasure or _type==UpViewRechargeType.AdvancedTreasure or _type==UpViewRechargeType.StarFireBuLingStone or _type==UpViewRechargeType.FixforDan or _type==UpViewRechargeType.FriendPoint or _type==UpViewRechargeType.Iron or _type==UpViewRechargeType.ChinaHas or _type==UpViewRechargeType.FindFairy or _type==UpViewRechargeType.StarSoul or _type==UpViewRechargeType.ChoasCoin or _type==UpViewRechargeType.SpiritJade or _type==UpViewRechargeType.BadgeGlory or _type==UpViewRechargeType.TopMatchCoin or _type==UpViewRechargeType.GuildToken then UIManager.OpenPanel(UIName.RewardItemSingleShowPopup, _type) --elseif _type==UpViewRechargeType.StarFireBuLingStone then -- -- 分解 -- JumpManager.GoJump(24001) --elseif _type==UpViewRechargeType.SpiritJade then -- -- 密盒 -- if UIManager.IsOpen(UIName.SecretBoxPanel) then -- UIManager.OpenPanel(UIName.RewardItemSingleShowPopup, _type) -- else -- JumpManager.GoJump(21001) -- end --elseif _type==UpViewRechargeType.BadgeGlory then -- -- 竞技场 -- JumpManager.GoJump(8001) --elseif _type==UpViewRechargeType.StarSoul then -- -- 魂印分解 -- JumpManager.GoJump(24004) --elseif _type==UpViewRechargeType.FriendPoint then -- -- 好友 -- JumpManager.GoJump(25001) --elseif _type==UpViewRechargeType.GuildToken then -- -- 公会主界面 -- JumpManager.GoJump(4001) --elseif _type==UpViewRechargeType.ChoasCoin then -- -- 混沌玉 -- if UIManager.IsOpen(UIName.ElementDrawCardPanel) then -- UIManager.OpenPanel(UIName.RewardItemSingleShowPopup, _type) -- else -- JumpManager.GoJump(1002) -- end --elseif _type==UpViewRechargeType.TopMatchCoin then -- -- 至尊之证 -- if ActTimeCtrlManager.SingleFuncState(FUNCTION_OPEN_TYPE.ARENA) then -- --UIManager.OpenPanel(UIName.ArenaTopMatchPanel) -- UIManager.OpenPanel(UIName.RewardItemSingleShowPopup, _type) -- else -- PopupTipPanel.ShowTip("竞技场暂未开启") -- end end end return UpView