Add Different Styles for Instruments (#9250)
This commit is contained in:
14
Content.Server/Instruments/SwappableInstrumentComponent.cs
Normal file
14
Content.Server/Instruments/SwappableInstrumentComponent.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
namespace Content.Server.Instruments;
|
||||
|
||||
[RegisterComponent]
|
||||
public sealed class SwappableInstrumentComponent : Component
|
||||
{
|
||||
/// <summary>
|
||||
/// 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
|
||||
/// </summary>
|
||||
[DataField("instrumentList", required: true)]
|
||||
public Dictionary<string, (byte, byte)> InstrumentList = new();
|
||||
}
|
||||
51
Content.Server/Instruments/SwappableInstrumentSystem.cs
Normal file
51
Content.Server/Instruments/SwappableInstrumentSystem.cs
Normal file
@@ -0,0 +1,51 @@
|
||||
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<SwappableInstrumentComponent, GetVerbsEvent<AlternativeVerb>>(AddStyleVerb);
|
||||
}
|
||||
|
||||
private void AddStyleVerb(EntityUid uid, SwappableInstrumentComponent component, GetVerbsEvent<AlternativeVerb> args)
|
||||
{
|
||||
if (!args.CanInteract || !args.CanAccess || component.InstrumentList.Count <= 1)
|
||||
return;
|
||||
|
||||
if (!TryComp<SharedInstrumentComponent>(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.Item1, entry.Value.Item2);
|
||||
_popup.PopupEntity(Loc.GetString("swappable-instrument-component-style-set", ("style", entry.Key)),
|
||||
args.User, Filter.Entities(args.User));
|
||||
}
|
||||
};
|
||||
|
||||
priority--;
|
||||
args.Verbs.Add(selection);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,12 @@ public abstract class SharedInstrumentSystem : EntitySystem
|
||||
public virtual void EndRenderer(EntityUid uid, bool fromStateChange, SharedInstrumentComponent? instrument = null)
|
||||
{ }
|
||||
|
||||
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)
|
||||
{
|
||||
args.State =
|
||||
|
||||
@@ -68,6 +68,9 @@ namespace Content.Shared.Verbs
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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}"
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -26,6 +26,10 @@
|
||||
components:
|
||||
- type: Instrument
|
||||
program: 62
|
||||
- type: SwappableInstrument
|
||||
instrumentList:
|
||||
"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
|
||||
@@ -43,7 +47,11 @@
|
||||
description: Anyway, here's Wonderwall.
|
||||
components:
|
||||
- type: Instrument
|
||||
program: 25
|
||||
program: 24
|
||||
- type: SwappableInstrument
|
||||
instrumentList:
|
||||
"Nylon": {24: 0}
|
||||
"Steel": {25: 0}
|
||||
- type: Sprite
|
||||
sprite: Objects/Fun/Instruments/guitar.rsi
|
||||
state: icon
|
||||
@@ -82,6 +90,10 @@
|
||||
components:
|
||||
- type: Instrument
|
||||
program: 56
|
||||
- type: SwappableInstrument
|
||||
instrumentList:
|
||||
"Standard": {56: 0}
|
||||
"Muted": {59: 0}
|
||||
- type: Sprite
|
||||
sprite: Objects/Fun/Instruments/trumpet.rsi
|
||||
state: icon
|
||||
@@ -117,6 +129,11 @@
|
||||
components:
|
||||
- type: Instrument
|
||||
program: 27
|
||||
- type: SwappableInstrument
|
||||
instrumentList:
|
||||
"Clean": {27: 0}
|
||||
"Jazz": {25: 0}
|
||||
"Muted": {28: 0}
|
||||
- type: Sprite
|
||||
sprite: Objects/Fun/Instruments/eguitar.rsi
|
||||
state: icon
|
||||
@@ -134,6 +151,10 @@
|
||||
components:
|
||||
- type: Instrument
|
||||
program: 21
|
||||
- type: SwappableInstrument
|
||||
instrumentList:
|
||||
"Standard": {21: 0}
|
||||
"Tango": {23: 0}
|
||||
- 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: 0}
|
||||
"Alto": {65: 0}
|
||||
"Tenor": {66: 0}
|
||||
"Baritone": {67: 0}
|
||||
- type: Sprite
|
||||
sprite: Objects/Fun/Instruments/saxophone.rsi
|
||||
state: icon
|
||||
|
||||
Reference in New Issue
Block a user