diff --git a/OpenDreamClient/Interface/Controls/ControlWindow.cs b/OpenDreamClient/Interface/Controls/ControlWindow.cs index ea29a7358d..e76c4907c7 100644 --- a/OpenDreamClient/Interface/Controls/ControlWindow.cs +++ b/OpenDreamClient/Interface/Controls/ControlWindow.cs @@ -33,6 +33,10 @@ public ControlWindow(WindowDescriptor windowDescriptor) : base(windowDescriptor, IoCManager.InjectDependencies(this); } + public IClydeWindow? GetClydeWindow() { + return _myWindow.osWindow is null ? _myWindow.clydeWindow : _myWindow.osWindow.ClydeWindow; + } + protected override void UpdateElementDescriptor() { // Don't call base.UpdateElementDescriptor(); diff --git a/OpenDreamClient/Interface/DebugWindows/MacrosWindow.cs b/OpenDreamClient/Interface/DebugWindows/MacrosWindow.cs index c320f978b6..51afec74f9 100644 --- a/OpenDreamClient/Interface/DebugWindows/MacrosWindow.cs +++ b/OpenDreamClient/Interface/DebugWindows/MacrosWindow.cs @@ -43,8 +43,8 @@ private GridContainer CreateMacroTable(InterfaceMacroSet macroSet) { foreach (var macro in macroSet.Macros.Values) { var idText = macro.Id; - if (macro.ElementDescriptor.Name.Value != idText.Value) - idText.Value += $" ({macro.ElementDescriptor.Name.AsRaw()})"; + if (macro.ElementDescriptor.Id.Value != idText.Value) + idText.Value += $" ({macro.ElementDescriptor.Id.AsRaw()})"; var idLabel = new Label { Text = idText.AsRaw() }; var commandLabel = new Label { Text = macro.Command }; diff --git a/OpenDreamClient/Interface/DreamInterfaceManager.cs b/OpenDreamClient/Interface/DreamInterfaceManager.cs index 1e97447d53..708b51ced5 100644 --- a/OpenDreamClient/Interface/DreamInterfaceManager.cs +++ b/OpenDreamClient/Interface/DreamInterfaceManager.cs @@ -21,6 +21,7 @@ using Robust.Shared.Utility; using SixLabors.ImageSharp; using System.Linq; +using Robust.Shared.Map; namespace OpenDreamClient.Interface; @@ -55,6 +56,7 @@ internal sealed class DreamInterfaceManager : IDreamInterfaceManager { public Dictionary Windows { get; } = new(); public Dictionary Menus { get; } = new(); public Dictionary MacroSets { get; } = new(); + private Dictionary ClydeWindowIdToControl { get; } = new(); public ViewRange View { get => _view; @@ -124,6 +126,7 @@ public void Initialize() { _netManager.RegisterNetMessage(RxLoadInterface); _netManager.RegisterNetMessage(); _netManager.RegisterNetMessage(RxUpdateClientInfo); + _clyde.OnWindowFocused += OnWindowFocused; } private void RxUpdateStatPanels(MsgUpdateStatPanels message) { @@ -914,6 +917,24 @@ private void LoadInterface(InterfaceDescriptor descriptor) { LayoutContainer.SetAnchorBottom(DefaultWindow.UIElement, 1); _uiManager.StateRoot.AddChild(DefaultWindow.UIElement); + + if (DefaultWindow.GetClydeWindow() is { } clydeWindow) { + ClydeWindowIdToControl.Add(clydeWindow.Id, DefaultWindow); + } + } + + private void OnWindowFocused(WindowFocusedEventArgs args) { + if(ClydeWindowIdToControl.TryGetValue(args.Window.Id, out var controlWindow)){ + _sawmill.Debug($"window id {controlWindow.Id} was {(args.Focused ? "focused" : "defocused")}"); + WindowDescriptor descriptor = (WindowDescriptor) controlWindow.ElementDescriptor; + descriptor.Focus = new DMFPropertyBool(args.Focused); + if(args.Focused && MacroSets.TryGetValue(descriptor.Macro.AsRaw(), out var windowMacroSet)){ + _sawmill.Debug($"Activating macroset {descriptor.Macro}"); + windowMacroSet.SetActive(); + } + } + else + _sawmill.Debug($"window id was not found (probably a modal) but was {(args.Focused ? "focused" : "defocused")}"); } private void LoadDescriptor(ElementDescriptor descriptor) { @@ -936,6 +957,10 @@ private void LoadDescriptor(ElementDescriptor descriptor) { DefaultWindow = window; } + if (window.GetClydeWindow() is { } clydeWindow) { + ClydeWindowIdToControl.Add(clydeWindow.Id, window); + } + break; } } diff --git a/OpenDreamClient/Interface/InterfaceMacro.cs b/OpenDreamClient/Interface/InterfaceMacro.cs index be94c0a168..76accd076a 100644 --- a/OpenDreamClient/Interface/InterfaceMacro.cs +++ b/OpenDreamClient/Interface/InterfaceMacro.cs @@ -25,7 +25,7 @@ public InterfaceMacroSet(MacroSetDescriptor descriptor, IEntitySystemManager ent _entitySystemManager = entitySystemManager; _uiManager = uiManager; - _inputContextName = $"{InputContextPrefix}{ElementDescriptor.Name}"; + _inputContextName = $"{InputContextPrefix}{ElementDescriptor.Id}"; if (inputManager.Contexts.TryGetContext(_inputContextName, out var existingContext)) { _inputContext = existingContext; } else { @@ -45,7 +45,7 @@ public override void AddChild(ElementDescriptor descriptor) { } public void SetActive() { - _inputManager.Contexts.SetActiveContext($"{InputContextPrefix}{ElementDescriptor.Name}"); + _inputManager.Contexts.SetActiveContext($"{InputContextPrefix}{ElementDescriptor.Id}"); } }