From 8470e81dc7340f76ade0fc278e6a6c31eb900e84 Mon Sep 17 00:00:00 2001 From: MapleWheels Date: Fri, 6 Mar 2026 04:57:00 -0500 Subject: [PATCH] Added tooltips and SettingControl input listener to the settings menu. Minor cosmetic adjustments. --- .../ClientSource/LuaCs/Data/SettingControl.cs | 101 ++++++++++++++++++ .../_SettingsMenu/ModsGameplaySettingsMenu.cs | 5 +- .../Config/SettingsShared.xml | 2 +- .../LuaCsForBarotrauma/Texts/English.xml | 4 +- 4 files changed, 107 insertions(+), 5 deletions(-) diff --git a/Barotrauma/BarotraumaClient/ClientSource/LuaCs/Data/SettingControl.cs b/Barotrauma/BarotraumaClient/ClientSource/LuaCs/Data/SettingControl.cs index bceb15068..65ed65ecd 100644 --- a/Barotrauma/BarotraumaClient/ClientSource/LuaCs/Data/SettingControl.cs +++ b/Barotrauma/BarotraumaClient/ClientSource/LuaCs/Data/SettingControl.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Xml.Linq; using Barotrauma.LuaCs.Data; using Microsoft.Toolkit.Diagnostics; +using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Input; using OneOf; @@ -148,4 +149,104 @@ public sealed class SettingControl : SettingBase, ISettingControl } return false; } + +#if CLIENT + private static GUICustomComponent InputListener; + + public override void AddDisplayComponent(GUILayoutGroup layoutGroup, Vector2 relativeSize, Action onSerializedValue) + { + var inputButton = new GUIButton(new RectTransform(relativeSize, layoutGroup.RectTransform), Alignment.Center, + style: "GUITextBoxNoIcon") + { + Text = this.Value.ToString(), + OnClicked = (btn, obj) => + { + if (InputListener is not null) + { + // Another button is active + return true; + } + CoroutineManager.Invoke(() => + { + CreateListener(btn); + }, 0f); // delay one frame for button inputs + return true; + } + }; + inputButton.OutlineColor = Color.PeachPuff; + inputButton.TextColor = Color.White; + + + void ClearListener() + { + InputListener?.Parent.RemoveChild(InputListener); + InputListener = null; + } + + void CreateListener(GUIButton button) + { + ClearListener(); + InputListener = new GUICustomComponent(new RectTransform(Vector2.Zero, layoutGroup.RectTransform), + onUpdate: (deltaTime, component) => + { + var pressedKeys = PlayerInput.GetKeyboardState.GetPressedKeys(); + if (pressedKeys?.Any() ?? false) + { + if (pressedKeys.Contains(Keys.Escape)) + { + ClearListener(); + return; + } + + ApplyValue(pressedKeys.First(), button); + return; + } + + if (PlayerInput.PrimaryMouseButtonClicked() && + (GUI.MouseOn == null || !(GUI.MouseOn is GUIButton) || GUI.MouseOn.IsChildOf(layoutGroup))) + { + ApplyValue(MouseButton.PrimaryMouse, button); + return; + } + else if (PlayerInput.SecondaryMouseButtonClicked()) + { + ApplyValue(MouseButton.SecondaryMouse, button); + return; + } + else if (PlayerInput.MidButtonClicked()) + { + ApplyValue(MouseButton.MiddleMouse, button); + return; + } + else if (PlayerInput.Mouse4ButtonClicked()) + { + ApplyValue(MouseButton.MouseButton4, button); + return; + } + else if (PlayerInput.Mouse5ButtonClicked()) + { + ApplyValue(MouseButton.MouseButton5, button); + return; + } + else if (PlayerInput.MouseWheelUpClicked()) + { + ApplyValue(MouseButton.MouseWheelUp, button); + return; + } + else if (PlayerInput.MouseWheelDownClicked()) + { + ApplyValue(MouseButton.MouseWheelDown, button); + return; + } + }); + } + + void ApplyValue(KeyOrMouse input, GUIButton button) + { + button.Text = input.ToString(); + onSerializedValue?.Invoke(input.ToString()); + ClearListener(); + } + } +#endif } diff --git a/Barotrauma/BarotraumaClient/ClientSource/LuaCs/Services/_SettingsMenu/ModsGameplaySettingsMenu.cs b/Barotrauma/BarotraumaClient/ClientSource/LuaCs/Services/_SettingsMenu/ModsGameplaySettingsMenu.cs index b885d1873..118e51f31 100644 --- a/Barotrauma/BarotraumaClient/ClientSource/LuaCs/Services/_SettingsMenu/ModsGameplaySettingsMenu.cs +++ b/Barotrauma/BarotraumaClient/ClientSource/LuaCs/Services/_SettingsMenu/ModsGameplaySettingsMenu.cs @@ -258,7 +258,8 @@ internal sealed class ModsGameplaySettingsMenu : ModsSettingsMenuBase GUIFrame entryFrame = new GUIFrame(new RectTransform(new Vector2(1f, settingHeight), parent)); GUILayoutGroup entryLayoutGroup = new GUILayoutGroup(new RectTransform(Vector2.One, entryFrame.RectTransform), isHorizontal: true); - new GUIFrame(new RectTransform(new Vector2(0.05f, 1f), entryLayoutGroup.RectTransform), + // padding + new GUIFrame(new RectTransform(new Vector2(0.02f, 1f), entryLayoutGroup.RectTransform), color: Color.TransparentBlack); new GUITextBlock(new RectTransform(labelSize - new Vector2(0.05f, 0f), entryLayoutGroup.RectTransform), @@ -267,7 +268,7 @@ internal sealed class ModsGameplaySettingsMenu : ModsSettingsMenuBase font: GUIStyle.SmallFont, textAlignment: Alignment.Left) { - CanBeFocused = false + ToolTip = GetLocalizedString(setting.GetDisplayInfo().Tooltip, string.Empty) }; setting.AddDisplayComponent(entryLayoutGroup, controlSize, newValue => diff --git a/Barotrauma/BarotraumaShared/LocalMods/LuaCsForBarotrauma/Config/SettingsShared.xml b/Barotrauma/BarotraumaShared/LocalMods/LuaCsForBarotrauma/Config/SettingsShared.xml index d6a5afe2a..4fcdaf06f 100644 --- a/Barotrauma/BarotraumaShared/LocalMods/LuaCsForBarotrauma/Config/SettingsShared.xml +++ b/Barotrauma/BarotraumaShared/LocalMods/LuaCsForBarotrauma/Config/SettingsShared.xml @@ -3,7 +3,7 @@ - + diff --git a/Barotrauma/BarotraumaShared/LocalMods/LuaCsForBarotrauma/Texts/English.xml b/Barotrauma/BarotraumaShared/LocalMods/LuaCsForBarotrauma/Texts/English.xml index 222a150af..84d297395 100644 --- a/Barotrauma/BarotraumaShared/LocalMods/LuaCsForBarotrauma/Texts/English.xml +++ b/Barotrauma/BarotraumaShared/LocalMods/LuaCsForBarotrauma/Texts/English.xml @@ -6,11 +6,11 @@ Suppress GUI Popup on Error General Are C# Mods Allowed + Should unsandboxed scripts and dlls be allowed to run. General Hide Local OS Account Name In Logs General - Where to Save Local Data - General Limit Network Message Size + Limits the maximum network message size to avoid buffer size issues. Networking