miduo_client/Assets/ManagedResources/~Lua/Modules/Guild/GuildMainCityPanel.lua

516 lines
20 KiB
Lua

require("Base/BasePanel")
local ctrlView = require("Modules/Guild/View/GuildSceneView")
local _IsMapView = false
local _IsWalkData = false
local GuildMainCityPanel = Inherit(BasePanel)
local this = GuildMainCityPanel
local _StageNameIcon = {
[GUILD_FIGHT_STAGE.DEFEND] = {"r_gonghui_bufangjieduan"},
[GUILD_FIGHT_STAGE.MATCHING] = {"r_gonghui_pipeijieduan"},
[GUILD_FIGHT_STAGE.ATTACK] = {"r_gonghui_jingongjieduan"},
[GUILD_FIGHT_STAGE.COUNTING] = {"r_gonghui_jiesuanjieduan", "r_gonghui_jiesuanwancheng"},
[GUILD_FIGHT_STAGE.EMPTEY] = {"r_gonghui_bencilunkong"},
}
--初始化组件(用于子类重写)
function GuildMainCityPanel:InitComponent()
this.btnBack = Util.GetGameObject(self.transform, "btnBack")
this.btnHelp = Util.GetGameObject(self.gameObject, "btnHelp")
this.helpPosition=this.btnHelp:GetComponent("RectTransform").localPosition
this.stageView = Util.GetGameObject(self.transform, "layout/panel1")
this.stageName = Util.GetGameObject(this.stageView, "stage/name"):GetComponent("Image")
this.stageTime = Util.GetGameObject(this.stageView, "stage/time"):GetComponent("Text")
this.myGuild = Util.GetGameObject(this.stageView, "stage/my")
this.enemyGuild = Util.GetGameObject(this.stageView, "stage/enemy")
this.myStar = Util.GetGameObject(this.stageView, "stage/my/starNum"):GetComponent("Text")
this.enemyStar = Util.GetGameObject(this.stageView, "stage/enemy/starNum"):GetComponent("Text")
this.rightBox = Util.GetGameObject(self.transform, "layout/panel2/btnbox")
this.btnOneKeyDefend = Util.GetGameObject(this.rightBox, "oneKeyDefend")
this.btnCheckDefend = Util.GetGameObject(this.rightBox, "checkDefend")
this.btnMatching = Util.GetGameObject(this.rightBox, "matching")
this.btnAttack = Util.GetGameObject(this.rightBox, "attack")
this.btnAttackLog = Util.GetGameObject(this.rightBox, "attackLog")
this.btnResult = Util.GetGameObject(this.rightBox, "result")
this.btnRedPacket=Util.GetGameObject(this.rightBox,"redPacket")
this.btnRedPacketRedPoint=Util.GetGameObject(this.btnRedPacket,"redPoint")
this.btnSkill=Util.GetGameObject(this.rightBox,"skill")
this.carDealy=Util.GetGameObject(this.rightBox,"carDealy")
-- this.leftBox = Util.GetGameObject(self.transform, "layout/panel2/leftBox")
-- this.btnBoss = Util.GetGameObject(this.leftBox, "boss/boss")
-- this.rpBoss = Util.GetGameObject(this.leftBox, "boss/boss/redpot")
-- 聊天
this.ChatTipView = SubUIManager.Open(SubUIConfig.ChatTipView, self.transform, 2)
this.UpView = SubUIManager.Open(SubUIConfig.UpView, self.gameObject.transform, { showType = UpViewOpenType.ShowLeft })
ctrlView.InitComponent(self.gameObject)
end
--绑定事件(用于子类重写)
function GuildMainCityPanel:BindEvent()
Util.AddClick(this.btnBack, function()
PlaySoundWithoutClick(SoundConfig.Sound_UICancel)
this:ClosePanel()
end)
--帮助按钮
Util.AddClick(this.btnHelp, function()
UIManager.OpenPanel(UIName.HelpPopup,HELP_TYPE.Guilds,this.helpPosition.x,this.helpPosition.y)
end)
-- 一键布防
Util.AddClick(this.btnOneKeyDefend, function()
-- 判断是否已经上阵
local defendData = GuildFightManager.GetDefendStagePlayerBuildType(PlayerManager.uid)
if defendData then
PopupTipPanel.ShowTip("您已布防")
return
end
-- 判断编队是否符合条件
local curFormationIndex = FormationManager.curFormationIndex
local formationList = FormationManager.GetFormationByID(curFormationIndex)
if #formationList.teamHeroInfos < 5 then
UIManager.OpenPanel(UIName.FormationPanel, FORMATION_TYPE.GUILD_DEFEND, "DEFEND", 0)
PopupTipPanel.ShowTip("一键编队阵容不符合编队条件,请手动设置布防阵容")
return
end
-- 布防到随机建筑
GuildFightManager.RequestDefend(0, function()
-- 刷新编队信息
FormationManager.RefreshFormationData()
PopupTipPanel.ShowTip("布防成功")
end)
end)
-- 查看布防
Util.AddClick(this.btnCheckDefend, function()
local curStage = GuildFightManager.GetCurFightStage()
if curStage == GUILD_FIGHT_STAGE.DEFEND then
GuildFightManager.RequestDefendStageData(function()
UIManager.OpenPanel(UIName.GuildFightDefendInfoPopup)
end)
end
end)
-- 去进攻
Util.AddClick(this.btnAttack, function()
local curStage = GuildFightManager.GetCurFightStage()
if curStage == GUILD_FIGHT_STAGE.ATTACK then
GuildFightManager.RequestAttackStageDefendData(function()
UIManager.OpenPanel(UIName.GuildFightAttackInfoPopup, GUILD_FIGHT_GUILD_TYPE.ENEMY)
end)
end
end)
-- 查看进攻日志
Util.AddClick(this.btnAttackLog, function()
-- 请求排名信息,也就是进攻日志
UIManager.OpenPanel(UIName.GuildFightAttackLogPopup)
end)
-- 查看结果
Util.AddClick(this.btnResult, function()
GuildFightManager.RequestGuildFightResultData(function()
UIManager.OpenPanel(UIName.GuildFightResultPopup)
end)
end)
--公会红包
Util.AddClick(this.btnRedPacket,function()
UIManager.OpenPanel(UIName.RedPacketPanel)
end)
Util.AddClick(this.btnSkill,function()
UIManager.OpenPanel(UIName.GuildSkillUpLvPopup)
end)
Util.AddClick(this.carDealy,function()
UIManager.OpenPanel(UIName.GuildCarDelayMainPanel)
end)
-- 绑定红点
BindRedPointObject(RedPointType.Guild_RedPacket, this.btnRedPacketRedPoint)
end
--添加事件监听(用于子类重写)
function GuildMainCityPanel:AddListener()
ctrlView.AddListener()
Game.GlobalEvent:AddEvent(GameEvent.Guild.OnQuitGuild, this.OnQuitGuild)
Game.GlobalEvent:AddEvent(GameEvent.Guild.BeKickOut, this.OnQuitGuild)
Game.GlobalEvent:AddEvent(GameEvent.Guild.DataUpdate, this.RefreshLogoShow)
Game.GlobalEvent:AddEvent(GameEvent.Guild.DismissStatusChanged, this.RefreshStageShow)
Game.GlobalEvent:AddEvent(GameEvent.GuildFight.FightBaseDataUpdate, this.RefreshStageShow)
Game.GlobalEvent:AddEvent(GameEvent.GuildFight.EnemyBaseDataUpdate, this.RefreshGuildInfo)
Game.GlobalEvent:AddEvent(GameEvent.GuildFight.ResultDataUpdate, this.RefreshGuildInfo)
Game.GlobalEvent:AddEvent(GameEvent.GuildFight.AttackStageDefendDataUpdate, this.RefreshGetStar)
Game.GlobalEvent:AddEvent(GameEvent.GuildRedPacket.OnCloseRedPointClick, this.CloseRedPointClick)
end
--移除事件监听(用于子类重写)
function GuildMainCityPanel:RemoveListener()
ctrlView.RemoveListener()
Game.GlobalEvent:RemoveEvent(GameEvent.Guild.OnQuitGuild, this.OnQuitGuild)
Game.GlobalEvent:RemoveEvent(GameEvent.Guild.BeKickOut, this.OnQuitGuild)
Game.GlobalEvent:RemoveEvent(GameEvent.Guild.DataUpdate, this.RefreshLogoShow)
Game.GlobalEvent:RemoveEvent(GameEvent.Guild.DismissStatusChanged, this.RefreshStageShow)
Game.GlobalEvent:RemoveEvent(GameEvent.GuildFight.FightBaseDataUpdate, this.RefreshStageShow)
Game.GlobalEvent:RemoveEvent(GameEvent.GuildFight.EnemyBaseDataUpdate, this.RefreshGuildInfo)
Game.GlobalEvent:RemoveEvent(GameEvent.GuildFight.ResultDataUpdate, this.RefreshGuildInfo)
Game.GlobalEvent:RemoveEvent(GameEvent.GuildFight.AttackStageDefendDataUpdate, this.RefreshGetStar)
Game.GlobalEvent:RemoveEvent(GameEvent.GuildRedPacket.OnCloseRedPointClick, this.CloseRedPointClick)
end
--界面打开时调用(用于子类重写)
function GuildMainCityPanel:OnOpen(...)
end
--界面打开或者重新打开后,界面刷新时调用(用于子类重写)
function GuildMainCityPanel:OnShow()
this.UpView:OnOpen({ showType = UpViewOpenType.ShowLeft, panelType = PanelType.Main })
CheckRedPointStatus(RedPointType.Guild_RedPacket)
if not PlayerManager.familyId or PlayerManager.familyId == 0 then
this:ClosePanel()
Log("尚未加入公会")
return
end
if not _IsMapView then
_IsMapView = true
Log("公会地图创建")
ctrlView.Init()
ctrlView.AddPointFunc(GUILD_MAP_BUILD_TYPE.HOUSE, function ()
UIManager.OpenPanel(UIName.GuildInfoPopup)
end)
ctrlView.AddPointFunc(GUILD_MAP_BUILD_TYPE.LOGO, function ()
UIManager.OpenPanel(UIName.GuildLogoPopup)
end)
ctrlView.AddPointFunc(GUILD_MAP_BUILD_TYPE.DOOR, function ()
local curStage = GuildFightManager.GetCurFightStage()
if curStage == GUILD_FIGHT_STAGE.CLOSE then
local stageData = GuildFightManager.GetGuildFightData()
if stageData.joinType == 1 then
PopupTipPanel.ShowTip("公会战期间加入的新成员无法参与本次公会战")
else
PopupTipPanel.ShowTip("公会战未开启,敬请期待")
end
return
end
if curStage == GUILD_FIGHT_STAGE.DISSMISS then
PopupTipPanel.ShowTip("公会解散中,无法参与公会战")
return
end
UIManager.OpenPanel(UIName.GuildFightPopup)
end)
ctrlView.AddPointFunc(GUILD_MAP_BUILD_TYPE.STORE, function ()
local isActive = ShopManager.IsActive(SHOP_TYPE.GUILD_SHOP)
if not isActive then
PopupTipPanel.ShowTip("公会商店尚未解锁")
return
end
UIManager.OpenPanel(UIName.MainShopPanel, SHOP_TYPE.GUILD_SHOP)
end)
ctrlView.AddPointFunc(GUILD_MAP_BUILD_TYPE.BOSS, function ()
UIManager.OpenPanel(UIName.GuildBossPanel)
end)
--公会祭祀
ctrlView.AddPointFunc(GUILD_MAP_BUILD_TYPE.FETE, function ()
UIManager.OpenPanel(UIName.GuildFetePopup)
end)
--十绝阵
ctrlView.AddPointFunc(GUILD_MAP_BUILD_TYPE.TENPOS,function ()
UIManager.OpenPanel(UIName.DeathPosPanel)
end)
end
-- 刷新一遍公会数据,这里主要是为了刷新玩家位置信息,避免返回地图界面出现的问题
NetManager.RequestMyGuildInfo(function()
if not _IsWalkData then
ctrlView.InitWalkData()
_IsWalkData = true
end
-- 刷洗图腾显示
this.RefreshLogoShow()
end)
-- 刷新公会战阶段信息
this.RefreshStageShow()
-- 开始定时刷新聊天数据
this.ChatTipView:StartCheck()
-- 刷新十绝阵是否开启
--this.RefreshDeathPos()
-- 开始吧
this._TimeUpdate()
if not this._TimeCounter then
this._TimeCounter = Timer.New(this._TimeUpdate, 1, -1, true)
this._TimeCounter:Start()
end
end
-- 刷新公会地图图腾显示
function this.RefreshLogoShow()
if ctrlView and _IsMapView then
local guildData = MyGuildManager.GetMyGuildInfo()
ctrlView.SetGuildLogo(guildData.icon)
end
end
--
function this.RefreshStageShow()
-- 关闭按钮显示
this.btnOneKeyDefend:SetActive(false)
this.btnCheckDefend:SetActive(false)
this.btnMatching:SetActive(false)
this.btnAttack:SetActive(false)
this.btnAttackLog:SetActive(false)
this.btnResult:SetActive(false)
this.stageView:SetActive(true)
local curStage = GuildFightManager.GetCurFightStage()
-- 阶段名称显示
this.stageName.gameObject:SetActive(_StageNameIcon[curStage] ~= nil)
if _StageNameIcon[curStage] then
this.stageName.gameObject:SetActive(true)
this.stageName.sprite = Util.LoadSprite(_StageNameIcon[curStage][1])
this.stageName:SetNativeSize()
end
-- 按钮显示,及特殊阶段处理
if curStage == GUILD_FIGHT_STAGE.UN_START then
elseif curStage == GUILD_FIGHT_STAGE.DEFEND then
this.btnCheckDefend:SetActive(true)
elseif curStage == GUILD_FIGHT_STAGE.MATCHING then
elseif curStage == GUILD_FIGHT_STAGE.ATTACK then
this.btnAttack:SetActive(true)
this.btnAttackLog:SetActive(true)
elseif curStage == GUILD_FIGHT_STAGE.COUNTING then
this.btnResult:SetActive(true)
local result = GuildFightManager.GetGuildFightResultData()
-- 显示结算完成
if result and _StageNameIcon[curStage] then
this.stageName.sprite = Util.LoadSprite(_StageNameIcon[curStage][2])
end
elseif curStage == GUILD_FIGHT_STAGE.EMPTEY then
elseif curStage == GUILD_FIGHT_STAGE.DISSMISS
or curStage == GUILD_FIGHT_STAGE.CLOSE then
this.stageView:SetActive(false)
end
-- 刷新展示信息
this.RefreshGuildInfo()
end
-- 刷新公会信息展示
function this.RefreshGuildInfo()
local enemyInfo = GuildFightManager.GetEnemyBaseData()
if not enemyInfo then
this.myGuild:SetActive(false)
this.enemyGuild:SetActive(false)
else
this.myGuild:SetActive(true)
this.enemyGuild:SetActive(true)
-- 敌方数据显示
this.GuildBaseInfoAdapter(this.enemyGuild, enemyInfo)
-- 我方数据显示
local myGuildData = GuildFightManager.GetMyBaseData()
this.GuildBaseInfoAdapter(this.myGuild, myGuildData)
end
-- 刷新获取的星数
this.RefreshGetStar()
-- 检测阶段提示
this.CheckStageTip()
end
-- 公会基础数据匹配
function this.GuildBaseInfoAdapter(node, data)
local nameText = Util.GetGameObject(node, "name"):GetComponent("Text")
local levelText = Util.GetGameObject(node, "level"):GetComponent("Text")
local levelbg = Util.GetGameObject(node, "lvbg")
local logoSpr = Util.GetGameObject(node, "icon"):GetComponent("Image")
levelText.gameObject:SetActive(data ~= nil)
levelbg.gameObject:SetActive(data ~= nil)
if data then
nameText.text = data.name
levelText.text = data.level
local logoName = GuildManager.GetLogoResName(data.pictureId)
logoSpr.sprite = Util.LoadSprite(logoName)
else
nameText.text = "..."
logoSpr.sprite = Util.LoadSprite("r_gonghui_pipeiwenhao")
end
-- logoSpr:SetNativeSize()
end
-- 刷新获取星数的显示
function this.RefreshGetStar()
this.myStar.gameObject:SetActive(false)
this.enemyStar.gameObject:SetActive(false)
local curStage = GuildFightManager.GetCurFightStage()
if curStage == GUILD_FIGHT_STAGE.ATTACK or curStage == GUILD_FIGHT_STAGE.COUNTING then
this.myStar.gameObject:SetActive(true)
this.enemyStar.gameObject:SetActive(true)
local myGetStar, enemyGetStar = GuildFightManager.GetBothGetStarNum()
this.myStar.text = myGetStar
this.enemyStar.text = enemyGetStar
end
end
-- 计时显示
local _BGMFlag = nil
function this._TimeUpdate()
local curStage = GuildFightManager.GetCurFightStage()
if curStage == GUILD_FIGHT_STAGE.DISSMISS or curStage == GUILD_FIGHT_STAGE.CLOSE then
if not _BGMFlag or _BGMFlag == 1 then
_BGMFlag = 0
SoundManager.PlayMusic(SoundConfig.BGM_Guild)
end
return
end
local guildFightData = GuildFightManager.GetGuildFightData()
local startTime = guildFightData.startTime
local curTime = GetTimeStamp()
if guildFightData.type == GUILD_FIGHT_STAGE.UN_START and curTime < startTime then
local leftTime = startTime - curTime
leftTime = leftTime < 0 and 0 or leftTime
this.stageTime.text = string.format("距离公会战开启:%s", TimeToHMS(leftTime))
if not _BGMFlag or _BGMFlag == 1 then
_BGMFlag = 0
SoundManager.PlayMusic(SoundConfig.BGM_Guild)
end
else
local roundEndTime = guildFightData.roundEndTime
local leftTime = roundEndTime - curTime
leftTime = leftTime < 0 and 0 or leftTime
this.stageTime.text = string.format("剩余时间:%s", TimeToHMS(leftTime))
if not _BGMFlag or _BGMFlag == 0 then
_BGMFlag = 1
SoundManager.PlayMusic(SoundConfig.BGM_GuildFight)
end
end
end
-- 退出公会回调事件
function this.OnQuitGuild()
this:ClosePanel()
end
--- 检测当前阶段是否需要显示阶段提示界面
function this.CheckStageTip()
-- 获取当前公会战阶段
local isInFight = GuildFightManager.IsInGuildFight()
if not isInFight then return end
local curStage = GuildFightManager.GetCurFightStage()
local curTipStage = GuildFightManager.GetCurTipStage()
-- 轮空状态特殊处理
if curStage == GUILD_FIGHT_STAGE.EMPTEY and curTipStage ~= GUILD_FIGHT_STAGE.EMPTEY then
GuildFightManager.SetCurTipStage(GUILD_FIGHT_STAGE.EMPTEY)
if UIManager.IsOpen(UIName.GuildFightMatchingPopup) then
UIManager.ClosePanel(UIName.GuildFightMatchingPopup)
end
-- 显示轮空提示
UIManager.OpenPanel(UIName.GuildFightMatchSuccessPopup, 2)
return
elseif curStage == GUILD_FIGHT_STAGE.MATCHING then
local enemyInfo = GuildFightManager.GetEnemyBaseData()
if not enemyInfo then
if not curTipStage or curTipStage < curStage - 0.5 then
-- 这里匹配阶段但是未匹配成功的阶段用 匹配阶段减0.5代替 以符合提示显示的规则
-- 阶段设计问题,应该将匹配阶段分开为两个阶段
GuildFightManager.SetCurTipStage(curStage - 0.5)
if UIManager.IsOpen(UIName.GuildFightDefendInfoPopup) then
UIManager.ClosePanel(UIName.GuildFightDefendInfoPopup)
end
UIManager.OpenPanel(UIName.GuildFightMatchingPopup)
end
else
if not curTipStage or curTipStage < curStage then
-- 匹配成功的阶段,显示匹配结果
GuildFightManager.SetCurTipStage(curStage)
if UIManager.IsOpen(UIName.GuildFightMatchingPopup) then
UIManager.ClosePanel(UIName.GuildFightMatchingPopup)
end
UIManager.OpenPanel(UIName.GuildFightMatchSuccessPopup, 1)
end
end
return
end
if not curTipStage or curTipStage < curStage then
GuildFightManager.SetCurTipStage(curStage)
-- 根据不同的阶段显示不同的界面
if curStage == GUILD_FIGHT_STAGE.DEFEND then
if UIManager.IsOpen(UIName.GuildFightResultPopup) then
UIManager.ClosePanel(UIName.GuildFightResultPopup)
end
UIManager.OpenPanel(UIName.GuildFightDefendInfoPopup, true)
elseif curStage == GUILD_FIGHT_STAGE.ATTACK then
if UIManager.IsOpen(UIName.GuildFightMatchSuccessPopup) then
UIManager.ClosePanel(UIName.GuildFightMatchSuccessPopup)
end
UIManager.OpenPanel(UIName.GuildFightAttackTipPopup)
elseif curStage == GUILD_FIGHT_STAGE.COUNTING then
if UIManager.IsOpen(UIName.GuildFightAttackTipPopup) then
UIManager.ClosePanel(UIName.GuildFightAttackTipPopup)
end
UIManager.OpenPanel(UIName.GuildFightResultPopup)
end
end
end
-- 刷新红包红点
function this.CloseRedPointClick()
GuildRedPacketManager.isCheck=false
CheckRedPointStatus(RedPointType.Guild_RedPacket)
end
--刷新十绝阵是否开启
function this.RefreshDeathPos()
NetManager.GetDeathPathStatusResponse(function(msg)
LogBlue(tostring("十绝阵开启状态 "..msg.status))
ctrlView.SetBuildFlagShow(GUILD_MAP_BUILD_TYPE.TENPOS,msg.status~=0)
end)
end
--界面关闭时调用(用于子类重写)
function GuildMainCityPanel:OnClose()
Log("公会地图删除")
ctrlView.Dispose()
_IsMapView = false
_IsWalkData = false
--
_BGMFlag = nil
-- 计时器关闭
if this._TimeCounter then
this._TimeCounter:Stop()
this._TimeCounter = nil
end
-- 关闭定时刷新数据
this.ChatTipView:StopCheck()
end
--界面销毁时调用(用于子类重写)
function GuildMainCityPanel:OnDestroy()
SubUIManager.Close(this.ChatTipView)
SubUIManager.Close(this.UpView)
-- 移除红点
-- ClearRedPointObject(RedPointType.Guild_Boss)
end
return GuildMainCityPanel