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 214 by alloc, Tue Jun 12 17:35:56 2007 UTC

# Line 2 | Line 2 | unit MetaEditor;
2   interface
3   uses
4    Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
5 <  Dialogs, VirtualTrees, _FileManager;
5 >  Dialogs, VirtualTrees, _MetaManager, StdCtrls, ExtCtrls;
6  
7   type
8    TForm_Meta = class(TForm)
9      VST: TVirtualStringTree;
10 +    Panel1: TPanel;
11 +    Button1: TButton;
12 +    combo_connection: TComboBox;
13 +    Label3: TLabel;
14 +    Splitter1: TSplitter;
15 +    Panel2: TPanel;
16      procedure FormClose(Sender: TObject; var Action: TCloseAction);
17      procedure FormCreate(Sender: TObject);
18      procedure VSTGetText(Sender: TBaseVirtualTree; Node: PVirtualNode;
19        Column: TColumnIndex; TextType: TVSTTextType; var CellText: WideString);
20 +    procedure Button1Click(Sender: TObject);
21 +    procedure VSTInitChildren(Sender: TBaseVirtualTree; Node: PVirtualNode;
22 +      var ChildCount: Cardinal);
23 +    procedure VSTPaintText(Sender: TBaseVirtualTree;
24 +      const TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex;
25 +      TextType: TVSTTextType);
26 +    procedure VSTFocusChanged(Sender: TBaseVirtualTree; Node: PVirtualNode;
27 +      Column: TColumnIndex);
28 +    procedure VSTFocusChanging(Sender: TBaseVirtualTree; OldNode,
29 +      NewNode: PVirtualNode; OldColumn, NewColumn: TColumnIndex;
30 +      var Allowed: Boolean);
31    private
32    public
16    FileManager: TFileManager;
33    end;
34  
35   var
# Line 21 | Line 37 | var
37  
38   implementation
39   uses
40 <  Data, _DataTypes, _FileTypes;
40 >  Data, _DataTypes, _FileTypes, ConnectionManager, TypeDefs, StrUtils;
41   {$R *.dfm}
42  
43   type
# Line 44 | Line 60 | end;
60  
61  
62  
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);
87 + var
88 +  name: String;
89 +  conid: Integer;
90 +
91 +  a,b,c: Int64;
92 +  i: Integer;
93 +  data: TNodeData;
94 +  node: PVirtualNode;
95 + begin
96 +  if combo_connection.ItemIndex >= 0 then
97 +  begin
98 +    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 +
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;
121 +  end;
122 + end;
123 +
124   procedure TForm_Meta.FormClose(Sender: TObject; var Action: TCloseAction);
125   begin
126 <  FileManager.Free;
126 >  Meta.Free;
127    Action := caFree;
128   end;
129  
130  
131   procedure TForm_Meta.FormCreate(Sender: TObject);
132   var
56  a,b,c: Int64;
133    i: Integer;
134 <  data: TNodeData;
134 >
135 >  fn, datatype, boxstring: String;
136 >  level: Integer;
137   begin
138 +  combo_connection.ItemIndex := -1;
139 +  combo_connection.Items.Clear;
140 +  if ConManager.Count > 0 then
141 +  begin
142 +    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
156 +    begin
157 +      combo_connection.ItemIndex := 0;
158 +    end;
159 +  end;
160 +
161 +
162    VST.NodeDataSize := SizeOf(TNodeData);
163    VST.Font.Charset := AppSettings.CharSet;
164    VST.Clear;
165 + end;
166 +
167  
64  QueryPerformanceFrequency(c);
65  QueryPerformanceCounter(a);
66  FileManager := TFileManager.Create(1);
67  QueryPerformanceCounter(b);
68  ShowMessage('Loading Done - ' + FloatToStr((b-a)/c) + 's');
168  
169 <  for i := 0 to FileManager.FileCount - 1 do
169 > procedure TForm_Meta.VSTFocusChanged(Sender: TBaseVirtualTree;
170 >  Node: PVirtualNode; Column: TColumnIndex);
171 > var
172 >  data: PNodeData;
173 > begin
174 >  data := Sender.GetNodeData(Node);
175 >  if data.Field is TFile then
176    begin
177 <    data.Field := FileManager.FileById[i];
178 <    AddVSTEntry(VST, nil, data);
177 >    TFile(data.Field).InitEditor;
178 >    if Assigned(TFile(data.Field).Editor) then
179 >    begin
180 >      panel2.InsertControl(TFile(data.Field).Editor);
181 >      TFile(data.Field).Opened := True;
182 >    end;
183    end;
184   end;
185  
186 <
186 > procedure TForm_Meta.VSTFocusChanging(Sender: TBaseVirtualTree; OldNode,
187 >  NewNode: PVirtualNode; OldColumn, NewColumn: TColumnIndex;
188 >  var Allowed: Boolean);
189 > var
190 >  data: PNodeData;
191 >  i: Integer;
192 > begin
193 >  data := Sender.GetNodeData(NewNode);
194 >  if data.Field is TFile then
195 >  begin
196 >    TFile(data.Field).InitEditor;
197 >    if Assigned(TFile(data.Field).Editor) then
198 >      Allowed := not TFile(data.Field).Opened
199 >    else
200 >      Allowed := True;
201 >  end;
202 >  if Allowed and Assigned(OldNode) then
203 >  begin
204 >    data := Sender.GetNodeData(OldNode);
205 >    if data.Field is TFile then
206 >    begin
207 >      if TFile(data.Field).Opened then
208 >      begin
209 >        if panel2.ControlCount > 0 then
210 >          for i := 0 to panel2.ControlCount - 1 do
211 >            panel2.RemoveControl(panel2.Controls[i]);
212 >        TFile(data.Field).Opened := False;
213 >      end;
214 >    end;
215 >  end;
216 > end;
217  
218   procedure TForm_Meta.VSTGetText(Sender: TBaseVirtualTree; Node: PVirtualNode;
219    Column: TColumnIndex; TextType: TVSTTextType; var CellText: WideString);
# Line 86 | Line 225 | begin
225    if TextType = ttNormal then
226    begin
227      case Column of
228 <      0: begin
90 <        if Data.Field is TFile then
228 >      0:
229          begin
230 <          CellText := TFile(Data.Field).FileName;
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;
94      end;
95 {      0:
96        CellText := Data.Caption;
237        1:
238 <        if Data.DataType > 0 then
239 <          CellText := '0x' + IntToHex(Data.Offset, 8)
240 <        else if Data.Offset > 0 then
241 <          CellText := '0x' + IntToHex(Data.Offset, 8);
238 >        begin
239 >          if Data.Field is TFile then
240 >            CellText := TFile(Data.Field).FileExt;
241 >        end;
242        2:
243 <        if Data.DataType > 0 then
244 <          CellText := GetDataType(Data.DataType);
245 <      3:
246 <        if Data.DataType > 0 then
247 <          CellText := Data.Value //GetValue(data.DataType, data.Offset)
248 <        else if Length(Data.Value) > 0 then
249 <          CellText := IntToStr(StrToInt(Data.Value)) + ' Bytes';
250 <      4:
251 <        CellText := Data.Description;
252 < }    end;
243 >        begin
244 >          if Data.Field is TFile then
245 >            CellText := IntToStr(TFile(Data.Field).FileID);
246 >        end;
247 >    end;
248 >  end;
249 > end;
250 >
251 > procedure TForm_Meta.VSTPaintText(Sender: TBaseVirtualTree;
252 >  const TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex;
253 >  TextType: TVSTTextType);
254 > var
255 >  Data: PNodeData;
256 > begin
257 >  Data     := Sender.GetNodeData(Node);
258 >  if TextType = ttNormal then
259 >  begin
260 >    case Column of
261 >      0:
262 >        begin
263 >          if Data.Field is TFile then
264 >          begin
265 >            if Length(TFile(Data.Field).FileName) = 0 then
266 >              TargetCanvas.Font.Color := $C06060;
267 >            if TFile(Data.Field).FileSize = 0 then
268 >              TargetCanvas.Font.Color := $2020A0;
269 >          end;
270 >        end;
271 >    end;
272    end;
273   end;
274  

Diff Legend

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