From 940b0e02e5d8410b3e6db7f39dfc40ce2faecdc7 Mon Sep 17 00:00:00 2001 From: envision3d Date: Wed, 28 Jun 2023 04:08:36 -0500 Subject: [PATCH] improve state syncing of context menus and editor options --- .../ContextMenuSingleSelectGroup.cs | 3 +-- Source/Editor/Modules/UIModule.cs | 19 +++++++++++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/Source/Editor/GUI/ContextMenu/ContextMenuSingleSelectGroup.cs b/Source/Editor/GUI/ContextMenu/ContextMenuSingleSelectGroup.cs index 794729547..9b58c09a8 100644 --- a/Source/Editor/GUI/ContextMenu/ContextMenuSingleSelectGroup.cs +++ b/Source/Editor/GUI/ContextMenu/ContextMenuSingleSelectGroup.cs @@ -92,6 +92,7 @@ namespace FlaxEditor.GUI.ContextMenu private void SetItemAsActive(SingleSelectGroupItem item) { DeselectAll(); + activeItem = item; var index = _items.IndexOf(item); OnSelectionChanged?.Invoke(item.value); @@ -101,8 +102,6 @@ namespace FlaxEditor.GUI.ContextMenu { btn.Checked = true; } - - activeItem = item; } } } diff --git a/Source/Editor/Modules/UIModule.cs b/Source/Editor/Modules/UIModule.cs index c41ccbec3..5e0af20fe 100644 --- a/Source/Editor/Modules/UIModule.cs +++ b/Source/Editor/Modules/UIModule.cs @@ -486,6 +486,14 @@ namespace FlaxEditor.Modules options.Interface.NumberOfGameClientsToLaunch = value; Editor.Options.Apply(options); }; + + Editor.Options.OptionsChanged += (options) => + { + if (options.Interface.NumberOfGameClientsToLaunch != _numberOfClientsGroup.activeItem.value) + { + _numberOfClientsGroup.SetItemAsActive(options.Interface.NumberOfGameClientsToLaunch); + } + }; } private void InitMainMenu(RootControl mainWindow) @@ -682,9 +690,16 @@ namespace FlaxEditor.Modules playActionGroup.SetItemAsActive(Editor.Options.Options.Interface.PlayButtonAction); // important to add the handler after setting the initial item as active above or the editor will crash playActionGroup.OnSelectionChanged = SetPlayAction; - // TODO: there are some holes in the syncing of these values + // TODO: there is a hole in the syncing of these values: // - when changing in the editor, the options will be updated, but the options UI in-editor will not - // - when updating the value in the options UI, the value in the tool strip will not update (adding an options changed event handler results in a crash) + + Editor.Options.OptionsChanged += (options) => + { + if (options.Interface.PlayButtonAction != playActionGroup.activeItem.value) + { + playActionGroup.SetItemAsActive(options.Interface.PlayButtonAction); + } + }; _toolStripPause = (ToolStripButton)ToolStrip.AddButton(Editor.Icons.Pause64, Editor.Simulation.RequestResumeOrPause).LinkTooltip($"Pause/Resume game({inputOptions.Pause.ToString()})"); _toolStripStep = (ToolStripButton)ToolStrip.AddButton(Editor.Icons.Skip64, Editor.Simulation.RequestPlayOneFrame).LinkTooltip("Step one frame in game");