-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathFSuperLemmixLevelSelect.pas
1693 lines (1422 loc) · 45.4 KB
/
FSuperLemmixLevelSelect.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
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 FSuperLemmixLevelSelect;
interface
uses
GameControl, GameSound,
LemNeoLevelPack,
LemStrings,
LemTypes,
LemCore,
LemTalisman,
PngInterface,
FLevelInfo, FPlaybackMode,
GR32, GR32_Resamplers, GR32_Layers, GR32_Image,
Generics.Collections,
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Buttons,
Dialogs, ComCtrls, StdCtrls, ExtCtrls, ImgList, StrUtils, UMisc, Math, UITypes,
Types, IOUtils, Vcl.FileCtrl, // For Playback Mode
ActiveX, ShlObj, ComObj, // For the shortcut creation
LemNeoParser, System.ImageList,
SharedGlobals, ShellAPI, Vcl.WinXCtrls;
type
TFLevelSelect = class(TForm)
tvLevelSelect: TTreeView;
btnOK: TButton;
lblName: TLabel;
pnLevelInfo: TPanel;
lblPosition: TLabel;
lblAuthor: TLabel;
ilStatuses: TImageList;
lblCompletion: TLabel;
btnMakeShortcut: TButton;
lblRecordsOptions: TLabel;
btnSaveImage: TButton;
btnReplayManager: TButton;
btnCleanseLevels: TButton;
btnCleanseOne: TButton;
btnClearRecords: TButton;
btnResetTalismans: TBitBtn;
btnPlaybackMode: TButton;
lblAdvancedOptions: TLabel;
lblReplayOptions: TLabel;
btnShowHideOptions: TButton;
sbSearchLevels: TSearchBox;
lblSearchLevels: TLabel;
pbSearchProgress: TProgressBar;
lbSearchResults: TListBox;
btnCloseSearch: TButton;
lblEditingOptions: TLabel;
btnEditLevel: TButton;
btnClose: TButton;
procedure FormCreate(Sender: TObject);
procedure btnOKClick(Sender: TObject);
procedure LoadCurrentLevelToPlayer;
procedure FormShow(Sender: TObject);
procedure btnMakeShortcutClick(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure btnSaveImageClick(Sender: TObject);
procedure btnReplayManagerClick(Sender: TObject);
procedure btnPlaybackModeClick(Sender:TObject);
procedure btnCleanseLevelsClick(Sender: TObject);
procedure btnCleanseOneClick(Sender: TObject);
procedure btnClearRecordsClick(Sender: TObject);
procedure tvLevelSelectChange(Sender: TObject; Node: TTreeNode);
procedure tvLevelSelectKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure btnResetTalismansClick(Sender: TObject);
procedure tvLevelSelectExpanded(Sender: TObject; Node: TTreeNode);
procedure btnShowHideOptionsClick(Sender: TObject);
procedure SetOptionButtons;
procedure ShowOptionButtons;
procedure HideOptionButtons;
procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure SearchLevels;
procedure CloseSearchResultsPanel;
procedure sbSearchLevelsKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure sbSearchLevelsInvokeSearch(Sender: TObject);
procedure lbSearchResultsClick(Sender: TObject);
procedure btnCloseSearchClick(Sender: TObject);
procedure btnEditLevelClick(Sender: TObject);
procedure btnCloseClick(Sender: TObject);
private
fLastLevelPath: String;
fLastGroup: TNeoLevelGroup;
fLoadAsPack: Boolean;
fInfoForm: TLevelInfoPanel;
fIconBMP: TBitmap32;
fPackTalBox: TScrollBox;
fTalismanButtons: TObjectList<TSpeedButton>;
fDisplayRecords: TRecordDisplay;
fSearchingLevels: Boolean;
fCurrentLevelVersion: Int64; // Used to check if we need to re-load the current level info
fIsHandlingActivation: Boolean;
procedure InitializeTreeview;
procedure SetInfo;
procedure LoadNodeLabels;
procedure WriteToParams;
function GetCompletedLevelString(G: TNeoLevelGroup): String;
function GetPackResultsString(G: TNeoLevelGroup): String;
procedure DisplayLevelInfo(RefreshLevel: Boolean = False);
procedure SetTalismanInfo;
procedure DrawTalismanButtons;
procedure ClearTalismanButtons;
procedure TalButtonClick(Sender: TObject);
procedure PackListTalButtonClick(Sender: TObject);
procedure DisplayPackTalismanInfo(Group: TNeoLevelGroup);
procedure DrawSpeedButton(aButton: TSpeedButton; aIconIndex: Integer; aOverlayIndex: Integer = -1);
procedure DrawIcon(aIconIndex: Integer; aDst: TBitmap32; aEraseColor: TColor);
procedure OverlayIcon(aIconIndex: Integer; aDst: TBitmap32);
procedure SetAdvancedOptionsGroup(G: TNeoLevelGroup);
procedure SetAdvancedOptionsLevel(L: TNeoLevelEntry);
procedure WMActivate(var Msg: TWMActivate); message WM_ACTIVATE;
procedure MaybeReloadLevelInfo;
property SearchingLevels: Boolean read fSearchingLevels write fSearchingLevels;
public
property LoadAsPack: Boolean read fLoadAsPack;
procedure LoadIcons;
function GetCurrentlySelectedPack: String;
end;
const // Icon indexes
ICON_BLANK = -1;
ICON_NORMAL_LEMMING = 0;
ICON_RIVAL_LEMMING = 1;
ICON_ZOMBIE_LEMMING = 2;
ICON_NEUTRAL_LEMMING = 3;
// Empty slot = 4;
// Empty slot = 5;
ICON_RELEASE_RATE = 6;
ICON_RELEASE_RATE_LOCKED = 7;
ICON_SAVE_REQUIREMENT = 8;
ICON_TIME_LIMIT = 9;
ICON_TIMER = 10;
// Empty slot = 11;
ICON_RECORDS = 12;
ICON_BRONZE_TALISMAN = 13;
ICON_SILVER_TALISMAN = 14;
ICON_GOLD_TALISMAN = 15;
ICON_COLLECTIBLE = 16;
// Empty slot = 17;
ICON_WORLD_RECORDS = 18;
ICON_TALISMAN: array[tcBronze..tcGold] of Integer =
( ICON_BRONZE_TALISMAN, ICON_SILVER_TALISMAN, ICON_GOLD_TALISMAN );
ICON_TALISMAN_UNOBTAINED_OFFSET = 6;
ICON_COLLECTIBLE_UNOBTAINED = 22;
// Empty slot = 23;
ICON_SELECTED_TALISMAN = 24;
ICON_MAX_SKILLS = 25;
ICON_MAX_SKILL_TYPES = 26;
ICON_CLASSIC_MODE = 27;
ICON_NO_PAUSE = 28;
ICON_KILL_ZOMBIES = 29;
ICON_SKILLS: array[Low(TSkillPanelButton)..LAST_SKILL_BUTTON] of Integer = (
30, // 0 Walker
31, // 1 Jumper
32, // 2 Shimmier
33, // 3 Ballooner
34, // 4 Slider
35, // 5 Climber
36, // 6 Swimmer
37, // 7 Floater
38, // 8 Glider
39, // 9 Disarmer
40, // 10 Timebomber
41, // 11 Bomber
42, // 12 Freezer
43, // 13 Blocker
44, // 14 Ladderer
45, // 15 Platformer
46, // 16 Builder
47, // 17 Stacker
48, // 18 Spearer
49, // 19 Grenader
50, // 20 Laserer
51, // 21 Basher
52, // 22 Fencer
53, // 23 Miner
54, // 24 Digger
// 55, Empty slot
// 56, Empty slot
// 57, Empty slot
// 58, Empty slot
59 // 25 Cloner
//?, // // Batter
//?, // // Propeller
);
implementation
uses
FReplayManager,
LemLevel;
const
SPEEDBUTTON_PADDING_SIZE = 3;
{$R *.dfm}
procedure TFLevelSelect.InitializeTreeview;
procedure AddLevel(aLevel: TNeoLevelEntry; ParentNode: TTreeNode);
var
N: TTreeNode;
begin
N := tvLevelSelect.Items.AddChildObject(ParentNode, '', aLevel);
case aLevel.Status of
lst_None: N.ImageIndex := 0;
lst_Attempted: N.ImageIndex := 1;
lst_Completed_Outdated: N.ImageIndex := 2;
lst_Completed: N.ImageIndex := 3;
end;
N.SelectedIndex := N.ImageIndex;
if GameParams.CurrentLevel = aLevel then
tvLevelSelect.Selected := N;
end;
procedure AddGroup(aGroup: TNeoLevelGroup; ParentNode: TTreeNode);
var
GroupNode: TTreeNode;
i: Integer;
begin
if aGroup = GameParams.BaseLevelPack then
GroupNode := nil
else
GroupNode := tvLevelSelect.Items.AddChildObject(ParentNode, aGroup.Name, aGroup);
for i := 0 to aGroup.Children.Count-1 do
AddGroup(aGroup.Children[i], GroupNode);
for i := 0 to aGroup.Levels.Count-1 do
AddLevel(aGroup.Levels[i], GroupNode);
if GroupNode <> nil then
begin
case aGroup.Status of
lst_None: GroupNode.ImageIndex := 0;
lst_Attempted: GroupNode.ImageIndex := 1;
lst_Completed_Outdated: GroupNode.ImageIndex := 2;
lst_Completed: GroupNode.ImageIndex := 3;
end;
GroupNode.SelectedIndex := GroupNode.ImageIndex;
end;
end;
procedure MakeImages;
var
BMP32, TempBMP: TBitmap32;
ImgBMP, MaskBMP: TBitmap;
procedure Load(aName: String; aName2: String = '');
begin
TPngInterface.LoadPngFile(AppPath + SFGraphicsMenu + aName, BMP32);
if aName2 <> '' then
begin
TPngInterface.LoadPngFile(AppPath + SFGraphicsMenu + aName2, TempBMP);
TempBMP.DrawMode := dmBlend;
TempBMP.CombineMode := cmMerge;
TempBMP.DrawTo(BMP32);
end;
TPngInterface.SplitBmp32(BMP32, ImgBMP, MaskBMP);
tvLevelSelect.Images.Add(ImgBMP, MaskBMP);
end;
begin
BMP32 := TBitmap32.Create;
TempBMP := TBitmap32.Create;
ImgBMP := TBitmap.Create;
MaskBMP := TBitmap.Create;
try
Load('level_not_attempted.png');
Load('level_attempted.png');
Load('level_completed_outdated.png');
Load('level_completed.png');
Load('level_talisman.png', 'level_not_attempted.png');
Load('level_talisman.png', 'level_attempted.png',);
Load('level_talisman.png', 'level_completed_outdated.png');
Load('level_talisman.png', 'level_completed.png');
finally
TempBMP.Free;
BMP32.Free;
ImgBMP.Free;
MaskBMP.Free;
end;
end;
begin
MakeImages;
tvLevelSelect.Items.BeginUpdate;
try
tvLevelSelect.Items.Clear;
AddGroup(GameParams.BaseLevelPack, nil);
finally
tvLevelSelect.Items.EndUpdate;
tvLevelSelect.Update;
end;
end;
procedure TFLevelSelect.LoadCurrentLevelToPlayer;
begin
WriteToParams;
if GameParams.MenuSounds then
SoundManager.PlaySound(SFX_OK);
ModalResult := mrOk;
end;
procedure TFLevelSelect.LoadIcons;
var
IconsImg, aStyle, aStylePath, aPath: String;
begin
IconsImg := 'levelinfo_icons.png';
aStyle := GameParams.Level.Info.GraphicSetName;
aStylePath := AppPath + SFStyles + aStyle + SFIcons;
aPath := GameParams.CurrentLevel.Group.ParentBasePack.Path;
if FileExists(aStylePath + IconsImg) then // Check styles folder first
TPNGInterface.LoadPngFile(aStylePath + IconsImg, fIconBMP)
else if FileExists(GameParams.CurrentLevel.Group.FindFile(IconsImg)) then // Then levelpack folder
TPNGInterface.LoadPngFile(aPath + IconsImg, fIconBMP)
else
TPNGInterface.LoadPngFile(AppPath + SFGraphicsMenu + IconsImg, fIconBMP); // Then default
end;
procedure TFLevelSelect.MaybeReloadLevelInfo;
var
NewVersion: Int64;
begin
GameParams.LoadCurrentLevel;
NewVersion := GameParams.Level.Info.LevelVersion;
if (NewVersion <> fCurrentLevelVersion) then
begin
DisplayLevelInfo(True);
fCurrentLevelVersion := NewVersion;
end;
end;
procedure TFLevelSelect.WMActivate(var Msg: TWMActivate);
begin
inherited;
if fIsHandlingActivation then Exit; // Prevent overload
fIsHandlingActivation := True;
try
if Msg.Active = WA_ACTIVE then
MaybeReloadLevelInfo;
finally
fIsHandlingActivation := False;
end;
end;
procedure TFLevelSelect.FormCreate(Sender: TObject);
begin
fTalismanButtons := TObjectList<TSpeedButton>.Create;
fIconBMP := TBitmap32.Create;
LoadIcons;
fIconBMP.DrawMode := dmBlend;
fIconBMP.CombineMode := cmMerge;
fInfoForm := TLevelInfoPanel.Create(Self, fIconBMP);
fInfoForm.Parent := Self;
fInfoForm.BoundsRect := pnLevelInfo.BoundsRect;
fInfoForm.Visible := False;
fPackTalBox := TScrollBox.Create(Self);
fPackTalBox.Parent := Self;
fPackTalBox.BoundsRect := pnLevelInfo.BoundsRect;
fPackTalBox.VertScrollBar.Tracking := True;
fPackTalBox.Visible := False;
pnLevelInfo.Visible := False;
btnResetTalismans.Enabled := False;
btnOK.Enabled := False;
SearchingLevels := False;
InitializeTreeview;
SetOptionButtons;
end;
procedure TFLevelSelect.FormShow(Sender: TObject);
begin
SetInfo;
end;
function TFLevelSelect.GetCurrentlySelectedPack: String;
var
G: TNeoLevelGroup;
N: TTreeNode;
Obj: TObject;
begin
Result := '';
N := tvLevelSelect.Selected;
if N = nil then Exit;
Obj := TObject(N.Data);
if Obj is TNeoLevelGroup then
G := TNeoLevelGroup(Obj).ParentBasePack
else if Obj is TNeoLevelEntry then
G := TNeoLevelEntry(Obj).Group.ParentBasePack
else
Exit;
Result := G.PackTitle;
if Result = '' then
Result := StringReplace(G.Name, '_', ' ', [rfReplaceAll]);
end;
procedure TFLevelSelect.FormDestroy(Sender: TObject);
begin
fIconBMP.Free;
fTalismanButtons.OwnsObjects := False; // Because TFLevelSelect itself will take care of any that remain
fTalismanButtons.Free;
GameParams.Save(scImportant);
end;
procedure TFLevelSelect.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if Key = VK_ESCAPE then
begin
Close;
end;
end;
procedure TFLevelSelect.btnCleanseOneClick(Sender: TObject);
var
SaveDlg: TSaveDialog;
begin
SaveDlg := TSaveDialog.Create(Self);
try
SaveDlg.Title := 'Select file to save to';
SaveDlg.Filter := 'NXLV Level Files|*.nxlv';
SaveDlg.InitialDir := AppPath + SFLevels;
SaveDlg.FileName := MakeSafeForFilename(GameParams.Level.Info.Title) + '.nxlv';
SaveDlg.Options := [ofOverwritePrompt];
if SaveDlg.Execute then
begin
GameParams.Level.Info.LevelVersion := GameParams.Level.Info.LevelVersion + 1;
GameParams.Level.SaveToFile(SaveDlg.FileName);
GameParams.Level.Info.LevelVersion := GameParams.Level.Info.LevelVersion - 1;
end;
finally
SaveDlg.Free;
end;
end;
procedure TFLevelSelect.btnMakeShortcutClick(Sender: TObject);
var
N: TTreeNode;
Obj: TObject;
G: TNeoLevelGroup absolute Obj;
L: TNeoLevelEntry absolute Obj;
TargetPath: String;
Description: String;
Dlg: TSaveDialog;
// Source: delphiexamples.com/others/createlnk.html
procedure CreateLink(const PathObj, PathLink, Desc, Param: string);
var
IObject: IUnknown;
SLink: IShellLink;
PFile: IPersistFile;
begin
IObject:=CreateComObject(CLSID_ShellLink);
SLink:=IObject as IShellLink;
PFile:=IObject as IPersistFile;
with SLink do
begin
SetArguments(PChar(Param));
SetDescription(PChar(Desc));
SetPath(PChar(PathObj));
end;
PFile.Save(PWChar(WideString(PathLink)), FALSE);
end;
function MakeNameRecursive(aGroup: TNeoLevelGroup): String;
begin
if aGroup.Parent = nil then
Result := ''
else if aGroup.IsBasePack then
Result := aGroup.Name
else begin
Result := MakeNameRecursive(aGroup.Parent);
if (Result <> '') then Result := Result + ' :: ';
Result := Result + aGroup.Name;
end;
end;
begin
N := tvLevelSelect.Selected;
if N = nil then Exit;
Obj := TObject(N.Data);
if Obj is TNeoLevelGroup then
begin
TargetPath := G.Path;
Description := 'SuperLemmix - ' + MakeNameRecursive(G);
end else if Obj is TNeoLevelEntry then
begin
TargetPath := L.Path;
Description := 'SuperLemmix - ' + MakeNameRecursive(L.Group) + ' :: ' + L.Title;
end else
Exit;
if Pos(AppPath + SFLevels, TargetPath) = 1 then
TargetPath := RightStr(TargetPath, Length(TargetPath) - Length(AppPath + SFLevels));
Dlg := TSaveDialog.Create(Self);
try
Dlg.Title := 'Select location for shortcut';
Dlg.Filter := 'Windows Shortcut (*.lnk)|*.lnk';
Dlg.FilterIndex := 1;
Dlg.DefaultExt := '.lnk';
Dlg.Options := [ofOverwritePrompt, ofEnableSizing];
if not Dlg.Execute then Exit;
CreateLink(ParamStr(0), Dlg.FileName, Description, 'shortcut "' + TargetPath + '"');
finally
Dlg.Free;
end;
end;
procedure TFLevelSelect.btnOKClick(Sender: TObject);
begin
LoadCurrentLevelToPlayer;
end;
procedure TFLevelSelect.btnPlaybackModeClick(Sender: TObject);
var
PlaybackModeForm: TFPlaybackMode;
ReplayFiles: TStringDynArray;
ReplayFile: string;
begin
PlaybackModeForm := TFPlaybackMode.Create(nil);
try
// Populate the form with the currently selected pack
PlaybackModeForm.CurrentlySelectedPack := GetCurrentlySelectedPack;
PlaybackModeForm.UpdatePackNameText;
if PlaybackModeForm.ShowModal = mrOk then
begin
if PlaybackModeForm.SelectedFolder = '' then
Exit;
// Get list of replay files
ReplayFiles := TDirectory.GetFiles(PlaybackModeForm.SelectedFolder, '*.nxrp');
// Add replay file names to ReplayVerifyList
for ReplayFile in ReplayFiles do
GameParams.ReplayVerifyList.Add(ReplayFile); // Storing full path for easier access later
GameParams.PlaybackModeActive := True;
GameParams.Save(scImportant);
WriteToParams;
ModalResult := mrRetry;
end;
finally
PlaybackModeForm.Free;
end;
end;
procedure TFLevelSelect.btnResetTalismansClick(Sender: TObject);
var
Obj: TObject;
L: TNeoLevelEntry absolute Obj;
N: TTreeNode;
begin
N := tvLevelSelect.Selected;
if N = nil then Exit; // Safeguard
Obj := TObject(N.Data);
if Obj is TNeoLevelGroup then Exit;
if MessageDlg('Are you sure you want to reset talismans for the level "' + L.Title + '"?',
mtCustom, [mbYes, mbNo], 0, mbNo) = mrYes then
begin
L.ResetTalismans;
SetTalismanInfo;
end;
end;
procedure TFLevelSelect.WriteToParams;
var
Obj: TObject;
G: TNeoLevelGroup absolute Obj;
L: TNeoLevelEntry absolute Obj;
N: TTreeNode;
begin
N := tvLevelSelect.Selected;
if N = nil then Exit; // Safeguard
Obj := TObject(N.Data);
fLoadAsPack := False;
if Obj is TNeoLevelGroup then
begin
if G.Levels.Count = 0 then
begin
if G.LevelCount > 0 then
fLoadAsPack := True
else
Exit;
end;
GameParams.SetGroup(G);
end
else if Obj is TNeoLevelEntry then
GameParams.SetLevel(L);
end;
procedure TFLevelSelect.btnClearRecordsClick(Sender: TObject);
var
Obj: TObject;
G: TNeoLevelGroup absolute Obj;
L: TNeoLevelEntry absolute Obj;
N: TTreeNode;
GroupWord: String;
begin
N := tvLevelSelect.Selected;
if N = nil then Exit; // Safeguard
Obj := TObject(N.Data);
if Obj is TNeoLevelGroup then
begin
if G.IsBasePack then
GroupWord := 'pack'
else
GroupWord := 'group';
if MessageDlg('Are you sure you want to clear records for all levels in the ' + GroupWord + ' "' + G.Name + '"?',
mtCustom, [mbYes, mbNo], 0, mbNo) = mrYes then
G.WipeAllRecords;
end else begin
if MessageDlg('Are you sure you want to clear records for the level "' + L.Title + '"?',
mtCustom, [mbYes, mbNo], 0, mbNo) = mrYes then
L.WipeRecords;
if fDisplayRecords <> rdNone then
fInfoForm.PrepareEmbedRecords(fDisplayRecords);
SetTalismanInfo;
end;
end;
procedure TFLevelSelect.tvLevelSelectChange(Sender: TObject; Node: TTreeNode);
begin
SetInfo;
end;
procedure TFLevelSelect.tvLevelSelectExpanded(Sender: TObject; Node: TTreeNode);
begin
SetInfo;
end;
// When treeview is active, pressing return loads the currently selected level
procedure TFLevelSelect.tvLevelSelectKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if Key = VK_RETURN then
LoadCurrentLevelToPlayer;
end;
function TFLevelSelect.GetCompletedLevelString(G: TNeoLevelGroup): String;
var
i, j, CompletedCount: Integer;
SubGroup: TNeoLevelGroup;
// ProgressDialog: TForm;
// ProgressBar: TProgressBar;
begin
Result := '';
CompletedCount := 0;
// // Create the progress dialog
// ProgressDialog := TForm.Create(nil);
// try
// ProgressDialog.Caption := 'Processing Completion Data...';
// ProgressDialog.Position := poScreenCenter;
// ProgressDialog.BorderStyle := bsDialog;
// ProgressDialog.Width := 300;
// ProgressDialog.Height := 100;
//
// // Create a progress bar
// ProgressBar := TProgressBar.Create(ProgressDialog);
// ProgressBar.Parent := ProgressDialog;
// ProgressBar.Left := 10;
// ProgressBar.Top := 10;
// ProgressBar.Width := ProgressDialog.Width - 20;
// ProgressBar.Max := G.LevelCount;
// ProgressBar.Position := 0;
// // Show the progress dialog
// ProgressDialog.Show;
for i := 0 to G.Children.Count -1 do
begin
SubGroup := G.Children[i];
for j := 0 to SubGroup.Levels.Count -1 do
if SubGroup.Levels[j].Status = lst_Completed then
begin
// Update progress
Inc(CompletedCount);
// ProgressBar.Position := CompletedCount;
// Application.ProcessMessages; // Ensure UI updates are processed
end;
end;
Result := IntToStr(CompletedCount) + ' of ' + IntToStr(G.LevelCount) + ' levels ';
// // Close the progress dialog when finished
// ProgressDialog.Close;
// finally
// ProgressDialog.Free;
// end;
end;
function TFLevelSelect.GetPackResultsString(G: TNeoLevelGroup): String;
begin
Result := '';
if G.LevelCount > 0 then
Result := GetCompletedLevelString(G);
if Result <> '' then
Result := Result + 'completed';
if G.Talismans.Count > 0 then
begin
if Result <> '' then
Result := Result + '; ';
Result := Result + IntToStr(G.TalismansUnlocked) + ' of ' + IntToStr(G.Talismans.Count) + ' talismans unlocked';
end;
end;
procedure TFLevelSelect.LoadNodeLabels;
var
i: Integer;
L: TNeoLevelEntry;
S: String;
// ProgressDialog: TForm;
// ProgressBar: TProgressBar;
// CurrentNode: Integer;
begin
tvLevelSelect.Items.BeginUpdate;
// CurrentNode := 0;
// // Create the progress dialog
// ProgressDialog := TForm.Create(nil);
try
// ProgressDialog.Caption := 'Processing Level Data...';
// ProgressDialog.Position := poScreenCenter;
// ProgressDialog.BorderStyle := bsDialog;
// ProgressDialog.Width := 300;
// ProgressDialog.Height := 100;
//
// // Create a progress bar
// ProgressBar := TProgressBar.Create(ProgressDialog);
// ProgressBar.Parent := ProgressDialog;
// ProgressBar.Left := 10;
// ProgressBar.Top := 10;
// ProgressBar.Width := ProgressDialog.Width - 20;
// ProgressBar.Max := 100; // This will need to be the number of visible Nodes
// ProgressBar.Position := 0;
// // Show the progress dialog
// ProgressDialog.Show;
for i := 0 to tvLevelSelect.Items.Count-1 do
begin
if not tvLevelSelect.Items[i].IsVisible then Continue;
if tvLevelSelect.Items[i].Text <> '' then Continue;
if TObject(tvLevelSelect.Items[i].Data) is TNeoLevelEntry then
begin
L := TNeoLevelEntry(tvLevelSelect.Items[i].Data);
S := '';
if L.Group.IsOrdered then
S := '(' + IntToStr(L.GroupIndex + 1) + ') ';
S := S + L.Title;
tvLevelSelect.Items[i].Text := S;
if (L.UnlockedTalismanList.Count < L.Talismans.Count)
and (tvLevelSelect.Items[i].ImageIndex < 4) {just in case}
and not SearchingLevels then
with tvLevelSelect.Items[i] do
begin
ImageIndex := ImageIndex + 4;
SelectedIndex := ImageIndex;
end;
end;
// // Update progress
// Inc(CurrentNode);
// ProgressBar.Position := CurrentNode;
// Application.ProcessMessages; // Ensure UI updates are processed
end;
// // Close the progress dialog when finished
// ProgressDialog.Close;
finally
// ProgressDialog.Free;
tvLevelSelect.Items.EndUpdate;
end;
end;
procedure TFLevelSelect.SetInfo;
var
Obj: TObject;
G: TNeoLevelGroup;
L: TNeoLevelEntry;
N: TTreeNode;
function GetGroupPositionText: String;
begin
if (G = GameParams.BaseLevelPack) or (G.IsBasePack) or not (G.Parent.IsOrdered) then
Result := ''
else
Result := 'Group ' + IntToStr(G.ParentGroupIndex + 1) + ' in ' + G.Parent.Name;
end;
function GetLevelPositionText: String;
begin
if not L.Group.IsOrdered then
Result := ''
else
Result := 'Level ' + IntToStr(L.GroupIndex + 1) + ' of ' + L.Group.Name;
end;
begin
LoadNodeLabels;
if SearchingLevels then Exit;
N := tvLevelSelect.Selected;
if N = nil then Exit;
Obj := TObject(N.Data);
if Obj is TNeoLevelGroup then
begin
G := TNeoLevelGroup(Obj);
lblName.Caption := G.Name;
lblPosition.Caption := GetGroupPositionText;
lblAuthor.Caption := G.Author;
if G.PackVersion <> '' then
lblAuthor.Caption := lblAuthor.Caption + ' | Version: ' + G.PackVersion;
lblCompletion.Caption := GetPackResultsString(G);
lblCompletion.Visible := True;
// Set the first unsolved level in the pack as the current level (or first level if pack is completed)
WriteToParams;
GameParams.LoadCurrentLevel(False);
ClearTalismanButtons;
DisplayPackTalismanInfo(G);
fInfoForm.Visible := False;
SetAdvancedOptionsGroup(G);
end else if Obj is TNeoLevelEntry then
begin
L := TNeoLevelEntry(Obj);
lblName.Caption := L.Title;
lblPosition.Caption := GetLevelPositionText;
if L.Author <> '' then
lblAuthor.Caption := 'Author: ' + L.Author
else
lblAuthor.Caption := '';
lblCompletion.Caption := '';
lblCompletion.Visible := False;
DisplayLevelInfo;
fPackTalBox.Visible := False;
SetAdvancedOptionsLevel(L);
fCurrentLevelVersion := GameParams.Level.Info.LevelVersion;
end;
end;
procedure TFLevelSelect.ShowOptionButtons;
begin
{ Resizes and recenters the main form to show the option buttons }
Self.Width := btnClearRecords.Left + btnClearRecords.Width + 20;
btnOK.Width := pnLevelInfo.Width - btnClose.Width;
btnClose.Left := btnClearRecords.Left;
btnShowHideOptions.Caption := '< Hide Options';
Self.Left := (Application.MainForm.Left + (Application.MainForm.Width div 2)) - (Self.Width div 2);
Self.Top := (Application.MainForm.Top + (Application.MainForm.Height div 2)) - (Self.Height div 2);
end;
procedure TFLevelSelect.HideOptionButtons;
begin
{ Resizes and recenters the main form to hide the option buttons }
Self.Width := btnClearRecords.Left - 5;
btnShowHideOptions.Caption := 'Show Options >';
btnOK.Width := pnLevelInfo.Width - (btnClose.Width * 2) - 20;
btnClose.Left := btnOK.Left + btnOK.Width + 10;
Self.Left := (Application.MainForm.Left + (Application.MainForm.Width div 2)) - (Self.Width div 2);
Self.Top := (Application.MainForm.Top + (Application.MainForm.Height div 2)) - (Self.Height div 2);
end;
procedure TFLevelSelect.SetOptionButtons;
begin
if GameParams.ShowLevelSelectOptions then
begin
ShowOptionButtons;
end else begin
HideOptionButtons;
end;
end;
procedure TFLevelSelect.DisplayLevelInfo(RefreshLevel: Boolean = False);
var
LevelChanged: Boolean;
begin
WriteToParams;
GameParams.LoadCurrentLevel(False);
LevelChanged := (GameParams.CurrentLevel.Path <> fLastLevelPath);
fLastLevelPath := GameParams.CurrentLevel.Path;
fInfoForm.Visible := True;
fInfoForm.BoundsRect := pnLevelInfo.BoundsRect;
fInfoForm.Level := GameParams.Level;
fInfoForm.Talisman := nil;
fDisplayRecords := rdNone;
LoadIcons;
fInfoForm.PrepareEmbed(LevelChanged or RefreshLevel);
SetTalismanInfo;
end;
procedure TFLevelSelect.DisplayPackTalismanInfo(Group: TNeoLevelGroup);
var
// ProgressDialog: TForm;
// ProgressBar: TProgressBar;
// TotalTalismans, CurrentTalisman: Integer;
// Group: TNeoLevelGroup;
Level: TNeoLevelEntry;
Talismans: TObjectList<TTalisman>;
Tal: TTalisman;
i, TotalHeight: Integer;
procedure CreateUIElements;
var
TitleLabel, LevLabel, ReqLabel: TLabel;
NewButton: TSpeedButton;
LabelStartY, LabelTotalHeight: Integer;
begin
if Trim(Tal.Title) <> '' then
begin