This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
dragengine:modules:dragonscript:behavior_playerlookatinteractprompt [2024/03/14 16:56] – dragonlord | dragengine:modules:dragonscript:behavior_playerlookatinteractprompt [2025/03/13 17:15] (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. | ||
====== Required Behaviors ====== | ====== Required Behaviors ====== | ||
+ | |||
* [[behavior_playercontrollable|ECBehaviorPlayerControllable]] | * [[behavior_playercontrollable|ECBehaviorPlayerControllable]] | ||
* [[behavior_lookat|ECBehaviorLookAt]] | * [[behavior_lookat|ECBehaviorLookAt]] | ||
====== Optional Behaviors ====== | ====== Optional Behaviors ====== | ||
+ | |||
This behavior does not support optional behaviors. | This behavior does not support optional behaviors. | ||
====== Persistency ====== | ====== Persistency ====== | ||
- | This behavior does not use persistency. | + | |
+ | This behavior does not required element class to be persistable (setPersistable). | ||
====== API Documentation ====== | ====== API Documentation ====== | ||
# | # | ||
- | 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 161: | ||
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=' | ||
+ | | ||
+ | <!-- set element properties. omit property prefix if used inside behavior tag --> | ||
+ | <integer name=' | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | ====== Live Examples ====== | ||
+ | |||
+ | * [[https:// | ||
+ |