[feat] Emote panel, monkey rsi fix
This commit is contained in:
@@ -0,0 +1,139 @@
|
||||
using System.Linq;
|
||||
using Content.Client.Chat.Managers;
|
||||
using Content.Client.Gameplay;
|
||||
using Content.Client.UserInterface.Controls;
|
||||
using Content.Client.UserInterface.Systems.Emotions.Windows;
|
||||
using Content.Shared.Chat;
|
||||
using Content.Shared.Chat.Prototypes;
|
||||
using Content.Shared.Input;
|
||||
using Robust.Client.UserInterface;
|
||||
using Robust.Client.UserInterface.Controllers;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Shared.Input.Binding;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Random;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Content.Client.UserInterface.Systems.Emotions;
|
||||
|
||||
public sealed class EmotionsUIController : UIController, IOnStateChanged<GameplayState>
|
||||
{
|
||||
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
||||
[Dependency] private readonly IRobustRandom _random = default!;
|
||||
[Dependency] private readonly IChatManager _chatManager = default!;
|
||||
|
||||
|
||||
private EmotionsWindow? _window;
|
||||
private MenuButton? EmotionsButton => UIManager.GetActiveUIWidgetOrNull<MenuBar.Widgets.GameTopMenuBar>()?.EmotionsButton;
|
||||
|
||||
private DateTime _lastEmotionTimeUse = DateTime.Now;
|
||||
private float _emoteCooldown = 1.5f;
|
||||
|
||||
public void OnStateEntered(GameplayState state)
|
||||
{
|
||||
DebugTools.Assert(_window == null);
|
||||
|
||||
_window = UIManager.CreateWindow<EmotionsWindow>();
|
||||
|
||||
_window.OnOpen += OnWindowOpened;
|
||||
_window.OnClose += OnWindowClosed;
|
||||
|
||||
var emotions = _prototypeManager.EnumeratePrototypes<EmotePrototype>().ToList();
|
||||
emotions.Sort((a,b) => string.Compare(a.ButtonText, b.ButtonText.ToString(), StringComparison.Ordinal));
|
||||
|
||||
foreach (var emote in emotions)
|
||||
{
|
||||
var control = new Button();
|
||||
control.OnPressed += _ => UseEmote(_random.Pick(emote.ChatMessages));
|
||||
control.Text = emote.ButtonText;
|
||||
control.HorizontalExpand = true;
|
||||
control.VerticalExpand = true;
|
||||
control.MaxWidth = 250;
|
||||
control.MaxHeight = 50;
|
||||
_window.EmotionsContainer.AddChild(control);
|
||||
}
|
||||
|
||||
CommandBinds.Builder
|
||||
.Bind(ContentKeyFunctions.OpenEmotionsMenu,
|
||||
InputCmdHandler.FromDelegate(_ => ToggleWindow()))
|
||||
.Register<EmotionsUIController>();
|
||||
}
|
||||
|
||||
public void UnloadButton()
|
||||
{
|
||||
if (EmotionsButton == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
EmotionsButton.OnPressed -= EmotionsButtonPressed;
|
||||
}
|
||||
|
||||
private void UseEmote(string emote)
|
||||
{
|
||||
var timeSpan = DateTime.Now - _lastEmotionTimeUse;
|
||||
var seconds = timeSpan.TotalSeconds;
|
||||
if (seconds < _emoteCooldown)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_lastEmotionTimeUse = DateTime.Now;
|
||||
_chatManager.SendMessage(emote, ChatSelectChannel.Emotes);
|
||||
}
|
||||
|
||||
public void LoadButton()
|
||||
{
|
||||
if (EmotionsButton == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
EmotionsButton.OnPressed += EmotionsButtonPressed;
|
||||
}
|
||||
|
||||
private void OnWindowOpened()
|
||||
{
|
||||
if (EmotionsButton != null)
|
||||
EmotionsButton.Pressed = true;
|
||||
}
|
||||
|
||||
private void OnWindowClosed()
|
||||
{
|
||||
if (EmotionsButton != null)
|
||||
EmotionsButton.Pressed = false;
|
||||
}
|
||||
|
||||
public void OnStateExited(GameplayState state)
|
||||
{
|
||||
if (_window != null)
|
||||
{
|
||||
_window.OnOpen -= OnWindowOpened;
|
||||
_window.OnClose -= OnWindowClosed;
|
||||
|
||||
_window.Dispose();
|
||||
_window = null;
|
||||
}
|
||||
|
||||
CommandBinds.Unregister<EmotionsUIController>();
|
||||
}
|
||||
|
||||
private void EmotionsButtonPressed(BaseButton.ButtonEventArgs args)
|
||||
{
|
||||
ToggleWindow();
|
||||
}
|
||||
|
||||
private void ToggleWindow()
|
||||
{
|
||||
if (_window == null)
|
||||
return;
|
||||
|
||||
if (_window.IsOpen)
|
||||
{
|
||||
_window.Close();
|
||||
return;
|
||||
}
|
||||
|
||||
_window.Open();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<windows:EmotionsWindow
|
||||
xmlns="https://spacestation14.io"
|
||||
xmlns:windows="clr-namespace:Content.Client.UserInterface.Systems.Emotions.Windows"
|
||||
Title="Меню эмоций"
|
||||
VerticalExpand="True"
|
||||
HorizontalExpand="True"
|
||||
MinHeight="250"
|
||||
MinWidth="300">
|
||||
<GridContainer Name="EmotionsContainer" Access="Public" Columns="3">
|
||||
|
||||
</GridContainer>
|
||||
</windows:EmotionsWindow>
|
||||
@@ -0,0 +1,13 @@
|
||||
using Robust.Client.AutoGenerated;
|
||||
using Robust.Client.UserInterface.CustomControls;
|
||||
using Robust.Client.UserInterface.XAML;
|
||||
|
||||
namespace Content.Client.UserInterface.Systems.Emotions.Windows;
|
||||
[GenerateTypedNameReferences]
|
||||
public sealed partial class EmotionsWindow : DefaultWindow
|
||||
{
|
||||
public EmotionsWindow()
|
||||
{
|
||||
RobustXamlLoader.Load(this);
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ using Content.Client.UserInterface.Systems.Admin;
|
||||
using Content.Client.UserInterface.Systems.Bwoink;
|
||||
using Content.Client.UserInterface.Systems.Character;
|
||||
using Content.Client.UserInterface.Systems.Crafting;
|
||||
using Content.Client.UserInterface.Systems.Emotions;
|
||||
using Content.Client.UserInterface.Systems.EscapeMenu;
|
||||
using Content.Client.UserInterface.Systems.Gameplay;
|
||||
using Content.Client.UserInterface.Systems.Guidebook;
|
||||
@@ -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 EmotionsUIController _emotions = default!;
|
||||
|
||||
private GameTopMenuBar? GameTopMenuBar => UIManager.GetActiveUIWidgetOrNull<GameTopMenuBar>();
|
||||
|
||||
@@ -44,6 +46,7 @@ public sealed class GameTopMenuBarUIController : UIController
|
||||
_ahelp.UnloadButton();
|
||||
_action.UnloadButton();
|
||||
_sandbox.UnloadButton();
|
||||
_emotions.UnloadButton();
|
||||
}
|
||||
|
||||
public void LoadButtons()
|
||||
@@ -56,5 +59,6 @@ public sealed class GameTopMenuBarUIController : UIController
|
||||
_ahelp.LoadButton();
|
||||
_action.LoadButton();
|
||||
_sandbox.LoadButton();
|
||||
_emotions.LoadButton();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,6 +43,16 @@
|
||||
HorizontalExpand="True"
|
||||
AppendStyleClass="{x:Static style:StyleBase.ButtonSquare}"
|
||||
/>
|
||||
<ui:MenuButton
|
||||
Name="EmotionsButton"
|
||||
Access="Internal"
|
||||
Icon="{xe:Tex '/Textures/Interface/emotions.svg.192dpi.png'}"
|
||||
ToolTip="{Loc 'game-hud-open-emotions-menu-button-tooltip'}"
|
||||
BoundKey = "{x:Static is:ContentKeyFunctions.OpenEmotionsMenu}"
|
||||
MinSize="42 64"
|
||||
HorizontalExpand="True"
|
||||
AppendStyleClass="{x:Static style:StyleBase.ButtonSquare}"
|
||||
/>
|
||||
<ui:MenuButton
|
||||
Name="CraftingButton"
|
||||
Access="Internal"
|
||||
|
||||
Reference in New Issue
Block a user