lang: ru: fix translation Enable Monsters -> Включить монстров
[d2df-editor.git] / src / editor / f_savemap.pas
blob0fecb85bfe91dce274a2fd90a857d96cf032969c
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 var
14 lbMapList: TListBox;
15 Panel1: TPanel;
16 bOK: TButton;
17 bCancel: TButton;
18 Panel2: TPanel;
19 eMapName: TEdit;
21 procedure GetMaps(FileName: String; placeName: Boolean; ArchiveFormat: String);
22 procedure FormActivate(Sender: TObject);
23 procedure eMapNameChange(Sender: TObject);
24 procedure lbMapListClick(Sender: TObject);
25 procedure bOKClick(Sender: TObject);
27 private
28 { Private declarations }
29 public
30 { Public declarations }
31 end;
33 var
34 SaveMapForm: TSaveMapForm;
36 implementation
38 uses
39 BinEditor, MAPREADER, WADEDITOR, WADSTRUCT, MAPSTRUCT, g_language;
41 {$R *.lfm}
43 procedure TSaveMapForm.FormActivate(Sender: TObject);
44 begin
45 bOK.Enabled := (eMapName.Text <> '');
46 eMapName.SetFocus();
47 end;
49 procedure TSaveMapForm.eMapNameChange(Sender: TObject);
50 begin
51 if eMapName.Text <> '' then
52 bOK.Enabled := True
53 else
54 bOK.Enabled := False;
55 end;
57 procedure TSaveMapForm.lbMapListClick(Sender: TObject);
58 begin
59 if lbMapList.ItemIndex > -1 then
60 eMapName.Text := lbMapList.Items[lbMapList.ItemIndex];
61 end;
63 procedure TSaveMapForm.bOKClick(Sender: TObject);
64 var
65 a: Integer;
66 ok: Boolean;
68 begin
69 ok := True;
70 for a := 0 to lbMapList.Count-1 do
71 if eMapName.Text = lbMapList.Items[a] then
72 begin
73 ok := Application.MessageBox(PChar(Format(MsgMsgMapExists,
74 [eMapName.Text])),
75 PChar(MsgMsgSaveMap),
76 MB_ICONQUESTION or MB_YESNO or MB_DEFBUTTON1) = mrYes;
77 if not ok then
78 Exit;
79 Break;
80 end;
82 if ok then
83 ModalResult := mrOk
84 else
85 ModalResult := mrCancel;
86 end;
88 procedure TSaveMapForm.GetMaps(FileName: String; placeName: Boolean; ArchiveFormat: String);
89 var
90 WAD: TWADEditor;
91 a, max_num, j: Integer;
92 ResList: SArray;
93 Data: Pointer;
94 Len: Integer;
95 Sign: Array [0..2] of Char;
96 nm: String;
98 begin
99 lbMapList.Items.Clear();
100 max_num := 1;
102 if ArchiveFormat = '' then
103 begin
104 // format not specified -> try open automatically and append to it (or create new default)
105 WAD := gWADEditorFactory.OpenFile(FileName);
106 if WAD = nil then
107 WAD := gWADEditorFactory.CreateDefaultEditor();
109 else
110 begin
111 // format specified -> append using exactly this format (overwrite if not compatible)
112 WAD := gWADEditorFactory.CreateEditor(ArchiveFormat);
113 if WAD.ReadFile(FileName) = False then
114 WAD.FreeWAD();
115 end;
117 ResList := WAD.GetResourcesList('');
119 if ResList <> nil then
120 for a := 0 to High(ResList) do
121 begin
122 if not WAD.GetResource('', ResList[a], Data, Len) then
123 Continue;
125 CopyMemory(@Sign[0], Data, 3);
126 FreeMem(Data);
128 if Sign = MAP_SIGNATURE then
129 begin
130 nm := win2utf(ResList[a]);
131 lbMapList.Items.Add(nm);
133 if placeName then
134 begin
135 nm := UpperCase(nm);
136 if (nm[1] = 'M') and
137 (nm[2] = 'A') and
138 (nm[3] = 'P') then
139 begin
140 nm := Trim(Copy(nm, 4, Length(nm)-3));
141 j := StrToIntDef(nm, 0);
142 if j >= max_num then
143 max_num := j + 1;
144 end;
145 end;
146 end;
148 Sign := '';
149 end;
151 WAD.Free();
153 if placeName then
154 begin
155 nm := IntToStr(max_num);
156 if Length(nm) < 2 then
157 nm := '0' + nm;
158 nm := 'MAP' + nm;
159 eMapName.Text := nm;
161 else
162 eMapName.Text := '';
163 end;
165 initialization
166 SaveMapForm := TSaveMapForm.Create(Application);
167 end.