Class InventoryDisplay

All Implemented Interfaces:
com.badlogic.gdx.utils.Disposable, Renderable, Comparable<Renderable>
Direct Known Subclasses:
CombatInventoryDisplay, PlayerInventoryDisplay

public abstract class InventoryDisplay extends UIComponent
Abstract class for displaying an inventory. Subclasses can extend this to implement specific types of inventory displays, such as player inventories, with additional features (e.g., hotBar, drag-and-drop).
  • Field Details

    • logger

      protected static final org.slf4j.Logger logger
    • inventory

      protected final Inventory inventory
    • numCols

      protected final int numCols
    • numRows

      protected final int numRows
  • Constructor Details

    • InventoryDisplay

      protected InventoryDisplay(Inventory inventory, int numCols, int hotBarCapacity, boolean displayHotBar, GdxGame game)
      Constructs a PlayerInventoryDisplay with the specified capacity and number of columns. The capacity must be evenly divisible by the number of columns.
      Parameters:
      inventory - The inventory from which to build the display
      numCols - The number of columns in the inventory display.
      Throws:
      IllegalArgumentException - if numCols is less than 1 or if capacity is not divisible by numCols.
  • Method Details

    • isMainGameScreen

      protected boolean isMainGameScreen()
      Checks if the current screen is an instance of MainGameScreen.
      Returns:
      true if the current screen is MainGameScreen, false otherwise.
    • create

      public void create()
      Initializes the component by setting up event listeners for toggling the inventory display and adding items.
      Overrides:
      create in class UIComponent
    • toggleMsg

      public abstract String toggleMsg()
    • draw

      public void draw(com.badlogic.gdx.graphics.g2d.SpriteBatch batch)
      Handles drawing of the component. The actual rendering is managed by the stage.
      Specified by:
      draw in class RenderComponent
      Parameters:
      batch - The SpriteBatch used for drawing.
    • getToggle

      public boolean getToggle()
      Determines if the toggle is active
      Returns:
      returns the toggle
    • toggleDisplay

      public void toggleDisplay()
      Toggles the inventory display on or off based on its current state.
    • addSlotListeners

      public void addSlotListeners(com.badlogic.gdx.scenes.scene2d.ui.ImageButton slot, AbstractItem item, int index)
      Adds listeners to the inventory slots for handling hover and click events. This allows items to be used and inventory to be regenerated.
      Parameters:
      slot - The ImageButton representing the inventory slot.
      item - The item in the slot.
      index - The index of the slot in the inventory.
    • enterSlot

      protected abstract void enterSlot(AbstractItem item)
    • exitSlot

      protected abstract void exitSlot(AbstractItem item)
    • useItem

      protected abstract void useItem(AbstractItem item, int index)
    • updateDisplay

      public void updateDisplay()
      Updates the display of the inventory (does not regenerate any of the images for any slot, simply creates a new table to hold them).
    • regenerateDisplay

      public void regenerateDisplay()
      Regenerates the entire inventory and hotBar display (recreates every image) This should only be used if the inventory has been changed (ie after sorting or loading). Otherwise, use updateDisplay.
    • dispose

      public void dispose()
      Disposes of the resources used by the component, including the window, table, and slots.
      Specified by:
      dispose in interface com.badlogic.gdx.utils.Disposable
      Overrides:
      dispose in class RenderComponent
    • getZIndex

      public float getZIndex()
      Description copied from interface: Renderable
      Z index controls rendering order within a layer. Higher Z index is drawn on top.
      Specified by:
      getZIndex in interface Renderable
      Overrides:
      getZIndex in class UIComponent
      Returns:
      The z-index for this component.
    • getNumCols

      public int getNumCols()
      return the num of cols
      Returns:
      num of cols
    • consumeItem

      protected void consumeItem(AbstractItem item, ItemUsageContext context, int index)
      Consumes an item from the inventory and triggers an event if successful.
      Parameters:
      item - The item to be consumed.
      context - The context in which the item is being used.
      index - The index of the item in the inventory.