Files
tbd-station-14/Content.Client/SprayPainter/SprayPainterSystem.cs
Whatstone 9ad99cfa64 Make more objects spray paintable (Reviving #31328) (#37341)
* PaintableAirlockComponent and AirlockGroupPrototype have been replaced

* Slightly redesigned SprayPainterSystem for greater versatility

* Added handling of changes to the appearance of doors and storages

* PaintableGroup prototypes have been created

* Generating tabs with styles in the UI

* Fix error with undiscovered layer

* Slight improvement

* Removed unnecessary property

* The category for `PaintableGroup` was allocated to a separate prototype so that the engine itself would check if the category existed

* Added canisters, but repainting doesn't work

* Added localization to styles

* Fix sprite changing

* Added the ability to paint canisters

* slight ui improvement

* Fix yamllinter errors

* Fix test

* The UI now remembers which tab was open

* Fix build (?)

* Rename

* Charges have been added to the spray painter

* Added a charge texture for the spray painter

* Now spray painter can paint decals

* Increased number of charges

* Spawning dummy objects has been replaced by PrototypeManager

* added a signature about the painting of the object

* fix

* Code commenting

* Fix upstream

* Update Content.Shared/SprayPainter/Components/SprayPainterAmmo.cs

Co-authored-by: pathetic meowmeow <uhhadd@gmail.com>

* review

* Now decals can only be painted if the corresponding tab in the menu is open.

* Fixed a bug with pipe and decal tabs not being remembered

* Update EntityStorageVisualizerSystem.cs

* record

* loc

* Cleanup

* Revert electrified visuals

* more cleanup, fix charges, del ammo4

* no empty file, remove meta component

* closet exceptions, storage visualizer fixes

* enable/disable decal through alt-verb

* Fix missed merge conflicts

* fix snap offset, button event handlers

* simpler order, fix snap loc string

* Remove PaintableViz.BaseRSI, no decal item, A-Z

* State-respecting UI, BUI updates, FTL fixes

* revert DecalPlacerWindow changes

* revert unwanted changes, cleanup function order

* Limit SprayPainterAmmo write access to AmmoSystem

* Remove PaintedSystem

* spray paint ammo lathe recipe, youtool listing

* category as a list, groups as subtabs

* Restore inhand copyright in meta.json

* empty spray painter, recipe produces an empty one

* allow alpha on spray painter decals

* add comments

* paintable wall lockers

* Restrict painting more objects

* Suggested event changes, event cleanup

* component comments, fix ammo inhands

* uncleanable decals, dirty styles on mapinit

* organize paintables, separate emergency/closet grp

* fix categories newline at EOF

* airlock group whitespace cleanup

* realphabetize

* Clean up EntityStorageViz merge conflict markers

* Apply requested changes

* Apply suggestions from sowelipililimute's review

Co-authored-by: pathetic meowmeow <uhhadd@gmail.com>

* betrayal most foul

* Remove members from EntityPaintedEvent

* No emerg. group, steelsec to secure, locker/closet

* Enable repainting the medical wall locker

* comments, no flags on PaintableVisuals

* Remove locked variants from closets/wall closets

* removable decals

* off value consistency

* can't paint away those bones

* fix precedence

* Remove AirlockDepartment, AirlockGroup protos

Both unused.

* whitelist consistency re: ammo component

* add standing emergency closet styles

* alphabetize the spray painter listings

---------

Co-authored-by: Ertanic <black.ikra.14@gmail.com>
Co-authored-by: Эдуард <36124833+Ertanic@users.noreply.github.com>
Co-authored-by: pathetic meowmeow <uhhadd@gmail.com>
2025-07-10 20:36:57 -04:00

130 lines
4.4 KiB
C#

using System.Linq;
using Content.Client.Items;
using Content.Client.Message;
using Content.Client.Stylesheets;
using Content.Shared.Decals;
using Content.Shared.SprayPainter;
using Content.Shared.SprayPainter.Components;
using Content.Shared.SprayPainter.Prototypes;
using Robust.Client.GameObjects;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Shared.Prototypes;
using Robust.Shared.Timing;
using Robust.Shared.Utility;
namespace Content.Client.SprayPainter;
/// <summary>
/// Client-side spray painter functions. Caches information for spray painter windows and updates the UI to reflect component state.
/// </summary>
public sealed class SprayPainterSystem : SharedSprayPainterSystem
{
[Dependency] private readonly UserInterfaceSystem _ui = default!;
public List<SprayPainterDecalEntry> Decals = [];
public Dictionary<string, List<string>> PaintableGroupsByCategory = new();
public Dictionary<string, Dictionary<string, EntProtoId>> PaintableStylesByGroup = new();
public override void Initialize()
{
base.Initialize();
Subs.ItemStatus<SprayPainterComponent>(ent => new StatusControl(ent));
SubscribeLocalEvent<SprayPainterComponent, AfterAutoHandleStateEvent>(OnStateUpdate);
SubscribeLocalEvent<PrototypesReloadedEventArgs>(OnPrototypesReloaded);
CachePrototypes();
}
private void OnStateUpdate(Entity<SprayPainterComponent> ent, ref AfterAutoHandleStateEvent args)
{
UpdateUi(ent);
}
protected override void UpdateUi(Entity<SprayPainterComponent> ent)
{
if (_ui.TryGetOpenUi(ent.Owner, SprayPainterUiKey.Key, out var bui))
bui.Update();
}
private void OnPrototypesReloaded(PrototypesReloadedEventArgs args)
{
if (!args.WasModified<PaintableGroupCategoryPrototype>() || !args.WasModified<PaintableGroupPrototype>() || !args.WasModified<DecalPrototype>())
return;
CachePrototypes();
}
private void CachePrototypes()
{
PaintableGroupsByCategory.Clear();
PaintableStylesByGroup.Clear();
foreach (var category in Proto.EnumeratePrototypes<PaintableGroupCategoryPrototype>().OrderBy(x => x.ID))
{
var groupList = new List<string>();
foreach (var groupId in category.Groups)
{
if (!Proto.TryIndex(groupId, out var group))
continue;
groupList.Add(groupId);
PaintableStylesByGroup[groupId] = group.Styles;
}
if (groupList.Count > 0)
PaintableGroupsByCategory[category.ID] = groupList;
}
Decals.Clear();
foreach (var decalPrototype in Proto.EnumeratePrototypes<DecalPrototype>().OrderBy(x => x.ID))
{
if (!decalPrototype.Tags.Contains("station")
&& !decalPrototype.Tags.Contains("markings")
|| decalPrototype.Tags.Contains("dirty"))
continue;
Decals.Add(new SprayPainterDecalEntry(decalPrototype.ID, decalPrototype.Sprite));
}
}
private sealed class StatusControl : Control
{
private readonly RichTextLabel _label;
private readonly Entity<SprayPainterComponent> _entity;
private DecalPaintMode? _lastPaintingDecals = null;
public StatusControl(Entity<SprayPainterComponent> ent)
{
_entity = ent;
_label = new RichTextLabel { StyleClasses = { StyleNano.StyleClassItemStatus } };
AddChild(_label);
}
protected override void FrameUpdate(FrameEventArgs args)
{
base.FrameUpdate(args);
if (_entity.Comp.DecalMode == _lastPaintingDecals)
return;
_lastPaintingDecals = _entity.Comp.DecalMode;
string modeLocString = _entity.Comp.DecalMode switch
{
DecalPaintMode.Add => "spray-painter-item-status-add",
DecalPaintMode.Remove => "spray-painter-item-status-remove",
_ => "spray-painter-item-status-off"
};
_label.SetMarkupPermissive(Robust.Shared.Localization.Loc.GetString("spray-painter-item-status-label",
("mode", Robust.Shared.Localization.Loc.GetString(modeLocString))));
}
}
}
/// <summary>
/// A spray paintable decal, mapped by ID.
/// </summary>
public sealed record SprayPainterDecalEntry(string Name, SpriteSpecifier Sprite);