From fb51c894e9f4da525b26e922d494159d420d61c7 Mon Sep 17 00:00:00 2001 From: ghostly_zsh Date: Sat, 4 Apr 2026 06:07:28 -0500 Subject: [PATCH] feat: drill button text changes --- crates/unified/src/client/crafting/ui.rs | 61 +++++++++++++++++------- crates/unified/src/server/part.rs | 13 ++++- 2 files changed, 55 insertions(+), 19 deletions(-) diff --git a/crates/unified/src/client/crafting/ui.rs b/crates/unified/src/client/crafting/ui.rs index 2ff673133471452cd9f29f135e4e382785103d9a..620cb22a5b8310d96e33b100f3ce47e86a0ff327 100644 --- a/crates/unified/src/client/crafting/ui.rs +++ b/crates/unified/src/client/crafting/ui.rs @@ -1,6 +1,6 @@ use bevy::{input_focus::{AutoFocus, InputFocus}, ui::RelativeCursorPosition}; -use crate::{attachment::PartInShip, client::colors, ecs::{CanCraft, CraftingUi, MainCamera, Me, ToggleDrillEvent}, prelude::*}; +use crate::{attachment::PartInShip, client::colors, ecs::{CanCraft, CraftingUi, Drill, MainCamera, Me, ToggleDrillEvent}, prelude::*}; pub fn crafting_ui_plugin(app: &mut App) { app.add_systems(Update, (close_button, drill_button)); @@ -19,6 +19,7 @@ pub fn open_crafting_ui( hearty: Query<(Entity, &Transform), (With, With)>, camera: Single<(Entity, &Camera, &GlobalTransform), (With, Without)>, commands: Commands, + drills: Query<&Drill>, ) { if matches!(ev.button, PointerButton::Secondary) { let (entity, transform) = if let Ok(part) = crafting_parts.get(ev.entity) { @@ -30,7 +31,7 @@ pub fn open_crafting_ui( }; // we have our crafting entity! // now make the ui - setup_ui(entity, transform, commands, camera); + setup_ui(entity, transform, commands, camera, drills); } } @@ -39,6 +40,7 @@ fn setup_ui( parent_transform: &Transform, mut commands: Commands, camera: Single<(Entity, &Camera, &GlobalTransform), (With, Without)>, + drills: Query<&Drill>, ) { let parent_pos = camera.1.world_to_viewport(camera.2, parent_transform.translation).unwrap(); let entity = commands.spawn(( @@ -78,34 +80,46 @@ fn setup_ui( Text::new("x"), )); }); - parent.spawn(( - Node { - ..Default::default() - }, - Button, - DrillButton(parent_part), - BackgroundColor(colors::CRUST), - PreviousInteraction(Interaction::None), - )) - .with_children(|parent| { + // only add the drill button if the part is a drill + if drills.get(parent_part).is_ok() { parent.spawn(( Node { ..Default::default() }, - Text::new("Start Drill"), - )); - }); + Button, + DrillButton(parent_part), + BackgroundColor(colors::CRUST), + PreviousInteraction(Interaction::None), + )) + .with_children(|parent| { + parent.spawn(( + Node { + ..Default::default() + }, + Text::new("Start Drill"), + )); + }); + } }); } fn drill_button( mut interaction_query: Query< - (&Interaction, &mut PreviousInteraction, &mut BackgroundColor, &DrillButton, &mut Button), + ( + &Interaction, + &mut PreviousInteraction, + &mut BackgroundColor, + &DrillButton, + &mut Button, + &Children, + ), Changed, >, mut toggle_drill_writer: MessageWriter, + mut text_query: Query<&mut Text>, + drills: Query<&Drill>, ) { - for (interaction, mut previous_interaction, mut color, drill_button, mut button) in &mut interaction_query { + for (interaction, mut previous_interaction, mut color, drill_button, mut button, children) in &mut interaction_query { match *interaction { Interaction::Pressed => { *color = colors::SURFACE_1.into(); @@ -114,6 +128,19 @@ fn drill_button( *color = colors::SURFACE_0.into(); if previous_interaction.0 == Interaction::Pressed { // released + let mut text = text_query.get_mut(children[0]).unwrap(); + let Ok(drill) = drills.get(drill_button.0) else { + error!("A former drill is now not a drill, causing a problem in the drill button"); + previous_interaction.0 = *interaction; + return + }; + // the text is flipped because drill.drilling is an old value, + // which was now toggled + if drill.drilling { + **text = "Start Drill".to_string(); + } else { + **text = "Stop Drill".to_string(); + } toggle_drill_writer.write(ToggleDrillEvent { drill_entity: drill_button.0 }); } } diff --git a/crates/unified/src/server/part.rs b/crates/unified/src/server/part.rs index 89f216e08940d771a8c7fed072476b2bc27caac2..0bbd44cb2adaf41570036815818473b1c2bba7f8 100644 --- a/crates/unified/src/server/part.rs +++ b/crates/unified/src/server/part.rs @@ -1,6 +1,6 @@ use crate::attachment::{Joint, JointId, JointOf, Joints, Peer, SnapOf, SnapOfJoint}; -use crate::config::part::{CoolingConfig, CraftingConfig, JointConfig, PartConfig}; -use crate::ecs::{CanCraft, Cooler, Part, PartHandle, Radiator, Temperature}; +use crate::config::part::{CoolingConfig, CraftingConfig, DrillConfig, JointConfig, PartConfig}; +use crate::ecs::{CanCraft, Cooler, Drill, Part, PartHandle, Radiator, Temperature}; use crate::prelude::*; use bevy_replicon::prelude::Replicated; use crate::ecs::thruster::{PartThrusters, Thruster, ThrusterBundle, ThrusterId, ThrusterOfPart}; @@ -38,6 +38,9 @@ fn handle_ready_parts( if let Some(ref cooling_config) = strong_config.cooling { cooling_bundle(&mut commands.entity(entity), &cooling_config); } + if let Some(ref drill_config) = strong_config.drill { + drill_bundle(&mut commands.entity(entity), &drill_config); + } spawn_joints(strong_config, entity, commands.reborrow()); spawn_thrusters(strong_config, entity, commands.reborrow()); } @@ -153,6 +156,12 @@ fn cooling_bundle(entity: &mut EntityCommands, config: &CoolingConfig) { heat_cooling_constant: config.heat_cooling_constant, }); } +fn drill_bundle(entity: &mut EntityCommands, config: &DrillConfig) { + entity.insert(Drill { + drilling: false, + resource_multiplier: config.resource_multiplier, + }); +} fn spawn_joint_bundle(joint: &JointConfig, part: &PartConfig, parent: &Entity) -> impl Bundle { let j_comp = Joint { id: JointId::from_part_and_joint_id(part.part.name.clone(), joint.id.clone()),