Skip to content

Commit

Permalink
BaseUIPlotEnd
Browse files Browse the repository at this point in the history
  • Loading branch information
Alwayswannahunt committed Aug 19, 2024
1 parent 4acb236 commit 63475c3
Show file tree
Hide file tree
Showing 56 changed files with 508 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public sealed class SuperMatterObserverSystem : EntitySystem
private List<EntityUid> _smReceiverUIOwnersToInit = new();
private TimeSpan _nextUpdateTime = default!;
private HashSet<Entity<SuperMatterObserverReceiverComponent>> _receivers = new();
private SortedList<int, EntityUid> _processedReceivers = new();
public override void Initialize()
{
base.Initialize();
Expand Down Expand Up @@ -102,12 +103,18 @@ private void OnCrystalUpdate(SuperMatterStateUpdate args)
_entityLookup.GetEntitiesOnMap(Transform(observerUid).MapID, _receivers);
// logic
foreach (var receiver in _receivers)
TrySendToUIState(receiver.Owner, new SuperMatterObserverUpdateState(args.Id, args.Name, args.Integrity, args.Pressure,
args.Temperature, args.Matter, args.InternalEnergy, args.Delaminate));
{
if (_processedReceivers.ContainsKey(receiver.Owner.Id))
continue;
if (TrySendToUIState(receiver.Owner, new SuperMatterObserverUpdateState(args.Id, args.Name, args.Integrity, args.Pressure,
args.Temperature, args.Matter, args.InternalEnergy, args.Delaminate)))
_processedReceivers.Add(receiver.Owner.Id, receiver.Owner);
}
_receivers.Clear();
// RaiseLocalEvent(SMpanels -> accept information)
}
_observerEntities.Clear();
_processedReceivers.Clear();
}
private void OnReceiverBoundUIOpened(Entity<SuperMatterObserverReceiverComponent> entity, ref BoundUIOpenedEvent args)
{
Expand Down
13 changes: 8 additions & 5 deletions Content.Client/SS220/SuperMatter/Ui/SuperMatterObserverBUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,19 @@ protected override void Open()

_menu.OnServerButtonPressed += (args, observerComp) =>
{
if (!args.Button.Pressed)
_menu.Observer = null;
else
if (args.Button.Pressed)
_menu.Observer = observerComp;
else
_menu.Observer = null;
_menu.CrystalKey = null;
_menu.LoadCrystal();
};
_menu.OnCrystalButtonPressed += (_, crystalKey) =>
_menu.OnCrystalButtonPressed += (args, crystalKey) =>
{
_menu.CrystalKey = crystalKey;
if (args.Button.Pressed)
_menu.CrystalKey = crystalKey;
else
_menu.CrystalKey = null;
_menu.LoadCachedData();
};
}
Expand Down
59 changes: 43 additions & 16 deletions Content.Client/SS220/SuperMatter/Ui/SuperMatterObserverMenu.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,54 @@
<controls:FancyWindow
xmlns="https://spacestation14.io"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:gfx="clr-namespace:Robust.Client.Graphics;assembly=Robust.Client"
xmlns:plot="clr-namespace:Content.Client.SS220.UserInterface.PlotFigure"
xmlns:controls="clr-namespace:Content.Client.UserInterface.Controls"
Title="{Loc 'supermatter-observer-title'}"
Resizable="False"
MinSize="512 608"
SetSize="512 608"
MinSize="800 632"
SetSize="800 632"
RectClipContent="False">
<BoxContainer Name="ContentHolderContainer" Orientation="Vertical">
<BoxContainer Name="ServerNavigationBar" HorizontalExpand="True" MinHeight="16" Margin="1 1 3 0">
<!-- Here goes all avaible "Servers" with SM data -->
</BoxContainer>
<BoxContainer Name="CrystalNavigationBar" HorizontalExpand="True" MinHeight="16" Margin="1 1 3 0">
<!-- Here goes all avaible "Servers" with SM data -->
</BoxContainer>
<BoxContainer Name="UpperDataContainer" MinHeight="256" Orientation="Vertical" Margin="8 8">
<plot:PlotSequencedView Name="PlotValueOverTime" MinHeight="256" MouseFilter="Stop"/>
<!-- Here go numberic Data -->
<Control>
<PanelContainer>
<PanelContainer.PanelOverride>
<gfx:StyleBoxFlat BackgroundColor="#1B1B1E"/>
</PanelContainer.PanelOverride>
</PanelContainer>
<BoxContainer Name="ContentHolderContainer" Orientation="Vertical">

<BoxContainer Name="ServerNavigationBar" VerticalAlignment="Center" HorizontalExpand="True" MinHeight="32" MaxHeight="32" Margin="2 2 6 2">
<!-- Here goes all avaible "Servers" with SM data -->
</BoxContainer>
<BoxContainer Name="LowerDataContainer" MinHeight="256" Orientation="Vertical" Margin="8 8">
<plot:Pseudo3DColoredView Name="ColorState" MinHeight="256" MouseFilter="Stop"/>
<!-- Here go data about gasses ratio near SM and their amount as label? or just in text -->
<PanelContainer StyleClasses="LowDivider" Margin="2 0 2 0"/>
<BoxContainer Name="CrystalNavigationBar" VerticalAlignment="Center" HorizontalExpand="True" MinHeight="32" MaxHeight="32" Margin="2 2 6 2">
<!-- Here goes all avaible "Servers" with SM data -->
</BoxContainer>
</BoxContainer>
<PanelContainer StyleClasses="LowDivider" Margin="2 0 2 0"/>
<BoxContainer Name="UpperDataContainer" MinHeight="256" HorizontalExpand="True" Orientation="Horizontal" Margin="4 4">
<plot:PlotSequencedView Name="PlotValueOverTime" HorizontalExpand="True" MaxWidth="512" MouseFilter="Stop" MinWidth ="384"/>
<BoxContainer HorizontalExpand="True" Orientation="Vertical" MaxWidth="256" MinWidth ="192">
<Control VerticalExpand ="True"/>
<RichTextLabel Name="NameLabel" HorizontalExpand="True"/>
<RichTextLabel Name="IntegrityLabel" HorizontalExpand="True"/>
<RichTextLabel Name="PressureLabel" HorizontalExpand="True"/>
<RichTextLabel Name="TemperatureLabel" HorizontalExpand="True"/>
<RichTextLabel Name="MatterLabel" HorizontalExpand="True"/>
<RichTextLabel Name="InternalEnergyLabel" HorizontalExpand="True"/>
<RichTextLabel Name="DelamStatus" HorizontalExpand="True"/>
<Control VerticalExpand ="True"/>
</BoxContainer>
<!-- Here go numberic Data -->
</BoxContainer>
<BoxContainer Name="LowerDataContainer" MinHeight="256" HorizontalExpand="True" Orientation="Horizontal" Margin="4 4">
<plot:Pseudo3DColoredView Name="ColorState" HorizontalExpand="True" MaxSize="512 256" MinSize="384 256" MouseFilter="Stop" Margin="4 4"/>
<ScrollContainer Name="GasScroll" HScrollEnabled="False" HorizontalExpand="True"
MaxSize="256 256" MinSize="192 192" Margin="2 2 2 20">
<BoxContainer Name="GasContainer" MinSize="192 256" Orientation="Vertical" HorizontalExpand="True" SizeFlagsStretchRatio ="4" Margin="0 0 4 0">
<!-- Gas Ratio Bars goes here-->
</BoxContainer>
</ScrollContainer>
</BoxContainer>
</BoxContainer>
</Control>
</controls:FancyWindow>
126 changes: 115 additions & 11 deletions Content.Client/SS220/SuperMatter/Ui/SuperMatterObserverMenu.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,43 @@
using FancyWindow = Content.Client.UserInterface.Controls.FancyWindow;
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface.XAML;
using Robust.Shared.Timing;
using Robust.Client.UserInterface.Controls;
using Content.Shared.SS220.SuperMatter.Ui;
using Content.Client.SS220.UserInterface.PlotFigure;
using Content.Client.SS220.SuperMatter.Observer;
using System.Numerics;
using System.Linq;
using Robust.Client.Graphics;
using Content.Shared.Atmos;

namespace Content.Client.SS220.SuperMatter.Ui;

// For optimization make cache value in ServerSystem and then subscribe from client if it needs it;
[GenerateTypedNameReferences]
public sealed partial class SuperMatterObserverMenu : FancyWindow
{

[Dependency] ILocalizationManager _localization = default!;
public event Action<BaseButton.ButtonEventArgs, SuperMatterObserverComponent>? OnServerButtonPressed;
public event Action<BaseButton.ButtonEventArgs, int>? OnCrystalButtonPressed;
public SuperMatterObserverComponent? Observer;
public int? CrystalKey;
public Dictionary<Gas, Color> GasBarColors = new()
{
{Gas.Oxygen, Color.SeaBlue},
{Gas.Nitrogen, Color.LightCoral},
{Gas.Plasma, Color.Violet},
{Gas.CarbonDioxide, Color.Gray}
};
public const int MAX_DATA_LENGTH = 180;
private int counter = 0;
private float conterAbobaX = 0f;
private float conterAbobaY = 0f;
public SuperMatterObserverMenu()
{
IoCManager.InjectDependencies(this);
RobustXamlLoader.Load(this);
PlotValueOverTime.SetLabels("time elapsed, s", " Integrity", " Crystal Integrity ");
PlotValueOverTime.SetLabels(_localization.GetString("smObserver-plotXLabel-integrity"), _localization.GetString("smObserver-plotYLabel-integrity"), _localization.GetString("smObserver-plotTitle-integrity"));
ColorState.MakeMeshgrid((1, 100, 25), (1, 100, 100));
ColorState.EvalFunctionOnMeshgrid(GetIntegrityDamageMap);
ColorState.SetLabels("Matter, a.u.", "Internal energy, a.u.", " Safe operation ");
ColorState.SetLabels(_localization.GetString("smObserver-plotXLabel-colorState"), _localization.GetString("smObserver-plotYLabel-colorState"), _localization.GetString("smObserver-plotTitle-colorState"));
InitGasRatioBars();
}
public void LoadState(List<Entity<SuperMatterObserverComponent>> observerEntities)
{
Expand All @@ -43,12 +49,17 @@ public void LoadState(List<Entity<SuperMatterObserverComponent>> observerEntitie
var serverButton = new ServerButton
{
Text = observerUid.ToString(),
StyleBoxOverride = new StyleBoxFlat(Color.DarkGray),
ObserverComponent = observerComp,
Margin = new Thickness(2, 0, 2, 0),
ToggleMode = true,
StyleClasses = { "OpenBoth" }
};

serverButton.OnPressed += args => OnServerButtonPressed?.Invoke(args, serverButton.ObserverComponent);
serverButton.OnPressed += args =>
{
OnServerButtonPressed?.Invoke(args, serverButton.ObserverComponent);
};
ServerNavigationBar.AddChild(serverButton);
}
}
Expand All @@ -62,12 +73,17 @@ public void LoadCrystal()
var crystalButton = new CrystalButton
{
Text = name,
StyleBoxOverride = new StyleBoxFlat(Color.DarkGray),
CrystalKey = crystalKey,
ToggleMode = true,
Margin = new Thickness(2, 0, 2, 0),
StyleClasses = { "OpenBoth" }
};

crystalButton.OnPressed += args => OnCrystalButtonPressed?.Invoke(args, crystalButton.CrystalKey);
crystalButton.OnPressed += args =>
{
OnCrystalButtonPressed?.Invoke(args, crystalButton.CrystalKey);
};
CrystalNavigationBar.AddChild(crystalButton);
}
}
Expand All @@ -77,23 +93,105 @@ public void LoadCachedData()
|| CrystalKey == null)
return;
PlotValueOverTime.LoadPlot2DTimePoints(new PlotPoints2D(MAX_DATA_LENGTH, Observer.Integrities[CrystalKey.Value],
-1f, -1f * Observer.Integrities[CrystalKey.Value].Count));
-1f, Observer.Integrities[CrystalKey.Value].Count));
ColorState.LoadMovingPoint(new Vector2(Observer.Matters[CrystalKey.Value].Last().Value, Observer.InternalEnergy[CrystalKey.Value].Last().Value),
new Vector2(Observer.Matters[CrystalKey.Value].Last().Derv, Observer.InternalEnergy[CrystalKey.Value].Last().Derv));
}
public void UpdateState(SuperMatterObserverUpdateState msg)
{
if (Observer == null
|| CrystalKey == null)
{
SetMessageDataToTextInfo();
return;
}
if (msg.Id != CrystalKey)
return;
PlotValueOverTime.AddPointToPlot(new Vector2(PlotValueOverTime.GetLastAddedPointX() + 1, msg.Integrity));

PlotValueOverTime.AddPointToPlot(new Vector2(PlotValueOverTime.GetLastAddedPointX() + 1f, msg.Integrity));
ColorState.LoadMovingPoint(new Vector2(msg.Matter.Value, msg.InternalEnergy.Value), new Vector2(msg.Matter.Derivative, msg.InternalEnergy.Derivative));
SetMessageDataToTextInfo(msg);
}

private void SetMessageDataToTextInfo(SuperMatterObserverUpdateState msg)
{
NameLabel.SetMessage(_localization.GetString("smObserver-name", ("name", msg.Name)));
IntegrityLabel.SetMessage(_localization.GetString("smObserver-integrity", ("value", msg.Integrity)));
PressureLabel.SetMessage(_localization.GetString("smObserver-pressure", ("value", msg.Pressure)));
TemperatureLabel.SetMessage(_localization.GetString("smObserver-temperature", ("value", msg.Temperature)));
MatterLabel.SetMessage(_localization.GetString("smObserver-matter", ("value", msg.Matter.Value)));
InternalEnergyLabel.SetMessage(_localization.GetString("smObserver-internalEnergy", ("value", msg.InternalEnergy.Value)));
DelamStatus.SetMessage(_localization.GetString("smObserver-delamStatus",
("status", msg.Delaminate.Delaminates), ("ETA", msg.Delaminate.ETOfDelamination)));
}
private void SetMessageDataToTextInfo()
{
NameLabel.SetMessage(_localization.GetString("smObserver-integrity-none"));
IntegrityLabel.SetMessage(_localization.GetString("smObserver-integrity-none"));
PressureLabel.SetMessage(_localization.GetString("smObserver-pressure-none"));
TemperatureLabel.SetMessage(_localization.GetString("smObserver-temperature-none"));
MatterLabel.SetMessage(_localization.GetString("smObserver-matter-none"));
InternalEnergyLabel.SetMessage(_localization.GetString("smObserver-internalEnergy-none"));
DelamStatus.SetMessage(_localization.GetString("smObserver-delamStatus-none"));
}
private float GetIntegrityDamageMap(float matter, float internalEnergy)
{
return SuperMatterFunctions.EnergyToMatterDamageFactorFunction(
internalEnergy - SuperMatterFunctions.SafeInternalEnergyToMatterFunction(matter / SuperMatterFunctions.MatterNondimensionalization));
}
private void InitGasRatioBars()
{
foreach (var gas in Enum.GetValues<Gas>())
{
var gasBar = MakeGasRatioProgressBar(gas);
GasContainer.AddChild(gasBar);
}
}
private void UpdateGasRatioBars(Dictionary<Gas, float> gasRatios)
{
foreach (var gasBar in GasContainer.Children)
{
if (gasBar.GetType() != typeof(GasBar))
return;

((ProgressBar)gasBar).SetAsRatio(gasRatios[((GasBar)gasBar).GasId]);
}
}
private ProgressBar MakeGasRatioProgressBar(Gas gas)
{

if (TryGetStyleProperty<StyleBoxFlat>(ProgressBar.StylePropertyBackground, out var retBackground))
retBackground.BackgroundColor = Color.FromHex("#2B2A26");
else
retBackground = new StyleBoxFlat(Color.FromHex("#2B2A26"));
if (TryGetStyleProperty<StyleBoxFlat>(ProgressBar.StylePropertyForeground, out var retForeground))
retForeground.BackgroundColor = GasBarColors.TryGetValue(gas, out var color) ? color : Color.ForestGreen;
else
retForeground = new StyleBoxFlat(GasBarColors.TryGetValue(gas, out var color) ? color : Color.ForestGreen);
retForeground.BorderThickness = new Thickness(2f, 2f, 0f, 4f);
retBackground.BorderThickness = new Thickness(2f, 2f, 0f, 4f);
var gasBar = new GasBar
{
GasId = gas,
HorizontalExpand = true,
VerticalExpand = true,
MinValue = 0f,
MaxValue = 1f,
MinHeight = 20f,
Page = 0f,
Value = 0.5f,
BackgroundStyleBoxOverride = retBackground,
ForegroundStyleBoxOverride = retForeground,
};

var gasLabel = new Label
{
Margin = new Thickness(2f, 2f, 0f, 14f),
Text = gas.ToString(),
};
gasBar.AddChild(gasLabel);
return gasBar;
}
private sealed class ServerButton : Button
{
public SuperMatterObserverComponent? ObserverComponent;
Expand All @@ -102,4 +200,10 @@ private sealed class CrystalButton : Button
{
public int CrystalKey;
}
private sealed class GasBar : ProgressBar
{
public Gas GasId;
}
}


Loading

0 comments on commit 63475c3

Please sign in to comment.