From 2325a7df9407998ac92df8894663591d85ed9cfc Mon Sep 17 00:00:00 2001 From: Flipp Syder <76629141+vulppine@users.noreply.github.com> Date: Thu, 28 Apr 2022 05:23:45 -0700 Subject: [PATCH] Rainbow crayon + color-selectable crayons (#7786) --- .../Crayon/CrayonDecalVisualizer.cs | 0 .../Crayon/UI/CrayonBoundUserInterface.cs | 5 +++ Content.Client/Crayon/UI/CrayonWindow.xaml | 1 + Content.Client/Crayon/UI/CrayonWindow.xaml.cs | 17 ++++++++ Content.Server/Crayon/CrayonComponent.cs | 4 ++ Content.Server/Crayon/CrayonSystem.cs | 43 ++++++++++++++++++- .../Crayon/SharedCrayonComponent.cs | 14 +++++- .../Fills/Backpacks/StarterGear/backpack.yml | 1 + .../Entities/Objects/Fun/crayons.yml | 23 ++++++++++ 9 files changed, 105 insertions(+), 3 deletions(-) delete mode 100644 Content.Client/Crayon/CrayonDecalVisualizer.cs diff --git a/Content.Client/Crayon/CrayonDecalVisualizer.cs b/Content.Client/Crayon/CrayonDecalVisualizer.cs deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/Content.Client/Crayon/UI/CrayonBoundUserInterface.cs b/Content.Client/Crayon/UI/CrayonBoundUserInterface.cs index bd69d867a4..cce8d205cf 100644 --- a/Content.Client/Crayon/UI/CrayonBoundUserInterface.cs +++ b/Content.Client/Crayon/UI/CrayonBoundUserInterface.cs @@ -40,6 +40,11 @@ namespace Content.Client.Crayon.UI SendMessage(new CrayonSelectMessage(state)); } + public void SelectColor(string color) + { + SendMessage(new CrayonColorMessage(color)); + } + protected override void Dispose(bool disposing) { base.Dispose(disposing); diff --git a/Content.Client/Crayon/UI/CrayonWindow.xaml b/Content.Client/Crayon/UI/CrayonWindow.xaml index 6289150b6e..7729318ae7 100644 --- a/Content.Client/Crayon/UI/CrayonWindow.xaml +++ b/Content.Client/Crayon/UI/CrayonWindow.xaml @@ -3,6 +3,7 @@ MinSize="250 300" SetSize="250 300"> + diff --git a/Content.Client/Crayon/UI/CrayonWindow.xaml.cs b/Content.Client/Crayon/UI/CrayonWindow.xaml.cs index 0fac212c08..3a3608e7b1 100644 --- a/Content.Client/Crayon/UI/CrayonWindow.xaml.cs +++ b/Content.Client/Crayon/UI/CrayonWindow.xaml.cs @@ -30,6 +30,16 @@ namespace Content.Client.Crayon.UI Owner = owner; Search.OnTextChanged += _ => RefreshList(); + ColorSelector.OnColorChanged += SelectColor; + } + + private void SelectColor(Color color) + { + _color = color; + + Owner.SelectColor(color.ToHex()); + + RefreshList(); } private void RefreshList() @@ -86,7 +96,14 @@ namespace Content.Client.Crayon.UI public void UpdateState(CrayonBoundUserInterfaceState state) { _selected = state.Selected; + ColorSelector.Visible = state.SelectableColor; _color = state.Color; + + if (ColorSelector.Visible) + { + ColorSelector.Color = state.Color; + } + RefreshList(); } diff --git a/Content.Server/Crayon/CrayonComponent.cs b/Content.Server/Crayon/CrayonComponent.cs index fbbeb4b3f0..fbecdc6083 100644 --- a/Content.Server/Crayon/CrayonComponent.cs +++ b/Content.Server/Crayon/CrayonComponent.cs @@ -18,6 +18,10 @@ namespace Content.Server.Crayon [ViewVariables] public Color Color { get; private set; } + [ViewVariables(VVAccess.ReadWrite)] + [DataField("selectableColor")] + public bool SelectableColor { get; set; } + [ViewVariables(VVAccess.ReadWrite)] public int Charges { get; set; } diff --git a/Content.Server/Crayon/CrayonSystem.cs b/Content.Server/Crayon/CrayonSystem.cs index 2ec5ac4934..e680a21574 100644 --- a/Content.Server/Crayon/CrayonSystem.cs +++ b/Content.Server/Crayon/CrayonSystem.cs @@ -33,6 +33,7 @@ public sealed class CrayonSystem : EntitySystem base.Initialize(); SubscribeLocalEvent(OnCrayonInit); SubscribeLocalEvent(OnCrayonBoundUI); + SubscribeLocalEvent(OnCrayonBoundUIColor); SubscribeLocalEvent(OnCrayonUse); SubscribeLocalEvent(OnCrayonAfterInteract); SubscribeLocalEvent(OnCrayonDropped); @@ -67,7 +68,21 @@ public sealed class CrayonSystem : EntitySystem return; } - if(!_decals.TryAddDecal(component.SelectedState, args.ClickLocation.Offset(new Vector2(-0.5f,-0.5f)), out _, Color.FromName(component._color), cleanable: true)) + Color color = Color.White; + if (Color.TryFromName(component._color, out var namedColor)) + { + color = namedColor; + } + else + { + var hexColor = Color.TryFromHex(component._color); + if (hexColor != null) + { + color = (Color) hexColor; + } + } + + if(!_decals.TryAddDecal(component.SelectedState, args.ClickLocation.Offset(new Vector2(-0.5f,-0.5f)), out _, color, cleanable: true)) return; if (component.UseSound != null) @@ -96,7 +111,7 @@ public sealed class CrayonSystem : EntitySystem if (component.UserInterface?.SessionHasOpen(actor.PlayerSession) == true) { // Tell the user interface the selected stuff - component.UserInterface.SetState(new CrayonBoundUserInterfaceState(component.SelectedState, component.Color)); + component.UserInterface.SetState(new CrayonBoundUserInterfaceState(component.SelectedState, component.SelectableColor, component.Color)); } args.Handled = true; @@ -108,9 +123,33 @@ public sealed class CrayonSystem : EntitySystem if (!_prototypeManager.TryIndex(args.State, out var prototype) || !prototype.Tags.Contains("crayon")) return; component.SelectedState = args.State; + Dirty(component); } + private void OnCrayonBoundUIColor(EntityUid uid, CrayonComponent component, CrayonColorMessage args) + { + // you still need to ensure that the given color is a valid color + if (component.SelectableColor && args.Color != component._color) + { + if (Color.TryFromName(component._color, out var namedColor)) + { + component._color = args.Color; + } + else + { + var hexColor = Color.TryFromHex(component._color); + if (hexColor != null) + { + component._color = args.Color; + } + } + + Dirty(component); + } + + } + private void OnCrayonInit(EntityUid uid, CrayonComponent component, ComponentInit args) { component.Charges = component.Capacity; diff --git a/Content.Shared/Crayon/SharedCrayonComponent.cs b/Content.Shared/Crayon/SharedCrayonComponent.cs index daac686f88..1a5d62a675 100644 --- a/Content.Shared/Crayon/SharedCrayonComponent.cs +++ b/Content.Shared/Crayon/SharedCrayonComponent.cs @@ -31,6 +31,16 @@ namespace Content.Shared.Crayon } } + [Serializable, NetSerializable] + public sealed class CrayonColorMessage : BoundUserInterfaceMessage + { + public readonly string Color; + public CrayonColorMessage(string color) + { + Color = color; + } + } + [Serializable, NetSerializable] public enum CrayonVisuals { @@ -58,11 +68,13 @@ namespace Content.Shared.Crayon public sealed class CrayonBoundUserInterfaceState : BoundUserInterfaceState { public string Selected; + public bool SelectableColor; public Color Color; - public CrayonBoundUserInterfaceState(string selected, Color color) + public CrayonBoundUserInterfaceState(string selected, bool selectableColor, Color color) { Selected = selected; + SelectableColor = selectableColor; Color = color; } } diff --git a/Resources/Prototypes/Catalog/Fills/Backpacks/StarterGear/backpack.yml b/Resources/Prototypes/Catalog/Fills/Backpacks/StarterGear/backpack.yml index 1350e17e3a..53a7ee9760 100644 --- a/Resources/Prototypes/Catalog/Fills/Backpacks/StarterGear/backpack.yml +++ b/Resources/Prototypes/Catalog/Fills/Backpacks/StarterGear/backpack.yml @@ -28,6 +28,7 @@ contents: - id: BoxHug - id: RubberStampClown + - id: CrayonRainbow - type: entity noSpawn: true diff --git a/Resources/Prototypes/Entities/Objects/Fun/crayons.yml b/Resources/Prototypes/Entities/Objects/Fun/crayons.yml index 23ea9f0f35..fd39c9fe31 100644 --- a/Resources/Prototypes/Entities/Objects/Fun/crayons.yml +++ b/Resources/Prototypes/Entities/Objects/Fun/crayons.yml @@ -65,6 +65,29 @@ - Recyclable - Trash +- type: entity + parent: Crayon + id: CrayonRainbow + name: rainbow crayon + components: + - type: Sprite + sprite: Objects/Fun/crayons.rsi + state: rainbow + - type: Item + sprite: Objects/Fun/crayons.rsi + size: 1 + HeldPrefix: rainbow + - type: Crayon + color: Red + selectableColor: true + capacity: 30 + - type: Tag + tags: + - Write + - Crayon + - Recyclable + - Trash + - type: entity parent: Crayon id: CrayonBlack