diff --git a/RebornToolbox/Features/MBShoppingList/MBShoppingList.UI.cs b/RebornToolbox/Features/MBShoppingList/MBShoppingList.UI.cs index 2d7c7d8..12df58f 100644 --- a/RebornToolbox/Features/MBShoppingList/MBShoppingList.UI.cs +++ b/RebornToolbox/Features/MBShoppingList/MBShoppingList.UI.cs @@ -42,20 +42,32 @@ public MBShoppingList_UI(MBShoppingList manager) : base("Supermarket Sweep", ImG public override void Draw() { DrawItemAdd(); - ImGui.SameLine(); if (ImGui.Button("Import MakePlace List")) { SelectFile(); } + ImGui.SameLine(); + if (ImGui.Button("Import from Clipboard")) + { + ExtractClipboardText(); + } + ImGuiEx.Tooltip("Import items from clipboard using the following format:\n'10x Ipe Log'\n'999x Iron Ore"); - RenderRegionTypeComboBox(); - var maxResults = Plugin.Configuration.ShoppingListConfig.MaxResults; + if (ImGuiUtil.GenericEnumCombo("Region/Datacenter", 300, Plugin.Configuration.ShoppingListConfig.ShoppingRegion, out RegionType newRegion, r => r.ToFriendlyString())) + { + Plugin.Configuration.ShoppingListConfig.ShoppingRegion = newRegion; + Plugin.Configuration.SaveConfig(); + } + + ImGui.SetNextItemWidth(100); + int maxResults = Plugin.Configuration.ShoppingListConfig.MaxResults; if (ImGui.InputInt("Max Search Results", ref maxResults)) { Plugin.Configuration.ShoppingListConfig.MaxResults = maxResults; Plugin.Configuration.SaveConfig(); } + if (Plugin.Configuration.ExpertMode) { if (ImGuiUtil.DrawDisabledButton("Refresh All Market Data", new Vector2(0, 0), @@ -84,6 +96,56 @@ public override void Draw() _fileDialogManager.Draw(); } + private void ExtractClipboardText() + { + var clipboardText = ImGuiUtil.GetClipboardText(); + if (!string.IsNullOrEmpty(clipboardText)) + { + try + { + Dictionary items = new Dictionary(); + + // Regex pattern + var pattern = @"\b(\d+)x\s(.+)\b"; + var matches = Regex.Matches(clipboardText, pattern); + + // Loop through matches and add them to dictionary + foreach (Match match in matches) + { + var quantity = int.Parse(match.Groups[1].Value); + var itemName = match.Groups[2].Value; + items[itemName] = quantity; + } + + bool saveNeeded = false; + foreach (var item in items) + { + var itemObj = MBShoppingList.AllItems.FirstOrDefault(i => string.Equals(i.Name, item.Key, StringComparison.OrdinalIgnoreCase)); + if (itemObj is null) + { + Svc.Log.Error($"Item {item.Key} not found"); + continue; + } + + var shoppingListItem = new ShoppingListItem(itemObj, item.Value); + _manager.WantedItems.Add(shoppingListItem); + saveNeeded = true; + } + if (saveNeeded) + _manager.SaveList(); + } + catch (Exception e) + { + Svc.Chat.PrintError("[Reborn Toolbox] Error importing clipboard text. See /xllog for details."); + Svc.Log.Error($"Error importing from clipboard: {e}"); + } + } + else + { + Svc.Chat.PrintError($"Clipboard text is empty or invalid"); + } + } + private DateTime _lastMassRefresh = DateTime.MinValue; private void DrawWantedItem(ShoppingListItem? item) @@ -101,6 +163,7 @@ private void DrawWantedItem(ShoppingListItem? item) var seString = new SeStringBuilder().AddText($"[Reborn Toolbox]").AddItemLink(item.ItemId).BuiltString; Svc.Chat.Print(seString); } + ImGuiEx.Tooltip("Click to print item link in chat"); @@ -115,7 +178,8 @@ private void DrawWantedItem(ShoppingListItem? item) ImGui.PopItemWidth(); ImGui.Text($"Already Owned: {item.InventoryCount}"); - ImGuiEx.Tooltip("Amount of this item you have across all characters (including retainers and alts)\nSourced from Allagan Tools\nSee Allagan Tools for detailed information"); + ImGuiEx.Tooltip( + "Amount of this item you have across all characters (including retainers and alts)\nSourced from Allagan Tools\nSee Allagan Tools for detailed information"); string buttonLabel; string buttonDescription; @@ -183,7 +247,9 @@ private void DrawRow(ShoppingListItem.WorldListing obj) Svc.Chat.PrintError($"[Reborn Toolbox] LifeStream is required to move between servers"); return; } - _manager.TaskManager.Enqueue(() => Lifestream_IPCSubscriber.ExecuteCommand(obj.WorldName), _manager.LifeStreamTaskConfig); + + _manager.TaskManager.Enqueue(() => Lifestream_IPCSubscriber.ExecuteCommand(obj.WorldName), + _manager.LifeStreamTaskConfig); _manager.TaskManager.Enqueue(() => !Lifestream_IPCSubscriber.IsBusy(), _manager.LifeStreamTaskConfig); _manager.TaskManager.Enqueue(GenericHelpers.IsScreenReady); _manager.TaskManager.Enqueue(_manager.QueueMoveToMarketboardTasks); @@ -200,8 +266,11 @@ private unsafe void DrawItemSearch(ShoppingListItem item) { AddonItemSearch* addonItemSearch = (AddonItemSearch*)Svc.GameGui.GetAddonByName("ItemSearch"); var disabled = addonItemSearch == null; - var description = disabled ? "Automatically search for this item on the Marketboard (MarketBoard window must be open)" : "Automatically search for this item on the Marketboard"; - if (ImGuiUtil.DrawDisabledButton($"Search Marketboard for Item##{item.ItemId}", new Vector2(), description, disabled)) + var description = disabled + ? "Automatically search for this item on the Marketboard (MarketBoard window must be open)" + : "Automatically search for this item on the Marketboard"; + if (ImGuiUtil.DrawDisabledButton($"Search Marketboard for Item##{item.ItemId}", new Vector2(), description, + disabled)) { addonItemSearch->SearchTextInput->SetText(item.Name); addonItemSearch->RunSearch(); @@ -280,20 +349,6 @@ private void DrawItemAdd() } } - private static readonly string[] RegionNames = ["North America", "Europe", "Japan", "Oceania"]; - - public void RenderRegionTypeComboBox() - { - int currentRegionIndex = (int)Plugin.Configuration.ShoppingListConfig.ShoppingRegion; - - if (ImGui.Combo("Select Region", ref currentRegionIndex, RegionNames, RegionNames.Length)) - { - Plugin.Configuration.ShoppingListConfig.ShoppingRegion = (RegionType)currentRegionIndex; - - Plugin.Configuration.SaveConfig(); - } - } - private unsafe void DrawMBButton(ShoppingListItem item) { var mbAddon = (AddonItemSearch*)Svc.GameGui.GetAddonByName("ItemSearch"); diff --git a/RebornToolbox/Features/MBShoppingList/Models/RegionType.cs b/RebornToolbox/Features/MBShoppingList/Models/RegionType.cs index 0a84398..ae3b6be 100644 --- a/RebornToolbox/Features/MBShoppingList/Models/RegionType.cs +++ b/RebornToolbox/Features/MBShoppingList/Models/RegionType.cs @@ -6,6 +6,17 @@ public enum RegionType Europe = 1, Japan = 2, Oceania = 3, + Aether = 4, + Crystal = 5, + Dynamis = 6, + Primal = 7, + Chaos = 8, + Light = 9, + Elemental = 10, + Gaia = 11, + Mana = 12, + Meteor = 13, + Materia = 14 } public static class RegionTypeExtensions @@ -23,24 +34,18 @@ public static string ToUniversalisString(this RegionType regionType) case RegionType.Oceania: return "oceania"; default: - return "north-america"; + return regionType.ToString().ToLower(); } } - public static RegionType ToRegionType(this string regionType) + public static string ToFriendlyString(this RegionType regionType) { switch (regionType) { - case "north-america": - return RegionType.NorthAmerica; - case "europe": - return RegionType.Europe; - case "japan": - return RegionType.Japan; - case "oceania": - return RegionType.Oceania; + case RegionType.NorthAmerica: + return "North America"; default: - return RegionType.NorthAmerica; + return regionType.ToString(); } } } \ No newline at end of file