Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
25 changes: 13 additions & 12 deletions OpenDreamClient/Interface/BrowsePopup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,19 @@
public BrowsePopup(
string name,
Vector2i size,
IClydeWindow ownerWindow) {
WindowDescriptor popupWindowDescriptor = new WindowDescriptor(name,
new() {
new ControlDescriptorBrowser {
Id = new DMFPropertyString("browser"),
Size = new DMFPropertySize(size),
Anchor1 = new DMFPropertyPos(0, 0),
Anchor2 = new DMFPropertyPos(100, 100)
}
}) {
Size = new DMFPropertySize(size)
};
IClydeWindow ownerWindow,
WindowDescriptor? descriptor = null) {

WindowDescriptor popupWindowDescriptor = descriptor ?? new WindowDescriptor(name) {

Check warning

Code scanning / InspectCode

Incorrect blank lines: Incorrect number of blank lines near braces Warning

Incorrect number of blank lines near braces, expected maximum 0 instead of 1
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
Size = new DMFPropertySize(size)
};

popupWindowDescriptor.ControlDescriptors.Add(new ControlDescriptorBrowser {
Id = new DMFPropertyString("browser"),
Size = new DMFPropertySize(size),
Anchor1 = new DMFPropertyPos(0, 0),
Anchor2 = new DMFPropertyPos(100, 100),
});

WindowElement = new ControlWindow(popupWindowDescriptor);
WindowElement.CreateChildControls();
Expand Down
128 changes: 86 additions & 42 deletions OpenDreamClient/Interface/DreamInterfaceManager.cs
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
using System.IO;
using System.Text;
using System.Globalization;
using OpenDreamShared.Network.Messages;
using OpenDreamClient.Interface.Controls;
using OpenDreamShared.Interface.Descriptors;
using OpenDreamShared.Interface.DMF;
using OpenDreamClient.Interface.Controls;
using OpenDreamClient.Interface.Prompts;
using OpenDreamClient.Resources;
using OpenDreamClient.Resources.ResourceTypes;
using OpenDreamShared.Dream;
using OpenDreamShared.Interface.Descriptors;
using OpenDreamShared.Interface.DMF;
using OpenDreamShared.Network.Messages;
using Robust.Client;
using Robust.Client.Graphics;
using Robust.Client.Input;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Shared.ContentPack;
using Robust.Shared.Map;
using Robust.Shared.Network;
using Robust.Shared.Random;
using Robust.Shared.Serialization.Manager;
using Robust.Shared.Serialization.Markdown.Mapping;
using Robust.Shared.Timing;
using Robust.Shared.Utility;
using SixLabors.ImageSharp;
using System.Globalization;
using System.IO;
using System.Linq;
using Robust.Shared.Map;
using System.Text;

namespace OpenDreamClient.Interface;

Expand Down Expand Up @@ -203,7 +204,10 @@
browser.SetFileSource(null);
}
} else if (pBrowse.HtmlSource != null) {
var htmlFileName = $"browse_{pBrowse.Window}_{_random.Next()}"; // TODO: Possible collisions and explicit file names
// TODO: Possible collisions and explicit file names
// pBrowse contains options, which may contain the 'file' property. When this is explicitly declared, instead of
// using a random htmlFileName, we should instead use that file instead.
var htmlFileName = $"browse_{pBrowse.Window}_{_random.Next()}";
ControlBrowser? outputBrowser = referencedElement as ControlBrowser;

if (outputBrowser == null) {
Expand All @@ -219,8 +223,36 @@
break;
}
} else if (pBrowse.Window != null) {

DMFParser? parser;

Check warning

Code scanning / InspectCode

Incorrect blank lines: Incorrect number of blank lines near braces Warning

Incorrect number of blank lines near braces, expected maximum 0 instead of 1
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
WindowDescriptor? descriptor = null;
(int x, int y) size = (480, 480);

// Handle using options to set the initial properties of the window
if (pBrowse.Options != null
&& (parser = ParseDmfParams(pBrowse.Options, out var CheckParserErrors)) != null

Check warning

Code scanning / InspectCode

Inconsistent Naming Warning

Name 'CheckParserErrors' does not match rule 'Local variables'. Suggested name is 'checkParserErrors'.
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
&& parser.AttributesValues() is Dictionary<string, string> attributes

Check warning

Code scanning / InspectCode

Use null check pattern instead of a type check succeeding on any not-null value Warning

Use not null pattern instead of a type check succeeding on any not-null value
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
&& !CheckParserErrors()) {

var mappingElement = new MappingDataNode();

Check warning

Code scanning / InspectCode

Incorrect blank lines: Incorrect number of blank lines near braces Warning

Incorrect number of blank lines near braces, expected maximum 0 instead of 1

Check notice

Code scanning / InspectCode

Use object or collection initializer when possible Note

Use collection initializer
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed

mappingElement.Add("id", pBrowse.Window);
foreach (var attribute in attributes) {
mappingElement.Add(attribute.Key, attribute.Value);
}
descriptor = (WindowDescriptor?)_serializationManager.Read(typeof(WindowDescriptor), mappingElement);

Check warning

Code scanning / InspectCode

Incorrect blank lines: Blank lines are missing elsewhere Warning

Blank lines are missing, expected minimum 1 instead of 0
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed

if (descriptor?.Size.X == 0 || descriptor?.Size.Y == 0) {
descriptor.Size.X = size.x;
descriptor.Size.Y = size.y;
} else if (descriptor != null) {
size.x = descriptor.Size.X;
size.y = descriptor.Size.Y;
}
}

// Creating a new popup
var popup = new BrowsePopup(pBrowse.Window, pBrowse.Size, _clyde.MainWindow);
var popup = new BrowsePopup(pBrowse.Window, size, _clyde.MainWindow, descriptor);
popup.Closed += () => { Windows.Remove(pBrowse.Window); };

outputBrowser = popup.Browser;
Expand Down Expand Up @@ -264,7 +296,7 @@
MsgPromptResponse response = new() {
PromptId = message.PromptId,
Type = DreamValueType.Text,
Value = WinGet(message.ControlId, message.QueryValue, forceSnowflake:true)
Value = WinGet(message.ControlId, message.QueryValue, forceSnowflake: true)
};

_netManager.ClientSendMessage(response);
Expand Down Expand Up @@ -366,7 +398,7 @@
} else if (Menus.TryGetValue(windowId, out var menu)) {
if (menu.MenuElementsById.TryGetValue(elementId, out var menuElement))
return menuElement;
} else if(MacroSets.TryGetValue(windowId, out var macroSet)) {
} else if (MacroSets.TryGetValue(windowId, out var macroSet)) {
if (macroSet.Macros.TryGetValue(elementId, out var macroElement))
return macroElement;
}
Expand Down Expand Up @@ -516,7 +548,7 @@
var result = HandleEmbeddedWinget(null, currentArg.ToString(), out var hadWinget);

// 64x64 or 64,64 gets split into two "64 64" args
if (hadWinget && result.Split(['x', ',']) is {Length: 2} wingetSplit &&
if (hadWinget && result.Split(['x', ',']) is { Length: 2 } wingetSplit &&
float.TryParse(wingetSplit[0], out _) && float.TryParse(wingetSplit[1], out _)) {
args.Add(wingetSplit[0]);
args.Add(wingetSplit[1]);
Expand All @@ -535,7 +567,7 @@
var result = HandleEmbeddedWinget(null, currentArg.ToString(), out var hadWinget);

// 64x64 or 64,64 gets split into two "64 64" args
if (hadWinget && result.Split(['x', ',']) is {Length: 2} wingetSplit &&
if (hadWinget && result.Split(['x', ',']) is { Length: 2 } wingetSplit &&
float.TryParse(wingetSplit[0], out _) && float.TryParse(wingetSplit[1], out _)) {
args.Add(wingetSplit[0]);
args.Add(wingetSplit[1]);
Expand All @@ -554,7 +586,7 @@
var result = HandleEmbeddedWinget(null, arg, out var hadWinget);

// 64x64 or 64,64 gets split into two "64 64" args
if (hadWinget && result.Split(['x', ',']) is {Length: 2} wingetSplit &&
if (hadWinget && result.Split(['x', ',']) is { Length: 2 } wingetSplit &&
float.TryParse(wingetSplit[0], out _) && float.TryParse(wingetSplit[1], out _)) {
args.Add(wingetSplit[0]);
args.Add(wingetSplit[1]);
Expand Down Expand Up @@ -614,35 +646,36 @@

string result = value;
int startPos = result.IndexOf("[[", StringComparison.Ordinal);
while(startPos > -1){
while (startPos > -1) {
int endPos = result.IndexOf("]]", startPos, StringComparison.Ordinal);
if(endPos == -1)
if (endPos == -1)
break;
string inner = result.Substring(startPos+2, endPos-startPos-2);
string inner = result.Substring(startPos + 2, endPos - startPos - 2);
string[] elementSplit = inner.Split('.');
string innerControlId = controlId ?? "";
if(elementSplit.Length > 1){
innerControlId = (string.IsNullOrEmpty(innerControlId) ? "" : innerControlId+".")+string.Join(".", elementSplit[..^1]);
if (elementSplit.Length > 1) {
innerControlId = (string.IsNullOrEmpty(innerControlId) ? "" : innerControlId + ".") + string.Join(".", elementSplit[..^1]);
inner = elementSplit[^1];
}

string innerResult = WinGet(innerControlId, inner);
hadWinget = true;
result = result.Substring(0, startPos) + innerResult + result.Substring(endPos+2);
result = result.Substring(0, startPos) + innerResult + result.Substring(endPos + 2);
startPos = result.IndexOf("[[", StringComparison.Ordinal);
}

return result;
}

public void WinSet(string? controlId, string winsetParams) {
private DMFParser? ParseDmfParams(string dmfParams, out Func<bool> CheckErrors) {

Check warning

Code scanning / InspectCode

Inconsistent Naming Warning

Name 'CheckErrors' does not match rule 'Parameters'. Suggested name is 'checkErrors'.
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
CheckErrors = null!;
DMFParser parser;
try{
var lexer = new DMFLexer(winsetParams);
try {
var lexer = new DMFLexer(dmfParams);
parser = new DMFParser(lexer, _serializationManager);
} catch (Exception e) {
_sawmill.Error($"Error parsing winset: {e}");
return;
return null;
}

bool CheckParserErrors() {
Expand All @@ -656,6 +689,17 @@
return true;
}

CheckErrors = CheckParserErrors;
return parser;
}

public void WinSet(string? controlId, string winsetParams) {
DMFParser? parser = ParseDmfParams(winsetParams, out var CheckParserErrors);

Check warning

Code scanning / InspectCode

Inconsistent Naming Warning

Name 'CheckParserErrors' does not match rule 'Local variables'. Suggested name is 'checkParserErrors'.
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed

if (parser == null) {
return;
}

if (string.IsNullOrEmpty(controlId)) {
List<DMFWinSet> winSets = parser.GlobalWinSet();

Expand All @@ -678,26 +722,26 @@
_sawmill.Error($"Invalid global winset \"{winsetParams}\"");
}
} else {
if(winSet.TrueStatements is not null) {
if (winSet.TrueStatements is not null) {
InterfaceElement? conditionalElement = FindElementWithId(elementId);
if(conditionalElement is null)
if (conditionalElement is null)
_sawmill.Error($"Invalid element on ternary condition \"{elementId}\"");
else
if(conditionalElement.TryGetProperty(winSet.Attribute, out var conditionalCheckValue) && conditionalCheckValue.Equals(winSet.Value)) {
foreach(DMFWinSet statement in winSet.TrueStatements) {
if (conditionalElement.TryGetProperty(winSet.Attribute, out var conditionalCheckValue) && conditionalCheckValue.Equals(winSet.Value)) {
foreach (DMFWinSet statement in winSet.TrueStatements) {
string statementElementId = statement.Element ?? elementId;
InterfaceElement? statementElement = FindElementWithId(statementElementId);
if(statementElement is not null) {
if (statementElement is not null) {
statementElement.SetProperty(statement.Attribute, HandleEmbeddedWinget(statementElementId, statement.Value, out _), manualWinset: true);
} else {
_sawmill.Error($"Invalid element on ternary \"{statementElementId}\"");
}
}
} else if (winSet.FalseStatements is not null){
foreach(DMFWinSet statement in winSet.FalseStatements) {
} else if (winSet.FalseStatements is not null) {
foreach (DMFWinSet statement in winSet.FalseStatements) {
string statementElementId = statement.Element ?? elementId;
InterfaceElement? statementElement = FindElementWithId(statementElementId);
if(statementElement is not null) {
if (statementElement is not null) {
statementElement.SetProperty(statement.Attribute, HandleEmbeddedWinget(statementElementId, statement.Value, out _), manualWinset: true);
} else {
_sawmill.Error($"Invalid element on ternary \"{statementElementId}\"");
Expand Down Expand Up @@ -750,16 +794,16 @@
//parse "as blah" from query if it's there
string[] querySplit = query.Split(" as ");
IDMFProperty propResult;
if(querySplit.Length != 2) //must be "thing as blah" or "thing". Anything else is invalid.
if(element.TryGetProperty(query, out propResult!)){
if (querySplit.Length != 2) //must be "thing as blah" or "thing". Anything else is invalid.
if (element.TryGetProperty(query, out propResult!)) {
result = forceJson ? propResult.AsJson() : forceSnowflake ? propResult.AsSnowflake() : propResult.AsRaw();
return true;
} else {
result = "";
return false;
}
else{
if(!element.TryGetProperty(querySplit[0], out propResult!)) {
else {
if (!element.TryGetProperty(querySplit[0], out propResult!)) {
result = "";
return false;
}
Expand All @@ -772,7 +816,7 @@
return true;
}

switch(querySplit[1]){
switch (querySplit[1]) {
case "arg":
result = propResult.AsArg();
break;
Expand Down Expand Up @@ -812,12 +856,12 @@
}

var multiQuery = queryValue.Split(';', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
if(multiQuery.Length > 1) {
if (multiQuery.Length > 1) {
var result = "";
foreach(var query in multiQuery) {
foreach (var query in multiQuery) {
if (!ParseAndTryGet(element, query, out var queryResult))
_sawmill.Error($"Could not winget property {query} on {element.Id}");
result += query+"="+queryResult + ";";
result += query + "=" + queryResult + ";";
}

return result.TrimEnd(';');
Expand Down Expand Up @@ -930,7 +974,7 @@
private void Reset() {
_uiManager.MainViewport.Visible = false;
//close windows if they're open, and clear all child ui elements
foreach (var window in Windows.Values){
foreach (var window in Windows.Values) {
window.CloseChildWindow();
window.UIElement.RemoveAllChildren();
}
Expand Down
Loading
Loading