158 lines
5.6 KiB
Lua
158 lines
5.6 KiB
Lua
|
---@class WB_Title1_C:UUserWidget
|
||
|
---@field CanvasPanel_2 UCanvasPanel
|
||
|
---@field Image_LeftSide_SlotBG UImage
|
||
|
---@field Image_RightSide_SlotBG UImage
|
||
|
---@field NewButton_TC_ScoreBoard UNewButton
|
||
|
---@field TextBlock_GameTime UTextBlock
|
||
|
---@field TextBlock_LeftSide_Champion_Level UTextBlock
|
||
|
---@field TextBlock_LeftSide_Current_Num UTextBlock
|
||
|
---@field TextBlock_LeftSide_Total_Num UTextBlock
|
||
|
---@field TextBlock_RightSide_Champion_Level UTextBlock
|
||
|
---@field TextBlock_RightSide_Current_Num UTextBlock
|
||
|
---@field TextBlock_RightSide_Total_Num UTextBlock
|
||
|
---@field TextBlock_TargetNum UTextBlock
|
||
|
---@field WidgetSwitcher_Enemy UWidgetSwitcher
|
||
|
---@field WidgetSwitcher_EnemyIconBorder UWidgetSwitcher
|
||
|
---@field WidgetSwitcher_EnemyTeamColor UWidgetSwitcher
|
||
|
---@field WidgetSwitcher_Self UWidgetSwitcher
|
||
|
---@field WidgetSwitcher_SelfIconBorder UWidgetSwitcher
|
||
|
---@field WidgetSwitcher_SelfTeamColor UWidgetSwitcher
|
||
|
--Edit Below--
|
||
|
---@type WB_Title1_C
|
||
|
local WB_Title1 = { bInitDoOnce = false }
|
||
|
WB_Title1.Owner = nil;
|
||
|
WB_Title1.Func = nil;
|
||
|
function WB_Title1:Construct()
|
||
|
self:LuaInit();
|
||
|
end
|
||
|
function WB_Title1:LuaInit()
|
||
|
if self.bInitDoOnce then return ; end
|
||
|
|
||
|
UGCEventSystem.AddListener(EventTypes.CountDownTimeChange, self.OnCountDownChange, self)
|
||
|
UGCEventSystem.AddListener(EventTypes.UpdatePlayerKDAs, self.OnUpdatePlayerKDAs, self)
|
||
|
UGCEventSystem.AddListener(EventTypes.UpdatePlayerDatas, self.OnUpdatePlayerDatas, self);
|
||
|
UGCEventSystem.AddListener(EventTypes.MiniStateChange, self.OnMiniStateChange, self)
|
||
|
|
||
|
--UITool.ButtonOnClickShowPanel(self.NewButton_TC_ScoreBoard, WidgetConfig.EUIType.PlayerScores, true);
|
||
|
UITool.BindButtonClicked(self.NewButton_TC_ScoreBoard, self.OnClickScore, self)
|
||
|
|
||
|
self.TextBlock_TargetNum:SetText("准备");
|
||
|
self.TextBlock_GameTime:SetText("00:00");
|
||
|
self.TextBlock_LeftSide_Current_Num:SetText("00");
|
||
|
self.TextBlock_RightSide_Total_Num:SetText("00");
|
||
|
|
||
|
self.bInitDoOnce = true;
|
||
|
end
|
||
|
function WB_Title1:Destruct()
|
||
|
UGCEventSystem.RemoveListener(EventTypes.CountDownTimeChange, self.OnCountDownChange, self)
|
||
|
UGCEventSystem.RemoveListener(EventTypes.UpdatePlayerKDAs, self.OnUpdatePlayerKDAs, self)
|
||
|
UGCEventSystem.RemoveListener(EventTypes.UpdatePlayerDatas, self.OnUpdatePlayerDatas, self);
|
||
|
UGCEventSystem.RemoveListener(EventTypes.MiniStateChange, self.OnMiniStateChange, self)
|
||
|
end
|
||
|
function WB_Title1:OnClickScore()
|
||
|
if self.Func and self.Owner then self.Func(self.Owner); end
|
||
|
end
|
||
|
function WB_Title1:SetOwner(InOwner, InFunc)
|
||
|
self.Owner = InOwner;
|
||
|
self.Func = InFunc;
|
||
|
end
|
||
|
-- function WB_Title1:Tick(MyGeometry, InDeltaTime)
|
||
|
-- end
|
||
|
function WB_Title1:OnCountDownChange(InTime)
|
||
|
UGCLogSystem.Log("[WB_Title1:OnCountDownChange] InTime = %s", tostring(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:OnUpdatePlayerKDAs(InKDAs)
|
||
|
local Self, Total, Max = 0, 0, 0;
|
||
|
-- 计算对面多的
|
||
|
local TeamMax = {};
|
||
|
for PlayerKey, Kda in pairs(InKDAs) do
|
||
|
local Info = UGCGameSystem.GameState.PlayerDatas.AccountInfo[PlayerKey];
|
||
|
if Info then
|
||
|
local TeamId = Info.TeamID;
|
||
|
if TeamMax[TeamId] == nil then
|
||
|
TeamMax[TeamId] = {
|
||
|
Kill = Kda.Kill,
|
||
|
PlayerKey = PlayerKey,
|
||
|
};
|
||
|
else
|
||
|
if Kda.Kill > TeamMax[TeamId].Kill then
|
||
|
TeamMax[TeamId] = {
|
||
|
Kill = Kda.Kill,
|
||
|
PlayerKey = PlayerKey,
|
||
|
};
|
||
|
end
|
||
|
end
|
||
|
-- 总数
|
||
|
if Kda.Kill > Max then Max = Kda.Kill; end
|
||
|
Total = Total + Kda.Kill;
|
||
|
end
|
||
|
end
|
||
|
|
||
|
UGCLogSystem.LogTree(string.format("[WB_Title1:OnUpdatePlayerKDAs] TeamMax"), TeamMax)
|
||
|
|
||
|
for TeamId, Info in pairs(TeamMax) do
|
||
|
if TeamId == LocalTeamId then
|
||
|
self.TextBlock_LeftSide_Current_Num:SetText(string.format("%02d", Info.Kill));
|
||
|
-- 计算数据
|
||
|
self:SetMaxIcon(self.Image_LeftSide_SlotBG, Info.PlayerKey);
|
||
|
else
|
||
|
self.TextBlock_RightSide_Total_Num:SetText(string.format("%02d", Info.Kill));
|
||
|
self:SetMaxIcon(self.Image_RightSide_SlotBG, Info.PlayerKey);
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
function WB_Title1:SetMaxIcon(Image, InPlayerKey)
|
||
|
local AccountInfo = GameState.PlayerDatas.AccountInfo[InPlayerKey]
|
||
|
if AccountInfo == nil then
|
||
|
-- 默认使用这个图片
|
||
|
Image:SetBrushFromTexture(ObjectPath.Armament_img_kuang2_50x50_png, true);
|
||
|
return ;
|
||
|
end
|
||
|
UITool.DownloadImage(AccountInfo.IconURL, function(Texture)
|
||
|
Image:SetBrushFromTextureDynamic(Texture);
|
||
|
end)
|
||
|
end
|
||
|
function WB_Title1:OnUpdatePlayerDatas(InDatas)
|
||
|
for i, v in pairs(InDatas.AccountInfo) do
|
||
|
-- 先缓存一波
|
||
|
UITool.DownloadImage(v.IconURL);
|
||
|
end
|
||
|
|
||
|
if LocalPlayerKey == nil then return; end
|
||
|
if LocalTeamId == nil then return; end
|
||
|
|
||
|
if LocalTeamId == ETeamType.Red then
|
||
|
-- 说明是红方
|
||
|
self.WidgetSwitcher_Self:SetActiveWidgetIndex(1);
|
||
|
self.WidgetSwitcher_SelfTeamColor:SetActiveWidgetIndex(1);
|
||
|
self.WidgetSwitcher_SelfIconBorder:SetActiveWidgetIndex(1);
|
||
|
|
||
|
self.WidgetSwitcher_Enemy:SetActiveWidgetIndex(0);
|
||
|
self.WidgetSwitcher_EnemyIconBorder:SetActiveWidgetIndex(0);
|
||
|
self.WidgetSwitcher_EnemyTeamColor:SetActiveWidgetIndex(0);
|
||
|
else
|
||
|
self.WidgetSwitcher_Self:SetActiveWidgetIndex(0);
|
||
|
self.WidgetSwitcher_SelfTeamColor:SetActiveWidgetIndex(0);
|
||
|
self.WidgetSwitcher_SelfIconBorder:SetActiveWidgetIndex(0);
|
||
|
|
||
|
self.WidgetSwitcher_Enemy:SetActiveWidgetIndex(1);
|
||
|
self.WidgetSwitcher_EnemyIconBorder:SetActiveWidgetIndex(1);
|
||
|
self.WidgetSwitcher_EnemyTeamColor:SetActiveWidgetIndex(1);
|
||
|
end
|
||
|
end
|
||
|
|
||
|
function WB_Title1:OnMiniStateChange(InState)
|
||
|
if InState < MiniGameState.ROUND_GAMING then
|
||
|
self.TextBlock_TargetNum:SetText("准备");
|
||
|
elseif InState == MiniGameState.ROUND_GAMING then
|
||
|
self.TextBlock_TargetNum:SetText("游戏中");
|
||
|
else
|
||
|
self.TextBlock_TargetNum:SetText("结束");
|
||
|
end
|
||
|
end
|
||
|
return WB_Title1
|