-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMainForm.cs
485 lines (457 loc) · 18.2 KB
/
MainForm.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
using Li.krkrfgformat;
using Li.Drawing;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Li.krkrfgformat
{
public partial class MainForm : Form
{
//public event MainFormImageChangeValue MainFormImageChange;
private const string name = "合成的文件名字:";
private string examplePicFullName = "";
private string saveFullPath = "";
private string saveFolderName = "输出合成";
private int SelectedListBoxCount
{
get;
set;
}
private int HaveItemListBoxCount
{
get;
set;
}
private string RuleFilePath
{
get;
set;
}
private ImageViewForm iv;
public MainForm()
{
InitializeComponent();
toolStrip1.Items.Add(new ToolStripControlHost(checkBox2));
new DataFormat();
}
private void Form1_Load(object sender, EventArgs e)
{
toolTip1.SetToolTip(checkBox2, "如果默认的合成显示有问题,可以尝试勾选这个。");
toolTip1.SetToolTip(pictureBox1, "双击大窗口查看。");
SelectedListBoxCount = 0;
HaveItemListBoxCount = 0;
toolStripStatusLabel1.Text = "合成的文件名字:";
RuleFilePath = "";
examplePicFullName = "";
saveFullPath = "";
//pictureBox1.BackgroundImage = Picture.CreatBackImage(pictureBox1.Width, pictureBox1.Height);
}
private void SelectTextFile_Click(object sender, EventArgs e)
{
OpenFileDialog openFileDialog = new OpenFileDialog
{
InitialDirectory = (TextPatchShow.Text.Equals(string.Empty) ? "C:\\" : Path.GetFullPath(TextPatchShow.Text)),
Filter = "文本文档(*.txt)|*.txt|json文件(*.json)|*.json|所有文件 (*.*)|*.*",
FilterIndex = 1,
RestoreDirectory = false
};
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
if (!Path.GetExtension(openFileDialog.FileName).Equals(".txt") && !Path.GetExtension(openFileDialog.FileName).Equals(".json"))
{
MessageBox.Show("不是txt或者json文件。", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
else
{
RuleFilePath = openFileDialog.FileName;
DataFormat.AddText(openFileDialog.FileName);
TextPatchShow.Text = openFileDialog.FileName;
}
}
DataFormat.AddText(TextPatchShow.Text);
}
private void FormatOne_Click(object sender, EventArgs e)
{
try
{
if (DataFormat.NewPicture != null)
{
if (!Directory.Exists(saveFullPath + "\\" + saveFolderName + "\\"))
{
Directory.CreateDirectory(saveFullPath + "\\" + saveFolderName + "\\");
}
DataFormat.NewPicture.Save(saveFullPath + "\\" + saveFolderName + "\\" + DataFormat.SaveFileName + ".png", ImageFormat.Png);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void ListBox_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
{
e.Effect = DragDropEffects.All;
}
else
{
e.Effect = DragDropEffects.None;
}
}
private void ListBox_DragDrop(object sender, DragEventArgs e)
{
ListBox listBox = sender as ListBox;
if (listBox.Items.Count != 0)
{
HaveItemListBoxCount--;
}
listBox.Items.Clear();
string[] array = (string[])e.Data.GetData(DataFormats.FileDrop);
foreach (string path in array)
{
if (Path.GetExtension(path).ToLower() == ".png"|| Path.GetExtension(path).ToLower() == ".tlg")
{
if (string.IsNullOrEmpty(examplePicFullName))
{
examplePicFullName = path;
}
if (string.IsNullOrEmpty(saveFullPath))
{
saveFullPath = Path.GetDirectoryName(path);
savePathBox.Text = saveFullPath;
}
listBox.Items.Add(Path.GetFileNameWithoutExtension(path));
}
}
if (listBox.Items.Count != 0)
{
HaveItemListBoxCount++;
}
//依次打开listbox的限制
switch (HaveItemListBoxCount)
{
case 1:
fgPart_2.BackColor = SystemColors.Window;
fgPart_2.AllowDrop = true;
break;
case 2:
fgPart_3.BackColor = SystemColors.Window;
fgPart_3.AllowDrop = true;
break;
case 3:
fgPart_4.BackColor = SystemColors.Window;
fgPart_4.AllowDrop = true;
break;
case 4:
fgPart_5.BackColor = SystemColors.Window;
fgPart_5.AllowDrop = true;
break;
case 5:
fgPart_6.BackColor = SystemColors.Window;
fgPart_6.AllowDrop = true;
break;
case 6:
fgPart_7.BackColor = SystemColors.Window;
fgPart_7.AllowDrop = true;
break;
case 7:
fgPart_8.BackColor = SystemColors.Window;
fgPart_8.AllowDrop = true;
break;
case 8:
fgPart_9.BackColor = SystemColors.Window;
fgPart_9.AllowDrop = true;
break;
case 9:
fgPart_10.BackColor = SystemColors.Window;
fgPart_10.AllowDrop = true;
break;
case 10:
fgPart_11.BackColor = SystemColors.Window;
fgPart_11.AllowDrop = true;
break;
case 11:
fgPart_12.BackColor = SystemColors.Window;
fgPart_12.AllowDrop = true;
break;
}
}
private void ListBox_MouseClick(object sender, MouseEventArgs e)
{
ListBox listBox = sender as ListBox;
int key = Convert.ToInt32(listBox.Name.Split('_')[1]);
int num2 = listBox.SelectedIndex = listBox.IndexFromPoint(e.X, e.Y);
//尝试自行寻找规则文件。
if (string.IsNullOrEmpty(RuleFilePath))
{
try
{
TryToFindRuleFile();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
finally
{
if (string.IsNullOrEmpty(RuleFilePath))
{
SelectTextFile_Click(sender, e);
}
}
}
if (listBox.SelectedIndex != -1)
{
if (File.Exists(Path.GetDirectoryName(RuleFilePath) + "\\" + listBox.SelectedItem.ToString() + ".png"))
{
DataFormat.AddPicture(key, Path.GetDirectoryName(RuleFilePath) + "\\" + listBox.SelectedItem.ToString() + ".png");
}else if (File.Exists(Path.GetDirectoryName(RuleFilePath) + "\\" + listBox.SelectedItem.ToString() + ".tlg"))
{
DataFormat.AddPicture(key, Path.GetDirectoryName(RuleFilePath) + "\\" + listBox.SelectedItem.ToString() + ".tlg");
}
}
DataFormat.NowFormat();
if (DataFormat.NewPicture.Width <= pictureBox1.Width && DataFormat.NewPicture.Height <= pictureBox1.Height)
{
pictureBox1.SizeMode = PictureBoxSizeMode.CenterImage;
}
else
{
pictureBox1.SizeMode = PictureBoxSizeMode.Zoom;
}
pictureBox1.Image = DataFormat.NewPicture;
if (!(iv == null || iv.IsDisposed))
{
iv.PictureChange((Bitmap)pictureBox1.Image);
}
toolStripStatusLabel1.Text = "合成的文件名字:" + DataFormat.SaveFileName;
}
private void ListBox_SelectedIndexChanged(object sender, EventArgs e)
{
ListBox listBox = sender as ListBox;
int key = Convert.ToInt32(listBox.Name.Split('_')[1]);
if (listBox.SelectedIndex != -1)
{
if (File.Exists(Path.GetDirectoryName(RuleFilePath) + "\\" + listBox.SelectedItem.ToString() + ".png"))
{
DataFormat.AddPicture(key, Path.GetDirectoryName(RuleFilePath) + "\\" + listBox.SelectedItem.ToString() + ".png");
}
else if (File.Exists(Path.GetDirectoryName(RuleFilePath) + "\\" + listBox.SelectedItem.ToString() + ".tlg"))
{
DataFormat.AddPicture(key, Path.GetDirectoryName(RuleFilePath) + "\\" + listBox.SelectedItem.ToString() + ".tlg");
}
}
DataFormat.NowFormat();
if (DataFormat.NewPicture.Width <= pictureBox1.Width && DataFormat.NewPicture.Height <= pictureBox1.Height)
{
pictureBox1.SizeMode = PictureBoxSizeMode.CenterImage;
}
else
{
pictureBox1.SizeMode = PictureBoxSizeMode.Zoom;
}
pictureBox1.Image = DataFormat.NewPicture;
if (!(iv == null || iv.IsDisposed))
{
iv.PictureChange((Bitmap)pictureBox1.Image);
}
toolStripStatusLabel1.Text = "合成的文件名字:" + DataFormat.SaveFileName;
}
private void TryToFindRuleFile()
{
string directoryName = Path.GetDirectoryName(examplePicFullName);
string[] array = Path.GetFileNameWithoutExtension(examplePicFullName).Split('_');
string text = array[0];
for (int i = 1; i < array.Length - 1; i++)
{
text = text + "_" + array[i];
}
string str = directoryName + "\\" + text;
string text2 = "";
if (File.Exists(str + ".txt"))
{
text2 = str + ".txt";
}
else if (File.Exists(str + ".json"))
{
text2 = str + ".json";
}
RuleFilePath = text2;
TextPatchShow.Text = text2;
DataFormat.AddText(text2);
}
private void ToolStripButton2_Click(object sender, EventArgs e)
{
foreach (Control control3 in freeMix1.Controls)
{
if (control3 is ListBox)
{
(control3 as ListBox).ClearSelected();
}
}
foreach (Control control4 in freeMix2.Controls)
{
if (control4 is ListBox)
{
(control4 as ListBox).ClearSelected();
}
}
pictureBox1.Image = null;
DataFormat.NewPicture.Dispose();
DataFormat.Pictures.Clear();
toolStripStatusLabel1.Text = "合成的文件名字:";
if (!(iv == null || iv.IsDisposed))
{ iv.ClearForm(); }
GC.Collect();
}
private void ToolStripButton1_Click(object sender, EventArgs e)
{
foreach (Control control3 in freeMix1.Controls)
{
if (control3 is ListBox)
{
ListBox listBox = control3 as ListBox;
listBox.Items.Clear();
listBox.ClearSelected();
if (listBox.Name != "fgPart_1")
{
listBox.BackColor = SystemColors.Control;
listBox.AllowDrop = false;
}
}
}
foreach (Control control4 in freeMix2.Controls)
{
if (control4 is ListBox)
{
ListBox obj = control4 as ListBox;
obj.Items.Clear();
obj.ClearSelected();
obj.BackColor = SystemColors.Control;
obj.AllowDrop = false;
}
}
RuleFilePath = "";
TextPatchShow.Clear();
savePathBox.Clear();
saveFullPath = "";
toolStripStatusLabel1.Text = "合成的文件名字:";
examplePicFullName = "";
checkBox2.Checked = false;
DataFormat.NewPicture = null;
pictureBox1.Image = null;
if (!(iv == null || iv.IsDisposed))
{ iv.Close(); }
DataFormat.TextDatas = null;
DataFormat.FilePatch = "";
DataFormat.SaveFileName = "";
DataFormat.Pictures.Clear();
SelectedListBoxCount = 0;
HaveItemListBoxCount = 0;
GC.Collect();
}
private void ToolStripButton3_Click(object sender, EventArgs e)
{
MessageBox.Show(
"从左往右,从上往下,依次为图片叠加的最底层到最高层。\n" +
"第二页的规则同上。\n" +
"\n" +
"现由于Xmoe的工具自身原因,部分解出来的json有问题,\n" +
"会导致报错,请重启工具。\n" +
"\n" +
"坐标文件支持自己选择,也支持自动选择。\n" +
"前提是规则跟图片在一个文件夹, 没在一起的会报错甚至崩溃。\n" +
"\n" +
"寻找文件是根据坐标文件名字在同一目录寻找的,方式为【[文件名]_[代号]】。\n" +
"如果有不同于坐标文件的图片在里面会炸。\n" +
"\n" +
"更多问题以及bug以后会更新以及修复。\n" +
"\n" +
"双击浏览窗口可以大窗口查看。\n" +
"\n" +
"联系:inabameguru@vip.qq.com", "帮助", MessageBoxButtons.OK);
}
private void OpenOutFolder_Click(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(saveFullPath))
{
string arguments = saveFullPath + "\\" + saveFolderName;
Process.Start("explorer.exe", arguments);
}
}
private void SaveFolderPatch_Click(object sender, EventArgs e)
{
FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog();
folderBrowserDialog.ShowDialog();
savePathBox.Text = folderBrowserDialog.SelectedPath;
saveFullPath = folderBrowserDialog.SelectedPath;
}
private void CheckBox2_CheckedChanged(object sender, EventArgs e)
{
if (checkBox2.Checked)
{
DataFormat.usingSizeOnly = true;
if (DataFormat.Pictures.Count != 0)
{
DataFormat.NowFormat();
if (DataFormat.NewPicture.Width <= pictureBox1.Width && DataFormat.NewPicture.Height <= pictureBox1.Height)
{
pictureBox1.SizeMode = PictureBoxSizeMode.CenterImage;
}
else
{
pictureBox1.SizeMode = PictureBoxSizeMode.Zoom;
}
pictureBox1.Image = DataFormat.NewPicture;
if (!(iv == null || iv.IsDisposed))
{
iv.PictureChange((Bitmap)pictureBox1.Image);
}
}
return;
}
DataFormat.usingSizeOnly = false;
if (DataFormat.Pictures.Count != 0)
{
DataFormat.NowFormat();
if (DataFormat.NewPicture.Width <= pictureBox1.Width && DataFormat.NewPicture.Height <= pictureBox1.Height)
{
pictureBox1.SizeMode = PictureBoxSizeMode.CenterImage;
}
else
{
pictureBox1.SizeMode = PictureBoxSizeMode.Zoom;
}
pictureBox1.Image = DataFormat.NewPicture;
}
}
private void PictureBox1_DoubleClick(object sender, EventArgs e)
{
if (DataFormat.NewPicture != null)
{
if (iv == null || iv.IsDisposed)
{
iv = new ImageViewForm
{
Picture = pictureBox1.Image
};
iv.Show();
}
else
{
iv.Activate();
}
}
}
}
}