Hello!
Today I wrote a behavior custom component that controls TCastleScene animations. Overall my component works as I need.
But I can’t understand how to make a drop-down list of animations appear in the Castle Editor, like in TCastleThirdPersonNavigation and other:
I write property as it is done in the same TCastleThirdPersonNavigation:
property IndicatorAnimationInactive: String read FAnimationInactive write FAnimationInactive stored AnimationInactiveStored nodefault;
and default initialization in constructor. And I get this in the editor:
How can I assign this field as a list and fill it with animation’s names?
To have a nice drop-down, you need to implement TStringPropertyEditor
descendant, that lists all possible values for the given field (e.g. by querying available animation names on given scene) and register it.
See how CGE is doing it for TCastleScene.AutoAnimation
and various TCastleThirdPersonNavigation.Animation...
fields:
Note that, while we use a separate unit for these “property editors” classes in CGE, it is also possible to put these in the same unit that defines the original component. See e.g. how gamecontrols.pas in examples/advanced_editor/custom_component/ is doing it, relying on CASTLE_DESIGN_MODE
define.
This is admittedly not documented nicely at Custom Components | Manual | Castle Game Engine (we only hint at this possibility by " 8. Add “verbs” to the context menu for given component"). In general, that’s because it’s not a system specific to CGE The property editors are a concept implemented fully in LCL (in a way much compatible with Delphi, from what I know), and we just use Lazarus Object Inspector component in CGE editor.
To explore all the possibilities, you can take a look at LCL PropEdits
source code ( components/ideintf/propedits.pp · main · FPC / Lazarus / Lazarus · GitLab ).
1 Like
Thanks!!
I made it!
If some one interesting there is my custom component:
MySwitch.pas (11.6 KB)
This is switch which can be activated touching by character (Activator: TCastleTransform) and can indicate self state with animated item (Indicator: TCastleScene).
1 Like
HaHaHa! Naive baka!
When I try to change level (Container.View:= NextLevel;) by any event from my behavior I’ve got error:
(There It’s happening call to methods of objects that have already been deleted)
It seems I can’t initiate a change level from behavior (o_o)
I found solution of my problem.
I made class field (FGetToGo: TCastleView;) that initiated by nil. When my switch’s behavior call level change I store in this field new level (FGetToGo:= NextLevel;). And change level happening in update (TBaseViewPlay.Update(…)) of current level.