This repository has been archived by the owner on Nov 1, 2024. It is now read-only.
forked from new-frontiers-14/frontier-station-14
-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
291 additions
and
4 deletions.
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
Content.Client/Radio/Ui/HandheldRadioBoundUserInterface.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
using Content.Shared.Radio; | ||
using JetBrains.Annotations; | ||
using Robust.Client.GameObjects; | ||
|
||
namespace Content.Client.Radio.Ui; | ||
|
||
|
||
[UsedImplicitly] | ||
public sealed class HandheldRadioBoundUserInterface : BoundUserInterface | ||
{ | ||
[ViewVariables] | ||
private HandheldRadioMenu? _menu; | ||
|
||
public HandheldRadioBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey) | ||
{ | ||
|
||
} | ||
|
||
protected override void Open() | ||
{ | ||
base.Open(); | ||
|
||
_menu = new(); | ||
|
||
_menu.OnMicPressed += enabled => | ||
{ | ||
SendMessage(new ToggleHandheldRadioMicMessage(enabled)); | ||
}; | ||
_menu.OnSpeakerPressed += enabled => | ||
{ | ||
SendMessage(new ToggleHandheldRadioSpeakerMessage(enabled)); | ||
}; | ||
_menu.OnFrequencyChanged += frequency => | ||
{ | ||
SendMessage(new SelectHandheldRadioFrequencyMessage(frequency)); | ||
}; | ||
|
||
_menu.OnClose += Close; | ||
_menu.OpenCentered(); | ||
} | ||
|
||
protected override void Dispose(bool disposing) | ||
{ | ||
base.Dispose(disposing); | ||
if (!disposing) | ||
return; | ||
_menu?.Close(); | ||
} | ||
|
||
protected override void UpdateState(BoundUserInterfaceState state) | ||
{ | ||
base.UpdateState(state); | ||
|
||
if (state is not HandheldRadioBoundUIState msg) | ||
return; | ||
|
||
_menu?.Update(msg); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<controls:FancyWindow xmlns="https://spacestation14.io" | ||
xmlns:controls="clr-namespace:Content.Client.UserInterface.Controls" | ||
Title="{Loc 'handheld-radio-menu-title'}" | ||
MinSize="200 170" | ||
SetSize="200 170"> | ||
<BoxContainer Orientation="Vertical" | ||
HorizontalExpand="True" | ||
VerticalExpand="True" | ||
Margin="5 0 5 0"> | ||
<Control MinHeight="10"/> | ||
<BoxContainer Orientation="Vertical" SeparationOverride="4" MinWidth="150"> | ||
<Label Name="CurrentTextFrequency" Text="{Loc 'handheld-radio-current-text-frequency'}" /> | ||
<LineEdit Name="FrequencyLineEdit" /> | ||
</BoxContainer> | ||
<BoxContainer Orientation="Horizontal" HorizontalExpand="True" HorizontalAlignment="Right" Margin="5 0 5 5"> | ||
<Button Name="MicButton" ToggleMode="True" Text="{Loc 'handheld-radio-button-text-mic'}" StyleClasses="OpenRight" MinWidth="70"/> | ||
<Button Name="SpeakerButton" ToggleMode="True" Text="{Loc 'handheld-radio-button-text-speaker'}" StyleClasses="OpenLeft" MinWidth="70"/> | ||
</BoxContainer> | ||
<BoxContainer Orientation="Vertical"> | ||
<PanelContainer StyleClasses="LowDivider" /> | ||
<BoxContainer Orientation="Horizontal" Margin="10 2 5 0" VerticalAlignment="Bottom"> | ||
<Label Text="{Loc 'handheld-radio-flavor-text-left'}" StyleClasses="WindowFooterText" | ||
HorizontalAlignment="Left" HorizontalExpand="True" Margin="0 0 5 0" /> | ||
<TextureRect StyleClasses="NTLogoDark" Stretch="KeepAspectCentered" | ||
VerticalAlignment="Center" HorizontalAlignment="Right" SetSize="19 19"/> | ||
</BoxContainer> | ||
</BoxContainer> | ||
</BoxContainer> | ||
</controls:FancyWindow> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using Content.Client.UserInterface.Controls; | ||
using Content.Shared.Radio; | ||
using Robust.Client.AutoGenerated; | ||
using Robust.Client.UserInterface.XAML; | ||
using Robust.Shared.Prototypes; | ||
|
||
namespace Content.Client.Radio.Ui; | ||
|
||
[GenerateTypedNameReferences] | ||
public sealed partial class HandheldRadioMenu : FancyWindow | ||
{ | ||
|
||
public event Action<bool>? OnMicPressed; | ||
public event Action<bool>? OnSpeakerPressed; | ||
public event Action<string>? OnFrequencyChanged; | ||
|
||
public HandheldRadioMenu() | ||
{ | ||
RobustXamlLoader.Load(this); | ||
IoCManager.InjectDependencies(this); | ||
|
||
MicButton.OnPressed += args => OnMicPressed?.Invoke(args.Button.Pressed); | ||
SpeakerButton.OnPressed += args => OnSpeakerPressed?.Invoke(args.Button.Pressed); | ||
|
||
FrequencyLineEdit.OnTextEntered += e => OnFrequencyChanged?.Invoke(e.Text); | ||
FrequencyLineEdit.OnFocusExit += e => OnFrequencyChanged?.Invoke(e.Text); | ||
} | ||
|
||
public void Update(HandheldRadioBoundUIState state) | ||
{ | ||
MicButton.Pressed = state.MicEnabled; | ||
SpeakerButton.Pressed = state.SpeakerEnabled; | ||
FrequencyLineEdit.Text = state.Frequency.ToString(); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
using Robust.Shared.Serialization; | ||
|
||
namespace Content.Shared.Radio; | ||
|
||
[Serializable, NetSerializable] | ||
public enum HandheldRadioUiKey : byte | ||
{ | ||
Key, | ||
} | ||
|
||
[Serializable, NetSerializable] | ||
public sealed class HandheldRadioBoundUIState : BoundUserInterfaceState | ||
{ | ||
public bool MicEnabled; | ||
public bool SpeakerEnabled; | ||
public int Frequency; | ||
|
||
public HandheldRadioBoundUIState(bool micEnabled, bool speakerEnabled, int frequency) | ||
{ | ||
MicEnabled = micEnabled; | ||
SpeakerEnabled = speakerEnabled; | ||
Frequency = frequency; | ||
} | ||
} | ||
|
||
[Serializable, NetSerializable] | ||
public sealed class ToggleHandheldRadioMicMessage : BoundUserInterfaceMessage | ||
{ | ||
public bool Enabled; | ||
|
||
public ToggleHandheldRadioMicMessage(bool enabled) | ||
{ | ||
Enabled = enabled; | ||
} | ||
} | ||
|
||
[Serializable, NetSerializable] | ||
public sealed class ToggleHandheldRadioSpeakerMessage : BoundUserInterfaceMessage | ||
{ | ||
public bool Enabled; | ||
|
||
public ToggleHandheldRadioSpeakerMessage(bool enabled) | ||
{ | ||
Enabled = enabled; | ||
} | ||
} | ||
|
||
[Serializable, NetSerializable] | ||
public sealed class SelectHandheldRadioFrequencyMessage : BoundUserInterfaceMessage | ||
{ | ||
public int Frequency; | ||
|
||
public SelectHandheldRadioFrequencyMessage(string frequency) | ||
{ | ||
int.TryParse(frequency.Trim(), out Frequency); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
handheld-radio-menu-title = Handheld radio. | ||
handheld-radio-current-text-frequency = Broadcast frequency | ||
handheld-radio-button-text-mic = Mic. | ||
handheld-radio-button-text-speaker = Speak | ||
handheld-radio-flavor-text-left = Wiretapping of closed frequencies | ||
is punishable by law. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
handheld-radio-menu-title = Портативная рация. | ||
handheld-radio-current-text-frequency = Частота вещания | ||
handheld-radio-button-text-mic = Микр. | ||
handheld-radio-button-text-speaker = Динам. | ||
handheld-radio-flavor-text-left = Прослушивание закрытых частот | ||
карается законом. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters