Skip to content

Commit

Permalink
on-show and on-hide for info and browser, handle winset attribute=; (O…
Browse files Browse the repository at this point in the history
  • Loading branch information
amylizzle authored Jan 2, 2024
1 parent a143b68 commit d86fa80
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 3 deletions.
26 changes: 25 additions & 1 deletion OpenDreamClient/Interface/Controls/ControlBrowser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,17 @@ protected override Control CreateUIElement() {

_webView.AddResourceRequestHandler(RequestHandler);
_webView.AddBeforeBrowseHandler(BeforeBrowseHandler);

_webView.OnVisibilityChanged += (args) => {
if (args.Visible) {
OnShowEvent();
} else {
OnHideEvent();
}
};
if(ControlDescriptor.IsVisible)
OnShowEvent();
else
OnHideEvent();
return _webView;
}

Expand Down Expand Up @@ -146,6 +156,20 @@ private void HandleEmbeddedWinset(string query) {
// We can finally call winset
_interfaceManager.WinSet(element, modifiedQuery);
}

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

public void OnHideEvent() {
ControlDescriptorBrowser controlDescriptor = (ControlDescriptorBrowser)ControlDescriptor;
if (controlDescriptor.OnHideCommand != null) {
_interfaceManager.RunCommand(controlDescriptor.OnHideCommand);
}
}
}

public sealed class BrowseWinCommand : IConsoleCommand {
Expand Down
26 changes: 25 additions & 1 deletion OpenDreamClient/Interface/Controls/ControlInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,17 @@ protected override Control CreateUIElement() {
_tabControl.OnTabChanged += OnSelectionChanged;

RefreshVerbs();

_tabControl.OnVisibilityChanged += (args) => {
if (args.Visible) {
OnShowEvent();
} else {
OnHideEvent();
}
};
if(ControlDescriptor.IsVisible)
OnShowEvent();
else
OnHideEvent();
return _tabControl;
}

Expand Down Expand Up @@ -285,4 +295,18 @@ private void OnSelectionChanged(int tabIndex) {

_netManager.ClientSendMessage(msg);
}

public void OnShowEvent() {
ControlDescriptorInfo controlDescriptor = (ControlDescriptorInfo)ControlDescriptor;
if (controlDescriptor.OnShowCommand != null) {
_interfaceManager.RunCommand(controlDescriptor.OnShowCommand);
}
}

public void OnHideEvent() {
ControlDescriptorInfo controlDescriptor = (ControlDescriptorInfo)ControlDescriptor;
if (controlDescriptor.OnHideCommand != null) {
_interfaceManager.RunCommand(controlDescriptor.OnHideCommand);
}
}
}
5 changes: 4 additions & 1 deletion OpenDreamClient/Interface/DMF/DMFParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,10 @@ private bool TryGetAttribute(out string? element, [NotNullWhen(true)] out string
if (!Check(TokenType.DMF_Value) && !Check(TokenType.DMF_Attribute))
Error($"Invalid attribute value ({valueText})");
} else if (!Check(TokenType.DMF_Value))
Error($"Invalid attribute value ({valueText})");
if(Check(TokenType.DMF_Semicolon)) //thing.attribute=; means thing.attribute=empty string
valueText = "";
else
Error($"Invalid attribute value ({valueText})");

Newline();
key = attributeToken.Text;
Expand Down
8 changes: 8 additions & 0 deletions OpenDreamClient/Interface/Descriptors/ControlDescriptors.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ public sealed partial class ControlDescriptorOutput : ControlDescriptor {
}

public sealed partial class ControlDescriptorInfo : ControlDescriptor {
[DataField("on-show")]
public string? OnShowCommand;
[DataField("on-hide")]
public string? OnHideCommand;
[DataField("allow-html")]
public bool AllowHtml = true; // Supposedly false by default, but it isn't if you're not using BYOND's default skin
}
Expand All @@ -150,6 +154,10 @@ public sealed partial class ControlDescriptorMap : ControlDescriptor {
}

public sealed partial class ControlDescriptorBrowser : ControlDescriptor {
[DataField("on-show")]
public string? OnShowCommand;
[DataField("on-hide")]
public string? OnHideCommand;
}

public sealed partial class ControlDescriptorLabel : ControlDescriptor {
Expand Down

0 comments on commit d86fa80

Please sign in to comment.