UI Components (6.0)
Documentation for the C# Placeable Selection UI components.
Overview
This guide shows how to use the Placeable Selection UI in the GridPlacement 6.0 C# plugin.
The goal is to:
- Display a list/grid of available placeables (single items and upgrade sequences).
- Let the player pick a placeable.
- Enter build mode for the selected placeable using the 6.0 services.
The implementation uses:
- Core services:
IPlaceableCatalog: The source of truth for available items.SelectionAdapter: Pure C# logic for filtering and selecting items.PlacementModeService: Tracks “which thing am I trying to place?”.
- Godot adapters:
PlaceableSelectionPanel: A Godot Control node that wraps theSelectionAdapter.
1. Prerequisites
Ensure a GPUserScopeRoot is in your scene (see Quick Start). This node initializes the ServiceRegistry required by the UI components.
2. Add a PlaceableSelectionPanel
In your UI scene (e.g. HUD or build menu):
- Create a
Controlnode. - Attach the C# script
GridPlacement.Godot.UI.PlaceableSelectionPanel. - (Optional) Set InitialCategoryFilter in the inspector, e.g.
buildings.
On _Ready, the panel will:
- Resolve
ServiceRegistryfromGPUserScopeRoot. - Resolve
IPlaceableCatalogandPlacementModeService. - Create a
SelectionAdapterand callInitialize(). - Apply the optional
InitialCategoryFilter.
Note: The panel does not create buttons automatically. It exposes the catalog data and selection signal so you can build your own UI layout (buttons, grid cells, etc.).
3. Building your UI
From GDScript or C# (Godot side), you can:
- Read the available items:
panel.Adapter.AvailableItems. - Read filtered items:
panel.Adapter.FilteredItems. - Connect to
PlaceableSelectedto react when a player picks something.
Example (C#)
| |
4. Interaction with Placement
SelectionAdaptercallsPlacementModeService.BeginPlacement(placeableId).PlacementModeServicestoresCurrentPlaceableIdand setsIsInPlacementMode = true.- Your targeting / manipulation systems should query
PlacementModeServiceto know what to preview.
5. Customizing the Catalog
The default catalog is populated by PlaceableCatalogBootstrap. For a real game, you will likely want to register your own IPlaceableCatalog implementation in the ServiceRegistry before the UI initializes, or populate the default one with your own data.