Skip to content

Commit

Permalink
Add return button to results screen
Browse files Browse the repository at this point in the history
  • Loading branch information
benfrankel committed Dec 8, 2023
1 parent f634b2a commit f60dd95
Show file tree
Hide file tree
Showing 13 changed files with 258 additions and 154 deletions.
10 changes: 7 additions & 3 deletions assets/config.ron
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
title_font_size: Vw(4.5),

button_width: Vw(40.0),
button_border_color: Rgba(red: 0.118, green: 0.306, blue: 0.820, alpha: 1.000),
button_border_width: Px(2.0),
button_normal_color: Rgba(red: 0.000, green: 0.188, blue: 0.702, alpha: 1.000),
button_hovered_color: Rgba(red: 0.039, green: 0.227, blue: 0.741, alpha: 1.000),
button_pressed_color: Rgba(red: 0.000, green: 0.176, blue: 0.690, alpha: 1.000),
Expand Down Expand Up @@ -131,13 +129,19 @@
background_color: Rgba(red: 0.067, green: 0.067, blue: 0.067, alpha: 1.000),
border_color: Rgba(red: 0.161, green: 0.161, blue: 0.161, alpha: 1.000),
border_width: VMin(0.9),
font_size: Vw(2.5),

title_text_color: Rgba(red: 0.737, green: 0.737, blue: 0.737, alpha: 1.000),
title_font_size: Vw(5.0),

table_header_background_color: Rgba(red: 0.106, green: 0.106, blue: 0.106, alpha: 1.000),
table_header_text_color: Rgba(red: 0.624, green: 0.624, blue: 0.624, alpha: 1.000),
table_text_color: Rgba(red: 0.737, green: 0.737, blue: 0.737, alpha: 1.000),
table_font_size: Vw(2.5),

return_button_normal_color: Rgba(red: 0.000, green: 0.188, blue: 0.702, alpha: 1.000),
return_button_hovered_color: Rgba(red: 0.039, green: 0.227, blue: 0.741, alpha: 1.000),
return_button_pressed_color: Rgba(red: 0.000, green: 0.176, blue: 0.690, alpha: 1.000),
return_button_text_color: Rgba(red: 1.000, green: 1.000, blue: 1.000, alpha: 1.000),
return_button_font_size: Px(32.0),
),
)
4 changes: 1 addition & 3 deletions src/camera.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ impl Plugin for CameraPlugin {
}
}

pub const CAMERA_WIDTH: f32 = 320.0;
pub const CAMERA_HEIGHT: f32 = 180.0;
pub const CAMERA_SCALING: f32 = 6.0;
pub const CAMERA_SCALING: f32 = 4.0;

fn spawn_camera(mut commands: Commands, mut root: ResMut<AppRoot>) {
root.camera = commands
Expand Down
14 changes: 7 additions & 7 deletions src/state/editor_screen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ mod upgrade_panel;

// Expose this for the upgrades.
use bevy::prelude::*;
use bevy::ui::Val::*;
use bevy_asset_loader::prelude::*;
pub use code_panel::spawn_code_panel;
use serde::Deserialize;
Expand Down Expand Up @@ -109,9 +110,8 @@ fn enter_editor_screen(
let config = &config.editor_screen;
commands.insert_resource(ClearColor(config.scene_view_background_color));

let editor_screen =
spawn_editor_screen(&mut commands, config, &upgrade_list, &simulation, true);
commands.entity(editor_screen).set_parent(root.ui);
let screen = spawn_editor_screen(&mut commands, config, &upgrade_list, &simulation, true);
commands.entity(screen).set_parent(root.ui);
}

pub fn spawn_editor_screen(
Expand All @@ -131,8 +131,8 @@ pub fn spawn_editor_screen(
Name::new("EditorScreen"),
NodeBundle {
style: Style {
width: Val::Percent(100.0),
height: Val::Percent(100.0),
width: Percent(100.0),
height: Percent(100.0),
flex_direction: FlexDirection::Column,
..default()
},
Expand All @@ -149,8 +149,8 @@ pub fn spawn_editor_screen(
Name::new("HBox"),
NodeBundle {
style: Style {
width: Val::Percent(100.0),
height: Val::Percent(100.0),
width: Percent(100.0),
height: Percent(100.0),
..default()
},
..default()
Expand Down
19 changes: 14 additions & 5 deletions src/state/editor_screen/code_panel.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,29 @@
use bevy::prelude::*;
use bevy::ui::Val::*;

use crate::state::editor_screen::EditorScreenTheme;
use crate::ui::CodeTyper;
use crate::ui::FontSize;
use crate::ui::FONT_HANDLE;

const LIGHT_THEME_TEXT: &str = "Aargh, my eyes!
I cannot work with this light theme!
I need to install a dark theme from the panel on the right.
The installed upgrades will appear on the left panel.";

/// Spawns the fake code panel with light theme.
pub fn spawn_light_code_panel(commands: &mut Commands, theme: &EditorScreenTheme) -> Entity {
let code_panel = commands
.spawn((
Name::new("CodePanel"),
NodeBundle {
style: Style {
width: Val::Percent(100.0),
width: Percent(100.0),
min_height: theme.code_panel_height,
padding: UiRect::all(Val::VMin(2.0)),
padding: UiRect::all(VMin(2.0)),
..default()
},
background_color: theme.code_panel_background_color.into(),
Expand All @@ -27,7 +36,7 @@ pub fn spawn_light_code_panel(commands: &mut Commands, theme: &EditorScreenTheme
.spawn((
Name::new("CodePanelText"),
TextBundle::from_section(
"Aargh, my eyes!\n\nI cannot work with this light theme!\n\nI need to install a dark theme from the panel on the right.\n\nThe installed upgrades will appear on the left panel.",
LIGHT_THEME_TEXT,
TextStyle {
font: FONT_HANDLE,
color: theme.code_panel_text_color,
Expand All @@ -47,9 +56,9 @@ pub fn spawn_code_panel(commands: &mut Commands, theme: &EditorScreenTheme) -> E
Name::new("CodePanel"),
NodeBundle {
style: Style {
width: Val::Percent(100.0),
width: Percent(100.0),
min_height: theme.code_panel_height,
padding: UiRect::all(Val::VMin(2.0)),
padding: UiRect::all(VMin(2.0)),
..default()
},
background_color: theme.code_panel_background_color.into(),
Expand Down
7 changes: 4 additions & 3 deletions src/state/editor_screen/info_bar.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use bevy::prelude::*;
use bevy::ui::Val::*;

use super::EditorScreenTheme;
use crate::simulation::Simulation;
use crate::state::editor_screen::EditorScreenTheme;
use crate::ui::FontSize;
use crate::ui::BOLD_FONT_HANDLE;
use crate::util::pretty_num;
Expand All @@ -22,9 +23,9 @@ pub fn spawn_info_bar(commands: &mut Commands, theme: &EditorScreenTheme) -> Ent
Name::new("InfoBar"),
NodeBundle {
style: Style {
width: Val::Percent(100.0),
width: Percent(100.0),
min_height: theme.info_bar_height,
padding: UiRect::horizontal(Val::Px(16.0)),
padding: UiRect::horizontal(Px(16.0)),
align_items: AlignItems::Center,
..default()
},
Expand Down
13 changes: 7 additions & 6 deletions src/state/editor_screen/outline_panel.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use bevy::math::vec2;
use bevy::prelude::*;
use bevy::ui::Val::*;
use bevy::utils::HashMap;

use crate::config::Config;
Expand Down Expand Up @@ -49,8 +50,8 @@ pub fn spawn_outline_panel(commands: &mut Commands, theme: &EditorScreenTheme) -
NodeBundle {
style: Style {
min_width: theme.outline_panel_width,
height: Val::Percent(100.0),
padding: UiRect::all(Val::Px(12.0)),
height: Percent(100.0),
padding: UiRect::all(Px(12.0)),
flex_direction: FlexDirection::Column,
..default()
},
Expand All @@ -76,7 +77,7 @@ pub fn spawn_outline_panel(commands: &mut Commands, theme: &EditorScreenTheme) -
style: Style {
// Hiding this because it looks bad :(
// display: Display::None,
margin: UiRect::bottom(Val::Px(10.0)),
margin: UiRect::bottom(Px(10.0)),
..default()
},
..default()
Expand All @@ -102,9 +103,9 @@ fn spawn_outline_entry(
Name::new("OutlineEntry"),
NodeBundle {
style: Style {
width: Val::Percent(100.0),
margin: UiRect::bottom(Val::Px(1.0)),
padding: UiRect::all(Val::Px(4.0)),
width: Percent(100.0),
margin: UiRect::bottom(Px(1.0)),
padding: UiRect::all(Px(4.0)),
..default()
},
..default()
Expand Down
25 changes: 13 additions & 12 deletions src/state/editor_screen/upgrade_panel.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use bevy::math::vec2;
use bevy::prelude::*;
use bevy::ui::Val::*;
use bevy_mod_picking::prelude::*;
use rand::seq::SliceRandom;
use rand::thread_rng;
Expand Down Expand Up @@ -55,9 +56,9 @@ pub fn spawn_upgrade_panel(
NodeBundle {
style: Style {
min_width: theme.upgrade_panel_width,
height: Val::Percent(100.0),
height: Percent(100.0),
align_items: AlignItems::Center,
padding: UiRect::all(Val::Px(12.0)),
padding: UiRect::all(Px(12.0)),
flex_direction: FlexDirection::Column,
..default()
},
Expand All @@ -79,7 +80,7 @@ pub fn spawn_upgrade_panel(
},
)
.with_style(Style {
margin: UiRect::bottom(Val::Px(15.0)),
margin: UiRect::bottom(Px(15.0)),
..default()
}),
FontSize::new(theme.upgrade_panel_header_font_size),
Expand All @@ -91,7 +92,7 @@ pub fn spawn_upgrade_panel(
Name::new("UpgradeContainer"),
NodeBundle {
style: Style {
width: Val::Percent(100.0),
width: Percent(100.0),
flex_direction: FlexDirection::Column,
flex_grow: 1.0,
..default()
Expand Down Expand Up @@ -119,8 +120,8 @@ pub fn spawn_upgrade_panel(
Name::new("SubmitContainer"),
NodeBundle {
style: Style {
width: Val::Percent(100.0),
height: Val::Px(130.0),
width: Percent(100.0),
height: Px(130.0),
align_items: AlignItems::Center,
justify_content: JustifyContent::Center,
..default()
Expand Down Expand Up @@ -152,14 +153,14 @@ fn spawn_upgrade_button(
Name::new("UpgradeButton"),
ButtonBundle {
style: Style {
width: Val::Percent(100.0),
width: Percent(100.0),
height: theme.upgrade_button_height,
align_items: AlignItems::Center,
justify_content: JustifyContent::Center,
margin: UiRect::bottom(Val::Px(10.0)),
padding: UiRect::vertical(Val::Px(4.0)),
margin: UiRect::bottom(Px(10.0)),
padding: UiRect::vertical(Px(4.0)),
flex_direction: FlexDirection::Column,
row_gap: Val::Px(4.0),
row_gap: Px(4.0),
..default()
},
background_color: theme.upgrade_button_normal_color.into(),
Expand Down Expand Up @@ -249,9 +250,9 @@ fn spawn_submit_button(commands: &mut Commands, theme: &EditorScreenTheme) -> En
Name::new("SubmitButton"),
ButtonBundle {
style: Style {
width: Val::Percent(80.0),
width: Percent(80.0),
height: theme.submit_button_height,
padding: UiRect::all(Val::Px(10.0)),
padding: UiRect::all(Px(10.0)),
justify_content: JustifyContent::Center,
align_items: AlignItems::Center,
..default()
Expand Down
22 changes: 11 additions & 11 deletions src/state/loading_screen.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use bevy::core::FrameCount;
use bevy::prelude::*;
use bevy::ui::Val::*;
use bevy_asset_loader::prelude::*;
use iyes_progress::prelude::*;
use serde::Deserialize;
Expand All @@ -8,7 +9,6 @@ use serde::Serialize;
use crate::config::Config;
use crate::state::editor_screen::EditorScreenAssets;
use crate::state::AppState::*;
use crate::ui::vmin;
use crate::ui::FontSize;
use crate::ui::BOLD_FONT_HANDLE;
use crate::AppRoot;
Expand Down Expand Up @@ -53,8 +53,8 @@ fn enter_loading(mut commands: Commands, root: Res<AppRoot>, config: Res<Config>
Name::new("LoadingScreen"),
NodeBundle {
style: Style {
width: Val::Percent(100.0),
height: Val::Percent(100.0),
width: Percent(100.0),
height: Percent(100.0),
..default()
},
..default()
Expand All @@ -71,8 +71,8 @@ fn enter_loading(mut commands: Commands, root: Res<AppRoot>, config: Res<Config>
flex_direction: FlexDirection::Column,
align_items: AlignItems::Center,
justify_content: JustifyContent::Center,
width: Val::Percent(100.0),
height: Val::Percent(100.0),
width: Percent(100.0),
height: Percent(100.0),
..default()
},
..default()
Expand All @@ -84,7 +84,7 @@ fn enter_loading(mut commands: Commands, root: Res<AppRoot>, config: Res<Config>
Name::new("LoadingHeader"),
TextBundle {
style: Style {
margin: UiRect::all(vmin(8.0)),
margin: UiRect::all(VMin(4.5)),
..default()
},
text: Text::from_section(
Expand All @@ -105,8 +105,8 @@ fn enter_loading(mut commands: Commands, root: Res<AppRoot>, config: Res<Config>
Name::new("LoadingBarContainer"),
NodeBundle {
style: Style {
width: Val::Percent(60.0),
height: Val::Percent(7.5),
width: Percent(60.0),
height: Percent(7.5),
border: UiRect::all(config.border_width),
..default()
},
Expand All @@ -120,8 +120,8 @@ fn enter_loading(mut commands: Commands, root: Res<AppRoot>, config: Res<Config>
NodeBundle {
background_color: BackgroundColor(config.foreground_color),
style: Style {
width: Val::Percent(0.0),
height: Val::Percent(100.0),
width: Percent(0.0),
height: Percent(100.0),
..default()
},
..default()
Expand Down Expand Up @@ -149,7 +149,7 @@ fn update_loading(
*last_done = done;

for mut style in &mut loading_bar_query {
style.width = Val::Percent(100.0 * done as f32 / total as f32);
style.width = Percent(100.0 * done as f32 / total as f32);
}

info!("[Frame {}] Loading: {done} / {total}", frame.0);
Expand Down
Loading

0 comments on commit f60dd95

Please sign in to comment.