Skip to content

Commit

Permalink
[Port] Emotions menu / Меню эмоций (#55)
Browse files Browse the repository at this point in the history
* add: emotions munu

* tweak

* fix

* WD EDIT

* test

* AI rewiew

* rewiew
  • Loading branch information
Spatison authored Sep 13, 2024
1 parent daf53fe commit b914415
Show file tree
Hide file tree
Showing 24 changed files with 547 additions and 75 deletions.
1 change: 1 addition & 0 deletions Content.Client/Input/ContentContexts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public static void SetupContexts(IInputContextContainer contexts)
human.AddFunction(ContentKeyFunctions.UseItemInHand);
human.AddFunction(ContentKeyFunctions.AltUseItemInHand);
human.AddFunction(ContentKeyFunctions.OpenCharacterMenu);
human.AddFunction(ContentKeyFunctions.OpenEmotionsMenu); // WD EDIT
human.AddFunction(ContentKeyFunctions.OpenLanguageMenu);
human.AddFunction(ContentKeyFunctions.ActivateItemInWorld);
human.AddFunction(ContentKeyFunctions.ThrowItemInHand);
Expand Down
1 change: 1 addition & 0 deletions Content.Client/Options/UI/Tabs/KeyRebindTab.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ void AddCheckBox(string checkBoxName, bool currentState, Action<BaseButton.Butto
AddButton(ContentKeyFunctions.CycleChatChannelForward);
AddButton(ContentKeyFunctions.CycleChatChannelBackward);
AddButton(ContentKeyFunctions.OpenCharacterMenu);
AddButton(ContentKeyFunctions.OpenEmotionsMenu); // WD EDIT
AddButton(ContentKeyFunctions.OpenCraftingMenu);
AddButton(ContentKeyFunctions.OpenGuidebook);
AddButton(ContentKeyFunctions.OpenInventoryMenu);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
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 All @@ -24,6 +25,7 @@ public sealed class GameTopMenuBarUIController : UIController
[Dependency] private readonly SandboxUIController _sandbox = default!;
[Dependency] private readonly GuidebookUIController _guidebook = default!;
[Dependency] private readonly LanguageMenuUIController _language = default!;
[Dependency] private readonly EmotionsUIController _emotions = default!; // WD EDIT

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

Expand All @@ -47,6 +49,7 @@ public void UnloadButtons()
_action.UnloadButton();
_sandbox.UnloadButton();
_language.UnloadButton();
_emotions.UnloadButton(); // WD EDIT
}

public void LoadButtons()
Expand All @@ -60,5 +63,6 @@ public void LoadButtons()
_action.LoadButton();
_sandbox.LoadButton();
_language.LoadButton();
_emotions.LoadButton(); // WD EDIT
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
Icon="{xe:Tex '/Textures/Interface/hamburger.svg.192dpi.png'}"
BoundKey = "{x:Static ic:EngineKeyFunctions.EscapeMenu}"
ToolTip="{Loc 'game-hud-open-escape-menu-button-tooltip'}"
MinSize="70 64"
MinSize="42 64"
HorizontalExpand="True"
AppendStyleClass="{x:Static style:StyleBase.ButtonOpenRight}"
/>
/> <!-- WD EDIT -->
<ui:MenuButton
Name="GuidebookButton"
Access="Internal"
Expand All @@ -43,6 +43,16 @@
HorizontalExpand="True"
AppendStyleClass="{x:Static style:StyleBase.ButtonSquare}"
/>
<ui:MenuButton
Name="EmotionsButton"
Access="Internal"
Icon="{xe:Tex '/Textures/_White/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}"
/> <!-- WD EDIT -->
<ui:MenuButton
Name="CraftingButton"
Access="Internal"
Expand Down
162 changes: 162 additions & 0 deletions Content.Client/_White/UI/Emotions/EmotionsUIController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
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;
}
}
2 changes: 1 addition & 1 deletion Content.Server/Chat/Systems/ChatSystem.Emote.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ private void CacheEmotes()
{
foreach (var word in emote.ChatTriggers)
{
var lowerWord = word.ToLower();
var lowerWord = Loc.GetString(word).ToLower(); // WD EDIT
if (dict.TryGetValue(lowerWord, out var value))
{
var errMsg = $"Duplicate of emote word {lowerWord} in emotes {emote.ID} and {value.ID}";
Expand Down
8 changes: 8 additions & 0 deletions Content.Shared/Chat/Prototypes/EmotePrototype.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ public sealed partial class EmotePrototype : IPrototype
/// </summary>
[DataField("chatTriggers")]
public HashSet<string> ChatTriggers = new();

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

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

/// <summary>
Expand Down
1 change: 1 addition & 0 deletions Content.Shared/Input/ContentKeyFunctions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public static class ContentKeyFunctions
public static readonly BoundKeyFunction CycleChatChannelBackward = "CycleChatChannelBackward";
public static readonly BoundKeyFunction EscapeContext = "EscapeContext";
public static readonly BoundKeyFunction OpenCharacterMenu = "OpenCharacterMenu";
public static readonly BoundKeyFunction OpenEmotionsMenu = "OpenEmotionsMenu"; // WD EDIT
public static readonly BoundKeyFunction OpenLanguageMenu = "OpenLanguageMenu";
public static readonly BoundKeyFunction OpenCraftingMenu = "OpenCraftingMenu";
public static readonly BoundKeyFunction OpenGuidebook = "OpenGuidebook";
Expand Down
1 change: 1 addition & 0 deletions Resources/Locale/en-US/_white/HUD/game-hud.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
game-hud-open-emotions-menu-button-tooltip = Open emotions menu.
119 changes: 119 additions & 0 deletions Resources/Locale/en-US/_white/emotes/speech-emotes.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
#Scream
emote-chat-button-text-scream = Scream
emote-chat-messages-scream-1 = screams
emote-chat-messages-scream-2 = shrieks
emote-chat-messages-scream-3 = screeches
emote-chat-messages-scream-4 = yells
#Laugh
emote-chat-button-text-laugh = Laugh
emote-chat-messages-laugh-1 = laughs
emote-chat-messages-laugh-2 = chuckles
emote-chat-messages-laugh-3 = giggles
emote-chat-messages-laugh-4 = chortles
#Honk
emote-chat-messages-honk-1 = chortles
#Sigh
emote-chat-button-text-sigh = Sigh
emote-chat-messages-sigh-1 = sighs
#Whistle
emote-chat-button-text-whistle = Whistle
emote-chat-messages-whistle-1 = whistles
#Crying
emote-chat-button-text-crying = Сry
emote-chat-messages-crying-1 = cries
#Squish
emote-chat-messages-squish-1 = squishes
#Chitter
emote-chat-messages-chitter-1 = chitters
#Squeak
emote-chat-messages-squeak-1 = squeaks
#Click
emote-chat-messages-click-1 = clicks
emote-chat-messages-click-2 = click
#Clap
emote-chat-button-text-clap = Clap
emote-chat-messages-clap-1 = сlaps
#Snap
emote-chat-button-text-snap = Snap fingers
emote-chat-messages-snap-1 = snaps
emote-chat-messages-snap-2 = snaps fingers
emote-chat-messages-snap-3 = snaps his fingers
emote-chat-messages-snap-4 = snaps her fingers
emote-chat-messages-snap-5 = snaps their fingers
emote-chat-messages-snap-6 = snaps its fingers
emote-chat-messages-snap-7 = snaps its' fingers
#Salute
emote-chat-button-text-salute = Salute
emote-chat-messages-salute-1 = salutes
#Deathgasp
emote-chat-messages-deathgasp-1 = seizes up and falls limp, {POSS-ADJ($entity)} eyes dead and lifeless...
emote-chat-messages-deathgasp-silicon-1 = seizes up and falls limp, {POSS-ADJ($entity)} lights sputtering into darkness...
emote-chat-messages-deathgasp-ipc-1 = With a hiss of grinding servos and a screech of dying myomers, {CAPITALIZE($entity)} suddenly goes silent.
#Buzz
emote-chat-messages-buzz-1 = buzzes
#Weh
emote-chat-messages-weh-1 = wehs
#Chirp
emote-chat-messages-chirp-1 = chirps
#Beep
emote-chat-messages-beep-1 = beeps
#Boop
emote-chat-messages-boop-1 = boops
#Chime
emote-chat-messages-chime-1 = chimes
#Buzz-Two
emote-chat-messages-buzz-two-1 = buzzes twice
#Ping
emote-chat-messages-ping-1 = pings
#Whirr
emote-chat-messages-whirr-1 = whirrs
#Nod
emote-chat-button-text-nod = Nod
emote-chat-messages-nod-1 = nods
#ShakeHead
emote-chat-button-text-shake-head = Shake head
emote-chat-messages-shake-head-1 = shakes head
#Frown
emote-chat-button-text-frown = Frown
emote-chat-messages-frown-1 = frowns
#Smile
emote-chat-button-text-smile = Smile
emote-chat-messages-smile-1 = smiles
2 changes: 2 additions & 0 deletions Resources/Locale/en-US/_white/escape-menu/options-menu.ftl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
ui-options-function-open-emotions-menu = Open emotions menu
ui-options-function-look-up = Look up/Take aim
ui-options-function-auto-get-up = Automatically get up after falling
ui-options-function-hold-look-up = Hold down the key to aim
Loading

0 comments on commit b914415

Please sign in to comment.