--- oup/current/Tools/MetaEditor.pas 2007/06/12 17:35:56 214 +++ oup/current/Tools/MetaEditor.pas 2007/08/10 17:26:03 243 @@ -1,50 +1,78 @@ unit MetaEditor; + interface + uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, - Dialogs, VirtualTrees, _MetaManager, StdCtrls, ExtCtrls; + Dialogs, _BaseTemplate, ExtCtrls, VirtualTrees, StdCtrls, ComCtrls, Grids, + MPHexEditor, Wrapgrid, VTHeaderPopup, Menus, _TreeElement; type - TForm_Meta = class(TForm) + TForm_Meta = class(TForm_BaseTemplate) VST: TVirtualStringTree; - Panel1: TPanel; - Button1: TButton; - combo_connection: TComboBox; - Label3: TLabel; - Splitter1: TSplitter; - Panel2: TPanel; - procedure FormClose(Sender: TObject; var Action: TCloseAction); + splitter: TSplitter; + rightPages: TPageControl; + tab_hex: TTabSheet; + tab_meta: TTabSheet; + panel_hex_actions: TPanel; + hex: TMPHexEditor; + splitter_hex_1: TSplitter; + value_viewer: TWrapGrid; + splitter_hex_2: TSplitter; + structviewer: TVirtualStringTree; + value_viewer_context: TPopupMenu; + value_viewer_context_copy: TMenuItem; + value_viewer_context_copyasdec: TMenuItem; + value_viewer_context_copyasfloat: TMenuItem; + value_viewer_context_copyasbitset: TMenuItem; + value_viewer_context_copyasstring: TMenuItem; + value_viewer_context_copyashex: TMenuItem; + VTHPopup: TVTHeaderPopupMenu; + btn_export: TButton; + btn_import: TButton; + vst_popup: TPopupMenu; + vst_newRoot: TMenuItem; + vst_setRoot: TMenuItem; procedure FormCreate(Sender: TObject); - procedure VSTGetText(Sender: TBaseVirtualTree; Node: PVirtualNode; - Column: TColumnIndex; TextType: TVSTTextType; var CellText: WideString); - procedure Button1Click(Sender: TObject); procedure VSTInitChildren(Sender: TBaseVirtualTree; Node: PVirtualNode; var ChildCount: Cardinal); - procedure VSTPaintText(Sender: TBaseVirtualTree; - const TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex; - TextType: TVSTTextType); + procedure FormClose(Sender: TObject; var Action: TCloseAction); procedure VSTFocusChanged(Sender: TBaseVirtualTree; Node: PVirtualNode; Column: TColumnIndex); procedure VSTFocusChanging(Sender: TBaseVirtualTree; OldNode, NewNode: PVirtualNode; OldColumn, NewColumn: TColumnIndex; var Allowed: Boolean); + procedure VSTGetText(Sender: TBaseVirtualTree; Node: PVirtualNode; + Column: TColumnIndex; TextType: TVSTTextType; var CellText: WideString); + procedure VSTPaintText(Sender: TBaseVirtualTree; + const TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex; + TextType: TVSTTextType); + procedure VSTGetPopupMenu(Sender: TBaseVirtualTree; Node: PVirtualNode; + Column: TColumnIndex; const P: TPoint; var AskParent: Boolean; + var PopupMenu: TPopupMenu); + procedure vst_setRootClick(Sender: TObject); + procedure vst_newRootClick(Sender: TObject); + procedure VSTGetHint(Sender: TBaseVirtualTree; Node: PVirtualNode; + Column: TColumnIndex; var LineBreakStyle: TVTTooltipLineBreakStyle; + var HintText: WideString); private + root: TTreeElement; + procedure NewCon(ID: Integer); public + procedure SetRoot(TreeElem: TTreeElement); end; -var - Form_Meta: TForm_Meta; implementation -uses - Data, _DataTypes, _FileTypes, ConnectionManager, TypeDefs, StrUtils; {$R *.dfm} +uses _MetaManager, _MetaTypes, ConnectionManager, Data, _FileTypes, Main, + TypeDefs; type PNodeData = ^TNodeData; TNodeData = record - Field: TObject; + Field: TTreeElement; end; function AddVSTEntry(AVST: TCustomVirtualStringTree; ANode: PVirtualNode; @@ -59,109 +87,56 @@ begin end; - -procedure TForm_Meta.VSTInitChildren(Sender: TBaseVirtualTree; - Node: PVirtualNode; var ChildCount: Cardinal); -var - data: PNodeData; - newdata: TNodeData; - newnode: PVirtualNode; - i: Integer; - id: Integer; +procedure TForm_Meta.NewCon(ID: Integer); begin - data := VST.GetNodeData(node); - for i := 0 to Meta.FileById[TFile(data.Field).FileID].ChildCount - 1 do - begin - id := Meta.FileById[TFile(data.Field).FileID].LinkByIndex[i].DestID; - Meta.InitFile(id); - newdata.Field := Meta.FileById[id]; - newnode := AddVSTEntry(VST, Node, newdata); - if Meta.FileById[id].ChildCount > 0 then - VST.HasChildren[newnode] := True; - end; - ChildCount := Meta.FileById[TFile(data.Field).FileID].ChildCount; + if ID >= 0 then + SetRoot(ConManager.Connection[FConnectionID].MetaData.Root); +//SetRoot(ConManager.Connection[FConnectionID].MetaData.FileById[454]); end; -procedure TForm_Meta.Button1Click(Sender: TObject); +procedure TForm_Meta.SetRoot(TreeElem: TTreeElement); var - name: String; - conid: Integer; - - a,b,c: Int64; i: Integer; data: TNodeData; node: PVirtualNode; begin - if combo_connection.ItemIndex >= 0 then + if FConnectionID <> TreeElem.ConnectionID then + SelectConnection(TreeElem.ConnectionID); + root := TreeElem; + VST.Clear; + VST.BeginUpdate; + for i := 0 to root.ChildCount - 1 do begin - name := combo_connection.Items.Strings[combo_connection.ItemIndex]; - conid := StrToInt(MidStr(name, Pos('[', name) + 1, Pos(']', name) - Pos('[', name) - 1)); - - QueryPerformanceFrequency(c); - QueryPerformanceCounter(a); - if not Assigned(Meta) then - Meta := TMetaManager.Create(conid); - QueryPerformanceCounter(b); - ShowMessage('Loading Done - ' + FloatToStr((b-a)/c) + 's'); - - VST.Clear; - VST.BeginUpdate; - for i := 0 to Meta.FileCount - 1 do - begin - if Assigned(Meta.FileById[i]) then - begin - data.Field := Meta.FileById[i]; - node := AddVSTEntry(VST, nil, data); - if Meta.FileById[i].ChildCount > 0 then - VST.HasChildren[node] := True; - end; - end; - VST.EndUpdate; + data.Field := root.Child[i]; + node := AddVSTEntry(VST, nil, data); + if data.Field.ChildCount > 0 then + VST.HasChildren[node] := True; end; + VST.EndUpdate; end; -procedure TForm_Meta.FormClose(Sender: TObject; var Action: TCloseAction); -begin - Meta.Free; - Action := caFree; -end; - - -procedure TForm_Meta.FormCreate(Sender: TObject); +procedure TForm_Meta.VSTInitChildren(Sender: TBaseVirtualTree; + Node: PVirtualNode; var ChildCount: Cardinal); var + data: PNodeData; + newdata: TNodeData; + newnode: PVirtualNode; i: Integer; - - fn, datatype, boxstring: String; - level: Integer; begin - combo_connection.ItemIndex := -1; - combo_connection.Items.Clear; - if ConManager.Count > 0 then + data := Sender.GetNodeData(node); + + if data.Field.ChildCount > 0 then begin - for i := 0 to ConManager.Count - 1 do + for i := 0 to data.Field.ChildCount - 1 do begin - level := ConManager.ConnectionByIndex[i].LevelNumber; - fn := ExtractFileName(ConManager.ConnectionByIndex[i].FileName); - if ConManager.ConnectionByIndex[i].Backend = DB_ONI then - datatype := 'ONI-.dat: ' - else if ConManager.ConnectionByIndex[i].Backend = DB_ADB then - datatype := 'OUP-DB: ' - else - datatype := 'Unknown: '; - boxstring := datatype + fn + ' (Level: ' + IntToStr(level) + ') [' + IntToStr(ConManager.ConnectionByIndex[i].ConnectionID) + ']'; - combo_connection.Items.Add(boxstring); - end; - if combo_connection.ItemIndex = -1 then - begin - combo_connection.ItemIndex := 0; + newdata.Field := data.Field.Child[i]; + newnode := AddVSTEntry(TCustomVirtualStringTree(Sender), Node, newdata); + if newdata.Field.ChildCount > 0 then + Sender.HasChildren[newnode] := True; end; end; - - - VST.NodeDataSize := SizeOf(TNodeData); - VST.Font.Charset := AppSettings.CharSet; - VST.Clear; + ChildCount := Sender.ChildCount[Node]; end; @@ -170,19 +145,35 @@ procedure TForm_Meta.VSTFocusChanged(Sen Node: PVirtualNode; Column: TColumnIndex); var data: PNodeData; + ffile: TFile; +//******************************************************************* + fs: TFileStream; +//******************************************************************* begin data := Sender.GetNodeData(Node); + ffile := nil; if data.Field is TFile then + ffile := TFile(data.Field); + if data.Field is _MetaTypes.TDatLink then + if Assigned(_MetaTypes.TDatLink(data.Field).TargetFile) then + ffile := TFile(_MetaTypes.TDatLink(data.Field).TargetFile); + if Assigned(ffile) then begin - TFile(data.Field).InitEditor; - if Assigned(TFile(data.Field).Editor) then + if Assigned(ffile.Editor) then begin - panel2.InsertControl(TFile(data.Field).Editor); - TFile(data.Field).Opened := True; + ffile.Editor.Align := alClient; + tab_meta.InsertControl(ffile.Editor); + ffile.Opened := True; end; +//******************************************************************* +// fs := TFileStream.Create('C:\Spiele\Oni\GameDataFolder\tests\'+IntToStr(ffile.FileInfo.ID)+'_recreated.hex', fmCreate); +// ffile.ReCreateFile(fs); +// fs.Free; +//******************************************************************* end; end; + procedure TForm_Meta.VSTFocusChanging(Sender: TBaseVirtualTree; OldNode, NewNode: PVirtualNode; OldColumn, NewColumn: TColumnIndex; var Allowed: Boolean); @@ -193,7 +184,6 @@ begin data := Sender.GetNodeData(NewNode); if data.Field is TFile then begin - TFile(data.Field).InitEditor; if Assigned(TFile(data.Field).Editor) then Allowed := not TFile(data.Field).Opened else @@ -206,15 +196,16 @@ begin begin if TFile(data.Field).Opened then begin - if panel2.ControlCount > 0 then - for i := 0 to panel2.ControlCount - 1 do - panel2.RemoveControl(panel2.Controls[i]); + if tab_meta.ControlCount > 0 then + for i := 0 to tab_meta.ControlCount - 1 do + tab_meta.RemoveControl(tab_meta.Controls[i]); TFile(data.Field).Opened := False; end; end; end; end; + procedure TForm_Meta.VSTGetText(Sender: TBaseVirtualTree; Node: PVirtualNode; Column: TColumnIndex; TextType: TVSTTextType; var CellText: WideString); var @@ -225,29 +216,18 @@ begin if TextType = ttNormal then begin case Column of - 0: - begin - if Data.Field is TFile then - begin - CellText := TFile(Data.Field).FileName; - if CellText = '' then - CellText := 'Unnamed'; - end; - end; - 1: - begin - if Data.Field is TFile then - CellText := TFile(Data.Field).FileExt; - end; + 0: CellText := Data.Field.Caption; + 1: CellText := data.Field.VType; 2: begin - if Data.Field is TFile then - CellText := IntToStr(TFile(Data.Field).FileID); + if Data.Field is TDataField then + CellText := TDataField(Data.Field).ValueAsString; end; end; end; end; + procedure TForm_Meta.VSTPaintText(Sender: TBaseVirtualTree; const TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex; TextType: TVSTTextType); @@ -262,9 +242,9 @@ begin begin if Data.Field is TFile then begin - if Length(TFile(Data.Field).FileName) = 0 then + if Length(TFile(Data.Field).FileInfo.Name) = 0 then TargetCanvas.Font.Color := $C06060; - if TFile(Data.Field).FileSize = 0 then + if TFile(Data.Field).FileInfo.Size = 0 then TargetCanvas.Font.Color := $2020A0; end; end; @@ -272,88 +252,111 @@ begin end; end; -{ -procedure WriteStructureInfos; + +procedure TForm_Meta.VSTGetHint(Sender: TBaseVirtualTree; Node: PVirtualNode; + Column: TColumnIndex; var LineBreakStyle: TVTTooltipLineBreakStyle; + var HintText: WideString); var - i, j: Integer; - pdata: PNodeData; - Data: TNodeData; - node: PVirtualNode; + data: PNodeData; + CellText: WideString; + + i: Integer; + links: TStrings; + ifile: TFile; begin - VST.BeginUpdate; - if VST.RootNodeCount = 0 then + inherited; + if Assigned(Node) then begin - structs := LoadStructureDefinition(ConID, fileid); - if structs.Data then + VSTGetText(Sender, Node, Column, ttNormal, CellText); + if Length(CellText) > 0 then begin - if Length(structs.Global) > 0 then + data := Sender.GetNodeData(Node); + if data.Field is TDataField then begin - for i := 0 to High(structs.Global) do - begin - Data.Caption := structs.Global[i].Name; - Data.Offset := structs.Global[i].offset; - Data.DataType := structs.Global[i].datatype; - Data.Value := GetValue(structs.Global[i].datatype, structs.Global[i].offset); - Data.Description := structs.Global[i].description; - AddVSTEntry(VST, nil, Data); + case Column of + 0,1: HintText := TDataField(data.Field).Description; + 2: HintText := ''; end; end; - if Length(structs.Subs) > 0 then + if data.Field is TFile then begin - for i := 0 to High(structs.Subs) do - begin - with structs.Subs[i] do - begin - if Length(Entries) > 0 then - begin - if Pos('#', SubName) > 0 then - begin - Data.Offset := StrToInt('$'+MidStr(SubName, Pos('#', SubName) + 1, 8)); - Data.Value := '$' + - MidStr(SubName, PosEx('#', SubName, Pos('#', SubName) + 1) + 1, 8); - Data.Caption := MidStr(SubName, 1, Pos('#', SubName) - 1); - Data.Description := SubDesc; - end - else - begin - Data.Caption := SubName; - Data.Description := SubDesc; - Data.Offset := 0; - Data.Value := ''; - end; - Data.DataType := 0; - node := AddVSTEntry(VST, nil, Data); - Data.Description := ''; - for j := 0 to High(Entries) do - begin - Data.Caption := Entries[j].Name; - Data.Offset := Entries[j].offset; - Data.DataType := Entries[j].datatype; - Data.Value := GetValue(Entries[j].datatype, Entries[j].offset); - Data.Description := Entries[j].description; - AddVSTEntry(VST, node, Data); - end; - end; - end; + ifile := TFile(data.Field); + case Column of + 0: HintText := + 'FileID: ' + IntToStr(ifile.FileInfo.ID) + #13#10 + + 'Name: ' + ifile.FileInfo.Name + #13#10 + + 'Extension: ' + ifile.FileInfo.Extension + #13#10 + + '.dat-size: ' + IntToStr(ifile.FileInfo.Size) + #13#10; end; end; end; - if VST.RootNodeCount > 0 then - VST.FocusedNode := VST.GetFirst; end else + HintText := ''; +end; + +procedure TForm_Meta.VSTGetPopupMenu(Sender: TBaseVirtualTree; + Node: PVirtualNode; Column: TColumnIndex; const P: TPoint; + var AskParent: Boolean; var PopupMenu: TPopupMenu); +var + data: PNodeData; +begin + inherited; + AskParent := False; + if Assigned(Node) then begin - Node := VST.GetFirst; - while Assigned(Node) do + Sender.Selected[Node] := True; + Sender.FocusedNode := Node; + data := Sender.GetNodeData(Node); + if Column = 0 then begin - pdata := VST.GetNodeData(Node); - if pdata.DataType > 0 then - pdata.Value := GetValue(pdata.Datatype, pdata.Offset); - Node := VST.GetNext(Node); + if TTreeElement(data.Field).ChildCount > 0 then + PopupMenu := vst_popup + else + PopupMenu := nil; end; end; - VST.EndUpdate; end; -} + +procedure TForm_Meta.vst_newRootClick(Sender: TObject); +var + data: PNodeData; + form: TForm_BaseTemplate; +begin + inherited; + data := VST.GetNodeData(VST.FocusedNode); + form := nil; + form := Form_Main.open_child('meta'); + if form is TForm_Meta then + TForm_Meta(form).SetRoot(data.Field); +end; + +procedure TForm_Meta.vst_setRootClick(Sender: TObject); +var + data: PNodeData; +begin + inherited; + data := VST.GetNodeData(VST.FocusedNode); + SetRoot(data.Field); +end; + +procedure TForm_Meta.FormClose(Sender: TObject; var Action: TCloseAction); +begin +// Meta.Free; + inherited; +end; + +procedure TForm_Meta.FormCreate(Sender: TObject); +begin + inherited; + OnNewConnection := NewCon; + + VST.NodeDataSize := SizeOf(TNodeData); + VST.Font.Charset := AppSettings.CharSet; + VST.Clear; + + UpdateConList; +end; + end.