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

on-show and on-hide for INFO and BROWSER plus handle winset attribute=; #1564

Merged
merged 2 commits into from
Jan 2, 2024
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
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
Loading