--- oup/current/Main.pas 2007/02/25 17:20:22 113 +++ oup/current/Main.pas 2007/06/18 14:49:24 224 @@ -6,11 +6,9 @@ uses MPHexEditor, ToolWin, ImgList, Tabs, MDITab, TB2Item, TB2Dock, TB2Toolbar, TB2MDI, OneInst, Data, TypeDefs, ConnectionManager, -// Functions, Exporters, DataStructures, - Functions, - Settings, {Helper_LevelDB, } - Template, - RawEdit, BinEdit, Extractor, Preview, TxmpReplace; + Functions, Settings, + RawEdit, BinEdit, Extractor, Preview, TxmpReplace, + _BaseTemplate, _TemplateFile, _TemplateFileList; type TForm_Main = class(TForm) @@ -110,7 +108,6 @@ type procedure menu_txmpreplaceClick(Sender: TObject); procedure menu_previewClick(Sender: TObject); procedure menu_metaClick(Sender: TObject); - function open_child(window_context: String; connection, fileid: Integer): TForm_ToolTemplate; procedure menu_windows_cascadeClick(Sender: TObject); procedure menu_windows_tilevertClick(Sender: TObject); @@ -129,6 +126,9 @@ type procedure WMCopyData(var Msg: TWMCopyData); message WM_COPYDATA; private public + function open_child(window_context: String; Connection, FileID: Integer): TForm_BaseTemplate; overload; + function open_child(window_context: String; Connection: Integer): TForm_BaseTemplate; overload; + function open_child(window_context: String): TForm_BaseTemplate; overload; procedure DefaultHandler(var Message); override; end; @@ -137,6 +137,9 @@ var implementation +uses + LevelDB, MetaEditor; + {$R *.dfm} @@ -167,16 +170,16 @@ end; function TForm_Main.CheckConnectionCloseable(index: Integer): Boolean; var i: Integer; - toolform: TForm_ToolTemplate; + toolform: TForm_BaseTemplate; begin Result := True; if MDITab.MDIChildCount > 0 then begin for i := 0 to MDITab.MDIChildCount - 1 do begin - if MDITab.MDIChildren[i] is TForm_ToolTemplate then + if MDITab.MDIChildren[i] is TForm_BaseTemplate then begin - toolform := TForm_ToolTemplate(MDITab.MDIChildren[i]); + toolform := TForm_BaseTemplate(MDITab.MDIChildren[i]); if toolform.ConnectionID = ConManager.ConnectionByIndex[index].ConnectionID then begin if not toolform.Closeable then @@ -254,6 +257,10 @@ 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.CharSet := DEFAULT_CHARSET; @@ -318,7 +325,7 @@ var pt: TPoint; tabIndex: Integer; hint: String; - tool: TForm_ToolTemplate; + tool: TForm_BaseTemplate; begin pt.X := X; pt.Y := Y; @@ -327,21 +334,24 @@ begin if tabIndex >= 0 then begin - if MDITab.MDIChildren[tabIndex] is TForm_ToolTemplate then + if MDITab.MDIChildren[tabIndex] is TForm_BaseTemplate then begin - tool := TForm_ToolTemplate(MDITab.MDIChildren[tabIndex]); + tool := TForm_BaseTemplate(MDITab.MDIChildren[tabIndex]); if tool.ConnectionID > -1 then hint := 'Connection: ' + - ExtractFileName(ConManager.Connection[tool.ConnectionID].FileName) + #13+#10 - else - hint := 'Connection: none' + #13+#10; - if tool.SelectedFile.ID > -1 then - hint := hint + 'Selected File: ' + - FormatNumber(tool.SelectedFile.ID, 5, '0') + '-' + - tool.SelectedFile.Name + '.' + - tool.SelectedFile.Extension + ExtractFileName(ConManager.Connection[tool.ConnectionID].FileName) else - hint := hint + 'Selected File: none'; + hint := 'Connection: none'; + if tool is TForm_TemplateFile then + begin + if TForm_TemplateFile(tool).SelectedFile.ID > -1 then + hint := hint + #13+#10 + 'Selected File: ' + + FormatNumber(TForm_TemplateFile(tool).SelectedFile.ID, 5, '0') + '-' + + TForm_TemplateFile(tool).SelectedFile.Name + '.' + + TForm_TemplateFile(tool).SelectedFile.Extension + else + hint := hint + #13+#10 + 'Selected File: none'; + end; end else hint := 'Window: ' + MDITab.MDIChildren[tabIndex].Caption; @@ -410,6 +420,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; @@ -475,8 +486,8 @@ var begin if MDITab.MDIChildCount > 0 then for i := 0 to MDITab.MDIChildCount - 1 do - if MDITab.MDIChildren[i] is TForm_ToolTemplate then - TForm_ToolTemplate(MDITab.MDIChildren[i]).UpdateConList; + if MDITab.MDIChildren[i] is TForm_BaseTemplate then + TForm_BaseTemplate(MDITab.MDIChildren[i]).UpdateConList; menu_conns.Clear; if ConManager.Count > 0 then @@ -547,29 +558,23 @@ end; {####################################} procedure TForm_Main.menu_createdbClick(Sender: TObject); begin - 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'); -{ 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; @@ -578,37 +583,37 @@ end; {#################################} procedure TForm_Main.menu_previewClick(Sender: TObject); begin - open_child('preview', -1, -1); + open_child('preview'); end; procedure TForm_Main.menu_bineditClick(Sender: TObject); begin - open_child('binedit', -1, -1); + open_child('binedit'); end; procedure TForm_Main.menu_raweditClick(Sender: TObject); begin - open_child('rawedit', -1, -1); + open_child('rawedit'); end; procedure TForm_Main.menu_txmpreplaceClick(Sender: TObject); begin - open_child('txmpreplace', -1, -1); + open_child('txmpreplace'); end; procedure TForm_Main.menu_extractorClick(Sender: TObject); begin - open_child('extractor', -1, -1); + open_child('extractor'); end; procedure TForm_Main.menu_metaClick(Sender: TObject); begin - ShowMessage('TBD'); + open_child('meta'); end; procedure TForm_Main.menu_filecompareClick(Sender: TObject); begin - open_child('compare', -1, -1); + open_child('compare'); end; @@ -677,7 +682,6 @@ var index: Integer; RepMsg: TStatusMessages; begin -// name := TTBItem(Sender).Caption; index := TTBItem(Sender).Parent.IndexOf(TTBItem(Sender)); name := ExtractFileName(ConManager.ConnectionByIndex[index].FileName); if MessageBox(Handle, PChar('Do you really want to close data-connection to' +#13+#10+ @@ -724,12 +728,28 @@ end; -function TForm_Main.open_child(window_context: String; connection, fileid: Integer): TForm_ToolTemplate; +function TForm_Main.open_child(window_context: String; connection, fileid: Integer): TForm_BaseTemplate; +type + TTemplate = class of TForm_BaseTemplate; + TTool = record + name: String; + icon: Integer; + caption: String; + classt: TTemplate; + end; +const + Tools: array[0..5] 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), + (name: 'meta'; icon: 11; caption: 'MetaEditor'; classt: TForm_Meta) + ); var - toolform: TForm_ToolTemplate; + toolform: TForm_BaseTemplate; i: Integer; tag: Integer; - caption_end: String; iconindex: Integer; begin Result := nil; @@ -741,39 +761,19 @@ begin tag := MDIChildren[i].Tag + 1; iconindex := -1; - caption_end := IntToStr(tag) + ' '; toolform := nil; - 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(Self); - toolform.Caption := 'TXMP Replacer ' + caption_end; - iconindex := 7; + 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 @@ -782,14 +782,24 @@ begin toolform.Tag := tag; MDITab.AddTab(TForm(toolform), iconindex); toolform.Caption := AnsiReplaceStr(toolform.Caption, ' ', ''); - if connection > -1 then + if Connection > -1 then begin toolform.SelectConnection(connection); - if fileid > -1 then - toolform.SelectFileID(connection, fileid); + if (FileID > -1) and (toolform is TForm_TemplateFile) then + TForm_TemplateFile(toolform).SelectFileID(Connection, FileID); end; Result := toolform; end; end; +function TForm_Main.open_child(window_context: String; Connection: Integer): TForm_BaseTemplate; +begin + open_child(window_context, Connection, -1); +end; + +function TForm_Main.open_child(window_context: String): TForm_BaseTemplate; +begin + open_child(window_context, -1, -1); +end; + end.