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) { // Create a container node that places its children (buttons) at the bottom of the screen let container_node = NodeBundle { style: Style { width: Val::Percent(100.0), // Full width of the screen height: Val::Percent(100.0), // Full height of the screen flex_direction: FlexDirection::Row, // Arrange children in a row (horizontal) justify_content: JustifyContent::Center, // Center horizontally align_items: AlignItems::FlexEnd, // Place at the bottom of the screen padding: UiRect::all(Val::Px(10.0)), // Optional padding ..default() }, ..default() }; // Button style (same for all buttons) let button_style = Style { width: Val::Px(150.0), height: Val::Px(65.0), margin: UiRect::all(Val::Px(10.0)), // Add margin between buttons justify_content: JustifyContent::Center, // Center text horizontally align_items: AlignItems::Center, // Center text vertically border: UiRect::all(Val::Px(5.0)), ..default() }; // Create the container for the buttons let container = commands.spawn(container_node).id(); // Function to create buttons with different text 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() }, ); // Spawn the button and its text as children of the container 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]); } // Label style for top corners let label_style = Style { position_type: PositionType::Absolute, // Absolute positioning width: Val::Auto, // Auto width to fit text height: Val::Auto, // Auto height to fit text margin: UiRect::all(Val::Px(10.0)), // Margin around the text ..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( "* * *", // Text content 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", // Text content TextStyle { // font: asset_server.load("fonts/FiraSans-Bold.ttf"), font_size: 30.0, color: Color::WHITE, ..default() }, ), ..default() }; // Centered container for the "Hint" label let centered_container_node = NodeBundle { style: Style { position_type: PositionType::Absolute, width: Val::Percent(100.0), // Full width top: Val::Px(20.0), // Positioned at the top justify_content: JustifyContent::Center, // Center horizontally align_items: AlignItems::Center, // Center vertically ..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() }, ); // Spawn the top left and top right labels commands.spawn((top_left_label_node, MainGame, HealthLabel)); commands.spawn((top_right_label_node, MainGame, ScoreLabel)); // Create a parent container and then spawn the hint label inside it 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)>, // Query to get Player and Transform sky: Res, // Res to access the Sky resource text_query: Query<&mut Text, With>, button_query: Query<(&mut BackgroundColor, &mut BorderColor), With