---@class WB_KeyMapSetting_C:UUserWidget ---@field Button_Break UButton ---@field Button_Reset UButton ---@field Button_Save UButton ---@field CanvasPanel_Buttons UCanvasPanel ---@field ProgressBar_Size UProgressBar ---@field Slider_Size USlider ---@field TextBlock_Size UTextBlock ---@field WB_KeyMapItemDash UWB_KeyMapItemDash_C ---@field WB_KeyMapItemDiscardsKey UWB_KeyMapItemDiscardsKey_C ---@field WB_KeyMapItemGameDesc UWB_KeyMapItemGameDesc_C ---@field WB_KeyMapItemHook UWB_KeyMapItemHook_C ---@field WB_KeyMapItemHookNum UWB_KeyMapItemHookNum_C ---@field WB_KeyMapItemLaunch UWB_KeyMapItemLaunch_C --Edit Below-- ---@type WB_KeyMapSetting_C local WB_KeyMapSetting = { bInitDoOnce = false; NowSelectBtnIndex = -1; SelectBtnIndex = -1; AllButtons = {}; MinScale = 0.5; MaxScale = 2.5; AllButtonsBeginPosition = {} -- Button 初始位置 {[Index] = FVector2D} Index与AllButtons的共同索引 }; function WB_KeyMapSetting:Construct() -- Bind WidgetLibrary.SliderOnValueChanged(self.Slider_Size, self.Slider_Size_OnValueChanged, self) WidgetLibrary.ButtonOnClickShowPanel(self.Button_Break, WidgetConfig.EUIType.KeyMapSetting, false) WidgetLibrary.BindButtonClicked(self.Button_Reset, self.ResetAllButtons, self) WidgetLibrary.BindButtonClicked(self.Button_Save, self.SaveAllButtons, self) -- Bind Finish -- Bind Event UGCEventSystem.AddListener(EventEnum.ButtonSettingCallBack, self.ButtonSettingCallBack, self) UGCEventSystem.AddListener(EventEnum.GameStateChange, self.BackupInitialPos, self) -- Bind Event Finish -- Init AllButtons self.AllButtons = {} for i = 0, self.CanvasPanel_Buttons:GetChildrenCount() - 1 do local Item = self.CanvasPanel_Buttons:GetChildAt(i) self.AllButtons[Item.TargetWidgetName] = Item UGCLogSystem.Log("[WB_KeyMapSetting_Construct] %s", KismetSystemLibrary.GetObjectName(Item)) end for TargetWidgetName, BtnItem in pairs(self.AllButtons) do BtnItem:AddTouchDelegation( function (ButtonItem, bTouch) if bTouch then self:SetNowSelectBtnIndex(TargetWidgetName) else self:SetNowSelectBtnIndex(-1) end end ) end -- Init AllButtons Finish -- 备份按键初始位置 self.BackupInitialPosHandle = UGCEventSystem.SetTimer(self, self.BackupInitialPos, 20) end function WB_KeyMapSetting:BackupInitialPos(GameStateType) if GameStateType == nil or GameStateType == CustomEnum.EGameState.Playing then if self.BackupInitialPosHandle then UGCEventSystem.StopTimer(self.BackupInitialPosHandle) self.BackupInitialPosHandle = nil self.AllButtonsBeginPosition = self:GetAllButtonsPosition() UGCLogSystem.LogTree("[WB_KeyMapSetting_BackupInitialPos]", self.AllButtonsBeginPosition) UGCSendRPCSystem.ActorRPCNotify(UGCSystemLibrary.GetLocalPlayerKey(), UGCGameSystem.GameState, "Server_GetButtonSetting", UGCSystemLibrary.GetLocalPlayerKey()) end end end function WB_KeyMapSetting:GetAllButtonsPosition() local AllButtonsPosition = {} for TargetWidgetName, ButtonItem in pairs(self.AllButtons) do local BtnSlot = WidgetLayoutLibrary.SlotAsCanvasSlot(ButtonItem) local BtnPos = VectorHelper.ToLuaTable2D(BtnSlot:GetPosition()) AllButtonsPosition[TargetWidgetName] = BtnPos end return AllButtonsPosition end function WB_KeyMapSetting:OnShowPanel() WidgetManager:ShowPanel(WidgetConfig.EUIType.KeyMapSettingBG, false) self.IsShow = true end function WB_KeyMapSetting:OnClosePanel() self:SetNowSelectBtnIndex(-1) self.IsShow = false WidgetManager:ClosePanel(WidgetConfig.EUIType.KeyMapSettingBG) end function WB_KeyMapSetting:SetNowSelectBtnIndex(Index) self.NowSelectBtnIndex = Index if self.AllButtons[self.NowSelectBtnIndex] then self:SetSelectBtnIndex(self.NowSelectBtnIndex) end end function WB_KeyMapSetting:SetSelectBtnIndex(Index) self.SelectBtnIndex = Index self:SelectBtn(self.SelectBtnIndex) local TargetWidget = self.AllButtons[self.SelectBtnIndex] if TargetWidget then local TargetScale = math.clamp(TargetWidget.RenderTransform.Scale.X, self.MinScale, self.MaxScale) local TargetValue = (TargetScale - self.MinScale) / (self.MaxScale - self.MinScale) self:SetSizeShowValue(TargetValue) end end function WB_KeyMapSetting:SetSizeShowValue(TargetValue) self.Slider_Size:SetValue(TargetValue) self.ProgressBar_Size:SetPercent(TargetValue) local TargetScale = KismetMathLibrary.Lerp(self.MinScale, self.MaxScale, TargetValue) self.TextBlock_Size:SetText(tostring(KismetMathLibrary.Round(TargetScale * 100)) .. "%") end function WB_KeyMapSetting:SelectBtn(BtnIndex) for TargetWidgetName, BtnItem in pairs(self.AllButtons) do BtnItem:SetSelect(TargetWidgetName == BtnIndex) end end function WB_KeyMapSetting:Tick(MyGeometry, InDeltaTime) --if self.IsShow then local TargetWidget = self.AllButtons[self.NowSelectBtnIndex] if TargetWidget then local BtnSlot = WidgetLayoutLibrary.SlotAsCanvasSlot(TargetWidget) local SlotAnchors = BtnSlot:GetAnchors() local Minimum = SlotAnchors.Minimum local LocalSize = SlateBlueprintLibrary.GetLocalSize(self:GetCachedGeometry()) local LocationX = 0. local LocationY = 0. local IsSucceed = false LocationX, LocationY, IsSucceed = UGCSystemLibrary.GetLocalPlayerController():GetInputTouchState(ETouchIndex.Touch1, LocationX, LocationY) local TouchPos = {X = LocationX, Y = LocationY} local ViewportSize = WidgetLayoutLibrary.GetViewportSize(self) local LocalTouchPos = KismetMathLibrary.Multiply_Vector2DVector2D(TouchPos, KismetMathLibrary.Divide_Vector2DVector2D(LocalSize, ViewportSize)) local Offset = KismetMathLibrary.Multiply_Vector2DVector2D(Minimum, LocalSize) -- local NewPos = KismetMathLibrary.Subtract_Vector2DVector2D(MousePos, Offset) local NewPos = KismetMathLibrary.Subtract_Vector2DVector2D(LocalTouchPos, Offset) BtnSlot:SetPosition(NewPos) end --end end function WB_KeyMapSetting:Slider_Size_OnValueChanged(Value) self.ProgressBar_Size:SetPercent(Value) local TargetWidget = self.AllButtons[self.SelectBtnIndex] if TargetWidget then local TargetScale = KismetMathLibrary.Lerp(self.MinScale, self.MaxScale, Value) TargetWidget:SetRenderScale({X = TargetScale, Y = TargetScale}) self.TextBlock_Size:SetText(tostring(KismetMathLibrary.Round(TargetScale * 100)) .. "%") end end function WB_KeyMapSetting:ResetAllButtons() self:SetNowSelectBtnIndex(-1) for Index, ButtonItem in pairs(self.AllButtons) do local TargetPos = self.AllButtonsBeginPosition[Index] local BtnSlot = WidgetLayoutLibrary.SlotAsCanvasSlot(ButtonItem) BtnSlot:SetPosition(TargetPos) ButtonItem:SetRenderScale({X = 1., Y = 1.}) end self:SetSizeShowValue((1. - self.MinScale)/ (self.MaxScale - self.MinScale)) end function WB_KeyMapSetting:SaveAllButtons() local SaveParam = {} for TargetWidgetName, ButtonItem in pairs(self.AllButtons) do if ButtonItem.TargetWidgetName then local BtnSlot = WidgetLayoutLibrary.SlotAsCanvasSlot(ButtonItem) local Pos = {X = BtnSlot:GetPosition().X, Y = BtnSlot:GetPosition().Y} local Scale = ButtonItem.RenderTransform.Scale.X SaveParam[TargetWidgetName] = {TargetWidgetName = ButtonItem.TargetWidgetName, Pos = Pos, Scale = Scale} else UGCLogSystem.LogError("[W_ButtonSetting_SaveAllButtons] %s TargetWidgetName is nil ", KismetSystemLibrary.GetObjectName(ButtonItem)) end end UGCSendRPCSystem.ActorRPCNotify(UGCSystemLibrary.GetLocalPlayerKey(), UGCGameSystem.GameState, "Server_SaveButtonSetting", UGCSystemLibrary.GetLocalPlayerKey(), SaveParam) end ---@param ButtonsRender {{TargetWidgetName = string, Pos = FVector2D, Scale = float}, ...} function WB_KeyMapSetting:ButtonSettingCallBack(ButtonsRender) local WidgetEnumToParam = {} local FightPanel = WidgetManager:GetPanel(WidgetConfig.EUIType.FightPanel) if FightPanel then for _, TempButtonRender in pairs(ButtonsRender) do local TargetWidget = FightPanel[TempButtonRender.TargetWidgetName] if UE.IsValid(TargetWidget) then local BtnSlot = WidgetLayoutLibrary.SlotAsCanvasSlot(TargetWidget) BtnSlot:SetPosition(TempButtonRender.Pos) TargetWidget:SetRenderScale({X = TempButtonRender.Scale, Y = TempButtonRender.Scale}) else UGCLogSystem.LogError("[WB_KeyMapSetting_ButtonSettingCallBack] %s TargetWidget is nil", TempButtonRender.TargetWidgetName) end local KeyMapItem = self.AllButtons[TempButtonRender.TargetWidgetName] if KeyMapItem then local BtnSlot = WidgetLayoutLibrary.SlotAsCanvasSlot(KeyMapItem) BtnSlot:SetPosition(TempButtonRender.Pos) KeyMapItem:SetRenderScale({X = TempButtonRender.Scale, Y = TempButtonRender.Scale}) end -- WidgetEnumToParam[TempButtonRender.TargetWidgetName] = {Pos = TempButtonRender.Pos, Scale = TempButtonRender.Scale } end --for Index, ButtonItem in pairs(self.AllButtons) do -- local RenderParam = WidgetEnumToParam[ButtonItem.TargetWidgetName] -- if ButtonItem.TargetWidgetName and RenderParam then -- local BtnSlot = WidgetLayoutLibrary.SlotAsCanvasSlot(ButtonItem) -- BtnSlot:SetPosition(RenderParam.Pos) -- ButtonItem:SetRenderScale({X = RenderParam.Scale, Y = RenderParam.Scale}) -- end --end end end -- function WB_KeyMapSetting:Destruct() -- end return WB_KeyMapSetting;