fix: clean up the new swap system
This commit is contained in:
parent
315f617ead
commit
803938564a
|
@ -21,6 +21,7 @@ namespace HudSwap {
|
|||
|
||||
public HudSlot StagingSlot { get; set; } = HudSlot.Four;
|
||||
|
||||
[Obsolete("Superceded by HudConditionMatches")]
|
||||
public Guid DefaultLayout { get; set; } = Guid.Empty;
|
||||
|
||||
#pragma warning disable CA1051 // Do not declare visible instance fields
|
||||
|
@ -111,24 +112,29 @@ namespace HudSwap {
|
|||
}
|
||||
|
||||
if (this.JobLayouts.Count != 0) {
|
||||
foreach (var jobLayout in this.JobLayouts)
|
||||
foreach (var jobLayout in this.JobLayouts) {
|
||||
this.HudConditionMatches.Add(new HudConditionMatch() {
|
||||
ClassJob = jobLayout.Key,
|
||||
Status = JobsCombatOnly ? Status.InCombat : default,
|
||||
LayoutId = jobLayout.Value
|
||||
});
|
||||
}
|
||||
|
||||
this.JobLayouts.Clear();
|
||||
}
|
||||
|
||||
if (this.StatusLayouts.Count != 0) {
|
||||
foreach (var statusLayout in this.StatusLayouts) {
|
||||
var match = new HudConditionMatch() {Status = statusLayout.Key, LayoutId = statusLayout.Value};
|
||||
if (HighPriorityJobs)
|
||||
var match = new HudConditionMatch() {
|
||||
Status = statusLayout.Key,
|
||||
LayoutId = statusLayout.Value
|
||||
};
|
||||
if (this.HighPriorityJobs) {
|
||||
this.HudConditionMatches.Add(match);
|
||||
else
|
||||
} else {
|
||||
this.HudConditionMatches.Insert(0, match);
|
||||
}
|
||||
}
|
||||
|
||||
this.StatusLayouts.Clear();
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using Dalamud.Game.ClientState.Actors.Types;
|
||||
using Dalamud.Interface;
|
||||
using Dalamud.Plugin;
|
||||
using ImGuiNET;
|
||||
using Lumina.Excel.GeneratedSheets;
|
||||
|
@ -42,6 +43,7 @@ namespace HudSwap {
|
|||
|
||||
private int editingConditionIndex = -1;
|
||||
private HudConditionMatch editingCondition;
|
||||
private bool scrollToAdd = false;
|
||||
|
||||
private static bool configErrorOpen = true;
|
||||
public static void ConfigError() {
|
||||
|
@ -59,9 +61,12 @@ namespace HudSwap {
|
|||
return;
|
||||
}
|
||||
|
||||
PlayerCharacter player = this.pi.ClientState.LocalPlayer;
|
||||
ImGui.SetNextWindowSize(new Vector2(500, 450), ImGuiCond.FirstUseEver);
|
||||
|
||||
if (!ImGui.Begin(this.plugin.Name, ref this._settingsVisible)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (ImGui.Begin("HudSwap", ref this._settingsVisible, ImGuiWindowFlags.AlwaysAutoResize)) {
|
||||
if (ImGui.BeginTabBar("##hudswap-tabs")) {
|
||||
if (!this.plugin.Config.UnderstandsRisks) {
|
||||
if (ImGui.BeginTabItem("About")) {
|
||||
|
@ -99,6 +104,7 @@ namespace HudSwap {
|
|||
if (this.plugin.Config.Layouts2.Count == 0) {
|
||||
ImGui.Text("None saved!");
|
||||
} else {
|
||||
ImGui.PushItemWidth(-1);
|
||||
if (ImGui.ListBoxHeader("##saved-layouts")) {
|
||||
foreach (KeyValuePair<Guid, Layout> entry in this.plugin.Config.Layouts2) {
|
||||
if (ImGui.Selectable($"{entry.Value.Name}##{entry.Key}", this.selectedLayout == entry.Key)) {
|
||||
|
@ -108,6 +114,7 @@ namespace HudSwap {
|
|||
}
|
||||
ImGui.ListBoxFooter();
|
||||
}
|
||||
ImGui.PopItemWidth();
|
||||
|
||||
ImGui.Text("Copy onto slot...");
|
||||
foreach (HudSlot slot in Enum.GetValues(typeof(HudSlot))) {
|
||||
|
@ -216,7 +223,8 @@ namespace HudSwap {
|
|||
if (this.plugin.Config.Layouts2.Count == 0) {
|
||||
ImGui.Text("Create at least one layout to begin setting up swaps.");
|
||||
} else {
|
||||
ImGui.Text("Add conditions below for when to swap.\nThe topmost condition in the list has priority.");
|
||||
ImGui.Text("Add swap conditions below.\nThe first condition that is satisfied will be the layout that is used.");
|
||||
ImGui.Separator();
|
||||
this.DrawConditionsTable();
|
||||
}
|
||||
|
||||
|
@ -228,15 +236,21 @@ namespace HudSwap {
|
|||
|
||||
ImGui.End();
|
||||
}
|
||||
|
||||
private void DrawConditionsTable() {
|
||||
ImGui.PushFont(UiBuilder.IconFont);
|
||||
float height = ImGui.GetContentRegionAvail().Y - ImGui.CalcTextSize(FontAwesomeIcon.Plus.ToIconString()).Y - ImGui.GetStyle().ItemSpacing.Y - ImGui.GetStyle().ItemInnerSpacing.Y * 2;
|
||||
ImGui.PopFont();
|
||||
if (!ImGui.BeginChild("##conditions-table", new Vector2(-1, height))) {
|
||||
return;
|
||||
}
|
||||
|
||||
private void DrawConditionsTable()
|
||||
{
|
||||
ImGui.Columns(4);
|
||||
|
||||
var conditions = new List<HudConditionMatch>(plugin.Config.HudConditionMatches);
|
||||
if (this.editingConditionIndex == conditions.Count)
|
||||
var conditions = new List<HudConditionMatch>(this.plugin.Config.HudConditionMatches);
|
||||
if (this.editingConditionIndex == conditions.Count) {
|
||||
conditions.Add(new HudConditionMatch());
|
||||
}
|
||||
|
||||
ImGui.Text("Job");
|
||||
ImGui.NextColumn();
|
||||
|
@ -257,39 +271,70 @@ namespace HudSwap {
|
|||
int action = 0; // 0 for delete, otherwise move.
|
||||
foreach (var item in conditions.Select((cond, i) => new { cond, i })) {
|
||||
if (this.editingConditionIndex == item.i) {
|
||||
ImGui.PushItemWidth(-1);
|
||||
if (ImGui.BeginCombo("##condition-edit-job", this.editingCondition.ClassJob ?? "Any")) {
|
||||
if (ImGui.Selectable("Any##condition-edit-job"))
|
||||
if (ImGui.Selectable("Any##condition-edit-job")) {
|
||||
this.editingCondition.ClassJob = null;
|
||||
foreach (ClassJob job in this.pi.Data.GetExcelSheet<ClassJob>().ToList())
|
||||
if (ImGui.Selectable($"{job.Abbreviation}##condition-edit-job"))
|
||||
}
|
||||
|
||||
foreach (ClassJob job in this.pi.Data.GetExcelSheet<ClassJob>().Skip(1)) {
|
||||
if (ImGui.Selectable($"{job.Abbreviation}##condition-edit-job")) {
|
||||
this.editingCondition.ClassJob = job.Abbreviation;
|
||||
}
|
||||
}
|
||||
|
||||
ImGui.EndCombo();
|
||||
}
|
||||
ImGui.PopItemWidth();
|
||||
ImGui.NextColumn();
|
||||
|
||||
ImGui.PushItemWidth(-1);
|
||||
if (ImGui.BeginCombo("##condition-edit-status", this.editingCondition.Status?.Name() ?? "Any")) {
|
||||
if (ImGui.Selectable("Any##condition-edit-status"))
|
||||
if (ImGui.Selectable("Any##condition-edit-status")) {
|
||||
this.editingCondition.Status = null;
|
||||
foreach (Status status in Enum.GetValues(typeof(Status)))
|
||||
if (ImGui.Selectable($"{status.Name()}##condition-edit-status"))
|
||||
}
|
||||
|
||||
foreach (Status status in Enum.GetValues(typeof(Status))) {
|
||||
if (ImGui.Selectable($"{status.Name()}##condition-edit-status")) {
|
||||
this.editingCondition.Status = status;
|
||||
}
|
||||
}
|
||||
|
||||
ImGui.EndCombo();
|
||||
}
|
||||
ImGui.PopItemWidth();
|
||||
ImGui.NextColumn();
|
||||
|
||||
if (ImGui.BeginCombo("##condition-edit-layout", this.editingCondition.LayoutId == Guid.Empty ? string.Empty : this.plugin.Config.Layouts2[this.editingCondition.LayoutId].Name)) {
|
||||
if (ImGui.Selectable("##condition-edit-layout-empty"))
|
||||
this.editingCondition.LayoutId = Guid.Empty;
|
||||
foreach (var layout in this.plugin.Config.Layouts2)
|
||||
if (ImGui.Selectable($"{layout.Value.Name}##condition-edit-layout"))
|
||||
ImGui.PushItemWidth(-1);
|
||||
string comboPreview = this.editingCondition.LayoutId == Guid.Empty ? string.Empty : this.plugin.Config.Layouts2[this.editingCondition.LayoutId].Name;
|
||||
if (ImGui.BeginCombo("##condition-edit-layout", comboPreview)) {
|
||||
foreach (var layout in this.plugin.Config.Layouts2) {
|
||||
if (ImGui.Selectable($"{layout.Value.Name}##condition-edit-layout-{layout.Key}")) {
|
||||
this.editingCondition.LayoutId = layout.Key;
|
||||
}
|
||||
}
|
||||
|
||||
ImGui.EndCombo();
|
||||
}
|
||||
ImGui.PopItemWidth();
|
||||
ImGui.NextColumn();
|
||||
|
||||
if (this.editingCondition.LayoutId != Guid.Empty)
|
||||
if (ImGui.Button("Confirm##condition-edit"))
|
||||
if (this.editingCondition.LayoutId != Guid.Empty) {
|
||||
if (IconButton(FontAwesomeIcon.Check, "condition-edit")) {
|
||||
addCondition = true;
|
||||
}
|
||||
|
||||
ImGui.SameLine();
|
||||
}
|
||||
|
||||
if (IconButton(FontAwesomeIcon.Times, "condition-stop")) {
|
||||
this.editingConditionIndex = -1;
|
||||
}
|
||||
|
||||
if (this.scrollToAdd) {
|
||||
this.scrollToAdd = false;
|
||||
ImGui.SetScrollHereY();
|
||||
}
|
||||
} else {
|
||||
ImGui.Text(item.cond.ClassJob ?? string.Empty);
|
||||
ImGui.NextColumn();
|
||||
|
@ -297,25 +342,28 @@ namespace HudSwap {
|
|||
ImGui.Text(item.cond.Status?.Name() ?? string.Empty);
|
||||
ImGui.NextColumn();
|
||||
|
||||
ImGui.Text(this.plugin.Config.Layouts2[item.cond.LayoutId].Name);
|
||||
this.plugin.Config.Layouts2.TryGetValue(item.cond.LayoutId, out Layout condLayout);
|
||||
ImGui.Text(condLayout?.Name ?? string.Empty);
|
||||
ImGui.NextColumn();
|
||||
|
||||
if (ImGui.Button($"E##{item.i}")) {
|
||||
if (IconButton(FontAwesomeIcon.PencilAlt, $"{item.i}")) {
|
||||
this.editingConditionIndex = item.i;
|
||||
this.editingCondition = item.cond;
|
||||
}
|
||||
|
||||
ImGui.SameLine();
|
||||
if (ImGui.Button($"D##{item.i}"))
|
||||
if (IconButton(FontAwesomeIcon.Trash, $"{item.i}")) {
|
||||
actionedItemIndex = item.i;
|
||||
}
|
||||
|
||||
ImGui.SameLine();
|
||||
if (ImGui.Button($"↑##{item.i}")) {
|
||||
if (IconButton(FontAwesomeIcon.ArrowUp, $"{item.i}")) {
|
||||
actionedItemIndex = item.i;
|
||||
action = -1;
|
||||
}
|
||||
|
||||
ImGui.SameLine();
|
||||
if (ImGui.Button($"↓##{item.i}")) {
|
||||
if (IconButton(FontAwesomeIcon.ArrowDown, $"{item.i}")) {
|
||||
actionedItemIndex = item.i;
|
||||
action = 1;
|
||||
}
|
||||
|
@ -324,19 +372,25 @@ namespace HudSwap {
|
|||
ImGui.NextColumn();
|
||||
}
|
||||
|
||||
ImGui.Columns();
|
||||
ImGui.Columns(1);
|
||||
|
||||
ImGui.Separator();
|
||||
|
||||
if (ImGui.Button("Add##condition")) {
|
||||
ImGui.EndChild();
|
||||
|
||||
if (IconButton(FontAwesomeIcon.Plus, "condition")) {
|
||||
this.editingConditionIndex = this.plugin.Config.HudConditionMatches.Count;
|
||||
this.editingCondition = new HudConditionMatch();
|
||||
this.scrollToAdd = true;
|
||||
}
|
||||
|
||||
bool recalculate = false;
|
||||
|
||||
if (addCondition) {
|
||||
if (this.editingConditionIndex == this.plugin.Config.HudConditionMatches.Count)
|
||||
recalculate = true;
|
||||
if (this.editingConditionIndex == this.plugin.Config.HudConditionMatches.Count) {
|
||||
this.plugin.Config.HudConditionMatches.Add(this.editingCondition);
|
||||
else {
|
||||
} else {
|
||||
this.plugin.Config.HudConditionMatches.RemoveAt(this.editingConditionIndex);
|
||||
this.plugin.Config.HudConditionMatches.Insert(this.editingConditionIndex, this.editingCondition);
|
||||
}
|
||||
|
@ -345,9 +399,10 @@ namespace HudSwap {
|
|||
}
|
||||
|
||||
if (actionedItemIndex >= 0) {
|
||||
if (action == 0)
|
||||
recalculate = true;
|
||||
if (action == 0) {
|
||||
this.plugin.Config.HudConditionMatches.RemoveAt(actionedItemIndex);
|
||||
else {
|
||||
} else {
|
||||
if (actionedItemIndex + action >= 0 && actionedItemIndex + action < this.plugin.Config.HudConditionMatches.Count) {
|
||||
// Move the condition.
|
||||
var c = this.plugin.Config.HudConditionMatches[actionedItemIndex];
|
||||
|
@ -357,6 +412,21 @@ namespace HudSwap {
|
|||
}
|
||||
this.plugin.Config.Save();
|
||||
}
|
||||
|
||||
if (recalculate) {
|
||||
PlayerCharacter player = this.pi.ClientState.LocalPlayer;
|
||||
if (player != null && this.plugin.Config.SwapsEnabled) {
|
||||
this.plugin.Statuses.Update(player);
|
||||
this.plugin.Statuses.SetHudLayout(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static bool IconButton(FontAwesomeIcon icon, string append = "") {
|
||||
ImGui.PushFont(UiBuilder.IconFont);
|
||||
bool button = ImGui.Button($"{icon.ToIconString()}##{append}");
|
||||
ImGui.PopFont();
|
||||
return button;
|
||||
}
|
||||
|
||||
private static void HelpMarker(string text) {
|
||||
|
@ -370,41 +440,10 @@ namespace HudSwap {
|
|||
}
|
||||
}
|
||||
|
||||
private string LayoutNameOrDefault(Guid key) {
|
||||
if (this.plugin.Config.Layouts2.TryGetValue(key, out Layout layout)) {
|
||||
return layout.Name;
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public void Draw() {
|
||||
this.DrawSettings();
|
||||
}
|
||||
|
||||
private bool LayoutBox(string name, Guid currentLayout, out Guid newLayout) {
|
||||
newLayout = Guid.Empty;
|
||||
bool updated = false;
|
||||
ImGui.Text(name);
|
||||
ImGui.NextColumn();
|
||||
if (ImGui.BeginCombo($"##{name}-layout", this.LayoutNameOrDefault(currentLayout))) {
|
||||
if (ImGui.Selectable("Not set")) {
|
||||
updated = true;
|
||||
}
|
||||
ImGui.Separator();
|
||||
foreach (KeyValuePair<Guid, Layout> entry in this.plugin.Config.Layouts2) {
|
||||
if (ImGui.Selectable(entry.Value.Name)) {
|
||||
updated = true;
|
||||
newLayout = entry.Key;
|
||||
}
|
||||
}
|
||||
ImGui.EndCombo();
|
||||
}
|
||||
ImGui.NextColumn();
|
||||
|
||||
return updated;
|
||||
}
|
||||
|
||||
private Dictionary<string, Vector2<short>> GetPositions() {
|
||||
Dictionary<string, Vector2<short>> positions = new Dictionary<string, Vector2<short>>();
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Converters;
|
||||
|
||||
// TODO: Zone swaps?
|
||||
|
||||
|
@ -57,11 +58,12 @@ namespace HudSwap {
|
|||
|
||||
foreach (var match in this.plugin.Config.HudConditionMatches) {
|
||||
if ((!match.Status.HasValue || this.condition[match.Status.Value]) &&
|
||||
(match.ClassJob == null || this.job.Abbreviation == match.ClassJob))
|
||||
(match.ClassJob == null || this.job.Abbreviation == match.ClassJob)) {
|
||||
return match.LayoutId;
|
||||
}
|
||||
}
|
||||
|
||||
return this.plugin.Config.DefaultLayout;
|
||||
return Guid.Empty;
|
||||
}
|
||||
|
||||
public void SetHudLayout(PlayerCharacter player, bool update = false) {
|
||||
|
@ -92,11 +94,13 @@ namespace HudSwap {
|
|||
/// </summary>
|
||||
public string ClassJob { get; set; }
|
||||
|
||||
[JsonConverter(typeof(StringEnumConverter))]
|
||||
public Status? Status { get; set; }
|
||||
|
||||
public Guid LayoutId { get; set; }
|
||||
}
|
||||
|
||||
// Note: Changing the names of these is a breaking change
|
||||
public enum Status {
|
||||
InCombat = ConditionFlag.InCombat,
|
||||
WeaponDrawn = ConditionFlag.None,
|
||||
|
|
Loading…
Reference in New Issue
Block a user