Skip to content

Commit

Permalink
QOL - Language Menu
Browse files Browse the repository at this point in the history
Remove the Action event to toggle the Language menu to the TopBar, more pretty and does not add up "useless" actions.
  • Loading branch information
FoxxoTrystan committed Mar 14, 2024
1 parent 800b7fa commit 6287ead
Show file tree
Hide file tree
Showing 12 changed files with 105 additions and 69 deletions.
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); // Frontier - Langauges
human.AddFunction(ContentKeyFunctions.ActivateItemInWorld);
human.AddFunction(ContentKeyFunctions.ThrowItemInHand);
human.AddFunction(ContentKeyFunctions.AltActivateItemInWorld);
Expand Down
1 change: 1 addition & 0 deletions Content.Client/Options/UI/Tabs/KeyRebindTab.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ void AddCheckBox(string checkBoxName, bool currentState, Action<BaseButton.Butto
AddButton(ContentKeyFunctions.CycleChatChannelForward);
AddButton(ContentKeyFunctions.CycleChatChannelBackward);
AddButton(ContentKeyFunctions.OpenCharacterMenu);
AddButton(ContentKeyFunctions.OpenLanguageMenu); // Frontier - Languages
AddButton(ContentKeyFunctions.OpenCraftingMenu);
AddButton(ContentKeyFunctions.OpenGuidebook);
AddButton(ContentKeyFunctions.OpenInventoryMenu);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Content.Client.UserInterface.Systems.MenuBar.Widgets;
using Content.Client.UserInterface.Systems.Sandbox;
using Robust.Client.UserInterface.Controllers;
using Content.Client.UserInterface.Systems.Language; // Frontier

namespace Content.Client.UserInterface.Systems.MenuBar;

Expand All @@ -22,6 +23,7 @@ public sealed class GameTopMenuBarUIController : UIController
[Dependency] private readonly ActionUIController _action = default!;
[Dependency] private readonly SandboxUIController _sandbox = default!;
[Dependency] private readonly GuidebookUIController _guidebook = default!;
[Dependency] private readonly LanguageMenuUIController _language = default!; // Frontier

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

Expand All @@ -44,6 +46,7 @@ public void UnloadButtons()
_ahelp.UnloadButton();
_action.UnloadButton();
_sandbox.UnloadButton();
_language.UnloadButton(); // Frontier - Languages
}

public void LoadButtons()
Expand All @@ -56,5 +59,6 @@ public void LoadButtons()
_ahelp.LoadButton();
_action.LoadButton();
_sandbox.LoadButton();
_language.LoadButton(); // Frontier - Languages
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,18 @@
HorizontalExpand="True"
AppendStyleClass="{x:Static style:StyleBase.ButtonSquare}"
/>
<!-- Frontier Block End -->
<ui:MenuButton
Name="LanguageButton"
Access="Internal"
Icon="{xe:Tex '/Textures/_NF/Interface/Actions/language.png'}"
BoundKey = "{x:Static is:ContentKeyFunctions.OpenLanguageMenu}"
ToolTip="Open the Language Menu"
MinSize="42 64"
HorizontalExpand="True"
AppendStyleClass="{x:Static style:StyleBase.ButtonSquare}"
/>
<!-- Frontier Block End -->
<ui:MenuButton
Name="AdminButton"
Access="Internal"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,83 +1,133 @@
using Content.Client._NF.Language;
using Content.Client.Gameplay;
using Content.Client.UserInterface.Systems.Chat;
using Content.Shared.Language;
using Robust.Client.UserInterface.Controllers;
using Robust.Client.UserInterface.Controls;
using Robust.Shared.Console;
using Robust.Shared.Timing;
using static Content.Shared.Language.Systems.SharedLanguageSystem;
using Content.Client.UserInterface.Controls;
using Content.Shared.Input;
using JetBrains.Annotations;
using Robust.Shared.Input.Binding;
using Robust.Shared.Utility;
using static Robust.Client.UserInterface.Controls.BaseButton;

namespace Content.Client.UserInterface.Systems.Language;

[UsedImplicitly]
public sealed class LanguageMenuUIController : UIController, IOnStateEntered<GameplayState>, IOnStateExited<GameplayState>
{
public LanguageMenuWindow? _languageWindow;
private TimeSpan _lastToggle = TimeSpan.Zero;
private MenuButton? LanguageButton => UIManager.GetActiveUIWidgetOrNull<MenuBar.Widgets.GameTopMenuBar>()?.LanguageButton;

public string? LastPreferredLanguage;
public Action<List<string>>? LanguagesChanged;

[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly IConsoleHost _consoleHost = default!;

public override void Initialize()
{
IoCManager.InjectDependencies(this);
EntityManager.EventBus.SubscribeLocalEvent<LanguageSpeakerComponent, LanguageMenuActionEvent>(OnActionMenu);
EntityManager.EventBus.SubscribeEvent<LanguageMenuStateMessage>(EventSource.Network, this, OnStateUpdate);
}
public void OnStateEntered(GameplayState state)
{
DebugTools.Assert(_languageWindow == null);

private void OnStateUpdate(LanguageMenuStateMessage ev)
_languageWindow = UIManager.CreateWindow<LanguageMenuWindow>();
_languageWindow.OnLanguageSelected += SetLanguage;
LayoutContainer.SetAnchorPreset(_languageWindow, LayoutContainer.LayoutPreset.CenterTop);

CommandBinds.Builder.Bind(ContentKeyFunctions.OpenLanguageMenu, InputCmdHandler.FromDelegate(_ => ToggleWindow())).Register<LanguageMenuUIController>();
RequestUpdate();
}

public void OnStateExited(GameplayState state)
{
if (_languageWindow != null)
{
_languageWindow.Dispose();
_languageWindow = null;
}

CommandBinds.Unregister<LanguageMenuUIController>();
}

public void UnloadButton()
{
if (LanguageButton == null)
{
return;
}

LanguageButton.OnPressed -= LanguageButtonPressed;
}

public void LoadButton()
{
if (LanguageButton == null)
{
return;
}

LanguageButton.OnPressed += LanguageButtonPressed;

if (_languageWindow == null)
{
return;
}

_languageWindow.UpdateState(ev);
LanguagesChanged?.Invoke(ev.Options);
_languageWindow.OnClose += DeactivateButton;
_languageWindow.OnOpen += ActivateButton;
}

private void OnActionMenu(EntityUid uid, LanguageSpeakerComponent component, LanguageMenuActionEvent args)
private void DeactivateButton() => LanguageButton!.Pressed = false;
private void ActivateButton() => LanguageButton!.Pressed = true;

private void LanguageButtonPressed(ButtonEventArgs args)
{
ToggleWindow();
}

private void CloseWindow()
{
if (_languageWindow == null || args.Handled || (_timing.RealTime - _lastToggle) < TimeSpan.FromMilliseconds(200))
_languageWindow?.Close();
}

private void ToggleWindow()
{
if (_languageWindow == null)
return;
_lastToggle = _timing.RealTime; // For some reason, this event seems to be fired multiple times, causing flickering

if (LanguageButton != null)
{
LanguageButton.SetClickPressed(!_languageWindow.IsOpen);
}

if (_languageWindow.IsOpen)
{
_languageWindow.Close();
CloseWindow();
}
else
{
_languageWindow!.Open();
RequestUpdate();
_languageWindow.Open();
}

args.Handled = true;
}

private void OnStateUpdate(LanguageMenuStateMessage ev)
{
if (_languageWindow == null)
return;

_languageWindow.UpdateState(ev);
LanguagesChanged?.Invoke(ev.Options);
}
public void RequestUpdate()
{
EntityManager.EntityNetManager?.SendSystemNetworkMessage(new RequestLanguageMenuStateMessage());
}

public void SetLanguage(string id)
{
_consoleHost.ExecuteCommand("lsselectlang " + id);
LastPreferredLanguage = id;
}

public void OnStateEntered(GameplayState state)
{
_languageWindow = UIManager.CreateWindow<LanguageMenuWindow>();
_languageWindow.OnLanguageSelected += SetLanguage;
LayoutContainer.SetAnchorPreset(_languageWindow, LayoutContainer.LayoutPreset.Center);
RequestUpdate();
}

public void OnStateExited(GameplayState state)
{
_languageWindow?.Dispose();
_languageWindow = null;
}
}
1 change: 1 addition & 0 deletions Content.Shared/Input/ContentKeyFunctions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public static class ContentKeyFunctions
public static readonly BoundKeyFunction CycleChatChannelBackward = "CycleChatChannelBackward";
public static readonly BoundKeyFunction EscapeContext = "EscapeContext";
public static readonly BoundKeyFunction OpenCharacterMenu = "OpenCharacterMenu";
public static readonly BoundKeyFunction OpenLanguageMenu = "OpenLanguageMenu"; // Frontier - Languages
public static readonly BoundKeyFunction OpenCraftingMenu = "OpenCraftingMenu";
public static readonly BoundKeyFunction OpenGuidebook = "OpenGuidebook";
public static readonly BoundKeyFunction OpenInventoryMenu = "OpenInventoryMenu";
Expand Down
18 changes: 0 additions & 18 deletions Content.Shared/_NF/Language/Components/LanguageSpeakerComponent.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
using Content.Shared.Actions;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.List;

namespace Content.Shared.Language;
Expand Down Expand Up @@ -30,18 +26,4 @@ public sealed partial class LanguageSpeakerComponent : Component
[ViewVariables]
[DataField("understands", customTypeSerializer: typeof(PrototypeIdListSerializer<LanguagePrototype>), required: true)]
public List<string> UnderstoodLanguages = new();

[ViewVariables(VVAccess.ReadWrite)]
[DataField("languageMenuAction", customTypeSerializer: typeof(PrototypeIdSerializer<EntityPrototype>))]
public string LanguageMenuAction = "ActionLanguageMenu";

[DataField] public EntityUid? Action;
}

[Serializable, NetSerializable]
public enum LanguageMenuUiKey : byte
{
Key
}

public sealed partial class LanguageMenuActionEvent : InstantActionEvent { }
9 changes: 0 additions & 9 deletions Content.Shared/_NF/Language/Systems/SharedLanguageSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ public abstract class SharedLanguageSystem : EntitySystem
public static readonly string UniversalPrototype = "Universal";
public static LanguagePrototype GalacticCommon { get; private set; } = default!;
public static LanguagePrototype Universal { get; private set; } = default!;

[Dependency] private readonly SharedActionsSystem _action = default!;
[Dependency] protected readonly IPrototypeManager _prototype = default!;
[Dependency] protected readonly IRobustRandom _random = default!;
protected ISawmill _sawmill = default!;
Expand All @@ -24,8 +22,6 @@ public override void Initialize()
GalacticCommon = _prototype.Index<LanguagePrototype>("GalacticCommon");
Universal = _prototype.Index<LanguagePrototype>("Universal");
_sawmill = Logger.GetSawmill("language");

SubscribeLocalEvent<LanguageSpeakerComponent, MapInitEvent>(OnInit);
}

public LanguagePrototype? GetLanguage(string id)
Expand All @@ -34,11 +30,6 @@ public override void Initialize()
return proto;
}

private void OnInit(EntityUid uid, LanguageSpeakerComponent component, MapInitEvent args)
{
_action.AddAction(uid, ref component.Action, component.LanguageMenuAction, uid);
}

/// <summary>
/// Raised on an entity when its list of languages changes.
/// </summary>
Expand Down
1 change: 1 addition & 0 deletions Resources/Locale/en-US/_NF/language/language-menu.ftl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
language-menu-window-title = Language Menu
language-menu-current-language = Current Language: {$language}
language-menu-description-header = Description
ui-options-function-open-language-menu = Open language Menu
10 changes: 0 additions & 10 deletions Resources/Prototypes/_NF/Actions/language.yml

This file was deleted.

Binary file modified Resources/Textures/_NF/Interface/Actions/language.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions Resources/keybinds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,9 @@ binds:
- function: OpenCharacterMenu
type: State
key: C
- function: OpenLanguageMenu # Frontier / Languages
type: State
key: M
- function: TextCursorSelect
# TextCursorSelect HAS to be above ExamineEntity
# So that LineEdit receives it correctly.
Expand Down

0 comments on commit 6287ead

Please sign in to comment.