127 lines
4.6 KiB
Lua
Raw Permalink Normal View History

2025-01-04 23:00:19 +08:00
---@class WB_NextWeapon_C:UUserWidget
---@field Button_ShowOther UButton
---@field Image_NextWeapon UImage
---@field TextBlock_Grade UTextBlock
---@field TextBlock_WeaponName UTextBlock
---@field VerticalBox_OtherWeapon UVerticalBox
---@field WidgetSwitcher_Next UWidgetSwitcher
---@field WidgetSwitcher_ShowOtherText UWidgetSwitcher
---@field WriteTex UTexture2D
--Edit Below--
---@type WB_NextWeapon_C
local WB_NextWeapon = {
bInitDoOnce = false;
PlayerWeaponGradient = {};
};
function WB_NextWeapon:Construct()
-- self:UpdateInfo()
UGCEventSystem.AddListener(EventEnum.PlayerGradientGradeChange, self.UpdateInfo, self)
-- UGCEventSystem.AddListener(EventEnum.PlayerGradientGradeChange, self.UpdateGradeInfo, self)
WidgetLibrary.BindButtonClicked(self.Button_ShowOther, self.ShowOtherWeaponInfo, self)
end
-- function WB_NextWeapon:Tick(MyGeometry, InDeltaTime)
-- end
-- function WB_NextWeapon:Destruct()
-- end
function WB_NextWeapon:UpdateInfo()
if not UE.IsValid(UGCGameSystem.GameState) then return end
local LocalPlayerKey = UGCSystemLibrary.GetLocalPlayerKey()
local WeaponID = UGCGameSystem.GameState:GetPlayerNextWeaponID(LocalPlayerKey)
local WeaponGradient = UGCGameSystem.GameState:GetPlayerWeaponGradientByPlayerKey(LocalPlayerKey)
local Grade = UGCGameSystem.GameState:GetPlayerWeaponGrade(LocalPlayerKey)
-- 检测梯度是否更新
self:CheckWeaponGradient(WeaponGradient)
-- 设置下一个武器信息
if WeaponID then
-- 设置武器图片名字等信息
self.TextBlock_WeaponName:SetVisibility(ESlateVisibility.SelfHitTestInvisible)
local ItemData = ItemTable.AllItem[WeaponID]
if ItemData and ItemData.BigPic then
local Tex = UGCSystemLibrary.LoadAsset(ItemData.BigPic, true)
self.Image_NextWeapon:SetBrushFromTexture(Tex, false)
self.TextBlock_WeaponName:SetText(ItemData.Name)
self.WidgetSwitcher_Next:SetActiveWidgetIndex(0)
elseif WeaponID < 0 then
self.TextBlock_WeaponName:SetText("-")
self.WidgetSwitcher_Next:SetActiveWidgetIndex(2)
else
UGCLogSystem.LogError("[WB_NextWeapon_UpdateInfo] ItemData Error %s", tostring(WeaponID))
end
else
self.WidgetSwitcher_Next:SetActiveWidgetIndex(1)
self.TextBlock_WeaponName:SetVisibility(ESlateVisibility.Hidden)
end
-- 设置等级
if Grade and WeaponGradient then
self.TextBlock_Grade:SetText(Grade .. " / " .. (#WeaponGradient))
end
-- 更新剩余梯度武器的显示
for i = 1, self.VerticalBox_OtherWeapon:GetChildrenCount() do
local Item = self.VerticalBox_OtherWeapon:GetChildAt(self.VerticalBox_OtherWeapon:GetChildrenCount() - i)
if i > #self.PlayerWeaponGradient - 2 or i < Grade then
Item:SetVis(false)
else
Item:SetVis(true)
end
end
end
function WB_NextWeapon:CheckWeaponGradient(NewWeaponGradient)
if type(NewWeaponGradient) ~= "table" then
return
end
local IsNew = false
if #NewWeaponGradient == self.PlayerWeaponGradient then
for i, v in pairs(NewWeaponGradient) do
if self.PlayerWeaponGradient[i] ~= v then
IsNew = true
break
end
end
else
IsNew = true
end
if IsNew then
self.PlayerWeaponGradient = table.DeepCopy(NewWeaponGradient)
self:CheckOtherWeaponItem()
for i = 1, self.VerticalBox_OtherWeapon:GetChildrenCount() do
local Item = self.VerticalBox_OtherWeapon:GetChildAt(self.VerticalBox_OtherWeapon:GetChildrenCount() - i)
if i > #self.PlayerWeaponGradient - 2 then
Item:SetVis(false)
else
Item:UpdateWeaponID(self.PlayerWeaponGradient[i + 2])
end
end
end
end
function WB_NextWeapon:CheckOtherWeaponItem()
while self.VerticalBox_OtherWeapon:GetChildrenCount() < (#self.PlayerWeaponGradient - 2) do
local Item = UserWidget.NewWidgetObjectBP(UGCSystemLibrary.GetLocalPlayerController(), ObjectPathTable.WB_NextWeaponItem_Class)
self.VerticalBox_OtherWeapon:AddChild(Item)
end
end
function WB_NextWeapon:ShowOtherWeaponInfo()
if self.VerticalBox_OtherWeapon:IsVisible() then
self.WidgetSwitcher_ShowOtherText:SetActiveWidgetIndex(0)
self.VerticalBox_OtherWeapon:SetVisibility(ESlateVisibility.Collapsed)
else
self.WidgetSwitcher_ShowOtherText:SetActiveWidgetIndex(1)
self.VerticalBox_OtherWeapon:SetVisibility(ESlateVisibility.SelfHitTestInvisible)
end
end
return WB_NextWeapon;