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 233 by alloc, Fri Jun 29 12:38:24 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      procedure FormCreate(Sender: TObject);
18    procedure VSTGetText(Sender: TBaseVirtualTree; Node: PVirtualNode;
19      Column: TColumnIndex; TextType: TVSTTextType; var CellText: WideString);
20    procedure Button1Click(Sender: TObject);
34      procedure VSTInitChildren(Sender: TBaseVirtualTree; Node: PVirtualNode;
35        var ChildCount: Cardinal);
36 <    procedure VSTPaintText(Sender: TBaseVirtualTree;
24 <      const TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex;
25 <      TextType: TVSTTextType);
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
51    end;
52  
35 var
36  Form_Meta: TForm_Meta;
53  
54   implementation
39 uses
40  Data, _DataTypes, _FileTypes, ConnectionManager, TypeDefs, StrUtils;
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 59 | Line 74 | begin
74   end;
75  
76  
77 <
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;
71 < begin
72 <  data := VST.GetNodeData(node);
73 <  for i := 0 to Meta.FileById[TFile(data.Field).FileID].ChildCount - 1 do
74 <  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;
83 < end;
84 <
85 <
86 < procedure TForm_Meta.Button1Click(Sender: TObject);
77 > procedure TForm_Meta.NewCon(ID: Integer);
78   var
88  name: String;
89  conid: Integer;
90
91  a,b,c: Int64;
79    i: Integer;
80    data: TNodeData;
81    node: PVirtualNode;
82 +  Meta: TMetaManager;
83 +  root: TTreeElement;
84   begin
85 <  if combo_connection.ItemIndex >= 0 then
85 >  if ID >= 0 then
86    begin
87 <    name := combo_connection.Items.Strings[combo_connection.ItemIndex];
99 <    conid := StrToInt(MidStr(name, Pos('[', name) + 1, Pos(']', name) - Pos('[', name)  - 1));
100 <
101 <    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 <
87 >    //VST
88      VST.Clear;
89      VST.BeginUpdate;
90 <    for i := 0 to Meta.FileCount - 1 do
90 >    root := ConManager.Connection[FConnectionID].MetaData.Root;
91 >    for i := 0 to root.ChildCount - 1 do
92      begin
93 <      if Assigned(Meta.FileById[i]) then
94 <      begin
95 <        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;
93 >      data.Field := root.Child[i];
94 >      node := AddVSTEntry(VST, nil, data);
95 >      VST.HasChildren[node] := True;
96      end;
97      VST.EndUpdate;
98    end;
99   end;
100  
124 procedure TForm_Meta.FormClose(Sender: TObject; var Action: TCloseAction);
125 begin
126  Meta.Free;
127  Action := caFree;
128 end;
101  
102 <
103 < procedure TForm_Meta.FormCreate(Sender: TObject);
102 > procedure TForm_Meta.VSTInitChildren(Sender: TBaseVirtualTree;
103 >  Node: PVirtualNode; var ChildCount: Cardinal);
104   var
105 +  data: PNodeData;
106 +  newdata: TNodeData;
107 +  newnode: PVirtualNode;
108    i: Integer;
109 <
135 <  fn, datatype, boxstring: String;
136 <  level: Integer;
109 >  Meta: TMetaManager;
110   begin
111 <  combo_connection.ItemIndex := -1;
112 <  combo_connection.Items.Clear;
113 <  if ConManager.Count > 0 then
111 >  data := Sender.GetNodeData(node);
112 >  Meta := ConManager.Connection[ConnectionID].MetaData;
113 >  if data.Field is TExtension then
114 >    if TExtension(data.Field).ChildCount = 0 then
115 >      TExtension(data.Field).InitList;
116 >
117 >  if data.Field.ChildCount > 0 then
118    begin
119 <    for i := 0 to ConManager.Count - 1 do
143 <    begin
144 <      level := ConManager.ConnectionByIndex[i].LevelNumber;
145 <      fn := ExtractFileName(ConManager.ConnectionByIndex[i].FileName);
146 <      if ConManager.ConnectionByIndex[i].Backend = DB_ONI then
147 <        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
119 >    for i := 0 to data.Field.ChildCount - 1 do
120      begin
121 <      combo_connection.ItemIndex := 0;
121 >      newdata.Field := data.Field.Child[i];
122 >      newnode := AddVSTEntry(TCustomVirtualStringTree(Sender), Node, newdata);
123 >      if newdata.Field.ChildCount > 0 then
124 >        Sender.HasChildren[newnode] := True;
125      end;
126    end;
127 <
161 <
162 <  VST.NodeDataSize := SizeOf(TNodeData);
163 <  VST.Font.Charset := AppSettings.CharSet;
164 <  VST.Clear;
127 >  ChildCount := Sender.ChildCount[Node];
128   end;
129  
130  
168
131   procedure TForm_Meta.VSTFocusChanged(Sender: TBaseVirtualTree;
132    Node: PVirtualNode; Column: TColumnIndex);
133   var
# Line 177 | Line 139 | begin
139      TFile(data.Field).InitEditor;
140      if Assigned(TFile(data.Field).Editor) then
141      begin
142 <      panel2.InsertControl(TFile(data.Field).Editor);
142 >      TFile(data.Field).Editor.Align := alClient;
143 >      tab_meta.InsertControl(TFile(data.Field).Editor);
144        TFile(data.Field).Opened := True;
145      end;
146    end;
147   end;
148  
149 +
150   procedure TForm_Meta.VSTFocusChanging(Sender: TBaseVirtualTree; OldNode,
151    NewNode: PVirtualNode; OldColumn, NewColumn: TColumnIndex;
152    var Allowed: Boolean);
# Line 206 | Line 170 | begin
170      begin
171        if TFile(data.Field).Opened then
172        begin
173 <        if panel2.ControlCount > 0 then
174 <          for i := 0 to panel2.ControlCount - 1 do
175 <            panel2.RemoveControl(panel2.Controls[i]);
173 >        if tab_meta.ControlCount > 0 then
174 >          for i := 0 to tab_meta.ControlCount - 1 do
175 >            tab_meta.RemoveControl(tab_meta.Controls[i]);
176          TFile(data.Field).Opened := False;
177        end;
178      end;
179    end;
180   end;
181  
182 +
183   procedure TForm_Meta.VSTGetText(Sender: TBaseVirtualTree; Node: PVirtualNode;
184    Column: TColumnIndex; TextType: TVSTTextType; var CellText: WideString);
185   var
# Line 227 | Line 192 | begin
192      case Column of
193        0:
194          begin
195 <          if Data.Field is TFile then
231 <          begin
232 <            CellText := TFile(Data.Field).FileName;
233 <            if CellText = '' then
234 <              CellText := 'Unnamed';
235 <          end;
195 >          CellText := Data.Field.GetCaption;
196          end;
197        1:
198          begin
199            if Data.Field is TFile then
200 <            CellText := TFile(Data.Field).FileExt;
200 >            CellText := TFile(Data.Field).FileInfo.Extension;
201          end;
202        2:
203          begin
204            if Data.Field is TFile then
205 <            CellText := IntToStr(TFile(Data.Field).FileID);
205 >            CellText := IntToStr(TFile(Data.Field).FileInfo.ID);
206          end;
207      end;
208    end;
209   end;
210  
211 +
212   procedure TForm_Meta.VSTPaintText(Sender: TBaseVirtualTree;
213    const TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex;
214    TextType: TVSTTextType);
# Line 262 | Line 223 | begin
223          begin
224            if Data.Field is TFile then
225            begin
226 <            if Length(TFile(Data.Field).FileName) = 0 then
226 >            if Length(TFile(Data.Field).FileInfo.Name) = 0 then
227                TargetCanvas.Font.Color := $C06060;
228 <            if TFile(Data.Field).FileSize = 0 then
228 >            if TFile(Data.Field).FileInfo.Size = 0 then
229                TargetCanvas.Font.Color := $2020A0;
230            end;
231          end;
# Line 272 | Line 233 | begin
233    end;
234   end;
235  
275 {
236  
237 < procedure WriteStructureInfos;
238 < var
279 <  i, j:    Integer;
280 <  pdata:   PNodeData;
281 <  Data:    TNodeData;
282 <  node:    PVirtualNode;
237 >
238 > procedure TForm_Meta.FormClose(Sender: TObject; var Action: TCloseAction);
239   begin
240 <  VST.BeginUpdate;
241 <  if VST.RootNodeCount = 0 then
286 <  begin
287 <    structs := LoadStructureDefinition(ConID, fileid);
288 <    if structs.Data then
289 <    begin
290 <      if Length(structs.Global) > 0 then
291 <      begin
292 <        for i := 0 to High(structs.Global) do
293 <        begin
294 <          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);
300 <        end;
301 <      end;
302 <      if Length(structs.Subs) > 0 then
303 <      begin
304 <        for i := 0 to High(structs.Subs) do
305 <        begin
306 <          with structs.Subs[i] do
307 <          begin
308 <            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;
339 <        end;
340 <      end;
341 <    end;
342 <    if VST.RootNodeCount > 0 then
343 <      VST.FocusedNode := VST.GetFirst;
344 <  end
345 <  else
346 <  begin
347 <    Node := VST.GetFirst;
348 <    while Assigned(Node) do
349 <    begin
350 <      pdata := VST.GetNodeData(Node);
351 <      if pdata.DataType > 0 then
352 <        pdata.Value := GetValue(pdata.Datatype, pdata.Offset);
353 <      Node := VST.GetNext(Node);
354 <    end;
355 <  end;
356 <  VST.EndUpdate;
240 > //  Meta.Free;
241 >  inherited;
242   end;
243 < }
243 >
244 > procedure TForm_Meta.FormCreate(Sender: TObject);
245 > begin
246 >  inherited;
247 >  OnNewConnection := NewCon;
248 >
249 >  VST.NodeDataSize := SizeOf(TNodeData);
250 >  VST.Font.Charset := AppSettings.CharSet;
251 >  VST.Clear;
252 >
253 >  UpdateConList;
254 > end;
255 >
256   end.

Diff Legend

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