Files
SpineViewer/SpineViewer/Dialogs/OpenSpineDialog.cs
2025-04-27 22:06:45 +07:00

120 lines
3.6 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using SpineViewer.Spine;
using SpineViewer.Utils;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace SpineViewer.Dialogs
{
public partial class OpenSpineDialog : Form
{
/// <summary>
/// 对话框结果
/// </summary>
public OpenSpineDialogResult Result { get; private set; }
public OpenSpineDialog()
{
InitializeComponent();
comboBox_Version.DataSource = SpineUtils.Names.ToList();
comboBox_Version.DisplayMember = "Value";
comboBox_Version.ValueMember = "Key";
comboBox_Version.SelectedValue = SpineVersion.Auto;
}
private void OpenSpineDialog_Load(object sender, EventArgs e)
{
button_SelectSkel_Click(sender, e);
}
private void button_SelectSkel_Click(object sender, EventArgs e)
{
openFileDialog_Skel.InitialDirectory = Path.GetDirectoryName(textBox_SkelPath.Text);
if (openFileDialog_Skel.ShowDialog() == DialogResult.OK)
{
textBox_SkelPath.Text = Path.GetFullPath(openFileDialog_Skel.FileName);
}
}
private void button_SelectAtlas_Click(object sender, EventArgs e)
{
openFileDialog_Atlas.InitialDirectory = Path.GetDirectoryName(textBox_AtlasPath.Text);
if (openFileDialog_Atlas.ShowDialog() == DialogResult.OK)
{
textBox_AtlasPath.Text = Path.GetFullPath(openFileDialog_Atlas.FileName);
}
}
private void button_Ok_Click(object sender, EventArgs e)
{
var skelPath = textBox_SkelPath.Text;
var atlasPath = textBox_AtlasPath.Text;
var version = (SpineVersion)comboBox_Version.SelectedValue;
if (!File.Exists(skelPath))
{
MessagePopup.Info($"{skelPath}", Properties.Resources.skelNotExist);
return;
}
else
{
skelPath = Path.GetFullPath(skelPath);
}
if (string.IsNullOrWhiteSpace(atlasPath))
{
atlasPath = null;
}
else if (!File.Exists(atlasPath))
{
MessagePopup.Info($"{atlasPath}", Properties.Resources.atlasNotExist);
return;
}
else
{
atlasPath = Path.GetFullPath(atlasPath);
}
if (version != SpineVersion.Auto && !Spine.SpineObject.HasImplementation(version))
{
MessagePopup.Info($"{version.GetName()} 版本尚未实现(咕咕咕~", Properties.Resources.msgBoxInfo);
return;
}
Result = new(version, skelPath, atlasPath);
DialogResult = DialogResult.OK;
}
private void button_Cancel_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
}
}
/// <summary>
/// 打开骨骼对话框结果
/// </summary>
public class OpenSpineDialogResult(SpineVersion version, string skelPath, string? atlasPath = null)
{
/// <summary>
/// 版本
/// </summary>
public SpineVersion Version => version;
/// <summary>
/// skel 文件路径
/// </summary>
public string SkelPath => skelPath;
/// <summary>
/// atlas 文件路径
/// </summary>
public string? AtlasPath => atlasPath;
}
}