using Noesis; using System.Collections.Generic; using System.Linq; using GUI = Noesis.GUI; using NoesisEventArgs = Noesis.EventArgs; using StellarConquest.Model.Extensions; namespace StellarConquest.Presentation.Unity.UI { public partial class EmotesControl : OverlayControl { public static readonly IReadOnlyList Emotes = new List() { "angry hurt", "angry point", "anticipate", "apex", "argue", "ashamed", "backhand", "beckon", "blame", "bow", "boxing", "brush off", "cheer", "chicken", "come at me", "conduct", "cough", "cough arm", "crazy", "cry", "cry slow", "dab left", "dab right", "dang", "despair", "drum", "embrace", "encourage", "exasperation", "exhaustion", "explain", "face palm", "faint", "frustration", "giggle", "glory spin", "grateful", "groin", "gunslinger", "hat tip", "headache", "hook line", "horns", "i can't hear you", "idea", "ignore", "impatient", "impatient foot", "jig", "karate kick", "kick ground", "knuckles", "lasso", "laugh", "laugh belly", "maca", "mime", "moonwalk", "mr universe", "nailed it", "nervous", "no more", "no way", "no", "nod", "nod left", "nod right", "over here", "pain", "please", "point behind", "point down", "point forward", "point left", "point right", "raise the roof", "rally", "regret", "relief", "ride bull", "ride bull circle", "robot", "sad", "salutations", "salute", "sarcastic clap", "scared", "shake behind", "shoot me now", "shut up", "slit throat", "stair walk", "stop", "that way", "the finger", "the wave", "think", "tired", "tired stretch", "touchdown", "up yours", "victory", "waiting", "warm up", "wave", "wave gentle", "wave long", "what", "winning", "yes" }; private FrameworkElement _Root; private ToggleButton _SortButton; private StackPanel _RecentEmotesStackPanel; private ListBox _RecentEmotesListBox; private ListBox _EmotesListBox; private List _Emotes = new List(Emotes); private List _RecentEmotes = new List(); public string SelectedEmote { get; private set; } public EmotesControl() { Name = nameof(EmotesControl); Initialized += OnInitialized; InitializeComponent(); } protected override void InitializeComponent() { base.InitializeComponent(); GUI.LoadComponent(this, "Assets/User Interface/Screens/Game/Overlay/Emotes/EmotesControl.xaml"); _Root = Content as FrameworkElement; _SortButton = _Root.FindName(nameof(_SortButton)) as ToggleButton; _RecentEmotesStackPanel = _Root.FindName("_RecentEmotesStackPanel") as StackPanel; _RecentEmotesListBox = _Root.FindName("_RecentEmotesListBox") as ListBox; _EmotesListBox = _Root.FindName("_EmotesListBox") as ListBox; } protected override void OnInitialized(object sender, NoesisEventArgs args) { base.OnInitialized(sender, args); _SortButton.Checked += (sender, e) => { _Emotes = _Emotes.OrderBy(a => a).ToList(); Update(); }; _SortButton.Unchecked += (sender, e) => { _Emotes = _Emotes.OrderByDescending(a => a).ToList(); Update(); }; UIUtility.SetToolTip(_SortButton, "Sort Emotes", null, "sort_svg", "Sorts emotes by name or last used date"); } public void Update(List emotes = null) { if (emotes != null) _Emotes = emotes.OrderByDescending(a => a).ToList(); SelectedEmote = null; if (_RecentEmotes.Count == 0) _RecentEmotesStackPanel.Visibility = Visibility.Collapsed; else { _RecentEmotesListBox.Items.Clear(); foreach (string emote in _RecentEmotes) { ListBoxItem item = CreateRow(emote); _RecentEmotesListBox.Items.Add(item); } _RecentEmotesStackPanel.Visibility = Visibility.Visible; } _EmotesListBox.Items.Clear(); foreach (string emote in _Emotes) { ListBoxItem item = CreateRow(emote); _EmotesListBox.Items.Add(item); } _EmotesListBox.ScrollIntoView(_EmotesListBox.Items[0]); _EmotesListBox.UpdateLayout(); } private ListBoxItem CreateRow(string emote) { string svgIcon = "emoteminimal_svg"; string emoteLabel = emote.ToTitleCase(); StackPanel stackPanel = UIUtility.CreateActionLabel(_Root, emoteLabel, svgIcon, emoteLabel); ((FrameworkElement)stackPanel.Children[1]).Margin = new Thickness(0, 0, 5, 0); ((FrameworkElement)stackPanel.Children[1]).HorizontalAlignment = HorizontalAlignment.Stretch; ListBoxItem item = new ListBoxItem(); item.Content = stackPanel; item.Margin = new Thickness(0, 0, 3, 0); item.PreviewKeyDown += (sender, e) => { SelectedEmote = emote; _RecentEmotes.Insert(0, SelectedEmote); if (_RecentEmotes.Count > 3) _RecentEmotes.RemoveAt(3); Hide(); }; item.MouseDown += (sender, e) => { SelectedEmote = emote; }; item.MouseDoubleClick += (sender, e) => { SelectedEmote = emote; _RecentEmotes.Insert(0, SelectedEmote); if (_RecentEmotes.Count > 3) _RecentEmotes.RemoveAt(3); Hide(); }; item.Content = stackPanel; return item; } } }