Player HUD Shop - UQcsse3200/2026-studio-2 GitHub Wiki
Part of the Player HUD.
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.

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"
-
ShopDisplaybuilds 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 firesopenBlackjack). Buy is disabled wheneverShopComponent.canBuyis false (not enough gold, or no room in the inventory). -
ShopComponentowns the purchase rules.buyreturns aPurchaseResultofSUCCESS,INSUFFICIENT_GOLD,INVENTORY_FULL,ALREADY_OWNEDorINVALID. It re-looks-up the listing inShopCatalogand ignores any price supplied by the caller. Gold is deducted only after the item has been added, so a failed purchase never costs gold. -
ShopCatalogis the single place prices and quantities are defined.
-
create()builds the actors (hidden) and registers listeners foropenShop,closeShop,itemPurchased,purchaseFailed,inventoryChangedandgoldChanged. -
open()clears the selected listing, builds the layout, shows the greeting, refreshes, makes the panel visible and pauses the game. -
While open, events set a
dirtyflag. The nextdraw()refreshes the gold label and listings once. This is done indraw()because render callbacks still run while gameplay is paused. Success firesitemPurchased(status:Purchased <item>.); failure firespurchaseFailedwith a message shown in the status line. -
close()hides the panel and resumes the game. -
dispose()removes the panel and disposes the background and dim textures.
| 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 |
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.
- Automated:
ShopCatalogTest(4),ShopComponentTest(6) andShopDisplayTest(3) incore/src/test/.../components/shop/. - Manual: Shop section of the Player HUD Test Plan (SH-1 to SH-8).
- Back to the Player HUD hub
- Player HUD Test Plan
- Player Inventory