-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.cs
More file actions
313 lines (290 loc) · 11.5 KB
/
Main.cs
File metadata and controls
313 lines (290 loc) · 11.5 KB
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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WorldEditor
{
public partial class Main : Form
{
private enum LGridTools { SelectTool, RectSelectTool, PencilTool, LineTool, DrawRectTool, FillRectTool, FillTool, TilePickerTool, EraseTool };
private LGridTools curTool = LGridTools.SelectTool;
private bool wsMouseDown = false;
public Main()
{
InitializeComponent();
this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.OptimizedDoubleBuffer, true);
tileSelector1.LoadTilesets();
worldWorkspace1.CreateNewLevel(75, 75);
tileSelector1.SelectTile(1, 1);
}
private void tileSelector1_MouseDown(object sender, MouseEventArgs e)
{
// Check X Bounds
if (e.X > (tileSelector1.Width - tileSelector1.Controls["vScrollBar1"].Width))
{
return;
}
tileSelector1.SelectTile(e.X, e.Y);
}
private void worldWorkspace1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
wsMouseDown = true;
// Translate screen coords into grid coords
int tmpCanvasX = e.X + worldWorkspace1.LGridXOffset - 24;
int tmpCanvasY = e.Y + worldWorkspace1.LGridYOffset - 24;
if (tmpCanvasX < 0 || (tmpCanvasX / 32) >= worldWorkspace1.LGridWidth || tmpCanvasY < 0 || (tmpCanvasY / 32) >= worldWorkspace1.LGridHeight)
{
// Release mouse down and don't do anything else, we hit the margins...
wsMouseDown = false;
return;
}
int tmpGridX = tmpCanvasX / 32;
int tmpGridY = tmpCanvasY / 32;
switch (curTool)
{
case LGridTools.SelectTool:
wsMouseDown = false; // Release immediately, no need to drag
break;
case LGridTools.RectSelectTool:
break;
case LGridTools.PencilTool:
if (tileSelector1.CurTileChanged)
{
if (!worldWorkspace1.UpdateSelectedTile(tileSelector1.GetCurTile))
{
MessageBox.Show("The level palette is full.");
wsMouseDown = false;
break;
}
tileSelector1.CurTileChanged = false;
}
worldWorkspace1.PaintTile(tmpGridX, tmpGridY);
break;
case LGridTools.LineTool:
if (tileSelector1.CurTileChanged)
{
if (!worldWorkspace1.UpdateSelectedTile(tileSelector1.GetCurTile))
{
MessageBox.Show("The level palette is full.");
wsMouseDown = false;
break;
}
tileSelector1.CurTileChanged = false;
}
break;
case LGridTools.DrawRectTool:
if (tileSelector1.CurTileChanged)
{
if (!worldWorkspace1.UpdateSelectedTile(tileSelector1.GetCurTile))
{
MessageBox.Show("The level palette is full.");
wsMouseDown = false;
break;
}
tileSelector1.CurTileChanged = false;
}
break;
case LGridTools.FillRectTool:
if (tileSelector1.CurTileChanged)
{
if (!worldWorkspace1.UpdateSelectedTile(tileSelector1.GetCurTile))
{
MessageBox.Show("The level palette is full.");
wsMouseDown = false;
break;
}
tileSelector1.CurTileChanged = false;
}
break;
case LGridTools.FillTool:
if (tileSelector1.CurTileChanged)
{
if (!worldWorkspace1.UpdateSelectedTile(tileSelector1.GetCurTile))
{
MessageBox.Show("The level palette is full.");
wsMouseDown = false;
break;
}
tileSelector1.CurTileChanged = false;
}
wsMouseDown = false; // Release immediately
break;
case LGridTools.TilePickerTool:
wsMouseDown = false; // Release immediately
break;
case LGridTools.EraseTool:
break;
}
}
}
private void worldWorkspace1_MouseMove(object sender, MouseEventArgs e)
{
// Translate screen coords into grid coords
int tmpCanvasX = e.X + worldWorkspace1.LGridXOffset - 24;
int tmpCanvasY = e.Y + worldWorkspace1.LGridYOffset - 24;
int tmpGridX = tmpCanvasX / 32;
int tmpGridY = tmpCanvasY / 32;
// Update X and Y Status Labels only if we're in Canvas Bounds
if (tmpCanvasX > 0 && tmpGridX < worldWorkspace1.LGridWidth && tmpCanvasY > 0 && tmpGridY < worldWorkspace1.LGridHeight)
{
xStatusLabel.Text = "X: " + tmpGridX;
yStatusLabel.Text = "Y: " + tmpGridY;
}
else
{
xStatusLabel.Text = "";
yStatusLabel.Text = "";
}
// Bounds Checking
if (tmpGridX > worldWorkspace1.LGridWidth)
tmpGridX = worldWorkspace1.LGridWidth - 1;
if (tmpGridY > worldWorkspace1.LGridHeight)
tmpGridY = worldWorkspace1.LGridHeight - 1;
if (wsMouseDown)
{
switch (curTool)
{
case LGridTools.SelectTool:
// Do nothing
break;
case LGridTools.RectSelectTool:
break;
case LGridTools.PencilTool:
worldWorkspace1.PaintTile(tmpGridX, tmpGridY);
break;
case LGridTools.LineTool:
break;
case LGridTools.DrawRectTool:
break;
case LGridTools.FillRectTool:
break;
case LGridTools.FillTool:
// Do nothing
break;
case LGridTools.TilePickerTool:
// Do nothing
break;
case LGridTools.EraseTool:
break;
}
}
}
private void worldWorkspace1_MouseUp(object sender, MouseEventArgs e)
{
wsMouseDown = false;
switch (curTool)
{
case LGridTools.SelectTool:
// Do nothing
break;
case LGridTools.RectSelectTool:
break;
case LGridTools.PencilTool:
// Don't have to do anything here
break;
case LGridTools.LineTool:
break;
case LGridTools.DrawRectTool:
break;
case LGridTools.FillRectTool:
break;
case LGridTools.FillTool:
// Do nothing
break;
case LGridTools.TilePickerTool:
// Do nothing
break;
case LGridTools.EraseTool:
break;
}
}
private void worldWorkspace1_MouseLeave(object sender, EventArgs e)
{
xStatusLabel.Text = "";
yStatusLabel.Text = "";
}
private void uncheckAllToolButtons()
{
selectToolButton.Checked = false;
rectSelectToolButton.Checked = false;
pencilToolButton.Checked = false;
lineToolButton.Checked = false;
drawRectToolButton.Checked = false;
fillRectToolButton.Checked = false;
fillToolButton.Checked = false;
tilePickerToolButton.Checked = false;
eraseToolButton.Checked = false;
}
private void selectToolButton_Click(object sender, EventArgs e)
{
uncheckAllToolButtons();
selectToolButton.Checked = true;
curTool = LGridTools.SelectTool;
}
private void rectSelectToolButton_Click(object sender, EventArgs e)
{
uncheckAllToolButtons();
rectSelectToolButton.Checked = true;
curTool = LGridTools.RectSelectTool;
}
private void pencilToolButton_Click(object sender, EventArgs e)
{
uncheckAllToolButtons();
pencilToolButton.Checked = true;
curTool = LGridTools.PencilTool;
}
private void lineToolButton_Click(object sender, EventArgs e)
{
uncheckAllToolButtons();
lineToolButton.Checked = true;
curTool = LGridTools.LineTool;
}
private void drawRectToolButton_Click(object sender, EventArgs e)
{
uncheckAllToolButtons();
drawRectToolButton.Checked = true;
curTool = LGridTools.DrawRectTool;
}
private void fillRectToolButton_Click(object sender, EventArgs e)
{
uncheckAllToolButtons();
fillRectToolButton.Checked = true;
curTool = LGridTools.FillRectTool;
}
private void fillToolButton_Click(object sender, EventArgs e)
{
uncheckAllToolButtons();
fillToolButton.Checked = true;
curTool = LGridTools.FillTool;
}
private void tilePickerToolButton_Click(object sender, EventArgs e)
{
uncheckAllToolButtons();
tilePickerToolButton.Checked = true;
curTool = LGridTools.TilePickerTool;
}
private void eraseToolButton_Click(object sender, EventArgs e)
{
uncheckAllToolButtons();
eraseToolButton.Checked = true;
curTool = LGridTools.EraseTool;
}
private void showGridLinesButton_Click(object sender, EventArgs e)
{
if (showGridLinesButton.Checked)
{
showGridLinesButton.Checked = false;
worldWorkspace1.ShowGridLines = false;
}
else
{
showGridLinesButton.Checked = true;
worldWorkspace1.ShowGridLines = true;
}
}
}
}