14 Commits

Author SHA1 Message Date
c39b6d2120 Add a const OCTAGON and use it in map.rs
We could made a bunch of pre-built Card constatns for all the basic
shapes. That way we can `Card::OCTAGON` to create one, instead of typing
out the whole function call.
2025-08-27 12:57:02 -05:00
c0ed58e890 Give the Card an associated fn new()
So that we don't have to keep doing the `{ cells: ... ..default() }`
thing.
2025-08-27 12:52:58 -05:00
Patrick Gelvin
37cb394bf5 Initial card => tilemap 2025-08-27 07:51:13 -07:00
Patrick Gelvin
c81d17ce31 Initial fuckery with ecs tilemap 2025-08-27 07:50:23 -07:00
4d8c8b5302 Demo the UI with a dummy machine
This finally shows the basic operating principle of the machine UIs.
There will be some object out in the world that, when clicked, will open
a new UI screen to operate the machine.

Next up is to attach various bits of info, like a `Fuel` component on
the machine which the UI widget locates and displays as text. This gives
me the infrastructure necessary to begin that work.
2025-08-26 16:34:18 -05:00
112b22875a Fix doc on CloseButton::bundle() 2025-08-26 13:38:12 -05:00
9411e57759 Make CloseButton observer functions private
Now that there's a UI plugin, these systems don't need to be public. So
they won't be.
2025-08-26 13:35:40 -05:00
a489cdc5e8 Add some theme TODOs on the button widgets 2025-08-26 13:35:20 -05:00
5f617a67f6 Fix a couple of lints 2025-08-26 13:28:39 -05:00
9fb374059a Fix: Delete trailing semicolon in BRB::bundle()
Normally this would be a compilation error, but Bevy has an
`impl Bundle for ()` somewhere.

The intended bundle content gets discarded and a unit is implicitly
returned. That unit is implicitly converted into a `Bundle`, satisfying
the compiler.
2025-08-26 13:17:38 -05:00
cf9b415bb7 Update BigRedButton usage sites, add callback note 2025-08-26 13:17:03 -05:00
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
14 changed files with 609 additions and 41 deletions

View File

@@ -6,6 +6,7 @@ edition = "2024"
[dependencies] [dependencies]
bevy = { version = "0.16.1", features = ["dynamic_linking"] } bevy = { version = "0.16.1", features = ["dynamic_linking"] }
bevy-inspector-egui = "0.33.1" bevy-inspector-egui = "0.33.1"
bevy_ecs_tilemap = "0.16.0"
[profile.dev] [profile.dev]
opt-level = 1 opt-level = 1

View File

Before

Width:  |  Height:  |  Size: 317 B

After

Width:  |  Height:  |  Size: 317 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 110 B

View File

Before

Width:  |  Height:  |  Size: 159 B

After

Width:  |  Height:  |  Size: 159 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 123 B

View File

@@ -2,14 +2,14 @@ use bevy::prelude::*;
use std::path::Path; use std::path::Path;
pub struct TileImage { pub struct TileImage {
name: &'static str, pub name: &'static str,
thumbnail_handle: Handle<Image>, pub thumbnail_handle: Handle<Image>,
tile_handle: Handle<Image>, pub tile_handle: Handle<Image>,
} }
#[derive(Resource)] #[derive(Resource)]
pub struct AssetLibrary { pub struct AssetLibrary {
tile_images: Vec<TileImage>, pub tile_images: Vec<TileImage>,
} }
impl AssetLibrary { impl AssetLibrary {
@@ -33,7 +33,8 @@ impl AssetLibrary {
"corner-sw-3-walls", "corner-sw-3-walls",
"full-0-walls", "full-0-walls",
"full-1-wall", "full-1-wall",
"full-2-walls", "full-2-walls-corner",
"full-2-walls-hallway",
"full-3-walls", "full-3-walls",
"full-4-walls", "full-4-walls",
]; ];
@@ -59,6 +60,15 @@ impl AssetLibrary {
Self { tile_images } Self { tile_images }
} }
pub fn get_index(&self, name: &str) -> Option<u32> {
self
.tile_images
.iter()
.enumerate()
.find(|(_, tile)| tile.name == name)
.map(|(index, _)| index as u32)
}
pub fn get_thumbnail(&self, name: &str) -> Option<Handle<Image>> { pub fn get_thumbnail(&self, name: &str) -> Option<Handle<Image>> {
self self
.tile_images .tile_images

View File

@@ -14,6 +14,25 @@ pub enum Cell {
Filled, Filled,
} }
#[derive(Clone, Copy, Debug)]
pub struct Walls {
pub north: bool,
pub east: bool,
pub south: bool,
pub west: bool,
}
impl Walls {
pub fn new(north: bool, east: bool, south: bool, west: bool) -> Self {
Self {
north,
east,
south,
west,
}
}
}
#[derive(Clone, Copy, Debug)] #[derive(Clone, Copy, Debug)]
pub enum CutLine { pub enum CutLine {
VertLeft, VertLeft,
@@ -51,18 +70,36 @@ pub enum RotationDir {
/// *or may not* be valid, yet. /// *or may not* be valid, yet.
#[derive(Clone, Copy, Component, Debug, Default, PartialEq)] #[derive(Clone, Copy, Component, Debug, Default, PartialEq)]
pub struct Card { pub struct Card {
cells: [Cell; 9], pub cells: [Cell; 9],
nw: bool, pub nw: bool,
n: bool, pub n: bool,
ne: bool, pub ne: bool,
w: bool, pub w: bool,
e: bool, pub e: bool,
sw: bool, pub sw: bool,
s: bool, pub s: bool,
se: bool, pub se: bool,
} }
impl Card { impl Card {
/// Create a new card from the given Cell array
pub const fn new(cells: [Cell; 9]) -> Self {
Self {
cells,
nw: false,
n: false,
ne: false,
w: false,
e: false,
sw: false,
s: false,
se: false,
}
}
// TODO: The other shapes
pub const OCTAGON: Self = Self::new(OCTAGON);
/// Produces a new card by stacking another on top of this one. /// Produces a new card by stacking another on top of this one.
pub fn merge(self, top: Self) -> (Self, Option<Self>) { pub fn merge(self, top: Self) -> (Self, Option<Self>) {
let mut new_card = Self::default(); let mut new_card = Self::default();

426
src/game/map.rs Normal file
View File

@@ -0,0 +1,426 @@
use bevy::prelude::*;
use bevy_ecs_tilemap::prelude::*;
use crate::assets::AssetLibrary;
use crate::card::{Card, Cell, Walls};
pub fn setup_test_tilemap(mut commands: Commands, assets: Res<AssetLibrary>) {
let tilemap_entity = commands.spawn_empty().id();
let tilemap_id = TilemapId(tilemap_entity);
let map_size = TilemapSize { x: 9, y: 9 };
let mut tile_storage = TileStorage::empty(map_size);
let card = Card::OCTAGON;
add_card_to_tilemap(
&card,
&assets,
TilePos { x: 0, y: 2 },
tilemap_id,
&mut commands,
&mut tile_storage,
);
let tile_size = TilemapTileSize { x: 48.0, y: 48.0 };
let grid_size = tile_size.into();
let map_type = TilemapType::default();
let texture_handles = assets
.tile_images
.iter()
.map(|image| image.tile_handle.clone())
.collect();
commands.entity(tilemap_entity).insert(TilemapBundle {
grid_size,
map_type,
size: map_size,
storage: tile_storage,
texture: TilemapTexture::Vector(texture_handles),
tile_size,
anchor: TilemapAnchor::BottomLeft,
..Default::default()
});
}
/// Returns a cell description for a tilemap, including the texture index and a flip configuration
fn get_cell_description(
cell: &Cell,
walls: &Walls,
assets: &AssetLibrary,
) -> Option<(u32, TileFlip)> {
// Filter allowed walls
let walls = match cell {
Cell::NW => Walls {
north: false,
east: walls.east,
south: walls.south,
west: false,
},
Cell::NE => Walls {
north: false,
east: false,
south: walls.south,
west: walls.west,
},
Cell::SE => Walls {
north: walls.north,
east: false,
south: false,
west: walls.west,
},
Cell::SW => Walls {
north: walls.north,
east: walls.east,
south: false,
west: false,
},
_ => *walls,
};
let wall_count = (if walls.north { 1 } else { 0 })
+ (if walls.east { 1 } else { 0 })
+ (if walls.south { 1 } else { 0 })
+ (if walls.west { 1 } else { 0 });
match (cell, wall_count) {
(Cell::Empty, _) => None,
(Cell::NW, 0) => Some((
assets.get_index("corner-nw-1-wall").unwrap(),
TileFlip::default(),
)),
(Cell::NW, 1) => {
if walls.east {
Some((
assets.get_index("corner-nw-2-walls-east").unwrap(),
TileFlip::default(),
))
} else if walls.south {
Some((
assets.get_index("corner-nw-2-walls-south").unwrap(),
TileFlip::default(),
))
} else {
unreachable!()
}
}
(Cell::NW, 2) => Some((
assets.get_index("corner-nw-3-walls").unwrap(),
TileFlip::default(),
)),
(Cell::NE, 0) => Some((
assets.get_index("corner-ne-1-wall").unwrap(),
TileFlip::default(),
)),
(Cell::NE, 1) => {
if walls.west {
Some((
assets.get_index("corner-ne-2-walls-west").unwrap(),
TileFlip::default(),
))
} else if walls.south {
Some((
assets.get_index("corner-ne-2-walls-south").unwrap(),
TileFlip::default(),
))
} else {
unreachable!()
}
}
(Cell::NE, 2) => Some((
assets.get_index("corner-ne-3-walls").unwrap(),
TileFlip::default(),
)),
(Cell::SE, 0) => Some((
assets.get_index("corner-se-1-wall").unwrap(),
TileFlip::default(),
)),
(Cell::SE, 1) => {
if walls.west {
Some((
assets.get_index("corner-se-2-walls-west").unwrap(),
TileFlip::default(),
))
} else if walls.north {
Some((
assets.get_index("corner-se-2-walls-north").unwrap(),
TileFlip::default(),
))
} else {
unreachable!()
}
}
(Cell::SE, 2) => Some((
assets.get_index("corner-se-3-walls").unwrap(),
TileFlip::default(),
)),
(Cell::SW, 0) => Some((
assets.get_index("corner-sw-1-wall").unwrap(),
TileFlip::default(),
)),
(Cell::SW, 1) => {
if walls.east {
Some((
assets.get_index("corner-sw-2-walls-east").unwrap(),
TileFlip::default(),
))
} else if walls.north {
Some((
assets.get_index("corner-sw-2-walls-north").unwrap(),
TileFlip::default(),
))
} else {
unreachable!()
}
}
(Cell::SW, 2) => Some((
assets.get_index("corner-sw-3-walls").unwrap(),
TileFlip::default(),
)),
(Cell::Filled, 0) => Some((
assets.get_index("full-0-walls").unwrap(),
TileFlip::default(),
)),
(Cell::Filled, 1) => {
if walls.north {
Some((
assets.get_index("full-1-wall").unwrap(),
TileFlip::default(),
))
} else if walls.east {
Some((
assets.get_index("full-1-wall").unwrap(),
TileFlip {
x: true,
y: false,
d: true,
},
))
} else if walls.south {
Some((
assets.get_index("full-1-wall").unwrap(),
TileFlip {
x: false,
y: true,
d: false,
},
))
} else {
// walls.west
Some((
assets.get_index("full-1-wall").unwrap(),
TileFlip {
x: false,
y: false,
d: true,
},
))
}
}
(Cell::Filled, 2) => {
if walls.west && walls.north {
Some((
assets.get_index("full-2-walls-corner").unwrap(),
TileFlip::default(),
))
} else if walls.north && walls.east {
Some((
assets.get_index("full-2-walls-corner").unwrap(),
TileFlip {
x: true,
y: false,
d: false,
},
))
} else if walls.east && walls.south {
Some((
assets.get_index("full-2-walls-corner").unwrap(),
TileFlip {
x: true,
y: true,
d: false,
},
))
} else if walls.south && walls.west {
Some((
assets.get_index("full-2-walls-corner").unwrap(),
TileFlip {
x: false,
y: true,
d: false,
},
))
} else if walls.north && walls.south {
Some((
assets.get_index("full-2-walls-hallway").unwrap(),
TileFlip {
x: false,
y: false,
d: false,
},
))
} else if walls.east && walls.west {
Some((
assets.get_index("full-2-walls-hallway").unwrap(),
TileFlip {
x: false,
y: false,
d: true,
},
))
} else {
unreachable!()
}
}
(Cell::Filled, 3) => {
if !walls.north {
Some((
assets.get_index("full-3-walls").unwrap(),
TileFlip {
x: false,
y: true,
d: true,
},
))
} else if !walls.east {
Some((
assets.get_index("full-3-walls").unwrap(),
TileFlip::default(),
))
} else if !walls.south {
Some((
assets.get_index("full-3-walls").unwrap(),
TileFlip {
x: false,
y: false,
d: true,
},
))
} else if walls.west {
Some((
assets.get_index("full-3-walls").unwrap(),
TileFlip {
x: true,
y: false,
d: false,
},
))
} else {
unreachable!()
}
}
(Cell::Filled, 4) => Some((
assets.get_index("full-4-walls").unwrap(),
TileFlip::default(),
)),
_ => unreachable!(),
}
}
/// Returns an array of cell descriptions, starting from the top right tile and moving right to left, top to bottom
fn get_card_description(card: &Card, assets: &AssetLibrary) -> [Option<(u32, TileFlip)>; 9] {
let mut walls = [
Walls::new(true, false, false, true),
Walls::new(true, false, false, false),
Walls::new(true, true, false, false),
Walls::new(false, false, false, true),
Walls::new(false, false, false, false),
Walls::new(false, true, false, false),
Walls::new(false, false, true, true),
Walls::new(false, false, true, false),
Walls::new(false, true, true, false),
];
if card.cells[0] == Cell::Empty {
walls[1].west = true;
walls[3].north = true;
}
if card.cells[1] == Cell::Empty {
walls[0].east = true;
walls[2].west = true;
walls[4].north = true;
}
if card.cells[2] == Cell::Empty {
walls[1].east = true;
walls[5].north = true;
}
if card.cells[3] == Cell::Empty {
walls[0].south = true;
walls[4].west = true;
walls[6].north = true;
}
if card.cells[4] == Cell::Empty {
walls[1].south = true;
walls[3].east = true;
walls[5].west = true;
walls[7].north = true;
}
if card.cells[5] == Cell::Empty {
walls[2].south = true;
walls[4].east = true;
walls[8].north = true;
}
if card.cells[6] == Cell::Empty {
walls[7].west = true;
walls[3].south = true;
}
if card.cells[7] == Cell::Empty {
walls[6].east = true;
walls[8].west = true;
walls[4].south = true;
}
if card.cells[8] == Cell::Empty {
walls[7].east = true;
walls[5].south = true;
}
card
.cells
.iter()
.zip(walls.iter())
.map(|(cell, walls)| get_cell_description(cell, walls, assets))
.collect::<Vec<_>>()
.try_into()
.unwrap()
}
fn add_card_to_tilemap(
card: &Card,
assets: &AssetLibrary,
top_left: TilePos,
tilemap_id: TilemapId,
commands: &mut Commands,
tile_storage: &mut TileStorage,
) {
get_card_description(card, assets)
.iter()
.enumerate()
.for_each(|(index, desc)| {
let dx = (index as u32) % 3;
let dy = (index as u32) / 3;
let position = TilePos {
x: top_left.x + dx,
y: top_left.y - dy,
};
match desc {
Some((texture_index, flip)) => {
let tile_entity = commands
.spawn(TileBundle {
position,
tilemap_id,
texture_index: TileTextureIndex(*texture_index),
flip: *flip,
..Default::default()
})
.id();
tile_storage.set(&position, tile_entity);
}
None => {
tile_storage.remove(&position);
}
};
});
}

View File

@@ -1,5 +1,8 @@
use bevy::prelude::*; use bevy::prelude::*;
pub mod map;
pub mod player;
/// Data component for info about the player's current set of cards. /// Data component for info about the player's current set of cards.
/// ///
/// [`Self::capacity`] is the maximum hand size. /// [`Self::capacity`] is the maximum hand size.

28
src/game/player.rs Normal file
View File

@@ -0,0 +1,28 @@
use bevy::prelude::*;
#[derive(Component)]
#[require(Transform)]
pub struct Player;
pub fn spawn_player(
mut commands: Commands,
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<ColorMaterial>>,
) {
let shape = Circle::new(12.0);
let mesh = meshes.add(shape);
let color = Color::srgb(1., 0., 0.);
let material = materials.add(color);
commands.spawn((
Player,
Mesh2d(mesh),
MeshMaterial2d(material),
Transform::from_translation(Vec3 {
x: 72.,
y: 72.,
z: 1.,
}),
));
}

View File

@@ -1,7 +1,11 @@
use bevy::{prelude::*, window::WindowResolution}; use bevy::{color::palettes::css::GREEN, prelude::*, window::WindowResolution};
use bevy_ecs_tilemap::prelude::*;
use bevy_inspector_egui::{bevy_egui::EguiPlugin, quick::WorldInspectorPlugin}; use bevy_inspector_egui::{bevy_egui::EguiPlugin, quick::WorldInspectorPlugin};
use crate::game::machines::{CuttingMachine, RotatingMachine}; use crate::{
game::machines::{CuttingMachine, RotatingMachine},
resources::UiTheme,
};
mod assets; mod assets;
mod card; mod card;
@@ -21,20 +25,38 @@ fn main() {
.add_plugins(EguiPlugin::default()) .add_plugins(EguiPlugin::default())
.add_plugins(WorldInspectorPlugin::new()) .add_plugins(WorldInspectorPlugin::new())
.add_plugins(widgets::GameUiPlugin) .add_plugins(widgets::GameUiPlugin)
.add_plugins(TilemapPlugin)
.init_resource::<resources::UiTheme>()
.register_type::<resources::UiTheme>()
.add_systems( .add_systems(
Startup, Startup,
( (
setup, setup,
assets::load_assets, assets::load_assets,
RotatingMachine::spawn_ui, game::map::setup_test_tilemap,
CuttingMachine::spawn_ui, dummy_machine,
), )
.chain(),
) )
.run(); .run();
} }
fn setup(mut commands: Commands) { fn setup(mut commands: Commands) {
commands.spawn(Camera2d); commands.spawn((
Camera2d,
Projection::Orthographic(OrthographicProjection {
scaling_mode: bevy::render::camera::ScalingMode::AutoMin {
min_width: 360.0,
min_height: 240.0,
},
..OrthographicProjection::default_2d()
}),
Transform::from_translation(Vec3 {
x: 72.,
y: 72.,
z: 0.,
}),
));
} }
/// Generic utility for despawning entities that have a given component. /// Generic utility for despawning entities that have a given component.
@@ -43,3 +65,27 @@ fn despawn<T: Component>(mut commands: Commands, to_despawn: Query<Entity, With<
commands.entity(entity).despawn(); commands.entity(entity).despawn();
} }
} }
fn dummy_machine(
mut commands: Commands,
// mut meshes: ResMut<Assets<Mesh>>,
// mut materials: ResMut<Assets<ColorMaterial>>,
) {
commands
.spawn((
Sprite::from_color(GREEN, Vec2::splat(40.0)),
// WARN: Mesh picking is not part of the `DefaultPlugins` plugin collection!
// (but sprite picking is!)
// Mesh2d(meshes.add(Rectangle::new(25., 25.))),
// MeshMaterial2d(materials.add(ColorMaterial::from_color(GREEN))),
Transform::default(),
Pickable::default(),
))
.observe(
|event: Trigger<Pointer<Click>>, commands: Commands, theme: Res<UiTheme>| {
let entity = event.target;
CuttingMachine::spawn_ui(commands, theme);
},
);
}

View File

@@ -36,7 +36,7 @@ pub struct UiTheme {
} }
impl FromWorld for UiTheme { impl FromWorld for UiTheme {
fn from_world(world: &mut World) -> Self { fn from_world(_world: &mut World) -> Self {
Self { Self {
pane_bg: SLATE_100.into(), pane_bg: SLATE_100.into(),

View File

@@ -42,7 +42,11 @@ impl CuttingMachine {
BackgroundColor(DARK_GRAY.into()), BackgroundColor(DARK_GRAY.into()),
Pickable::default(), Pickable::default(),
)) ))
.with_children(|cmds| BigRedButton::spawn_big_red_button(cmds, "CUT")); .with_children(|cmds| {
let _button_cmds = cmds.spawn(BigRedButton::bundle("CUT"));
// TODO: Attach on-press observer so this machine can do something
// in response to that button being pressed
});
}); });
} }
} }
@@ -82,7 +86,10 @@ impl RotatingMachine {
BackgroundColor(DARK_GRAY.into()), BackgroundColor(DARK_GRAY.into()),
Pickable::default(), Pickable::default(),
)) ))
.with_children(|cmds| BigRedButton::spawn_big_red_button(cmds, "TURN")); .with_children(|cmds| {
let _button_cmds = cmds.spawn(BigRedButton::bundle("TURN"));
// TODO: Attach on-press observer to the button.
});
}); });
} }
} }

View File

@@ -20,7 +20,11 @@ impl Plugin for GameUiPlugin {
.add_observer(CloseButton::hover_start) .add_observer(CloseButton::hover_start)
.add_observer(CloseButton::hover_stop) .add_observer(CloseButton::hover_stop)
.add_observer(CloseButton::press_start) .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,17 @@ fn machine_ui_base(commands: &mut Commands, header: impl Into<String>, theme: &U
pub struct BigRedButton; pub struct BigRedButton;
impl BigRedButton { impl BigRedButton {
// TODO: Hook up action handling (callback? Observer? Some other weird component?) /// Default bundle for a Big Red Button. Remember to attach on-press observers!
fn spawn_big_red_button(commands: &mut ChildSpawnerCommands, text: impl Into<String>) { ///
let mut builder = commands.spawn(( /// 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.
///
/// TODO: Pass in the UiTheme struct
fn bundle(text: impl Into<String>) -> impl Bundle {
(
// TODO: Remove `Button`? Add `Button` to the `CloseButton` bundle?
Button, Button,
BigRedButton,
Node { Node {
width: Px(60.0), width: Px(60.0),
height: Px(60.0), height: Px(60.0),
@@ -112,11 +123,7 @@ impl BigRedButton {
TextColor(WHITE.into()), TextColor(WHITE.into()),
TextShadow::default(), 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 /// Re-color the button when a pointer passes over it
@@ -124,7 +131,7 @@ impl BigRedButton {
event: Trigger<Pointer<Over>>, event: Trigger<Pointer<Over>>,
// Get button background and border colors so we can change them. // Get button background and border colors so we can change them.
// Filter for *changed* interactions, and only entities with a [`Button`] // 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>, ui_theme: Res<UiTheme>,
) { ) {
// Get the components for only the Trigger's target entity // Get the components for only the Trigger's target entity
@@ -139,7 +146,7 @@ impl BigRedButton {
fn button_hover_stop( fn button_hover_stop(
event: Trigger<Pointer<Out>>, 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>, ui_theme: Res<UiTheme>,
) { ) {
if let Ok((mut bg, mut border)) = button_colors.get_mut(event.target()) { if let Ok((mut bg, mut border)) = button_colors.get_mut(event.target()) {
@@ -150,7 +157,7 @@ impl BigRedButton {
fn button_press_start( fn button_press_start(
event: Trigger<Pointer<Pressed>>, 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>, ui_theme: Res<UiTheme>,
) { ) {
if let Ok((mut bg, mut border)) = button_colors.get_mut(event.target()) { if let Ok((mut bg, mut border)) = button_colors.get_mut(event.target()) {
@@ -161,7 +168,7 @@ impl BigRedButton {
fn button_press_stop( fn button_press_stop(
event: Trigger<Pointer<Released>>, 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>, ui_theme: Res<UiTheme>,
) { ) {
if let Ok((mut bg, mut border)) = button_colors.get_mut(event.target()) { if let Ok((mut bg, mut border)) = button_colors.get_mut(event.target()) {
@@ -177,9 +184,12 @@ impl BigRedButton {
pub struct CloseButton(Entity); pub struct CloseButton(Entity);
impl CloseButton { impl CloseButton {
/// Spawn a button that will despawn the top-most node when pressed. /// Default bundle for a panel's close button. Pass in the entity to despawn.
///
/// TODO: Pass in the UiTheme struct
fn bundle(target: Entity) -> impl Bundle { fn bundle(target: Entity) -> impl Bundle {
( (
// TODO: Add `Button`? Remove `Button` from the BigRedButton bundle?
CloseButton(target), CloseButton(target),
Node { Node {
width: Px(20.0), width: Px(20.0),
@@ -204,7 +214,7 @@ impl CloseButton {
) )
} }
pub fn hover_start( fn hover_start(
event: Trigger<Pointer<Over>>, event: Trigger<Pointer<Over>>,
// Get button background and border colors so we can change them. // Get button background and border colors so we can change them.
// Filter for *changed* interactions, and only entities with a [`Button`] // Filter for *changed* interactions, and only entities with a [`Button`]
@@ -218,7 +228,7 @@ impl CloseButton {
} }
} }
pub fn hover_stop( fn hover_stop(
event: Trigger<Pointer<Out>>, event: Trigger<Pointer<Out>>,
mut button_colors: Query<(&mut BackgroundColor, &mut BorderColor), With<CloseButton>>, mut button_colors: Query<(&mut BackgroundColor, &mut BorderColor), With<CloseButton>>,
ui_theme: Res<UiTheme>, ui_theme: Res<UiTheme>,
@@ -229,7 +239,7 @@ impl CloseButton {
} }
} }
pub fn press_start( fn press_start(
event: Trigger<Pointer<Pressed>>, event: Trigger<Pointer<Pressed>>,
mut button_colors: Query<(&mut BackgroundColor, &mut BorderColor), With<CloseButton>>, mut button_colors: Query<(&mut BackgroundColor, &mut BorderColor), With<CloseButton>>,
ui_theme: Res<UiTheme>, ui_theme: Res<UiTheme>,
@@ -240,7 +250,7 @@ impl CloseButton {
} }
} }
pub fn press_stop( fn press_stop(
event: Trigger<Pointer<Released>>, event: Trigger<Pointer<Released>>,
mut commands: Commands, mut commands: Commands,
mut button_colors: Query<(&mut BackgroundColor, &mut BorderColor, &CloseButton)>, mut button_colors: Query<(&mut BackgroundColor, &mut BorderColor, &CloseButton)>,