DEADSOFTWARE

fixed sky changing
[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, utils;
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 MAPREADER, MAPSTRUCT, g_language, g_resources, sfs;
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 nm: String;
90 data: Pbyte;
91 list: TSFSFileList;
92 i, j, len, max_num: Integer;
93 sign: Array [0..2] of Char;
94 begin
95 lbMapList.Items.Clear();
96 max_num := 1;
98 list := SFSFileList(FileName);
99 if list <> nil then
100 begin
101 for i := 0 to list.Count - 1 do
102 begin
103 g_ReadResource(FileName, win2utf(list.Files[i].path), win2utf(list.Files[i].name), data, len);
105 if len >= 3 then
106 begin
107 sign[0] := chr(data[0]);
108 sign[1] := chr(data[1]);
109 sign[2] := chr(data[2]);
110 if sign = MAP_SIGNATURE then
111 begin
112 nm := win2utf(list.Files[i].name);
113 lbMapList.Items.Add(nm);
114 if placeName then
115 begin
116 nm := UpperCase(nm);
117 if (nm[1] = 'M') and (nm[2] = 'A') and (nm[3] = 'P') then
118 begin
119 nm := Trim(Copy(nm, 4, Length(nm)-3));
120 j := StrToIntDef(nm, 0);
121 if j >= max_num then
122 max_num := j + 1;
123 end
124 end
125 end
126 end;
128 if len > 0 then FreeMem(data)
129 end;
131 list.Destroy;
132 end;
135 if placeName then
136 begin
137 nm := IntToStr(max_num);
138 if Length(nm) < 2 then
139 nm := '0' + nm;
140 eMapName.Text := 'MAP' + nm
141 end
142 else
143 begin
144 eMapName.Text := ''
145 end
146 end;
148 end.