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

263 lines
8.7 KiB
Lua

---@class WB_Main_C:UAEUserWidget
---@field ShowScore UWidgetAnimation
---@field Button_FaceNotice UButton
---@field Button_Score UButton
---@field Button_Test UButton
---@field Button_Test_Custom UButton
---@field Button_TestSide UButton
---@field CanvasPanel_Prepare UCanvasPanel
---@field CanvasPanel_Test UCanvasPanel
---@field Image_248 UImage
---@field TextBlock_CountDown UTextBlock
---@field TextBlock_EnemyScore UTextBlock
---@field TextBlock_Prepare UTextBlock
---@field TextBlock_ReloadTime UTextBlock
---@field TextBlock_SelfScore UTextBlock
---@field TextBlock_ServerTime UTextBlock
---@field TextBlock_State UTextBlock
---@field TextBlock_Time UTextBlock
---@field WB_Bolts UWB_Bolts_C
---@field WB_BoltTips UWB_BoltTips_C
---@field WB_InTest_Side UWB_InTest_Side_C
---@field WB_PlayerInfo_Small UWB_PlayerInfo_Small_C
---@field WB_RoundEnd UWB_RoundEnd_C
---@field WB_SelectParts UWB_SelectParts_C
--Edit Below--
---@type WB_Main_C
local WB_Main = { bInitDoOnce = false; };
WB_Main.IsTestShow = true;
WB_Main.BuffButtons = {};
WB_Main.ShowRoundTimes = false;
function WB_Main:Construct()
UGCLogSystem.Log("[WB_Main:Construct] 执行")
UGCEventSystem.AddListener(EventTypes.CountDownTimeChange, self.OnCountDownChange, self)
UGCEventSystem.AddListener(EventTypes.MiniStateChange, self.OnMiniStateChange, self)
UGCEventSystem.AddListener(EventTypes.UpdateRoundTimes, self.OnUpdateRoundTimes, self)
UGCEventSystem.AddListener(EventTypes.UpdatePlayerKDAs, self.OnUpdatePlayerKDAs, self)
UGCEventSystem.AddListener(EventTypes.ChangeBuffs, self.OnChangeBuffs, self)
UITool.ButtonOnClickShowPanel(self.Button_FaceNotice, WidgetConfig.EUIType.FaceNotice, true);
if DefaultSettings.EnableTest then
self.WB_InTest_Side:LuaInit();
UITool.ButtonOnClickShowPanel(self.Button_Test, WidgetConfig.EUIType.Test, true);
UITool.BindButtonClicked(self.Button_TestSide, self.OnClickTestSide, self);
UITool.BindButtonClicked(self.Button_Test_Custom, self.OnClickCustomTest, self);
GlobalTickTool:AddTick(self, function(o, dt, st)
o.TextBlock_ServerTime:SetText(string.format("服务器时间:%0.1f", st))
end);
else
self.CanvasPanel_Test:SetVisibility(ESlateVisibility.Collapsed);
end
UITool.BindButtonClicked(self.Button_Score, self.OnShowScore, self)
self.TextBlock_Time:SetText("0")
self.TextBlock_SelfScore:SetText("0")
self.TextBlock_EnemyScore:SetText("0")
self.WB_RoundEnd:SetVisibility(ESlateVisibility.Collapsed);
if GlobalMiniMode then
if GlobalMiniMode.State then
if GlobalMiniMode.State < MiniGameState.ROUND_GAMING then
self.CanvasPanel_Prepare:SetVisibility(ESlateVisibility.SelfHitTestInvisible);
else
self.CanvasPanel_Prepare:SetVisibility(ESlateVisibility.Collapsed);
end
end
end
self.WB_Bolts:SetVisibility(ESlateVisibility.Collapsed);
UIManager:Register("WB_Bolts", self.WB_Bolts);
UIManager:Register("WB_PlayerInfo_Small", self.WB_PlayerInfo_Small);
UIManager:Register("WB_RoundEnd", self.WB_RoundEnd);
UIManager:Register("WB_SelectParts", self.WB_SelectParts);
UIManager:Register("WB_Main", self);
UIManager:Register("WB_BoltTips", self.WB_BoltTips);
if self.ShowRoundTimes then
self.TextBlock_Time:SetVisibility(ESlateVisibility.SelfHitTestInvisible);
else
self.TextBlock_Time:SetVisibility(ESlateVisibility.Collapsed);
end
self.WB_SelectParts:SetType({ EWeaponPartType.Telescope, EWeaponPartType.Grip, EWeaponPartType.Muzzle, });
self.BuffButtons = {
self.WB_BuffButton,
}
for i, v in pairs(self.BuffButtons) do v:SetBuffIndex(i); end
self:OnClickTestSide();
end
function WB_Main:Tick(MyGeometry, InDeltaTime)
end
function WB_Main:Destruct()
UGCEventSystem.RemoveListener(EventTypes.CountDownTimeChange, self.OnCountDownChange, self)
UGCEventSystem.RemoveListener(EventTypes.MiniStateChange, self.OnMiniStateChange, self);
UGCEventSystem.RemoveListener(EventTypes.UpdateRoundTimes, self.OnUpdateRoundTimes, self);
UGCEventSystem.RemoveListener(EventTypes.ChangeBuffs, self.OnChangeBuffs, self);
end
function WB_Main:OnClickTestSide()
UITool.TurnVisible(self.WB_InTest_Side)
end
function WB_Main:OnClickCustomTest()
if self.IsTestShow then
self.WB_InTest_Side:SetVisibility(ESlateVisibility.Collapsed)
self.Button_FaceNotice:SetVisibility(ESlateVisibility.Collapsed)
self.Button_Test:SetVisibility(ESlateVisibility.Collapsed)
self.Button_TestSide:SetVisibility(ESlateVisibility.Collapsed)
else
self.WB_InTest_Side:SetVisibility(ESlateVisibility.SelfHitTestInvisible)
self.Button_FaceNotice:SetVisibility(ESlateVisibility.SelfHitTestInvisible)
self.Button_Test:SetVisibility(ESlateVisibility.SelfHitTestInvisible)
self.Button_TestSide:SetVisibility(ESlateVisibility.SelfHitTestInvisible)
end
self.IsTestShow = not self.IsTestShow;
end
function WB_Main:OnCountDownChange(InTime)
if not self.ShowRoundTimes then
UGCLogSystem.Log("[WB_Main:OnCountDownChange] InTime = %s", tostring(InTime));
if InTime <= 0 then
self.TextBlock_CountDown:SetText("00:00")
else
self.TextBlock_CountDown:SetText(string.format("%02d:%02d", InTime // 60, InTime % 60));
end
end
end
--function WB_Main:OnAllPlayerKDAChange(InList)
-- UGCLogSystem.LogTree(string.format("[WB_Main:OnAllPlayerKDAChange] InList ="), InList)
-- -- 计算总数
-- local Total = 0;
-- for i, v in pairs(InList) do
-- -- 加载头像
-- Total = Total + v.KDA.Kill;
-- if LocalPlayerKey == v.PlayerKey then
-- self.TextBlock_SelfScore:SetText(v.KDA.Kill);
-- end
-- end
-- self.TextBlock_EnemyScore:SetText(Total);
--end
WB_Main.IsShowScore = false;
function WB_Main:OnShowScore()
self.IsShowScore = not self.IsShowScore;
if self.IsShowScore then
self:PlayAnimation(self.ShowScore, 0, 1, EUMGSequencePlayMode.Forward, 1)
else
self:PlayAnimation(self.ShowScore, 0, 1, EUMGSequencePlayMode.Reverse, 1);
end
end
WB_Main.DotCount = 0;
function WB_Main:OnPrepareTick()
--UGCLogSystem.Log("[WB_Main:OnPrepareTick] DotCount = %s", tostring(self.DotCount));
self.DotCount = (self.DotCount + 1) % 3;
local Str = "游戏准备中."
for i = 1, self.DotCount do Str = Str .. '.' end
self.TextBlock_Prepare:SetText(Str);
end
WB_Main.IsShowDetail = false;
function WB_Main:OnGameStart()
UGCLogSystem.Log("[WB_Main:OnGameStart] 执行")
self.CanvasPanel_Prepare:SetVisibility(ESlateVisibility.Collapsed);
GlobalTickTool:RemoveAll(self);
self.DotCount = nil;
--WidgetManager:ClosePanel(WidgetConfig.EUIType.FaceNotice);
end
WB_Main.ShowRoundWinTimer = nil;
function WB_Main:ShowRoundWin(IsShow, Winner)
if IsShow then
self.WB_RoundEnd:SetVisibility(ESlateVisibility.HitTestInvisible);
self.WB_RoundEnd:SetWin(Winner == LocalPlayerKey);
-- 定时关闭
UGCEventSystem.SetTimer(self, function()
self.WB_RoundEnd:SetVisibility(ESlateVisibility.Collapsed);
end, 10);
else
self.WB_RoundEnd:SetVisibility(ESlateVisibility.Collapsed);
if self.ShowRoundWinTimer ~= nil then
UGCEventSystem.StopTimer(self.ShowRoundWinTimer);
self.ShowRoundWinTimer = nil;
end
end
end
function WB_Main:SetReloadTime(InTime)
UGCLogSystem.Log("[WB_Main:SetReloadTime] InTime = %f", InTime);
if InTime >= 0 then
self.TextBlock_ReloadTime:SetText(string.format("%0.1f", InTime));
UITool.ShowTips("换弹时间:%0.1f", InTime)
else
self.TextBlock_ReloadTime:SetText(string.format("无限"));
UITool.ShowTips("不需要换弹!!")
end
end
function WB_Main:OnMiniStateChange(InState)
self.TextBlock_State:SetText(TableHelper.printEnum(MiniGameState, InState));
end
function WB_Main:OnUpdateRoundTimes(InTimes, InTotal)
UGCLogSystem.Log("[WB_Main:OnUpdateRoundTimes] InTimes = %s, InTotal = %s", tostring(InTimes), tostring(InTotal));
if InTimes ~= nil and InTotal ~= nil then
self.TextBlock_Time:SetText(tostring(InTotal - InTimes));
end
end
function WB_Main:OnUpdatePlayerKDAs(InKDAs)
local Self, Total, Max = 0, 0, 0;
for PlayerKey, Kda in pairs(InKDAs) do
if PlayerKey == LocalPlayerKey then
Self = Kda.Kill;
end
if Kda.Kill > Max then Max = Kda.Kill; end
Total = Total + Kda.Kill;
end
self.TextBlock_SelfScore:SetText(Self);
self.TextBlock_EnemyScore:SetText(Max);
if Self == Max then
-- 设置颜色
else
-- 设置颜色
end
self.WB_PlayerInfo_Small:UpdatePlayerKDAs(InKDAs);
end
function WB_Main:OnChangeBuffs(InPlayerKey, InBuffs)
if table.isEmpty(InBuffs) then
for i, v in pairs(self.BuffButtons) do
v:SetVisibility(ESlateVisibility.Collapsed);
end
end
for i, v in pairs(self.BuffButtons) do
v:SetBuffType(InBuffs[i]);
v:SetVisibility(ESlateVisibility.Visible);
end
end
function WB_Main:SetRangePercent(InPercent)
self.WB_RangeMinimap:SetRangePercent(InPercent);
end
------------------------------------ Test ------------------------------------
function WB_Main:AddLogItems(InList)
self.WB_TestLog:AddLogItems(InList);
end
function WB_Main:AddLogItem(Color, fmt, ...)
self.WB_TestLog:AddLog(Color, fmt, ...);
end
return WB_Main;