Re-organize all projects (#4166)

This commit is contained in:
DrSmugleaf
2021-06-09 22:19:39 +02:00
committed by GitHub
parent 9f50e4061b
commit ff1a2d97ea
1773 changed files with 5258 additions and 5508 deletions

View File

@@ -0,0 +1,14 @@
using Content.Client.Stylesheets;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
namespace Content.Client.HUD.UI
{
public sealed class HighDivider : Control
{
public HighDivider()
{
Children.Add(new PanelContainer {StyleClasses = {StyleBase.ClassHighDivider}});
}
}
}

View File

@@ -0,0 +1,153 @@
using Content.Client.Viewport;
using Content.Shared;
using Robust.Client.UserInterface;
using Robust.Shared.Configuration;
using Robust.Shared.IoC;
using Robust.Shared.Maths;
namespace Content.Client.HUD.UI
{
/// <summary>
/// Wrapper for <see cref="ScalingViewport"/> that listens to configuration variables.
/// Also does NN-snapping within tolerances.
/// </summary>
public sealed class MainViewport : Control
{
[Dependency] private readonly IConfigurationManager _cfg = default!;
[Dependency] private readonly ViewportManager _vpManager = default!;
public ScalingViewport Viewport { get; }
public MainViewport()
{
IoCManager.InjectDependencies(this);
Viewport = new ScalingViewport
{
AlwaysRender = true,
RenderScaleMode = ScalingViewportRenderScaleMode.CeilInt,
MouseFilter = MouseFilterMode.Stop
};
AddChild(Viewport);
}
protected override void EnteredTree()
{
base.EnteredTree();
_vpManager.AddViewport(this);
}
protected override void ExitedTree()
{
base.ExitedTree();
_vpManager.RemoveViewport(this);
}
public void UpdateCfg()
{
var stretch = _cfg.GetCVar(CCVars.ViewportStretch);
var renderScaleUp = _cfg.GetCVar(CCVars.ViewportScaleRender);
var fixedFactor = _cfg.GetCVar(CCVars.ViewportFixedScaleFactor);
if (stretch)
{
var snapFactor = CalcSnappingFactor();
if (snapFactor == null)
{
// Did not find a snap, enable stretching.
Viewport.FixedStretchSize = null;
Viewport.StretchMode = ScalingViewportStretchMode.Bilinear;
if (renderScaleUp)
{
Viewport.RenderScaleMode = ScalingViewportRenderScaleMode.CeilInt;
}
else
{
Viewport.RenderScaleMode = ScalingViewportRenderScaleMode.Fixed;
Viewport.FixedRenderScale = 1;
}
return;
}
// Found snap, set fixed factor and run non-stretching code.
fixedFactor = snapFactor.Value;
}
Viewport.FixedStretchSize = Viewport.ViewportSize * fixedFactor;
Viewport.StretchMode = ScalingViewportStretchMode.Nearest;
if (renderScaleUp)
{
Viewport.RenderScaleMode = ScalingViewportRenderScaleMode.Fixed;
Viewport.FixedRenderScale = fixedFactor;
}
else
{
// Snapping but forced to render scale at scale 1 so...
// At least we can NN.
Viewport.RenderScaleMode = ScalingViewportRenderScaleMode.Fixed;
Viewport.FixedRenderScale = 1;
}
}
private int? CalcSnappingFactor()
{
// Margin tolerance is tolerance of "the window is too big"
// where we add a margin to the viewport to make it fit.
var cfgToleranceMargin = _cfg.GetCVar(CCVars.ViewportSnapToleranceMargin);
// Clip tolerance is tolerance of "the window is too small"
// where we are clipping the viewport to make it fit.
var cfgToleranceClip = _cfg.GetCVar(CCVars.ViewportSnapToleranceClip);
// Calculate if the viewport, when rendered at an integer scale,
// is close enough to the control size to enable "snapping" to NN,
// potentially cutting a tiny bit off/leaving a margin.
//
// Idea here is that if you maximize the window at 1080p or 1440p
// we are close enough to an integer scale (2x and 3x resp) that we should "snap" to it.
// Just do it iteratively.
// I'm sure there's a smarter approach that needs one try with math but I'm dumb.
for (var i = 1; i <= 10; i++)
{
var toleranceMargin = i * cfgToleranceMargin;
var toleranceClip = i * cfgToleranceClip;
var scaled = (Vector2) Viewport.ViewportSize * i;
var (dx, dy) = PixelSize - scaled;
// The rule for which snap fits is that at LEAST one axis needs to be in the tolerance size wise.
// One axis MAY be larger but not smaller than tolerance.
// Obviously if it's too small it's bad, and if it's too big on both axis we should stretch up.
if (Fits(dx) && Fits(dy) || Fits(dx) && Larger(dy) || Larger(dx) && Fits(dy))
{
// Found snap that fits.
return i;
}
bool Larger(float a)
{
return a > toleranceMargin;
}
bool Fits(float a)
{
return a <= toleranceMargin && a >= -toleranceClip;
}
}
return null;
}
protected override void Resized()
{
base.Resized();
UpdateCfg();
}
}
}

View File

@@ -0,0 +1,31 @@
using Content.Client.Stylesheets;
using Robust.Client.UserInterface.Controls;
namespace Content.Client.HUD.UI
{
public class NanoHeading : Container
{
private readonly Label _label;
private readonly PanelContainer _panel;
public NanoHeading()
{
_panel = new PanelContainer
{
Children = {(_label = new Label
{
StyleClasses = {StyleNano.StyleClassLabelHeading}
})}
};
AddChild(_panel);
HorizontalAlignment = HAlignment.Left;
}
public string? Text
{
get => _label.Text;
set => _label.Text = value;
}
}
}

View File

@@ -0,0 +1,29 @@
using Robust.Client.UserInterface.Controls;
namespace Content.Client.HUD.UI
{
public sealed class Placeholder : PanelContainer
{
public const string StyleClassPlaceholderText = "PlaceholderText";
private readonly Label _label;
public string? PlaceholderText
{
get => _label.Text;
set => _label.Text = value;
}
public Placeholder()
{
_label = new Label
{
VerticalAlignment = VAlignment.Stretch,
Align = Label.AlignMode.Center,
VAlign = Label.VAlignMode.Center
};
_label.AddStyleClass(StyleClassPlaceholderText);
AddChild(_label);
}
}
}

View File

@@ -0,0 +1,124 @@
using Robust.Client.Graphics;
using Robust.Client.UserInterface.Controls;
using Robust.Shared.Maths;
namespace Content.Client.HUD.UI
{
public class StripeBack : Container
{
private const float PadSize = 4;
private const float EdgeSize = 2;
private static readonly Color EdgeColor = Color.FromHex("#525252ff");
private bool _hasTopEdge = true;
private bool _hasBottomEdge = true;
private bool _hasMargins = true;
public const string StylePropertyBackground = "background";
public bool HasTopEdge
{
get => _hasTopEdge;
set
{
_hasTopEdge = value;
InvalidateMeasure();
}
}
public bool HasBottomEdge
{
get => _hasBottomEdge;
set
{
_hasBottomEdge = value;
InvalidateMeasure();
}
}
public bool HasMargins
{
get => _hasMargins;
set
{
_hasMargins = value;
InvalidateMeasure();
}
}
protected override Vector2 MeasureOverride(Vector2 availableSize)
{
var padSize = HasMargins ? PadSize : 0;
var padSizeTotal = 0f;
if (HasBottomEdge)
padSizeTotal += padSize + EdgeSize;
if (HasTopEdge)
padSizeTotal += padSize + EdgeSize;
var size = Vector2.Zero;
availableSize.Y -= padSizeTotal;
foreach (var child in Children)
{
child.Measure(availableSize);
size = Vector2.ComponentMax(size, child.DesiredSize);
}
return size + (0, padSizeTotal);
}
protected override Vector2 ArrangeOverride(Vector2 finalSize)
{
var box = new UIBox2(Vector2.Zero, finalSize);
var padSize = HasMargins ? PadSize : 0;
if (HasTopEdge)
{
box += (0, padSize + EdgeSize, 0, 0);
}
if (HasBottomEdge)
{
box += (0, 0, 0, -(padSize + EdgeSize));
}
foreach (var child in Children)
{
child.Arrange(box);
}
return finalSize;
}
protected override void Draw(DrawingHandleScreen handle)
{
UIBox2 centerBox = PixelSizeBox;
var padSize = HasMargins ? PadSize : 0;
if (HasTopEdge)
{
centerBox += (0, (padSize + EdgeSize) * UIScale, 0, 0);
handle.DrawRect(new UIBox2(0, padSize * UIScale, PixelWidth, centerBox.Top), EdgeColor);
}
if (HasBottomEdge)
{
centerBox += (0, 0, 0, -((padSize + EdgeSize) * UIScale));
handle.DrawRect(new UIBox2(0, centerBox.Bottom, PixelWidth, PixelHeight - padSize * UIScale),
EdgeColor);
}
GetActualStyleBox()?.Draw(handle, centerBox);
}
private StyleBox? GetActualStyleBox()
{
return TryGetStyleProperty(StylePropertyBackground, out StyleBox? box) ? box : null;
}
}
}

View File

@@ -0,0 +1,9 @@
using Robust.Client.UserInterface;
namespace Content.Client.HUD.UI
{
public class TopNotification : Control
{
}
}