From 662e65d88177ee51cd7054f2b36c6e39746f5804 Mon Sep 17 00:00:00 2001 From: Infi Date: Sat, 11 May 2024 07:43:05 +0200 Subject: [PATCH] More emote improvements --- ChatTwo/EmoteCache.cs | 19 +++++----- ChatTwo/Resources/Language.Designer.cs | 36 +++++++++++++++++++ ChatTwo/Resources/Language.resx | 12 +++++++ ChatTwo/Ui/ChatLogWindow.cs | 5 ++- ChatTwo/Ui/SettingsTabs/Emote.cs | 48 +++++++++++++++++++++----- ChatTwo/Util/SearchSelector.cs | 2 +- 6 files changed, 100 insertions(+), 22 deletions(-) diff --git a/ChatTwo/EmoteCache.cs b/ChatTwo/EmoteCache.cs index a84f480..32b2fbf 100644 --- a/ChatTwo/EmoteCache.cs +++ b/ChatTwo/EmoteCache.cs @@ -28,8 +28,6 @@ public static class EmoteCache public string Code { get; set; } [JsonPropertyName("imageType")] public string ImageType { get; set; } - [JsonPropertyName("animated")] - public bool Animated { get; set; } }; public enum LoadingState @@ -41,9 +39,8 @@ public static class EmoteCache private const string BetterTTV = "https://api.betterttv.net/3"; private const string GlobalEmotes = $"{BetterTTV}/cached/emotes/global"; - private const string Top100Emotes = $"{BetterTTV}/emotes/shared/top?limit=100"; - private const string Top100BeforeEmotes = "{0}/emotes/shared/top?before={1}&limit=100"; - private const string EmotePath = "https://cdn.betterttv.net/emote/{0}/3x"; + private const string Top100Emotes = "{0}/emotes/shared/top?before={1}&limit=100"; + private const string EmotePath = "https://cdn.betterttv.net/emote/{0}/1x"; private static readonly HttpClient Client = new(); @@ -53,7 +50,7 @@ public static class EmoteCache private static Dictionary Cache = new(); - public static string[] EmoteCodeArray = []; + public static string[] SortedCodeArray = []; public static async void LoadData() { @@ -70,9 +67,9 @@ public static class EmoteCache Cache.TryAdd(emote.Code, emote); var lastId = string.Empty; - for (var i = 0; i < 10; i++) + for (var i = 0; i < 15; i++) { - var top = await Client.GetAsync(lastId == string.Empty ? Top100Emotes : Top100BeforeEmotes.Format(BetterTTV, lastId)); + var top = await Client.GetAsync(Top100Emotes.Format(BetterTTV, lastId)); var topList = await top.Content.ReadAsStringAsync(); var jsonList = JsonSerializer.Deserialize>(topList)!; @@ -82,18 +79,18 @@ public static class EmoteCache lastId = jsonList.Last().Id; } - EmoteCodeArray = Cache.Keys.ToArray(); + SortedCodeArray = Cache.Keys.Order().ToArray(); State = LoadingState.Done; } catch (Exception ex) { - Plugin.Log.Error(ex, "BetterTTV cache wasn't initialized1"); + Plugin.Log.Error(ex, "BetterTTV cache wasn't initialized"); } } internal static bool Exists(string code) { - return State is LoadingState.Done && EmoteCodeArray.Contains(code); + return State is LoadingState.Done && SortedCodeArray.Contains(code); } internal static IEmote? GetEmote(string code) diff --git a/ChatTwo/Resources/Language.Designer.cs b/ChatTwo/Resources/Language.Designer.cs index 0bbee95..85d8b8a 100755 --- a/ChatTwo/Resources/Language.Designer.cs +++ b/ChatTwo/Resources/Language.Designer.cs @@ -1877,6 +1877,15 @@ namespace ChatTwo.Resources { } } + /// + /// Looks up a localized string similar to Emote Stats. + /// + internal static string Options_Emote_EmoteStats { + get { + return ResourceManager.GetString("Options_Emote_EmoteStats", resourceCulture); + } + } + /// /// Looks up a localized string similar to Emote. /// @@ -1886,6 +1895,33 @@ namespace ChatTwo.Resources { } } + /// + /// Looks up a localized string similar to Emotes available:. + /// + internal static string Options_Emote_Loaded { + get { + return ResourceManager.GetString("Options_Emote_Loaded", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Not Ready. + /// + internal static string Options_Emote_NotReady { + get { + return ResourceManager.GetString("Options_Emote_NotReady", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Ready. + /// + internal static string Options_Emote_Ready { + get { + return ResourceManager.GetString("Options_Emote_Ready", resourceCulture); + } + } + /// /// Looks up a localized string similar to Emotes. /// diff --git a/ChatTwo/Resources/Language.resx b/ChatTwo/Resources/Language.resx index 1ea4d60..ec4994a 100644 --- a/ChatTwo/Resources/Language.resx +++ b/ChatTwo/Resources/Language.resx @@ -1039,4 +1039,16 @@ Hide the chat during battles. + + Emote Stats + + + Ready + + + Not Ready + + + Emotes available: + diff --git a/ChatTwo/Ui/ChatLogWindow.cs b/ChatTwo/Ui/ChatLogWindow.cs index aab70e2..8c9a155 100644 --- a/ChatTwo/Ui/ChatLogWindow.cs +++ b/ChatTwo/Ui/ChatLogWindow.cs @@ -1531,7 +1531,10 @@ public sealed class ChatLogWindow : Window image.Draw(emoteSize); else ImGui.Dummy(emoteSize); - ImGui.SetTooltip(emotePayload.Code); + + if (ImGui.IsItemHovered()) + ImGui.SetTooltip(emotePayload.Code); + return; } diff --git a/ChatTwo/Ui/SettingsTabs/Emote.cs b/ChatTwo/Ui/SettingsTabs/Emote.cs index 66acb9d..c8ae72a 100644 --- a/ChatTwo/Ui/SettingsTabs/Emote.cs +++ b/ChatTwo/Ui/SettingsTabs/Emote.cs @@ -15,7 +15,7 @@ internal sealed class Emote : ISettingsTab public string Name => Language.Options_Emote_Tab + "###tabs-emote"; - private static SearchSelector.SelectorPopupOptions WordPopupOptions = null!; + private static SearchSelector.SelectorPopupOptions? WordPopupOptions; internal Emote(Plugin plugin, Configuration mutable) { @@ -24,7 +24,15 @@ internal sealed class Emote : ISettingsTab WordPopupOptions = new SearchSelector.SelectorPopupOptions { - FilteredSheet = EmoteCache.EmoteCodeArray.Where(w => !Mutable.BlockedEmotes.Contains(w)) + FilteredSheet = EmoteCache.SortedCodeArray.Where(w => !Mutable.BlockedEmotes.Contains(w)).ToArray() + }; + } + + private SearchSelector.SelectorPopupOptions RefillSheet() + { + return new SearchSelector.SelectorPopupOptions + { + FilteredSheet = EmoteCache.SortedCodeArray.Where(w => !Mutable.BlockedEmotes.Contains(w)).ToArray() }; } @@ -38,6 +46,10 @@ internal sealed class Emote : ISettingsTab ImGui.TextUnformatted(Language.Options_Emote_BlockedEmotes); ImGui.Spacing(); + WordPopupOptions ??= RefillSheet(); + if (EmoteCache.State is EmoteCache.LoadingState.Done && WordPopupOptions.FilteredSheet.Length == 0) + WordPopupOptions = RefillSheet(); + var buttonWidth = ImGui.GetContentRegionAvail().X / 3; using (Plugin.FontManager.FontAwesome.Push()) ImGui.Button(FontAwesomeIcon.Plus.ToIconString(), new Vector2(buttonWidth, 0)); @@ -71,14 +83,32 @@ internal sealed class Emote : ISettingsTab ImGui.Separator(); ImGui.Spacing(); - if (EmoteCache.State is EmoteCache.LoadingState.Done) - ImGui.TextColored(ImGuiColors.HealerGreen, "Ready"); - else - ImGui.TextColored(ImGuiColors.DPSRed, "Not Ready"); + ImGui.TextUnformatted(Language.Options_Emote_EmoteStats); + ImGui.Spacing(); - ImGui.TextUnformatted($"Emotes loaded: {EmoteCache.EmoteCodeArray.Length}"); - foreach (var word in EmoteCache.EmoteCodeArray) - ImGui.TextUnformatted(word); + if (EmoteCache.State is EmoteCache.LoadingState.Done) + ImGui.TextColored(ImGuiColors.HealerGreen, Language.Options_Emote_Ready); + else + ImGui.TextColored(ImGuiColors.DPSRed, Language.Options_Emote_NotReady); + + ImGui.TextUnformatted($"{Language.Options_Emote_Loaded} {EmoteCache.SortedCodeArray.Length}"); + using (var emoteTable = ImRaii.Table("##LoadedEmotes", 5, ImGuiTableFlags.RowBg | ImGuiTableFlags.BordersInner)) + { + if (emoteTable) + { + ImGui.TableSetupColumn("##word1"); + ImGui.TableSetupColumn("##word2"); + ImGui.TableSetupColumn("##word3"); + ImGui.TableSetupColumn("##word4"); + ImGui.TableSetupColumn("##word5"); + + foreach (var word in EmoteCache.SortedCodeArray) + { + ImGui.TableNextColumn(); + ImGui.TextUnformatted(word); + } + } + } ImGui.PopTextWrapPos(); } diff --git a/ChatTwo/Util/SearchSelector.cs b/ChatTwo/Util/SearchSelector.cs index a6aa6e0..3acc6f2 100644 --- a/ChatTwo/Util/SearchSelector.cs +++ b/ChatTwo/Util/SearchSelector.cs @@ -20,7 +20,7 @@ public static class SearchSelector public Func FormatRow { get; init; } = row => row.ToString(); public Func? SearchPredicate { get; init; } = null; public Func? DrawSelectable { get; init; } = null; - public IEnumerable FilteredSheet { get; init; } = []; + public string[] FilteredSheet { get; init; } = []; public Vector2? Size { get; init; } = null; }