Skip to content

Commit

Permalink
Add credits view
Browse files Browse the repository at this point in the history
Also fix menu navigation, as it broke at some point.
  • Loading branch information
haihala committed Dec 12, 2024
1 parent f4e6b0f commit 960e1f4
Show file tree
Hide file tree
Showing 10 changed files with 199 additions and 78 deletions.
2 changes: 1 addition & 1 deletion client/foundation/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ mod args;
pub use args::{Dev, WagArgs};

mod cancels;
pub use cancels::*;
pub use cancels::{ActionCategory, CancelType};

mod character_id;
pub use character_id::{CharacterId, Characters, LocalCharacter};
Expand Down
1 change: 1 addition & 0 deletions client/foundation/src/time/game_flow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ pub enum MatchState {
pub enum GameState {
#[default]
MainMenu,
Credits,

Local(LocalState),
Online(OnlineState),
Expand Down
7 changes: 6 additions & 1 deletion client/foundation/src/time/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ pub struct RollbackSchedule;
#[derive(Debug, SystemSet, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum SystemStep {
HouseKeeping,
MenuNavigation,
StateTransitions,
Inputs,
Physics,
Expand All @@ -69,7 +70,11 @@ impl Plugin for TimePlugin {
fn build(&self, app: &mut App) {
app.configure_sets(
RollbackSchedule,
(SystemStep::HouseKeeping, SystemStep::StateTransitions)
(
SystemStep::HouseKeeping,
SystemStep::MenuNavigation,
SystemStep::StateTransitions,
)
.chain()
.before(SystemStep::Inputs),
)
Expand Down
10 changes: 5 additions & 5 deletions client/lib/src/ui/views/character_select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ use crate::{
};
use bevy::prelude::*;
use foundation::{
CharacterId, Characters, Controllers, GameButton, GameState, InputEvent, LocalCharacter,
LocalController, LocalState, MatchState, OnlineState, Player, StickPosition,
CharacterId, Characters, Controllers, GameButton, GameState, InputEvent, InputStream,
LocalCharacter, LocalController, LocalState, MatchState, OnlineState, Player, StickPosition,
CHARACTER_SELECT_HIGHLIGHT_TEXT_COLOR, GENERIC_TEXT_COLOR, VERTICAL_MENU_OPTION_BACKGROUND,
};
use strum::IntoEnumIterator;

use super::{setup_view_title, MenuInputs};
use super::setup_view_title;

#[derive(Debug, Resource, Deref, DerefMut)]
pub struct CharacterSelectNav(SharedVerticalNav);
Expand Down Expand Up @@ -143,10 +143,10 @@ pub fn navigate_character_select(
options: Query<&CharacterId>,
mut game_state: ResMut<NextState<GameState>>,
mut match_state: ResMut<NextState<MatchState>>,
mut events: ResMut<MenuInputs>,
input_stream: ResMut<InputStream>,
local_controller: Option<Res<LocalController>>,
) {
while let Some(ev) = events.pop_front() {
for ev in input_stream.events.clone() {
let player = if let Some(ref lc) = local_controller {
if lc.0 != ev.player_handle {
continue;
Expand Down
8 changes: 4 additions & 4 deletions client/lib/src/ui/views/controller_assignment.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use bevy::{ecs::system::SystemId, prelude::*};
use foundation::{
Controllers, GameButton, GameState, InputEvent, LocalState, Player, StickPosition,
Controllers, GameButton, GameState, InputEvent, InputStream, LocalState, Player, StickPosition,
CONTROLLER_ASSIGNMENT_SIDE_COLOR,
};

use crate::{assets::Fonts, entity_management::VisibleInStates};

use super::{setup_view_title, MenuInputs};
use super::setup_view_title;

#[derive(Debug, Resource, Default)]
pub struct ControllerAssignment {
Expand Down Expand Up @@ -168,11 +168,11 @@ fn create_unused_controller_area(fonts: &Fonts, root: &mut ChildBuilder) {
pub fn navigate_controller_assignment_menu(
mut commands: Commands,
mut ca: ResMut<ControllerAssignment>,
mut events: ResMut<MenuInputs>,
input_stream: ResMut<InputStream>,
callback: Res<SubmitCallback>,
mut state: ResMut<NextState<GameState>>,
) {
while let Some(ev) = events.pop_front() {
for ev in input_stream.events.clone() {
match ev.event {
InputEvent::Point(StickPosition::E) => ca.right(ev.player_handle),
InputEvent::Point(StickPosition::W) => ca.left(ev.player_handle),
Expand Down
134 changes: 134 additions & 0 deletions client/lib/src/ui/views/credits.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
pub use bevy::prelude::*;
use foundation::{GameButton, GameState, InputEvent, InputStream, StickPosition};

use crate::{assets::Fonts, entity_management::VisibleInStates};

#[derive(Component)]
pub struct CreditsNav;

pub fn setup_credits_menu(mut commands: Commands, fonts: Res<Fonts>) {
commands
.spawn((
NodeBundle {
style: Style {
height: Val::Percent(100.0),
width: Val::Percent(100.0),
position_type: PositionType::Absolute,
left: Val::Percent(0.0),
top: Val::Percent(0.0),
flex_direction: FlexDirection::Column,
row_gap: Val::Percent(5.0),
padding: UiRect::all(Val::Percent(20.0)),
align_items: AlignItems::Center,
..default()
},
..default()
},
VisibleInStates(vec![GameState::Credits]),
CreditsNav,
Name::new("Credits UI"),
))
.with_children(|cb| {
cb.spawn((
TextBundle::from_section(
"Credits",
TextStyle {
font: fonts.basic.clone(),
font_size: 128.0,
..default()
},
),
Name::new("Credits main heading"),
));

for section in credits_sections() {
cb.spawn((
TextBundle {
style: Style {
margin: UiRect::top(Val::Percent(4.0)),
..default()
},
..TextBundle::from_section(
section.heading.clone(),
TextStyle {
font: fonts.basic.clone(),
font_size: 48.0,
..default()
},
)
},
Name::new(format!("{} credits subheading", section.heading)),
));

for name in section.people {
cb.spawn((
TextBundle::from_section(
name.clone(),
TextStyle {
font: fonts.basic.clone(),
font_size: 24.0,
..default()
},
),
Name::new(format!("{} credit for {}", name, section.heading)),
));
}
}
});
}

struct CreditSection {
heading: String,
people: Vec<String>,
}

fn credits_sections() -> Vec<CreditSection> {
vec![
CreditSection {
heading: "Playtesting".into(),
people: vec![
"Friends".into(),
"Family".into(),
"And especially the Tampere FGC, yall rock".into(),
],
},
CreditSection {
heading: "And everything else".into(),
people: vec!["Eero Häihälä".into()],
},
]
}

const SCROLL_SPEED: f32 = 1.0;

pub fn navigate_credits(
input_stream: Res<InputStream>,
mut next_state: ResMut<NextState<GameState>>,
mut ui_root: Query<&mut Style, With<CreditsNav>>,
mut scroll_direction: Local<f32>,
) {
let mut style = ui_root.single_mut();

for ev in input_stream.events.clone() {
match ev.event {
InputEvent::Press(GameButton::Strong) => {
style.top = Val::Percent(0.0);
next_state.set(GameState::MainMenu);
}
InputEvent::Point(dir) => {
match dir {
StickPosition::N => *scroll_direction = 1.0,
StickPosition::S => *scroll_direction = -1.0,
_ => *scroll_direction = 0.0,
};
}
_ => {}
}
}

let Val::Percent(old) = style.top else {
panic!()
};
let new = old + SCROLL_SPEED * *scroll_direction;
style.top = Val::Percent(new.clamp(-10.0, 0.0));
}
11 changes: 6 additions & 5 deletions client/lib/src/ui/views/end_screen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ use crate::{
};
use bevy::prelude::*;
use foundation::{
Controllers, GameButton, GameResult, GameState, InputEvent, MatchState, Player, StickPosition,
CHARACTER_SELECT_HIGHLIGHT_TEXT_COLOR, GENERIC_TEXT_COLOR, VERTICAL_MENU_OPTION_BACKGROUND,
Controllers, GameButton, GameResult, GameState, InputEvent, InputStream, MatchState, Player,
StickPosition, CHARACTER_SELECT_HIGHLIGHT_TEXT_COLOR, GENERIC_TEXT_COLOR,
VERTICAL_MENU_OPTION_BACKGROUND,
};

use super::{setup_view_subtitle, setup_view_title, MenuInputs};
use super::{setup_view_subtitle, setup_view_title};

#[derive(Debug, Resource, Deref, DerefMut)]
pub struct EndScreenNav(SharedVerticalNav);
Expand Down Expand Up @@ -160,14 +161,14 @@ fn setup_end_screen_option(
pub fn navigate_end_screen(
mut commands: Commands,
mut nav: ResMut<EndScreenNav>,
mut events: ResMut<MenuInputs>,
input_stream: ResMut<InputStream>,
controllers: Res<Controllers>,
options: Query<&EndScreenOption>,
mut next_game_state: ResMut<NextState<GameState>>,
mut next_match_state: ResMut<NextState<MatchState>>,
mut quitter: EventWriter<AppExit>,
) {
while let Some(ev) = events.pop_front() {
for ev in input_stream.events.clone() {
let Some(player) = controllers.get_player(ev.player_handle) else {
continue;
};
Expand Down
16 changes: 11 additions & 5 deletions client/lib/src/ui/views/main_menu.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use bevy::prelude::*;
use foundation::{
GameButton, GameState, InputEvent, LocalController, LocalState, OnlineState, StickPosition,
GENERIC_TEXT_COLOR, MAIN_MENU_HIGHLIGHT_TEXT_COLOR,
GameButton, GameState, InputEvent, InputStream, LocalController, LocalState, OnlineState,
StickPosition, GENERIC_TEXT_COLOR, MAIN_MENU_HIGHLIGHT_TEXT_COLOR,
};

use crate::{assets::Fonts, entity_management::VisibleInStates, ui::VerticalMenuNavigation};

use super::{setup_view_title, MenuInputs};
use super::setup_view_title;

#[derive(Debug, Resource, Deref, DerefMut)]
pub struct MainMenuNav(VerticalMenuNavigation);
Expand All @@ -15,6 +15,7 @@ pub struct MainMenuNav(VerticalMenuNavigation);
pub enum MainMenuOptions {
LocalPlay,
OnlinePlay,
Credits,
QuitToDesktop,
}

Expand All @@ -26,6 +27,7 @@ impl std::fmt::Display for MainMenuOptions {
match self {
MainMenuOptions::LocalPlay => "Local play",
MainMenuOptions::OnlinePlay => "Online play",
MainMenuOptions::Credits => "Credits",
MainMenuOptions::QuitToDesktop => "Quit to desktop",
}
)
Expand Down Expand Up @@ -69,6 +71,7 @@ fn setup_buttons(root: &mut ChildBuilder, fonts: &Fonts) -> Vec<Entity> {
vec![
MainMenuOptions::LocalPlay,
MainMenuOptions::OnlinePlay,
MainMenuOptions::Credits,
MainMenuOptions::QuitToDesktop,
]
.into_iter()
Expand All @@ -93,12 +96,12 @@ fn setup_buttons(root: &mut ChildBuilder, fonts: &Fonts) -> Vec<Entity> {
pub fn navigate_main_menu(
mut commands: Commands,
mut nav: ResMut<MainMenuNav>,
mut events: ResMut<MenuInputs>,
input_stream: ResMut<InputStream>,
options: Query<&MainMenuOptions>,
mut state: ResMut<NextState<GameState>>,
mut exit: EventWriter<AppExit>,
) {
while let Some(ev) = events.pop_front() {
for ev in input_stream.events.clone() {
match ev.event {
InputEvent::Point(StickPosition::N) => nav.up(),
InputEvent::Point(StickPosition::S) => nav.down(),
Expand All @@ -110,6 +113,9 @@ pub fn navigate_main_menu(
commands.insert_resource(LocalController(ev.player_handle));
state.set(GameState::Online(OnlineState::CharacterSelect));
}
MainMenuOptions::Credits => {
state.set(GameState::Credits);
}
MainMenuOptions::QuitToDesktop => {
exit.send_default();
}
Expand Down
Loading

0 comments on commit 960e1f4

Please sign in to comment.