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

Diff Legend

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