Revert "Feature/shader radial menu" due to shader issue (#36470)

This commit is contained in:
Pieter-Jan Briers
2025-04-11 23:30:52 +02:00
committed by GitHub
parent 86620dbe6c
commit e6e60dead4
5 changed files with 55 additions and 272 deletions

View File

@@ -1,23 +1,12 @@
using Robust.Client.UserInterface.Controls;
using System.Linq;
using System.Numerics;
using Robust.Client.Graphics;
using Robust.Shared.Prototypes;
namespace Content.Client.UserInterface.Controls;
[Virtual]
public class RadialContainer : LayoutContainer
{
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly IClyde _clyde= default!;
private readonly ShaderInstance _shader;
private readonly float[] _angles = new float[64];
private readonly float[] _sectorMedians = new float[64];
private readonly Color[] _sectorColors = new Color[64];
private readonly Color[] _borderColors = new Color[64];
/// <summary>
/// Increment of radius per child element to be rendered.
/// </summary>
@@ -35,7 +24,11 @@ public class RadialContainer : LayoutContainer
[ViewVariables(VVAccess.ReadWrite)]
public Vector2 AngularRange
{
get => _angularRange;
get
{
return _angularRange;
}
set
{
var x = value.X;
@@ -96,9 +89,7 @@ public class RadialContainer : LayoutContainer
/// </summary>
public RadialContainer()
{
IoCManager.InjectDependencies(this);
_shader = _prototypeManager.Index<ShaderPrototype>("RadialMenu")
.InstanceUnique();
}
/// <inheritdoc />
@@ -170,67 +161,6 @@ public class RadialContainer : LayoutContainer
return base.ArrangeOverride(finalSize);
}
/// <inheritdoc />
protected override void Draw(DrawingHandleScreen handle)
{
base.Draw(handle);
float selectedFrom = 0;
float selectedTo = 0;
var i = 0;
foreach (var child in Children)
{
if (child is not IRadialMenuItemWithSector menuWithSector)
{
continue;
}
_angles[i] = menuWithSector.AngleSectorTo;
_sectorMedians[i] = (menuWithSector.AngleSectorTo + menuWithSector.AngleSectorFrom) / 2;
if (menuWithSector.IsHovered)
{
// menuWithSector.DrawBackground;
// menuWithSector.DrawBorder;
_sectorColors[i] = menuWithSector.HoverBackgroundColor;
_borderColors[i] = menuWithSector.HoverBorderColor;
selectedFrom = menuWithSector.AngleSectorFrom;
selectedTo = menuWithSector.AngleSectorTo;
}
else
{
_sectorColors[i] = menuWithSector.BackgroundColor;
_borderColors[i] = menuWithSector.BorderColor;
}
i++;
}
var screenSize = _clyde.ScreenSize;
var menuCenter = new Vector2(
ScreenCoordinates.X + (Size.X / 2) * UIScale,
screenSize.Y - ScreenCoordinates.Y - (Size.Y / 2) * UIScale
);
_shader.SetParameter("separatorAngles", _angles);
_shader.SetParameter("sectorMedianAngles", _sectorMedians);
_shader.SetParameter("selectedFrom", selectedFrom);
_shader.SetParameter("selectedTo", selectedTo);
_shader.SetParameter("childCount", i);
_shader.SetParameter("sectorColors", _sectorColors);
_shader.SetParameter("borderColors", _borderColors);
_shader.SetParameter("centerPos", menuCenter);
_shader.SetParameter("screenSize", screenSize);
_shader.SetParameter("innerRadius", CalculatedRadius * InnerRadiusMultiplier * UIScale);
_shader.SetParameter("outerRadius", CalculatedRadius * OuterRadiusMultiplier * UIScale);
handle.UseShader(_shader);
handle.DrawRect(new UIBox2(0, 0, screenSize.X, screenSize.Y), Color.White);
handle.UseShader(null);
}
/// <summary>
/// Specifies the different radial alignment modes
/// </summary>

View File

@@ -362,12 +362,12 @@ public interface IRadialMenuItemWithSector
/// <summary>
/// Angle in radian where button sector should start.
/// </summary>
public float AngleSectorFrom { set; get; }
public float AngleSectorFrom { set; }
/// <summary>
/// Angle in radian where button sector should end.
/// </summary>
public float AngleSectorTo { set; get; }
public float AngleSectorTo { set; }
/// <summary>
/// Outer radius for drawing segment and pointer detection.
@@ -388,41 +388,6 @@ public interface IRadialMenuItemWithSector
/// Coordinates of center in parent component - button container.
/// </summary>
public Vector2 ParentCenter { set; }
/// <summary>
/// Marker, is menu item hovered currently.
/// </summary>
public bool IsHovered { get; }
/// <summary>
/// Color for menu item background when it is hovered over.
/// </summary>
Color HoverBackgroundColor { get; }
/// <summary>
/// Color for menu item default state.
/// </summary>
Color BackgroundColor { get; }
/// <summary>
/// Color for menu item border when item is hovered over.
/// </summary>
Color HoverBorderColor { get; }
/// <summary>
/// Color for menu item border default state.
/// </summary>
Color BorderColor { get; }
/// <summary>
/// Marker, if menu item background should be drawn.
/// </summary>
public bool DrawBackground { get; }
/// <summary>
/// Marker, if menu item borders should be drawn.
/// </summary>
public bool DrawBorder { get; }
}
[Virtual]
@@ -448,7 +413,7 @@ public class RadialMenuTextureButtonWithSector : RadialMenuTextureButton, IRadia
/// Marker, that controls if border of segment should be rendered. Is false by default.
/// </summary>
/// <remarks>
/// Default color of border is same as color of background. Use <see cref="BorderColor"/>
/// By default color of border is same as color of background. Use <see cref="BorderColor"/>
/// and <see cref="HoverBorderColor"/> to change it.
/// </remarks>
public bool DrawBorder { get; set; } = false;
@@ -494,6 +459,12 @@ public class RadialMenuTextureButtonWithSector : RadialMenuTextureButton, IRadia
set => _hoverBorderColorSrgb = Color.ToSrgb(value);
}
/// <summary>
/// Color of separator lines.
/// Separator lines are used to visually separate sector of radial menu items.
/// </summary>
public Color SeparatorColor { get; set; } = new Color(128, 128, 128, 128);
/// <inheritdoc />
float IRadialMenuItemWithSector.AngleSectorFrom
{
@@ -502,7 +473,6 @@ public class RadialMenuTextureButtonWithSector : RadialMenuTextureButton, IRadia
_angleSectorFrom = value;
_isWholeCircle = IsWholeCircle(value, _angleSectorTo);
}
get => _angleSectorFrom;
}
/// <inheritdoc />
@@ -513,7 +483,6 @@ public class RadialMenuTextureButtonWithSector : RadialMenuTextureButton, IRadia
_angleSectorTo = value;
_isWholeCircle = IsWholeCircle(_angleSectorFrom, value);
}
get => _angleSectorTo;
}
/// <inheritdoc />
@@ -535,6 +504,44 @@ public class RadialMenuTextureButtonWithSector : RadialMenuTextureButton, IRadia
{
}
/// <inheritdoc />
protected override void Draw(DrawingHandleScreen handle)
{
base.Draw(handle);
if (_parentCenter == null)
{
return;
}
// draw sector where space that button occupies actually is
var containerCenter = (_parentCenter.Value - Position) * UIScale;
var angleFrom = _angleSectorFrom + _angleOffset;
var angleTo = _angleSectorTo + _angleOffset;
if (DrawBackground)
{
var segmentColor = DrawMode == DrawModeEnum.Hover
? _hoverBackgroundColorSrgb
: _backgroundColorSrgb;
DrawAnnulusSector(handle, containerCenter, _innerRadius * UIScale, _outerRadius * UIScale, angleFrom, angleTo, segmentColor);
}
if (DrawBorder)
{
var borderColor = DrawMode == DrawModeEnum.Hover
? _hoverBorderColorSrgb
: _borderColorSrgb;
DrawAnnulusSector(handle, containerCenter, _innerRadius * UIScale, _outerRadius * UIScale, angleFrom, angleTo, borderColor, false);
}
if (!_isWholeCircle && DrawBorder)
{
DrawSeparatorLines(handle, containerCenter, _innerRadius * UIScale, _outerRadius * UIScale, angleFrom, angleTo, SeparatorColor);
}
}
/// <inheritdoc />
protected override bool HasPoint(Vector2 point)
{

View File

@@ -7,7 +7,6 @@ using Robust.Client.GameObjects;
using Robust.Shared.Timing;
using Robust.Client.UserInterface.XAML;
using Robust.Client.Input;
using Robust.Shared.Collections;
namespace Content.Client.UserInterface.Controls;
@@ -174,7 +173,7 @@ public partial class SimpleRadialMenu : RadialMenu
private void ClearExistingChildrenRadialButtons()
{
var toRemove = new ValueList<Control>(ChildCount);
var toRemove = new List<Control>(ChildCount);
foreach (var child in Children)
{
if (child != ContextualButton && child != MenuOuterAreaButton)