3 {$INCLUDE ../shared/a_modes.inc}
8 LCLIntf
, LCLType
, LMessages
, SysUtils
, Variants
, Classes
,
9 Graphics
, Controls
, Forms
, Dialogs
, StdCtrls
, ExtCtrls
, utils
;
12 TPackMapForm
= class (TForm
)
15 SaveDialog
: TSaveDialog
;
25 cbTextrures
: TCheckBox
;
26 LabelTextures
: TLabel
;
38 cbNonStandart
: TCheckBox
;
40 procedure bSelectWADClick(Sender
: TObject
);
41 procedure bPackClick(Sender
: TObject
);
42 procedure FormCreate(Sender
: TObject
);
45 { Private declarations }
47 { Public declarations }
51 PackMapForm
: TPackMapForm
;
56 BinEditor
, WADEDITOR
, g_map
, MAPREADER
, MAPWRITER
, MAPSTRUCT
,
57 f_main
, math
, g_language
, g_options
, e_log
;
62 STANDART_WAD
= 'standart.wad';
63 SHRSHADE_WAD
= 'shrshade.wad';
66 procedure TPackMapForm
.bSelectWADClick(Sender
: TObject
);
68 SaveDialog
.Filter
:= MsgFileFilterWad
;
70 if SaveDialog
.Execute() then
71 eWAD
.Text := SaveDialog
.FileName
;
74 function ProcessResource(wad_to
: TWADEditor_1
; section_to
, filename
, section
, resource
: String): Boolean;
85 g_ProcessResourceStr(OpenedMap
, @filename
, nil, nil)
87 filename
:= WadsDir
+ DirectorySeparator
+ filename
;
89 // Читаем ресурс из WAD-файла карты или какого-то другого:
90 wad2
:= TWADEditor_1
.Create();
92 if not wad2
.ReadFile(filename
) then
94 Application
.MessageBox(PChar(Format(MsgMsgWadError
, [ExtractFileName(filename
)])), PChar(MsgMsgError
), MB_OK
+ MB_ICONERROR
);
99 if not wad2
.GetResource(utf2win(section
), utf2win(resource
), data
, reslen
) then
101 Application
.MessageBox(PChar(Format(MsgMsgResError
, [filename
, section
, resource
])), PChar(MsgMsgError
), MB_OK
+ MB_ICONERROR
);
108 {if wad_to.HaveResource(utf2win(section_to), utf2win(resource)) then
113 if not wad_to.HaveResource(utf2win(section_to), utf2win(resource+s)) then Break;
115 resource := resource+s;
118 // Если такого ресурса нет в WAD-файле-назначении, то копируем:
119 if not wad_to
.HaveResource(utf2win(section_to
), utf2win(resource
)) then
121 if not wad_to
.HaveSection(utf2win(section_to
)) then
122 wad_to
.AddSection(utf2win(section_to
));
123 wad_to
.AddResource(data
, reslen
, utf2win(resource
), utf2win(section_to
));
131 procedure TPackMapForm
.bPackClick(Sender
: TObject
);
138 textures
: TTexturesRec1Array
;
139 header
: TMapHeaderRec_1
;
141 res
, tsection
, ssection
, msection
, filename
, section
, resource
: String;
144 if eWAD
.Text = '' then
146 if eResource
.Text = '' then
149 tsection
:= eTSection
.Text;
150 ssection
:= eSSection
.Text;
151 msection
:= eMSection
.Text;
153 // Сохраняем карту в память:
154 data
:= SaveMap('', '');
158 WAD
:= TWADEditor_1
.Create();
160 // Не перезаписывать WAD, а дополнить:
161 if cbAdd
.Checked
then
162 if WAD
.ReadFile(eWAD
.Text) then
165 // Читаем карту из памяти:
166 mr
:= TMapReader_1
.Create();
170 // Получаем текстуры:
171 textures
:= mr
.GetTextures();
173 // Нужно копировать текстуры:
174 if cbTextrures
.Checked
and (textures
<> nil) then
175 for a
:= 0 to High(textures
) do
177 res
:= win2utf(textures
[a
].Resource
);
178 if IsSpecialTexture(res
) then
181 g_ProcessResourceStr(res
, @filename
, @section
, @resource
);
183 // Не записывать стандартные текстуры:
184 if (not cbNonStandart
.Checked
) or
185 ( (AnsiLowerCase(filename
) <> STANDART_WAD
) and
186 (AnsiLowerCase(filename
) <> SHRSHADE_WAD
) ) then
188 // Копируем ресурс текстуры:
189 if not f_packmap
.ProcessResource(WAD
, tsection
, filename
, section
, resource
) then
196 // Переименовываем ресурс текстуры:
197 res
:= utf2win(Format(':%s\%s', [tsection
, resource
]));
198 ZeroMemory(@textures
[a
].Resource
[0], 64);
199 CopyMemory(@textures
[a
].Resource
[0], @res
[1], Min(Length(res
), 64));
203 // Получаем заголовок карты:
204 header
:= mr
.GetMapHeader();
206 // Нужно копировать небо:
207 if cbSky
.Checked
then
209 res
:= win2utf(header
.SkyName
);
210 g_ProcessResourceStr(res
, @filename
, @section
, @resource
);
212 // Не записывать стандартное небо:
213 if (not cbNonStandart
.Checked
) or
214 ( (AnsiLowerCase(filename
) <> STANDART_WAD
) and
215 (AnsiLowerCase(filename
) <> SHRSHADE_WAD
) ) then
217 // Копируем ресурс неба:
218 if not f_packmap
.ProcessResource(WAD
, ssection
, filename
, section
, resource
) then
225 // Переименовываем ресурс неба:
226 res
:= utf2win(Format(':%s\%s', [ssection
, resource
]));
227 ZeroMemory(@header
.SkyName
[0], 64);
228 CopyMemory(@header
.SkyName
[0], @res
[1], Min(Length(res
), 64));
232 // Нужно копировать музыку:
233 if cbMusic
.Checked
then
235 res
:= win2utf(header
.MusicName
);
236 g_ProcessResourceStr(res
, @filename
, @section
, @resource
);
238 // Не записывать стандартную музыку:
239 if (not cbNonStandart
.Checked
) or
240 ( (AnsiLowerCase(filename
) <> STANDART_WAD
) and
241 (AnsiLowerCase(filename
) <> SHRSHADE_WAD
) ) then
243 // Копируем ресурс музыки:
244 if not f_packmap
.ProcessResource(WAD
, msection
, filename
, section
, resource
) then
251 // Переименовываем ресурс музыки:
252 res
:= utf2win(Format(':%s\%s', [msection
, resource
]));
253 ZeroMemory(@header
.MusicName
[0], 64);
254 CopyMemory(@header
.MusicName
[0], @res
[1], Min(Length(res
), 64));
259 // Нужно копировать дополнительные текстуры:
260 if cbTextrures.Checked and (textures <> nil) and
261 (gPanels <> nil) and (gTriggers <> nil) then
263 for a := 0 to High(gPanels) do
267 // Ссылаются ли на эту панель триггеры:
268 for b := 0 to High(gTriggers) do
269 if ( (gTriggers[b].TriggerType in [TRIGGER_OPENDOOR,
270 TRIGGER_CLOSEDOOR, TRIGGER_DOOR, TRIGGER_DOOR5,
271 TRIGGER_CLOSETRAP, TRIGGER_TRAP, TRIGGER_LIFTUP,
272 TRIGGER_LIFTDOWN, TRIGGER_LIFT]) and
273 (gTriggers[b].Data.PanelID = a) ) or
274 (gTriggers[b].TexturePanel = a) then
280 // Есть триггеры на эту панель:
281 if ok and (gPanels[a].TextureName <> '') and
282 (not IsSpecialTexture(gPanels[a].TextureName) and
283 g_Texture_NumNameFindStart(gPanels[a].TextureName) then
287 r := g_Texture_NumNameFindNext(res);
290 NNF_NAME_EQUALS: Continue;
297 g_ProcessResourceStr(res, @filename, @section, @resource);
299 // Не записывать стандартные дополнительные текстуры:
300 if (not cbNonStandart.Checked) or
301 ( (AnsiLowerCase(filename) <> STANDART_WAD) and
302 (AnsiLowerCase(filename) <> SHRSHADE_WAD) ) then
304 // Копируем ресурс дополнительной текстуры:
305 if f_packmap.ProcessResource(WAD, tsection, filename, section, resource) then
308 Нужно проверять есть такая текстура textures и есть ли она вообще?
309 // Переименовываем ресурс текстуры:
310 res := utf2win(Format(':%s\%s', [tsection, resource]));
311 ZeroMemory(@textures[a].Resource[0], 64);
312 CopyMemory(@textures[a].Resource[0], @res[1], Min(Length(res), 64));
324 // Записываем изменения карты:
325 mw
:= TMapWriter_1
.Create();
327 mw
.AddHeader(header
);
328 mw
.AddTextures(textures
);
329 mw
.AddPanels(mr
.GetPanels());
330 mw
.AddItems(mr
.GetItems());
331 mw
.AddAreas(mr
.GetAreas());
332 mw
.AddMonsters(mr
.GetMonsters());
333 mw
.AddTriggers(mr
.GetTriggers());
335 // Сохраняем карту из памяти под новым именем в WAD-файл:
336 len
:= mw
.SaveMap(data
);
337 WAD
.AddResource(data
, len
, eResource
.Text, '');
338 WAD
.SaveTo(eWAD
.Text);
344 MessageDlg(Format(MsgMsgPacked
, [eResource
.Text, ExtractFileName(eWAD
.Text)]), mtInformation
, [mbOK
], 0);
348 procedure TPackMapForm
.FormCreate(Sender
: TObject
);
350 SaveDialog
.InitialDir
:= MapsDir
;
354 PackMapForm
:= TPackMapForm
.Create(Application
);