mirror of
https://github.com/WWhiteDreamProject/wwdpublic.git
synced 2026-04-16 21:17:39 +03:00
* fix: thermals and night vision now work * fix: it has to be this way Signed-off-by: Remuchi <RemuchiOfficial@gmail.com> * fix: I hate the way they are separated * fix: now cult actions close examine menu (#1046) Signed-off-by: Remuchi <RemuchiOfficial@gmail.com> * fix: railins and some other things now dont snap to south upon being built (#1029) * fix: who did this translation wtf * fix: assball bat can now wideswing (#1030) Signed-off-by: Remuchi <RemuchiOfficial@gmail.com> * fix: spend flares are actually spent now (#959) Signed-off-by: Remuchi <RemuchiOfficial@gmail.com> * fix: made part exchange system a bit less shitty I really have no time or interest in it to rewrite it completely rn Signed-off-by: Remuchi <RemuchiOfficial@gmail.com> * fix: fixed cult factories timers being broken Also fixed them being openable by anyone. Signed-off-by: Remuchi <RemuchiOfficial@gmail.com> * Apply suggestions from code review Co-authored-by: Spatison <137375981+Spatison@users.noreply.github.com> Co-authored-by: RedFoxIV <38788538+RedFoxIV@users.noreply.github.com> --------- Signed-off-by: Remuchi <RemuchiOfficial@gmail.com> Co-authored-by: Spatison <137375981+Spatison@users.noreply.github.com> Co-authored-by: RedFoxIV <38788538+RedFoxIV@users.noreply.github.com>
158 lines
4.9 KiB
C#
158 lines
4.9 KiB
C#
using System.Linq;
|
|
using System.Numerics;
|
|
using Content.Client.UserInterface.Controls;
|
|
using Content.Shared.Construction.Prototypes;
|
|
using Content.Shared.RadialSelector;
|
|
using Robust.Client.GameObjects;
|
|
using Robust.Client.Graphics;
|
|
using Robust.Client.ResourceManagement;
|
|
using Robust.Client.UserInterface;
|
|
using Robust.Client.UserInterface.Controls;
|
|
using Robust.Shared.Prototypes;
|
|
|
|
// ReSharper disable InconsistentNaming
|
|
// White Dream Code but moved to general folder for consistency
|
|
|
|
namespace Content.Client.RadialSelector;
|
|
|
|
public abstract class BasedRadialSelectorMenuBUI : BoundUserInterface
|
|
{
|
|
[Dependency] protected readonly IPrototypeManager ProtoManager = default!;
|
|
[Dependency] protected readonly IResourceCache Resources = default!;
|
|
|
|
protected readonly SpriteSystem _spriteSystem;
|
|
|
|
// Used to clearing on state changing
|
|
private readonly HashSet<RadialContainer> _cachedContainers = new();
|
|
|
|
private readonly Vector2 ItemSize = Vector2.One * 64;
|
|
|
|
protected BasedRadialSelectorMenuBUI(EntityUid owner, Enum uiKey) : base(owner, uiKey)
|
|
{
|
|
_spriteSystem = EntMan.System<SpriteSystem>();
|
|
}
|
|
|
|
protected void CreateMenu(List<RadialSelectorEntry> entries, RadialMenu menu, string parentCategory = "")
|
|
{
|
|
var container = new RadialContainer
|
|
{
|
|
Name = !string.IsNullOrEmpty(parentCategory) ? parentCategory : "Main",
|
|
};
|
|
|
|
menu.AddChild(container);
|
|
_cachedContainers.Add(container);
|
|
|
|
foreach (var entry in entries)
|
|
{
|
|
if (entry.Category != null)
|
|
{
|
|
var button = CreateButton(entry.Category.Name, _spriteSystem.Frame0(entry.Category.Icon));
|
|
button.TargetLayer = entry.Category.Name;
|
|
CreateMenu(entry.Category.Entries, menu, entry.Category.Name);
|
|
container.AddChild(button);
|
|
}
|
|
else if (entry.Prototype != null)
|
|
{
|
|
var name = GetName(entry.Prototype);
|
|
var icon = GetTextures(entry);
|
|
var button = CreateButton(name, icon);
|
|
button.OnButtonUp += _ =>
|
|
{
|
|
var msg = new RadialSelectorSelectedMessage(entry.Prototype);
|
|
SendPredictedMessage(msg);
|
|
};
|
|
|
|
container.AddChild(button);
|
|
}
|
|
}
|
|
}
|
|
|
|
private string GetName(string proto)
|
|
{
|
|
if (ProtoManager.TryIndex(proto, out var prototype))
|
|
return prototype.Name;
|
|
|
|
if (ProtoManager.TryIndex(proto, out ConstructionPrototype? constructionPrototype))
|
|
return constructionPrototype.Name;
|
|
|
|
return proto;
|
|
}
|
|
|
|
private List<Texture> GetTextures(RadialSelectorEntry entry)
|
|
{
|
|
var result = new List<Texture>();
|
|
if (entry.Icon is not null)
|
|
{
|
|
result.Add(_spriteSystem.Frame0(entry.Icon));
|
|
return result;
|
|
}
|
|
|
|
if (ProtoManager.TryIndex(entry.Prototype!, out var prototype))
|
|
{
|
|
result.AddRange(SpriteComponent.GetPrototypeTextures(prototype, Resources).Select(o => o.Default));
|
|
return result;
|
|
}
|
|
|
|
if (ProtoManager.TryIndex(entry.Prototype!, out ConstructionPrototype? constructionProto))
|
|
{
|
|
result.Add(_spriteSystem.Frame0(constructionProto.Icon));
|
|
return result;
|
|
}
|
|
|
|
// No icons provided and no icons found in prototypes. There's nothing we can do.
|
|
return result;
|
|
}
|
|
|
|
private RadialMenuTextureButton CreateButton(string name, Texture icon)
|
|
{
|
|
var button = new RadialMenuTextureButton
|
|
{
|
|
ToolTip = Loc.GetString(name),
|
|
StyleClasses = { "RadialMenuButton" },
|
|
SetSize = ItemSize
|
|
};
|
|
|
|
var iconScale = ItemSize / icon.Size;
|
|
var texture = new TextureRect
|
|
{
|
|
VerticalAlignment = Control.VAlignment.Center,
|
|
HorizontalAlignment = Control.HAlignment.Center,
|
|
Texture = icon,
|
|
TextureScale = iconScale
|
|
};
|
|
|
|
button.AddChild(texture);
|
|
return button;
|
|
}
|
|
|
|
private RadialMenuTextureButton CreateButton(string name, List<Texture> icons)
|
|
{
|
|
var button = new RadialMenuTextureButton
|
|
{
|
|
ToolTip = Loc.GetString(name),
|
|
StyleClasses = { "RadialMenuButton" },
|
|
SetSize = ItemSize
|
|
};
|
|
|
|
var iconScale = ItemSize / icons[0].Size;
|
|
var texture = new LayeredTextureRect
|
|
{
|
|
VerticalAlignment = Control.VAlignment.Center,
|
|
HorizontalAlignment = Control.HAlignment.Center,
|
|
Textures = icons,
|
|
TextureScale = iconScale
|
|
};
|
|
|
|
button.AddChild(texture);
|
|
return button;
|
|
}
|
|
|
|
protected void ClearExistingContainers(RadialMenu menu)
|
|
{
|
|
foreach (var container in _cachedContainers)
|
|
menu.RemoveChild(container);
|
|
|
|
_cachedContainers.Clear();
|
|
}
|
|
}
|