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

227 lines
10 KiB
Lua
Raw Normal View History

require("Base/BasePanel")
require("View/FourElementSingleWave")
FourElementMonsterCampPanel = Inherit(BasePanel)
local itemConfig = ConfigManager.GetConfig(ConfigName.ItemConfig)
local this = FourElementMonsterCampPanel
this.grid = {}
this.singledataList = {}
2021-08-30 14:21:41 +08:00
--this.singlePreList = {}
local curType = 0
local trailData = {}
local itemId = 0
local costNum = 0
local freeTimes = 0
local buyTimes = 0
local storeDataId = 0
local callBack
2021-09-01 10:43:57 +08:00
local screenwidth
local redTrailType = {
[1] = RedPointType.PersonTrailHelp,
[2] = RedPointType.BuddishTrailHelp,
[3] = RedPointType.DemonTrailHelp,
[4] = RedPointType.TaoistTrailHelp,
}
--初始化组件(用于子类重写)
function FourElementMonsterCampPanel:InitComponent()
2021-09-01 10:43:57 +08:00
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.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,
2023-12-28 16:44:58 +08:00
this.pre, nil, Vector2.New(width, rootHight), 1, 1, Vector2.New(0, 0))
this.scrollView.moveTween.MomentumAmount = 1
this.scrollView.moveTween.Strength = 2
this.titleText = Util.GetGameObject(self.gameObject, "InfoRoot/tiitleRoot/title"):GetComponent("Text")
2021-08-30 14:21:41 +08:00
this.moppingUpBtn = Util.GetGameObject(self.gameObject, "InfoRoot/bottomLayout/moppingUpBtn")
2022-11-04 17:59:39 +08:00
this.moppingUpBtn:SetActive(false)
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")
2021-08-26 17:25:02 +08:00
this.btnHelpFightRed = Util.GetGameObject(this.btnHelpFight, "redPoint")
2023-08-30 20:33:29 +08:00
-- this.btnHelpFight:GetComponent("Image").sprite = this.spLoader:LoadSprite("s_silingshilian_zhuzhananniu_zh")
end
--绑定事件(用于子类重写)
function FourElementMonsterCampPanel:BindEvent()
Util.AddClick(this.btnBack, function ()
self:ClosePanel()
if callBack then callBack() end
end)
Util.AddClick(this.helpBtn, function ()
if curType == 1 then
UIManager.OpenPanel(UIName.HelpPopup,HELP_TYPE.FoueElementPeo,this.helpPosition.x,this.helpPosition.y)
elseif curType == 2 then
UIManager.OpenPanel(UIName.HelpPopup,HELP_TYPE.FoueElementBud,this.helpPosition.x,this.helpPosition.y)
elseif curType == 3 then
UIManager.OpenPanel(UIName.HelpPopup,HELP_TYPE.FoueElementDem,this.helpPosition.x,this.helpPosition.y)
elseif curType == 4 then
UIManager.OpenPanel(UIName.HelpPopup,HELP_TYPE.FoueElementTao,this.helpPosition.x,this.helpPosition.y)
end
end)
Util.AddClick(this.addBtn, function ()
2021-09-01 10:08:25 +08:00
if buyTimes < 1 then
PopupTipPanel.ShowTip("今日已无购买次数")
2021-09-01 10:08:25 +08:00
return
else
if BagManager.GetItemCountById(itemId) < costNum then
2021-09-01 10:43:57 +08:00
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()
PrivilegeManager.RefreshPrivilegeUsedTimes(trailData.buyTimeId, 1)
this.UpdatePrivilage()
end)
end,"取消","确定")
end
end)
Util.AddClick(this.btnRank, function ()
2021-08-26 17:25:02 +08:00
UIManager.OpenPanel(UIName.RankingSingleListPanel,rankKingList[curType+26])
end)
Util.AddClick(this.btnFormation, function ()
UIManager.OpenPanel(UIName.FormationPanelV2, FORMATION_TYPE.FOUR_ELEMENT, trailData.fourElementType, nil, 2)
end)
Util.AddClick(this.btnHelpFight, function ()
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)
end)
2021-08-30 14:21:41 +08:00
Util.AddClick(this.moppingUpBtn, function ()
if trailData.canFightTime < 1 then
2021-09-02 16:38:51 +08:00
PopupTipPanel.ShowTip("今日已无挑战次数")
2021-08-30 14:21:41 +08:00
return
end
2021-08-31 19:03:29 +08:00
if not ConfigManager.TryGetConfigDataByDoubleKey(ConfigName.CampTowerConfig,"CampId",curType,"FloorId",trailData.monsterWave + 1) then
PopupTipPanel.ShowTip("已通关全部层数,无法继续挑战")
return
end
2021-09-02 17:29:44 +08:00
if FormationManager.CheckFormationValid(curType + 3000) then
2021-08-30 14:21:41 +08:00
MonsterCampManager.ExecuteFightBattle(trailData.monsterWave + 1 ,0,function() this:OnShow() end,curType,true)
else
PopupTipPanel.ShowTip("编队不能为空")
return
end
end)
end
this.UpdatePrivilage = function()
if this.singledataList[trailData.monsterWave] then
this.singledataList[trailData.monsterWave]:UpdatePrivilage()
end
storeDataId,itemId,costNum = MonsterCampManager.GetCost(curType)
freeTimes,buyTimes = MonsterCampManager.GetTimeTip(curType)
2023-08-30 20:33:29 +08:00
this.freeMoppingTimes.text = freeTimes
this.buyMoppingTimes.text = buyTimes
end
--添加事件监听(用于子类重写)
function FourElementMonsterCampPanel:AddListener()
Game.GlobalEvent:AddEvent(GameEvent.FourEle.UpdatePri, self.UpdatePrivilage,self)
Game.GlobalEvent:AddEvent(GameEvent.FourEle.RefreshView, self.OnShow,self)
end
--移除事件监听(用于子类重写)
function FourElementMonsterCampPanel:RemoveListener()
Game.GlobalEvent:RemoveEvent(GameEvent.FourEle.UpdatePri, self.UpdatePrivilage,self)
Game.GlobalEvent:RemoveEvent(GameEvent.FourEle.RefreshView, self.OnShow,self)
end
--界面打开时调用(用于子类重写)
function FourElementMonsterCampPanel:OnOpen(index)
curType = index
BindRedPointObject(redTrailType[curType],this.btnHelpFightRed)
this.UpView:OnOpen({showType = UpViewOpenType.ShowLeft, panelType = PanelType.MonsterCamp })
end
--界面打开时调用(用于子类重写)
function FourElementMonsterCampPanel:OnShow()
trailData = MonsterCampManager.GetCurFourElementMonsterInfo(curType)
if trailData.openState == 0 then
self:ClosePanel()
return
end
storeDataId,itemId,costNum = MonsterCampManager.GetCost(curType)
this.titleText.text = FourElementName[curType]
this.canFightWaves.text = "可挑战层数:"..trailData.canFightTime
freeTimes,buyTimes = MonsterCampManager.GetTimeTip(curType)
2023-08-30 20:33:29 +08:00
this.freeMoppingTimes.text = freeTimes
this.buyMoppingTimes.text= buyTimes
this.InitMonsterShow()
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
2021-09-02 16:09:04 +08:00
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})
2021-09-01 14:52:13 +08:00
end
end
end
end
function this.SingleDataShow(go, data)
local singledata = FourElementSingleWave:New(go)
2021-09-01 10:43:57 +08:00
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 = MonsterCampManager.GetFourElementMonstersInfo(curType,curwaves)
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
2021-08-30 14:21:41 +08:00
--this.singlePreList[go] = this.singledataList[monsterInfo[index].wave]
2021-09-01 11:02:07 +08:00
end,true,true)
this.scrollView:SetIndex(#monsterInfo - curwaves - 1)
-- if MonsterCampManager.CurOffsetIndex < 0 then
-- this.scrollView:SetIndex((#monsterInfo-trailData.monsterWave-2))
-- else
-- this.scrollView:SetIndex((#monsterInfo-MonsterCampManager.CurOffsetIndex-2))
-- end
end
--界面关闭时调用(用于子类重写)
2021-09-02 16:09:04 +08:00
function FourElementMonsterCampPanel:OnClose()
ClearRedPointObject(redTrailType[curType],this.btnHelpFightRed)
MonsterCampManager.CurOffsetIndex = -1
end
--界面销毁时调用(用于子类重写)
2021-09-02 16:09:04 +08:00
function FourElementMonsterCampPanel:OnDestroy()
this.spLoader:Destroy()
2021-08-30 14:21:41 +08:00
for k,v in pairs(this.singledataList) do
v:OnDestroy()
end
2021-08-30 14:21:41 +08:00
--this.singlePreList = {}
this.singledataList = {}
SubUIManager.Close(this.scrollView)
2021-08-26 17:25:02 +08:00
this.spLoader:Destroy()
end
return FourElementMonsterCampPanel