124 lines
4.4 KiB
Lua
124 lines
4.4 KiB
Lua
|
---@class WB_AutoRankItem_C:UUserWidget
|
||
|
---@field Button_Result_AddFriend UButton
|
||
|
---@field HorizontalBox_AllScore UHorizontalBox
|
||
|
---@field Image_PlayerIcon UImage
|
||
|
---@field TextBlock_PlayerName UTextBlock
|
||
|
---@field TextBlock_RankNum UTextBlock
|
||
|
---@field WidgetSwitcher_IsLocalPlayer UWidgetSwitcher
|
||
|
--Edit Below--
|
||
|
---@type WB_TeamRankItem_C
|
||
|
local WB_AutoRankItem = {
|
||
|
bInitDoOnce = false;
|
||
|
PlayerKey = -1;
|
||
|
};
|
||
|
|
||
|
function WB_AutoRankItem:LuaInit()
|
||
|
if self.bInitDoOnce then
|
||
|
return;
|
||
|
end
|
||
|
self.bInitDoOnce = true;
|
||
|
|
||
|
-- 初始化生成和设置颜色
|
||
|
for i, v in pairs(PlayerScoreSystem.Config.ShowRankType) do
|
||
|
local Item = self.HorizontalBox_AllScore:GetChildAt(i - 1)
|
||
|
if not UE.IsValid(Item) then
|
||
|
Item = UserWidget.NewWidgetObjectBP(UGCSystemLibrary.GetLocalPlayerController(), self:GetScoreItemClass());
|
||
|
self.HorizontalBox_AllScore:AddChild(Item)
|
||
|
end
|
||
|
Item:SetColorIndex(i)
|
||
|
end
|
||
|
-- 隐藏多余的Item的起始索引
|
||
|
local HideStartIndex = #PlayerScoreSystem.Config.ShowRankType
|
||
|
-- 判断是否显示总得分
|
||
|
if PlayerScoreSystem.Config.ShowTotalScore then
|
||
|
-- 如果显示总得分则起始索引+1
|
||
|
HideStartIndex = HideStartIndex + 1
|
||
|
-- 得分的初始化生成和设置颜色
|
||
|
local Item = self.HorizontalBox_AllScore:GetChildAt(#PlayerScoreSystem.Config.ShowRankType)
|
||
|
if not UE.IsValid(Item) then
|
||
|
Item = UserWidget.NewWidgetObjectBP(UGCSystemLibrary.GetLocalPlayerController(), self:GetScoreItemClass());
|
||
|
self.HorizontalBox_AllScore:AddChild(Item)
|
||
|
end
|
||
|
Item:SetColorIndex(#PlayerScoreSystem.Config.ShowRankType + 1)
|
||
|
end
|
||
|
-- 隐藏多余的Item
|
||
|
for i = HideStartIndex, self.HorizontalBox_AllScore:GetChildrenCount() - 1 do
|
||
|
self.HorizontalBox_AllScore:GetChildAt(i):SetVisibility(ESlateVisibility.Collapsed)
|
||
|
end
|
||
|
|
||
|
-- 绑定加好友
|
||
|
WidgetLibrary.BindButtonClicked(self.Button_Result_AddFriend, self.AddFriend, self)
|
||
|
end
|
||
|
|
||
|
function WB_AutoRankItem:SetTeam(TeamType)
|
||
|
-- UGCLogSystem.Log("[WB_TeamRankItem_SetTeam]")
|
||
|
local TeamColor = TeamConfig.TeamColor[TeamType]
|
||
|
-- 设置队伍颜色
|
||
|
if TeamColor then
|
||
|
self.TextBlock_RankNum:SetColorAndOpacity({SpecifiedColor = TeamColor, ColorUseRule = 0})
|
||
|
self.TextBlock_PlayerName:SetColorAndOpacity({SpecifiedColor = TeamColor, ColorUseRule = 0})
|
||
|
else
|
||
|
UGCLogSystem.LogError("[WB_TeamRankItem_SetTeam] TeamType:%s, TeamColorType: %s", tostring(TeamType), type(TeamColor))
|
||
|
end
|
||
|
end
|
||
|
|
||
|
function WB_AutoRankItem:SetIndex(Index)
|
||
|
self:LuaInit()
|
||
|
-- 设置索引
|
||
|
self.TextBlock_RankNum:SetText(tostring(Index));
|
||
|
end
|
||
|
|
||
|
function WB_AutoRankItem:HideAddFriend()
|
||
|
self.IsHideAddFriend = true
|
||
|
self.Button_Result_AddFriend:SetVisibility(ESlateVisibility.Collapsed)
|
||
|
end
|
||
|
|
||
|
function WB_AutoRankItem:AddFriend()
|
||
|
if UGCSystemLibrary.GetLocalPlayerKey() == self.PlayerKey then return end
|
||
|
local UID = UGCGameSystem.GameState:GetPlayerUIDByPlayerKey(self.PlayerKey)
|
||
|
if UID then
|
||
|
UGCGameSystem.AddFriend(UID)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
function WB_AutoRankItem:GetScoreItemClass()
|
||
|
if self.ScoreItemClass == nil then
|
||
|
self.ScoreItemClass = UE.LoadClass(UGCGameSystem.GetUGCResourcesFullPath('Asset/UI/Rank/AutoRank/WB_RankScore.WB_RankScore_C'))
|
||
|
end
|
||
|
return self.ScoreItemClass
|
||
|
end
|
||
|
|
||
|
function WB_AutoRankItem:InitRankInfo(PlayerKey)
|
||
|
-- 判断玩家PlayerKey是否修改
|
||
|
if self.PlayerKey ~= PlayerKey then
|
||
|
self.PlayerKey = PlayerKey
|
||
|
-- 若修改了则刷新玩家信息
|
||
|
UGCSystemLibrary.DownloadImageToUImage(self.Image_PlayerIcon, UGCGameSystem.GameState:GetHeadIconByPlayerKey(PlayerKey), true);
|
||
|
local PlayerName = UGCGameSystem.GameState:GetPlayerNameByPlayerKey(PlayerKey);
|
||
|
self.TextBlock_PlayerName:SetText(PlayerName);
|
||
|
if PlayerKey == UGCSystemLibrary.GetLocalPlayerKey() then
|
||
|
self.WidgetSwitcher_IsLocalPlayer:SetActiveWidgetIndex(1)
|
||
|
if not self.IsHideAddFriend then
|
||
|
self.Button_Result_AddFriend:SetVisibility(ESlateVisibility.Hidden)
|
||
|
end
|
||
|
else
|
||
|
self.WidgetSwitcher_IsLocalPlayer:SetActiveWidgetIndex(0)
|
||
|
if not self.IsHideAddFriend then
|
||
|
self.Button_Result_AddFriend:SetVisibility(ESlateVisibility.Visible)
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
|
||
|
-- 设置显示的参数数值
|
||
|
for i, v in pairs(PlayerScoreSystem.Config.ShowRankType) do
|
||
|
local Item = self.HorizontalBox_AllScore:GetChildAt(i - 1)
|
||
|
Item:SetScore(PlayerScoreSystem.GetPlayerScoreDataFromType(PlayerKey, v))
|
||
|
end
|
||
|
-- 判断是否显示总得分
|
||
|
if PlayerScoreSystem.Config.ShowTotalScore then
|
||
|
local Item = self.HorizontalBox_AllScore:GetChildAt(#PlayerScoreSystem.Config.ShowRankType)
|
||
|
Item:SetScore(PlayerScoreSystem.GetPlayerScore(PlayerKey))
|
||
|
end
|
||
|
end
|
||
|
|
||
|
return WB_AutoRankItem;
|