Fix PDA ringtone crash (#8299)
This commit is contained in:
@@ -1,11 +1,7 @@
|
|||||||
using System;
|
|
||||||
using Content.Client.Message;
|
|
||||||
using Content.Shared.PDA;
|
using Content.Shared.PDA;
|
||||||
using Content.Shared.PDA.Ringer;
|
using Content.Shared.PDA.Ringer;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using Robust.Client.GameObjects;
|
using Robust.Client.GameObjects;
|
||||||
using Robust.Shared.GameObjects;
|
|
||||||
using Robust.Shared.Localization;
|
|
||||||
namespace Content.Client.PDA.Ringer
|
namespace Content.Client.PDA.Ringer
|
||||||
{
|
{
|
||||||
[UsedImplicitly]
|
[UsedImplicitly]
|
||||||
@@ -47,17 +43,12 @@ namespace Content.Client.PDA.Ringer
|
|||||||
|
|
||||||
ringtone = new Note[4];
|
ringtone = new Note[4];
|
||||||
|
|
||||||
if (!Enum.TryParse<Note>(_menu.RingerNoteOneInput.Text.Replace("#", "sharp"), false, out var one)) return false;
|
for (int i = 0; i < _menu.RingerNoteInputs.Length; i++)
|
||||||
ringtone[0] = one;
|
{
|
||||||
|
if (!Enum.TryParse<Note>(_menu.RingerNoteInputs[i].Text.Replace("#", "sharp"), false, out var note))
|
||||||
if (!Enum.TryParse<Note>(_menu.RingerNoteTwoInput.Text.Replace("#", "sharp"), false, out var two)) return false;
|
return false;
|
||||||
ringtone[1] = two;
|
ringtone[i] = note;
|
||||||
|
}
|
||||||
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;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -66,36 +57,22 @@ namespace Content.Client.PDA.Ringer
|
|||||||
{
|
{
|
||||||
base.UpdateState(state);
|
base.UpdateState(state);
|
||||||
|
|
||||||
if (_menu == null)
|
if (_menu == null || state is not RingerUpdateState msg)
|
||||||
{
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
for (int i = 0; i < _menu.RingerNoteInputs.Length; i++)
|
||||||
|
{
|
||||||
|
|
||||||
|
var note = msg.Ringtone[i].ToString();
|
||||||
|
if (RingtoneMenu.IsNote(note))
|
||||||
|
{
|
||||||
|
_menu.PreviousNoteInputs[i] = note.Replace("sharp", "#");
|
||||||
|
_menu.RingerNoteInputs[i].Text = _menu.PreviousNoteInputs[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
_menu.TestRingerButton.Visible = !msg.IsPlaying;
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
<SS14Window xmlns="https://spacestation14.io"
|
<DefaultWindow xmlns="https://spacestation14.io"
|
||||||
Title="{Loc 'comp-ringer-ui-menu-title'}"
|
Title="{Loc 'comp-ringer-ui-menu-title'}"
|
||||||
MinSize="256 128"
|
MinSize="256 128"
|
||||||
SetSize="256 128">
|
SetSize="256 128">
|
||||||
@@ -70,4 +70,4 @@
|
|||||||
</BoxContainer>
|
</BoxContainer>
|
||||||
</PanelContainer>
|
</PanelContainer>
|
||||||
</BoxContainer>
|
</BoxContainer>
|
||||||
</SS14Window>
|
</DefaultWindow>
|
||||||
|
|||||||
@@ -1,89 +1,39 @@
|
|||||||
using Robust.Client.AutoGenerated;
|
using Robust.Client.AutoGenerated;
|
||||||
using Robust.Client.UserInterface.CustomControls;
|
using Robust.Client.UserInterface.CustomControls;
|
||||||
using Robust.Client.UserInterface.XAML;
|
using Robust.Client.UserInterface.XAML;
|
||||||
using Robust.Shared.Maths;
|
|
||||||
using System;
|
|
||||||
using Content.Client;
|
|
||||||
using Content.Shared.PDA;
|
using Content.Shared.PDA;
|
||||||
|
using Robust.Client.UserInterface.Controls;
|
||||||
|
|
||||||
namespace Content.Client.PDA.Ringer
|
namespace Content.Client.PDA.Ringer
|
||||||
{
|
{
|
||||||
[GenerateTypedNameReferences]
|
[GenerateTypedNameReferences]
|
||||||
public sealed partial class RingtoneMenu : SS14Window
|
public sealed partial class RingtoneMenu : DefaultWindow
|
||||||
{
|
{
|
||||||
private string[] _previousNoteInputs = new string[4];
|
public string[] PreviousNoteInputs = new string[] { "A", "A", "A", "A"};
|
||||||
|
public LineEdit[] RingerNoteInputs = default!;
|
||||||
|
|
||||||
public RingtoneMenu()
|
public RingtoneMenu()
|
||||||
{
|
{
|
||||||
RobustXamlLoader.Load(this);
|
RobustXamlLoader.Load(this);
|
||||||
|
|
||||||
//RingerNoteOneInput
|
RingerNoteInputs = new LineEdit[] { RingerNoteOneInput, RingerNoteTwoInput, RingerNoteThreeInput, RingerNoteFourInput };
|
||||||
RingerNoteOneInput.OnTextChanged += _ => //Prevents unauthorized characters from being entered into the LineEdit
|
|
||||||
{
|
|
||||||
RingerNoteOneInput.Text = RingerNoteOneInput.Text.ToUpper();
|
|
||||||
|
|
||||||
if(!IsNote(RingerNoteOneInput.Text))
|
for (int i = 0; i < RingerNoteInputs.Length; i++)
|
||||||
{
|
{
|
||||||
RingerNoteOneInput.Text = _previousNoteInputs[0];
|
var input = RingerNoteInputs[i];
|
||||||
}
|
int index = i;
|
||||||
|
input.OnTextChanged += _ => //Prevents unauthorized characters from being entered into the LineEdit
|
||||||
|
{
|
||||||
|
input.Text = input.Text.ToUpper();
|
||||||
|
|
||||||
|
if (!IsNote(input.Text))
|
||||||
|
input.Text = PreviousNoteInputs[index];
|
||||||
else
|
else
|
||||||
{
|
PreviousNoteInputs[index] = input.Text;
|
||||||
_previousNoteInputs[0] = RingerNoteOneInput.Text;
|
|
||||||
}
|
|
||||||
|
|
||||||
RingerNoteOneInput.CursorPosition = RingerNoteOneInput.Text.Length; //Resets caret position to the end of the typed input
|
input.CursorPosition = input.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)
|
protected override DragMode GetDragModeFor(Vector2 relativeMousePos)
|
||||||
|
|||||||
Reference in New Issue
Block a user