CatStation/Content.Client/MapText/MapTextSystem.cs
Whatstone f42f8df6d1
Cleanup: ProtoMan Part 2 - remove Client and Server EntitySystem IPrototypeManager instances (#44416)
* Remove all IPrototypeManager instances

* Remove redundant IComponentFactory instances too

* Found some stragglers

* DestructibleSystem.PrototypeManager: no dependency

* not based
2026-06-29 21:33:56 +00:00

79 lines
3 KiB
C#

using Content.Shared.MapText;
using Robust.Client.Graphics;
using Robust.Client.ResourceManagement;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.RichText;
using Robust.Shared.Configuration;
using Robust.Shared.GameStates;
using Robust.Shared.Utility;
namespace Content.Client.MapText;
/// <inheritdoc/>
public sealed partial class MapTextSystem : SharedMapTextSystem
{
[Dependency] private IConfigurationManager _configManager = default!;
[Dependency] private IUserInterfaceManager _uiManager = default!;
[Dependency] private SharedTransformSystem _transform = default!;
[Dependency] private IResourceCache _resourceCache = default!;
[Dependency] private IOverlayManager _overlayManager = default!;
private MapTextOverlay _overlay = default!;
/// <inheritdoc/>
public override void Initialize()
{
SubscribeLocalEvent<MapTextComponent, ComponentStartup>(OnComponentStartup);
SubscribeLocalEvent<MapTextComponent, ComponentHandleState>(HandleCompState);
_overlay = new MapTextOverlay(_configManager, EntityManager, _uiManager, _transform, _resourceCache, ProtoMan);
_overlayManager.AddOverlay(_overlay);
// TODO move font prototype to robust.shared, then use ProtoId<FontPrototype>
DebugTools.Assert(ProtoMan.HasIndex<FontPrototype>(SharedMapTextComponent.DefaultFont));
}
private void OnComponentStartup(Entity<MapTextComponent> ent, ref ComponentStartup args)
{
CacheText(ent.Comp);
// TODO move font prototype to robust.shared, then use ProtoId<FontPrototype>
DebugTools.Assert(ProtoMan.HasIndex<FontPrototype>(ent.Comp.FontId));
}
private void HandleCompState(Entity<MapTextComponent> ent, ref ComponentHandleState args)
{
if (args.Current is not MapTextComponentState state)
return;
ent.Comp.Text = state.Text;
ent.Comp.LocText = state.LocText;
ent.Comp.Color = state.Color;
ent.Comp.FontId = state.FontId;
ent.Comp.FontSize = state.FontSize;
ent.Comp.Offset = state.Offset;
CacheText(ent.Comp);
}
private void CacheText(MapTextComponent component)
{
component.CachedFont = null;
component.CachedText = string.IsNullOrWhiteSpace(component.Text)
? Loc.GetString(component.LocText)
: component.Text;
if (!ProtoMan.TryIndex<FontPrototype>(component.FontId, out var fontPrototype))
{
component.CachedText = Loc.GetString("map-text-font-error");
component.Color = Color.Red;
if (ProtoMan.TryIndex<FontPrototype>(SharedMapTextComponent.DefaultFont, out var @default))
component.CachedFont = new VectorFont(_resourceCache.GetResource<FontResource>(@default.Path), 14);
return;
}
var fontResource = _resourceCache.GetResource<FontResource>(fontPrototype.Path);
component.CachedFont = new VectorFont(fontResource, component.FontSize);
}
}