101 lines
3.3 KiB
Lua
101 lines
3.3 KiB
Lua
---@class WB_Title1_C:UUserWidget
|
|
---@field TextBlock_EnemyKill UTextBlock
|
|
---@field TextBlock_EnemyScore UTextBlock
|
|
---@field TextBlock_GameTime UTextBlock
|
|
---@field TextBlock_SelfKill UTextBlock
|
|
---@field TextBlock_SelfScore UTextBlock
|
|
---@field TextBlock_Time UTextBlock
|
|
--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);
|
|
|
|
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");
|
|
|
|
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
|
|
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: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);
|
|
if table.isEmpty(Kills) then return ; end
|
|
for i, v in pairs(Kills) do
|
|
if i == LocalPlayerKey then
|
|
self.TextBlock_EnemyKill:SetText(v);
|
|
else
|
|
self.TextBlock_SelfKill:SetText(v);
|
|
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; |