forked from space-wizards/space-station-14
-
Notifications
You must be signed in to change notification settings - Fork 154
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
eceb3c8
commit 357ec46
Showing
9 changed files
with
275 additions
and
2 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
Content.Client/SS220/SuperMatterCrystalUIs/SuperMatterObserverBUI.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
namespace Content.Client.SS220.SuperMatterCrystalUIs; | ||
|
||
public sealed class SuperMatterObserverBUI : BoundUserInterface | ||
{ | ||
[ViewVariables] | ||
private SuperMatterObserverMenu? _menu; | ||
|
||
public SuperMatterObserverBUI(EntityUid owner, Enum uiKey) : base(owner, uiKey) { } | ||
protected override void Open() | ||
{ | ||
base.Open(); | ||
|
||
_menu = new SuperMatterObserverMenu(); | ||
_menu.OnClose += Close; | ||
_menu.OpenCentered(); | ||
} | ||
protected override void UpdateState(BoundUserInterfaceState state) | ||
{ | ||
base.UpdateState(state); | ||
|
||
_menu?.UpdateState(); | ||
} | ||
protected override void Dispose(bool disposing) | ||
{ | ||
base.Dispose(disposing); | ||
if (!disposing) | ||
return; | ||
_menu?.Close(); | ||
_menu?.Dispose(); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
Content.Client/SS220/SuperMatterCrystalUIs/SuperMatterObserverMenu.xaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<controls:FancyWindow | ||
xmlns="https://spacestation14.io" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:plot="clr-namespace:Content.Client.SS220.UserInterface.PlotFigure" | ||
xmlns:controls="clr-namespace:Content.Client.UserInterface.Controls" | ||
Title="{Loc 'apc-menu-title'}" | ||
Resizable="False" | ||
MinSize="512 512" | ||
SetSize="512 512"> | ||
<BoxContainer Orientation="Vertical"> | ||
<plot:Plot2DTimeView Name="PlotView2D" MinHeight="256" MouseFilter="Stop" Margin="8 8" /> | ||
</BoxContainer> | ||
</controls:FancyWindow> |
29 changes: 29 additions & 0 deletions
29
Content.Client/SS220/SuperMatterCrystalUIs/SuperMatterObserverMenu.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using FancyWindow = Content.Client.UserInterface.Controls.FancyWindow; | ||
using System.Numerics; | ||
using Robust.Client.AutoGenerated; | ||
using Robust.Client.UserInterface.XAML; | ||
using Robust.Shared.Timing; | ||
|
||
namespace Content.Client.SS220.SuperMatterCrystalUIs; | ||
|
||
[GenerateTypedNameReferences] | ||
public sealed partial class SuperMatterObserverMenu : FancyWindow | ||
{ | ||
private int counter = 0; | ||
public SuperMatterObserverMenu() | ||
{ | ||
IoCManager.InjectDependencies(this); | ||
RobustXamlLoader.Load(this); | ||
PlotView2D.SetXLabel("t, с"); | ||
PlotView2D.SetYLabel("u, эрг"); | ||
} | ||
public void UpdateState() | ||
{ | ||
// PlotView2D.AddPointToPlot(new Vector2(counter++, counter++)); | ||
} | ||
protected override void FrameUpdate(FrameEventArgs args) | ||
{ | ||
base.FrameUpdate(args); | ||
PlotView2D.AddPointToPlot(new Vector2(counter++, counter++)); | ||
} | ||
} |
95 changes: 95 additions & 0 deletions
95
Content.Client/SS220/UserInterface/PlotFigure/Plot2DTimeView.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
using Content.Client.Resources; | ||
using Robust.Client.ResourceManagement; | ||
using Robust.Client.UserInterface; | ||
using Robust.Client.Graphics; | ||
using System.Numerics; | ||
|
||
namespace Content.Client.SS220.UserInterface.PlotFigure; | ||
|
||
internal sealed class Plot2DTimeView : Control | ||
{ | ||
[Dependency] private readonly IResourceCache _cache = default!; | ||
private Plot2DTimePoints _plotPoints; | ||
private const int SerifSize = 5; | ||
private const int FontSize = 12; | ||
private readonly List<float> _steps = new() { 0.2f, 0.4f, 0.6f, 0.8f }; | ||
private readonly Font _font; | ||
private const int AxisBorderPosition = 20; | ||
public Plot2DTimeView() | ||
{ | ||
RectClipContent = true; | ||
IoCManager.InjectDependencies(this); | ||
_plotPoints = new Plot2DTimePoints(128); | ||
|
||
_font = _cache.GetFont("/Fonts/NotoSans/NotoSans-Regular.ttf", FontSize); | ||
} | ||
public void LoadPlot2DTimePoints(Plot2DTimePoints plotPoints) | ||
{ | ||
_plotPoints = plotPoints; | ||
} | ||
public void AddPointToPlot(Vector2 point) | ||
{ | ||
_plotPoints.AddPoint(point); | ||
} | ||
public void SetXLabel(string label) => _plotPoints.XLabel = label; | ||
public void SetYLabel(string label) => _plotPoints.YLabel = label; | ||
|
||
protected override void Draw(DrawingHandleScreen handle) | ||
{ | ||
if (_plotPoints == null) | ||
return; | ||
if (_plotPoints.Point2Ds == null) | ||
return; | ||
if (!_plotPoints.TryGetDeltaBetweenMaxMinX(out var xWidth)) | ||
return; | ||
if (!_plotPoints.TryGetMaxY(out var yMax)) | ||
return; | ||
if (!(PixelWidth - AxisBorderPosition > 0)) | ||
return; | ||
|
||
var yMaxResult = (yMax + 0.1f) * 1.1f ?? 0.1f; | ||
var xWidthResult = xWidth ?? 1f; | ||
var deltaXWidth = (PixelWidth - (float) AxisBorderPosition) / _plotPoints.Point2Ds.Count; | ||
var yNormalizer = PixelHeight / yMaxResult; | ||
|
||
var point2Ds = _plotPoints.Point2Ds; | ||
for (var i = 1; i < point2Ds.Count; i++) | ||
{ | ||
var firstPoint = CorrectVector(deltaXWidth * (i - 1) + AxisBorderPosition, point2Ds[i - 1].Y * yNormalizer); | ||
var secondPoint = CorrectVector(deltaXWidth * i + AxisBorderPosition, point2Ds[i].Y * yNormalizer); | ||
|
||
handle.DrawLine(firstPoint, secondPoint, Color.Black); | ||
} | ||
//Draw axis here to draw it on top of other | ||
DrawAxis(handle, yMaxResult, xWidthResult); | ||
} | ||
private void DrawAxis(DrawingHandleScreen handle, float maxY, float xWidth) | ||
{ | ||
|
||
//start with drawing axises | ||
handle.DrawLine(CorrectVector(AxisBorderPosition, AxisBorderPosition), CorrectVector(PixelWidth, AxisBorderPosition), Color.Black); | ||
handle.DrawLine(CorrectVector(AxisBorderPosition, AxisBorderPosition), CorrectVector(AxisBorderPosition, PixelHeight), Color.Black); | ||
foreach (var step in _steps) | ||
{ | ||
// X | ||
handle.DrawLine(CorrectVector(PixelWidth * step + AxisBorderPosition, AxisBorderPosition), | ||
CorrectVector(PixelWidth * step + AxisBorderPosition, AxisBorderPosition + SerifSize), Color.Black); | ||
handle.DrawString(_font, CorrectVector(PixelWidth * step, AxisBorderPosition), $"{step * xWidth - xWidth:0.}"); | ||
// Y | ||
handle.DrawLine(CorrectVector(AxisBorderPosition, PixelHeight * step), | ||
CorrectVector(AxisBorderPosition + SerifSize, PixelHeight * step), Color.Black); | ||
handle.DrawString(_font, CorrectVector(AxisBorderPosition + SerifSize, PixelHeight * step), $"{step * maxY:0.}"); | ||
} | ||
handle.DrawString(_font, CorrectVector(AxisBorderPosition + 2 * SerifSize, AxisBorderPosition), $"{-xWidth:0.}"); | ||
// here goes labels | ||
handle.DrawString(_font, CorrectVector(AxisBorderPosition + SerifSize, PixelHeight), $"{_plotPoints.YLabel}"); | ||
if (_plotPoints.XLabel != null) | ||
handle.DrawString(_font, CorrectVector(PixelWidth - _plotPoints.XLabel.Length * FontSize, AxisBorderPosition), $"{_plotPoints.XLabel}"); | ||
} | ||
private Vector2 CorrectVector(float x, float y) | ||
{ | ||
var newX = Math.Clamp(x, 1f, PixelWidth); | ||
var newY = Math.Clamp(PixelHeight - y, 1f, PixelHeight); | ||
return new Vector2(newX, newY); | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
Content.Client/SS220/UserInterface/PlotFigure/Point2DHelper.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
using System.Diagnostics.CodeAnalysis; | ||
using System.Numerics; | ||
using System.Linq; | ||
|
||
namespace Content.Client.SS220.UserInterface.PlotFigure; | ||
/// <summary> | ||
/// This class make working with time dependent plot easier | ||
/// It is designed to have the newest dots in the end and oldest at the start | ||
/// </summary> | ||
public sealed class Plot2DTimePoints(int maxPoints) | ||
{ | ||
public string? XLabel; | ||
public string? YLabel; | ||
public List<Vector2>? Point2Ds => _point2Ds; | ||
public int MaxLength => _maxAmountOfPoints; | ||
private List<Vector2>? _point2Ds; | ||
private int _maxAmountOfPoints = maxPoints; | ||
|
||
public void AddPoint(Vector2 point) | ||
{ | ||
_point2Ds ??= new() { point }; | ||
|
||
if (_point2Ds.Count == _maxAmountOfPoints) | ||
{ | ||
_point2Ds.RemoveAt(0); | ||
} | ||
if (_point2Ds[_point2Ds.Count - 1].X > point.X) | ||
throw new Exception("To Plot2DTimePoints added value with lesser X then last element"); | ||
_point2Ds.Add(point); | ||
} | ||
public bool TryGetDeltaBetweenMaxMinX([NotNullWhen(true)] out float? delta) | ||
{ | ||
delta = null; | ||
if (_point2Ds == null) | ||
return false; | ||
|
||
var xList = _point2Ds.Select(element => element.X); | ||
var maxX = xList.Max(); | ||
var minX = xList.Min(); | ||
var deltaMaxMinX = maxX - minX; | ||
if (deltaMaxMinX == 0) | ||
return false; | ||
|
||
delta = deltaMaxMinX; | ||
return true; | ||
} | ||
public bool TryGetMaxY([NotNullWhen(true)] out float? maxY) | ||
{ | ||
maxY = null; | ||
if (_point2Ds == null) | ||
return false; | ||
|
||
var yList = _point2Ds.Select(element => element.Y); | ||
maxY = yList.Max(); | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
Content.Shared/SS220/SuperMatterCrystalUI/SuperMatterObserverUI.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using Robust.Shared.Serialization; | ||
|
||
namespace Content.Shared.Store; | ||
|
||
[Serializable, NetSerializable] | ||
public enum SuperMatterObserverUiKey : byte | ||
{ | ||
Key | ||
} | ||
|
||
// [Serializable, NetSerializable] | ||
// public sealed class SuperMatterObserverUpdateState : BoundUserInterfaceState | ||
// { | ||
|
||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters