ViewVC Help
View File | Revision Log | View Changeset | Root Listing
root/Oni2/oup/current/Tools/MetaEditor.pas
(Generate patch)

Comparing oup/current/Tools/MetaEditor.pas (file contents):
Revision 209 by alloc, Mon Jun 4 22:07:29 2007 UTC vs.
Revision 237 by alloc, Sat Jul 14 14:18:23 2007 UTC

# Line 1 | Line 1
1   unit MetaEditor;
2 +
3   interface
4 +
5   uses
6    Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
7 <  Dialogs, VirtualTrees, _FileManager;
7 >  Dialogs, _BaseTemplate, ExtCtrls, VirtualTrees, StdCtrls, ComCtrls, Grids,
8 >  MPHexEditor, Wrapgrid, VTHeaderPopup, Menus, _TreeElement;
9  
10   type
11 <  TForm_Meta = class(TForm)
11 >  TForm_Meta = class(TForm_BaseTemplate)
12      VST: TVirtualStringTree;
13 <    procedure FormClose(Sender: TObject; var Action: TCloseAction);
13 >    splitter: TSplitter;
14 >    rightPages: TPageControl;
15 >    tab_hex: TTabSheet;
16 >    tab_meta: TTabSheet;
17 >    panel_hex_actions: TPanel;
18 >    hex: TMPHexEditor;
19 >    splitter_hex_1: TSplitter;
20 >    value_viewer: TWrapGrid;
21 >    splitter_hex_2: TSplitter;
22 >    structviewer: TVirtualStringTree;
23 >    value_viewer_context: TPopupMenu;
24 >    value_viewer_context_copy: TMenuItem;
25 >    value_viewer_context_copyasdec: TMenuItem;
26 >    value_viewer_context_copyasfloat: TMenuItem;
27 >    value_viewer_context_copyasbitset: TMenuItem;
28 >    value_viewer_context_copyasstring: TMenuItem;
29 >    value_viewer_context_copyashex: TMenuItem;
30 >    VTHPopup: TVTHeaderPopupMenu;
31 >    btn_export: TButton;
32 >    btn_import: TButton;
33      procedure FormCreate(Sender: TObject);
34 +    procedure VSTInitChildren(Sender: TBaseVirtualTree; Node: PVirtualNode;
35 +      var ChildCount: Cardinal);
36 +    procedure FormClose(Sender: TObject; var Action: TCloseAction);
37 +    procedure VSTFocusChanged(Sender: TBaseVirtualTree; Node: PVirtualNode;
38 +      Column: TColumnIndex);
39 +    procedure VSTFocusChanging(Sender: TBaseVirtualTree; OldNode,
40 +      NewNode: PVirtualNode; OldColumn, NewColumn: TColumnIndex;
41 +      var Allowed: Boolean);
42      procedure VSTGetText(Sender: TBaseVirtualTree; Node: PVirtualNode;
43        Column: TColumnIndex; TextType: TVSTTextType; var CellText: WideString);
44 +    procedure VSTPaintText(Sender: TBaseVirtualTree;
45 +      const TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex;
46 +      TextType: TVSTTextType);
47    private
48 +    root: TTreeElement;
49 +    procedure NewCon(ID: Integer);
50    public
16    FileManager: TFileManager;
51    end;
52  
19 var
20  Form_Meta: TForm_Meta;
53  
54   implementation
23 uses
24  Data, _DataTypes, _FileTypes;
55   {$R *.dfm}
56 + uses _MetaManager, _MetaTypes, ConnectionManager, Data, _FileTypes;
57  
58   type
59    PNodeData = ^TNodeData;
60  
61    TNodeData = record
62 <    Field: TObject;
62 >    Field: TTreeElement;
63    end;
64  
65   function AddVSTEntry(AVST: TCustomVirtualStringTree; ANode: PVirtualNode;
# Line 43 | Line 74 | begin
74   end;
75  
76  
77 <
78 < procedure TForm_Meta.FormClose(Sender: TObject; var Action: TCloseAction);
77 > procedure TForm_Meta.NewCon(ID: Integer);
78 > var
79 >  i: Integer;
80 >  data: TNodeData;
81 >  node: PVirtualNode;
82 >  Meta: TMetaManager;
83 >  root: TTreeElement;
84   begin
85 <  FileManager.Free;
86 <  Action := caFree;
85 >  if ID >= 0 then
86 >  begin
87 >    //VST
88 >    VST.Clear;
89 >    VST.BeginUpdate;
90 > //    root := ConManager.Connection[FConnectionID].MetaData.Root;
91 >    root := ConManager.Connection[FConnectionID].MetaData.FileById[454];
92 >    for i := 0 to root.ChildCount - 1 do
93 >    begin
94 >      data.Field := root.Child[i];
95 >      node := AddVSTEntry(VST, nil, data);
96 >      VST.HasChildren[node] := True;
97 >    end;
98 >    VST.EndUpdate;
99 >  end;
100   end;
101  
102  
103 < procedure TForm_Meta.FormCreate(Sender: TObject);
103 > procedure TForm_Meta.VSTInitChildren(Sender: TBaseVirtualTree;
104 >  Node: PVirtualNode; var ChildCount: Cardinal);
105   var
106 <  a,b,c: Int64;
106 >  data: PNodeData;
107 >  newdata: TNodeData;
108 >  newnode: PVirtualNode;
109    i: Integer;
110 <  data: TNodeData;
110 >  Meta: TMetaManager;
111   begin
112 <  VST.NodeDataSize := SizeOf(TNodeData);
113 <  VST.Font.Charset := AppSettings.CharSet;
114 <  VST.Clear;
112 >  data := Sender.GetNodeData(node);
113 >  Meta := ConManager.Connection[ConnectionID].MetaData;
114 >
115 >  if data.Field.ChildCount > 0 then
116 >  begin
117 >    for i := 0 to data.Field.ChildCount - 1 do
118 >    begin
119 >      newdata.Field := data.Field.Child[i];
120 >      newnode := AddVSTEntry(TCustomVirtualStringTree(Sender), Node, newdata);
121 >      if newdata.Field.ChildCount > 0 then
122 >        Sender.HasChildren[newnode] := True;
123 >    end;
124 >  end;
125 >  ChildCount := Sender.ChildCount[Node];
126 > end;
127  
64  QueryPerformanceFrequency(c);
65  QueryPerformanceCounter(a);
66  FileManager := TFileManager.Create(1);
67  QueryPerformanceCounter(b);
68  ShowMessage('Loading Done - ' + FloatToStr((b-a)/c) + 's');
128  
129 <  for i := 0 to FileManager.FileCount - 1 do
129 > procedure TForm_Meta.VSTFocusChanged(Sender: TBaseVirtualTree;
130 >  Node: PVirtualNode; Column: TColumnIndex);
131 > var
132 >  data: PNodeData;
133 > begin
134 >  data := Sender.GetNodeData(Node);
135 >  if data.Field is TFile then
136    begin
137 <    data.Field := FileManager.FileById[i];
138 <    AddVSTEntry(VST, nil, data);
137 >    TFile(data.Field).InitEditor;
138 >    if Assigned(TFile(data.Field).Editor) then
139 >    begin
140 >      TFile(data.Field).Editor.Align := alClient;
141 >      tab_meta.InsertControl(TFile(data.Field).Editor);
142 >      TFile(data.Field).Opened := True;
143 >    end;
144    end;
145   end;
146  
147  
148 + procedure TForm_Meta.VSTFocusChanging(Sender: TBaseVirtualTree; OldNode,
149 +  NewNode: PVirtualNode; OldColumn, NewColumn: TColumnIndex;
150 +  var Allowed: Boolean);
151 + var
152 +  data: PNodeData;
153 +  i: Integer;
154 + begin
155 +  data := Sender.GetNodeData(NewNode);
156 +  if data.Field is TFile then
157 +  begin
158 +    TFile(data.Field).InitEditor;
159 +    if Assigned(TFile(data.Field).Editor) then
160 +      Allowed := not TFile(data.Field).Opened
161 +    else
162 +      Allowed := True;
163 +  end;
164 +  if Allowed and Assigned(OldNode) then
165 +  begin
166 +    data := Sender.GetNodeData(OldNode);
167 +    if data.Field is TFile then
168 +    begin
169 +      if TFile(data.Field).Opened then
170 +      begin
171 +        if tab_meta.ControlCount > 0 then
172 +          for i := 0 to tab_meta.ControlCount - 1 do
173 +            tab_meta.RemoveControl(tab_meta.Controls[i]);
174 +        TFile(data.Field).Opened := False;
175 +      end;
176 +    end;
177 +  end;
178 + end;
179 +
180  
181   procedure TForm_Meta.VSTGetText(Sender: TBaseVirtualTree; Node: PVirtualNode;
182    Column: TColumnIndex; TextType: TVSTTextType; var CellText: WideString);
# Line 86 | Line 188 | begin
188    if TextType = ttNormal then
189    begin
190      case Column of
191 <      0: begin
90 <        if Data.Field is TFile then
191 >      0:
192          begin
193 <          CellText := TFile(Data.Field).FileName;
193 >          CellText := Data.Field.GetCaption;
194          end;
94      end;
95 {      0:
96        CellText := Data.Caption;
195        1:
196 <        if Data.DataType > 0 then
197 <          CellText := '0x' + IntToHex(Data.Offset, 8)
198 <        else if Data.Offset > 0 then
199 <          CellText := '0x' + IntToHex(Data.Offset, 8);
196 >        begin
197 >          if Data.Field is TFile then
198 >            CellText := TFile(Data.Field).FileInfo.Extension;
199 >        end;
200        2:
201 <        if Data.DataType > 0 then
202 <          CellText := GetDataType(Data.DataType);
201 >        begin
202 >          if Data.Field is TFile then
203 >            CellText := IntToStr(TFile(Data.Field).FileInfo.ID);
204 >        end;
205        3:
206 <        if Data.DataType > 0 then
207 <          CellText := Data.Value //GetValue(data.DataType, data.Offset)
208 <        else if Length(Data.Value) > 0 then
209 <          CellText := IntToStr(StrToInt(Data.Value)) + ' Bytes';
210 <      4:
111 <        CellText := Data.Description;
112 < }    end;
206 >        begin
207 >          if Data.Field is TDataField then
208 >            CellText := TDataField(Data.Field).ValueAsString;
209 >        end;
210 >    end;
211    end;
212   end;
213  
116 {
214  
215 < procedure WriteStructureInfos;
215 > procedure TForm_Meta.VSTPaintText(Sender: TBaseVirtualTree;
216 >  const TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex;
217 >  TextType: TVSTTextType);
218   var
219 <  i, j:    Integer;
121 <  pdata:   PNodeData;
122 <  Data:    TNodeData;
123 <  node:    PVirtualNode;
219 >  Data: PNodeData;
220   begin
221 <  VST.BeginUpdate;
222 <  if VST.RootNodeCount = 0 then
221 >  Data     := Sender.GetNodeData(Node);
222 >  if TextType = ttNormal then
223    begin
224 <    structs := LoadStructureDefinition(ConID, fileid);
225 <    if structs.Data then
130 <    begin
131 <      if Length(structs.Global) > 0 then
132 <      begin
133 <        for i := 0 to High(structs.Global) do
134 <        begin
135 <          Data.Caption  := structs.Global[i].Name;
136 <          Data.Offset   := structs.Global[i].offset;
137 <          Data.DataType := structs.Global[i].datatype;
138 <          Data.Value    := GetValue(structs.Global[i].datatype, structs.Global[i].offset);
139 <          Data.Description := structs.Global[i].description;
140 <          AddVSTEntry(VST, nil, Data);
141 <        end;
142 <      end;
143 <      if Length(structs.Subs) > 0 then
144 <      begin
145 <        for i := 0 to High(structs.Subs) do
224 >    case Column of
225 >      0:
226          begin
227 <          with structs.Subs[i] do
227 >          if Data.Field is TFile then
228            begin
229 <            if Length(Entries) > 0 then
230 <            begin
231 <              if Pos('#', SubName) > 0 then
232 <              begin
153 <                Data.Offset  := StrToInt('$'+MidStr(SubName, Pos('#', SubName) + 1, 8));
154 <                Data.Value   := '$' +
155 <                  MidStr(SubName, PosEx('#', SubName, Pos('#', SubName) + 1) + 1, 8);
156 <                Data.Caption := MidStr(SubName, 1, Pos('#', SubName) - 1);
157 <                Data.Description := SubDesc;
158 <              end
159 <              else
160 <              begin
161 <                Data.Caption := SubName;
162 <                Data.Description := SubDesc;
163 <                Data.Offset := 0;
164 <                Data.Value := '';
165 <              end;
166 <              Data.DataType := 0;
167 <              node := AddVSTEntry(VST, nil, Data);
168 <              Data.Description := '';
169 <              for j := 0 to High(Entries) do
170 <              begin
171 <                Data.Caption  := Entries[j].Name;
172 <                Data.Offset   := Entries[j].offset;
173 <                Data.DataType := Entries[j].datatype;
174 <                Data.Value    := GetValue(Entries[j].datatype, Entries[j].offset);
175 <                Data.Description := Entries[j].description;
176 <                AddVSTEntry(VST, node, Data);
177 <              end;
178 <            end;
229 >            if Length(TFile(Data.Field).FileInfo.Name) = 0 then
230 >              TargetCanvas.Font.Color := $C06060;
231 >            if TFile(Data.Field).FileInfo.Size = 0 then
232 >              TargetCanvas.Font.Color := $2020A0;
233            end;
234          end;
181      end;
182    end;
183    if VST.RootNodeCount > 0 then
184      VST.FocusedNode := VST.GetFirst;
185  end
186  else
187  begin
188    Node := VST.GetFirst;
189    while Assigned(Node) do
190    begin
191      pdata := VST.GetNodeData(Node);
192      if pdata.DataType > 0 then
193        pdata.Value := GetValue(pdata.Datatype, pdata.Offset);
194      Node := VST.GetNext(Node);
235      end;
236    end;
197  VST.EndUpdate;
237   end;
238 < }
238 >
239 >
240 >
241 > procedure TForm_Meta.FormClose(Sender: TObject; var Action: TCloseAction);
242 > begin
243 > //  Meta.Free;
244 >  inherited;
245 > end;
246 >
247 > procedure TForm_Meta.FormCreate(Sender: TObject);
248 > begin
249 >  inherited;
250 >  OnNewConnection := NewCon;
251 >
252 >  VST.NodeDataSize := SizeOf(TNodeData);
253 >  VST.Font.Charset := AppSettings.CharSet;
254 >  VST.Clear;
255 >
256 >  UpdateConList;
257 > end;
258 >
259   end.

Diff Legend

Removed lines
+ Added lines
< Changed lines (old)
> Changed lines (new)