User Tools

Site Tools


dragengine:modules:dragonscript:behavior_playerinteractprompt

ECBehaviorPlayerInteractPrompt

Example usage of interact prompt behavior.

Behavior element behavior adding interact prompt support to player actor.

In contrary to ECBehaviorPlayerLookAtInteractPrompt this behavior allows showing ECBehaviorInteractPrompt assigned to the player itself. This can be used show prompts if the player is doing something specific like sitting on a chair to show how he can get up or if the player is mounted on an object to show controls.

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 player has 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.

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.

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
// 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(), instance.getBindingIconHeight())
    end
  end
  
  // create prompt controller instance
  public func new(BindingManager bindingManager, int bindingIconHeight) super(bindingManager, bindingIconHeight)
  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, 1, 1)
  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 playerInteractPrompt..

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)
    <integer name='interactPrompt.bindingIconHeight'>32</integer>

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)
    <float name='interactPrompt.transparency'>0.75</float>

Required Behaviors

Optional Behaviors

This behavior does not support optional behaviors.

Persistency

This behavior does not use persistency.

API Documentation

ECBehaviorInteractPrompt.

Since DragonScript Module Version 1.2

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/disabled depending in the situation and ECBehaviorPlayerInteractPrompt to show the prompts.

Element Class Example

class PlayerElementClass extends BaseActorClass
   public var ECBehaviorPlayerInteractPrompt playerInteractPrompt
   
   public func new() super("PlayerActor")
     // 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.
     playerInteractPrompt = ECBehaviorPlayerInteractPrompt.new(this, \
        getPlayerControlled(), PanelInteractPromptController.ControllerFactory.new(), \
        BaseGameApp.getApp().getWindowGameWorld(), null)
     
     // create interact prompt behavior. shows an icon with the verb "Super Attack" underneath.
     // the player has to use the input he assigned to the "superAttack" command. The prompt
     // is disabled. Enable it dynamically during for example when a power bar is full.
     interactPrompt = ECBehaviorInteractPrompt.new(this)
     interactPrompt.getImage().setPath("superAttack.png")
     interactPrompt.getVerb().setValue(UnicodeString.newFromUTF8("Super Attack"))
     interactPrompt.getCommand().setValue("superAttack")
     interactPrompt.getEnabled().setValue(false)
   end
end
You could leave a comment if you were logged in.
dragengine/modules/dragonscript/behavior_playerinteractprompt.txt · Last modified: 2024/03/14 16:56 by dragonlord