This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
dragengine:modules:dragonscript:behavior_playerlookatinteractprompt [2020/05/24 14:49] – created dragonlord | dragengine:modules:dragonscript:behavior_playerlookatinteractprompt [2025/05/07 14:30] (current) – dragonlord | ||
---|---|---|---|
Line 1: | Line 1: | ||
{{tag> | {{tag> | ||
<WRAP youarehere> | <WRAP youarehere> | ||
- | [[: | + | [[: |
</ | </ | ||
Line 32: | Line 32: | ||
===== Prompt Widget ===== | ===== Prompt Widget ===== | ||
- | To display the prompt a prompt widget is required. This widget is created at the appropriate time by the behavior. For this to work you have to assign a //Prompt Controller Factory// while adding the behavior. THe //Prompt Controller Factory// is an interface knowing how to create an instance of a //Prompt Controller//. The //Prompt Controller// itself knows how to create the prompt widget, how to update the widget to reflect the visible prompts as well as how to apply transparency and visibility changes. | + | To display the prompt a prompt widget is required. This widget is created at the appropriate time by the behavior. For this to work you have to assign a '' |
- | The //PanelInteractPromptController// is the default prompt controller provided by the DragonScript module. It creates and manages an instance of //PanelInteractPrompt// which shows a horizontal list of prompts centered in the middle of the parent container. By subclassing | + | The '' |
- | < | + | |
- | // create prompt controller based on PanelInteractPromptController. this is the | + | See [[# |
- | // fastest way to get started. otherwise you can implement | + | |
- | // ECBehaviorPlayerLookAtInteractPrompt.PromptController to customize everything | + | |
- | class CustomPromptController extends PanelInteractPromptController | + | |
- | // factory creating instances of CustomPromptController | + | |
- | class ControllerFactory implements ECBehaviorPlayerLookAtInteractPrompt.PromptControllerFactory | + | |
- | // create instance of prompt controller | + | |
- | public func new() | + | |
- | end | + | |
- | + | ||
- | // create prompt controller | + | |
- | public func ECBehaviorPlayerLookAtInteractPrompt.PromptController \ | + | |
- | createPromptController(ECBehaviorPlayerLookAtInteractPrompt.Instance instance) | + | |
- | return CustomPromptController.new(instance.getECBehavior().getBindingManager(), | + | |
- | end | + | |
- | end | + | |
- | + | ||
- | // create prompt controller instance | + | |
- | public func new(BindingManager bindingManager, | + | |
- | end | + | |
- | + | ||
- | // create prompt widget. this solution here just changes how the prompt panel | + | |
- | // content is created to place the prompt underneath the screen center. this is | + | |
- | // a typical solution | + | |
- | // use BorderLayout to place the prompts at the top or bottom | + | |
- | protected func void createContent(PanelInteractPrompt panelInteractPrompt) | + | |
- | this.runWhileBlockingLayout(block | + | |
- | // split screen into 2 equally sized cells along the y axis | + | |
- | setLayout(GridLayout.new(1, | + | |
- | + | ||
- | // put a filler widget in upper half | + | |
- | addWidget(Widget.new()) | + | |
- | + | ||
- | // add prompt | + | |
- | // the 0.5 centers the box horizontally while 0 places the box at the top. | + | |
- | addWidget(Panel.new(CentrizedBoxLayout.new(LayoutAxis.x, | + | |
- | p.addWidget(panelInteractPrompt) | + | |
- | end)) | + | |
- | end) | + | |
- | + | ||
- | // runWhileBlockingLayout blocks layout calls for performance reasons | + | |
- | doLayoutIfBlocked() | + | |
- | end | + | |
- | end | + | |
- | </ | + | |
===== Container Widget ===== | ===== Container Widget ===== | ||
- | You have to specify where the prompt controller created prompt widget has to be shown in. Requires a //Container// instance with an optional layout settings instance. Layout settings instances are only required for certain layouts like BorderLayout. In general this can be null. | + | You have to specify where the prompt controller created prompt widget has to be shown in. Requires a '' |
- | //BaseGameApp.getApp().getWindowGameWorld()// is suitable as container UI since it uses StackLayout which works well with PanelInteractPrompt. You can though use any subclass of //Container// as long as you can provide the container instances early enough. | + | '' |
+ | |||
+ | ===== Behavior Factory ===== | ||
+ | |||
+ | The behavior factory script class is an abstract class. To use this behavior create a factory subclass and implement these functions: | ||
+ | ^Function^Description^ | ||
+ | |createPromptControllerFactory|Create prompt controller factory.| | ||
+ | |getUiContainer|Get UI container.| | ||
+ | |getUiContainerAddSettings|Get UI container add settings.| | ||
+ | |||
+ | This is required since these functions are so game specific that no sane default value can be provided. | ||
====== Instance Counts ====== | ====== Instance Counts ====== | ||
- | This behavior can be used only once on an element. The behavior always has identifier //empty string//. | + | This behavior can be used only once on an element. |
====== Element Class Properties ====== | ====== Element Class Properties ====== | ||
- | Element class properties have the prefix | + | Element class properties have the prefix |
===== bindingIconHeight ===== | ===== bindingIconHeight ===== | ||
- | Size in pixels to use for bindings to display. This is used to pick from the //Input Module// the device button or axis display image with the best matching size. | + | |
- | * Full name: " | + | Size in pixels to use for bindings to display. This is used to pick from the '' |
- | * Type integer | + | |
- | * Minimum | + | * Full name: '' |
- | * Default Value 32 | + | * Type: integer |
- | * Example (*.deeclass) <code xml>< | + | * Default |
+ | * Restrictions: | ||
+ | * Example (*.deeclass): <code xml>< | ||
===== transparency ===== | ===== transparency ===== | ||
+ | |||
Transparency of the prompt widget. The used prompt controller decides how the transparency is applied. The default prompt widget applies the transparency to the panel containing all displayed prompts. | Transparency of the prompt widget. The used prompt controller decides how the transparency is applied. The default prompt widget applies the transparency to the panel containing all displayed prompts. | ||
- | | + | |
- | * Type integer | + | |
- | * Minimum Value 0 | + | * Type: integer |
- | * Maximum | + | * Default |
- | * Default Value 1 | + | * Restrictions: |
- | * Example (*.deeclass) <code xml>< | + | * Example (*.deeclass): <code xml>< |
+ | |||
+ | ===== visibleIfEmpty ===== | ||
+ | |||
+ | Show prompt widget if no prompts are present. | ||
+ | |||
+ | * Full name: '' | ||
+ | * Type: boolean | ||
+ | * Default Value: '' | ||
+ | * Example (*.deeclass): | ||
+ | |||
+ | ====== Events ====== | ||
+ | |||
+ | This behavior has no events. | ||
+ | |||
+ | ====== Behavior Tree Actions ====== | ||
+ | |||
+ | This behavior adds these behavior tree actions if behavior tree is present. | ||
+ | |||
+ | ===== playerLookAtInteractPrompt.set ===== | ||
+ | |||
+ | Set one or more player look at interact prompt parameters. | ||
+ | |||
+ | ^Parameter^Value^Description^ | ||
+ | |enabled|'' | ||
+ | |||
+ | This is an example of using this action: | ||
+ | <code xml> | ||
+ | <action name=' | ||
+ | < | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | ===== playerLookAtInteractPrompt.check ===== | ||
+ | |||
+ | Check one or more player look at interact prompt parameters. Action succeeds if all parameter value matches their respective player look at interact prompt parameter otherwise action fails. This action is typically used as first action in a sequence to run the sequence only if a player look at interact prompt parameter matches (or not). | ||
+ | |||
+ | ^Parameter^Value^Description^ | ||
+ | |enabled|'' | ||
+ | |wait| |If present action returns BTResult.running instead of BTResult.failed to wait until the checks are all fulfilled| | ||
+ | |||
+ | This is an example of using this action: | ||
+ | <code xml> | ||
+ | < | ||
+ | <action name=' | ||
+ | < | ||
+ | </ | ||
+ | <!-- actions here run only if player look at interact prompt is enabled --> | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | ====== Behavior Tree Conditions ====== | ||
+ | |||
+ | This behavior adds these behavior tree conditions if behavior tree is present. | ||
+ | |||
+ | ===== playerLookAtInteractPrompt.check ===== | ||
+ | |||
+ | Check one or more player look at interact prompt parameters. Conditions returns true if all parameter value match their respective player look at interact prompt parameter. This condition is typically used to run an action or sequence of actions as long as player look at interact prompt conditions are true. | ||
+ | |||
+ | ^Parameter^Value^Description^ | ||
+ | |playerLookAtInteractPrompt.enabled|'' | ||
+ | |||
+ | This is an example of using this condition: | ||
+ | <code xml> | ||
+ | <action name=' | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | ====== State Machine Actions ====== | ||
+ | |||
+ | Same as [[# | ||
+ | |||
+ | ====== State Machine Conditions ====== | ||
+ | |||
+ | Same as [[# | ||
+ | |||
+ | ====== State Machine Events ====== | ||
+ | |||
+ | This behavior send no events to state machine. | ||
====== Required Behaviors ====== | ====== Required Behaviors ====== | ||
+ | |||
* [[behavior_playercontrollable|ECBehaviorPlayerControllable]] | * [[behavior_playercontrollable|ECBehaviorPlayerControllable]] | ||
* [[behavior_lookat|ECBehaviorLookAt]] | * [[behavior_lookat|ECBehaviorLookAt]] | ||
====== Optional Behaviors ====== | ====== Optional Behaviors ====== | ||
- | This behavior | + | |
+ | * [[behavior_behaviortree|ECBehaviorBehaviorTree]]: | ||
+ | * [[behavior_statemachine|ECBehaviorStateMachine]]: | ||
====== Persistency ====== | ====== Persistency ====== | ||
- | This behavior does not use persistency. | + | |
+ | This behavior does not required element class to be persistable (setPersistable). | ||
====== API Documentation ====== | ====== API Documentation ====== | ||
- | [[https:// | + | # |
- | Since DragonScript Module Version | + | Since DragonScript Module Version |
====== Use Cases ====== | ====== Use Cases ====== | ||
+ | |||
* Show how player can interact with objects in the game world he is looking at. Requires the object to use ECBehaviorInteractPrompt while the actor (player) requires to use [[behavior_lookat|ECBehaviorLookAt]] and [[behavior_playerlookatinteractprompt|ECBehaviorPlayerLookAtInteractPrompt]]. | * Show how player can interact with objects in the game world he is looking at. Requires the object to use ECBehaviorInteractPrompt while the actor (player) requires to use [[behavior_lookat|ECBehaviorLookAt]] and [[behavior_playerlookatinteractprompt|ECBehaviorPlayerLookAtInteractPrompt]]. | ||
Line 175: | Line 229: | ||
end | end | ||
</ | </ | ||
+ | |||
+ | Example of a prompt controller: | ||
+ | < | ||
+ | // create prompt controller based on PanelInteractPromptController. this is the | ||
+ | // fastest way to get started. otherwise you can implement | ||
+ | // ECBehaviorPlayerLookAtInteractPrompt.PromptController to customize everything | ||
+ | class CustomPromptController extends PanelInteractPromptController | ||
+ | // factory creating instances of CustomPromptController | ||
+ | class ControllerFactory implements ECBehaviorPlayerLookAtInteractPrompt.PromptControllerFactory | ||
+ | // create instance of prompt controller | ||
+ | public func new() | ||
+ | end | ||
+ | | ||
+ | // create prompt controller | ||
+ | public func ECBehaviorPlayerLookAtInteractPrompt.PromptController \ | ||
+ | createPromptController(ECBehaviorPlayerLookAtInteractPrompt.Instance instance) | ||
+ | return CustomPromptController.new(instance.getECBehavior().getBindingManager(), | ||
+ | end | ||
+ | end | ||
+ | | ||
+ | // create prompt controller instance | ||
+ | public func new(BindingManager bindingManager, | ||
+ | end | ||
+ | | ||
+ | // create prompt widget. this solution here just changes how the prompt panel | ||
+ | // content is created to place the prompt underneath the screen center. this is | ||
+ | // a typical solution for first-person handling. another solution would be to | ||
+ | // use BorderLayout to place the prompts at the top or bottom of the screen | ||
+ | protected func void createContent(PanelInteractPrompt panelInteractPrompt) | ||
+ | this.runWhileBlockingLayout(block | ||
+ | // split screen into 2 equally sized cells along the y axis | ||
+ | setLayout(GridLayout.new(1, | ||
+ | | ||
+ | // put a filler widget in upper half | ||
+ | addWidget(Widget.new()) | ||
+ | | ||
+ | // add prompt panel widget to a centrized box layout in the lower half. | ||
+ | // the 0.5 centers the box horizontally while 0 places the box at the top. | ||
+ | addWidget(Panel.new(CentrizedBoxLayout.new(LayoutAxis.x, | ||
+ | p.addWidget(panelInteractPrompt) | ||
+ | end)) | ||
+ | end) | ||
+ | | ||
+ | // runWhileBlockingLayout blocks layout calls for performance reasons | ||
+ | doLayoutIfBlocked() | ||
+ | end | ||
+ | end | ||
+ | </ | ||
+ | |||
+ | ====== Behavior Factory ====== | ||
+ | |||
+ | Using element class supporting adding behaviors the behavior can be added like this: | ||
+ | <code xml> | ||
+ | <?xml version=' | ||
+ | < | ||
+ | < | ||
+ | <!-- optional: use BaseGameApp command manager. game can add more supported values. | ||
+ | | ||
+ | <string name=' | ||
+ | | ||
+ | <!-- optional: use BaseGameApp binding manager. game can add more supported values. | ||
+ | | ||
+ | <string name=' | ||
+ | | ||
+ | <!-- optional: use behavior tree with id instead of empty string --> | ||
+ | <string name=' | ||
+ | | ||
+ | <!-- optional: use state machine with id instead of empty string --> | ||
+ | <string name=' | ||
+ | | ||
+ | <!-- set element properties. omit property prefix if used inside behavior tag --> | ||
+ | <integer name=' | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | ====== Live Examples ====== | ||
+ | |||
+ | * [[https:// | ||
+ |