-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathGroupDialog.cs
165 lines (151 loc) · 4.52 KB
/
GroupDialog.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
#region Using directives
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using NoxShared;
#endregion
namespace NoxMapEditor
{
partial class GroupDialog : Form
{
private Map.Group selected;
private Map.Group.GroupTypes newType;
protected Map.GroupData groupData;
public Map.GroupData GroupD
{
get
{
return groupData;
}
set
{
groupData = value;
foreach (Map.Group g in groupData.Values)
groupList.Items.Add(g.name);
}
}
public GroupDialog()
{
InitializeComponent();
}
private void saveButton_Click(object sender, EventArgs e)
{
if (selected != null)
{
if (!groupData.ContainsKey(selected.name))
groupData.Add(selected.name, selected);
selected.type = newType;
switch (selected.type)
{
case Map.Group.GroupTypes.objects:
selected.Clear();
foreach (String s in itemList.Text.Trim().Split('\n'))
selected.Add(Int32.Parse(s.Trim()));
break;
case Map.Group.GroupTypes.walls:
selected.Clear();
foreach (String s in itemList.Text.Split('\n'))
{
string[] loc = s.Trim().Split(',');
if (loc.Length != 2)
break;
selected.Add(new Point(Int32.Parse(loc[0]), Int32.Parse(loc[1])));
}
break;
case Map.Group.GroupTypes.waypoint:
selected.Clear();
foreach (String s in itemList.Text.Split('\n'))
selected.Add(Int32.Parse(s.Trim()));
break;
default:
break;
}
selected.id = Int32.Parse(groupId.Text);
groupList.Items.Clear();
foreach (Map.Group g in groupData.Values)
groupList.Items.Add(g.name);
}
}
private void groupList_SelectedValueChanged(object sender, EventArgs e)
{
itemList.Clear();
if (groupList.Text.Length > 0)
{
selected = groupData.ContainsKey((string)groupList.Text) ? groupData[(string)groupList.Text] : new Map.Group((string)groupList.Text, Map.Group.GroupTypes.objects, 0);
switch (selected.type)
{
case Map.Group.GroupTypes.objects:
foreach (Int32 i in selected)
itemList.Text += String.Format("{0}\r\n", i);
wallRadio.Checked = false;
objectRadio.Checked = true;
waypointRadio.Checked = false;
break;
case Map.Group.GroupTypes.waypoint:
foreach (Int32 i in selected)
itemList.Text += String.Format("{0}\r\n", i);
wallRadio.Checked = false;
objectRadio.Checked = false;
waypointRadio.Checked = true;
break;
case Map.Group.GroupTypes.walls:
foreach (Point pt in selected)
itemList.Text += String.Format("{0},{1}\r\n", pt.X, pt.Y);
wallRadio.Checked = true;
objectRadio.Checked = false;
waypointRadio.Checked = false;
break;
}
groupId.Text = selected.id.ToString();
}
else
selected = null;
}
private void objectRadio_CheckedChanged(object sender, EventArgs e)
{
if (objectRadio.Checked)
{
wallRadio.Checked = false;
waypointRadio.Checked = false;
newType = Map.Group.GroupTypes.objects;
}
}
private void wallRadio_CheckedChanged(object sender, EventArgs e)
{
if (wallRadio.Checked)
{
objectRadio.Checked = false;
waypointRadio.Checked = false;
newType = Map.Group.GroupTypes.walls;
}
}
private void closeButton_Click(object sender, EventArgs e)
{
Close();
}
private void waypointRadio_CheckedChanged(object sender, EventArgs e)
{
if (waypointRadio.Checked)
{
objectRadio.Checked = false;
wallRadio.Checked = false;
newType = Map.Group.GroupTypes.waypoint;
}
}
private void delButton_Click(object sender, EventArgs e)
{
if (groupData.ContainsKey(selected.name))
{
groupData.Remove(selected.name);
groupList.Text = "";
groupList.Items.Clear();
foreach (Map.Group g in groupData.Values)
groupList.Items.Add(g.name);
}
}
}
}