9d3a20ce1e6b619ffa359802745d2d5068a584bd
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 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);
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 := win2utf(AddSkyForm
.ResourceName
);
119 function SetMusic
: Boolean;
121 MapOptionsForm
.eMusic
.Text := win2utf(AddSoundForm
.ResourceName
);
126 procedure TMapOptionsForm
.FormActivate(Sender
: TObject
);
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;
145 lTextureCount
.Caption
:= IntToStr(MainForm
.lbTextureList
.Count
);
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
);
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
);
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
);
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
);
172 if gTriggers
<> nil then
173 for a
:= 0 to High(gTriggers
) do
174 if gTriggers
[a
].TriggerType
<> 0 then
176 lTriggerCount
.Caption
:= IntToStr(b
);
180 procedure TMapOptionsForm
.bCancelClick(Sender
: TObject
);
185 procedure TMapOptionsForm
.bOKClick(Sender
: TObject
);
187 newWidth
, newHeight
: Integer;
189 newWidth
:= StrToInt(eMapWidth
.Text);
190 newHeight
:= StrToInt(eMapHeight
.Text);
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
202 if Height
> newHeight
then
205 ShiftMapObjects( CalcOffsetX(newWidth
- Width
),
206 CalcOffsetY(newHeight
- Height
) );
212 LoadSky(gMapInfo
.SkyName
);
214 MainForm
.FormResize(Self
);
218 // Counters of chars in edit fields
219 procedure TMapOptionsForm
.eMapNameChange(Sender
: TObject
);
221 lCharCountName
.Caption
:= Format('%.2d\32', [Length(eMapName
.Text)]);
224 procedure TMapOptionsForm
.eMapDescriptionChange(Sender
: TObject
);
226 lCharCountDescription
.Caption
:= Format('%.3d\256', [Length(eMapDescription
.Text)]);
229 procedure TMapOptionsForm
.eAuthorChange(Sender
: TObject
);
231 lCharCountAuthor
.Caption
:= Format('%.2d\32', [Length(eAuthor
.Text)]);
234 // Buttons processing
235 procedure TMapOptionsForm
.bSelectBackClick(Sender
: TObject
);
237 AddSkyForm
.OKFunction
:= SetSky
;
238 AddSkyForm
.lbResourcesList
.MultiSelect
:= False;
239 AddSkyForm
.SetResource
:= utf2win(eBack
.Text);
240 AddSkyForm
.ShowModal();
243 procedure TMapOptionsForm
.bSelectMusicClick(Sender
: TObject
);
245 AddSoundForm
.OKFunction
:= SetMusic
;
246 AddSoundForm
.lbResourcesList
.MultiSelect
:= False;
247 AddSoundForm
.SetResource
:= utf2win(eMusic
.Text);
248 AddSoundForm
.ShowModal();
251 procedure TMapOptionsForm
.bRemoveBackClick(Sender
: TObject
);
256 procedure TMapOptionsForm
.bRemoveMusicClick(Sender
: TObject
);
261 // Map width/height edit fields input processor: only digits are allowed
262 procedure TMapOptionsForm
.eMapSizeKeyPress( Sender
: TObject
;
265 if not ( Key
in ['0'..'9', #8, #127] ) then // #8 - bs, #127 - del
269 // Offsets calculating for shifting map objects
270 function TMapOptionsForm
.CalcOffsetX(WidthDiff
: Integer): Integer;
273 if (sbMoveCenter
.Down
or
275 sbMoveDown
.Down
) then Result
:= WidthDiff
div 2
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
;
284 function TMapOptionsForm
.CalcOffsetY(HeightDiff
: Integer): Integer;
287 if (sbMoveCenter
.Down
or
289 sbMoveRight
.Down
) then Result
:= HeightDiff
div 2
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
;