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 212 by alloc, Tue Jun 12 16:42:53 2007 UTC vs.
Revision 239 by alloc, Sat Jul 14 20:22:05 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    private
56 +    root: TTreeElement;
57 +    procedure NewCon(ID: Integer);
58    public
59 <    MetaManager: TMetaManager;
59 >    procedure SetRoot(TreeElem: TTreeElement);
60    end;
61  
28 var
29  Form_Meta: TForm_Meta;
62  
63   implementation
32 uses
33  Data, _DataTypes, _FileTypes, ConnectionManager, TypeDefs, StrUtils;
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 52 | Line 83 | begin
83   end;
84  
85  
86 + procedure TForm_Meta.NewCon(ID: Integer);
87 + begin
88 +  if ID >= 0 then
89 +    SetRoot(ConManager.Connection[FConnectionID].MetaData.Root);
90 + end;
91 +
92 +
93 + procedure TForm_Meta.SetRoot(TreeElem: TTreeElement);
94 + var
95 +  i: Integer;
96 +  data: TNodeData;
97 +  node: PVirtualNode;
98 + begin
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   procedure TForm_Meta.VSTInitChildren(Sender: TBaseVirtualTree;
115    Node: PVirtualNode; var ChildCount: Cardinal);
# Line 60 | Line 118 | var
118    newdata: TNodeData;
119    newnode: PVirtualNode;
120    i: Integer;
121 <  id: Integer;
121 >  Meta: TMetaManager;
122   begin
123 <  data := VST.GetNodeData(node);
124 <  for i := 0 to MetaManager.FileById[TFile(data.Field).FileID].ChildCount - 1 do
123 >  data := Sender.GetNodeData(node);
124 >  Meta := ConManager.Connection[ConnectionID].MetaData;
125 >
126 >  if data.Field.ChildCount > 0 then
127    begin
128 <    id := MetaManager.FileById[TFile(data.Field).FileID].LinkByIndex[i].DestID;
129 <    MetaManager.InitFile(id);
130 <    newdata.Field := MetaManager.FileById[id];
131 <    newnode := AddVSTEntry(VST, Node, newdata);
132 <    if MetaManager.FileById[id].ChildCount > 0 then
133 <      VST.HasChildren[newnode] := True;
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 := MetaManager.FileById[TFile(data.Field).FileID].ChildCount;
136 >  ChildCount := Sender.ChildCount[Node];
137   end;
138  
139  
140 < procedure TForm_Meta.Button1Click(Sender: TObject);
140 > procedure TForm_Meta.VSTFocusChanged(Sender: TBaseVirtualTree;
141 >  Node: PVirtualNode; Column: TColumnIndex);
142   var
143 <  name: String;
82 <  conid: Integer;
83 <
84 <  a,b,c: Int64;
85 <  i: Integer;
86 <  data: TNodeData;
87 <  node: PVirtualNode;
143 >  data: PNodeData;
144   begin
145 <  if combo_connection.ItemIndex >= 0 then
145 >  data := Sender.GetNodeData(Node);
146 >  if data.Field is TFile then
147    begin
148 <    name := combo_connection.Items.Strings[combo_connection.ItemIndex];
149 <    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
148 >    TFile(data.Field).InitEditor;
149 >    if Assigned(TFile(data.Field).Editor) then
150      begin
151 <      if Assigned(MetaManager.FileById[i]) then
152 <      begin
153 <        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;
151 >      TFile(data.Field).Editor.Align := alClient;
152 >      tab_meta.InsertControl(TFile(data.Field).Editor);
153 >      TFile(data.Field).Opened := True;
154      end;
112    VST.EndUpdate;
155    end;
156   end;
157  
116 procedure TForm_Meta.FormClose(Sender: TObject; var Action: TCloseAction);
117 begin
118  MetaManager.Free;
119  Action := caFree;
120 end;
121
158  
159 < procedure TForm_Meta.FormCreate(Sender: TObject);
159 > procedure TForm_Meta.VSTFocusChanging(Sender: TBaseVirtualTree; OldNode,
160 >  NewNode: PVirtualNode; OldColumn, NewColumn: TColumnIndex;
161 >  var Allowed: Boolean);
162   var
163 +  data: PNodeData;
164    i: Integer;
126
127  fn, datatype, boxstring: String;
128  level: Integer;
165   begin
166 <  combo_connection.ItemIndex := -1;
167 <  combo_connection.Items.Clear;
132 <  if ConManager.Count > 0 then
166 >  data := Sender.GetNodeData(NewNode);
167 >  if data.Field is TFile then
168    begin
169 <    for i := 0 to ConManager.Count - 1 do
170 <    begin
171 <      level := ConManager.ConnectionByIndex[i].LevelNumber;
172 <      fn := ExtractFileName(ConManager.ConnectionByIndex[i].FileName);
173 <      if ConManager.ConnectionByIndex[i].Backend = DB_ONI then
174 <        datatype := 'ONI-.dat: '
175 <      else if ConManager.ConnectionByIndex[i].Backend = DB_ADB then
176 <        datatype := 'OUP-DB: '
177 <      else
178 <        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
169 >    TFile(data.Field).InitEditor;
170 >    if Assigned(TFile(data.Field).Editor) then
171 >      Allowed := not TFile(data.Field).Opened
172 >    else
173 >      Allowed := True;
174 >  end;
175 >  if Allowed and Assigned(OldNode) then
176 >  begin
177 >    data := Sender.GetNodeData(OldNode);
178 >    if data.Field is TFile then
179      begin
180 <      combo_connection.ItemIndex := 0;
180 >      if TFile(data.Field).Opened then
181 >      begin
182 >        if tab_meta.ControlCount > 0 then
183 >          for i := 0 to tab_meta.ControlCount - 1 do
184 >            tab_meta.RemoveControl(tab_meta.Controls[i]);
185 >        TFile(data.Field).Opened := False;
186 >      end;
187      end;
188    end;
152
153
154  VST.NodeDataSize := SizeOf(TNodeData);
155  VST.Font.Charset := AppSettings.CharSet;
156  VST.Clear;
189   end;
190  
191  
160
192   procedure TForm_Meta.VSTGetText(Sender: TBaseVirtualTree; Node: PVirtualNode;
193    Column: TColumnIndex; TextType: TVSTTextType; var CellText: WideString);
194   var
# Line 170 | Line 201 | begin
201      case Column of
202        0:
203          begin
204 <          if Data.Field is TFile then
174 <          begin
175 <            CellText := TFile(Data.Field).FileName;
176 <            if CellText = '' then
177 <              CellText := 'Unnamed';
178 <          end;
204 >          CellText := Data.Field.GetCaption;
205          end;
206        1:
207          begin
208            if Data.Field is TFile then
209 <            CellText := TFile(Data.Field).FileExt;
209 >            CellText := TFile(Data.Field).FileInfo.Extension;
210          end;
211        2:
212          begin
213            if Data.Field is TFile then
214 <            CellText := IntToStr(TFile(Data.Field).FileID);
214 >            CellText := IntToStr(TFile(Data.Field).FileInfo.ID);
215 >        end;
216 >      3:
217 >        begin
218 >          if Data.Field is TDataField then
219 >            CellText := TDataField(Data.Field).ValueAsString;
220          end;
221      end;
222    end;
223   end;
224  
225 +
226   procedure TForm_Meta.VSTPaintText(Sender: TBaseVirtualTree;
227    const TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex;
228    TextType: TVSTTextType);
# Line 204 | Line 236 | begin
236        0:
237          begin
238            if Data.Field is TFile then
239 <            if Length(TFile(Data.Field).FileName) = 0 then
240 <              TargetCanvas.Font.Color := $000060;
239 >          begin
240 >            if Length(TFile(Data.Field).FileInfo.Name) = 0 then
241 >              TargetCanvas.Font.Color := $C06060;
242 >            if TFile(Data.Field).FileInfo.Size = 0 then
243 >              TargetCanvas.Font.Color := $2020A0;
244 >          end;
245          end;
246      end;
247    end;
248   end;
249  
214 {
250  
251 < procedure WriteStructureInfos;
251 >
252 > procedure TForm_Meta.VSTGetPopupMenu(Sender: TBaseVirtualTree;
253 >  Node: PVirtualNode; Column: TColumnIndex; const P: TPoint;
254 >  var AskParent: Boolean; var PopupMenu: TPopupMenu);
255   var
256 <  i, j:    Integer;
219 <  pdata:   PNodeData;
220 <  Data:    TNodeData;
221 <  node:    PVirtualNode;
256 >  data: PNodeData;
257   begin
258 <  VST.BeginUpdate;
259 <  if VST.RootNodeCount = 0 then
260 <  begin
226 <    structs := LoadStructureDefinition(ConID, fileid);
227 <    if structs.Data then
228 <    begin
229 <      if Length(structs.Global) > 0 then
230 <      begin
231 <        for i := 0 to High(structs.Global) do
232 <        begin
233 <          Data.Caption  := structs.Global[i].Name;
234 <          Data.Offset   := structs.Global[i].offset;
235 <          Data.DataType := structs.Global[i].datatype;
236 <          Data.Value    := GetValue(structs.Global[i].datatype, structs.Global[i].offset);
237 <          Data.Description := structs.Global[i].description;
238 <          AddVSTEntry(VST, nil, Data);
239 <        end;
240 <      end;
241 <      if Length(structs.Subs) > 0 then
242 <      begin
243 <        for i := 0 to High(structs.Subs) do
244 <        begin
245 <          with structs.Subs[i] do
246 <          begin
247 <            if Length(Entries) > 0 then
248 <            begin
249 <              if Pos('#', SubName) > 0 then
250 <              begin
251 <                Data.Offset  := StrToInt('$'+MidStr(SubName, Pos('#', SubName) + 1, 8));
252 <                Data.Value   := '$' +
253 <                  MidStr(SubName, PosEx('#', SubName, Pos('#', SubName) + 1) + 1, 8);
254 <                Data.Caption := MidStr(SubName, 1, Pos('#', SubName) - 1);
255 <                Data.Description := SubDesc;
256 <              end
257 <              else
258 <              begin
259 <                Data.Caption := SubName;
260 <                Data.Description := SubDesc;
261 <                Data.Offset := 0;
262 <                Data.Value := '';
263 <              end;
264 <              Data.DataType := 0;
265 <              node := AddVSTEntry(VST, nil, Data);
266 <              Data.Description := '';
267 <              for j := 0 to High(Entries) do
268 <              begin
269 <                Data.Caption  := Entries[j].Name;
270 <                Data.Offset   := Entries[j].offset;
271 <                Data.DataType := Entries[j].datatype;
272 <                Data.Value    := GetValue(Entries[j].datatype, Entries[j].offset);
273 <                Data.Description := Entries[j].description;
274 <                AddVSTEntry(VST, node, Data);
275 <              end;
276 <            end;
277 <          end;
278 <        end;
279 <      end;
280 <    end;
281 <    if VST.RootNodeCount > 0 then
282 <      VST.FocusedNode := VST.GetFirst;
283 <  end
284 <  else
258 >  inherited;
259 >  AskParent := False;
260 >  if Assigned(Node) then
261    begin
262 <    Node := VST.GetFirst;
263 <    while Assigned(Node) do
262 >    Sender.Selected[Node] := True;
263 >    Sender.FocusedNode := Node;
264 >    data := Sender.GetNodeData(Node);
265 >    if Column = 0 then
266      begin
267 <      pdata := VST.GetNodeData(Node);
268 <      if pdata.DataType > 0 then
269 <        pdata.Value := GetValue(pdata.Datatype, pdata.Offset);
270 <      Node := VST.GetNext(Node);
267 >      if TTreeElement(data.Field).GetChildCount > 0 then
268 >        PopupMenu := vst_popup
269 >      else
270 >        PopupMenu := nil;
271      end;
272    end;
295  VST.EndUpdate;
273   end;
274 < }
274 >
275 > procedure TForm_Meta.vst_newRootClick(Sender: TObject);
276 > var
277 >  data: PNodeData;
278 >  form: TForm_BaseTemplate;
279 > begin
280 >  inherited;
281 >  data := VST.GetNodeData(VST.FocusedNode);
282 >  form := nil;
283 >  form := Form_Main.open_child('meta');
284 >  if form is TForm_Meta then
285 >    TForm_Meta(form).SetRoot(data.Field);
286 > end;
287 >
288 > procedure TForm_Meta.vst_setRootClick(Sender: TObject);
289 > var
290 >  data: PNodeData;
291 > begin
292 >  inherited;
293 >  data := VST.GetNodeData(VST.FocusedNode);
294 >  SetRoot(data.Field);
295 > end;
296 >
297 > procedure TForm_Meta.FormClose(Sender: TObject; var Action: TCloseAction);
298 > begin
299 > //  Meta.Free;
300 >  inherited;
301 > end;
302 >
303 > procedure TForm_Meta.FormCreate(Sender: TObject);
304 > begin
305 >  inherited;
306 >  OnNewConnection := NewCon;
307 >
308 >  VST.NodeDataSize := SizeOf(TNodeData);
309 >  VST.Font.Charset := AppSettings.CharSet;
310 >  VST.Clear;
311 >
312 >  UpdateConList;
313 > end;
314 >
315   end.

Diff Legend

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