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

72 lines
2.0 KiB
Lua

---@class W_WeaponProp_C:UUserWidget
---@field Image_Part UImage
---@field Overlay_WeaponCount UOverlay
---@field TextBlock_Count UTextBlock
---@field WidgetSwitcher_BG UWidgetSwitcher
---@field WidgetSwitcher_HasPart UWidgetSwitcher
---@field WidgetSwitcher_PartType UWidgetSwitcher
--Edit Below--
---@type W_WeaponProp_C
local W_WeaponProp = { bInitDoOnce = false; };
--[==[ Construct
function W_WeaponProp:Construct()
end
-- Construct ]==]
-- function W_WeaponProp:Tick(MyGeometry, InDeltaTime)
-- end
-- function W_WeaponProp:Destruct()
-- end
function W_WeaponProp:Init(InPartType)
self.PartType = InPartType
self.WidgetSwitcher_PartType:SetActiveWidgetIndex(InPartType - 1)
end
function W_WeaponProp:GetPartType()
return self.PartType
end
function W_WeaponProp:SetHasPart(InHasPart, InPartID)
self.PartID = nil
if InHasPart then
self.WidgetSwitcher_HasPart:SetActiveWidgetIndex(1)
self.WidgetSwitcher_BG:SetActiveWidgetIndex(1)
self.PartID = InPartID
local PartPath = ItemTable.AllItem[self.PartID].SmallPic
local Tex = UGCSystemLibrary.LoadAsset(PartPath, true)
self.Image_Part:SetBrushFromTexture(Tex)
else
self.WidgetSwitcher_HasPart:SetActiveWidgetIndex(0)
self.WidgetSwitcher_BG:SetActiveWidgetIndex(0)
end
self:UpdateCount()
end
function W_WeaponProp:UpdateCount()
if self.PartID then
local LocalPawn = UGCSystemLibrary.GetLocalPlayerPawn()
if UE.IsValid(LocalPawn) then
local Count = UGCBackPackSystem.GetItemCount(LocalPawn, self.PartID)
self:SetCount(Count)
end
else
self:SetCount(0)
end
end
function W_WeaponProp:SetCount(InCount)
if InCount > 0 then
self.TextBlock_Count:SetText(tostring(InCount))
self.Overlay_WeaponCount:SetVisibility(ESlateVisibility.SelfHitTestInvisible)
else
self.Overlay_WeaponCount:SetVisibility(ESlateVisibility.Collapsed)
end
end
return W_WeaponProp;