DEADSOFTWARE

Two small additional fixes for Lazarus
[d2df-editor.git] / src / editor / f_selectmap.pas
1 unit f_selectmap;
3 {$INCLUDE ../shared/a_modes.inc}
5 interface
7 uses
8 LCLIntf, LCLType, LMessages, SysUtils, Variants, Classes, Graphics,
9 Controls, Forms, Dialogs, StdCtrls, ExtCtrls, utils;
11 type
12 TSelectMapForm = class (TForm)
13 lbMapList: TListBox;
14 Panel1: TPanel;
15 bOK: TButton;
16 bCancel: TButton;
18 procedure GetMaps(FileName: String);
19 procedure FormActivate(Sender: TObject);
20 procedure lbMapListClick(Sender: TObject);
21 procedure bCancelClick(Sender: TObject);
23 private
24 { Private declarations }
25 public
26 { Public declarations }
27 end;
29 var
30 SelectMapForm: TSelectMapForm;
32 implementation
34 uses
35 BinEditor, MAPREADER, WADEDITOR, WADSTRUCT, MAPSTRUCT;
37 {$R *.lfm}
39 procedure TSelectMapForm.FormActivate(Sender: TObject);
40 begin
41 bOK.Enabled := (lbMapList.ItemIndex <> -1);
42 lbMapList.SetFocus();
43 end;
45 procedure TSelectMapForm.lbMapListClick(Sender: TObject);
46 begin
47 if lbMapList.ItemIndex <> -1 then
48 bOK.Enabled := True;
49 end;
51 procedure TSelectMapForm.bCancelClick(Sender: TObject);
52 begin
53 Close();
54 end;
56 procedure TSelectMapForm.GetMaps(FileName: String);
57 var
58 WAD: TWADEditor_1;
59 a: Integer;
60 ResList: SArray;
61 Data: Pointer;
62 Len: Integer;
63 Sign: Array [0..2] of Char;
65 begin
66 lbMapList.Items.Clear();
68 WAD := TWADEditor_1.Create();
69 if not WAD.ReadFile(FileName) then
70 begin
71 WAD.Free();
72 Exit;
73 end;
75 ResList := WAD.GetResourcesList('');
77 if ResList <> nil then
78 for a := 0 to High(ResList) do
79 begin
80 if not WAD.GetResource('', ResList[a], Data, Len) then
81 Continue;
83 CopyMemory(@Sign[0], Data, 3);
84 FreeMem(Data);
86 if Sign = MAP_SIGNATURE then
87 lbMapList.Items.Add(win2utf(ResList[a]));
88 Sign := '';
89 end;
91 WAD.Free();
92 end;
94 end.