2020-04-18 22:24:48 +02:00
|
|
|
|
using System;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
|
|
|
|
namespace VoxCharger
|
|
|
|
|
{
|
|
|
|
|
public partial class LevelEditorForm : Form
|
|
|
|
|
{
|
2023-01-06 14:58:29 +01:00
|
|
|
|
private static readonly Image DummyJacket = VoxCharger.Properties.Resources.jk_dummy_s;
|
2020-04-18 22:24:48 +02:00
|
|
|
|
|
2023-01-06 14:58:29 +01:00
|
|
|
|
private VoxHeader _header;
|
|
|
|
|
private Ksh _kshUpdate = null;
|
|
|
|
|
private string _voxUpdatePath = string.Empty;
|
|
|
|
|
private string _audioMainUpdatePath = string.Empty;
|
|
|
|
|
private string _audioPreviewUpdatePath = string.Empty;
|
2020-04-18 22:24:48 +02:00
|
|
|
|
|
|
|
|
|
public VoxLevelHeader Result { get; private set; }
|
|
|
|
|
|
|
|
|
|
public Action Action { get; private set; } = null;
|
|
|
|
|
|
|
|
|
|
public LevelEditorForm(VoxHeader header, Difficulty difficulty)
|
|
|
|
|
{
|
2023-01-06 14:58:29 +01:00
|
|
|
|
this._header = header;
|
2020-04-18 22:24:48 +02:00
|
|
|
|
VoxLevelHeader level;
|
|
|
|
|
if (!header.Levels.TryGetValue(difficulty, out level))
|
|
|
|
|
Result = new VoxLevelHeader();
|
|
|
|
|
else
|
|
|
|
|
Result = level;
|
|
|
|
|
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnLevelEditorFormLoad(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
switch (Result.Difficulty)
|
|
|
|
|
{
|
|
|
|
|
case Difficulty.Novice: Text = "Level Editor - NOV"; break;
|
|
|
|
|
case Difficulty.Advanced: Text = "Level Editor - ADV"; break;
|
|
|
|
|
case Difficulty.Exhaust: Text = "Level Editor - EXH"; break;
|
|
|
|
|
default:
|
2023-01-06 14:58:29 +01:00
|
|
|
|
switch (_header.InfVersion)
|
2020-04-18 22:24:48 +02:00
|
|
|
|
{
|
2023-01-06 14:58:29 +01:00
|
|
|
|
case InfiniteVersion.Inf: Text = "Level Editor - INF"; break;
|
|
|
|
|
case InfiniteVersion.Grv: Text = "Level Editor - GRV"; break;
|
|
|
|
|
case InfiniteVersion.Hvn: Text = "Level Editor - HVN"; break;
|
|
|
|
|
case InfiniteVersion.Vvd: Text = "Level Editor - VVD"; break;
|
|
|
|
|
case InfiniteVersion.Xcd: Text = "Level Editor - XCD"; break;
|
2020-04-18 22:24:48 +02:00
|
|
|
|
default: Text = "Level Editor - MXM"; break;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LevelNumericBox.Value = Result.Level;
|
|
|
|
|
EffectorTextBox.Text = Result.Effector;
|
|
|
|
|
IllustratorTextBox.Text = Result.Illustrator;
|
2023-01-06 14:58:29 +01:00
|
|
|
|
|
|
|
|
|
AddRadarDataButton.Visible = Result.Radar == null;
|
|
|
|
|
RadarGroupBox.Visible = Result.Radar != null;
|
2020-04-18 22:24:48 +02:00
|
|
|
|
|
2023-01-06 14:58:29 +01:00
|
|
|
|
if (Result.Radar != null)
|
|
|
|
|
{
|
|
|
|
|
NotesNumericUpDown.Value = Result.Radar.Notes;
|
|
|
|
|
PeakNumericUpDown.Value = Result.Radar.Peak;
|
|
|
|
|
TsumamiNumericUpDown.Value = Result.Radar.Lasers;
|
|
|
|
|
TrickyNumericUpDown.Value = Result.Radar.Tricky;
|
|
|
|
|
HandTripNumericUpDown.Value = Result.Radar.HandTrip;
|
|
|
|
|
OneHandNumericUpDown.Value = Result.Radar.OneHand;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
Height -= (RadarGroupBox.Height - AddRadarDataButton.Height);
|
|
|
|
|
|
2020-04-18 22:24:48 +02:00
|
|
|
|
LoadJacket();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnJacketButtonClick(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
using (var browser = new OpenFileDialog())
|
|
|
|
|
{
|
|
|
|
|
browser.Filter = "Portable Network Graphic|*.png";
|
|
|
|
|
browser.CheckFileExists = true;
|
|
|
|
|
|
|
|
|
|
if (browser.ShowDialog() == DialogResult.OK)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
using (var image = Image.FromFile(browser.FileName))
|
|
|
|
|
JacketPictureBox.Image = Result.Jacket = new Bitmap(image);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception)
|
|
|
|
|
{
|
|
|
|
|
Result.Jacket = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnVoxButtonClick(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
using (var browser = new OpenFileDialog())
|
|
|
|
|
{
|
|
|
|
|
browser.Filter = "All supported types|*.vox;*.ksh|Sound Voltex Chart File|*.vox|Kshoot Chart File|*.ksh";
|
|
|
|
|
browser.CheckFileExists = true;
|
|
|
|
|
|
|
|
|
|
if (browser.ShowDialog() == DialogResult.OK)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
// Shoving vox file while it's not actually vox? well.. stupid input get stupid output
|
|
|
|
|
string filename = browser.FileName;
|
|
|
|
|
if (filename.EndsWith(".vox"))
|
|
|
|
|
{
|
|
|
|
|
var vox = new VoxChart();
|
|
|
|
|
vox.Parse(filename);
|
|
|
|
|
|
2023-01-06 14:58:29 +01:00
|
|
|
|
_voxUpdatePath = filename;
|
|
|
|
|
_kshUpdate = null;
|
2020-04-18 22:24:48 +02:00
|
|
|
|
}
|
|
|
|
|
else if (filename.EndsWith(".ksh"))
|
|
|
|
|
{
|
|
|
|
|
var ksh = new Ksh();
|
|
|
|
|
ksh.Parse(filename);
|
|
|
|
|
|
2023-01-06 14:58:29 +01:00
|
|
|
|
_kshUpdate = ksh;
|
|
|
|
|
_voxUpdatePath = string.Empty;
|
2020-04-18 22:24:48 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
MessageBox.Show("Warning! Stupid input, get stupid output :)", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2023-01-06 14:58:29 +01:00
|
|
|
|
_voxUpdatePath = null;
|
2020-04-18 22:24:48 +02:00
|
|
|
|
MessageBox.Show(
|
|
|
|
|
$"Failed to load chart.\n{ex.Message}",
|
|
|
|
|
"Error",
|
|
|
|
|
MessageBoxButtons.OK,
|
|
|
|
|
MessageBoxIcon.Error
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnMainDxButtonClick(object sender, EventArgs e)
|
|
|
|
|
{
|
2023-01-06 14:58:29 +01:00
|
|
|
|
LoadAudio();
|
2020-04-18 22:24:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnPreview2DXClick(object sender, EventArgs e)
|
|
|
|
|
{
|
2023-01-06 14:58:29 +01:00
|
|
|
|
LoadAudio(true);
|
2020-04-18 22:24:48 +02:00
|
|
|
|
}
|
2023-01-06 14:58:29 +01:00
|
|
|
|
|
|
|
|
|
private void OnAddRadarDataButtonClick(object sender, EventArgs e)
|
2020-04-18 22:24:48 +02:00
|
|
|
|
{
|
2023-01-06 14:58:29 +01:00
|
|
|
|
RadarGroupBox.Visible = true;
|
|
|
|
|
Height += RadarGroupBox.Height - AddRadarDataButton.Height;
|
2020-04-18 22:24:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnJacketPictureBoxClick(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (Result.Jacket == null)
|
|
|
|
|
{
|
2023-01-06 14:58:29 +01:00
|
|
|
|
string jacket = $"{AssetManager.GetJacketPath(_header, Result.Difficulty)}_b.png";
|
2020-04-18 22:24:48 +02:00
|
|
|
|
if (!File.Exists(jacket))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
using (var image = Image.FromFile(jacket))
|
|
|
|
|
using (var viewer = new JacketViewerForm(image))
|
|
|
|
|
viewer.ShowDialog();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
using (var viewer = new JacketViewerForm(Result.Jacket))
|
|
|
|
|
viewer.ShowDialog();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnCancelEditButtonClick(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
DialogResult = DialogResult.Cancel;
|
|
|
|
|
Close();
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-06 14:58:29 +01:00
|
|
|
|
private void OnLevelEditorFormFormClosing(object sender, FormClosingEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-18 22:24:48 +02:00
|
|
|
|
private void OnSaveEditButtonClick(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
string voxData = string.Empty;
|
2023-01-06 14:58:29 +01:00
|
|
|
|
if (!string.IsNullOrEmpty(_voxUpdatePath))
|
2020-04-18 22:24:48 +02:00
|
|
|
|
{
|
2023-01-06 14:58:29 +01:00
|
|
|
|
if (File.Exists(_voxUpdatePath))
|
|
|
|
|
voxData = File.ReadAllText(_voxUpdatePath, Encoding.GetEncoding("Shift_JIS"));
|
2020-04-18 22:24:48 +02:00
|
|
|
|
else
|
2023-01-06 14:58:29 +01:00
|
|
|
|
throw new FileNotFoundException("Vox file not found", _voxUpdatePath);
|
2020-04-18 22:24:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VoxChart voxChart = null;
|
2023-01-06 14:58:29 +01:00
|
|
|
|
if (_kshUpdate != null)
|
2020-04-18 22:24:48 +02:00
|
|
|
|
{
|
|
|
|
|
voxChart = new VoxChart();
|
2023-01-06 14:58:29 +01:00
|
|
|
|
voxChart.Import(_kshUpdate);
|
2020-04-18 22:24:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2023-01-06 14:58:29 +01:00
|
|
|
|
if (!string.IsNullOrEmpty(_audioMainUpdatePath))
|
2020-04-18 22:24:48 +02:00
|
|
|
|
{
|
2023-01-06 14:58:29 +01:00
|
|
|
|
if (File.Exists(_audioMainUpdatePath))
|
2020-04-18 22:24:48 +02:00
|
|
|
|
{
|
|
|
|
|
string tmp = Path.Combine(
|
|
|
|
|
Path.GetTempPath(),
|
2023-01-06 14:58:29 +01:00
|
|
|
|
$"{Path.GetRandomFileName()}{new FileInfo(_audioMainUpdatePath).Extension}"
|
2020-04-18 22:24:48 +02:00
|
|
|
|
);
|
|
|
|
|
|
2023-01-06 14:58:29 +01:00
|
|
|
|
File.Copy(_audioMainUpdatePath, tmp);
|
|
|
|
|
_audioMainUpdatePath = tmp;
|
2020-04-18 22:24:48 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
2023-01-06 14:58:29 +01:00
|
|
|
|
throw new FileNotFoundException("Music file not found", _audioMainUpdatePath);
|
2020-04-18 22:24:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2023-01-06 14:58:29 +01:00
|
|
|
|
if (!string.IsNullOrEmpty(_audioPreviewUpdatePath))
|
2020-04-18 22:24:48 +02:00
|
|
|
|
{
|
2023-01-06 14:58:29 +01:00
|
|
|
|
if (File.Exists(_audioPreviewUpdatePath))
|
2020-04-18 22:24:48 +02:00
|
|
|
|
{
|
|
|
|
|
string tmp = Path.Combine(
|
|
|
|
|
Path.GetTempPath(),
|
2023-01-06 14:58:29 +01:00
|
|
|
|
$"{Path.GetRandomFileName()}{new FileInfo(_audioPreviewUpdatePath).Extension}"
|
2020-04-18 22:24:48 +02:00
|
|
|
|
);
|
|
|
|
|
|
2023-01-06 14:58:29 +01:00
|
|
|
|
File.Copy(_audioPreviewUpdatePath, tmp);
|
|
|
|
|
_audioPreviewUpdatePath = tmp;
|
2020-04-18 22:24:48 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
2023-01-06 14:58:29 +01:00
|
|
|
|
throw new FileNotFoundException("Preview file not found", _audioPreviewUpdatePath);
|
2020-04-18 22:24:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2023-01-06 14:58:29 +01:00
|
|
|
|
if (Result.Jacket != null || voxChart != null || !string.IsNullOrEmpty(voxData) || !string.IsNullOrEmpty(_audioMainUpdatePath) || !string.IsNullOrEmpty(_audioPreviewUpdatePath))
|
2020-04-18 22:24:48 +02:00
|
|
|
|
{
|
2023-01-06 14:58:29 +01:00
|
|
|
|
Action = () =>
|
2020-04-18 22:24:48 +02:00
|
|
|
|
{
|
|
|
|
|
if (Result.Jacket != null)
|
2023-01-06 14:58:29 +01:00
|
|
|
|
AssetManager.ImportJacket(_header, Result.Difficulty, Result.Jacket);
|
2020-04-18 22:24:48 +02:00
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(voxData))
|
2023-01-06 14:58:29 +01:00
|
|
|
|
AssetManager.ImportVox(_header, Result.Difficulty, _voxUpdatePath);
|
2020-04-18 22:24:48 +02:00
|
|
|
|
else if (voxChart != null)
|
2023-01-06 14:58:29 +01:00
|
|
|
|
AssetManager.ImportVox(_header, Result.Difficulty, voxChart);
|
2020-04-18 22:24:48 +02:00
|
|
|
|
|
2023-01-06 14:58:29 +01:00
|
|
|
|
if (File.Exists(_audioMainUpdatePath))
|
|
|
|
|
{
|
|
|
|
|
var audioFormat = _audioMainUpdatePath.ToLower().EndsWith(".s3v") ? AudioFormat.S3V : AudioFormat.Iidx;
|
|
|
|
|
AssetManager.ImportAudio(_audioMainUpdatePath, _header, Result.Difficulty, AudioImportOptions.WithFormat(audioFormat));
|
|
|
|
|
}
|
2020-04-18 22:24:48 +02:00
|
|
|
|
|
2023-01-06 14:58:29 +01:00
|
|
|
|
if (File.Exists(_audioPreviewUpdatePath))
|
|
|
|
|
{
|
|
|
|
|
var audioFormat = _audioPreviewUpdatePath.ToLower().EndsWith(".s3v") ? AudioFormat.S3V : AudioFormat.Iidx;
|
|
|
|
|
AssetManager.ImportAudio(_audioPreviewUpdatePath, _header, Result.Difficulty, AudioImportOptions.WithFormat(audioFormat).AsPreview());
|
|
|
|
|
}
|
|
|
|
|
};
|
2020-04-18 22:24:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Result.Level = (int)LevelNumericBox.Value;
|
|
|
|
|
Result.Effector = EffectorTextBox.Text;
|
|
|
|
|
Result.Illustrator = IllustratorTextBox.Text;
|
2023-01-06 14:58:29 +01:00
|
|
|
|
if (RadarGroupBox.Visible)
|
|
|
|
|
{
|
|
|
|
|
Result.Radar = new VoxLevelRadar
|
|
|
|
|
{
|
|
|
|
|
Notes = (byte)NotesNumericUpDown.Value,
|
|
|
|
|
Peak = (byte)PeakNumericUpDown.Value,
|
|
|
|
|
Lasers = (byte)TsumamiNumericUpDown.Value,
|
|
|
|
|
Tricky = (byte)TrickyNumericUpDown.Value,
|
|
|
|
|
HandTrip = (byte)HandTripNumericUpDown.Value,
|
|
|
|
|
OneHand = (byte)OneHandNumericUpDown.Value,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-18 22:24:48 +02:00
|
|
|
|
|
2023-01-06 14:58:29 +01:00
|
|
|
|
DialogResult = DialogResult.OK;
|
2020-04-18 22:24:48 +02:00
|
|
|
|
Close();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-01-06 14:58:29 +01:00
|
|
|
|
|
|
|
|
|
private void LoadAudio(bool preview = false)
|
|
|
|
|
{
|
|
|
|
|
using (var browser = new OpenFileDialog())
|
|
|
|
|
{
|
|
|
|
|
browser.Filter = "All supported formats|*.2dx;*.s3v;*.asf;*.wav;*.ogg;*.mp3;*.flac|BEMANI Music Files|*.2dx;*.s3v|Music Files|*.wav;*.ogg;*.mp3;*.flac;*.asf";
|
|
|
|
|
browser.CheckFileExists = true;
|
|
|
|
|
|
|
|
|
|
if (browser.ShowDialog() == DialogResult.OK)
|
|
|
|
|
{
|
|
|
|
|
if (!preview)
|
|
|
|
|
_audioMainUpdatePath = browser.FileName;
|
|
|
|
|
else
|
|
|
|
|
_audioPreviewUpdatePath = browser.FileName;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-04-18 22:24:48 +02:00
|
|
|
|
|
|
|
|
|
private void LoadJacket()
|
|
|
|
|
{
|
|
|
|
|
if (Result.Jacket != null)
|
|
|
|
|
{
|
|
|
|
|
JacketPictureBox.Image = Result.Jacket;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
2023-01-06 14:58:29 +01:00
|
|
|
|
string currentJacket = $"{AssetManager.GetJacketPath(_header, Result.Difficulty)}_s.png";
|
|
|
|
|
string defaultJacket = $"{AssetManager.GetDefaultJacketPath(_header)}_s.png";
|
2020-04-18 22:24:48 +02:00
|
|
|
|
if (File.Exists(currentJacket))
|
|
|
|
|
{
|
|
|
|
|
using (var image = Image.FromFile(currentJacket))
|
|
|
|
|
JacketPictureBox.Image = new Bitmap(image);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (File.Exists(defaultJacket))
|
|
|
|
|
{
|
|
|
|
|
using (var image = Image.FromFile(defaultJacket))
|
|
|
|
|
JacketPictureBox.Image = new Bitmap(image);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
JacketPictureBox.Image = DummyJacket;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception)
|
|
|
|
|
{
|
|
|
|
|
JacketPictureBox.Image = DummyJacket;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|