forked from SpaceStation14-Shenanigans/Monolith
a75a27b456
Co-authored-by: Moony <moony@hellomouse.net> Co-authored-by: J <billsmith116@gmail.com> Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> Co-authored-by: Tayrtahn <tayrtahn@gmail.com> Co-authored-by: chromiumboy <50505512+chromiumboy@users.noreply.github.com> Co-authored-by: SlamBamActionman <83650252+SlamBamActionman@users.noreply.github.com> Co-authored-by: Kyle Tyo <36606155+VerinSenpai@users.noreply.github.com> Co-authored-by: Nemanja <98561806+EmoGarbage404@users.noreply.github.com> Co-authored-by: Cojoke <83733158+Cojoke-dot@users.noreply.github.com> Co-authored-by: Pieter-Jan Briers <pieterjan.briers+git@gmail.com> Co-authored-by: TemporalOroboros <TemporalOroboros@gmail.com> Co-authored-by: Lordbrandon12 <107556696+Lordbrandon12@users.noreply.github.com> Co-authored-by: Perry Fraser <perryprog@users.noreply.github.com> Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com> Co-authored-by: Princess Cheeseballs <66055347+Pronana@users.noreply.github.com> Co-authored-by: ArtisticRoomba <145879011+ArtisticRoomba@users.noreply.github.com> Co-authored-by: Krunklehorn <42424291+Krunklehorn@users.noreply.github.com> Co-authored-by: Leon Friedrich <60421075+ElectroJr@users.noreply.github.com> Co-authored-by: paige404 <59348003+paige404@users.noreply.github.com> Co-authored-by: ElectroJr <leonsfriedrich@gmail.com> Co-authored-by: M4rchy-S <89603088+M4rchy-S@users.noreply.github.com> Co-authored-by: Princess Cheeseballs <66055347+Princess-Cheeseballs@users.noreply.github.com> Co-authored-by: Connor Huffine <chuffine@gmail.com> Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com> Co-authored-by: Whatstone <166147148+whatston3@users.noreply.github.com> Co-authored-by: Errant <35878406+Errant-4@users.noreply.github.com> Co-authored-by: Schrödinger <132720404+Schrodinger71@users.noreply.github.com> Co-authored-by: Samuka-C <47865393+Samuka-C@users.noreply.github.com> Co-authored-by: Milon <milonpl.git@proton.me> Co-authored-by: ScarKy0 <scarky0@onet.eu> Co-authored-by: beck-thompson <107373427+beck-thompson@users.noreply.github.com> Co-authored-by: psykana <36602558+psykana@users.noreply.github.com> Co-authored-by: thetuerk <46725294+ThanosDeGraf@users.noreply.github.com> Co-authored-by: ScarKy0 <106310278+ScarKy0@users.noreply.github.com> Co-authored-by: Ed <96445749+TheShuEd@users.noreply.github.com> Co-authored-by: MilenVolf <63782763+MilenVolf@users.noreply.github.com> Co-authored-by: YotaXP <yotaxp+git@gmail.com> Co-authored-by: BarryNorfolk <barrynorfolkman@protonmail.com> Co-authored-by: JesterX666 <32009105+JesterX666@users.noreply.github.com> Co-authored-by: mtrs163 <153596133+mtrs163@users.noreply.github.com> Co-authored-by: IProduceWidgets <107586145+IProduceWidgets@users.noreply.github.com>
82 lines
3.1 KiB
C#
82 lines
3.1 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.Prototypes;
|
|
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 IPrototypeManager _prototypeManager = 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, _prototypeManager);
|
|
_overlayManager.AddOverlay(_overlay);
|
|
|
|
// TODO move font prototype to robust.shared, then use ProtoId<FontPrototype>
|
|
DebugTools.Assert(_prototypeManager.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(_prototypeManager.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 (!_prototypeManager.TryIndex<FontPrototype>(component.FontId, out var fontPrototype))
|
|
{
|
|
component.CachedText = Loc.GetString("map-text-font-error");
|
|
component.Color = Color.Red;
|
|
|
|
if(_prototypeManager.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);
|
|
}
|
|
}
|