87 lines
2.3 KiB
Lua
87 lines
2.3 KiB
Lua
---@class WB_SelectPartItem_C:UUserWidget
|
|
---@field Button_Item UButton
|
|
---@field Image_Item UImage
|
|
---@field Image_None UImage
|
|
---@field WidgetSwitcher_Item UWidgetSwitcher
|
|
---@field WidgetSwitcher_Select UWidgetSwitcher
|
|
--Edit Below--
|
|
---@type WB_SelectPartItem_C
|
|
local WB_SelectPartItem = { bInitDoOnce = false; };
|
|
|
|
WB_SelectPartItem.PartId = 0;
|
|
|
|
function WB_SelectPartItem:Construct()
|
|
self:LuaInit();
|
|
end
|
|
|
|
WB_SelectPartItem.Owner = nil;
|
|
WB_SelectPartItem.Func = nil;
|
|
|
|
function WB_SelectPartItem:Init(Parent, Func)
|
|
self.Owner = Parent;
|
|
self.Func = Func;
|
|
self:LuaInit();
|
|
end
|
|
|
|
function WB_SelectPartItem:LuaInit()
|
|
if self.bInitDoOnce then return; end
|
|
|
|
self.Button_Item.OnClicked:Add(self.OnClickItem, self)
|
|
|
|
self.bInitDoOnce = true;
|
|
end
|
|
|
|
function WB_SelectPartItem:SetPartId(InPartId)
|
|
UGCLogSystem.Log("[WB_SelectPartItem:SetPartId] PartId = %d", InPartId);
|
|
self:SetVisibility(ESlateVisibility.Collapsed);
|
|
local InfoIcon = UGCItemSystem.GetItemData(InPartId).ItemSmallIcon_n
|
|
UE.AsyncLoadObject_Cached(InfoIcon, function(TargetObject)
|
|
self.Image_Item:SetBrushFromTexture(TargetObject);
|
|
self:SetVisibility(ESlateVisibility.SelfHitTestInvisible);
|
|
self:SetAsNone(false);
|
|
end);
|
|
self.PartId = InPartId;
|
|
end
|
|
|
|
function WB_SelectPartItem:ClearPartId()
|
|
self.PartId = 0;
|
|
-- 清空
|
|
self.Image_Item:SetBrushFromTexture(nil);
|
|
self:SetAsNone(true);
|
|
end
|
|
|
|
function WB_SelectPartItem:OnClickItem()
|
|
local PartType = self.Owner:GetCurrPartType()
|
|
if PartType == nil then return; end
|
|
-- 发送过去
|
|
if not self:IsSelect() then
|
|
local Pawn = UGCGameSystem.GetPlayerPawnByPlayerKey(LocalPlayerKey);
|
|
UnrealNetwork.CallUnrealRPC(LocalPlayerController, Pawn, "ReplacePartId", self.PartId, PartType);
|
|
-- 设置点击
|
|
self.Func(self.Owner, self);
|
|
end
|
|
end
|
|
|
|
function WB_SelectPartItem:SetAsNone(IsNone)
|
|
self.WidgetSwitcher_Item:SetActiveWidgetIndex(IsNone and 1 or 0);
|
|
end
|
|
|
|
function WB_SelectPartItem:SetSelect(IsSelect)
|
|
self.WidgetSwitcher_Select:SetActiveWidgetIndex(IsSelect and 0 or 1);
|
|
end
|
|
|
|
function WB_SelectPartItem:GetPartId() return self.PartId; end
|
|
|
|
function WB_SelectPartItem:IsSelect()
|
|
return self.WidgetSwitcher_Select:GetActiveWidgetIndex() == 0;
|
|
end
|
|
|
|
-- function WB_SelectPartItem:Tick(MyGeometry, InDeltaTime)
|
|
|
|
-- end
|
|
|
|
-- function WB_SelectPartItem:Destruct()
|
|
|
|
-- end
|
|
|
|
return WB_SelectPartItem; |