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

392 lines
14 KiB
Lua

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,
UpViewRechargeType.HeroExchange,
UpViewRechargeType.TianGong,
UpViewRechargeType.EndlessCoin,
UpViewRechargeType.XianLingCao,
UpViewRechargeType.PuTiZi,
UpViewRechargeType.YHMF,
UpViewRechargeType.QuLingBi,
UpViewRechargeType.DingKunShenChu,
UpViewRechargeType.YeQiuQuan,
UpViewRechargeType.HuaLingFu,
UpViewRechargeType.XuanHuangZhiQi,
UpViewRechargeType.XiuXian,
UpViewRechargeType.SuiFanXingCheng,
UpViewRechargeType.LuoFuJingShi,
UpViewRechargeType.XunBaoMiZong,
}
-- 判断是否显示加号
local function _IsShowPlus(_type)
-- 判断是否是可购买的类型
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.spLoader = SpriteLoader.New()
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
--界面打开时调用(用于子类重写)
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.spLoader:Destroy()
self:_ClearRP()
if self.timer then
self.timer:Stop()
self.timer = nil
end
self.IsClose = true
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()
if self.IsClose then
return
end
-- 先清一遍红点
self:_ClearRP()
local panelShowItemList = self.itemList
for i = 1, _ItemMaxNum do
if panelShowItemList[i] then
if not IsNull(self.cnyList[i]) and self.cnyList[i].gameObject then
self.cnyList[i].gameObject:SetActive(true)
Util.GetGameObject(self.cnyList[i].gameObject, "icon"):GetComponent("Image").sprite = SetIcon(self.spLoader, panelShowItemList[i])
Util.GetGameObject(self.cnyList[i].gameObject, "addFlag"):SetActive(_IsShowPlus(panelShowItemList[i]))
if panelShowItemList[i] == 20 then
Util.GetGameObject(self.cnyList[i].gameObject, "addFlag"):SetActive(true)
end
if panelShowItemList[i] == 2 then
Util.GetGameObject(self.cnyList[i].gameObject, "value"):GetComponent("Text").text = PrintWanNum(BagManager.GetTotalItemNum(panelShowItemList[i])) .. "/" .. PlayerManager.maxEnergy
elseif panelShowItemList[i] == 44 then
Util.GetGameObject(self.cnyList[i].gameObject, "value"):GetComponent("Text").text = PrintWanNum(BagManager.GetTotalItemNum(panelShowItemList[i])).."/"..PrivilegeManager.GetPrivilegeNumber(9)
elseif panelShowItemList[i] == 53 then
Util.GetGameObject(self.cnyList[i].gameObject, "value"):GetComponent("Text").text = PrintWanNum(BagManager.GetTotalItemNum(panelShowItemList[i])).."/"..MonsterCampManager.GetMaxCostItem()
elseif panelShowItemList[i] == 87 then
Util.GetGameObject(self.cnyList[i].gameObject, "value"):GetComponent("Text").text = PrintWanNum(BagManager.GetTotalItemNum(panelShowItemList[i]))
else
Util.GetGameObject(self.cnyList[i].gameObject, "value"):GetComponent("Text").text = PrintWanNum(BagManager.GetTotalItemNum(panelShowItemList[i]))
end
-- 绑定红点
local redpot = Util.GetGameObject(self.cnyList[i].gameObject, "redpot")
redpot:SetActive(false)
self:_BindRP(panelShowItemList[i], redpot)
end
else
if not IsNull(self.cnyList[i]) and self.cnyList[i].gameObject then
self.cnyList[i].gameObject:SetActive(false)
end
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)
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)
if (not RECHARGEABLE) and (reChargeType==16 or reChargeType==20 or reChargeType==19 or reChargeType==61) then--(是否开启充值)
return
end
if(reChargeType==20) then
UIManager.OpenPanel(UIName.RewardItemSingleShowPopup, 20)--元素神符
end
self:RechargeType(reChargeType)
end
function UpView:RechargeType(_type)
if MapManager.Mapping then
PopupTipPanel.ShowTip(Language[12040])
return
end
if _type == UpViewRechargeType.Energy or
_type == UpViewRechargeType.Gold or
_type == UpViewRechargeType.ChallengeTicket or
_type == UpViewRechargeType.EliteCarbonTicket or
_type == UpViewRechargeType.LightRing or
_type == UpViewRechargeType.AdventureAlianInvasionTicket or
_type == UpViewRechargeType.MonsterCampTicket or
_type==UpViewRechargeType.DingKunShenChu
then
--功能快捷购买
UIManager.OpenPanel(UIName.QuickPurchasePanel, { type = _type })
elseif _type == UpViewRechargeType.HeroExchange then--神将置换
JumpManager.GoJump(1002)
elseif _type == UpViewRechargeType.DemonCrystal then
LogError(tostring(SERVER_VERSION))
if SERVER_VERSION == 1 then
JumpManager.GoJump(36010)
return
end
-- 充值商店
if not ShopManager.IsActive(SHOP_TYPE.SOUL_STONE_SHOP) then
PopupTipPanel.ShowTip(Language[10422])
return
end
JumpManager.GoJump(36008)
elseif _type == UpViewRechargeType.SoulCrystal then
-- 充值商店
if not MapManager.Mapping then
if not ShopManager.IsActive(SHOP_TYPE.SOUL_STONE_SHOP) then
PopupTipPanel.ShowTip(Language[10422])
return
end
JumpManager.GoJump(36008)
end
elseif _type == UpViewRechargeType.YeQiuQuan then--跳限时商市
if UIManager.IsOpen(UIName.TenRecruitPanel) then
UIManager.ClosePanel(UIName.TenRecruitPanel)
end
JumpManager.GoJump(40014)
elseif _type == UpViewRechargeType.HuaLingFu then--跳灵兽特惠
JumpManager.GoJump(40010)
elseif _type == UpViewRechargeType.XunBaoMiZong then--寻宝迷踪->主题活动日任务
JumpManager.GoJump(40030)
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 or
_type==UpViewRechargeType.TianGong or
_type==UpViewRechargeType.PuTiZi or
_type==UpViewRechargeType.XianLingCao or
_type==UpViewRechargeType.YHMF or
_type==UpViewRechargeType.EndlessCoin or
_type==UpViewRechargeType.QuLingBi or
_type==UpViewRechargeType.XuanHuangZhiQi or
_type==UpViewRechargeType.LuoFuJingShi or
_type==UpViewRechargeType.XiuXian or
_type==UpViewRechargeType.SuiFanXingCheng then
UIManager.OpenPanel(UIName.RewardItemSingleShowPopup, _type)
end
end
return UpView