source: oup/releases/0.18a/Unit1_main.pas@ 776

Last change on this file since 776 was 21, checked in by alloc, 18 years ago
File size: 9.5 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 procedure menu_windows_previousClick(Sender: TObject);
35 procedure menu_windows_nextClick(Sender: TObject);
36 procedure menu_windows_tileClick(Sender: TObject);
37 PROCEDURE open_child(window_context:String);
38 PROCEDURE menu_windows_closeallClick(Sender: TObject);
39 PROCEDURE menu_windows_cascadeClick(Sender: TObject);
40 PROCEDURE menu_window_entryClick(Sender: TObject);
41 PROCEDURE menu_bineditClick(Sender: TObject);
42 PROCEDURE menu_loaddatClick(Sender: TObject);
43 PROCEDURE menu_txmpreplaceClick(Sender: TObject);
44 PROCEDURE menu_exitClick(Sender: TObject);
45 PROCEDURE menu_previewClick(Sender: TObject);
46 PROCEDURE FormClose(Sender: TObject; var Action: TCloseAction);
47 PROCEDURE FormResize(Sender: TObject);
48 PROCEDURE FormCreate(Sender: TObject);
49 PRIVATE
50 PUBLIC
51 END;
52
53VAR
54 Form1: TForm1;
55
56IMPLEMENTATION
57{$R *.dfm}
58
59PROCEDURE LoadDat;
60 VAR i:LongWord;
61 BEGIN
62 Form1.fopen.InitialDir:=AppSettings.DatPath;
63 IF Form1.fopen.Execute THEN BEGIN
64 Form1.Caption:='Oni Un/Packer '+version+' ('+ExtractFileName(Form1.fopen.FileName)+')';
65 AppSettings.DatPath:=ExtractFilepath(Form1.fopen.FileName);
66 IF LoadDatInfos(Form1.fopen.FileName) THEN BEGIN
67 Form1.statbar.Panels.Items[0].Text:='Current .dat: '+dat_FileName;
68 Form1.statbar.Panels.Items[1].Text:='Files: '+IntToStr(dat_header.Files);
69 Form1.statbar.Panels.Items[2].Text:='Extensions: '+IntToStr(dat_header.Extensions);
70 Form1.menu_tools.Enabled:=True;
71 Form1.menu_extract.Enabled:=True;
72
73 IF Form1.MDIChildCount>0 THEN
74 FOR i:=0 TO Form1.MDIChildCount-1 DO BEGIN
75 IF Pos('binedit',Form1.MDIChildren[i].Name)>0 THEN
76 TForm8(Form1.MDIChildren[i]).Recreatelist;
77 IF Pos('preview',Form1.MDIChildren[i].Name)>0 THEN
78 TForm5(Form1.MDIChildren[i]).Recreatelist;
79 IF Pos('txmpreplace',Form1.MDIChildren[i].Name)>0 THEN
80 TForm7(Form1.MDIChildren[i]).Recreatelist;
81 END;
82 END ELSE BEGIN
83 ShowMessage('Error while loading the file:'+CrLf+Form1.fopen.FileName+CrLf+'Perhaps not an Oni-.dat-file?');
84 END;
85 END;
86 END;
87
88PROCEDURE TForm1.FormCreate(Sender: TObject);
89 BEGIN
90 Form1.Caption:='Oni Un/Packer '+version;
91 Form1.FormResize(Form1);
92
93 IF FileExists(ExtractFilepath(Application.EXEname)+'\oniunpacker.ini') THEN BEGIN
94 AssignFile(AppSettingsFile,ExtractFilepath(Application.EXEname)+'\oniunpacker.ini');
95 Reset(AppSettingsFile);
96 Read(AppSettingsFile,AppSettings);
97 CloseFile(AppSettingsFile);
98 END ELSE BEGIN
99 AppSettings.DatPath:='D:\Spiele\Oni\GameDataFolder';
100 AppSettings.ExtractPath:='C:\Dokumente und Einstellungen\Administrator\Desktop';
101 END;
102 END;
103
104PROCEDURE TForm1.FormResize(Sender: TObject);
105 CONST
106 MinWidth:Integer=750;
107 MinHeight:Integer=500;
108 BEGIN
109 IF Form1.Width<MinWidth THEN Form1.Width:=MinWidth;
110 IF Form1.Height<MinHeight THEN Form1.Height:=MinHeight;
111 Form1.statbar.Panels.Items[0].Width:=Form1.Width-200;
112 END;
113
114PROCEDURE TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
115 BEGIN
116 AssignFile(AppSettingsFile,ExtractFilepath(Application.EXEname)+'\oniunpacker.ini');
117 IF FileExists(ExtractFilepath(Application.EXEname)+'\oniunpacker.ini') THEN
118 Reset(AppSettingsFile)
119 ELSE
120 Rewrite(AppSettingsFile);
121 Write(AppSettingsFile,AppSettings);
122 CloseFile(AppSettingsFile);
123 Action:=caFree;
124 END;
125
126
127{##### Main-Menu-Handlers #####}
128PROCEDURE TForm1.menu_loaddatClick(Sender: TObject);
129 BEGIN
130 LoadDat;
131 END;
132PROCEDURE TForm1.menu_exitClick(Sender: TObject);
133 BEGIN
134 Form1.Close;
135 END;
136
137{##### Tools-Menu-Handlers #####}
138PROCEDURE TForm1.menu_previewClick(Sender: TObject);
139 BEGIN
140 open_child('preview');
141 END;
142PROCEDURE TForm1.menu_txmpreplaceClick(Sender: TObject);
143 BEGIN
144 open_child('txmpreplace');
145 END;
146PROCEDURE TForm1.menu_bineditClick(Sender: TObject);
147 BEGIN
148 open_child('binedit');
149 END;
150
151{##### Window-Menu-Handlers #####}
152PROCEDURE TForm1.menu_windows_cascadeClick(Sender: TObject);
153 BEGIN
154 Form1.Cascade;
155 END;
156PROCEDURE TForm1.menu_windows_closeallClick(Sender: TObject);
157 VAR
158 i:Byte;
159 BEGIN
160 IF MDIChildCount>0 THEN BEGIN
161 FOR i:=0 TO MDIChildCount-1 DO BEGIN
162 MDIChildren[i].Close;
163 END;
164 END;
165 END;
166PROCEDURE TForm1.menu_window_entryClick(Sender: TObject);
167 VAR
168 i:Byte;
169 window_name:String;
170 BEGIN
171 window_name:=MidStr(TComponent(Sender).Name,Pos('window_',TComponent(Sender).Name)+7,Length(TComponent(Sender).Name)-Pos('window_',TComponent(Sender).Name)+7+1);
172 FOR i:=0 TO MDIChildCount-1 DO BEGIN
173 IF MDIChildren[i].Name=window_name THEN BEGIN
174 MDIChildren[i].BringToFront;
175 END;
176 END;
177 END;
178
179
180
181PROCEDURE TForm1.open_child(window_context:String);
182 VAR
183 binEdit:TForm8;
184 preview:TForm5;
185 txmpreplacer:TForm7;
186 menu_button:TMenuItem;
187 used:Array[1..9] OF Boolean;
188 i,j:Byte;
189 caption:String;
190 name:String;
191 BEGIN
192 FOR i:=1 TO 9 DO used[i]:=False;
193 IF MDIChildCount>0 THEN
194 FOR i:=0 TO MDIChildCount-1 DO
195 IF Pos(window_context,Form1.MDIChildren[i].Name)=1 THEN
196 used[StrToInt(RightStr(Form1.MDIChildren[i].Caption,1))]:=True;
197 FOR i:=1 TO 10 DO
198 IF i=10 THEN
199 Break
200 ELSE
201 IF NOT used[i] THEN Break;
202 IF i<10 THEN BEGIN
203 name:=window_context+IntToStr(i);
204 IF window_context='binedit' THEN BEGIN
205 caption:='Binary .dat-Editor '+IntToStr(i);
206 binEdit:=TForm8.Create(Application);
207 binEdit.Name:=name;
208 binEdit.Caption:=caption;
209 binEdit.Recreatelist;
210 END;
211 IF window_context='preview' THEN BEGIN
212 caption:='Preview-Window '+IntToStr(i);
213 preview:=TForm5.Create(Application);
214 preview.Name:=name;
215 preview.Caption:=caption;
216 preview.Recreatelist;
217 END;
218 IF window_context='txmpreplace' THEN BEGIN
219 caption:='TXMP Replacer '+IntToStr(i);
220 txmpreplacer:=TForm7.Create(Application);
221 txmpreplacer.Name:=name;
222 txmpreplacer.Caption:=caption;
223 txmpreplacer.Recreatelist;
224 END;
225
226 menu_button:=TMenuItem.Create(menu_windows);
227 menu_button.Caption:=caption;
228 menu_button.Name:='menu_window_'+name;
229 menu_button.OnClick:=Form1.menu_window_entryClick;
230 FOR j:=0 TO menu_windows.Count DO BEGIN
231 IF j<menu_windows.Count THEN BEGIN
232 IF Pos(window_context,menu_windows.Items[j].Name)>0 THEN BEGIN
233 IF StrToInt(RightStr(menu_windows.Items[j].Name,1))>i THEN BEGIN
234 menu_windows.Insert(j,menu_button);
235 Break;
236 END;
237 END;
238 END ELSE BEGIN
239 menu_windows.Add(menu_button);
240 END;
241 END;
242 IF MDIChildCount=9 THEN menu_tools.Enabled:=False;
243 END;
244 END;
245
246
247PROCEDURE TForm1.menu_windows_tileClick(Sender: TObject);
248 BEGIN
249 Form1.TileMode:=tbHorizontal;
250 Form1.Tile;
251 END;
252
253PROCEDURE TForm1.menu_windows_nextClick(Sender: TObject);
254 VAR i:Byte;
255 first_window:Byte;
256 current_focus:String;
257 BEGIN
258 IF MDIChildCount>1 THEN BEGIN
259 FOR i:=0 TO menu_windows.Count-1 DO BEGIN
260 IF Pos('menu_window_',menu_windows.Items[i].Name)=1 THEN BEGIN
261 first_window:=i;
262 Break;
263 END;
264 END;
265 current_focus:=ActiveMDIChild.Name;
266 FOR i:=first_window TO menu_windows.Count-1 DO
267 IF Pos(current_focus,menu_windows.Items[i].Name)>0 THEN
268 Break;
269 IF i=menu_windows.Count-1 THEN
270 menu_windows.Items[first_window].Click
271 ELSE
272 menu_windows.Items[i+1].Click;
273 END;
274 END;
275
276PROCEDURE TForm1.menu_windows_previousClick(Sender: TObject);
277 VAR i:Byte;
278 first_window:Byte;
279 current_focus:String;
280 BEGIN
281 IF MDIChildCount>1 THEN BEGIN
282 FOR i:=0 TO menu_windows.Count-1 DO BEGIN
283 IF Pos('menu_window_',menu_windows.Items[i].Name)=1 THEN BEGIN
284 first_window:=i;
285 Break;
286 END;
287 END;
288 current_focus:=ActiveMDIChild.Name;
289 FOR i:=first_window TO menu_windows.Count-1 DO
290 IF Pos(current_focus,menu_windows.Items[i].Name)>0 THEN
291 Break;
292 IF i=first_window THEN
293 menu_windows.Items[menu_windows.Count-1].Click
294 ELSE
295 menu_windows.Items[i-1].Click;
296 END;
297 END;
298
299END.
Note: See TracBrowser for help on using the repository browser.