From 309f07c3e9c20a4c9f52fb1146647834c8022dea Mon Sep 17 00:00:00 2001 From: Liza Carvelli Date: Mon, 30 Oct 2023 01:44:42 +0100 Subject: [PATCH] Show errors if turn-in isn't possible (instead of only printing to log) --- Workshoppa/Windows/MainWindow.cs | 16 ++++++++++------ Workshoppa/WorkshopPlugin.Craft.cs | 17 +++++++++++++++++ Workshoppa/WorkshopPlugin.cs | 4 +++- Workshoppa/Workshoppa.csproj | 2 +- 4 files changed, 31 insertions(+), 8 deletions(-) diff --git a/Workshoppa/Windows/MainWindow.cs b/Workshoppa/Windows/MainWindow.cs index ac63e3c..d089328 100644 --- a/Workshoppa/Windows/MainWindow.cs +++ b/Workshoppa/Windows/MainWindow.cs @@ -27,7 +27,8 @@ internal sealed class MainWindow : Window private string _searchString = string.Empty; private bool _checkInventory; - public MainWindow(WorkshopPlugin plugin, DalamudPluginInterface pluginInterface, IClientState clientState, Configuration configuration, WorkshopCache workshopCache) + public MainWindow(WorkshopPlugin plugin, DalamudPluginInterface pluginInterface, IClientState clientState, + Configuration configuration, WorkshopCache workshopCache) : base("Workshoppa###WorkshoppaMainWindow") { _plugin = plugin; @@ -42,7 +43,7 @@ internal sealed class MainWindow : Window SizeConstraints = new WindowSizeConstraints { MinimumSize = new Vector2(350, 50), - MaximumSize = new Vector2(500, 500), + MaximumSize = new Vector2(500, 9999), }; Flags = ImGuiWindowFlags.AlwaysAutoResize | ImGuiWindowFlags.NoCollapse; @@ -52,7 +53,7 @@ internal sealed class MainWindow : Window public bool NearFabricationStation { get; set; } public ButtonState State { get; set; } = ButtonState.None; - public bool IsDiscipleOfHand => + private bool IsDiscipleOfHand => _clientState.LocalPlayer != null && _clientState.LocalPlayer.ClassJob.Id is >= 8 and <= 15; public override void Draw() @@ -89,6 +90,7 @@ internal sealed class MainWindow : Window _checkInventory = false; } } + ImGui.EndDisabled(); ImGui.SameLine(); @@ -100,6 +102,7 @@ internal sealed class MainWindow : Window Save(); } + ImGui.EndDisabled(); if (ImGui.IsItemHovered(ImGuiHoveredFlags.AllowWhenDisabled) && !ImGui.GetIO().KeyCtrl) ImGui.SetTooltip( @@ -125,7 +128,8 @@ internal sealed class MainWindow : Window _checkInventory = !_checkInventory; ImGui.SameLine(); - ImGui.BeginDisabled(!NearFabricationStation || _configuration.ItemQueue.Sum(x => x.Quantity) == 0 || _plugin.CurrentStage != Stage.Stopped || !IsDiscipleOfHand); + ImGui.BeginDisabled(!NearFabricationStation || _configuration.ItemQueue.Sum(x => x.Quantity) == 0 || + _plugin.CurrentStage != Stage.Stopped || !IsDiscipleOfHand); if (ImGuiComponents.IconButtonWithText(FontAwesomeIcon.Play, "Start Crafting")) { State = ButtonState.Start; @@ -147,7 +151,7 @@ internal sealed class MainWindow : Window ImGui.Text("Queue:"); ImGui.BeginDisabled(_plugin.CurrentStage != Stage.Stopped); Configuration.QueuedItem? itemToRemove = null; - for (int i = 0; i < _configuration.ItemQueue.Count; ++ i) + for (int i = 0; i < _configuration.ItemQueue.Count; ++i) { ImGui.PushID($"ItemQueue{i}"); var item = _configuration.ItemQueue[i]; @@ -202,6 +206,7 @@ internal sealed class MainWindow : Window ImGui.EndCombo(); } + ImGui.EndDisabled(); ImGui.Separator(); @@ -294,7 +299,6 @@ internal sealed class MainWindow : Window private void ShowErrorConditions() { - if (!_plugin.WorkshopTerritories.Contains(_clientState.TerritoryType)) ImGui.TextColored(ImGuiColors.DalamudRed, "You are not in the Company Workshop."); else if (!NearFabricationStation) diff --git a/Workshoppa/WorkshopPlugin.Craft.cs b/Workshoppa/WorkshopPlugin.Craft.cs index 69677fb..e174b4b 100644 --- a/Workshoppa/WorkshopPlugin.Craft.cs +++ b/Workshoppa/WorkshopPlugin.Craft.cs @@ -2,6 +2,7 @@ using System.Linq; using Dalamud.Game.Addon.Lifecycle; using Dalamud.Game.Addon.Lifecycle.AddonArgTypes; +using FFXIVClientStructs.FFXIV.Client.Game; using FFXIVClientStructs.FFXIV.Client.UI; using FFXIVClientStructs.FFXIV.Component.GUI; using Workshoppa.GameData; @@ -110,6 +111,22 @@ partial class WorkshopPlugin { _pluginLog.Error( $"Can't contribute item {item.ItemId} to craft, couldn't find {item.ItemCountPerStep}x in a single inventory slot"); + + InventoryManager* inventoryManager = InventoryManager.Instance(); + int itemCount = 0; + if (inventoryManager != null) + { + itemCount = inventoryManager->GetInventoryItemCount(item.ItemId, true, false, false) + + inventoryManager->GetInventoryItemCount(item.ItemId, false, false, false); + } + + if (itemCount < item.ItemCountPerStep) + _chatGui.PrintError( + $"[Workshoppa] You don't have the needed {item.ItemCountPerStep}x {item.ItemName} to continue."); + else + _chatGui.PrintError( + $"[Workshoppa] You don't have {item.ItemCountPerStep}x {item.ItemName} in a single stack, you need to merge the items in your inventory manually to continue."); + CurrentStage = Stage.RequestStop; break; } diff --git a/Workshoppa/WorkshopPlugin.cs b/Workshoppa/WorkshopPlugin.cs index 0b9a832..7495f26 100644 --- a/Workshoppa/WorkshopPlugin.cs +++ b/Workshoppa/WorkshopPlugin.cs @@ -30,6 +30,7 @@ public sealed partial class WorkshopPlugin : IDalamudPlugin private readonly ICommandManager _commandManager; private readonly IPluginLog _pluginLog; private readonly IAddonLifecycle _addonLifecycle; + private readonly IChatGui _chatGui; private readonly Configuration _configuration; private readonly ExternalPluginHandler _externalPluginHandler; @@ -47,7 +48,7 @@ public sealed partial class WorkshopPlugin : IDalamudPlugin public WorkshopPlugin(DalamudPluginInterface pluginInterface, IGameGui gameGui, IFramework framework, ICondition condition, IClientState clientState, IObjectTable objectTable, IDataManager dataManager, - ICommandManager commandManager, IPluginLog pluginLog, IAddonLifecycle addonLifecycle) + ICommandManager commandManager, IPluginLog pluginLog, IAddonLifecycle addonLifecycle, IChatGui chatGui) { _pluginInterface = pluginInterface; _gameGui = gameGui; @@ -58,6 +59,7 @@ public sealed partial class WorkshopPlugin : IDalamudPlugin _commandManager = commandManager; _pluginLog = pluginLog; _addonLifecycle = addonLifecycle; + _chatGui = chatGui; _externalPluginHandler = new ExternalPluginHandler(_pluginInterface, _framework, _pluginLog); _configuration = (Configuration?)_pluginInterface.GetPluginConfig() ?? new Configuration(); diff --git a/Workshoppa/Workshoppa.csproj b/Workshoppa/Workshoppa.csproj index 74dd627..6d2b1fb 100644 --- a/Workshoppa/Workshoppa.csproj +++ b/Workshoppa/Workshoppa.csproj @@ -1,7 +1,7 @@ net7.0-windows - 3.2 + 3.3 11.0 enable true