DEADSOFTWARE

fixed wadeditor; added nosound mode; fixed codepage problems; fixed pointers; cleanup
[d2df-editor.git] / src / editor / f_mapoptions.pas
1 unit f_mapoptions;
3 {$INCLUDE ../shared/a_modes.inc}
5 interface
7 uses
8 SysUtils, Classes, Forms, Dialogs,
9 Controls, StdCtrls, ComCtrls, Buttons,
10 f_main, utils;
12 type
13 TMapOptionsForm = class (TForm)
14 // Имя карты:
15 LabelName: TLabel;
16 lCharCountName: TLabel;
17 eMapName: TEdit;
18 // Описание карты:
19 LabelDesc: TLabel;
20 lCharCountDescription: TLabel;
21 eMapDescription: TEdit;
22 // Автор карты:
23 LabelAuthor: TLabel;
24 lCharCountAuthor: TLabel;
25 eAuthor: TEdit;
26 // Фон:
27 LabelBack: TLabel;
28 eBack: TEdit;
29 bRemoveBack: TButton;
30 bSelectBack: TButton;
31 // Музыка:
32 LabelMusic: TLabel;
33 eMusic: TEdit;
34 bRemoveMusic: TButton;
35 bSelectMusic: TButton;
37 // Статистика:
38 GBStats: TGroupBox;
39 LabelTexs: TLabel;
40 lTextureCount: TLabel;
41 LabelPanels: TLabel;
42 lPanelCount: TLabel;
43 LabelItems: TLabel;
44 lItemCount: TLabel;
45 LabelMonsters: TLabel;
46 lMonsterCount: TLabel;
47 LabelAreas: TLabel;
48 lAreaCount: TLabel;
49 LabelTriggers: TLabel;
50 lTriggerCount: TLabel;
52 // Размеры:
53 GBSizes: TGroupBox;
54 eMapWidth: TEdit;
55 UpDown1: TUpDown;
56 eMapHeight: TEdit;
57 UpDown2: TUpDown;
58 LabelWidth: TLabel;
59 LabelHeight: TLabel;
60 LabelCurSize: TLabel;
61 lCurrentMapSizes: TLabel;
63 // Навигатор направления смещения
64 sbMoveCenter: TSpeedButton;
65 sbMoveLeft: TSpeedButton;
66 sbMoveRight: TSpeedButton;
67 sbMoveUp: TSpeedButton;
68 sbMoveUpLeft: TSpeedButton;
69 sbMoveUpRight: TSpeedButton;
70 sbMoveDown: TSpeedButton;
71 sbMoveDownLeft: TSpeedButton;
72 sbMoveDownRight: TSpeedButton;
73 LabelMapMove: TLabel;
74 cbSnapping: TCheckBox;
76 // Кнопки:
77 bOK: TButton;
78 bCancel: TButton;
80 procedure FormActivate(Sender: TObject);
81 procedure bCancelClick(Sender: TObject);
82 procedure bOKClick(Sender: TObject);
84 procedure eMapNameChange(Sender: TObject);
85 procedure eMapDescriptionChange(Sender: TObject);
86 procedure eAuthorChange(Sender: TObject);
88 procedure bSelectBackClick(Sender: TObject);
89 procedure bSelectMusicClick(Sender: TObject);
90 procedure bRemoveBackClick(Sender: TObject);
91 procedure bRemoveMusicClick(Sender: TObject);
92 procedure eMapSizeKeyPress(Sender: TObject; var Key: Char);
94 private
95 function CalcOffsetX(WidthDiff: Integer): Integer;
96 function CalcOffsetY(HeightDiff: Integer): Integer;
98 public
99 { Public declarations }
100 end;
102 var
103 MapOptionsForm: TMapOptionsForm;
105 implementation
107 uses
108 g_map, f_addresource_sky, f_addresource_sound;
110 {$R *.lfm}
112 // Callbacks to receive results from resource choosing dialogs
113 function SetSky: Boolean;
114 begin
115 MapOptionsForm.eBack.Text := win2utf(AddSkyForm.ResourceName);
116 Result := True;
117 end;
119 function SetMusic: Boolean;
120 begin
121 MapOptionsForm.eMusic.Text := win2utf(AddSoundForm.ResourceName);
122 Result := True;
123 end;
125 // Form processing
126 procedure TMapOptionsForm.FormActivate(Sender: TObject);
127 var
128 a, b: Integer;
129 begin
130 // General map options
131 eMapName.Text := win2utf(gMapInfo.Name);
132 eMapDescription.Text := win2utf(gMapInfo.Description);
133 eAuthor.Text := win2utf(gMapInfo.Author);
135 eBack.Text := win2utf(gMapInfo.SkyName);
136 eMusic.Text := win2utf(gMapInfo.MusicName);
138 eMapWidth.Text := IntToStr(gMapInfo.Width);
139 eMapHeight.Text := IntToStr(gMapInfo.Height);
140 lCurrentMapSizes.Caption := eMapWidth.Text + 'x' + eMapHeight.Text;
142 sbMoveCenter.Down := True;
144 // Map statistics
145 lTextureCount.Caption := IntToStr(MainForm.lbTextureList.Count);
147 b := 0; // Panels
148 if gPanels <> nil then
149 for a := 0 to High(gPanels) do
150 if gPanels[a].PanelType <> 0 then b := b+1;
151 lPanelCount.Caption := IntToStr(b);
153 b := 0; // Items
154 if gItems <> nil then
155 for a := 0 to High(gItems) do
156 if gItems[a].ItemType <> 0 then b := b+1;
157 lItemCount.Caption := IntToStr(b);
159 b := 0; // Areas
160 if gAreas <> nil then
161 for a := 0 to High(gAreas) do
162 if gAreas[a].AreaType <> 0 then b := b+1;
163 lAreaCount.Caption := IntToStr(b);
165 b := 0; // Monsters
166 if gMonsters <> nil then
167 for a := 0 to High(gMonsters) do
168 if gMonsters[a].MonsterType <> 0 then b := b+1;
169 lMonsterCount.Caption := IntToStr(b);
171 b := 0; // Triggers
172 if gTriggers <> nil then
173 for a := 0 to High(gTriggers) do
174 if gTriggers[a].TriggerType <> 0 then
175 b := b + 1;
176 lTriggerCount.Caption := IntToStr(b);
178 end;
180 procedure TMapOptionsForm.bCancelClick(Sender: TObject);
181 begin
182 Close();
183 end;
185 procedure TMapOptionsForm.bOKClick(Sender: TObject);
186 var
187 newWidth, newHeight: Integer;
188 begin
189 newWidth := StrToInt(eMapWidth.Text);
190 newHeight := StrToInt(eMapHeight.Text);
192 with gMapInfo do
193 begin
194 Name := utf2win(eMapName.Text);
195 Description := utf2win(eMapDescription.Text);
196 Author := utf2win(eAuthor.Text);
197 SkyName := utf2win(eBack.Text);
198 MusicName := utf2win(eMusic.Text);
200 if Width > newWidth then
201 MapOffset.X := 0;
202 if Height > newHeight then
203 MapOffset.Y := 0;
205 ShiftMapObjects( CalcOffsetX(newWidth - Width),
206 CalcOffsetY(newHeight - Height) );
208 Width := newWidth;
209 Height := newHeight;
210 end;
212 LoadSky(gMapInfo.SkyName);
214 MainForm.FormResize(Self);
215 Close();
216 end;
218 // Counters of chars in edit fields
219 procedure TMapOptionsForm.eMapNameChange(Sender: TObject);
220 begin
221 lCharCountName.Caption := Format('%.2d\32', [Length(eMapName.Text)]);
222 end;
224 procedure TMapOptionsForm.eMapDescriptionChange(Sender: TObject);
225 begin
226 lCharCountDescription.Caption := Format('%.3d\256', [Length(eMapDescription.Text)]);
227 end;
229 procedure TMapOptionsForm.eAuthorChange(Sender: TObject);
230 begin
231 lCharCountAuthor.Caption := Format('%.2d\32', [Length(eAuthor.Text)]);
232 end;
234 // Buttons processing
235 procedure TMapOptionsForm.bSelectBackClick(Sender: TObject);
236 begin
237 AddSkyForm.OKFunction := SetSky;
238 AddSkyForm.lbResourcesList.MultiSelect := False;
239 AddSkyForm.SetResource := utf2win(eBack.Text);
240 AddSkyForm.ShowModal();
241 end;
243 procedure TMapOptionsForm.bSelectMusicClick(Sender: TObject);
244 begin
245 AddSoundForm.OKFunction := SetMusic;
246 AddSoundForm.lbResourcesList.MultiSelect := False;
247 AddSoundForm.SetResource := utf2win(eMusic.Text);
248 AddSoundForm.ShowModal();
249 end;
251 procedure TMapOptionsForm.bRemoveBackClick(Sender: TObject);
252 begin
253 eBack.Clear();
254 end;
256 procedure TMapOptionsForm.bRemoveMusicClick(Sender: TObject);
257 begin
258 eMusic.Clear();
259 end;
261 // Map width/height edit fields input processor: only digits are allowed
262 procedure TMapOptionsForm.eMapSizeKeyPress( Sender: TObject;
263 var Key: Char );
264 begin
265 if not ( Key in ['0'..'9', #8, #127] ) then // #8 - bs, #127 - del
266 Key := #0;
267 end;
269 // Offsets calculating for shifting map objects
270 function TMapOptionsForm.CalcOffsetX(WidthDiff: Integer): Integer;
271 begin
272 Result := 0;
273 if (sbMoveCenter.Down or
274 sbMoveUp.Down or
275 sbMoveDown.Down) then Result := WidthDiff div 2
276 else
277 if (sbMoveRight.Down or
278 sbMoveUpRight.Down or
279 sbMoveDownRight.Down) then Result := WidthDiff;
281 if cbSnapping.Checked then Result := Trunc(Result / DotStep) * DotStep;
282 end;
284 function TMapOptionsForm.CalcOffsetY(HeightDiff: Integer): Integer;
285 begin
286 Result := 0;
287 if (sbMoveCenter.Down or
288 sbMoveLeft.Down or
289 sbMoveRight.Down) then Result := HeightDiff div 2
290 else
291 if (sbMoveDown.Down or
292 sbMoveDownLeft.Down or
293 sbMoveDownRight.Down) then Result := HeightDiff;
295 if cbSnapping.Checked then Result := Trunc(Result / DotStep) * DotStep;
296 end;
298 end.