2025-01-04 23:00:19 +08:00

188 lines
8.1 KiB
Lua

---@class WB_TeamSettlement_C:UUserWidget
---@field Button_AutoReturnToLobby UButton
---@field Button_share UButton
---@field CanvasPanel_Result UCanvasPanel
---@field HorizontalBox_AllName1 UHorizontalBox
---@field HorizontalBox_AllName2 UHorizontalBox
---@field Image_Left UImage
---@field Image_Right UImage
---@field Image_titlebg UImage
---@field TextBlock_AutoReturnToLobby UTextBlock
---@field TextBlock_LeftName UTextBlock
---@field TextBlock_LeftScore UTextBlock
---@field TextBlock_Levels2_2 UTextBlock
---@field TextBlock_RightName UTextBlock
---@field TextBlock_RightScore UTextBlock
---@field UIParticleEmitter_95 UUIParticleEmitter
---@field VerticalBox_Left UVerticalBox
---@field VerticalBox_Right UVerticalBox
---@field WB_RankScore_Name UWB_RankScore_Name_C
---@field WidgetSwitcher_Win UWidgetSwitcher
--Edit Below--
local WB_TeamSettlement = {
bInitDoOnce = false;
LeftTeamType = 1;
RightTeamType = 2;
};
function WB_TeamSettlement: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
for i, v in pairs(PlayerScoreSystem.Config.ShowRankType) do
local Item1 = self.HorizontalBox_AllName1:GetChildAt(i - 1)
local Item2 = self.HorizontalBox_AllName2:GetChildAt(i - 1)
if not UE.IsValid(Item1) then
Item1 = UserWidget.NewWidgetObjectBP(UGCSystemLibrary.GetLocalPlayerController(), self:GetScoreNameItemClass());
self.HorizontalBox_AllName1:AddChild(Item1)
end
if not UE.IsValid(Item2) then
Item2 = UserWidget.NewWidgetObjectBP(UGCSystemLibrary.GetLocalPlayerController(), self:GetScoreNameItemClass());
self.HorizontalBox_AllName2:AddChild(Item2)
end
Item1:SetColorIndex(i)
Item2:SetColorIndex(i)
Item1:SetName(PlayerScoreSystem.Config.ScoreTypeName[v])
Item2:SetName(PlayerScoreSystem.Config.ScoreTypeName[v])
end
-- 隐藏多余的Item的起始索引
local HideStartIndex = #PlayerScoreSystem.Config.ShowRankType
-- 判断是否显示总得分
if PlayerScoreSystem.Config.ShowTotalScore then
HideStartIndex = HideStartIndex + 1
local Item1 = self.HorizontalBox_AllName1:GetChildAt(#PlayerScoreSystem.Config.ShowRankType)
local Item2 = self.HorizontalBox_AllName2:GetChildAt(#PlayerScoreSystem.Config.ShowRankType)
if not UE.IsValid(Item1) then
Item1 = UserWidget.NewWidgetObjectBP(UGCSystemLibrary.GetLocalPlayerController(), self:GetScoreNameItemClass());
self.HorizontalBox_AllName1:AddChild(Item1)
end
if not UE.IsValid(Item2) then
Item2 = UserWidget.NewWidgetObjectBP(UGCSystemLibrary.GetLocalPlayerController(), self:GetScoreNameItemClass());
self.HorizontalBox_AllName2:AddChild(Item2)
end
Item1:SetName("得分")
Item2:SetName("得分")
end
-- 隐藏多余的Item
for i = HideStartIndex, self.HorizontalBox_AllName1:GetChildrenCount() - 1 do
self.HorizontalBox_AllName1:GetChildAt(i):SetVisibility(ESlateVisibility.Collapsed)
self.HorizontalBox_AllName2:GetChildAt(i):SetVisibility(ESlateVisibility.Collapsed)
end
end
function WB_TeamSettlement:GetScoreNameItemClass()
if self.ScoreNameItemClass == nil then
self.ScoreNameItemClass = UE.LoadClass(UGCGameSystem.GetUGCResourcesFullPath('Asset/UI/Rank/AutoRank/WB_RankScore_Name.WB_RankScore_Name_C'))
end
return self.ScoreNameItemClass
end
function WB_TeamSettlement:OnShowPanel()
self:AutoReturnToLobby()
self:UpdateRank()
self:SetItemTeam()
end
function WB_TeamSettlement: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_TeamSettlement:UpdateRank()
UGCLogSystem.Log("[WB_TeamSettlement_UpdateRank]")
local CTScore = UGCGameSystem.GameState:GetTeamScore(self.LeftTeamType)
local TScore = UGCGameSystem.GameState:GetTeamScore(self.RightTeamType)
self.TextBlock_LeftScore:SetText(tostring(CTScore))
self.TextBlock_RightScore:SetText(tostring(TScore))
-- 设置胜利图标
local PlayerTeamID = UGCGameSystem.GameState:GetPlayerTeamIDByPlayerKey(UGCSystemLibrary.GetLocalPlayerKey())
self.WidgetSwitcher_Win:SetActiveWidgetIndex(0)
if PlayerTeamID == self.LeftTeamType then
if CTScore < TScore then
self.WidgetSwitcher_Win:SetActiveWidgetIndex(1)
end
else
if CTScore > TScore then
self.WidgetSwitcher_Win:SetActiveWidgetIndex(1)
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_TeamSettlement: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_TeamSettlement: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
--停止检测DS连接
if NetUtil then
NetUtil.StopCheckDSActive();
end
--忽略DS链接报错
if BattleResult then
BattleResult.IgnoreDSError = true;
end
UGCGameSystem.ReturnToLobby()
UGCLogSystem.Log("[WB_TeamSettlement_Button_AutoReturnToLobby_OnClicked]")
end
--- 分享战绩
function WB_TeamSettlement:ShareSettlement()
UGCWidgetManagerSystem.Share();
end
return WB_TeamSettlement;