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 229 by alloc, Wed Jun 20 10:57: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, _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, _FileTypes, 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 >  a,b,c: Int64;
60 >  i: Integer;
61 >  data: TNodeData;
62 >  node: PVirtualNode;
63   begin
64 <  FileManager.Free;
65 <  Action := caFree;
64 > {
65 >  if ID >= 0 then
66 >  begin
67 >    QueryPerformanceFrequency(c);
68 >    QueryPerformanceCounter(a);
69 >    if not Assigned(Meta) then
70 >      Meta := TMetaManager.Create(ID, Self);
71 >    QueryPerformanceCounter(b);
72 >    ShowMessage('Loading Done - ' + FloatToStr((b-a)/c) + 's');
73 >
74 >    VST.Clear;
75 >    VST.BeginUpdate;
76 >    for i := 0 to Meta.FileCount - 1 do
77 >    begin
78 >      if Assigned(Meta.FileById[i]) then
79 >      begin
80 >        data.Field := Meta.FileById[i];
81 >        node := AddVSTEntry(VST, nil, data);
82 >        if Meta.FileById[i].ChildCount > 0 then
83 >          VST.HasChildren[node] := True;
84 >      end;
85 >    end;
86 >    VST.EndUpdate;
87 >  end;
88 > }
89   end;
90  
91  
92 < procedure TForm_Meta.FormCreate(Sender: TObject);
92 > procedure TForm_Meta.VSTInitChildren(Sender: TBaseVirtualTree;
93 >  Node: PVirtualNode; var ChildCount: Cardinal);
94   var
95 <  a,b,c: Int64;
95 >  data: PNodeData;
96 >  newdata: TNodeData;
97 >  newnode: PVirtualNode;
98    i: Integer;
99 <  data: TNodeData;
99 >  id: Integer;
100   begin
101 <  VST.NodeDataSize := SizeOf(TNodeData);
102 <  VST.Font.Charset := AppSettings.CharSet;
103 <  VST.Clear;
101 > {
102 >  data := VST.GetNodeData(node);
103 >  for i := 0 to Meta.FileById[TFile(data.Field).FileID].ChildCount - 1 do
104 >  begin
105 >    id := Meta.FileById[TFile(data.Field).FileID].LinkByIndex[i].DestID;
106 >    Meta.InitFile(id);
107 >    newdata.Field := Meta.FileById[id];
108 >    newnode := AddVSTEntry(VST, Node, newdata);
109 >    if Meta.FileById[id].ChildCount > 0 then
110 >      VST.HasChildren[newnode] := True;
111 >  end;
112 >  ChildCount := Meta.FileById[TFile(data.Field).FileID].ChildCount;
113 > }
114 > end;
115  
64  QueryPerformanceFrequency(c);
65  QueryPerformanceCounter(a);
66  FileManager := TFileManager.Create(1);
67  QueryPerformanceCounter(b);
68  ShowMessage('Loading Done - ' + FloatToStr((b-a)/c) + 's');
116  
117 <  for i := 0 to FileManager.FileCount - 1 do
117 > procedure TForm_Meta.VSTFocusChanged(Sender: TBaseVirtualTree;
118 >  Node: PVirtualNode; Column: TColumnIndex);
119 > var
120 >  data: PNodeData;
121 > begin
122 >  data := Sender.GetNodeData(Node);
123 >  if data.Field is TFile then
124    begin
125 <    data.Field := FileManager.FileById[i];
126 <    AddVSTEntry(VST, nil, data);
125 >    TFile(data.Field).InitEditor;
126 >    if Assigned(TFile(data.Field).Editor) then
127 >    begin
128 >      panel2.InsertControl(TFile(data.Field).Editor);
129 >      TFile(data.Field).Opened := True;
130 >    end;
131    end;
132   end;
133  
134  
135 + procedure TForm_Meta.VSTFocusChanging(Sender: TBaseVirtualTree; OldNode,
136 +  NewNode: PVirtualNode; OldColumn, NewColumn: TColumnIndex;
137 +  var Allowed: Boolean);
138 + var
139 +  data: PNodeData;
140 +  i: Integer;
141 + begin
142 +  data := Sender.GetNodeData(NewNode);
143 +  if data.Field is TFile then
144 +  begin
145 +    TFile(data.Field).InitEditor;
146 +    if Assigned(TFile(data.Field).Editor) then
147 +      Allowed := not TFile(data.Field).Opened
148 +    else
149 +      Allowed := True;
150 +  end;
151 +  if Allowed and Assigned(OldNode) then
152 +  begin
153 +    data := Sender.GetNodeData(OldNode);
154 +    if data.Field is TFile then
155 +    begin
156 +      if TFile(data.Field).Opened then
157 +      begin
158 +        if panel2.ControlCount > 0 then
159 +          for i := 0 to panel2.ControlCount - 1 do
160 +            panel2.RemoveControl(panel2.Controls[i]);
161 +        TFile(data.Field).Opened := False;
162 +      end;
163 +    end;
164 +  end;
165 + end;
166 +
167  
168   procedure TForm_Meta.VSTGetText(Sender: TBaseVirtualTree; Node: PVirtualNode;
169    Column: TColumnIndex; TextType: TVSTTextType; var CellText: WideString);
# Line 86 | Line 175 | begin
175    if TextType = ttNormal then
176    begin
177      case Column of
178 <      0: begin
90 <        if Data.Field is TFile then
178 >      0:
179          begin
180 <          CellText := TFile(Data.Field).FileName;
180 >          if Data.Field is TFile then
181 >          begin
182 >            CellText := TFile(Data.Field).FileName;
183 >            if CellText = '' then
184 >              CellText := 'Unnamed';
185 >          end;
186          end;
94      end;
95 {      0:
96        CellText := Data.Caption;
187        1:
188 <        if Data.DataType > 0 then
189 <          CellText := '0x' + IntToHex(Data.Offset, 8)
190 <        else if Data.Offset > 0 then
191 <          CellText := '0x' + IntToHex(Data.Offset, 8);
188 >        begin
189 >          if Data.Field is TFile then
190 >            CellText := TFile(Data.Field).FileExt;
191 >        end;
192        2:
193 <        if Data.DataType > 0 then
194 <          CellText := GetDataType(Data.DataType);
195 <      3:
196 <        if Data.DataType > 0 then
197 <          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;
193 >        begin
194 >          if Data.Field is TFile then
195 >            CellText := IntToStr(TFile(Data.Field).FileID);
196 >        end;
197 >    end;
198    end;
199   end;
200  
116 {
201  
202 < procedure WriteStructureInfos;
202 > procedure TForm_Meta.VSTPaintText(Sender: TBaseVirtualTree;
203 >  const TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex;
204 >  TextType: TVSTTextType);
205   var
206 <  i, j:    Integer;
121 <  pdata:   PNodeData;
122 <  Data:    TNodeData;
123 <  node:    PVirtualNode;
206 >  Data: PNodeData;
207   begin
208 <  VST.BeginUpdate;
209 <  if VST.RootNodeCount = 0 then
208 >  Data     := Sender.GetNodeData(Node);
209 >  if TextType = ttNormal then
210    begin
211 <    structs := LoadStructureDefinition(ConID, fileid);
212 <    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
211 >    case Column of
212 >      0:
213          begin
214 <          with structs.Subs[i] do
214 >          if Data.Field is TFile then
215            begin
216 <            if Length(Entries) > 0 then
217 <            begin
218 <              if Pos('#', SubName) > 0 then
219 <              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;
216 >            if Length(TFile(Data.Field).FileName) = 0 then
217 >              TargetCanvas.Font.Color := $C06060;
218 >            if TFile(Data.Field).FileSize = 0 then
219 >              TargetCanvas.Font.Color := $2020A0;
220            end;
221          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);
222      end;
223    end;
197  VST.EndUpdate;
224   end;
225 < }
225 >
226 >
227 >
228 > procedure TForm_Meta.FormClose(Sender: TObject; var Action: TCloseAction);
229 > begin
230 > //  Meta.Free;
231 >  inherited;
232 > end;
233 >
234 > procedure TForm_Meta.FormCreate(Sender: TObject);
235 > begin
236 >  inherited;
237 >  OnNewConnection := NewCon;
238 >
239 >  VST.NodeDataSize := SizeOf(TNodeData);
240 >  VST.Font.Charset := AppSettings.CharSet;
241 >  VST.Clear;
242 >
243 >  UpdateConList;
244 > end;
245 >
246   end.

Diff Legend

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