Skip to content

Commit

Permalink
Center upgrade panel description
Browse files Browse the repository at this point in the history
  • Loading branch information
benfrankel committed Jan 4, 2024
1 parent d39b5b1 commit 329e512
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 28 deletions.
Binary file modified assets/font/pypx-B.ttf
Binary file not shown.
Binary file modified assets/font/pypx-T.ttf
Binary file not shown.
Binary file modified assets/font/pypx.ttf
Binary file not shown.
1 change: 1 addition & 0 deletions src/state/editor_screen/code_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pub fn spawn_light_code_panel(
NodeBundle {
style: Style {
width: Percent(100.0),
height: Val::ZERO,
min_height: config.code_panel_height,
padding: UiRect::all(VMin(2.0)),
..default()
Expand Down
1 change: 1 addition & 0 deletions src/state/editor_screen/info_bar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ pub fn spawn_info_bar(
NodeBundle {
style: Style {
width: Percent(100.0),
height: Val::ZERO,
min_height: config.info_bar_height,
padding: UiRect::horizontal(Px(16.0)),
align_items: AlignItems::Center,
Expand Down
2 changes: 1 addition & 1 deletion src/state/editor_screen/outline_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ impl Plugin for OutlinePanelPlugin {
#[reflect(Resource)]
pub struct UpgradeOutline(pub HashMap<UpgradeKind, usize>);

// TODO: Add scrollbar
pub fn spawn_outline_panel(
commands: &mut Commands,
config: &EditorScreenConfig,
Expand All @@ -56,6 +55,7 @@ pub fn spawn_outline_panel(
Name::new("OutlinePanel"),
NodeBundle {
style: Style {
width: Val::ZERO,
min_width: config.outline_panel_width,
height: Percent(100.0),
padding: UiRect::new(Px(12.0), Px(8.0), Px(12.0), Px(12.0)),
Expand Down
49 changes: 23 additions & 26 deletions src/state/editor_screen/upgrade_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ pub fn spawn_upgrade_panel(
Name::new("UpgradePanel"),
NodeBundle {
style: Style {
width: Val::ZERO,
min_width: config.upgrade_panel_width,
height: Percent(100.0),
align_items: AlignItems::Center,
Expand Down Expand Up @@ -95,6 +96,7 @@ pub fn spawn_upgrade_panel(
NodeBundle {
style: Style {
width: Percent(100.0),
align_items: AlignItems::Center,
flex_direction: FlexDirection::Column,
flex_grow: 1.0,
..default()
Expand Down Expand Up @@ -248,29 +250,23 @@ fn spawn_separator(
commands: &mut Commands,
config: &EditorScreenConfig,
theme: &EditorScreenTheme,
parent: Entity,
) {
) -> Entity {
commands
.spawn((
Name::new("Separator"),
NodeBundle {
style: Style {
width: Percent(100.0),
max_height: Px(0.0),
border: UiRect::top(config.separator_width),
margin: UiRect {
left: Px(0.0),
right: Px(0.0),
// 16 vertical margin, compensates for buttons
top: Px(6.0),
bottom: Px(16.0),
},
margin: UiRect::vertical(Px(16.0)),
..default()
},
border_color: theme.separator_color.into(),
..default()
},
))
.set_parent(parent);
.id()
}

fn spawn_submit_button(commands: &mut Commands, config: &EditorScreenConfig) -> Entity {
Expand Down Expand Up @@ -348,7 +344,7 @@ fn offer_next_upgrades(
) {
let config = &config.editor_screen;
let theme = &theme.0;
for (entity, buttons) in &container_query {
for (container, buttons) in &container_query {
// Despawn old upgrade options
for &button in buttons.into_iter().flatten() {
despawn.recursive(button);
Expand All @@ -359,7 +355,8 @@ fn offer_next_upgrades(
for kind in next_upgrades {
if kind == UpgradeKind::RefreshUpgradeList {
// Add a separator.
spawn_separator(&mut commands, config, theme, entity);
let separator = spawn_separator(&mut commands, config, theme);
commands.entity(separator).set_parent(container);
}
let upgrade_button = spawn_upgrade_button(
&mut commands,
Expand All @@ -369,29 +366,29 @@ fn offer_next_upgrades(
kind,
&simulation,
);
commands.entity(upgrade_button).set_parent(entity);
commands.entity(upgrade_button).set_parent(container);
}

// Show description if present.
if !desc.is_empty() {
spawn_separator(&mut commands, config, theme, entity);
let mut text_bundle = TextBundle::from_section(
desc,
TextStyle {
font: FONT_HANDLE,
color: theme.outline_panel_text_color,
..default()
},
);
// Panel width - horizontal padding
text_bundle.style.max_width = Px(280.0 - 24.0);
let separator = spawn_separator(&mut commands, config, theme);
commands.entity(separator).set_parent(container);

commands
.spawn((
Name::new("Description"),
text_bundle,
TextBundle::from_section(
desc,
TextStyle {
font: FONT_HANDLE,
color: theme.outline_panel_text_color,
..default()
},
)
.with_text_alignment(TextAlignment::Center),
FontSize::new(config.outline_panel_font_size),
))
.set_parent(entity);
.set_parent(container);
}
}
}
2 changes: 1 addition & 1 deletion src/upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ fn load_upgrade_sequence(mut commands: Commands) {
),
(
vec![TouchOfLifePlugin],
"\"I don't know what I'm making, but I should start spawning entities.\"".to_string(),
"\"I don't know what I'm making, but I should start by spawning some entities.\"".to_string(),
),

// Reward
Expand Down

0 comments on commit 329e512

Please sign in to comment.