Skip to content
Open
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
2 changes: 2 additions & 0 deletions Content.Client/Input/ContentContexts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ public static void SetupContexts(IInputContextContainer contexts)
human.AddFunction(ContentKeyFunctions.AltUseItemInHand);
human.AddFunction(ContentKeyFunctions.OpenCharacterMenu);
human.AddFunction(ContentKeyFunctions.OpenEmotesMenu);
human.AddFunction(ContentKeyFunctions.OpenLanguageMenu); // DEN: Languages
human.AddFunction(ContentKeyFunctions.OpenQuickLanguageMenu); // DEN: Languages
human.AddFunction(ContentKeyFunctions.ActivateItemInWorld);
human.AddFunction(ContentKeyFunctions.ThrowItemInHand);
human.AddFunction(ContentKeyFunctions.AltActivateItemInWorld);
Expand Down
2 changes: 2 additions & 0 deletions Content.Client/Options/UI/OptionsMenu.xaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<DefaultWindow xmlns="https://spacestation14.io"
xmlns:tabs="clr-namespace:Content.Client.Options.UI.Tabs"
xmlns:den="clr-namespace:Content.Client._DEN.Options.UI.Tabs"
Title="{Loc 'ui-options-title'}"
MinSize="800 450">
<TabContainer Name="Tabs" Access="Public">
Expand All @@ -9,5 +10,6 @@
<tabs:AudioTab Name="AudioTab" />
<tabs:AccessibilityTab Name="AccessibilityTab" />
<tabs:AdminOptionsTab Name="AdminOptionsTab" />
<den:DenTab Name="Den" /><!-- DEN Options Tab -->
</TabContainer>
</DefaultWindow>
2 changes: 2 additions & 0 deletions Content.Client/Options/UI/Tabs/KeyRebindTab.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,8 @@ void AddToggleCvarCheckBox(string checkBoxName, CVarDef<bool> cvar)
AddButton(ContentKeyFunctions.OpenAHelp);
AddButton(ContentKeyFunctions.OpenActionsMenu);
AddButton(ContentKeyFunctions.OpenEmotesMenu);
AddButton(ContentKeyFunctions.OpenLanguageMenu); // DEN: Languages
AddButton(ContentKeyFunctions.OpenQuickLanguageMenu); // DEN: Languages
AddButton(ContentKeyFunctions.ToggleRoundEndSummaryWindow);
AddButton(ContentKeyFunctions.OpenEntitySpawnWindow);
AddButton(ContentKeyFunctions.OpenSandboxWindow);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Content.Client._DEN.UserInterface.Systems.Language;
using Content.Client.UserInterface.Systems.Actions;
using Content.Client.UserInterface.Systems.Admin;
using Content.Client.UserInterface.Systems.Bwoink;
Expand All @@ -24,6 +25,7 @@ public sealed class GameTopMenuBarUIController : UIController
[Dependency] private readonly SandboxUIController _sandbox = default!;
[Dependency] private readonly GuidebookUIController _guidebook = default!;
[Dependency] private readonly EmotesUIController _emotes = default!;
[Dependency] private readonly LanguageUIController _language = default!; // DEN: Languages

private GameTopMenuBar? GameTopMenuBar => UIManager.GetActiveUIWidgetOrNull<GameTopMenuBar>();

Expand All @@ -47,6 +49,7 @@ public void UnloadButtons()
_action.UnloadButton();
_sandbox.UnloadButton();
_emotes.UnloadButton();
_language.UnloadButton(); // DEN: Languages
}

public void LoadButtons()
Expand All @@ -60,5 +63,6 @@ public void LoadButtons()
_action.LoadButton();
_sandbox.LoadButton();
_emotes.LoadButton();
_language.LoadButton(); // DEN: Languages
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,17 @@
HorizontalExpand="True"
AppendStyleClass="{x:Static style:StyleClass.ButtonSquare}"
/>
<!-- DEN LANGUAGES -->
<ui:MenuButton
Name="LanguageButton"
Access="Internal"
Icon="{xe:Tex '/Textures/_DEN/Interface/language-solid-full.svg.192dpi.png'}"
BoundKey = "{x:Static is:ContentKeyFunctions.OpenLanguageMenu}"
ToolTip="{Loc 'game-hud-open-language-menu-button-tooltip'}"
MinSize="42 64"
HorizontalExpand="True"
AppendStyleClass="{x:Static style:StyleClass.ButtonSquare}"
/>
<ui:MenuButton
Name="AdminButton"
Access="Internal"
Expand Down
104 changes: 104 additions & 0 deletions Content.Client/_DEN/Language/EntitySystems/LanguageSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
using Content.Shared._DEN.CCVars;
using Content.Shared._DEN.Language;
using Content.Shared._DEN.Language.Components;
using Content.Shared._DEN.Language.EntitySystems;
using Content.Shared.GameTicking;
using Robust.Client.Player;

namespace Content.Client._DEN.Language.EntitySystems;

public sealed class LanguageSystem : SharedLanguageSystem
{
[Dependency] private readonly IPlayerManager _playerManager = default!;

public event Action<Entity<LanguageComponent>>? OnLanguageEntityUpdate;
public event Action<Entity<LanguageComponent>?>? OnLanguageCommunicatorUpdate;
public event Action<bool>? OnLanguagesEnabledUpdate;

public override void Initialize()
{
base.Initialize();

_cfg.OnValueChanged(DenCCVars.HideLanguageFonts, SetHideLanguageFonts);
_cfg.OnValueChanged(DenCCVars.LanguageEnabled, SetLanguageEnabledState);

SubscribeLocalEvent<LanguageComponent, AfterAutoHandleStateEvent>(OnLanguageComponentHandleState);
SubscribeLocalEvent<LanguageCommunicatorComponent, AfterAutoHandleStateEvent>(OnLanguageCommunicatorHandleState);

SubscribeLocalEvent<PlayerSpawnCompleteEvent>(OnPlayerSpawnComplete);
}

private void SetLanguageEnabledState(bool enabled)
{
OnLanguagesEnabledUpdate?.Invoke(enabled);
}

private void OnPlayerSpawnComplete(PlayerSpawnCompleteEvent evt)
{
RaiseNetworkEvent(new HideFontsMessage(_cfg.GetCVar(DenCCVars.HideLanguageFonts)));
}

private void SetHideLanguageFonts(HideLanguageFontSetting hide)
{
RaiseNetworkEvent(new HideFontsMessage(hide));
}

public void TrySetSpokenLanguage(Entity<LanguageComponent> lang)
{
if (_playerManager.LocalEntity is not { } localEnt ||
!TryComp<LanguageCommunicatorComponent>(localEnt, out var localComm))
return;

var request = new RequestSetSpokenLanguageEvent(GetNetEntity(lang));
RaiseNetworkEvent(request);

OnLanguageCommunicatorUpdate?.Invoke(lang);
}

private void OnLanguageComponentHandleState(Entity<LanguageComponent> ent, ref AfterAutoHandleStateEvent evt)
{
LanguageUpdated(ent);
}

private void OnLanguageCommunicatorHandleState(Entity<LanguageCommunicatorComponent> ent,
ref AfterAutoHandleStateEvent evt)
{
if (_playerManager.LocalEntity == ent)
{
var currLang = GetCurrentLanguageEntity(ent);
OnLanguageCommunicatorUpdate?.Invoke(currLang);
}
}

protected override void OnLanguageRemoved(Entity<LanguageCommunicatorComponent> holder, Entity<LanguageComponent> language)
{
if (_playerManager.LocalEntity == holder)
{
OnLanguageEntityUpdate?.Invoke(language);
}
}

public Entity<LanguageCommunicatorComponent>? GetLocalCommunicator()
{
if (_playerManager.LocalEntity is { } localEnt && TryComp<LanguageCommunicatorComponent>(localEnt, out var localCommunicator))
return (localEnt, localCommunicator);

return null;
}

public override void OnLanguageUpdated(Entity<LanguageComponent?> lang)
{
if (!Resolve(lang, ref lang.Comp))
return;

LanguageUpdated((lang, lang.Comp));
}

private void LanguageUpdated(Entity<LanguageComponent> ent)
{
if (_playerManager.LocalEntity is { } localEnt && localEnt == ent.Comp.Holder)
{
OnLanguageEntityUpdate?.Invoke(ent);
}
}
}
15 changes: 15 additions & 0 deletions Content.Client/_DEN/Options/UI/Tabs/DenTab.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<tabs:DenTab xmlns="https://spacestation14.io"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:ui="clr-namespace:Content.Client.Options.UI"
xmlns:tabs="clr-namespace:Content.Client._DEN.Options.UI.Tabs">
<BoxContainer Orientation="Vertical">
<ScrollContainer VerticalExpand="True" HorizontalExpand="True">
<BoxContainer Orientation="Vertical" Margin="8 8 8 8" VerticalExpand="True">
<Label Text="{Loc 'ui-options-language-related'}"
StyleClasses="LabelKeyText"/>
<ui:OptionDropDown Name="HideLanguageFonts" Title="{Loc 'ui-options-language-hide-fonts'}"/>
</BoxContainer>
</ScrollContainer>
<ui:OptionsTabControlRow Name="Control" Access="Public" />
</BoxContainer>
</tabs:DenTab>
36 changes: 36 additions & 0 deletions Content.Client/_DEN/Options/UI/Tabs/DenTab.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using Content.Client._DEN.Language.EntitySystems;
using Content.Client.Options.UI;
using Content.Shared._DEN.CCVars;
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.XAML;
using Robust.Shared.Configuration;

namespace Content.Client._DEN.Options.UI.Tabs;

[GenerateTypedNameReferences]
public sealed partial class DenTab : Control
{
public DenTab()
{
RobustXamlLoader.Load(this);

Control.AddOptionDropDown(DenCCVars.HideLanguageFonts,
HideLanguageFonts,
[
new OptionDropDownCVar<HideLanguageFontSetting>.ValueOption(HideLanguageFontSetting.None,
Loc.GetString("ui-options-language-hide-fonts-none")),
new OptionDropDownCVar<HideLanguageFontSetting>.ValueOption(HideLanguageFontSetting.All,
Loc.GetString("ui-options-language-hide-fonts-all")),
new OptionDropDownCVar<HideLanguageFontSetting>.ValueOption(HideLanguageFontSetting.Understood,
Loc.GetString("ui-options-language-hide-fonts-understood")),
]);

IoCManager.Resolve<IConfigurationManager>().OnValueChanged(DenCCVars.LanguageEnabled, OnLanguageEnableChanged);
}

private void OnLanguageEnableChanged(bool enabled)
{
HideLanguageFonts.Visible = enabled;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
using Content.Client._DEN.Language.EntitySystems;
using Content.Shared._DEN.Language.Components;
using Content.Shared.Examine;
using Robust.Client.Player;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Shared.Prototypes;
using Robust.Shared.Utility;

namespace Content.Client._DEN.UserInterface.Systems.Language.Controls;

public sealed class LanguageContainer : Control
{
private IEntityManager _entities;
private IPlayerManager _player;
private IPrototypeManager _proto;
private LanguageSystem _language;

public event Action? SpeakPressed;

public Entity<LanguageComponent>? LanguageEnt { get; private set; }

private Label _languageName;
private Button _languageButton;
private RichTextLabel _description;
private BoxContainer _header;

public LanguageContainer(IEntityManager entities, IPlayerManager player, IPrototypeManager proto, LanguageSystem language)
{
_entities = entities;
_player = player;
_proto = proto;
_language = language;

var container = new BoxContainer
{
Orientation = BoxContainer.LayoutOrientation.Vertical,
HorizontalExpand = true,
};

_header = new BoxContainer
{
Orientation = BoxContainer.LayoutOrientation.Horizontal,
HorizontalExpand = true,
};

_languageName = new Label
{
Name = "LanguageName",
HorizontalExpand = true,
};

_languageButton = new Button { Text = Loc.GetString("language-ui-speak-language") };
_languageButton.OnPressed += _ => SpeakPressed?.Invoke();

_header.AddChild(_languageName);
_header.AddChild(_languageButton);

container.AddChild(_header);

var cbody = new CollapsibleBody
{
HorizontalExpand = false,
Margin = new Thickness(4f, 4f),
};

var body = new BoxContainer
{
Orientation = BoxContainer.LayoutOrientation.Vertical,
HorizontalExpand = true,
};

_description = new RichTextLabel { HorizontalExpand = true };
body.AddChild(_description);
cbody.AddChild(body);

var collapsible = new Collapsible(Loc.GetString("language-ui-language-description"), cbody)
{
Orientation = BoxContainer.LayoutOrientation.Vertical,
HorizontalExpand = true,
};
container.AddChild(collapsible);

var wrapper = new PanelContainer
{
Margin = new Thickness(4f),
};
wrapper.StyleClasses.Add("PdaBorderRect");
wrapper.AddChild(container);

AddChild(wrapper);

SpeakPressed += OnLanguageChosen;
}

public void UpdateLanguage(Entity<LanguageComponent> language)
{
LanguageEnt = language;
UpdateData();
}

public void SetCurrentSpoken(bool current)
{
if (current)
{
if (_header.Children.Contains(_languageButton))
_header.RemoveChild(_languageButton);
}
else
{
if (!_header.Children.Contains(_languageButton))
_header.AddChild(_languageButton);
}
}

private void UpdateData()
{
if (LanguageEnt == null || _player.LocalEntity == null)
return;

var langProto = _proto.Index(LanguageEnt.Value.Comp.Language);
var fluencyProto = _proto.Index(LanguageEnt.Value.Comp.Fluency);

_languageName.Text = langProto.LocalizedName;

_languageButton.Disabled = !LanguageEnt.Value.Comp.Speaks;

var desc = FormattedMessage.FromMarkupPermissive(
Loc.GetString("language-ui-language-fluency",
("fluency", Loc.GetString(fluencyProto.Name)),
("color", Color.InterpolateBetween(Color.Red, Color.Green, (float)(fluencyProto.Understanding / 100.0)))));
desc.PushNewline();
desc.AddMarkupPermissive(langProto.LocalizedDescription);

var ev = new ExaminedEvent(desc, LanguageEnt.Value, _player.LocalEntity.Value, true, !desc.IsEmpty);
_entities.EventBus.RaiseLocalEvent(LanguageEnt.Value, ev);

_description.SetMessage(ev.GetTotalMessage());
}

private void OnLanguageChosen()
{
if (LanguageEnt != null)
_language.TrySetSpokenLanguage(LanguageEnt.Value);
}
}
Loading
Loading