-
Notifications
You must be signed in to change notification settings - Fork 14
/
FormTile.cs
235 lines (203 loc) · 8.17 KB
/
FormTile.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
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.Windows.Forms;
namespace Aesir5
{
public partial class FormTile : Form
{
private readonly List<Point> selectedTiles = new List<Point>();
private Point focusedTile = new Point(-1,-1);
private int sizeModifier;
private bool showGrid;
public bool ShowGrid
{
get { return showGrid; }
set { showGrid = value; this.Invalidate(); }
}
public FormTile()
{
InitializeComponent();
this.MouseWheel += new MouseEventHandler(frmTile_MouseWheel);
//this.Paint += frmTile_Paint;
}
private void frmTile_Load(object sender, EventArgs e)
{
Reload(false);
MinimumSize = new Size(MinimumSize.Width + 10, MinimumSize.Height + 10);
MaximumSize = new Size(MaximumSize.Width + 10, MaximumSize.Height + 10);
if (this.BackgroundImage == null) this.BackgroundImage = new Bitmap(10 * sizeModifier, 10 * sizeModifier);
menuStrip.Visible = false;
sb1.Maximum = (TileManager.Epf[0].max / 100) + 9;
RenderTileset();
}
private int GetTileNumber(int x, int y)
{
return sb1.Value*100 + (y*10) + x;
}
private void RenderTileset()
{
//Bitmap tSet = new Bitmap(360, 360);
if (this.BackgroundImage == null) this.BackgroundImage = new Bitmap(10 * sizeModifier, 10 * sizeModifier);
Graphics g = Graphics.FromImage(this.BackgroundImage);
g.Clear(Color.DarkGreen);
for (int x = 0; x < 10; x++)
{
for (int y = 0; y < 10; y++)
{
int tile = GetTileNumber(x, y);
if (tile < TileManager.Epf[0].max)
{
//Bitmap bitmap = ImageRenderer.Singleton.GetTileBitmap(tile);
g.DrawImage(ImageRenderer.Singleton.GetTileBitmap(tile), x * sizeModifier, y * sizeModifier);//, 36, 36);
//bitmap = null;
}
}
}
g.Dispose();
this.Invalidate();
//this.BackgroundImage = tSet;
//picTileset.Image = tSet;
//Application.DoEvents();
//tSet = null;
}
private void sb1_Scroll(object sender, ScrollEventArgs e)
{
selectedTiles.Clear();
RenderTileset();
}
void frmTile_Paint(object sender, PaintEventArgs e)
{
//base.OnPaint(e);
if (ShowGrid)
{
Pen penGrid = new Pen(Color.LightCyan, 1);
for (int i = 0; i < 10; i++)
{
for (int j = 0; j < 10; j++)
{
e.Graphics.DrawRectangle(penGrid, i*sizeModifier, j*sizeModifier, sizeModifier, sizeModifier);
}
}
penGrid.Dispose();
}
if (selectedTiles.Count > 0)
{
Pen pen = new Pen(Color.Red, 2);
foreach (var selectedTile in selectedTiles)
{
e.Graphics.DrawRectangle(pen, selectedTile.X * sizeModifier, selectedTile.Y * sizeModifier, sizeModifier, sizeModifier);
}
pen.Dispose();
}
if (focusedTile.X >= 0 && focusedTile.Y >= 0)
{
Pen pen = new Pen(Color.Green, 2);
e.Graphics.DrawRectangle(pen, focusedTile.X * sizeModifier, focusedTile.Y * sizeModifier, sizeModifier, sizeModifier);
pen.Dispose();
}
}
private void frmTile_MouseWheel(object sender, MouseEventArgs e)
{
if (e.Delta > 0)
{
if (sb1.Value - 1 >= sb1.Minimum) sb1.Value--;
}
else if (e.Delta < 0)
{
if (sb1.Value + 1 <= sb1.Maximum) sb1.Value++;
}
sb1_Scroll(null, null);
}
private void frmTile_MouseMove(object sender, MouseEventArgs e)
{
int newFocusedTileX = e.X / sizeModifier;
int newFocusedTileY = e.Y / sizeModifier;
bool refresh = (newFocusedTileX != focusedTile.X || newFocusedTileY != focusedTile.Y);
if (refresh)
{
focusedTile = new Point(newFocusedTileX, newFocusedTileY);
this.Invalidate();
int tileNumber = GetTileNumber(newFocusedTileX, newFocusedTileY);
toolStripStatusLabel.Text = string.Format("Tile number: {0}", tileNumber);
}
}
private void frmTile_MouseClick(object sender, MouseEventArgs e)
{
if (e.Button != MouseButtons.Left) return;
int newSelectedTileX = e.X / sizeModifier;
int newSelectedTileY = e.Y / sizeModifier;
Point selectedTile = new Point(newSelectedTileX, newSelectedTileY);
if (ModifierKeys == Keys.Control)
{
if (!selectedTiles.Contains(selectedTile))
selectedTiles.Add(selectedTile);
}
else
{
selectedTiles.Clear();
selectedTiles.Add(selectedTile);
}
TileManager.TileSelection = GetSelection();
TileManager.LastSelection = TileManager.SelectionType.Tile;
//RenderTileset();
}
public Dictionary<Point, int> GetSelection()
{
Dictionary<Point, int> dictionary = new Dictionary<Point, int>();
if (selectedTiles.Count == 0) return dictionary;
int xMin = selectedTiles[0].X, yMin = selectedTiles[0].Y;
foreach (Point selectedTile in selectedTiles)
{
if (xMin > selectedTile.X) xMin = selectedTile.X;
if (yMin > selectedTile.Y) yMin = selectedTile.Y;
}
foreach (Point selectedTile in selectedTiles)
{
dictionary.Add(new Point(selectedTile.X - xMin, selectedTile.Y - yMin),
GetTileNumber(selectedTile.X, selectedTile.Y));
}
return dictionary;
}
/*public void ClearSelection()
{
selectedTiles.Clear();
this.Invalidate();
}*/
private void findTileToolStripMenuItem_Click(object sender, EventArgs e)
{
NumberInputForm numberInputForm = new NumberInputForm(@"Enter object number");
if (numberInputForm.ShowDialog(this) == DialogResult.OK)
{
NavigateToTile(numberInputForm.Number);
}
}
private void showGridToolStripMenuItem_Click(object sender, EventArgs e)
{
ShowGrid = showGridToolStripMenuItem.Checked;
}
public void NavigateToTile(int number)
{
if (number < 0 || number>(sb1.Maximum*100 + 99)) return;
int sbIndex = number / 100;
int y = (number - sbIndex * 100) / 10;
int x = number - sbIndex * 100 - y * 10;
sb1.Value = sbIndex;
selectedTiles.Clear();
selectedTiles.Add(new Point(x, y));
TileManager.TileSelection = GetSelection();
TileManager.LastSelection = TileManager.SelectionType.Tile;
RenderTileset();
}
public void Reload(bool render)
{
sizeModifier = ImageRenderer.Singleton.sizeModifier;
SetClientSizeCore((10 * sizeModifier) - 1, (10 * sizeModifier) + 39);
MinimumSize = new Size(ClientSize.Width + 6, ClientSize.Height + 24);
MaximumSize = new Size(ClientSize.Width + 6, ClientSize.Height + 24);
this.BackgroundImage = null;
if (render) RenderTileset();
}
}
}