176 lines
5.7 KiB
Lua
176 lines
5.7 KiB
Lua
---@class WB_Title1_2_C:UUserWidget
|
|
---@field Border_LeftSideTeam UBorder
|
|
---@field Border_RightSideTeam UBorder
|
|
---@field CanvasPanel_3 UCanvasPanel
|
|
---@field CanvasPanel_LeftSidechampion UCanvasPanel
|
|
---@field CanvasPanel_RightSidechampion UCanvasPanel
|
|
---@field CanvasPanel_ScoreBoard UCanvasPanel
|
|
---@field HorizontalBox_8 UHorizontalBox
|
|
---@field HorizontalBox_9 UHorizontalBox
|
|
---@field HorizontalBox_EnemyKill UHorizontalBox
|
|
---@field HorizontalBox_Kill UHorizontalBox
|
|
---@field Image_LeftHead UImage
|
|
---@field Image_LeftSide_ScoreBG UImage
|
|
---@field Image_LeftSide_ScoreBG2 UImage
|
|
---@field Image_LeftSide_SlotBG UImage
|
|
---@field Image_LeftSideKillBar UImage
|
|
---@field Image_RightHead UImage
|
|
---@field Image_RightSide_ScoreBG UImage
|
|
---@field Image_RightSide_ScoreBG2 UImage
|
|
---@field Image_RightSide_SlotBG UImage
|
|
---@field Image_RightSideKillBar UImage
|
|
---@field TextBlock_EnemyKill UTextBlock
|
|
---@field TextBlock_EnemyScore UTextBlock
|
|
---@field TextBlock_GameTime UTextBlock
|
|
---@field TextBlock_Left UTextBlock
|
|
---@field TextBlock_LeftSide_Total_Num UTextBlock
|
|
---@field TextBlock_Right UTextBlock
|
|
---@field TextBlock_RightSide_Total_Num UTextBlock
|
|
---@field TextBlock_SelfKill UTextBlock
|
|
---@field TextBlock_SelfScore UTextBlock
|
|
---@field TextBlock_Time UTextBlock
|
|
---@field WidgetSwitcher_LeftSide_ScoreBG UWidgetSwitcher
|
|
---@field WidgetSwitcher_RightSide_ScoreBG UWidgetSwitcher
|
|
--Edit Below--
|
|
local WB_Title1 = { bInitDoOnce = false }
|
|
|
|
function WB_Title1:Construct()
|
|
self:LuaInit();
|
|
end
|
|
|
|
function WB_Title1:LuaInit()
|
|
if self.bInitDoOnce then return ; end
|
|
self.bInitDoOnce = true;
|
|
|
|
UGCEventSystem.AddListener(EventTypes.GameCountDownTimeChange, self.OnCountDownChange, self);
|
|
UGCEventSystem.AddListener(EventTypes.UpdateRoundTimes, self.OnUpdateRoundTimes, self);
|
|
UGCEventSystem.AddListener(EventTypes.UpdateRoundWinners, self.OnUpdateRoundWinners, self);
|
|
UGCEventSystem.AddListener(EventTypes.UpdateAccountInfo, self.OnUpdateAccountInfo, self)
|
|
|
|
self.TextBlock_SelfScore:SetText("0");
|
|
self.TextBlock_EnemyScore:SetText("0");
|
|
self.TextBlock_Time:SetText("0/7");
|
|
self.TextBlock_EnemyKill:SetText("0");
|
|
self.TextBlock_SelfKill:SetText("0");
|
|
self:SetKillCount(0)
|
|
self:SetEnemyKillCount(0)
|
|
|
|
|
|
local RoundWinners = UE.GetMiniRepData("RoundWinners")
|
|
if RoundWinners ~= nil then
|
|
UGCLogSystem.LogTree(string.format("[WB_Title1:LuaInit] RoundWinners ="), RoundWinners)
|
|
self:OnUpdateRoundWinners(RoundWinners);
|
|
end
|
|
|
|
local RoundTimes = UE.GetMiniRepData("RoundTimes");
|
|
UGCLogSystem.Log("[WB_Title1:LuaInit] RoundTimes = %s", tostring(RoundTimes))
|
|
if RoundTimes ~= nil then self:OnUpdateRoundTimes(RoundTimes, 7); end
|
|
|
|
local RoundDeadTimes = UE.GetMiniRepData("RoundDeadTimes");
|
|
if RoundDeadTimes ~= nil then
|
|
self:SetRoundKill(RoundDeadTimes);
|
|
UGCLogSystem.LogTree(string.format("[WB_Title1:LuaInit] RoundDeadTimes ="), RoundDeadTimes)
|
|
end
|
|
|
|
self:OnUpdateAccountInfo();
|
|
end
|
|
|
|
function WB_Title1:OnCountDownChange(InTime)
|
|
if InTime <= 0 then
|
|
self.TextBlock_GameTime:SetText("00:00")
|
|
else
|
|
self.TextBlock_GameTime:SetText(string.format("%02d:%02d", InTime // 60, InTime % 60));
|
|
end
|
|
end
|
|
|
|
function WB_Title1:OnUpdateRoundTimes(InTimes, InTotal)
|
|
UGCLogSystem.Log("[WB_Title1:OnUpdateRoundTimes] InTimes = %s, InTotal = %s", tostring(InTimes), tostring(InTotal));
|
|
if InTimes ~= nil and InTotal ~= nil then
|
|
self.TextBlock_Time:SetText(string.format("%d/%d", InTotal - InTimes, InTotal));
|
|
end
|
|
end
|
|
|
|
function WB_Title1:OnUpdateAccountInfo()
|
|
-- 找到 LocalPlayerKey
|
|
for PlayerKey, Info in pairs(UE.GetAccountInfo()) do
|
|
if PlayerKey == LocalPlayerKey then
|
|
self.TextBlock_Left:SetText(Info.PlayerName);
|
|
UITool.DownloadImage(Info.IconURL, function(Texture)
|
|
self.Image_LeftHead:SetBrushFromTextureDynamic(Texture);
|
|
end)
|
|
else
|
|
self.TextBlock_Right:SetText(Info.PlayerName);
|
|
UITool.DownloadImage(Info.IconURL, function(Texture)
|
|
self.Image_RightHead:SetBrushFromTextureDynamic(Texture);
|
|
end)
|
|
end
|
|
end
|
|
end
|
|
|
|
function WB_Title1:OnUpdateRoundWinners(InWinners)
|
|
local Rounds = {};
|
|
for i, v in pairs(InWinners) do
|
|
if v.Winner then
|
|
Rounds[v.Winner] = (Rounds[v.Winner] or 0) + 1;
|
|
end
|
|
end
|
|
UGCLogSystem.LogTree(string.format("[WB_Title1:OnUpdateRoundWinners] Rounds ="), Rounds);
|
|
for i, v in pairs(Rounds) do
|
|
if i == LocalPlayerKey then
|
|
self.TextBlock_SelfScore:SetText(Rounds[i] or 0);
|
|
else
|
|
self.TextBlock_EnemyScore:SetText(Rounds[i] or 0);
|
|
end
|
|
end
|
|
end
|
|
|
|
function WB_Title1:SetRoundKill(Kills)
|
|
self.TextBlock_SelfKill:SetText(0);
|
|
self.TextBlock_EnemyKill:SetText(0);
|
|
self:SetKillCount(0)
|
|
self:SetEnemyKillCount(0)
|
|
if table.isEmpty(Kills) then return ; end
|
|
for i, v in pairs(Kills) do
|
|
if i == LocalPlayerKey then
|
|
self.TextBlock_EnemyKill:SetText(v);
|
|
self:SetEnemyKillCount(v)
|
|
else
|
|
self.TextBlock_SelfKill:SetText(v);
|
|
self:SetKillCount(v)
|
|
end
|
|
end
|
|
end
|
|
|
|
function WB_Title1:SetKillCount(Count)
|
|
for i = 1, self.HorizontalBox_Kill:GetChildrenCount() do
|
|
local Item = self.HorizontalBox_Kill:GetChildAt(i - 1)
|
|
if Count >= i then
|
|
Item:SetActiveWidgetIndex(1)
|
|
else
|
|
Item:SetActiveWidgetIndex(0)
|
|
end
|
|
end
|
|
end
|
|
|
|
function WB_Title1:SetEnemyKillCount(Count)
|
|
for i = 1, self.HorizontalBox_EnemyKill:GetChildrenCount() do
|
|
local Item = self.HorizontalBox_EnemyKill:GetChildAt(i - 1)
|
|
if Count >= i then
|
|
Item:SetActiveWidgetIndex(1)
|
|
else
|
|
Item:SetActiveWidgetIndex(0)
|
|
end
|
|
end
|
|
end
|
|
|
|
-- function WB_Title1:Tick(MyGeometry, InDeltaTime)
|
|
|
|
-- end
|
|
|
|
function WB_Title1:Destruct()
|
|
UGCEventSystem.RemoveListener(EventTypes.GameCountDownTimeChange, self.OnCountDownChange, self);
|
|
UGCEventSystem.RemoveListener(EventTypes.UpdateRoundTimes, self.OnUpdateRoundTimes, self);
|
|
UGCEventSystem.RemoveListener(EventTypes.UpdateRoundWinners, self.OnUpdateRoundWinners, self);
|
|
end
|
|
|
|
return WB_Title1; |