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 213 by alloc, Tue Jun 12 17:00:48 2007 UTC vs.
Revision 244 by alloc, Fri Aug 17 21:09:51 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, _MetaManager, StdCtrls;
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 <    Button1: TButton;
14 <    Label3: TLabel;
15 <    combo_connection: TComboBox;
16 <    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);
15    procedure VSTGetText(Sender: TBaseVirtualTree; Node: PVirtualNode;
16      Column: TColumnIndex; TextType: TVSTTextType; var CellText: WideString);
17    procedure Button1Click(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 +    procedure VSTGetHint(Sender: TBaseVirtualTree; Node: PVirtualNode;
56 +      Column: TColumnIndex; var LineBreakStyle: TVTTooltipLineBreakStyle;
57 +      var HintText: WideString);
58    private
59 +    root: TTreeElement;
60 +    procedure NewCon(ID: Integer);
61    public
62 <    MetaManager: TMetaManager;
62 >    procedure SetRoot(TreeElem: TTreeElement);
63    end;
64  
28 var
29  Form_Meta: TForm_Meta;
65  
66   implementation
32 uses
33  Data, _DataTypes, _FileTypes, ConnectionManager, TypeDefs, StrUtils;
67   {$R *.dfm}
68 + uses _MetaManager, _MetaTypes, ConnectionManager, Data, _FileTypes, Main,
69 +  TypeDefs;
70  
71   type
72    PNodeData = ^TNodeData;
73  
74    TNodeData = record
75 <    Field: TObject;
75 >    Field: TTreeElement;
76    end;
77  
78   function AddVSTEntry(AVST: TCustomVirtualStringTree; ANode: PVirtualNode;
# Line 52 | Line 87 | begin
87   end;
88  
89  
90 + procedure TForm_Meta.NewCon(ID: Integer);
91 + begin
92 +  if ID >= 0 then
93 +    SetRoot(ConManager.Connection[FConnectionID].MetaData.Root);
94 + //SetRoot(ConManager.Connection[FConnectionID].MetaData.FileById[454]);
95 + end;
96 +
97 +
98 + procedure TForm_Meta.SetRoot(TreeElem: TTreeElement);
99 + var
100 +  i: Integer;
101 +  data: TNodeData;
102 +  node: PVirtualNode;
103 +  basenode: PVirtualNode;
104 + begin
105 +  if FConnectionID <> TreeElem.ConnectionID then
106 +    SelectConnection(TreeElem.ConnectionID);
107 +  root := TreeElem;
108 +  VST.Clear;
109 +  VST.BeginUpdate;
110 +  data.Field := root;
111 +  basenode := AddVSTEntry(VST, nil, data);
112 +  for i := 0 to root.ChildCount - 1 do
113 +  begin
114 +    data.Field := root.Child[i];
115 +    node := AddVSTEntry(VST, basenode, data);
116 +    if data.Field.ChildCount > 0 then
117 +      VST.HasChildren[node] := True;
118 +  end;
119 +  VST.EndUpdate;
120 + end;
121  
122   procedure TForm_Meta.VSTInitChildren(Sender: TBaseVirtualTree;
123    Node: PVirtualNode; var ChildCount: Cardinal);
# Line 60 | Line 126 | var
126    newdata: TNodeData;
127    newnode: PVirtualNode;
128    i: Integer;
63  id: Integer;
129   begin
130 <  data := VST.GetNodeData(node);
131 <  for i := 0 to MetaManager.FileById[TFile(data.Field).FileID].ChildCount - 1 do
130 >  data := Sender.GetNodeData(node);
131 >
132 >  if data.Field.ChildCount > 0 then
133    begin
134 <    id := MetaManager.FileById[TFile(data.Field).FileID].LinkByIndex[i].DestID;
135 <    MetaManager.InitFile(id);
136 <    newdata.Field := MetaManager.FileById[id];
137 <    newnode := AddVSTEntry(VST, Node, newdata);
138 <    if MetaManager.FileById[id].ChildCount > 0 then
139 <      VST.HasChildren[newnode] := True;
134 >    for i := 0 to data.Field.ChildCount - 1 do
135 >    begin
136 >      newdata.Field := data.Field.Child[i];
137 >      newnode := AddVSTEntry(TCustomVirtualStringTree(Sender), Node, newdata);
138 >      if newdata.Field.ChildCount > 0 then
139 >        Sender.HasChildren[newnode] := True;
140 >    end;
141    end;
142 <  ChildCount := MetaManager.FileById[TFile(data.Field).FileID].ChildCount;
142 >  ChildCount := Sender.ChildCount[Node];
143   end;
144  
145  
79 procedure TForm_Meta.Button1Click(Sender: TObject);
80 var
81  name: String;
82  conid: Integer;
146  
147 <  a,b,c: Int64;
148 <  i: Integer;
149 <  data: TNodeData;
150 <  node: PVirtualNode;
147 > procedure TForm_Meta.VSTFocusChanged(Sender: TBaseVirtualTree;
148 >  Node: PVirtualNode; Column: TColumnIndex);
149 > var
150 >  data: PNodeData;
151 >  ffile: TFile;
152 > //*******************************************************************
153 >  fs: TFileStream;
154 > //*******************************************************************
155   begin
156 <  if combo_connection.ItemIndex >= 0 then
156 >  data := Sender.GetNodeData(Node);
157 >  ffile := nil;
158 >  if data.Field is TFile then
159 >    ffile := TFile(data.Field);
160 >  if data.Field is _MetaTypes.TDatLink then
161 >    if Assigned(_MetaTypes.TDatLink(data.Field).TargetFile) then
162 >      ffile := TFile(_MetaTypes.TDatLink(data.Field).TargetFile);
163 >  if Assigned(ffile) then
164    begin
165 <    name := combo_connection.Items.Strings[combo_connection.ItemIndex];
92 <    conid := StrToInt(MidStr(name, Pos('[', name) + 1, Pos(']', name) - Pos('[', name)  - 1));
93 <
94 <    QueryPerformanceFrequency(c);
95 <    QueryPerformanceCounter(a);
96 <    MetaManager := TMetaManager.Create(conid);
97 <    QueryPerformanceCounter(b);
98 <    ShowMessage('Loading Done - ' + FloatToStr((b-a)/c) + 's');
99 <
100 <    VST.Clear;
101 <    VST.BeginUpdate;
102 <    for i := 0 to MetaManager.FileCount - 1 do
165 >    if Assigned(ffile.Editor) then
166      begin
167 <      if Assigned(MetaManager.FileById[i]) then
168 <      begin
169 <        data.Field := MetaManager.FileById[i];
107 <        node := AddVSTEntry(VST, nil, data);
108 <        if MetaManager.FileById[i].ChildCount > 0 then
109 <          VST.HasChildren[node] := True;
110 <      end;
167 >      ffile.Editor.Align := alClient;
168 >      tab_meta.InsertControl(ffile.Editor);
169 >      ffile.Opened := True;
170      end;
171 <    VST.EndUpdate;
171 > //*******************************************************************
172 > //    fs := TFileStream.Create('C:\Spiele\Oni\GameDataFolder\tests\'+IntToStr(ffile.FileInfo.ID)+'_recreated.hex', fmCreate);
173 > //    ffile.ReCreateFile(fs);
174 > //    fs.Free;
175 > //*******************************************************************
176    end;
177   end;
178  
116 procedure TForm_Meta.FormClose(Sender: TObject; var Action: TCloseAction);
117 begin
118  MetaManager.Free;
119  Action := caFree;
120 end;
121
179  
180 < procedure TForm_Meta.FormCreate(Sender: TObject);
180 > procedure TForm_Meta.VSTFocusChanging(Sender: TBaseVirtualTree; OldNode,
181 >  NewNode: PVirtualNode; OldColumn, NewColumn: TColumnIndex;
182 >  var Allowed: Boolean);
183   var
184 +  data: PNodeData;
185    i: Integer;
126
127  fn, datatype, boxstring: String;
128  level: Integer;
186   begin
187 <  combo_connection.ItemIndex := -1;
188 <  combo_connection.Items.Clear;
132 <  if ConManager.Count > 0 then
187 >  data := Sender.GetNodeData(NewNode);
188 >  if data.Field is TFile then
189    begin
190 <    for i := 0 to ConManager.Count - 1 do
191 <    begin
192 <      level := ConManager.ConnectionByIndex[i].LevelNumber;
193 <      fn := ExtractFileName(ConManager.ConnectionByIndex[i].FileName);
194 <      if ConManager.ConnectionByIndex[i].Backend = DB_ONI then
195 <        datatype := 'ONI-.dat: '
196 <      else if ConManager.ConnectionByIndex[i].Backend = DB_ADB then
197 <        datatype := 'OUP-DB: '
198 <      else
143 <        datatype := 'Unknown: ';
144 <      boxstring := datatype + fn + ' (Level: ' + IntToStr(level) + ') [' + IntToStr(ConManager.ConnectionByIndex[i].ConnectionID) + ']';
145 <      combo_connection.Items.Add(boxstring);
146 <    end;
147 <    if combo_connection.ItemIndex = -1 then
190 >    if Assigned(TFile(data.Field).Editor) then
191 >      Allowed := not TFile(data.Field).Opened
192 >    else
193 >      Allowed := True;
194 >  end;
195 >  if Allowed and Assigned(OldNode) then
196 >  begin
197 >    data := Sender.GetNodeData(OldNode);
198 >    if data.Field is TFile then
199      begin
200 <      combo_connection.ItemIndex := 0;
200 >      if TFile(data.Field).Opened then
201 >      begin
202 >        if tab_meta.ControlCount > 0 then
203 >          for i := 0 to tab_meta.ControlCount - 1 do
204 >            tab_meta.RemoveControl(tab_meta.Controls[i]);
205 >        TFile(data.Field).Opened := False;
206 >      end;
207      end;
208    end;
152
153
154  VST.NodeDataSize := SizeOf(TNodeData);
155  VST.Font.Charset := AppSettings.CharSet;
156  VST.Clear;
209   end;
210  
211  
160
212   procedure TForm_Meta.VSTGetText(Sender: TBaseVirtualTree; Node: PVirtualNode;
213    Column: TColumnIndex; TextType: TVSTTextType; var CellText: WideString);
214   var
# Line 168 | Line 219 | begin
219    if TextType = ttNormal then
220    begin
221      case Column of
222 <      0:
223 <        begin
173 <          if Data.Field is TFile then
174 <          begin
175 <            CellText := TFile(Data.Field).FileName;
176 <            if CellText = '' then
177 <              CellText := 'Unnamed';
178 <          end;
179 <        end;
180 <      1:
181 <        begin
182 <          if Data.Field is TFile then
183 <            CellText := TFile(Data.Field).FileExt;
184 <        end;
222 >      0: CellText := Data.Field.Caption;
223 >      1: CellText := data.Field.VType;
224        2:
225          begin
226 <          if Data.Field is TFile then
227 <            CellText := IntToStr(TFile(Data.Field).FileID);
226 >          if Data.Field is TDataField then
227 >            CellText := TDataField(Data.Field).ValueAsString;
228          end;
229      end;
230    end;
231   end;
232  
233 +
234   procedure TForm_Meta.VSTPaintText(Sender: TBaseVirtualTree;
235    const TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex;
236    TextType: TVSTTextType);
# Line 205 | Line 245 | begin
245          begin
246            if Data.Field is TFile then
247            begin
248 <            if Length(TFile(Data.Field).FileName) = 0 then
248 >            if Length(TFile(Data.Field).FileInfo.Name) = 0 then
249                TargetCanvas.Font.Color := $C06060;
250 <            if TFile(Data.Field).FileSize = 0 then
250 >            if TFile(Data.Field).FileInfo.Size = 0 then
251                TargetCanvas.Font.Color := $2020A0;
252            end;
253          end;
# Line 215 | Line 255 | begin
255    end;
256   end;
257  
218 {
258  
259 < procedure WriteStructureInfos;
259 >
260 > procedure TForm_Meta.VSTGetHint(Sender: TBaseVirtualTree; Node: PVirtualNode;
261 >  Column: TColumnIndex; var LineBreakStyle: TVTTooltipLineBreakStyle;
262 >  var HintText: WideString);
263   var
264 <  i, j:    Integer;
265 <  pdata:   PNodeData;
266 <  Data:    TNodeData;
267 <  node:    PVirtualNode;
264 >  data: PNodeData;
265 >  CellText: WideString;
266 >
267 >  i: Integer;
268 >  links: TStrings;
269 >  ifile: TFile;
270   begin
271 <  VST.BeginUpdate;
272 <  if VST.RootNodeCount = 0 then
271 >  inherited;
272 >  if Assigned(Node) then
273    begin
274 <    structs := LoadStructureDefinition(ConID, fileid);
275 <    if structs.Data then
274 >    VSTGetText(Sender, Node, Column, ttNormal, CellText);
275 >    if Length(CellText) > 0 then
276      begin
277 <      if Length(structs.Global) > 0 then
277 >      data := Sender.GetNodeData(Node);
278 >      if data.Field is TDataField then
279        begin
280 <        for i := 0 to High(structs.Global) do
281 <        begin
282 <          Data.Caption  := structs.Global[i].Name;
238 <          Data.Offset   := structs.Global[i].offset;
239 <          Data.DataType := structs.Global[i].datatype;
240 <          Data.Value    := GetValue(structs.Global[i].datatype, structs.Global[i].offset);
241 <          Data.Description := structs.Global[i].description;
242 <          AddVSTEntry(VST, nil, Data);
280 >        case Column of
281 >          0,1: HintText := TDataField(data.Field).Description;
282 >          2: HintText := '';
283          end;
284        end;
285 <      if Length(structs.Subs) > 0 then
285 >      if data.Field is TFile then
286        begin
287 <        for i := 0 to High(structs.Subs) do
288 <        begin
289 <          with structs.Subs[i] do
290 <          begin
291 <            if Length(Entries) > 0 then
292 <            begin
293 <              if Pos('#', SubName) > 0 then
254 <              begin
255 <                Data.Offset  := StrToInt('$'+MidStr(SubName, Pos('#', SubName) + 1, 8));
256 <                Data.Value   := '$' +
257 <                  MidStr(SubName, PosEx('#', SubName, Pos('#', SubName) + 1) + 1, 8);
258 <                Data.Caption := MidStr(SubName, 1, Pos('#', SubName) - 1);
259 <                Data.Description := SubDesc;
260 <              end
261 <              else
262 <              begin
263 <                Data.Caption := SubName;
264 <                Data.Description := SubDesc;
265 <                Data.Offset := 0;
266 <                Data.Value := '';
267 <              end;
268 <              Data.DataType := 0;
269 <              node := AddVSTEntry(VST, nil, Data);
270 <              Data.Description := '';
271 <              for j := 0 to High(Entries) do
272 <              begin
273 <                Data.Caption  := Entries[j].Name;
274 <                Data.Offset   := Entries[j].offset;
275 <                Data.DataType := Entries[j].datatype;
276 <                Data.Value    := GetValue(Entries[j].datatype, Entries[j].offset);
277 <                Data.Description := Entries[j].description;
278 <                AddVSTEntry(VST, node, Data);
279 <              end;
280 <            end;
281 <          end;
287 >        ifile := TFile(data.Field);
288 >        case Column of
289 >          0: HintText :=
290 >            'FileID:    ' + IntToStr(ifile.FileInfo.ID) + #13#10 +
291 >            'Name:      ' + ifile.FileInfo.Name + #13#10 +
292 >            'Extension: ' + ifile.FileInfo.Extension + #13#10 +
293 >            '.dat-size: ' + IntToStr(ifile.FileInfo.Size) + #13#10;
294          end;
295        end;
296      end;
285    if VST.RootNodeCount > 0 then
286      VST.FocusedNode := VST.GetFirst;
297    end
298    else
299 +    HintText := '';
300 + end;
301 +
302 + procedure TForm_Meta.VSTGetPopupMenu(Sender: TBaseVirtualTree;
303 +  Node: PVirtualNode; Column: TColumnIndex; const P: TPoint;
304 +  var AskParent: Boolean; var PopupMenu: TPopupMenu);
305 + var
306 +  data: PNodeData;
307 + begin
308 +  inherited;
309 +  AskParent := False;
310 +  if Assigned(Node) then
311    begin
312 <    Node := VST.GetFirst;
313 <    while Assigned(Node) do
312 >    Sender.Selected[Node] := True;
313 >    Sender.FocusedNode := Node;
314 >    data := Sender.GetNodeData(Node);
315 >    if Column = 0 then
316      begin
317 <      pdata := VST.GetNodeData(Node);
318 <      if pdata.DataType > 0 then
319 <        pdata.Value := GetValue(pdata.Datatype, pdata.Offset);
320 <      Node := VST.GetNext(Node);
317 >      if TTreeElement(data.Field).ChildCount > 0 then
318 >        PopupMenu := vst_popup
319 >      else
320 >        PopupMenu := nil;
321      end;
322    end;
299  VST.EndUpdate;
323   end;
324 < }
324 >
325 > procedure TForm_Meta.vst_newRootClick(Sender: TObject);
326 > var
327 >  data: PNodeData;
328 >  form: TForm_BaseTemplate;
329 > begin
330 >  inherited;
331 >  data := VST.GetNodeData(VST.FocusedNode);
332 >  form := nil;
333 >  form := Form_Main.open_child('meta');
334 >  if form is TForm_Meta then
335 >    TForm_Meta(form).SetRoot(data.Field);
336 > end;
337 >
338 > procedure TForm_Meta.vst_setRootClick(Sender: TObject);
339 > var
340 >  data: PNodeData;
341 > begin
342 >  inherited;
343 >  data := VST.GetNodeData(VST.FocusedNode);
344 >  SetRoot(data.Field);
345 > end;
346 >
347 > procedure TForm_Meta.FormClose(Sender: TObject; var Action: TCloseAction);
348 > begin
349 > //  Meta.Free;
350 >  inherited;
351 > end;
352 >
353 > procedure TForm_Meta.FormCreate(Sender: TObject);
354 > begin
355 >  inherited;
356 >  OnNewConnection := NewCon;
357 >
358 >  VST.NodeDataSize := SizeOf(TNodeData);
359 >  VST.Font.Charset := AppSettings.CharSet;
360 >  VST.Clear;
361 >
362 >  UpdateConList;
363 > end;
364 >
365   end.

Diff Legend

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