-
Notifications
You must be signed in to change notification settings - Fork 37
[Feat] Recoloring / Spray Paint #81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
honeyed-lemons
wants to merge
22
commits into
TheDenSS14:master
Choose a base branch
from
honeyed-lemons:recoloring
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
9766c38
basis up
honeyed-lemons 17ef36c
clean and fix so much code its so much better it works on inhands and…
honeyed-lemons 7e21044
what the fuck?
honeyed-lemons 3221207
add recolor remover, etc etc etc etc
honeyed-lemons c16a917
add trash and update ftl
honeyed-lemons 3ea4c34
magic spray paint
honeyed-lemons a92f8db
clean code drastically
honeyed-lemons c4e9bf7
comments, polish, organization.
honeyed-lemons 7e18637
add orders
honeyed-lemons b54c0dc
fix tests
honeyed-lemons 52a785e
fix more tests
honeyed-lemons a9ff88f
PLEASE TELL ME THIS IS THE LAST TEST FAIL.
honeyed-lemons b0c89df
i did the wrong one oops
honeyed-lemons 279a1a3
Fix multiple bugs, add support for togglable items
honeyed-lemons 67a05ca
Merge branch 'master' into recoloring
portfiend cd4ae2e
add the ability for no examine text
honeyed-lemons ea76bd7
Merge remote-tracking branch 'origin/recoloring' into recoloring
honeyed-lemons acd2c19
suggested changes.
honeyed-lemons 7baf85e
fix magic spray paint
honeyed-lemons 9c89fce
requested changes + cleanup + rainbow can resprite
honeyed-lemons 68e648e
requested changes
honeyed-lemons 9e781f4
Merge branch 'master' into recoloring
portfiend File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,144 @@ | ||
| using System.Linq; | ||
| using Content.Client.Clothing; | ||
| using Content.Client.Items.Systems; | ||
| using Content.Shared._DEN.Recolor; | ||
| using Content.Shared._DEN.Recolor.Components; | ||
| using Content.Shared.Clothing; | ||
| using Content.Shared.Hands; | ||
| using Robust.Client.GameObjects; | ||
|
|
||
| namespace Content.Client._DEN.Recolor; | ||
|
|
||
| public sealed class RecolorVisualizerSystem : VisualizerSystem<RecoloredComponent> | ||
| { | ||
| [Dependency] private readonly ItemSystem _item = default!; | ||
|
|
||
| public override void Initialize() | ||
| { | ||
| base.Initialize(); | ||
|
|
||
| SubscribeLocalEvent<RecoloredComponent, OnRecolorRemovedEvent>(OnRecolorRemoved); | ||
|
|
||
| SubscribeLocalEvent<RecoloredComponent, GetInhandVisualsEvent>(ApplyRecolorInHands, | ||
| after: [typeof(ItemSystem)]); // Done so ItemSystem can handle sprite layers first, otherwise we apply our changes to nothing. | ||
|
|
||
| SubscribeLocalEvent<RecoloredComponent, GetEquipmentVisualsEvent>(ApplyRecolorEquipment, | ||
| after: [typeof(ClientClothingSystem)]); // Same as above. | ||
| } | ||
|
|
||
| protected override void OnAppearanceChange(EntityUid uid, RecoloredComponent component, ref AppearanceChangeEvent args) | ||
| { | ||
| base.OnAppearanceChange(uid, component, ref args); | ||
|
|
||
| if (args.Sprite == null) | ||
| return; | ||
|
|
||
| ApplyRecolorSprite((uid, component), args.Sprite); | ||
| _item.VisualsChanged(uid); | ||
| } | ||
|
|
||
| private void OnRecolorRemoved(Entity<RecoloredComponent> ent, ref OnRecolorRemovedEvent args) | ||
| { | ||
| if (!TryComp(ent, out SpriteComponent? sprite)) | ||
| return; | ||
|
|
||
| RemoveRecolor(ent,sprite); | ||
| _item.VisualsChanged(ent); | ||
| } | ||
|
|
||
| private void ApplyRecolorInHands(Entity<RecoloredComponent> ent, ref GetInhandVisualsEvent args) | ||
| { | ||
| ApplyRecolorLayers(ent,args.Layers); | ||
| } | ||
|
|
||
| private void ApplyRecolorEquipment(Entity<RecoloredComponent> ent, ref GetEquipmentVisualsEvent args) | ||
| { | ||
| ApplyRecolorLayers(ent,args.Layers); | ||
| } | ||
|
|
||
| private void ApplyRecolorLayers(Entity<RecoloredComponent> ent, List<(string, PrototypeLayerData)> layers) | ||
| { | ||
| if(!TryComp<AppearanceComponent>(ent, out var appearance)) | ||
| return; | ||
|
|
||
| if (!AppearanceSystem.TryGetData(ent, RecolorVisuals.RecolorData, out RecolorData recolorData,appearance)) | ||
| return; | ||
|
|
||
| foreach (var (_, layerData) in layers) | ||
| { | ||
| // Apply Color | ||
| layerData.Color = recolorData.Color; | ||
|
|
||
| //Test shader whitelists and blacklists | ||
| if (!AllowedShader(layerData.Shader, recolorData)) | ||
| continue; | ||
|
|
||
| // Apply shaders | ||
| layerData.Shader = recolorData.Shader; | ||
| } | ||
| } | ||
|
|
||
| private void ApplyRecolorSprite(Entity<RecoloredComponent> ent, SpriteComponent sprite) | ||
| { | ||
| if(!TryComp<AppearanceComponent>(ent, out var appearance)) | ||
| return; | ||
|
|
||
| if (!AppearanceSystem.TryGetData(ent, RecolorVisuals.RecolorData, out RecolorData recolorData, appearance)) | ||
| return; | ||
|
|
||
| for (var i = 0; i < sprite.AllLayers.Count(); i++) | ||
| { | ||
| if (!SpriteSystem.TryGetLayer((ent, sprite), i, out var layer, false)) | ||
| continue; | ||
|
|
||
| // Apply color | ||
| SpriteSystem.LayerSetColor(layer, recolorData.Color); | ||
|
|
||
| var layerShader = layer.ShaderPrototype; | ||
|
|
||
| if (!AllowedShader(layerShader?.Id, recolorData)) | ||
| continue; | ||
|
|
||
| // Apply shaders | ||
| if (recolorData.Shader != null) | ||
| sprite.LayerSetShader(i, recolorData.Shader); | ||
| } | ||
| } | ||
|
|
||
| private void RemoveRecolor(Entity<RecoloredComponent> ent, SpriteComponent sprite) | ||
| { | ||
| if(!TryComp<AppearanceComponent>(ent, out var appearance)) | ||
| return; | ||
|
|
||
| if (!AppearanceSystem.TryGetData(ent, RecolorVisuals.RecolorData, out RecolorData recolorData, appearance)) | ||
| return; | ||
|
|
||
| for (var i = 0; i < sprite.AllLayers.Count(); i++) | ||
| { | ||
| // TODO: Make it possible to get the previous color and shaders, currently impossible due to sprite system being fully clientside | ||
|
|
||
| if (!SpriteSystem.TryGetLayer((ent, sprite), i, out var layer, false)) | ||
| continue; | ||
|
|
||
| // Remove colors | ||
| SpriteSystem.LayerSetColor(layer, Color.White); | ||
|
|
||
| // Remove shaders | ||
| var layerShader = layer.ShaderPrototype; | ||
|
|
||
| if (!AllowedShader(layerShader?.Id, recolorData)) | ||
| continue; | ||
|
|
||
| sprite.LayerSetShader(i, null, null); | ||
| } | ||
| } | ||
|
|
||
| private static bool AllowedShader(string? shader, RecolorData appearanceData) | ||
| { | ||
| if (shader == null) | ||
| return true; | ||
|
|
||
| return (appearanceData.ShaderBlacklist == null || !appearanceData.ShaderBlacklist.Contains(shader)) | ||
| && (appearanceData.ShaderWhitelist == null || appearanceData.ShaderWhitelist.Contains(shader)); | ||
| } | ||
| } |
33 changes: 33 additions & 0 deletions
33
Content.Client/_DEN/Recolor/UI/RecolorApplierColorSelectorBui.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| using Content.Shared._DEN.Recolor; | ||
| using Robust.Client.UserInterface; | ||
|
|
||
| namespace Content.Client._DEN.Recolor.UI; | ||
|
|
||
| public sealed class RecolorApplierColorSelectorBui(EntityUid owner, Enum uiKey) : BoundUserInterface(owner, uiKey) | ||
| { | ||
| [ViewVariables] | ||
| private RecolorApplierColorSelectorMenu? _menu; | ||
|
|
||
| protected override void Open() | ||
| { | ||
| base.Open(); | ||
|
|
||
| _menu = this.CreateWindow<RecolorApplierColorSelectorMenu>(); | ||
| _menu.OnColorChanged += SelectColor; | ||
| } | ||
|
|
||
| protected override void UpdateState(BoundUserInterfaceState state) | ||
| { | ||
| base.UpdateState(state); | ||
| // Set the color of the color selector to the same color as the spray paint currently is | ||
| if (state is RecolorSystem.RecolorApplierColorState recolorApplierColorState) | ||
| { | ||
| _menu?.SelectColor(recolorApplierColorState.Color); | ||
| } | ||
| } | ||
| // Sent out when a new color is chosen | ||
| private void SelectColor(Color color) | ||
| { | ||
| SendMessage(new RecolorSystem.RecolorApplierColorMessage(color)); | ||
| } | ||
| } |
9 changes: 9 additions & 0 deletions
9
Content.Client/_DEN/Recolor/UI/RecolorApplierColorSelectorMenu.xaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| <DefaultWindow xmlns="https://spacestation14.io" | ||
| Title="{Loc 'recolor-applier-color-selector-window-title'}" | ||
| MinSize="400 170" | ||
| SetSize="400 170" | ||
| MaxSize="800 170"> | ||
| <BoxContainer Orientation="Vertical" SeparationOverride="5"> | ||
| <ColorSelectorSliders Name="ColorSelector"/> | ||
| </BoxContainer> | ||
| </DefaultWindow> |
29 changes: 29 additions & 0 deletions
29
Content.Client/_DEN/Recolor/UI/RecolorApplierColorSelectorMenu.xaml.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| using Content.Shared._DEN.Recolor; | ||
| using Robust.Client.AutoGenerated; | ||
| using Robust.Client.UserInterface.Controls; | ||
| using Robust.Client.UserInterface.CustomControls; | ||
| using Robust.Client.UserInterface.XAML; | ||
|
|
||
| namespace Content.Client._DEN.Recolor.UI; | ||
|
|
||
| [GenerateTypedNameReferences] | ||
| public sealed partial class RecolorApplierColorSelectorMenu : DefaultWindow | ||
| { | ||
| public Action<Color>? OnColorChanged; | ||
|
|
||
| public RecolorApplierColorSelectorMenu() | ||
| { | ||
| RobustXamlLoader.Load(this); | ||
|
|
||
| ColorSelector.OnColorChanged += color => | ||
| { | ||
| OnColorChanged?.Invoke(color); | ||
| }; | ||
| } | ||
|
|
||
| // Set the color selector's color. | ||
| public void SelectColor(Color color) | ||
| { | ||
| ColorSelector.Color = color; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
Content.Shared/_DEN/Clothing/EntitySystems/ToggleableClothingSystem.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| using Content.Shared._DEN.Recolor; | ||
| using Content.Shared.Clothing.Components; | ||
|
|
||
| namespace Content.Shared.Clothing.EntitySystems; | ||
|
|
||
| public sealed partial class ToggleableClothingSystem | ||
| { | ||
| [Dependency] private readonly RecolorSystem _recolor = default!; | ||
|
|
||
| // DEN, recolor system start | ||
| private void OnToggleableRecolored(Entity<ToggleableClothingComponent> ent, ref OnRecoloredEvent args) | ||
| { | ||
| var toggled = ent.Comp.ClothingUid; | ||
|
|
||
| if (toggled != null) | ||
| _recolor.Recolor(toggled.Value,args.RecolorData, args.Recolorer); | ||
| } | ||
|
|
||
| private void OnToggleableRecolorRemoved(Entity<ToggleableClothingComponent> ent, ref OnRecolorRemovedEvent args) | ||
| { | ||
| var toggled = ent.Comp.ClothingUid; | ||
|
|
||
| if (toggled != null) | ||
| _recolor.RemoveRecolor(toggled.Value); | ||
| } | ||
| } |
6 changes: 6 additions & 0 deletions
6
Content.Shared/_DEN/Recolor/Components/RecolorApplierColorSelectorComponent.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| namespace Content.Shared._DEN.Recolor.Components; | ||
| /// <summary> | ||
| /// Component used to designate that a recolor applier can have its color selected via a ui. | ||
| /// </summary> | ||
| [RegisterComponent] | ||
| public sealed partial class RecolorApplierColorSelectorComponent : Component; | ||
91 changes: 91 additions & 0 deletions
91
Content.Shared/_DEN/Recolor/Components/RecolorApplierComponent.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| using Content.Shared.Whitelist; | ||
| using Robust.Shared.Audio; | ||
| using Robust.Shared.GameStates; | ||
| using Robust.Shared.Utility; | ||
|
|
||
| namespace Content.Shared._DEN.Recolor.Components; | ||
| /// <summary> | ||
| /// Component used to designate something can apply recolors, EG spray paint. | ||
| /// </summary> | ||
| [RegisterComponent, NetworkedComponent, AutoGenerateComponentState] | ||
| public sealed partial class RecolorApplierComponent : Component | ||
|
honeyed-lemons marked this conversation as resolved.
|
||
| { | ||
|
|
||
| /// <summary> | ||
| /// RecolorData to recolor items with. | ||
| /// </summary> | ||
| [DataField, AutoNetworkedField] | ||
| public RecolorData RecolorData; | ||
|
|
||
| /// <summary> | ||
| /// How long it takes for this object to apply the recolor to the target. | ||
| /// </summary> | ||
| [DataField] | ||
| public TimeSpan DoAfterDuration = TimeSpan.FromSeconds(2.0f); | ||
|
|
||
| /// <summary> | ||
| /// Sound to play when the doafter is over. | ||
| /// </summary> | ||
| [DataField] | ||
| public SoundSpecifier? DoAfterSound = new SoundPathSpecifier("/Audio/Effects/spray2.ogg"); | ||
|
|
||
| /// <summary> | ||
| /// Maximum amount of uses the applier can spray, if left null the applier can apply infinitely. | ||
| /// </summary> | ||
| [DataField] | ||
| public int? MaxUses; | ||
|
|
||
| /// <summary> | ||
| /// Current amount of uses the applier can spray. | ||
| /// </summary> | ||
| [ViewVariables(VVAccess.ReadWrite), AutoNetworkedField] | ||
| public int UsesLeft; | ||
|
|
||
| /// <summary> | ||
| /// LocId used for the "you're outta paint!" popup. | ||
| /// </summary> | ||
| [DataField] | ||
| public LocId NoMoreUsesPopup = "spray-paint-empty"; | ||
|
|
||
| /// <summary> | ||
| /// LocId used for the "you can't paint that!" popup. | ||
| /// </summary> | ||
| [DataField] | ||
| public LocId CantRecolorPopup = "spray-paint-fail"; | ||
|
|
||
| /// <summary> | ||
| /// LocId used for the "you can't paint that!" popup. | ||
| /// </summary> | ||
| [DataField] | ||
| public LocId ColorShowcaseExamine = "spray-paint-examine-color"; | ||
|
|
||
| /// <summary> | ||
| /// LocId used for the "you can't paint that!" popup. | ||
| /// </summary> | ||
| [DataField] | ||
| public LocId UsesExamine = "spray-paint-examine-uses"; | ||
|
|
||
| /// <summary> | ||
| /// Entity Whitelist to determine what items can be repainted. | ||
| /// </summary> | ||
| [DataField] | ||
| public EntityWhitelist? EntityWhitelist; | ||
|
|
||
| /// <summary> | ||
| /// Entity Blacklist to determine what items can't be repainted. | ||
| /// </summary> | ||
| [DataField] | ||
| public EntityWhitelist? EntityBlacklist; | ||
|
|
||
| /// <summary> | ||
| /// LocId used for the apply recolor verb. | ||
| /// </summary> | ||
| [DataField] | ||
| public LocId VerbText = "verb-spray-paint"; | ||
|
|
||
| /// <summary> | ||
| /// Icon used for the apply recolor verb. | ||
| /// </summary> | ||
| [DataField] | ||
| public SpriteSpecifier VerbIcon = new SpriteSpecifier.Texture(new ResPath("/Textures/_DEN/Interface/VerbIcons/paint-spray-can.svg.192dpi.png")); | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.