Skip to content

Commit

Permalink
remove: отключим наше меню эмоций в пользу колеса эмоций
Browse files Browse the repository at this point in the history
  • Loading branch information
Remuchi committed Oct 19, 2024
1 parent 3318f65 commit 526211b
Show file tree
Hide file tree
Showing 3 changed files with 166 additions and 174 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using Content.Client._White.UI.Emotions;
using Content.Client.UserInterface.Systems.Actions;
using Content.Client.UserInterface.Systems.Admin;
using Content.Client.UserInterface.Systems.Bwoink;
Expand Down Expand Up @@ -27,7 +26,6 @@ public sealed class GameTopMenuBarUIController : UIController
[Dependency] private readonly GuidebookUIController _guidebook = default!;
[Dependency] private readonly EmotesUIController _emotes = default!;
[Dependency] private readonly LanguageMenuUIController _language = default!;
[Dependency] private readonly EmotionsUIController _emotions = default!; // WD EDIT

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

Expand All @@ -52,7 +50,6 @@ public void UnloadButtons()
_sandbox.UnloadButton();
_emotes.UnloadButton();
_language.UnloadButton();
_emotions.UnloadButton(); // WD EDIT
}

public void LoadButtons()
Expand All @@ -67,6 +64,5 @@ public void LoadButtons()
_sandbox.LoadButton();
_emotes.LoadButton();
_language.LoadButton();
_emotions.LoadButton(); // WD EDIT
}
}
328 changes: 166 additions & 162 deletions Content.Client/_White/UI/Emotions/EmotionsUIController.cs
Original file line number Diff line number Diff line change
@@ -1,162 +1,166 @@
using System.Linq;
using Content.Client.Chat.Managers;
using Content.Client.Gameplay;
using Content.Client.UserInterface.Controls;
using Content.Shared.Chat;
using Content.Shared.Chat.Prototypes;
using Content.Shared.Input;
using Robust.Client.UserInterface.Controllers;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.CustomControls;
using Robust.Shared.Input.Binding;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;

namespace Content.Client._White.UI.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 DefaultWindow? _window;
private MenuButton? EmotionsButton => UIManager.GetActiveUIWidgetOrNull<UserInterface.Systems.MenuBar.Widgets.GameTopMenuBar>()?.EmotionsButton;

private DateTime _lastEmotionTimeUse = DateTime.Now;
private const float EmoteCooldown = 1.5f;

public void OnStateEntered(GameplayState state)
{
_window = FormMenu();

_window.OnOpen += OnWindowOpened;
_window.OnClose += OnWindowClosed;

CommandBinds.Builder
.Bind(ContentKeyFunctions.OpenEmotionsMenu,
InputCmdHandler.FromDelegate(_ => ToggleWindow()))
.Register<EmotionsUIController>();
}

public void OnStateExited(GameplayState state)
{
if (_window != null)
{
_window.OnOpen -= OnWindowOpened;
_window.OnClose -= OnWindowClosed;

_window.Dispose();
_window = null;
}

CommandBinds.Unregister<EmotionsUIController>();
}

public void LoadButton()
{
if (EmotionsButton == null)
return;

EmotionsButton.OnPressed += EmotionsButtonPressed;
}

public void UnloadButton()
{
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;
}

private void EmotionsButtonPressed(BaseButton.ButtonEventArgs args)
{
ToggleWindow();
}

private void ToggleWindow()
{
if (_window == null)
return;

if (_window.IsOpen)
{
_window.Close();
return;
}

_window.Open();
}

private void UseEmote(string emote)
{
var time = (DateTime.Now - _lastEmotionTimeUse).TotalSeconds;
if (time < EmoteCooldown)
return;

_lastEmotionTimeUse = DateTime.Now;
_chatManager.SendMessage(emote, ChatSelectChannel.Emotes);
}

private Button CreateEmoteButton(EmotePrototype emote)
{
var control = new Button
{
ClipText = true,
HorizontalExpand = true,
VerticalExpand = true,
MinWidth = 120,
MaxWidth = 250,
MaxHeight = 35,
TextAlign = Label.AlignMode.Left,
Text = Loc.GetString(emote.ButtonText)
};

control.OnPressed += _ => UseEmote(Loc.GetString(_random.Pick(emote.ChatMessages)));
return control;
}

private DefaultWindow FormMenu()
{
var window = new DefaultWindow
{
Title = Loc.GetString("emotions-menu-title"),
VerticalExpand = true,
HorizontalExpand = true,
MinHeight = 250,
MinWidth = 300
};

var grid = new GridContainer
{
Columns = 3
};

var emotions = _prototypeManager.EnumeratePrototypes<EmotePrototype>().ToList();
emotions.Sort((a,b) => string.Compare(Loc.GetString(a.ButtonText), Loc.GetString(b.ButtonText.ToString()), StringComparison.Ordinal));

foreach (var emote in emotions)
{
if (!emote.AllowToEmotionsMenu)
continue;

var button = CreateEmoteButton(emote);
grid.AddChild(button);
}

window.Contents.AddChild(grid);
return window;
}
}
/*
* DISABLED IN FAVOR OF EMOTES RADIAL MENU
*/


// using System.Linq;
// using Content.Client.Chat.Managers;
// using Content.Client.Gameplay;
// using Content.Client.UserInterface.Controls;
// using Content.Shared.Chat;
// using Content.Shared.Chat.Prototypes;
// using Content.Shared.Input;
// using Robust.Client.UserInterface.Controllers;
// using Robust.Client.UserInterface.Controls;
// using Robust.Client.UserInterface.CustomControls;
// using Robust.Shared.Input.Binding;
// using Robust.Shared.Prototypes;
// using Robust.Shared.Random;
//
// namespace Content.Client._White.UI.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 DefaultWindow? _window;
// private MenuButton? EmotionsButton => UIManager.GetActiveUIWidgetOrNull<UserInterface.Systems.MenuBar.Widgets.GameTopMenuBar>()?.EmotionsButton;
//
// private DateTime _lastEmotionTimeUse = DateTime.Now;
// private const float EmoteCooldown = 1.5f;
//
// public void OnStateEntered(GameplayState state)
// {
// _window = FormMenu();
//
// _window.OnOpen += OnWindowOpened;
// _window.OnClose += OnWindowClosed;
//
// CommandBinds.Builder
// .Bind(ContentKeyFunctions.OpenEmotesMenu, InputCmdHandler.FromDelegate(_ => ToggleWindow()))
// .Register<EmotionsUIController>();
// }
//
// public void OnStateExited(GameplayState state)
// {
// if (_window != null)
// {
// _window.OnOpen -= OnWindowOpened;
// _window.OnClose -= OnWindowClosed;
//
// _window.Dispose();
// _window = null;
// }
//
// CommandBinds.Unregister<EmotionsUIController>();
// }
//
// public void LoadButton()
// {
// if (EmotionsButton == null)
// return;
//
// EmotionsButton.OnPressed += EmotionsButtonPressed;
// }
//
// public void UnloadButton()
// {
// 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;
// }
//
// private void EmotionsButtonPressed(BaseButton.ButtonEventArgs args)
// {
// ToggleWindow();
// }
//
// private void ToggleWindow()
// {
// if (_window == null)
// return;
//
// if (_window.IsOpen)
// {
// _window.Close();
// return;
// }
//
// _window.Open();
// }
//
// private void UseEmote(string emote)
// {
// var time = (DateTime.Now - _lastEmotionTimeUse).TotalSeconds;
// if (time < EmoteCooldown)
// return;
//
// _lastEmotionTimeUse = DateTime.Now;
// _chatManager.SendMessage(emote, ChatSelectChannel.Emotes);
// }
//
// private Button CreateEmoteButton(EmotePrototype emote)
// {
// var control = new Button
// {
// ClipText = true,
// HorizontalExpand = true,
// VerticalExpand = true,
// MinWidth = 120,
// MaxWidth = 250,
// MaxHeight = 35,
// TextAlign = Label.AlignMode.Left,
// Text = Loc.GetString(emote.ButtonText)
// };
//
// control.OnPressed += _ => UseEmote(Loc.GetString(_random.Pick(emote.ChatMessages)));
// return control;
// }
//
// private DefaultWindow FormMenu()
// {
// var window = new DefaultWindow
// {
// Title = Loc.GetString("emotions-menu-title"),
// VerticalExpand = true,
// HorizontalExpand = true,
// MinHeight = 250,
// MinWidth = 300
// };
//
// var grid = new GridContainer
// {
// Columns = 3
// };
//
// var emotions = _prototypeManager.EnumeratePrototypes<EmotePrototype>().ToList();
// emotions.Sort((a,b) => string.Compare(Loc.GetString(a.ButtonText), Loc.GetString(b.ButtonText.ToString()), StringComparison.Ordinal));
//
// foreach (var emote in emotions)
// {
// if (!emote.AllowToEmotionsMenu)
// continue;
//
// var button = CreateEmoteButton(emote);
// grid.AddChild(button);
// }
//
// window.Contents.AddChild(grid);
// return window;
// }
// }
8 changes: 0 additions & 8 deletions Content.Shared/Chat/Prototypes/EmotePrototype.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,6 @@ public sealed partial class EmotePrototype : IPrototype
/// </summary>
[DataField]
public HashSet<string> ChatTriggers = new();

// WD EDIT START
[DataField]
public string ButtonText = "Unknown";

[DataField("allowMenu")]
public bool AllowToEmotionsMenu;
// WD EDIT END
}

/// <summary>
Expand Down

0 comments on commit 526211b

Please sign in to comment.