-
Notifications
You must be signed in to change notification settings - Fork 0
/
Form1.cs
103 lines (89 loc) · 2.5 KB
/
Form1.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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Reflection;
using AlienGame.Tools;
using System.Xml;
namespace AlienGame
{
public partial class Form1 : Form
{
public static Font font;
public Form1()
{
InitializeComponent();
var model = new Model();
surface1.Model = model;
var tools = typeof(Tool).ConcreteSubtypes()
.Select(t => Activator.CreateInstance(t))
.OrderBy(t => t.ToString());
comboBox1.Items.AddRange(tools.ToArray());
comboBox1.SelectedIndex = 0;
surface1.Tool = comboBox1.SelectedItem as Tool;
var actorClasses = typeof(Actor).ConcreteSubtypes();
comboBox2.Items.AddRange(actorClasses.ToArray());
comboBox2.SelectedIndex = 0;
ActorTool.NewActorType = comboBox2.SelectedItem as Type;
EditActorTool.Ui = new PropertiesForm(() => { model.SyncActorList(); surface1.Invalidate(); });
font = Font;
}
void ChangeRenderOption(object sender, EventArgs e)
{
var bit = (RenderOptions)int.Parse((string)(sender as Control).Tag);
if ((sender as CheckBox).Checked) surface1.Options |= bit;
else surface1.Options &= ~bit;
}
void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
surface1.Tool = comboBox1.SelectedItem as Tool;
}
void timer1_Tick(object sender, EventArgs e)
{
if (surface1.Tool.GetType() == typeof(SimulateTool))
{
surface1.Model.Tick();
surface1.Invalidate();
}
}
void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
{
ActorTool.NewActorType = comboBox2.SelectedItem as Type;
}
void SaveScenario(object sender, EventArgs e)
{
var sfd = new SaveFileDialog()
{
RestoreDirectory = true,
DefaultExt = ".ags",
Filter = "Alien Game Scenario (*.ags)|*.ags",
};
if (sfd.ShowDialog() == DialogResult.OK)
{
var w = XmlWriter.Create(sfd.FileName,
new XmlWriterSettings() { Indent = true });
surface1.Model.Save(w);
w.Close();
}
}
void LoadScenario(object sender, EventArgs e)
{
var ofd = new OpenFileDialog()
{
RestoreDirectory = true,
DefaultExt = ".ags",
Filter = "Alien Game Scenario (*.ags)|*.ags",
};
if (ofd.ShowDialog() == DialogResult.OK)
{
var doc = new XmlDocument();
doc.Load(ofd.FileName);
surface1.Model = new Model(doc);
}
}
}
}