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

Turn DMF properties into DMFProperty types #1757

Merged
merged 37 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
6091064
start
amylizzle Apr 15, 2024
dfacb1b
bunch more
amylizzle Apr 15, 2024
6166d15
move comment
amylizzle Apr 15, 2024
7109911
beginning to think this was a mistake
amylizzle Apr 17, 2024
457a8e7
more
amylizzle Apr 21, 2024
c74dd45
good news I have broken everything
amylizzle Apr 21, 2024
17f7952
menus broken, todo more default values
amylizzle Apr 21, 2024
a882ffe
clean up trygetproperty
amylizzle Apr 23, 2024
9880a4f
have some defaults
amylizzle Apr 23, 2024
d53300a
more defaults
amylizzle Apr 24, 2024
26d62fd
and that's all of them
amylizzle Apr 24, 2024
e993841
tyop
amylizzle Apr 24, 2024
937ba83
hooray I fixed it
amylizzle Apr 26, 2024
3bd4731
Fix menus
amylizzle Apr 26, 2024
9ea9dc3
Merge remote-tracking branch 'upstream/master' into dmfprops
amylizzle May 6, 2024
0b7343c
clear uneeded usings
amylizzle May 6, 2024
f762981
implement the various as functions, and remove test code from default…
amylizzle May 8, 2024
c396db8
parse verb args better
amylizzle May 8, 2024
c4420a1
HandleEmbeddedWinget(null ,currentArg)
amylizzle May 8, 2024
10e9377
make the verbs work
amylizzle May 10, 2024
ac71a08
bump the RT tag
amylizzle May 10, 2024
9c814d5
defaults
amylizzle May 10, 2024
f5c1f0e
fix window size
amylizzle May 10, 2024
d1ffa28
cleanup unused
amylizzle May 10, 2024
493c349
our interface positioning code is broken
amylizzle May 10, 2024
a337f60
Merge branch 'master' into dmfprops
amylizzle May 15, 2024
4200bcd
Merge branch 'master' into dmfprops
amylizzle May 17, 2024
d2a57dd
Merge branch 'master' into dmfprops
amylizzle May 23, 2024
cf7945d
shush linter
amylizzle May 27, 2024
d7649b5
Merge branch 'master' into dmfprops
amylizzle May 31, 2024
5a2376c
Apply suggestions from code review
wixoaGit Jun 1, 2024
95a838d
Apply suggestions from code review
wixoaGit Jun 1, 2024
51ea6c7
Code style fixes
wixoaGit Jun 1, 2024
b2a5d0d
code review
amylizzle Jun 3, 2024
da50cb0
more permissive number parsing
amylizzle Jun 3, 2024
127d2ff
codestyle
amylizzle Jun 3, 2024
b84148c
fix ternary comparisons
amylizzle Jun 3, 2024
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
10 changes: 5 additions & 5 deletions OpenDreamClient/Interface/BrowsePopup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ public BrowsePopup(
WindowDescriptor popupWindowDescriptor = new WindowDescriptor(name,
new() {
new ControlDescriptorBrowser {
Id = "browser",
Size = size,
Anchor1 = new Vector2i(0, 0),
Anchor2 = new Vector2i(100, 100)
Id = new DMFPropertyString("browser"),
Size = new DMFPropertyVec2(size),
Anchor1 = new DMFPropertyVec2(0, 0),
Anchor2 = new DMFPropertyVec2(100, 100)
}
}) {
Size = size
Size = new DMFPropertyVec2(size)
};

WindowElement = new ControlWindow(popupWindowDescriptor);
Expand Down
20 changes: 10 additions & 10 deletions OpenDreamClient/Interface/Controls/ControlBar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ protected override void UpdateElementDescriptor() {
base.UpdateElementDescriptor();

//width
float barWidth = BarDescriptor.Width ?? 10f;
float barWidth = BarDescriptor.Width.Value;

//TODO dir - these both need RT level changes
//TODO angles

//is-slider
if (BarDescriptor.IsSlider) {
if (BarDescriptor.IsSlider.Value) {
if (_slider is null) {
_slider = new Slider {
MaxValue = 100,
Expand All @@ -35,7 +35,7 @@ protected override void UpdateElementDescriptor() {
HorizontalExpand = true,
VerticalExpand = (barWidth == 0f),
MinHeight = barWidth,
Value = BarDescriptor.Value ?? 0.0f
Value = BarDescriptor.Value.Value
};

_slider.OnValueChanged += OnValueChanged;
Expand All @@ -47,12 +47,12 @@ protected override void UpdateElementDescriptor() {

_container.AddChild(_slider);
} else {
_slider.Value = BarDescriptor.Value ?? 0.0f;
_slider.Value = BarDescriptor.Value.Value;
}

//bar-color
if (_slider.TryGetStyleProperty<StyleBoxFlat>(Slider.StylePropertyGrabber, out var box)) {
box.BackgroundColor = BarDescriptor.BarColor ?? Color.Transparent;
box.BackgroundColor = BarDescriptor.BarColor.Value;
_slider.GrabberStyleBoxOverride = box;
}
} else {
Expand All @@ -64,7 +64,7 @@ protected override void UpdateElementDescriptor() {
HorizontalExpand = true,
VerticalExpand = (barWidth == 0f),
MinHeight = barWidth,
Value = BarDescriptor.Value ?? 0.0f
Value = BarDescriptor.Value.Value
};

_bar.OnValueChanged += OnValueChanged;
Expand All @@ -76,12 +76,12 @@ protected override void UpdateElementDescriptor() {

_container.AddChild(_bar);
} else {
_bar.Value = BarDescriptor.Value ?? 0.0f;
_bar.Value = BarDescriptor.Value.Value;
}

//bar-color
if (_bar.TryGetStyleProperty<StyleBoxFlat>(ProgressBar.StylePropertyForeground, out var box)) {
box.BackgroundColor = BarDescriptor.BarColor ?? Color.Transparent;
box.BackgroundColor = BarDescriptor.BarColor.Value;
_bar.ForegroundStyleBoxOverride = box;
}
}
Expand All @@ -93,9 +93,9 @@ private void OnValueChanged(Robust.Client.UserInterface.Controls.Range range) {
//if (_slider is not null && _slider.Grabbed)
// return;

if (BarDescriptor.OnChange != null) {
if (!string.IsNullOrEmpty(BarDescriptor.OnChange.Value)) {
var valueReplaced =
BarDescriptor.OnChange.Replace("[[*]]", range.Value.ToString(CultureInfo.InvariantCulture));
BarDescriptor.OnChange.Value.Replace("[[*]]", range.Value.ToString(CultureInfo.InvariantCulture));

_interfaceManager.RunCommand(valueReplaced);
}
Expand Down
10 changes: 5 additions & 5 deletions OpenDreamClient/Interface/Controls/ControlBrowser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ protected override Control CreateUIElement() {
}
};

if(ControlDescriptor.IsVisible)
if(ControlDescriptor.IsVisible.Value)
OnShowEvent();
else
OnHideEvent();
Expand Down Expand Up @@ -165,15 +165,15 @@ private void HandleEmbeddedWinset(string query) {

private void OnShowEvent() {
ControlDescriptorBrowser controlDescriptor = (ControlDescriptorBrowser)ControlDescriptor;
if (!string.IsNullOrWhiteSpace(controlDescriptor.OnShowCommand)) {
_interfaceManager.RunCommand(controlDescriptor.OnShowCommand);
if (!string.IsNullOrWhiteSpace(controlDescriptor.OnShowCommand.Value)) {
_interfaceManager.RunCommand(controlDescriptor.OnShowCommand.AsRaw());
}
}

private void OnHideEvent() {
ControlDescriptorBrowser controlDescriptor = (ControlDescriptorBrowser)ControlDescriptor;
if (!string.IsNullOrWhiteSpace(controlDescriptor.OnHideCommand)) {
_interfaceManager.RunCommand(controlDescriptor.OnHideCommand);
if (!string.IsNullOrWhiteSpace(controlDescriptor.OnHideCommand.Value)) {
_interfaceManager.RunCommand(controlDescriptor.OnHideCommand.AsRaw());
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions OpenDreamClient/Interface/Controls/ControlButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ protected override void UpdateElementDescriptor() {

ControlDescriptorButton controlDescriptor = (ControlDescriptorButton)ElementDescriptor;

_button.Text = controlDescriptor.Text;
_button.Text = controlDescriptor.Text.AsRaw();
}

private void OnButtonClick(BaseButton.ButtonEventArgs args) {
ControlDescriptorButton controlDescriptor = (ControlDescriptorButton)ElementDescriptor;

if (controlDescriptor.Command != null) {
_interfaceManager.RunCommand(controlDescriptor.Command);
if (!string.IsNullOrEmpty(controlDescriptor.Command.Value)) {
_interfaceManager.RunCommand(controlDescriptor.Command.AsRaw());
}
}
}
19 changes: 10 additions & 9 deletions OpenDreamClient/Interface/Controls/ControlChild.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using OpenDreamClient.Interface.Descriptors;
using System.Diagnostics.CodeAnalysis;
using OpenDreamClient.Interface.Descriptors;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;

Expand All @@ -23,10 +24,10 @@ protected override Control CreateUIElement() {
protected override void UpdateElementDescriptor() {
base.UpdateElementDescriptor();

var newLeftElement = ChildDescriptor.Left != null && _interfaceManager.Windows.TryGetValue(ChildDescriptor.Left, out var leftWindow)
var newLeftElement = ChildDescriptor.Left.Value != null && _interfaceManager.Windows.TryGetValue(ChildDescriptor.Left.Value, out var leftWindow)
? leftWindow.UIElement
: null;
var newRightElement = ChildDescriptor.Right != null && _interfaceManager.Windows.TryGetValue(ChildDescriptor.Right, out var rightWindow)
var newRightElement = ChildDescriptor.Right.Value != null && _interfaceManager.Windows.TryGetValue(ChildDescriptor.Right.Value, out var rightWindow)
? rightWindow.UIElement
: null;

Expand Down Expand Up @@ -71,27 +72,27 @@ protected override void UpdateElementDescriptor() {
}

public override void Shutdown() {
if (ChildDescriptor.Left != null && _interfaceManager.Windows.TryGetValue(ChildDescriptor.Left, out var left))
if (ChildDescriptor.Left.Value != null && _interfaceManager.Windows.TryGetValue(ChildDescriptor.Left.Value, out var left))
left.Shutdown();
if (ChildDescriptor.Right != null && _interfaceManager.Windows.TryGetValue(ChildDescriptor.Right, out var right))
if (ChildDescriptor.Right.Value != null && _interfaceManager.Windows.TryGetValue(ChildDescriptor.Right.Value, out var right))
right.Shutdown();
}

private void UpdateGrid() {
_grid.Orientation = ChildDescriptor.IsVert
_grid.Orientation = ChildDescriptor.IsVert.Value
? SplitContainer.SplitOrientation.Horizontal
: SplitContainer.SplitOrientation.Vertical;

if (_grid.Size == Vector2.Zero)
return;

_grid.SplitFraction = ChildDescriptor.Splitter / 100f;
_grid.SplitFraction = ChildDescriptor.Splitter.Value / 100f;
}

public override bool TryGetProperty(string property, out string value) {
public override bool TryGetProperty(string property, [NotNullWhen(true)] out DMFProperty? value) {
switch (property) {
case "splitter":
value = $"{_grid.SplitFraction * 100}";
value = new DMFPropertyNum(_grid.SplitFraction * 100);
return true;
default:
return base.TryGetProperty(property, out value);
Expand Down
12 changes: 6 additions & 6 deletions OpenDreamClient/Interface/Controls/ControlInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public void UpdateLabels(string name, string value, string? atomRef) {
_nameText.PushTag(new MarkupNode("font", null, null));
_valueText.PushTag(new MarkupNode("font", null, null));

if (_owner.InfoDescriptor.AllowHtml) {
if (_owner.InfoDescriptor.AllowHtml.Value) {
// TODO: Look into using RobustToolbox's markup parser once it's customizable enough
HtmlParser.Parse(name, _nameText);
HtmlParser.Parse(value, _valueText);
Expand Down Expand Up @@ -219,7 +219,7 @@ protected override Control CreateUIElement() {
}
};

if(ControlDescriptor.IsVisible)
if(ControlDescriptor.IsVisible.Value)
OnShowEvent();
else
OnHideEvent();
Expand Down Expand Up @@ -316,15 +316,15 @@ private void OnSelectionChanged(int tabIndex) {

public void OnShowEvent() {
ControlDescriptorInfo controlDescriptor = (ControlDescriptorInfo)ControlDescriptor;
if (!string.IsNullOrWhiteSpace(controlDescriptor.OnShowCommand)) {
_interfaceManager.RunCommand(controlDescriptor.OnShowCommand);
if (!string.IsNullOrWhiteSpace(controlDescriptor.OnShowCommand.Value)) {
_interfaceManager.RunCommand(controlDescriptor.OnShowCommand.AsRaw());
}
}

public void OnHideEvent() {
ControlDescriptorInfo controlDescriptor = (ControlDescriptorInfo)ControlDescriptor;
if (!string.IsNullOrWhiteSpace(controlDescriptor.OnHideCommand)) {
_interfaceManager.RunCommand(controlDescriptor.OnHideCommand);
if (!string.IsNullOrWhiteSpace(controlDescriptor.OnHideCommand.Value)) {
_interfaceManager.RunCommand(controlDescriptor.OnHideCommand.AsRaw());
}
}
}
Expand Down
9 changes: 5 additions & 4 deletions OpenDreamClient/Interface/Controls/ControlInput.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using OpenDreamClient.Interface.Descriptors;
using System.Diagnostics.CodeAnalysis;
using OpenDreamClient.Interface.Descriptors;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;

Expand All @@ -23,13 +24,13 @@ private void TextBox_OnSubmit(LineEdit.LineEditEventArgs lineEditEventArgs) {
protected override void UpdateElementDescriptor() {
base.UpdateElementDescriptor();
ControlDescriptorInput inputDescriptor = (ControlDescriptorInput)ElementDescriptor;
_textBox.Text = inputDescriptor.Text ?? "";
_textBox.Text = inputDescriptor.Text.AsRaw();
}

public override bool TryGetProperty(string property, out string value) {
public override bool TryGetProperty(string property, [NotNullWhen(true)] out DMFProperty? value) {
switch (property) {
case "text":
value = _textBox.Text;
value = new DMFPropertyString(_textBox.Text);
return true;
default:
return base.TryGetProperty(property, out value);
Expand Down
2 changes: 1 addition & 1 deletion OpenDreamClient/Interface/Controls/ControlLabel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ protected override void UpdateElementDescriptor() {
base.UpdateElementDescriptor();

ControlDescriptorLabel controlDescriptor = (ControlDescriptorLabel)ElementDescriptor;
_label.Text = controlDescriptor.Text;
_label.Text = controlDescriptor.Text.AsRaw();
}
}
16 changes: 8 additions & 8 deletions OpenDreamClient/Interface/Controls/ControlMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public sealed class ControlMap(ControlDescriptor controlDescriptor, ControlWindo
protected override void UpdateElementDescriptor() {
base.UpdateElementDescriptor();

Viewport.StretchMode = MapDescriptor.ZoomMode switch {
Viewport.StretchMode = MapDescriptor.ZoomMode.Value switch {
"blur" => ScalingViewportStretchMode.Bilinear,
"distort" => ScalingViewportStretchMode.Nearest,

Expand All @@ -36,9 +36,9 @@ public void UpdateViewRange(ViewRange view) {
var viewHeight = Math.Max(view.Height, 1);

Viewport.ViewportSize = new Vector2i(viewWidth, viewHeight) * EyeManager.PixelsPerMeter;
if (MapDescriptor.IconSize != 0) {
if (MapDescriptor.IconSize.Value != 0) {
// BYOND supports a negative number here (flips the view), but we're gonna enforce a positive number instead
var iconSize = Math.Max(MapDescriptor.IconSize, 1);
var iconSize = Math.Max(MapDescriptor.IconSize.Value, 1);

Viewport.SetWidth = iconSize * viewWidth;
Viewport.SetHeight = iconSize * viewHeight;
Expand All @@ -60,7 +60,7 @@ protected override Control CreateUIElement() {
OnHideEvent();
}
};
if(ControlDescriptor.IsVisible)
if(ControlDescriptor.IsVisible.Value)
OnShowEvent();
else
OnHideEvent();
Expand All @@ -83,15 +83,15 @@ private void OnViewportKeyBindEvent(GUIBoundKeyEventArgs e) {

public void OnShowEvent() {
ControlDescriptorMap controlDescriptor = (ControlDescriptorMap)ControlDescriptor;
if (!string.IsNullOrWhiteSpace(controlDescriptor.OnShowCommand)) {
_interfaceManager.RunCommand(controlDescriptor.OnShowCommand);
if (!string.IsNullOrWhiteSpace(controlDescriptor.OnShowCommand.Value)) {
_interfaceManager.RunCommand(controlDescriptor.OnShowCommand.AsRaw());
}
}

public void OnHideEvent() {
ControlDescriptorMap controlDescriptor = (ControlDescriptorMap)ControlDescriptor;
if (!string.IsNullOrWhiteSpace(controlDescriptor.OnHideCommand)) {
_interfaceManager.RunCommand(controlDescriptor.OnHideCommand);
if (!string.IsNullOrWhiteSpace(controlDescriptor.OnHideCommand.Value)) {
_interfaceManager.RunCommand(controlDescriptor.OnHideCommand.AsRaw());
}
}
}
9 changes: 5 additions & 4 deletions OpenDreamClient/Interface/Controls/ControlTab.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using OpenDreamClient.Interface.Descriptors;
using Robust.Client.UserInterface;
Expand All @@ -23,8 +24,8 @@ protected override void UpdateElementDescriptor() {

_tabs.Clear();
_tab.RemoveAllChildren();
if (TabDescriptor.Tabs != null) {
var tabIds = TabDescriptor.Tabs.Split(',',
if (TabDescriptor.Tabs.Value != null) {
var tabIds = TabDescriptor.Tabs.Value.Split(',',
StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries);

foreach (var tabId in tabIds) {
Expand All @@ -34,13 +35,13 @@ protected override void UpdateElementDescriptor() {
TabContainer.SetTabTitle(pane.UIElement, pane.Title);
_tab.AddChild(pane.UIElement);
_tabs.Add(pane);
if (TabDescriptor.CurrentTab == pane.Title)
if (TabDescriptor.CurrentTab.Value == pane.Title)
_tab.CurrentTab = pane.UIElement.GetPositionInParent();
}
}
}

public override bool TryGetProperty(string property, out string value) {
public override bool TryGetProperty(string property, [NotNullWhen(true)] out DMFProperty? value) {
switch (property) {
case "current-tab":
var currentTab = _tab.GetChild(_tab.CurrentTab);
Expand Down
Loading
Loading