Compare commits

3 Commits

Author SHA1 Message Date
9bb15b7511 Convert BigRedButton ctor into just a Bundle
The BigRedButton isn't doing anything that requires the `Commands`, so
it'll be turned back into just a Bundle.
2025-08-26 13:01:49 -05:00
c567bc3706 Fix: Filter for BigRedButton in it's observers
There was no BRB component so the Observer systems would only filter for
`Button`, which matched against the close button by accident.
2025-08-26 12:54:46 -05:00
85499f4156 Move BigRedButton's input handling observers
But there's a bug... the `CloseButton`s now get colored red and pink.
2025-08-26 12:49:37 -05:00

View File

@@ -20,7 +20,11 @@ impl Plugin for GameUiPlugin {
.add_observer(CloseButton::hover_start)
.add_observer(CloseButton::hover_stop)
.add_observer(CloseButton::press_start)
.add_observer(CloseButton::press_stop);
.add_observer(CloseButton::press_stop)
.add_observer(BigRedButton::button_hover_start)
.add_observer(BigRedButton::button_hover_stop)
.add_observer(BigRedButton::button_press_start)
.add_observer(BigRedButton::button_press_stop);
}
}
@@ -87,10 +91,14 @@ fn machine_ui_base(commands: &mut Commands, header: impl Into<String>, theme: &U
pub struct BigRedButton;
impl BigRedButton {
// TODO: Hook up action handling (callback? Observer? Some other weird component?)
fn spawn_big_red_button(commands: &mut ChildSpawnerCommands, text: impl Into<String>) {
let mut builder = commands.spawn((
/// Default bundle for a Big Red Button. Remember to attach on-press observers!
///
/// I haven't figure out what will receive the on-press events, so I'm moving
/// the problem. It will not be the button's job to hook up the event notice.
fn bundle(text: impl Into<String>) -> impl Bundle {
(
Button,
BigRedButton,
Node {
width: Px(60.0),
height: Px(60.0),
@@ -112,11 +120,7 @@ impl BigRedButton {
TextColor(WHITE.into()),
TextShadow::default(),
],
));
builder.observe(BigRedButton::button_hover_start);
builder.observe(BigRedButton::button_hover_stop);
builder.observe(BigRedButton::button_press_start);
builder.observe(BigRedButton::button_press_stop);
);
}
/// Re-color the button when a pointer passes over it
@@ -124,7 +128,7 @@ impl BigRedButton {
event: Trigger<Pointer<Over>>,
// Get button background and border colors so we can change them.
// Filter for *changed* interactions, and only entities with a [`Button`]
mut button_colors: Query<(&mut BackgroundColor, &mut BorderColor), With<Button>>,
mut button_colors: Query<(&mut BackgroundColor, &mut BorderColor), With<BigRedButton>>,
ui_theme: Res<UiTheme>,
) {
// Get the components for only the Trigger's target entity
@@ -139,7 +143,7 @@ impl BigRedButton {
fn button_hover_stop(
event: Trigger<Pointer<Out>>,
mut button_colors: Query<(&mut BackgroundColor, &mut BorderColor), With<Button>>,
mut button_colors: Query<(&mut BackgroundColor, &mut BorderColor), With<BigRedButton>>,
ui_theme: Res<UiTheme>,
) {
if let Ok((mut bg, mut border)) = button_colors.get_mut(event.target()) {
@@ -150,7 +154,7 @@ impl BigRedButton {
fn button_press_start(
event: Trigger<Pointer<Pressed>>,
mut button_colors: Query<(&mut BackgroundColor, &mut BorderColor), With<Button>>,
mut button_colors: Query<(&mut BackgroundColor, &mut BorderColor), With<BigRedButton>>,
ui_theme: Res<UiTheme>,
) {
if let Ok((mut bg, mut border)) = button_colors.get_mut(event.target()) {
@@ -161,7 +165,7 @@ impl BigRedButton {
fn button_press_stop(
event: Trigger<Pointer<Released>>,
mut button_colors: Query<(&mut BackgroundColor, &mut BorderColor), With<Button>>,
mut button_colors: Query<(&mut BackgroundColor, &mut BorderColor), With<BigRedButton>>,
ui_theme: Res<UiTheme>,
) {
if let Ok((mut bg, mut border)) = button_colors.get_mut(event.target()) {