use bevy::prelude::*; use std::f64::consts::PI; use rand::seq::SliceRandom; use rand::RngCore; use crate::Player; use crate::GameState; use crate::MainGame; use crate::Sky; use crate::ConstellationLine; use crate::PlayerState; use crate::celestial_to_cartesian; use crate::spawn_cons_lines; use crate::NORMAL_BUTTON; use crate::RIGHT_BUTTON; use crate::WRONG_BUTTON; #[derive(Component)] pub struct AnswerButton; #[derive(Component)] pub struct HealthLabel; #[derive(Component)] pub struct ScoreLabel; #[derive(Component)] pub struct HintLabel; pub fn setup(mut commands: Commands, _asset_server: Res) { let container_node = NodeBundle { style: Style { width: Val::Percent(100.0), height: Val::Percent(100.0), flex_direction: FlexDirection::Row, justify_content: JustifyContent::Center, align_items: AlignItems::FlexEnd, padding: UiRect::all(Val::Px(10.0)), ..default() }, ..default() }; let button_style = Style { width: Val::Px(150.0), height: Val::Px(65.0), margin: UiRect::all(Val::Px(10.0)), justify_content: JustifyContent::Center, align_items: AlignItems::Center, border: UiRect::all(Val::Px(5.0)), ..default() }; let container = commands.spawn(container_node).id(); for _i in 1..=4 { let button_node = ButtonBundle { style: button_style.clone(), border_color: BorderColor(Color::BLACK), background_color: NORMAL_BUTTON.into(), ..default() }; let button_text_node = TextBundle::from_section( "".to_string(), TextStyle { //font: asset_server.load("fonts/FiraSans-Bold.ttf"), // Load font font_size: 15.0, color: Color::srgb(0.9, 0.9, 0.9), ..default() }, ); let button = commands.spawn((button_node, MainGame)).id(); let button_text = commands.spawn((button_text_node, AnswerButton, MainGame)).id(); commands.entity(button).push_children(&[button_text]); commands.entity(container).push_children(&[button]); } let label_style = Style { position_type: PositionType::Absolute, width: Val::Auto, height: Val::Auto, margin: UiRect::all(Val::Px(10.0)), ..default() }; // Top left label let top_left_label_node = TextBundle { style: Style { position_type: PositionType::Absolute, left: Val::Px(10.0), top: Val::Px(10.0), ..label_style.clone() }, text: Text::from_section( "* * *", TextStyle { // font: asset_server.load("fonts/FiraSans-Bold.ttf"), font_size: 30.0, color: Color::WHITE, ..default() }, ), ..default() }; // Top right label let top_right_label_node = TextBundle { style: Style { position_type: PositionType::Absolute, right: Val::Px(10.0), top: Val::Px(10.0), ..label_style.clone() }, text: Text::from_section( "0", TextStyle { // font: asset_server.load("fonts/FiraSans-Bold.ttf"), font_size: 30.0, color: Color::WHITE, ..default() }, ), ..default() }; let centered_container_node = NodeBundle { style: Style { position_type: PositionType::Absolute, width: Val::Percent(100.0), top: Val::Px(20.0), justify_content: JustifyContent::Center, align_items: AlignItems::Center, ..default() }, ..default() }; // Hint label let hint_label_node = TextBundle::from_section( "hint", TextStyle { // font: asset_server.load("fonts/FiraSans-Bold.ttf"), font_size: 20.0, color: Color::srgb(0.7, 0.7, 0.7), ..default() }, ); commands.spawn((top_left_label_node, MainGame, HealthLabel)); commands.spawn((top_right_label_node, MainGame, ScoreLabel)); let centered_container = commands.spawn(centered_container_node).id(); let hint_label = commands.spawn((hint_label_node, MainGame, HintLabel)).id(); commands.entity(centered_container).push_children(&[hint_label]); } pub fn player_interact( keys: Res>, mut player_query: Query<(&mut Player, &mut Transform)>, sky: Res, text_query: Query<&mut Text, With>, button_query: Query<(&mut BackgroundColor, &mut BorderColor), With