source: oup/releases/0.19a/Unit1_main.pas@ 1154

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