{{tag>dragonscript behavior}} [[:start|Start Page]] >> [[main|DragonScript Scripting Language]] >> [[abstractions#behavior_elementsquick_and_easy_development|Behavior Elements: Quick and Easy Development]] >> **ECBehaviorPlayerLookAtInteractPrompt** * [[behaviors_use_cases|Behaviors Explained: By Use-Case]] * [[behaviors_a_to_z|Behaviors Explained: From A to Z]] ====== ECBehaviorPlayerLookAtInteractPrompt ====== {{youtube>QXytMlYqe5U?medium}} Example usage of interact prompt behavior. Behavior element behavior adding look-at interact prompt support to player actor. If the actor is the player controlled actor creates a UI panel overlayed on the HUD showing interaction prompts. If the actor is not the active player actor destroys the UI panel. If the actor looks an an element supporting [[behavior_interactprompt|ECBehaviorInteractPrompt]] the UI panel is shown and updated with the prompt information. Otherwise the UI panel is cleared and hidden. The widget is shown inside a container Panel created by the behavior. The default layout of the panel is CentrizedBoxLayout. Change the layout instance to use your own. While player is the active actor this behavior polls every frame update for changes in prompts and updates the prompt display. This ensures dynamic changes on prompts can be detected. While the player is not the active actor this behavior disables per-frame updates to not waste performance. If the look-at behavior is disabled this behavior is showing no interact prompts. If is though possible to temporarily disabled this behavior no matter if the look-at behavior is enabled or disabled. 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. This behavior is used for player actors only. ===== 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. 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 //PanelInteractPromptController// you can change what promtp widget is created. This is an example of such 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(), instance.getBindingIconHeight()) end end // create prompt controller instance public func new(BindingManager bindingManager, int bindingIconHeight) super(bindingManager, bindingIconHeight) 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, 2)) // columns=1, rows=2 // 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, 0.5, 0), block Panel p p.addWidget(panelInteractPrompt) end)) end) // runWhileBlockingLayout blocks layout calls for performance reasons doLayoutIfBlocked() end end ===== 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. //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. ====== Instance Counts ====== This behavior can be used only once on an element. The behavior always has identifier //empty string//. ====== Element Class Properties ====== Element class properties have the prefix **playerLookAtInteractPrompt.**. ===== 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" * Type integer * Minimum Value 1 * Default Value 32 * Example (*.deeclass) 32 ===== 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. * Full name: "interactPrompt.transparency" * Type integer * Minimum Value 0 * Maximum Value 1 * Default Value 1 * Example (*.deeclass) 0.75 ====== Required Behaviors ====== * [[behavior_playercontrollable|ECBehaviorPlayerControllable]] * [[behavior_lookat|ECBehaviorLookAt]] ====== Optional Behaviors ====== This behavior does not support optional behaviors. ====== Persistency ====== This behavior does not use persistency. ====== API Documentation ====== #@LinkApiDocDEDS2_HTML~classDragengine_1_1Scenery_1_1ECBehaviorInteractPrompt.html,ECBehaviorInteractPrompt~@#. Since DragonScript Module Version **1.1** ====== 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]]. ====== Element Class Example ====== class ObjectElementClass extends BehaviorElementClass public var ECBehaviorInteractPrompt interactPrompt public func new() super("ExampleObject") // create interact prompt behavior. shows an icon with the verb "Interact" underneath. // the player has to use the input he assigned to the "primaryAction" command. // also the prompt is only shown if the player looks at the bone named "bigBadButton". interactPrompt = ECBehaviorInteractPrompt.new(this) interactPrompt.getImage().setPath("interact.png") interactPrompt.getVerb().setValue(UnicodeString.newFromUTF8("Interact")) interactPrompt.getCommand().setValue("primaryAction") interactPrompt.getBones().add("bigBadButton") end end class PlayerElementClass extends BaseActorClass public var ECBehaviorLookAt lookAt public var ECBehaviorPlayerLookAtInteractPrompt playerLookAtInteractPrompt public func new() super("PlayerActor") // allow actor to figure out what the player is looking at lookAt = ECBehaviorLookAt.new(this) // show an interact prompt widget on screen. the behavior requires a couple of // parameters to work properly. // // you have to create a controller factory instance which allows the behavior // to create the prompt widget. // // then you also have to specify where the newly created prompt widget will be // added to. in this example the panel is added to the current WindowGameWorld. // this window uses a StackLayout which works best with PanelInteractPrompt. // the last parameter is the object layout settings to use while adding the // widget to the container. this is only required to be non-null if you use // layouts requiring extra information, for example BorderLayout. playerLookAtInteractPrompt = ECBehaviorPlayerLookAtInteractPrompt.new(this, \ getPlayerControlled(), lookAt, PanelInteractPromptController.ControllerFactory.new(), \ BaseGameApp.getApp().getWindowGameWorld(), null) end end