update
Some checks failed
Rust Checks / checks (push) Failing after 18s
Rust Checks / checks (pull_request) Failing after 5s

This commit is contained in:
CoCo_Sol 2024-03-07 22:15:02 +01:00
parent cee6a0f8f4
commit e3d3da2029

View file

@ -16,6 +16,11 @@ pub struct TileJustClicked(pub u32);
#[derive(Event)]
struct ClickOnTheWorld(Vec2);
/// A zone that can't be clicked.
/// For exemple the UI of the game.
#[derive(Component)]
pub struct ZoneNotClickable;
/// A plugin that handles the selection of tiles.
pub struct SelectorPlugin;
@ -35,20 +40,29 @@ fn mouse_handler(
windows: Query<&Window>,
cameras: Query<(&Camera, &GlobalTransform)>,
mut events_writer: EventWriter<ClickOnTheWorld>,
not_clickable_zones: Query<(&Node, &GlobalTransform), With<ZoneNotClickable>>,
ui_scale: Res<UiScale>,
) {
if !mouse_button_input.just_pressed(MouseButton::Left) {
return;
}
let cursor_position_on_screen = windows
.get_single()
.expect("Main window not found")
.cursor_position();
let window = windows.get_single().expect("Main window not found");
let cursor_position_on_screen = window.cursor_position();
let Some(cursor_position_on_screen) = cursor_position_on_screen else {
return;
};
for (node, global_transform) in not_clickable_zones.iter() {
let rect = node.physical_rect(global_transform, window.scale_factor(), ui_scale.0);
if rect.contains(cursor_position_on_screen) {
return;
}
}
let (camera, camera_transform) = cameras.get_single().expect("Camera not found");
let cursor_position_in_world = camera