Skip to content

Commit

Permalink
Небольшое улучшение функционала
Browse files Browse the repository at this point in the history
  • Loading branch information
mortany committed May 5, 2020
1 parent bf7d441 commit b562217
Show file tree
Hide file tree
Showing 9 changed files with 476 additions and 61 deletions.
36 changes: 36 additions & 0 deletions Editor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,42 @@ public void CopyAnims(AnimationsContainer omf_1, AnimationsContainer omf_2)
omf_1.RecalcAllAnimIndex();
}

public void CopyAnims(AnimationsContainer omf_1, AnimationsContainer omf_2, List<string> list)
{
omf_1.RecalcAnimNum();

short new_count = (short)omf_1.AnimsCount;

for (int i = 0; i < omf_2.Anims.Count; i++)
{
AnimVector anim = omf_2.Anims[i];

for (int ii = 0; ii < list.Count; ii++)
{
if (anim.MotionName == list[ii])
{
omf_1.AddAnim(anim);

AnimationParams anim_param = omf_2.AnimsParams[i];

anim_param.MotionID = new_count;

if ((omf_1.bone_cont.OGF_V != omf_2.bone_cont.OGF_V) && omf_1.bone_cont.OGF_V == 3)
{
anim_param.MarksCount = 0;
anim_param.m_marks = null;
}

omf_1.AddAnimParams(anim_param);
new_count++;
}
}
}

omf_1.RecalcAnimNum();
omf_1.RecalcAllAnimIndex();

}

public void WriteOMF(BinaryWriter writer, AnimationsContainer omf_file)
{
Expand Down
23 changes: 18 additions & 5 deletions Form1.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

178 changes: 142 additions & 36 deletions Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Windows.Forms;
using System.IO;
using System.Text.RegularExpressions;
using System.Globalization;

namespace OMF_Editor
{
Expand Down Expand Up @@ -38,6 +39,7 @@ public Form1()
InitButtons();
// Very dirty hack
if (Environment.GetCommandLineArgs().Length > 1) OpenFile(Environment.GetCommandLineArgs()[1]);

}

private void InitButtons()
Expand All @@ -63,44 +65,59 @@ private void OpenFile(string filename)
if (Main_OMF != null)
{
bs.DataSource = Main_OMF.AnimsParams;
listBox1.DisplayMember = "Name";
listBox1.DataSource = bs;
listBox1.DisplayMember = "Name";
}
}

private void UpdateList()
{
//listBox1.DisplayMember = "Name";

bs.ResetBindings(false);

}

private void AppendFile(string filename)
AnimationsContainer OpenSecondOMF(string filename)
{
if (Main_OMF == null) OpenFile(filename);
if (Main_OMF == null) return null;

AnimationsContainer new_omf = editor.OpenOMF(filename);

if (new_omf == null) return;
if (new_omf == null) return new_omf;

int error_v = editor.CompareOMF(Main_OMF, new_omf);

if(error_v==1)
if (error_v == 1)
{
DialogResult result = MessageBox.Show("Скелеты OMF файлов различаются, вы уверены что хотите объединить?", "Внимание!", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (DialogResult == DialogResult.No) return;
DialogResult result = GetErrorCode(1);
if (DialogResult == DialogResult.No) return null;
}
else if(error_v == 2)
else if (error_v == 2)
{
MessageBox.Show("Версии OMF отличаются, параметры анимаций будут преобразованы под текущую версию OMF", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
GetErrorCode(2);
}

editor.CopyAnims(Main_OMF, new_omf);
return new_omf;
}

private void UpdateList(bool save_pos = false)
{
int pos = listBox1.SelectedIndex;
bs.ResetBindings(false);
if (save_pos) listBox1.SelectedIndex = pos;
MotionParamsUpdate();
}

private void AppendFile(string filename, List<string> list)
{
AnimationsContainer new_omf = OpenSecondOMF(filename);
if (new_omf == null) return;
editor.CopyAnims(Main_OMF, new_omf, list);
UpdateList();

}

private void AppendFile(string filename)
{
AnimationsContainer new_omf = OpenSecondOMF(filename);
if (new_omf == null) return;
editor.CopyAnims(Main_OMF, new_omf);
UpdateList();
}

private void SaveOMF(AnimationsContainer omf_file, string file_name)
{
using (BinaryWriter writer = new BinaryWriter(File.Create(file_name)))
Expand All @@ -112,30 +129,41 @@ private void SaveOMF(AnimationsContainer omf_file, string file_name)
private void button1_Click(object sender, EventArgs e)
{
openFileDialog1.FileName = "";
openFileDialog1.Tag = "Open";
openFileDialog1.ShowDialog();
DialogResult res = openFileDialog1.ShowDialog();

if(res == DialogResult.OK)
{
try
{
OpenFile(openFileDialog1.FileName);
}
catch (Exception exp)
{
MessageBox.Show(exp.ToString());
}

}
}

private void button3_Click(object sender, EventArgs e)
{
openFileDialog1.FileName = "";
openFileDialog1.Tag = "Append";
openFileDialog1.ShowDialog();
}
DialogResult res = openFileDialog1.ShowDialog();

private void openFileDialog1_FileOk(object sender, CancelEventArgs e)
{
try
if (res == DialogResult.OK)
{
if(openFileDialog1.Tag.ToString() == "Open")
OpenFile(openFileDialog1.FileName);
else
try
{
AppendFile(openFileDialog1.FileName);
}
catch (Exception exp)
{
MessageBox.Show(exp.ToString());
}

}
catch (Exception exp)
{
MessageBox.Show(exp.ToString());
}



}

Expand All @@ -150,6 +178,11 @@ private void button2_Click(object sender, EventArgs e)
}

private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
MotionParamsUpdate();
}

private void MotionParamsUpdate()
{
if (Main_OMF == null) return;

Expand Down Expand Up @@ -186,10 +219,13 @@ private void TextBoxFilter(object sender, EventArgs e)
case "Falloff": CurrentAnim.Falloff = Convert.ToSingle(current.Text); break;
case "MotionName":
{
if (CurrentAnim.Name == current.Text) return;
CurrentAnim.Name = current.Text;
int index = CurrentAnim.MotionID;
Main_OMF.Anims[index].Name = current.Text;
}break;
UpdateList(true);
}
break;
default: break;
}
}
Expand Down Expand Up @@ -218,8 +254,6 @@ private void deleteToolStripMenuItem_Click(object sender, EventArgs e)
private void cloneToolStripMenuItem_Click(object sender, EventArgs e)
{
if (current_index == -1) return;


}

private void listBox1_MouseDown(object sender, MouseEventArgs e)
Expand All @@ -231,6 +265,7 @@ private void listBox1_MouseDown(object sender, MouseEventArgs e)
{
contextMenuStrip1.Show(Cursor.Position);
deleteToolStripMenuItem.Enabled = listBox1.Items.Count > 1;
cloneToolStripMenuItem.Enabled = listBox1.Items.Count > 0;
contextMenuStrip1.Visible = true;
current_index = index;
}
Expand Down Expand Up @@ -279,5 +314,76 @@ private void checkBox1_CheckedChanged(object sender, EventArgs e)

WriteAllFlags();
}


//Самая простая установка языка, тупо костыли

DialogResult GetErrorCode(int code)
{
bool rus = CultureInfo.CurrentCulture.ToString() == "ru-RU";

if (code == 1)
{
if (rus)
return MessageBox.Show("Скелеты OMF файлов различаются, вы уверены что хотите объединить?", "Внимание!", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
else
return MessageBox.Show("The bones in OMF files are different, are you sure want to merge it?", "Attention!", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
}
else
{
if (rus)
return MessageBox.Show("Версии OMF отличаются, параметры анимаций будут преобразованы под текущую версию OMF", "Инфо", MessageBoxButtons.OK, MessageBoxIcon.Information);
else
return MessageBox.Show("OMF versions are different, animations parameters will be converted to current OMF version", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}

private void listBox1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyData == Keys.Delete)
{
if (listBox1.Items.Count == 1) return;

int cur = listBox1.SelectedIndex;
Main_OMF.Anims.RemoveAt(cur);
Main_OMF.AnimsParams.RemoveAt(cur);
Main_OMF.RecalcAllAnimIndex();
Main_OMF.RecalcAnimNum();
UpdateList();
//listBox1.SelectedIndex = current_index - 1;
}
}

private void button4_Click(object sender, EventArgs e)
{
Form2 form = new Form2();
form.Owner = this;
DialogResult result = form.ShowDialog();
if (result == DialogResult.Cancel) form.Dispose();
if (result == DialogResult.OK)
{

if (form.richTextBox1.Text == "") return;

List<string> list = form.richTextBox1.Text.Split('\n').ToList();
form.Dispose();

openFileDialog1.FileName = "";
DialogResult res = openFileDialog1.ShowDialog();

if (res == DialogResult.OK)
{
try
{
AppendFile(openFileDialog1.FileName, list);
}
catch (Exception exp)
{
MessageBox.Show(exp.ToString());
}

}
}
}
}
}
Loading

0 comments on commit b562217

Please sign in to comment.