308 lines
13 KiB
Lua
308 lines
13 KiB
Lua
|
---@class WB_PlacePanel_C:UAEUserWidget
|
|||
|
---@field RetractItemInfo UWidgetAnimation
|
|||
|
---@field Button_AddYaw UButton
|
|||
|
---@field Button_ChangeMode UButton
|
|||
|
---@field Button_Debug UButton
|
|||
|
---@field Button_Fly UButton
|
|||
|
---@field Button_GetPlaceCode UNewButton
|
|||
|
---@field Button_ImportCode UNewButton
|
|||
|
---@field Button_ItemIncrement UButton
|
|||
|
---@field Button_PlaceOrClear UButton
|
|||
|
---@field Button_Retract UButton
|
|||
|
---@field Button_RunTest UNewButton
|
|||
|
---@field Button_SubYaw UButton
|
|||
|
---@field Button_ToMenu UNewButton
|
|||
|
---@field CustomizeCanvasPanel_BP_Desc UCustomizeCanvasPanel_BP_C
|
|||
|
---@field CustomizeCanvasPanel_ChangeMode UCustomizeCanvasPanel_BP_C
|
|||
|
---@field CustomizeCanvasPanel_PlaceBtn UCustomizeCanvasPanel_BP_C
|
|||
|
---@field CustomizeCanvasPanel_PlaceValue UCustomizeCanvasPanel_BP_C
|
|||
|
---@field CustomizeCanvasPanel_SelectPlaceItem UCustomizeCanvasPanel_BP_C
|
|||
|
---@field CustomizeCanvasPanel_SetYaw UCustomizeCanvasPanel_BP_C
|
|||
|
---@field ScrollBox_Items UScrollBox
|
|||
|
---@field Slider_Yaw USlider
|
|||
|
---@field TextBlock_Increment UTextBlock
|
|||
|
---@field TextBlock_ItemCountRange UTextBlock
|
|||
|
---@field TextBlock_ItemDesc UTextBlock
|
|||
|
---@field TextBlock_ItemName UTextBlock
|
|||
|
---@field TextBlock_PlaceValue UTextBlock
|
|||
|
---@field TextBlock_Yaw UTextBlock
|
|||
|
---@field WidgetSwitcher_ChangeMode UWidgetSwitcher
|
|||
|
---@field WidgetSwitcher_Increment UWidgetSwitcher
|
|||
|
---@field WidgetSwitcher_IsPlace UWidgetSwitcher
|
|||
|
---@field WidgetSwitcher_Retract UWidgetSwitcher
|
|||
|
---@field WidgetSwitcher_UnlockType UWidgetSwitcher
|
|||
|
--Edit Below--
|
|||
|
local WB_PlacePanel = {
|
|||
|
bItemInfoPanelIsRetract = false;
|
|||
|
bCanIncrement = false;
|
|||
|
};
|
|||
|
|
|||
|
function WB_PlacePanel:Construct()
|
|||
|
self:InitPlaceItem()
|
|||
|
|
|||
|
WidgetLibrary.BindButtonPressed(self.Button_PlaceOrClear, self.PlaceItem, self)
|
|||
|
WidgetLibrary.BindButtonPressed(self.Button_AddYaw, self.AddYaw, self)
|
|||
|
WidgetLibrary.BindButtonPressed(self.Button_SubYaw, self.SubYaw, self)
|
|||
|
WidgetLibrary.BindButtonPressed(self.Button_Retract, self.RetractItemInfoPanel, self)
|
|||
|
WidgetLibrary.SliderOnValueChanged(self.Slider_Yaw, self.YawChange, self)
|
|||
|
WidgetLibrary.BindButtonPressed(self.Button_ChangeMode, self.ChangePlaceMode, self)
|
|||
|
WidgetLibrary.BindButtonClicked(self.Button_RunTest, self.EnableRunTest, self)
|
|||
|
WidgetLibrary.BindButtonClicked(self.Button_ToMenu, self.ClickToMenu, self)
|
|||
|
WidgetLibrary.BindButtonClicked(self.Button_ItemIncrement, self.ClickItemIncrement, self)
|
|||
|
WidgetLibrary.ButtonOnClickShowPanel(self.Button_GetPlaceCode, WidgetConfig.EUIType.ShowPlaceCode)
|
|||
|
WidgetLibrary.ButtonOnClickShowPanel(self.Button_ImportCode, WidgetConfig.EUIType.ImportPlaceCode)
|
|||
|
|
|||
|
|
|||
|
UGCEventSystem.AddListener(EventEnum.PlaceModeChange, self.UpdatePlaceMode, self)
|
|||
|
UGCEventSystem.AddListener(EventEnum.UpdatePlaceValue, self.UpdatePlaceValue, self)
|
|||
|
UGCEventSystem.AddListener(EventEnum.PlaceItemTypeIsChange, self.PlaceItemTypeIsChange, self)
|
|||
|
UGCEventSystem.AddListener(ArchiveDataConfig.GetParamNotifyEvent(ArchiveDataConfig.EArchiveType.ItemIncrement), self.UpdatePlaceItemInfo, self)
|
|||
|
UGCEventSystem.AddListener(ArchiveDataConfig.GetParamNotifyEvent(ArchiveDataConfig.EArchiveType.Exp), self.UpdatePlaceValue, self)
|
|||
|
|
|||
|
|
|||
|
if GlobalConfigs.IsDebug then
|
|||
|
self.Button_Debug:SetVisibility(ESlateVisibility.Visible)
|
|||
|
WidgetLibrary.ButtonOnClickShowPanel(self.Button_Debug, WidgetConfig.EUIType.Debug)
|
|||
|
end
|
|||
|
|
|||
|
end
|
|||
|
|
|||
|
function WB_PlacePanel:OnShowPanel()
|
|||
|
WidgetConfig.SetDefaultUIMode(WidgetConfig.EDefaultUIMode.PlaceMode)
|
|||
|
|
|||
|
PlacementModeConfig.GetPlaceManager():SetPlaceMode(PlacementModeConfig.EPlaceMode.PlaceMode)
|
|||
|
self:UpdatePlaceValue()
|
|||
|
for i = 1, self.ScrollBox_Items:GetChildrenCount() do
|
|||
|
local Item = self.ScrollBox_Items:GetChildAt(i - 1)
|
|||
|
Item:UpdatePlacedItemCount()
|
|||
|
end
|
|||
|
|
|||
|
end
|
|||
|
|
|||
|
function WB_PlacePanel:OnClosePanel()
|
|||
|
WidgetConfig.RemoveDefaultUIMode(WidgetConfig.EDefaultUIMode.PlaceMode)
|
|||
|
PlacementModeConfig.GetPlaceManager():SetPlaceMode(PlacementModeConfig.EPlaceMode.None)
|
|||
|
end
|
|||
|
|
|||
|
function WB_PlacePanel:PlaceItem()
|
|||
|
SoundSystem.PlaySound(SoundSystem.ESound.Click)
|
|||
|
if self.PlaceMode == PlacementModeConfig.EPlaceMode.PlaceMode then
|
|||
|
PlacementModeConfig.GetPlaceManager():ClientPlace()
|
|||
|
elseif self.PlaceMode == PlacementModeConfig.EPlaceMode.RemoveMode then
|
|||
|
PlacementModeConfig.GetPlaceManager():ClientRemoveItem()
|
|||
|
end
|
|||
|
end
|
|||
|
|
|||
|
|
|||
|
WB_PlacePanel.LastYawValue = 0
|
|||
|
---@param Value float
|
|||
|
function WB_PlacePanel:YawChange(Value)
|
|||
|
local YawValue = (Value - 0.5) * 360
|
|||
|
-- if YawValue < 0 then YawValue = YawValue + 360 end
|
|||
|
YawValue = KismetMathLibrary.Round(YawValue / PlacementModeConfig.PlacingAttr.RotationSpacing) * PlacementModeConfig.PlacingAttr.RotationSpacing
|
|||
|
self:UpdateYawValue(YawValue)
|
|||
|
end
|
|||
|
|
|||
|
function WB_PlacePanel:AddYaw()
|
|||
|
SoundSystem.PlaySound(SoundSystem.ESound.Click)
|
|||
|
self:UpdateYawValue(self.LastYawValue + PlacementModeConfig.PlacingAttr.RotationSpacing, true)
|
|||
|
end
|
|||
|
|
|||
|
function WB_PlacePanel:SubYaw()
|
|||
|
SoundSystem.PlaySound(SoundSystem.ESound.Click)
|
|||
|
self:UpdateYawValue(self.LastYawValue - PlacementModeConfig.PlacingAttr.RotationSpacing, true)
|
|||
|
end
|
|||
|
|
|||
|
function WB_PlacePanel:UpdateYawValue(YawValue, UpdateSlider)
|
|||
|
YawValue = math.clamp(YawValue, -180, 180)
|
|||
|
self.LastYawValue = YawValue
|
|||
|
PlacementModeConfig.GetPlaceManager():SetAddPreviewQuat(self.LastYawValue % 360)
|
|||
|
self.TextBlock_Yaw:SetText(tostring(YawValue) .. "°")
|
|||
|
if UpdateSlider then
|
|||
|
self.Slider_Yaw:SetValue(math.clamp(YawValue / 360 + 0.5), 0, 1)
|
|||
|
end
|
|||
|
end
|
|||
|
|
|||
|
function WB_PlacePanel:InitPlaceItem()
|
|||
|
local PlaceItemWidgetPath = UGCGameSystem.GetUGCResourcesFullPath('Asset/UI/StatusUI/PlacePanel/WB_PlaceItem.WB_PlaceItem_C');
|
|||
|
local PlaceItemWidgetClass = UE.LoadClass(PlaceItemWidgetPath)
|
|||
|
local LocalPC = UGCSystemLibrary.GetLocalPlayerController()
|
|||
|
|
|||
|
local PlaceManager = PlacementModeConfig.GetPlaceManager()
|
|||
|
local ItemTypes = table.getKeys(PlacementModeConfig.ItemInfo)
|
|||
|
table.sort(ItemTypes, function(a, b) return a < b end)
|
|||
|
for i, v in pairs(ItemTypes) do
|
|||
|
local Item = UserWidget.NewWidgetObjectBP(LocalPC, PlaceItemWidgetClass);
|
|||
|
self.ScrollBox_Items:AddChild(Item)
|
|||
|
Item:SetItemType(v)
|
|||
|
if UE.IsValid(PlaceManager) then
|
|||
|
Item:UpdateSelectItem(PlaceManager:GetPlaceItemType())
|
|||
|
end
|
|||
|
end
|
|||
|
|
|||
|
end
|
|||
|
|
|||
|
function WB_PlacePanel:UpdatePlaceMode(InPlaceMode)
|
|||
|
if InPlaceMode ~= self.PlaceMode then
|
|||
|
self.PlaceMode = InPlaceMode
|
|||
|
if self.PlaceMode == PlacementModeConfig.EPlaceMode.PlaceMode then
|
|||
|
self.WidgetSwitcher_IsPlace:SetActiveWidgetIndex(0)
|
|||
|
self.WidgetSwitcher_ChangeMode:SetActiveWidgetIndex(0)
|
|||
|
self.CustomizeCanvasPanel_SetYaw:SetVisibility(ESlateVisibility.SelfHitTestInvisible);
|
|||
|
-- self.CustomizeCanvasPanel_SelectPlaceItem:SetVisibility(ESlateVisibility.SelfHitTestInvisible);
|
|||
|
elseif self.PlaceMode == PlacementModeConfig.EPlaceMode.RemoveMode then
|
|||
|
self.WidgetSwitcher_IsPlace:SetActiveWidgetIndex(1)
|
|||
|
self.WidgetSwitcher_ChangeMode:SetActiveWidgetIndex(1)
|
|||
|
self.CustomizeCanvasPanel_SetYaw:SetVisibility(ESlateVisibility.Collapsed);
|
|||
|
-- self.CustomizeCanvasPanel_SelectPlaceItem:SetVisibility(ESlateVisibility.Collapsed);
|
|||
|
end
|
|||
|
end
|
|||
|
end
|
|||
|
|
|||
|
function WB_PlacePanel:ChangePlaceMode()
|
|||
|
SoundSystem.PlaySound(SoundSystem.ESound.Click)
|
|||
|
if self.PlaceMode == PlacementModeConfig.EPlaceMode.PlaceMode then
|
|||
|
PlacementModeConfig.GetPlaceManager():SetPlaceMode(PlacementModeConfig.EPlaceMode.RemoveMode)
|
|||
|
elseif self.PlaceMode == PlacementModeConfig.EPlaceMode.RemoveMode then
|
|||
|
PlacementModeConfig.GetPlaceManager():SetPlaceMode(PlacementModeConfig.EPlaceMode.PlaceMode)
|
|||
|
end
|
|||
|
end
|
|||
|
|
|||
|
function WB_PlacePanel:UpdatePlaceValue()
|
|||
|
local PlaceValue = PlacementModeConfig.GetPlaceManager():GetPlaceValue()
|
|||
|
local PlaceMaxValue = PlacementModeConfig.GetPlaceMaxValue(UGCSystemLibrary.GetLocalPlayerKey())
|
|||
|
self.TextBlock_PlaceValue:SetText(tostring(PlaceValue) .. "/" .. tostring(PlaceMaxValue))
|
|||
|
-- self.TextBlock_PlaceValue:SetColorAndOpacity({SpecifiedColor = {R = PlaceValue / PlaceMaxValue, G = 1 - PlaceValue / PlaceMaxValue, B = 0, A = 1}, ColorUseRule = 0})
|
|||
|
end
|
|||
|
|
|||
|
function WB_PlacePanel:EnableRunTest()
|
|||
|
SoundSystem.PlaySound(SoundSystem.ESound.Click)
|
|||
|
UGCLogSystem.Log("[WB_PlacePanel_EnableRunTest]")
|
|||
|
UGCSendRPCSystem.RPCEvent(nil, EventEnum.RunMapTest)
|
|||
|
end
|
|||
|
|
|||
|
function WB_PlacePanel:ReturnToMenu()
|
|||
|
SoundSystem.PlaySound(SoundSystem.ESound.Click)
|
|||
|
UGCLogSystem.Log("[WB_PlacePanel_ReturnToMenu]")
|
|||
|
UGCSendRPCSystem.ActorRPCNotify(nil, UGCGameSystem.GameState, "ShowSimplePlaceModeUI", WidgetConfig.EUIType.PlaceModeMainMenu)
|
|||
|
end
|
|||
|
|
|||
|
function WB_PlacePanel:ClickToMenu()
|
|||
|
local SecondaryConfirmationWidget = WidgetManager:GetPanel(WidgetConfig.EUIType.SecondaryConfirmation)
|
|||
|
SecondaryConfirmationWidget:SetTextInfo("该地图还未保存,是否进行跑图测试后保存?", "不保存", "跑图测试")
|
|||
|
SecondaryConfirmationWidget:BindCancellationCallBack(self.ReturnToMenu, self)
|
|||
|
SecondaryConfirmationWidget:BindConfirmCallBack(self.EnableRunTest, self)
|
|||
|
WidgetManager:ShowPanel(WidgetConfig.EUIType.SecondaryConfirmation, false)
|
|||
|
end
|
|||
|
|
|||
|
function WB_PlacePanel:PlaceItemTypeIsChange(InPlaceItemType)
|
|||
|
local ItemInfo = PlacementModeConfig.ItemInfo[InPlaceItemType]
|
|||
|
self.PlaceItemType = InPlaceItemType
|
|||
|
if ItemInfo then
|
|||
|
self:UpdatePlaceItemInfo()
|
|||
|
self.TextBlock_ItemName:SetText(ItemInfo.Name)
|
|||
|
self.TextBlock_ItemDesc:SetText(ItemInfo.Desc)
|
|||
|
end
|
|||
|
end
|
|||
|
|
|||
|
--- 刷新增量信息
|
|||
|
function WB_PlacePanel:UpdateItemIncrementInfo()
|
|||
|
local ItemInfo = PlacementModeConfig.ItemInfo[self.PlaceItemType]
|
|||
|
if ItemInfo then
|
|||
|
local ItemIncrement = ArchiveDataConfig.GetPlayerArchiveDataFromType(UGCSystemLibrary.GetLocalPlayerKey(), ArchiveDataConfig.EArchiveType.ItemIncrement)
|
|||
|
local Count = ItemInfo.InitialCount
|
|||
|
if ItemIncrement and ItemIncrement[self.PlaceItemType] then
|
|||
|
Count = ItemIncrement[self.PlaceItemType] + ItemInfo.InitialCount
|
|||
|
end
|
|||
|
self.bCanIncrement = false
|
|||
|
if Count == 0 then
|
|||
|
self.WidgetSwitcher_Increment:SetActiveWidgetIndex(1)
|
|||
|
elseif Count >= ItemInfo.MaxCount then
|
|||
|
self.WidgetSwitcher_Increment:SetActiveWidgetIndex(2)
|
|||
|
else
|
|||
|
self.bCanIncrement = true
|
|||
|
self.WidgetSwitcher_Increment:SetActiveWidgetIndex(0)
|
|||
|
end
|
|||
|
local UnlockType, Cost = PlacementModeConfig.GetPlaceItemIncrementInfo(self.PlaceItemType)
|
|||
|
-- 类型索引是从2开始的
|
|||
|
self.WidgetSwitcher_UnlockType:SetActiveWidgetIndex(UnlockType - 2)
|
|||
|
self.TextBlock_Increment:SetText(tostring(Cost))
|
|||
|
end
|
|||
|
end
|
|||
|
|
|||
|
|
|||
|
--- 更新放置上限
|
|||
|
function WB_PlacePanel:UpdateItemCountRange()
|
|||
|
local ItemInfo = PlacementModeConfig.ItemInfo[self.PlaceItemType]
|
|||
|
local CanPlaceNum = PlacementModeConfig.GetPlayerPlaceItemCount(UGCSystemLibrary.GetLocalPlayerKey(), self.PlaceItemType)
|
|||
|
local MaxCount = ItemInfo.MaxCount
|
|||
|
self.TextBlock_ItemCountRange:SetText(string.format("上限:%d/%d", CanPlaceNum, MaxCount))
|
|||
|
end
|
|||
|
|
|||
|
--- 更新放置物信息栏
|
|||
|
function WB_PlacePanel:UpdatePlaceItemInfo()
|
|||
|
self:UpdateItemCountRange()
|
|||
|
self:UpdateItemIncrementInfo()
|
|||
|
end
|
|||
|
|
|||
|
--- 增量
|
|||
|
function WB_PlacePanel:ClickItemIncrement()
|
|||
|
if self.PlaceItemType and self.bCanIncrement then
|
|||
|
SoundSystem.PlaySound(SoundSystem.ESound.Click)
|
|||
|
local UnlockType, Cost = PlacementModeConfig.GetPlaceItemIncrementInfo(self.PlaceItemType)
|
|||
|
-- 二次确定消耗解锁
|
|||
|
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.ConfirmIncrement, self)
|
|||
|
WidgetManager:ShowPanel(WidgetConfig.EUIType.SecondaryConfirmation, false)
|
|||
|
end
|
|||
|
end
|
|||
|
|
|||
|
function WB_PlacePanel:ConfirmIncrement()
|
|||
|
if self.PlaceItemType then
|
|||
|
UGCSendRPCSystem.ActorRPCNotify(nil, UGCGameSystem.GameState, "AddItemIncrement", UGCSystemLibrary.GetLocalPlayerKey(), self.PlaceItemType)
|
|||
|
end
|
|||
|
end
|
|||
|
|
|||
|
--- 收起或展开Item信息面板
|
|||
|
function WB_PlacePanel:RetractItemInfoPanel()
|
|||
|
SoundSystem.PlaySound(SoundSystem.ESound.Click)
|
|||
|
if self.bItemInfoPanelIsRetract then
|
|||
|
self:PlayAnimation(self.RetractItemInfo, 0, 1, EUMGSequencePlayMode.Reverse, 1)
|
|||
|
else
|
|||
|
self:PlayAnimation(self.RetractItemInfo, 0, 1, EUMGSequencePlayMode.Forward, 1)
|
|||
|
end
|
|||
|
self.bItemInfoPanelIsRetract = not self.bItemInfoPanelIsRetract
|
|||
|
end
|
|||
|
|
|||
|
--[[
|
|||
|
function WB_PlacePanel:ReceiveTick(DeltaTime)
|
|||
|
self.SuperClass.ReceiveTick(self, DeltaTime);
|
|||
|
end
|
|||
|
--]]
|
|||
|
|
|||
|
--[[
|
|||
|
function WB_PlacePanel:ReceiveEndPlay()
|
|||
|
self.SuperClass.ReceiveEndPlay(self);
|
|||
|
end
|
|||
|
--]]
|
|||
|
|
|||
|
--[[
|
|||
|
function WB_PlacePanel:GetReplicatedProperties()
|
|||
|
return
|
|||
|
end
|
|||
|
--]]
|
|||
|
|
|||
|
--[[
|
|||
|
function WB_PlacePanel:GetAvailableServerRPCs()
|
|||
|
return
|
|||
|
end
|
|||
|
--]]
|
|||
|
|
|||
|
return WB_PlacePanel;
|