Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement focus and macro selection for windows #2192

Merged
merged 2 commits into from
Feb 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions OpenDreamClient/Interface/Controls/ControlWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
4 changes: 2 additions & 2 deletions OpenDreamClient/Interface/DebugWindows/MacrosWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand Down
25 changes: 25 additions & 0 deletions OpenDreamClient/Interface/DreamInterfaceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
using Robust.Shared.Utility;
using SixLabors.ImageSharp;
using System.Linq;
using Robust.Shared.Map;

namespace OpenDreamClient.Interface;

Expand Down Expand Up @@ -55,6 +56,7 @@ internal sealed class DreamInterfaceManager : IDreamInterfaceManager {
public Dictionary<string, ControlWindow> Windows { get; } = new();
public Dictionary<string, InterfaceMenu> Menus { get; } = new();
public Dictionary<string, InterfaceMacroSet> MacroSets { get; } = new();
private Dictionary<WindowId, ControlWindow> ClydeWindowIdToControl { get; } = new();

public ViewRange View {
get => _view;
Expand Down Expand Up @@ -124,6 +126,7 @@ public void Initialize() {
_netManager.RegisterNetMessage<MsgLoadInterface>(RxLoadInterface);
_netManager.RegisterNetMessage<MsgAckLoadInterface>();
_netManager.RegisterNetMessage<MsgUpdateClientInfo>(RxUpdateClientInfo);
_clyde.OnWindowFocused += OnWindowFocused;
}

private void RxUpdateStatPanels(MsgUpdateStatPanels message) {
Expand Down Expand Up @@ -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) {
Expand All @@ -936,6 +957,10 @@ private void LoadDescriptor(ElementDescriptor descriptor) {
DefaultWindow = window;
}

if (window.GetClydeWindow() is { } clydeWindow) {
ClydeWindowIdToControl.Add(clydeWindow.Id, window);
}

break;
}
}
Expand Down
4 changes: 2 additions & 2 deletions OpenDreamClient/Interface/InterfaceMacro.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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}");
}
}

Expand Down
Loading