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

Реворк языков (опять 25) #976

Merged
merged 14 commits into from
Jan 23, 2025
Merged
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
7 changes: 7 additions & 0 deletions Content.Client/ADT/Language/TranslatorSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
using Content.Shared.ADT.Language;

namespace Content.Client.ADT.Language;

public sealed class TranslatorSystem : SharedTranslatorSystem
{
}
91 changes: 91 additions & 0 deletions Content.Client/ADT/Language/UI/HumanoidProfileEditor.Languages.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
using System.Linq;
using Content.Client.ADT.Language.UI;
using Content.Shared.ADT.Language;
using Content.Shared.Humanoid.Prototypes;
using Robust.Client.UserInterface.Controls;

namespace Content.Client.Lobby.UI;

public sealed partial class HumanoidProfileEditor
{
public void RefreshLanguages()
{
LanguagesList.DisposeAllChildren();
TabContainer.SetTabTitle(1, Loc.GetString("humanoid-profile-editor-languages-tab"));
SetDefaultLanguagesButton.OnPressed += SetDefaultLanguages;

if (Profile == null)
return;
var species = _prototypeManager.Index(Profile.Species);

LanguagesCountLabel.Text = Loc.GetString("humanoid-profile-editor-languages-count",
("current", Profile.Languages.Count),
("max", species.MaxLanguages));

var list = _prototypeManager.EnumeratePrototypes<LanguagePrototype>().Where(x => x.Roundstart).ToList();
foreach (var item in species.UniqueLanguages)
{
list.Add(_prototypeManager.Index(item));
}

list.Sort((x, y) => x.LocalizedName[0].CompareTo(y.LocalizedName[0]));
list.Sort((x, y) => y.Priority.CompareTo(x.Priority));

List<LanguagePrototype> defaultList = new();
defaultList.AddRange(list.Where(x => species.DefaultLanguages.Contains(x) && !species.UniqueLanguages.Contains(x)));
defaultList.AddRange(list.Where(x => species.UniqueLanguages.Contains(x)));
defaultList.Sort((x, y) => x.LocalizedName[0].CompareTo(y.LocalizedName[0]));
defaultList.Sort((x, y) => y.Priority.CompareTo(x.Priority));

foreach (var item in defaultList)
{
AddLanguageEntry(item, species);
}

foreach (var item in list)
{
if (defaultList.Contains(item))
continue;
AddLanguageEntry(item, species);
}
}

private void AddLanguageEntry(LanguagePrototype proto, SpeciesPrototype species)
{
if (Profile == null)
return;
var entry = new LanguageEntry(proto, false);
entry.SelectButton.Text = Loc.GetString(!Profile.Languages.Contains(proto) ? "language-lobby-add-button" : "language-lobby-remove-button");
entry.SelectButton.ToolTip = null;
entry.SelectButton.Disabled = Profile.Languages.Count >= species.MaxLanguages && !Profile.Languages.Contains(proto);
entry.OnLanguageSelected += SelectLanguage;
entry.Margin = new(7);
entry.MaxWidth = 750f;
LanguagesList.AddChild(entry);
}

public void SelectLanguage(string protoId)
{
Profile = (Profile?.Languages.Contains(protoId) ?? false) ? Profile?.WithoutLanguage(protoId) : Profile?.WithLanguage(protoId);
SetDirty();
RefreshLanguages();
}

private void SetDefaultLanguages(BaseButton.ButtonEventArgs args)
{
if (Profile == null)
return;
var species = _prototypeManager.Index(Profile.Species);
foreach (var item in Profile.Languages)
{
Profile = Profile?.WithoutLanguage(item);
}
foreach (var item in species.DefaultLanguages)
{
Profile = Profile?.WithLanguage(item);
}

SetDirty();
RefreshLanguages();
}
}
29 changes: 29 additions & 0 deletions Content.Client/ADT/Language/UI/LanguageEntry.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<Control
xmlns="https://spacestation14.io">
<PanelContainer Name="Wrapper"
StyleClasses="PdaBorderRect">
<BoxContainer Orientation="Vertical">
<BoxContainer
Orientation="Horizontal"
HorizontalExpand="True"
SeparationOverride="2">
<Label Name="Name"
MinWidth="50"
HorizontalExpand="True"/>
<Button Name="SelectButton"
Text = "{Loc 'language-choose-button'}"
Access="Public"/>
</BoxContainer>
<Collapsible
Orientation="Vertical"
HorizontalExpand="True">
<CollapsibleHeading Title="{Loc 'language-menu-description-header'}" />
<CollapsibleBody
HorizontalExpand="True"
Margin="4">
<RichTextLabel Name="Description" />
</CollapsibleBody>
</Collapsible>
</BoxContainer>
</PanelContainer>
</Control>
29 changes: 29 additions & 0 deletions Content.Client/ADT/Language/UI/LanguageEntry.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using Content.Shared.ADT.Language;
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.XAML;

namespace Content.Client.ADT.Language.UI;

[GenerateTypedNameReferences]
public sealed partial class LanguageEntry : Control
{
public Action<string>? OnLanguageSelected;
public string Language;

public LanguageEntry(LanguagePrototype proto, bool translator)
{
RobustXamlLoader.Load(this);
Name.Text = proto.LocalizedName;
if (proto.Color.HasValue)
Name.FontColorOverride = proto.Color.Value;
SelectButton.ToolTip = translator ?
Loc.GetString("language-choose-button-tooltip-translator") :
Loc.GetString("language-choose-button-tooltip-known");
Description.SetMessage(proto.LocalizedDescription);
Language = proto.ID;

SelectButton.OnPressed += _ => OnLanguageSelected?.Invoke(proto.ID);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,19 @@
using Content.Shared.Input;
using Content.Client.ADT.Language.UI;
using Robust.Shared.Input.Binding;
using Robust.Client.Player;
using Content.Client.ADT.Language;
using System.Linq;

namespace Content.Client.UserInterface.Systems.Language; // ADT Languages
namespace Content.Client.ADT.UserInterface.Systems.Language;

public sealed class LanguageMenuUIController : UIController, IOnStateEntered<GameplayState>, IOnStateExited<GameplayState>
{
public LanguageMenuWindow? _menu;
private MenuButton? LanguagesButton => UIManager.GetActiveUIWidgetOrNull<MenuBar.Widgets.GameTopMenuBar>()?.LanguagesButton;
private MenuButton? LanguagesButton => UIManager.GetActiveUIWidgetOrNull<Content.Client.UserInterface.Systems.MenuBar.Widgets.GameTopMenuBar>()?.LanguagesButton;

[Dependency] private readonly IPlayerManager _player = default!;
[Dependency] private readonly IEntityManager _entMan = default!;
public override void Initialize()
{

Expand All @@ -25,7 +30,7 @@ private void OnStateUpdate(LanguageMenuStateMessage ev)
if (_menu == null)
return;

_menu.UpdateState(ev);
_menu.UpdateState(ev.CurrentLanguage, ev.Options, ev.TranslatorOptions);
}


Expand All @@ -44,12 +49,23 @@ public void OnStateExited(GameplayState state)

private void ToggleLanguagesMenu()
{
var player = _player.LocalEntity;
if (!player.HasValue)
return;

if (_menu == null)
{
var lang = _entMan.System<LanguageSystem>();
if (!lang.GetLanguages(player, out _, out var translator, out var current) || !lang.GetLanguagesKnowledged(player, LanguageKnowledge.Understand, out var langs, out _))
return;

// setup window
_menu = UIManager.CreateWindow<LanguageMenuWindow>();
_menu.Owner = player.Value;
_menu.UpdateState(current, langs, translator);
_menu.OnClose += OnWindowClosed;
_menu.OnOpen += OnWindowOpen;
_menu.OnLanguageSelected += OnLanguageSelected;

if (LanguagesButton != null)
LanguagesButton.SetClickPressed(true);
Expand All @@ -60,7 +76,7 @@ private void ToggleLanguagesMenu()
{
_menu.OnClose -= OnWindowClosed;
_menu.OnOpen -= OnWindowOpen;
//_menu.OnPlayEmote -= OnPlayEmote;
_menu.OnLanguageSelected -= OnLanguageSelected;

if (LanguagesButton != null)
LanguagesButton.SetClickPressed(false);
Expand All @@ -69,6 +85,16 @@ private void ToggleLanguagesMenu()
}
}

private void OnLanguageSelected(string lang)
{
var player = _player.LocalEntity;
if (!player.HasValue)
return;

var ev = new LanguageChosenMessage(_entMan.GetNetEntity(player.Value), lang);
_entMan.RaisePredictiveEvent(ev);
}

public void UnloadButton()
{
if (LanguagesButton == null)
Expand Down
Loading
Loading