Save queue as/load queue from presets

master v4.0
Liza 2024-01-19 09:41:04 +01:00
parent aa635c8620
commit 2b5fb62842
Signed by: liza
GPG Key ID: 7199F8D727D55F67
3 changed files with 207 additions and 60 deletions

View File

@ -14,6 +14,7 @@ internal sealed class Configuration : IPluginConfiguration
public List<QueuedItem> ItemQueue { get; set; } = new(); public List<QueuedItem> ItemQueue { get; set; } = new();
public bool EnableRepairKitCalculator { get; set; } = true; public bool EnableRepairKitCalculator { get; set; } = true;
public bool EnableCeruleumTankCalculator { get; set; } = true; public bool EnableCeruleumTankCalculator { get; set; } = true;
public List<Preset> Presets { get; set; } = new();
internal sealed class QueuedItem internal sealed class QueuedItem
{ {
@ -76,4 +77,11 @@ internal sealed class Configuration : IPluginConfiguration
public uint ItemId { get; set; } public uint ItemId { get; set; }
public uint QuantityComplete { get; set; } public uint QuantityComplete { get; set; }
} }
internal sealed class Preset
{
public required Guid Id { get; set; }
public required string Name { get; set; }
public List<QueuedItem> ItemQueue { get; set; } = new();
}
} }

View File

@ -34,6 +34,7 @@ internal sealed class MainWindow : LImGui.LWindow
private string _searchString = string.Empty; private string _searchString = string.Empty;
private bool _checkInventory; private bool _checkInventory;
private string _newPresetName = string.Empty;
public MainWindow(WorkshopPlugin plugin, DalamudPluginInterface pluginInterface, IClientState clientState, public MainWindow(WorkshopPlugin plugin, DalamudPluginInterface pluginInterface, IClientState clientState,
Configuration configuration, WorkshopCache workshopCache, IconCache iconCache, IChatGui chatGui, Configuration configuration, WorkshopCache workshopCache, IconCache iconCache, IChatGui chatGui,
@ -58,7 +59,7 @@ internal sealed class MainWindow : LImGui.LWindow
MaximumSize = new Vector2(500, 9999), MaximumSize = new Vector2(500, 9999),
}; };
Flags = ImGuiWindowFlags.AlwaysAutoResize | ImGuiWindowFlags.NoCollapse; Flags = ImGuiWindowFlags.AlwaysAutoResize | ImGuiWindowFlags.NoCollapse | ImGuiWindowFlags.MenuBar;
AllowClickthrough = false; AllowClickthrough = false;
} }
@ -71,6 +72,16 @@ internal sealed class MainWindow : LImGui.LWindow
public override void Draw() public override void Draw()
{ {
if (ImGui.BeginMenuBar())
{
ImGui.BeginDisabled(_plugin.CurrentStage != Stage.Stopped);
DrawPresetsMenu();
DrawClipboardMenu();
ImGui.EndDisabled();
ImGui.EndMenuBar();
}
var currentItem = _configuration.CurrentlyCraftedItem; var currentItem = _configuration.CurrentlyCraftedItem;
if (currentItem != null) if (currentItem != null)
{ {
@ -244,36 +255,137 @@ internal sealed class MainWindow : LImGui.LWindow
ImGui.EndCombo(); ImGui.EndCombo();
} }
DrawImportExport();
ImGui.EndDisabled(); ImGui.EndDisabled();
ImGui.Separator(); ImGui.Separator();
ImGui.Text($"Debug (Stage): {_plugin.CurrentStage}"); ImGui.Text($"Debug (Stage): {_plugin.CurrentStage}");
} }
private void DrawImportExport() private void DrawPresetsMenu()
{ {
ImGui.BeginDisabled(_configuration.ItemQueue.Count == 0); if (ImGui.BeginMenu("Presets"))
if (ImGuiComponents.IconButtonWithText(FontAwesomeIcon.Upload, "Export to Clipboard"))
{ {
var toClipboardItems = _configuration.ItemQueue.Select(x => new ClipboardItem if (_configuration.Presets.Count == 0)
{
ImGui.BeginDisabled();
ImGui.MenuItem("Import Queue from Preset");
ImGui.EndDisabled();
}
else if (ImGui.BeginMenu("Import Queue from Preset"))
{
if (_configuration.Presets.Count == 0)
ImGui.MenuItem("You have no presets.");
foreach (var preset in _configuration.Presets)
{
ImGui.PushID($"Preset{preset.Id}");
if (ImGui.MenuItem(preset.Name))
{
foreach (var item in preset.ItemQueue)
{
var queuedItem =
_configuration.ItemQueue.FirstOrDefault(x => x.WorkshopItemId == item.WorkshopItemId);
if (queuedItem != null)
queuedItem.Quantity += item.Quantity;
else
{
_configuration.ItemQueue.Add(new Configuration.QueuedItem
{
WorkshopItemId = item.WorkshopItemId,
Quantity = item.Quantity,
});
}
}
Save();
_chatGui.Print($"Imported {preset.ItemQueue.Count} items from preset.");
}
ImGui.PopID();
}
ImGui.EndMenu();
}
if (_configuration.ItemQueue.Count == 0)
{
ImGui.BeginDisabled();
ImGui.MenuItem("Export Queue to Preset");
ImGui.EndDisabled();
}
else if (ImGui.BeginMenu("Export Queue to Preset"))
{
ImGui.InputTextWithHint("", "Preset Name...", ref _newPresetName, 64);
ImGui.BeginDisabled(_configuration.Presets.Any(x =>
x.Name.Equals(_newPresetName, StringComparison.CurrentCultureIgnoreCase)));
if (ImGuiComponents.IconButtonWithText(FontAwesomeIcon.Save, "Save"))
{
_configuration.Presets.Add(new Configuration.Preset
{
Id = Guid.NewGuid(),
Name = _newPresetName,
ItemQueue = _configuration.ItemQueue.Select(x => new Configuration.QueuedItem
{ {
WorkshopItemId = x.WorkshopItemId, WorkshopItemId = x.WorkshopItemId,
Quantity = x.Quantity Quantity = x.Quantity
}) }).ToList()
.ToList(); });
var clipboardText = Save();
Convert.ToBase64String(Encoding.UTF8.GetBytes(JsonPrefix + JsonSerializer.Serialize(toClipboardItems))); _chatGui.Print($"Saved queue as preset '{_newPresetName}'.");
ImGui.SetClipboardText(clipboardText);
_chatGui.Print("Copied queue content to clipboard."); _newPresetName = string.Empty;
} }
ImGui.EndDisabled(); ImGui.EndDisabled();
ImGui.SameLine(); ImGui.EndMenu();
}
if (_configuration.Presets.Count == 0)
{
ImGui.BeginDisabled();
ImGui.MenuItem("Delete Preset");
ImGui.EndDisabled();
}
else if (ImGui.BeginMenu("Delete Preset"))
{
if (_configuration.Presets.Count == 0)
ImGui.MenuItem("You have no presets.");
Guid? presetToRemove = null;
foreach (var preset in _configuration.Presets)
{
ImGui.PushID($"Preset{preset.Id}");
if (ImGui.MenuItem(preset.Name))
{
presetToRemove = preset.Id;
}
ImGui.PopID();
}
if (presetToRemove != null)
{
var preset = _configuration.Presets.First(x => x.Id == presetToRemove);
_configuration.Presets.Remove(preset);
Save();
_chatGui.Print($"Deleted preset '{preset.Name}'.");
}
ImGui.EndMenu();
}
ImGui.EndMenu();
}
}
private void DrawClipboardMenu()
{
if (ImGui.BeginMenu("Clipboard"))
{
List<ClipboardItem> fromClipboardItems = new(); List<ClipboardItem> fromClipboardItems = new();
try try
{ {
@ -294,9 +406,10 @@ internal sealed class MainWindow : LImGui.LWindow
} }
ImGui.BeginDisabled(fromClipboardItems.Count == 0); ImGui.BeginDisabled(fromClipboardItems.Count == 0);
if (ImGuiComponents.IconButtonWithText(FontAwesomeIcon.Download, "Import from Clipboard")) if (ImGui.MenuItem("Import Queue from Clipboard"))
{ {
_pluginLog.Information($"Importing {fromClipboardItems.Count} items"); _pluginLog.Information($"Importing {fromClipboardItems.Count} items...");
int count = 0;
foreach (var item in fromClipboardItems) foreach (var item in fromClipboardItems)
{ {
var craft = _workshopCache.Crafts.FirstOrDefault(x => x.WorkshopItemId == item.WorkshopItemId); var craft = _workshopCache.Crafts.FirstOrDefault(x => x.WorkshopItemId == item.WorkshopItemId);
@ -314,13 +427,39 @@ internal sealed class MainWindow : LImGui.LWindow
Quantity = item.Quantity, Quantity = item.Quantity,
}); });
} }
++count;
} }
} }
Save(); Save();
_chatGui.Print($"Imported {count} items from clipboard.");
} }
ImGui.EndDisabled(); ImGui.EndDisabled();
ImGui.BeginDisabled(_configuration.ItemQueue.Count == 0);
if (ImGui.MenuItem("Export Queue to Clipboard"))
{
var toClipboardItems = _configuration.ItemQueue.Select(x => new ClipboardItem
{
WorkshopItemId = x.WorkshopItemId,
Quantity = x.Quantity
})
.ToList();
var clipboardText =
Convert.ToBase64String(
Encoding.UTF8.GetBytes(JsonPrefix + JsonSerializer.Serialize(toClipboardItems)));
ImGui.SetClipboardText(clipboardText);
_chatGui.Print("Copied queue content to clipboard.");
}
ImGui.EndDisabled();
ImGui.EndMenu();
}
} }
/// <summary> /// <summary>

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>net7.0-windows</TargetFramework> <TargetFramework>net7.0-windows</TargetFramework>
<Version>3.8</Version> <Version>4.0</Version>
<LangVersion>11.0</LangVersion> <LangVersion>11.0</LangVersion>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies> <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>