Skip to content

Commit

Permalink
follow button on all entities
Browse files Browse the repository at this point in the history
  • Loading branch information
Uriopass committed Aug 15, 2023
1 parent 99a7cdb commit 320c922
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 8 deletions.
10 changes: 4 additions & 6 deletions native_app/src/gui/inspect/inspect_human.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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::<FollowEntity>().0 = Some(AnyEntity::HumanID(id));
}
follow_button(uiworld, ui, id);
});
is_open
}
5 changes: 4 additions & 1 deletion native_app/src/gui/inspect/inspect_train.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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
Expand Down
4 changes: 3 additions & 1 deletion native_app/src/gui/inspect/inspect_vehicle.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -47,6 +47,8 @@ pub fn inspect_vehicle(
});
}
}

follow_button(uiworld, ui, id);
});

is_open
Expand Down
11 changes: 11 additions & 0 deletions native_app/src/gui/inspect/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<AnyEntity>) {
follow_button_inner(uiworld, ui, id.into())
}

fn follow_button_inner(uiworld: &UiWorld, ui: &mut Ui, id: AnyEntity) {
let mut follow = uiworld.write::<FollowEntity>();
if follow.0 != Some(id) && ui.small_button("follow").clicked() {
follow.0 = Some(id);
}
}

0 comments on commit 320c922

Please sign in to comment.