-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdebugUMainForm.pas
More file actions
1545 lines (1292 loc) · 51.8 KB
/
debugUMainForm.pas
File metadata and controls
1545 lines (1292 loc) · 51.8 KB
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
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
unit UMainForm;
(*
TODO:
[X] Add "New..." to File Menu that creates a blank TLK file. Allow user to specify
language id when the menu option is selected, then fill in other header info
automatically.
[X] Add "Merge TLK..." to Tools Menu that will let user select a TLK file
and then append it at the end of the currently open one (with new strrefs
set in sequence of course).
[_] Add a search flag that does a word search instead of a string search with
the specified criteria. ("fuel telos" would match "the fuel situation on telos".
Those two functions will be useful for the TLK/2DA patcher app that all this is
supposed to lead to. (For use with my Force Powers Mod.)
*)
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, UTLKFile,
StdCtrls, ComCtrls, Menus, ExtCtrls, StoffeUtils, Grids, UStrTok, Clipbrd,
XPMan;
type
TMainForm = class(TForm)
OpenTlkFile: TOpenDialog;
bpanel: TStatusBar;
MainMenu: TMainMenu;
File1: TMenuItem;
Open1: TMenuItem;
Save1: TMenuItem;
N1: TMenuItem;
Quit1: TMenuItem;
SaveTlkFile: TSaveDialog;
Edit1: TMenuItem;
Copy1: TMenuItem;
Selectall1: TMenuItem;
Paste1: TMenuItem;
Cut1: TMenuItem;
N2: TMenuItem;
Tools1: TMenuItem;
Search1: TMenuItem;
Newentry1: TMenuItem;
Panel1: TPanel;
Editrow1: TMenuItem;
N3: TMenuItem;
N4: TMenuItem;
New1: TMenuItem;
N5: TMenuItem;
Appendfile1: TMenuItem;
N6: TMenuItem;
Setlanguage1: TMenuItem;
Deleteselected1: TMenuItem;
Save2: TMenuItem;
PadtoStrRef1: TMenuItem;
N7: TMenuItem;
btnShow: TButton;
lblInterval1: TLabel;
edStart: TEdit;
lblInterval2: TLabel;
edStop: TEdit;
lblMax: TLabel;
Label1: TLabel;
pbar: TProgressBar;
grid: TStringGrid;
Splitter1: TSplitter;
Panel2: TPanel;
txtDisplay: TMemo;
Panel3: TPanel;
Label2: TLabel;
Label3: TLabel;
XPManifest1: TXPManifest;
procedure btnShowClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure FormResize(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure Open1Click(Sender: TObject);
procedure Quit1Click(Sender: TObject);
procedure Save1Click(Sender: TObject);
procedure gridClick(Sender: TObject);
procedure Copy1Click(Sender: TObject);
procedure Selectall1Click(Sender: TObject);
procedure Paste1Click(Sender: TObject);
procedure Cut1Click(Sender: TObject);
procedure Search1Click(Sender: TObject);
procedure Newentry1Click(Sender: TObject);
procedure Editrow1Click(Sender: TObject);
procedure Setlanguage1Click(Sender: TObject);
procedure New1Click(Sender: TObject);
procedure Appendfile1Click(Sender: TObject);
procedure edStartKeyPress(Sender: TObject; var Key: Char);
procedure edStopKeyPress(Sender: TObject; var Key: Char);
procedure gridDblClick(Sender: TObject);
procedure Deleteselected1Click(Sender: TObject);
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
procedure Save2Click(Sender: TObject);
procedure PadtoStrRef1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
l_firstnew : integer;
l_resultslisted : boolean;
procedure LoadFile(sFile : string);
procedure DoSearchFilter();
procedure DoAddEntry();
procedure DoModifyEntry(tlkentry : TTLKString);
function CheckWordMatch(sCriteria : string; sData : string) : boolean;
function ShowAlertBox(sMessage : string) : word;
function ShowInfoBox(sMessage : string) : word;
function ShowConfirmBox(sMessage : string) : word;
end;
const
SOUND_COLUMN_WIDTH = 128;
SOUND_COLUMN_WIDTH_MARGIN = 130;
var
MainForm: TMainForm;
tlkdata : TTLKFileHandler;
implementation
uses USearchForm, UEntryForm, ULanguageForm, UConfirmDelete, UPadForm;
{$R *.DFM}
procedure ResetStringGrid(g : TStringGrid);
begin
g.cols[0].clear();
g.cols[1].clear();
g.cols[2].clear();
g.FixedRows := 0;
g.RowCount := 1;
end;
function TMainForm.ShowAlertBox(sMessage : string) : word;
begin
result := MessageDlgPos(sMessage, mtWarning, [mbOK], 0, Left + 64, Top + 128);
end;
function TMainForm.ShowInfoBox(sMessage : string) : word;
begin
result := MessageDlgPos(sMessage, mtInformation, [mbOK], 0, Left + 64, Top + 128);
end;
function TMainForm.ShowConfirmBox(sMessage : string) : word;
begin
result := MessageDlgPos(sMessage, mtConfirmation, [mbYes, mbNo], 0, Left + 64, Top + 128);
end;
procedure TMainForm.btnShowClick(Sender: TObject);
var
tlkentry : TTLKString;
iCount : dword;
iStart : dword;
iStop : dword;
iComp : integer;
sSnd : string;
begin
DBP('btnShowClick - START');
try
if (tlkdata = nil) then
raise EHell.Create('Uh oh... No valid TLK file has been opened!');
iStart := StrToInt(edStart.text);
iStop := StrToInt(edStop.text);
iComp := tlkdata.count -1;
if ((iStart = 0) and (iStop >= dword(iComp)) and (iComp > 136000)) then begin
DBP('btnShowClick - Showing large Interval alert...');
if (ShowConfirmBox('Are you sure you wish to display all ' + IntToStr(iComp) + ' entries at once? It will take about 30 seconds to make the list and requires 240 MB of free RAM. It is probably better to use a narrower interval or do a search. Continue anyway?') = mrNo) then
exit;
end;
if (Integer(iStop) > iComp) then begin
if (iComp < 0) then
iComp := 0;
edStop.text := IntToStr(iComp);
iStop := iComp;
end;
if ((iStart > iStop)) then
raise EHell.Create('Invalid start value of interval to display!');
if (iStop > (tlkdata.count-1)) or (iStop < iStart) then
raise EHell.Create('Oi! Invalid end value of interval to display!');
// Clear out the old values from the StrInggrid
DBP('btnShowClick - Resetting string grid');
ResetStringGrid(grid);
l_resultslisted := False;
pbar.position := 1;
pbar.max := iStop - iStart;
with grid do
begin
enabled := false;
colcount := 3;
FixedCols := 1;
rowcount := (iStop - iStart) + 2;
ColWidths[0] := 64;
ColWidths[1] := (grid.Width - 70 - SOUND_COLUMN_WIDTH_MARGIN);
ColWidths[2] := SOUND_COLUMN_WIDTH;
Cells[0, 0] := 'StrRef';
Cells[1, 0] := 'Entry text';
Cells[2, 0] := 'Sound Resref';
end;
if (grid.rowcount > 1) then
grid.FixedRows := 1;
DBP('btnShowClick - Starting to loop through entries in interval...');
iCount := 1;
tlkentry := tlkdata.strings.first();
while ((tlkentry <> nil) and (tlkentry.strref <= iStop)) do
begin
if ((tlkentry.strref >= iStart) and (tlkentry.strref <= iStop)) then
begin
grid.cells[0, iCount] := IntToStr(tlkentry.strref);
grid.cells[1, iCount] := ReplaceInString(tlkentry.strtext, #13, ''); // tlkentry.strtext;
grid.cells[2, iCount] := tlkentry.soundstring;
pbar.position := iCount;
iCount := iCount + 1;
DBP('btnShowClick - Displaying entry ' + IntToStr(tlkentry.strref));
end;
tlkentry := tlkdata.strings.next();
end;
DBP('btnShowClick - Done looping through entries in interval...');
pbar.position := 0;
grid.enabled := true;
sSnd := grid.cells[2, grid.row];
if (Length(sSnd) > 0) then
sSnd := '(' + sSnd + ')';
DBP('btnShowClick - Resetting text display box');
txtDisplay.clear();
txtDisplay.lines.Text := grid.cells[0, 0] + ' ' + sSnd + ':' + #10 + #10 + grid.cells[1, 0];
bpanel.panels[0].text := 'Displaying entries between StrRef '
+ IntToStr(iStart) + ' to ' + IntToStr(iStop)
+ ' out of a total of ' + IntToStr(tlkdata.count) + ' entries.';
except
on e : EHell do ShowAlertBox('ERROR! ' + e.Message);
end;
DBP('btnShowClick - END');
end;
procedure TMainForm.FormCreate(Sender: TObject);
begin
DBP('FormCreate - START');
Tools1.Enabled := False;
Save1.Enabled := False;
Save2.Enabled := False;
Setlanguage1.Enabled := False;
lblMax.caption := '';
if (tlkdata = nil) then begin
DBP('FormCreate - Creating instance of TTLKFileHandler Class...');
tlkdata := TTLKFileHandler.Create();
DBP('FormCreate - Created instance of TTLKFileHandler Class.');
end;
DBP('FormCreate - END');
end;
procedure TMainForm.FormDestroy(Sender: TObject);
begin
if (tlkdata <> nil) then
tlkdata.free();
end;
procedure TMainForm.FormResize(Sender: TObject);
begin
if (grid.ColCount = 3) then
begin
if (grid.rowcount > 1) then
grid.fixedrows := 1;
grid.Cells[0, 0] := 'StrRef';
grid.Cells[1, 0] := 'Entry text';
grid.Cells[2, 0] := 'Sound Resref';
grid.ColWidths[0] := 64;
grid.ColWidths[1] := (grid.Width - 70 - SOUND_COLUMN_WIDTH_MARGIN);
grid.ColWidths[2] := SOUND_COLUMN_WIDTH;
end
else
grid.ColWidths[0] := grid.Width - 6;
end;
procedure TMainForm.FormShow(Sender: TObject);
begin
if ((tlkdata.fileexists = False) or (tlkdata.count = 0)) then
begin
grid.FixedCols := 0;
grid.FixedRows := 0;
grid.colcount := 1;
grid.ColWidths[0] := grid.Width - 6;
if (tlkdata.fileexists = False) then
grid.cells[0, 0] := 'Please use the menu to open a TLK file to display.'
else if (tlkdata.count = 0) then
grid.cells[0, 0] := 'No entries present. Please use the Tools menu to add new entries.';
grid.enabled := false;
end
else
begin
(*
grid.ColCount := 3;
grid.FixedCols := 1;
if (grid.rowcount > 1) then
grid.FixedRows := 1;
grid.Cells[0, 0] := 'StrRef';
grid.Cells[1, 0] := 'Entry text';
grid. Cells[2, 0] := 'Sound Resref';
*)
if (grid.ColCount = 3) then begin
grid.ColWidths[0] := 64;
grid.ColWidths[1] := (grid.Width - 70 - SOUND_COLUMN_WIDTH_MARGIN);
grid.ColWidths[2] := SOUND_COLUMN_WIDTH;
end
else begin
grid.ColWidths[0] := grid.Width - 6;
end;
end;
end;
procedure TMainForm.LoadFile(sFile : string);
var
filePath : string;
i : integer;
begin
DBP('LoadFile - START');
try
If not FileExists(sFile) then
raise EHell.Create('Unable to load specified file "' + sFile + '"');
l_firstnew := -1;
btnShow.enabled := False;
edStart.enabled := False;
edStop.Enabled := False;
grid.Enabled := False;
Tools1.Enabled := False;
Save1.Enabled := False;
Save2.Enabled := False;
Setlanguage1.Enabled := False;
DBP('LoadFile - Resetting GUI');
filePath := sFile;
if (tlkdata = nil) then
raise EHell.Create('Failed to load selected TLK file! TLK Handler not initialized.');
DBP('LoadFile - Running TTLKFileHandler.LoadTlkFile()');
tlkdata.LoadTlkFile(filePath);
DBP('LoadFile - TTLKFileHandler.LoadFile() call completed...');
Mainform.Caption := 'TalkEd v1.0b (' + filePath + ')';
bpanel.panels[0].text := 'Opened file ' + filePath
+ '. ' + tlkdata.fileid
+ ' ' + tlkdata.version
+ '. ' + IntToStr(tlkdata.count) + ' entries read.';
DBP('LoadFile - Resetting StringGrid and text display boxes...');
ResetStringGrid(grid);
txtDisplay.clear();
grid.FixedCols := 0;
grid.FixedRows := 0;
grid.colcount := 1;
grid.ColWidths[0] := grid.Width - 6;
grid.cells[0, 0] := 'Please specify a StrRef interval of strings to display. Bigger interval uses more memory and time.';
grid.enabled := false;
DBP('LoadFile - Enabling GUI controls...');
lblInterval1.enabled := True;
lblInterval2.enabled := True;
btnShow.enabled := True;
edStart.enabled := True;
edStop.Enabled := True;
Tools1.Enabled := True;
Save1.Enabled := True;
Save2.Enabled := True;
Setlanguage1.Enabled := True;
i := tlkdata.count - 1;
if (i < 0) then
i := 0;
lblMax.Caption := '(' + IntToStr(i) + ' max.)';
edStart.text := '0';
edStop.text := IntToStr(i);
except
on e : EHell do ShowAlertBox('ERROR! ' + e.Message);
end;
DBP('LoadFile - END');
end;
procedure TMainForm.Open1Click(Sender: TObject);
var
sMessage : string;
oCursor : TCursor;
begin
DBP('OpenClick - START');
if (tlkdata.fileexists = True) then begin
if tlkdata.modified then begin
sMessage := 'Opening another TLK file will close the currently open one, causing any unsaved changes to be lost. Still continue?';
if (ShowConfirmBox(sMessage) = mrNo) then
exit;
end;
end;
try
DBP('OpenClick - Showing Open dialog box...');
OpenTlkFile.FileName := 'dialog.tlk';
if not OpenTlkFile.Execute then
begin
bpanel.panels[0].text := 'No valid file opened!';
Exit;
end;
DBP('OpenClick - Get value from Open dialog box...');
DBP('OpenClick - Changing cursor to hourglass....');
oCursor := Screen.Cursor;
Screen.Cursor := crHourglass;
Application.Processmessages;
DBP('OpenClick - Running LoadFile()');
LoadFile(OpenTlkFile.FileName);
edStart.SetFocus;
Screen.Cursor := oCursor;
DBP('OpenClick - Changing cursor back to default.');
except
on e : EHell do ShowAlertBox('ERROR! ' + e.Message);
end;
DBP('OpenClick - END');
end;
procedure TMainForm.Quit1Click(Sender: TObject);
var
sMessage : string;
begin
if (tlkdata <> nil) and (tlkdata.fileexists = True) then begin
if tlkdata.modified then begin
sMessage := 'Are you sure you wish to quit? Any unsaved information in the currently open TLK file will be lost.';
if (ShowConfirmBox(sMessage) = mrNo) then
exit;
end;
end;
Application.terminate;
end;
procedure TMainForm.Save1Click(Sender: TObject);
begin
try
SaveTlkFile.Filename := tlkdata.filename;
if not SaveTlkFile.Execute then
exit;
// raise EHell.Create('No valid filename or location specified!');
if (tlkdata = nil) then
raise EHell.Create('No open TLK file to write!');
tlkdata.SaveTlkFile(SaveTlkFile.FileName);
bpanel.panels[0].text := 'Saved file ' + SaveTlkFile.FileName
+ '. ' + tlkdata.fileid
+ ' ' + tlkdata.version
+ '. ' + IntToStr(tlkdata.count) + ' entries written.';
except
on e : EHell do ShowAlertBox('ERROR! ' + e.Message);
end;
end;
procedure TMainForm.gridClick(Sender: TObject);
var
sTemp : string;
sSnd : string;
begin
if (grid.colcount > 1) then
begin
sSnd := grid.cells[2, grid.row];
if (Length(sSnd) > 0) then
sSnd := '(' + sSnd + ')';
sTemp := grid.cells[1, grid.row];
txtDisplay.clear();
txtDisplay.lines.Text := grid.cells[0, grid.row] + ' ' + sSnd + ':' + #10 + #10 + sTemp;
end;
// REMEMBER: linefeed #10, creturn #13
end;
procedure TMainForm.Copy1Click(Sender: TObject);
begin
if (MainForm.ActiveControl is TCustomEdit) then
TCustomEdit(MainForm.ActiveControl).CopyToClipboard;
end;
procedure TMainForm.Selectall1Click(Sender: TObject);
begin
if (MainForm.ActiveControl is TCustomEdit) then
TCustomEdit(MainForm.ActiveControl).SelectAll;
end;
procedure TMainForm.Paste1Click(Sender: TObject);
var
sTemp : string;
iTemp : integer;
oEdit : TCustomEdit;
begin
// FIX(2005-10-06) Don't allow pasting non-number characters into
// the StrRef interval boxes.
if (MainForm.ActiveControl is TCustomEdit) then begin
oEdit := (MainForm.ActiveControl as TCustomEdit);
if ((oEdit.Name = 'edStart') or (oEdit.Name = 'edStop')) then begin
try
sTemp := Clipboard.AsText;
iTemp := StrToInt(sTemp);
except
beep();
exit;
end;
end;
end;
if (MainForm.ActiveControl is TCustomEdit) then
TCustomEdit(MainForm.ActiveControl).PasteFromClipboard;
end;
procedure TMainForm.Cut1Click(Sender: TObject);
var
oCtrl : TCustomEdit;
begin
if (MainForm.ActiveControl is TCustomEdit) then
begin
oCtrl := TCustomEdit(MainForm.ActiveControl);
if ((oCtrl is TMemo) and TMemo(oCtrl).ReadOnly) then
oCtrl.CopyToClipboard
else
oCtrl.CutToClipboard;
end;
end;
procedure TMainForm.Search1Click(Sender: TObject);
begin
if (tlkdata.fileexists = False) then begin
ShowAlertBox('Error! No TLK file is currently open. There is nothing to search in.');
exit;
end;
SearchForm.entrycount := tlkdata.count;
SearchForm.Reposition(Left + 32, Top + 64);
if (SearchForm.ShowModal = mrOk) then
DoSearchFilter();
end;
// -----------------------------------------------------------------------------
// Check if each individual word in the search criteria exists within the
// search data. Ordering is not important, but all criteria must be found.
// -----------------------------------------------------------------------------
function TMainForm.CheckWordMatch(sCriteria : string; sData : string) : boolean;
var
oCrit : TStringTokenizer;
oData : TStringTokenizer;
i, n : integer;
iMatches : integer;
sCWord : string;
sDWord : string;
begin
if ((Length(sCriteria) < 3)
or (Pos(' ', sCriteria) = 0)
or (Length(sData) < 3)
or (Pos(' ', sData) = 0))
then begin
result := (sCriteria = sData);
end
else begin
oCrit := TStringTokenizer.Create(sCriteria, ' ');
try
oData := TStringTokenizer.Create(sData, ' ');
try
// No data to search in, match none...
if (oData.count = 0) then begin
result := False;
exit;
end
// No search criteria, match all...
else if (oCrit.count = 0) then begin
result := True;
exit;
end;
// Check for matches....
for i := 0 to (oCrit.count - 1) do begin
iMatches := 0;
sCWord := oCrit.strings[i];
// Cut away any trailing periods, commas, exclamation
// marks and question marks before comparing.
if (sCWord[Length(sCWord)] in ['.', '!', '?', ',']) then
sCWord := copy(sCWord, 1, Length(sCWord) - 1);
for n := 0 to (oData.count - 1) do begin
sDWord := oData.strings[n];
// Cut away any trailing periods, commas, exclamation
// marks and question marks before comparing.
if (sDWord[Length(sDWord)] in ['.', '!', '?', ',']) then
sDWord := copy(sDWord, 1, Length(sDWord) - 1);
// Check if this word matches the search criteria.
if (sCWord = sDWord) then
inc(iMatches);
end;
// If no word in the string matched this word criteria,
// the search may as well stop. Every criteria needs to be
// matched at least once in the search data.
if (iMatches = 0) then begin
result := False;
exit;
end;
end;
result := True;
finally
oData.free();
end;
finally
oCrit.free();
end;
end;
end;
procedure TMainForm.DoSearchFilter();
var
iCount : integer;
iStart : DWORD;
iStop : DWORD;
sResref : string;
tlkentry : TTLKString;
str : string;
sSub : string;
sFull : string;
bCase : boolean;
bNegate : boolean;
bExact : boolean;
bWords : boolean;
bNew : boolean;
bNoBlank : boolean;
bSound : boolean;
begin
try
if (tlkdata = nil) then
raise EHell.Create('Error while performing search. No valid TLK file found to search');
str := SearchForm.edString.text;
sResRef := SearchForm.edResref.text;
try
iStart := StrToInt(SearchForm.edStart.text);
iStop := StrToInt(SearchForm.edStop.text);
except
on e : EConvertError do begin
ShowAlertBox('Error! You can only use numbers when specifying an interval to search in!');
exit;
end;
end;
bCase := SearchForm.cbMatchCase.checked;
bNegate := SearchForm.cbNegate.checked;
bExact := SearchForm.cbExactMatch.checked;
bWords := SearchForm.cbWordSearch.checked;
bSound := SearchForm.cbSoundSearch.checked;
bNew := SearchForm.cbFlagNew.checked;
bNoBlank := SearchForm.cbFilterBlank.checked;
if ((iStart > iStop)) then
raise EHell.Create('Invalid start value of interval to search!');
if (iStop > (tlkdata.count-1)) or (iStop < iStart) then
raise EHell.Create('Oi! Invalid end value of interval to search!');
pbar.position := 0;
pbar.max := iStop - iStart;
txtDisplay.clear();
ResetStringGrid(grid);
grid.enabled := false;
grid.colcount := 3;
grid.rowcount := 2;
grid.FixedCols := 1;
grid.FixedRows := 1;
grid.Cells[0, 0] := 'StrRef';
grid.Cells[1, 0] := 'Entry text';
grid. Cells[2, 0] := 'Sound Resref';
grid.ColWidths[0] := 64;
grid.ColWidths[1] := (grid.Width - 70 - SOUND_COLUMN_WIDTH_MARGIN);
grid.ColWidths[2] := SOUND_COLUMN_WIDTH;
iCount := 1;
tlkentry := tlkdata.strings.first();
while ((tlkentry <> nil) and (tlkentry.strref <= iStop)) do
begin
if ((tlkentry.strref >= iStart) and (tlkentry.strref <= iStop)) then
begin
if (bCase = True) then begin
sSub := str;
sFull := tlkentry.strtext;
end
else begin
sSub := lowercase(str);
sFull := lowercase(tlkentry.strtext);
end;
if ( ((bNoBlank = False) or ((bNoBlank = True) and (Length(tlkentry.strtext) > 0)))
and ((bNew = False) or ((bNew = True) and (tlkentry.iscustom = True)))
and ((bSound = False) or ((bSound = True) and (Length(tlkentry.soundstring) > 0)))
and ( (Length(str) = 0)
or ((bNegate = False)
and (((bWords = True) and CheckWordMatch(sSub, sFull))
or (((bExact = False) and (Pos(sSub, sFull) <> 0)) or ((bExact = True) and (sSub = sFull)))))
or ((bNegate = True)
and (((bWords = True) and not CheckWordMatch(sSub, sFull))
or (((bExact = False) and (Pos(sSub, sFull) = 0)) or ((bExact = True) and (sSub <> sFull))))) )
and ((Length(sResRef) = 0) or (Pos(lowercase(sResRef), lowercase(tlkentry.strsound)) <> 0)))
then
begin
grid.rowcount := grid.rowcount + 1;
grid.cells[0, iCount] := IntToStr(tlkentry.strref);
grid.cells[1, iCount] := ReplaceInString(tlkentry.strtext, #13, ''); // tlkentry.strtext;
grid.cells[2, iCount] := tlkentry.soundstring;
pbar.position := iCount;
iCount := iCount + 1;
end;
end;
tlkentry := tlkdata.strings.next();
end;
// FIX(2005-10-05) No entries were found if iCount is 1, not 0...
if (iCount = 1) then
begin
grid.FixedCols := 0;
grid.FixedRows := 0;
grid.colcount := 1;
grid.rowcount := 1; // FIX(2005-10-05) Reduced RC to 1 again.
grid.ColWidths[0] := grid.Width - 6;
grid.cells[0, 0] := 'No entries matching the specified criteria were found!';
grid.enabled := false;
bpanel.panels[0].text := 'Search completed. No matching results found.';
end
else
begin
grid.rowcount := grid.rowcount - 1;
grid.enabled := true;
bpanel.panels[0].text := 'Search completed. ' + IntToStr(iCount)
+ ' matches found to specified criteria.';
txtDisplay.setfocus();
grid.setfocus();
l_resultslisted := True;
end;
pbar.position := 0;
except
on e : EHell do ShowAlertBox('ERROR! ' + e.Message);
end;
end;
procedure TMainForm.Newentry1Click(Sender: TObject);
begin
EntryForm.Reset();
EntryForm.Reposition(Left + 32, Top + 64);
EntryForm.Caption := 'Add new entry';
EntryForm.entrycount := tlkdata.count;
if (EntryForm.ShowModal = mrOk) then
DoAddEntry();
end;
procedure TMainForm.DoAddEntry();
var
tlkentry : TTLKString;
fLength : float;
sResref : TResRef;
iFlags : DWORD;
iVolume : DWORD;
iPitch : DWORD;
i : integer;
sTempString : string;
iStart : DWORD;
begin
try
if (tlkdata.fileexists = False) then
raise EHell.Create('No TLK file us currently open. Nothing to add an entry to');
// This shouldn't happen, but it's best to check that the handler is created.
if (tlkdata = nil) then
raise EHell.Create('Unable to locate a valid TLK to add an entry to!');
// Put this up here to break off early due to invalid decimal
// operator usage exceptions and such....
try
fLength := StrToFloat(EntryForm.edLength.text);
except
on e : EConvertError do
begin;
ShowAlertBox('Error reading decimal value. Only numbers allowed, and you must use ' + DecimalSeparator + ' as a decimal separator!');
exit;
end;
end;
try
iVolume := StrToInt(EntryForm.edVolume.text);
iPitch := StrToInt(EntryForm.edPitch.text);
except
on e : EConvertError do begin
ShowAlertBox('Error! Volume and pitch variance must be non-decimal numbers!');
exit;
end;
end;
// Combine the checked flags into the bitfield data that should be stored.
iFlags := $0;
if (EntryForm.cbText.checked = True) then
iFlags := iFlags or TEXT_PRESENT;
if (EntryForm.cbSound.checked = True) then
iFlags := iFlags or SND_PRESENT;
if (EntryForm.cbLength.checked = True) then
iFlags := iFlags or SNDLENGTH_PRESENT;
// Transform the Resref from a string into a TResRef so it can be stored.
for i := 0 to 15 do begin
if (Length(EntryForm.edResref.text) > i) then
sResRef[i] := EntryForm.edResref.text[i+1]
else
sResRef[i] := #0;
end;
// Create a new String Entry and store the info from the input boxes.
tlkentry := TTLKString.Create();
tlkentry.strflags := iFlags;
tlkentry.sndvolume := iVolume;
tlkentry.sndpitch := iPitch;
tlkentry.sndlength := fLength;
tlkentry.strsound := sResRef;
// Remove carriage returns from the text, since the Text property
// returns both LF and CR for changing rows.
sTempString := EntryForm.txtString.text;
sTempString := ReplaceInString(sTempString, #13, '');
tlkentry.strtext := sTempString;
// Add the new entry to the list of entries...
tlkdata.AddEntry(tlkentry);
// Display some feedback that the entry has been added.
sTempString := IntToStr(tlkdata.count-1);
// ShowInfoBox('New string entry added to TLK with StrRef #' + sTempString + '.');
// FIX(2005-05-21)
// Start the listing at the first new entry instead....
if (l_firstnew = -1) then
l_firstnew := tlkdata.count-1;
iStart := StrToInt(edStart.text);
if (((tlkdata.count-1) - iStart) > 1000) then
edStart.text := IntToStr((tlkdata.count-1) - 1000);
edStop.text := sTempString;
btnShowClick(btnShow);
Save2.enabled := True;
for i:= 0 to (grid.rowcount - 1) do begin
if (grid.cells[0, i] = sTempString) then begin
grid.row := i;
break;
end;
end;
lblMax.Caption := '(' + sTempString + ' max.)';
btnShowClick(btnShow);
grid.row := grid.rowcount - 1;
Save2.enabled := True;
except
on e : EHell do ShowAlertBox('ERROR! ' + e.Message);
end;
end;
procedure TMainForm.DoModifyEntry(tlkentry : TTLKString);
var
fLength : float;
sResref : TResRef;
iFlags : DWORD;
i : integer;
sTempString : string;
begin
try
// This shouldn't happen, but it's best to check that the handler is created.
if (tlkdata = nil) then
raise EHell.Create('Unable to locate a valid TLK to modify an entry in!');
if (tlkentry = nil) then
raise EHell.Create('Unable to find the entry that should be modified!');
// Put this up here to break off early due to invalid decimal
// operator usage exceptions and such....
try
fLength := StrToFloat(EntryForm.edLength.text);
except
on e : EConvertError do
begin;
ShowAlertBox('Error reading decimal value. Only numbers allowed, and you must use ' + DecimalSeparator + ' as a decimal separator!');
exit;
end;
end;
// Combine the checked flags into the bitfield data that should be stored.
iFlags := $0;
if (EntryForm.cbText.checked = True) then
iFlags := iFlags or TEXT_PRESENT;
if (EntryForm.cbSound.checked = True) then
iFlags := iFlags or SND_PRESENT;
if (EntryForm.cbLength.checked = True) then
iFlags := iFlags or SNDLENGTH_PRESENT;
// Transform the Resref from a string into a TResRef so it can be stored.
for i := 0 to 15 do begin
if (Length(EntryForm.edResref.text) > i) then
sResRef[i] := EntryForm.edResref.text[i+1]
else
sResRef[i] := #0;
end;
// Store the info from the input boxes in the entry object.
tlkentry.strflags := iFlags;
tlkentry.sndvolume := StrToInt(EntryForm.edVolume.text);
tlkentry.sndpitch := StrToInt(EntryForm.edPitch.text);
tlkentry.sndlength := fLength;
tlkentry.strsound := sResRef;
// Remove carriage returns from the text, since the Text property
// returns both LF and CR for changing rows.
sTempString := EntryForm.txtString.text;
sTempString := ReplaceInString(sTempString, #13, '');
tlkentry.strtext := sTempString;
// Modify an existing entry with this data
tlkdata.ReplaceEntry(tlkentry);
// ShowInfoBox('String entry with StrRef #' + IntToStr(tlkentry.strref) + ' has now been modified!');
if (dword(StrToInt(edStart.text)) > tlkentry.strref) then
edStart.text := IntToStr(tlkentry.strref);
if (dword(StrToInt(edStop.text)) < tlkentry.strref) then
edStop.text := IntToStr(tlkentry.strref);
if l_resultslisted then
DoSearchFilter()
else