source: oup/releases/0.18a2/Unit1_main.pas@ 207

Last change on this file since 207 was 21, checked in by alloc, 18 years ago
File size: 11.4 KB
Line 
1UNIT Unit1_main;
2INTERFACE
3USES
4 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
5 Dialogs, StdCtrls, StrUtils, Clipbrd, ExtCtrls, ComCtrls, Menus,
6 Unit2_functions, Unit3_data, Unit5_preview, Unit7_txmpreplace, Unit8_binedit,
7 Grids, MPHexEditor, ToolWin, ImgList, Tabs;
8
9TYPE
10 TForm1 = Class(TForm)
11 fopen: TOpenDialog;
12 menu: TMainMenu;
13 menu_main: TMenuItem;
14 menu_exit: TMenuItem;
15 menu_preview: TMenuItem;
16 menu_tools: TMenuItem;
17 menu_txmpreplace: TMenuItem;
18 menu_extract: TMenuItem;
19 menu_extractfile: TMenuItem;
20 menu_extractlist: TMenuItem;
21 menu_extractall: TMenuItem;
22 menu_loaddat: TMenuItem;
23 menu_sep1: TMenuItem;
24 menu_binedit: TMenuItem;
25 statbar: TStatusBar;
26 menu_windows: TMenuItem;
27 menu_windows_cascade: TMenuItem;
28 menu_windows_closeall: TMenuItem;
29 menu_sep2: TMenuItem;
30 menu_windows_tile: TMenuItem;
31 menu_sep3: TMenuItem;
32 menu_windows_next: TMenuItem;
33 menu_windows_previous: TMenuItem;
34 tabs: TTabSet;
35 PROCEDURE SetActiveWindow(window_name:String);
36 PROCEDURE tabsChange(Sender: TObject; NewTab: Integer; var AllowChange: Boolean);
37 PROCEDURE close_window(window_name:String);
38 PROCEDURE menu_windows_previousClick(Sender: TObject);
39 PROCEDURE menu_windows_nextClick(Sender: TObject);
40 PROCEDURE menu_windows_tileClick(Sender: TObject);
41 PROCEDURE open_child(window_context:String);
42 PROCEDURE menu_windows_closeallClick(Sender: TObject);
43 PROCEDURE menu_windows_cascadeClick(Sender: TObject);
44 PROCEDURE menu_window_entryClick(Sender: TObject);
45 PROCEDURE menu_bineditClick(Sender: TObject);
46 PROCEDURE menu_loaddatClick(Sender: TObject);
47 PROCEDURE menu_txmpreplaceClick(Sender: TObject);
48 PROCEDURE menu_exitClick(Sender: TObject);
49 PROCEDURE menu_previewClick(Sender: TObject);
50 PROCEDURE FormClose(Sender: TObject; var Action: TCloseAction);
51 PROCEDURE FormResize(Sender: TObject);
52 PROCEDURE FormCreate(Sender: TObject);
53 PRIVATE
54 PUBLIC
55 END;
56
57VAR
58 Form1: TForm1;
59
60IMPLEMENTATION
61{$R *.dfm}
62VAR
63 tablist:Array OF String;
64
65PROCEDURE LoadDat;
66 VAR i:LongWord;
67 BEGIN
68 Form1.fopen.InitialDir:=AppSettings.DatPath;
69 IF Form1.fopen.Execute THEN BEGIN
70 Form1.Caption:='Oni Un/Packer '+version+' ('+ExtractFileName(Form1.fopen.FileName)+')';
71 AppSettings.DatPath:=ExtractFilepath(Form1.fopen.FileName);
72 IF LoadDatInfos(Form1.fopen.FileName) THEN BEGIN
73 Form1.statbar.Panels.Items[0].Text:='Current .dat: '+dat_FileName;
74 Form1.statbar.Panels.Items[1].Text:='Files: '+IntToStr(dat_header.Files);
75 Form1.statbar.Panels.Items[2].Text:='Extensions: '+IntToStr(dat_header.Extensions);
76 Form1.menu_tools.Enabled:=True;
77 Form1.menu_extract.Enabled:=True;
78
79 IF Form1.MDIChildCount>0 THEN
80 FOR i:=0 TO Form1.MDIChildCount-1 DO BEGIN
81 IF Pos('binedit',Form1.MDIChildren[i].Name)>0 THEN
82 TForm8(Form1.MDIChildren[i]).Recreatelist;
83 IF Pos('preview',Form1.MDIChildren[i].Name)>0 THEN
84 TForm5(Form1.MDIChildren[i]).Recreatelist;
85 IF Pos('txmpreplace',Form1.MDIChildren[i].Name)>0 THEN
86 TForm7(Form1.MDIChildren[i]).Recreatelist;
87 END;
88 END ELSE BEGIN
89 ShowMessage('Error while loading the file:'+CrLf+Form1.fopen.FileName+CrLf+'Perhaps not an Oni-.dat-file?');
90 END;
91 END;
92 END;
93
94PROCEDURE TForm1.FormCreate(Sender: TObject);
95 BEGIN
96 Form1.Caption:='Oni Un/Packer '+version;
97 Form1.FormResize(Form1);
98
99 IF FileExists(ExtractFilepath(Application.EXEname)+'\oniunpacker.ini') THEN BEGIN
100 AssignFile(AppSettingsFile,ExtractFilepath(Application.EXEname)+'\oniunpacker.ini');
101 Reset(AppSettingsFile);
102 Read(AppSettingsFile,AppSettings);
103 CloseFile(AppSettingsFile);
104 END ELSE BEGIN
105 AppSettings.DatPath:='D:\Spiele\Oni\GameDataFolder';
106 AppSettings.ExtractPath:='C:\Dokumente und Einstellungen\Administrator\Desktop';
107 END;
108 END;
109
110PROCEDURE TForm1.FormResize(Sender: TObject);
111 CONST
112 MinWidth:Integer=750;
113 MinHeight:Integer=500;
114 BEGIN
115 IF Form1.Width<MinWidth THEN Form1.Width:=MinWidth;
116 IF Form1.Height<MinHeight THEN Form1.Height:=MinHeight;
117 Form1.statbar.Panels.Items[0].Width:=Form1.Width-200;
118 END;
119
120PROCEDURE TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
121 BEGIN
122 AssignFile(AppSettingsFile,ExtractFilepath(Application.EXEname)+'\oniunpacker.ini');
123 IF FileExists(ExtractFilepath(Application.EXEname)+'\oniunpacker.ini') THEN
124 Reset(AppSettingsFile)
125 ELSE
126 Rewrite(AppSettingsFile);
127 Write(AppSettingsFile,AppSettings);
128 CloseFile(AppSettingsFile);
129 Action:=caFree;
130 END;
131
132
133{#################################}
134{##### Main-Menu-Handlers #####}
135{#################################}
136PROCEDURE TForm1.menu_loaddatClick(Sender: TObject);
137 BEGIN
138 LoadDat;
139 END;
140PROCEDURE TForm1.menu_exitClick(Sender: TObject);
141 BEGIN
142 Form1.Close;
143 END;
144
145{#################################}
146{##### Tools-Menu-Handlers #####}
147{#################################}
148PROCEDURE TForm1.menu_previewClick(Sender: TObject);
149 BEGIN
150 open_child('preview');
151 END;
152PROCEDURE TForm1.menu_txmpreplaceClick(Sender: TObject);
153 BEGIN
154 open_child('txmpreplace');
155 END;
156PROCEDURE TForm1.menu_bineditClick(Sender: TObject);
157 BEGIN
158 open_child('binedit');
159 END;
160
161{#################################}
162{##### Window-Menu-Handlers #####}
163{#################################}
164PROCEDURE TForm1.menu_windows_cascadeClick(Sender: TObject);
165 BEGIN
166 Form1.Cascade;
167 END;
168PROCEDURE TForm1.menu_windows_tileClick(Sender: TObject);
169 BEGIN
170 Form1.TileMode:=tbHorizontal;
171 Form1.Tile;
172 END;
173PROCEDURE TForm1.menu_windows_closeallClick(Sender: TObject);
174 VAR
175 i:Byte;
176 BEGIN
177 IF MDIChildCount>0 THEN BEGIN
178 FOR i:=0 TO MDIChildCount-1 DO BEGIN
179 MDIChildren[i].Close;
180 END;
181 END;
182 tabs.Tabs.Clear;
183 END;
184PROCEDURE TForm1.menu_windows_nextClick(Sender: TObject);
185 VAR i:Byte;
186 first_window:Byte;
187 current_focus:String;
188 BEGIN
189 IF MDIChildCount>1 THEN BEGIN
190 FOR i:=0 TO menu_windows.Count-1 DO BEGIN
191 IF Pos('menu_window_',menu_windows.Items[i].Name)=1 THEN BEGIN
192 first_window:=i;
193 Break;
194 END;
195 END;
196 current_focus:=ActiveMDIChild.Name;
197 FOR i:=first_window TO menu_windows.Count-1 DO
198 IF Pos(current_focus,menu_windows.Items[i].Name)>0 THEN
199 Break;
200 IF i=menu_windows.Count-1 THEN
201 menu_windows.Items[first_window].Click
202 ELSE
203 menu_windows.Items[i+1].Click;
204 FOR i:=0 TO High(tablist) DO BEGIN
205 IF tablist[i]=ActiveMDIChild.Name THEN BEGIN
206 tabs.TabIndex:=i;
207 END;
208 END;
209 END;
210 END;
211PROCEDURE TForm1.menu_windows_previousClick(Sender: TObject);
212 VAR i:Byte;
213 first_window:Byte;
214 current_focus:String;
215 BEGIN
216 IF MDIChildCount>1 THEN BEGIN
217 FOR i:=0 TO menu_windows.Count-1 DO BEGIN
218 IF Pos('menu_window_',menu_windows.Items[i].Name)=1 THEN BEGIN
219 first_window:=i;
220 Break;
221 END;
222 END;
223 current_focus:=ActiveMDIChild.Name;
224 FOR i:=first_window TO menu_windows.Count-1 DO
225 IF Pos(current_focus,menu_windows.Items[i].Name)>0 THEN
226 Break;
227 IF i=first_window THEN
228 menu_windows.Items[menu_windows.Count-1].Click
229 ELSE
230 menu_windows.Items[i-1].Click;
231 FOR i:=0 TO High(tablist) DO BEGIN
232 IF tablist[i]=ActiveMDIChild.Name THEN BEGIN
233 tabs.TabIndex:=i;
234 END;
235 END;
236 END;
237 END;
238
239PROCEDURE TForm1.menu_window_entryClick(Sender: TObject);
240 VAR
241 i:Byte;
242 window_name:String;
243 BEGIN
244 window_name:=MidStr(TComponent(Sender).Name,Pos('window_',TComponent(Sender).Name)+7,Length(TComponent(Sender).Name)-Pos('window_',TComponent(Sender).Name)+7+1);
245 FOR i:=0 TO MDIChildCount-1 DO BEGIN
246 IF MDIChildren[i].Name=window_name THEN BEGIN
247 MDIChildren[i].BringToFront;
248 END;
249 END;
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
257
258
259PROCEDURE TForm1.open_child(window_context:String);
260 VAR
261 binEdit:TForm8;
262 preview:TForm5;
263 txmpreplacer:TForm7;
264 menu_button:TMenuItem;
265 used:Array[1..9] OF Boolean;
266 i:Byte;
267 caption:String;
268 name:String;
269 BEGIN
270 FOR i:=1 TO 9 DO used[i]:=False;
271 IF MDIChildCount>0 THEN
272 FOR i:=0 TO MDIChildCount-1 DO
273 IF Pos(window_context,Form1.MDIChildren[i].Name)=1 THEN
274 used[StrToInt(RightStr(Form1.MDIChildren[i].Caption,1))]:=True;
275 FOR i:=1 TO 10 DO
276 IF i=10 THEN
277 Break
278 ELSE
279 IF NOT used[i] THEN Break;
280
281 IF i<10 THEN BEGIN
282 name:=window_context+IntToStr(i);
283 IF window_context='binedit' THEN
284 caption:='Binary .dat-Editor '+IntToStr(i);
285 IF window_context='preview' THEN
286 caption:='Preview-Window '+IntToStr(i);
287 IF window_context='txmpreplace' THEN
288 caption:='TXMP Replacer '+IntToStr(i);
289
290 menu_button:=TMenuItem.Create(menu_windows);
291 menu_button.Caption:=caption;
292 menu_button.Name:='menu_window_'+name;
293 menu_button.OnClick:=Form1.menu_window_entryClick;
294 menu_windows.Add(menu_button);
295
296 SetLength(tablist,Length(tablist)+1);
297 tablist[High(tablist)]:=name;
298 tabs.Tabs.Add(caption);
299
300 IF window_context='binedit' THEN BEGIN
301 binEdit:=TForm8.Create(Application);
302 binEdit.Name:=name;
303 binEdit.Caption:=caption;
304 binEdit.Recreatelist;
305 END;
306 IF window_context='preview' THEN BEGIN
307 preview:=TForm5.Create(Application);
308 preview.Name:=name;
309 preview.Caption:=caption;
310 preview.Recreatelist;
311 END;
312 IF window_context='txmpreplace' THEN BEGIN
313 txmpreplacer:=TForm7.Create(Application);
314 txmpreplacer.Name:=name;
315 txmpreplacer.Caption:=caption;
316 txmpreplacer.Recreatelist;
317 END;
318
319 tabs.TabIndex:=High(tablist);
320 IF MDIChildCount=9 THEN menu_tools.Enabled:=False;
321 END;
322 END;
323
324
325PROCEDURE TForm1.close_window(window_name:String);
326 VAR
327 i,j:Byte;
328 BEGIN
329 FOR i:=0 TO menu_windows.Count-1 DO BEGIN
330 IF menu_windows.Items[i].Name='menu_window_'+window_name THEN BEGIN
331 menu_windows.Items[i].Free;
332 Break;
333 END;
334 END;
335 FOR i:=0 TO High(tablist) DO BEGIN
336 IF tablist[i]=window_name THEN BEGIN
337 tabs.Tabs.Delete(i);
338 IF High(tablist)>0 THEN
339 FOR j:=i TO High(tablist)-1 DO
340 tablist[j]:=tablist[j+1];
341 SetLength(tablist,Length(tablist)-1);
342 Break;
343 END;
344 END;
345 menu_tools.Enabled:=True;
346 END;
347
348
349PROCEDURE TForm1.tabsChange(Sender: TObject; NewTab: Integer; var AllowChange: Boolean);
350 VAR
351 i:Byte;
352 BEGIN
353 FOR i:=0 TO MDIChildCount-1 DO BEGIN
354 IF MDIChildren[i].Name=tablist[NewTab] THEN
355 MDIChildren[i].BringToFront;
356 END;
357 END;
358
359PROCEDURE TForm1.SetActiveWindow(window_name:String);
360 VAR
361 i:Byte;
362 BEGIN
363 IF Length(tablist)>0 THEN
364 FOR i:=0 TO High(tablist) DO
365 IF tablist[i]=window_name THEN
366 tabs.TabIndex:=i;
367 END;
368
369
370END.
Note: See TracBrowser for help on using the repository browser.