Placeable Selection UI (C# 6.0)
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:
GridBuilding.Core.Catalog.IPlaceableCatalogGridBuilding.Core.Catalog.SelectionAdapterGridBuilding.Core.Services.Placement.IPlacementService(backend placement)GridBuilding.Core.Services.PlacementModeService(“which thing am I trying to place?”)
- Godot adapters:
GridBuilding.Godot.Bootstrap.ServiceCompositionRootGridBuilding.Godot.UI.PlaceableSelectionPanel
1. Ensure ServiceCompositionRoot is in your scene
Add ServiceCompositionRoot as an autoload or as a root node in your main scene:
- In Godot, add the C# script
GridBuilding.Godot.Bootstrap.ServiceCompositionRootto aNode. - Mark it as an autoload (recommended) or place it at the top of your game scene.
At runtime this will:
- Create a
ServiceRegistry. - Register core services:
GridBuilding.Core.Services.Placement.PlacementServiceGridBuilding.Core.Catalog.PlaceableCatalog(seeded viaPlaceableCatalogBootstrap)GridBuilding.Core.Services.PlacementModeService
- Register Godot services:
GridBuilding.Godot.Services.Placement.SceneService
2. Add a PlaceableSelectionPanel to your UI
In your UI scene (e.g. HUD or build menu):
- Create a
Controlnode. - Attach the C# script
GridBuilding.Godot.UI.PlaceableSelectionPanel. - (Optional) Set InitialCategoryFilter in the inspector, e.g.
buildings.
On _Ready, the panel will:
- Resolve
ServiceRegistryfromServiceCompositionRoot. - Resolve
IPlaceableCatalogandPlacementModeServicefrom the registry. - Create a
SelectionAdapterand callInitialize(). - Apply the optional
InitialCategoryFilter. - Connect the adapter’s selection to the Godot signal
PlaceableSelected.
Note: The panel does not create buttons automatically. It exposes the catalog data and selection signal so you can build your own UI layout.
3. Building your actual UI grid
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# script on a parent UI node):
| |
4. How this interacts with placement and targeting
SelectionAdaptercallsPlacementModeService.BeginPlacement(placeableId).PlacementModeServicestoresCurrentPlaceableIdand flipsIsInPlacementMode = true.- Your targeting / manipulation systems should query
PlacementModeServiceto know:- Whether the player is in build mode.
- Which placeable ID to resolve to a
Placeableand preview.
- When the player cancels build mode, call
PlacementModeService.CancelPlacement()(e.g. via an input handler or UI cancel button).
The actual backend placement is still performed by
GridBuilding.Core.Services.Placement.IPlacementService and related
command services. The selection UI and PlacementModeService are responsible
only for which thing the player wants to place next.
5. Overriding the default catalog
The default catalog is populated by PlaceableCatalogBootstrap.SeedDefaults.
For a real game you will usually:
- Define your own data source (JSON, scriptable configs, DB, etc.).
- Replace the catalog registration in your own composition root, or
- Extend
ServiceCompositionRoot.RegisterCoreServicesin a fork.
Example override (pseudocode):
| |
As long as you implement IPlaceableCatalog and keep using
SelectionAdapter, the Placeable Selection UI will keep working.