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 240 by alloc, Sat Jul 14 23:12:26 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 >    vst_popup: TPopupMenu;
34 >    vst_newRoot: TMenuItem;
35 >    vst_setRoot: TMenuItem;
36      procedure FormCreate(Sender: TObject);
37 +    procedure VSTInitChildren(Sender: TBaseVirtualTree; Node: PVirtualNode;
38 +      var ChildCount: Cardinal);
39 +    procedure FormClose(Sender: TObject; var Action: TCloseAction);
40 +    procedure VSTFocusChanged(Sender: TBaseVirtualTree; Node: PVirtualNode;
41 +      Column: TColumnIndex);
42 +    procedure VSTFocusChanging(Sender: TBaseVirtualTree; OldNode,
43 +      NewNode: PVirtualNode; OldColumn, NewColumn: TColumnIndex;
44 +      var Allowed: Boolean);
45      procedure VSTGetText(Sender: TBaseVirtualTree; Node: PVirtualNode;
46        Column: TColumnIndex; TextType: TVSTTextType; var CellText: WideString);
47 +    procedure VSTPaintText(Sender: TBaseVirtualTree;
48 +      const TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex;
49 +      TextType: TVSTTextType);
50 +    procedure VSTGetPopupMenu(Sender: TBaseVirtualTree; Node: PVirtualNode;
51 +      Column: TColumnIndex; const P: TPoint; var AskParent: Boolean;
52 +      var PopupMenu: TPopupMenu);
53 +    procedure vst_setRootClick(Sender: TObject);
54 +    procedure vst_newRootClick(Sender: TObject);
55    private
56 +    root: TTreeElement;
57 +    procedure NewCon(ID: Integer);
58    public
59 <    FileManager: TFileManager;
59 >    procedure SetRoot(TreeElem: TTreeElement);
60    end;
61  
19 var
20  Form_Meta: TForm_Meta;
62  
63   implementation
23 uses
24  Data, _DataTypes, _FileTypes;
64   {$R *.dfm}
65 + uses _MetaManager, _MetaTypes, ConnectionManager, Data, _FileTypes, Main;
66  
67   type
68    PNodeData = ^TNodeData;
69  
70    TNodeData = record
71 <    Field: TObject;
71 >    Field: TTreeElement;
72    end;
73  
74   function AddVSTEntry(AVST: TCustomVirtualStringTree; ANode: PVirtualNode;
# Line 43 | Line 83 | begin
83   end;
84  
85  
86 <
47 < procedure TForm_Meta.FormClose(Sender: TObject; var Action: TCloseAction);
86 > procedure TForm_Meta.NewCon(ID: Integer);
87   begin
88 <  FileManager.Free;
89 <  Action := caFree;
88 >  if ID >= 0 then
89 >    SetRoot(ConManager.Connection[FConnectionID].MetaData.Root);
90   end;
91  
92  
93 < procedure TForm_Meta.FormCreate(Sender: TObject);
93 > procedure TForm_Meta.SetRoot(TreeElem: TTreeElement);
94   var
56  a,b,c: Int64;
95    i: Integer;
96    data: TNodeData;
97 +  node: PVirtualNode;
98   begin
99 <  VST.NodeDataSize := SizeOf(TNodeData);
100 <  VST.Font.Charset := AppSettings.CharSet;
99 >  if FConnectionID <> TreeElem.ConnectionID then
100 >    SelectConnection(TreeElem.ConnectionID);
101 >  root := TreeElem;
102    VST.Clear;
103 +  VST.BeginUpdate;
104 +  for i := 0 to root.ChildCount - 1 do
105 +  begin
106 +    data.Field := root.Child[i];
107 +    node := AddVSTEntry(VST, nil, data);
108 +    if data.Field.ChildCount > 0 then
109 +      VST.HasChildren[node] := True;
110 +  end;
111 +  VST.EndUpdate;
112 + end;
113  
114 <  QueryPerformanceFrequency(c);
115 <  QueryPerformanceCounter(a);
116 <  FileManager := TFileManager.Create(1);
117 <  QueryPerformanceCounter(b);
118 <  ShowMessage('Loading Done - ' + FloatToStr((b-a)/c) + 's');
114 > procedure TForm_Meta.VSTInitChildren(Sender: TBaseVirtualTree;
115 >  Node: PVirtualNode; var ChildCount: Cardinal);
116 > var
117 >  data: PNodeData;
118 >  newdata: TNodeData;
119 >  newnode: PVirtualNode;
120 >  i: Integer;
121 >  Meta: TMetaManager;
122 > begin
123 >  data := Sender.GetNodeData(node);
124 >  Meta := ConManager.Connection[ConnectionID].MetaData;
125  
126 <  for i := 0 to FileManager.FileCount - 1 do
126 >  if data.Field.ChildCount > 0 then
127    begin
128 <    data.Field := FileManager.FileById[i];
129 <    AddVSTEntry(VST, nil, data);
128 >    for i := 0 to data.Field.ChildCount - 1 do
129 >    begin
130 >      newdata.Field := data.Field.Child[i];
131 >      newnode := AddVSTEntry(TCustomVirtualStringTree(Sender), Node, newdata);
132 >      if newdata.Field.ChildCount > 0 then
133 >        Sender.HasChildren[newnode] := True;
134 >    end;
135    end;
136 +  ChildCount := Sender.ChildCount[Node];
137   end;
138  
139  
140  
141 + procedure TForm_Meta.VSTFocusChanged(Sender: TBaseVirtualTree;
142 +  Node: PVirtualNode; Column: TColumnIndex);
143 + var
144 +  data: PNodeData;
145 +  ffile: TFile;
146 + //*******************************************************************
147 +  fs: TFileStream;
148 + //*******************************************************************
149 + begin
150 +  data := Sender.GetNodeData(Node);
151 +  ffile := nil;
152 +  if data.Field is TFile then
153 +    ffile := TFile(data.Field);
154 +  if data.Field is TDatLink then
155 +    if Assigned(TDatLink(data.Field).TargetFile) then
156 +      ffile := TFile(TDatLink(data.Field).TargetFile);
157 +  if Assigned(ffile) then
158 +  begin
159 +    if Assigned(ffile.Editor) then
160 +    begin
161 +      ffile.Editor.Align := alClient;
162 +      tab_meta.InsertControl(ffile.Editor);
163 +      ffile.Opened := True;
164 +    end;
165 + //*******************************************************************
166 +    fs := TFileStream.Create('C:\Spiele\Oni\GameDataFolder\tests\'+IntToStr(ffile.FileInfo.ID)+'_recreated.hex', fmCreate);
167 +    ffile.ReCreateFile(fs);
168 +    fs.Free;
169 + //*******************************************************************
170 +  end;
171 + end;
172 +
173 +
174 + procedure TForm_Meta.VSTFocusChanging(Sender: TBaseVirtualTree; OldNode,
175 +  NewNode: PVirtualNode; OldColumn, NewColumn: TColumnIndex;
176 +  var Allowed: Boolean);
177 + var
178 +  data: PNodeData;
179 +  i: Integer;
180 + begin
181 +  data := Sender.GetNodeData(NewNode);
182 +  if data.Field is TFile then
183 +  begin
184 +    if Assigned(TFile(data.Field).Editor) then
185 +      Allowed := not TFile(data.Field).Opened
186 +    else
187 +      Allowed := True;
188 +  end;
189 +  if Allowed and Assigned(OldNode) then
190 +  begin
191 +    data := Sender.GetNodeData(OldNode);
192 +    if data.Field is TFile then
193 +    begin
194 +      if TFile(data.Field).Opened then
195 +      begin
196 +        if tab_meta.ControlCount > 0 then
197 +          for i := 0 to tab_meta.ControlCount - 1 do
198 +            tab_meta.RemoveControl(tab_meta.Controls[i]);
199 +        TFile(data.Field).Opened := False;
200 +      end;
201 +    end;
202 +  end;
203 + end;
204 +
205 +
206   procedure TForm_Meta.VSTGetText(Sender: TBaseVirtualTree; Node: PVirtualNode;
207    Column: TColumnIndex; TextType: TVSTTextType; var CellText: WideString);
208   var
# Line 86 | Line 213 | begin
213    if TextType = ttNormal then
214    begin
215      case Column of
216 <      0: begin
90 <        if Data.Field is TFile then
216 >      0:
217          begin
218 <          CellText := TFile(Data.Field).FileName;
218 >          CellText := Data.Field.GetCaption;
219          end;
94      end;
95 {      0:
96        CellText := Data.Caption;
220        1:
221 <        if Data.DataType > 0 then
222 <          CellText := '0x' + IntToHex(Data.Offset, 8)
223 <        else if Data.Offset > 0 then
224 <          CellText := '0x' + IntToHex(Data.Offset, 8);
221 >        begin
222 >          if Data.Field is TFile then
223 >            CellText := TFile(Data.Field).FileInfo.Extension;
224 >        end;
225        2:
226 <        if Data.DataType > 0 then
227 <          CellText := GetDataType(Data.DataType);
226 >        begin
227 >          if Data.Field is TFile then
228 >            CellText := IntToStr(TFile(Data.Field).FileInfo.ID);
229 >        end;
230        3:
231 <        if Data.DataType > 0 then
232 <          CellText := Data.Value //GetValue(data.DataType, data.Offset)
233 <        else if Length(Data.Value) > 0 then
234 <          CellText := IntToStr(StrToInt(Data.Value)) + ' Bytes';
235 <      4:
111 <        CellText := Data.Description;
112 < }    end;
231 >        begin
232 >          if Data.Field is TDataField then
233 >            CellText := TDataField(Data.Field).ValueAsString;
234 >        end;
235 >    end;
236    end;
237   end;
238  
116 {
239  
240 < procedure WriteStructureInfos;
240 > procedure TForm_Meta.VSTPaintText(Sender: TBaseVirtualTree;
241 >  const TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex;
242 >  TextType: TVSTTextType);
243   var
244 <  i, j:    Integer;
121 <  pdata:   PNodeData;
122 <  Data:    TNodeData;
123 <  node:    PVirtualNode;
244 >  Data: PNodeData;
245   begin
246 <  VST.BeginUpdate;
247 <  if VST.RootNodeCount = 0 then
246 >  Data     := Sender.GetNodeData(Node);
247 >  if TextType = ttNormal then
248    begin
249 <    structs := LoadStructureDefinition(ConID, fileid);
250 <    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
249 >    case Column of
250 >      0:
251          begin
252 <          with structs.Subs[i] do
252 >          if Data.Field is TFile then
253            begin
254 <            if Length(Entries) > 0 then
255 <            begin
256 <              if Pos('#', SubName) > 0 then
257 <              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;
254 >            if Length(TFile(Data.Field).FileInfo.Name) = 0 then
255 >              TargetCanvas.Font.Color := $C06060;
256 >            if TFile(Data.Field).FileInfo.Size = 0 then
257 >              TargetCanvas.Font.Color := $2020A0;
258            end;
259          end;
181      end;
260      end;
261 <    if VST.RootNodeCount > 0 then
262 <      VST.FocusedNode := VST.GetFirst;
263 <  end
264 <  else
261 >  end;
262 > end;
263 >
264 >
265 >
266 > procedure TForm_Meta.VSTGetPopupMenu(Sender: TBaseVirtualTree;
267 >  Node: PVirtualNode; Column: TColumnIndex; const P: TPoint;
268 >  var AskParent: Boolean; var PopupMenu: TPopupMenu);
269 > var
270 >  data: PNodeData;
271 > begin
272 >  inherited;
273 >  AskParent := False;
274 >  if Assigned(Node) then
275    begin
276 <    Node := VST.GetFirst;
277 <    while Assigned(Node) do
276 >    Sender.Selected[Node] := True;
277 >    Sender.FocusedNode := Node;
278 >    data := Sender.GetNodeData(Node);
279 >    if Column = 0 then
280      begin
281 <      pdata := VST.GetNodeData(Node);
282 <      if pdata.DataType > 0 then
283 <        pdata.Value := GetValue(pdata.Datatype, pdata.Offset);
284 <      Node := VST.GetNext(Node);
281 >      if TTreeElement(data.Field).GetChildCount > 0 then
282 >        PopupMenu := vst_popup
283 >      else
284 >        PopupMenu := nil;
285      end;
286    end;
197  VST.EndUpdate;
287   end;
288 < }
288 >
289 > procedure TForm_Meta.vst_newRootClick(Sender: TObject);
290 > var
291 >  data: PNodeData;
292 >  form: TForm_BaseTemplate;
293 > begin
294 >  inherited;
295 >  data := VST.GetNodeData(VST.FocusedNode);
296 >  form := nil;
297 >  form := Form_Main.open_child('meta');
298 >  if form is TForm_Meta then
299 >    TForm_Meta(form).SetRoot(data.Field);
300 > end;
301 >
302 > procedure TForm_Meta.vst_setRootClick(Sender: TObject);
303 > var
304 >  data: PNodeData;
305 > begin
306 >  inherited;
307 >  data := VST.GetNodeData(VST.FocusedNode);
308 >  SetRoot(data.Field);
309 > end;
310 >
311 > procedure TForm_Meta.FormClose(Sender: TObject; var Action: TCloseAction);
312 > begin
313 > //  Meta.Free;
314 >  inherited;
315 > end;
316 >
317 > procedure TForm_Meta.FormCreate(Sender: TObject);
318 > begin
319 >  inherited;
320 >  OnNewConnection := NewCon;
321 >
322 >  VST.NodeDataSize := SizeOf(TNodeData);
323 >  VST.Font.Charset := AppSettings.CharSet;
324 >  VST.Clear;
325 >
326 >  UpdateConList;
327 > end;
328 >
329   end.

Diff Legend

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