| 1 |
{%MainUnit castlepropedits.pas} |
| 2 |
{ |
| 3 |
Copyright 2020-2020 Michalis Kamburelis. |
| 4 |
|
| 5 |
This file is part of "Castle Game Engine". |
| 6 |
|
| 7 |
"Castle Game Engine" is free software; see the file COPYING.txt, |
| 8 |
included in this distribution, for details about the copyright. |
| 9 |
|
| 10 |
"Castle Game Engine" is distributed in the hope that it will be useful, |
| 11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 13 |
|
| 14 |
---------------------------------------------------------------------------- |
| 15 |
} |
| 16 |
|
| 17 |
{ TCastleSceneCore.ExposeTransforms property editor. } |
| 18 |
|
| 19 |
{ TExposeTransformsPropertyEditor ------------------------------------------ } |
| 20 |
|
| 21 |
type |
| 22 |
{ Property editor to select transforms in TCastleSceneCore. } |
| 23 |
TExposeTransformsPropertyEditor = class(TStringsPropertyEditor) |
| 24 |
strict private |
| 25 |
DialogSelection: TExposeTransformSelection; // valid only during EnumTransformNode |
| 26 |
procedure EnumTransformNode(Node: TX3DNode); |
| 27 |
public |
| 28 |
procedure Edit; override; |
| 29 |
end; |
| 30 |
|
| 31 |
procedure TExposeTransformsPropertyEditor.EnumTransformNode(Node: TX3DNode); |
| 32 |
var |
| 33 |
TransformName: String; |
| 34 |
Item: TExposeTransformSelectionItem; |
| 35 |
begin |
| 36 |
if Node.X3DName <> '' then |
| 37 |
begin |
| 38 |
TransformName := Node.X3DName; |
| 39 |
if DialogSelection.FindName(TransformName) = nil then |
| 40 |
begin |
| 41 |
Item := TExposeTransformSelectionItem.Create; |
| 42 |
Item.Name := TransformName; |
| 43 |
Item.ExistsInScene := true; |
| 44 |
Item.Selected := false; // may be changed to true later |
| 45 |
DialogSelection.Add(Item); |
| 46 |
end; |
| 47 |
end; |
| 48 |
end; |
| 49 |
|
| 50 |
procedure TExposeTransformsPropertyEditor.Edit; |
| 51 |
var |
| 52 |
D: TExposeTransformsDialog; |
| 53 |
Scene: TCastleSceneCore; |
| 54 |
ValueStrings, SelectionList: TStrings; |
| 55 |
S: String; |
| 56 |
SelItem: TExposeTransformSelectionItem; |
| 57 |
begin |
| 58 |
D := TExposeTransformsDialog.Create(Application); |
| 59 |
try |
| 60 |
Scene := GetComponent(0) as TCastleSceneCore; |
| 61 |
D.Caption := 'Edit ' + Scene.Name + '.ExposeTransforms'; |
| 62 |
|
| 63 |
DialogSelection := D.Selection; |
| 64 |
DialogSelection.Clear; |
| 65 |
|
| 66 |
// add to D.Selection all possible transforms from the scene |
| 67 |
if Scene.RootNode <> nil then |
| 68 |
Scene.RootNode.EnumerateNodes(TTransformNode, @EnumTransformNode, false); |
| 69 |
|
| 70 |
// add/update in D.Selection all currently selected transforms |
| 71 |
ValueStrings := TStrings(GetObjectValue); |
| 72 |
for S in ValueStrings do |
| 73 |
if S <> '' then // ignore empty strings, just like TCastleSceneCore.ExposeTransformsChange does |
| 74 |
begin |
| 75 |
SelItem := D.Selection.FindName(S); |
| 76 |
if SelItem = nil then |
| 77 |
begin |
| 78 |
SelItem := TExposeTransformSelectionItem.Create; |
| 79 |
SelItem.Name := S; |
| 80 |
SelItem.ExistsInScene := false; |
| 81 |
DialogSelection.Add(SelItem); |
| 82 |
end; |
| 83 |
SelItem.Selected := true |
| 84 |
end; |
| 85 |
|
| 86 |
D.UpdateSelectionUi; |
| 87 |
if D.ShowModal = mrOK then |
| 88 |
begin |
| 89 |
SelectionList := DialogSelection.ToList; |
| 90 |
try |
| 91 |
SetPtrValue(SelectionList); |
| 92 |
finally FreeAndNil(SelectionList) end; |
| 93 |
end; |
| 94 |
Modified; |
| 95 |
finally FreeAndNil(D) end; |
| 96 |
end; |
| 97 |
|
| 98 |
|