Skip to content

Commit

Permalink
migrate more inspects
Browse files Browse the repository at this point in the history
  • Loading branch information
Uriopass committed Feb 14, 2024
1 parent f560389 commit 12cf377
Show file tree
Hide file tree
Showing 11 changed files with 260 additions and 274 deletions.
11 changes: 8 additions & 3 deletions goryak/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ use crate::{
};

pub struct Window<'a> {
pub title: &'static str,
pub title: Cow<'static, str>,
pub pad: Pad,
pub radius: f32,
pub opened: &'a mut bool,
pub child_spacing: f32,
}

impl<'a> Window<'a> {
Expand Down Expand Up @@ -53,9 +54,13 @@ impl<'a> Window<'a> {
});
});
});
textc(on_primary_container(), Cow::Borrowed(self.title));
textc(on_primary_container(), self.title);
divider(outline(), 10.0, 1.0);
children();
if self.child_spacing != 0.0 {
mincolumn(self.child_spacing, children);
} else {
children();
}
});
});
});
Expand Down
118 changes: 0 additions & 118 deletions native_app/src/gui/inspect/inspect_human.rs

This file was deleted.

52 changes: 0 additions & 52 deletions native_app/src/gui/inspect/inspect_vehicle.rs

This file was deleted.

58 changes: 11 additions & 47 deletions native_app/src/gui/inspect/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,10 @@ use crate::uiworld::UiWorld;
use egui::{Context, Ui, Window};
use inspect_building::inspect_building;
use inspect_debug::InspectRenderer;
use inspect_human::inspect_human;
use inspect_vehicle::inspect_vehicle;
use simulation::map::BuildingID;
use simulation::{AnyEntity, Simulation};
use slotmapd::Key;

mod inspect_building;
mod inspect_debug;
mod inspect_human;
mod inspect_vehicle;

pub fn inspector(ui: &Context, uiworld: &UiWorld, sim: &Simulation) {
profiling::scope!("hud::inspector");
Expand All @@ -28,43 +22,24 @@ pub fn inspector(ui: &Context, uiworld: &UiWorld, sim: &Simulation) {
let force_debug_inspect = uiworld.read::<DebugState>().debug_inspector;

let mut is_open = true;
match e {
AnyEntity::HumanID(id) if !force_debug_inspect => {
is_open = inspect_human(uiworld, sim, ui, id);
}
AnyEntity::VehicleID(id) if !force_debug_inspect => {
is_open = inspect_vehicle(uiworld, sim, ui, id);
}
AnyEntity::WagonID(_) if !force_debug_inspect => {}
AnyEntity::TrainID(_) if !force_debug_inspect => {}
_ => {
Window::new("Inspect")
.default_size([400.0, 500.0])
.default_pos([30.0, 160.0])
.resizable(true)
.open(&mut is_open)
.show(ui, |ui| {
let mut ins = InspectRenderer { entity: e };
ins.render(uiworld, sim, ui);
uiworld.write::<InspectedEntity>().e = Some(ins.entity);
});
}
if force_debug_inspect {
Window::new("Inspect")
.default_size([400.0, 500.0])
.default_pos([30.0, 160.0])
.resizable(true)
.open(&mut is_open)
.show(ui, |ui| {
let mut ins = InspectRenderer { entity: e };
ins.render(uiworld, sim, ui);
uiworld.write::<InspectedEntity>().e = Some(ins.entity);
});
}

if !is_open {
uiworld.write::<InspectedEntity>().e = None;
}
}

pub fn building_link(uiworld: &UiWorld, sim: &Simulation, ui: &mut Ui, b: BuildingID) {
if ui.link(format!("{:?}", b.data())).clicked() {
uiworld.write::<InspectedBuilding>().e = Some(b);
if let Some(b) = sim.map().buildings().get(b) {
uiworld.camera_mut().targetpos = b.door_pos;
}
}
}

pub fn entity_link(uiworld: &UiWorld, sim: &Simulation, ui: &mut Ui, e: impl Into<AnyEntity>) {
entity_link_inner(uiworld, sim, ui, e.into())
}
Expand All @@ -88,14 +63,3 @@ fn entity_link_inner(uiworld: &UiWorld, sim: &Simulation, ui: &mut Ui, e: AnyEnt
}
}
}

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);
}
}
42 changes: 19 additions & 23 deletions native_app/src/newgui/hud/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::sync::atomic::Ordering;
use std::time::Instant;

use yakui::widgets::{List, Pad};
use yakui::{column, reflow, spacer, Alignment, CrossAxisAlignment, Dim2, MainAxisSize};
use yakui::{column, reflow, spacer, Alignment, CrossAxisAlignment, Dim2};

use goryak::{
blur_bg, button_primary, button_secondary, constrained_viewport, on_primary_container,
Expand Down Expand Up @@ -62,36 +62,32 @@ fn save_window(gui: &mut GuiState, uiw: &UiWorld) {
ExitState::ExitAsk | ExitState::Saving => {
let mut opened = true;
Window {
title: "Exit Menu",
title: "Exit Menu".into(),
pad: Pad::all(15.0),
radius: 10.0,
opened: &mut opened,
child_spacing: 5.0,
}
.show(|| {
let mut l = List::column();
l.item_spacing = 5.0;
l.main_axis_size = MainAxisSize::Min;
l.show(|| {
if let ExitState::Saving = *estate {
textc(on_secondary_container(), "Saving...");
if !slstate.please_save && !slstate.saving_status.load(Ordering::SeqCst) {
std::process::exit(0);
}
return;
}
if button_secondary("Save and exit").show().clicked {
if let ExitState::ExitAsk = *estate {
slstate.please_save = true;
*estate = ExitState::Saving;
}
}
if button_secondary("Exit without saving").show().clicked {
if let ExitState::Saving = *estate {
textc(on_secondary_container(), "Saving...");
if !slstate.please_save && !slstate.saving_status.load(Ordering::SeqCst) {
std::process::exit(0);
}
if button_secondary("Cancel").show().clicked {
*estate = ExitState::NoExit;
return;
}
if button_secondary("Save and exit").show().clicked {
if let ExitState::ExitAsk = *estate {
slstate.please_save = true;
*estate = ExitState::Saving;
}
});
}
if button_secondary("Exit without saving").show().clicked {
std::process::exit(0);
}
if button_secondary("Cancel").show().clicked {
*estate = ExitState::NoExit;
}
});

if !opened {
Expand Down
28 changes: 12 additions & 16 deletions native_app/src/newgui/hud/windows/economy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,31 +47,27 @@ pub struct EconomyState {
/// Shows the economy stats
pub fn economy(uiw: &UiWorld, sim: &Simulation, opened: &mut bool) {
Window {
title: "Economy",
title: "Economy".into(),
pad: Pad::all(10.0),
radius: 10.0,
opened,
child_spacing: 10.0,
}
.show(|| {
let mut state = uiw.write::<EconomyState>();
let ecostats = sim.read::<EcoStats>();
pady(10.0, || {
let mut l = List::row();
l.main_axis_size = MainAxisSize::Min;
l.item_spacing = 10.0;
l.show(|| {
let tabs = &[
("Import/Exports", EconomyTab::ImportExports),
("Internal Trade", EconomyTab::InternalTrade),
("Market Prices", EconomyTab::MarketPrices),
];

for (label, tab) in tabs {
if selectable_label_primary(state.tab == *tab, label).clicked {
state.tab = *tab;
}
let tabs = &[
("Import/Exports", EconomyTab::ImportExports),
("Internal Trade", EconomyTab::InternalTrade),
("Market Prices", EconomyTab::MarketPrices),
];

for (label, tab) in tabs {
if selectable_label_primary(state.tab == *tab, label).clicked {
state.tab = *tab;
}
});
}
});

pady(10.0, || {
Expand Down
Loading

0 comments on commit 12cf377

Please sign in to comment.