172 lines
6.9 KiB
Lua
172 lines
6.9 KiB
Lua
|
---@class WB_PlaceItem_C:UUserWidget
|
|||
|
---@field Button_Select UButton
|
|||
|
---@field Image_BG UImage
|
|||
|
---@field Image_ItemTex UImage
|
|||
|
---@field Overlay_CanUnlock UOverlay
|
|||
|
---@field Overlay_Count UOverlay
|
|||
|
---@field Overlay_IsSelect UOverlay
|
|||
|
---@field Overlay_Lock UOverlay
|
|||
|
---@field TextBlock_Cost UTextBlock
|
|||
|
---@field TextBlock_Count UTextBlock
|
|||
|
---@field TextBlock_Name UTextBlock
|
|||
|
---@field TextBlock_Unlock UTextBlock
|
|||
|
---@field WidgetSwitcher_CanUnLock UWidgetSwitcher
|
|||
|
---@field WidgetSwitcher_UnlockType UWidgetSwitcher
|
|||
|
--Edit Below--
|
|||
|
local WB_PlaceItem = {
|
|||
|
bInitDoOnce = false;
|
|||
|
ItemType = nil;
|
|||
|
bIsLock = false;
|
|||
|
};
|
|||
|
|
|||
|
--[==[ Construct
|
|||
|
function WB_PlaceItem:Construct()
|
|||
|
|
|||
|
end
|
|||
|
-- Construct ]==]
|
|||
|
|
|||
|
-- function WB_PlaceItem:Tick(MyGeometry, InDeltaTime)
|
|||
|
|
|||
|
-- end
|
|||
|
|
|||
|
-- function WB_PlaceItem:Destruct()
|
|||
|
|
|||
|
-- end
|
|||
|
|
|||
|
function WB_PlaceItem:LuaInit()
|
|||
|
if self.bInitDoOnce then
|
|||
|
return;
|
|||
|
end
|
|||
|
self.bInitDoOnce = true;
|
|||
|
self.Button_Select:SetTouchMethod(EButtonTouchMethod.PreciseTap)
|
|||
|
WidgetLibrary.BindButtonPressed(self.Button_Select, self.SelectItem, self)
|
|||
|
UGCEventSystem.AddListener(EventEnum.PlaceItemTypeIsChange, self.UpdateSelectItem, self)
|
|||
|
UGCEventSystem.AddListener(EventEnum.UpdatePlacedItemCount, self.UpdatePlacedItemCount, self)
|
|||
|
UGCEventSystem.AddListener(ArchiveDataConfig.GetParamNotifyEvent(ArchiveDataConfig.EArchiveType.ItemIncrement), self.UpdateIsLock, self)
|
|||
|
UGCEventSystem.AddListener(ArchiveDataConfig.GetParamNotifyEvent(ArchiveDataConfig.EArchiveType.Exp), self.UpdateCanUnlock, self)
|
|||
|
UGCEventSystem.AddListener(ArchiveDataConfig.GetParamNotifyEvent(ArchiveDataConfig.EArchiveType.Gold), self.UpdateCanUnlock, self)
|
|||
|
end
|
|||
|
|
|||
|
|
|||
|
|
|||
|
function WB_PlaceItem:SetItemType(InType)
|
|||
|
self:LuaInit()
|
|||
|
if PlacementModeConfig.ItemInfo[InType] then
|
|||
|
self.ItemType = InType
|
|||
|
local TexPath = PlacementModeConfig.ItemInfo[InType].SelectTex
|
|||
|
local Cost = PlacementModeConfig.ItemInfo[InType].Cost
|
|||
|
-- local Name = PlacementModeConfig.ItemInfo[InType].Name
|
|||
|
local Tex = UGCSystemLibrary.LoadAsset(TexPath, false)
|
|||
|
if Tex then
|
|||
|
self.Image_ItemTex:SetBrushFromTexture(Tex, false)
|
|||
|
end
|
|||
|
self.TextBlock_Cost:SetText(tostring(Cost))
|
|||
|
self:UpdateIsLock()
|
|||
|
end
|
|||
|
end
|
|||
|
|
|||
|
function WB_PlaceItem:SelectItem()
|
|||
|
if self.ItemType then
|
|||
|
SoundSystem.PlaySound(SoundSystem.ESound.Click)
|
|||
|
local PlaceManager = PlacementModeConfig.GetPlaceManager()
|
|||
|
if self.bIsLock then
|
|||
|
-- 二次确定消耗解锁
|
|||
|
|
|||
|
local UnlockType, Cost = PlacementModeConfig.GetPlaceItemUnlockInfo(self.ItemType)
|
|||
|
local SecondaryConfirmationWidget = WidgetManager:GetPanel(WidgetConfig.EUIType.SecondaryConfirmation)
|
|||
|
|
|||
|
if PlacementModeConfig.EUnlockType.None == UnlockType then
|
|||
|
elseif PlacementModeConfig.EUnlockType.Level == UnlockType then
|
|||
|
SecondaryConfirmationWidget:SetTextInfo("是否进行解锁?")
|
|||
|
else
|
|||
|
SecondaryConfirmationWidget:SetTextInfo(string.format("是否消耗%s%s进行解锁?", tostring(Cost), PlacementModeConfig.UnlockName[UnlockType]))
|
|||
|
end
|
|||
|
SecondaryConfirmationWidget:BindConfirmCallBack(self.ConfirmUnLock, self)
|
|||
|
WidgetManager:ShowPanel(WidgetConfig.EUIType.SecondaryConfirmation, false)
|
|||
|
else
|
|||
|
if PlaceManager then
|
|||
|
local PlacementModeType = PlaceManager:GetPlacementModeType()
|
|||
|
if PlacementModeType == PlacementModeConfig.EPlaceMode.RemoveMode then
|
|||
|
local SecondaryConfirmationWidget = WidgetManager:GetPanel(WidgetConfig.EUIType.SecondaryConfirmation)
|
|||
|
SecondaryConfirmationWidget:SetTextInfo(string.format("是否要清除所有%s?", PlacementModeConfig.ItemInfo[self.ItemType].Name))
|
|||
|
SecondaryConfirmationWidget:BindConfirmCallBack(self.ConfirmClearItem, self)
|
|||
|
WidgetManager:ShowPanel(WidgetConfig.EUIType.SecondaryConfirmation, false)
|
|||
|
end
|
|||
|
end
|
|||
|
end
|
|||
|
if PlaceManager then
|
|||
|
PlaceManager:SetPlaceItemType(self.ItemType)
|
|||
|
end
|
|||
|
end
|
|||
|
end
|
|||
|
|
|||
|
function WB_PlaceItem:ConfirmUnLock()
|
|||
|
if self.ItemType then
|
|||
|
UGCSendRPCSystem.ActorRPCNotify(nil, UGCGameSystem.GameState, "UnlockPlaceItem", UGCSystemLibrary.GetLocalPlayerKey(), self.ItemType)
|
|||
|
end
|
|||
|
end
|
|||
|
|
|||
|
function WB_PlaceItem:ConfirmClearItem()
|
|||
|
if self.ItemType then
|
|||
|
UGCSendRPCSystem.ActorRPCNotify(nil, PlacementModeConfig.GetPlaceManager(), "RemoveItemFromType", self.ItemType)
|
|||
|
end
|
|||
|
end
|
|||
|
|
|||
|
function WB_PlaceItem:UpdateSelectItem(InItemType)
|
|||
|
if InItemType == self.ItemType then
|
|||
|
self.Image_BG:SetVisibility(ESlateVisibility.SelfHitTestInvisible);
|
|||
|
self.Overlay_IsSelect:SetVisibility(ESlateVisibility.SelfHitTestInvisible);
|
|||
|
else
|
|||
|
self.Image_BG:SetVisibility(ESlateVisibility.Collapsed);
|
|||
|
self.Overlay_IsSelect:SetVisibility(ESlateVisibility.Collapsed);
|
|||
|
end
|
|||
|
end
|
|||
|
|
|||
|
function WB_PlaceItem:UpdatePlacedItemCount()
|
|||
|
local PlaceManage = PlacementModeConfig.GetPlaceManager()
|
|||
|
UGCLogSystem.Log("[WB_PlaceItem_UpdatePlacedItemCount] PlaceManage:%s", tostring(UE.IsValid(PlaceManage)))
|
|||
|
local Count = PlacementModeConfig.GetPlaceManager():GetPlacedItemNum(self.ItemType)
|
|||
|
if Count <= 0 then
|
|||
|
self.Overlay_Count:SetVisibility(ESlateVisibility.Collapsed)
|
|||
|
else
|
|||
|
self.TextBlock_Count:SetText(tostring(Count))
|
|||
|
self.Overlay_Count:SetVisibility(ESlateVisibility.SelfHitTestInvisible)
|
|||
|
end
|
|||
|
end
|
|||
|
|
|||
|
function WB_PlaceItem:ItemIsLock(InType)
|
|||
|
if InType == nil then return false end
|
|||
|
local UnlockType = PlacementModeConfig.GetPlaceItemUnlockInfo(InType)
|
|||
|
if UnlockType == PlacementModeConfig.EUnlockType.None then return false end
|
|||
|
local ItemIncrement = ArchiveDataConfig.GetPlayerArchiveDataFromType(UGCSystemLibrary.GetLocalPlayerKey(), ArchiveDataConfig.EArchiveType.ItemIncrement)
|
|||
|
return (ItemIncrement == nil or ItemIncrement[InType] == nil or ItemIncrement[InType] == 0)
|
|||
|
end
|
|||
|
|
|||
|
function WB_PlaceItem:UpdateIsLock()
|
|||
|
self.bIsLock = self:ItemIsLock(self.ItemType)
|
|||
|
if self.bIsLock then
|
|||
|
self.Overlay_Lock:SetVisibility(ESlateVisibility.SelfHitTestInvisible)
|
|||
|
local UnlockType, Cost = PlacementModeConfig.GetPlaceItemUnlockInfo(self.ItemType)
|
|||
|
-- 类型索引是从2开始的
|
|||
|
self.WidgetSwitcher_UnlockType:SetActiveWidgetIndex(UnlockType - 2)
|
|||
|
self.TextBlock_Unlock:SetText(tostring(Cost))
|
|||
|
|
|||
|
else
|
|||
|
self.Overlay_Lock:SetVisibility(ESlateVisibility.Collapsed)
|
|||
|
end
|
|||
|
end
|
|||
|
|
|||
|
function WB_PlaceItem:UpdateCanUnlock()
|
|||
|
if self:ItemIsLock(self.bIsLock) then
|
|||
|
local UnlockType, Cost = PlacementModeConfig.GetPlaceItemUnlockInfo(self.ItemType)
|
|||
|
if UGCGameSystem.GameState:CheckUnlockProperty(UGCSystemLibrary.GetLocalPlayerKey(), UnlockType, Cost) then
|
|||
|
self.WidgetSwitcher_CanUnLock:SetActiveWidgetIndex(1)
|
|||
|
else
|
|||
|
self.WidgetSwitcher_CanUnLock:SetActiveWidgetIndex(0)
|
|||
|
end
|
|||
|
end
|
|||
|
end
|
|||
|
|
|||
|
|
|||
|
|
|||
|
return WB_PlaceItem;
|