forked from ericlangedijk/Lemmix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GameScreen.Finder.pas
958 lines (833 loc) · 29.6 KB
/
GameScreen.Finder.pas
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
unit GameScreen.Finder;
interface
// THIS SCREEN IS IN AN EXPERIMENTAL PHASE
// todo: do not use Grid DblClick: dblclick on header will PLAY the level and only god knows why. Row is not updated.
// todo: grid index out of range
uses
LCLIntf, LCLType, LMessages,
Types, Classes, SysUtils, Generics.Collections, UITypes, Contnrs, Variants,
Generics.Defaults,
Graphics, Controls, StdCtrls, ExtCtrls, Dialogs, Forms, GraphUtil, Grids, ClipBrd,
Base.Utils, Base.Bitmaps,
Dos.Consts,
Prog.Types, Prog.Base, Prog.Data, Prog.Cache,
Styles.Base,
Game,
Prog.App,
Form.Base, Form.Message;
type
// This is a 'normal' windows screen
TGameScreenFinder = class(TBaseDosForm)
private
type
TProp = record
Value: Variant;
Text: string;
end;
type
TRecord = class
private
const
property_count = 28;
prop_refindex = 0;
prop_sectionindex = 1;
prop_levelindex = 2;
prop_stylename = 3;
prop_leveltitle = 4;
prop_releaserate = 5;
prop_lemmingscount = 6;
prop_rescuecount = 7;
prop_timelimit = 8;
prop_climbercount = 9;
prop_floatercount = 10;
prop_bombercount = 11;
prop_blockercount = 12;
prop_buildercount = 13;
prop_bashercount = 14;
prop_minercount = 15;
prop_diggercount = 16;
prop_graphicset = 17;
prop_graphicsetex = 18;
prop_superlemming = 19;
prop_objectcount = 20;
prop_terraincount = 21;
prop_entrancecount = 22;
prop_exitcount = 23;
prop_levelhash = 24;
prop_levelcode = 25;
prop_duplicates = 26;
prop_sourcefile = 27;
//prop_cachedate = 28;
private
Ref: TStyleCache.TLevelCacheItem; // ref to original cache item in the style cache
RefIndex: Integer; // the original index in the cache
Duplicates: Integer; // calulated once during contruction
MyStyle: (sOriginal, sCustom, sLemmini); // for colorizing
//Cachedate: TDateTime;
public
constructor Create(cacheIndex: Integer);
function GetProp(index: Integer): TProp;
function GetText(index: Integer): string;
function Filter(index: Integer; const s: string): Boolean;
end;
TRecordList = class(TFastObjectList<TRecord>);
private
const
Headers: array[0..TRecord.property_count - 1] of string = (
'Index', 'Sect', 'Lev', 'Style', 'Title',
'RR', 'Lem', 'Res', 'Tim', 'Cli', 'Flo', 'Bom', 'Blo', 'Bui', 'Bas', 'Min', 'Dig',
'Gra', 'Spec', 'Fast', 'Obj', 'Ter', 'Entr', 'Ex', 'Hash', 'Code', 'Dup', 'Source'
);
ColumnColors : array[0..TRecord.property_count - 1] of TColor = (
clSilver, TColor($4169E1), TColor($4169E1), clNone, clWhite,
clFuchsia, clFuchsia,clFuchsia,clFuchsia,clFuchsia,clFuchsia,clFuchsia,clFuchsia,clFuchsia,clFuchsia,clFuchsia,clFuchsia,
TColor($FF4500), TColor($FF4500), TColor($6495ED), TColor($FF4500), TColor($FF4500), TColor($FF4500), TColor($FF4500), TColor($4169E1), TColor($4169E1), clRed, TColor($F08080));
const
DEF_ROWHEIGHT = 21;
HEADER_ROWCOUNT = 3;
FIRST_DATAROW = 3;
private
fLockCount: Integer;
fRecordList: TRecordList;
fRefList: TList<Integer>;
fGrid: TDrawGrid;
fSortColumn: Integer;
fSortedAscending: Boolean;
fLabelRecordCount: TLabel;
fEdit: TEdit;
fEditorCol: Integer;
fLastSelectedRecord: TRecord;
fLastRelativePosition: Integer;
fApproxRowsOnScreen: Integer;
fUserFilters: array[0..TRecord.property_count - 1] of string;
fHighlightBitmap: TBitmap;
function GetItem(aRow: Integer): TRecord; inline;
procedure Grid_KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure Grid_KeyPress(Sender: TObject; var Key: Char);
procedure Grid_DblClick(Sender: TObject);
procedure Grid_DrawCell(Sender: TObject; aCol, aRow: Longint; aRect: TRect; aState: TGridDrawState);
procedure Grid_SelectCell(Sender: TObject; aCol, aRow: Longint; var canSelect: Boolean);
procedure Grid_FixedCellClick(Sender: TObject; aCol, aRow: Longint);
procedure Editor_KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure Editor_KeyPress(Sender: TObject; var Key: Char);
function EditorVisible: Boolean;
procedure SetSelectedRecord(item: TRecord; aRelativePosition: Integer);
procedure Lock;
procedure Unlock;
procedure UpdateLabel;
procedure PaintArrowDown(const aRect: TRect; aColor: TColor);
procedure PaintArrowUp(const aRect: TRect; aColor: TColor);
procedure Sort(aCol: Integer; Asc: Boolean);
procedure Filter;
procedure ClearFilters;
procedure TryCloseAndPlay;
procedure CopyGridToClipBoard;
procedure EditorStart(aCol: Integer);
procedure EditorEnd(accept: Boolean);
protected
procedure BuildScreen; override;
public
constructor Create(aOwner: TComponent); override;
destructor Destroy; override;
end;
implementation
uses
GameScreen.Options; // only for color consts GUI
type
TDrawGridHack = class(TDrawGrid);
{ TGameScreenFinder.TRecord }
constructor TGameScreenFinder.TRecord.Create(cacheIndex: Integer);
var
info: Consts.TStyleInformation;
begin
RefIndex := cacheIndex;
Ref := App.StyleCache.FlatList[RefIndex];
Duplicates := Length(App.StyleCache.FindLevelsByHash(Ref.LevelHash)) - 1;
info := Consts.FindStyleInfo(Ref.StyleName);
if Assigned(info) then begin
if info.StyleDef < TStyleDef.User then
myStyle := sOriginal
else begin
if info.Family = TStyleFamily.DOS then
myStyle := sCustom
else
myStyle := sLemmini;
end;
end;
end;
function TGameScreenFinder.TRecord.GetText(index: Integer): string;
procedure SetResult(const s: string);
begin
Result := s;
end;
begin
case index of
prop_refindex: SetResult(RefIndex.ToString);
prop_sectionindex: SetResult(Ref.SectionIndex.ToString);
prop_levelindex: SetResult(Ref.LevelIndex.ToString);
prop_stylename: SetResult(Ref.StyleName);
prop_leveltitle: SetResult(Trim(string(Ref.LevelTitle)));
prop_releaserate: SetResult(Ref.Statics.ReleaseRate.ToString);
prop_lemmingscount: SetResult(Ref.Statics.LemmingsCount.ToString);
prop_rescuecount: SetResult(Ref.Statics.RescueCount.ToString);
prop_timelimit: SetResult(Ref.Statics.TimeLimit.ToString);
prop_climbercount: SetResult(Ref.Statics.ClimberCount.ToString);
prop_floatercount: SetResult(Ref.Statics.FloaterCount.ToString);
prop_bombercount: SetResult(Ref.Statics.BomberCount.ToString);
prop_blockercount: SetResult(Ref.Statics.BlockerCount.ToString);
prop_buildercount: SetResult(Ref.Statics.BuilderCount.ToString);
prop_bashercount: SetResult(Ref.Statics.BasherCount.ToString);
prop_minercount: SetResult(Ref.Statics.MinerCount.ToString);
prop_diggercount: SetResult(Ref.Statics.DiggerCount.ToString);
prop_graphicset: SetResult(Ref.Statics.GraphicSet.ToString);
prop_graphicsetex: SetResult(Ref.Statics.GraphicSetEx.ToString);
prop_superlemming: SetResult(Byte(Ref.Statics.SuperLemming).ToString);
prop_objectcount: SetResult(Ref.Statics.ObjectCount.ToString);
prop_terraincount: SetResult(Ref.Statics.TerrainCount.ToString);
prop_entrancecount: SetResult(Ref.Statics.EntranceCount.ToString);
prop_exitcount: SetResult(Ref.Statics.ExitCount.ToString);
prop_levelhash: SetResult(IntToHex(Ref.LevelHash, 16));
prop_duplicates: SetResult(Duplicates.ToString);
prop_levelcode: SetResult(Ref.LevelCode);
prop_sourcefile: SetResult(Ref.SourceFile);
//prop_cachedate: SetResult('date');
else
SetResult('');
end;
end;
function TGameScreenFinder.TRecord.GetProp(index: Integer): TProp;
procedure SetResult(const v: Variant; const s: string);
begin
Result.Value := v;
Result.Text := s;
end;
begin
case index of
prop_refindex : SetResult(RefIndex, RefIndex.ToString);
prop_sectionindex : SetResult(Ref.SectionIndex, Ref.SectionIndex.ToString);
prop_levelindex : SetResult(Ref.LevelIndex, Ref.LevelIndex.ToString);
prop_stylename : SetResult(Ref.StyleName, Ref.StyleName);
prop_leveltitle : SetResult(string(Ref.LevelTitle), Trim(string(Ref.LevelTitle)));
prop_releaserate : SetResult(Ref.Statics.ReleaseRate, Ref.Statics.ReleaseRate.ToString);
prop_lemmingscount : SetResult(Ref.Statics.LemmingsCount, Ref.Statics.LemmingsCount.ToString);
prop_rescuecount : SetResult(Ref.Statics.RescueCount, Ref.Statics.RescueCount.ToString);
prop_timelimit : SetResult(Ref.Statics.TimeLimit, Ref.Statics.TimeLimit.ToString);
prop_climbercount : SetResult(Ref.Statics.ClimberCount, Ref.Statics.ClimberCount.ToString);
prop_floatercount : SetResult(Ref.Statics.FloaterCount, Ref.Statics.FloaterCount.ToString);
prop_bombercount : SetResult(Ref.Statics.BomberCount, Ref.Statics.BomberCount.ToString);
prop_blockercount : SetResult(Ref.Statics.BlockerCount, Ref.Statics.BlockerCount.ToString);
prop_buildercount : SetResult(Ref.Statics.BuilderCount, Ref.Statics.BuilderCount.ToString);
prop_bashercount : SetResult(Ref.Statics.BasherCount, Ref.Statics.BasherCount.ToString);
prop_minercount : SetResult(Ref.Statics.MinerCount, Ref.Statics.MinerCount.ToString);
prop_diggercount : SetResult(Ref.Statics.DiggerCount, Ref.Statics.DiggerCount.ToString);
prop_graphicset : SetResult(Ref.Statics.GraphicSet, Ref.Statics.GraphicSet.ToString);
prop_graphicsetex : SetResult(Ref.Statics.GraphicSetEx, Ref.Statics.GraphicSetEx.ToString);
prop_superlemming : SetResult(Ref.Statics.SuperLemming, Byte(Ref.Statics.SuperLemming).ToString);
prop_objectcount : SetResult(Ref.Statics.ObjectCount, Ref.Statics.ObjectCount.ToString);
prop_terraincount : SetResult(Ref.Statics.TerrainCount, Ref.Statics.TerrainCount.ToString);
prop_entrancecount : SetResult(Ref.Statics.EntranceCount, Ref.Statics.EntranceCount.ToString);
prop_exitcount : SetResult(Ref.Statics.ExitCount, Ref.Statics.ExitCount.ToString);
prop_levelhash : SetResult(Ref.LevelHash, IntToHex(Ref.LevelHash, 16));
prop_duplicates : SetResult(Duplicates, Duplicates.ToString);
prop_levelcode : SetResult(Ref.LevelCode, Ref.LevelCode);
prop_sourcefile : SetResult(Ref.SourceFile,Ref.SourceFile);
//prop_cachedate : SetResult(Cachedate, '1');
else
SetResult(RefIndex, RefIndex.ToString);
end;
end;
function TGameScreenFinder.TRecord.Filter(index: Integer; const s: string): Boolean;
begin
if index in [prop_stylename, prop_leveltitle, prop_levelhash, prop_levelcode, prop_sourcefile] then
Result := GetText(index).ToUpper.Contains(s.ToUpper)
else
Result := GetText(index) = s;
end;
{ TGameScreenFinder }
constructor TGameScreenFinder.Create(aOwner: TComponent);
begin
inherited;
DoubleBuffered := True;
Cursor := crDefault;
fRecordList := TRecordList.Create(True);
fRefList := TList<Integer>.Create;
fGrid := TDrawGrid.Create(Self);
fHighlightBitmap := TBitmap.Create;
fHighlightBitmap.SetSize(32, 32);
fHighlightBitmap.Canvas.Brush.Color := clLime;
fHighlightBitmap.Canvas.FillRect(Rect(0, 0, 32, 32));
end;
destructor TGameScreenFinder.Destroy;
begin
fRecordList.Free;
fRefList.Free;
fHighlightBitmap.Free;
inherited;
end;
procedure TGameScreenFinder.BuildScreen;
function TW(cnt: Integer): Integer;
var
a, b: Integer;
begin
a := fGrid.Canvas.TextWidth(StringOfChar('W', cnt));
b := fGrid.Canvas.TextWidth(StringOfChar('y', cnt));
Result := (a + b) div 2;
end;
var
initiallySelectedRecord: TRecord;
currLevel: TLevelLoadingInformation;
cachedItem: TStyleCache.TLevelCacheItem;
newRec: TRecord;
i: Integer;
// totalColWidths: Integer;
begin
initiallySelectedRecord := nil;
currLevel := App.CurrentLevelInfo;
// for var cachename: string in App.StyleCache.GetCacheFilenames do begin
//
// end;
// get all record refs
fRecordList.Clear;
for i := 0 to App.StyleCache.FlatList.Count - 1 do begin
newRec := TRecord.Create(i);
fRecordList.Add(newRec);
fRefList.Add(i);
// initially selected item
cachedItem := App.StyleCache.FlatList[i];
if Assigned(currLevel)
and not Assigned(initiallySelectedRecord)
and (cachedItem.SectionIndex = currLevel.SectionIndex)
and (cachedItem.LevelIndex = currLevel.LevelIndex)
and (cachedItem.StyleName = currLevel.Style.Name) then
initiallySelectedRecord := newRec;
end;
fGrid.Parent := Self;
fGrid.Align := alClient;
//fGrid.AlignWithMargins := True;
//fGrid.Margins.SetBounds(8, 8, 8, 8);
fGrid.ColCount := (fGrid.Width - Scale(24)) div Scale(320);
fGrid.ScrollBars := ssNone;
fGrid.RowCount := fRecordList.Count + 3;
fGrid.ColCount := TRecord.property_count;
fGrid.FixedRows := 3; // 0 = filter, 1 = sort, 2 = title
fGrid.FixedCols := 0;
fGrid.DefaultColWidth := 80;
fGrid.DefaultRowHeight := DEF_ROWHEIGHT;
fGrid.Color := clBlack;
fGrid.ParentColor := True;
fGrid.DefaultDrawing := False;
//fGrid.DrawingStyle := TGridDrawingStyle.gdsClassic;
fGrid.BorderStyle := bsNone;
fGrid.Options := fGrid.Options
- [TGridOption.goDrawFocusSelected, TGridOption.goVertLine, TGridOption.goHorzLine, TGridOption.goRangeSelect, TGridOption.goFixedVertLine, TGridOption.goFixedHorzLine]
+ [TGridOption.goColSizing{, TGridOption.goFixedRowClick}];
//const TW(4) = TW(4);
fGrid.ColWidths[TRecord.prop_refindex] := TW(6);
fGrid.ColWidths[TRecord.prop_sectionindex] := TW(4);
fGrid.ColWidths[TRecord.prop_levelindex] := TW(4);
fGrid.ColWidths[TRecord.prop_stylename] := TW(4) * 4;
fGrid.ColWidths[TRecord.prop_leveltitle] := TW(4) * 8;
fGrid.ColWidths[TRecord.prop_releaserate] := TW(4);
fGrid.ColWidths[TRecord.prop_lemmingscount] := TW(4);
fGrid.ColWidths[TRecord.prop_rescuecount] := TW(4);
fGrid.ColWidths[TRecord.prop_timelimit] := TW(4);
fGrid.ColWidths[TRecord.prop_climbercount] := TW(4);
fGrid.ColWidths[TRecord.prop_floatercount] := TW(4);
fGrid.ColWidths[TRecord.prop_bombercount] := TW(4);
fGrid.ColWidths[TRecord.prop_blockercount] := TW(4);
fGrid.ColWidths[TRecord.prop_buildercount] := TW(4);
fGrid.ColWidths[TRecord.prop_bashercount] := TW(4);
fGrid.ColWidths[TRecord.prop_minercount] := TW(4);
fGrid.ColWidths[TRecord.prop_diggercount] := TW(4);
fGrid.ColWidths[TRecord.prop_graphicset] := TW(4);
fGrid.ColWidths[TRecord.prop_graphicsetex] := TW(4);
fGrid.ColWidths[TRecord.prop_superlemming] := TW(4);
fGrid.ColWidths[TRecord.prop_objectcount] := TW(4);
fGrid.ColWidths[TRecord.prop_terraincount] := TW(4);
fGrid.ColWidths[TRecord.prop_entrancecount] := TW(4);
fGrid.ColWidths[TRecord.prop_exitcount] := TW(4);
fGrid.ColWidths[TRecord.prop_levelhash] := TW(4) * 4;
fGrid.ColWidths[TRecord.prop_levelcode] := TW(4) * 3;
fGrid.ColWidths[TRecord.prop_duplicates] := TW(4);
fGrid.ColWidths[TRecord.prop_sourcefile] := TW(4) * 8;
// // todo: we have to find out what is going wrong here on High-Dpi
// totalColWidths := 0;
// for var i := 0 to fgrid.ColCount - 2 do
// Inc(totalColWidths, fGrid.ColWidths[i]);
//
//// dlg(totalColWidths.ToString + ' ' + fGrid.ClientWidth.ToString);
//
// //var w: integer := fGrid.ColWidths[TRecord.prop_sourcefile];
// if totalColWidths < fGrid.ClientWidth then
// fGrid.ColWidths[TRecord.prop_sourcefile] := fGrid.ClientWidth - totalColWidths;
// fGrid.RowHeights[1] := 12;
fGrid.OnDrawCell := Grid_DrawCell;
fGrid.OnDblClick := Grid_DblClick;
fGrid.OnSelectCell := Grid_SelectCell;
//fGrid.OnFixedCellClick := Grid_FixedCellClick;
fGrid.OnKeyDown := Grid_KeyDown;
fGrid.OnKeyPress := Grid_KeyPress;
fLabelRecordCount := TLabel.Create(Self);
fLabelRecordCount.Parent := Self;
fLabelRecordCount.AutoSize := False;
fLabelRecordCount.Height := DEF_ROWHEIGHT;
fLabelRecordCount.Align := alBottom;
fLabelRecordCount.Alignment := taCenter;
fLabelRecordCount.Font.Color := clgray;
fEdit := TEdit.Create(Self);
fEdit.Parent := fGrid;
fEdit.Visible := False;
fEdit.Color := clblack;
fEdit.Font.Color := clYellow;
fEdit.BorderStyle := bsNone;
fEdit.OnKeyDown := Editor_KeyDown;
fEdit.OnKeyPress := Editor_KeyPress;
fSortColumn := TRecord.prop_refindex;
fSortedAscending := True;
UpdateLabel;
fGrid.Col := TRecord.prop_leveltitle;
fApproxRowsOnScreen := (fGrid.Height div Scale(DEF_ROWHEIGHT));
if Assigned(initiallySelectedRecord) then
SetSelectedRecord(initiallySelectedRecord, fApproxRowsOnScreen div 2);
end;
function TGameScreenFinder.GetItem(aRow: Integer): TRecord;
begin
if (aRow >= FIRST_DATAROW) and (aRow - HEADER_ROWCOUNT < fRefList.Count) then
Result := fRecordList[fRefList[aRow - HEADER_ROWCOUNT]]
else
Result := nil;
end;
procedure TGameScreenFinder.PaintArrowDown(const aRect: TRect; aColor: TColor);
// sortmarker
var
P: TPoint;
begin
if aRect.Width < Scale(10) then
Exit;
P := Point(aRect.Left + Scale(2), aRect.Top + Scale(4));
fGrid.Canvas.Pen.Color := aColor;
DrawArrow(fGrid.Canvas, GraphUtil.sdDown, P, Scale(5));
end;
procedure TGameScreenFinder.PaintArrowUp(const aRect: TRect; aColor: TColor);
// sortmarker
var
P: TPoint;
begin
if aRect.Width < Scale(10) then
Exit;
P := Point(aRect.Left + Scale(2), aRect.Top + Scale(4));
fGrid.Canvas.Pen.Color := aColor;
DrawArrow(fGrid.Canvas, GraphUtil.sdUp, P, Scale(5));
end;
procedure TGameScreenFinder.SetSelectedRecord(item: TRecord; aRelativePosition: Integer);
var
newTop: Integer;
found: Boolean;
i: Integer;
begin
if (item = nil) and (fGrid.RowCount <= HEADER_ROWCOUNT) then
Exit;
found := False;
for i := FIRST_DATAROW to fGrid.RowCount - 1 do
if GetItem(i) = item then begin
fGrid.Row := i;
found := True;
Break;
end;
// not found
if not found then begin
if fGrid.RowCount > HEADER_ROWCOUNT then
fGrid.Row := FIRST_DATAROW;
Exit;
end;
newTop := fGrid.Row - aRelativePosition;
if (newTop >= FIRST_DATAROW) and (fGrid.Row > fApproxRowsOnScreen) and (fGrid.RowCount >= fApproxRowsOnScreen) then // (fGrid.RowCount > fGrid.ClientHeight div Scale(20)) then
fGrid.TopRow := newTop
// else
// fGrid.TopRow := FIRST_DATAROW
end;
procedure TGameScreenFinder.Sort(aCol: Integer; Asc: Boolean);
begin
{
Lock;
try
fRefList.Sort(
TComparer<Integer>.Construct(
function(const a, b: Integer): Integer
var
r1, r2: TRecord;
compareResult: TVariantRelationShip;
begin
r1 := fRecordList[a];
r2 := fRecordList[b];
if aCol in [TRecord.prop_stylename, TRecord.prop_leveltitle, TRecord.prop_levelcode, TRecord.prop_sourcefile] then
Result := CompareText(r1.GetText(aCol), r2.GetText(aCol))
else begin
compareResult:= VarCompareValue(r1.GetProp(aCol).Value, r2.GetProp(aCol).Value);
case compareResult of
TVariantRelationship.vrLessThan: Result := -1;
TVariantRelationship.vrGreaterThan: Result := 1;
else
Result := 0;
end;
end;
if not Asc then Result := -Result;
end)
);
fSortColumn := aCol;
fSortedAscending := Asc;
finally
Unlock;
end;
}
end;
procedure TGameScreenFinder.TryCloseAndPlay;
var
item: TRecord;
begin
item := GetItem(fGrid.Row);
if not Assigned(item) then
Exit;
App.NewStyleName := item.Ref.StyleName;
App.NewSectionIndex := Item.Ref.SectionIndex;
App.NewLevelIndex := Item.Ref.LevelIndex;
CloseScreen(TGameScreenType.Preview);
end;
procedure TGameScreenFinder.Lock;
begin
Inc(fLockCount);
if fLockCount = 1 then begin
fLastSelectedRecord := GetItem(fGrid.Row);
fLastRelativePosition := fGrid.Row - fGrid.TopRow;
end;
end;
procedure TGameScreenFinder.Unlock;
begin
if fLockCount = 1 then begin
SetSelectedRecord(fLastSelectedRecord, fLastRelativePosition);
fGrid.Invalidate;
end;
Dec(fLockCount);
end;
procedure TGameScreenFinder.UpdateLabel;
begin
if fRefList.Count = fRecordList.Count then
fLabelRecordCount.Caption := fRefList.Count.ToString + ' levels'
else
fLabelRecordCount.Caption := fRefList.Count.ToString + ' / ' + fRecordList.Count.ToString + ' levels';
end;
procedure TGameScreenFinder.Filter;
var
filterlist: TList<Integer>;
i, ix: Integer;
rec: TRecord;
accept: Boolean;
prop: Integer;
begin
Lock;
try
fRefList.Clear;
filterlist := TList<Integer>.Create;
try
for i := 0 to TRecord.property_count - 1 do
if not fUserFilters[i].IsEmpty then
filterList.Add(i);
if filterlist.Count = 0 then begin
for ix := 0 to fRecordList.Count - 1 do
fRefList.Add(ix);
end
else begin
ix := 0;
for rec in fRecordList do begin
accept := True;
for prop in filterlist do begin
accept := accept and rec.Filter(prop, fUserFilters[prop]);
if not accept then
break;
end;
if accept then
fRefList.Add(ix);
Inc(ix);
end;
end;
fGrid.RowCount := 3 + fRefList.Count;
Sort(fSortColumn, fSortedAscending);
UpdateLabel;
finally
filterlist.Free;
end;
finally
Unlock;
end;
end;
procedure TGameScreenFinder.ClearFilters;
var
i: Integer;
begin
for i := 0 to TRecord.property_count - 1 do
fUserFilters[i] := '';
Filter;
end;
procedure TGameScreenFinder.CopyGridToClipBoard;
const
tab: char = Chr(9);
var
list: TStringList;
s: string;
p, i: Integer;
rec: TRecord;
begin
list := TStringList.Create;
s := '';
for p := 0 to TRecord.property_count - 1 do begin
s := s + Headers[p];
if p < TRecord.property_count - 1 then
s := s + tab;
end;
list.Add(s);
for i in fReflist do begin
rec := fRecordList[i];
s := '';
for p := 0 to TRecord.property_count - 1 do begin
s := s + rec.GetText(p);
if p < TRecord.property_count - 1 then
s := s + tab;
end;
list.Add(s);
end;
ClipBoard.AsText := list.Text;
list.Free;
end;
procedure TGameScreenFinder.Grid_DblClick(Sender: TObject);
begin
if (fGrid.Row >= FIRST_DATAROW) then begin
TryCloseAndPlay;
end;
end;
procedure TGameScreenFinder.Grid_DrawCell(Sender: TObject; aCol, aRow: Longint; aRect: TRect; aState: TGridDrawState);
var
item: TRecord;
canv: TCanvas;
txt: string;
rowHighlight: Boolean;
size: TSize;
yDelta: Integer;
begin
if fLockCount <> 0 then
Exit;
txt := '';
canv := fGrid.Canvas;
canv.Font := fGrid.Font;
// prop.value := 0;
// prop.Text := '';
item := GetItem(aRow);
if (gdFixed in aState) then
canv.Brush.Color := RGB(20,20,20)
else
canv.Brush.Color := clBlack;
rowHighlight := (aRow >= FIRST_DATAROW) and (aRow = fGrid.Row) and not (aCol = fGrid.Col);
if rowHighlight then
canv.Brush.Color := RGB(16,20,16);
// if aRow = 0 then
// canv.Brush.Color := clWebIndigo;
// if aRow < FIRST_DATAROW then
// canv.Brush.Color := RGB(40,40,40);
canv.FillRect(aRect);
if aRow = 1 then begin
if aCol = fSortColumn then begin
if fSortedAscending then PaintArrowUp(aRect, clLime) else PaintArrowDown(aRect, clLime)
end
else
PaintArrowUp(aRect, RGB(60,60,60));
Exit;
end;
// row #1 has no text
if aRow <> 1 then begin
if Assigned(item) then
txt := item.GetText(aCol)
else begin
case aRow of
0: txt := fUserFilters[aCol];
2: txt := Headers[aCol];
end;
end;
canv.Font.Color := ColumnColors[aCol];
if Assigned(item) and (aCol = TRecord.prop_stylename) then begin
case item.MyStyle of
sOriginal : canv.Font.Color := TGameScreenOptions.COLOR_DOS;
sCustom : canv.Font.Color := TGameScreenOptions.COLOR_CUSTOM;
sLemmini : canv.Font.Color := TGameScreenOptions.COLOR_LEMMINI;
end;
end
else
if aRow < FIRST_DATAROW then begin
if aRow = 0 then
canv.Font.Color := clYellow // filter
else
canv.Font.Color := clLime; // header
end;
if (aCol in [TRecord.prop_lemmingscount..TRecord.prop_diggercount, TRecord.prop_graphicsetex, TRecord.prop_superlemming, TRecord.prop_duplicates])
and (txt = '0') then begin
txt := '-';
canv.Font.Color := RGB(60,60,60);
end;
if aCol in [TRecord.prop_levelhash, TRecord.prop_levelcode] then
canv.Font.Name := 'Lucida Console';
GetTextExtentPoint(canv.Handle, 'Wq', 2, size);
yDelta := (Scale(DEF_ROWHEIGHT) - size.cy) div 2;
SetBkMode(canv.Handle, TRANSPARENT);
// canv.TextFlags := ETO_CLIPPED;
canv.TextOut(aRect.Left + Scale(3), aRect.Top + yDelta{+ Scale(2)}, txt);
end;
// if rowHighlight then
// DrawTransparentBitmap(fHighlightBitmap, canv, aRect, 20);
// line
canv.Pen.Color := RGB(20,20,20);
if aRow < 3 then
canv.Pen.Color := clSilver;
if aRow <> 1 then begin
canv.MoveTo(aRect.Left, aRect.Bottom - 1);
canv.LineTo(aRect.Right, aRect.Bottom - 1); end;
// selector
if (gdSelected in aState) and (aRow > 2) then begin
canv.Brush.Color := clLime;
canv.FrameRect(aRect);
end;
end;
procedure TGameScreenFinder.Grid_FixedCellClick(Sender: TObject; aCol, aRow: Longint);
begin
if (aRow = 0) then begin
fGrid.Col := aCol;
EditorStart(aCol);
// fUserFilters[TRecord.prop_leveltitle] := 'just a final test';
// Filter;
// fGrid.Row := 0;
// fGrid.EditorMode := True;
end
else if aRow in [1,2] then begin
if aCol = fSortColumn then
Sort(aCol, not fSortedAscending)
else
Sort(aCol, True);
end;
end;
procedure TGameScreenFinder.Grid_KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
if EditorVisible then
Exit;
if Shift = [] then begin
case Key of
VK_ESCAPE: CloseScreen(TGameScreenType.Menu);
VK_F2:
begin
Key := 0;
EditorStart(fGrid.Col);
end;
VK_F3:
begin
Key := 0;
ClearFilters;
end;
end;
end
else if ssCtrl in Shift then begin
case Key of
VK_RETURN:
if ssCtrl in Shift then TryCloseAndPlay;
VK_F2:
begin
Key := 0;
if fUserFilters[fGrid.Col] <> '' then begin
fUserFilters[fGrid.Col] := '';
Filter;
end;
end;
VK_END:
begin
Key := 0;
if fGrid.RowCount > 3 then
fGrid.Row := fGrid.RowCount - 1;
end;
VK_HOME:
begin
Key := 0;
if fGrid.RowCount > 3 then
fGrid.Row := 3;
end;
end;
end;
end;
procedure TGameScreenFinder.Grid_KeyPress(Sender: TObject; var Key: Char);
var
item: TRecord;
col: Integer;
begin
if Key = ^C then begin
item := GetItem(fGrid.Row);
if Assigned(item) then begin
col := fGrid.Col;
//if col <> TRecord.prop_sourcefile then
ClipBoard.AsText := item.GetText(col)
//else
//ClipBoard.AsText := Consts.PathToStyle[item.GetText(TRecord.prop_stylename)] + item.GetText(col);
end;
end
else if Key = ^E then begin
CopyGridToClipBoard;
key := #0;
end;
end;
procedure TGameScreenFinder.Grid_SelectCell(Sender: TObject; aCol, aRow: Longint; var canSelect: Boolean);
begin
EditorEnd(False);
canSelect := aRow >= FIRST_DATAROW;
if fLockCount = 0 then begin
if fGrid.Row >= FIRST_DATAROW then
TDrawGridHack(fGrid).InvalidateRow(fGrid.Row);
TDrawGridHack(fGrid).InvalidateRow(aRow);
end;
end;
function TGameScreenFinder.EditorVisible: Boolean;
begin
Result := fEdit.Visible;
end;
procedure TGameScreenFinder.EditorEnd(accept: Boolean);
begin
if EditorVisible then begin
fEdit.Hide;
if accept and (fEditorCol >= 0) then begin
fUserFilters[fEditorCol] := fEdit.Text;
fEditorCol := -1;
Filter;
end;
if not fGrid.Focused then
fGrid.SetFocus;
end;
end;
procedure TGameScreenFinder.EditorStart(aCol: Integer);
var
r: TRect;
begin
r := fGrid.CellRect(aCol, 0);
r.Inflate(-1, -1);
fEdit.BoundsRect := r;
fEditorCol := aCol;
fEdit.Text := fUserFilters[aCol];
fEdit.SelectAll;
fEdit.Show;
fEdit.SetFocus;
end;
procedure TGameScreenFinder.Editor_KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
case Key of
VK_RETURN: begin Key := 0; EditorEnd(True); end;
VK_ESCAPE: begin Key := 0; EditorEnd(False); end;
end;
end;
procedure TGameScreenFinder.Editor_KeyPress(Sender: TObject; var Key: Char);
// #$#$(% avoid Beep
begin
if (Key = #13) or (Key = Chr(VK_ESCAPE)) then
Key := #0;
end;
end.