Safely get current stage name for Save Menu
This commit is contained in:
parent
8684dd8448
commit
2b9a0198cb
|
@ -37,7 +37,8 @@
|
||||||
"save_menu": {
|
"save_menu": {
|
||||||
"new": "New Save",
|
"new": "New Save",
|
||||||
"delete_info": "Press Right to Delete",
|
"delete_info": "Press Right to Delete",
|
||||||
"delete_confirm": "Delete?"
|
"delete_confirm": "Delete?",
|
||||||
|
"invalid_save": "Invalid Save"
|
||||||
},
|
},
|
||||||
|
|
||||||
"difficulty_menu": {
|
"difficulty_menu": {
|
||||||
|
|
|
@ -34,7 +34,8 @@
|
||||||
"save_menu": {
|
"save_menu": {
|
||||||
"new": "新しいデータ",
|
"new": "新しいデータ",
|
||||||
"delete_info": "右矢印キーで削除",
|
"delete_info": "右矢印キーで削除",
|
||||||
"delete_confirm": "消去?"
|
"delete_confirm": "消去?",
|
||||||
|
"invalid_save": "無効な保存"
|
||||||
},
|
},
|
||||||
"difficulty_menu": {
|
"difficulty_menu": {
|
||||||
"title": "難易度選択",
|
"title": "難易度選択",
|
||||||
|
|
|
@ -547,17 +547,15 @@ impl<T: std::cmp::PartialEq + std::default::Default + Clone> Menu<T> {
|
||||||
batch.draw(ctx)?;
|
batch.draw(ctx)?;
|
||||||
}
|
}
|
||||||
MenuEntry::SaveData(save) | MenuEntry::SaveDataSingle(save) => {
|
MenuEntry::SaveData(save) | MenuEntry::SaveDataSingle(save) => {
|
||||||
let name = &state.stages[save.current_map as usize].name;
|
let valid_save = state.stages.get(save.current_map as usize).is_some();
|
||||||
|
let name = if valid_save {
|
||||||
|
state.stages.get(save.current_map as usize).unwrap().name.clone()
|
||||||
|
} else {
|
||||||
|
state.t("menus.save_menu.invalid_save")
|
||||||
|
};
|
||||||
let bar_width = (save.life as f32 / save.max_life as f32 * 39.0) as u16;
|
let bar_width = (save.life as f32 / save.max_life as f32 * 39.0) as u16;
|
||||||
let right_edge = self.x as f32 + self.width as f32 - 4.0;
|
let right_edge = self.x as f32 + self.width as f32 - 4.0;
|
||||||
|
|
||||||
// Lifebar
|
|
||||||
let batch = state.texture_set.get_or_load_batch(ctx, &state.constants, "TextBox")?;
|
|
||||||
|
|
||||||
batch.add_rect(right_edge - 60.0, y, &Rect::new_size(0, 40, 24, 8));
|
|
||||||
batch.add_rect(right_edge - 36.0, y, &Rect::new_size(24, 40, 40, 8));
|
|
||||||
batch.add_rect(right_edge - 36.0, y, &Rect::new_size(0, 24, bar_width, 8));
|
|
||||||
|
|
||||||
state.font.draw_text(
|
state.font.draw_text(
|
||||||
name.chars(),
|
name.chars(),
|
||||||
self.x as f32 + 20.0,
|
self.x as f32 + 20.0,
|
||||||
|
@ -567,6 +565,14 @@ impl<T: std::cmp::PartialEq + std::default::Default + Clone> Menu<T> {
|
||||||
ctx,
|
ctx,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
|
if valid_save {
|
||||||
|
// Lifebar
|
||||||
|
let batch = state.texture_set.get_or_load_batch(ctx, &state.constants, "TextBox")?;
|
||||||
|
|
||||||
|
batch.add_rect(right_edge - 60.0, y, &Rect::new_size(0, 40, 24, 8));
|
||||||
|
batch.add_rect(right_edge - 36.0, y, &Rect::new_size(24, 40, 40, 8));
|
||||||
|
batch.add_rect(right_edge - 36.0, y, &Rect::new_size(0, 24, bar_width, 8));
|
||||||
|
|
||||||
// Difficulty
|
// Difficulty
|
||||||
if state.constants.is_cs_plus {
|
if state.constants.is_cs_plus {
|
||||||
let difficulty = GameDifficulty::from_primitive(save.difficulty);
|
let difficulty = GameDifficulty::from_primitive(save.difficulty);
|
||||||
|
@ -616,6 +622,7 @@ impl<T: std::cmp::PartialEq + std::default::Default + Clone> Menu<T> {
|
||||||
|
|
||||||
draw_number(right_edge - 36.0, y, save.life as usize, Alignment::Right, state, ctx)?;
|
draw_number(right_edge - 36.0, y, save.life as usize, Alignment::Right, state, ctx)?;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
MenuEntry::Control(name, data) => {
|
MenuEntry::Control(name, data) => {
|
||||||
state.font.draw_text(
|
state.font.draw_text(
|
||||||
name.chars(),
|
name.chars(),
|
||||||
|
|
Loading…
Reference in New Issue