From 671931c23bd17fa316600550929ab61fca8ed938 Mon Sep 17 00:00:00 2001 From: Anna Date: Mon, 22 Jul 2024 13:31:44 -0400 Subject: [PATCH] feat: add more search and remove useless fields --- client/Message.cs | 2 -- client/Ui/MainWindowTabs/Write.cs | 54 ++++++++++++++++++++----------- server/src/main.rs | 1 - server/src/message.rs | 6 ++-- server/src/web/write.rs | 2 +- 5 files changed, 38 insertions(+), 27 deletions(-) diff --git a/client/Message.cs b/client/Message.cs index 7be684a..b5ab5d3 100644 --- a/client/Message.cs +++ b/client/Message.cs @@ -95,7 +95,6 @@ public class EquipmentData { public required byte Stain0 { get; set; } [JsonProperty("stain_1")] public required byte Stain1 { get; set; } - public required ulong Value { get; set; } } [Serializable] @@ -119,7 +118,6 @@ public class WeaponModelId { public required byte Stain0 { get; set; } [JsonProperty("stain_1")] public required byte Stain1 { get; set; } - public required ulong Value { get; set; } } [Serializable] diff --git a/client/Ui/MainWindowTabs/Write.cs b/client/Ui/MainWindowTabs/Write.cs index 8ad7dfe..b80997c 100644 --- a/client/Ui/MainWindowTabs/Write.cs +++ b/client/Ui/MainWindowTabs/Write.cs @@ -29,6 +29,9 @@ internal class Write : ITab { private (int, int) _word2 = (-1, -1); private int _glyph; private int _emoteIdx = -1; + + private string _word1Search = string.Empty; + private string _word2Search = string.Empty; private string _emoteSearch = string.Empty; private const string Placeholder = "****"; @@ -69,10 +72,12 @@ internal class Write : ITab { internal Write(Plugin plugin) { this.Plugin = plugin; - this.Emotes = this.Plugin.DataManager.GetExcelSheet()! - .Skip(1) - .Where(emote => emote.TextCommand.Row != 0) - .ToList(); + this.Emotes = [ + .. this.Plugin.DataManager.GetExcelSheet()! + .Skip(1) + .Where(emote => emote.TextCommand.Row != 0) + .OrderBy(emote => emote.Order) + ]; this._glyph = this.Plugin.Config.DefaultGlyph; Pack.UpdatePacks(); @@ -161,7 +166,7 @@ internal class Write : ITab { } } - void DrawSpecificWordPicker(string id, Template template, ref (int, int) x) { + void DrawSpecificWordPicker(string id, Template template, ref (int, int) x, ref string search) { if (template.Words == null) { return; } @@ -171,16 +176,21 @@ internal class Write : ITab { return; } + using var endCombo = new OnDispose(ImGui.EndCombo); + for (var wordIdx = 0; wordIdx < template.Words.Length; wordIdx++) { - if (ImGui.Selectable(template.Words[wordIdx], x == (-1, wordIdx))) { + var word = template.Words[wordIdx]; + if (!string.IsNullOrEmpty(search) && !word.Contains(search, StringComparison.InvariantCultureIgnoreCase)) { + continue; + } + + if (ImGui.Selectable(word, x == (-1, wordIdx))) { x = (-1, wordIdx); } } - - ImGui.EndCombo(); } - void DrawWordPicker(string id, IReadOnlyList words, ref (int, int) x) { + void DrawWordPicker(string id, IReadOnlyList words, ref (int, int) x, ref string search) { var preview = x == (-1, -1) ? "" : words[x.Item1].Words[x.Item2]; if (!ImGui.BeginCombo(id, preview)) { return; @@ -196,8 +206,15 @@ internal class Write : ITab { using var endMenu = new OnDispose(ImGui.EndMenu); + ImGui.InputText("###word-search", ref search, 100); + for (var wordIdx = 0; wordIdx < list.Words.Length; wordIdx++) { - if (ImGui.MenuItem(list.Words[wordIdx])) { + var word = list.Words[wordIdx]; + if (!string.IsNullOrEmpty(search) && !word.Contains(search, StringComparison.InvariantCultureIgnoreCase)) { + continue; + } + + if (ImGui.MenuItem(word)) { x = (listIdx, wordIdx); } } @@ -265,9 +282,9 @@ internal class Write : ITab { DrawTemplatePicker("Template##part-1", templateStrings, ref this._part1, ref this._word1); if (this.Template1 is { } template1 && template1.Text.Contains("{0}")) { if (template1.Words == null && pack.Words != null) { - DrawWordPicker("Word##word-1", pack.Words, ref this._word1); + DrawWordPicker("Word##word-1", pack.Words, ref this._word1, ref this._word1Search); } else if (template1.Words != null) { - DrawSpecificWordPicker("Word##word-1", template1, ref this._word1); + DrawSpecificWordPicker("Word##word-1", template1, ref this._word1, ref this._word1Search); } } @@ -279,9 +296,9 @@ internal class Write : ITab { DrawTemplatePicker("Template##part-2", templateStrings, ref this._part2, ref this._word2); if (this.Template1 is { } template2 && template2.Text.Contains("{0}")) { if (template2.Words == null && pack.Words != null) { - DrawWordPicker("Word##word-2", pack.Words, ref this._word2); + DrawWordPicker("Word##word-2", pack.Words, ref this._word2, ref this._word2Search); } else if (template2.Words != null) { - DrawSpecificWordPicker("Word##word-2", template2, ref this._word2); + DrawSpecificWordPicker("Word##word-2", template2, ref this._word2, ref this._word2Search); } } } @@ -336,16 +353,15 @@ internal class Write : ITab { for (var i = 0; i < this.Emotes.Count; i++) { var emote = this.Emotes[i]; + var name = emote.Name.ToDalamudString().TextValue; if (!string.IsNullOrEmpty(this._emoteSearch)) { - if (!emote.Name.ToDalamudString().TextValue.Contains(this._emoteSearch, StringComparison.InvariantCultureIgnoreCase)) { + if (!name.Contains(this._emoteSearch, StringComparison.InvariantCultureIgnoreCase)) { if (!emote.TextCommand.Value!.Command.ToDalamudString().TextValue.Contains(this._emoteSearch, StringComparison.InvariantCultureIgnoreCase)) { continue; } } } - var name = emote.Name.ToDalamudString().TextValue; - var unlocked = IsEmoteUnlocked(emote); if (!unlocked) { ImGui.BeginDisabled(); @@ -451,7 +467,6 @@ internal class Write : ITab { Variant = equip.Variant, Stain0 = equip.Stain0, Stain1 = equip.Stain1, - Value = equip.Value, }) .ToArray(), Weapon = chara->DrawData.WeaponData @@ -463,7 +478,6 @@ internal class Write : ITab { Variant = weapon.ModelId.Variant, Stain0 = weapon.ModelId.Stain0, Stain1 = weapon.ModelId.Stain1, - Value = weapon.ModelId.Value, }, Flags1 = weapon.Flags1, Flags2 = weapon.Flags2, @@ -488,6 +502,8 @@ internal class Write : ITab { this._glyph = this.Plugin.Config.DefaultGlyph; this._emoteIdx = -1; this._emoteSearch = string.Empty; + this._word1Search = string.Empty; + this._word2Search = string.Empty; } private void ClearIfNecessary() { diff --git a/server/src/main.rs b/server/src/main.rs index ebfd3cf..4ccd7f6 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -112,7 +112,6 @@ async fn main() -> Result<()> { spawn_command_reader(Arc::clone(&state), Handle::current()); - let address = state.config.address.clone(); let server = warp::serve(web::routes(state)); println!("listening at {address}"); diff --git a/server/src/message.rs b/server/src/message.rs index 434d610..d3e2e14 100644 --- a/server/src/message.rs +++ b/server/src/message.rs @@ -106,8 +106,8 @@ pub struct OwnMessage { pub struct EmoteData { pub id: u32, pub customise: Vec, - pub equipment_data: Vec, - pub weapon_data: Vec, + pub equipment: Vec, + pub weapon: Vec, pub glasses: u32, pub hat_hidden: bool, pub visor_toggled: bool, @@ -120,7 +120,6 @@ pub struct EquipmentData { pub variant: u8, pub stain_0: u8, pub stain_1: u8, - pub value: u64, } #[derive(Debug, Deserialize, Serialize)] @@ -138,5 +137,4 @@ pub struct WeaponModelId { pub variant: u16, pub stain_0: u8, pub stain_1: u8, - pub value: u64, } diff --git a/server/src/web/write.rs b/server/src/web/write.rs index 338de94..0b148f3 100644 --- a/server/src/web/write.rs +++ b/server/src/web/write.rs @@ -15,7 +15,7 @@ pub fn write(state: Arc) -> BoxedFilter<(impl Reply, )> { .and(warp::path("messages")) .and(warp::path::end()) .and(super::get_id(Arc::clone(&state))) - .and(warp::body::content_length_limit(1024)) + .and(warp::body::content_length_limit(8192)) .and(warp::body::json()) .and_then(move |(id, extra), message: Message| logic(Arc::clone(&state), id, extra, message)) .boxed()