333 lines
14 KiB
Lua
333 lines
14 KiB
Lua
require("Base/BasePanel")
|
||
require("View/GodsWaySingleSingleWave")
|
||
GodsWayTowerPanel = Inherit(BasePanel)
|
||
local itemConfig = ConfigManager.GetConfig(ConfigName.ItemConfig)
|
||
local SpecialConfig = ConfigManager.GetConfigData(ConfigName.SpecialConfig, 159)
|
||
local this = GodsWayTowerPanel
|
||
|
||
this.grid = {}
|
||
this.singledataList = {}
|
||
--this.singlePreList = {}
|
||
|
||
local curType = 0
|
||
local trailData = {}
|
||
local itemId = 0
|
||
local costNum = 0
|
||
local freeTimes = 0
|
||
local buyTimes = 0
|
||
local storeDataId = 0
|
||
local callBack
|
||
local screenwidth
|
||
local maxTime = 0
|
||
local curFloor = 0
|
||
local showTime
|
||
local redTrailType = {
|
||
[1] = RedPointType.PersonTrailHelp,
|
||
[2] = RedPointType.BuddishTrailHelp,
|
||
[3] = RedPointType.DemonTrailHelp,
|
||
[4] = RedPointType.TaoistTrailHelp,
|
||
}
|
||
--初始化组件(用于子类重写)
|
||
function GodsWayTowerPanel:InitComponent()
|
||
maxTime = tonumber(SpecialConfig.Value) * 60
|
||
screenwidth = self.gameObject.transform.rect.width
|
||
this.spLoader = SpriteLoader.New()
|
||
this.UpView = SubUIManager.Open(SubUIConfig.UpView, self.gameObject.transform)
|
||
|
||
this.btnBack = Util.GetGameObject(self.gameObject, "InfoRoot/btnBack")
|
||
this.helpBtn = Util.GetGameObject(self.gameObject, "InfoRoot/help")
|
||
this.helpBtn:SetActive(false)
|
||
this.helpPosition = this.helpBtn:GetComponent("RectTransform").localPosition
|
||
this.pre = Util.GetGameObject(self.gameObject, "InfoRoot/pre")
|
||
this.grid = Util.GetGameObject(self.gameObject, "InfoRoot/grid")
|
||
local rootHight = this.grid.transform.rect.height
|
||
local width = this.grid.transform.rect.width
|
||
this.scrollView = SubUIManager.Open(SubUIConfig.ScrollCycleView, this.grid.transform,
|
||
this.pre, nil, Vector2.New(width, rootHight), 1, 1, Vector2.New(0, 0))
|
||
this.scrollView.moveTween.MomentumAmount = 1
|
||
this.scrollView.moveTween.Strength = 2
|
||
-- 挂机奖励
|
||
this.rewardList = {}
|
||
this.titleText = Util.GetGameObject(self.gameObject, "InfoRoot/tiitleRoot/title"):GetComponent("Text")
|
||
this.moppingUpBtn = Util.GetGameObject(self.gameObject, "InfoRoot/bottomLayout/moppingUpBtn")
|
||
this.canFightWaves = Util.GetGameObject(self.gameObject, "InfoRoot/bottomLayout/canFightWaves"):GetComponent("Text")
|
||
this.freeMoppingTimes = Util.GetGameObject(self.gameObject, "InfoRoot/bottomLayout/freeMoppingTimes"):GetComponent(
|
||
"Text")
|
||
this.buyMoppingTimes = Util.GetGameObject(self.gameObject, "InfoRoot/bottomLayout/buyMoppingTimes"):GetComponent(
|
||
"Text")
|
||
this.addBtn = Util.GetGameObject(self.gameObject, "InfoRoot/bottomLayout/addBtn")
|
||
this.btnRank = Util.GetGameObject(self.gameObject, "InfoRoot/btnRank")
|
||
this.btnFormation = Util.GetGameObject(self.gameObject, "InfoRoot/btnFormation")
|
||
this.btnHelpFight = Util.GetGameObject(self.gameObject, "InfoRoot/btnHelpFight")
|
||
this.btnHelpFightRed = Util.GetGameObject(this.btnHelpFight, "redPoint")
|
||
-- this.btnHelpFight:GetComponent("Image").sprite = this.spLoader:LoadSprite("godsWayTower_treasure_zh")
|
||
this.rewardItemPre = Util.GetGameObject(self.gameObject, "InfoRoot/rewardContent/item")
|
||
this.rewardGrid = Util.GetGameObject(self.gameObject, "InfoRoot/rewardContent")
|
||
this.rewardTxt = Util.GetGameObject(self.gameObject, "InfoRoot/getBoxReward/time/Text"):GetComponent("Text")
|
||
--this.progress = Util.GetGameObject(self.gameObject, "InfoRoot/getBoxReward/fill"):GetComponent("Image")
|
||
this.rewardRed = Util.GetGameObject(self.gameObject, "InfoRoot/getBoxReward/rewardBoxRedPoint")
|
||
this.btn_reward = Util.GetGameObject(self.gameObject, "InfoRoot/getBoxReward")
|
||
end
|
||
|
||
--绑定事件(用于子类重写)
|
||
function GodsWayTowerPanel:BindEvent()
|
||
Util.AddClick(this.btnBack, function()
|
||
self:ClosePanel()
|
||
if callBack then callBack() end
|
||
end)
|
||
Util.AddClick(this.helpBtn, function()
|
||
|
||
end)
|
||
Util.AddClick(this.btn_reward, function()
|
||
if curFloor == 0 then
|
||
PopupTipPanel.ShowTip("至少通关一层才可领取挂机奖励")
|
||
return
|
||
end
|
||
LogError("GetTimeStamp()==" .. GetTimeStamp() .. " showTime==" .. showTime)
|
||
if GetTimeStamp() - showTime < 60 then
|
||
PopupTipPanel.ShowTip("累计挂机奖励中")
|
||
return
|
||
end
|
||
NetManager.RequestDuoDuiReward(curType, 1, function(msg)
|
||
UIManager.OpenPanel(UIName.RewardItemPopup, msg.drop, 1)
|
||
GodsWayTowerManager.SetTowerTimeByType(curType, GetTimeStamp())
|
||
showTime = GodsWayTowerManager.GetTowerTimeByType(curType)
|
||
this.GetBoxShowState(GetTimeStamp())
|
||
end)
|
||
end)
|
||
Util.AddClick(this.addBtn, function()
|
||
if buyTimes < 1 then
|
||
PopupTipPanel.ShowTip("今日已无购买次数")
|
||
return
|
||
else
|
||
if BagManager.GetItemCountById(itemId) < costNum then
|
||
PopupTipPanel.ShowTip(string.format(Language[10298], itemConfig[itemId].Name))
|
||
return
|
||
end
|
||
MsgPanel.ShowTwo(string.format("是否花费%s%s购买一次扫荡次数?", costNum, itemConfig[itemId].Name), function() end,
|
||
function()
|
||
ShopManager.RequestBuyShopItem(SHOP_TYPE.FUNCTION_SHOP, storeDataId, 1, function()
|
||
local buyId = GodsWayTowerManager.GetTowerBuyIdByType(curType)
|
||
PrivilegeManager.RefreshPrivilegeUsedTimes(buyId, 1)
|
||
this.UpdatePrivilage()
|
||
end)
|
||
end, "取消", "确定")
|
||
end
|
||
end)
|
||
Util.AddClick(this.btnRank, function()
|
||
UIManager.OpenPanel(UIName.RankingSingleListPanel, rankKingList[curType + 48])
|
||
end)
|
||
Util.AddClick(this.btnFormation, function()
|
||
UIManager.OpenPanel(UIName.GodsWayMyTeamPanel, curType)
|
||
end)
|
||
Util.AddClick(this.btnHelpFight, function()
|
||
UIManager.OpenPanel(UIName.GodsWayTreasurePanel, curType)
|
||
end)
|
||
Util.AddClick(this.moppingUpBtn, function()
|
||
if freeTimes < 1 then
|
||
PopupTipPanel.ShowTip("扫荡次数不足")
|
||
return
|
||
end
|
||
-- if not ConfigManager.TryGetConfigDataByDoubleKey(ConfigName.DuoDuiTower,"Type",curType,"TowerNumber",curFloor + 1) then
|
||
-- PopupTipPanel.ShowTip("已通关全部层数,无法继续挑战")
|
||
-- return
|
||
-- end
|
||
-- if FormationManager.CheckFormationValid(curType + 3000) then
|
||
-- MonsterCampManager.ExecuteFightBattle(trailData.monsterWave + 1 ,0,function() this:OnShow() end,curType,true)
|
||
-- else
|
||
-- PopupTipPanel.ShowTip("编队不能为空")
|
||
-- return
|
||
-- end
|
||
NetManager.RequestDuoDuiReward(curType, 2, function(msg)
|
||
UIManager.OpenPanel(UIName.RewardItemPopup, msg.drop, 1)
|
||
local freeId = GodsWayTowerManager.GetTowerFreeIdByType(curType)
|
||
PrivilegeManager.RefreshPrivilegeUsedTimes(freeId, 1)
|
||
self.UpdatePrivilage()
|
||
end)
|
||
end)
|
||
end
|
||
|
||
this.UpdatePrivilage = function()
|
||
-- if this.singledataList[trailData.monsterWave] then
|
||
-- this.singledataList[trailData.monsterWave]:UpdatePrivilage()
|
||
-- end
|
||
storeDataId, itemId, costNum = GodsWayTowerManager.GetCost(curType)
|
||
freeTimes, buyTimes = GodsWayTowerManager.GetTimeTip(curType)
|
||
this.freeMoppingTimes.text = freeTimes
|
||
this.buyMoppingTimes.text = buyTimes
|
||
end
|
||
--添加事件监听(用于子类重写)
|
||
function GodsWayTowerPanel:AddListener()
|
||
Game.GlobalEvent:AddEvent(GameEvent.FourEle.UpdatePri, self.UpdatePrivilage, self)
|
||
Game.GlobalEvent:AddEvent(GameEvent.FourEle.RefreshView, self.OnShow, self)
|
||
end
|
||
|
||
--移除事件监听(用于子类重写)
|
||
function GodsWayTowerPanel:RemoveListener()
|
||
Game.GlobalEvent:RemoveEvent(GameEvent.FourEle.UpdatePri, self.UpdatePrivilage, self)
|
||
Game.GlobalEvent:RemoveEvent(GameEvent.FourEle.RefreshView, self.OnShow, self)
|
||
end
|
||
|
||
--界面打开时调用(用于子类重写)
|
||
function GodsWayTowerPanel:OnOpen(index)
|
||
curType = index
|
||
--BindRedPointObject(redTrailType[curType],this.btnHelpFightRed)
|
||
this.UpView:OnOpen({ showType = UpViewOpenType.ShowLeft, panelType = PanelType.MonsterCamp })
|
||
end
|
||
|
||
function this.GetBoxShowState(hangupTime)
|
||
-- Log("挂机时长 hangupTime " .. hangupTime)
|
||
local state = 0
|
||
local curTime = GetTimeStamp()
|
||
local addTime = curTime - hangupTime
|
||
if addTime > maxTime then
|
||
hangupTime = maxTime
|
||
else
|
||
hangupTime = addTime
|
||
end
|
||
if hangupTime < AdventureManager.adventureRefresh then
|
||
state = 0
|
||
elseif hangupTime >= AdventureManager.adventureRefresh and hangupTime < AdventureManager.adventureBoxShow[1] then
|
||
state = 1
|
||
elseif hangupTime >= AdventureManager.adventureRefresh and hangupTime < AdventureManager.adventureBoxShow[2] then
|
||
state = 2
|
||
else
|
||
state = 3
|
||
end
|
||
|
||
--FightPointPassManager.SetBoxState(state)
|
||
-- if hangupTime > (AdventureManager.adventureOffline*3600) then
|
||
-- hangupTime = AdventureManager.adventureOffline*3600
|
||
-- end
|
||
if hangupTime < 0 then
|
||
hangupTime = 0
|
||
end
|
||
this.rewardTxt.text = TimeToHM(hangupTime)
|
||
--this.progress.fillAmount = hangupTime / (AdventureManager.adventureOffline * 3600)
|
||
return state
|
||
end
|
||
|
||
--界面打开时调用(用于子类重写)
|
||
function GodsWayTowerPanel:OnShow()
|
||
LogError("刷新多队塔界面---------")
|
||
--trailData = MonsterCampManager.GetCurFourElementMonsterInfo(curType)
|
||
-- if trailData.openState == 0 then
|
||
-- self:ClosePanel()
|
||
-- return
|
||
-- end
|
||
curFloor = GodsWayTowerManager.GetTowerFloorByType(curType)
|
||
this.moppingUpBtn:SetActive(curFloor ~= 0)
|
||
local curId = 0
|
||
if curType == 1 then
|
||
curId = ActivityGiftManager.GetActivityIdByType(ActivityTypeDef.godsWayTowerTreasure_two)
|
||
else
|
||
curId = ActivityGiftManager.GetActivityIdByType(ActivityTypeDef.godsWayTowerTreasure_three)
|
||
end
|
||
this.btnHelpFight:SetActive(curId ~= 0)
|
||
storeDataId, itemId, costNum = GodsWayTowerManager.GetCost(curType)
|
||
if curType == 1 then
|
||
this.titleText.text = "双队比拼"
|
||
else
|
||
this.titleText.text = "三连决战"
|
||
end
|
||
--this.canFightWaves.text = "可挑战层数:"..trailData.canFightTime
|
||
this.canFightWaves.gameObject:SetActive(false)
|
||
freeTimes, buyTimes = GodsWayTowerManager.GetTimeTip(curType)
|
||
this.freeMoppingTimes.text = freeTimes
|
||
this.buyMoppingTimes.text = buyTimes
|
||
this.InitMonsterShow()
|
||
this.IntiReward()
|
||
showTime = GodsWayTowerManager.GetTowerTimeByType(curType)
|
||
this.GetBoxShowState(showTime)
|
||
-- local waves = MonsterCampManager.GetFourElementTotalWave()
|
||
-- if not PlayerPrefs.HasKey("FourElement"..PlayerManager.uid) then
|
||
-- PlayerPrefs.SetInt("FourElement"..PlayerManager.uid,-1)
|
||
-- end
|
||
-- if waves ~= PlayerPrefs.GetInt("FourElement"..PlayerManager.uid) then
|
||
-- PlayerPrefs.SetInt("FourElement"..PlayerManager.uid,waves)
|
||
-- local propertyId = SacredTreeManager.GetUnLockNewProperty(waves)
|
||
-- if propertyId > 0 then
|
||
-- Timer.New(function()
|
||
-- UIManager.OpenPanel(UIName.RewardItemPopup,nil,nil,nil,CompShowType.fourElement,nil,nil,nil,propertyId)
|
||
-- end,0.2):Start()
|
||
-- local power = FormationManager.GetFormationPower(FormationTypeDef.FORMATION_NORMAL)
|
||
-- if power - MonsterCampManager.oldpower > 0 then
|
||
-- UIManager.OpenPanel(UIName.WarPowerChangeNotifyPanelV2,{oldValue = MonsterCampManager.oldpower,newValue = power})
|
||
-- end
|
||
-- end
|
||
-- end
|
||
end
|
||
|
||
function this.SingleDataShow(go, data)
|
||
local singledata = GodsWaySingleSingleWave:New(go)
|
||
--go:GetComponent("RectTransform").sizeDelta=Vector2.New(screenwidth,380)
|
||
singledata:InitComponent(go, data, curType)
|
||
singledata:OnOpen()
|
||
return singledata
|
||
end
|
||
|
||
function this.InitMonsterShow()
|
||
--local curwaves = trailData.monsterWave + 1 --当前可挑战层
|
||
local monsterInfo = GodsWayTowerManager.GetTowerDataByType(curType) --MonsterCampManager.GetFourElementMonstersInfo(curType,curwaves)
|
||
LogError("monsterInfo==" .. #monsterInfo)
|
||
table.sort(monsterInfo, function(a, b) return a.wave > b.wave end)
|
||
this.scrollView:SetData(monsterInfo, function(index, go)
|
||
local tempData = this.SingleDataShow(go, monsterInfo[index])
|
||
this.singledataList[monsterInfo[index].wave] = tempData
|
||
--this.singlePreList[go] = this.singledataList[monsterInfo[index].wave]
|
||
end, true, true)
|
||
this.scrollView:SetIndex(#monsterInfo)
|
||
-- if MonsterCampManager.CurOffsetIndex < 0 then
|
||
-- this.scrollView:SetIndex((#monsterInfo-trailData.monsterWave-2))
|
||
-- else
|
||
-- this.scrollView:SetIndex((#monsterInfo-MonsterCampManager.CurOffsetIndex-2))
|
||
-- end
|
||
end
|
||
|
||
function this.IntiReward()
|
||
local rewardData
|
||
rewardData = GodsWayTowerManager.GetCurrFloorRewardByType(curType)
|
||
LogError("获取当前层挂机奖励")
|
||
for i = 1, #rewardData do
|
||
if not this.rewardList[i] then
|
||
local go = {}
|
||
go.item = newObjToParent(this.rewardItemPre, this.rewardGrid)
|
||
go.icon = Util.GetGameObject(go.item, "iconBg/icon"):GetComponent("Image")
|
||
go.text = Util.GetGameObject(go.item, "rewardbg/context"):GetComponent("Text")
|
||
this.rewardList[i] = go
|
||
end
|
||
|
||
this.rewardList[i].icon.sprite = SetIcon(this.spLoader, rewardData[i][1])
|
||
|
||
local addValue = FightPointPassManager.GetItemVipValue(rewardData[i][1])
|
||
local baseValue = rewardData[i][2]
|
||
if addValue - 1 <= 0 then
|
||
this.rewardList[i].text.text = "+" .. rewardData[i][2]
|
||
else
|
||
local valueShow = math.round((addValue - 1) * baseValue)
|
||
this.rewardList[i].text.text = string.format("+%s\n<color=#00FF00>(+%s)</color>", baseValue, valueShow)
|
||
end
|
||
end
|
||
end
|
||
|
||
--界面关闭时调用(用于子类重写)
|
||
function GodsWayTowerPanel:OnClose()
|
||
ClearRedPointObject(redTrailType[curType], this.btnHelpFightRed)
|
||
MonsterCampManager.CurOffsetIndex = -1
|
||
CheckRedPointStatus(RedPointType.godsWayTower)
|
||
end
|
||
|
||
--界面销毁时调用(用于子类重写)
|
||
function GodsWayTowerPanel:OnDestroy()
|
||
this.spLoader:Destroy()
|
||
for k, v in pairs(this.singledataList) do
|
||
v:OnDestroy()
|
||
end
|
||
--this.singlePreList = {}
|
||
this.singledataList = {}
|
||
SubUIManager.Close(this.scrollView)
|
||
this.spLoader:Destroy()
|
||
end
|
||
|
||
return GodsWayTowerPanel
|