3 {$INCLUDE ../shared/a_modes.inc}
8 SysUtils
, Classes
, Forms
, Dialogs
,
9 Controls
, StdCtrls
, ComCtrls
, Buttons
,
13 TMapOptionsForm
= class (TForm
)
16 lCharCountName
: TLabel
;
20 lCharCountDescription
: TLabel
;
21 eMapDescription
: TEdit
;
24 lCharCountAuthor
: TLabel
;
34 bRemoveMusic
: TButton
;
35 bSelectMusic
: TButton
;
40 lTextureCount
: TLabel
;
45 LabelMonsters
: TLabel
;
46 lMonsterCount
: TLabel
;
49 LabelTriggers
: TLabel
;
50 lTriggerCount
: 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
;
74 cbSnapping
: TCheckBox
;
80 procedure FormShow(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);
95 function CalcOffsetX(WidthDiff
: Integer): Integer;
96 function CalcOffsetY(HeightDiff
: Integer): Integer;
99 { Public declarations }
103 MapOptionsForm
: TMapOptionsForm
;
108 g_map
, f_addresource_sky
, f_addresource_sound
;
112 // Callbacks to receive results from resource choosing dialogs
113 function SetSky
: Boolean;
115 MapOptionsForm
.eBack
.Text := AddSkyForm
.ResourceName
;
119 function SetMusic
: Boolean;
121 MapOptionsForm
.eMusic
.Text := AddSoundForm
.ResourceName
;
125 procedure TMapOptionsForm
.FormShow(Sender
: TObject
);
128 // General map options
129 eMapName
.Text := gMapInfo
.Name
;
130 eMapDescription
.Text := gMapInfo
.Description
;
131 eAuthor
.Text := gMapInfo
.Author
;
133 eBack
.Text := gMapInfo
.SkyName
;
134 eMusic
.Text := gMapInfo
.MusicName
;
136 eMapWidth
.Text := IntToStr(gMapInfo
.Width
);
137 eMapHeight
.Text := IntToStr(gMapInfo
.Height
);
138 lCurrentMapSizes
.Caption
:= eMapWidth
.Text + 'x' + eMapHeight
.Text;
140 sbMoveCenter
.Down
:= True;
143 lTextureCount
.Caption
:= IntToStr(MainForm
.lbTextureList
.Count
);
146 if gPanels
<> nil then
147 for a
:= 0 to High(gPanels
) do
148 if gPanels
[a
].PanelType
<> 0 then b
:= b
+1;
149 lPanelCount
.Caption
:= IntToStr(b
);
152 if gItems
<> nil then
153 for a
:= 0 to High(gItems
) do
154 if gItems
[a
].ItemType
<> 0 then b
:= b
+1;
155 lItemCount
.Caption
:= IntToStr(b
);
158 if gAreas
<> nil then
159 for a
:= 0 to High(gAreas
) do
160 if gAreas
[a
].AreaType
<> 0 then b
:= b
+1;
161 lAreaCount
.Caption
:= IntToStr(b
);
164 if gMonsters
<> nil then
165 for a
:= 0 to High(gMonsters
) do
166 if gMonsters
[a
].MonsterType
<> 0 then b
:= b
+1;
167 lMonsterCount
.Caption
:= IntToStr(b
);
170 if gTriggers
<> nil then
171 for a
:= 0 to High(gTriggers
) do
172 if gTriggers
[a
].TriggerType
<> 0 then
174 lTriggerCount
.Caption
:= IntToStr(b
);
177 procedure TMapOptionsForm
.bCancelClick(Sender
: TObject
);
182 procedure TMapOptionsForm
.bOKClick(Sender
: TObject
);
184 newWidth
, newHeight
: Integer;
186 newWidth
:= StrToInt(eMapWidth
.Text);
187 newHeight
:= StrToInt(eMapHeight
.Text);
191 Name
:= eMapName
.Text;
192 Description
:= eMapDescription
.Text;
193 Author
:= eAuthor
.Text;
194 SkyName
:= eBack
.Text;
195 MusicName
:= eMusic
.Text;
197 if Width
> newWidth
then
199 if Height
> newHeight
then
202 ShiftMapObjects( CalcOffsetX(newWidth
- Width
),
203 CalcOffsetY(newHeight
- Height
) );
209 LoadSky(gMapInfo
.SkyName
);
211 MainForm
.FormResize(Self
);
215 // Counters of chars in edit fields
216 procedure TMapOptionsForm
.eMapNameChange(Sender
: TObject
);
218 lCharCountName
.Caption
:= Format('%.2d\32', [Length(eMapName
.Text)]);
221 procedure TMapOptionsForm
.eMapDescriptionChange(Sender
: TObject
);
223 lCharCountDescription
.Caption
:= Format('%.3d\256', [Length(eMapDescription
.Text)]);
226 procedure TMapOptionsForm
.eAuthorChange(Sender
: TObject
);
228 lCharCountAuthor
.Caption
:= Format('%.2d\32', [Length(eAuthor
.Text)]);
231 // Buttons processing
232 procedure TMapOptionsForm
.bSelectBackClick(Sender
: TObject
);
234 AddSkyForm
.OKFunction
:= SetSky
;
235 AddSkyForm
.lbResourcesList
.MultiSelect
:= False;
236 AddSkyForm
.SetResource
:= eBack
.Text;
237 AddSkyForm
.ShowModal();
240 procedure TMapOptionsForm
.bSelectMusicClick(Sender
: TObject
);
242 AddSoundForm
.OKFunction
:= SetMusic
;
243 AddSoundForm
.lbResourcesList
.MultiSelect
:= False;
244 AddSoundForm
.SetResource
:= eMusic
.Text;
245 AddSoundForm
.ShowModal();
248 procedure TMapOptionsForm
.bRemoveBackClick(Sender
: TObject
);
253 procedure TMapOptionsForm
.bRemoveMusicClick(Sender
: TObject
);
258 // Map width/height edit fields input processor: only digits are allowed
259 procedure TMapOptionsForm
.eMapSizeKeyPress( Sender
: TObject
;
262 if not ( Key
in ['0'..'9', #8, #127] ) then // #8 - bs, #127 - del
266 // Offsets calculating for shifting map objects
267 function TMapOptionsForm
.CalcOffsetX(WidthDiff
: Integer): Integer;
270 if (sbMoveCenter
.Down
or
272 sbMoveDown
.Down
) then Result
:= WidthDiff
div 2
274 if (sbMoveRight
.Down
or
275 sbMoveUpRight
.Down
or
276 sbMoveDownRight
.Down
) then Result
:= WidthDiff
;
278 if cbSnapping
.Checked
then Result
:= Trunc(Result
/ DotStep
) * DotStep
;
281 function TMapOptionsForm
.CalcOffsetY(HeightDiff
: Integer): Integer;
284 if (sbMoveCenter
.Down
or
286 sbMoveRight
.Down
) then Result
:= HeightDiff
div 2
288 if (sbMoveDown
.Down
or
289 sbMoveDownLeft
.Down
or
290 sbMoveDownRight
.Down
) then Result
:= HeightDiff
;
292 if cbSnapping
.Checked
then Result
:= Trunc(Result
/ DotStep
) * DotStep
;