forked from Simple-Station/Einstein-Engines
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request Simple-Station#7 from FoxxoTrystan/Languages
Languages
- Loading branch information
Showing
86 changed files
with
3,270 additions
and
136 deletions.
There are no files selected for viewing
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,18 @@ | ||
<DefaultWindow xmlns="https://spacestation14.io" | ||
xmlns:ui="clr-namespace:Content.Client.UserInterface.Controls" | ||
Title="{Loc language-menu-window-title}" | ||
SetSize="300 300"> | ||
<BoxContainer Orientation="Vertical" SeparationOverride="4" MinWidth="150"> | ||
<PanelContainer Name="CurrentLanguageContainer" Access="Public" StyleClasses="PdaBorderRect"> | ||
<Label Name="CurrentLanguageLabel" Access="Public" Text="Current Language:" HorizontalExpand="True"></Label> | ||
</PanelContainer> | ||
|
||
<ui:HLine></ui:HLine> | ||
|
||
<ScrollContainer HorizontalExpand="True" VerticalExpand="True" HScrollEnabled="False" VScrollEnabled="True" MinHeight="50"> | ||
<BoxContainer Name="OptionsList" Access="Public" HorizontalExpand="True" SeparationOverride="2" Orientation="Vertical"> | ||
<!-- The rest here is generated programmatically --> | ||
</BoxContainer> | ||
</ScrollContainer> | ||
</BoxContainer> | ||
</DefaultWindow> |
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,121 @@ | ||
using Content.Client.Language.Systems; | ||
using Content.Shared.Language; | ||
using Content.Shared.Language.Systems; | ||
using Robust.Client.AutoGenerated; | ||
using Robust.Client.UserInterface.Controls; | ||
using Robust.Client.UserInterface.CustomControls; | ||
using Robust.Client.UserInterface.XAML; | ||
using Robust.Shared.Console; | ||
using Robust.Shared.Utility; | ||
using static Content.Shared.Language.Systems.SharedLanguageSystem; | ||
|
||
namespace Content.Client.Language; | ||
|
||
[GenerateTypedNameReferences] | ||
public sealed partial class LanguageMenuWindow : DefaultWindow | ||
{ | ||
private readonly LanguageSystem _clientLanguageSystem; | ||
private readonly List<EntryState> _entries = new(); | ||
|
||
public LanguageMenuWindow() | ||
{ | ||
RobustXamlLoader.Load(this); | ||
_clientLanguageSystem = IoCManager.Resolve<IEntitySystemManager>().GetEntitySystem<LanguageSystem>(); | ||
} | ||
|
||
public void UpdateState(string currentLanguage, List<string> spokenLanguages) | ||
{ | ||
var langName = Loc.GetString($"language-{currentLanguage}-name"); | ||
CurrentLanguageLabel.Text = Loc.GetString("language-menu-current-language", ("language", langName)); | ||
|
||
OptionsList.RemoveAllChildren(); | ||
_entries.Clear(); | ||
|
||
foreach (var language in spokenLanguages) | ||
{ | ||
AddLanguageEntry(language); | ||
} | ||
|
||
// Disable the button for the currently chosen language | ||
foreach (var entry in _entries) | ||
{ | ||
if (entry.button != null) | ||
entry.button.Disabled = entry.language == currentLanguage; | ||
} | ||
} | ||
|
||
private void AddLanguageEntry(string language) | ||
{ | ||
var proto = _clientLanguageSystem.GetLanguage(language); | ||
var state = new EntryState { language = language }; | ||
|
||
var container = new BoxContainer(); | ||
container.Orientation = BoxContainer.LayoutOrientation.Vertical; | ||
|
||
// Create and add a header with the name and the button to select the language | ||
{ | ||
var header = new BoxContainer(); | ||
header.Orientation = BoxContainer.LayoutOrientation.Horizontal; | ||
|
||
header.Orientation = BoxContainer.LayoutOrientation.Horizontal; | ||
header.HorizontalExpand = true; | ||
header.SeparationOverride = 2; | ||
|
||
var name = new Label(); | ||
name.Text = proto?.Name ?? "<error>"; | ||
name.MinWidth = 50; | ||
name.HorizontalExpand = true; | ||
|
||
var button = new Button(); | ||
button.Text = "Choose"; | ||
button.OnPressed += _ => OnLanguageChosen(language); | ||
state.button = button; | ||
|
||
header.AddChild(name); | ||
header.AddChild(button); | ||
|
||
container.AddChild(header); | ||
} | ||
|
||
// Create and add a collapsible description | ||
{ | ||
var body = new CollapsibleBody(); | ||
body.HorizontalExpand = true; | ||
body.Margin = new Thickness(4f, 4f); | ||
|
||
var description = new RichTextLabel(); | ||
description.SetMessage(proto?.Description ?? "<error>"); | ||
description.HorizontalExpand = true; | ||
|
||
body.AddChild(description); | ||
|
||
var collapser = new Collapsible(Loc.GetString("language-menu-description-header"), body); | ||
collapser.Orientation = BoxContainer.LayoutOrientation.Vertical; | ||
collapser.HorizontalExpand = true; | ||
|
||
container.AddChild(collapser); | ||
} | ||
|
||
// Before adding, wrap the new container in a PanelContainer to give it a distinct look | ||
var wrapper = new PanelContainer(); | ||
wrapper.StyleClasses.Add("PdaBorderRect"); | ||
|
||
wrapper.AddChild(container); | ||
OptionsList.AddChild(wrapper); | ||
|
||
_entries.Add(state); | ||
} | ||
|
||
private void OnLanguageChosen(string id) | ||
{ | ||
var proto = _clientLanguageSystem.GetLanguage(id); | ||
if (proto != null) | ||
_clientLanguageSystem.RequestSetLanguage(proto); | ||
} | ||
|
||
private struct EntryState | ||
{ | ||
public string language; | ||
public Button? button; | ||
} | ||
} |
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,67 @@ | ||
using Content.Shared.Language; | ||
using Content.Shared.Language.Events; | ||
using Content.Shared.Language.Systems; | ||
using Robust.Shared.Console; | ||
|
||
namespace Content.Client.Language.Systems; | ||
|
||
/// <summary> | ||
/// Client-side language system. | ||
/// </summary> | ||
/// <remarks> | ||
/// Unlike the server, the client is not aware of other entities' languages; it's only notified about the entity that it posesses. | ||
/// Due to that, this system stores such information in a static manner. | ||
/// </remarks> | ||
public sealed class LanguageSystem : SharedLanguageSystem | ||
{ | ||
/// <summary> | ||
/// The current language of the entity currently possessed by the player. | ||
/// </summary> | ||
public string CurrentLanguage { get; private set; } = default!; | ||
/// <summary> | ||
/// The list of languages the currently possessed entity can speak. | ||
/// </summary> | ||
public List<string> SpokenLanguages { get; private set; } = new(); | ||
/// <summary> | ||
/// The list of languages the currently possessed entity can understand. | ||
/// </summary> | ||
public List<string> UnderstoodLanguages { get; private set; } = new(); | ||
|
||
[Dependency] private readonly IConsoleHost _consoleHost = default!; | ||
|
||
public override void Initialize() | ||
{ | ||
SubscribeNetworkEvent<LanguagesUpdatedMessage>(OnLanguagesUpdated); | ||
} | ||
|
||
/// <summary> | ||
/// Sends a network request to the server to update this system's state. | ||
/// The server may ignore the said request if the player is not possessing an entity. | ||
/// </summary> | ||
public void RequestStateUpdate() | ||
{ | ||
RaiseNetworkEvent(new RequestLanguagesMessage()); | ||
} | ||
|
||
public void RequestSetLanguage(LanguagePrototype language) | ||
{ | ||
// May cause some minor desync... | ||
if (language.ID == CurrentLanguage) | ||
return; | ||
|
||
// (This is dumb. This is very dumb. It should be a message instead.) | ||
// TODO Change this, soonish | ||
_consoleHost.ExecuteCommand("languageselect " + language.ID); | ||
|
||
// So to reduce the probability of desync, we replicate the change locally too | ||
if (SpokenLanguages.Contains(language.ID)) | ||
CurrentLanguage = language.ID; | ||
} | ||
|
||
private void OnLanguagesUpdated(LanguagesUpdatedMessage message) | ||
{ | ||
CurrentLanguage = message.CurrentLanguage; | ||
SpokenLanguages = message.Spoken; | ||
UnderstoodLanguages = message.Understood; | ||
} | ||
} |
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,8 @@ | ||
using Content.Shared.Language.Systems; | ||
|
||
namespace Content.Client.Language.Systems; | ||
|
||
public sealed class TranslatorImplanterSystem : SharedTranslatorImplanterSystem | ||
{ | ||
|
||
} |
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
1 change: 1 addition & 0 deletions
1
Content.Client/UserInterface/Systems/Chat/Controls/ChatInputBox.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
107 changes: 107 additions & 0 deletions
107
Content.Client/UserInterface/Systems/Language/LanguageMenuUIController.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,107 @@ | ||
using Content.Client.Language; | ||
using Content.Client.Gameplay; | ||
using Content.Client.UserInterface.Controls; | ||
using Content.Shared.Input; | ||
using Content.Shared.Language.Events; | ||
using Robust.Client.UserInterface.Controllers; | ||
using Robust.Client.UserInterface.Controls; | ||
using Robust.Shared.Input.Binding; | ||
using Robust.Shared.Utility; | ||
using static Robust.Client.UserInterface.Controls.BaseButton; | ||
using JetBrains.Annotations; | ||
|
||
namespace Content.Client.UserInterface.Systems.Language; | ||
|
||
[UsedImplicitly] | ||
public sealed class LanguageMenuUIController : UIController, IOnStateEntered<GameplayState>, IOnStateExited<GameplayState> | ||
{ | ||
public LanguageMenuWindow? _languageWindow; | ||
private MenuButton? LanguageButton => UIManager.GetActiveUIWidgetOrNull<MenuBar.Widgets.GameTopMenuBar>()?.LanguageButton; | ||
|
||
public override void Initialize() | ||
{ | ||
SubscribeNetworkEvent((LanguagesUpdatedMessage message, EntitySessionEventArgs args) => _languageWindow?.UpdateState(message.CurrentLanguage, message.Spoken)); | ||
} | ||
|
||
public void OnStateEntered(GameplayState state) | ||
{ | ||
DebugTools.Assert(_languageWindow == null); | ||
|
||
_languageWindow = UIManager.CreateWindow<LanguageMenuWindow>(); | ||
LayoutContainer.SetAnchorPreset(_languageWindow, LayoutContainer.LayoutPreset.CenterTop); | ||
|
||
CommandBinds.Builder.Bind(ContentKeyFunctions.OpenLanguageMenu, InputCmdHandler.FromDelegate(_ => ToggleWindow())).Register<LanguageMenuUIController>(); | ||
} | ||
|
||
public void OnStateExited(GameplayState state) | ||
{ | ||
if (_languageWindow != null) | ||
{ | ||
_languageWindow.Dispose(); | ||
_languageWindow = null; | ||
} | ||
|
||
CommandBinds.Unregister<LanguageMenuUIController>(); | ||
} | ||
|
||
public void UnloadButton() | ||
{ | ||
if (LanguageButton == null) | ||
{ | ||
return; | ||
} | ||
|
||
LanguageButton.OnPressed -= LanguageButtonPressed; | ||
} | ||
|
||
public void LoadButton() | ||
{ | ||
if (LanguageButton == null) | ||
{ | ||
return; | ||
} | ||
|
||
LanguageButton.OnPressed += LanguageButtonPressed; | ||
|
||
if (_languageWindow == null) | ||
{ | ||
return; | ||
} | ||
|
||
_languageWindow.OnClose += DeactivateButton; | ||
_languageWindow.OnOpen += ActivateButton; | ||
} | ||
|
||
private void DeactivateButton() => LanguageButton!.Pressed = false; | ||
private void ActivateButton() => LanguageButton!.Pressed = true; | ||
|
||
private void LanguageButtonPressed(ButtonEventArgs args) | ||
{ | ||
ToggleWindow(); | ||
} | ||
|
||
private void CloseWindow() | ||
{ | ||
_languageWindow?.Close(); | ||
} | ||
|
||
private void ToggleWindow() | ||
{ | ||
if (_languageWindow == null) | ||
return; | ||
|
||
if (LanguageButton != null) | ||
{ | ||
LanguageButton.SetClickPressed(!_languageWindow.IsOpen); | ||
} | ||
|
||
if (_languageWindow.IsOpen) | ||
{ | ||
CloseWindow(); | ||
} | ||
else | ||
{ | ||
_languageWindow.Open(); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.