UNIT Unit1_main; INTERFACE USES Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, StrUtils, Clipbrd, ExtCtrls, ComCtrls, Menus, Grids, MPHexEditor, ToolWin, ImgList, Tabs, Unit2_functions, Unit3_data, Unit10_leveldb, Unit4_exporters, Unit5_preview, Unit7_txmpreplace, Unit8_binedit, Unit11_extractor, Unit13_rawedit; TYPE TForm1 = Class(TForm) tabs: TTabSet; saved: TSaveDialog; opend: TOpenDialog; statbar: TStatusBar; menu: TMainMenu; menu_main: TMenuItem; menu_loaddat: TMenuItem; menu_lvldb: TMenuItem; menu_exit: TMenuItem; menu_convert: TMenuItem; menu_createdb: TMenuItem; menu_createlvl: TMenuItem; menu_tools: TMenuItem; menu_preview: TMenuItem; menu_txmpreplace: TMenuItem; menu_binedit: TMenuItem; menu_extractor: TMenuItem; menu_windows: TMenuItem; menu_windows_cascade: TMenuItem; menu_windows_tile: TMenuItem; menu_windows_closeall: TMenuItem; menu_windows_next: TMenuItem; menu_windows_previous: TMenuItem; menu_sep1: TMenuItem; menu_sep2: TMenuItem; menu_sep3: TMenuItem; menu_levelstructedit: TMenuItem; menu_rawedit: TMenuItem; PROCEDURE menu_raweditClick(Sender: TObject); PROCEDURE menu_createlvlClick(Sender: TObject); PROCEDURE menu_extractorClick(Sender: TObject); PROCEDURE menu_lvldbClick(Sender: TObject); PROCEDURE menu_createdbClick(Sender: TObject); PROCEDURE SetActiveWindow(window_name:String); PROCEDURE tabsChange(Sender: TObject; NewTab: Integer; var AllowChange: Boolean); PROCEDURE close_window(window_name:String); PROCEDURE menu_windows_previousClick(Sender: TObject); PROCEDURE menu_windows_nextClick(Sender: TObject); PROCEDURE menu_windows_tileClick(Sender: TObject); FUNCTION open_child(window_context:String):Boolean; PROCEDURE menu_windows_closeallClick(Sender: TObject); PROCEDURE menu_windows_cascadeClick(Sender: TObject); PROCEDURE menu_window_entryClick(Sender: TObject); PROCEDURE menu_bineditClick(Sender: TObject); PROCEDURE menu_loaddatClick(Sender: TObject); PROCEDURE menu_txmpreplaceClick(Sender: TObject); PROCEDURE menu_exitClick(Sender: TObject); PROCEDURE menu_previewClick(Sender: TObject); PROCEDURE FormClose(Sender: TObject; var Action: TCloseAction); PROCEDURE FormResize(Sender: TObject); PROCEDURE FormCreate(Sender: TObject); PRIVATE PUBLIC END; VAR Form1: TForm1; IMPLEMENTATION {$R *.dfm} VAR tablist:Array OF String; PROCEDURE TForm1.FormCreate(Sender: TObject); BEGIN Form1.Caption:='Oni Un/Packer '+version; Form1.FormResize(Form1); IF FileExists(ExtractFilepath(Application.EXEname)+'\oniunpacker.ini') THEN BEGIN AssignFile(AppSettingsFile,ExtractFilepath(Application.EXEname)+'\oniunpacker.ini'); Reset(AppSettingsFile); Read(AppSettingsFile,AppSettings); CloseFile(AppSettingsFile); END ELSE BEGIN AppSettings.DatPath:='D:\Spiele\Oni\GameDataFolder'; AppSettings.ExtractPath:='C:\Dokumente und Einstellungen\Administrator\Desktop'; END; END; PROCEDURE TForm1.FormResize(Sender: TObject); CONST MinWidth:Integer=750; MinHeight:Integer=500; BEGIN IF Form1.Width0 THEN BEGIN FOR i:=0 TO MDIChildCount-1 DO BEGIN MDIChildren[i].Close; END; END; tabs.Tabs.Clear; END; PROCEDURE TForm1.menu_windows_nextClick(Sender: TObject); VAR i:Byte; first_window:Byte; current_focus:String; BEGIN IF MDIChildCount>1 THEN BEGIN FOR i:=0 TO menu_windows.Count-1 DO BEGIN IF Pos('menu_window_',menu_windows.Items[i].Name)=1 THEN BEGIN first_window:=i; Break; END; END; current_focus:=ActiveMDIChild.Name; FOR i:=first_window TO menu_windows.Count-1 DO IF Pos(current_focus,menu_windows.Items[i].Name)>0 THEN Break; IF i=menu_windows.Count-1 THEN menu_windows.Items[first_window].Click ELSE menu_windows.Items[i+1].Click; FOR i:=0 TO High(tablist) DO BEGIN IF tablist[i]=ActiveMDIChild.Name THEN BEGIN tabs.TabIndex:=i; END; END; END; END; PROCEDURE TForm1.menu_windows_previousClick(Sender: TObject); VAR i:Byte; first_window:Byte; current_focus:String; BEGIN IF MDIChildCount>1 THEN BEGIN FOR i:=0 TO menu_windows.Count-1 DO BEGIN IF Pos('menu_window_',menu_windows.Items[i].Name)=1 THEN BEGIN first_window:=i; Break; END; END; current_focus:=ActiveMDIChild.Name; FOR i:=first_window TO menu_windows.Count-1 DO IF Pos(current_focus,menu_windows.Items[i].Name)>0 THEN Break; IF i=first_window THEN menu_windows.Items[menu_windows.Count-1].Click ELSE menu_windows.Items[i-1].Click; FOR i:=0 TO High(tablist) DO BEGIN IF tablist[i]=ActiveMDIChild.Name THEN BEGIN tabs.TabIndex:=i; END; END; END; END; PROCEDURE TForm1.menu_window_entryClick(Sender: TObject); VAR i:Byte; window_name:String; BEGIN window_name:=MidStr(TComponent(Sender).Name,Pos('window_',TComponent(Sender).Name)+7,Length(TComponent(Sender).Name)-Pos('window_',TComponent(Sender).Name)+7+1); FOR i:=0 TO MDIChildCount-1 DO BEGIN IF MDIChildren[i].Name=window_name THEN BEGIN MDIChildren[i].BringToFront; END; END; FOR i:=0 TO High(tablist) DO BEGIN IF tablist[i]=ActiveMDIChild.Name THEN BEGIN tabs.TabIndex:=i; END; END; END; FUNCTION TForm1.open_child(window_context:String):Boolean; VAR rawEdit:TForm13; binEdit:TForm8; preview:TForm5; txmpreplacer:TForm7; extractor:TForm11; menu_button:TMenuItem; used:Array[1..9] OF Boolean; i:Byte; caption:String; name:String; BEGIN Result:=True; FOR i:=1 TO 9 DO used[i]:=False; IF MDIChildCount>0 THEN FOR i:=0 TO MDIChildCount-1 DO IF Pos(window_context,Form1.MDIChildren[i].Name)=1 THEN used[StrToInt(RightStr(Form1.MDIChildren[i].Caption,1))]:=True; FOR i:=1 TO 10 DO IF i=10 THEN Break ELSE IF NOT used[i] THEN Break; IF i<10 THEN BEGIN name:=window_context+IntToStr(i); IF window_context='binedit' THEN caption:='Binary .dat-Editor '+IntToStr(i); IF window_context='rawedit' THEN caption:='Binary .raw-Editor '+IntToStr(i); IF window_context='preview' THEN caption:='Preview-Window '+IntToStr(i); IF window_context='txmpreplace' THEN caption:='TXMP Replacer '+IntToStr(i); IF window_context='extractor' THEN caption:='Extractor '+IntToStr(i); menu_button:=TMenuItem.Create(menu_windows); menu_button.Caption:=caption; menu_button.Name:='menu_window_'+name; menu_button.OnClick:=Form1.menu_window_entryClick; menu_windows.Add(menu_button); SetLength(tablist,Length(tablist)+1); tablist[High(tablist)]:=name; tabs.Tabs.Add(caption); IF window_context='binedit' THEN BEGIN binEdit:=TForm8.Create(Application); binEdit.Name:=name; binEdit.Caption:=caption; binEdit.Recreatelist; END; IF window_context='rawedit' THEN BEGIN rawEdit:=TForm13.Create(Application); rawEdit.Name:=name; rawEdit.Caption:=caption; rawEdit.Recreatelist; END; IF window_context='preview' THEN BEGIN preview:=TForm5.Create(Application); preview.Name:=name; preview.Caption:=caption; preview.Recreatelist; END; IF window_context='txmpreplace' THEN BEGIN txmpreplacer:=TForm7.Create(Application); txmpreplacer.Name:=name; txmpreplacer.Caption:=caption; txmpreplacer.Recreatelist; END; IF window_context='extractor' THEN BEGIN extractor:=TForm11.Create(Application); extractor.Name:=name; extractor.Caption:=caption; extractor.Recreatelist; END; tabs.TabIndex:=High(tablist); IF MDIChildCount=9 THEN menu_tools.Enabled:=False; END ELSE BEGIN Result:=False; END; END; PROCEDURE TForm1.close_window(window_name:String); VAR i,j:Byte; BEGIN FOR i:=0 TO menu_windows.Count-1 DO BEGIN IF menu_windows.Items[i].Name='menu_window_'+window_name THEN BEGIN menu_windows.Items[i].Free; Break; END; END; FOR i:=0 TO High(tablist) DO BEGIN IF tablist[i]=window_name THEN BEGIN tabs.Tabs.Delete(i); IF High(tablist)>0 THEN FOR j:=i TO High(tablist)-1 DO tablist[j]:=tablist[j+1]; SetLength(tablist,Length(tablist)-1); Break; END; END; menu_tools.Enabled:=True; END; PROCEDURE TForm1.tabsChange(Sender: TObject; NewTab: Integer; var AllowChange: Boolean); VAR i:Byte; BEGIN FOR i:=0 TO MDIChildCount-1 DO BEGIN IF MDIChildren[i].Name=tablist[NewTab] THEN MDIChildren[i].BringToFront; END; END; PROCEDURE TForm1.SetActiveWindow(window_name:String); VAR i:Byte; BEGIN IF Length(tablist)>0 THEN FOR i:=0 TO High(tablist) DO IF tablist[i]=window_name THEN tabs.TabIndex:=i; END; END.