Skip to content

Commit 29d1943

Browse files
committed
Улучшение управления
1 parent 6fd2b06 commit 29d1943

14 files changed

+1387
-268
lines changed

Form1.Designer.cs

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

Form1.cs

Lines changed: 91 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using System.Text.RegularExpressions;
1212
using System.Globalization;
1313
using System.Reflection;
14+
using System.Resources;
1415

1516
namespace OMF_Editor
1617
{
@@ -32,9 +33,15 @@ public partial class Form1 : Form
3233
//int Idle = 1 << 6;
3334
//int UseWeaponBone = 1 << 7;
3435

36+
bool bKeyIsDown = false;
37+
bool bTextBoxEnabled = false;
38+
3539
int current_index = -1;
3640

3741
List<CheckBox> Boxes = new List<CheckBox>();
42+
List<TextBox> textBoxes = new List<TextBox>();
43+
44+
ResourceManager rm = new ResourceManager(typeof(Form1));
3845

3946
public Form1()
4047
{
@@ -64,6 +71,14 @@ private void InitButtons()
6471
Boxes.Add(checkBox5);
6572
Boxes.Add(checkBox6);
6673
Boxes.Add(checkBox7);
74+
75+
textBoxes.Add(textBox1);
76+
textBoxes.Add(textBox3);
77+
textBoxes.Add(textBox4);
78+
textBoxes.Add(textBox5);
79+
textBoxes.Add(textBox6);
80+
81+
DisableInput();
6782
}
6883

6984
private void OpenFile(string filename)
@@ -90,12 +105,12 @@ AnimationsContainer OpenSecondOMF(string filename)
90105

91106
if (error_v == 1)
92107
{
93-
DialogResult result = GetErrorCode(1);
108+
DialogResult result = MessageBox.Show(rm.GetString("MERGE_ERROR_1"),"Info", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
94109
if (DialogResult == DialogResult.No) return null;
95110
}
96111
else if (error_v == 2)
97112
{
98-
GetErrorCode(2);
113+
MessageBox.Show(rm.GetString("MERGE_ERROR_2"), "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
99114
}
100115

101116
return new_omf;
@@ -145,7 +160,7 @@ private void button1_Click(object sender, EventArgs e)
145160
openFileDialog1.FileName = "";
146161
DialogResult res = openFileDialog1.ShowDialog();
147162

148-
if(res == DialogResult.OK)
163+
if (res == DialogResult.OK)
149164
{
150165
try
151166
{
@@ -177,8 +192,6 @@ private void button3_Click(object sender, EventArgs e)
177192

178193
}
179194

180-
181-
182195
}
183196

184197
private void button2_Click(object sender, EventArgs e)
@@ -193,12 +206,15 @@ private void button2_Click(object sender, EventArgs e)
193206

194207
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
195208
{
196-
MotionParamsUpdate();
209+
if (bTextBoxEnabled && (listBox1.SelectedItems.Count > 1 || Main_OMF == null))
210+
DisableInput();
211+
else if (listBox1.SelectedItems.Count == 1)
212+
MotionParamsUpdate();
197213
}
198214

199215
private void MotionParamsUpdate()
200216
{
201-
if (Main_OMF == null) return;
217+
if(!bTextBoxEnabled) EnableInput();
202218

203219
textBox1.Text = (listBox1.SelectedItem as AnimationParams).Name;
204220
textBox3.Text = (listBox1.SelectedItem as AnimationParams).Speed.ToString();
@@ -209,23 +225,57 @@ private void MotionParamsUpdate()
209225
FillFlagsStates();
210226
}
211227

228+
private void DisableInput()
229+
{
230+
bTextBoxEnabled = false;
231+
foreach (TextBox box in textBoxes)
232+
{
233+
box.Text = "";
234+
box.Enabled = false;
235+
}
236+
237+
foreach (CheckBox box in Boxes)
238+
{
239+
box.Enabled = false;
240+
box.Checked = false;
241+
}
242+
}
243+
244+
private void EnableInput()
245+
{
246+
bTextBoxEnabled = true;
247+
foreach (TextBox box in textBoxes)
248+
{
249+
box.Text = "";
250+
box.Enabled = true;
251+
}
252+
253+
foreach (CheckBox box in Boxes)
254+
{
255+
box.Enabled = true;
256+
}
257+
}
258+
212259
private void TextBoxFilter(object sender, EventArgs e)
213260
{
214-
if (Main_OMF == null) return;
261+
if (Main_OMF == null || !bTextBoxEnabled) return;
215262

216263
TextBox current = sender as TextBox;
217264

218-
string mask = current.Tag.ToString() == "MotionName" ? @"^\w*$" : number_mask;
219-
220-
221-
Match match = Regex.Match(current.Text, mask);
222-
if (!match.Success)
265+
if(bKeyIsDown)
223266
{
224-
int temp = current.SelectionStart;
225-
current.Text = current.Text.Remove(current.SelectionStart-1, 1);
226-
current.SelectionStart = temp-1;
267+
string mask = current.Tag.ToString() == "MotionName" ? @"^[A-Za-z0-9_$]*$" : number_mask;
268+
Match match = Regex.Match(current.Text, mask);
269+
if (!match.Success)
270+
{
271+
int temp = current.SelectionStart;
272+
current.Text = current.Text.Remove(current.SelectionStart - 1, 1);
273+
current.SelectionStart = temp - 1;
274+
}
227275
}
228276

277+
bKeyIsDown = false;
278+
229279
AnimationParams CurrentAnim = listBox1.SelectedItem as AnimationParams;
230280

231281
switch (current.Tag.ToString())
@@ -255,17 +305,13 @@ private void saveFileDialog1_FileOk(object sender, CancelEventArgs e)
255305

256306
private void deleteToolStripMenuItem_Click(object sender, EventArgs e)
257307
{
258-
if (current_index == -1) return;
308+
if(listBox1.SelectedIndex == -1) return;
259309

260-
Main_OMF.Anims.RemoveAt(current_index);
261-
Main_OMF.AnimsParams.RemoveAt(current_index);
310+
Main_OMF.Anims.RemoveAt(listBox1.SelectedIndex);
311+
Main_OMF.AnimsParams.RemoveAt(listBox1.SelectedIndex);
262312
Main_OMF.RecalcAllAnimIndex();
263313
Main_OMF.RecalcAnimNum();
264314
UpdateList();
265-
if (current_index != 0) listBox1.SelectedIndex = current_index - 1;
266-
else listBox1.SelectedIndex = 0;
267-
268-
current_index = -1;
269315
}
270316

271317
private void cloneToolStripMenuItem_Click(object sender, EventArgs e)
@@ -284,12 +330,15 @@ private void listBox1_MouseDown(object sender, MouseEventArgs e)
284330
deleteToolStripMenuItem.Enabled = listBox1.Items.Count > 1;
285331
cloneToolStripMenuItem.Enabled = listBox1.Items.Count > 0;
286332
contextMenuStrip1.Visible = true;
287-
current_index = index;
333+
334+
listBox1.SelectedIndex = index;
335+
336+
//current_index = index;
288337
}
289338
else
290339
{
291340
contextMenuStrip1.Visible = false;
292-
current_index = -1;
341+
//current_index = -1;
293342
}
294343
}
295344

@@ -332,42 +381,27 @@ private void checkBox1_CheckedChanged(object sender, EventArgs e)
332381
WriteAllFlags();
333382
}
334383

335-
336-
//Самая простая установка языка, тупо костыли
337-
338-
DialogResult GetErrorCode(int code)
339-
{
340-
bool rus = CultureInfo.CurrentCulture.ToString() == "ru-RU";
341-
342-
if (code == 1)
343-
{
344-
if (rus)
345-
return MessageBox.Show("Скелеты OMF файлов различаются, вы уверены что хотите объединить?", "Внимание!", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
346-
else
347-
return MessageBox.Show("The bones in OMF files are different, are you sure want to merge it?", "Attention!", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
348-
}
349-
else
350-
{
351-
if (rus)
352-
return MessageBox.Show("Версии OMF отличаются, параметры анимаций будут преобразованы под текущую версию OMF", "Инфо", MessageBoxButtons.OK, MessageBoxIcon.Information);
353-
else
354-
return MessageBox.Show("OMF versions are different, animations parameters will be converted to current OMF version", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
355-
}
356-
}
357-
358384
private void listBox1_KeyDown(object sender, KeyEventArgs e)
359385
{
360386
if (e.KeyData == Keys.Delete)
361387
{
362388
if (listBox1.Items.Count == 1) return;
389+
390+
ListBox.SelectedIndexCollection _list = listBox1.SelectedIndices;
391+
int count = _list.Count;
392+
393+
while (count > 0 && Main_OMF.AnimsParams.Count > 1)
394+
{
395+
int i = _list[count - 1];
396+
Main_OMF.AnimsParams.RemoveAt(i);
397+
Main_OMF.Anims.RemoveAt(i);
398+
--count;
399+
400+
}
363401

364-
int cur = listBox1.SelectedIndex;
365-
Main_OMF.Anims.RemoveAt(cur);
366-
Main_OMF.AnimsParams.RemoveAt(cur);
367402
Main_OMF.RecalcAllAnimIndex();
368403
Main_OMF.RecalcAnimNum();
369404
UpdateList();
370-
//listBox1.SelectedIndex = current_index - 1;
371405
}
372406
}
373407

@@ -409,5 +443,10 @@ private void button5_Click(object sender, EventArgs e)
409443

410444
Main_OMF.GunslingerRepair();
411445
}
446+
447+
private void textBox1_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
448+
{
449+
bKeyIsDown = true;
450+
}
412451
}
413452
}

0 commit comments

Comments
 (0)