Skip to content

Overlays

remmy edited this page Sep 11, 2024 · 24 revisions

Introduction

Overlays act as effective entity containers while pausing (disabling) all existing entities. Overlay instances are unique and managed by their respective screens. This works as disabled entities are not updated by the game engine. All components also work this way except for the inputComponents as they are not actually components. Overlays work by holding a list of entities and conditionally enabling them or disabling them based on the status of the overlay. The Screen handles overlay management and will dictate which overlay is to be displayed.

  • TESTING: Visual testing was conducted for overlays please check sprint 2 form.

main overlay package: com.csse3200.game.overlays

Overlays-MainGameScreen sequence diagram

Note: overlays are usually triggered through listeners (player Entity's EventService) in PlayerActions where overlays are also added. Overlays are usually removed from within specific overlay screens upon pressing a button.

Sequence diagram

Other overlays

PauseOverlay

image

QuestOverlay

image

Usage

Pause overlay and Quest overlay pause the main game and sit on top. Waking and resting uses the following methods

These are the eventService methods that alter all entities regardless of overlays,

/**
   * Pause (disable) all entities so update in the gameplay loop doesn't occur for
   * the event and its components.
   */
  public void restWholeScreen() {
    for (Entity entity : entities) {
      entity.setEnabled(false);
    }
  }
  /**
   * Play (enable) all entities so update in the gameplay loop occurs for
   * the event and its components.
   */
  public void wakeWholeScreen() {
    for (Entity entity : entities) {
      entity.setEnabled(true);
    }
  }

Overlays contain the following methods and property:

/**
     * Puts the overlay into a resting state by disabling all entities.
     */
    public void rest() {
        for (Entity entity : this.entities) {
            entity.setEnabled(false);
        }
    }
    /**
     * Wakes the overlay by enabling all entities.
     */
    public void wake() {
        for (Entity entity : this.entities) {
            entity.setEnabled(true);
        }
    }
private final List<Entity> entities = new ArrayList<>();

The game screen manages the overlays with the following methods:

/**
   * Adds an overlay to the screen.
   * @param overlayType The type of overlay to add.
   */
  public void addOverlay(OverlayType overlayType){
    logger.debug("Attempting to Add {} Overlay", overlayType);
    if (activeOverlayTypes.get(overlayType)){
      return;
    }
      if (enabledOverlays.isEmpty()) {
          this.rest();
      }
      else {
        enabledOverlays.getFirst().rest();
      }
    switch (overlayType) {
      case QUEST_OVERLAY:
        enabledOverlays.addFirst(new QuestOverlay());
        break;
      case PAUSE_OVERLAY:
        enabledOverlays.addFirst(new PauseOverlay());
        break;
      default:
        logger.warn("Unknown Overlay type: {}", overlayType);
        break;
    }
    logger.info("Added {} Overlay", overlayType);
    activeOverlayTypes.put(overlayType,true);
  }
  /**
   * Removes the topmost overlay from the screen.
   */

  public void removeOverlay(){
    logger.info("Removing top Overlay");

    if (enabledOverlays.isEmpty()){
        this.wake();
        return;
    }
    Overlay currentFirst = enabledOverlays.getFirst();
    activeOverlayTypes.put(currentFirst.overlayType,false);
    currentFirst.remove();
    enabledOverlays.removeFirst();

    if (enabledOverlays.isEmpty()){
        this.wake();

    } else {
      enabledOverlays.getFirst().wake();
    }
  }
  /**
   * Puts the screen into a resting state, pausing music and resting all entities.
   */
  public void rest() {
    logger.info("Screen is resting");
    resting = true;
    gameArea.pauseMusic();
    ServiceLocator.getEntityService().restWholeScreen();
  }
  /**
   * Wakes the screen from a resting state.
   */
  public void wake() {
    logger.info("Screen is Awake");
    resting = false;
    ServiceLocator.getEventService().getGlobalEventHandler().trigger("resetVelocity");
    gameArea.playMusic();
    ServiceLocator.getEntityService().wakeWholeScreen();
  }

UML Diagram

This UML diagram represents an overview of the Overlays classes in the game, detailing their structure and interactions within the project.

Screenshot 2024-09-10 at 2 56 11 pm

Note: the green unlock symbol means public, the orange key means protected and the red lock means private.

the little hats on the (f) means final variable and, the star on the (f) means static variable

QuestDisplay: Represents quests menu display and logic for managing and displaying quests onto screen.

Attributes:

  • logger: Logger for debugging quests.
  • background: Background table for UI elements.
  • rootTable: Root table for UI elements.

Methods:

  • questComparator(): Comparator to sort quests.
  • QuestDisplay()Displays the quests.
  • create()Creates the display.
  • makeSliders()Creates and updates a table with slider.
  • addQuestsCompletedLabel(Table table)Creates and adds a label to the table that shows the number of completed quests.
  • addQuestComponents(Table table, AbstractQuest quest) Adds quest components to display.
  • determineQuestColor(AbstractQuest quest) Returns the color representing the quests' status.
  • refreshTheUI()Refreshes the UI so quest display components display properly without collision.
  • addQuestInfo(Table table, AbstractQuest quest) Adds quest description and hint labels
  • updateQuestsCompletedLabel(Table table, List<QuestBasic> questList) Updates and displays the number of quests completed.
  • makeMenuBtns() Creates and returns a table containing menu buttons
  • addActors() Adds actors to the stage for displaying the quest UI components.
  • update() Updates the quest UI based on time.
  • dispose() Disposes of assets used by the quest display.

QuestOverlay: Represents an overlay that displays quest-related information.

Attributes:

  • logger: Logger for debugging quests.
  • stage: The Stage object used to display UI components.
  • ui: Entity holding the quest display components and input decorator.

Methods:

  • QuestOverlay(): Constructor for initializing the QuestOverlay. It sets up the UI and logs the initialization.
  • rest(): Handles the rest state of the overlay. Logs the transition to the rest state and calls the superclass method.
  • wake(): Handles the wake state of the overlay. Logs the transition to the wake state and calls the superclass method.
  • createUI(): Creates and sets up the UI components for the quest overlay.

PauseDisplay: Represents the pause menu that pauses the screen.

Attributes:

  • logger: Logger for debugging pause display.
  • stage: The Stage object used to display UI components.
  • rootTable: The root table that holds and arranges the UI components.
  • screen: The screen instance.
  • game: The GdxGame instance to manage game screens.

Methods:

  • PauseDisplay(PausableScreen screen, GdxGame game): Constructor for initializing the PauseDisplay.
  • create(): Creates pausable screen.
  • addActors(): Sets up the UI components such as labels and buttons in the root table.
  • makeMenuBtns(): Creates and configures the buttons for the pause menu.
  • exitOverlay(): Removes the pause overlay from the screen.
  • openQuests(): Opens the quest overlay.
  • draw(SpriteBatch batch): Draws the UI components.
  • update(): Updates the stage.
  • dispose(): Clears the root table and disposes.

PauseOverlay: Represents an overlay that is displayed when the game is paused.

Attributes:

  • logger: Logger for debugging pause display.
  • stage: The Stage object used to display UI components.
  • game: The GdxGame instance to manage game screens.

Methods:

  • rest(): Handles the rest state of the overlay. Logs the transition to the rest state and calls the superclass method.
  • wake(): Handles the wake state of the overlay. Logs the transition to the wake state and calls the superclass method.
  • createUI(): Creates and sets up the UI components for the pause overlay.

This UML diagram encompasses all the dependencies and connections of the overlays class.

Clone this wiki locally