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 on-show and on-hide for map controls, plus winset parsing fixes #1450

Merged
merged 14 commits into from
Oct 14, 2023
Merged
33 changes: 4 additions & 29 deletions OpenDreamClient/Input/DreamCommandSystem.cs
amylizzle marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,11 @@ public sealed class DreamCommandSystem : SharedDreamCommandSystem {
[Dependency] private readonly IDreamInterfaceManager _interfaceManager = default!;

public void RunCommand(string command) {
string[] split = command.Split(" ");
string verb = split[0];

switch (verb) {
case ".quit":
IoCManager.Resolve<IClientNetManager>().ClientDisconnect(".quit used");
break;

case ".screenshot":
_interfaceManager.SaveScreenshot(split.Length == 1 || split[1] != "auto");
break;

case ".configure":
Log.Warning(".configure command is not implemented");
break;

case ".winset":
// Everything after .winset, excluding the space and quotes
string winsetParams = command.Substring(verb.Length + 2, command.Length - verb.Length - 3);

_interfaceManager.WinSet(null, winsetParams);
break;
_interfaceManager.RunCommand(command);
}

default: {
// Send the entire command to the server.
// It has more info about argument types so it can parse it better than we can.
RaiseNetworkEvent(new CommandEvent(command));
break;
}
}
public void SendServerCommand(string command) {
RaiseNetworkEvent(new CommandEvent(command));
}

public void StartRepeatingCommand(string command) {
Expand Down
26 changes: 26 additions & 0 deletions OpenDreamClient/Interface/Controls/ControlMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,17 @@ public void UpdateViewRange(ViewRange view) {
protected override Control CreateUIElement() {
Viewport = new ScalingViewport { MouseFilter = Control.MouseFilterMode.Stop };
Viewport.OnKeyBindDown += OnViewportKeyBindDown;
Viewport.OnVisibilityChanged += (args) => {
if (args.Visible) {
OnShowEvent();
} else {
OnHideEvent();
}
};
if(ControlDescriptor.IsVisible)
OnShowEvent();
else
OnHideEvent();

UpdateViewRange(_dreamInterfaceManager.View);

Expand All @@ -54,4 +65,19 @@ private void OnViewportKeyBindDown(GUIBoundKeyEventArgs e) {
}
}
}

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

public void OnHideEvent() {
ControlDescriptorMap controlDescriptor = (ControlDescriptorMap)ControlDescriptor;
if (controlDescriptor.OnHideCommand != null) {
_dreamInterfaceManager.RunCommand(controlDescriptor.OnHideCommand);
//EntitySystem.Get<DreamCommandSystem>().RunCommand(controlDescriptor.OnHideCommand);
amylizzle marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
6 changes: 4 additions & 2 deletions OpenDreamClient/Interface/DMF/DMFParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,10 @@ private bool TryGetAttribute(out string? element, [NotNullWhen(true)] out string
Token attributeToken = Current();

if (Check(_attributeTokenTypes)) {
if (Check(TokenType.DMF_Period)) { // element.attribute=value
element = attributeToken.Text;
while(Check(TokenType.DMF_Period)) { // element.attribute=value
element ??= "";
if(element.Length > 0) element += ".";
element += attributeToken.Text;
attributeToken = Current();

if (!Check(_attributeTokenTypes)) {
Expand Down
6 changes: 6 additions & 0 deletions OpenDreamClient/Interface/Descriptors/ControlDescriptors.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,14 @@ public sealed partial class ControlDescriptorInfo : ControlDescriptor {
}

public sealed partial class ControlDescriptorMap : ControlDescriptor {

[DataField("on-show")]
public string? OnShowCommand;
[DataField("on-hide")]
public string? OnHideCommand;
[DataField("zoom-mode")]
public string ZoomMode = "normal";

amylizzle marked this conversation as resolved.
Show resolved Hide resolved
}

public sealed partial class ControlDescriptorBrowser : ControlDescriptor {
Expand Down
39 changes: 38 additions & 1 deletion OpenDreamClient/Interface/DreamInterfaceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
using Robust.Shared.Timing;
using Robust.Shared.Utility;
using SixLabors.ImageSharp;
using static OpenDreamShared.Input.SharedDreamCommandSystem;
using System.Linq;

namespace OpenDreamClient.Interface;
Expand Down Expand Up @@ -434,6 +435,40 @@ public void SaveScreenshot(bool openDialog) {
});
}

public void RunCommand(string command){
switch (command) {
case string x when x.StartsWith(".quit"):
IoCManager.Resolve<IClientNetManager>().ClientDisconnect(".quit used");
break;

case string x when x.StartsWith(".screenshot"):
string[] split = command.Split(" ");
SaveScreenshot(split.Length == 1 || split[1] != "auto");
break;

case string x when x.StartsWith(".configure"):
_sawmill.Warning(".configure command is not implemented");
break;

case string x when x.StartsWith(".winset"):
// Everything after .winset, excluding the space and quotes
string winsetParams = command.Substring(7); //clip .winset
winsetParams = winsetParams.Trim(); //clip space
winsetParams = winsetParams.Trim('\"'); //clip quotes

WinSet(null, winsetParams);
break;

default: {
// Send the entire command to the server.
// It has more info about argument types so it can parse it better than we can.
//RaiseNetworkEvent(new CommandEvent(command));
amylizzle marked this conversation as resolved.
Show resolved Hide resolved
EntitySystem.Get<DreamCommandSystem>().SendServerCommand(command);
amylizzle marked this conversation as resolved.
Show resolved Hide resolved
break;
}
}
}

public void WinSet(string? controlId, string winsetParams) {
DMFLexer lexer = new DMFLexer($"winset({controlId}, \"{winsetParams}\")", winsetParams);
DMFParser parser = new DMFParser(lexer, _serializationManager);
Expand Down Expand Up @@ -485,7 +520,7 @@ bool CheckParserErrors() {
if (element != null) {
element.PopulateElementDescriptor(node, _serializationManager);
} else {
_sawmill.Error($"Invalid element \"{controlId}\"");
_sawmill.Error($"Invalid element \"{elementId}\"");
}
}
}
Expand Down Expand Up @@ -698,5 +733,7 @@ public interface IDreamInterfaceManager {
InterfaceElement? FindElementWithId(string id);
void SaveScreenshot(bool openDialog);
void LoadInterfaceFromSource(string source);

void RunCommand(string command);
void WinSet(string? controlId, string winsetParams);
}
4 changes: 4 additions & 0 deletions OpenDreamClient/Interface/DummyDreamInterfaceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,8 @@ public void LoadInterfaceFromSource(string source) {
public void WinSet(string? controlId, string winsetParams) {

}

public void RunCommand(string command) {

}
}
Loading