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

236 lines
10 KiB
Lua

require("Base/BasePanel")
require("View/FourElementSingleWave")
FourElementMonsterCampPanel = Inherit(BasePanel)
local itemConfig = ConfigManager.GetConfig(ConfigName.ItemConfig)
local this = FourElementMonsterCampPanel
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 redTrailType = {
[1] = RedPointType.PersonTrailHelp,
[2] = RedPointType.BuddishTrailHelp,
[3] = RedPointType.DemonTrailHelp,
[4] = RedPointType.TaoistTrailHelp,
}
--初始化组件(用于子类重写)
function FourElementMonsterCampPanel:InitComponent()
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,
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")
this.moppingUpBtn = Util.GetGameObject(self.gameObject, "InfoRoot/bottomLayout/moppingUpBtn")
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")
this.btnHelpFight:SetActive(false)
this.btnHelpFightRed = Util.GetGameObject(this.btnHelpFight, "redPoint")
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()
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, GetLanguageStrById(itemConfig[itemId].Name)), function() end, function()
ShopManager.RequestBuyShopItem(SHOP_TYPE.FUNCTION_SHOP, storeDataId, 1, function()
PrivilegeManager.RefreshPrivilegeUsedTimes(trailData.buyTimeId, 1)
this.UpdatePrivilage()
end)
end, Language[10685], Language[10686])
end
end)
Util.AddClick(this.btnRank, function()
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)
Util.AddClick(this.moppingUpBtn, function()
if trailData.canFightTime < 1 then
PopupTipPanel.ShowTip(Language[11885])
return
end
if not ConfigManager.TryGetConfigDataByDoubleKey(ConfigName.CampTowerConfig, "CampId", curType, "FloorId", trailData.monsterWave + 1) then
PopupTipPanel.ShowTip(Language[11886])
return
end
if FormationManager.CheckFormationValid(curType + 3000) then
MonsterCampManager.ExecuteFightBattle(trailData.monsterWave + 1, 0, function() this:OnShow() end, curType,
true)
else
PopupTipPanel.ShowTip(Language[10862])
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)
this.freeMoppingTimes.text = Language[11887] .. freeTimes
this.buyMoppingTimes.text = Language[11643] .. 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 = Language[11888] .. trailData.canFightTime
freeTimes, buyTimes = MonsterCampManager.GetTimeTip(curType)
this.freeMoppingTimes.text = Language[11887] .. freeTimes
this.buyMoppingTimes.text = Language[11643] .. 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
--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 = FourElementSingleWave: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 = 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
--this.singlePreList[go] = this.singledataList[monsterInfo[index].wave]
end, true, true)
--this.scrollView:SetIndex(#monsterInfo - curwaves - 1)
this.scrollView:SetIndex(10)
-- if MonsterCampManager.CurOffsetIndex < 0 then
-- this.scrollView:SetIndex((#monsterInfo-trailData.monsterWave-2))
-- else
-- this.scrollView:SetIndex((#monsterInfo-MonsterCampManager.CurOffsetIndex-2))
-- end
end
--界面关闭时调用(用于子类重写)
function FourElementMonsterCampPanel:OnClose()
ClearRedPointObject(redTrailType[curType], this.btnHelpFightRed)
MonsterCampManager.CurOffsetIndex = -1
end
--界面销毁时调用(用于子类重写)
function FourElementMonsterCampPanel: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 FourElementMonsterCampPanel