mirror of
https://github.com/space-syndicate/space-station-14.git
synced 2026-10-09 10:21:18 +03:00
* Vertically expanding channels, -pointless Controls * scamboni * XAML control for the base midi CFG item
129 lines
4.5 KiB
C#
129 lines
4.5 KiB
C#
using Content.Client.Stylesheets;
|
|
using Content.Client.UserInterface.Controls;
|
|
using Robust.Client.AutoGenerated;
|
|
using Robust.Client.Graphics;
|
|
using Robust.Client.UserInterface;
|
|
using Robust.Client.UserInterface.Controls;
|
|
using Robust.Client.UserInterface.XAML;
|
|
using Robust.Shared.Utility;
|
|
|
|
namespace Content.Client.Instruments.UI;
|
|
|
|
[GenerateTypedNameReferences]
|
|
public sealed partial class InstrumentMenu : FancyWindow
|
|
{
|
|
private InstrumentMidiSourceBase? _currentMode;
|
|
|
|
public InstrumentMenu()
|
|
{
|
|
RobustXamlLoader.Load(this);
|
|
|
|
var styleBox = new StyleBoxFlat
|
|
{
|
|
BorderThickness = new Thickness(0),
|
|
Padding = new Thickness(10),
|
|
};
|
|
|
|
MainTabContainer.PanelStyleBoxOverride = styleBox;
|
|
MainTabContainer.SetTabTitle(0, Loc.GetString("instruments-component-menu-play-tab-title"));
|
|
MainTabContainer.SetTabTitle(1, Loc.GetString("instruments-component-menu-config-tab-title"));
|
|
}
|
|
|
|
protected override void ExitedTree()
|
|
{
|
|
base.ExitedTree();
|
|
_currentMode?.Disable();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Registers the passed midi source controls as children of this instrument menu and creates a button
|
|
/// for each one on the left hand side of the menu.
|
|
/// </summary>
|
|
/// <param name="sources">The sources to be registered</param>
|
|
public void SetupSources(params InstrumentMidiSourceBase[] sources)
|
|
{
|
|
var group = new ButtonGroup();
|
|
for (var i = 0; i < sources.Length; i++)
|
|
{
|
|
var source = sources[i];
|
|
var button = new Button();
|
|
button.Text = source.ButtonName;
|
|
button.Group = group;
|
|
button.OnPressed += _ => { SwitchMode(source); };
|
|
MidiSourceButtonsBoxContainer.Children.Add(button);
|
|
MidiSourcesContainer.Children.Add(source);
|
|
source.VerticalExpand = true;
|
|
source.HorizontalExpand = true;
|
|
source.Visible = false;
|
|
|
|
// Set nicer style classes depending on button position.
|
|
if (i == 0)
|
|
{
|
|
button.Pressed = true;
|
|
button.StyleClasses.Add("OpenLeft");
|
|
}
|
|
else if (i == sources.Length - 1)
|
|
{
|
|
button.StyleClasses.Add("OpenRight");
|
|
}
|
|
else
|
|
{
|
|
button.StyleClasses.Add("OpenBoth");
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Takes the given control and registers it as an option for the configuration tab control.
|
|
/// </summary>
|
|
/// <param name="name">The string to display on the tab header for this configuration.</param>
|
|
/// <param name="ctrl">The control used for this configuration.</param>
|
|
/// <returns>The new control.</param>
|
|
public MidiConfigurationControl AddConfigurationControl(string name, Control ctrl)
|
|
{
|
|
var formatted = new FormattedMessage();
|
|
var cfgCtrl = new MidiConfigurationControl();
|
|
|
|
ctrl.VerticalExpand = true;
|
|
ctrl.Margin = new Thickness(5);
|
|
|
|
formatted.AddMarkupOrThrow($"[bold]{name}[/bold]");
|
|
cfgCtrl.Header.SetMessage(formatted, Color.FromHex("#A88B5E"));
|
|
|
|
cfgCtrl.Panel.AddChild(ctrl);
|
|
|
|
ConfigurationItemsContainer.AddChild(cfgCtrl);
|
|
return cfgCtrl;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Disables & hides the currently active source control, then enables & shows the given one.
|
|
/// </summary>
|
|
/// <param name="source">The source control to enable.</param>
|
|
/// <remarks>The given source must be registered first using the <see cref="SetupSources" /> function.</remarks>
|
|
public void SwitchMode(InstrumentMidiSourceBase source)
|
|
{
|
|
_currentMode?.Disable();
|
|
_currentMode = source;
|
|
_currentMode.Enable();
|
|
}
|
|
|
|
/// <summary>
|
|
/// When true, overlays the menu with a notice that MIDI is currently not available.
|
|
/// </summary>
|
|
/// <param name="available">Set to true when MIDI is available.</param>
|
|
/// <remarks>This should be set to false when MIDI playback is not available on the system.</remarks>
|
|
public void SetMidiAvailability(bool available)
|
|
{
|
|
UnavailableOverlay.Visible = !available;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Takes an entity with an <see cref="InstrumentComponent" /> and displays its sprite on the left hand side.
|
|
/// </summary>
|
|
/// <param name="entity">The entity to display.</param>
|
|
public void SetInstrument(Entity<InstrumentComponent> entity)
|
|
{
|
|
InstrumentSpriteView.SetEntity(entity);
|
|
}
|
|
}
|