feat: add exporting and implement clipboard
This commit is contained in:
parent
b8c99f1839
commit
2fdba230b8
|
@ -10,6 +10,7 @@ using HUD_Manager.Structs;
|
||||||
using HUD_Manager.Tree;
|
using HUD_Manager.Tree;
|
||||||
using ImGuiNET;
|
using ImGuiNET;
|
||||||
using Lumina.Excel.GeneratedSheets;
|
using Lumina.Excel.GeneratedSheets;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
// TODO: Zone swaps?
|
// TODO: Zone swaps?
|
||||||
|
|
||||||
|
@ -266,10 +267,19 @@ namespace HUD_Manager {
|
||||||
ImGui.OpenPopup(Popups.ImportLayout);
|
ImGui.OpenPopup(Popups.ImportLayout);
|
||||||
}
|
}
|
||||||
|
|
||||||
HoverTooltip("Import a layout from an in-game HUD slot");
|
HoverTooltip("Import a layout from an in-game HUD slot or the clipboard");
|
||||||
|
|
||||||
this.SetUpImportLayoutPopup();
|
this.SetUpImportLayoutPopup();
|
||||||
|
|
||||||
|
ImGui.SameLine();
|
||||||
|
if (IconButton(FontAwesomeIcon.FileExport, "uimanager-export-layout")) {
|
||||||
|
ImGui.OpenPopup(Popups.ExportLayout);
|
||||||
|
}
|
||||||
|
|
||||||
|
HoverTooltip("Export a layout to an in-game HUD slot or the clipboard");
|
||||||
|
|
||||||
|
this.SetUpExportLayoutPopup();
|
||||||
|
|
||||||
if (this._selectedEditLayout == Guid.Empty) {
|
if (this._selectedEditLayout == Guid.Empty) {
|
||||||
goto EndTabItem;
|
goto EndTabItem;
|
||||||
}
|
}
|
||||||
|
@ -436,7 +446,7 @@ namespace HUD_Manager {
|
||||||
var current = this.Plugin.Hud.GetActiveHudSlot();
|
var current = this.Plugin.Hud.GetActiveHudSlot();
|
||||||
foreach (var slot in (HudSlot[]) Enum.GetValues(typeof(HudSlot))) {
|
foreach (var slot in (HudSlot[]) Enum.GetValues(typeof(HudSlot))) {
|
||||||
var name = current == slot ? $"({(int) slot + 1})" : $"{(int) slot + 1}";
|
var name = current == slot ? $"({(int) slot + 1})" : $"{(int) slot + 1}";
|
||||||
if (ImGui.Button($"{name}##import-{slot}")) {
|
if (ImGui.Button($"{name}##import-{slot}") && this._importName != null) {
|
||||||
Guid id;
|
Guid id;
|
||||||
string newName;
|
string newName;
|
||||||
Dictionary<string, Vector2<short>> positions;
|
Dictionary<string, Vector2<short>> positions;
|
||||||
|
@ -447,7 +457,7 @@ namespace HUD_Manager {
|
||||||
positions = overwriting.Value.Positions;
|
positions = overwriting.Value.Positions;
|
||||||
} else {
|
} else {
|
||||||
id = Guid.NewGuid();
|
id = Guid.NewGuid();
|
||||||
newName = this._importName!;
|
newName = this._importName;
|
||||||
positions = new Dictionary<string, Vector2<short>>();
|
positions = new Dictionary<string, Vector2<short>>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -464,7 +474,54 @@ namespace HUD_Manager {
|
||||||
ImGui.SameLine();
|
ImGui.SameLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IconButton(FontAwesomeIcon.Clipboard, "import-clipboard")) {
|
if (IconButton(FontAwesomeIcon.Clipboard, "import-clipboard") && this._importName != null) {
|
||||||
|
SavedLayout? saved;
|
||||||
|
try {
|
||||||
|
saved = JsonConvert.DeserializeObject<SavedLayout>(ImGui.GetClipboardText());
|
||||||
|
} catch (Exception) {
|
||||||
|
saved = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (saved != null) {
|
||||||
|
saved.Name = this._importName;
|
||||||
|
|
||||||
|
var id = Guid.NewGuid();
|
||||||
|
this.Plugin.Config.Layouts[id] = saved;
|
||||||
|
this.Plugin.Config.Save();
|
||||||
|
|
||||||
|
this._selectedEditLayout = id;
|
||||||
|
|
||||||
|
ImGui.CloseCurrentPopup();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui.EndPopup();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetUpExportLayoutPopup() {
|
||||||
|
if (!ImGui.BeginPopup(Popups.ExportLayout)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this.Plugin.Config.Layouts.TryGetValue(this._selectedEditLayout, out var layout)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var current = this.Plugin.Hud.GetActiveHudSlot();
|
||||||
|
foreach (var slot in (HudSlot[]) Enum.GetValues(typeof(HudSlot))) {
|
||||||
|
var name = current == slot ? $"({(int) slot + 1})" : $"{(int) slot + 1}";
|
||||||
|
if (ImGui.Button($"{name}##export-{slot}")) {
|
||||||
|
this.Plugin.Hud.WriteEffectiveLayout(slot, this._selectedEditLayout);
|
||||||
|
|
||||||
|
ImGui.CloseCurrentPopup();
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui.SameLine();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (IconButton(FontAwesomeIcon.Clipboard, "export-clipboard")) {
|
||||||
|
var json = JsonConvert.SerializeObject(layout);
|
||||||
|
ImGui.SetClipboardText(json);
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui.EndPopup();
|
ImGui.EndPopup();
|
||||||
|
@ -918,6 +975,7 @@ namespace HUD_Manager {
|
||||||
public const string AddLayout = "uimanager-add-layout-popup";
|
public const string AddLayout = "uimanager-add-layout-popup";
|
||||||
public const string RenameLayout = "uimanager-rename-layout-popup";
|
public const string RenameLayout = "uimanager-rename-layout-popup";
|
||||||
public const string ImportLayout = "uimanager-import-layout-popup";
|
public const string ImportLayout = "uimanager-import-layout-popup";
|
||||||
|
public const string ExportLayout = "uimanager-export-layout-popup";
|
||||||
public const string AddElement = "uimanager-add-element-popup";
|
public const string AddElement = "uimanager-add-element-popup";
|
||||||
public const string DeleteVerify = "Delete layout?##uimanager-delete-layout-modal";
|
public const string DeleteVerify = "Delete layout?##uimanager-delete-layout-modal";
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue