Skip to content

Player HUD Hotbar

Ayooluwa Fadeyibi edited this page Oct 18, 2026 · 1 revision

Player HUD: Hotbar

Part of the Player HUD.

Purpose

Shows the first row of the player's inventory as a row of item slots along the bottom edge of the screen. The selected slot has a brown border. Each slot is a Table with a rounded nine-patch background rather than an image atlas.

HUD hotbar

Class diagram

classDiagram
    class UIComponent {
        <<abstract>>
    }

    class InventoryBarDisplay {
        -Table root
        -Table table
        +create()
        -populateSlots()
        -createSlot(ItemType item, int count, boolean selected) Table
        -createEmptySlot(boolean selected) Table
        -refresh()
        -hideBar()
        -showBar()
    }

    class InventoryComponent {
        -List~InventorySlot~ slots
        +getHotbarSlotCount() int
        +getSelectedSlotIndex() int
        +getSlot(int index) InventorySlot
    }

    UIComponent <|-- InventoryBarDisplay
    InventoryBarDisplay --> InventoryComponent : reads (fetched live, not cached)
    InventoryComponent ..> InventoryBarDisplay : "inventoryChanged" event
    InventoryBarDisplay ..> InventorySlotStyle : styles slots
Loading

UML class diagram of InventoryBarDisplay: it extends UIComponent, reads InventoryComponent live on every refresh, and depends on InventorySlotStyle and ServiceLocator

InventoryComponent and InventorySlot are the data model; see Player Inventory for how items are added, stacked and swapped. This page only covers how that state is drawn.

Lifecycle

InventoryBarDisplay listens for these events on the player entity:

Event Effect
inventoryChanged, inventorySelectionChanged Full populateSlots() rebuild
backpackOpened / backpackClosed Hide / show the hotbar so it does not compete with the backpack grid
dictionaryOpened / dictionaryClosed Hide / show the hotbar while the item dictionary is open

Unlike the heart row, the hotbar is rebuilt rather than updated in place. populateSlots() calls table.clearChildren() and recreates one slot per hotbar index (inventory.getHotbarSlotCount()), asking InventoryComponent for each slot instead of keeping its own copy of the state. This is simpler than the heart row's pool-and-hide approach, but a change to one slot redraws all of them (selecting a different item redraws every slot, not just the two whose selection changed).

Each slot's background comes from InventorySlotStyle, a shared, cached NinePatchDrawable per state (normal or selected). Occupied slots (createSlot) show the item icon (from ItemType.getTexturePath()) and an x<count> label; empty slots (createEmptySlot) are just the background.

Public methods

The component is event-driven; there is nothing to call directly. To change what it shows, change the inventory:

Call Effect on the hotbar
inventory.addItem(...) / removeItem(...) Fires inventoryChanged, slots redraw
inventory.selectSlot(index) Fires inventorySelectionChanged, border moves

Tuning constants

In InventoryBarDisplay:

Constant Value Purpose
SLOT_WIDTH / SLOT_HEIGHT 90px Size of each slot
SLOT_SPACING 10px Gap between slots
ICON_SIZE 56px Size of the item icon inside a slot

Tests

Links

Clone this wiki locally