From d86fa80d79181e65d05fe11e3629cb2609e3ef05 Mon Sep 17 00:00:00 2001 From: Amy <3855802+amylizzle@users.noreply.github.com> Date: Tue, 2 Jan 2024 20:36:36 +0000 Subject: [PATCH] on-show and on-hide for info and browser, handle winset attribute=; (#1564) --- .../Interface/Controls/ControlBrowser.cs | 26 ++++++++++++++++++- .../Interface/Controls/ControlInfo.cs | 26 ++++++++++++++++++- OpenDreamClient/Interface/DMF/DMFParser.cs | 5 +++- .../Descriptors/ControlDescriptors.cs | 8 ++++++ 4 files changed, 62 insertions(+), 3 deletions(-) diff --git a/OpenDreamClient/Interface/Controls/ControlBrowser.cs b/OpenDreamClient/Interface/Controls/ControlBrowser.cs index 6c0eeb9933..85d6ad5ee4 100644 --- a/OpenDreamClient/Interface/Controls/ControlBrowser.cs +++ b/OpenDreamClient/Interface/Controls/ControlBrowser.cs @@ -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; } @@ -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 { diff --git a/OpenDreamClient/Interface/Controls/ControlInfo.cs b/OpenDreamClient/Interface/Controls/ControlInfo.cs index a6f3bce85b..884ee6e261 100644 --- a/OpenDreamClient/Interface/Controls/ControlInfo.cs +++ b/OpenDreamClient/Interface/Controls/ControlInfo.cs @@ -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; } @@ -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); + } + } } diff --git a/OpenDreamClient/Interface/DMF/DMFParser.cs b/OpenDreamClient/Interface/DMF/DMFParser.cs index 1f6be372b9..397edc8b53 100644 --- a/OpenDreamClient/Interface/DMF/DMFParser.cs +++ b/OpenDreamClient/Interface/DMF/DMFParser.cs @@ -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; diff --git a/OpenDreamClient/Interface/Descriptors/ControlDescriptors.cs b/OpenDreamClient/Interface/Descriptors/ControlDescriptors.cs index 8ab31110cf..9e9b17658d 100644 --- a/OpenDreamClient/Interface/Descriptors/ControlDescriptors.cs +++ b/OpenDreamClient/Interface/Descriptors/ControlDescriptors.cs @@ -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 } @@ -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 {