From cd72f4f19b8438915f5f99502edd265d44fb36ee Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Tue, 11 Mar 2025 00:04:57 +0100 Subject: [PATCH] Add `Edit GUI` option to Game Window #3269 --- Source/Editor/Windows/GameWindow.cs | 34 ++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/Source/Editor/Windows/GameWindow.cs b/Source/Editor/Windows/GameWindow.cs index ebc64cbd8..540beb2bf 100644 --- a/Source/Editor/Windows/GameWindow.cs +++ b/Source/Editor/Windows/GameWindow.cs @@ -21,7 +21,7 @@ namespace FlaxEditor.Windows { private readonly RenderOutputControl _viewport; private readonly GameRoot _guiRoot; - private bool _showGUI = true; + private bool _showGUI = true, _editGUI = true; private bool _showDebugDraw = false; private bool _audioMuted = false; private float _audioVolume = 1; @@ -84,6 +84,22 @@ namespace FlaxEditor.Windows } } + /// + /// Gets or sets a value indicating whether allow editing game GUI in the view or keep it visible-only. + /// + public bool EditGUI + { + get => _editGUI; + set + { + if (value != _editGUI) + { + _editGUI = value; + _guiRoot.Editable = value; + } + } + } + /// /// Gets or sets a value indicating whether show Debug Draw shapes in the view or keep it hidden. /// @@ -275,8 +291,9 @@ namespace FlaxEditor.Windows /// private class GameRoot : UIEditorRoot { - public override bool EnableInputs => !Time.GamePaused && Editor.IsPlayMode; - public override bool EnableSelecting => !Editor.IsPlayMode || Time.GamePaused; + internal bool Editable = true; + public override bool EnableInputs => !Time.GamePaused && Editor.IsPlayMode && Editable; + public override bool EnableSelecting => (!Editor.IsPlayMode || Time.GamePaused) && Editable; public override TransformGizmo TransformGizmo => Editor.Instance.MainTransformGizmo; } @@ -668,6 +685,13 @@ namespace FlaxEditor.Windows checkbox.StateChanged += x => ShowGUI = x.Checked; } + // Edit GUI + { + var button = menu.AddButton("Edit GUI"); + var checkbox = new CheckBox(140, 2, EditGUI) { Parent = button }; + checkbox.StateChanged += x => EditGUI = x.Checked; + } + // Show Debug Draw { var button = menu.AddButton("Show Debug Draw"); @@ -1191,6 +1215,7 @@ namespace FlaxEditor.Windows public override void OnLayoutSerialize(XmlWriter writer) { writer.WriteAttributeString("ShowGUI", ShowGUI.ToString()); + writer.WriteAttributeString("EditGUI", EditGUI.ToString()); writer.WriteAttributeString("ShowDebugDraw", ShowDebugDraw.ToString()); writer.WriteAttributeString("DefaultViewportScaling", JsonSerializer.Serialize(_defaultViewportScaling)); writer.WriteAttributeString("CustomViewportScaling", JsonSerializer.Serialize(_customViewportScaling)); @@ -1201,6 +1226,8 @@ namespace FlaxEditor.Windows { if (bool.TryParse(node.GetAttribute("ShowGUI"), out bool value1)) ShowGUI = value1; + if (bool.TryParse(node.GetAttribute("EditGUI"), out value1)) + EditGUI = value1; if (bool.TryParse(node.GetAttribute("ShowDebugDraw"), out value1)) ShowDebugDraw = value1; if (node.HasAttribute("CustomViewportScaling")) @@ -1226,6 +1253,7 @@ namespace FlaxEditor.Windows public override void OnLayoutDeserialize() { ShowGUI = true; + EditGUI = true; ShowDebugDraw = false; } }