| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- 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));
- }
- }
|