Skip to content

Commit

Permalink
rewiew
Browse files Browse the repository at this point in the history
  • Loading branch information
Spatison committed Sep 12, 2024
1 parent dcd1634 commit 5ccd0ae
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void UnloadButtons()
_action.UnloadButton();
_sandbox.UnloadButton();
_language.UnloadButton();
_emotions.LoadButton(); // WD EDIT
_emotions.UnloadButton(); // WD EDIT
}

public void LoadButtons()
Expand Down
71 changes: 48 additions & 23 deletions Content.Client/_White/UI/Emotions/EmotionsUIController.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Linq;
using Content.Client._White.UI.Emotions.Windows;
using Content.Client.Chat.Managers;
using Content.Client.Gameplay;
using Content.Client.UserInterface.Controls;
Expand All @@ -8,6 +7,7 @@
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;
Expand All @@ -20,37 +20,24 @@ public sealed class EmotionsUIController : UIController, IOnStateChanged<Gamepla
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly IChatManager _chatManager = default!;


private EmotionsWindow? _window;
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 = UIManager.CreateWindow<EmotionsWindow>();
_window = FormMenu();

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

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);
_window.EmotionsContainer.AddChild(button);
}

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

public void OnStateExited(GameplayState state)
{
Expand Down Expand Up @@ -125,13 +112,51 @@ private void UseEmote(string emote)

private Button CreateEmoteButton(EmotePrototype emote)
{
var control = new Button();
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)));
control.Text = Loc.GetString(emote.ButtonText);
control.HorizontalExpand = true;
control.VerticalExpand = true;
control.MaxWidth = 250;
control.MaxHeight = 50;
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;
}
}
12 changes: 0 additions & 12 deletions Content.Client/_White/UI/Emotions/Windows/EmotionsWindow.xaml

This file was deleted.

14 changes: 0 additions & 14 deletions Content.Client/_White/UI/Emotions/Windows/EmotionsWindow.xaml.cs

This file was deleted.

0 comments on commit 5ccd0ae

Please sign in to comment.