| 4 |
|
|
| 5 |
|
uses |
| 6 |
|
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, |
| 7 |
< |
Dialogs, _BaseTemplate, ExtCtrls, VirtualTrees, StdCtrls; |
| 7 |
> |
Dialogs, _BaseTemplate, ExtCtrls, VirtualTrees, StdCtrls, ComCtrls, Grids, |
| 8 |
> |
MPHexEditor, Wrapgrid, VTHeaderPopup, Menus, _TreeElement; |
| 9 |
|
|
| 10 |
|
type |
| 11 |
|
TForm_Meta = class(TForm_BaseTemplate) |
| 12 |
|
VST: TVirtualStringTree; |
| 12 |
– |
Panel2: TPanel; |
| 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); |
| 37 |
|
procedure VSTInitChildren(Sender: TBaseVirtualTree; Node: PVirtualNode; |
| 38 |
|
var ChildCount: Cardinal); |
| 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 |
+ |
procedure VSTGetHint(Sender: TBaseVirtualTree; Node: PVirtualNode; |
| 56 |
+ |
Column: TColumnIndex; var LineBreakStyle: TVTTooltipLineBreakStyle; |
| 57 |
+ |
var HintText: WideString); |
| 58 |
|
private |
| 59 |
+ |
root: TTreeElement; |
| 60 |
|
procedure NewCon(ID: Integer); |
| 61 |
|
public |
| 62 |
+ |
procedure SetRoot(TreeElem: TTreeElement); |
| 63 |
|
end; |
| 64 |
|
|
| 65 |
|
|
| 66 |
|
implementation |
| 67 |
|
{$R *.dfm} |
| 68 |
< |
uses _MetaManager, _MetaTypes, ConnectionManager, Data; |
| 68 |
> |
uses _MetaManager, _MetaTypes, ConnectionManager, Data, _FileTypes, Main, |
| 69 |
> |
TypeDefs; |
| 70 |
|
|
| 71 |
|
type |
| 72 |
|
PNodeData = ^TNodeData; |
| 73 |
|
|
| 74 |
|
TNodeData = record |
| 75 |
< |
Field: TObject; |
| 75 |
> |
Field: TTreeElement; |
| 76 |
|
end; |
| 77 |
|
|
| 78 |
|
function AddVSTEntry(AVST: TCustomVirtualStringTree; ANode: PVirtualNode; |
| 88 |
|
|
| 89 |
|
|
| 90 |
|
procedure TForm_Meta.NewCon(ID: Integer); |
| 91 |
+ |
begin |
| 92 |
+ |
if ID >= 0 then |
| 93 |
+ |
SetRoot(ConManager.Connection[FConnectionID].MetaData.Root); |
| 94 |
+ |
//SetRoot(ConManager.Connection[FConnectionID].MetaData.FileById[454]); |
| 95 |
+ |
end; |
| 96 |
+ |
|
| 97 |
+ |
|
| 98 |
+ |
procedure TForm_Meta.SetRoot(TreeElem: TTreeElement); |
| 99 |
|
var |
| 100 |
|
i: Integer; |
| 101 |
|
data: TNodeData; |
| 102 |
|
node: PVirtualNode; |
| 62 |
– |
Meta: TMetaManager; |
| 103 |
|
begin |
| 104 |
< |
if ID >= 0 then |
| 104 |
> |
if FConnectionID <> TreeElem.ConnectionID then |
| 105 |
> |
SelectConnection(TreeElem.ConnectionID); |
| 106 |
> |
root := TreeElem; |
| 107 |
> |
VST.Clear; |
| 108 |
> |
VST.BeginUpdate; |
| 109 |
> |
for i := 0 to root.ChildCount - 1 do |
| 110 |
|
begin |
| 111 |
< |
VST.Clear; |
| 112 |
< |
VST.BeginUpdate; |
| 113 |
< |
Meta := ConManager.Connection[ID].MetaData; |
| 114 |
< |
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; |
| 111 |
> |
data.Field := root.Child[i]; |
| 112 |
> |
node := AddVSTEntry(VST, nil, data); |
| 113 |
> |
if data.Field.ChildCount > 0 then |
| 114 |
> |
VST.HasChildren[node] := True; |
| 115 |
|
end; |
| 116 |
+ |
VST.EndUpdate; |
| 117 |
|
end; |
| 118 |
|
|
| 83 |
– |
|
| 119 |
|
procedure TForm_Meta.VSTInitChildren(Sender: TBaseVirtualTree; |
| 120 |
|
Node: PVirtualNode; var ChildCount: Cardinal); |
| 121 |
|
var |
| 123 |
|
newdata: TNodeData; |
| 124 |
|
newnode: PVirtualNode; |
| 125 |
|
i: Integer; |
| 91 |
– |
id: Integer; |
| 92 |
– |
Meta: TMetaManager; |
| 126 |
|
begin |
| 127 |
|
data := Sender.GetNodeData(node); |
| 128 |
< |
Meta := ConManager.Connection[ID].MetaData; |
| 129 |
< |
for i := 0 to TFile(data.Field).ChildCount - 1 do |
| 128 |
> |
|
| 129 |
> |
if data.Field.ChildCount > 0 then |
| 130 |
|
begin |
| 131 |
< |
id := TFile(data.Field).LinkByIndex[i].DestID; |
| 132 |
< |
Meta.InitFile(id); |
| 133 |
< |
newdata.Field := Meta.FileById[id]; |
| 134 |
< |
newnode := AddVSTEntry(TCustomVirtualStringTree(Sender), Node, newdata); |
| 135 |
< |
if Meta.FileById[id].ChildCount > 0 then |
| 136 |
< |
Sender.HasChildren[newnode] := True; |
| 131 |
> |
for i := 0 to data.Field.ChildCount - 1 do |
| 132 |
> |
begin |
| 133 |
> |
newdata.Field := data.Field.Child[i]; |
| 134 |
> |
newnode := AddVSTEntry(TCustomVirtualStringTree(Sender), Node, newdata); |
| 135 |
> |
if newdata.Field.ChildCount > 0 then |
| 136 |
> |
Sender.HasChildren[newnode] := True; |
| 137 |
> |
end; |
| 138 |
|
end; |
| 139 |
|
ChildCount := Sender.ChildCount[Node]; |
| 140 |
|
end; |
| 141 |
|
|
| 142 |
|
|
| 143 |
+ |
|
| 144 |
|
procedure TForm_Meta.VSTFocusChanged(Sender: TBaseVirtualTree; |
| 145 |
|
Node: PVirtualNode; Column: TColumnIndex); |
| 146 |
|
var |
| 147 |
|
data: PNodeData; |
| 148 |
+ |
ffile: TFile; |
| 149 |
+ |
//******************************************************************* |
| 150 |
+ |
fs: TFileStream; |
| 151 |
+ |
//******************************************************************* |
| 152 |
|
begin |
| 153 |
|
data := Sender.GetNodeData(Node); |
| 154 |
+ |
ffile := nil; |
| 155 |
|
if data.Field is TFile then |
| 156 |
+ |
ffile := TFile(data.Field); |
| 157 |
+ |
if data.Field is _MetaTypes.TDatLink then |
| 158 |
+ |
if Assigned(_MetaTypes.TDatLink(data.Field).TargetFile) then |
| 159 |
+ |
ffile := TFile(_MetaTypes.TDatLink(data.Field).TargetFile); |
| 160 |
+ |
if Assigned(ffile) then |
| 161 |
|
begin |
| 162 |
< |
TFile(data.Field).InitEditor; |
| 118 |
< |
if Assigned(TFile(data.Field).Editor) then |
| 162 |
> |
if Assigned(ffile.Editor) then |
| 163 |
|
begin |
| 164 |
< |
panel2.InsertControl(TFile(data.Field).Editor); |
| 165 |
< |
TFile(data.Field).Opened := True; |
| 164 |
> |
ffile.Editor.Align := alClient; |
| 165 |
> |
tab_meta.InsertControl(ffile.Editor); |
| 166 |
> |
ffile.Opened := True; |
| 167 |
|
end; |
| 168 |
+ |
//******************************************************************* |
| 169 |
+ |
// fs := TFileStream.Create('C:\Spiele\Oni\GameDataFolder\tests\'+IntToStr(ffile.FileInfo.ID)+'_recreated.hex', fmCreate); |
| 170 |
+ |
// ffile.ReCreateFile(fs); |
| 171 |
+ |
// fs.Free; |
| 172 |
+ |
//******************************************************************* |
| 173 |
|
end; |
| 174 |
|
end; |
| 175 |
|
|
| 184 |
|
data := Sender.GetNodeData(NewNode); |
| 185 |
|
if data.Field is TFile then |
| 186 |
|
begin |
| 137 |
– |
TFile(data.Field).InitEditor; |
| 187 |
|
if Assigned(TFile(data.Field).Editor) then |
| 188 |
|
Allowed := not TFile(data.Field).Opened |
| 189 |
|
else |
| 196 |
|
begin |
| 197 |
|
if TFile(data.Field).Opened then |
| 198 |
|
begin |
| 199 |
< |
if panel2.ControlCount > 0 then |
| 200 |
< |
for i := 0 to panel2.ControlCount - 1 do |
| 201 |
< |
panel2.RemoveControl(panel2.Controls[i]); |
| 199 |
> |
if tab_meta.ControlCount > 0 then |
| 200 |
> |
for i := 0 to tab_meta.ControlCount - 1 do |
| 201 |
> |
tab_meta.RemoveControl(tab_meta.Controls[i]); |
| 202 |
|
TFile(data.Field).Opened := False; |
| 203 |
|
end; |
| 204 |
|
end; |
| 216 |
|
if TextType = ttNormal then |
| 217 |
|
begin |
| 218 |
|
case Column of |
| 219 |
< |
0: |
| 220 |
< |
begin |
| 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; |
| 179 |
< |
1: |
| 180 |
< |
begin |
| 181 |
< |
if Data.Field is TFile then |
| 182 |
< |
CellText := TFile(Data.Field).FileInfo.Extension; |
| 183 |
< |
end; |
| 219 |
> |
0: CellText := Data.Field.Caption; |
| 220 |
> |
1: CellText := data.Field.VType; |
| 221 |
|
2: |
| 222 |
|
begin |
| 223 |
< |
if Data.Field is TFile then |
| 224 |
< |
CellText := IntToStr(TFile(Data.Field).FileInfo.ID); |
| 223 |
> |
if Data.Field is TDataField then |
| 224 |
> |
CellText := TDataField(Data.Field).ValueAsString; |
| 225 |
|
end; |
| 226 |
|
end; |
| 227 |
|
end; |
| 254 |
|
|
| 255 |
|
|
| 256 |
|
|
| 257 |
+ |
procedure TForm_Meta.VSTGetHint(Sender: TBaseVirtualTree; Node: PVirtualNode; |
| 258 |
+ |
Column: TColumnIndex; var LineBreakStyle: TVTTooltipLineBreakStyle; |
| 259 |
+ |
var HintText: WideString); |
| 260 |
+ |
var |
| 261 |
+ |
data: PNodeData; |
| 262 |
+ |
CellText: WideString; |
| 263 |
+ |
|
| 264 |
+ |
i: Integer; |
| 265 |
+ |
links: TStrings; |
| 266 |
+ |
ifile: TFile; |
| 267 |
+ |
begin |
| 268 |
+ |
inherited; |
| 269 |
+ |
if Assigned(Node) then |
| 270 |
+ |
begin |
| 271 |
+ |
VSTGetText(Sender, Node, Column, ttNormal, CellText); |
| 272 |
+ |
if Length(CellText) > 0 then |
| 273 |
+ |
begin |
| 274 |
+ |
data := Sender.GetNodeData(Node); |
| 275 |
+ |
if data.Field is TDataField then |
| 276 |
+ |
begin |
| 277 |
+ |
case Column of |
| 278 |
+ |
0,1: HintText := TDataField(data.Field).Description; |
| 279 |
+ |
2: HintText := ''; |
| 280 |
+ |
end; |
| 281 |
+ |
end; |
| 282 |
+ |
if data.Field is TFile then |
| 283 |
+ |
begin |
| 284 |
+ |
ifile := TFile(data.Field); |
| 285 |
+ |
case Column of |
| 286 |
+ |
0: HintText := |
| 287 |
+ |
'FileID: ' + IntToStr(ifile.FileInfo.ID) + #13#10 + |
| 288 |
+ |
'Name: ' + ifile.FileInfo.Name + #13#10 + |
| 289 |
+ |
'Extension: ' + ifile.FileInfo.Extension + #13#10 + |
| 290 |
+ |
'.dat-size: ' + IntToStr(ifile.FileInfo.Size) + #13#10; |
| 291 |
+ |
end; |
| 292 |
+ |
end; |
| 293 |
+ |
end; |
| 294 |
+ |
end |
| 295 |
+ |
else |
| 296 |
+ |
HintText := ''; |
| 297 |
+ |
end; |
| 298 |
+ |
|
| 299 |
+ |
procedure TForm_Meta.VSTGetPopupMenu(Sender: TBaseVirtualTree; |
| 300 |
+ |
Node: PVirtualNode; Column: TColumnIndex; const P: TPoint; |
| 301 |
+ |
var AskParent: Boolean; var PopupMenu: TPopupMenu); |
| 302 |
+ |
var |
| 303 |
+ |
data: PNodeData; |
| 304 |
+ |
begin |
| 305 |
+ |
inherited; |
| 306 |
+ |
AskParent := False; |
| 307 |
+ |
if Assigned(Node) then |
| 308 |
+ |
begin |
| 309 |
+ |
Sender.Selected[Node] := True; |
| 310 |
+ |
Sender.FocusedNode := Node; |
| 311 |
+ |
data := Sender.GetNodeData(Node); |
| 312 |
+ |
if Column = 0 then |
| 313 |
+ |
begin |
| 314 |
+ |
if TTreeElement(data.Field).ChildCount > 0 then |
| 315 |
+ |
PopupMenu := vst_popup |
| 316 |
+ |
else |
| 317 |
+ |
PopupMenu := nil; |
| 318 |
+ |
end; |
| 319 |
+ |
end; |
| 320 |
+ |
end; |
| 321 |
+ |
|
| 322 |
+ |
procedure TForm_Meta.vst_newRootClick(Sender: TObject); |
| 323 |
+ |
var |
| 324 |
+ |
data: PNodeData; |
| 325 |
+ |
form: TForm_BaseTemplate; |
| 326 |
+ |
begin |
| 327 |
+ |
inherited; |
| 328 |
+ |
data := VST.GetNodeData(VST.FocusedNode); |
| 329 |
+ |
form := nil; |
| 330 |
+ |
form := Form_Main.open_child('meta'); |
| 331 |
+ |
if form is TForm_Meta then |
| 332 |
+ |
TForm_Meta(form).SetRoot(data.Field); |
| 333 |
+ |
end; |
| 334 |
+ |
|
| 335 |
+ |
procedure TForm_Meta.vst_setRootClick(Sender: TObject); |
| 336 |
+ |
var |
| 337 |
+ |
data: PNodeData; |
| 338 |
+ |
begin |
| 339 |
+ |
inherited; |
| 340 |
+ |
data := VST.GetNodeData(VST.FocusedNode); |
| 341 |
+ |
SetRoot(data.Field); |
| 342 |
+ |
end; |
| 343 |
+ |
|
| 344 |
|
procedure TForm_Meta.FormClose(Sender: TObject; var Action: TCloseAction); |
| 345 |
|
begin |
| 346 |
|
// Meta.Free; |