Skip to content

Commit

Permalink
Переводчики заработали как надо
Browse files Browse the repository at this point in the history
  • Loading branch information
FaDeOkno committed Aug 6, 2024
1 parent a5e8cd8 commit 6e9e4aa
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 32 deletions.
39 changes: 17 additions & 22 deletions Content.Client/ADT/Language/UI/LanguageMenuWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,19 @@ public void UpdateState(LanguageMenuStateMessage state)
{
CurrentLanguageLabel.Text = Loc.GetString("language-menu-current-language", ("language", _language.GetLanguage(state.CurrentLanguage).LocalizedName));

//OptionsList.RemoveAllChildren();
List<string> options = new();
List<Option> optionList = _optionLists;

options.AddRange(state.Options);
options.AddRange(state.TranslatorOptions);

List<string> translatorOptions = new();
translatorOptions.AddRange(state.TranslatorOptions);
List<string> translatorOptions = state.TranslatorOptions;
List<EntryState> entries = _entries.ToList();

foreach (var lng in state.Options)
{
translatorOptions.Remove(lng);
}
foreach (var entry in _entries)
foreach (var entry in entries)
{
if (state.Options.Contains(entry.Language))
{
Expand All @@ -63,7 +62,7 @@ public void UpdateState(LanguageMenuStateMessage state)
}
else if (state.TranslatorOptions.Contains(entry.Language))
{
options.Remove(entry.Language);
translatorOptions.Remove(entry.Language);
continue;
}
else
Expand All @@ -85,7 +84,14 @@ public void UpdateState(LanguageMenuStateMessage state)
{
foreach (var language in options)
{
AddLanguageEntry(language, translatorOptions.Contains(language));
AddLanguageEntry(language);
}
}
if (translatorOptions.Count > 0)
{
foreach (var language in translatorOptions)
{
AddLanguageEntry(language, true);
}
}

Expand All @@ -99,14 +105,6 @@ public void UpdateState(LanguageMenuStateMessage state)
entry.Button.Text = Loc.GetString("language-choose-button-chosen");
if (!_language.CanSpeak(_entManager.GetEntity(state.ComponentOwner), _language.GetLanguage(entry.Language)))
entry.Button.Text = Loc.GetString("language-choose-button-cannot");

if (translatorOptions.Contains(entry.Language))
{
entry.Button.Text = "П | " + entry.Button.Text;
entry.Button.ToolTip = Loc.GetString("language-choose-button-tooltip-translator");
}
else
entry.Button.ToolTip = Loc.GetString("language-choose-button-tooltip-known");
}
}
}
Expand Down Expand Up @@ -137,13 +135,10 @@ private void AddLanguageEntry(string language, bool translator = false)
var button = new Button();
button.Text = Loc.GetString("language-choose-button");
button.OnPressed += _ => OnLanguageChosen(language);
if (translator)
{
//button.Text = "П | " + button.Text;
button.ToolTip = Loc.GetString("language-choose-button-tooltip-translator");
}
else
button.ToolTip = Loc.GetString("language-choose-button-tooltip-known");
button.ToolTip =
translator ?
Loc.GetString("language-choose-button-tooltip-translator") :
Loc.GetString("language-choose-button-tooltip-known");

state.Button = button;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ private void ToggleLanguagesMenu()
_menu = UIManager.CreateWindow<LanguageMenuWindow>();
_menu.OnClose += OnWindowClosed;
_menu.OnOpen += OnWindowOpen;
//_menu.OnPlayEmote += OnPlayEmote;

if (LanguagesButton != null)
LanguagesButton.SetClickPressed(true);
Expand Down
21 changes: 17 additions & 4 deletions Content.Server/ADT/Language/TranslatorSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ public override void Initialize()
SubscribeLocalEvent<HandheldTranslatorComponent, ActivateInWorldEvent>(OnTranslatorActivateInWorld);
SubscribeLocalEvent<HandheldTranslatorComponent, UseInHandEvent>(OnTranslatorUseInHand);

SubscribeLocalEvent<HandheldTranslatorComponent, EquippedHandEvent>(OnPickUp);
SubscribeLocalEvent<HandheldTranslatorComponent, DroppedEvent>(OnDrop);
SubscribeLocalEvent<HandheldTranslatorComponent, GotEquippedHandEvent>(OnPickUp);
SubscribeLocalEvent<HandheldTranslatorComponent, GotUnequippedHandEvent>(OnDrop);

SubscribeLocalEvent<HandheldTranslatorComponent, PowerCellSlotEmptyEvent>(OnPowerCellSlotEmpty);
}
Expand All @@ -49,28 +49,37 @@ private void OnTranslatorUseInHand(EntityUid translator, HandheldTranslatorCompo
Dirty(translator, component);

ToggleTranslator(translator);
component.User = component.Enabled ? args.User : null;

if (_language.GetLanguages(args.User, out var understood, out _, out var translatorUnderstood, out _, out var current))
{
var ev = new LanguageMenuStateMessage(GetNetEntity(args.User), current, understood, translatorUnderstood);
RaiseNetworkEvent(ev, args.User);
}
}

private void OnPickUp(EntityUid translator, HandheldTranslatorComponent component, EquippedHandEvent args)
private void OnPickUp(EntityUid translator, HandheldTranslatorComponent component, GotEquippedHandEvent args)
{
Dirty(translator, component);

component.User = args.User;

if (_language.GetLanguages(args.User, out var understood, out _, out var translatorUnderstood, out _, out var current))
{
var ev = new LanguageMenuStateMessage(GetNetEntity(args.User), current, understood, translatorUnderstood);
RaiseNetworkEvent(ev, args.User);
}
}

private void OnDrop(EntityUid translator, HandheldTranslatorComponent component, DroppedEvent args)
private void OnDrop(EntityUid translator, HandheldTranslatorComponent component, GotUnequippedHandEvent args)
{
Dirty(translator, component);

if (component.User.HasValue)
_language.SelectDefaultLanguage(component.User.Value);

component.User = null;

if (_language.GetLanguages(args.User, out var understood, out _, out var translatorUnderstood, out _, out var current))
{
var ev = new LanguageMenuStateMessage(GetNetEntity(args.User), current, understood, translatorUnderstood);
Expand All @@ -90,6 +99,8 @@ private void ToggleTranslator(EntityUid uid, HandheldTranslatorComponent? compon
component.Enabled = !component.Enabled;
var popupMessage = Loc.GetString(component.Enabled ? "translator-component-turnon" : "translator-component-shutoff", ("translator", component.Owner));
_popup.PopupEntity(popupMessage, component.Owner);
if (!component.Enabled && component.User.HasValue)
_language.SelectDefaultLanguage(component.User.Value);
}

Dirty(uid, component);
Expand All @@ -99,6 +110,8 @@ private void OnPowerCellSlotEmpty(EntityUid translator, HandheldTranslatorCompon
{
component.Enabled = false;

component.User = null;

Dirty(translator, component);
OnAppearanceChange(translator, component);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ public sealed partial class HandheldTranslatorComponent : Component
[DataField]
public bool Enabled = false;

public EntityUid? User;
}
18 changes: 17 additions & 1 deletion Content.Shared/ADT/Language/Systems/SharedLanguageSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,22 @@ public void SelectLanguage(NetEntity ent, string language, LanguageSpeakerCompon
RaiseNetworkEvent(new LanguageChosenMessage(ent, language));
}

public void SelectDefaultLanguage(EntityUid uid, LanguageSpeakerComponent? component = null)
{
if (!Resolve(uid, ref component))
return;

var language = component.SpokenLanguages.FirstOrDefault("Universal");

GetLanguages(uid, out _, out _, out var translator, out _, out _);
component.CurrentLanguage = language;

Dirty(uid, component);

RaiseNetworkEvent(new LanguageMenuStateMessage(GetNetEntity(uid), language, component.UnderstoodLanguages, translator));
RaiseNetworkEvent(new LanguageChosenMessage(GetNetEntity(uid), language));
}

public bool GetLanguages(
EntityUid? player,
out List<string> understood,
Expand Down Expand Up @@ -178,7 +194,7 @@ public bool GetLanguages(

foreach (var item in _hands.EnumerateHeld(uid))
{
if (TryComp<HandheldTranslatorComponent>(item, out var translator))
if (TryComp<HandheldTranslatorComponent>(item, out var translator) && translator.Enabled)
{
foreach (var lang in translator.Required)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ language-menu-description-header = Описание
language-choose-button = Выбрать
language-choose-button-chosen = Выбрано
language-choose-button-cannot = Только понимание
language-menu-action = Меню языков
language-menu-action-desc = Открыть меню выбора языка.
language-choose-button-tooltip-translator = Вы используете переводчик для пользования данным языком.
language-choose-button-tooltip-known = Вы полностью владеете данным языком.
game-hud-open-languages-menu-button-tooltip = Открыть меню выбора языка
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
translator-component-shutoff = {$translator} выключается.
translator-component-turnon = The {$translator} включается.
translator-component-shutoff = {CAPITALIZE($translator)} выключается.
translator-component-turnon = {CAPITALIZE($translator)} включается.
translator-enabled = Оно включено.
translator-disabled = Оно выключено.
Expand Down

0 comments on commit 6e9e4aa

Please sign in to comment.