UGCProjects/AthleticMasters/Script/UI/Shop/W_WeaponShopWeaponInst.lua
2025-01-04 23:00:19 +08:00

98 lines
2.7 KiB
Lua

---@class W_WeaponShopWeaponInst_C:UUserWidget
---@field Button_ItemType UButton
---@field Image_WeaponType UImage
---@field Image_WeaponType2 UImage
---@field Overlay_WeaponCount UOverlay
---@field TextBlock_Count UTextBlock
---@field WidgetSwitcher_CanBuy UWidgetSwitcher
---@field WidgetSwitcher_Select UWidgetSwitcher
--Edit Below--
---@type W_WeaponShopWeaponInst_C
local W_WeaponShopWeaponInst = {
bInitDoOnce = false;
ItemKey = nil;
ItemCoin = 0;
};
--[==[ Construct
function W_WeaponShopWeaponInst:Construct()
end
-- Construct ]==]
-- function W_WeaponShopWeaponInst:Tick(MyGeometry, InDeltaTime)
-- end
-- function W_WeaponShopWeaponInst:Destruct()
-- end
function W_WeaponShopWeaponInst:LuaInit()
if self.bInitDoOnce then
return;
end
UGCEventSystem.AddListener(EventEnum.PlayerGoldCoinChange, self.UpdateCanBuy, self)
end
function W_WeaponShopWeaponInst:InitSelectInfo(ItemKey)
self:LuaInit()
self.Button_ItemType:SetTouchMethod(EButtonTouchMethod.PreciseTap)
self:SetItemKey(ItemKey)
if ItemTable.AllItem[ItemKey].BigPic then
local Tex = UGCSystemLibrary.LoadAsset(ItemTable.AllItem[ItemKey].BigPic, true)
self.Image_WeaponType:SetBrushFromTexture(Tex)
self.Image_WeaponType2:SetBrushFromTexture(Tex)
end
self.ItemCoin = WeaponShopTable.ItemPrice[ItemKey]
self:UpdateCanBuy()
self:UpdateCount()
end
function W_WeaponShopWeaponInst:SetItemKey(NewKey)
self.ItemKey = NewKey
end
function W_WeaponShopWeaponInst:GetItemKey()
return self.ItemKey
end
---@param bIsSelect: bool
function W_WeaponShopWeaponInst:SetSelect(bIsSelect)
self.WidgetSwitcher_Select:SetActiveWidgetIndex(bIsSelect and 1 or 0)
end
function W_WeaponShopWeaponInst:UpdateCanBuy()
local PlayerCoin = UGCGameSystem.GameState:GetPlayerCoin(UGCSystemLibrary.GetLocalPlayerKey())
if PlayerCoin >= self.ItemCoin then
self.WidgetSwitcher_CanBuy:SetActiveWidgetIndex(0)
else
self.WidgetSwitcher_CanBuy:SetActiveWidgetIndex(1)
end
end
function W_WeaponShopWeaponInst:UpdateCount()
if self.ItemKey then
local LocalPawn = UGCSystemLibrary.GetLocalPlayerPawn()
if UE.IsValid(LocalPawn) then
local Count = UGCBackPackSystem.GetItemCount(LocalPawn, self.ItemKey)
self:SetCount(Count)
end
else
self:SetCount(0)
end
end
function W_WeaponShopWeaponInst: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_WeaponShopWeaponInst;