source: oup/current/Unit1_main.pas@ 28

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