--- oup/rewrite/Main.pas 2007/01/22 23:05:45 97 +++ oup/current/Main.pas 2007/06/04 22:07:29 209 @@ -6,12 +6,8 @@ uses MPHexEditor, ToolWin, ImgList, Tabs, MDITab, TB2Item, TB2Dock, TB2Toolbar, TB2MDI, OneInst, Data, TypeDefs, ConnectionManager, -// Functions, Exporters, DataStructures, - Functions, - Settings, {Helper_LevelDB, } - Template, - Preview; -// BinEdit, Extractor, RawEdit, TxmpReplace; + Functions, Settings, Template, + RawEdit, BinEdit, Extractor, Preview, TxmpReplace; type TForm_Main = class(TForm) @@ -138,6 +134,9 @@ var implementation +uses + LevelDB, MetaEditor; + {$R *.dfm} @@ -161,6 +160,7 @@ begin if RepMsg = SM_OK then begin UpdateStatBar; + UpdateConLists; end; end; @@ -169,6 +169,7 @@ var i: Integer; toolform: TForm_ToolTemplate; begin + Result := True; if MDITab.MDIChildCount > 0 then begin for i := 0 to MDITab.MDIChildCount - 1 do @@ -179,7 +180,10 @@ begin if toolform.ConnectionID = ConManager.ConnectionByIndex[index].ConnectionID then begin if not toolform.Closeable then - ShowMessage('Can not close toolwindow: ' + toolform.Caption); + begin + ShowMessage('Can not close toolwindow: ' + toolform.Caption); + Result := False; + end; end; end; end; @@ -234,8 +238,6 @@ end; procedure TForm_Main.FormCreate(Sender: TObject); -var - RepMsg: TStatusMessages; begin Self.Caption := 'Oni Un/Packer ' + version; Self.FormResize(Self); @@ -252,9 +254,12 @@ begin end else begin + ShowMessage('Warning!' + #13#10 + + 'It seems like this is the first time you OUP.' + #13#10 + + 'I do not take any responsibility for messed up data files' + #13+#10 + + 'Do not forget to make backup copies of your *.dat/*.raw/*.sep files!'); AppSettings.DatPath := ExtractFilepath(Application.EXEname); AppSettings.ExtractPath := ExtractFilepath(Application.EXEname) + '\extract'; - AppSettings.FilenumbersAsHex := False; AppSettings.CharSet := DEFAULT_CHARSET; AppSettings.HideUnusedData := False; end; @@ -409,6 +414,7 @@ begin tb_rawedit.Enabled := active; tb_txmpreplacer.Enabled := active; tb_extractor.Enabled := active; + tb_meta.Enabled := active; // tb_compare.Enabled := active; // tb_structure.Enabled := active; end; @@ -441,7 +447,6 @@ var position: TTBDockPosition; mode: TTBItemDisplayMode; i: Integer; - isEnabled: Boolean; begin toolbar := TTBToolbar(Sender); if toolbar.Floating then @@ -496,7 +501,7 @@ end; procedure TForm_Main.LoadFile(typedb: Boolean); var - ext: String; + i: Integer; begin opend.InitialDir := AppSettings.DatPath; opend.Filter := 'Compatible level files|*.dat;*.oldb|Oni level (*.dat)|*.dat|OUP level database (*.oldb)|*.oldb|Any (*.*)|*'; @@ -506,15 +511,9 @@ begin opend.FilterIndex := 2; if opend.Execute then begin - ext := ExtractFileExt(opend.FileName); - if ext = '.dat' then - begin - CreateConnection(opend.FileName); - end else if ext = '.oldb' then - begin - CreateConnection(opend.FileName); - end else - ShowMessage('Incompatible file'); + if opend.Files.Count > 0 then + for i := 0 to opend.Files.Count - 1 do + CreateConnection(opend.Files.Strings[i]); AppSettings.DatPath := ExtractFilepath(opend.FileName); end; UpdateStatBar; @@ -553,29 +552,27 @@ end; {####################################} procedure TForm_Main.menu_createdbClick(Sender: TObject); begin - ShowMessage('Not yet usable'); -{ +// ShowMessage('Not yet usable'); + opend.Filter := 'Oni-Dat-Files|*.dat'; saved.Filter := 'OUP-Level-DB (*.oldb)|*.oldb'; saved.DefaultExt := 'oldb'; if opend.Execute then if saved.Execute then Form_LevelDB.CreateDatabase(opend.FileName, saved.FileName); -} end; procedure TForm_Main.menu_createlvlClick(Sender: TObject); begin - ShowMessage('Not yet usable'); -{ +// ShowMessage('Not yet usable'); + opend.Filter := 'OUP-Level-DB (*.oldb)|*.oldb'; saved.Filter := 'Oni-Dat-Files|*.dat'; saved.DefaultExt := 'dat'; if opend.Execute then if saved.Execute then Form_LevelDB.CreateLevel(opend.FileName, saved.FileName); -} end; @@ -608,8 +605,33 @@ begin end; procedure TForm_Main.menu_metaClick(Sender: TObject); +var + toolform: TForm_Meta; + i: Integer; + tag: Integer; + iconindex: Integer; begin - ShowMessage('TBD'); + tag := 1; + if MDIChildCount > 0 then + for i := 0 to MDIChildCount - 1 do + if MDIChildren[i].Tag >= tag then + tag := MDIChildren[i].Tag + 1; + + iconindex := -1; + + toolform := nil; + + toolform := TForm_Meta.Create(Self); + toolform.Caption := 'MetaEditor' + ' ' + IntToStr(tag) + ' '; + iconindex := 11; + + if Assigned(toolform) then + begin + toolform.Name := 'meta' + IntToStr(tag); + toolform.Tag := tag; + MDITab.AddTab(TForm(toolform), iconindex); + toolform.Caption := AnsiReplaceStr(toolform.Caption, ' ', ''); + end; end; procedure TForm_Main.menu_filecompareClick(Sender: TObject); @@ -680,7 +702,6 @@ end; procedure TForm_Main.menu_conns_itemClick(Sender: TObject); var name: String; - i: Integer; index: Integer; RepMsg: TStatusMessages; begin @@ -692,6 +713,8 @@ begin begin CheckConnectionCloseable(index); ConManager.CloseConnectionByIndex(index, RepMsg); + ShowOpenMsg(RepMsg); + UpdateConLists; end; UpdateStatBar; end; @@ -730,11 +753,26 @@ end; function TForm_Main.open_child(window_context: String; connection, fileid: Integer): TForm_ToolTemplate; +type + TTemplate = class of TForm_ToolTemplate; + TTool = record + name: String; + icon: Integer; + caption: String; + classt: TTemplate; + end; +const + Tools: array[0..4] of TTool = ( + (name: 'binedit'; icon: 5; caption: 'Binary .dat-Editor'; classt: TForm_BinEdit), + (name: 'extractor'; icon: 8; caption: 'Extractor'; classt: TForm_Extractor), + (name: 'preview'; icon: 4; caption: 'Preview-Window'; classt: TForm_Preview), + (name: 'rawedit'; icon: 6; caption: 'Binary .raw-Editor'; classt: TForm_RawEdit), + (name: 'txmpreplace'; icon: 7; caption: 'TXMP Replacer'; classt: TForm_TxmpReplace) + ); var toolform: TForm_ToolTemplate; i: Integer; tag: Integer; - caption_end: String; iconindex: Integer; begin Result := nil; @@ -746,37 +784,19 @@ begin tag := MDIChildren[i].Tag + 1; iconindex := -1; - caption_end := IntToStr(tag) + ' '; - if window_context = 'binedit' then - begin -// toolform := TForm_BinEdit.Create(Self); - toolform.Caption := 'Binary .dat-Editor ' + caption_end; - iconindex := 5; - end; - if window_context = 'extractor' then - begin -// toolform := TForm_Extractor.Create(Self); - toolform.Caption := 'Extractor ' + caption_end; - iconindex := 8; - end; - if window_context = 'preview' then - begin - toolform := TForm_Preview.Create(Self); - toolform.Caption := 'Preview-Window ' + caption_end; - iconindex := 4; - end; - if window_context = 'rawedit' then - begin -// toolform := TForm_RawEdit.Create(Self); - toolform.Caption := 'Binary .raw-Editor ' + caption_end; - iconindex := 6; - end; - if window_context = 'txmpreplace' then - begin -// toolform := TForm_TxmpReplace.Create(Application); - toolform.Caption := 'TXMP Replacer ' + caption_end; - iconindex := 7; + toolform := nil; + + for i := 0 to High(Tools) do + if Tools[i].name = window_context then + Break; + if i < Length(Tools) then + begin + toolform := TTemplate(Tools[i].classt).Create(Self); + toolform.Caption := Tools[i].caption + ' ' + IntToStr(tag) + ' '; + iconindex := Tools[i].icon; + end else begin + ShowMessage('WindowContext not found!'); end; if Assigned(toolform) then