From 7e625a2113e0d98615888943814f9c92b3bd15bb Mon Sep 17 00:00:00 2001 From: EmoGarbage404 Date: Tue, 28 Jun 2022 00:50:55 -0400 Subject: [PATCH 1/3] Add different styles for instruments trumpet, accordion, synth, electric guitar, acoustic guitar, saxophone --- .../SwappableInstrumentComponent.cs | 12 +++++ .../Instruments/SwappableInstrumentSystem.cs | 53 +++++++++++++++++++ .../Instruments/SharedInstrumentSystem.cs | 5 ++ Content.Shared/Verbs/VerbCategory.cs | 3 ++ .../instruments/instruments-component.ftl | 3 ++ Resources/Locale/en-US/verbs/verb-system.ftl | 1 + .../Entities/Objects/Fun/instruments.yml | 31 ++++++++++- 7 files changed, 106 insertions(+), 2 deletions(-) create mode 100644 Content.Server/Instruments/SwappableInstrumentComponent.cs create mode 100644 Content.Server/Instruments/SwappableInstrumentSystem.cs diff --git a/Content.Server/Instruments/SwappableInstrumentComponent.cs b/Content.Server/Instruments/SwappableInstrumentComponent.cs new file mode 100644 index 000000000000..8f7f210ce9d9 --- /dev/null +++ b/Content.Server/Instruments/SwappableInstrumentComponent.cs @@ -0,0 +1,12 @@ +namespace Content.Server.Instruments; + +[RegisterComponent] +public sealed class SwappableInstrumentComponent : Component +{ + /// + /// string = the name of the style, used for display + /// byte = the corresponding program number for the instrument + /// + [DataField("instrumentList", required: true)] + public Dictionary InstrumentList = new(); +} diff --git a/Content.Server/Instruments/SwappableInstrumentSystem.cs b/Content.Server/Instruments/SwappableInstrumentSystem.cs new file mode 100644 index 000000000000..8fba5fc3d15b --- /dev/null +++ b/Content.Server/Instruments/SwappableInstrumentSystem.cs @@ -0,0 +1,53 @@ +using Content.Server.Stunnable; +using Content.Server.UserInterface; +using Content.Shared.Instruments; +using Content.Shared.Popups; +using Content.Shared.Verbs; +using Robust.Shared.Player; + +namespace Content.Server.Instruments; + +public sealed class SwappableInstrumentSystem : EntitySystem +{ + [Dependency] private readonly SharedInstrumentSystem _sharedInstrument = default!; + [Dependency] private readonly SharedPopupSystem _popup = default!; + + public override void Initialize() + { + base.Initialize(); + + SubscribeLocalEvent>(AddStyleVerb); + } + + private void AddStyleVerb(EntityUid uid, SwappableInstrumentComponent component, GetVerbsEvent args) + { + if (!args.CanInteract || !args.CanAccess || component.InstrumentList.Count <= 1) + return; + + if (!TryComp(uid, out var instrument)) + return; + + if (instrument.Playing) //no changing while playing + return; + + var priority = 0; + foreach (var entry in component.InstrumentList) + { + AlternativeVerb selection = new() + { + Text = entry.Key, + Category = VerbCategory.InstrumentStyle, + Priority = priority, + Act = () => + { + _sharedInstrument.SetInstrumentProgram(instrument, entry.Value); + _popup.PopupEntity(Loc.GetString("swappable-instrument-component-style-set", ("style", entry.Key)), + args.User, Filter.Entities(args.User)); + } + }; + + priority--; + args.Verbs.Add(selection); + } + } +} diff --git a/Content.Shared/Instruments/SharedInstrumentSystem.cs b/Content.Shared/Instruments/SharedInstrumentSystem.cs index f356b722b40f..9b7172f9101c 100644 --- a/Content.Shared/Instruments/SharedInstrumentSystem.cs +++ b/Content.Shared/Instruments/SharedInstrumentSystem.cs @@ -18,6 +18,11 @@ public virtual void SetupRenderer(EntityUid uid, bool fromStateChange, SharedIns public virtual void EndRenderer(EntityUid uid, bool fromStateChange, SharedInstrumentComponent? instrument = null) { } + public void SetInstrumentProgram(SharedInstrumentComponent component, byte program) + { + component.InstrumentProgram = program; + } + private void OnGetState(EntityUid uid, SharedInstrumentComponent instrument, ref ComponentGetState args) { args.State = diff --git a/Content.Shared/Verbs/VerbCategory.cs b/Content.Shared/Verbs/VerbCategory.cs index 66b0e39055b3..53a05cacc5eb 100644 --- a/Content.Shared/Verbs/VerbCategory.cs +++ b/Content.Shared/Verbs/VerbCategory.cs @@ -68,6 +68,9 @@ public VerbCategory(string text, string? icon, bool iconsOnly = false) public static readonly VerbCategory Split = new("verb-categories-split", null); + public static readonly VerbCategory InstrumentStyle = + new("verb-categories-instrument-style", null); + public static readonly VerbCategory SetSensor = new("verb-categories-set-sensor", null); } } diff --git a/Resources/Locale/en-US/instruments/instruments-component.ftl b/Resources/Locale/en-US/instruments/instruments-component.ftl index db412a9342cb..cbbe835140c3 100644 --- a/Resources/Locale/en-US/instruments/instruments-component.ftl +++ b/Resources/Locale/en-US/instruments/instruments-component.ftl @@ -8,3 +8,6 @@ instruments-component-menu-no-midi-support = MIDI support is currently not FluidSynth or a development package for FluidSynth. +# SwappableInstrumentComponent +swappable-instrument-component-style-set = Style set to "{$style}" + diff --git a/Resources/Locale/en-US/verbs/verb-system.ftl b/Resources/Locale/en-US/verbs/verb-system.ftl index c4fdaed060e8..27d4da4985df 100644 --- a/Resources/Locale/en-US/verbs/verb-system.ftl +++ b/Resources/Locale/en-US/verbs/verb-system.ftl @@ -20,6 +20,7 @@ verb-categories-rotate = Rotate verb-categories-smite = Smite verb-categories-transfer = Set Transfer Amount verb-categories-split = Split +verb-categories-instrument-style = Instrument Style verb-categories-set-sensor = Sensor verb-categories-timer = Set Delay diff --git a/Resources/Prototypes/Entities/Objects/Fun/instruments.yml b/Resources/Prototypes/Entities/Objects/Fun/instruments.yml index 957ea64dba9b..4925c1f3a388 100644 --- a/Resources/Prototypes/Entities/Objects/Fun/instruments.yml +++ b/Resources/Prototypes/Entities/Objects/Fun/instruments.yml @@ -26,6 +26,10 @@ components: - type: Instrument program: 62 + - type: SwappableInstrument + instrumentList: + "Electro": 62 #i needed generic sounding synth presets, sue me + "Bubbles": 63 - type: Sprite sprite: Objects/Fun/Instruments/h_synthesizer.rsi state: icon @@ -43,7 +47,11 @@ description: Anyway, here's Wonderwall. components: - type: Instrument - program: 25 + program: 24 + - type: SwappableInstrument + instrumentList: + "Nylon": 24 + "Steel": 25 - type: Sprite sprite: Objects/Fun/Instruments/guitar.rsi state: icon @@ -82,6 +90,10 @@ components: - type: Instrument program: 56 + - type: SwappableInstrument + instrumentList: + "Standard": 56 + "Muted": 59 - type: Sprite sprite: Objects/Fun/Instruments/trumpet.rsi state: icon @@ -117,6 +129,11 @@ components: - type: Instrument program: 27 + - type: SwappableInstrument + instrumentList: + "Clean": 27 + "Jazz": 25 + "Muted": 28 - type: Sprite sprite: Objects/Fun/Instruments/eguitar.rsi state: icon @@ -134,6 +151,10 @@ components: - type: Instrument program: 21 + - type: SwappableInstrument + instrumentList: + "Standard": 21 + "Tango": 23 - type: Sprite sprite: Objects/Fun/Instruments/accordion.rsi state: icon @@ -240,7 +261,13 @@ description: An instrument. You could probably grind this into raw jazz. components: - type: Instrument - program: 67 + program: 66 + - type: SwappableInstrument + instrumentList: + "Soprano": 64 + "Alto": 65 + "Tenor": 66 + "Baritone": 67 - type: Sprite sprite: Objects/Fun/Instruments/saxophone.rsi state: icon From f4826125d8b71de758aa18190fd13278b2183633 Mon Sep 17 00:00:00 2001 From: EmoGarbage404 Date: Tue, 28 Jun 2022 00:51:40 -0400 Subject: [PATCH 2/3] cleanup --- Content.Server/Instruments/SwappableInstrumentSystem.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/Content.Server/Instruments/SwappableInstrumentSystem.cs b/Content.Server/Instruments/SwappableInstrumentSystem.cs index 8fba5fc3d15b..e6da0289b83f 100644 --- a/Content.Server/Instruments/SwappableInstrumentSystem.cs +++ b/Content.Server/Instruments/SwappableInstrumentSystem.cs @@ -1,5 +1,3 @@ -using Content.Server.Stunnable; -using Content.Server.UserInterface; using Content.Shared.Instruments; using Content.Shared.Popups; using Content.Shared.Verbs; From 9cc88972c0dce7a9dcc389bdef1da79637180b3d Mon Sep 17 00:00:00 2001 From: EmoGarbage404 Date: Tue, 28 Jun 2022 10:36:50 -0400 Subject: [PATCH 3/3] bank support --- .../SwappableInstrumentComponent.cs | 8 +++-- .../Instruments/SwappableInstrumentSystem.cs | 2 +- .../Instruments/SharedInstrumentSystem.cs | 3 +- .../Entities/Objects/Fun/instruments.yml | 30 +++++++++---------- 4 files changed, 23 insertions(+), 20 deletions(-) diff --git a/Content.Server/Instruments/SwappableInstrumentComponent.cs b/Content.Server/Instruments/SwappableInstrumentComponent.cs index 8f7f210ce9d9..bfe8b5c3a604 100644 --- a/Content.Server/Instruments/SwappableInstrumentComponent.cs +++ b/Content.Server/Instruments/SwappableInstrumentComponent.cs @@ -4,9 +4,11 @@ namespace Content.Server.Instruments; public sealed class SwappableInstrumentComponent : Component { /// - /// string = the name of the style, used for display - /// byte = the corresponding program number for the instrument + /// Used to store the different instruments that can be swapped between. + /// string = display name of the instrument + /// byte 1 = instrument midi program + /// byte 2 = instrument midi bank /// [DataField("instrumentList", required: true)] - public Dictionary InstrumentList = new(); + public Dictionary InstrumentList = new(); } diff --git a/Content.Server/Instruments/SwappableInstrumentSystem.cs b/Content.Server/Instruments/SwappableInstrumentSystem.cs index e6da0289b83f..1f64a0c7c7c6 100644 --- a/Content.Server/Instruments/SwappableInstrumentSystem.cs +++ b/Content.Server/Instruments/SwappableInstrumentSystem.cs @@ -38,7 +38,7 @@ private void AddStyleVerb(EntityUid uid, SwappableInstrumentComponent component, Priority = priority, Act = () => { - _sharedInstrument.SetInstrumentProgram(instrument, entry.Value); + _sharedInstrument.SetInstrumentProgram(instrument, entry.Value.Item1, entry.Value.Item2); _popup.PopupEntity(Loc.GetString("swappable-instrument-component-style-set", ("style", entry.Key)), args.User, Filter.Entities(args.User)); } diff --git a/Content.Shared/Instruments/SharedInstrumentSystem.cs b/Content.Shared/Instruments/SharedInstrumentSystem.cs index 9b7172f9101c..767738f175ce 100644 --- a/Content.Shared/Instruments/SharedInstrumentSystem.cs +++ b/Content.Shared/Instruments/SharedInstrumentSystem.cs @@ -18,9 +18,10 @@ public virtual void SetupRenderer(EntityUid uid, bool fromStateChange, SharedIns public virtual void EndRenderer(EntityUid uid, bool fromStateChange, SharedInstrumentComponent? instrument = null) { } - public void SetInstrumentProgram(SharedInstrumentComponent component, byte program) + public void SetInstrumentProgram(SharedInstrumentComponent component, byte program, byte bank) { component.InstrumentProgram = program; + component.InstrumentBank = bank; } private void OnGetState(EntityUid uid, SharedInstrumentComponent instrument, ref ComponentGetState args) diff --git a/Resources/Prototypes/Entities/Objects/Fun/instruments.yml b/Resources/Prototypes/Entities/Objects/Fun/instruments.yml index 4925c1f3a388..7dd8b43082a5 100644 --- a/Resources/Prototypes/Entities/Objects/Fun/instruments.yml +++ b/Resources/Prototypes/Entities/Objects/Fun/instruments.yml @@ -28,8 +28,8 @@ program: 62 - type: SwappableInstrument instrumentList: - "Electro": 62 #i needed generic sounding synth presets, sue me - "Bubbles": 63 + "Electro": {62: 0} #i needed generic sounding synth presets, sue me + "Bubbles": {63: 0} - type: Sprite sprite: Objects/Fun/Instruments/h_synthesizer.rsi state: icon @@ -50,8 +50,8 @@ program: 24 - type: SwappableInstrument instrumentList: - "Nylon": 24 - "Steel": 25 + "Nylon": {24: 0} + "Steel": {25: 0} - type: Sprite sprite: Objects/Fun/Instruments/guitar.rsi state: icon @@ -92,8 +92,8 @@ program: 56 - type: SwappableInstrument instrumentList: - "Standard": 56 - "Muted": 59 + "Standard": {56: 0} + "Muted": {59: 0} - type: Sprite sprite: Objects/Fun/Instruments/trumpet.rsi state: icon @@ -131,9 +131,9 @@ program: 27 - type: SwappableInstrument instrumentList: - "Clean": 27 - "Jazz": 25 - "Muted": 28 + "Clean": {27: 0} + "Jazz": {25: 0} + "Muted": {28: 0} - type: Sprite sprite: Objects/Fun/Instruments/eguitar.rsi state: icon @@ -153,8 +153,8 @@ program: 21 - type: SwappableInstrument instrumentList: - "Standard": 21 - "Tango": 23 + "Standard": {21: 0} + "Tango": {23: 0} - type: Sprite sprite: Objects/Fun/Instruments/accordion.rsi state: icon @@ -264,10 +264,10 @@ program: 66 - type: SwappableInstrument instrumentList: - "Soprano": 64 - "Alto": 65 - "Tenor": 66 - "Baritone": 67 + "Soprano": {64: 0} + "Alto": {65: 0} + "Tenor": {66: 0} + "Baritone": {67: 0} - type: Sprite sprite: Objects/Fun/Instruments/saxophone.rsi state: icon