Feature/shader radial menu (#35152)

* it works! kinda

* so it works now

* minor cleanup

* central button now is useful too

* more cleanup

* minor cleanup

* more cleanup

* refactor: migrated code from toolbox (as it was rejected as too specific)

* feat: moved border drawing for radial menu into RadialMenuTextureButton. Radial menu position setting into was moved to OverrideArrange to not being called on every frame

* refactor: major reworks!

* renamed DrawBagleSector to DrawAnnulusSector

* Remove strange indexing

* Regularize math

* refactor: re-orienting segment elements to be Y-mirrored

* refactor: extracted radial menu radius multiplier property, changed color pallet for radial menu button

* refactor: removed icon backgrounds on textures used in current radial menu buttons with sectors, RadialContainer Radius renamed and now actually changed control radius.

* refactor: in RadialMenuTextureButtonWithSector all sector colors are converted to and from sRGB in property getter-setters

* refactor: renamed srgb to include Srgb suffix so devs gonna see that its srgb clearly

* fix: enabled any functional keys pressed when pushing radial menu buttons

* fix: radial menu sector now scales with UIScale

* fix: accept only one event when clicking on radial menu ContextualButton

* fix: now radial menu buttons accepts only click/alt-click, now clicks outside menu closes menu always

* feat: simple radial menu prototype for easier creation

* refactor: cleanup, restored emote filtering, button models now have class hierarchy

* refactor: remove usage of closure from 'outside code'

* refactor: remove non existing type from UiControlTest

* refactor: remove unused using

* refactor: revert ability to declare radial menu layers in xaml, scale 32px sprites using scale in radial menu

* refactor: whitespaces

* refactor: subscribe for dispose on existing radial menus

* feat: now simple radial menu button models can have custom color for each sector background (and hover background color). Also added OpenOverMouseScreenPosition inside SimpleRadialMenu

* fix: AI door menu now can be closed by verb if it gets unpowered

* overlay and its registration

* radial menu shader but it requires wierd offset

* remove unused file

* smol cleanup

* remove unused code

* neat internal subsctors in radial menu shaders

* refactor finalize visual style

* comments, simplify, extract variable and other minor refactors on radial-menu shader

* refactor: extract more data from radial menu with sector to radial container for shader drawing

* replaced DrawSeparators for RadialMenuTextureButtonWithSector with DrawBorder (no reason to make them separate), also now colors are properly applied

* refactor: simplify hiding border, extended xml-doc for simple radial menu settings

* refactor: remove duplication of radial menu shaders, use ValueList to collect ClearExistingChildrenRadialButtons buttons to remove

* refactor: remove linq

* fix: fix AI radial action serialization using invalid type

* refactor: fix duplicate ShowDeviceNotRespondingPopup for AI by properly checking if it can interact

* refactor: removed *if* blocks from shader, replaced with branchless logic

* refactor: whitespaces, changed list to array in simple radial button preparing methods

* fix: merge duplicated code

---------

Co-authored-by: pa.pecherskij <pa.pecherskij@interfax.ru>
Co-authored-by: Eoin Mcloughlin <helloworld@eoinrul.es>
This commit is contained in:
Fildrance
2025-04-10 13:42:53 +03:00
committed by GitHub
parent 2172eaa492
commit 56710697a9
5 changed files with 272 additions and 55 deletions

View File

@@ -362,12 +362,12 @@ public interface IRadialMenuItemWithSector
/// <summary>
/// Angle in radian where button sector should start.
/// </summary>
public float AngleSectorFrom { set; }
public float AngleSectorFrom { set; get; }
/// <summary>
/// Angle in radian where button sector should end.
/// </summary>
public float AngleSectorTo { set; }
public float AngleSectorTo { set; get; }
/// <summary>
/// Outer radius for drawing segment and pointer detection.
@@ -388,6 +388,41 @@ 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]
@@ -413,7 +448,7 @@ public class RadialMenuTextureButtonWithSector : RadialMenuTextureButton, IRadia
/// Marker, that controls if border of segment should be rendered. Is false by default.
/// </summary>
/// <remarks>
/// By default color of border is same as color of background. Use <see cref="BorderColor"/>
/// 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;
@@ -459,12 +494,6 @@ 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
{
@@ -473,6 +502,7 @@ public class RadialMenuTextureButtonWithSector : RadialMenuTextureButton, IRadia
_angleSectorFrom = value;
_isWholeCircle = IsWholeCircle(value, _angleSectorTo);
}
get => _angleSectorFrom;
}
/// <inheritdoc />
@@ -483,6 +513,7 @@ public class RadialMenuTextureButtonWithSector : RadialMenuTextureButton, IRadia
_angleSectorTo = value;
_isWholeCircle = IsWholeCircle(_angleSectorFrom, value);
}
get => _angleSectorTo;
}
/// <inheritdoc />
@@ -504,44 +535,6 @@ 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)
{