Skip to content
This repository has been archived by the owner on Apr 27, 2024. It is now read-only.

Languages #10

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
using Content.Shared.Chat;
using Content.Client._NF.Language.Systems.Chat.Controls;
using Content.Client.UserInterface.Systems.Language;

Check failure on line 2 in Content.Client/UserInterface/Systems/Chat/Controls/ChatInputBox.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

The type or namespace name 'Language' does not exist in the namespace 'Content.Client.UserInterface.Systems' (are you missing an assembly reference?)

Check failure on line 2 in Content.Client/UserInterface/Systems/Chat/Controls/ChatInputBox.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

The type or namespace name 'Language' does not exist in the namespace 'Content.Client.UserInterface.Systems' (are you missing an assembly reference?)

Check failure on line 2 in Content.Client/UserInterface/Systems/Chat/Controls/ChatInputBox.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

The type or namespace name 'Language' does not exist in the namespace 'Content.Client.UserInterface.Systems' (are you missing an assembly reference?)

Check failure on line 2 in Content.Client/UserInterface/Systems/Chat/Controls/ChatInputBox.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

The type or namespace name 'Language' does not exist in the namespace 'Content.Client.UserInterface.Systems' (are you missing an assembly reference?)

Check failure on line 2 in Content.Client/UserInterface/Systems/Chat/Controls/ChatInputBox.cs

View workflow job for this annotation

GitHub Actions / YAML Linter

The type or namespace name 'Language' does not exist in the namespace 'Content.Client.UserInterface.Systems' (are you missing an assembly reference?)

Check failure on line 2 in Content.Client/UserInterface/Systems/Chat/Controls/ChatInputBox.cs

View workflow job for this annotation

GitHub Actions / YAML Linter

The type or namespace name 'Language' does not exist in the namespace 'Content.Client.UserInterface.Systems' (are you missing an assembly reference?)
using Content.Shared.Chat;
using Content.Shared.Input;
using Content.Shared.Language;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;

namespace Content.Client.UserInterface.Systems.Chat.Controls;
Expand All @@ -8,6 +12,7 @@
public class ChatInputBox : PanelContainer
{
public readonly ChannelSelectorButton ChannelSelector;
public readonly LanguageSelectorButton LanguageSelector; // Frontier
public readonly HistoryLineEdit Input;
public readonly ChannelFilterButton FilterButton;
protected readonly BoxContainer Container;
Expand All @@ -30,6 +35,17 @@
MinWidth = 75
};
Container.AddChild(ChannelSelector);
// frontier block - begin
LanguageSelector = new LanguageSelectorButton
{
Name = "LanguageSelector",
ToggleMode = true,
StyleClasses = { "chatSelectorOptionButton" },
MinWidth = 75
};
Container.AddChild(LanguageSelector);
LanguageSelector.OnLanguageSelect += SelectLanguage;
// frontier block - end
Input = new HistoryLineEdit
{
Name = "Input",
Expand All @@ -52,6 +68,13 @@
ActiveChannel = (ChatChannel) selectedChannel;
}

// Frontier
private void SelectLanguage(LanguagePrototype language)
{
// This sucks a lot
IoCManager.Resolve<IUserInterfaceManager>().GetUIController<LanguageMenuUIController>().SetLanguage(language.ID);
}

private static string GetChatboxInfoPlaceholder()
{
return (BoundKeyHelper.IsBound(ContentKeyFunctions.FocusChat), BoundKeyHelper.IsBound(ContentKeyFunctions.CycleChatChannelForward)) switch
Expand Down
18 changes: 18 additions & 0 deletions Content.Client/_NF/Language/LanguageMenuWindow.xaml
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"
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/_NF/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._NF.Language; // This EXACT class must have the _NF part because of xaml linking

[GenerateTypedNameReferences]
public sealed partial class LanguageMenuWindow : DefaultWindow
{
private readonly LanguageSystem _language;
private readonly List<EntryState> _entries = new();

public Action<string>? OnLanguageSelected;

public LanguageMenuWindow()
{
RobustXamlLoader.Load(this);
_language = IoCManager.Resolve<IEntitySystemManager>().GetEntitySystem<LanguageSystem>();

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

public void UpdateState(LanguageMenuStateMessage state)
{
var clanguage = _language.GetLanguage(state.CurrentLanguage);
CurrentLanguageLabel.Text = Loc.GetString("language-menu-current-language", ("language", clanguage?.LocalizedName ?? "<error>"));

OptionsList.RemoveAllChildren();
_entries.Clear();

foreach (var language in state.Options)
{
AddLanguageEntry(language);
}

// Disable the button for the currently chosen language
foreach (var entry in _entries)
{
if (entry.button != null)
entry.button.Disabled = entry.language == state.CurrentLanguage;
}
}

private void AddLanguageEntry(string language)
{
var proto = _language.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?.LocalizedName ?? "<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?.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;

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)
{
OnLanguageSelected?.Invoke(id);
}

private struct EntryState
{
public string language;
public Button? button;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
using System.Linq;
using System.Numerics;
using Content.Client.UserInterface.Systems.Chat.Controls;
using Content.Shared.Language;
using Robust.Shared.Utility;

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

// Mostly copied from ChannelSelectorButton
public sealed class LanguageSelectorButton : ChatPopupButton<LanguageSelectorPopup>
{
public event Action<LanguagePrototype>? OnLanguageSelect;

public LanguagePrototype? SelectedLanguage { get; private set; }

private const int SelectorDropdownOffset = 38;

public LanguageSelectorButton()
{
Name = "LanguageSelector";

Popup.Selected += OnLanguageSelected;

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

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

private void OnLanguageSelected(LanguagePrototype channel)
{
Select(channel);
}

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

if (SelectedLanguage == language)
return;
SelectedLanguage = language;
OnLanguageSelect?.Invoke(language);

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

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

// Alternatively, take the first 5 letters
return name[..5];
}

// public Color ChannelSelectColor(ChatSelectChannel channel)
// {
// return channel switch
// {
// ChatSelectChannel.Radio => Color.LimeGreen,
// ChatSelectChannel.LOOC => Color.MediumTurquoise,
// ChatSelectChannel.OOC => Color.LightSkyBlue,
// ChatSelectChannel.Dead => Color.MediumPurple,
// ChatSelectChannel.Admin => Color.HotPink,
// _ => Color.DarkGray
// };
// }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
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._NF.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);

// var prefix = ChatUIController.ChannelPrefixes[selector];
// if (prefix != default)
// Text = Loc.GetString("hud-chatbox-select-name-prefixed", ("name", Text), ("prefix", prefix));
}
}
Loading
Loading