Compare commits
3 Commits
1c0681e67e
...
9bb15b7511
| Author | SHA1 | Date | |
|---|---|---|---|
| 9bb15b7511 | |||
| c567bc3706 | |||
| 85499f4156 |
@@ -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()) {
|
||||
|
||||
Reference in New Issue
Block a user