Class PromptComponent

java.lang.Object
com.csse3200.game.components.Component
com.csse3200.game.components.PromptComponent

public class PromptComponent extends Component
A component responsible for displaying a temporary prompt or tooltip when player collides with another entity.

The prompt text and display duration are configured upon instantiation.

  • Field Details

    • prompt

      public final String prompt
      The text content of the prompt/tooltip to be displayed.
    • duration

      public final Float duration
      The duration, in seconds, for which the prompt will be displayed.
  • Constructor Details

    • PromptComponent

      public PromptComponent(String prompt, Float duration)
      Creates a new PromptComponent with the specified prompt text and display duration.
      Parameters:
      prompt - The string content to display in the tooltip.
      duration - The time, in seconds, before the tooltip automatically disappears.
  • Method Details

    • create

      public void create()
      Registers a listener for "onCollisionStart" events. When a collision starts, the onCollide(Entity) method is executed.
      Overrides:
      create in class Component
    • onCollide

      protected boolean onCollide(Entity collector)
      Handles collision events.

      Displays the stored prompt using the TooltipSystem and schedules the tooltip to hide after the specified duration.

      Parameters:
      collector - The entity that has collided with this entity (and is thus the one "triggering" the prompt display).
      Returns:
      true to indicate the collision event was handled.