400 lines
16 KiB
C#
400 lines
16 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Windows.Forms;
|
|
using System.Diagnostics;
|
|
using System.Threading;
|
|
using System.IO;
|
|
|
|
namespace UA_AtlasEditor
|
|
{
|
|
//=============================================================================================
|
|
//
|
|
// Options form
|
|
//
|
|
//=============================================================================================
|
|
public partial class OptionsForm : Form
|
|
{
|
|
//=============================================================================================
|
|
// members
|
|
//=============================================================================================
|
|
public MainForm _mainForm;
|
|
public Options _options;
|
|
|
|
//=============================================================================================
|
|
// init / Close
|
|
//=============================================================================================
|
|
|
|
//-----------------------------------------------------------------------------------------
|
|
public OptionsForm(MainForm mainForm, Options options)
|
|
{
|
|
_mainForm = mainForm;
|
|
_options = options;
|
|
|
|
InitializeComponent();
|
|
|
|
buttonBackgroundColor.BackColor = _options._backColor;
|
|
buttonCreatedRectangle.BackColor = _options._createColor;
|
|
buttonSelectedRectangle.BackColor = _options._selColor;
|
|
buttonUnselectedRectangle.BackColor = _options._unselColor;
|
|
checkBoxSnapGrid.Checked = _options._editGridSnapEnable;
|
|
textBoxSnapGrid.Enabled = _options._editGridSnapEnable;
|
|
textBoxSnapGrid.Text = _options._editGridSnap.ToString(System.Globalization.CultureInfo.InvariantCulture);
|
|
checkBoxSnap.Checked = _options._editSnapEnable;
|
|
checkBoxShowUnselected.Checked = _options._showUnselected;
|
|
checkBoxShowPointIndex.Checked = _options._showPointIndex;
|
|
checkBoxShowPointWeight.Checked = _options._showPointWeight;
|
|
checkBoxShowPointDepth.Checked = _options._showPointDepth;
|
|
checkBoxBilinearFilter.Checked = _options._bilinearFilter;
|
|
|
|
if (_options._editCreateListPoint)
|
|
radioButtonListPoints.Checked = true;
|
|
else
|
|
radioButtonRectangle.Checked = true;
|
|
|
|
checkBoxAtlRectangle.Checked = _options._saveRectangle;
|
|
checkBoxAtlListPoints.Checked = _options._saveListPoint;
|
|
checkBoxAtlMesh2D.Checked = _options._saveMesh2D;
|
|
checkBoxSaveRectangleAsListPoint.Checked = _options._saveRectangleAsListOfPoints;
|
|
checkBoxSaveWeight.Checked = _options._saveWeight;
|
|
checkBoxSaveDepth.Checked = _options._saveDepth;
|
|
checkBoxSaveColor.Checked = _options._saveColor;
|
|
checkBoxLoadTwoPointAsRectangle.Checked = _options._load2PointsAsRectangle;
|
|
|
|
textBoxWeightMin.Text = _options._editWeightMin.ToString();
|
|
textBoxWeightMax.Text = _options._editWeightMax.ToString();
|
|
|
|
textBoxDepthMin.Text = _options._editDepthMin.ToString();
|
|
textBoxDepthMax.Text = _options._editDepthMax.ToString();
|
|
|
|
checkBoxBreakableHelper.Checked = _options._breakableShow;
|
|
textBoxBreakableRefSize.Text = _options._breakableCellPixelSize.ToString();
|
|
|
|
labelTexturePackerExe.Text = _options._texturePackerExe;
|
|
labelTexturePackerRoot.Text = _options._texturePackerRoot;
|
|
comboBoxTexturePackerSampling.SelectedIndex = comboBoxTexturePackerSampling.FindStringExact(_options._texturePackerSampling.ToString());
|
|
comboBoxTexturePackerDownscale.SelectedIndex = comboBoxTexturePackerDownscale.FindStringExact(_options._texturePackerDownscale.ToString());
|
|
comboBoxTexturePackerDownscale.Text = _options._texturePackerDownscale.ToString();
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------------------
|
|
private void OptionsFor_FormClosing(object sender, FormClosingEventArgs e)
|
|
{
|
|
Visible = false;
|
|
e.Cancel = true;
|
|
return;
|
|
}
|
|
|
|
//=============================================================================================
|
|
// misc functions
|
|
//=============================================================================================
|
|
private bool chooseColor( ref Color color )
|
|
{
|
|
ColorDialog colorDialog = new ColorDialog();
|
|
colorDialog.Color = color;
|
|
if (colorDialog.ShowDialog() != DialogResult.OK)
|
|
return false;
|
|
color = colorDialog.Color;
|
|
Invalidate();
|
|
_mainForm.Invalidate();
|
|
return true;
|
|
}
|
|
|
|
//=============================================================================================
|
|
// display options
|
|
//=============================================================================================
|
|
|
|
private void buttonBackgroundColor_Click(object sender, EventArgs e)
|
|
{
|
|
if (chooseColor( ref _options._backColor ))
|
|
buttonBackgroundColor.BackColor = _options._backColor;
|
|
}
|
|
|
|
private void buttonCreatedRectangle_Click(object sender, EventArgs e)
|
|
{
|
|
if (chooseColor(ref _options._createColor))
|
|
buttonCreatedRectangle.BackColor = _options._createColor;
|
|
}
|
|
|
|
private void buttonSelectedRectangle_Click(object sender, EventArgs e)
|
|
{
|
|
if (chooseColor(ref _options._selColor))
|
|
buttonSelectedRectangle.BackColor = _options._selColor;
|
|
}
|
|
|
|
private void buttonUnselectedRectangle_Click(object sender, EventArgs e)
|
|
{
|
|
if (chooseColor(ref _options._unselColor))
|
|
buttonUnselectedRectangle.BackColor = _options._unselColor;
|
|
}
|
|
|
|
private void checkBoxShowUnselected_CheckedChanged(object sender, EventArgs e)
|
|
{
|
|
_options._showUnselected = checkBoxShowUnselected.Checked;
|
|
_mainForm.Invalidate();
|
|
}
|
|
|
|
private void checkBoxShowPointIndex_CheckedChanged(object sender, EventArgs e)
|
|
{
|
|
_options._showPointIndex = checkBoxShowPointIndex.Checked;
|
|
_mainForm.Invalidate();
|
|
}
|
|
|
|
private void checkBoxShowPointWeight_CheckedChanged(object sender, EventArgs e)
|
|
{
|
|
_options._showPointWeight = checkBoxShowPointWeight.Checked;
|
|
_mainForm.Invalidate();
|
|
}
|
|
|
|
private void checkBoxShowPointDepth_CheckedChanged(object sender, EventArgs e)
|
|
{
|
|
_options._showPointDepth = checkBoxShowPointDepth.Checked;
|
|
_mainForm.Invalidate();
|
|
}
|
|
|
|
private void checkBoxBilinearFilter_Click(object sender, EventArgs e)
|
|
{
|
|
_options._bilinearFilter = checkBoxBilinearFilter.Checked;
|
|
_mainForm.Invalidate();
|
|
}
|
|
|
|
//=============================================================================================
|
|
// Edit options
|
|
//=============================================================================================
|
|
|
|
private void checkBoxSnapGrid_CheckedChanged(object sender, EventArgs e)
|
|
{
|
|
_options._editGridSnapEnable = checkBoxSnapGrid.Checked;
|
|
textBoxSnapGrid.Enabled = _options._editGridSnapEnable;
|
|
}
|
|
|
|
private void textBoxSnapGrid_TextChanged(object sender, EventArgs e)
|
|
{
|
|
_options._editGridSnap = Convert.ToSingle(textBoxSnapGrid.Text, System.Globalization.CultureInfo.InvariantCulture);
|
|
}
|
|
|
|
private void checkBoxSnap_CheckedChanged(object sender, EventArgs e)
|
|
{
|
|
_options._editSnapEnable = checkBoxSnap.Checked;
|
|
}
|
|
|
|
private void radioButtonRectangle_CheckedChanged(object sender, EventArgs e)
|
|
{
|
|
_options._editCreateListPoint = !radioButtonRectangle.Checked;
|
|
}
|
|
|
|
private void radioButtonListPoints_CheckedChanged(object sender, EventArgs e)
|
|
{
|
|
_options._editCreateListPoint = radioButtonListPoints.Checked;
|
|
}
|
|
|
|
private void textBoxWeightMax_TextChanged(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
_options._editWeightMax = Convert.ToSingle(textBoxWeightMax.Text, System.Globalization.CultureInfo.InvariantCulture);
|
|
if (_options._editWeightMax < _options._editWeightMin)
|
|
_options._editWeightMin = _options._editWeightMax - 0.001f;
|
|
}
|
|
catch { }
|
|
}
|
|
|
|
private void textBoxWeightMin_TextChanged(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
_options._editWeightMin = Convert.ToSingle(textBoxWeightMin.Text, System.Globalization.CultureInfo.InvariantCulture);
|
|
if (_options._editWeightMin > _options._editWeightMax)
|
|
_options._editWeightMax = _options._editWeightMin + 0.001f;
|
|
}
|
|
catch { }
|
|
}
|
|
|
|
private void textBoxDepthMax_TextChanged(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
_options._editDepthMax = Convert.ToSingle(textBoxDepthMax.Text, System.Globalization.CultureInfo.InvariantCulture);
|
|
if (_options._editDepthMax < _options._editDepthMin)
|
|
_options._editDepthMin = _options._editDepthMax - 0.001f;
|
|
}
|
|
catch { }
|
|
}
|
|
|
|
private void textBoxDepthMin_TextChanged(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
_options._editDepthMin = Convert.ToSingle(textBoxDepthMin.Text, System.Globalization.CultureInfo.InvariantCulture);
|
|
if (_options._editDepthMin > _options._editDepthMax)
|
|
_options._editDepthMax = _options._editDepthMin + 0.001f;
|
|
}
|
|
catch { }
|
|
}
|
|
|
|
private void textBoxBreakableRefSize_TextChanged(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
_options._breakableCellPixelSize = Convert.ToInt32(textBoxBreakableRefSize.Text, System.Globalization.CultureInfo.InvariantCulture);
|
|
}
|
|
catch { }
|
|
}
|
|
|
|
private void checkBoxBreakableHelper_CheckedChanged(object sender, EventArgs e)
|
|
{
|
|
_options._breakableShow = checkBoxBreakableHelper.Checked;
|
|
_mainForm.Invalidate();
|
|
}
|
|
|
|
|
|
//=============================================================================================
|
|
// save functions
|
|
//=============================================================================================
|
|
|
|
|
|
|
|
private void checkBoxAtlRectangle_CheckedChanged(object sender, EventArgs e)
|
|
{
|
|
_options._saveRectangle = checkBoxAtlRectangle.Checked;
|
|
}
|
|
|
|
private void checkBoxAtlListPoints_CheckedChanged(object sender, EventArgs e)
|
|
{
|
|
_options._saveListPoint = checkBoxAtlListPoints.Checked;
|
|
}
|
|
|
|
private void checkBoxAtlMesh2D_CheckedChanged(object sender, EventArgs e)
|
|
{
|
|
_options._saveMesh2D = checkBoxAtlMesh2D.Checked;
|
|
}
|
|
|
|
private void checkBoxSaveRectangleAsListPoint_CheckedChanged(object sender, EventArgs e)
|
|
{
|
|
_options._saveRectangleAsListOfPoints = checkBoxSaveRectangleAsListPoint.Checked;
|
|
}
|
|
|
|
private void checkBoxSaveWeight_CheckedChanged(object sender, EventArgs e)
|
|
{
|
|
_options._saveWeight = checkBoxSaveWeight.Checked;
|
|
}
|
|
|
|
private void checkBoxSaveDepth_CheckedChanged(object sender, EventArgs e)
|
|
{
|
|
_options._saveDepth = checkBoxSaveDepth.Checked;
|
|
}
|
|
|
|
private void checkBoxSaveColor_CheckedChanged(object sender, EventArgs e)
|
|
{
|
|
_options._saveColor = checkBoxSaveColor.Checked;
|
|
}
|
|
|
|
private void checkBoxLoadTwoPointAsRectangle_CheckedChanged(object sender, EventArgs e)
|
|
{
|
|
_options._load2PointsAsRectangle = checkBoxLoadTwoPointAsRectangle.Checked;
|
|
Atlas.Load2PointShapeAsRectangle = _options._load2PointsAsRectangle;
|
|
}
|
|
|
|
//=============================================================================================
|
|
// perforce options
|
|
//=============================================================================================
|
|
|
|
private void buttonSaveConfig_Click(object sender, EventArgs e)
|
|
{
|
|
_mainForm.optionsUnapply();
|
|
_options.save();
|
|
}
|
|
|
|
|
|
|
|
//=============================================================================================
|
|
// Texture Packer options
|
|
//=============================================================================================
|
|
|
|
private void comboBoxTexturePackerSampling_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
_options._texturePackerSampling = Convert.ToInt32(comboBoxTexturePackerSampling.Text);
|
|
}
|
|
|
|
private void comboBoxTexturePackerDownscale_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
_options._texturePackerDownscale = Convert.ToInt32(comboBoxTexturePackerDownscale.Text);
|
|
}
|
|
|
|
private void buttonTexturePackerExe_Click(object sender, EventArgs e)
|
|
{
|
|
OpenFileDialog openFile = new OpenFileDialog();
|
|
|
|
openFile.InitialDirectory = Path.GetDirectoryName(_options._texturePackerExe);
|
|
openFile.Filter = "Exe files (*.exe)|*.exe";
|
|
openFile.RestoreDirectory = true;
|
|
openFile.CheckFileExists = true;
|
|
|
|
if (_mainForm.ShowDialog() == DialogResult.OK)
|
|
_options._texturePackerExe = openFile.FileName;
|
|
labelTexturePackerExe.Text = _options._texturePackerExe;
|
|
}
|
|
|
|
private void buttonTexturePackerRoot_Click(object sender, EventArgs e)
|
|
{
|
|
FolderBrowserDialog folder = new FolderBrowserDialog();
|
|
if (folder.ShowDialog() == DialogResult.OK)
|
|
_options._texturePackerRoot = folder.SelectedPath;
|
|
labelTexturePackerRoot.Text = _options._texturePackerRoot;
|
|
}
|
|
|
|
private void buttonPackTexture_Click(object sender, EventArgs e)
|
|
{
|
|
Process process = new Process();
|
|
|
|
if (_mainForm._atlas == null)
|
|
{
|
|
MessageBox.Show("no atlas edited", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error );
|
|
return;
|
|
}
|
|
|
|
string dir = _options._texturePackerRoot;
|
|
dir = dir.Replace('\\', '/').ToLower();
|
|
if (dir == "" || !Directory.Exists(dir))
|
|
{
|
|
MessageBox.Show("root directory is invalid", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error );
|
|
return;
|
|
}
|
|
if (dir[dir.Length - 1] != '/') dir += '/';
|
|
|
|
string atlas = _mainForm._atlas.FileImage;
|
|
atlas = atlas.Replace('\\', '/').ToLower();
|
|
if (atlas.Length < dir.Length || atlas.Substring(0, dir.Length) != dir)
|
|
{
|
|
MessageBox.Show("atlas path have to include root path", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error );
|
|
return;
|
|
}
|
|
atlas = atlas.Substring(dir.Length);
|
|
|
|
string sampling = _options._texturePackerSampling.ToString();
|
|
string downscale = _options._texturePackerDownscale.ToString();
|
|
|
|
process.StartInfo.FileName = _options._texturePackerExe;
|
|
process.StartInfo.Arguments = $"Directory={dir};packAtlas={atlas};sampling={sampling};hdDownscale=\"{downscale}\"";
|
|
process.StartInfo.CreateNoWindow = false;
|
|
process.Start();
|
|
//process.WaitForExit();
|
|
//process.Close();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
}
|