diff --git a/native_app/src/game_loop.rs b/native_app/src/game_loop.rs index 1c9b14ed..59c23e81 100644 --- a/native_app/src/game_loop.rs +++ b/native_app/src/game_loop.rs @@ -153,7 +153,7 @@ impl State { self.all_audio .update(&self.goria.read().unwrap(), &mut self.uiw, &mut ctx.audio); - self.manage_entity_follow(); + FollowEntity::update_camera(self); self.camera.update(ctx); } @@ -288,23 +288,6 @@ impl State { ctx.audio.set_settings(settings); } - fn manage_entity_follow(&mut self) { - if self - .uiw - .read::() - .just_act - .contains(&InputAction::Close) - { - self.uiw.write::().0.take(); - } - - if let Some(e) = self.uiw.read::().0 { - if let Some(pos) = self.goria.read().unwrap().pos_any(e) { - self.camera.follow(pos); - } - } - } - fn manage_io(&mut self, ctx: &mut Context) { let goria = self.goria.read().unwrap(); let map = goria.map(); diff --git a/native_app/src/gui/follow.rs b/native_app/src/gui/follow.rs index d1d9a30b..f122ae4a 100644 --- a/native_app/src/gui/follow.rs +++ b/native_app/src/gui/follow.rs @@ -1,3 +1,5 @@ +use crate::game_loop::State; +use crate::inputmap::{InputAction, InputMap}; use egregoria::AnyEntity; use egui::Ui; @@ -7,7 +9,7 @@ use egui::Ui; pub struct FollowEntity(pub(crate) Option); impl FollowEntity { - pub fn update(&mut self, ui: &mut Ui, entity: AnyEntity) { + pub fn update_ui(&mut self, ui: &mut Ui, entity: AnyEntity) { if self.0.is_none() { if ui.small_button("Follow").clicked() { self.0.replace(entity); @@ -19,4 +21,27 @@ impl FollowEntity { self.0.take(); } } + + pub fn update_camera(state: &mut State) { + let just = &state.uiw.read::().just_act; + if [ + InputAction::Close, + InputAction::CameraMove, + InputAction::GoForward, + InputAction::GoBackward, + InputAction::GoLeft, + InputAction::GoRight, + ] + .iter() + .any(|x| just.contains(x)) + { + state.uiw.write::().0.take(); + } + + if let Some(e) = state.uiw.read::().0 { + if let Some(pos) = state.goria.read().unwrap().pos_any(e) { + state.camera.follow(pos); + } + } + } } diff --git a/native_app/src/gui/inspect.rs b/native_app/src/gui/inspect.rs index 36cc69fb..4bc70f9d 100644 --- a/native_app/src/gui/inspect.rs +++ b/native_app/src/gui/inspect.rs @@ -92,7 +92,7 @@ impl InspectRenderer { { let mut follow = uiworld.write::(); - follow.update(ui, entity); + follow.update_ui(ui, entity); } if let Ok(soul) = SoulID::try_from(entity) { diff --git a/native_app/src/gui/windows/settings.rs b/native_app/src/gui/windows/settings.rs index 1b918fcc..6c6a6daf 100644 --- a/native_app/src/gui/windows/settings.rs +++ b/native_app/src/gui/windows/settings.rs @@ -83,7 +83,7 @@ pub(crate) struct Settings { impl Default for Settings { fn default() -> Self { Self { - camera_border_move: true, + camera_border_move: false, camera_smooth: true, music_volume_percent: 100.0, effects_volume_percent: 100.0,