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

120 lines
3.5 KiB
Lua

---@class WB_Title2_C:UUserWidget
---@field TextBlock_EnemyKill UTextBlock
---@field TextBlock_EnemyScore UTextBlock
---@field TextBlock_GameTime UTextBlock
---@field TextBlock_Left UTextBlock
---@field TextBlock_Right UTextBlock
---@field TextBlock_SelfKill UTextBlock
---@field TextBlock_SelfScore UTextBlock
---@field TextBlock_Time UTextBlock
--Edit Below--
---@type WB_Title2_C
local WB_Title2 = { bInitDoOnce = false }
function WB_Title2:Construct()
self:LuaInit();
end
function WB_Title2: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);
-- 初始化
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");
--- 设置名字
for PlayerKey, Info in pairs(UE.GetAccountInfo()) do
if Info.TeamID == 1 then
self.TextBlock_Left:SetText(Info.PlayerName);
else
self.TextBlock_Right:SetText(Info.PlayerName);
end
end
local RoundWinners = UE.GetMiniRepData("RoundWinners")
if RoundWinners ~= nil then
UGCLogSystem.LogTree(string.format("[WB_Title1:LuaInit] RoundWinners ="), RoundWinners)
self:OnUpdateRoundWinners(RoundWinners);
else
self.TextBlock_SelfScore:SetText(0);
self.TextBlock_EnemyScore:SetText(0);
end
local RoundTimes = UE.GetMiniRepData("RoundTimes");
UGCLogSystem.Log("[WB_Title1:LuaInit] RoundTimes = %s", tostring(RoundTimes))
self:OnUpdateRoundTimes(RoundTimes or 0, 7);
local RoundDeadTimes = UE.GetMiniRepData("RoundDeadTimes");
if RoundDeadTimes ~= nil then
self:SetRoundKill(RoundDeadTimes);
UGCLogSystem.LogTree(string.format("[WB_Title1:LuaInit] RoundDeadTimes ="), RoundDeadTimes)
else
self.TextBlock_SelfKill:SetText(0);
self.TextBlock_EnemyKill:SetText(0);
end
end
function WB_Title2: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_Title2:OnUpdateRoundTimes(InTimes, InTotal)
UGCLogSystem.Log("[WB_Title2: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_Title2: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_Title2:OnUpdateRoundWinners] Rounds ="), Rounds);
for PlayerKey, Times in pairs(Rounds) do
local TeamId = UE.GetTeamID(PlayerKey);
if TeamId == 1 then
self.TextBlock_SelfScore:SetText(Rounds[PlayerKey] or 0);
else
self.TextBlock_EnemyScore:SetText(Rounds[PlayerKey] or 0);
end
end
end
function WB_Title2:SetRoundKill(Kills)
self.TextBlock_SelfKill:SetText(0);
self.TextBlock_EnemyKill:SetText(0);
if table.isEmpty(Kills) then return ; end
for PlayerKey, Times in pairs(Kills) do
local TeamId = UE.GetTeamID(PlayerKey);
if TeamId == 1 then
self.TextBlock_EnemyKill:SetText(Times);
else
self.TextBlock_SelfKill:SetText(Times);
end
end
end
-- function WB_Title2:Tick(MyGeometry, InDeltaTime)
-- end
-- function WB_Title2:Destruct()
-- end
return WB_Title2