-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue 63 - Add components window (#69)
* Add component window spawns on right click * limits egui context * fmt * Fix camera input blocking * Fix input blocking from interact * cargo fmt --------- Co-authored-by: a.yamaev <[email protected]>
- Loading branch information
1 parent
65266fd
commit ded7991
Showing
3 changed files
with
168 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
use bevy::{prelude::*, window::PrimaryWindow}; | ||
use bevy_egui::EguiContexts; | ||
|
||
#[derive(Default)] | ||
pub struct MouseCheck; | ||
|
||
impl Plugin for MouseCheck { | ||
fn build(&self, app: &mut App) { | ||
app.init_resource::<PointerContextCheck>() | ||
.add_systems(Startup, initialize_mouse_context) | ||
.add_systems(PreUpdate, update_mouse_context); | ||
} | ||
} | ||
|
||
#[derive(Resource)] | ||
pub struct PointerContextCheck { | ||
pointer_is_valid: bool, | ||
primary_window: Option<Entity>, | ||
} | ||
|
||
impl Default for PointerContextCheck { | ||
fn default() -> Self { | ||
Self { | ||
pointer_is_valid: true, | ||
primary_window: None, | ||
} | ||
} | ||
} | ||
|
||
pub fn initialize_mouse_context( | ||
mut pointer_ctx: ResMut<PointerContextCheck>, | ||
window_q: Query<Entity, With<PrimaryWindow>>, | ||
) { | ||
if let Ok(window_id) = window_q.get_single() { | ||
pointer_ctx.primary_window = Some(window_id); | ||
} else { | ||
error!("could not get Primary Window"); | ||
} | ||
} | ||
|
||
pub fn update_mouse_context( | ||
mut pointer_ctx: ResMut<PointerContextCheck>, | ||
mut egui_ctxs: EguiContexts, | ||
) { | ||
if let Some(window_id) = pointer_ctx.primary_window { | ||
pointer_ctx.pointer_is_valid = !egui_ctxs | ||
.ctx_for_window_mut(window_id) | ||
.wants_pointer_input(); | ||
} | ||
} | ||
|
||
pub fn pointer_context_check() -> impl Fn(Res<PointerContextCheck>) -> bool + Clone { | ||
move |egui_mouse_check: Res<PointerContextCheck>| egui_mouse_check.pointer_is_valid | ||
} |