-
Notifications
You must be signed in to change notification settings - Fork 473
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove the Action event to toggle the Language menu to the TopBar, more pretty and does not add up "useless" actions.
- Loading branch information
1 parent
800b7fa
commit 6287ead
Showing
12 changed files
with
105 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
114 changes: 82 additions & 32 deletions
114
Content.Client/_NF/UserInterface/Systems/Language/LanguageMenuUIController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file was deleted.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters