Skip to content

Commit

Permalink
Add support for the TAB control (#1680)
Browse files Browse the repository at this point in the history
  • Loading branch information
wixoaGit authored Feb 24, 2024
1 parent 4891115 commit 61f8f76
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 13 deletions.
6 changes: 4 additions & 2 deletions OpenDreamClient/Interface/Controls/ControlBrowser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,12 @@ protected override Control CreateUIElement() {
OnHideEvent();
}
};

if(ControlDescriptor.IsVisible)
OnShowEvent();
else
OnHideEvent();

return _webView;
}

Expand Down Expand Up @@ -157,14 +159,14 @@ private void HandleEmbeddedWinset(string query) {
_interfaceManager.WinSet(element, modifiedQuery);
}

public void OnShowEvent() {
private void OnShowEvent() {
ControlDescriptorBrowser controlDescriptor = (ControlDescriptorBrowser)ControlDescriptor;
if (!string.IsNullOrWhiteSpace(controlDescriptor.OnShowCommand)) {
_interfaceManager.RunCommand(controlDescriptor.OnShowCommand);
}
}

public void OnHideEvent() {
private void OnHideEvent() {
ControlDescriptorBrowser controlDescriptor = (ControlDescriptorBrowser)ControlDescriptor;
if (!string.IsNullOrWhiteSpace(controlDescriptor.OnHideCommand)) {
_interfaceManager.RunCommand(controlDescriptor.OnHideCommand);
Expand Down
48 changes: 41 additions & 7 deletions OpenDreamClient/Interface/Controls/ControlTab.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,55 @@
using System.Linq;
using OpenDreamClient.Interface.Descriptors;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;

namespace OpenDreamClient.Interface.Controls;

internal sealed class ControlTab : InterfaceControl {
internal sealed class ControlTab(ControlDescriptor controlDescriptor, ControlWindow window)
: InterfaceControl(controlDescriptor, window) {
private ControlDescriptorTab TabDescriptor => (ControlDescriptorTab)ElementDescriptor;

private TabContainer _tab;
private readonly List<ControlWindow> _tabs = new();

protected override Control CreateUIElement() {
_tab = new TabContainer();

public ControlTab(ControlDescriptor controlDescriptor, ControlWindow window) :
base(controlDescriptor, window) {
return _tab;
}

protected override Control CreateUIElement() {
_tab = new TabContainer() {
protected override void UpdateElementDescriptor() {
base.UpdateElementDescriptor();

};
_tabs.Clear();
_tab.RemoveAllChildren();
if (TabDescriptor.Tabs != null) {
var tabIds = TabDescriptor.Tabs.Split(',',
StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries);

return _tab;
foreach (var tabId in tabIds) {
if (!_interfaceManager.Windows.TryGetValue(tabId, out var pane))
continue;

TabContainer.SetTabTitle(pane.UIElement, pane.Title);
_tab.AddChild(pane.UIElement);
_tabs.Add(pane);
if (TabDescriptor.CurrentTab == pane.Title)
_tab.CurrentTab = pane.UIElement.GetPositionInParent();
}
}
}

public override bool TryGetProperty(string property, out string value) {
switch (property) {
case "current-tab":
var currentTab = _tab.GetChild(_tab.CurrentTab);

// The use of First() is kinda bad but hopefully this isn't large or performance critical
value = _tabs.First(tab => tab.UIElement == currentTab).Id;
return true;
default:
return base.TryGetProperty(property, out value);
}
}
}
9 changes: 5 additions & 4 deletions OpenDreamClient/Interface/Controls/ControlWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ namespace OpenDreamClient.Interface.Controls;
public sealed class ControlWindow : InterfaceControl {
[Dependency] private readonly IClyde _clyde = default!;
[Dependency] private readonly IUserInterfaceManager _uiMgr = default!;
[Dependency] private readonly IEntitySystemManager _entitySystemManager = default!;

private readonly ISawmill _sawmill = Logger.GetSawmill("opendream.window");

Expand All @@ -18,6 +17,7 @@ public sealed class ControlWindow : InterfaceControl {

public readonly List<InterfaceControl> ChildControls = new();

public string Title => WindowDescriptor.Title ?? (WindowDescriptor.IsDefault ? "OpenDream World" : WindowDescriptor.Id);
public InterfaceMacroSet Macro => _interfaceManager.MacroSets[WindowDescriptor.Macro];

private WindowDescriptor WindowDescriptor => (WindowDescriptor)ElementDescriptor;
Expand Down Expand Up @@ -160,22 +160,23 @@ public void UpdateAnchors() {
private void UpdateWindowAttributes((OSWindow? osWindow, IClydeWindow? clydeWindow) windowRoot) {
// TODO: this would probably be cleaner if an OSWindow for MainWindow was available.
var (osWindow, clydeWindow) = windowRoot;

//if our window is null or closed, and we are visible, we need to create a new one. Otherwise we need to update the existing one.
if(osWindow == null && clydeWindow == null) {
if (WindowDescriptor.IsVisible) {
CreateWindow();
return; //we return because CreateWindow() calls UpdateWindowAttributes() again.
}
}

if(osWindow != null && !osWindow.IsOpen) {
if (WindowDescriptor.IsVisible) {
osWindow.Show();
}
}

var title = WindowDescriptor.Title ?? "OpenDream World";
if (osWindow != null) osWindow.Title = title;
else if (clydeWindow != null) clydeWindow.Title = title;
if (osWindow != null) osWindow.Title = Title;
else if (clydeWindow != null) clydeWindow.Title = Title;

WindowRoot? root = null;
if (osWindow?.Window != null)
Expand Down
4 changes: 4 additions & 0 deletions OpenDreamClient/Interface/Descriptors/ControlDescriptors.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,10 @@ public sealed partial class ControlDescriptorGrid : ControlDescriptor {
}

public sealed partial class ControlDescriptorTab : ControlDescriptor {
[DataField("tabs")]
public string? Tabs;
[DataField("current-tab")]
public string? CurrentTab;
}


Expand Down

0 comments on commit 61f8f76

Please sign in to comment.