Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Languages #43

Merged
merged 92 commits into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
92 commits
Select commit Hold shift + click to select a range
da76123
Fixes for universal speakers (no more walls speaking GC)
Mnemotechnician Mar 20, 2024
a95f105
Fixes for universal speakers (no more walls speaking GC)
Mnemotechnician Mar 20, 2024
728e9b1
Fixes for universal speakers (no more walls speaking GC)
Mnemotechnician Mar 20, 2024
113826b
Revert "Fixes for universal speakers (no more walls speaking GC)"
FoxxoTrystan Mar 24, 2024
6bdc514
Fixes for universal speakers (no more walls speaking GC)
Mnemotechnician Mar 20, 2024
3d86f02
Port
FoxxoTrystan Mar 24, 2024
bf80a15
Missing Default Langauges (Only Harpies duh)
FoxxoTrystan Mar 25, 2024
c65c1d3
Animals SPEAKS!
FoxxoTrystan Mar 25, 2024
c61e061
Apply suggestions from code review
Mnemotechnician Mar 30, 2024
0b7dd07
Did what the review suggested
Mnemotechnician Mar 30, 2024
54b15c1
Merge remote-tracking branch 'upstream/master' into Languages
FoxxoTrystan Mar 31, 2024
f3b2daa
abstract + yml changes
FoxxoTrystan Mar 31, 2024
381eea1
Split translator comps into separate files and pray it compiles
Mnemotechnician Apr 7, 2024
6f841fb
Refactor RadioReceiveEvent
Mnemotechnician Apr 7, 2024
cdb786c
Refactor ChatSystem & add comments
Mnemotechnician Apr 7, 2024
f9dcd71
Clean up using directives after jetbrains rider messed em up
Mnemotechnician Apr 7, 2024
4bc2c46
Merge branch 'master' into Languages
FoxxoTrystan Apr 8, 2024
076bfc3
Merge branch 'Simple-Station:master' into Languages
FoxxoTrystan Apr 24, 2024
7dff567
Tiny Fixes/Requests
FoxxoTrystan Apr 24, 2024
a0d8c08
Added the most basic of syndicate flavor
Eagle-0 Apr 25, 2024
d14461e
Synths real
Eagle-0 Apr 25, 2024
55794de
Updated Door Sprites, syndicate Dropship, Saltern, Captains Cape
Arkyfloof Apr 26, 2024
4c3724d
Fixed traitors, new synth sounds, Urist update
Eagle-0 Apr 26, 2024
e819a63
Mechs real, Synth balance, Terragov Preset
Eagle-0 Apr 27, 2024
ec92c56
Changed cargo gifts, no more centcomm, urist shuttles
Eagle-0 Apr 28, 2024
937a4d9
Resolved Test
FoxxoTrystan Apr 29, 2024
21dd8dd
Update LanguageMenuUIController.cs
FoxxoTrystan Apr 29, 2024
f6d46f8
Added new Shuttle for the Terragov faction
Reese1243 Apr 29, 2024
1baab28
added a new shuttle for the TerraGov faction
Reese1243 Apr 29, 2024
c1287b8
Fixed some announcements, centcom name change, atmosia fake
Eagle-0 Apr 29, 2024
ba7d807
Delete TerraGovernor.yml
Reese1243 Apr 30, 2024
1618f20
SyndieSaltern
VMSolidus Apr 30, 2024
c10d283
Merge pull request #3 from Eagle-0/saltern-updates
Eagle-0 Apr 30, 2024
0983aa7
Update LanguageMenuUIController.cs
FoxxoTrystan May 1, 2024
b3ad259
Merge branch 'Simple-Station:master' into Languages
FoxxoTrystan May 1, 2024
041ef46
Update LanguageMenuUIController.cs
FoxxoTrystan May 1, 2024
7452487
Update LanguageMenuUIController.cs
FoxxoTrystan May 1, 2024
2b3a807
Merge branch 'Languages' of https://github.com/FoxxoTrystan/Einstein-…
FoxxoTrystan May 1, 2024
a938832
Update LanguageMenuUIController.cs
FoxxoTrystan May 1, 2024
e66df36
Update LanguageMenuUIController.cs
FoxxoTrystan May 1, 2024
c507898
Added terragov shuttle
Reese1243 May 1, 2024
70987a9
Merge pull request #4 from Eagle-0/Blitz
Reese1243 May 1, 2024
5ce48b2
Reverting
FoxxoTrystan May 1, 2024
d5d51b6
Uhh, test, if this works accept it
Arkyfloof May 1, 2024
b47718d
Merge pull request #5 from Eagle-0/arky
Arkyfloof May 1, 2024
52c4566
swapped the Shuttle Consoles and Communications consoles to the syndi…
Reese1243 May 1, 2024
d2ca520
Mons are real, Total Catgirl removal
Eagle-0 May 1, 2024
d873884
Edited Terragov shuttle
Reese1243 May 1, 2024
8af1830
Changed Antag role timers to match Wizards Den
Reese1243 May 1, 2024
5300226
Changed Antag role timers to match Wizards Den
Reese1243 May 1, 2024
93e7218
Merge branch 'Blitz' of https://github.com/Eagle-0/Syndicate-Station …
Reese1243 May 1, 2024
873ab05
Merge branch 'master' into Blitz
Reese1243 May 2, 2024
a7fefa4
New SOM guns, broken clothing :sob:
Eagle-0 May 2, 2024
b5a6013
Fixed LoneOps time requirement to be the same as NukeOps
Reese1243 May 3, 2024
a4ecd2b
Merge branch 'master' of https://github.com/Eagle-0/Syndicate-Station
Eagle-0 May 3, 2024
875cf7b
Update LanguageMenuUIController.cs
FoxxoTrystan May 3, 2024
5201873
Merge branch 'master' into Languages
FoxxoTrystan May 3, 2024
96e1c0a
Update LanguageMenuUIController.cs
FoxxoTrystan May 3, 2024
7c2621b
Merge branch 'Languages' of https://github.com/FoxxoTrystan/Einstein-…
FoxxoTrystan May 3, 2024
5023cc4
Update LanguageMenuUIController.cs
FoxxoTrystan May 3, 2024
38060c9
Finally Fixing it
VMSolidus May 3, 2024
9f6ee28
Update LanguageMenuUIController.cs
FoxxoTrystan May 3, 2024
54dee4f
Update LanguageMenuUIController.cs
FoxxoTrystan May 3, 2024
b75939c
Fixed SOM gear
Eagle-0 May 3, 2024
87a0a87
Merge branch 'master' into Languages
FoxxoTrystan May 5, 2024
d935e80
Added HoP drip, new Terragov uplink items
Eagle-0 May 5, 2024
6234be8
UI Better and Test!
FoxxoTrystan May 6, 2024
ec9116a
Oops
FoxxoTrystan May 6, 2024
afdb7ce
Merge branch 'master' into Languages
FoxxoTrystan May 6, 2024
932bc29
SPACE!
FoxxoTrystan May 6, 2024
90f3588
Merge branch 'Languages' of https://github.com/FoxxoTrystan/Einstein-…
FoxxoTrystan May 6, 2024
f2adcee
Merge branch 'master' into Languages
FoxxoTrystan May 6, 2024
f5e8bca
Revert "Merge branch 'master' into Languages"
FoxxoTrystan May 6, 2024
c25d2ec
Update Resources/Prototypes/Entities/Objects/Devices/translator_impla…
FoxxoTrystan May 7, 2024
566d861
Update Resources/Prototypes/Entities/Objects/Devices/translator_impla…
FoxxoTrystan May 7, 2024
146c32f
Merge branch 'master' into Languages
FoxxoTrystan May 7, 2024
9cb5950
Networking OnClientSetLanguage
FoxxoTrystan May 8, 2024
f526f0a
Move LanguageSpeaker from BaseMobSpeciesOrganic to BaseMobSpecies
FoxxoTrystan May 9, 2024
0fa806c
Merge branch 'master' into Languages
FoxxoTrystan May 9, 2024
dea18f0
Merge branch 'master' into Languages
VMSolidus May 12, 2024
e0d65d4
Merge branch 'master' into Languages
VMSolidus May 12, 2024
a85ed4d
Parrots Moments
FoxxoTrystan May 12, 2024
e23dabe
Merge branch 'Simple-Station:master' into Languages
FoxxoTrystan May 13, 2024
f336f5a
Sanitize Messes!
FoxxoTrystan May 13, 2024
5ebbbc0
Merge branch 'Simple-Station:master' into Languages
FoxxoTrystan May 13, 2024
b9850d8
Merge branch 'master' into Languages
FoxxoTrystan May 28, 2024
19697bb
Merge branch 'master' into Languages
FoxxoTrystan Jun 3, 2024
789cf4e
Apply (some) suggestions from code review
Mnemotechnician Jun 4, 2024
1d7d5d2
Please, for the sake of god and all that's holy, never ever creature …
Mnemotechnician Jun 4, 2024
f6f6679
More refactoring & linter fixes
Mnemotechnician Jun 4, 2024
c4cec66
Lots of refactoring; partially fixed language menu desync
Mnemotechnician Jun 4, 2024
7581981
Update Content.Server/Chat/Systems/ChatSystem.cs
FoxxoTrystan Jun 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Content.Client/Input/ContentContexts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public static void SetupContexts(IInputContextContainer contexts)
human.AddFunction(ContentKeyFunctions.UseItemInHand);
human.AddFunction(ContentKeyFunctions.AltUseItemInHand);
human.AddFunction(ContentKeyFunctions.OpenCharacterMenu);
human.AddFunction(ContentKeyFunctions.OpenLanguageMenu);
human.AddFunction(ContentKeyFunctions.ActivateItemInWorld);
human.AddFunction(ContentKeyFunctions.ThrowItemInHand);
human.AddFunction(ContentKeyFunctions.AltActivateItemInWorld);
Expand Down
18 changes: 18 additions & 0 deletions Content.Client/Language/LanguageMenuWindow.xaml
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps see if you can get anyone experienced in UI involved to make something neat looking? A little slimmer would also probably be better for a utilitarian-menu.

Also this should probably be a FancyWindow

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="a"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bad place holder title. You should also be able to embed the localization call for the title directly in here rather than in the system, see other UI.

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>
123 changes: 123 additions & 0 deletions Content.Client/Language/LanguageMenuWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
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>();

Title = Loc.GetString("language-menu-window-title");
}

public void UpdateState(string currentLanguage, List<string> spokenLanguages)
{
var langName = LanguagePrototype.GetLocalizedName(currentLanguage);
CurrentLanguageLabel.Text = Loc.GetString("language-menu-current-language", ("language", langName ?? "<error>"));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple notes, first off, this seems very strange when the name can be accessed directly through the property. Furthermore, this doesn't need to be validated with '' since GetString will always return a string, it just may be the same one you gave it. Loc.TryGetString can return null, but not GetString.
Just replace langName in the function call with LanguagePrototype

I have only just realized you're using it as a static. Ah. Let me rethink that.
Probably just don't. Get the name from elsewhere, or simply resolve the prototype here and now. It's not a big deal.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace line 30 with resolving the prototype with the ID we have and then get name from prototype.
Remove ?? "Error"
IoCManager.Resolve<>


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;
Mnemotechnician marked this conversation as resolved.
Show resolved Hide resolved

// 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;
Mnemotechnician marked this conversation as resolved.
Show resolved Hide resolved

var name = new Label();
name.Text = proto?.LocalizedName ?? "<error>";
name.MinWidth = 50;
name.HorizontalExpand = true;

var button = new Button();
button.Text = "Choose";
button.OnPressed += _ => OnLanguageChosen(language);
state.button = button;
Mnemotechnician marked this conversation as resolved.
Show resolved Hide resolved

FoxxoTrystan marked this conversation as resolved.
Show resolved Hide resolved
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);
Mnemotechnician marked this conversation as resolved.
Show resolved Hide resolved

var description = new RichTextLabel();
description.SetMessage(proto?.LocalizedDescription ?? "<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;
Mnemotechnician marked this conversation as resolved.
Show resolved Hide resolved

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);
}

Mnemotechnician marked this conversation as resolved.
Show resolved Hide resolved
private struct EntryState
{
public string language;
public Button? button;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
using System.Linq;
using System.Numerics;
using Content.Client.Language.Systems;
using Content.Client.UserInterface.Systems.Chat.Controls;
using Content.Client.UserInterface.Systems.Language;
using Content.Shared.Language;
using Robust.Client.UserInterface;
using Robust.Shared.Utility;

namespace Content.Client.Language.Systems.Chat.Controls;

// Mostly copied from ChannelSelectorButton
public sealed class LanguageSelectorButton : ChatPopupButton<LanguageSelectorPopup>
{
public LanguagePrototype? SelectedLanguage { get; private set; }

private const int SelectorDropdownOffset = 38;

public LanguageSelectorButton()
{
Name = "LanguageSelector";

Popup.Selected += Select;

if (Popup.FirstLanguage is { } firstSelector)
{
Select(firstSelector);
}

IoCManager.Resolve<IUserInterfaceManager>().GetUIController<LanguageMenuUIController>().LanguagesUpdatedHook += UpdateLanguage;
}

private void UpdateLanguage((string current, List<string> spoken, List<string> understood) args)
{
Popup.SetLanguages(args.spoken);

// Kill me please
SelectedLanguage = IoCManager.Resolve<IEntitySystemManager>().GetEntitySystem<LanguageSystem>().GetLanguage(args.current);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make a variable for this system and cache it in the constructor when the UI starts instead of resolving it every time.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to do that before and it turned out that UI is created before systems are loaded, where'd you suggest caching it to avoid that?

Text = LanguageSelectorName(SelectedLanguage!);
}

protected override UIBox2 GetPopupPosition()
{
var globalLeft = GlobalPosition.X;
var globalBot = GlobalPosition.Y + Height;
return UIBox2.FromDimensions(
new Vector2(globalLeft, globalBot),
new Vector2(SizeBox.Width, SelectorDropdownOffset));
}

public void Select(LanguagePrototype language)
{
if (Popup.Visible)
{
Popup.Close();
}

if (SelectedLanguage == language)
return;
SelectedLanguage = language;
IoCManager.Resolve<IEntitySystemManager>().GetEntitySystem<LanguageSystem>().RequestSetLanguage(language);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto


Text = LanguageSelectorName(language);
}

public static string LanguageSelectorName(LanguagePrototype language, bool full = false)
{
var name = language.LocalizedName;

// if the language name is short enough, just return it
if (full || name.Length < 5)
return name;

// If the language name is multi-word, collect first letters and capitalize them
if (name.Contains(' '))
{
var result = name
.Split(" ")
.Select(it => it.FirstOrNull())
.Where(it => it != null)
.Select(it => char.ToUpper(it!.Value));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't love the name 'it' for this, makes it even harder to read :P
Add some inline comments to the right of each line here with a quick few words on what it's doing. Also maybe consider a cleaner way of doing this(?)


return new string(result.ToArray());
}

// Alternatively, take the first 5 letters
return name[..5];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using Content.Client.Stylesheets;
using Content.Client.UserInterface.Systems.Chat;
using Content.Client.UserInterface.Systems.Chat.Controls;
using Content.Shared.Chat;
using Content.Shared.Language;
using Robust.Client.UserInterface.Controls;

namespace Content.Client.Language.Systems.Chat.Controls;

// Mostly copied from ChannelSelectorItemButton
public sealed class LanguageSelectorItemButton : Button
{
public readonly LanguagePrototype Language;

public bool IsHidden => Parent == null;

public LanguageSelectorItemButton(LanguagePrototype language)
{
Language = language;
AddStyleClass(StyleNano.StyleClassChatChannelSelectorButton);

Text = LanguageSelectorButton.LanguageSelectorName(language, full: true);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
using Content.Client.Language.Systems;
using Content.Client.UserInterface.Systems.Language;
using Content.Shared.Language;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using static Robust.Client.UserInterface.Controls.BaseButton;

namespace Content.Client.Language.Systems.Chat.Controls;

// Mostly copied from LanguageSelectorPopup
public sealed class LanguageSelectorPopup : Popup
{
private readonly BoxContainer _channelSelectorHBox;
private readonly Dictionary<string, LanguageSelectorItemButton> _selectorStates = new();

public event Action<LanguagePrototype>? Selected;

public LanguageSelectorPopup()
{
_channelSelectorHBox = new BoxContainer
{
Orientation = BoxContainer.LayoutOrientation.Horizontal,
SeparationOverride = 1
};

AddChild(_channelSelectorHBox);
}

public LanguagePrototype? FirstLanguage
{
get
{
foreach (var selector in _selectorStates.Values)
{
if (!selector.IsHidden)
return selector.Language;
}

return null;
}
}

public void SetLanguages(List<string> languages)
{
var languageSystem = IoCManager.Resolve<IEntitySystemManager>().GetEntitySystem<LanguageSystem>();
_channelSelectorHBox.RemoveAllChildren();

foreach (var language in languages)
{
if (!_selectorStates.TryGetValue(language, out var selector))
{
var proto = languageSystem.GetLanguage(language);
if (proto == null)
continue;

selector = new LanguageSelectorItemButton(proto);
_selectorStates[language] = selector;
selector.OnPressed += OnSelectorPressed;
}

if (selector.IsHidden)
{
_channelSelectorHBox.AddChild(selector);
}
}
}

private void OnSelectorPressed(ButtonEventArgs args)
{
var button = (LanguageSelectorItemButton) args.Button;
Select(button.Language);
}

private void Select(LanguagePrototype language)
{
Selected?.Invoke(language);
}
}
Loading
Loading