mirror of
https://github.com/doukutsu-rs/doukutsu-rs
synced 2025-03-23 10:29:18 +00:00
soundtrack switching menu
This commit is contained in:
parent
e09ea37bda
commit
3374f13c2b
|
@ -22,7 +22,7 @@ enum CurrentMenu {
|
|||
pub struct PauseMenu {
|
||||
is_paused: bool,
|
||||
current_menu: CurrentMenu,
|
||||
option_menu: SettingsMenu,
|
||||
settings_menu: SettingsMenu,
|
||||
controller: CombinedMenuController,
|
||||
pause_menu: Menu,
|
||||
confirm_menu: Menu,
|
||||
|
@ -36,7 +36,7 @@ impl PauseMenu {
|
|||
PauseMenu {
|
||||
is_paused: false,
|
||||
current_menu: CurrentMenu::PauseMenu,
|
||||
option_menu: SettingsMenu::new(),
|
||||
settings_menu: SettingsMenu::new(),
|
||||
controller: CombinedMenuController::new(),
|
||||
pause_menu: main,
|
||||
confirm_menu: Menu::new(0, 0, 75, 0),
|
||||
|
@ -62,7 +62,7 @@ impl PauseMenu {
|
|||
|
||||
self.update_sizes(state);
|
||||
|
||||
self.option_menu.init(state, ctx)?;
|
||||
self.settings_menu.init(state, ctx)?;
|
||||
|
||||
self.controller.update(state, ctx)?;
|
||||
self.controller.update_trigger();
|
||||
|
@ -136,7 +136,7 @@ impl PauseMenu {
|
|||
},
|
||||
CurrentMenu::OptionsMenu => {
|
||||
let cm = &mut self.current_menu;
|
||||
self.option_menu.tick(
|
||||
self.settings_menu.tick(
|
||||
&mut || {
|
||||
*cm = CurrentMenu::PauseMenu;
|
||||
},
|
||||
|
@ -186,7 +186,7 @@ impl PauseMenu {
|
|||
graphics::set_clip_rect(ctx, None)?;
|
||||
}
|
||||
CurrentMenu::OptionsMenu => {
|
||||
self.option_menu.draw(state, ctx)?;
|
||||
self.settings_menu.draw(state, ctx)?;
|
||||
}
|
||||
CurrentMenu::ConfirmMenu => {
|
||||
graphics::set_clip_rect(ctx, Some(clip_rect))?;
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
use itertools::Itertools;
|
||||
|
||||
use crate::framework::context::Context;
|
||||
use crate::framework::error::GameResult;
|
||||
use crate::framework::filesystem;
|
||||
use crate::input::combined_menu_controller::CombinedMenuController;
|
||||
use crate::menu::MenuEntry;
|
||||
use crate::menu::{Menu, MenuSelectionResult};
|
||||
|
@ -13,6 +16,7 @@ enum CurrentMenu {
|
|||
MainMenu,
|
||||
GraphicsMenu,
|
||||
SoundMenu,
|
||||
SoundtrackMenu,
|
||||
}
|
||||
|
||||
pub struct SettingsMenu {
|
||||
|
@ -20,6 +24,8 @@ pub struct SettingsMenu {
|
|||
main: Menu,
|
||||
graphics: Menu,
|
||||
sound: Menu,
|
||||
soundtrack: Menu,
|
||||
pub on_title: bool,
|
||||
}
|
||||
|
||||
static DISCORD_LINK: &str = "https://discord.gg/fbRsNNB";
|
||||
|
@ -29,8 +35,9 @@ impl SettingsMenu {
|
|||
let main = Menu::new(0, 0, 220, 0);
|
||||
let graphics = Menu::new(0, 0, 180, 0);
|
||||
let sound = Menu::new(0, 0, 260, 0);
|
||||
let soundtrack = Menu::new(0, 0, 260, 0);
|
||||
|
||||
SettingsMenu { current: CurrentMenu::MainMenu, main, graphics, sound }
|
||||
SettingsMenu { current: CurrentMenu::MainMenu, main, graphics, sound, soundtrack, on_title: false }
|
||||
}
|
||||
|
||||
pub fn init(&mut self, state: &mut SharedGameState, ctx: &mut Context) -> GameResult {
|
||||
|
@ -83,7 +90,7 @@ impl SettingsMenu {
|
|||
"Linear".to_owned(),
|
||||
"Cosine".to_owned(),
|
||||
"Cubic".to_owned(),
|
||||
"Polyphase".to_owned(),
|
||||
"Linear+LP".to_owned(),
|
||||
],
|
||||
vec![
|
||||
"(Fastest, lowest quality)".to_owned(),
|
||||
|
@ -94,9 +101,32 @@ impl SettingsMenu {
|
|||
],
|
||||
));
|
||||
self.sound.push_entry(MenuEntry::DisabledWhite("".to_owned()));
|
||||
self.sound.push_entry(MenuEntry::Disabled(format!("Soundtrack: {}", state.settings.soundtrack)));
|
||||
self.sound.push_entry(MenuEntry::Active(format!("Soundtrack: {}", state.settings.soundtrack)));
|
||||
self.sound.push_entry(MenuEntry::Active("< Back".to_owned()));
|
||||
|
||||
let mut soundtrack_entries = state.constants.soundtracks.keys().map(|s| s.to_owned()).collect_vec();
|
||||
soundtrack_entries.push("Organya".to_owned());
|
||||
|
||||
if let Ok(dir) = filesystem::read_dir(ctx, "/Soundtracks/") {
|
||||
for entry in dir {
|
||||
if filesystem::is_dir(ctx, &entry) {
|
||||
let filename = entry.file_name().unwrap().to_string_lossy().to_string();
|
||||
|
||||
if !soundtrack_entries.contains(&filename) {
|
||||
soundtrack_entries.push(filename);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
soundtrack_entries.sort();
|
||||
|
||||
for soundtrack in soundtrack_entries {
|
||||
self.soundtrack.push_entry(MenuEntry::Active(soundtrack));
|
||||
}
|
||||
|
||||
self.soundtrack.push_entry(MenuEntry::Active("< Back".to_owned()));
|
||||
|
||||
self.update_sizes(state);
|
||||
|
||||
Ok(())
|
||||
|
@ -114,6 +144,10 @@ impl SettingsMenu {
|
|||
self.sound.update_height();
|
||||
self.sound.x = ((state.canvas_size.0 - self.sound.width as f32) / 2.0).floor() as isize;
|
||||
self.sound.y = 30 + ((state.canvas_size.1 - self.sound.height as f32) / 2.0).floor() as isize;
|
||||
|
||||
self.soundtrack.update_height();
|
||||
self.soundtrack.x = ((state.canvas_size.0 - self.soundtrack.width as f32) / 2.0).floor() as isize;
|
||||
self.soundtrack.y = ((state.canvas_size.1 - self.soundtrack.height as f32) / 2.0).floor() as isize;
|
||||
}
|
||||
|
||||
pub fn tick(
|
||||
|
@ -249,11 +283,31 @@ impl SettingsMenu {
|
|||
let _ = state.settings.save(ctx);
|
||||
}
|
||||
}
|
||||
MenuSelectionResult::Selected(4, _) => self.current = CurrentMenu::SoundtrackMenu,
|
||||
MenuSelectionResult::Selected(5, _) | MenuSelectionResult::Canceled => {
|
||||
self.current = CurrentMenu::MainMenu
|
||||
}
|
||||
_ => (),
|
||||
},
|
||||
CurrentMenu::SoundtrackMenu => {
|
||||
let last = self.soundtrack.entries.len() - 1;
|
||||
match self.soundtrack.tick(controller, state) {
|
||||
MenuSelectionResult::Selected(idx, entry) => {
|
||||
if let (true, MenuEntry::Active(name)) = (idx != last, entry) {
|
||||
state.settings.soundtrack = name.to_owned();
|
||||
self.sound.entries[4] =
|
||||
MenuEntry::Active(format!("Soundtrack: {}", state.settings.soundtrack));
|
||||
state.sound_manager.reload_songs(&state.constants, &state.settings, ctx)?;
|
||||
}
|
||||
|
||||
self.current = CurrentMenu::SoundMenu;
|
||||
}
|
||||
MenuSelectionResult::Canceled => {
|
||||
self.current = CurrentMenu::SoundMenu;
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
@ -263,6 +317,7 @@ impl SettingsMenu {
|
|||
CurrentMenu::MainMenu => self.main.draw(state, ctx)?,
|
||||
CurrentMenu::GraphicsMenu => self.graphics.draw(state, ctx)?,
|
||||
CurrentMenu::SoundMenu => self.sound.draw(state, ctx)?,
|
||||
CurrentMenu::SoundtrackMenu => self.soundtrack.draw(state, ctx)?,
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
|
|
@ -33,7 +33,7 @@ pub struct TitleScene {
|
|||
controller: CombinedMenuController,
|
||||
current_menu: CurrentMenu,
|
||||
main_menu: Menu,
|
||||
option_menu: SettingsMenu,
|
||||
settings_menu: SettingsMenu,
|
||||
save_select_menu: SaveSelectMenu,
|
||||
background: Background,
|
||||
frame: Frame,
|
||||
|
@ -62,12 +62,15 @@ impl TitleScene {
|
|||
let mut textures = StageTexturePaths::new();
|
||||
textures.update(&fake_stage);
|
||||
|
||||
let mut settings_menu = SettingsMenu::new();
|
||||
settings_menu.on_title = true;
|
||||
|
||||
Self {
|
||||
tick: 0,
|
||||
controller: CombinedMenuController::new(),
|
||||
current_menu: CurrentMenu::MainMenu,
|
||||
main_menu: Menu::new(0, 0, 100, 0),
|
||||
option_menu: SettingsMenu::new(),
|
||||
settings_menu,
|
||||
save_select_menu: SaveSelectMenu::new(),
|
||||
background: Background::new(),
|
||||
frame: Frame::new(),
|
||||
|
@ -136,7 +139,7 @@ impl Scene for TitleScene {
|
|||
}
|
||||
self.main_menu.push_entry(MenuEntry::Active("Quit".to_string()));
|
||||
|
||||
self.option_menu.init(state, ctx)?;
|
||||
self.settings_menu.init(state, ctx)?;
|
||||
|
||||
self.save_select_menu.init(state, ctx)?;
|
||||
|
||||
|
@ -183,7 +186,7 @@ impl Scene for TitleScene {
|
|||
CurrentMenu::OptionMenu => {
|
||||
let timing_mode = state.settings.timing_mode;
|
||||
let cm = &mut self.current_menu;
|
||||
self.option_menu.tick(
|
||||
self.settings_menu.tick(
|
||||
&mut || {
|
||||
*cm = CurrentMenu::MainMenu;
|
||||
},
|
||||
|
@ -251,7 +254,7 @@ impl Scene for TitleScene {
|
|||
|
||||
match self.current_menu {
|
||||
CurrentMenu::MainMenu => self.main_menu.draw(state, ctx)?,
|
||||
CurrentMenu::OptionMenu => self.option_menu.draw(state, ctx)?,
|
||||
CurrentMenu::OptionMenu => self.settings_menu.draw(state, ctx)?,
|
||||
CurrentMenu::SaveSelectMenu => self.save_select_menu.draw(state, ctx)?,
|
||||
_ => {}
|
||||
}
|
||||
|
|
|
@ -156,6 +156,23 @@ impl SoundManager {
|
|||
let _ = self.tx.send(PlaybackMessage::SetSampleVolume(volume.powf(3.0)));
|
||||
}
|
||||
|
||||
pub fn reload_songs(
|
||||
&mut self,
|
||||
constants: &EngineConstants,
|
||||
settings: &Settings,
|
||||
ctx: &mut Context,
|
||||
) -> GameResult {
|
||||
let prev_song = self.prev_song_id;
|
||||
let current_song = self.current_song_id;
|
||||
|
||||
self.play_song(0, constants, settings, ctx)?;
|
||||
self.play_song(prev_song, constants, settings, ctx)?;
|
||||
self.save_state()?;
|
||||
self.play_song(current_song, constants, settings, ctx)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn play_song(
|
||||
&mut self,
|
||||
song_id: usize,
|
||||
|
|
Loading…
Reference in a new issue