Rainbow crayon + color-selectable crayons (#7786)

This commit is contained in:
Flipp Syder
2022-04-28 05:23:45 -07:00
committed by GitHub
parent 4c9e45a480
commit 2325a7df94
9 changed files with 105 additions and 3 deletions

View File

@@ -40,6 +40,11 @@ namespace Content.Client.Crayon.UI
SendMessage(new CrayonSelectMessage(state)); SendMessage(new CrayonSelectMessage(state));
} }
public void SelectColor(string color)
{
SendMessage(new CrayonColorMessage(color));
}
protected override void Dispose(bool disposing) protected override void Dispose(bool disposing)
{ {
base.Dispose(disposing); base.Dispose(disposing);

View File

@@ -3,6 +3,7 @@
MinSize="250 300" MinSize="250 300"
SetSize="250 300"> SetSize="250 300">
<BoxContainer Orientation="Vertical"> <BoxContainer Orientation="Vertical">
<ColorSelectorSliders Name="ColorSelector" Visible="False" />
<LineEdit Name="Search" /> <LineEdit Name="Search" />
<ScrollContainer VerticalExpand="True"> <ScrollContainer VerticalExpand="True">
<GridContainer Name="Grid" Columns="6"> <GridContainer Name="Grid" Columns="6">

View File

@@ -30,6 +30,16 @@ namespace Content.Client.Crayon.UI
Owner = owner; Owner = owner;
Search.OnTextChanged += _ => RefreshList(); Search.OnTextChanged += _ => RefreshList();
ColorSelector.OnColorChanged += SelectColor;
}
private void SelectColor(Color color)
{
_color = color;
Owner.SelectColor(color.ToHex());
RefreshList();
} }
private void RefreshList() private void RefreshList()
@@ -86,7 +96,14 @@ namespace Content.Client.Crayon.UI
public void UpdateState(CrayonBoundUserInterfaceState state) public void UpdateState(CrayonBoundUserInterfaceState state)
{ {
_selected = state.Selected; _selected = state.Selected;
ColorSelector.Visible = state.SelectableColor;
_color = state.Color; _color = state.Color;
if (ColorSelector.Visible)
{
ColorSelector.Color = state.Color;
}
RefreshList(); RefreshList();
} }

View File

@@ -18,6 +18,10 @@ namespace Content.Server.Crayon
[ViewVariables] [ViewVariables]
public Color Color { get; private set; } public Color Color { get; private set; }
[ViewVariables(VVAccess.ReadWrite)]
[DataField("selectableColor")]
public bool SelectableColor { get; set; }
[ViewVariables(VVAccess.ReadWrite)] [ViewVariables(VVAccess.ReadWrite)]
public int Charges { get; set; } public int Charges { get; set; }

View File

@@ -33,6 +33,7 @@ public sealed class CrayonSystem : EntitySystem
base.Initialize(); base.Initialize();
SubscribeLocalEvent<CrayonComponent, ComponentInit>(OnCrayonInit); SubscribeLocalEvent<CrayonComponent, ComponentInit>(OnCrayonInit);
SubscribeLocalEvent<CrayonComponent, CrayonSelectMessage>(OnCrayonBoundUI); SubscribeLocalEvent<CrayonComponent, CrayonSelectMessage>(OnCrayonBoundUI);
SubscribeLocalEvent<CrayonComponent, CrayonColorMessage>(OnCrayonBoundUIColor);
SubscribeLocalEvent<CrayonComponent, UseInHandEvent>(OnCrayonUse); SubscribeLocalEvent<CrayonComponent, UseInHandEvent>(OnCrayonUse);
SubscribeLocalEvent<CrayonComponent, AfterInteractEvent>(OnCrayonAfterInteract); SubscribeLocalEvent<CrayonComponent, AfterInteractEvent>(OnCrayonAfterInteract);
SubscribeLocalEvent<CrayonComponent, DroppedEvent>(OnCrayonDropped); SubscribeLocalEvent<CrayonComponent, DroppedEvent>(OnCrayonDropped);
@@ -67,7 +68,21 @@ public sealed class CrayonSystem : EntitySystem
return; 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; return;
if (component.UseSound != null) if (component.UseSound != null)
@@ -96,7 +111,7 @@ public sealed class CrayonSystem : EntitySystem
if (component.UserInterface?.SessionHasOpen(actor.PlayerSession) == true) if (component.UserInterface?.SessionHasOpen(actor.PlayerSession) == true)
{ {
// Tell the user interface the selected stuff // 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; args.Handled = true;
@@ -108,9 +123,33 @@ public sealed class CrayonSystem : EntitySystem
if (!_prototypeManager.TryIndex<DecalPrototype>(args.State, out var prototype) || !prototype.Tags.Contains("crayon")) return; if (!_prototypeManager.TryIndex<DecalPrototype>(args.State, out var prototype) || !prototype.Tags.Contains("crayon")) return;
component.SelectedState = args.State; component.SelectedState = args.State;
Dirty(component); 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) private void OnCrayonInit(EntityUid uid, CrayonComponent component, ComponentInit args)
{ {
component.Charges = component.Capacity; component.Charges = component.Capacity;

View File

@@ -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] [Serializable, NetSerializable]
public enum CrayonVisuals public enum CrayonVisuals
{ {
@@ -58,11 +68,13 @@ namespace Content.Shared.Crayon
public sealed class CrayonBoundUserInterfaceState : BoundUserInterfaceState public sealed class CrayonBoundUserInterfaceState : BoundUserInterfaceState
{ {
public string Selected; public string Selected;
public bool SelectableColor;
public Color Color; public Color Color;
public CrayonBoundUserInterfaceState(string selected, Color color) public CrayonBoundUserInterfaceState(string selected, bool selectableColor, Color color)
{ {
Selected = selected; Selected = selected;
SelectableColor = selectableColor;
Color = color; Color = color;
} }
} }

View File

@@ -28,6 +28,7 @@
contents: contents:
- id: BoxHug - id: BoxHug
- id: RubberStampClown - id: RubberStampClown
- id: CrayonRainbow
- type: entity - type: entity
noSpawn: true noSpawn: true

View File

@@ -65,6 +65,29 @@
- Recyclable - Recyclable
- Trash - 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 - type: entity
parent: Crayon parent: Crayon
id: CrayonBlack id: CrayonBlack