CatStation/Content.Client/Instruments/UI/MinVolumeControl.xaml.cs
Ataman 82b7cfa947
Instrument UI MinVolume slider (#41272)
* Added localization string for MIDI input volume.

* Added MinVolume property to SharedInstrumentComponent & InstrumentComponentState.

* Implemented MinVolume property into InstrumentSystem's.

* Added UI slider for MinVolume to InstrumentMenu.

* Added network event for updating MinVolume.

* Removed unnecessary empty line.

* Readability fix as suggested by Pok27

Co-authored-by: Pok <113675512+Pok27@users.noreply.github.com>

* Added MinVolumeControl

* Added MinVolumeControl to instrument menu configuration (and cleaned up Content.Client.InstrumentSystem.SetMinVolume)

* Added label to MinVolumeSlider indicating the current value

* Minor cleanup

---------

Co-authored-by: Pok <113675512+Pok27@users.noreply.github.com>
2026-07-28 04:29:08 +00:00

60 lines
1.6 KiB
C#

using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.XAML;
using Robust.Shared.Input;
namespace Content.Client.Instruments.UI;
[GenerateTypedNameReferences]
public sealed partial class MinVolumeControl : Control
{
/// <summary>
/// Raised when the user changes the min volume for MIDI input.
/// </summary>
public event Action<int>? MinVolumeChanged;
public int MinVolume
{
get => (int)Math.Ceiling(MidiMinVolumeSlider.Value);
set
{
MidiMinVolumeSlider.Value = value;
UpdateLabel();
}
}
public MinVolumeControl()
{
RobustXamlLoader.Load(this);
IoCManager.InjectDependencies(this);
MidiMinVolumeSlider.OnValueChanged += OnMidiMinVolumeSliderValueChanged;
MidiMinVolumeSlider.OnKeyBindUp += OnMidiMinVolumeSliderKeyUp;
MidiMinVolumeSlider.Value = 0;
}
private void OnMidiMinVolumeSliderValueChanged(Robust.Client.UserInterface.Controls.Range _)
{
UpdateLabel();
// Do not update while still grabbed.
if (MidiMinVolumeSlider.Grabbed)
return;
MinVolumeChanged?.Invoke(MinVolume);
}
private void OnMidiMinVolumeSliderKeyUp(GUIBoundKeyEventArgs args)
{
if (args.Function != EngineKeyFunctions.UIClick)
return;
UpdateLabel();
MinVolumeChanged?.Invoke(MinVolume);
}
private void UpdateLabel()
{
MidiMinVolumeValueLabel.Text = ((int)Math.Ceiling(MidiMinVolumeSlider.Value)).ToString();
}
}