-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathCoordForm.cs
203 lines (164 loc) · 6.08 KB
/
CoordForm.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
using gta5refactor.Properties;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace gta5refactor
{
public partial class CoordForm : Form
{
private MainForm OwnerForm;
volatile bool AbortOperation = false;
bool InProgress = false;
public CoordForm(MainForm owner)
{
InitializeComponent();
OwnerForm = owner;
ScriptFolderTextBox.Text = Settings.Default.ScriptFolder;
}
private void FolderBrowseButton_Click(object sender, EventArgs e)
{
FolderBrowserDialog.SelectedPath = ScriptFolderTextBox.Text;
DialogResult res = FolderBrowserDialog.ShowDialog();
if (res == DialogResult.OK)
{
ScriptFolderTextBox.Text = FolderBrowserDialog.SelectedPath;
}
}
private void FindButton_Click(object sender, EventArgs e)
{
if (InProgress) return;
Find();
}
private void Find()
{
AbortOperation = false;
InProgress = true;
string scriptfolder = ScriptFolderTextBox.Text;
string posstr = PositionTextBox.Text;
double range = (double)RangeUpDown.Value;
bool use3ddist = Use3dDistCheckBox.Checked;
bool ignoresign = IgnoreSignCheckBox.Checked;
double px = 0.0;
double py = 0.0;
double pz = 0.0;
string[] psplit = posstr.Split(',');
for (int i = 0; i < psplit.Length; i++)
{
double val;
if (double.TryParse(psplit[i].Trim(), out val))
{
switch (i)
{
case 0: px = val; break;
case 1: py = val; break;
case 2: pz = val; break;
}
}
}
ResultTextBox.Text = string.Empty;
Task.Run(() =>
{
UpdateStatus("Task beginning...");
DateTime starttime = DateTime.Now;
List<ScriptCoord> coords = new List<ScriptCoord>();
Dictionary<Vec3D, List<ScriptCoord>> coorddict = new Dictionary<Vec3D, List<ScriptCoord>>();
string[] scriptfiles = Directory.GetFiles(scriptfolder);
foreach (string scriptfile in scriptfiles)
{
if (AbortOperation)
{
UpdateStatus("Search aborted.");
FindComplete(coords, coorddict);
return;
}
string filel = scriptfile.ToLower();
if (!(filel.EndsWith(".c") || filel.EndsWith(".c4"))) continue;
UpdateStatus("Searching " + scriptfile);
ScriptFile sf = new ScriptFile(scriptfile);
List<ScriptCoord> filecoords = sf.FindCoordinates();
foreach (ScriptCoord coord in filecoords)
{
double dist = coord.DistanceTo(px, py, pz, use3ddist, ignoresign);
if (dist <= range)
{
coords.Add(coord);
Vec3D v3d = coord.GetVec3D();
List<ScriptCoord> coordlist;
if (!coorddict.TryGetValue(v3d, out coordlist))
{
coordlist = new List<ScriptCoord>();
coorddict.Add(v3d, coordlist);
}
coordlist.Add(coord);
}
}
//coords.AddRange(filecoords);
}
UpdateStatus(string.Format("Find complete. {0} possible coordinates found, {1} unique.", coords.Count, coorddict.Count));
FindComplete(coords, coorddict);
});
}
private void FindComplete(List<ScriptCoord> coords, Dictionary<Vec3D, List<ScriptCoord>> cdict)
{
try
{
if (InvokeRequired)
{
Invoke(new Action(() => { FindComplete(coords, cdict); }));
}
else
{
InProgress = false;
StringBuilder sb = new StringBuilder();
if (DeduplicateCheckBox.Checked)
{
foreach (KeyValuePair<Vec3D, List<ScriptCoord>> kvp in cdict)
{
int count = kvp.Value.Count;
ScriptCoord c = kvp.Value[0];
if (count == 1)
{
sb.AppendLine(c.GetOutputString());
}
else
{
sb.AppendLine(string.Format("{0} (+{1} other{2})", c.GetOutputString(), count - 1, count>2?"s":""));
}
}
}
else
{
foreach (ScriptCoord c in coords)
{
sb.AppendLine(c.GetOutputString());
}
}
ResultTextBox.Text = sb.ToString();
}
}
catch { }
}
private void UpdateStatus(string text)
{
try
{
if (InvokeRequired)
{
Invoke(new Action(() => { UpdateStatus(text); }));
}
else
{
StatusLabel.Text = text;
}
}
catch { }
}
}
}