-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathEditor.cs
190 lines (159 loc) · 5.75 KB
/
Editor.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
using AMMEdit.amm;
using AMMEdit.ani;
using AMMEdit.axs;
using AMMEdit.objects;
using AMMEdit.objects.loaders;
using AMMEdit.PropertyEditors;
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace AMMEdit
{
public partial class Editor : Form
{
private MapFile currentMap;
private DatFile currentDataFile;
private List<byte> dataBytes;
private Thread ioThread;
private TaskScheduler scheduler;
public Editor()
{
InitializeComponent();
}
private void openAMMFile()
{
if (openAMMFileDialog.ShowDialog() == DialogResult.OK)
{
currentAMMFile.Text = openAMMFileDialog.FileName;
// TODO: load async. It is fast enough for now.
currentMap = new MapFileLoader(openAMMFileDialog.FileName).Read(currentDataFile);
listBox1.DataSource = currentMap.GetGenericFields();
listBox1.DisplayMember = "DisplayFieldName";
listBox1.ValueMember = "FieldID";
List<IGenericFieldBlock> fields = currentMap.GetGenericFields();
dataBytes = new List<byte>();
fields.ForEach(x =>
{
dataBytes.AddRange(x.ToBytes());
});
rawBinaryOutput.Lines = new string[] { "Select a block to preview contents" };
saveAsToolStripMenuItem.Enabled = true;
}
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
ListBox lb = (ListBox)sender;
IGenericFieldBlock block = (IGenericFieldBlock)lb.SelectedItem;
rawBinaryOutput.Lines = block.ToFormattedPreview();
buttonEditProps.Enabled = block.CanEditProperties;
}
private void saveAMMAs()
{
if (saveAMMFileDialog.ShowDialog() == DialogResult.OK)
{
currentMap.SaveAs(saveAMMFileDialog.FileName);
}
}
private void button3_Click(object sender, EventArgs e)
{
IGenericFieldBlock block = (IGenericFieldBlock)listBox1.SelectedItem;
block.ShowPropertyEditor(this);
}
private void Editor_Load(object sender, EventArgs e)
{
scheduler = TaskScheduler.FromCurrentSynchronizationContext();
}
private void loadDataFile()
{
currentDataFile = new DatFileLoader(openDATFileDialog.FileName, progressBar1).Read();
new Task(() =>
{
statusLabel.Text = "Done";
progressBar1.Value = 100;
progressBar1.Visible = false;
openToolStripMenuItem.Enabled = true;
viewToolStripMenuItem.Enabled = true;
}).Start(scheduler);
}
private void openToolStripMenuItem_Click(object sender, EventArgs e)
{
openAMMFile();
}
private void saveAsToolStripMenuItem_Click(object sender, EventArgs e)
{
saveAMMAs();
}
private void viewToolStripMenuItem_Click(object sender, EventArgs e)
{
if (currentDataFile != null)
{
ObjectsFileViewer fv = new ObjectsFileViewer(currentDataFile);
fv.Show(this);
}
}
private void loadAM1AXSFileToolStripMenuItem_Click(object sender, EventArgs e)
{
if (openAXSFileDialog.ShowDialog() == DialogResult.OK)
{
AxsFile axsFile;
using (FileStream fs = new FileStream(openAXSFileDialog.FileName, FileMode.Open, FileAccess.Read))
{
using (BinaryReader r = new BinaryReader(fs))
{
axsFile = new AxsFile(r);
}
}
if (axsFile != null)
{
AnimatedSpriteViewer sv = new AnimatedSpriteViewer(axsFile);
sv.Show(this);
}
}
}
private void loadAM2ANIFileToolStripMenuItem_Click(object sender, EventArgs e)
{
if (openANIDialog1.ShowDialog() == DialogResult.OK)
{
AniFile aniFile;
using (FileStream fs = new FileStream(openANIDialog1.FileName, FileMode.Open, FileAccess.Read))
{
using (BinaryReader r = new BinaryReader(fs))
{
aniFile = new AniFile(r);
}
}
if (aniFile != null)
{
AnimatedANISpriteView sv = new AnimatedANISpriteView(aniFile);
sv.Show(this);
}
}
}
private void openToolStripMenuItem1_Click(object sender, EventArgs e)
{
if (openDATFileDialog.ShowDialog() == DialogResult.OK)
{
if (ioThread != null && ioThread.IsAlive)
{
statusLabel.Text = "Terminating existing operation";
ioThread.Abort();
ioThread = null;
}
statusLabel.Text = "Loading `" + openDATFileDialog.FileName + "`";
progressBar1.Value = 0;
progressBar1.Visible = true;
ioThread = new Thread(loadDataFile);
ioThread.Priority = ThreadPriority.Highest;
ioThread.IsBackground = true;
ioThread.Start();
}
else
{
statusLabel.Text = "Idle.";
}
}
}
}