source: oup/releases/0.21a/Unit1_main.pas@ 1080

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