Emotes Menu (#26702)
* Basic emote radial menu * Move out from corvax * Move to UI controller & add to top menu bar and key bind * Make emote play * Add name localization for emotes * Localize chat messages * Fix emote menu * Add categories localization * Fixes * Fix * Add emotes entity blacklist * Fix entity whitelist required all logic * Remove unused wagging emote * Revert sprite * Set default texture for emote icon * Update Resources/keybinds.yml --------- Co-authored-by: Kara <lunarautomaton6@gmail.com>
This commit is contained in:
@@ -0,0 +1,125 @@
|
||||
using Content.Client.Chat.UI;
|
||||
using Content.Client.Gameplay;
|
||||
using Content.Client.UserInterface.Controls;
|
||||
using Content.Shared.Chat;
|
||||
using Content.Shared.Chat.Prototypes;
|
||||
using Content.Shared.Input;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Client.Input;
|
||||
using Robust.Client.UserInterface.Controllers;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Shared.Input.Binding;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.Client.UserInterface.Systems.Emotes;
|
||||
|
||||
[UsedImplicitly]
|
||||
public sealed class EmotesUIController : UIController, IOnStateChanged<GameplayState>
|
||||
{
|
||||
[Dependency] private readonly IEntityManager _entityManager = default!;
|
||||
[Dependency] private readonly IClyde _displayManager = default!;
|
||||
[Dependency] private readonly IInputManager _inputManager = default!;
|
||||
|
||||
private MenuButton? EmotesButton => UIManager.GetActiveUIWidgetOrNull<MenuBar.Widgets.GameTopMenuBar>()?.EmotesButton;
|
||||
private EmotesMenu? _menu;
|
||||
|
||||
public void OnStateEntered(GameplayState state)
|
||||
{
|
||||
CommandBinds.Builder
|
||||
.Bind(ContentKeyFunctions.OpenEmotesMenu,
|
||||
InputCmdHandler.FromDelegate(_ => ToggleEmotesMenu(false)))
|
||||
.Register<EmotesUIController>();
|
||||
}
|
||||
|
||||
public void OnStateExited(GameplayState state)
|
||||
{
|
||||
CommandBinds.Unregister<EmotesUIController>();
|
||||
}
|
||||
|
||||
private void ToggleEmotesMenu(bool centered)
|
||||
{
|
||||
if (_menu == null)
|
||||
{
|
||||
// setup window
|
||||
_menu = UIManager.CreateWindow<EmotesMenu>();
|
||||
_menu.OnClose += OnWindowClosed;
|
||||
_menu.OnOpen += OnWindowOpen;
|
||||
_menu.OnPlayEmote += OnPlayEmote;
|
||||
|
||||
if (EmotesButton != null)
|
||||
EmotesButton.SetClickPressed(true);
|
||||
|
||||
if (centered)
|
||||
{
|
||||
_menu.OpenCentered();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Open the menu, centered on the mouse
|
||||
var vpSize = _displayManager.ScreenSize;
|
||||
_menu.OpenCenteredAt(_inputManager.MouseScreenPosition.Position / vpSize);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_menu.OnClose -= OnWindowClosed;
|
||||
_menu.OnOpen -= OnWindowOpen;
|
||||
_menu.OnPlayEmote -= OnPlayEmote;
|
||||
|
||||
if (EmotesButton != null)
|
||||
EmotesButton.SetClickPressed(false);
|
||||
|
||||
CloseMenu();
|
||||
}
|
||||
}
|
||||
|
||||
public void UnloadButton()
|
||||
{
|
||||
if (EmotesButton == null)
|
||||
return;
|
||||
|
||||
EmotesButton.OnPressed -= ActionButtonPressed;
|
||||
}
|
||||
|
||||
public void LoadButton()
|
||||
{
|
||||
if (EmotesButton == null)
|
||||
return;
|
||||
|
||||
EmotesButton.OnPressed += ActionButtonPressed;
|
||||
}
|
||||
|
||||
private void ActionButtonPressed(BaseButton.ButtonEventArgs args)
|
||||
{
|
||||
ToggleEmotesMenu(true);
|
||||
}
|
||||
|
||||
private void OnWindowClosed()
|
||||
{
|
||||
if (EmotesButton != null)
|
||||
EmotesButton.Pressed = false;
|
||||
|
||||
CloseMenu();
|
||||
}
|
||||
|
||||
private void OnWindowOpen()
|
||||
{
|
||||
if (EmotesButton != null)
|
||||
EmotesButton.Pressed = true;
|
||||
}
|
||||
|
||||
private void CloseMenu()
|
||||
{
|
||||
if (_menu == null)
|
||||
return;
|
||||
|
||||
_menu.Dispose();
|
||||
_menu = null;
|
||||
}
|
||||
|
||||
private void OnPlayEmote(ProtoId<EmotePrototype> protoId)
|
||||
{
|
||||
_entityManager.RaisePredictiveEvent(new PlayEmoteMessage(protoId));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user