User Tools

Site Tools


dragengine:modules:dragonscript:behavior_playerlookatinteractprompt

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
dragengine:modules:dragonscript:behavior_playerlookatinteractprompt [2020/05/24 14:49] – created dragonlorddragengine:modules:dragonscript:behavior_playerlookatinteractprompt [2025/03/13 17:15] (current) dragonlord
Line 1: Line 1:
 {{tag>dragonscript behavior}} {{tag>dragonscript behavior}}
 <WRAP youarehere> <WRAP youarehere>
-[[:start|Start Page]] >> [[main|DragonScript Scripting Language]] >> [[abstractions#behavior_elementsquick_and_easy_development|Behavior Elements: Quick and Easy Development]] >> **ECBehaviorPlayerLookAtInteractPrompt**+[[:start|Start Page]] >> [[main|DragonScript Scripting Language]] >> [[dragengine:modules:dragonscript:abstractions|Abstraction Layers: How you want to build your Game]] >> [[dragengine:modules:dragonscript:behavior_elements|Behavior Elements]] >> **ECBehaviorPlayerLookAtInteractPrompt**
 </WRAP> </WRAP>
  
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 ''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: +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 prompt widget is created.  
-<code> + 
-// create prompt controller based on PanelInteractPromptController. this is the +See [[#element_class_example|Element Class Example]] for example code of a prompt controller.
-// 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 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 +
-</code>+
  
 ===== 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 ''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.+''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 **playerLookAtInteractPrompt.**.+Element class properties have the prefix ''playerLookAtInteractPrompt.'' .
  
 ===== 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 ''Input Module'' the device button or axis display image with the best matching size. 
-  * Type integer + 
-  * Minimum Value 1 +  * Full name: ''playerLookAtInteractPrompt.bindingIconHeight'' 
-  * Default Value 32 +  * Typeinteger 
-  * Example (*.deeclass) <code xml><integer name='interactPrompt.bindingIconHeight'>32</integer></code>+  * Default Value: ''32'' 
 +  * Restrictions: At least ''1'' 
 +  * Example (*.deeclass)<code xml><integer name='playerLookAtInteractPrompt.bindingIconHeight'>32</integer></code>
  
 ===== 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.
-  * Full name: "interactPrompt.transparency" + 
-  * Type integer +  * Full name: ''playerLookAtInteractPrompt.transparency'' 
-  * Minimum Value 0 +  * Typeinteger 
-  * Maximum Value 1 +  * Default Value: ''1'' 
-  * Default Value +  * Restrictions: At least ''0'' and at most ''1'' 
-  * Example (*.deeclass) <code xml><float name='interactPrompt.transparency'>0.75</float></code>+  * Example (*.deeclass)<code xml><float name='playerLookAtInteractPrompt.transparency'>0.75</float></code> 
 + 
 +===== visibleIfEmpty ===== 
 + 
 +Show prompt widget if no prompts are present. 
 + 
 +  * Full name: ''playerLookAtInteractPrompt.visibleIfEmpty'' 
 +  * Type: boolean 
 +  * Default Value: ''false'' 
 +  * Example (*.deeclass): <code xml><boolean name='playerLookAtInteractPrompt.visibleIfEmpty'>true</boolean></code> 
 + 
 +====== 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 ======
-[[https://developer.dragondreams.ch/docs/dragonscript/scriptapi/latest/classDragengine_1_1Scenery_1_1ECBehaviorInteractPrompt.html|ECBehaviorInteractPrompt]].+#@LinkApiDocDEDS2_HTML~classDragengine_1_1Scenery_1_1ECBehaviorInteractPrompt.html,ECBehaviorInteractPrompt~@#.
  
-Since DragonScript Module Version **1.1**+Since DragonScript Module Version ''1.1''
  
 ====== 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
 </code> </code>
 +
 +Example of a prompt controller:
 +<code>
 +// 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
 +</code>
 +
 +====== Behavior Factory ======
 +
 +Using element class supporting adding behaviors the behavior can be added like this:
 +<code xml>
 +<?xml version='1.0' encoding='UTF-8'?>
 +<elementClass name='MyClass' class='GenericBehaviorElement'>
 +  <behavior type='ECBehaviorPlayerLookAtInteractPrompt'>
 +    <!-- optional: use BaseGameApp command manager. game can add more supported values.
 +                   default is 'default' -->
 +    <string name='commandManager'>default</string>
 +    
 +    <!-- optional: use BaseGameApp binding manager. game can add more supported values.
 +                   default is 'default' -->
 +    <string name='bindingManager'>default</string>
 +    
 +    <!-- set element properties. omit property prefix if used inside behavior tag -->
 +    <integer name='.bindingIconHeight'>32</integer>
 +  </behavior>
 +</elementClass>
 +</code>
 +
 +====== Live Examples ======
 +
 +  * [[https://github.com/LordOfDragons/deexamples|DEExamples Repository]]
 +
dragengine/modules/dragonscript/behavior_playerlookatinteractprompt.1590331781.txt.gz · Last modified: 2020/05/24 14:49 by dragonlord