diff --git a/native_app/src/gui/inspect/inspect_human.rs b/native_app/src/gui/inspect/inspect_human.rs index ce65330f..f3536bed 100644 --- a/native_app/src/gui/inspect/inspect_human.rs +++ b/native_app/src/gui/inspect/inspect_human.rs @@ -4,10 +4,10 @@ use egregoria::economy::{ItemRegistry, Market}; use egregoria::map_dynamic::Destination; use egregoria::souls::desire::WorkKind; use egregoria::transportation::Location; -use egregoria::{AnyEntity, Egregoria, HumanID}; +use egregoria::{Egregoria, HumanID}; -use crate::gui::inspect::building_link; -use crate::gui::{item_icon, FollowEntity}; +use crate::gui::inspect::{building_link, follow_button}; +use crate::gui::item_icon; use crate::uiworld::UiWorld; /// Inspect a specific building, showing useful information about it @@ -109,9 +109,7 @@ pub fn inspect_human(uiworld: &mut UiWorld, goria: &Egregoria, ui: &Context, id: item_icon(ui, uiworld, item, v); } - if ui.small_button("follow").clicked() { - uiworld.write::().0 = Some(AnyEntity::HumanID(id)); - } + follow_button(uiworld, ui, id); }); is_open } diff --git a/native_app/src/gui/inspect/inspect_train.rs b/native_app/src/gui/inspect/inspect_train.rs index 3ada6fb8..67c07be0 100644 --- a/native_app/src/gui/inspect/inspect_train.rs +++ b/native_app/src/gui/inspect/inspect_train.rs @@ -1,8 +1,9 @@ +use crate::gui::inspect::follow_button; use crate::uiworld::UiWorld; use egregoria::{Egregoria, TrainID}; use egui::Context; -pub fn inspect_train(_uiworld: &mut UiWorld, goria: &Egregoria, ui: &Context, id: TrainID) -> bool { +pub fn inspect_train(uiworld: &mut UiWorld, goria: &Egregoria, ui: &Context, id: TrainID) -> bool { let Some(t) = goria.get(id) else { return false; }; let mut is_open = true; @@ -16,6 +17,8 @@ pub fn inspect_train(_uiworld: &mut UiWorld, goria: &Egregoria, ui: &Context, id } ui.label(format!("Going at {:.0}km/h", t.speed.0)); + + follow_button(uiworld, ui, id); }); is_open diff --git a/native_app/src/gui/inspect/inspect_vehicle.rs b/native_app/src/gui/inspect/inspect_vehicle.rs index 74d271eb..c9e099b1 100644 --- a/native_app/src/gui/inspect/inspect_vehicle.rs +++ b/native_app/src/gui/inspect/inspect_vehicle.rs @@ -1,4 +1,4 @@ -use crate::gui::inspect::entity_link; +use crate::gui::inspect::{entity_link, follow_button}; use crate::uiworld::UiWorld; use egregoria::transportation::VehicleState; use egregoria::{Egregoria, VehicleID}; @@ -47,6 +47,8 @@ pub fn inspect_vehicle( }); } } + + follow_button(uiworld, ui, id); }); is_open diff --git a/native_app/src/gui/inspect/mod.rs b/native_app/src/gui/inspect/mod.rs index 04ef01dc..50c2eef3 100644 --- a/native_app/src/gui/inspect/mod.rs +++ b/native_app/src/gui/inspect/mod.rs @@ -95,3 +95,14 @@ fn entity_link_inner(uiworld: &mut UiWorld, goria: &Egregoria, ui: &mut Ui, e: A } } } + +pub fn follow_button(uiworld: &UiWorld, ui: &mut Ui, id: impl Into) { + follow_button_inner(uiworld, ui, id.into()) +} + +fn follow_button_inner(uiworld: &UiWorld, ui: &mut Ui, id: AnyEntity) { + let mut follow = uiworld.write::(); + if follow.0 != Some(id) && ui.small_button("follow").clicked() { + follow.0 = Some(id); + } +}