Paint towers with some the colors of the wind

This commit is contained in:
Ben Calegari 2026-06-02 23:59:44 -07:00
parent fec4433691
commit 04ead32846
15 changed files with 584 additions and 32 deletions

View file

@ -82,6 +82,10 @@ namespace TD.Gameplay
// it may not exist at OnNetworkSpawn time.
private TowerPlacementController cachedPlacementController;
// Cached reference to the local TowerPaintController, looked up lazily (same
// rationale as the placement controller).
private TowerPaintController cachedPaintController;
// ----- Lifecycle --------------------------------------------------
public override void OnNetworkSpawn()
@ -114,7 +118,9 @@ namespace TD.Gameplay
var keyboard = Keyboard.current;
if (mouse == null) return;
bool isPlacing = IsLocalPlayerPlacing();
// Placement and paint are both modal: while either is active, the local
// controller for that mode owns left-/right-click, so selection here yields.
bool isModal = IsLocalPlayerPlacing() || IsLocalPlayerPainting();
Vector2 mousePos = mouse.position.ReadValue();
// UI Toolkit dispatches button click events AFTER Update runs, but raw mouse
@ -123,9 +129,9 @@ namespace TD.Gameplay
// and deselects before the button's action fires. Same risk on right-click.
bool pointerOverHud = HUDController.IsPointerOverInteractiveHud(mousePos);
// Left-click: selection. Suppressed during placement mode (left-click is
// the placement-submit gesture there) and when the pointer is over HUD.
if (!isPlacing && !pointerOverHud && mouse.leftButton.wasPressedThisFrame)
// Left-click: selection. Suppressed during a modal mode (placement-submit /
// paint-apply own the click there) and when the pointer is over HUD.
if (!isModal && !pointerOverHud && mouse.leftButton.wasPressedThisFrame)
{
HandleLeftClickSelection(mousePos);
}
@ -140,9 +146,9 @@ namespace TD.Gameplay
SelectionState.Instance?.Clear();
}
// Right-click. Suppressed entirely during placement mode (TowerPlacementController
// handles right-click as cancel-placement there) and when over HUD.
if (isPlacing) return;
// Right-click. Suppressed entirely during a modal mode (placement/paint
// controllers handle right-click as cancel there) and when over HUD.
if (isModal) return;
if (pointerOverHud) return;
if (!mouse.rightButton.wasPressedThisFrame) return;
@ -251,5 +257,17 @@ namespace TD.Gameplay
}
return cachedPlacementController.IsPlacing;
}
private bool IsLocalPlayerPainting()
{
if (cachedPaintController == null)
{
// Find lazily — controller may have been added after this component spawned.
cachedPaintController =
UnityEngine.Object.FindAnyObjectByType<TowerPaintController>();
if (cachedPaintController == null) return false;
}
return cachedPaintController.IsPainting;
}
}
}