source: oup/releases/0.30a/Unit1_main.pas@ 89

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