From 93f636bd5b069a1aa6ac6b2ab8e00a577c2b57d8 Mon Sep 17 00:00:00 2001 From: amy Date: Sat, 15 Jul 2023 17:53:00 +0100 Subject: [PATCH 1/9] start, don't forget to restore defaultinterface --- .../Interface/Controls/ControlBar.cs | 48 +++++++++++++++++++ .../Interface/Controls/ControlWindow.cs | 1 + .../Descriptors/ControlDescriptors.cs | 22 +++++++++ Resources/OpenDream/DefaultInterface.dmf | 17 +++---- 4 files changed, 80 insertions(+), 8 deletions(-) create mode 100644 OpenDreamClient/Interface/Controls/ControlBar.cs diff --git a/OpenDreamClient/Interface/Controls/ControlBar.cs b/OpenDreamClient/Interface/Controls/ControlBar.cs new file mode 100644 index 0000000000..541d15d8cb --- /dev/null +++ b/OpenDreamClient/Interface/Controls/ControlBar.cs @@ -0,0 +1,48 @@ +using OpenDreamClient.Interface.Descriptors; +using Robust.Client.UserInterface; +using Robust.Client.UserInterface.Controls; + +namespace OpenDreamClient.Interface.Controls; + +internal sealed class ControlBar : InterfaceControl { + private ProgressBar? _bar = null; + private Slider? _slider = null; + private BoxContainer? _container; + + public ControlBar(ControlDescriptor controlDescriptor, ControlWindow window) : + base(controlDescriptor, window) { + } + + protected override void UpdateElementDescriptor() { + base.UpdateElementDescriptor(); + ControlDescriptorBar controlDescriptor = (ControlDescriptorBar)ElementDescriptor; + if(controlDescriptor.IsSlider){ + if(_slider is null){ + _slider = new Slider() {MaxValue = 100, MinValue = 0}; + if(_bar is not null){ + _container!.RemoveChild(_bar); + _bar = null; + } + _container!.AddChild(_slider); + } + _slider.Value = controlDescriptor.Value == null ? 0.0f : (float)controlDescriptor.Value; + } + else { + if(_bar is null){ + _bar = new ProgressBar() {MaxValue = 100, MinValue = 0}; + if(_slider is not null){ + _container!.RemoveChild(_slider); + _slider = null; + } + _container!.AddChild(_bar); + } + _bar.Value = controlDescriptor.Value == null ? 0.0f : (float)controlDescriptor.Value; + } + } + + protected override Control CreateUIElement() { + ControlDescriptorBar controlDescriptor = (ControlDescriptorBar)ElementDescriptor; + _container = new BoxContainer() {Orientation = BoxContainer.LayoutOrientation.Vertical}; + return _container; + } +} diff --git a/OpenDreamClient/Interface/Controls/ControlWindow.cs b/OpenDreamClient/Interface/Controls/ControlWindow.cs index 494ad9539c..b4bd194e18 100644 --- a/OpenDreamClient/Interface/Controls/ControlWindow.cs +++ b/OpenDreamClient/Interface/Controls/ControlWindow.cs @@ -190,6 +190,7 @@ public override void AddChild(ElementDescriptor descriptor) { ControlDescriptorLabel => new ControlLabel(controlDescriptor, this), ControlDescriptorGrid => new ControlGrid(controlDescriptor, this), ControlDescriptorTab => new ControlTab(controlDescriptor, this), + ControlDescriptorBar => new ControlBar(controlDescriptor, this), _ => throw new Exception($"Invalid descriptor {controlDescriptor.GetType()}") }; diff --git a/OpenDreamClient/Interface/Descriptors/ControlDescriptors.cs b/OpenDreamClient/Interface/Descriptors/ControlDescriptors.cs index 27b03d2904..2f0d27a386 100644 --- a/OpenDreamClient/Interface/Descriptors/ControlDescriptors.cs +++ b/OpenDreamClient/Interface/Descriptors/ControlDescriptors.cs @@ -76,6 +76,7 @@ public WindowDescriptor() { "LABEL" => typeof(ControlDescriptorLabel), "GRID" => typeof(ControlDescriptorGrid), "TAB" => typeof(ControlDescriptorTab), + "BAR" => typeof(ControlDescriptorBar), _ => null }; @@ -148,3 +149,24 @@ public sealed class ControlDescriptorGrid : ControlDescriptor { public sealed class ControlDescriptorTab : ControlDescriptor { } + +public sealed class ControlDescriptorBar : ControlDescriptor { + [DataField("width")] + public int? Width = 10; //width of the progress bar in pixels. In the default EAST dir, this is more accurately thought of as "height" + [DataField("dir")] + public string? Dir = "east"; //valid values: north/east/south/west/clockwise/cw/counterclockwise/ccw + [DataField("angle1")] + public int? Angle1 = 0; //start angle + [DataField("angle2")] + public int? Angle2 = 180; //end angle + [DataField("bar-color")] + public Color? BarColor = null; //insanely, the default is null which causes the bar not to render regardless of value + [DataField("is-slider")] + public bool IsSlider = false; + [DataField("value")] + public float? Value = 0f; //position of the progress bar + [DataField("on-change")] + public string? OnChange = null; + +} + diff --git a/Resources/OpenDream/DefaultInterface.dmf b/Resources/OpenDream/DefaultInterface.dmf index c56b4178d2..041bde5205 100644 --- a/Resources/OpenDream/DefaultInterface.dmf +++ b/Resources/OpenDream/DefaultInterface.dmf @@ -76,21 +76,22 @@ window "outputwindow" pos = 0,0 size = 640x480 is-pane = true - elem "output" - type = OUTPUT - pos = 0,0 - size = 0x0 - anchor1 = 0,0 - anchor2 = 100,100 - is-default = true elem "input" type = INPUT - pos = 0,460 + pos = 0,440 size = 640x20 anchor1 = 0,100 anchor2 = 100,100 background-color = #d3b5b5 is-default = true + elem "bar" + type = BAR + value = 40 + pos = 0,460 + size = 640x20 + anchor1 = 0,100 + anchor2 = 100,100 + is-slider = true window "statwindow" elem "statwindow" From ff9cf7309cd80085d9d392043ec6f1b0cc8f7e3d Mon Sep 17 00:00:00 2001 From: amy Date: Sat, 15 Jul 2023 23:25:39 +0100 Subject: [PATCH 2/9] basic functionality --- .../Interface/Controls/ControlBar.cs | 37 ++++++++++++++++++- OpenDreamClient/Interface/DreamStylesheet.cs | 10 +++++ Resources/OpenDream/DefaultInterface.dmf | 5 ++- 3 files changed, 48 insertions(+), 4 deletions(-) diff --git a/OpenDreamClient/Interface/Controls/ControlBar.cs b/OpenDreamClient/Interface/Controls/ControlBar.cs index 541d15d8cb..4975d89987 100644 --- a/OpenDreamClient/Interface/Controls/ControlBar.cs +++ b/OpenDreamClient/Interface/Controls/ControlBar.cs @@ -1,4 +1,6 @@ +using OpenDreamClient.Input; using OpenDreamClient.Interface.Descriptors; +using Robust.Client.Graphics; using Robust.Client.UserInterface; using Robust.Client.UserInterface.Controls; @@ -15,10 +17,15 @@ public ControlBar(ControlDescriptor controlDescriptor, ControlWindow window) : protected override void UpdateElementDescriptor() { base.UpdateElementDescriptor(); + //TODO dir + //TODO angles ControlDescriptorBar controlDescriptor = (ControlDescriptorBar)ElementDescriptor; + float bar_width = controlDescriptor.Width != null ? (float)controlDescriptor.Width : 10; + if(bar_width == 0 && this._container is not null) + bar_width = _container.Size.Y; if(controlDescriptor.IsSlider){ if(_slider is null){ - _slider = new Slider() {MaxValue = 100, MinValue = 0}; + _slider = new Slider() {MaxValue = 100, MinValue = 0, Margin=new Thickness(4), HorizontalExpand=true, MinHeight=bar_width}; if(_bar is not null){ _container!.RemoveChild(_bar); _bar = null; @@ -26,23 +33,49 @@ protected override void UpdateElementDescriptor() { _container!.AddChild(_slider); } _slider.Value = controlDescriptor.Value == null ? 0.0f : (float)controlDescriptor.Value; + _slider.OnValueChanged += OnValueChanged; + //TODO grabber color override } else { if(_bar is null){ - _bar = new ProgressBar() {MaxValue = 100, MinValue = 0}; + _bar = new ProgressBar() {MaxValue = 100, MinValue = 0, Margin=new Thickness(4), HorizontalExpand=true, MinHeight=bar_width}; if(_slider is not null){ _container!.RemoveChild(_slider); _slider = null; } _container!.AddChild(_bar); } + if (controlDescriptor.OnChange != null && _bar.Value != controlDescriptor.Value) { + EntitySystem.Get().RunCommand(controlDescriptor.OnChange); + } _bar.Value = controlDescriptor.Value == null ? 0.0f : (float)controlDescriptor.Value; + //_bar.ForegroundStyleBoxOverride = new StyleBoxFlat(Color.Green); TODO + } + } + + private void OnValueChanged(Robust.Client.UserInterface.Controls.Range range) { //todo check if this runs only when you're done (it should for byond parity) + ControlDescriptorBar controlDescriptor = (ControlDescriptorBar)ElementDescriptor; + if (controlDescriptor.OnChange != null) { + EntitySystem.Get().RunCommand(controlDescriptor.OnChange); } } + protected override Control CreateUIElement() { ControlDescriptorBar controlDescriptor = (ControlDescriptorBar)ElementDescriptor; _container = new BoxContainer() {Orientation = BoxContainer.LayoutOrientation.Vertical}; + _container.OnResized += OnContainerResized; return _container; } + + private void OnContainerResized() { + ControlDescriptorBar controlDescriptor = (ControlDescriptorBar)ElementDescriptor; + float bar_width = controlDescriptor.Width != null ? (float)controlDescriptor.Width : 10; + if(bar_width == 0 && this._container is not null) + bar_width = _container.Size.Y; + if(_slider is not null) + _slider.SetHeight=bar_width; + else if (_bar is not null) + _bar.SetHeight=bar_width; + } } diff --git a/OpenDreamClient/Interface/DreamStylesheet.cs b/OpenDreamClient/Interface/DreamStylesheet.cs index 05480d1cbe..25b25c7e01 100644 --- a/OpenDreamClient/Interface/DreamStylesheet.cs +++ b/OpenDreamClient/Interface/DreamStylesheet.cs @@ -171,6 +171,16 @@ public static Stylesheet Make() { }) .Prop("font", notoSansFont10), + //BarControl - composed of ProgressBar and Slider + Element() + .Prop(ProgressBar.StylePropertyBackground, new StyleBoxFlat { BackgroundColor = Color.White, BorderThickness = new Thickness(1), BorderColor = Color.Black}) + .Prop(ProgressBar.StylePropertyForeground, new StyleBoxFlat { BackgroundColor = Color.Green, BorderThickness = new Thickness(1), BorderColor = Color.Black}), + Element() + .Prop(Slider.StylePropertyBackground, new StyleBoxFlat { BackgroundColor = Color.White, BorderThickness = new Thickness(1), BorderColor = Color.Black}) + .Prop(Slider.StylePropertyForeground, new StyleBoxFlat { BackgroundColor = Color.Green, BorderThickness = new Thickness(1), BorderColor = Color.Black}) + .Prop(Slider.StylePropertyGrabber, new StyleBoxFlat { BackgroundColor = Color.Red, BorderThickness = new Thickness(1), BorderColor = Color.Black}) + .Prop(Slider.StylePropertyFill, new StyleBoxFlat { BackgroundColor = Color.Blue, BorderThickness = new Thickness(1), BorderColor = Color.Black}), + }); } } diff --git a/Resources/OpenDream/DefaultInterface.dmf b/Resources/OpenDream/DefaultInterface.dmf index 041bde5205..c166ac1418 100644 --- a/Resources/OpenDream/DefaultInterface.dmf +++ b/Resources/OpenDream/DefaultInterface.dmf @@ -87,8 +87,9 @@ window "outputwindow" elem "bar" type = BAR value = 40 - pos = 0,460 - size = 640x20 + pos = 0,0 + size = 0x0 + width=50 anchor1 = 0,100 anchor2 = 100,100 is-slider = true From 112d0a22ef01c88450c5f6868d7cda833a18f090 Mon Sep 17 00:00:00 2001 From: amy Date: Sun, 16 Jul 2023 12:50:06 +0100 Subject: [PATCH 3/9] finish --- .../Interface/Controls/ControlBar.cs | 83 ++++++++++++------- OpenDreamClient/Interface/DreamStylesheet.cs | 12 +-- Resources/OpenDream/DefaultInterface.dmf | 18 ++-- 3 files changed, 65 insertions(+), 48 deletions(-) diff --git a/OpenDreamClient/Interface/Controls/ControlBar.cs b/OpenDreamClient/Interface/Controls/ControlBar.cs index 4975d89987..3185c4ec29 100644 --- a/OpenDreamClient/Interface/Controls/ControlBar.cs +++ b/OpenDreamClient/Interface/Controls/ControlBar.cs @@ -17,12 +17,37 @@ public ControlBar(ControlDescriptor controlDescriptor, ControlWindow window) : protected override void UpdateElementDescriptor() { base.UpdateElementDescriptor(); - //TODO dir - //TODO angles + OnContainerResized(); //most of the actual logic needs to go here anyway, so lets just shove it all in there + } + + private void OnValueChanged(Robust.Client.UserInterface.Controls.Range range) { + if(_slider is not null && _slider.Grabbed) //don't run while you're still sliding, only after + return; + ControlDescriptorBar controlDescriptor = (ControlDescriptorBar)ElementDescriptor; + if (controlDescriptor.OnChange != null) { + EntitySystem.Get().RunCommand(controlDescriptor.OnChange); + } + } + + + protected override Control CreateUIElement() { ControlDescriptorBar controlDescriptor = (ControlDescriptorBar)ElementDescriptor; + _container = new BoxContainer() {Orientation = BoxContainer.LayoutOrientation.Vertical}; + _container.OnResized += OnContainerResized; + return _container; + } + + private void OnContainerResized() { + ControlDescriptorBar controlDescriptor = (ControlDescriptorBar)ElementDescriptor; + //TODO dir - these both need RT level changes + //TODO angles + + //width float bar_width = controlDescriptor.Width != null ? (float)controlDescriptor.Width : 10; if(bar_width == 0 && this._container is not null) bar_width = _container.Size.Y; + + //is-slider if(controlDescriptor.IsSlider){ if(_slider is null){ _slider = new Slider() {MaxValue = 100, MinValue = 0, Margin=new Thickness(4), HorizontalExpand=true, MinHeight=bar_width}; @@ -31,12 +56,22 @@ protected override void UpdateElementDescriptor() { _bar = null; } _container!.AddChild(_slider); + } else { + _slider.SetHeight=bar_width; } + + //value _slider.Value = controlDescriptor.Value == null ? 0.0f : (float)controlDescriptor.Value; + //on-change _slider.OnValueChanged += OnValueChanged; - //TODO grabber color override - } - else { + //bar-color + _slider.TryGetStyleProperty(Slider.StylePropertyGrabber, out var box); + if(box is not null){ + StyleBoxFlat boxflat = (StyleBoxFlat) box; + boxflat.BackgroundColor = controlDescriptor.BarColor is null ? Color.Transparent : controlDescriptor.BarColor.Value; + _slider.GrabberStyleBoxOverride = boxflat; + } + } else { if(_bar is null){ _bar = new ProgressBar() {MaxValue = 100, MinValue = 0, Margin=new Thickness(4), HorizontalExpand=true, MinHeight=bar_width}; if(_slider is not null){ @@ -44,38 +79,22 @@ protected override void UpdateElementDescriptor() { _slider = null; } _container!.AddChild(_bar); + } else { + _bar.SetHeight=bar_width; } + //on-change if (controlDescriptor.OnChange != null && _bar.Value != controlDescriptor.Value) { EntitySystem.Get().RunCommand(controlDescriptor.OnChange); } + //bar-color + _bar.TryGetStyleProperty(ProgressBar.StylePropertyForeground , out var box); + if(box is not null){ + StyleBoxFlat boxflat = (StyleBoxFlat) box; + boxflat.BackgroundColor = controlDescriptor.BarColor is null ? Color.Transparent : controlDescriptor.BarColor.Value; + _bar.ForegroundStyleBoxOverride = boxflat; + } + //value _bar.Value = controlDescriptor.Value == null ? 0.0f : (float)controlDescriptor.Value; - //_bar.ForegroundStyleBoxOverride = new StyleBoxFlat(Color.Green); TODO - } - } - - private void OnValueChanged(Robust.Client.UserInterface.Controls.Range range) { //todo check if this runs only when you're done (it should for byond parity) - ControlDescriptorBar controlDescriptor = (ControlDescriptorBar)ElementDescriptor; - if (controlDescriptor.OnChange != null) { - EntitySystem.Get().RunCommand(controlDescriptor.OnChange); } } - - - protected override Control CreateUIElement() { - ControlDescriptorBar controlDescriptor = (ControlDescriptorBar)ElementDescriptor; - _container = new BoxContainer() {Orientation = BoxContainer.LayoutOrientation.Vertical}; - _container.OnResized += OnContainerResized; - return _container; - } - - private void OnContainerResized() { - ControlDescriptorBar controlDescriptor = (ControlDescriptorBar)ElementDescriptor; - float bar_width = controlDescriptor.Width != null ? (float)controlDescriptor.Width : 10; - if(bar_width == 0 && this._container is not null) - bar_width = _container.Size.Y; - if(_slider is not null) - _slider.SetHeight=bar_width; - else if (_bar is not null) - _bar.SetHeight=bar_width; - } } diff --git a/OpenDreamClient/Interface/DreamStylesheet.cs b/OpenDreamClient/Interface/DreamStylesheet.cs index 25b25c7e01..94438a55b5 100644 --- a/OpenDreamClient/Interface/DreamStylesheet.cs +++ b/OpenDreamClient/Interface/DreamStylesheet.cs @@ -173,13 +173,13 @@ public static Stylesheet Make() { //BarControl - composed of ProgressBar and Slider Element() - .Prop(ProgressBar.StylePropertyBackground, new StyleBoxFlat { BackgroundColor = Color.White, BorderThickness = new Thickness(1), BorderColor = Color.Black}) - .Prop(ProgressBar.StylePropertyForeground, new StyleBoxFlat { BackgroundColor = Color.Green, BorderThickness = new Thickness(1), BorderColor = Color.Black}), + .Prop(ProgressBar.StylePropertyBackground, new StyleBoxFlat { BackgroundColor = Color.LightGray, BorderThickness = new Thickness(1), BorderColor = Color.Black}) + .Prop(ProgressBar.StylePropertyForeground, new StyleBoxFlat { BackgroundColor = Color.Transparent, BorderThickness = new Thickness(1), BorderColor = Color.Black}), Element() - .Prop(Slider.StylePropertyBackground, new StyleBoxFlat { BackgroundColor = Color.White, BorderThickness = new Thickness(1), BorderColor = Color.Black}) - .Prop(Slider.StylePropertyForeground, new StyleBoxFlat { BackgroundColor = Color.Green, BorderThickness = new Thickness(1), BorderColor = Color.Black}) - .Prop(Slider.StylePropertyGrabber, new StyleBoxFlat { BackgroundColor = Color.Red, BorderThickness = new Thickness(1), BorderColor = Color.Black}) - .Prop(Slider.StylePropertyFill, new StyleBoxFlat { BackgroundColor = Color.Blue, BorderThickness = new Thickness(1), BorderColor = Color.Black}), + .Prop(Slider.StylePropertyBackground, new StyleBoxFlat { BackgroundColor = Color.Transparent, BorderThickness = new Thickness(1), BorderColor = Color.Black}) + .Prop(Slider.StylePropertyForeground, new StyleBoxFlat { BackgroundColor = Color.LightGray, BorderThickness = new Thickness(1), BorderColor = Color.Black}) + .Prop(Slider.StylePropertyGrabber, new StyleBoxFlat { BackgroundColor = Color.Transparent, BorderThickness = new Thickness(1), BorderColor = Color.Black, ContentMarginLeftOverride=10, ContentMarginRightOverride=10}) + .Prop(Slider.StylePropertyFill, new StyleBoxFlat { BackgroundColor = Color.Transparent, BorderThickness = new Thickness(0), BorderColor = Color.Black}), }); } diff --git a/Resources/OpenDream/DefaultInterface.dmf b/Resources/OpenDream/DefaultInterface.dmf index c166ac1418..c56b4178d2 100644 --- a/Resources/OpenDream/DefaultInterface.dmf +++ b/Resources/OpenDream/DefaultInterface.dmf @@ -76,23 +76,21 @@ window "outputwindow" pos = 0,0 size = 640x480 is-pane = true + elem "output" + type = OUTPUT + pos = 0,0 + size = 0x0 + anchor1 = 0,0 + anchor2 = 100,100 + is-default = true elem "input" type = INPUT - pos = 0,440 + pos = 0,460 size = 640x20 anchor1 = 0,100 anchor2 = 100,100 background-color = #d3b5b5 is-default = true - elem "bar" - type = BAR - value = 40 - pos = 0,0 - size = 0x0 - width=50 - anchor1 = 0,100 - anchor2 = 100,100 - is-slider = true window "statwindow" elem "statwindow" From 41adeab35e704746828b3095360ff0508dd6d666 Mon Sep 17 00:00:00 2001 From: amylizzle Date: Sun, 24 Sep 2023 11:22:17 +0100 Subject: [PATCH 4/9] well that was an easy fix --- OpenDreamClient/Interface/Descriptors/ControlDescriptors.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OpenDreamClient/Interface/Descriptors/ControlDescriptors.cs b/OpenDreamClient/Interface/Descriptors/ControlDescriptors.cs index 0f2beb7797..88463dc2a6 100644 --- a/OpenDreamClient/Interface/Descriptors/ControlDescriptors.cs +++ b/OpenDreamClient/Interface/Descriptors/ControlDescriptors.cs @@ -156,7 +156,7 @@ public sealed partial class ControlDescriptorTab : ControlDescriptor { } -public sealed class ControlDescriptorBar : ControlDescriptor { +public sealed partial class ControlDescriptorBar : ControlDescriptor { [DataField("width")] public int? Width = 10; //width of the progress bar in pixels. In the default EAST dir, this is more accurately thought of as "height" [DataField("dir")] From 438f75821017f60702077cd2b4002ef27f98464d Mon Sep 17 00:00:00 2001 From: amylizzle Date: Sun, 3 Dec 2023 11:19:10 +0000 Subject: [PATCH 5/9] fix --- OpenDreamClient/Interface/Controls/ControlBar.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/OpenDreamClient/Interface/Controls/ControlBar.cs b/OpenDreamClient/Interface/Controls/ControlBar.cs index 3185c4ec29..2e3d4d6947 100644 --- a/OpenDreamClient/Interface/Controls/ControlBar.cs +++ b/OpenDreamClient/Interface/Controls/ControlBar.cs @@ -25,7 +25,7 @@ private void OnValueChanged(Robust.Client.UserInterface.Controls.Range range) { return; ControlDescriptorBar controlDescriptor = (ControlDescriptorBar)ElementDescriptor; if (controlDescriptor.OnChange != null) { - EntitySystem.Get().RunCommand(controlDescriptor.OnChange); + _interfaceManager.RunCommand(controlDescriptor.OnChange); } } @@ -84,7 +84,7 @@ private void OnContainerResized() { } //on-change if (controlDescriptor.OnChange != null && _bar.Value != controlDescriptor.Value) { - EntitySystem.Get().RunCommand(controlDescriptor.OnChange); + _interfaceManager.RunCommand(controlDescriptor.OnChange); } //bar-color _bar.TryGetStyleProperty(ProgressBar.StylePropertyForeground , out var box); From 91bc01199f69a6af224158ce1e364956d4bc4f5e Mon Sep 17 00:00:00 2001 From: wixoaGit Date: Sat, 9 Dec 2023 15:42:18 -0500 Subject: [PATCH 6/9] Some code quality --- .../Interface/Controls/ControlBar.cs | 87 +++++++++++-------- 1 file changed, 51 insertions(+), 36 deletions(-) diff --git a/OpenDreamClient/Interface/Controls/ControlBar.cs b/OpenDreamClient/Interface/Controls/ControlBar.cs index 2e3d4d6947..d924830a8c 100644 --- a/OpenDreamClient/Interface/Controls/ControlBar.cs +++ b/OpenDreamClient/Interface/Controls/ControlBar.cs @@ -1,4 +1,3 @@ -using OpenDreamClient.Input; using OpenDreamClient.Interface.Descriptors; using Robust.Client.Graphics; using Robust.Client.UserInterface; @@ -7,12 +6,11 @@ namespace OpenDreamClient.Interface.Controls; internal sealed class ControlBar : InterfaceControl { - private ProgressBar? _bar = null; - private Slider? _slider = null; - private BoxContainer? _container; + private ProgressBar? _bar; + private Slider? _slider; + private BoxContainer _container = default!; // Created by base constructor - public ControlBar(ControlDescriptor controlDescriptor, ControlWindow window) : - base(controlDescriptor, window) { + public ControlBar(ControlDescriptor controlDescriptor, ControlWindow window) : base(controlDescriptor, window) { } protected override void UpdateElementDescriptor() { @@ -21,8 +19,9 @@ protected override void UpdateElementDescriptor() { } private void OnValueChanged(Robust.Client.UserInterface.Controls.Range range) { - if(_slider is not null && _slider.Grabbed) //don't run while you're still sliding, only after + if (_slider is not null && _slider.Grabbed) //don't run while you're still sliding, only after return; + ControlDescriptorBar controlDescriptor = (ControlDescriptorBar)ElementDescriptor; if (controlDescriptor.OnChange != null) { _interfaceManager.RunCommand(controlDescriptor.OnChange); @@ -31,8 +30,7 @@ private void OnValueChanged(Robust.Client.UserInterface.Controls.Range range) { protected override Control CreateUIElement() { - ControlDescriptorBar controlDescriptor = (ControlDescriptorBar)ElementDescriptor; - _container = new BoxContainer() {Orientation = BoxContainer.LayoutOrientation.Vertical}; + _container = new BoxContainer { Orientation = BoxContainer.LayoutOrientation.Vertical }; _container.OnResized += OnContainerResized; return _container; } @@ -43,58 +41,75 @@ private void OnContainerResized() { //TODO angles //width - float bar_width = controlDescriptor.Width != null ? (float)controlDescriptor.Width : 10; - if(bar_width == 0 && this._container is not null) - bar_width = _container.Size.Y; + float barWidth = controlDescriptor.Width ?? 10f; + if (barWidth == 0) + barWidth = _container.Size.Y; //is-slider - if(controlDescriptor.IsSlider){ - if(_slider is null){ - _slider = new Slider() {MaxValue = 100, MinValue = 0, Margin=new Thickness(4), HorizontalExpand=true, MinHeight=bar_width}; - if(_bar is not null){ - _container!.RemoveChild(_bar); + if (controlDescriptor.IsSlider) { + if (_slider is null) { + _slider = new Slider { + MaxValue = 100, + MinValue = 0, + Margin = new Thickness(4), + HorizontalExpand = true, + MinHeight = barWidth + }; + + if (_bar is not null) { + _container.RemoveChild(_bar); _bar = null; } - _container!.AddChild(_slider); + + _container.AddChild(_slider); } else { - _slider.SetHeight=bar_width; + _slider.SetHeight = barWidth; } //value - _slider.Value = controlDescriptor.Value == null ? 0.0f : (float)controlDescriptor.Value; + _slider.Value = controlDescriptor.Value ?? 0.0f; //on-change _slider.OnValueChanged += OnValueChanged; //bar-color _slider.TryGetStyleProperty(Slider.StylePropertyGrabber, out var box); - if(box is not null){ - StyleBoxFlat boxflat = (StyleBoxFlat) box; - boxflat.BackgroundColor = controlDescriptor.BarColor is null ? Color.Transparent : controlDescriptor.BarColor.Value; - _slider.GrabberStyleBoxOverride = boxflat; + if (box is not null) { + StyleBoxFlat boxFlat = (StyleBoxFlat)box; + boxFlat.BackgroundColor = controlDescriptor.BarColor ?? Color.Transparent; + _slider.GrabberStyleBoxOverride = boxFlat; } } else { - if(_bar is null){ - _bar = new ProgressBar() {MaxValue = 100, MinValue = 0, Margin=new Thickness(4), HorizontalExpand=true, MinHeight=bar_width}; - if(_slider is not null){ - _container!.RemoveChild(_slider); + if (_bar is null) { + _bar = new ProgressBar { + MaxValue = 100, + MinValue = 0, + Margin = new Thickness(4), + HorizontalExpand = true, + MinHeight = barWidth + }; + + if (_slider is not null) { + _container.RemoveChild(_slider); _slider = null; } - _container!.AddChild(_bar); + + _container.AddChild(_bar); } else { - _bar.SetHeight=bar_width; + _bar.SetHeight = barWidth; } + //on-change if (controlDescriptor.OnChange != null && _bar.Value != controlDescriptor.Value) { _interfaceManager.RunCommand(controlDescriptor.OnChange); } + //bar-color - _bar.TryGetStyleProperty(ProgressBar.StylePropertyForeground , out var box); - if(box is not null){ - StyleBoxFlat boxflat = (StyleBoxFlat) box; - boxflat.BackgroundColor = controlDescriptor.BarColor is null ? Color.Transparent : controlDescriptor.BarColor.Value; - _bar.ForegroundStyleBoxOverride = boxflat; + if (_bar.TryGetStyleProperty(ProgressBar.StylePropertyForeground, out var box)) { + box.BackgroundColor = controlDescriptor.BarColor ?? Color.Transparent; + _bar.ForegroundStyleBoxOverride = box; } + //value - _bar.Value = controlDescriptor.Value == null ? 0.0f : (float)controlDescriptor.Value; + _bar.Value = controlDescriptor.Value ?? 0.0f; } } } From 2a4cd362926b6523c9b51b034a392446a6b902b0 Mon Sep 17 00:00:00 2001 From: wixoaGit Date: Sat, 9 Dec 2023 16:12:55 -0500 Subject: [PATCH 7/9] Use `VerticalExpand` instead of the resize event --- .../Interface/Controls/ControlBar.cs | 81 ++++++++----------- 1 file changed, 34 insertions(+), 47 deletions(-) diff --git a/OpenDreamClient/Interface/Controls/ControlBar.cs b/OpenDreamClient/Interface/Controls/ControlBar.cs index d924830a8c..9287d0ef02 100644 --- a/OpenDreamClient/Interface/Controls/ControlBar.cs +++ b/OpenDreamClient/Interface/Controls/ControlBar.cs @@ -10,52 +10,35 @@ internal sealed class ControlBar : InterfaceControl { private Slider? _slider; private BoxContainer _container = default!; // Created by base constructor + private ControlDescriptorBar BarDescriptor => (ControlDescriptorBar)ElementDescriptor; + public ControlBar(ControlDescriptor controlDescriptor, ControlWindow window) : base(controlDescriptor, window) { } protected override void UpdateElementDescriptor() { base.UpdateElementDescriptor(); - OnContainerResized(); //most of the actual logic needs to go here anyway, so lets just shove it all in there - } - - private void OnValueChanged(Robust.Client.UserInterface.Controls.Range range) { - if (_slider is not null && _slider.Grabbed) //don't run while you're still sliding, only after - return; - - ControlDescriptorBar controlDescriptor = (ControlDescriptorBar)ElementDescriptor; - if (controlDescriptor.OnChange != null) { - _interfaceManager.RunCommand(controlDescriptor.OnChange); - } - } - - protected override Control CreateUIElement() { - _container = new BoxContainer { Orientation = BoxContainer.LayoutOrientation.Vertical }; - _container.OnResized += OnContainerResized; - return _container; - } + //width + float barWidth = BarDescriptor.Width ?? 10f; - private void OnContainerResized() { - ControlDescriptorBar controlDescriptor = (ControlDescriptorBar)ElementDescriptor; //TODO dir - these both need RT level changes //TODO angles - //width - float barWidth = controlDescriptor.Width ?? 10f; - if (barWidth == 0) - barWidth = _container.Size.Y; - //is-slider - if (controlDescriptor.IsSlider) { + if (BarDescriptor.IsSlider) { if (_slider is null) { _slider = new Slider { MaxValue = 100, MinValue = 0, Margin = new Thickness(4), HorizontalExpand = true, - MinHeight = barWidth + VerticalExpand = (barWidth == 0f), + MinHeight = barWidth, + Value = BarDescriptor.Value ?? 0.0f }; + _slider.OnValueChanged += OnValueChanged; + if (_bar is not null) { _container.RemoveChild(_bar); _bar = null; @@ -63,19 +46,13 @@ private void OnContainerResized() { _container.AddChild(_slider); } else { - _slider.SetHeight = barWidth; + _slider.Value = BarDescriptor.Value ?? 0.0f; } - //value - _slider.Value = controlDescriptor.Value ?? 0.0f; - //on-change - _slider.OnValueChanged += OnValueChanged; //bar-color - _slider.TryGetStyleProperty(Slider.StylePropertyGrabber, out var box); - if (box is not null) { - StyleBoxFlat boxFlat = (StyleBoxFlat)box; - boxFlat.BackgroundColor = controlDescriptor.BarColor ?? Color.Transparent; - _slider.GrabberStyleBoxOverride = boxFlat; + if (_slider.TryGetStyleProperty(Slider.StylePropertyGrabber, out var box)) { + box.BackgroundColor = BarDescriptor.BarColor ?? Color.Transparent; + _slider.GrabberStyleBoxOverride = box; } } else { if (_bar is null) { @@ -84,9 +61,13 @@ private void OnContainerResized() { MinValue = 0, Margin = new Thickness(4), HorizontalExpand = true, - MinHeight = barWidth + VerticalExpand = (barWidth == 0f), + MinHeight = barWidth, + Value = BarDescriptor.Value ?? 0.0f }; + _bar.OnValueChanged += OnValueChanged; + if (_slider is not null) { _container.RemoveChild(_slider); _slider = null; @@ -94,22 +75,28 @@ private void OnContainerResized() { _container.AddChild(_bar); } else { - _bar.SetHeight = barWidth; - } - - //on-change - if (controlDescriptor.OnChange != null && _bar.Value != controlDescriptor.Value) { - _interfaceManager.RunCommand(controlDescriptor.OnChange); + _bar.Value = BarDescriptor.Value ?? 0.0f; } //bar-color if (_bar.TryGetStyleProperty(ProgressBar.StylePropertyForeground, out var box)) { - box.BackgroundColor = controlDescriptor.BarColor ?? Color.Transparent; + box.BackgroundColor = BarDescriptor.BarColor ?? Color.Transparent; _bar.ForegroundStyleBoxOverride = box; } + } + } + + private void OnValueChanged(Robust.Client.UserInterface.Controls.Range range) { + if (_slider is not null && _slider.Grabbed) //don't run while you're still sliding, only after + return; - //value - _bar.Value = controlDescriptor.Value ?? 0.0f; + if (BarDescriptor.OnChange != null) { + _interfaceManager.RunCommand(BarDescriptor.OnChange); } } + + protected override Control CreateUIElement() { + _container = new BoxContainer { Orientation = BoxContainer.LayoutOrientation.Vertical }; + return _container; + } } From 7988aeb2166535c8ca6f479bfe543cd94efcb098 Mon Sep 17 00:00:00 2001 From: wixoaGit Date: Sat, 9 Dec 2023 16:14:43 -0500 Subject: [PATCH 8/9] Use `Control` instead of `BoxContainer` We're not laying out multiple controls, no need for a container --- OpenDreamClient/Interface/Controls/ControlBar.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/OpenDreamClient/Interface/Controls/ControlBar.cs b/OpenDreamClient/Interface/Controls/ControlBar.cs index 9287d0ef02..563f9f96a0 100644 --- a/OpenDreamClient/Interface/Controls/ControlBar.cs +++ b/OpenDreamClient/Interface/Controls/ControlBar.cs @@ -8,7 +8,7 @@ namespace OpenDreamClient.Interface.Controls; internal sealed class ControlBar : InterfaceControl { private ProgressBar? _bar; private Slider? _slider; - private BoxContainer _container = default!; // Created by base constructor + private Control _container = default!; // Created by base constructor private ControlDescriptorBar BarDescriptor => (ControlDescriptorBar)ElementDescriptor; @@ -96,7 +96,7 @@ private void OnValueChanged(Robust.Client.UserInterface.Controls.Range range) { } protected override Control CreateUIElement() { - _container = new BoxContainer { Orientation = BoxContainer.LayoutOrientation.Vertical }; + _container = new Control(); return _container; } } From acbab89f8b514441b86ffcbaf84dc3b49493fa2e Mon Sep 17 00:00:00 2001 From: wixoaGit Date: Sat, 9 Dec 2023 16:59:08 -0500 Subject: [PATCH 9/9] Replace `[[*]]` in `on-change` --- OpenDreamClient/Interface/Controls/ControlBar.cs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/OpenDreamClient/Interface/Controls/ControlBar.cs b/OpenDreamClient/Interface/Controls/ControlBar.cs index 563f9f96a0..148a7cc2eb 100644 --- a/OpenDreamClient/Interface/Controls/ControlBar.cs +++ b/OpenDreamClient/Interface/Controls/ControlBar.cs @@ -1,3 +1,4 @@ +using System.Globalization; using OpenDreamClient.Interface.Descriptors; using Robust.Client.Graphics; using Robust.Client.UserInterface; @@ -87,11 +88,16 @@ protected override void UpdateElementDescriptor() { } private void OnValueChanged(Robust.Client.UserInterface.Controls.Range range) { - if (_slider is not null && _slider.Grabbed) //don't run while you're still sliding, only after - return; + //don't run while you're still sliding, only after + // TODO: RT doesn't update Grabbed until after OnValueChanged, fix that + //if (_slider is not null && _slider.Grabbed) + // return; if (BarDescriptor.OnChange != null) { - _interfaceManager.RunCommand(BarDescriptor.OnChange); + var valueReplaced = + BarDescriptor.OnChange.Replace("[[*]]", range.Value.ToString(CultureInfo.InvariantCulture)); + + _interfaceManager.RunCommand(valueReplaced); } }