source: oup/releases/0.24a/Unit1_main.pas@ 1009

Last change on this file since 1009 was 24, checked in by alloc, 18 years ago
File size: 14.3 KB
Line 
1UNIT Unit1_main;
2INTERFACE
3USES
4 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
5 Dialogs, StdCtrls, StrUtils, Clipbrd, ExtCtrls, ComCtrls, Menus, Grids,
6 MPHexEditor, ToolWin, ImgList, Tabs,
7 Unit2_functions, Unit3_data,
8 Unit10_leveldb, Unit4_exporters,
9 Unit5_preview, Unit7_txmpreplace, Unit8_binedit, Unit11_extractor, Unit13_rawedit;
10
11TYPE
12 TForm1 = Class(TForm)
13 tabs: TTabSet;
14 saved: TSaveDialog;
15 opend: TOpenDialog;
16 statbar: TStatusBar;
17 menu: TMainMenu;
18 menu_main: TMenuItem;
19 menu_loaddat: TMenuItem;
20 menu_lvldb: TMenuItem;
21 menu_exit: TMenuItem;
22 menu_convert: TMenuItem;
23 menu_createdb: TMenuItem;
24 menu_createlvl: TMenuItem;
25 menu_tools: TMenuItem;
26 menu_preview: TMenuItem;
27 menu_txmpreplace: TMenuItem;
28 menu_binedit: TMenuItem;
29 menu_extractor: TMenuItem;
30 menu_windows: TMenuItem;
31 menu_windows_cascade: TMenuItem;
32 menu_windows_tile: TMenuItem;
33 menu_windows_closeall: TMenuItem;
34 menu_windows_next: TMenuItem;
35 menu_windows_previous: TMenuItem;
36 menu_sep1: TMenuItem;
37 menu_sep2: TMenuItem;
38 menu_sep3: TMenuItem;
39 menu_levelstructedit: TMenuItem;
40 menu_rawedit: TMenuItem;
41 PROCEDURE menu_raweditClick(Sender: TObject);
42 PROCEDURE menu_createlvlClick(Sender: TObject);
43 PROCEDURE menu_extractorClick(Sender: TObject);
44 PROCEDURE menu_lvldbClick(Sender: TObject);
45 PROCEDURE menu_createdbClick(Sender: TObject);
46 PROCEDURE SetActiveWindow(window_name:String);
47 PROCEDURE tabsChange(Sender: TObject; NewTab: Integer; var AllowChange: Boolean);
48 PROCEDURE close_window(window_name:String);
49 PROCEDURE menu_windows_previousClick(Sender: TObject);
50 PROCEDURE menu_windows_nextClick(Sender: TObject);
51 PROCEDURE menu_windows_tileClick(Sender: TObject);
52 FUNCTION open_child(window_context:String):Boolean;
53 PROCEDURE menu_windows_closeallClick(Sender: TObject);
54 PROCEDURE menu_windows_cascadeClick(Sender: TObject);
55 PROCEDURE menu_window_entryClick(Sender: TObject);
56 PROCEDURE menu_bineditClick(Sender: TObject);
57 PROCEDURE menu_loaddatClick(Sender: TObject);
58 PROCEDURE menu_txmpreplaceClick(Sender: TObject);
59 PROCEDURE menu_exitClick(Sender: TObject);
60 PROCEDURE menu_previewClick(Sender: TObject);
61 PROCEDURE FormClose(Sender: TObject; var Action: TCloseAction);
62 PROCEDURE FormResize(Sender: TObject);
63 PROCEDURE FormCreate(Sender: TObject);
64 PRIVATE
65 PUBLIC
66 END;
67
68VAR
69 Form1: TForm1;
70
71IMPLEMENTATION
72{$R *.dfm}
73VAR
74 tablist:Array OF String;
75
76PROCEDURE TForm1.FormCreate(Sender: TObject);
77 BEGIN
78 Form1.Caption:='Oni Un/Packer '+version;
79 Form1.FormResize(Form1);
80
81 IF FileExists(ExtractFilepath(Application.EXEname)+'\oniunpacker.ini') THEN BEGIN
82 AssignFile(AppSettingsFile,ExtractFilepath(Application.EXEname)+'\oniunpacker.ini');
83 Reset(AppSettingsFile);
84 Read(AppSettingsFile,AppSettings);
85 CloseFile(AppSettingsFile);
86 END ELSE BEGIN
87 AppSettings.DatPath:='D:\Spiele\Oni\GameDataFolder';
88 AppSettings.ExtractPath:='C:\Dokumente und Einstellungen\Administrator\Desktop';
89 END;
90 END;
91
92PROCEDURE TForm1.FormResize(Sender: TObject);
93 CONST
94 MinWidth:Integer=750;
95 MinHeight:Integer=500;
96 BEGIN
97 IF Form1.Width<MinWidth THEN Form1.Width:=MinWidth;
98 IF Form1.Height<MinHeight THEN Form1.Height:=MinHeight;
99 Form1.statbar.Panels.Items[0].Width:=Form1.Width-200;
100 END;
101
102PROCEDURE TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
103 BEGIN
104 AssignFile(AppSettingsFile,ExtractFilepath(Application.EXEname)+'\oniunpacker.ini');
105 IF FileExists(ExtractFilepath(Application.EXEname)+'\oniunpacker.ini') THEN
106 Reset(AppSettingsFile)
107 ELSE
108 Rewrite(AppSettingsFile);
109 Write(AppSettingsFile,AppSettings);
110 CloseFile(AppSettingsFile);
111 Action:=caFree;
112 END;
113
114
115{#################################}
116{##### Main-Menu-Handlers #####}
117{#################################}
118PROCEDURE TForm1.menu_loaddatClick(Sender: TObject);
119 VAR i:LongWord;
120 BEGIN
121 opend.InitialDir:=AppSettings.DatPath;
122 opend.Filter:='Oni-Dat-Files|*.dat';
123 IF opend.Execute THEN BEGIN
124 menu_windows_closeallClick(Form1);
125 IF opened_state=opened_db THEN CloseDatabase;
126 IF Length(tablist)=0 THEN BEGIN
127 Caption:='Oni Un/Packer '+version;
128 statbar.Panels.Items[0].Text:='Nothing loaded';
129 statbar.Panels.Items[1].Text:='Files: -';
130 statbar.Panels.Items[2].Text:='Extensions: -';
131 AppSettings.DatPath:=ExtractFilepath(opend.FileName);
132 IF LoadDatInfos(opend.FileName) THEN BEGIN
133 Form1.Caption:='Oni Un/Packer '+version+' ('+ExtractFileName(opend.FileName)+')';
134 statbar.Panels.Items[0].Text:='.dat loaded: '+dat_FileName;
135 statbar.Panels.Items[1].Text:='Files: '+IntToStr(dat_header.Files);
136 statbar.Panels.Items[2].Text:='Extensions: '+IntToStr(dat_header.Extensions);
137 menu_tools.Enabled:=True;
138 menu_convert.Enabled:=True;
139 menu_createdb.Enabled:=True;
140 menu_createlvl.Enabled:=False;
141 END ELSE BEGIN
142 ShowMessage('Error while loading the file:'+CrLf+opend.FileName+CrLf+'Perhaps not an Oni-.dat-file?');
143 END;
144 END;
145 END;
146 END;
147PROCEDURE TForm1.menu_lvldbClick(Sender: TObject);
148 BEGIN
149 opend.InitialDir:=AppSettings.DatPath;
150 opend.Filter:='OUP-Level-DB (*.oldb)|*.oldb';
151 IF opend.Execute THEN BEGIN
152 menu_windows_closeallClick(Form1);
153 IF opened_state=opened_db THEN CloseDatabase;
154 IF Length(tablist)=0 THEN BEGIN
155 Form1.Caption:='Oni Un/Packer '+version;
156 opened_state:=opened_nothing;
157 statbar.Panels.Items[0].Text:='Nothing loaded';
158 statbar.Panels.Items[1].Text:='Files: -';
159 statbar.Panels.Items[2].Text:='Extensions: -';
160 OpenDatabase(opend.FileName);
161 IF opened_state=opened_db THEN BEGIN
162 menu_tools.Enabled:=True;
163 menu_convert.Enabled:=True;
164 menu_createdb.Enabled:=False;
165 menu_createlvl.Enabled:=True;
166 statbar.Panels.Items[0].Text:='OLDB loaded: '+opend.FileName;
167 statbar.Panels.Items[1].Text:='Files: '+IntToStr(Length(GetFilesList('','',False)));
168 statbar.Panels.Items[2].Text:='Extensions: '+IntToStr(Length(GetExtensionsList));
169 END ELSE BEGIN
170 menu_tools.Enabled:=False;
171 menu_convert.Enabled:=False;
172 END;
173 END;
174 END;
175 END;
176PROCEDURE TForm1.menu_exitClick(Sender: TObject);
177 BEGIN
178 Form1.Close;
179 END;
180
181{####################################}
182{##### Converters-Menu-Handlers #####}
183{####################################}
184PROCEDURE TForm1.menu_createdbClick(Sender: TObject);
185 BEGIN
186 IF opened_state=opened_dat THEN BEGIN
187 saved.Filter:='OUP-Level-DB (*.oldb)|*.oldb';
188 saved.DefaultExt:='oldb';
189 IF saved.Execute THEN BEGIN
190 Form10.CreateDatabase(saved.FileName);
191 END;
192 END;
193 END;
194PROCEDURE TForm1.menu_createlvlClick(Sender: TObject);
195 BEGIN
196 BEGIN END;
197 END;
198
199{#################################}
200{##### Tools-Menu-Handlers #####}
201{#################################}
202PROCEDURE TForm1.menu_previewClick(Sender: TObject);
203 BEGIN
204 open_child('preview');
205 END;
206PROCEDURE TForm1.menu_txmpreplaceClick(Sender: TObject);
207 BEGIN
208 open_child('txmpreplace');
209 END;
210PROCEDURE TForm1.menu_bineditClick(Sender: TObject);
211 BEGIN
212 open_child('binedit');
213 END;
214PROCEDURE TForm1.menu_raweditClick(Sender: TObject);
215 BEGIN
216 open_child('rawedit');
217 END;
218PROCEDURE TForm1.menu_extractorClick(Sender: TObject);
219 BEGIN
220 open_child('extractor');
221 END;
222
223{#################################}
224{##### Window-Menu-Handlers #####}
225{#################################}
226PROCEDURE TForm1.menu_windows_cascadeClick(Sender: TObject);
227 BEGIN
228 Form1.Cascade;
229 END;
230PROCEDURE TForm1.menu_windows_tileClick(Sender: TObject);
231 BEGIN
232 Form1.TileMode:=tbHorizontal;
233 Form1.Tile;
234 END;
235PROCEDURE TForm1.menu_windows_closeallClick(Sender: TObject);
236 VAR
237 i:Byte;
238 BEGIN
239 IF MDIChildCount>0 THEN BEGIN
240 FOR i:=0 TO MDIChildCount-1 DO BEGIN
241 MDIChildren[i].Close;
242 END;
243 END;
244 tabs.Tabs.Clear;
245 END;
246PROCEDURE TForm1.menu_windows_nextClick(Sender: TObject);
247 VAR i:Byte;
248 first_window:Byte;
249 current_focus:String;
250 BEGIN
251 IF MDIChildCount>1 THEN BEGIN
252 FOR i:=0 TO menu_windows.Count-1 DO BEGIN
253 IF Pos('menu_window_',menu_windows.Items[i].Name)=1 THEN BEGIN
254 first_window:=i;
255 Break;
256 END;
257 END;
258 current_focus:=ActiveMDIChild.Name;
259 FOR i:=first_window TO menu_windows.Count-1 DO
260 IF Pos(current_focus,menu_windows.Items[i].Name)>0 THEN
261 Break;
262 IF i=menu_windows.Count-1 THEN
263 menu_windows.Items[first_window].Click
264 ELSE
265 menu_windows.Items[i+1].Click;
266 FOR i:=0 TO High(tablist) DO BEGIN
267 IF tablist[i]=ActiveMDIChild.Name THEN BEGIN
268 tabs.TabIndex:=i;
269 END;
270 END;
271 END;
272 END;
273PROCEDURE TForm1.menu_windows_previousClick(Sender: TObject);
274 VAR i:Byte;
275 first_window:Byte;
276 current_focus:String;
277 BEGIN
278 IF MDIChildCount>1 THEN BEGIN
279 FOR i:=0 TO menu_windows.Count-1 DO BEGIN
280 IF Pos('menu_window_',menu_windows.Items[i].Name)=1 THEN BEGIN
281 first_window:=i;
282 Break;
283 END;
284 END;
285 current_focus:=ActiveMDIChild.Name;
286 FOR i:=first_window TO menu_windows.Count-1 DO
287 IF Pos(current_focus,menu_windows.Items[i].Name)>0 THEN
288 Break;
289 IF i=first_window THEN
290 menu_windows.Items[menu_windows.Count-1].Click
291 ELSE
292 menu_windows.Items[i-1].Click;
293 FOR i:=0 TO High(tablist) DO BEGIN
294 IF tablist[i]=ActiveMDIChild.Name THEN BEGIN
295 tabs.TabIndex:=i;
296 END;
297 END;
298 END;
299 END;
300
301PROCEDURE TForm1.menu_window_entryClick(Sender: TObject);
302 VAR
303 i:Byte;
304 window_name:String;
305 BEGIN
306 window_name:=MidStr(TComponent(Sender).Name,Pos('window_',TComponent(Sender).Name)+7,Length(TComponent(Sender).Name)-Pos('window_',TComponent(Sender).Name)+7+1);
307 FOR i:=0 TO MDIChildCount-1 DO BEGIN
308 IF MDIChildren[i].Name=window_name THEN BEGIN
309 MDIChildren[i].BringToFront;
310 END;
311 END;
312 FOR i:=0 TO High(tablist) DO BEGIN
313 IF tablist[i]=ActiveMDIChild.Name THEN BEGIN
314 tabs.TabIndex:=i;
315 END;
316 END;
317 END;
318
319
320
321FUNCTION TForm1.open_child(window_context:String):Boolean;
322 VAR
323 rawEdit:TForm13;
324 binEdit:TForm8;
325 preview:TForm5;
326 txmpreplacer:TForm7;
327 extractor:TForm11;
328 menu_button:TMenuItem;
329 used:Array[1..9] OF Boolean;
330 i:Byte;
331 caption:String;
332 name:String;
333 BEGIN
334 Result:=True;
335 FOR i:=1 TO 9 DO used[i]:=False;
336 IF MDIChildCount>0 THEN
337 FOR i:=0 TO MDIChildCount-1 DO
338 IF Pos(window_context,Form1.MDIChildren[i].Name)=1 THEN
339 used[StrToInt(RightStr(Form1.MDIChildren[i].Caption,1))]:=True;
340 FOR i:=1 TO 10 DO
341 IF i=10 THEN
342 Break
343 ELSE
344 IF NOT used[i] THEN Break;
345
346 IF i<10 THEN BEGIN
347 name:=window_context+IntToStr(i);
348 IF window_context='binedit' THEN
349 caption:='Binary .dat-Editor '+IntToStr(i);
350 IF window_context='rawedit' THEN
351 caption:='Binary .raw-Editor '+IntToStr(i);
352 IF window_context='preview' THEN
353 caption:='Preview-Window '+IntToStr(i);
354 IF window_context='txmpreplace' THEN
355 caption:='TXMP Replacer '+IntToStr(i);
356 IF window_context='extractor' THEN
357 caption:='Extractor '+IntToStr(i);
358
359 menu_button:=TMenuItem.Create(menu_windows);
360 menu_button.Caption:=caption;
361 menu_button.Name:='menu_window_'+name;
362 menu_button.OnClick:=Form1.menu_window_entryClick;
363 menu_windows.Add(menu_button);
364
365 SetLength(tablist,Length(tablist)+1);
366 tablist[High(tablist)]:=name;
367 tabs.Tabs.Add(caption);
368
369 IF window_context='binedit' THEN BEGIN
370 binEdit:=TForm8.Create(Application);
371 binEdit.Name:=name;
372 binEdit.Caption:=caption;
373 binEdit.Recreatelist;
374 END;
375 IF window_context='rawedit' THEN BEGIN
376 rawEdit:=TForm13.Create(Application);
377 rawEdit.Name:=name;
378 rawEdit.Caption:=caption;
379 rawEdit.Recreatelist;
380 END;
381 IF window_context='preview' THEN BEGIN
382 preview:=TForm5.Create(Application);
383 preview.Name:=name;
384 preview.Caption:=caption;
385 preview.Recreatelist;
386 END;
387 IF window_context='txmpreplace' THEN BEGIN
388 txmpreplacer:=TForm7.Create(Application);
389 txmpreplacer.Name:=name;
390 txmpreplacer.Caption:=caption;
391 txmpreplacer.Recreatelist;
392 END;
393 IF window_context='extractor' THEN BEGIN
394 extractor:=TForm11.Create(Application);
395 extractor.Name:=name;
396 extractor.Caption:=caption;
397 extractor.Recreatelist;
398 END;
399
400 tabs.TabIndex:=High(tablist);
401 IF MDIChildCount=9 THEN menu_tools.Enabled:=False;
402 END ELSE BEGIN
403 Result:=False;
404 END;
405 END;
406
407
408PROCEDURE TForm1.close_window(window_name:String);
409 VAR
410 i,j:Byte;
411 BEGIN
412 FOR i:=0 TO menu_windows.Count-1 DO BEGIN
413 IF menu_windows.Items[i].Name='menu_window_'+window_name THEN BEGIN
414 menu_windows.Items[i].Free;
415 Break;
416 END;
417 END;
418 FOR i:=0 TO High(tablist) DO BEGIN
419 IF tablist[i]=window_name THEN BEGIN
420 tabs.Tabs.Delete(i);
421 IF High(tablist)>0 THEN
422 FOR j:=i TO High(tablist)-1 DO
423 tablist[j]:=tablist[j+1];
424 SetLength(tablist,Length(tablist)-1);
425 Break;
426 END;
427 END;
428 menu_tools.Enabled:=True;
429 END;
430
431
432PROCEDURE TForm1.tabsChange(Sender: TObject; NewTab: Integer; var AllowChange: Boolean);
433 VAR
434 i:Byte;
435 BEGIN
436 FOR i:=0 TO MDIChildCount-1 DO BEGIN
437 IF MDIChildren[i].Name=tablist[NewTab] THEN
438 MDIChildren[i].BringToFront;
439 END;
440 END;
441
442PROCEDURE TForm1.SetActiveWindow(window_name:String);
443 VAR
444 i:Byte;
445 BEGIN
446 IF Length(tablist)>0 THEN
447 FOR i:=0 TO High(tablist) DO
448 IF tablist[i]=window_name THEN
449 tabs.TabIndex:=i;
450 END;
451
452
453END.
Note: See TracBrowser for help on using the repository browser.