1
0
Fork 0
mirror of https://github.com/doukutsu-rs/doukutsu-rs synced 2024-11-26 23:33:01 +00:00

Merge pull request #49 from Daedliy/master

small start menu fixes
This commit is contained in:
alula 2022-01-17 21:51:56 +01:00 committed by GitHub
commit 529a1c122d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 65 additions and 14 deletions

View file

@ -17,6 +17,7 @@ pub enum MenuEntry {
Disabled(String), Disabled(String),
Toggle(String, bool), Toggle(String, bool),
Options(String, usize, Vec<String>), Options(String, usize, Vec<String>),
DescriptiveOptions(String, usize, Vec<String>, Vec<String>),
SaveData(MenuSaveInfo), SaveData(MenuSaveInfo),
NewSave, NewSave,
} }
@ -30,6 +31,7 @@ impl MenuEntry {
MenuEntry::Disabled(_) => 14.0, MenuEntry::Disabled(_) => 14.0,
MenuEntry::Toggle(_, _) => 14.0, MenuEntry::Toggle(_, _) => 14.0,
MenuEntry::Options(_, _, _) => 14.0, MenuEntry::Options(_, _, _) => 14.0,
MenuEntry::DescriptiveOptions(_, _, _, _) => 14.0,
MenuEntry::SaveData(_) => 30.0, MenuEntry::SaveData(_) => 30.0,
MenuEntry::NewSave => 30.0, MenuEntry::NewSave => 30.0,
} }
@ -43,6 +45,7 @@ impl MenuEntry {
MenuEntry::Disabled(_) => false, MenuEntry::Disabled(_) => false,
MenuEntry::Toggle(_, _) => true, MenuEntry::Toggle(_, _) => true,
MenuEntry::Options(_, _, _) => true, MenuEntry::Options(_, _, _) => true,
MenuEntry::DescriptiveOptions(_, _, _, _) => true,
MenuEntry::SaveData(_) => true, MenuEntry::SaveData(_) => true,
MenuEntry::NewSave => true, MenuEntry::NewSave => true,
} }
@ -250,7 +253,7 @@ impl Menu {
} }
MenuEntry::Toggle(name, value) => { MenuEntry::Toggle(name, value) => {
let value_text = if *value { "ON" } else { "OFF" }; let value_text = if *value { "ON" } else { "OFF" };
let val_text_len = state.font.text_width(value_text.chars(), &state.constants); let name_text_len = state.font.text_width(name.chars(), &state.constants);
state.font.draw_text( state.font.draw_text(
name.chars(), name.chars(),
@ -263,7 +266,7 @@ impl Menu {
state.font.draw_text( state.font.draw_text(
value_text.chars(), value_text.chars(),
self.x as f32 + self.width as f32 - val_text_len, self.x as f32 + 25.0 + name_text_len,
y, y,
&state.constants, &state.constants,
&mut state.texture_set, &mut state.texture_set,
@ -272,7 +275,7 @@ impl Menu {
} }
MenuEntry::Options(name, index, value) => { MenuEntry::Options(name, index, value) => {
let value_text = if let Some(text) = value.get(*index) { text.as_str() } else { "???" }; let value_text = if let Some(text) = value.get(*index) { text.as_str() } else { "???" };
let val_text_len = state.font.text_width(value_text.chars(), &state.constants); let name_text_len = state.font.text_width(name.chars(), &state.constants);
state.font.draw_text( state.font.draw_text(
name.chars(), name.chars(),
@ -285,13 +288,46 @@ impl Menu {
state.font.draw_text( state.font.draw_text(
value_text.chars(), value_text.chars(),
self.x as f32 + self.width as f32 - val_text_len, self.x as f32 + 25.0 + name_text_len,
y, y,
&state.constants, &state.constants,
&mut state.texture_set, &mut state.texture_set,
ctx, ctx,
)?; )?;
} }
MenuEntry::DescriptiveOptions(name, index, value, description) => {
let value_text = if let Some(text) = value.get(*index) { text.as_str() } else { "???" };
let description_text = if let Some(text) = description.get(*index) { text.as_str() } else { "???" };
let name_text_len = state.font.text_width(name.chars(), &state.constants);
state.font.draw_text(
name.chars(),
self.x as f32 + 20.0,
y,
&state.constants,
&mut state.texture_set,
ctx,
)?;
state.font.draw_text(
value_text.chars(),
self.x as f32 + 25.0 + name_text_len,
y,
&state.constants,
&mut state.texture_set,
ctx,
)?;
state.font.draw_colored_text(
description_text.chars(),
self.x as f32 + 20.0,
y + 14.0,
(0xa0, 0xa0, 0xff, 0xff),
&state.constants,
&mut state.texture_set,
ctx,
)?;
}
_ => {} _ => {}
} }
@ -346,7 +382,7 @@ impl Menu {
y += entry.height() as f32; y += entry.height() as f32;
match entry { match entry {
MenuEntry::Active(_) | MenuEntry::Toggle(_, _) | MenuEntry::Options(_, _, _) MenuEntry::Active(_) | MenuEntry::Toggle(_, _) | MenuEntry::Options(_, _, _) | MenuEntry::DescriptiveOptions(_, _, _, _)
if (self.selected == idx && controller.trigger_ok()) if (self.selected == idx && controller.trigger_ok())
|| state.touch_controls.consume_click_in(entry_bounds) => || state.touch_controls.consume_click_in(entry_bounds) =>
{ {
@ -361,6 +397,14 @@ impl Menu {
state.sound_manager.play_sfx(1); state.sound_manager.play_sfx(1);
return MenuSelectionResult::Right(self.selected, entry); return MenuSelectionResult::Right(self.selected, entry);
} }
MenuEntry::DescriptiveOptions(_, _, _, _) if controller.trigger_left() => {
state.sound_manager.play_sfx(1);
return MenuSelectionResult::Left(self.selected, entry);
}
MenuEntry::DescriptiveOptions(_, _, _, _) if controller.trigger_right() => {
state.sound_manager.play_sfx(1);
return MenuSelectionResult::Right(self.selected, entry);
}
_ => {} _ => {}
} }
} }

View file

@ -35,7 +35,7 @@ impl SettingsMenu {
pub fn init(&mut self, state: &mut SharedGameState, ctx: &mut Context) -> GameResult { pub fn init(&mut self, state: &mut SharedGameState, ctx: &mut Context) -> GameResult {
self.graphics.push_entry(MenuEntry::Toggle("Lighting effects:".to_string(), state.settings.shader_effects)); self.graphics.push_entry(MenuEntry::Toggle("Lighting effects:".to_string(), state.settings.shader_effects));
self.graphics.push_entry(MenuEntry::Toggle("Player's weapon light cone:".to_string(), state.settings.light_cone)); self.graphics.push_entry(MenuEntry::Toggle("Weapon light cone:".to_string(), state.settings.light_cone));
self.graphics self.graphics
.push_entry(MenuEntry::Toggle("Motion interpolation:".to_string(), state.settings.motion_interpolation)); .push_entry(MenuEntry::Toggle("Motion interpolation:".to_string(), state.settings.motion_interpolation));
self.graphics.push_entry(MenuEntry::Toggle("Subpixel scrolling:".to_string(), state.settings.subpixel_coords)); self.graphics.push_entry(MenuEntry::Toggle("Subpixel scrolling:".to_string(), state.settings.subpixel_coords));
@ -72,18 +72,25 @@ impl SettingsMenu {
self.main.push_entry(MenuEntry::Active("< Back".to_owned())); self.main.push_entry(MenuEntry::Active("< Back".to_owned()));
self.sound.push_entry(MenuEntry::DisabledWhite("BGM Interpolation:".to_owned())); self.sound.push_entry(MenuEntry::DescriptiveOptions(
self.sound.push_entry(MenuEntry::Options( "BGM Interpolation:".to_owned(),
"".to_owned(),
state.settings.organya_interpolation as usize, state.settings.organya_interpolation as usize,
vec![ vec![
"Nearest (fastest, lowest quality)".to_owned(), "Nearest".to_owned(),
"Linear (fast, similar to freeware on Vista+)".to_owned(), "Linear".to_owned(),
"Cosine".to_owned(), "Cosine".to_owned(),
"Cubic".to_owned(), "Cubic".to_owned(),
"Polyphase (slowest, similar to freeware on XP)".to_owned() "Polyphase".to_owned()
],
vec![
"(Fastest, lowest quality)".to_owned(),
"(Fast, similar to freeware on Vista+)".to_owned(),
"(Cosine interpolation)".to_owned(),
"(Cubic interpolation)".to_owned(),
"(Slowest, similar to freeware on XP)".to_owned()
], ],
)); ));
self.sound.push_entry(MenuEntry::DisabledWhite("".to_owned()));
self.sound.push_entry(MenuEntry::Disabled(format!("Soundtrack: {}", state.settings.soundtrack))); self.sound.push_entry(MenuEntry::Disabled(format!("Soundtrack: {}", state.settings.soundtrack)));
self.sound.push_entry(MenuEntry::Active("< Back".to_owned())); self.sound.push_entry(MenuEntry::Active("< Back".to_owned()));
@ -204,8 +211,8 @@ impl SettingsMenu {
_ => (), _ => (),
}, },
CurrentMenu::SoundMenu => match self.sound.tick(controller, state) { CurrentMenu::SoundMenu => match self.sound.tick(controller, state) {
MenuSelectionResult::Selected(1, toggle) => { MenuSelectionResult::Selected(0, toggle) => {
if let MenuEntry::Options(_, value, _) = toggle { if let MenuEntry::DescriptiveOptions(_, value, _, _) = toggle {
let (new_mode, new_value) = match *value { let (new_mode, new_value) = match *value {
0 => (InterpolationMode::Linear, 1), 0 => (InterpolationMode::Linear, 1),
1 => (InterpolationMode::Cosine, 2), 1 => (InterpolationMode::Cosine, 2),