Skip to content

Commit

Permalink
Merge pull request #47 from bytestring-net/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
IDEDARY authored Jul 1, 2024
2 parents 759e419 + daa5b1e commit 9a64045
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
26 changes: 24 additions & 2 deletions crates/bevy_lunex/src/logic/actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,20 @@ fn apply_event_hide_cursor_2d(mut events: EventReader<HideCursor2d>, mut query:
}
}

/// This event will override layout of targetted entity
#[derive(Event, PartialEq, Clone, Copy)]
pub struct ConfineCursor2d (pub bool);
fn apply_event_confine_cursor_2d(mut events: EventReader<ConfineCursor2d>, mut query: Query<&mut Cursor2d>) {
for event in events.read() {
for mut cursor in &mut query {
#[cfg(feature = "verbose")]
info!("{} - Confined cursor: {}", "EVENT".purple().bold(), event.0);
cursor.confined = event.0;
}
}
}


/// This event will override layout of targetted entity
#[derive(Event, PartialEq, Clone, Copy)]
pub struct SetUiLayout {
Expand All @@ -186,9 +200,9 @@ pub struct SetColor {
pub target: Entity,
pub color: Color,
}
fn apply_event_set_color(mut events: EventReader<SetColor>, mut query: Query<(Option<&mut Sprite>, Option<&mut Text>)>) {
fn apply_event_set_color(mut events: EventReader<SetColor>, mut materials: ResMut<Assets<StandardMaterial>>, mut query: Query<(Option<&mut Sprite>, Option<&mut Text>, Option<&Handle<StandardMaterial>>)>) {
for event in events.read() {
if let Ok((sprite_option, text_option)) = query.get_mut(event.target) {
if let Ok((sprite_option, text_option, material_option)) = query.get_mut(event.target) {
if let Some(mut sprite) = sprite_option {
sprite.color = event.color;
}
Expand All @@ -197,6 +211,11 @@ fn apply_event_set_color(mut events: EventReader<SetColor>, mut query: Query<(Op
section.style.color = event.color;
}
}
if let Some(material_handle) = material_option {
if let Some(material) = materials.get_mut(material_handle) {
material.base_color = event.color;
}
}
}
}
}
Expand Down Expand Up @@ -249,6 +268,9 @@ impl Plugin for ActionsPlugin {
.add_event::<HideCursor2d>()
.add_systems(Update, apply_event_hide_cursor_2d.run_if(on_event::<HideCursor2d>()))

.add_event::<ConfineCursor2d>()
.add_systems(Update, apply_event_confine_cursor_2d.run_if(on_event::<ConfineCursor2d>()))

.add_event::<SetUiLayout>()
.add_systems(Update, apply_event_set_ui_layout.run_if(on_event::<SetUiLayout>()))

Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_lunex/src/logic/cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ fn cursor_update(
if window.cursor.visible { window.cursor.icon = cursor.cursor_request; }

if cursor.confined {
window.cursor.grab_mode = CursorGrabMode::Locked;
window.cursor.grab_mode = CursorGrabMode::Confined;
} else {
window.cursor.grab_mode = CursorGrabMode::None;
}
Expand Down
Binary file added promo/bevypunk_3.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 9a64045

Please sign in to comment.