|
|
发表于 2005-1-27 14:37:00
|
显示全部楼层
Re:用c#开发的地图编辑器!
呵呵~谢谢楼主。
学习笔记
<Form1>核心代码:
private void button1_Click(object sender, EventArgs e)
{
this.RECT.X = 0;
this.RECT.Y = 0x100;
}
private void button5_Click(object sender, EventArgs e)
{
for (int num1 = 0; num1 < 12; num1++)
{
for (int num2 = 0; num2 < 20; num2++)
{
this.mymap.mymapX[num1, num2].picRect.X = 0;
this.mymap.mymapX[num1, num2].picRect.Y = 0x100;
}
}
this.flashWin();
}
private void button6_Click(object sender, EventArgs e)
{
this.flashWin();
}
public void flashWin()
{
for (int num1 = 0; num1 < 12; num1++)
{
for (int num2 = 0; num2 < 20; num2++)
{
this.mygrap.DrawImage(this.picBit, (int) ((num2 - 1) * 0x20), (int) ((num1 - 1) * 0x20), this.mymap.mymapX[num1, num2].picRect, this.myunit);
}
}
}
private void Form1_Load(object sender, EventArgs e)
{
this.mygrap = this.panel1.CreateGraphics();
this.tuKuanTu = this.pictureBox2.CreateGraphics();
this.panel1.MouseMove += new MouseEventHandler(this.panel1_MouseMove);
this.panel1.MouseLeave += new EventHandler(this.panel1_MouseLeave);
this.panel1.MouseDown += new MouseEventHandler(this.panel1_MouseDown);
this.pictureBox2.MouseDown += new MouseEventHandler(this.pictureBox2_MouseDown);
this.pictureBox2.MouseMove += new MouseEventHandler(this.pictureBox2_MouseMove);
this.bita.MakeTransparent(Color.Aqua);
this.panel1.BackgroundImage = Image.FromFile("pic/\u7eff\u5730.bmp");
this.timer1.Enabled = false;
}
private void hScrollBar2_Scroll(object sender, ScrollEventArgs e)
{
if (this.hScrollBar2.Value == 3)
{
MessageBox.Show("ASDf");
}
}
private void menuItem10_Click(object sender, EventArgs e)
{
MessageBox.Show("\u53ea\u80fd\u4fdd\u5b58\u5230\u7a0b\u5e8f\u7684\u6267\u884c\u6587\u4ef6.exe\u76ee\u5f55\u5185");
this.saveFileDialog1.AddExtension = true;
this.saveFileDialog1.ShowDialog();
}
private void menuItem18_Click(object sender, EventArgs e)
{
this.Cursor = new Cursor("cur/\u666e\u901a.cur");
}
private void menuItem19_Click(object sender, EventArgs e)
{
this.Cursor = new Cursor("cur/\u5927\u753b\u7b14.cur");
}
private void menuItem20_Click(object sender, EventArgs e)
{
this.openFileDialog1.ShowDialog();
}
private void menuItem3_Click(object sender, EventArgs e)
{
base.Close();
}
private void menuItem6_Click(object sender, EventArgs e)
{
this.mapShuxing.ShowDialog();
}
private void menuItem8_Click(object sender, EventArgs e)
{
this.timer1.Enabled = false;
this.panel1.Refresh();
}
private void menuItem9_Click(object sender, EventArgs e)
{
this.timer1.Enabled = true;
}
private void openFileDialog1_FileOk(object sender, CancelEventArgs e)
{
StreamReader reader1 = new StreamReader(this.openFileDialog1.FileName);
this.mymap.mapName = reader1.ReadLine();
this.mymap.PointX = reader1.ReadLine();
this.mymap.Pointy = reader1.ReadLine();
this.mymap.exInfo = reader1.ReadLine();
for (int num1 = 0; num1 < 12; num1++)
{
for (int num2 = 0; num2 < 20; num2++)
{
this.mymap.mymapX[num1, num2].picRect.X = Convert.ToInt32(reader1.ReadLine(), 10);
this.mymap.mymapX[num1, num2].picRect.Y = Convert.ToInt32(reader1.ReadLine(), 10);
this.mymap.mymapX[num1, num2].suf = reader1.ReadLine();
this.mymap.mymapX[num1, num2].zudang = reader1.ReadLine();
}
}
reader1.Close();
}
private void panel1_MouseDown(object sender, MouseEventArgs e)
{
int num1 = 0;
int num2 = 0;
int num3 = 0;
int num4 = 0;
for (int num5 = 0; num5 < 20; num5++)
{
if ((e.X > (num1 * num5)) && (e.X < (0x20 * num5)))
{
num3 = num5;
this.label6.Text = num5.ToString();
num1 += 0x20;
break;
}
}
for (int num6 = 0; num6 < 12; num6++)
{
if ((e.Y > (num2 * num6)) && (e.Y < (0x20 * num6)))
{
num4 = num6;
this.label7.Text = num6.ToString();
num2 += 0x20;
break;
}
}
if (e.Button == MouseButtons.Left)
{
this.mymap.mymapX[num4, num3].picRect.X = this.RECT.X;
this.mymap.mymapX[num4, num3].picRect.Y = this.RECT.Y;
this.mygrap.DrawImage(this.picBit, (int) ((num3 - 1) * 0x20), (int) ((num4 - 1) * 0x20), this.RECT, this.myunit);
}
if (e.Button == MouseButtons.Right)
{
this.mymap.mymapX[num4, num3].picRect.X = 0;
this.mymap.mymapX[num4, num3].picRect.Y = 0x100;
this.mygrap.DrawImage(this.picBit, (int) ((num3 - 1) * 0x20), (int) ((num4 - 1) * 0x20), this.mymap.mymapX[num4, num3].picRect, this.myunit);
}
}
private void panel1_MouseMove(object sender, MouseEventArgs e)
{
this.label6.Text = e.X.ToString();
this.label7.Text = e.Y.ToString();
int num1 = 0;
int num2 = 0;
int num3 = 0;
int num4 = 0;
for (int num5 = 0; num5 < 20; num5++)
{
if ((e.X > (num1 * num5)) && (e.X < (0x20 * num5)))
{
num3 = num5;
this.label6.Text = num5.ToString();
num1 += 0x20;
break;
}
}
for (int num6 = 0; num6 < 12; num6++)
{
if ((e.Y > (num2 * num6)) && (e.Y < (0x20 * num6)))
{
num4 = num6;
this.label7.Text = num6.ToString();
num2 += 0x20;
break;
}
}
int num7 = num3;
this.label8.Text = num7.ToString();
}
private void pictureBox2_MouseDown(object sender, MouseEventArgs e)
{
if ((e.X < 0x20) && (e.Y < 0x20))
{
this.RECT.X = this.aa.X;
this.RECT.Y = this.aa.Y;
}
else if ((e.X < 0x40) && (e.Y < 0x20))
{
this.RECT.X = 0x20 + this.aa.X;
this.RECT.Y = this.aa.Y;
}
else if ((e.X < 0x80) && (e.Y < 0x20))
{
this.RECT.X = 0x40 + this.aa.X;
this.RECT.Y = this.aa.Y;
}
else if ((e.X < 0x20) && (e.Y < 0x40))
{
this.RECT.X = this.aa.X;
this.RECT.Y = 0x20 + this.aa.Y;
}
else if ((e.X < 0x40) && (e.Y < 0x40))
{
this.RECT.X = 0x20 + this.aa.X;
this.RECT.Y = 0x20 + this.aa.Y;
}
else if ((e.X < 0x80) && (e.Y < 0x40))
{
this.RECT.X = 0x40 + this.aa.X;
this.RECT.Y = 0x20 + this.aa.Y;
}
else if ((e.X < 0x20) && (e.Y < 0x60))
{
this.RECT.X = this.aa.X;
this.RECT.Y = 0x40 + this.aa.Y;
}
else if ((e.X < 0x40) && (e.Y < 0x60))
{
this.RECT.X = 0x20 + this.aa.X;
this.RECT.Y = 0x40 + this.aa.Y;
}
else if ((e.X < 0x80) && (e.Y < 0x60))
{
this.RECT.X = 0x40 + this.aa.X;
this.RECT.Y = 0x40 + this.aa.Y;
}
else if ((e.X < 0x20) && (e.Y < 0x80))
{
this.RECT.X = this.aa.X;
this.RECT.Y = 0x60 + this.aa.Y;
}
else if ((e.X < 0x40) && (e.Y < 0x80))
{
this.RECT.X = 0x20 + this.aa.X;
this.RECT.Y = 0x60 + this.aa.Y;
}
else if ((e.X < 0x80) && (e.Y < 0x80))
{
this.RECT.X = 0x40 + this.aa.X;
this.RECT.Y = 0x60 + this.aa.Y;
}
}
private void pictureBox2_MouseMove(object sender, MouseEventArgs e)
{
if ((e.X < 0x20) && (e.Y < 0x20))
{
this.tuKuanTu.DrawImage(this.picBit, 0, 0, this.aa, this.myunit);
this.tuKuanTu.DrawImageUnscaled(this.bita, 0, 0);
}
else if ((e.X < 0x40) && (e.Y < 0x20))
{
this.tuKuanTu.DrawImage(this.picBit, 0, 0, this.aa, this.myunit);
this.tuKuanTu.DrawImageUnscaled(this.bita, 0x20, 0);
}
else if ((e.X < 0x80) && (e.Y < 0x20))
{
this.tuKuanTu.DrawImage(this.picBit, 0, 0, this.aa, this.myunit);
this.tuKuanTu.DrawImageUnscaled(this.bita, 0x40, 0);
}
else if ((e.X < 0x20) && (e.Y < 0x40))
{
this.tuKuanTu.DrawImage(this.picBit, 0, 0, this.aa, this.myunit);
this.tuKuanTu.DrawImageUnscaled(this.bita, 0, 0x20);
}
else if ((e.X < 0x40) && (e.Y < 0x40))
{
this.tuKuanTu.DrawImage(this.picBit, 0, 0, this.aa, this.myunit);
this.tuKuanTu.DrawImageUnscaled(this.bita, 0x20, 0x20);
}
else if ((e.X < 0x80) && (e.Y < 0x40))
{
this.tuKuanTu.DrawImage(this.picBit, 0, 0, this.aa, this.myunit);
this.tuKuanTu.DrawImageUnscaled(this.bita, 0x40, 0x20);
}
else if ((e.X < 0x20) && (e.Y < 0x60))
{
this.tuKuanTu.DrawImage(this.picBit, 0, 0, this.aa, this.myunit);
this.tuKuanTu.DrawImageUnscaled(this.bita, 0, 0x40);
}
else if ((e.X < 0x40) && (e.Y < 0x60))
{
this.tuKuanTu.DrawImage(this.picBit, 0, 0, this.aa, this.myunit);
this.tuKuanTu.DrawImageUnscaled(this.bita, 0x20, 0x40);
}
else if ((e.X < 0x80) && (e.Y < 0x60))
{
this.tuKuanTu.DrawImage(this.picBit, 0, 0, this.aa, this.myunit);
this.tuKuanTu.DrawImageUnscaled(this.bita, 0x40, 0x40);
}
else if ((e.X < 0x20) && (e.Y < 0x80))
{
this.tuKuanTu.DrawImage(this.picBit, 0, 0, this.aa, this.myunit);
this.tuKuanTu.DrawImageUnscaled(this.bita, 0, 0x60);
}
else if ((e.X < 0x40) && (e.Y < 0x80))
{
this.tuKuanTu.DrawImage(this.picBit, 0, 0, this.aa, this.myunit);
this.tuKuanTu.DrawImageUnscaled(this.bita, 0x20, 0x60);
}
else if ((e.X < 0x80) && (e.Y < 0x80))
{
this.tuKuanTu.DrawImage(this.picBit, 0, 0, this.aa, this.myunit);
this.tuKuanTu.DrawImageUnscaled(this.bita, 0x40, 0x60);
}
}
private void saveFileDialog1_FileOk(object sender, CancelEventArgs e)
{
this.mymap.mapName = this.mapShuxing.textBox3.Text;
StreamWriter writer1 = new StreamWriter(this.saveFileDialog1.FileName);
writer1.WriteLine(this.mymap.mapName);
writer1.WriteLine(this.mymap.PointX);
writer1.WriteLine(this.mymap.Pointy);
writer1.WriteLine(this.mymap.exInfo);
for (int num1 = 0; num1 < 12; num1++)
{
for (int num2 = 0; num2 < 20; num2++)
{
writer1.WriteLine(this.mymap.mymapX[num1, num2].picRect.X);
writer1.WriteLine(this.mymap.mymapX[num1, num2].picRect.Y);
writer1.WriteLine(this.mymap.mymapX[num1, num2].suf);
writer1.WriteLine(this.mymap.mymapX[num1, num2].zudang);
}
}
writer1.Close();
}
private void timer1_Tick(object sender, EventArgs e)
{
Pen pen1 = new Pen(Color.Black, 1f);
int num1 = 0x20;
for (int num2 = 0; num2 < 20; num2++)
{
this.mygrap.DrawLine(pen1, num1, 0, num1, 0x198);
num1 += 0x20;
}
int num3 = 0x20;
for (int num4 = 0; num4 < 0x13; num4++)
{
this.mygrap.DrawLine(pen1, 0, num3, 0x278, num3);
num3 += 0x20;
}
pen1.Dispose();
}
private void timer2_Tick(object sender, EventArgs e)
{
this.flashWin();
}
private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
{
string text1;
if ((text1 = e.Node.Text) != null)
{
text1 = string.IsInterned(text1);
if (text1 != "\u5730\u9762")
{
if (text1 == "\u7070\u571f\u5730")
{
this.aa.X = 0xc0;
this.aa.Y = 0;
gricap.showBmp(this.picBit, 0, 0, this.tuKuanTu, this.aa);
}
else if (text1 == "\u7eff\u5730")
{
this.aa.X = 0x60;
this.aa.Y = 0x100;
gricap.showBmp(this.picBit, 0, 0, this.tuKuanTu, this.aa);
}
else if (text1 == "\u77f3\u5934\u5730")
{
this.aa.X = 0xc0;
this.aa.Y = 0x80;
gricap.showBmp(this.picBit, 0, 0, this.tuKuanTu, this.aa);
}
else if (text1 == "\u7816\u5757\u5730")
{
this.aa.X = 480;
this.aa.Y = 0;
gricap.showBmp(this.picBit, 0, 0, this.tuKuanTu, this.aa);
}
else if (text1 == "\u5927\u77f3\u5934\u5730")
{
this.aa.X = 480;
this.aa.Y = 0x100;
gricap.showBmp(this.picBit, 0, 0, this.tuKuanTu, this.aa);
}
}
else
{
this.picBit = (Bitmap) Image.FromFile("pic/dimian.png");
this.aa.X = 0x60;
this.aa.Y = 0x100;
gricap.showBmp(this.picBit, 0, 0, this.tuKuanTu, this.aa);
}
}
}
好累,<Form1>差不多就是这样子了。 |
|