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

251 lines
11 KiB
Lua
Raw Normal View History

2021-05-25 14:51:26 +08:00
require("Base/BasePanel")
require("View/MonsterCampSingleWave")
MonsterCampNewPanel = Inherit(BasePanel)
local itemConfig = ConfigManager.GetConfig(ConfigName.ItemConfig)
local this = MonsterCampNewPanel
this.grid = {}
this.singledataList = {}
local itemId = 0
local costNum = 0
local freeTimes = 0
local buyTimes = 0
local storeDataId = 0
local callBack
local screenwidth
2021-07-12 16:35:54 +08:00
local isClick = false
2021-05-25 14:51:26 +08:00
-- local redTrailType = {
-- [1] = RedPointType.PersonTrailHelp,
-- [2] = RedPointType.BuddishTrailHelp,
-- [3] = RedPointType.DemonTrailHelp,
-- [4] = RedPointType.TaoistTrailHelp,
-- }
--初始化组件(用于子类重写)
function MonsterCampNewPanel:InitComponent()
this.spLoader = SpriteLoader.New()
2021-05-25 14:51:26 +08:00
this.UpView = SubUIManager.Open(SubUIConfig.UpView, self.gameObject.transform)
this.btnBack = Util.GetGameObject(self.gameObject, "InfoRoot/btnBack")
2021-05-25 20:50:23 +08:00
this.helpBtn = Util.GetGameObject(self.gameObject, "InfoRoot/help")
this.helpBtn:SetActive(false)
2021-05-25 14:51:26 +08:00
this.helpPosition=this.helpBtn:GetComponent("RectTransform").localPosition
this.pre = Util.GetGameObject(self.gameObject, "InfoRoot/pre")
this.grid = Util.GetGameObject(self.gameObject, "InfoRoot/grid")
screenwidth=self.gameObject.transform.rect.width
2021-05-25 14:51:26 +08:00
local rootHight = this.grid.transform.rect.height
local width = this.grid.transform.rect.width
this.scrollView = SubUIManager.Open(SubUIConfig.ScrollCycleView,this.grid.transform,
2023-08-30 20:33:29 +08:00
this.pre, nil, Vector2.New(width, rootHight), 1, 2, Vector2.New(230, 0))
2021-05-25 14:51:26 +08:00
this.scrollView.moveTween.MomentumAmount = 1
this.scrollView.moveTween.Strength = 2
this.titleText = Util.GetGameObject(self.gameObject, "InfoRoot/tiitleRoot/title"):GetComponent("Text")
2021-05-25 20:50:23 +08:00
this.moppingUpBtn = Util.GetGameObject(self.gameObject, "InfoRoot/bottomLayout/moppingUpBtn")
Util.GetGameObject(self.gameObject, "InfoRoot/bottomLayout/moppingUpBtn/Text"):GetComponent("Text").text = "快速挑战"
2021-05-25 14:51:26 +08:00
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")
2021-05-25 14:51:26 +08:00
this.btnHelpFight = Util.GetGameObject(self.gameObject, "InfoRoot/btnHelpFight")
2023-08-30 20:33:29 +08:00
-- this.hintTxt=Util.GetGameObject(self.gameObject, "InfoRoot/hintTxt"):GetComponent("Text")
-- this.hintTxt.fontSize=40
-- this.hintTxt.text="开通超级特权开启快速挑战"
2021-05-25 14:51:26 +08:00
end
--绑定事件(用于子类重写)
function MonsterCampNewPanel:BindEvent()
Util.AddClick(this.btnBack, function ()
self:ClosePanel()
if callBack then callBack() end
end)
Util.AddClick(this.helpBtn, function ()
UIManager.OpenPanel(UIName.HelpPopup,HELP_TYPE.FoueElementPeo,this.helpPosition.x,this.helpPosition.y)
end)
Util.AddClick(this.addBtn, function ()
2021-05-26 10:00:30 +08:00
if buyTimes <= 0 then
2021-05-25 14:51:26 +08:00
PopupTipPanel.ShowTip("今日已无购买次数")
else
if BagManager.GetItemCountById(itemId) < costNum then
2021-05-25 20:50:23 +08:00
PopupTipPanel.ShowTip(string.format(Language[10298], itemConfig[itemId].Name))
2021-05-25 14:51:26 +08:00
return
end
MsgPanel.ShowTwo(string.format("是否花费%s%s购买一次扫荡次数",costNum,itemConfig[itemId].Name),function() end,function()
ShopManager.RequestBuyShopItem(SHOP_TYPE.FUNCTION_SHOP,storeDataId,1,function()
PrivilegeManager.RefreshPrivilegeUsedTimes(PRIVILEGE_TYPE.MONSTERCAMP_BUY_BATTLENUM, 1)
2021-05-26 11:48:44 +08:00
this.UpdatePrivilage()
CheckRedPointStatus(RedPointType.EpicExplore_MoppingUp)
2021-05-25 14:51:26 +08:00
end)
end,"取消","确定")
end
end)
Util.AddClick(this.btnRank, function ()
-- UIManager.OpenPanel(UIName.RankingSingleListPanel,rankKingList[4])]\
UIManager.OpenPanel(UIName.CarbonScoreSortPanel, 2)
end)
Util.AddClick(this.btnFormation, function ()
UIManager.OpenPanel(UIName.FormationPanelV2, FORMATION_TYPE.MONSTER_CAMP, 2)
end)
2021-05-25 14:51:26 +08:00
Util.AddClick(this.btnHelpFight, function ()
MonsterCampManager.preType = 2
UIManager.OpenPanel(UIName.TrialRewardPopup,MonsterCampManager.SetRewardData(),function(id,rewardFunc)
NetManager.DemonsTrialRewardRequest(id, function(msg)
MonsterCampManager.SetRewardWave({id}) --本地记录已领奖励信息
UIManager.OpenPanel(UIName.RewardItemPopup,msg.drop,1,function()
if rewardFunc then
rewardFunc()
end
2021-05-26 11:48:44 +08:00
CheckRedPointStatus(RedPointType.EpicExplore_LevleReward)
2021-05-25 14:51:26 +08:00
end)
end)
end,2)
end)
2021-05-25 20:50:23 +08:00
Util.AddClick(this.moppingUpBtn, function ()
local waveConfig = ConfigManager.TryGetConfigData(ConfigName.FloodConfig,MonsterCampManager.monsterWave)
if not waveConfig then
PopupTipPanel.ShowTip("已通过最高层,无法快速挑战!")
return
end
if FormationManager.CheckFormationValid(FormationTypeDef.MONSTER_CAMP_ATTACK) then
this.QuickStartMonsterFightRequest()
else
local formationList = FormationManager.GetFormationByID(FormationTypeDef.MONSTER_CAMP_ATTACK)
if formationList.teamHeroInfos > 0 then
this.QuickStartMonsterFightRequest()
2021-05-26 11:48:44 +08:00
end
end
2021-05-25 20:50:23 +08:00
end)
2021-05-26 11:48:44 +08:00
BindRedPointObject(RedPointType.EpicExplore_LevleReward,Util.GetGameObject(this.btnHelpFight, "redPoint"))
2021-05-25 14:51:26 +08:00
end
--快速战斗
function this.QuickStartMonsterFightRequest()
if isClick then
return
end
isClick = true
-- 请求战斗结果
NetManager.GetMonsterFightResult(MonsterCampManager.monsterWave, FormationTypeDef.MONSTER_CAMP_ATTACK, function (msg)
local result = {}
result.drop = msg.enventDrop
-- 设置战斗数据用于统计战斗
local _fightData = BattleManager.GetBattleServerData(msg)
BattleRecordManager.SetBattleRecord(_fightData)
--用一个变量接收最近的战斗结果
this.lastBattleResult = {
result = msg.result,
hpList = {},
drop = msg.enventDrop,
}
BattleManager.SetLastBattleResult(this.lastBattleResult,BATTLE_TYPE.MONSTER_CAMP)
if msg.result == 0 then
UIManager.OpenPanel(UIName.BattleFailPopup, nil, true, UIName.MonsterCampNewPanel,BATTLE_TYPE.MONSTER_CAMP)
isClick = false
else
2021-07-12 16:35:54 +08:00
Timer.New(function ()
isClick = false
end,1):Start()
2021-12-10 17:37:07 +08:00
MonsterCampManager.SetMonsterCampCurWave(MonsterCampManager.monsterWave + 1)
UIManager.OpenPanel(UIName.BattleWinPopup, nil, false, BATTLE_TYPE.MONSTER_CAMP, result, true, true,function()
-- UIManager.OpenPanel(UIName.RewardItemPopup,msg.enventDrop,1,function()
this.OnShowPanel()--刷新界面
-- end)
end)
end
end)
end
2021-05-25 14:51:26 +08:00
this.UpdatePrivilage = function()
2021-05-25 20:50:23 +08:00
if this.singledataList[MonsterCampManager.monsterWave - 1] then
this.singledataList[MonsterCampManager.monsterWave - 1]:UpdatePrivilage()
end
2021-05-25 14:51:26 +08:00
storeDataId,itemId,costNum = MonsterCampManager.MonsterCampGetCost()
freeTimes = MonsterCampManager.GetCanBattleCount()
buyTimes = MonsterCampManager.GetCanBuyBattleCount()
2023-08-30 20:33:29 +08:00
this.freeMoppingTimes.text = freeTimes
this.buyMoppingTimes.text = buyTimes
2021-05-25 14:51:26 +08:00
end
--添加事件监听(用于子类重写)
function MonsterCampNewPanel:AddListener()
Game.GlobalEvent:AddEvent(GameEvent.MonsterCamp.UpdatePri, self.UpdatePrivilage,self)
-- Game.GlobalEvent:AddEvent(GameEvent.MonsterCamp.UpdatePanel, this.OnShowPanel)
2021-05-25 14:51:26 +08:00
end
--移除事件监听(用于子类重写)
function MonsterCampNewPanel:RemoveListener()
Game.GlobalEvent:RemoveEvent(GameEvent.MonsterCamp.UpdatePri, self.UpdatePrivilage,self)
-- Game.GlobalEvent:RemoveEvent(GameEvent.MonsterCamp.UpdatePanel, this.OnShowPanel)
2021-05-25 14:51:26 +08:00
end
--界面打开时调用(用于子类重写)
function MonsterCampNewPanel:OnOpen()
this.UpView:OnOpen({showType = UpViewOpenType.ShowLeft, panelType = PanelType.MonsterCamp })
2021-07-12 16:35:54 +08:00
isClick = false
2021-05-25 14:51:26 +08:00
end
--界面打开时调用(用于子类重写)
function MonsterCampNewPanel:OnShow()
this.sortingOrder = self.sortingOrder
2021-05-27 11:07:32 +08:00
this.OnShowPanel()
end
function this.OnShowPanel()
local mission=ActivityGiftManager.GetActivityInfo(ActivityTypeDef.shuaChongTeQuan,2202)
local isBuy= OperatingManager.IsBuyGift(2202) or OperatingManager.IsBuyGift(2203) or OperatingManager.IsBuyGift(2204) or PrivilegeManager.GetPrivilegeRemainValue(2038)>0 or (mission and mission.state>0)
--local isBuy=PrivilegeManager.GetPrivilegeRemainValue(2038)>0
2023-02-13 17:49:11 +08:00
if isBuy then
this.moppingUpBtn:SetActive(true)
2023-08-30 20:33:29 +08:00
-- this.hintTxt.gameObject:SetActive(false)
2023-02-13 17:49:11 +08:00
else
this.moppingUpBtn:SetActive(false)
2023-08-30 20:33:29 +08:00
-- this.hintTxt.gameObject:SetActive(true)
2023-02-13 17:49:11 +08:00
end
SoundManager.PlayMusic(SoundConfig.BGM_Carbon)
2021-05-26 15:47:29 +08:00
CheckRedPointStatus(RedPointType.EpicExplore_LevleReward)
CheckRedPointStatus(RedPointType.EpicExplore_MoppingUp)
2021-10-28 16:03:23 +08:00
CheckRedPointStatus(RedPointType.DemonSlayerNew)
2021-05-25 14:51:26 +08:00
storeDataId,itemId,costNum = MonsterCampManager.MonsterCampGetCost()
this.titleText.text = Language[12099]
freeTimes = MonsterCampManager.GetCanBattleCount()
buyTimes = MonsterCampManager.GetCanBuyBattleCount()
2023-08-30 20:33:29 +08:00
this.freeMoppingTimes.text = freeTimes
this.buyMoppingTimes.text= buyTimes
2021-05-25 14:51:26 +08:00
this.InitMonsterShow()
2021-05-27 11:07:32 +08:00
PatFaceManager.RefreshPatface()
2021-05-25 14:51:26 +08:00
end
function this.SingleDataShow(go, data)
local singledata = MonsterCampSingleWave:New(go)
go:GetComponent("RectTransform").sizeDelta=Vector2.New(screenwidth,380)
2021-05-25 14:51:26 +08:00
singledata:InitComponent(go,data)
singledata:OnOpen(this.sortingOrder)
2021-05-25 14:51:26 +08:00
return singledata
end
function this.InitMonsterShow()
local monsterInfo = MonsterCampManager.GetMonstersInfo()
table.sort(monsterInfo,function(a,b) return a.Id > b.Id end)
this.scrollView:SetData(monsterInfo, function (index, go)
local tempData = this.SingleDataShow(go, monsterInfo[index])
this.singledataList[monsterInfo[index].Id] = tempData
2021-05-27 11:07:32 +08:00
end,true,true)
2021-05-26 11:48:44 +08:00
this.scrollView:SetIndex(#monsterInfo - MonsterCampManager.monsterWave - 1)
2021-05-25 14:51:26 +08:00
end
--界面关闭时调用(用于子类重写)
function MonsterCampNewPanel:OnClose()
MonsterCampManager.CurOffsetIndex = -1
end
--界面销毁时调用(用于子类重写)
function MonsterCampNewPanel:OnDestroy()
2021-05-26 11:48:44 +08:00
ClearRedPointObject(RedPointType.EpicExplore_LevleReward,Util.GetGameObject(this.btnHelpFight, "redPoint"))
2021-05-25 14:51:26 +08:00
for k,v in pairs(this.singledataList) do
v:OnDestroy()
end
this.singledataList = {}
SubUIManager.Close(this.scrollView)
this.spLoader:Destroy()
2021-05-25 14:51:26 +08:00
end
return MonsterCampNewPanel