miduo_client/Assets/ManagedResources/~Lua/Modules/MonsterCamp/GodsWayTowerPanel.lua

372 lines
16 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.

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.becomeAGodText = Util.GetGameObject(self.gameObject, "InfoRoot/bottomLayout/tips2"):GetComponent("Text")
this.becomeAGodText1 = Util.GetGameObject(self.gameObject, "InfoRoot/bottomLayout/tips")
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/btnRankImg/btnRank")
this.btnRankRoot = Util.GetGameObject(self.gameObject, "InfoRoot/btnRankImg")
this.btnFormation = Util.GetGameObject(self.gameObject, "InfoRoot/btnFormationBg/btnFormation")
this.btnHelpFightObj = Util.GetGameObject(self.gameObject, "InfoRoot/btnHelpFightBg")
this.btnHelpFight = Util.GetGameObject(self.gameObject, "InfoRoot/btnHelpFightBg/btnHelpFight")
Util.GetGameObject(self.gameObject, "InfoRoot/btnHelpFightBg/btnHelpFightText"):GetComponent("Text").text = Language
[11889]
this.btnHelpFightRed = Util.GetGameObject(this.btnHelpFight, "redPoint")
this.btnHelpFight:GetComponent("Image").sprite = this.spLoader:LoadSprite("godsWayTower_treasure")
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.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(Language[11890])
return
end
LogError("GetTimeStamp()==" .. GetTimeStamp() .. " showTime==" .. showTime)
if GetTimeStamp() - showTime < 60 then
PopupTipPanel.ShowTip(Language[11891])
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(Language[11884])
return
else
if BagManager.GetItemCountById(itemId) < costNum then
PopupTipPanel.ShowTip(string.format(Language[10320], GetLanguageStrById(itemConfig[itemId].Name)))
return
end
MsgPanel.ShowTwo(string.format(Language[10684], 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, Language[10685], Language[10686])
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(Language[11892])
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 = Language[11887] .. freeTimes
this.buyMoppingTimes.text = Language[11643] .. 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)
if curType == 3 then
this.UpView:OnOpen({ showType = UpViewOpenType.ShowLeft, panelType = PanelType.BecomeAGod })
else
this.UpView:OnOpen({ showType = UpViewOpenType.ShowLeft, panelType = PanelType.MonsterCamp })
end
end
function this.GetBoxShowState(hangupTime)
LogError("挂机时长 hangupTime " .. hangupTime)
if curFloor == 0 then
this.rewardTxt.text = TimeToHM(0)
return 0
end
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)
return state
end
--界面打开时调用(用于子类重写)
function GodsWayTowerPanel:OnShow()
LogError("刷新多队塔界面---------" .. curType)
--trailData = MonsterCampManager.GetCurFourElementMonsterInfo(curType)
-- if trailData.openState == 0 then
-- self:ClosePanel()
-- return
-- end
curFloor = GodsWayTowerManager.GetTowerFloorByType(curType)
local curId = 0
if curType == 1 then
curId = ActivityGiftManager.GetActivityIdByType(ActivityTypeDef.godsWayTowerTreasure_two)
this.becomeAGodText1.gameObject:SetActive(true)
this.becomeAGodText.gameObject:SetActive(false)
this.btnRank.gameObject:SetActive(true)
elseif curType == 2 then
curId = ActivityGiftManager.GetActivityIdByType(ActivityTypeDef.godsWayTowerTreasure_three)
this.becomeAGodText1.gameObject:SetActive(true)
this.becomeAGodText.gameObject:SetActive(false)
this.btnRank.gameObject:SetActive(true)
else
this.btnRank.gameObject:SetActive(false)
this.btnRankRoot.gameObject:SetActive(false)
curId = 0
this.becomeAGodText1.gameObject:SetActive(false)
this.becomeAGodText.gameObject:SetActive(true)
local curDay = math.ceil((CalculateSecondsNowTo_N_OClock(0) + GetTimeStamp() - PlayerManager.userCreateTime) /
86400) + 1
local floorPerDay = tonumber(ConfigManager.GetConfigData(ConfigName.SpecialConfig, 193).Value)
local floorLimit = curDay * floorPerDay
this.becomeAGodText.text = "当前可挑战层数上限" .. floorLimit .. "功能开启后每天解锁20层挑战上限"
end
this.btnHelpFightObj:SetActive(curId ~= 0)
this.moppingUpBtn:SetActive(curFloor ~= 0 and curType ~= 3)
storeDataId, itemId, costNum = GodsWayTowerManager.GetCost(curType)
if curType == 1 then
this.titleText.text = Language[11635]
this.freeMoppingTimes.gameObject:SetActive(true)
this.buyMoppingTimes.gameObject:SetActive(true)
this.addBtn.gameObject:SetActive(true)
elseif curType == 2 then
this.titleText.text = Language[11636]
this.freeMoppingTimes.gameObject:SetActive(true)
this.buyMoppingTimes.gameObject:SetActive(true)
this.addBtn.gameObject:SetActive(true)
else
this.titleText.text = "主角神塔"
this.freeMoppingTimes.gameObject:SetActive(false)
this.buyMoppingTimes.gameObject:SetActive(false)
this.addBtn.gameObject:SetActive(false)
end
--this.canFightWaves.text = "可挑战层数:"..trailData.canFightTime
this.canFightWaves.gameObject:SetActive(false)
freeTimes, buyTimes = GodsWayTowerManager.GetTimeTip(curType)
this.freeMoppingTimes.text = Language[11887] .. freeTimes
this.buyMoppingTimes.text = Language[11643] .. 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=#1CC853>(+%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