miduo_client/Assets/ManagedResources/~Lua/View/UpView.lua

398 lines
14 KiB
Lua
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

UpView = {}
local ArenaSetting = ConfigManager.GetConfig(ConfigName.ArenaSetting)
local StoreTypeConfig = ConfigManager.GetConfig(ConfigName.StoreTypeConfig)
local _ItemMaxNum = 4
function UpView:New(gameObject)
local u = {}
u.gameObject = gameObject
u.transform = gameObject.transform
setmetatable(u, { __index = UpView })
return u
end
--- 要显示加号的类型,有购买功能的物品要配置在这里显示 加号
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,
UpViewRechargeType.SummonStamps,
}
-- 判断是否显示加号
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.itemList = 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.itemList = args.panelType
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 = self.itemList
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 itemId = self.itemList[i]
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 itemId = self.itemList[i]
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 = self.itemList[index]
Log("reChargeType:"..reChargeType)
--24暂时关闭删除这里就行
if (reChargeType==16 or reChargeType==20 or reChargeType==19 or reChargeType==61) then
return
end
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.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, "兑换妖晶")
-- 充值商店
if not MapManager.isInMap then
if not ShopManager.IsActive(SHOP_TYPE.SOUL_STONE_SHOP) then
PopupTipPanel.ShowTip(Language[10438])
return
end
UIManager.OpenPanel(UIName.MainRechargePanel, 1)
else
PopupTipPanel.ShowTip(Language[12099])
end
elseif _type == UpViewRechargeType.SoulCrystal then
-- 充值商店
if not MapManager.isInMap then
if not ShopManager.IsActive(SHOP_TYPE.SOUL_STONE_SHOP) then
PopupTipPanel.ShowTip(Language[10438])
return
end
UIManager.OpenPanel(UIName.MainRechargePanel, 1)
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 or
_type==UpViewRechargeType.SpiritTicket or
_type==UpViewRechargeType.SummonStamps
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