UGCProjects/BreakThrough/Script/UI/Settlement/WB_BreakThroughSettlement.lua

152 lines
7.2 KiB
Lua
Raw Normal View History

2025-01-04 23:00:19 +08:00
---@class WB_BreakThroughSettlement_C:UUserWidget
---@field Button_AutoReturnToLobby UButton
---@field Button_share UButton
---@field CanvasPanel_Result UCanvasPanel
---@field Image_3 UImage
---@field Image_Left UImage
---@field Image_Right UImage
---@field Image_titlebg UImage
---@field TextBlock_AutoReturnToLobby UTextBlock
---@field TextBlock_LeftName UTextBlock
---@field TextBlock_LeftTime UTextBlock
---@field TextBlock_Levels2_2 UTextBlock
---@field TextBlock_RightName UTextBlock
---@field TextBlock_RightTime UTextBlock
---@field UIParticleEmitter_95 UUIParticleEmitter
---@field VerticalBox_Left UVerticalBox
---@field VerticalBox_Right UVerticalBox
---@field WidgetSwitcher_Win UWidgetSwitcher
--Edit Below--
local WB_BreakThroughSettlement = {
bInitDoOnce = false;
LeftTeamType = 1;
RightTeamType = 2;
};
function WB_BreakThroughSettlement:Construct()
--UGCEventSystem.AddListener(EventEnum.UpdatePlayerScoreData, self.UpdateRank, self);
--UGCEventSystem.AddListener(EventEnum.UpdatePlayerRank, self.UpdateRank, self);
WidgetLibrary.BindButtonClicked(self.Button_AutoReturnToLobby, self.Button_AutoReturnToLobby_OnClicked, self)
WidgetLibrary.BindButtonClicked(self.Button_share, self.ShareSettlement, self)
self:SetItemTeam()
for i = 0, self.VerticalBox_Left:GetChildrenCount() - 1 do
local ItemLeftInst = self.VerticalBox_Left:GetChildAt(i)
local ItemRightInst = self.VerticalBox_Right:GetChildAt(i)
ItemLeftInst:SetIndex(i + 1)
ItemRightInst:SetIndex(i + 1)
end
end
function WB_BreakThroughSettlement:OnShowPanel()
self:AutoReturnToLobby()
self:UpdateRank()
UGCEventSystem.AddListener(EventEnum.UpdateTeamBreakThroughTime, self.UpdateRank, self)
-- UGCWidgetManagerSystem.GetMainControlUI():SetVisibility(ESlateVisibility.Collapsed)
-- UGCWidgetManagerSystem.GetShootingUIPanel():SetVisibility(ESlateVisibility.Collapsed)
end
function WB_BreakThroughSettlement:OnClosePanel()
--UGCWidgetManagerSystem.GetMainControlUI():SetVisibility(ESlateVisibility.SelfHitTestInvisible)
-- UGCWidgetManagerSystem.GetShootingUIPanel():SetVisibility(ESlateVisibility.SelfHitTestInvisible)
end
function WB_BreakThroughSettlement:SetItemTeam()
local LocalPlayerTeamID = UGCPlayerControllerSystem.GetTeamID(UGCSystemLibrary.GetLocalPlayerController())
if LocalPlayerTeamID == TeamConfig.TeamType.CT then
self.LeftTeamType, self.RightTeamType = TeamConfig.TeamType.CT, TeamConfig.TeamType.T
else
self.LeftTeamType, self.RightTeamType = TeamConfig.TeamType.T, TeamConfig.TeamType.CT
end
for i = 0, self.VerticalBox_Left:GetChildrenCount() - 1 do
local ItemLeftInst = self.VerticalBox_Left:GetChildAt(i)
local ItemRightInst = self.VerticalBox_Right:GetChildAt(i)
ItemLeftInst:SetTeam(TeamConfig.TeamType.CT)
ItemRightInst:SetTeam(TeamConfig.TeamType.T)
end
end
function WB_BreakThroughSettlement:UpdateRank()
UGCLogSystem.Log("[WB_BreakThroughSettlement_UpdateRank]")
local LeftScore = UGCGameSystem.GameState:GetTeamBreakThroughTime(self.LeftTeamType)
local RightScore = UGCGameSystem.GameState:GetTeamBreakThroughTime(self.RightTeamType)
self.TextBlock_LeftTime:SetText((LeftScore > 0 and UGCSystemLibrary.formatTime(LeftScore, true, false, false) or "--"))
self.TextBlock_RightTime:SetText((RightScore > 0 and UGCSystemLibrary.formatTime(RightScore, true, false, false) or "--"))
-- 设置胜利图标
if LeftScore == RightScore then
if LeftScore > 0 then
-- 平局
self.WidgetSwitcher_Win:SetActiveWidgetIndex(2)
else
self.TextBlock_LeftName:SetText("己方突围次数")
self.TextBlock_RightTime:SetText("敌方突围次数")
local LeftBreakTroughCount = UGCGameSystem.GameState:GetTeamBreakThroughCount(self.LeftTeamType)
local RightBreakTroughCount = UGCGameSystem.GameState:GetTeamBreakThroughCount(self.RightTeamType)
if LeftBreakTroughCount > RightBreakTroughCount then
self.WidgetSwitcher_Win:SetActiveWidgetIndex(0)
elseif LeftBreakTroughCount < RightBreakTroughCount then
self.WidgetSwitcher_Win:SetActiveWidgetIndex(1)
else
-- 平局
self.WidgetSwitcher_Win:SetActiveWidgetIndex(2)
end
self.TextBlock_LeftTime:SetText(LeftBreakTroughCount)
self.TextBlock_RightTime:SetText(RightBreakTroughCount)
end
else
self.WidgetSwitcher_Win:SetActiveWidgetIndex(0)
if LeftScore < 0 or (RightScore > 0 and LeftScore > RightScore) then
self.WidgetSwitcher_Win:SetActiveWidgetIndex(1)
else
self.WidgetSwitcher_Win:SetActiveWidgetIndex(0)
end
end
local RankData = PlayerScoreSystem.GetTeamRank()
UGCLogSystem.LogTree("[WB_TeamRank_UpdateRank]", RankData)
for i = 0, self.VerticalBox_Left:GetChildrenCount() - 1 do
local ItemLeftInst = self.VerticalBox_Left:GetChildAt(i)
local ItemRightInst = self.VerticalBox_Right:GetChildAt(i)
local PlayerKeyLeft = RankData[self.LeftTeamType] and RankData[self.LeftTeamType][i + 1] or nil
local PlayerKeyRight = RankData[self.RightTeamType] and RankData[self.RightTeamType][i + 1] or nil
if PlayerKeyLeft then
ItemLeftInst:SetVisibility(ESlateVisibility.SelfHitTestInvisible)
ItemLeftInst:InitRankInfo(PlayerKeyLeft)
else
ItemLeftInst:SetVisibility(ESlateVisibility.Collapsed)
end
if PlayerKeyRight then
ItemRightInst:SetVisibility(ESlateVisibility.SelfHitTestInvisible)
ItemRightInst:InitRankInfo(PlayerKeyRight)
else
ItemRightInst:SetVisibility(ESlateVisibility.Collapsed)
end
end
end
function WB_BreakThroughSettlement:AutoReturnToLobby()
self.DelayReturnToLobbyTime = GlobalConfigs.GameSetting.DelayReturnToLobbyTime
self.SettlementTime = KismetSystemLibrary.GetGameTimeInSeconds(self)
self.DelayReturnToLobbyTimerHandle = UGCEventSystem.SetTimerLoop(
self,
function ()
local NowTime = KismetSystemLibrary.GetGameTimeInSeconds(self)
local ShowTime = math.floor(self.DelayReturnToLobbyTime - (NowTime - self.SettlementTime))
ShowTime = ShowTime >= 0 and ShowTime or 0
self.TextBlock_AutoReturnToLobby:SetText(string.format("返回大厅(%ds)", ShowTime))
if ShowTime <= 0 then self:Button_AutoReturnToLobby_OnClicked() end
end,
0.5
)
end
function WB_BreakThroughSettlement:Button_AutoReturnToLobby_OnClicked()
if UGCGameSystem.GameState.GameStateType ~= CustomEnum.EGameState.End then return end
if self == nil or self.DoOnceReturnToLobby then return end
if self.DelayReturnToLobbyTimerHandle then
UGCEventSystem.StopTimer(self.DelayReturnToLobbyTimerHandle)
self.DelayReturnToLobbyTimerHandle = nil
end
self.DoOnceReturnToLobby = true
UGCGameSystem.ReturnToLobby()
UGCLogSystem.Log("[WB_BreakThroughSettlement_Button_AutoReturnToLobby_OnClicked]")
end
--- 分享战绩
function WB_BreakThroughSettlement:ShareSettlement()
UGCWidgetManagerSystem.Share();
end
return WB_BreakThroughSettlement;