Confirmation Popup

ChoicePopupController is a UIViewComponent that renders an N-button modal — Yes/No, Save/Discard/Cancel, or any custom set. Buttons are built dynamically from a serialized ChoicePopupChoice[] list (text + color), and the controller fires OnButtonClick(int index) so callers can handle each choice.

Confirmation Popup Example

Setup

1. UXML

The popup expects three named elements inside a UIDocument:

ElementName
LabelHeader
LabelBody
VisualElementButtonContainer

The controller fills ButtonContainer with one Button per ChoicePopupChoice on fade-in.

2. Add component + configure

Add ChoicePopupController to the GameObject. In the inspector:

  • _textHeader / _textBody — initial labels.
  • _choices — the button list (text + color name).
  • _buttonClasses — extra USS classes applied to every generated button (e.g. "btn-xl").

Confirmation Popup Inspector

3. Drive from code

csharp
[SerializeField] ChoicePopupController _popup; void OnDeleteClicked() { _popup.TextHeader = "Delete save?"; _popup.TextBody = "This cannot be undone."; _popup.Choices = new[] { new ChoicePopupChoice("Delete", "red"), new ChoicePopupChoice("Cancel", "slate"), }; _popup.OnButtonClick += OnConfirmDelete; _popup.UIView.Fade.FadeIn(); } void OnConfirmDelete(int index) { if (index == 0) DeleteSave(); _popup.OnButtonClick -= OnConfirmDelete; }

Use the standard UIView.Fade API (FadeIn, FadeOutThenDestroy) to show/hide.

API

csharp
namespace CupkekGames.Luna; public class ChoicePopupController : UIViewComponent

Properties

PropertyTypeDescription
ChoicesChoicePopupChoice[]Button list. Re-assigning rebuilds buttons on next fade-in.
TextHeaderstringRead/write the header label.
TextBodystringRead/write the body label.

Events

csharp
public event Action<int> OnButtonClick;

Fires with the index of the clicked choice. After click, all buttons are disabled and the popup fades out.

ChoicePopupChoice

csharp
public ChoicePopupChoice(string text, string color);

color is a Luna color-class name ("lime", "red", "slate", etc. — see colors). Applied as a USS class on the button alongside btn.

Default behaviour

  • Escape: A UIViewActionEscape(Fade.FadeOut) is registered on Awake, so Escape closes the popup with a fade-out.
  • Initial focus: First button gets keyboard focus on fade-in (gamepad-friendly).
  • Cleanup: On fade-out, the button container is cleared.

See also

Settings

Theme

Light

Contrast

Material

Dark

Dim

Material Dark

System

Sidebar(Light & Contrast only)

Light
Dark

Font Family

DM Sans

Wix

Inclusive Sans

AR One Sans

Direction

LTR
RTL