Skip to content

Commit b562217

Browse files
committed
Небольшое улучшение функционала
1 parent bf7d441 commit b562217

File tree

9 files changed

+476
-61
lines changed

9 files changed

+476
-61
lines changed

Editor.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,42 @@ public void CopyAnims(AnimationsContainer omf_1, AnimationsContainer omf_2)
3939
omf_1.RecalcAllAnimIndex();
4040
}
4141

42+
public void CopyAnims(AnimationsContainer omf_1, AnimationsContainer omf_2, List<string> list)
43+
{
44+
omf_1.RecalcAnimNum();
45+
46+
short new_count = (short)omf_1.AnimsCount;
47+
48+
for (int i = 0; i < omf_2.Anims.Count; i++)
49+
{
50+
AnimVector anim = omf_2.Anims[i];
51+
52+
for (int ii = 0; ii < list.Count; ii++)
53+
{
54+
if (anim.MotionName == list[ii])
55+
{
56+
omf_1.AddAnim(anim);
57+
58+
AnimationParams anim_param = omf_2.AnimsParams[i];
59+
60+
anim_param.MotionID = new_count;
61+
62+
if ((omf_1.bone_cont.OGF_V != omf_2.bone_cont.OGF_V) && omf_1.bone_cont.OGF_V == 3)
63+
{
64+
anim_param.MarksCount = 0;
65+
anim_param.m_marks = null;
66+
}
67+
68+
omf_1.AddAnimParams(anim_param);
69+
new_count++;
70+
}
71+
}
72+
}
73+
74+
omf_1.RecalcAnimNum();
75+
omf_1.RecalcAllAnimIndex();
76+
77+
}
4278

4379
public void WriteOMF(BinaryWriter writer, AnimationsContainer omf_file)
4480
{

Form1.Designer.cs

Lines changed: 18 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Form1.cs

Lines changed: 142 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using System.Windows.Forms;
1010
using System.IO;
1111
using System.Text.RegularExpressions;
12+
using System.Globalization;
1213

1314
namespace OMF_Editor
1415
{
@@ -38,6 +39,7 @@ public Form1()
3839
InitButtons();
3940
// Very dirty hack
4041
if (Environment.GetCommandLineArgs().Length > 1) OpenFile(Environment.GetCommandLineArgs()[1]);
42+
4143
}
4244

4345
private void InitButtons()
@@ -63,44 +65,59 @@ private void OpenFile(string filename)
6365
if (Main_OMF != null)
6466
{
6567
bs.DataSource = Main_OMF.AnimsParams;
66-
listBox1.DisplayMember = "Name";
6768
listBox1.DataSource = bs;
69+
listBox1.DisplayMember = "Name";
6870
}
6971
}
7072

71-
private void UpdateList()
72-
{
73-
//listBox1.DisplayMember = "Name";
74-
75-
bs.ResetBindings(false);
76-
77-
}
78-
79-
private void AppendFile(string filename)
73+
AnimationsContainer OpenSecondOMF(string filename)
8074
{
81-
if (Main_OMF == null) OpenFile(filename);
75+
if (Main_OMF == null) return null;
8276

8377
AnimationsContainer new_omf = editor.OpenOMF(filename);
8478

85-
if (new_omf == null) return;
79+
if (new_omf == null) return new_omf;
8680

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

89-
if(error_v==1)
83+
if (error_v == 1)
9084
{
91-
DialogResult result = MessageBox.Show("Скелеты OMF файлов различаются, вы уверены что хотите объединить?", "Внимание!", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
92-
if (DialogResult == DialogResult.No) return;
85+
DialogResult result = GetErrorCode(1);
86+
if (DialogResult == DialogResult.No) return null;
9387
}
94-
else if(error_v == 2)
88+
else if (error_v == 2)
9589
{
96-
MessageBox.Show("Версии OMF отличаются, параметры анимаций будут преобразованы под текущую версию OMF", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
90+
GetErrorCode(2);
9791
}
9892

99-
editor.CopyAnims(Main_OMF, new_omf);
93+
return new_omf;
94+
}
95+
96+
private void UpdateList(bool save_pos = false)
97+
{
98+
int pos = listBox1.SelectedIndex;
99+
bs.ResetBindings(false);
100+
if (save_pos) listBox1.SelectedIndex = pos;
101+
MotionParamsUpdate();
102+
}
103+
104+
private void AppendFile(string filename, List<string> list)
105+
{
106+
AnimationsContainer new_omf = OpenSecondOMF(filename);
107+
if (new_omf == null) return;
108+
editor.CopyAnims(Main_OMF, new_omf, list);
100109
UpdateList();
101110

102111
}
103112

113+
private void AppendFile(string filename)
114+
{
115+
AnimationsContainer new_omf = OpenSecondOMF(filename);
116+
if (new_omf == null) return;
117+
editor.CopyAnims(Main_OMF, new_omf);
118+
UpdateList();
119+
}
120+
104121
private void SaveOMF(AnimationsContainer omf_file, string file_name)
105122
{
106123
using (BinaryWriter writer = new BinaryWriter(File.Create(file_name)))
@@ -112,30 +129,41 @@ private void SaveOMF(AnimationsContainer omf_file, string file_name)
112129
private void button1_Click(object sender, EventArgs e)
113130
{
114131
openFileDialog1.FileName = "";
115-
openFileDialog1.Tag = "Open";
116-
openFileDialog1.ShowDialog();
132+
DialogResult res = openFileDialog1.ShowDialog();
133+
134+
if(res == DialogResult.OK)
135+
{
136+
try
137+
{
138+
OpenFile(openFileDialog1.FileName);
139+
}
140+
catch (Exception exp)
141+
{
142+
MessageBox.Show(exp.ToString());
143+
}
144+
145+
}
117146
}
118147

119148
private void button3_Click(object sender, EventArgs e)
120149
{
121150
openFileDialog1.FileName = "";
122-
openFileDialog1.Tag = "Append";
123-
openFileDialog1.ShowDialog();
124-
}
151+
DialogResult res = openFileDialog1.ShowDialog();
125152

126-
private void openFileDialog1_FileOk(object sender, CancelEventArgs e)
127-
{
128-
try
153+
if (res == DialogResult.OK)
129154
{
130-
if(openFileDialog1.Tag.ToString() == "Open")
131-
OpenFile(openFileDialog1.FileName);
132-
else
155+
try
156+
{
133157
AppendFile(openFileDialog1.FileName);
158+
}
159+
catch (Exception exp)
160+
{
161+
MessageBox.Show(exp.ToString());
162+
}
163+
134164
}
135-
catch (Exception exp)
136-
{
137-
MessageBox.Show(exp.ToString());
138-
}
165+
166+
139167

140168
}
141169

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

152180
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
181+
{
182+
MotionParamsUpdate();
183+
}
184+
185+
private void MotionParamsUpdate()
153186
{
154187
if (Main_OMF == null) return;
155188

@@ -186,10 +219,13 @@ private void TextBoxFilter(object sender, EventArgs e)
186219
case "Falloff": CurrentAnim.Falloff = Convert.ToSingle(current.Text); break;
187220
case "MotionName":
188221
{
222+
if (CurrentAnim.Name == current.Text) return;
189223
CurrentAnim.Name = current.Text;
190224
int index = CurrentAnim.MotionID;
191225
Main_OMF.Anims[index].Name = current.Text;
192-
}break;
226+
UpdateList(true);
227+
}
228+
break;
193229
default: break;
194230
}
195231
}
@@ -218,8 +254,6 @@ private void deleteToolStripMenuItem_Click(object sender, EventArgs e)
218254
private void cloneToolStripMenuItem_Click(object sender, EventArgs e)
219255
{
220256
if (current_index == -1) return;
221-
222-
223257
}
224258

225259
private void listBox1_MouseDown(object sender, MouseEventArgs e)
@@ -231,6 +265,7 @@ private void listBox1_MouseDown(object sender, MouseEventArgs e)
231265
{
232266
contextMenuStrip1.Show(Cursor.Position);
233267
deleteToolStripMenuItem.Enabled = listBox1.Items.Count > 1;
268+
cloneToolStripMenuItem.Enabled = listBox1.Items.Count > 0;
234269
contextMenuStrip1.Visible = true;
235270
current_index = index;
236271
}
@@ -279,5 +314,76 @@ private void checkBox1_CheckedChanged(object sender, EventArgs e)
279314

280315
WriteAllFlags();
281316
}
317+
318+
319+
//Самая простая установка языка, тупо костыли
320+
321+
DialogResult GetErrorCode(int code)
322+
{
323+
bool rus = CultureInfo.CurrentCulture.ToString() == "ru-RU";
324+
325+
if (code == 1)
326+
{
327+
if (rus)
328+
return MessageBox.Show("Скелеты OMF файлов различаются, вы уверены что хотите объединить?", "Внимание!", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
329+
else
330+
return MessageBox.Show("The bones in OMF files are different, are you sure want to merge it?", "Attention!", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
331+
}
332+
else
333+
{
334+
if (rus)
335+
return MessageBox.Show("Версии OMF отличаются, параметры анимаций будут преобразованы под текущую версию OMF", "Инфо", MessageBoxButtons.OK, MessageBoxIcon.Information);
336+
else
337+
return MessageBox.Show("OMF versions are different, animations parameters will be converted to current OMF version", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
338+
}
339+
}
340+
341+
private void listBox1_KeyDown(object sender, KeyEventArgs e)
342+
{
343+
if (e.KeyData == Keys.Delete)
344+
{
345+
if (listBox1.Items.Count == 1) return;
346+
347+
int cur = listBox1.SelectedIndex;
348+
Main_OMF.Anims.RemoveAt(cur);
349+
Main_OMF.AnimsParams.RemoveAt(cur);
350+
Main_OMF.RecalcAllAnimIndex();
351+
Main_OMF.RecalcAnimNum();
352+
UpdateList();
353+
//listBox1.SelectedIndex = current_index - 1;
354+
}
355+
}
356+
357+
private void button4_Click(object sender, EventArgs e)
358+
{
359+
Form2 form = new Form2();
360+
form.Owner = this;
361+
DialogResult result = form.ShowDialog();
362+
if (result == DialogResult.Cancel) form.Dispose();
363+
if (result == DialogResult.OK)
364+
{
365+
366+
if (form.richTextBox1.Text == "") return;
367+
368+
List<string> list = form.richTextBox1.Text.Split('\n').ToList();
369+
form.Dispose();
370+
371+
openFileDialog1.FileName = "";
372+
DialogResult res = openFileDialog1.ShowDialog();
373+
374+
if (res == DialogResult.OK)
375+
{
376+
try
377+
{
378+
AppendFile(openFileDialog1.FileName, list);
379+
}
380+
catch (Exception exp)
381+
{
382+
MessageBox.Show(exp.ToString());
383+
}
384+
385+
}
386+
}
387+
}
282388
}
283389
}

0 commit comments

Comments
 (0)