diff --git a/engine/src/gfx.rs b/engine/src/gfx.rs index f0e81620..4653ec0f 100644 --- a/engine/src/gfx.rs +++ b/engine/src/gfx.rs @@ -263,7 +263,7 @@ impl GfxContext { backends = Backends::VULKAN; } - let mut flags = if cfg!(debug_assertions) { + let flags = if cfg!(debug_assertions) { // TODO: re enable validation when https://github.com/gfx-rs/wgpu/issues/5231 is fixed wgpu::InstanceFlags::DEBUG } else { diff --git a/native_app/src/gui/debug_inspect.rs b/native_app/src/debug_gui/debug_inspect.rs similarity index 98% rename from native_app/src/gui/debug_inspect.rs rename to native_app/src/debug_gui/debug_inspect.rs index fa23fa62..4e9d9b3e 100644 --- a/native_app/src/gui/debug_inspect.rs +++ b/native_app/src/debug_gui/debug_inspect.rs @@ -1,7 +1,7 @@ use egui::Ui; use egui::{Context, Window}; -use crate::gui::debug_window::DebugState; +use crate::debug_gui::debug_window::DebugState; use egui_inspect::{Inspect, InspectArgs}; use simulation::economy::Market; use simulation::transportation::Location; @@ -10,8 +10,8 @@ use simulation::{ WagonEnt, }; -use crate::newgui::follow::FollowEntity; -use crate::newgui::InspectedEntity; +use crate::gui::follow::FollowEntity; +use crate::gui::InspectedEntity; use crate::uiworld::UiWorld; pub fn debug_inspector(ui: &Context, uiworld: &UiWorld, sim: &Simulation) { diff --git a/native_app/src/gui/debug_window.rs b/native_app/src/debug_gui/debug_window.rs similarity index 99% rename from native_app/src/gui/debug_window.rs rename to native_app/src/debug_gui/debug_window.rs index 803a4b21..f16375e4 100644 --- a/native_app/src/gui/debug_window.rs +++ b/native_app/src/debug_gui/debug_window.rs @@ -1,15 +1,15 @@ #![allow(clippy::type_complexity)] use crate::game_loop::Timings; -use crate::newgui::{GuiState, InspectedEntity}; +use crate::gui::{GuiState, InspectedEntity}; use crate::uiworld::UiWorld; use simulation::map_dynamic::ParkingManagement; use simulation::transportation::TransportGrid; use simulation::{Simulation, TrainID}; use std::time::{Duration, Instant}; +use crate::gui::windows::settings::Settings; use crate::inputmap::{InputAction, InputMap}; -use crate::newgui::windows::settings::Settings; use egui::{Context, Widget}; use engine::{PerfCountersStatic, Tesselator}; use geom::{Camera, Color, LinearColor, Spline3, Vec2}; diff --git a/native_app/src/debug_gui/hud.rs b/native_app/src/debug_gui/hud.rs new file mode 100644 index 00000000..10776055 --- /dev/null +++ b/native_app/src/debug_gui/hud.rs @@ -0,0 +1,61 @@ +use egui::{Color32, Context, Id, RichText}; + +use prototypes::Money; +use simulation::economy::Government; +use simulation::Simulation; + +use crate::debug_gui::debug_inspect::debug_inspector; +use crate::debug_gui::debug_window::debug_window; +use crate::gui::{ErrorTooltip, GuiState, PotentialCommands}; +use crate::uiworld::UiWorld; + +/// Root GUI entrypoint +pub fn render_oldgui(ui: &Context, uiworld: &UiWorld, sim: &Simulation) { + profiling::scope!("hud::render"); + if uiworld.read::().hidden { + return; + } + + debug_inspector(ui, uiworld, sim); + + debug_window(ui, uiworld, sim); + + tooltip(ui, uiworld, sim); +} + +pub fn tooltip(ui: &Context, uiworld: &UiWorld, sim: &Simulation) { + profiling::scope!("gui::tooltip"); + let tooltip = std::mem::take(&mut *uiworld.write::()); + if let Some(msg) = tooltip.msg { + if !(tooltip.isworld && ui.is_pointer_over_area()) { + let s = ui.available_rect().size(); + egui::show_tooltip_at( + ui, + Id::new("tooltip_error"), + egui::Pos2::new(s.x, s.y), + |ui| ui.label(RichText::new(msg).color(Color32::from_rgb(255, 100, 100))), + ); + } + } + + if ui.is_pointer_over_area() { + return; + } + let pot = &mut uiworld.write::().0; + let cost: Money = pot + .drain(..) + .map(|cmd| Government::action_cost(&cmd, sim)) + .sum(); + + if cost == Money::ZERO { + return; + } + + egui::show_tooltip(ui, Id::new("tooltip_command_cost"), |ui| { + if cost > sim.read::().money { + ui.colored_label(Color32::RED, format!("{cost} too expensive")); + } else { + ui.label(cost.to_string()); + } + }); +} diff --git a/native_app/src/debug_gui/mod.rs b/native_app/src/debug_gui/mod.rs new file mode 100644 index 00000000..9910c373 --- /dev/null +++ b/native_app/src/debug_gui/mod.rs @@ -0,0 +1,5 @@ +pub mod debug_inspect; +pub mod debug_window; +pub mod hud; + +pub use hud::*; diff --git a/native_app/src/game_loop.rs b/native_app/src/game_loop.rs index 0c118196..1f66cbec 100644 --- a/native_app/src/game_loop.rs +++ b/native_app/src/game_loop.rs @@ -10,17 +10,17 @@ use geom::{vec2, vec3, Camera, LinearColor}; use simulation::Simulation; use crate::audio::GameAudio; -use crate::gui::debug_window::DebugObjs; -use crate::gui::render_oldgui; +use crate::debug_gui::debug_window::DebugObjs; +use crate::debug_gui::render_oldgui; +use crate::gui; +use crate::gui::follow::FollowEntity; +use crate::gui::keybinds::KeybindState; +use crate::gui::terraforming::TerraformingResource; +use crate::gui::toolbox::building; +use crate::gui::windows::settings::{manage_settings, Settings}; +use crate::gui::UiTextures; +use crate::gui::{render_newgui, ExitState, GuiState, TimeAlways, Tool}; use crate::inputmap::{Bindings, InputAction, InputMap}; -use crate::newgui; -use crate::newgui::follow::FollowEntity; -use crate::newgui::keybinds::KeybindState; -use crate::newgui::terraforming::TerraformingResource; -use crate::newgui::toolbox::building; -use crate::newgui::windows::settings::{manage_settings, Settings}; -use crate::newgui::UiTextures; -use crate::newgui::{render_newgui, ExitState, GuiState, TimeAlways, Tool}; use crate::rendering::{InstancedRender, MapRenderOptions, MapRenderer, OrbitCamera}; use crate::uiworld::{SaveLoadState, UiWorld}; use prototypes::GameTime; @@ -160,7 +160,7 @@ impl engine::framework::State for State { !ctx.egui.last_kb_captured, !ctx.egui.last_mouse_captured, ); - newgui::run_ui_systems(&self.sim.read().unwrap(), &self.uiw); + gui::run_ui_systems(&self.sim.read().unwrap(), &self.uiw); self.uiw.write::().all.add_value(ctx.delta); self.uiw.write::().per_game_system = self.game_schedule.times(); diff --git a/native_app/src/newgui/follow.rs b/native_app/src/gui/follow.rs similarity index 100% rename from native_app/src/newgui/follow.rs rename to native_app/src/gui/follow.rs diff --git a/native_app/src/gui/hud.rs b/native_app/src/gui/hud.rs index 56ac66fd..5763459b 100644 --- a/native_app/src/gui/hud.rs +++ b/native_app/src/gui/hud.rs @@ -1,61 +1,137 @@ -use egui::{Color32, Context, Id, RichText}; +use std::time::Instant; -use prototypes::Money; -use simulation::economy::Government; +use goryak::{image_button, minrow, on_secondary_container, textc}; +use ordered_float::OrderedFloat; +use prototypes::ItemID; +use yakui::{reflow, Alignment, Color, Dim2, Pivot, Vec2}; + +use simulation::map_dynamic::ElectricityFlow; use simulation::Simulation; -use crate::gui::debug_inspect::debug_inspector; -use crate::gui::debug_window::debug_window; -use crate::newgui::{ErrorTooltip, GuiState, PotentialCommands}; -use crate::uiworld::UiWorld; +use crate::gui::hud::menu::menu_bar; +use crate::gui::hud::time_controls::time_controls; +use crate::gui::hud::toolbox::new_toolbox; +use crate::gui::inspect::new_inspector; +use crate::gui::textures::UiTextures; +use crate::gui::windows::settings::Settings; +use crate::gui::GuiState; +use crate::uiworld::{SaveLoadState, UiWorld}; + +pub mod chat; +pub mod keybinds; +mod menu; +mod time_controls; +pub mod toolbox; +pub mod windows; /// Root GUI entrypoint -pub fn render_oldgui(ui: &Context, uiworld: &UiWorld, sim: &Simulation) { +pub fn render_newgui(uiworld: &UiWorld, sim: &Simulation) { profiling::scope!("hud::render"); + auto_save(uiworld); + if uiworld.read::().hidden { return; } - debug_inspector(ui, uiworld, sim); - - debug_window(ui, uiworld, sim); - - tooltip(ui, uiworld, sim); + yakui::column(|| { + power_errors(uiworld, sim); + new_toolbox(uiworld, sim); + menu_bar(uiworld, sim); + chat::chat(uiworld, sim); + new_inspector(uiworld, sim); + uiworld.write::().windows.render(uiworld, sim); + time_controls(uiworld, sim); + keybinds::keybind_modal(uiworld, sim) + }); + //goryak::debug_layout(); } -pub fn tooltip(ui: &Context, uiworld: &UiWorld, sim: &Simulation) { - profiling::scope!("gui::tooltip"); - let tooltip = std::mem::take(&mut *uiworld.write::()); - if let Some(msg) = tooltip.msg { - if !(tooltip.isworld && ui.is_pointer_over_area()) { - let s = ui.available_rect().size(); - egui::show_tooltip_at( - ui, - Id::new("tooltip_error"), - egui::Pos2::new(s.x, s.y), - |ui| ui.label(RichText::new(msg).color(Color32::from_rgb(255, 100, 100))), - ); +fn auto_save(uiworld: &UiWorld) { + let every = uiworld.read::().auto_save_every.into(); + let mut gui = uiworld.write::(); + if let Some(every) = every { + if gui.last_save.elapsed() > every { + uiworld.write::().please_save = true; + uiworld.save_to_disk(); + gui.last_save = Instant::now(); } } +} - if ui.is_pointer_over_area() { - return; - } - let pot = &mut uiworld.write::().0; - let cost: Money = pot - .drain(..) - .map(|cmd| Government::action_cost(&cmd, sim)) - .sum(); +fn power_errors(uiworld: &UiWorld, sim: &Simulation) { + profiling::scope!("hud::power_errors"); + let map = sim.map(); + let flow = sim.read::(); - if cost == Money::ZERO { - return; + let no_power_img = uiworld.read::().get("no_power"); + + for network in map.electricity.networks() { + if !flow.blackout(network.id) { + continue; + } + + let mut buildings_with_issues = Vec::with_capacity(network.buildings.len()); + + for &building in &network.buildings { + let Some(b) = map.get(building) else { + continue; + }; + + let center = b.obb.center(); + + let pos = center + .z(b.height + 20.0 + 1.0 * f32::cos(uiworld.time_always() + center.mag() * 0.05)); + let (screenpos, depth) = uiworld.camera().project(pos); + + let size = 10000.0 / depth; + + buildings_with_issues.push((screenpos, size)); + } + + buildings_with_issues.sort_by_key(|x| OrderedFloat(x.1)); + + for (screenpos, size) in buildings_with_issues { + reflow( + Alignment::TOP_LEFT, + Pivot::TOP_LEFT, + Dim2::pixels(screenpos.x - size * 0.5, screenpos.y - size * 0.5), + || { + let mut image = yakui::widgets::Image::new(no_power_img, Vec2::new(size, size)); + image.color = Color::WHITE.with_alpha(0.7); + image.show(); + }, + ); + } } +} - egui::show_tooltip(ui, Id::new("tooltip_command_cost"), |ui| { - if cost > sim.read::().money { - ui.colored_label(Color32::RED, format!("{cost} too expensive")); +pub fn item_icon_yakui(uiworld: &UiWorld, id: ItemID, multiplier: i32) { + let item = id.prototype(); + minrow(5.0, || { + if let Some(id) = uiworld + .read::() + .try_get(&format!("icon/{}", item.name)) + { + if image_button( + id, + Vec2::new(32.0, 32.0), + Color::WHITE, + Color::WHITE, + Color::WHITE, + "", + ) + .hovering + { + reflow(Alignment::CENTER, Pivot::TOP_LEFT, Dim2::ZERO, || { + textc( + on_secondary_container(), + format!("{} x{}", item.name, multiplier), + ); + }); + } } else { - ui.label(cost.to_string()); + textc(on_secondary_container(), format!("- {} ", &item.label)); } + textc(on_secondary_container(), format!("x{multiplier}")) }); } diff --git a/native_app/src/newgui/hud/chat.rs b/native_app/src/gui/hud/chat.rs similarity index 100% rename from native_app/src/newgui/hud/chat.rs rename to native_app/src/gui/hud/chat.rs diff --git a/native_app/src/newgui/hud/keybinds.rs b/native_app/src/gui/hud/keybinds.rs similarity index 100% rename from native_app/src/newgui/hud/keybinds.rs rename to native_app/src/gui/hud/keybinds.rs diff --git a/native_app/src/newgui/hud/menu.rs b/native_app/src/gui/hud/menu.rs similarity index 99% rename from native_app/src/newgui/hud/menu.rs rename to native_app/src/gui/hud/menu.rs index 3a4d31ab..1f7117df 100644 --- a/native_app/src/newgui/hud/menu.rs +++ b/native_app/src/gui/hud/menu.rs @@ -11,8 +11,8 @@ use goryak::{ use simulation::economy::Government; use simulation::Simulation; +use crate::gui::{ExitState, GuiState}; use crate::inputmap::{InputAction, InputMap}; -use crate::newgui::{ExitState, GuiState}; use crate::uiworld::{SaveLoadState, UiWorld}; pub fn menu_bar(uiworld: &UiWorld, sim: &Simulation) { diff --git a/native_app/src/newgui/hud/time_controls.rs b/native_app/src/gui/hud/time_controls.rs similarity index 98% rename from native_app/src/newgui/hud/time_controls.rs rename to native_app/src/gui/hud/time_controls.rs index 42e2f870..e712ba3d 100644 --- a/native_app/src/newgui/hud/time_controls.rs +++ b/native_app/src/gui/hud/time_controls.rs @@ -11,9 +11,9 @@ use goryak::{ use prototypes::GameTime; use simulation::Simulation; +use crate::gui::windows::settings::Settings; +use crate::gui::GuiState; use crate::inputmap::{InputAction, InputMap}; -use crate::newgui::windows::settings::Settings; -use crate::newgui::GuiState; use crate::uiworld::UiWorld; pub fn time_controls(uiworld: &UiWorld, sim: &Simulation) { diff --git a/native_app/src/newgui/hud/toolbox/building.rs b/native_app/src/gui/hud/toolbox/building.rs similarity index 99% rename from native_app/src/newgui/hud/toolbox/building.rs rename to native_app/src/gui/hud/toolbox/building.rs index 5f97ccc6..c09e4cf5 100644 --- a/native_app/src/newgui/hud/toolbox/building.rs +++ b/native_app/src/gui/hud/toolbox/building.rs @@ -6,7 +6,7 @@ use yakui::{ TextureId, Vec2, }; -use crate::newgui::item_icon_yakui; +use crate::gui::item_icon_yakui; use engine::wgpu::TextureFormat; use geom::{Camera, Degrees, Polygon, Vec3}; use goryak::{ @@ -22,7 +22,7 @@ use simulation::world_command::WorldCommand; use std::path::PathBuf; use std::time::Instant; -use crate::newgui::specialbuilding::{SpecialBuildKind, SpecialBuildingResource}; +use crate::gui::specialbuilding::{SpecialBuildKind, SpecialBuildingResource}; use crate::uiworld::UiWorld; pub fn special_building_properties(uiw: &UiWorld) { diff --git a/native_app/src/newgui/hud/toolbox/mod.rs b/native_app/src/gui/hud/toolbox/mod.rs similarity index 98% rename from native_app/src/newgui/hud/toolbox/mod.rs rename to native_app/src/gui/hud/toolbox/mod.rs index a799e28f..945af275 100644 --- a/native_app/src/newgui/hud/toolbox/mod.rs +++ b/native_app/src/gui/hud/toolbox/mod.rs @@ -11,9 +11,9 @@ use goryak::{ }; use simulation::Simulation; +use crate::gui::textures::UiTextures; +use crate::gui::Tool; use crate::inputmap::{InputAction, InputMap}; -use crate::newgui::textures::UiTextures; -use crate::newgui::Tool; use crate::uiworld::UiWorld; pub mod building; diff --git a/native_app/src/newgui/hud/toolbox/roadbuild.rs b/native_app/src/gui/hud/toolbox/roadbuild.rs similarity index 98% rename from native_app/src/newgui/hud/toolbox/roadbuild.rs rename to native_app/src/gui/hud/toolbox/roadbuild.rs index f36518d1..be564fdf 100644 --- a/native_app/src/newgui/hud/toolbox/roadbuild.rs +++ b/native_app/src/gui/hud/toolbox/roadbuild.rs @@ -7,9 +7,9 @@ use yakui::{ use goryak::{image_button, mincolumn, minrow, padxy, primary}; use simulation::map::LanePatternBuilder; -use crate::newgui::hud::toolbox::updown_value; -use crate::newgui::roadbuild::{HeightReference, RoadBuildResource, Snapping}; -use crate::newgui::textures::UiTextures; +use crate::gui::hud::toolbox::updown_value; +use crate::gui::roadbuild::{HeightReference, RoadBuildResource, Snapping}; +use crate::gui::textures::UiTextures; use crate::uiworld::UiWorld; pub fn roadbuild_properties(uiw: &UiWorld) { diff --git a/native_app/src/newgui/hud/toolbox/roadedit.rs b/native_app/src/gui/hud/toolbox/roadedit.rs similarity index 95% rename from native_app/src/newgui/hud/toolbox/roadedit.rs rename to native_app/src/gui/hud/toolbox/roadedit.rs index 19ddf2cd..f44da55c 100644 --- a/native_app/src/newgui/hud/toolbox/roadedit.rs +++ b/native_app/src/gui/hud/toolbox/roadedit.rs @@ -6,10 +6,10 @@ use yakui::{ use goryak::{padxy, primary_image_button}; use simulation::map::LightPolicy; -use crate::newgui::hud::toolbox; -use crate::newgui::hud::toolbox::select_triangle; -use crate::newgui::roadeditor::RoadEditorResource; -use crate::newgui::textures::UiTextures; +use crate::gui::hud::toolbox; +use crate::gui::hud::toolbox::select_triangle; +use crate::gui::roadeditor::RoadEditorResource; +use crate::gui::textures::UiTextures; use crate::uiworld::UiWorld; pub fn roadedit_properties(uiw: &UiWorld) { diff --git a/native_app/src/newgui/hud/toolbox/terraforming.rs b/native_app/src/gui/hud/toolbox/terraforming.rs similarity index 95% rename from native_app/src/newgui/hud/toolbox/terraforming.rs rename to native_app/src/gui/hud/toolbox/terraforming.rs index 36f5b5a1..b601acf2 100644 --- a/native_app/src/newgui/hud/toolbox/terraforming.rs +++ b/native_app/src/gui/hud/toolbox/terraforming.rs @@ -4,9 +4,9 @@ use yakui::{column, CrossAxisAlignment, MainAxisAlignment, Vec2}; use goryak::{fixed_spacer, padxy, primary_image_button}; use simulation::map::TerraformKind; -use crate::newgui::hud::toolbox::{select_triangle, updown_value}; -use crate::newgui::terraforming::TerraformingResource; -use crate::newgui::textures::UiTextures; +use crate::gui::hud::toolbox::{select_triangle, updown_value}; +use crate::gui::terraforming::TerraformingResource; +use crate::gui::textures::UiTextures; use crate::uiworld::UiWorld; pub fn terraform_properties(uiw: &UiWorld) { diff --git a/native_app/src/newgui/hud/toolbox/train.rs b/native_app/src/gui/hud/toolbox/train.rs similarity index 98% rename from native_app/src/newgui/hud/toolbox/train.rs rename to native_app/src/gui/hud/toolbox/train.rs index 1476a539..c3e2842e 100644 --- a/native_app/src/newgui/hud/toolbox/train.rs +++ b/native_app/src/gui/hud/toolbox/train.rs @@ -3,7 +3,7 @@ use prototypes::{prototypes_iter, RollingStockID, RollingStockPrototype}; use yakui::widgets::List; use yakui::{button, divider, label, CrossAxisAlignment, MainAxisAlignment}; -use crate::newgui::addtrain::TrainSpawnResource; +use crate::gui::addtrain::TrainSpawnResource; use crate::uiworld::UiWorld; pub fn train_properties(uiw: &UiWorld) { diff --git a/native_app/src/newgui/hud/windows/economy.rs b/native_app/src/gui/hud/windows/economy.rs similarity index 100% rename from native_app/src/newgui/hud/windows/economy.rs rename to native_app/src/gui/hud/windows/economy.rs diff --git a/native_app/src/newgui/hud/windows/load.rs b/native_app/src/gui/hud/windows/load.rs similarity index 100% rename from native_app/src/newgui/hud/windows/load.rs rename to native_app/src/gui/hud/windows/load.rs diff --git a/native_app/src/newgui/hud/windows/mod.rs b/native_app/src/gui/hud/windows/mod.rs similarity index 100% rename from native_app/src/newgui/hud/windows/mod.rs rename to native_app/src/gui/hud/windows/mod.rs diff --git a/native_app/src/newgui/hud/windows/network.rs b/native_app/src/gui/hud/windows/network.rs similarity index 100% rename from native_app/src/newgui/hud/windows/network.rs rename to native_app/src/gui/hud/windows/network.rs diff --git a/native_app/src/newgui/hud/windows/settings.rs b/native_app/src/gui/hud/windows/settings.rs similarity index 99% rename from native_app/src/newgui/hud/windows/settings.rs rename to native_app/src/gui/hud/windows/settings.rs index e341d6b3..bd3df6b4 100644 --- a/native_app/src/newgui/hud/windows/settings.rs +++ b/native_app/src/gui/hud/windows/settings.rs @@ -16,8 +16,8 @@ use serde::{Deserialize, Serialize}; use simulation::Simulation; use crate::game_loop::Timings; +use crate::gui::keybinds::{KeybindState, KeybindStateInner}; use crate::inputmap::{Bindings, InputMap}; -use crate::newgui::keybinds::{KeybindState, KeybindStateInner}; use crate::uiworld::UiWorld; const SETTINGS_SAVE_NAME: &str = "settings"; diff --git a/native_app/src/newgui/inspect/inspect_building.rs b/native_app/src/gui/inspect/inspect_building.rs similarity index 99% rename from native_app/src/newgui/inspect/inspect_building.rs rename to native_app/src/gui/inspect/inspect_building.rs index cf733c92..bf67e835 100644 --- a/native_app/src/newgui/inspect/inspect_building.rs +++ b/native_app/src/gui/inspect/inspect_building.rs @@ -12,8 +12,8 @@ use std::borrow::Cow; use yakui::widgets::Pad; use yakui::Vec2; -use crate::newgui::inspect::entity_link; -use crate::newgui::item_icon_yakui; +use crate::gui::inspect::entity_link; +use crate::gui::item_icon_yakui; use crate::uiworld::UiWorld; fn label(x: impl Into>) { diff --git a/native_app/src/newgui/inspect/inspect_human.rs b/native_app/src/gui/inspect/inspect_human.rs similarity index 97% rename from native_app/src/newgui/inspect/inspect_human.rs rename to native_app/src/gui/inspect/inspect_human.rs index a4095196..76f4e305 100644 --- a/native_app/src/newgui/inspect/inspect_human.rs +++ b/native_app/src/gui/inspect/inspect_human.rs @@ -9,8 +9,8 @@ use simulation::souls::desire::WorkKind; use simulation::transportation::Location; use simulation::{HumanID, Simulation}; -use crate::newgui::inspect::{building_link, follow_button}; -use crate::newgui::item_icon_yakui; +use crate::gui::inspect::{building_link, follow_button}; +use crate::gui::item_icon_yakui; use crate::uiworld::UiWorld; /// Inspect a specific building, showing useful information about it diff --git a/native_app/src/newgui/inspect/inspect_train.rs b/native_app/src/gui/inspect/inspect_train.rs similarity index 94% rename from native_app/src/newgui/inspect/inspect_train.rs rename to native_app/src/gui/inspect/inspect_train.rs index de96a7ce..49a48c1a 100644 --- a/native_app/src/newgui/inspect/inspect_train.rs +++ b/native_app/src/gui/inspect/inspect_train.rs @@ -1,4 +1,4 @@ -use crate::newgui::inspect::follow_button; +use crate::gui::inspect::follow_button; use crate::uiworld::UiWorld; use goryak::{on_secondary_container, textc, Window}; use simulation::{Simulation, TrainID}; diff --git a/native_app/src/newgui/inspect/inspect_vehicle.rs b/native_app/src/gui/inspect/inspect_vehicle.rs similarity index 96% rename from native_app/src/newgui/inspect/inspect_vehicle.rs rename to native_app/src/gui/inspect/inspect_vehicle.rs index 7d08add8..d7e9a95e 100644 --- a/native_app/src/newgui/inspect/inspect_vehicle.rs +++ b/native_app/src/gui/inspect/inspect_vehicle.rs @@ -1,4 +1,4 @@ -use crate::newgui::inspect::{entity_link, follow_button}; +use crate::gui::inspect::{entity_link, follow_button}; use crate::uiworld::UiWorld; use goryak::{minrow, on_secondary_container, textc, Window}; use simulation::transportation::VehicleState; diff --git a/native_app/src/newgui/inspect/mod.rs b/native_app/src/gui/inspect/mod.rs similarity index 95% rename from native_app/src/newgui/inspect/mod.rs rename to native_app/src/gui/inspect/mod.rs index cfb4dd1b..2379ac3a 100644 --- a/native_app/src/newgui/inspect/mod.rs +++ b/native_app/src/gui/inspect/mod.rs @@ -1,6 +1,6 @@ -use crate::gui::debug_window::DebugState; -use crate::newgui::follow::FollowEntity; -use crate::newgui::{InspectedBuilding, InspectedEntity}; +use crate::debug_gui::debug_window::DebugState; +use crate::gui::follow::FollowEntity; +use crate::gui::{InspectedBuilding, InspectedEntity}; use crate::uiworld::UiWorld; use goryak::{button_primary, primary_link}; use inspect_building::inspect_building; diff --git a/native_app/src/gui/mod.rs b/native_app/src/gui/mod.rs index 9910c373..49a3dab4 100644 --- a/native_app/src/gui/mod.rs +++ b/native_app/src/gui/mod.rs @@ -1,5 +1,167 @@ -pub mod debug_inspect; -pub mod debug_window; -pub mod hud; +use crate::gui::windows::GUIWindows; +use crate::uiworld::UiWorld; +use serde::{Deserialize, Serialize}; +use simulation::map::BuildingID; +use simulation::world_command::WorldCommand; +use simulation::{AnyEntity, Simulation}; +use std::borrow::Cow; +use std::time::Instant; + +pub mod follow; +mod hud; +pub mod inspect; +mod textures; +mod tools; pub use hud::*; +pub use textures::*; +pub use tools::*; + +pub struct GuiState { + pub debug_window: bool, + pub windows: GUIWindows, + pub last_save: Instant, + pub depause_warp: u32, + pub hidden: bool, +} + +impl Default for GuiState { + fn default() -> Self { + Self { + debug_window: false, + windows: Default::default(), + last_save: Instant::now(), + depause_warp: 1, + hidden: false, + } + } +} + +pub fn run_ui_systems(sim: &Simulation, uiworld: &UiWorld) { + profiling::scope!("gui::run_ui_systems"); + bulldozer::bulldozer(sim, uiworld); + inspected_aura::inspected_aura(sim, uiworld); + lotbrush::lotbrush(sim, uiworld); + roadbuild::roadbuild(sim, uiworld); + roadeditor::roadeditor(sim, uiworld); + specialbuilding::specialbuilding(sim, uiworld); + addtrain::addtrain(sim, uiworld); + zoneedit::zoneedit(sim, uiworld); + terraforming::terraforming(sim, uiworld); + + // run last so other systems can have the chance to cancel select + selectable::selectable(sim, uiworld); +} + +#[derive(Default, Clone, Debug)] +pub struct ErrorTooltip { + pub msg: Option>, + // Whether this tooltip is about something happening in the game world + // Avoid showing tooltip when the UI is hovered + pub isworld: bool, +} + +impl ErrorTooltip { + pub fn new(msg: impl Into>) -> Self { + Self { + msg: Some(msg.into()), + isworld: true, + } + } + + #[allow(unused)] + pub fn new_ui(msg: impl Into>) -> Self { + Self { + msg: Some(msg.into()), + isworld: false, + } + } +} + +#[derive(Default, Clone, Debug)] +pub struct PotentialCommands(pub Vec); + +impl PotentialCommands { + pub fn set(&mut self, cmd: WorldCommand) { + self.0.clear(); + self.0.push(cmd); + } +} + +#[derive(Copy, Clone, Debug, Default)] +pub struct InspectedBuilding { + pub e: Option, + pub dontclear: bool, +} + +#[derive(Copy, Clone, Debug)] +pub struct InspectedEntity { + pub e: Option, + pub dist2: f32, + pub dontclear: bool, +} + +impl Default for InspectedEntity { + fn default() -> Self { + Self { + e: None, + dist2: 0.0, + dontclear: false, + } + } +} + +/// Time that always progresses even when the game is paused +/// Is moduloed to 3600 +#[derive(Copy, Clone, Debug, Default)] +pub struct TimeAlways(pub f32); + +#[derive(Copy, Clone, Default, Serialize, Deserialize, Eq, PartialEq)] +pub enum Tool { + #[default] + Hand, + RoadbuildStraight, + RoadbuildCurved, + RoadEditor, + Bulldozer, + LotBrush, + SpecialBuilding, + Train, + Terraforming, +} + +impl Tool { + pub fn is_roadbuild(&self) -> bool { + matches!(self, Tool::RoadbuildStraight | Tool::RoadbuildCurved) + } + + pub fn show_arrows(&self) -> bool { + matches!( + self, + Tool::RoadbuildStraight + | Tool::RoadbuildCurved + | Tool::RoadEditor + | Tool::Bulldozer + | Tool::Train + ) + } + + pub fn show_lots(&self) -> bool { + matches!( + self, + Tool::RoadbuildStraight | Tool::RoadbuildCurved | Tool::Bulldozer | Tool::LotBrush + ) + } +} + +pub enum ExitState { + NoExit, + ExitAsk, + Saving, +} + +impl Default for ExitState { + fn default() -> Self { + Self::NoExit + } +} diff --git a/native_app/src/newgui/textures.rs b/native_app/src/gui/textures.rs similarity index 100% rename from native_app/src/newgui/textures.rs rename to native_app/src/gui/textures.rs diff --git a/native_app/src/newgui/tools/addtrain.rs b/native_app/src/gui/tools/addtrain.rs similarity index 98% rename from native_app/src/newgui/tools/addtrain.rs rename to native_app/src/gui/tools/addtrain.rs index a6d1904c..7c384739 100644 --- a/native_app/src/newgui/tools/addtrain.rs +++ b/native_app/src/gui/tools/addtrain.rs @@ -1,5 +1,5 @@ +use crate::gui::{PotentialCommands, Tool}; use crate::inputmap::{InputAction, InputMap}; -use crate::newgui::{PotentialCommands, Tool}; use crate::rendering::immediate::ImmediateDraw; use crate::uiworld::UiWorld; use geom::{Color, OBB}; diff --git a/native_app/src/newgui/tools/bulldozer.rs b/native_app/src/gui/tools/bulldozer.rs similarity index 96% rename from native_app/src/newgui/tools/bulldozer.rs rename to native_app/src/gui/tools/bulldozer.rs index 2f7eb998..ae6da323 100644 --- a/native_app/src/newgui/tools/bulldozer.rs +++ b/native_app/src/gui/tools/bulldozer.rs @@ -1,6 +1,6 @@ +use crate::gui::specialbuilding::SpecialBuildingResource; +use crate::gui::Tool; use crate::inputmap::{InputAction, InputMap}; -use crate::newgui::specialbuilding::SpecialBuildingResource; -use crate::newgui::Tool; use crate::rendering::immediate::ImmediateDraw; use crate::uiworld::UiWorld; use egui_inspect::Inspect; diff --git a/native_app/src/newgui/tools/inspected_aura.rs b/native_app/src/gui/tools/inspected_aura.rs similarity index 94% rename from native_app/src/newgui/tools/inspected_aura.rs rename to native_app/src/gui/tools/inspected_aura.rs index 0aba1410..610bb4a7 100644 --- a/native_app/src/newgui/tools/inspected_aura.rs +++ b/native_app/src/gui/tools/inspected_aura.rs @@ -1,5 +1,5 @@ -use crate::newgui::selectable::select_radius; -use crate::newgui::{InspectedBuilding, InspectedEntity}; +use crate::gui::selectable::select_radius; +use crate::gui::{InspectedBuilding, InspectedEntity}; use crate::rendering::immediate::ImmediateDraw; use crate::uiworld::UiWorld; use geom::Color; diff --git a/native_app/src/newgui/tools/lotbrush.rs b/native_app/src/gui/tools/lotbrush.rs similarity index 98% rename from native_app/src/newgui/tools/lotbrush.rs rename to native_app/src/gui/tools/lotbrush.rs index 75226485..625db0cc 100644 --- a/native_app/src/newgui/tools/lotbrush.rs +++ b/native_app/src/gui/tools/lotbrush.rs @@ -1,5 +1,5 @@ +use crate::gui::Tool; use crate::inputmap::{InputAction, InputMap}; -use crate::newgui::Tool; use crate::rendering::immediate::ImmediateDraw; use crate::uiworld::UiWorld; use serde::{Deserialize, Serialize}; diff --git a/native_app/src/newgui/tools/mod.rs b/native_app/src/gui/tools/mod.rs similarity index 100% rename from native_app/src/newgui/tools/mod.rs rename to native_app/src/gui/tools/mod.rs diff --git a/native_app/src/newgui/tools/roadbuild.rs b/native_app/src/gui/tools/roadbuild.rs similarity index 99% rename from native_app/src/newgui/tools/roadbuild.rs rename to native_app/src/gui/tools/roadbuild.rs index 857728cb..cbe48bef 100644 --- a/native_app/src/newgui/tools/roadbuild.rs +++ b/native_app/src/gui/tools/roadbuild.rs @@ -9,8 +9,8 @@ use simulation::Simulation; use BuildState::{Connection, Hover, Interpolation, Start, StartInterp}; use ProjectKind::{Building, Ground, Inter, Road}; +use crate::gui::{PotentialCommands, Tool}; use crate::inputmap::{InputAction, InputMap}; -use crate::newgui::{PotentialCommands, Tool}; use crate::rendering::immediate::{ImmediateDraw, ImmediateSound}; use crate::uiworld::UiWorld; diff --git a/native_app/src/newgui/tools/roadeditor.rs b/native_app/src/gui/tools/roadeditor.rs similarity index 99% rename from native_app/src/newgui/tools/roadeditor.rs rename to native_app/src/gui/tools/roadeditor.rs index 40d51247..13973f07 100644 --- a/native_app/src/newgui/tools/roadeditor.rs +++ b/native_app/src/gui/tools/roadeditor.rs @@ -1,5 +1,5 @@ +use crate::gui::Tool; use crate::inputmap::{InputAction, InputMap}; -use crate::newgui::Tool; use crate::rendering::immediate::ImmediateDraw; use crate::uiworld::UiWorld; use geom::Color; diff --git a/native_app/src/newgui/tools/selectable.rs b/native_app/src/gui/tools/selectable.rs similarity index 97% rename from native_app/src/newgui/tools/selectable.rs rename to native_app/src/gui/tools/selectable.rs index 7d012e2b..3c6ff116 100644 --- a/native_app/src/newgui/tools/selectable.rs +++ b/native_app/src/gui/tools/selectable.rs @@ -1,5 +1,5 @@ +use crate::gui::{InspectedBuilding, InspectedEntity, Tool}; use crate::inputmap::{InputAction, InputMap}; -use crate::newgui::{InspectedBuilding, InspectedEntity, Tool}; use crate::uiworld::UiWorld; use geom::Vec2; use simulation::map::ProjectFilter; diff --git a/native_app/src/newgui/tools/specialbuilding.rs b/native_app/src/gui/tools/specialbuilding.rs similarity index 98% rename from native_app/src/newgui/tools/specialbuilding.rs rename to native_app/src/gui/tools/specialbuilding.rs index 2ed7f185..62920bf4 100644 --- a/native_app/src/newgui/tools/specialbuilding.rs +++ b/native_app/src/gui/tools/specialbuilding.rs @@ -1,5 +1,5 @@ +use crate::gui::{ErrorTooltip, InspectedBuilding, PotentialCommands, Tool}; use crate::inputmap::{InputAction, InputMap}; -use crate::newgui::{ErrorTooltip, InspectedBuilding, PotentialCommands, Tool}; use crate::rendering::immediate::{ImmediateDraw, ImmediateSound}; use crate::uiworld::UiWorld; use engine::AudioKind; diff --git a/native_app/src/newgui/tools/terraforming.rs b/native_app/src/gui/tools/terraforming.rs similarity index 99% rename from native_app/src/newgui/tools/terraforming.rs rename to native_app/src/gui/tools/terraforming.rs index 43fe54f4..4786c5ad 100644 --- a/native_app/src/newgui/tools/terraforming.rs +++ b/native_app/src/gui/tools/terraforming.rs @@ -3,8 +3,8 @@ use simulation::map::TerraformKind; use simulation::world_command::WorldCommand; use simulation::Simulation; +use crate::gui::Tool; use crate::inputmap::{InputAction, InputMap}; -use crate::newgui::Tool; use crate::rendering::immediate::ImmediateDraw; use crate::uiworld::UiWorld; diff --git a/native_app/src/newgui/tools/zoneedit.rs b/native_app/src/gui/tools/zoneedit.rs similarity index 98% rename from native_app/src/newgui/tools/zoneedit.rs rename to native_app/src/gui/tools/zoneedit.rs index 01129934..bc79a43a 100644 --- a/native_app/src/newgui/tools/zoneedit.rs +++ b/native_app/src/gui/tools/zoneedit.rs @@ -1,5 +1,5 @@ +use crate::gui::{ErrorTooltip, InspectedBuilding, PotentialCommands}; use crate::inputmap::{InputAction, InputMap}; -use crate::newgui::{ErrorTooltip, InspectedBuilding, PotentialCommands}; use crate::rendering::immediate::ImmediateDraw; use crate::uiworld::UiWorld; use geom::{Polygon, Vec2}; diff --git a/native_app/src/init.rs b/native_app/src/init.rs index 0035eff4..fb9f8198 100644 --- a/native_app/src/init.rs +++ b/native_app/src/init.rs @@ -1,26 +1,26 @@ +use crate::debug_gui::debug_window::{DebugObjs, DebugState, TestFieldProperties}; use crate::game_loop::Timings; -use crate::gui::debug_window::{DebugObjs, DebugState, TestFieldProperties}; -use crate::inputmap::{Bindings, InputMap}; -use crate::network::NetworkState; -use crate::newgui::addtrain::TrainSpawnResource; -use crate::newgui::bulldozer::BulldozerState; -use crate::newgui::chat::GUIChatState; -use crate::newgui::follow::FollowEntity; -use crate::newgui::keybinds::KeybindState; -use crate::newgui::lotbrush::LotBrushResource; -use crate::newgui::roadbuild::RoadBuildResource; -use crate::newgui::roadeditor::RoadEditorResource; -use crate::newgui::specialbuilding::SpecialBuildingResource; -use crate::newgui::terraforming::TerraformingResource; -use crate::newgui::toolbox::building::BuildingIcons; -use crate::newgui::windows::economy::EconomyState; -use crate::newgui::windows::load::LoadState; -use crate::newgui::windows::settings::{Settings, SettingsState}; -use crate::newgui::zoneedit::ZoneEditState; -use crate::newgui::{ +use crate::gui::addtrain::TrainSpawnResource; +use crate::gui::bulldozer::BulldozerState; +use crate::gui::chat::GUIChatState; +use crate::gui::follow::FollowEntity; +use crate::gui::keybinds::KeybindState; +use crate::gui::lotbrush::LotBrushResource; +use crate::gui::roadbuild::RoadBuildResource; +use crate::gui::roadeditor::RoadEditorResource; +use crate::gui::specialbuilding::SpecialBuildingResource; +use crate::gui::terraforming::TerraformingResource; +use crate::gui::toolbox::building::BuildingIcons; +use crate::gui::windows::economy::EconomyState; +use crate::gui::windows::load::LoadState; +use crate::gui::windows::settings::{Settings, SettingsState}; +use crate::gui::zoneedit::ZoneEditState; +use crate::gui::{ ErrorTooltip, ExitState, GuiState, InspectedBuilding, InspectedEntity, PotentialCommands, TimeAlways, Tool, }; +use crate::inputmap::{Bindings, InputMap}; +use crate::network::NetworkState; use crate::rendering::immediate::{ImmediateDraw, ImmediateSound}; use crate::uiworld::{ReceivedCommands, SaveLoadState, UiWorld}; use common::saveload::Encoder; @@ -34,7 +34,7 @@ pub fn init() { simulation::init::init(); register_resource::("settings"); #[cfg(feature = "multiplayer")] - register_resource::("netinfo"); + register_resource::("netinfo"); register_resource::("lot_brush"); register_resource::("bindings"); diff --git a/native_app/src/main.rs b/native_app/src/main.rs index 4eff6ec3..8413423a 100644 --- a/native_app/src/main.rs +++ b/native_app/src/main.rs @@ -13,12 +13,12 @@ extern crate inline_tweak; mod uiworld; mod audio; +mod debug_gui; mod game_loop; mod gui; mod init; mod inputmap; mod network; -mod newgui; mod rendering; fn main() { diff --git a/native_app/src/network.rs b/native_app/src/network.rs index 25bd48f0..16cf02e3 100644 --- a/native_app/src/network.rs +++ b/native_app/src/network.rs @@ -1,6 +1,6 @@ pub use self::inner::*; use crate::game_loop::{State, Timings}; -use crate::newgui::windows::settings::Settings; +use crate::gui::windows::settings::Settings; use crate::uiworld::{ReceivedCommands, SaveLoadState}; use common::timestep::Timestep; use simulation::utils::scheduler::SeqSchedule; @@ -101,8 +101,8 @@ fn handle_replay( #[cfg(feature = "multiplayer")] mod inner { use crate::game_loop::{State, Timings, VERSION}; + use crate::gui::windows::network::NetworkConnectionInfo; use crate::network::handle_replay; - use crate::newgui::windows::network::NetworkConnectionInfo; use crate::uiworld::{ReceivedCommands, SaveLoadState}; use common::timestep::Timestep; use networking::{ diff --git a/native_app/src/newgui/hud.rs b/native_app/src/newgui/hud.rs deleted file mode 100644 index 8cbcdd7b..00000000 --- a/native_app/src/newgui/hud.rs +++ /dev/null @@ -1,137 +0,0 @@ -use std::time::Instant; - -use goryak::{image_button, minrow, on_secondary_container, textc}; -use ordered_float::OrderedFloat; -use prototypes::ItemID; -use yakui::{reflow, Alignment, Color, Dim2, Pivot, Vec2}; - -use simulation::map_dynamic::ElectricityFlow; -use simulation::Simulation; - -use crate::newgui::hud::menu::menu_bar; -use crate::newgui::hud::time_controls::time_controls; -use crate::newgui::hud::toolbox::new_toolbox; -use crate::newgui::inspect::new_inspector; -use crate::newgui::textures::UiTextures; -use crate::newgui::windows::settings::Settings; -use crate::newgui::GuiState; -use crate::uiworld::{SaveLoadState, UiWorld}; - -pub mod chat; -pub mod keybinds; -mod menu; -mod time_controls; -pub mod toolbox; -pub mod windows; - -/// Root GUI entrypoint -pub fn render_newgui(uiworld: &UiWorld, sim: &Simulation) { - profiling::scope!("hud::render"); - auto_save(uiworld); - - if uiworld.read::().hidden { - return; - } - - yakui::column(|| { - power_errors(uiworld, sim); - new_toolbox(uiworld, sim); - menu_bar(uiworld, sim); - chat::chat(uiworld, sim); - new_inspector(uiworld, sim); - uiworld.write::().windows.render(uiworld, sim); - time_controls(uiworld, sim); - keybinds::keybind_modal(uiworld, sim) - }); - //goryak::debug_layout(); -} - -fn auto_save(uiworld: &UiWorld) { - let every = uiworld.read::().auto_save_every.into(); - let mut gui = uiworld.write::(); - if let Some(every) = every { - if gui.last_save.elapsed() > every { - uiworld.write::().please_save = true; - uiworld.save_to_disk(); - gui.last_save = Instant::now(); - } - } -} - -fn power_errors(uiworld: &UiWorld, sim: &Simulation) { - profiling::scope!("hud::power_errors"); - let map = sim.map(); - let flow = sim.read::(); - - let no_power_img = uiworld.read::().get("no_power"); - - for network in map.electricity.networks() { - if !flow.blackout(network.id) { - continue; - } - - let mut buildings_with_issues = Vec::with_capacity(network.buildings.len()); - - for &building in &network.buildings { - let Some(b) = map.get(building) else { - continue; - }; - - let center = b.obb.center(); - - let pos = center - .z(b.height + 20.0 + 1.0 * f32::cos(uiworld.time_always() + center.mag() * 0.05)); - let (screenpos, depth) = uiworld.camera().project(pos); - - let size = 10000.0 / depth; - - buildings_with_issues.push((screenpos, size)); - } - - buildings_with_issues.sort_by_key(|x| OrderedFloat(x.1)); - - for (screenpos, size) in buildings_with_issues { - reflow( - Alignment::TOP_LEFT, - Pivot::TOP_LEFT, - Dim2::pixels(screenpos.x - size * 0.5, screenpos.y - size * 0.5), - || { - let mut image = yakui::widgets::Image::new(no_power_img, Vec2::new(size, size)); - image.color = Color::WHITE.with_alpha(0.7); - image.show(); - }, - ); - } - } -} - -pub fn item_icon_yakui(uiworld: &UiWorld, id: ItemID, multiplier: i32) { - let item = id.prototype(); - minrow(5.0, || { - if let Some(id) = uiworld - .read::() - .try_get(&format!("icon/{}", item.name)) - { - if image_button( - id, - Vec2::new(32.0, 32.0), - Color::WHITE, - Color::WHITE, - Color::WHITE, - "", - ) - .hovering - { - reflow(Alignment::CENTER, Pivot::TOP_LEFT, Dim2::ZERO, || { - textc( - on_secondary_container(), - format!("{} x{}", item.name, multiplier), - ); - }); - } - } else { - textc(on_secondary_container(), format!("- {} ", &item.label)); - } - textc(on_secondary_container(), format!("x{multiplier}")) - }); -} diff --git a/native_app/src/newgui/mod.rs b/native_app/src/newgui/mod.rs deleted file mode 100644 index 9c71bf88..00000000 --- a/native_app/src/newgui/mod.rs +++ /dev/null @@ -1,167 +0,0 @@ -use crate::newgui::windows::GUIWindows; -use crate::uiworld::UiWorld; -use serde::{Deserialize, Serialize}; -use simulation::map::BuildingID; -use simulation::world_command::WorldCommand; -use simulation::{AnyEntity, Simulation}; -use std::borrow::Cow; -use std::time::Instant; - -pub mod follow; -mod hud; -pub mod inspect; -mod textures; -mod tools; - -pub use hud::*; -pub use textures::*; -pub use tools::*; - -pub struct GuiState { - pub debug_window: bool, - pub windows: GUIWindows, - pub last_save: Instant, - pub depause_warp: u32, - pub hidden: bool, -} - -impl Default for GuiState { - fn default() -> Self { - Self { - debug_window: false, - windows: Default::default(), - last_save: Instant::now(), - depause_warp: 1, - hidden: false, - } - } -} - -pub fn run_ui_systems(sim: &Simulation, uiworld: &UiWorld) { - profiling::scope!("gui::run_ui_systems"); - bulldozer::bulldozer(sim, uiworld); - inspected_aura::inspected_aura(sim, uiworld); - lotbrush::lotbrush(sim, uiworld); - roadbuild::roadbuild(sim, uiworld); - roadeditor::roadeditor(sim, uiworld); - specialbuilding::specialbuilding(sim, uiworld); - addtrain::addtrain(sim, uiworld); - zoneedit::zoneedit(sim, uiworld); - terraforming::terraforming(sim, uiworld); - - // run last so other systems can have the chance to cancel select - selectable::selectable(sim, uiworld); -} - -#[derive(Default, Clone, Debug)] -pub struct ErrorTooltip { - pub msg: Option>, - // Whether this tooltip is about something happening in the game world - // Avoid showing tooltip when the UI is hovered - pub isworld: bool, -} - -impl ErrorTooltip { - pub fn new(msg: impl Into>) -> Self { - Self { - msg: Some(msg.into()), - isworld: true, - } - } - - #[allow(unused)] - pub fn new_ui(msg: impl Into>) -> Self { - Self { - msg: Some(msg.into()), - isworld: false, - } - } -} - -#[derive(Default, Clone, Debug)] -pub struct PotentialCommands(pub Vec); - -impl PotentialCommands { - pub fn set(&mut self, cmd: WorldCommand) { - self.0.clear(); - self.0.push(cmd); - } -} - -#[derive(Copy, Clone, Debug, Default)] -pub struct InspectedBuilding { - pub e: Option, - pub dontclear: bool, -} - -#[derive(Copy, Clone, Debug)] -pub struct InspectedEntity { - pub e: Option, - pub dist2: f32, - pub dontclear: bool, -} - -impl Default for InspectedEntity { - fn default() -> Self { - Self { - e: None, - dist2: 0.0, - dontclear: false, - } - } -} - -/// Time that always progresses even when the game is paused -/// Is moduloed to 3600 -#[derive(Copy, Clone, Debug, Default)] -pub struct TimeAlways(pub f32); - -#[derive(Copy, Clone, Default, Serialize, Deserialize, Eq, PartialEq)] -pub enum Tool { - #[default] - Hand, - RoadbuildStraight, - RoadbuildCurved, - RoadEditor, - Bulldozer, - LotBrush, - SpecialBuilding, - Train, - Terraforming, -} - -impl Tool { - pub fn is_roadbuild(&self) -> bool { - matches!(self, Tool::RoadbuildStraight | Tool::RoadbuildCurved) - } - - pub fn show_arrows(&self) -> bool { - matches!( - self, - Tool::RoadbuildStraight - | Tool::RoadbuildCurved - | Tool::RoadEditor - | Tool::Bulldozer - | Tool::Train - ) - } - - pub fn show_lots(&self) -> bool { - matches!( - self, - Tool::RoadbuildStraight | Tool::RoadbuildCurved | Tool::Bulldozer | Tool::LotBrush - ) - } -} - -pub enum ExitState { - NoExit, - ExitAsk, - Saving, -} - -impl Default for ExitState { - fn default() -> Self { - Self::NoExit - } -} diff --git a/native_app/src/rendering/orbit_camera.rs b/native_app/src/rendering/orbit_camera.rs index 1daafa43..b618cc8c 100644 --- a/native_app/src/rendering/orbit_camera.rs +++ b/native_app/src/rendering/orbit_camera.rs @@ -5,8 +5,8 @@ use engine::{Context, Tesselator}; use geom::{Camera, Plane, Radians, Vec2, Vec3, AABB}; use simulation::map::pathfinding_crate::num_traits::Pow; +use crate::gui::windows::settings::Settings; use crate::inputmap::{InputAction, InputMap}; -use crate::newgui::windows::settings::Settings; /// CameraHandler3D is the camera handler for the 3D view /// It controls the camera using an orbit view diff --git a/native_app/src/uiworld.rs b/native_app/src/uiworld.rs index f7fd9491..bb3f4ab7 100644 --- a/native_app/src/uiworld.rs +++ b/native_app/src/uiworld.rs @@ -1,5 +1,5 @@ +use crate::gui::TimeAlways; use crate::init::{INIT_FUNCS, SAVELOAD_FUNCS}; -use crate::newgui::TimeAlways; use simulation::utils::resources::{RefMutSingle, RefSingle, ResourcesSingleThread}; use simulation::world_command::{WorldCommand, WorldCommands}; use simulation::{Simulation, SimulationReplayLoader};