DEADSOFTWARE

fixed wadeditor; added nosound mode; fixed codepage problems; fixed pointers; cleanup
[d2df-editor.git] / src / editor / f_savemap.pas
1 unit f_savemap;
3 {$INCLUDE ../shared/a_modes.inc}
5 interface
7 uses
8 LCLIntf, LCLType, LMessages, SysUtils, Variants, Classes,
9 Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls;
11 type
12 TSaveMapForm = class (TForm)
13 lbMapList: TListBox;
14 Panel1: TPanel;
15 bOK: TButton;
16 bCancel: TButton;
17 Panel2: TPanel;
18 eMapName: TEdit;
20 procedure GetMaps(FileName: String; placeName: Boolean);
21 procedure FormActivate(Sender: TObject);
22 procedure eMapNameChange(Sender: TObject);
23 procedure lbMapListClick(Sender: TObject);
24 procedure bOKClick(Sender: TObject);
26 private
27 { Private declarations }
28 public
29 { Public declarations }
30 end;
32 var
33 SaveMapForm: TSaveMapForm;
35 implementation
37 uses
38 BinEditor, MAPREADER, WADEDITOR, WADSTRUCT, MAPSTRUCT, g_language;
40 {$R *.lfm}
42 procedure TSaveMapForm.FormActivate(Sender: TObject);
43 begin
44 bOK.Enabled := (eMapName.Text <> '');
45 eMapName.SetFocus();
46 end;
48 procedure TSaveMapForm.eMapNameChange(Sender: TObject);
49 begin
50 if eMapName.Text <> '' then
51 bOK.Enabled := True
52 else
53 bOK.Enabled := False;
54 end;
56 procedure TSaveMapForm.lbMapListClick(Sender: TObject);
57 begin
58 if lbMapList.ItemIndex > -1 then
59 eMapName.Text := lbMapList.Items[lbMapList.ItemIndex];
60 end;
62 procedure TSaveMapForm.bOKClick(Sender: TObject);
63 var
64 a: Integer;
65 ok: Boolean;
67 begin
68 ok := True;
69 for a := 0 to lbMapList.Count-1 do
70 if eMapName.Text = lbMapList.Items[a] then
71 begin
72 ok := MessageBox(0, PChar(Format(_lc[I_MSG_MAP_EXISTS],
73 [eMapName.Text])),
74 PChar(_lc[I_MSG_SAVE_MAP]),
75 MB_ICONQUESTION or MB_YESNO or MB_DEFBUTTON1) = mrYes;
76 if not ok then
77 Exit;
78 Break;
79 end;
81 if ok then
82 SaveMapForm.ModalResult := mrOk
83 else
84 SaveMapForm.ModalResult := mrCancel;
85 end;
87 procedure TSaveMapForm.GetMaps(FileName: String; placeName: Boolean);
88 var
89 WAD: TWADEditor_1;
90 a, max_num, j: Integer;
91 ResList: SArray;
92 Data: Pointer;
93 Len: Integer;
94 Sign: Array [0..2] of Char;
95 nm: String;
97 begin
98 lbMapList.Items.Clear();
99 max_num := 1;
101 WAD := TWADEditor_1.Create();
102 WAD.ReadFile(FileName);
103 ResList := WAD.GetResourcesList('');
105 if ResList <> nil then
106 for a := 0 to High(ResList) do
107 begin
108 if not WAD.GetResource('', ResList[a], Data, Len) then
109 Continue;
111 CopyMemory(@Sign[0], Data, 3);
112 FreeMem(Data);
114 if Sign = MAP_SIGNATURE then
115 begin
116 nm := ResList[a];
117 lbMapList.Items.Add(nm);
119 if placeName then
120 begin
121 nm := UpperCase(nm);
122 if (nm[1] = 'M') and
123 (nm[2] = 'A') and
124 (nm[3] = 'P') then
125 begin
126 nm := Trim(Copy(nm, 4, Length(nm)-3));
127 j := StrToIntDef(nm, 0);
128 if j >= max_num then
129 max_num := j + 1;
130 end;
131 end;
132 end;
134 Sign := '';
135 end;
137 WAD.Free();
139 if placeName then
140 begin
141 nm := IntToStr(max_num);
142 if Length(nm) < 2 then
143 nm := '0' + nm;
144 nm := 'MAP' + nm;
145 eMapName.Text := nm;
146 end
147 else
148 eMapName.Text := '';
149 end;
151 end.