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 231 by alloc, Wed Jun 20 22:24:04 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;
8  
9   type
10 <  TForm_Meta = class(TForm)
10 >  TForm_Meta = class(TForm_BaseTemplate)
11      VST: TVirtualStringTree;
12 <    procedure FormClose(Sender: TObject; var Action: TCloseAction);
12 >    Panel2: TPanel;
13 >    splitter: TSplitter;
14      procedure FormCreate(Sender: TObject);
15 +    procedure VSTInitChildren(Sender: TBaseVirtualTree; Node: PVirtualNode;
16 +      var ChildCount: Cardinal);
17 +    procedure FormClose(Sender: TObject; var Action: TCloseAction);
18 +    procedure VSTFocusChanged(Sender: TBaseVirtualTree; Node: PVirtualNode;
19 +      Column: TColumnIndex);
20 +    procedure VSTFocusChanging(Sender: TBaseVirtualTree; OldNode,
21 +      NewNode: PVirtualNode; OldColumn, NewColumn: TColumnIndex;
22 +      var Allowed: Boolean);
23      procedure VSTGetText(Sender: TBaseVirtualTree; Node: PVirtualNode;
24        Column: TColumnIndex; TextType: TVSTTextType; var CellText: WideString);
25 +    procedure VSTPaintText(Sender: TBaseVirtualTree;
26 +      const TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex;
27 +      TextType: TVSTTextType);
28    private
29 +    procedure NewCon(ID: Integer);
30    public
16    FileManager: TFileManager;
31    end;
32  
19 var
20  Form_Meta: TForm_Meta;
33  
34   implementation
23 uses
24  Data, _DataTypes, _FileTypes;
35   {$R *.dfm}
36 + uses _MetaManager, _MetaTypes, ConnectionManager, Data;
37  
38   type
39    PNodeData = ^TNodeData;
# Line 43 | Line 54 | begin
54   end;
55  
56  
57 <
58 < procedure TForm_Meta.FormClose(Sender: TObject; var Action: TCloseAction);
57 > procedure TForm_Meta.NewCon(ID: Integer);
58 > var
59 >  i: Integer;
60 >  data: TNodeData;
61 >  node: PVirtualNode;
62 >  Meta: TMetaManager;
63   begin
64 <  FileManager.Free;
65 <  Action := caFree;
64 >  if ID >= 0 then
65 >  begin
66 >    VST.Clear;
67 >    VST.BeginUpdate;
68 >    Meta := ConManager.Connection[ID].MetaData;
69 >    for i := 0 to Meta.FileCount - 1 do
70 >    begin
71 >      if Assigned(Meta.FileById[i]) then
72 >      begin
73 >        data.Field := Meta.FileById[i];
74 >        node := AddVSTEntry(VST, nil, data);
75 >        if Meta.FileById[i].ChildCount > 0 then
76 >          VST.HasChildren[node] := True;
77 >      end;
78 >    end;
79 >    VST.EndUpdate;
80 >  end;
81   end;
82  
83  
84 < procedure TForm_Meta.FormCreate(Sender: TObject);
84 > procedure TForm_Meta.VSTInitChildren(Sender: TBaseVirtualTree;
85 >  Node: PVirtualNode; var ChildCount: Cardinal);
86   var
87 <  a,b,c: Int64;
87 >  data: PNodeData;
88 >  newdata: TNodeData;
89 >  newnode: PVirtualNode;
90    i: Integer;
91 <  data: TNodeData;
91 >  id: Integer;
92 >  Meta: TMetaManager;
93   begin
94 <  VST.NodeDataSize := SizeOf(TNodeData);
95 <  VST.Font.Charset := AppSettings.CharSet;
96 <  VST.Clear;
94 >  data := Sender.GetNodeData(node);
95 >  Meta := ConManager.Connection[ID].MetaData;
96 >  for i := 0 to TFile(data.Field).ChildCount - 1 do
97 >  begin
98 >    id := TFile(data.Field).LinkByIndex[i].DestID;
99 >    Meta.InitFile(id);
100 >    newdata.Field := Meta.FileById[id];
101 >    newnode := AddVSTEntry(TCustomVirtualStringTree(Sender), Node, newdata);
102 >    if Meta.FileById[id].ChildCount > 0 then
103 >      Sender.HasChildren[newnode] := True;
104 >  end;
105 >  ChildCount := Sender.ChildCount[Node];
106 > end;
107  
64  QueryPerformanceFrequency(c);
65  QueryPerformanceCounter(a);
66  FileManager := TFileManager.Create(1);
67  QueryPerformanceCounter(b);
68  ShowMessage('Loading Done - ' + FloatToStr((b-a)/c) + 's');
108  
109 <  for i := 0 to FileManager.FileCount - 1 do
109 > procedure TForm_Meta.VSTFocusChanged(Sender: TBaseVirtualTree;
110 >  Node: PVirtualNode; Column: TColumnIndex);
111 > var
112 >  data: PNodeData;
113 > begin
114 >  data := Sender.GetNodeData(Node);
115 >  if data.Field is TFile then
116    begin
117 <    data.Field := FileManager.FileById[i];
118 <    AddVSTEntry(VST, nil, data);
117 >    TFile(data.Field).InitEditor;
118 >    if Assigned(TFile(data.Field).Editor) then
119 >    begin
120 >      panel2.InsertControl(TFile(data.Field).Editor);
121 >      TFile(data.Field).Opened := True;
122 >    end;
123    end;
124   end;
125  
126  
127 + procedure TForm_Meta.VSTFocusChanging(Sender: TBaseVirtualTree; OldNode,
128 +  NewNode: PVirtualNode; OldColumn, NewColumn: TColumnIndex;
129 +  var Allowed: Boolean);
130 + var
131 +  data: PNodeData;
132 +  i: Integer;
133 + begin
134 +  data := Sender.GetNodeData(NewNode);
135 +  if data.Field is TFile then
136 +  begin
137 +    TFile(data.Field).InitEditor;
138 +    if Assigned(TFile(data.Field).Editor) then
139 +      Allowed := not TFile(data.Field).Opened
140 +    else
141 +      Allowed := True;
142 +  end;
143 +  if Allowed and Assigned(OldNode) then
144 +  begin
145 +    data := Sender.GetNodeData(OldNode);
146 +    if data.Field is TFile then
147 +    begin
148 +      if TFile(data.Field).Opened then
149 +      begin
150 +        if panel2.ControlCount > 0 then
151 +          for i := 0 to panel2.ControlCount - 1 do
152 +            panel2.RemoveControl(panel2.Controls[i]);
153 +        TFile(data.Field).Opened := False;
154 +      end;
155 +    end;
156 +  end;
157 + end;
158 +
159  
160   procedure TForm_Meta.VSTGetText(Sender: TBaseVirtualTree; Node: PVirtualNode;
161    Column: TColumnIndex; TextType: TVSTTextType; var CellText: WideString);
# Line 86 | Line 167 | begin
167    if TextType = ttNormal then
168    begin
169      case Column of
170 <      0: begin
90 <        if Data.Field is TFile then
170 >      0:
171          begin
172 <          CellText := TFile(Data.Field).FileName;
172 >          if Data.Field is TFile then
173 >          begin
174 >            CellText := TFile(Data.Field).FileInfo.Name;
175 >            if CellText = '' then
176 >              CellText := 'Unnamed';
177 >          end;
178          end;
94      end;
95 {      0:
96        CellText := Data.Caption;
179        1:
180 <        if Data.DataType > 0 then
181 <          CellText := '0x' + IntToHex(Data.Offset, 8)
182 <        else if Data.Offset > 0 then
183 <          CellText := '0x' + IntToHex(Data.Offset, 8);
180 >        begin
181 >          if Data.Field is TFile then
182 >            CellText := TFile(Data.Field).FileInfo.Extension;
183 >        end;
184        2:
185 <        if Data.DataType > 0 then
186 <          CellText := GetDataType(Data.DataType);
187 <      3:
188 <        if Data.DataType > 0 then
189 <          CellText := Data.Value //GetValue(data.DataType, data.Offset)
108 <        else if Length(Data.Value) > 0 then
109 <          CellText := IntToStr(StrToInt(Data.Value)) + ' Bytes';
110 <      4:
111 <        CellText := Data.Description;
112 < }    end;
185 >        begin
186 >          if Data.Field is TFile then
187 >            CellText := IntToStr(TFile(Data.Field).FileInfo.ID);
188 >        end;
189 >    end;
190    end;
191   end;
192  
116 {
193  
194 < procedure WriteStructureInfos;
194 > procedure TForm_Meta.VSTPaintText(Sender: TBaseVirtualTree;
195 >  const TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex;
196 >  TextType: TVSTTextType);
197   var
198 <  i, j:    Integer;
121 <  pdata:   PNodeData;
122 <  Data:    TNodeData;
123 <  node:    PVirtualNode;
198 >  Data: PNodeData;
199   begin
200 <  VST.BeginUpdate;
201 <  if VST.RootNodeCount = 0 then
200 >  Data     := Sender.GetNodeData(Node);
201 >  if TextType = ttNormal then
202    begin
203 <    structs := LoadStructureDefinition(ConID, fileid);
204 <    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
203 >    case Column of
204 >      0:
205          begin
206 <          with structs.Subs[i] do
206 >          if Data.Field is TFile then
207            begin
208 <            if Length(Entries) > 0 then
209 <            begin
210 <              if Pos('#', SubName) > 0 then
211 <              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;
208 >            if Length(TFile(Data.Field).FileInfo.Name) = 0 then
209 >              TargetCanvas.Font.Color := $C06060;
210 >            if TFile(Data.Field).FileInfo.Size = 0 then
211 >              TargetCanvas.Font.Color := $2020A0;
212            end;
213          end;
181      end;
182    end;
183    if VST.RootNodeCount > 0 then
184      VST.FocusedNode := VST.GetFirst;
185  end
186  else
187  begin
188    Node := VST.GetFirst;
189    while Assigned(Node) do
190    begin
191      pdata := VST.GetNodeData(Node);
192      if pdata.DataType > 0 then
193        pdata.Value := GetValue(pdata.Datatype, pdata.Offset);
194      Node := VST.GetNext(Node);
214      end;
215    end;
197  VST.EndUpdate;
216   end;
217 < }
217 >
218 >
219 >
220 > procedure TForm_Meta.FormClose(Sender: TObject; var Action: TCloseAction);
221 > begin
222 > //  Meta.Free;
223 >  inherited;
224 > end;
225 >
226 > procedure TForm_Meta.FormCreate(Sender: TObject);
227 > begin
228 >  inherited;
229 >  OnNewConnection := NewCon;
230 >
231 >  VST.NodeDataSize := SizeOf(TNodeData);
232 >  VST.Font.Charset := AppSettings.CharSet;
233 >  VST.Clear;
234 >
235 >  UpdateConList;
236 > end;
237 >
238   end.

Diff Legend

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