Skip to content
This repository has been archived by the owner on Aug 13, 2024. It is now read-only.

Commit

Permalink
Swapped Import window from Explorer to ImGui
Browse files Browse the repository at this point in the history
  • Loading branch information
StoiaCode committed May 29, 2023
1 parent 61ed428 commit 10125ae
Showing 1 changed file with 57 additions and 24 deletions.
81 changes: 57 additions & 24 deletions CustomizePlus/Interface/ConfigurationInterface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,20 @@ namespace CustomizePlus.Interface
using CustomizePlus.Data.Configuration;
using CustomizePlus.Memory;
using Dalamud.Game.ClientState.Objects.SubKinds;
using Dalamud.Interface.ImGuiFileDialog;
using Dalamud.Game.ClientState.Objects.Types;
using Dalamud.Interface;
using Dalamud.Interface.Components;
using Dalamud.Logging;
using ImGuiNET;
using Newtonsoft.Json;
using System.Windows.Forms.Design;

public class ConfigurationInterface : WindowBase
{
private string newScaleName = string.Empty;
private string newScaleCharacter = string.Empty;
private FileDialogManager picker = new();

private string? playerCharacterName;

Expand All @@ -49,6 +52,9 @@ protected override void DrawContents()

playerCharacterName = DalamudServices.ObjectTable[0]?.Name.ToString();

// Draw the File Picker
picker.Draw();

/* Upcoming feature to group by either scale name or character name
List<string> uniqueCharacters = new();
List<string> uniqueScales = new();
Expand Down Expand Up @@ -168,7 +174,7 @@ protected override void DrawContents()

ImGui.SameLine();
if (ImGui.Button("Add Character from Clipboard")) {
Byte importVer = 0;
byte importVer = 0;
BodyScale importScale = null;
string json = null;

Expand Down Expand Up @@ -330,7 +336,7 @@ protected override void DrawContents()
// Import Ana
ImGui.SameLine();
if (ImGuiComponents.IconButton(FontAwesomeIcon.FileImport)) {
this.Import(extBS);
this.ImportWithImgui(extBS);
Plugin.ConfigurationManager.SaveConfiguration();
Plugin.LoadConfig(true);
}
Expand Down Expand Up @@ -426,29 +432,56 @@ public static byte ImportFromBase64(string base64, out string data) {
return version;
}

private void Import(BodyScale scale)
{
Action importAction = () =>
{
OpenFileDialog picker = new();
picker.Filter = "Anamnesis Pose (*.pose)|*.pose";
picker.CheckFileExists = true;
picker.Title = "Customize+ - Import Anamnesis Pose";

DialogResult result = picker.ShowDialog();
if (result != DialogResult.OK)
return;

string json = File.ReadAllText(picker.FileName);

BuildFromJSON(scale, json);

string name = Path.GetFileNameWithoutExtension(picker.FileName);

scale.ScaleName = name;
};
// Deprecated, remove with the next update.
//private void Import(BodyScale scale)
//{
// Action importAction = () =>
// {
// OpenFileDialog picker = new();
// picker.Filter = "Anamnesis Pose (*.pose)|*.pose";
// picker.CheckFileExists = true;
// picker.Title = "Customize+ - Import Anamnesis Pose";

// DialogResult result = picker.ShowDialog();
// if (result != DialogResult.OK)
// return;

// string json = File.ReadAllText(picker.FileName);

// BuildFromJSON(scale, json);

// string name = Path.GetFileNameWithoutExtension(picker.FileName);

// scale.ScaleName = name;
// };

// MessageWindow.Show("Customize+ is only able to import scale from the *.pose files. Position and rotation will be ignored.", new Vector2(570, 100), importAction, "ana_import_pos_rot_warning");
//}


/// <summary>
/// Imports a BodyScale using Dalamuds Imgui FileDialog.
/// </summary>
/// <param name="scale">The BodyScale object to import the data into.</param>
private void ImportWithImgui(BodyScale scale) {

/// <summary>
/// Action performed when the file is imported.
/// </summary>
void ImportAction() {
picker.OpenFileDialog("Import Pose File", ".pose", (isSuccess, path) => {
if (isSuccess) {
var result = path.FirstOrDefault();
var json = File.ReadAllText(result);
BuildFromJSON(scale, json);
scale.ScaleName = Path.GetFileNameWithoutExtension(result);
} else {
PluginLog.Information(isSuccess + " NO valid file has been selected. " + path);
}
}, 1, null, true);
}

MessageWindow.Show("Customize+ is only able to import scale from the *.pose files. Position and rotation will be ignored.", new Vector2(570, 100), importAction, "ana_import_pos_rot_warning");
MessageWindow.Show("Customize+ is only able to import scale from the *.pose files. Position and rotation will be ignored.", new Vector2(570, 100), ImportAction, "ana_import_pos_rot_warning");
}

// TODO: Finish feature. May require additional skeleton code from Anamnesis
Expand Down

0 comments on commit 10125ae

Please sign in to comment.