source: oup/releases/0.23a/Unit1_main.pas@ 455

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