-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rename newgui -> gui now that it's main ui
- Loading branch information
Showing
48 changed files
with
428 additions
and
428 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
native_app/src/gui/debug_window.rs → native_app/src/debug_gui/debug_window.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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::<GuiState>().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::<ErrorTooltip>()); | ||
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::<PotentialCommands>().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::<Government>().money { | ||
ui.colored_label(Color32::RED, format!("{cost} too expensive")); | ||
} else { | ||
ui.label(cost.to_string()); | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
pub mod debug_inspect; | ||
pub mod debug_window; | ||
pub mod hud; | ||
|
||
pub use hud::*; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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::<GuiState>().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::<GuiState>().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::<ErrorTooltip>()); | ||
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::<Settings>().auto_save_every.into(); | ||
let mut gui = uiworld.write::<GuiState>(); | ||
if let Some(every) = every { | ||
if gui.last_save.elapsed() > every { | ||
uiworld.write::<SaveLoadState>().please_save = true; | ||
uiworld.save_to_disk(); | ||
gui.last_save = Instant::now(); | ||
} | ||
} | ||
} | ||
|
||
if ui.is_pointer_over_area() { | ||
return; | ||
} | ||
let pot = &mut uiworld.write::<PotentialCommands>().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::<ElectricityFlow>(); | ||
|
||
if cost == Money::ZERO { | ||
return; | ||
let no_power_img = uiworld.read::<UiTextures>().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::<Government>().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::<UiTextures>() | ||
.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}")) | ||
}); | ||
} |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.