More emote improvements
This commit is contained in:
+8
-11
@@ -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<string, Emote> 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<List<Top100>>(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)
|
||||
|
||||
Generated
+36
@@ -1877,6 +1877,15 @@ namespace ChatTwo.Resources {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Emote Stats.
|
||||
/// </summary>
|
||||
internal static string Options_Emote_EmoteStats {
|
||||
get {
|
||||
return ResourceManager.GetString("Options_Emote_EmoteStats", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Emote.
|
||||
/// </summary>
|
||||
@@ -1886,6 +1895,33 @@ namespace ChatTwo.Resources {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Emotes available:.
|
||||
/// </summary>
|
||||
internal static string Options_Emote_Loaded {
|
||||
get {
|
||||
return ResourceManager.GetString("Options_Emote_Loaded", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Not Ready.
|
||||
/// </summary>
|
||||
internal static string Options_Emote_NotReady {
|
||||
get {
|
||||
return ResourceManager.GetString("Options_Emote_NotReady", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Ready.
|
||||
/// </summary>
|
||||
internal static string Options_Emote_Ready {
|
||||
get {
|
||||
return ResourceManager.GetString("Options_Emote_Ready", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Emotes.
|
||||
/// </summary>
|
||||
|
||||
@@ -1039,4 +1039,16 @@
|
||||
<data name="Options_HideInBattle_Description" xml:space="preserve">
|
||||
<value>Hide the chat during battles.</value>
|
||||
</data>
|
||||
<data name="Options_Emote_EmoteStats" xml:space="preserve">
|
||||
<value>Emote Stats</value>
|
||||
</data>
|
||||
<data name="Options_Emote_Ready" xml:space="preserve">
|
||||
<value>Ready</value>
|
||||
</data>
|
||||
<data name="Options_Emote_NotReady" xml:space="preserve">
|
||||
<value>Not Ready</value>
|
||||
</data>
|
||||
<data name="Options_Emote_Loaded" xml:space="preserve">
|
||||
<value>Emotes available:</value>
|
||||
</data>
|
||||
</root>
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ public static class SearchSelector
|
||||
public Func<string, string> FormatRow { get; init; } = row => row.ToString();
|
||||
public Func<string, string, bool>? SearchPredicate { get; init; } = null;
|
||||
public Func<string, bool, bool>? DrawSelectable { get; init; } = null;
|
||||
public IEnumerable<string> FilteredSheet { get; init; } = [];
|
||||
public string[] FilteredSheet { get; init; } = [];
|
||||
public Vector2? Size { get; init; } = null;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user