0c361c52e5ba19bac69a6d399ed6e039851f0716
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
)
14 SaveDialog
: TSaveDialog
;
24 cbTextrures
: TCheckBox
;
25 LabelTextures
: TLabel
;
37 cbNonStandart
: TCheckBox
;
39 procedure bSelectWADClick(Sender
: TObject
);
40 procedure bPackClick(Sender
: TObject
);
41 procedure FormCreate(Sender
: TObject
);
44 { Private declarations }
46 { Public declarations }
50 PackMapForm
: TPackMapForm
;
55 BinEditor
, WADEDITOR
, g_map
, MAPREADER
, MAPWRITER
, MAPSTRUCT
,
56 f_main
, math
, g_language
, g_resources
;
61 STANDART_WAD
= 'standart.wad';
62 SHRSHADE_WAD
= 'shrshade.wad';
65 procedure TPackMapForm
.bSelectWADClick(Sender
: TObject
);
67 SaveDialog
.Filter
:= _lc
[I_FILE_FILTER_WAD
];
69 if SaveDialog
.Execute() then
70 eWAD
.Text := SaveDialog
.FileName
;
73 function ProcessResource(wad_to
, section_to
, filename
, section
, resource
: String): Boolean;
79 g_ProcessResourceStr(OpenedMap
, @filename
, nil, nil)
81 filename
:= EditorDir
+ 'wads/' + filename
;
83 g_ReadResource(filename
, section
, resource
, data
, len
);
86 (* Write resource only if it does not exists *)
87 g_ExistsResource(wad_to
, section_to
, resource
, res
);
90 g_AddResource(wad_to
, section_to
, resource
, data
, len
, res
);
98 //MessageBox(0, PChar(Format(_lc[I_MSG_WAD_ERROR], [ExtractFileName(filename)])), PChar(_lc[I_MSG_ERROR]), MB_OK + MB_ICONERROR);
99 MessageBox(0, PChar(Format(_lc
[I_MSG_RES_ERROR
], [filename
, section
, resource
])), PChar(_lc
[I_MSG_ERROR
]), MB_OK
+ MB_ICONERROR
);
104 procedure TPackMapForm
.bPackClick(Sender
: TObject
);
110 textures
: TTexturesRec1Array
;
111 header
: TMapHeaderRec_1
;
113 res
, tsection
, ssection
, msection
, filename
, section
, resource
: String;
116 if eWAD
.Text = '' then
118 if eResource
.Text = '' then
121 tsection
:= eTSection
.Text;
122 ssection
:= eSSection
.Text;
123 msection
:= eMSection
.Text;
125 // Сохраняем карту в память:
130 // Не перезаписывать WAD, а дополнить:
131 if not cbAdd
.Checked
then
133 if FileExists(eWAD
.Text) then
135 if FileExists(eWAD
.Text + '.bak0') then
136 ASSERT(DeleteFile(eWAD
.Text + '.bak0'));
137 ASSERT(RenameFile(eWAD
.Text, eWAD
.Text + '.bak0'))
141 // Читаем карту из памяти:
142 mr
:= TMapReader_1
.Create();
146 // Получаем текстуры:
147 textures
:= mr
.GetTextures();
149 // Нужно копировать текстуры:
150 if cbTextrures
.Checked
and (textures
<> nil) then
151 for a
:= 0 to High(textures
) do
153 res
:= win2utf(textures
[a
].Resource
);
154 if IsSpecialTexture(res
) then
157 g_ProcessResourceStr(res
, @filename
, @section
, @resource
);
159 // Не записывать стандартные текстуры:
160 if (not cbNonStandart
.Checked
) or
161 ( (AnsiLowerCase(filename
) <> STANDART_WAD
) and
162 (AnsiLowerCase(filename
) <> SHRSHADE_WAD
) ) then
164 // Копируем ресурс текстуры:
165 if not f_packmap
.ProcessResource(eWAD
.Text, tsection
, filename
, section
, resource
) then
171 // Переименовываем ресурс текстуры:
172 res
:= utf2win(Format(':%s\%s', [tsection
, resource
]));
173 ZeroMemory(@textures
[a
].Resource
[0], 64);
174 CopyMemory(@textures
[a
].Resource
[0], @res
[1], Min(Length(res
), 64));
178 // Получаем заголовок карты:
179 header
:= mr
.GetMapHeader();
181 // Нужно копировать небо:
182 if cbSky
.Checked
then
184 res
:= win2utf(header
.SkyName
);
185 g_ProcessResourceStr(res
, @filename
, @section
, @resource
);
187 // Не записывать стандартное небо:
188 if (not cbNonStandart
.Checked
) or
189 ( (AnsiLowerCase(filename
) <> STANDART_WAD
) and
190 (AnsiLowerCase(filename
) <> SHRSHADE_WAD
) ) then
192 // Копируем ресурс неба:
193 if not f_packmap
.ProcessResource(eWAD
.Text, ssection
, filename
, section
, resource
) then
199 // Переименовываем ресурс неба:
200 res
:= utf2win(Format(':%s\%s', [ssection
, resource
]));
201 ZeroMemory(@header
.SkyName
[0], 64);
202 CopyMemory(@header
.SkyName
[0], @res
[1], Min(Length(res
), 64));
206 // Нужно копировать музыку:
207 if cbMusic
.Checked
then
209 res
:= win2utf(header
.MusicName
);
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(eWAD
.Text, msection
, filename
, section
, resource
) then
224 // Переименовываем ресурс музыки:
225 res
:= utf2win(Format(':%s\%s', [msection
, resource
]));
226 ZeroMemory(@header
.MusicName
[0], 64);
227 CopyMemory(@header
.MusicName
[0], @res
[1], Min(Length(res
), 64));
232 // Нужно копировать дополнительные текстуры:
233 if cbTextrures.Checked and (textures <> nil) and
234 (gPanels <> nil) and (gTriggers <> nil) then
236 for a := 0 to High(gPanels) do
240 // Ссылаются ли на эту панель триггеры:
241 for b := 0 to High(gTriggers) do
242 if ( (gTriggers[b].TriggerType in [TRIGGER_OPENDOOR,
243 TRIGGER_CLOSEDOOR, TRIGGER_DOOR, TRIGGER_DOOR5,
244 TRIGGER_CLOSETRAP, TRIGGER_TRAP, TRIGGER_LIFTUP,
245 TRIGGER_LIFTDOWN, TRIGGER_LIFT]) and
246 (gTriggers[b].Data.PanelID = a) ) or
247 (gTriggers[b].TexturePanel = a) then
253 // Есть триггеры на эту панель:
254 if ok and (gPanels[a].TextureName <> '') and
255 (not IsSpecialTexture(gPanels[a].TextureName) and
256 g_Texture_NumNameFindStart(gPanels[a].TextureName) then
260 r := g_Texture_NumNameFindNext(res);
263 NNF_NAME_EQUALS: Continue;
270 g_ProcessResourceStr(res, @filename, @section, @resource);
272 // Не записывать стандартные дополнительные текстуры:
273 if (not cbNonStandart.Checked) or
274 ( (AnsiLowerCase(filename) <> STANDART_WAD) and
275 (AnsiLowerCase(filename) <> SHRSHADE_WAD) ) then
277 // Копируем ресурс дополнительной текстуры:
278 if f_packmap.ProcessResource(eWAD.Text, tsection, filename, section, resource) then
281 Нужно проверять есть такая текстура textures и есть ли она вообще?
282 // Переименовываем ресурс текстуры:
283 res := utf2win(Format(':%s\%s', [tsection, resource]));
284 ZeroMemory(@textures[a].Resource[0], 64);
285 CopyMemory(@textures[a].Resource[0], @res[1], Min(Length(res), 64));
297 // Записываем изменения карты:
298 mw
:= TMapWriter_1
.Create();
300 mw
.AddHeader(header
);
301 mw
.AddTextures(textures
);
302 mw
.AddPanels(mr
.GetPanels());
303 mw
.AddItems(mr
.GetItems());
304 mw
.AddAreas(mr
.GetAreas());
305 mw
.AddMonsters(mr
.GetMonsters());
306 mw
.AddTriggers(mr
.GetTriggers());
308 // Сохраняем карту из памяти под новым именем в WAD-файл:
309 len
:= mw
.SaveMap(data
);
310 g_AddResource(eWAD
.Text, '', eResource
.Text, data
, len
, a
);
315 ASSERT(a
= 0); (* saved *)
316 MessageDlg(Format(_lc
[I_MSG_PACKED
], [eResource
.Text, ExtractFileName(eWAD
.Text)]), mtInformation
, [mbOK
], 0);
319 procedure TPackMapForm
.FormCreate(Sender
: TObject
);
321 SaveDialog
.InitialDir
:= EditorDir
;