From dc1bd1795d8085029cfbe10a1600f73a6164f975 Mon Sep 17 00:00:00 2001 From: Paris DOUADY Date: Wed, 14 Feb 2024 13:49:21 +0100 Subject: [PATCH] move follow to newgui --- native_app/src/game_loop.rs | 3 ++- native_app/src/gui/inspect/inspect_debug.rs | 6 ++++-- native_app/src/gui/inspect/mod.rs | 2 +- native_app/src/gui/mod.rs | 2 -- native_app/src/init.rs | 2 +- native_app/src/{gui => newgui}/follow.rs | 15 --------------- native_app/src/newgui/inspect/mod.rs | 2 +- native_app/src/newgui/mod.rs | 1 + 8 files changed, 10 insertions(+), 23 deletions(-) rename native_app/src/{gui => newgui}/follow.rs (69%) diff --git a/native_app/src/game_loop.rs b/native_app/src/game_loop.rs index 9cd92ff6..69d776f0 100644 --- a/native_app/src/game_loop.rs +++ b/native_app/src/game_loop.rs @@ -9,10 +9,11 @@ use geom::{vec2, vec3, Camera, LinearColor}; use simulation::Simulation; use crate::audio::GameAudio; +use crate::gui::render_oldgui; use crate::gui::windows::debug::DebugObjs; -use crate::gui::{render_oldgui, FollowEntity}; use crate::inputmap::{Bindings, InputAction, InputMap}; use crate::newgui; +use crate::newgui::follow::FollowEntity; use crate::newgui::terraforming::TerraformingResource; use crate::newgui::toolbox::building; use crate::newgui::windows::settings::{manage_settings, Settings}; diff --git a/native_app/src/gui/inspect/inspect_debug.rs b/native_app/src/gui/inspect/inspect_debug.rs index 713f3bfe..ae9da6b0 100644 --- a/native_app/src/gui/inspect/inspect_debug.rs +++ b/native_app/src/gui/inspect/inspect_debug.rs @@ -1,4 +1,4 @@ -use crate::gui::follow::FollowEntity; +use crate::newgui::follow::FollowEntity; use crate::uiworld::UiWorld; use egui::Ui; use egui_inspect::{Inspect, InspectArgs}; @@ -92,7 +92,9 @@ impl InspectRenderer { { let mut follow = uiworld.write::(); - follow.update_ui(ui, entity); + if ui.small_button("Follow").clicked() { + follow.0.replace(entity); + } } if let Ok(soul) = SoulID::try_from(entity) { diff --git a/native_app/src/gui/inspect/mod.rs b/native_app/src/gui/inspect/mod.rs index 8d69d7ad..2fd8ab6e 100644 --- a/native_app/src/gui/inspect/mod.rs +++ b/native_app/src/gui/inspect/mod.rs @@ -1,5 +1,5 @@ use crate::gui::windows::debug::DebugState; -use crate::gui::FollowEntity; +use crate::newgui::follow::FollowEntity; use crate::newgui::{InspectedBuilding, InspectedEntity}; use crate::uiworld::UiWorld; use egui::{Context, Ui, Window}; diff --git a/native_app/src/gui/mod.rs b/native_app/src/gui/mod.rs index 49ab1779..b0661a42 100644 --- a/native_app/src/gui/mod.rs +++ b/native_app/src/gui/mod.rs @@ -1,8 +1,6 @@ pub mod chat; -pub mod follow; pub mod hud; pub mod inspect; pub mod windows; -pub use follow::FollowEntity; pub use hud::*; diff --git a/native_app/src/init.rs b/native_app/src/init.rs index a6eadee1..2df7f0b6 100644 --- a/native_app/src/init.rs +++ b/native_app/src/init.rs @@ -1,10 +1,10 @@ use crate::game_loop::Timings; use crate::gui::chat::GUIChatState; use crate::gui::windows::debug::{DebugObjs, DebugState, TestFieldProperties}; -use crate::gui::FollowEntity; use crate::inputmap::{Bindings, InputMap}; use crate::network::NetworkState; use crate::newgui::bulldozer::BulldozerState; +use crate::newgui::follow::FollowEntity; use crate::newgui::lotbrush::LotBrushResource; use crate::newgui::roadbuild::RoadBuildResource; use crate::newgui::roadeditor::RoadEditorResource; diff --git a/native_app/src/gui/follow.rs b/native_app/src/newgui/follow.rs similarity index 69% rename from native_app/src/gui/follow.rs rename to native_app/src/newgui/follow.rs index 31f089a9..590fdd4c 100644 --- a/native_app/src/gui/follow.rs +++ b/native_app/src/newgui/follow.rs @@ -1,27 +1,12 @@ use crate::game_loop::State; use crate::inputmap::{InputAction, InputMap}; -use egui::Ui; use simulation::AnyEntity; /// FollowEntity is a component that tells the camera to follow an entity -/// Entity is defined by a function that returns the position of the entity #[derive(Default)] pub struct FollowEntity(pub Option); impl FollowEntity { - 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); - } - return; - } - - if ui.small_button("Unfollow").clicked() { - self.0.take(); - } - } - pub fn update_camera(state: &mut State) { let just = &state.uiw.read::().just_act; if [ diff --git a/native_app/src/newgui/inspect/mod.rs b/native_app/src/newgui/inspect/mod.rs index e574efe2..2129d463 100644 --- a/native_app/src/newgui/inspect/mod.rs +++ b/native_app/src/newgui/inspect/mod.rs @@ -1,5 +1,5 @@ use crate::gui::windows::debug::DebugState; -use crate::gui::FollowEntity; +use crate::newgui::follow::FollowEntity; use crate::newgui::{InspectedBuilding, InspectedEntity}; use crate::uiworld::UiWorld; use goryak::{button_primary, primary_link}; diff --git a/native_app/src/newgui/mod.rs b/native_app/src/newgui/mod.rs index 9e058f0e..fc877979 100644 --- a/native_app/src/newgui/mod.rs +++ b/native_app/src/newgui/mod.rs @@ -7,6 +7,7 @@ use simulation::{AnyEntity, Simulation}; use std::borrow::Cow; use std::time::Instant; +pub mod follow; mod hud; pub mod inspect; mod textures;