card-game/src/dev_tools/mod.rs
2026-01-29 02:06:48 +05:00

99 lines
2.9 KiB
Rust

use bevy::prelude::*;
use crate::buttons;
use crate::card;
use crate::turns::try_confirm_turn;
const PANEL_BORDER: Color = Color::srgb_u8(36, 36, 143);
const PANEL_BACKGROUND: Color = Color::srgb_u8(0, 0, 52);
const BUTTON_BORDER: Color = Color::srgb_u8(61, 68, 12);
const BUTTON_BACKGROUND: Color = Color::srgb_u8(35, 51, 38);
pub struct DevToolsPlugin;
impl Plugin for DevToolsPlugin {
fn build(&self, app: &mut App) {
app.add_systems(Startup, setup_debug_menu);
}
}
fn setup_debug_menu(mut commands: Commands) {
let root = commands
.spawn((
Node {
width: percent(100.),
height: percent(100.),
align_items: AlignItems::Start,
justify_content: JustifyContent::End,
..default()
},
Pickable::IGNORE,
))
.id();
let panel = commands
.spawn((
Node {
display: Display::Flex,
position_type: PositionType::Relative,
min_width: px(128),
min_height: px(32),
border: UiRect {
left: px(4.),
right: px(4.),
top: px(10.),
bottom: px(4.),
},
margin: UiRect::all(px(10)),
padding: UiRect::all(px(3)),
justify_items: JustifyItems::Start,
align_items: AlignItems::Center,
flex_direction: FlexDirection::Column,
..default()
},
BorderColor::all(PANEL_BORDER),
BackgroundColor(PANEL_BACKGROUND),
ChildOf(root),
))
.id();
commands.spawn(button(panel, "AddCard")).observe(
|_: On<buttons::ButtonPressedEvent>, mut commands: Commands| {
commands.trigger(card::AddCard)
},
);
commands.spawn(button(panel, "ClearCards")).observe(
|_: On<buttons::ButtonPressedEvent>, mut commands: Commands| {
commands.trigger(card::ClearCards)
},
);
commands.spawn(button(panel, "ConfirmTurn")).observe(
|_: On<buttons::ButtonPressedEvent>, mut commands: Commands| {
commands.run_system_cached(try_confirm_turn);
},
);
}
fn button(child_of: Entity, text: impl Into<String>) -> impl Bundle {
(
Button,
Node {
min_height: px(32),
width: percent(100.),
justify_content: JustifyContent::Center,
align_items: AlignItems::Center,
margin: UiRect::all(px(4)),
border: UiRect::all(px(3)),
..default()
},
BorderColor::all(BUTTON_BORDER),
BackgroundColor(BUTTON_BACKGROUND),
ChildOf(child_of),
children![(
Text::new(text),
TextFont {
font_size: 11.0,
..default()
},
)],
)
}