* Moodsystem cleanups * remove overhydrated and overfed mood debuffs * admins now join game deadmined + new player timers * faster arrivals * recharging rcd with metal, glass, plastic or cable coils * better timings and costs + building apc and camera * preparing for rpd * RPD + make RCD more generic * add rpd to atmos lockers, rcd to engivend * rcd and rpd to technologies * dont deadmin me in debug * rcd ammo buff * add ChargeCountModifier logic for non stackable items * increase time to become experienced player * Dynamic Radial Menus (#29678) * fix * Clean Some Code * Some Commentaries * Update Content.Client/UserInterface/Controls/RadialContainer.cs * Update Content.Client/UserInterface/Controls/RadialContainer.cs --------- Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> * more dynamically parameters --------- Co-authored-by: Rinary <72972221+Rinary1@users.noreply.github.com> Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
219 lines
6.9 KiB
C#
219 lines
6.9 KiB
C#
using System.Linq;
|
|
using Content.Client.UserInterface.Controls;
|
|
using Content.Shared.Popups;
|
|
using Content.Shared.RCD;
|
|
using Content.Shared.RCD.Components;
|
|
using Robust.Client.AutoGenerated;
|
|
using Robust.Client.GameObjects;
|
|
using Robust.Client.Player;
|
|
using Robust.Client.UserInterface;
|
|
using Robust.Client.UserInterface.Controls;
|
|
using Robust.Client.UserInterface.XAML;
|
|
using Robust.Shared.Prototypes;
|
|
using System.Numerics;
|
|
using Robust.Client.Graphics;
|
|
using Robust.Shared.Graphics.RSI;
|
|
using Robust.Shared.Serialization.Manager.Exceptions;
|
|
using Robust.Shared.Utility;
|
|
|
|
namespace Content.Client.RCD;
|
|
|
|
[GenerateTypedNameReferences]
|
|
public sealed partial class RCDMenu : RadialMenu
|
|
{
|
|
[Dependency] private readonly EntityManager _entManager = default!;
|
|
[Dependency] private readonly IPrototypeManager _protoManager = default!;
|
|
[Dependency] private readonly IPlayerManager _playerManager = default!;
|
|
|
|
private readonly SpriteSystem _spriteSystem;
|
|
private readonly SharedPopupSystem _popup;
|
|
|
|
public event Action<ProtoId<RCDPrototype>>? SendRCDSystemMessageAction;
|
|
|
|
private EntityUid _owner;
|
|
|
|
public RCDMenu(EntityUid owner, RCDMenuBoundUserInterface bui)
|
|
{
|
|
IoCManager.InjectDependencies(this);
|
|
RobustXamlLoader.Load(this);
|
|
|
|
_spriteSystem = _entManager.System<SpriteSystem>();
|
|
_popup = _entManager.System<SharedPopupSystem>();
|
|
|
|
_owner = owner;
|
|
|
|
// Find the main radial container
|
|
var main = FindControl<RadialContainer>("Main");
|
|
|
|
// Populate secondary radial containers
|
|
if (!_entManager.TryGetComponent<RCDComponent>(owner, out var rcd))
|
|
return;
|
|
|
|
SetupCategories(main, rcd); // WD
|
|
|
|
foreach (var protoId in rcd.AvailablePrototypes)
|
|
{
|
|
if (!_protoManager.TryIndex(protoId, out var proto))
|
|
continue;
|
|
|
|
if (proto.Mode == RcdMode.Invalid)
|
|
continue;
|
|
|
|
var parent = Children.First(c => c.Name == proto.Category.Id);
|
|
|
|
var tooltip = Loc.GetString(proto.Name);
|
|
|
|
if ((proto.Mode == RcdMode.ConstructTile || proto.Mode == RcdMode.ConstructObject) &&
|
|
proto.Prototype != null && _protoManager.TryIndex(proto.Prototype, out var entProto))
|
|
{
|
|
tooltip = Loc.GetString(entProto.Name);
|
|
}
|
|
|
|
tooltip = char.ToUpper(tooltip[0]) + tooltip.Remove(0, 1);
|
|
|
|
var button = new RCDMenuButton()
|
|
{
|
|
StyleClasses = { "RadialMenuButton" },
|
|
SetSize = new Vector2(64f, 64f),
|
|
ToolTip = tooltip,
|
|
ProtoId = protoId,
|
|
};
|
|
|
|
if (proto.Sprite != null)
|
|
{
|
|
var tex = new TextureRect
|
|
{
|
|
VerticalAlignment = VAlignment.Center,
|
|
HorizontalAlignment = HAlignment.Center,
|
|
Texture = GetSprite(proto.Sprite),
|
|
TextureScale = new Vector2(2f, 2f),
|
|
};
|
|
|
|
button.AddChild(tex);
|
|
}
|
|
parent.AddChild(button);
|
|
|
|
// Ensure that the button that transitions the menu to the associated category layer
|
|
// is visible in the main radial container (as these all start with Visible = false)
|
|
foreach (var child in main.Children)
|
|
{
|
|
var castChild = child as RadialMenuTextureButton;
|
|
|
|
if (castChild is not RadialMenuTextureButton)
|
|
continue;
|
|
|
|
if (castChild.TargetLayer == proto.Category)
|
|
{
|
|
castChild.Visible = true;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
// Set up menu actions
|
|
foreach (var child in Children)
|
|
AddRCDMenuButtonOnClickActions(child);
|
|
|
|
OnChildAdded += AddRCDMenuButtonOnClickActions;
|
|
|
|
SendRCDSystemMessageAction += bui.SendRCDSystemMessage;
|
|
}
|
|
|
|
private void SetupCategories(RadialContainer main, RCDComponent rcd)
|
|
{
|
|
foreach (var categoryId in rcd.CategoryPrototypes)
|
|
{
|
|
if (!_protoManager.TryIndex(categoryId, out var category))
|
|
continue;
|
|
|
|
var button = new RadialMenuTextureButton
|
|
{
|
|
StyleClasses = { "RadialMenuButton" },
|
|
SetSize = new Vector2(64f, 64f),
|
|
ToolTip = Loc.GetString(category.TooltipBase + categoryId), // rcd-component- + WindowsAndGrilles = rcd-component-WindowsAndGrilles
|
|
TargetLayer = categoryId,
|
|
Visible = false,
|
|
};
|
|
|
|
var texture = new TextureRect
|
|
{
|
|
VerticalAlignment = VAlignment.Center,
|
|
HorizontalAlignment = HAlignment.Center,
|
|
TextureScale = new Vector2(2, 2),
|
|
Texture = GetSprite(category.SpritePath)
|
|
};
|
|
|
|
button.AddChild(texture);
|
|
main.AddChild(button);
|
|
|
|
var container = new RadialContainer
|
|
{
|
|
Name = categoryId,
|
|
VerticalExpand = true,
|
|
HorizontalExpand = true,
|
|
Radius = 64
|
|
};
|
|
|
|
AddChild(container);
|
|
}
|
|
}
|
|
|
|
private Texture GetSprite(SpriteSpecifier specifier)
|
|
{
|
|
return _spriteSystem.Frame0(specifier);
|
|
}
|
|
|
|
private void AddRCDMenuButtonOnClickActions(Control control)
|
|
{
|
|
var radialContainer = control as RadialContainer;
|
|
|
|
if (radialContainer == null)
|
|
return;
|
|
|
|
foreach (var child in radialContainer.Children)
|
|
{
|
|
var castChild = child as RCDMenuButton;
|
|
|
|
if (castChild == null)
|
|
continue;
|
|
|
|
castChild.OnButtonUp += _ =>
|
|
{
|
|
SendRCDSystemMessageAction?.Invoke(castChild.ProtoId);
|
|
|
|
if (_playerManager.LocalSession?.AttachedEntity != null &&
|
|
_protoManager.TryIndex(castChild.ProtoId, out var proto))
|
|
{
|
|
var msg = Loc.GetString("rcd-component-change-mode", ("mode", Loc.GetString(proto.Name)));
|
|
|
|
if (proto.Mode == RcdMode.ConstructTile || proto.Mode == RcdMode.ConstructObject)
|
|
{
|
|
var name = Loc.GetString(proto.Name);
|
|
|
|
if (proto.Prototype != null &&
|
|
_protoManager.TryIndex(proto.Prototype, out var entProto))
|
|
name = entProto.Name;
|
|
|
|
msg = Loc.GetString("rcd-component-change-build-mode", ("name", name));
|
|
}
|
|
|
|
// Popup message
|
|
_popup.PopupClient(msg, _owner, _playerManager.LocalSession.AttachedEntity);
|
|
}
|
|
|
|
Close();
|
|
};
|
|
}
|
|
}
|
|
}
|
|
|
|
public sealed class RCDMenuButton : RadialMenuTextureButton
|
|
{
|
|
public ProtoId<RCDPrototype> ProtoId { get; set; }
|
|
|
|
public RCDMenuButton()
|
|
{
|
|
|
|
}
|
|
}
|