source: oup/releases/0.28a/Unit1_main.pas@ 482

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