This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
dragengine:modules:dragonscript:behavior_playerinteractprompt [2024/03/14 16:56] – dragonlord | dragengine:modules:dragonscript:behavior_playerinteractprompt [2025/03/13 17:15] (current) – dragonlord | ||
---|---|---|---|
Line 1: | Line 1: | ||
{{tag> | {{tag> | ||
<WRAP youarehere> | <WRAP youarehere> | ||
- | [[: | + | [[: |
</ | </ | ||
Line 27: | Line 27: | ||
It is possible to temporarily disabled this behavior. This allows to hide interact prompts for example if the player is performing an action where he is not able to interact with anything, for example being in a conversation or playing a cutscene. | It is possible to temporarily disabled this behavior. This allows to hide interact prompts for example if the player is performing an action where he is not able to interact with anything, for example being in a conversation or playing a cutscene. | ||
+ | |||
+ | See [[# | ||
This behavior is used for player actors only. | This behavior is used for player actors only. | ||
Line 32: | Line 34: | ||
===== 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 | + | |
- | // fastest way to get started. otherwise you can implement | + | |
- | // ECBehaviorPlayerInteractPrompt.PromptController to customize everything | + | |
- | class CustomPromptController extends PanelInteractPromptController | + | |
- | // factory creating instances of CustomPromptController | + | |
- | class ControllerFactory implements ECBehaviorPlayerInteractPrompt.PromptControllerFactory | + | |
- | // create instance of prompt controller | + | |
- | public func new() | + | |
- | end | + | |
- | + | ||
- | // create prompt controller | + | |
- | public func ECBehaviorPlayerInteractPrompt.PromptController \ | + | |
- | createPromptController(ECBehaviorPlayerInteractPrompt.Instance instance) | + | |
- | return CustomPromptController.new(instance.getECBehavior().getBindingManager(), | + | |
- | end | + | |
- | end | + | |
- | + | ||
- | // create prompt controller instance | + | |
- | public func new(BindingManager bindingManager, | + | |
- | end | + | |
- | + | ||
- | // create prompt widget. place the prompts in the lower right corner of the screen. | + | |
- | protected func void createContent(PanelInteractPrompt panelInteractPrompt) | + | |
- | super.createContent(PanelInteractPrompt panelInteractPrompt) | + | |
- | + | ||
- | // the two numbers indicate the relative placement of the centrized box. | + | |
- | // the first number is the X axis and the second the Y axis. both values | + | |
- | // are one which means at the right edge and at the bottom edge. | + | |
- | setLayout(CentrizedBoxLayout.new(LayoutAxis.x, | + | |
- | 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: "interactPrompt.bindingIconHeight" | + | 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. | ||
+ | |||
+ | ===== acceptInteractPrompt ===== | ||
+ | |||
+ | Accept interact prompt to be shown. If all listeners return true the prompt is accepted otherwise rejected. | ||
====== Required Behaviors ====== | ====== Required Behaviors ====== | ||
+ | |||
* [[behavior_playercontrollable|ECBehaviorPlayerControllable]] | * [[behavior_playercontrollable|ECBehaviorPlayerControllable]] | ||
====== 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 situation dependend interactions the player can do. This can be for example a sitting player shown how he can get up or an energy bar filled up and the player can now do a special attack. Requires the player to use ECBehaviorInteractPrompt enabled/ | * Show situation dependend interactions the player can do. This can be for example a sitting player shown how he can get up or an energy bar filled up and the player can now do a special attack. Requires the player to use ECBehaviorInteractPrompt enabled/ | ||
Line 151: | Line 154: | ||
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 | ||
+ | // ECBehaviorPlayerInteractPrompt.PromptController to customize everything | ||
+ | class CustomPromptController extends PanelInteractPromptController | ||
+ | // factory creating instances of CustomPromptController | ||
+ | class ControllerFactory implements ECBehaviorPlayerInteractPrompt.PromptControllerFactory | ||
+ | // create instance of prompt controller | ||
+ | public func new() | ||
+ | end | ||
+ | | ||
+ | // create prompt controller | ||
+ | public func ECBehaviorPlayerInteractPrompt.PromptController \ | ||
+ | createPromptController(ECBehaviorPlayerInteractPrompt.Instance instance) | ||
+ | return CustomPromptController.new(instance.getECBehavior().getBindingManager(), | ||
+ | end | ||
+ | end | ||
+ | | ||
+ | // create prompt controller instance | ||
+ | public func new(BindingManager bindingManager, | ||
+ | end | ||
+ | | ||
+ | // create prompt widget. place the prompts in the lower right corner of the screen. | ||
+ | protected func void createContent(PanelInteractPrompt panelInteractPrompt) | ||
+ | super.createContent(PanelInteractPrompt panelInteractPrompt) | ||
+ | | ||
+ | // the two numbers indicate the relative placement of the centrized box. | ||
+ | // the first number is the X axis and the second the Y axis. both values | ||
+ | // are one which means at the right edge and at the bottom edge. | ||
+ | setLayout(CentrizedBoxLayout.new(LayoutAxis.x, | ||
+ | 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:// | ||
+ |