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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
| unit userscript;
uses mteFunctions;
const
vs = 'v2.5';
sFunctions = 'Add'#13'ElementAssign'#13'Remove'#13'Replace'#13'Formula'#13'Restore'#13'TemplateRestore'#13'Copy'#13'Import'#13'ArrayImport';
formuladebug = false; // set formuladebug to true to debug the formula function
var
badfile, processed: boolean;
slFunctions, slInput, slImport, slImportValues, slImportPaths, slArray: TStringList;
sFiles: string;
frm: TForm;
sb: TScrollBox;
lbl01: TLabel;
pnlBottom: TPanel;
btnPlus, btnMinus, btnOk, btnCancel: TButton;
lstEntries: TList;
//=========================================================================
// ClearPanel: Frees components in the panel, excluding the base combobox
procedure ClearPanel(Sender: TObject);
var
pnl: TPanel;
i: integer;
begin
pnl := TComboBox(Sender).GetParentComponent;
for i := pnl.ControlCount - 1 downto 1 do
pnl.Controls[i].Free;
end;
//=========================================================================
// CreatePathEdit: Makes a path TEdit component at index
function CreatePathEdit(Sender: TObject): TObject;
var
ed: TEdit;
pnl: TPanel;
begin
// create entry inside of panel
pnl := TComboBox(Sender).GetParentComponent;
// create path edit
ed := TEdit.Create(frm);
ed.Parent := pnl;
ed.Left := 116;
ed.Top := 8;
ed.Width := 150;
ed.Text := '<Path>';
Result := ed;
end;
//=========================================================================
// CreateAddEntry: Makes an entry for the Add function
procedure CreateAddEntry(Sender: TObject);
var
ed: TEdit;
pnl: TPanel;
begin
// clear panel of previous entries and create entry inside of it
ClearPanel(Sender);
pnl := TComboBox(Sender).GetParentComponent;
// create path edit
CreatePathEdit(Sender);
// create value edit
ed := TEdit.Create(frm);
ed.Parent := pnl;
ed.Left := 274;
ed.Top := 8;
ed.Width := 100;
ed.Text := '<Value>';
end;
//=========================================================================
// CreateElementAssignEntry: Makes an entry for the ElementAssign function
procedure CreateElementAssignEntry(Sender: TObject);
var
ed: TEdit;
pnl: TPanel;
begin
// clear panel of previous entries and create entry inside of it
ClearPanel(Sender);
pnl := TComboBox(Sender).GetParentComponent;
// create path edit
CreatePathEdit(Sender);
// create value edit
ed := TEdit.Create(frm);
ed.Parent := pnl;
ed.Left := 274;
ed.Top := 8;
ed.Width := 100;
ed.Text := '<Value>';
end;
//=========================================================================
// CreateRemoveEntry: Makes an entry for the Remove function
procedure CreateRemoveEntry(Sender: TObject);
var
ed: TEdit;
pnl: TPanel;
begin
// clear panel of previous entries and create entry inside of it
ClearPanel(Sender);
pnl := TComboBox(Sender).GetParentComponent;
// create path edit
CreatePathEdit(Sender);
// create index edit
ed := TEdit.Create(frm);
ed.Parent := pnl;
ed.Left := 274;
ed.Top := 8;
ed.Width := 50;
ed.Text := '<Index>';
end;
//=========================================================================
// CreateReplaceEntry: Makes an entry for the Replace function
procedure CreateReplaceEntry(Sender: TObject);
var
ed1, ed2: TEdit;
pnl: TPanel;
begin
// clear panel of previous entries and create entry inside of it
ClearPanel(Sender);
pnl := TComboBox(Sender).GetParentComponent;
// create path edit
CreatePathEdit(Sender);
// create find edit
ed1 := TEdit.Create(frm);
ed1.Parent := pnl;
ed1.Left := 274;
ed1.Top := 8;
ed1.Width := 100;
ed1.Text := '<Find>';
// create replace edit
ed2 := TEdit.Create(frm);
ed2.Parent := pnl;
ed2.Left := ed1.Left + ed1.Width + 8;
ed2.Top := ed1.Top;
ed2.Width := 100;
ed2.Text := '<Replace>';
end;
//=========================================================================
// CreateRestoreEntry: Makes an entry for the Restore function
procedure CreateRestoreEntry(Sender: TObject);
var
cb: TComboBox;
pnl: TPanel;
begin
// clear panel of previous entries and create entry inside of it
ClearPanel(Sender);
pnl := TComboBox(Sender).GetParentComponent;
// create path edit
CreatePathEdit(Sender);
// create files combobox
cb := TComboBox.Create(frm);
cb.Parent := pnl;
cb.Left := 274;
cb.Top := 8;
cb.Width := 150;
cb.Autocomplete := True;
cb.Style := csDropDown;
cb.Sorted := False;
cb.AutoDropDown := True;
cb.Items.Text := sFiles;
cb.ItemIndex := 3;
end;
//=========================================================================
// CreateTemplateRestoreEntry: Makes an entry for the TemplateRestore function
procedure CreateTemplateRestoreEntry(Sender: TObject);
var
pnl: TPanel;
begin
// clear panel of previous entries and create entry inside of it
ClearPanel(Sender);
pnl := TComboBox(Sender).GetParentComponent;
// create path edit
CreatePathEdit(Sender);
end;
//=========================================================================
// CreateImportEntry: Makes an entry for the Import function
procedure CreateImportEntry(Sender: TObject);
var
ed: TEdit;
pnl: TPanel;
begin
// clear panel of previous entries and create entry inside of it
ClearPanel(Sender);
pnl := TComboBox(Sender).GetParentComponent;
// create import edit
ed := TEdit.Create(frm);
ed.Parent := pnl;
ed.Left := 116;
ed.Top := 8;
ed.Width := 450;
ed.Text := ProgramPath + 'Edit Scripts\Exported.csv';
end;
//=========================================================================
// CreateImportEntry: Makes an entry for the Import function
procedure CreateArrayImportEntry(Sender: TObject);
var
ed: TEdit;
pnl: TPanel;
begin
// clear panel of previous entries and create entry inside of it
ClearPanel(Sender);
pnl := TComboBox(Sender).GetParentComponent;
// create path edit
CreatePathEdit(Sender);
// create import edit
ed := TEdit.Create(frm);
ed.Parent := pnl;
ed.Left := 274;
ed.Top := 8;
ed.Width := 300;
ed.Text := ProgramPath + 'Edit Scripts\';
end;
//=========================================================================
// CreateFormulaEntry: Makes an entry for the Formula function
procedure CreateFormulaEntry(Sender: TObject);
var
ed: TEdit;
pnl: TPanel;
begin
// clear panel of previous entries and create entry inside of it
ClearPanel(Sender);
pnl := TComboBox(Sender).GetParentComponent;
// create path edit
CreatePathEdit(Sender);
// create Formula edit
ed := TEdit.Create(frm);
ed.Parent := pnl;
ed.Left := 274;
ed.Top := 8;
ed.Width := 150;
ed.Text := '<Formula>';
end;
//=========================================================================
// LoadGroups: Loads record groups from a file into a TComboBox
procedure LoadGroups(Sender: TObject);
var
fn, sGroups: string;
f, g: IInterface;
i: integer;
pnl: TPanel;
begin
pnl := TComboBox(Sender).GetParentComponent;
// clear groups, records, and exit if invalid file specified
if TComboBox(Sender).ItemIndex = -1 then begin
TComboBox(pnl.Controls[2]).Items.Text := '';
TComboBox(pnl.Controls[3]).Items.Text := '';
exit;
end;
// find file
fn := TComboBox(Sender).Text;
for i := 0 to FileCount - 1 do begin
if (fn = GetFileName(FileByLoadOrder(i))) then begin
f := FileByLoadOrder(i);
Break;
end;
end;
// if file found, load groups
if Assigned(f) then begin
sGroups := '';
for i := 0 to ElementCount(f) - 1 do begin
g := ElementByIndex(f, i);
if Signature(g) = 'TES4' then Continue;
if not (sGroups = '') then sGroups := sGroups + #13 + GroupSignature(g)
else sGroups := GroupSignature(g);
end;
TComboBox(pnl.Controls[2]).Items.Text := sGroups;
TComboBox(pnl.Controls[2]).ItemIndex := 0;
end;
end;
//=========================================================================
// ProcessElementsIn: Processes elements in a file or group
procedure ProcessElementsIn(g: IInterface; lst: TStringList);
var
r: IInterface;
s: string;
i: integer;
begin
for i := 0 to ElementCount(g) - 1 do begin
r := ElementByIndex(g, i);
if (Pos('GRUP Cell', Name(r)) = 1) then Continue;
if (Pos('GRUP Exterior Cell', Name(r)) = 1) then begin
ProcessElementsIn(r, lst);
Continue;
end;
if (Signature(r) = 'GRUP') then
ProcessElementsIn(r, lst)
else if (Signature(r) = 'CELL') then
lst.AddObject(Name(r), TObject(r))
else begin
lst.AddObject(geev(r, 'EDID'), r);
end;
end;
end;
//=========================================================================
// LoadRecords: Loads records from group into combobox
procedure LoadRecords(Sender: TObject);
var
f, g: IInterface;
fn: string;
i, j: integer;
pnl: TPanel;
slRecords: TStringList;
begin
pnl := TComboBox(Sender).GetParentComponent;
// we're using a stringlist so we can access the record later
slRecords := TStringList.Create;
// clear records
TComboBox(pnl.Controls[3]).Items.Clear;
//exit if invalid group specified
if TComboBox(Sender).ItemIndex = -1 then
exit;
// find file
fn := pnl.Controls[1].Text;
if TComboBox(Sender).ItemIndex > -1 then begin
for i := 0 to FileCount - 1 do begin
if (fn = GetFileName(FileByIndex(i))) then begin
f := FileByIndex(i);
Break;
end;
end;
// if file found, set records combobox content
if Assigned(f) then begin
g := GroupBySignature(f, TComboBox(Sender).Text);
ProcessElementsIn(g, slRecords);
for j := 0 to slRecords.Count - 1 do
TComboBox(pnl.Controls[3]).Items.AddObject(slRecords[j], slRecords.Objects[j]);
TComboBox(pnl.Controls[3]).ItemIndex := 0;
end;
end;
slRecords.Free;
end;
//=========================================================================
// CreateCopyEntry: Makes an entry for the Copy function
procedure CreateCopyEntry(Sender: TObject);
var
cb1, cb2, cb3: TComboBox;
ed1, ed2: TEdit;
ix: integer;
pnl: TPanel;
begin
// clear panel of previous entries and create entry inside of it
ClearPanel(Sender);
pnl := TComboBox(Sender).GetParentComponent;
// create Files combobox
cb1 := TComboBox.Create(frm);
cb1.Parent := pnl;
cb1.Left := 116;
cb1.Top := 8;
cb1.Width := 100;
cb1.Autocomplete := True;
cb1.Style := csDropDown;
cb1.Sorted := False;
cb1.AutoDropDown := True;
cb1.Items.Text := sFiles;
cb1.Text := '<File>';
cb1.OnSelect := LoadGroups;
// create groups combobox
cb2 := TComboBox.Create(frm);
cb2.Parent := pnl;
cb2.Left := cb1.Left + cb1.Width + 8;
cb2.Top := cb1.Top;
cb2.Width := 70;
cb2.Autocomplete := True;
cb2.Style := csDropDown;
cb2.Sorted := True;
cb2.AutoDropDown := True;
cb2.Text := '<Group>';
cb2.OnSelect := LoadRecords;
// create records combobox
cb3 := TComboBox.Create(frm);
cb3.Parent := pnl;
cb3.Left := cb2.Left + cb2.Width + 8;
cb3.Top := cb1.Top;
cb3.Width := 149;
cb3.Autocomplete := True;
cb3.Style := csDropDown;
cb3.Sorted := True;
cb3.AutoDropDown := True;
cb3.Text := '<Record>';
// create path edit
ed1 := TEdit.Create(frm);
ed1.Parent := pnl;
ed1.Left := cb3.Left + cb3.Width + 8;
ed1.Top := cb1.Top;
ed1.Width := 100;
ed1.Text := '<Path>';
end;
//=========================================================================
// AddEntry: Creates a new empty function entry
procedure AddEntry;
var
i: integer;
cb: TComboBox;
pnl: TPanel;
begin
// create panel
pnl := TPanel.Create(frm);
pnl.Parent := sb;
pnl.Width := 595;
pnl.Height := 30;
pnl.Top := 30*lstEntries.Count - sb.VertScrollBar.Position;
pnl.BevelOuter := bvNone;
// create combobox
cb := TComboBox.Create(frm);
cb.Parent := pnl;
cb.Left := 10;
cb.Top := 8;
cb.Width := 100;
cb.Style := csDropDownList;
cb.Items.Text := sFunctions;
cb.OnSelect := FunctionManager;
cb.ItemIndex := 3;
FunctionManager(cb);
lstEntries.Add(pnl);
end;
//=========================================================================
// RemoveEntry: Deletes the lowest function entry
procedure RemoveEntry;
var
pnl: TPanel;
i: integer;
begin
if lstEntries.Count > 1 then begin
pnl := TPanel(lstEntries[Pred(lstEntries.Count)]);
for i := pnl.ControlCount - 1 downto 0 do begin
pnl.Controls[i].Visible := false;
pnl.Controls[i].Free;
end;
lstEntries.Delete(Pred(lstEntries.Count));
pnl.Free;
end;
end;
//=========================================================================
// FunctionManager: Handles what entry to make when a function is chosen
procedure FunctionManager(Sender: TObject);
var
s, t: string;
n: integer;
ed: TEdit;
begin
s := TComboBox(Sender).Text;
if (s = 'Add') then CreateAddEntry(Sender)
else if (s = 'ElementAssign') then CreateElementAssignEntry(Sender)
else if (s = 'Remove') then CreateRemoveEntry(Sender)
else if (s = 'Replace') then CreateReplaceEntry(Sender)
else if (s = 'Formula') then CreateFormulaEntry(Sender)
else if (s = 'Restore') then CreateRestoreEntry(Sender)
else if (s = 'TemplateRestore') then CreateTemplateRestoreEntry(Sender)
else if (s = 'Copy') then CreateCopyEntry(Sender)
else if (s = 'Import') then CreateImportEntry(Sender)
else if (s = 'ArrayImport') then CreateArrayImportEntry(Sender);
end; |