Player HUD Shop - UQcsse3200/2026-studio-2 GitHub Wiki

Player HUD: Shop

Part of the Player HUD.

Purpose

The shop is a centred overlay opened by pressing F next to a shopkeeper NPC; pressing F again, or the Close button, closes it. Opening it pauses the game (EntityService.setPaused(true)) and closing it resumes. KeyboardPlayerInputComponent ignores gameplay keys other than F while it is open.

Shop overlay

Class diagram

classDiagram
    class UIComponent {
        <<abstract>>
    }

    class ShopDisplay {
        -Table listingsTable
        -Label goldLabel
        -Label statusLabel
        -boolean open
        -boolean dirty
        +open()
        +close()
        +isOpen() boolean
    }

    class ShopComponent {
        +buy(ShopListing) PurchaseResult
        +canBuy(ShopListing) boolean
        +canAfford(ShopListing) boolean
        +canStore(ShopListing) boolean
    }

    class ShopCatalog {
        +getListings() List~ShopListing~
        +getListing(ItemType) ShopListing
    }

    class ShopListing {
        -ItemType itemType
        -int price
        -int quantity
    }

    UIComponent <|-- ShopDisplay
    ShopDisplay --> ShopComponent : buy / canBuy
    ShopDisplay --> ShopCatalog : reads listings
    ShopComponent --> ShopCatalog : validates against
    ShopCatalog o-- ShopListing
    ShopComponent ..> ShopDisplay : "itemPurchased" / "purchaseFailed"
Loading
  • ShopDisplay builds the panel: the player's gold, one tile per catalog listing, a details panel, a status line and a Close button (plus a Play Blackjack button that closes the shop and fires openBlackjack). Buy is disabled whenever ShopComponent.canBuy is false (not enough gold, or no room in the inventory).
  • ShopComponent owns the purchase rules. buy returns a PurchaseResult of SUCCESS, INSUFFICIENT_GOLD, INVENTORY_FULL, ALREADY_OWNED or INVALID. It re-looks-up the listing in ShopCatalog and ignores any price supplied by the caller. Gold is deducted only after the item has been added, so a failed purchase never costs gold.
  • ShopCatalog is the single place prices and quantities are defined.

Lifecycle

  1. create() builds the actors (hidden) and registers listeners for openShop, closeShop, itemPurchased, purchaseFailed, inventoryChanged and goldChanged.
  2. open() clears the selected listing, builds the layout, shows the greeting, refreshes, makes the panel visible and pauses the game.
  3. While open, events set a dirty flag. The next draw() refreshes the gold label and listings once. This is done in draw() because render callbacks still run while gameplay is paused. Success fires itemPurchased (status: Purchased <item>.); failure fires purchaseFailed with a message shown in the status line.
  4. close() hides the panel and resumes the game.
  5. dispose() removes the panel and disposes the background and dim textures.

Public methods

Class Method Purpose
ShopDisplay open() / close() / isOpen() Show, hide and query the overlay (normally driven by openShop / closeShop)
ShopComponent buy(ShopListing) / buy(ItemType) Attempt a purchase, returns a PurchaseResult
ShopComponent canBuy / canAfford / canStore Purchase checks used to enable Buy
ShopCatalog getListings() / getListing(ItemType) Read the catalog

Tuning constants

Prices and quantities are placeholders (the player starts with 50 gold) and can be retuned in ShopCatalog without touching the UI:

Item Quantity Price
Standard arrow 5 10g
Fire arrow 5 15g
Ice arrow 5 15g
Health potion 1 8g
Speed potion 1 12g
Poison potion 1 12g

Layout in ShopDisplay is expressed as fractions of the shop scene image (SCENE_TABLE_TOP, SCENE_TABLE_WIDTH, SCENE_PANEL_*, SCENE_PLAQUE_*), with LISTING_COLUMNS = 6, REFERENCE_HEIGHT = 720, SCENE_SCREEN_FRACTION = 0.85 and a DIM_COLOR of 80% black behind the scene.

Tests

Links

⚠️ **GitHub.com Fallback** ⚠️