forked from SS14-Classic/deep-station-14
-
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.
Resolves Simple-Station/Einstein-Engines#37 # Description This PR adds languages. Every entity who can speak now speaks a specific language (or Universal, for entities that are not supposed to speak, which is understood by everyone). Other entities who do not understand this language will see gibberish (it's possible to learn how certain induvidual words are spelled. But the spelling changes between rounds). This means that certain creatures, like xenos, cats, vulps, can communicate within their species in their own languages. Similarly, it means that xenos, cats and other things cannot understand GalacticCommon speakers without a translator or cognization. An entity may be able to speak multiple languages, or understand a language but be unable to speak it. Thi PR was orignally made for Frontier but is now being ported and will be maintain here. Orignal PR: new-frontiers-14/frontier-station-14#671 This PR was made orignally by Mnemotechnician and FoxxoTrystan. --- # TODO - [x] Language System. (Check Frontier PR for all the compleated todo list) - [x] Port PR from Frontier. - [x] QOL Changes. - [x] Missing Default Languages. (Missing default langauges for some roundstart species) - [x] Animals Languages. --- <details><summary><h1>Media</h1></summary> <p> ![image](https://github.com/Simple-Station/Einstein-Engines/assets/45297731/fc43efd9-612e-4a6d-8ed6-90a26d315c6f) ![image](https://github.com/Simple-Station/Einstein-Engines/assets/45297731/b86616a3-d5fb-408d-865e-90d09096b6d7) ![image](https://github.com/Simple-Station/Einstein-Engines/assets/45297731/ab1e8581-522d-4e7e-95e8-f62575bc5039) </p> </details> --- # Changelog :cl: FoxxoTrystan / Mnemotechnician - add: All species can now bring their own cultures and languages --------- Signed-off-by: Mnemotechnican <[email protected]> Signed-off-by: FoxxoTrystan <[email protected]> Co-authored-by: fox <[email protected]> Co-authored-by: Mnemotechnican <[email protected]> Co-authored-by: Pspritechologist <[email protected]> Co-authored-by: Lincoln McQueen <[email protected]> Co-authored-by: Arkyfloof <[email protected]> Co-authored-by: reese1243 <[email protected]> Co-authored-by: VMSolidus <[email protected]> Co-authored-by: Eagle-0 <[email protected]> Co-authored-by: BlitzDev <[email protected]> Co-authored-by: Arkyfloof <[email protected]> Co-authored-by: Danger Revolution! <[email protected]> Co-authored-by: DEATHB4DEFEAT <[email protected]>
- Loading branch information
1 parent
310e3ae
commit 82edb60
Showing
87 changed files
with
3,270 additions
and
134 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,134 @@ | ||
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 Serilog; | ||
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>(); | ||
} | ||
|
||
protected override void Opened() | ||
{ | ||
// Refresh the window when it gets opened. | ||
// This actually causes two refreshes: one immediately, and one after the server sends a state message. | ||
UpdateState(_clientLanguageSystem.CurrentLanguage, _clientLanguageSystem.SpokenLanguages); | ||
_clientLanguageSystem.RequestStateUpdate(); | ||
} | ||
|
||
|
||
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.GetLanguagePrototype(language); | ||
var state = new EntryState { language = language }; | ||
|
||
var container = new BoxContainer { Orientation = BoxContainer.LayoutOrientation.Vertical }; | ||
|
||
#region Header | ||
var header = new BoxContainer | ||
{ | ||
Orientation = BoxContainer.LayoutOrientation.Horizontal, | ||
HorizontalExpand = true, | ||
SeparationOverride = 2 | ||
}; | ||
|
||
var name = new Label | ||
{ | ||
Text = proto?.Name ?? Loc.GetString("generic-error"), | ||
MinWidth = 50, | ||
HorizontalExpand = true | ||
}; | ||
|
||
var button = new Button { Text = "Choose" }; | ||
button.OnPressed += _ => OnLanguageChosen(language); | ||
state.button = button; | ||
|
||
header.AddChild(name); | ||
header.AddChild(button); | ||
|
||
container.AddChild(header); | ||
#endregion | ||
|
||
#region Collapsible description | ||
var body = new CollapsibleBody | ||
{ | ||
HorizontalExpand = true, | ||
Margin = new Thickness(4f, 4f) | ||
}; | ||
|
||
var description = new RichTextLabel { HorizontalExpand = true }; | ||
description.SetMessage(proto?.Description ?? Loc.GetString("generic-error")); | ||
body.AddChild(description); | ||
|
||
var collapser = new Collapsible(Loc.GetString("language-menu-description-header"), body) | ||
{ | ||
Orientation = BoxContainer.LayoutOrientation.Vertical, | ||
HorizontalExpand = true | ||
}; | ||
|
||
container.AddChild(collapser); | ||
#endregion | ||
|
||
// 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.GetLanguagePrototype(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,76 @@ | ||
using Content.Shared.Language; | ||
using Content.Shared.Language.Events; | ||
using Content.Shared.Language.Systems; | ||
using Robust.Client; | ||
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 | ||
{ | ||
[Dependency] private readonly IBaseClient _client = default!; | ||
|
||
/// <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(); | ||
|
||
public override void Initialize() | ||
{ | ||
base.Initialize(); | ||
|
||
SubscribeNetworkEvent<LanguagesUpdatedMessage>(OnLanguagesUpdated); | ||
_client.RunLevelChanged += OnRunLevelChanged; | ||
} | ||
|
||
private void OnLanguagesUpdated(LanguagesUpdatedMessage message) | ||
{ | ||
CurrentLanguage = message.CurrentLanguage; | ||
SpokenLanguages = message.Spoken; | ||
UnderstoodLanguages = message.Understood; | ||
} | ||
|
||
private void OnRunLevelChanged(object? sender, RunLevelChangedEventArgs args) | ||
{ | ||
// Request an update when entering a game | ||
if (args.NewLevel == ClientRunLevel.InGame) | ||
RequestStateUpdate(); | ||
} | ||
|
||
/// <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) | ||
{ | ||
if (language.ID == CurrentLanguage) | ||
return; | ||
|
||
RaiseNetworkEvent(new LanguagesSetMessage(language.ID)); | ||
|
||
// May cause some minor desync... | ||
// So to reduce the probability of desync, we replicate the change locally too | ||
if (SpokenLanguages.Contains(language.ID)) | ||
CurrentLanguage = language.ID; | ||
} | ||
} |
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
89 changes: 89 additions & 0 deletions
89
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,89 @@ | ||
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 _) => | ||
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 += () => LanguageButton.Pressed = false; | ||
LanguageWindow.OnOpen += () => LanguageButton.Pressed = true; | ||
} | ||
|
||
private void LanguageButtonPressed(ButtonEventArgs args) | ||
{ | ||
ToggleWindow(); | ||
} | ||
|
||
private void ToggleWindow() | ||
{ | ||
if (LanguageWindow == null) | ||
return; | ||
|
||
if (LanguageButton != null) | ||
LanguageButton.SetClickPressed(!LanguageWindow.IsOpen); | ||
|
||
if (LanguageWindow.IsOpen) | ||
LanguageWindow.Close(); | ||
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
Oops, something went wrong.