miduo_client/Assets/ManagedResources/~Lua/Modules/MonsterCamp/FourElementMonsterCampPanel...

174 lines
7.5 KiB
Lua
Raw Normal View History

2020-12-08 17:01:53 +08:00
require("Base/BasePanel")
2020-12-22 20:33:35 +08:00
require("View/FourElementSingleWave")
2020-12-08 17:01:53 +08:00
FourElementMonsterCampPanel = Inherit(BasePanel)
local itemConfig = ConfigManager.GetConfig(ConfigName.ItemConfig)
local this = FourElementMonsterCampPanel
2020-12-21 09:51:08 +08:00
2020-12-08 17:01:53 +08:00
this.grid = {}
2020-12-22 20:33:35 +08:00
this.singledataList = {}
2020-12-21 09:51:08 +08:00
local curType = 0
local trailData = {}
2020-12-21 20:24:36 +08:00
local itemId = 0
local costNum = 0
local freeTimes = 0
local buyTimes = 0
local storeDataId = 0
2020-12-08 17:01:53 +08:00
local callBack
2021-03-01 18:35:35 +08:00
local redTrailType = {
[1] = RedPointType.PersonTrailHelp,
[2] = RedPointType.BuddishTrailHelp,
[3] = RedPointType.DemonTrailHelp,
[4] = RedPointType.TaoistTrailHelp,
}
2020-12-08 17:01:53 +08:00
--初始化组件(用于子类重写)
function FourElementMonsterCampPanel:InitComponent()
2020-12-21 20:24:36 +08:00
this.UpView = SubUIManager.Open(SubUIConfig.UpView, self.gameObject.transform)
2020-12-21 09:51:08 +08:00
this.btnBack = Util.GetGameObject(self.gameObject, "InfoRoot/btnBack")
2020-12-21 20:24:36 +08:00
this.helpBtn = Util.GetGameObject(self.gameObject, "InfoRoot/help")
this.helpPosition=this.helpBtn:GetComponent("RectTransform").localPosition
2020-12-21 09:51:08 +08:00
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(40, 10))
this.scrollView.moveTween.MomentumAmount = 1
this.scrollView.moveTween.Strength = 2
this.titleText = Util.GetGameObject(self.gameObject, "InfoRoot/tiitleRoot/title"):GetComponent("Text")
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.btnHelpFight = Util.GetGameObject(self.gameObject, "InfoRoot/btnHelpFight")
2020-12-08 17:01:53 +08:00
end
--绑定事件(用于子类重写)
function FourElementMonsterCampPanel:BindEvent()
Util.AddClick(this.btnBack, function ()
self:ClosePanel()
if callBack then callBack() end
end)
2020-12-21 20:24:36 +08:00
Util.AddClick(this.helpBtn, function ()
UIManager.OpenPanel(UIName.HelpPopup,HELP_TYPE.FoueElement,this.helpPosition.x,this.helpPosition.y)
2020-12-21 09:51:08 +08:00
end)
Util.AddClick(this.addBtn, function ()
2020-12-21 20:24:36 +08:00
if buyTimes < 0 then
PopupTipPanel.ShowTip("今日已无购买次数")
else
if BagManager.GetItemCountById(itemId) < costNum then
PopupTipPanel.ShowTip(string.format(Language[10343], itemConfig[itemId].Name))
return
end
2020-12-22 20:33:35 +08:00
MsgPanel.ShowTwo(string.format("是否花费%s%s购买一次扫荡次数",costNum,itemConfig[itemId].Name),function() end,function()
ShopManager.RequestBuyShopItem(SHOP_TYPE.FUNCTION_SHOP,storeDataId,1,function()
PrivilegeManager.RefreshPrivilegeUsedTimes(trailData.buyTimeId, 1)
this.UpdatePrivilage()
end)
end,"取消","确定")
2020-12-21 20:24:36 +08:00
end
2020-12-21 09:51:08 +08:00
end)
Util.AddClick(this.btnRank, function ()
2021-02-03 18:40:26 +08:00
UIManager.OpenPanel(UIName.RankingSingleListPanel,rankKingList[curType+14])
2020-12-21 09:51:08 +08:00
end)
Util.AddClick(this.btnHelpFight, function ()
2021-02-05 17:57:59 +08:00
local MyHeroData = HeroManager.GetHeroDataByProperty(curType,0)
MonsterCampManager.GetFriendHelpHeros(curType,function(data)
UIManager.OpenPanel(UIName.GeneralBigPopup,GENERAL_POPUP_TYPE.FourElementHelpFight,trailData.monsterWave + 1,curType,data,MyHeroData)
end)
2020-12-21 09:51:08 +08:00
end)
2020-12-08 17:01:53 +08:00
end
2020-12-22 20:33:35 +08:00
this.UpdatePrivilage = function()
if this.singledataList[trailData.monsterWave] then
this.singledataList[trailData.monsterWave]:UpdatePrivilage()
end
2020-12-21 20:24:36 +08:00
storeDataId,itemId,costNum = MonsterCampManager.GetCost(curType)
2020-12-22 20:33:35 +08:00
freeTimes,buyTimes = MonsterCampManager.GetTimeTip(curType)
this.freeMoppingTimes.text = "免费扫荡:" ..freeTimes
this.buyMoppingTimes.text = "购买次数:" ..buyTimes
end
2020-12-08 17:01:53 +08:00
--添加事件监听(用于子类重写)
function FourElementMonsterCampPanel:AddListener()
2021-02-07 14:09:05 +08:00
Game.GlobalEvent:AddEvent(GameEvent.FourEle.UpdatePri, self.UpdatePrivilage,self)
Game.GlobalEvent:AddEvent(GameEvent.FourEle.RefreshView, self.OnShow,self)
2020-12-08 17:01:53 +08:00
end
--移除事件监听(用于子类重写)
function FourElementMonsterCampPanel:RemoveListener()
2021-02-07 14:09:05 +08:00
Game.GlobalEvent:RemoveEvent(GameEvent.FourEle.UpdatePri, self.UpdatePrivilage,self)
Game.GlobalEvent:RemoveEvent(GameEvent.FourEle.RefreshView, self.OnShow,self)
2020-12-08 17:01:53 +08:00
end
--界面打开时调用(用于子类重写)
2020-12-21 09:51:08 +08:00
function FourElementMonsterCampPanel:OnOpen(index)
2021-03-01 18:35:35 +08:00
curType = index
BindRedPointObject(redTrailType[curType],Util.GetGameObject(this.btnHelpFight, "redPoint"))
2020-12-22 20:33:35 +08:00
this.UpView:OnOpen({showType = UpViewOpenType.ShowLeft, panelType = PanelType.MonsterCamp })
2020-12-21 09:51:08 +08:00
end
--界面打开时调用(用于子类重写)
function FourElementMonsterCampPanel:OnShow()
2021-02-05 17:57:59 +08:00
trailData = MonsterCampManager.GetCurFourElementMonsterInfo(curType)
if trailData.openState == 0 then
self:ClosePanel()
return
end
2020-12-21 20:24:36 +08:00
storeDataId,itemId,costNum = MonsterCampManager.GetCost(curType)
2020-12-21 09:51:08 +08:00
this.titleText.text = FourElementName[curType]
this.canFightWaves.text = "可挑战层数:"..trailData.canFightTime
2020-12-21 20:24:36 +08:00
freeTimes,buyTimes = MonsterCampManager.GetTimeTip(curType)
2020-12-22 20:33:35 +08:00
this.freeMoppingTimes.text = "免费扫荡:" ..freeTimes
this.buyMoppingTimes.text= "购买次数:" ..buyTimes
2020-12-08 17:01:53 +08:00
this.InitMonsterShow()
2021-02-26 17:44:13 +08:00
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
UIManager.OpenPanel(UIName.RewardItemPopup,nil,nil,nil,CompShowType.fourElement,nil,nil,nil,propertyId)
end
end
2020-12-08 17:01:53 +08:00
end
2020-12-21 09:51:08 +08:00
function this.SingleDataShow(go, data)
2020-12-22 20:33:35 +08:00
local singledata = FourElementSingleWave:New(go)
singledata:InitComponent(go,data,curType)
singledata:OnOpen()
return singledata
2020-12-21 09:51:08 +08:00
end
function this.InitMonsterShow()
local curwaves = trailData.monsterWave + 1 --当前可挑战层
local monsterInfo = MonsterCampManager.GetFourElementMonstersInfo(curType,curwaves)
2020-12-22 20:33:35 +08:00
table.sort(monsterInfo,function(a,b) return a.wave > b.wave end)
2020-12-21 09:51:08 +08:00
this.scrollView:SetData(monsterInfo, function (index, go)
2020-12-22 20:33:35 +08:00
local tempData = this.SingleDataShow(go, monsterInfo[index])
this.singledataList[monsterInfo[index].wave] = tempData
2020-12-21 09:51:08 +08:00
end)
2021-02-26 17:44:13 +08:00
this.scrollView:SetIndex((#monsterInfo-trailData.monsterWave-2))
2020-12-08 17:01:53 +08:00
end
--界面关闭时调用(用于子类重写)
function FourElementMonsterCampPanel:OnClose()
end
--界面销毁时调用(用于子类重写)
function FourElementMonsterCampPanel:OnDestroy()
2020-12-22 20:33:35 +08:00
this.singledataList = {}
for k,v in pairs(this.singledataList) do
v:OnDestroy()
end
2021-03-01 18:35:35 +08:00
ClearRedPointObject(redTrailType[curType],Util.GetGameObject(this.btnHelpFight, "redPoint"))
2020-12-08 17:01:53 +08:00
end
return FourElementMonsterCampPanel