Add PDA Ringtones (#5842)
Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
This commit is contained in:
@@ -48,6 +48,11 @@ namespace Content.Client.PDA
|
||||
SendMessage(new PDAShowUplinkMessage());
|
||||
};
|
||||
|
||||
_menu.AccessRingtoneButton.OnPressed += _ =>
|
||||
{
|
||||
SendMessage(new PDAShowRingtoneMessage());
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
protected override void UpdateState(BoundUserInterfaceState state)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<DefaultWindow xmlns="https://spacestation14.io"
|
||||
Title="{Loc 'comp-pda-ui-menu-title'}"
|
||||
MinSize="512 256"
|
||||
SetSize="512 256">
|
||||
MinSize="576 256"
|
||||
SetSize="576 256">
|
||||
<TabContainer Name="MasterTabContainer">
|
||||
<BoxContainer Orientation="Vertical"
|
||||
VerticalExpand="True"
|
||||
@@ -23,6 +23,11 @@
|
||||
Text="{Loc 'comp-pda-ui-eject-pen-button'}"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center" />
|
||||
<Button Name="AccessRingtoneButton"
|
||||
Access="Public"
|
||||
Text="{Loc 'comp-pda-ui-ringtone-button'}"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center" />
|
||||
</BoxContainer>
|
||||
</PanelContainer>
|
||||
<Button Name="FlashLightToggleButton"
|
||||
|
||||
111
Content.Client/PDA/Ringer/RingerBoundUserInterface.cs
Normal file
111
Content.Client/PDA/Ringer/RingerBoundUserInterface.cs
Normal file
@@ -0,0 +1,111 @@
|
||||
using System;
|
||||
using Content.Client.Message;
|
||||
using Content.Shared.PDA;
|
||||
using Content.Shared.PDA.Ringer;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Localization;
|
||||
namespace Content.Client.PDA.Ringer
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public sealed class RingerBoundUserInterface : BoundUserInterface
|
||||
{
|
||||
private RingtoneMenu? _menu;
|
||||
|
||||
public RingerBoundUserInterface(ClientUserInterfaceComponent owner, object uiKey) : base(owner, uiKey)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void Open()
|
||||
{
|
||||
base.Open();
|
||||
_menu = new RingtoneMenu();
|
||||
_menu.OpenToLeft();
|
||||
_menu.OnClose += Close;
|
||||
|
||||
_menu.TestRingerButton.OnPressed += _ =>
|
||||
{
|
||||
SendMessage(new RingerPlayRingtoneMessage());
|
||||
};
|
||||
|
||||
_menu.SetRingerButton.OnPressed += _ =>
|
||||
{
|
||||
if (!TryGetRingtone(out var ringtone)) return;
|
||||
|
||||
SendMessage(new RingerSetRingtoneMessage(ringtone));
|
||||
};
|
||||
}
|
||||
|
||||
private bool TryGetRingtone(out Note[] ringtone)
|
||||
{
|
||||
if (_menu == null)
|
||||
{
|
||||
ringtone = Array.Empty<Note>();
|
||||
return false;
|
||||
}
|
||||
|
||||
ringtone = new Note[4];
|
||||
|
||||
if (!Enum.TryParse<Note>(_menu.RingerNoteOneInput.Text.Replace("#", "sharp"), false, out var one)) return false;
|
||||
ringtone[0] = one;
|
||||
|
||||
if (!Enum.TryParse<Note>(_menu.RingerNoteTwoInput.Text.Replace("#", "sharp"), false, out var two)) return false;
|
||||
ringtone[1] = two;
|
||||
|
||||
if (!Enum.TryParse<Note>(_menu.RingerNoteThreeInput.Text.Replace("#", "sharp"), false, out var three)) return false;
|
||||
ringtone[2] = three;
|
||||
|
||||
if (!Enum.TryParse<Note>(_menu.RingerNoteFourInput.Text.Replace("#", "sharp"), false, out var four)) return false;
|
||||
ringtone[3] = four;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected override void UpdateState(BoundUserInterfaceState state)
|
||||
{
|
||||
base.UpdateState(state);
|
||||
|
||||
if (_menu == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
switch (state)
|
||||
{
|
||||
case RingerUpdateState msg:
|
||||
{
|
||||
var noteOne = msg.Ringtone[0].ToString();
|
||||
var noteTwo = msg.Ringtone[1].ToString();
|
||||
var noteThree = msg.Ringtone[2].ToString();
|
||||
var noteFour = msg.Ringtone[3].ToString();
|
||||
|
||||
if (RingtoneMenu.IsNote(noteOne))
|
||||
_menu.RingerNoteOneInput.Text = noteOne.Replace("sharp", "#");
|
||||
|
||||
if (RingtoneMenu.IsNote(noteTwo))
|
||||
_menu.RingerNoteTwoInput.Text = noteTwo.Replace("sharp", "#");
|
||||
|
||||
if (RingtoneMenu.IsNote(noteThree))
|
||||
_menu.RingerNoteThreeInput.Text = noteThree.Replace("sharp", "#");
|
||||
|
||||
if (RingtoneMenu.IsNote(noteFour))
|
||||
_menu.RingerNoteFourInput.Text = noteFour.Replace("sharp", "#");
|
||||
|
||||
_menu.TestRingerButton.Visible = !msg.IsPlaying;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
base.Dispose(disposing);
|
||||
if (!disposing)
|
||||
return;
|
||||
|
||||
_menu?.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
73
Content.Client/PDA/Ringer/RingtoneMenu.xaml
Normal file
73
Content.Client/PDA/Ringer/RingtoneMenu.xaml
Normal file
@@ -0,0 +1,73 @@
|
||||
<SS14Window xmlns="https://spacestation14.io"
|
||||
Title="{Loc 'comp-ringer-ui-menu-title'}"
|
||||
MinSize="256 128"
|
||||
SetSize="256 128">
|
||||
<BoxContainer Orientation="Vertical"
|
||||
VerticalExpand="True"
|
||||
HorizontalExpand="True"
|
||||
HorizontalAlignment="Center"
|
||||
MinSize="50 50">
|
||||
<PanelContainer>
|
||||
<BoxContainer Orientation="Horizontal"
|
||||
VerticalExpand="True"
|
||||
HorizontalExpand="True"
|
||||
HorizontalAlignment="Center"
|
||||
MinSize="120 0">
|
||||
<Label Name = "Indent_0Label"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"
|
||||
Text="♪" />
|
||||
<LineEdit Name ="RingerNoteOneInput"
|
||||
Access="Public"
|
||||
MinSize="40 0"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"/>
|
||||
<Label Name = "Indent_1Label"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"
|
||||
Text="-" />
|
||||
<LineEdit Name ="RingerNoteTwoInput"
|
||||
Access="Public"
|
||||
MinSize="40 0"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center" />
|
||||
<Label Name = "Indent_2Label"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"
|
||||
Text="-" />
|
||||
<LineEdit Name ="RingerNoteThreeInput"
|
||||
Access="Public"
|
||||
MinSize="40 0"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center" />
|
||||
<Label Name = "Indent_3Label"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"
|
||||
Text="-" />
|
||||
<LineEdit Name ="RingerNoteFourInput"
|
||||
Access="Public"
|
||||
MinSize="40 0"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center" />
|
||||
</BoxContainer>
|
||||
</PanelContainer>
|
||||
<PanelContainer>
|
||||
<BoxContainer Orientation="Horizontal"
|
||||
VerticalExpand="True"
|
||||
HorizontalExpand="True"
|
||||
HorizontalAlignment="Center"
|
||||
MinSize="120 50">
|
||||
<Button Name = "TestRingerButton"
|
||||
Access="Public"
|
||||
Text="{Loc 'comp-ringer-ui-test-ringtone-button'}"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center" />
|
||||
<Button Name = "SetRingerButton"
|
||||
Access="Public"
|
||||
Text="{Loc 'comp-ringer-ui-set-ringtone-button'}"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center" />
|
||||
</BoxContainer>
|
||||
</PanelContainer>
|
||||
</BoxContainer>
|
||||
</SS14Window>
|
||||
105
Content.Client/PDA/Ringer/RingtoneMenu.xaml.cs
Normal file
105
Content.Client/PDA/Ringer/RingtoneMenu.xaml.cs
Normal file
@@ -0,0 +1,105 @@
|
||||
using Robust.Client.AutoGenerated;
|
||||
using Robust.Client.UserInterface.CustomControls;
|
||||
using Robust.Client.UserInterface.XAML;
|
||||
using Robust.Shared.Maths;
|
||||
using System;
|
||||
using Content.Client;
|
||||
using Content.Shared.PDA;
|
||||
|
||||
namespace Content.Client.PDA.Ringer
|
||||
{
|
||||
[GenerateTypedNameReferences]
|
||||
public sealed partial class RingtoneMenu : SS14Window
|
||||
{
|
||||
private string[] _previousNoteInputs = new string[4];
|
||||
|
||||
public RingtoneMenu()
|
||||
{
|
||||
RobustXamlLoader.Load(this);
|
||||
|
||||
//RingerNoteOneInput
|
||||
RingerNoteOneInput.OnTextChanged += _ => //Prevents unauthorized characters from being entered into the LineEdit
|
||||
{
|
||||
RingerNoteOneInput.Text = RingerNoteOneInput.Text.ToUpper();
|
||||
|
||||
if(!IsNote(RingerNoteOneInput.Text))
|
||||
{
|
||||
RingerNoteOneInput.Text = _previousNoteInputs[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
_previousNoteInputs[0] = RingerNoteOneInput.Text;
|
||||
}
|
||||
|
||||
RingerNoteOneInput.CursorPosition = RingerNoteOneInput.Text.Length; //Resets caret position to the end of the typed input
|
||||
};
|
||||
|
||||
//RingerNoteTwoInput
|
||||
RingerNoteTwoInput.OnTextChanged += _ => //Prevents unauthorized characters from being entered into the LineEdit
|
||||
{
|
||||
RingerNoteTwoInput.Text = RingerNoteTwoInput.Text.ToUpper();
|
||||
|
||||
if(!IsNote(RingerNoteTwoInput.Text))
|
||||
{
|
||||
RingerNoteTwoInput.Text = _previousNoteInputs[1];
|
||||
}
|
||||
else
|
||||
{
|
||||
_previousNoteInputs[1] = RingerNoteTwoInput.Text;
|
||||
}
|
||||
|
||||
RingerNoteTwoInput.CursorPosition = RingerNoteTwoInput.Text.Length; //Resets caret position to the end of the typed input
|
||||
};
|
||||
|
||||
//RingerNoteThreeInput
|
||||
RingerNoteThreeInput.OnTextChanged += _ => //Prevents unauthorized characters from being entered into the LineEdit
|
||||
{
|
||||
RingerNoteThreeInput.Text = RingerNoteThreeInput.Text.ToUpper();
|
||||
|
||||
if(!IsNote(RingerNoteThreeInput.Text))
|
||||
{
|
||||
RingerNoteThreeInput.Text = _previousNoteInputs[2];
|
||||
}
|
||||
else
|
||||
{
|
||||
_previousNoteInputs[2] = RingerNoteThreeInput.Text;
|
||||
}
|
||||
|
||||
RingerNoteThreeInput.CursorPosition = RingerNoteThreeInput.Text.Length; //Resets caret position to the end of the typed input
|
||||
};
|
||||
|
||||
//RingerNoteFourInput
|
||||
RingerNoteFourInput.OnTextChanged += _ => //Prevents unauthorized characters from being entered into the LineEdit
|
||||
{
|
||||
RingerNoteFourInput.Text = RingerNoteFourInput.Text.ToUpper();
|
||||
|
||||
if(!IsNote(RingerNoteFourInput.Text))
|
||||
{
|
||||
RingerNoteFourInput.Text = _previousNoteInputs[3];
|
||||
}
|
||||
else
|
||||
{
|
||||
_previousNoteInputs[3] = RingerNoteFourInput.Text;
|
||||
}
|
||||
|
||||
RingerNoteFourInput.CursorPosition = RingerNoteFourInput.Text.Length; //Resets caret position to the end of the typed input
|
||||
};
|
||||
}
|
||||
|
||||
protected override DragMode GetDragModeFor(Vector2 relativeMousePos)
|
||||
{
|
||||
//Prevents the ringtone window from being resized
|
||||
return DragMode.Move;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether or not the characters inputed are authorized
|
||||
/// </summary>
|
||||
public static bool IsNote(string input)
|
||||
{
|
||||
input = input.Replace("#", "sharp");
|
||||
|
||||
return Enum.TryParse(input, true, out Note _);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user