forked from aly/qstbak
muffin v7.5.12
This commit is contained in:
parent
3102923ce2
commit
911ed68baa
65 changed files with 2356 additions and 1539 deletions
|
|
@ -2,12 +2,15 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using System.Text;
|
||||
using Dalamud.Bindings.ImGui;
|
||||
using Dalamud.Interface;
|
||||
using Dalamud.Interface.Components;
|
||||
using Dalamud.Interface.Utility.Raii;
|
||||
using Dalamud.Plugin;
|
||||
using Dalamud.Plugin.Services;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Newtonsoft.Json;
|
||||
using Questionable.Controller;
|
||||
using Questionable.Controller.Conditions;
|
||||
using Questionable.Data;
|
||||
|
|
@ -21,6 +24,8 @@ namespace Questionable.Windows.ConfigComponents;
|
|||
|
||||
internal sealed class StopConditionComponent : ConfigComponent
|
||||
{
|
||||
private const string ClipboardPrefix = "qst:stop:";
|
||||
|
||||
private static readonly string[] ConditionModeNames = new string[2] { "Pause", "Stop" };
|
||||
|
||||
private static readonly string[] ConditionTypeNames = new string[7] { "Quest Complete", "Quest Accept", "Level", "Global Sequence", "Inventory Full", "Before Duty", "Gil Threshold" };
|
||||
|
|
@ -59,6 +64,8 @@ internal sealed class StopConditionComponent : ConfigComponent
|
|||
|
||||
private long _acceptedQuestsRefreshAtMs;
|
||||
|
||||
private StopCondition? _draggedCondition;
|
||||
|
||||
public StopConditionComponent(IDalamudPluginInterface pluginInterface, QuestSelector questSelector, QuestFunctions questFunctions, QuestRegistry questRegistry, QuestData questData, QuestTooltipComponent questTooltipComponent, UiUtils uiUtils, IObjectTable objectTable, QuestController questController, Configuration configuration, ILogger<StopConditionComponent> logger)
|
||||
: base(pluginInterface, configuration)
|
||||
{
|
||||
|
|
@ -131,31 +138,120 @@ internal sealed class StopConditionComponent : ConfigComponent
|
|||
private void DrawConditionsList()
|
||||
{
|
||||
List<StopCondition> conditions = base.Configuration.Stop.Conditions;
|
||||
DrawClipboardButtons(conditions);
|
||||
if (conditions.Count == 0)
|
||||
{
|
||||
ImGui.TextDisabled("No conditions configured.");
|
||||
return;
|
||||
}
|
||||
ImGui.SameLine();
|
||||
if (UiThemeUtils.DestructiveButton(FontAwesomeIcon.Trash, "Clear all"))
|
||||
{
|
||||
conditions.Clear();
|
||||
Save();
|
||||
}
|
||||
int? indexToRemove = null;
|
||||
StopCondition stopCondition = null;
|
||||
int index = 0;
|
||||
float x = ImGui.GetContentRegionAvail().X;
|
||||
List<(Vector2, Vector2)> list = new List<(Vector2, Vector2)>();
|
||||
for (int i = 0; i < conditions.Count; i++)
|
||||
{
|
||||
Vector2 item = ImGui.GetCursorScreenPos() + new Vector2(0f, (0f - ImGui.GetStyle().ItemSpacing.Y) / 2f);
|
||||
using (ImRaii.PushId(i))
|
||||
{
|
||||
StopCondition condition = conditions[i];
|
||||
DrawConditionRow(condition, i, ref indexToRemove);
|
||||
StopCondition stopCondition2 = conditions[i];
|
||||
if (conditions.Count > 1)
|
||||
{
|
||||
ImGuiComponents.IconButton("##Move", FontAwesomeIcon.Bars);
|
||||
if (_draggedCondition == null && ImGui.IsItemActive() && ImGui.IsMouseDragging(ImGuiMouseButton.Left))
|
||||
{
|
||||
_draggedCondition = stopCondition2;
|
||||
}
|
||||
if (ImGui.IsItemHovered())
|
||||
{
|
||||
ImGui.SetTooltip("Drag to reorder");
|
||||
}
|
||||
ImGui.SameLine();
|
||||
}
|
||||
DrawConditionRow(stopCondition2, i, ref indexToRemove);
|
||||
Vector2 item2 = new Vector2(item.X + x, ImGui.GetCursorScreenPos().Y - ImGui.GetStyle().ItemSpacing.Y + 2f);
|
||||
list.Add((item, item2));
|
||||
}
|
||||
}
|
||||
if (!ImGui.IsMouseDragging(ImGuiMouseButton.Left))
|
||||
{
|
||||
_draggedCondition = null;
|
||||
}
|
||||
else if (_draggedCondition != null)
|
||||
{
|
||||
int num = conditions.IndexOf(_draggedCondition);
|
||||
if (num >= 0)
|
||||
{
|
||||
var (pMin, pMax) = list[num];
|
||||
ImGui.GetWindowDrawList().AddRect(pMin, pMax, ImGui.ColorConvertFloat4ToU32(UiThemeUtils.CardBorderHighColor), 3f, ImDrawFlags.RoundCornersAll);
|
||||
int num2 = list.FindIndex(((Vector2 TopLeft, Vector2 BottomRight) tuple2) => ImGui.IsMouseHoveringRect(tuple2.TopLeft, tuple2.BottomRight, clip: true));
|
||||
if (num2 >= 0 && num != num2)
|
||||
{
|
||||
stopCondition = _draggedCondition;
|
||||
index = num2;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (indexToRemove.HasValue)
|
||||
{
|
||||
int valueOrDefault = indexToRemove.GetValueOrDefault();
|
||||
conditions.RemoveAt(valueOrDefault);
|
||||
_draggedCondition = null;
|
||||
Save();
|
||||
}
|
||||
else if (stopCondition != null)
|
||||
{
|
||||
conditions.Remove(stopCondition);
|
||||
conditions.Insert(index, stopCondition);
|
||||
Save();
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawClipboardButtons(List<StopCondition> conditions)
|
||||
{
|
||||
using (ImRaii.Disabled(conditions.Count == 0))
|
||||
{
|
||||
if (UiThemeUtils.IconTextButton(FontAwesomeIcon.Copy, "Copy"))
|
||||
{
|
||||
string s = JsonConvert.SerializeObject(conditions);
|
||||
ImGui.SetClipboardText("qst:stop:" + Convert.ToBase64String(Encoding.UTF8.GetBytes(s)));
|
||||
}
|
||||
}
|
||||
ImGui.SameLine();
|
||||
string text = ThrottledClipboard.GetText();
|
||||
using (ImRaii.Disabled(!text.StartsWith("qst:stop:", StringComparison.InvariantCulture)))
|
||||
{
|
||||
if (UiThemeUtils.IconTextButton(FontAwesomeIcon.Paste, "Paste"))
|
||||
{
|
||||
ImportConditions(text);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ImportConditions(string clipboardText)
|
||||
{
|
||||
try
|
||||
{
|
||||
string s = clipboardText.Substring("qst:stop:".Length);
|
||||
List<StopCondition> list = JsonConvert.DeserializeObject<List<StopCondition>>(Encoding.UTF8.GetString(Convert.FromBase64String(s))) ?? new List<StopCondition>();
|
||||
list.RemoveAll((StopCondition x) => x?.IsSession ?? true);
|
||||
if (list.Count != 0)
|
||||
{
|
||||
base.Configuration.Stop.Conditions.Clear();
|
||||
base.Configuration.Stop.Conditions.AddRange(list);
|
||||
Save();
|
||||
}
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
_logger.LogDebug(exception, "Failed to import stop conditions from clipboard");
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawConditionRow(StopCondition condition, int index, ref int? indexToRemove)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue