Finally got around to returning to menu on death or exit. I shouldn't have put this off for so long, was painful. Also quest system future proofed if I decide to add anything that might cause death in one of them.
This commit is contained in:
+16
-4
@@ -90,6 +90,7 @@ void run_game()
|
|||||||
init_item_registry();
|
init_item_registry();
|
||||||
init_search_pools();
|
init_search_pools();
|
||||||
|
|
||||||
|
while (true) {
|
||||||
bool game_started = false;
|
bool game_started = false;
|
||||||
while (!game_started) {
|
while (!game_started) {
|
||||||
int selection = run_main_menu();
|
int selection = run_main_menu();
|
||||||
@@ -123,10 +124,18 @@ void run_game()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
while(true)
|
while (game_started) {
|
||||||
{
|
|
||||||
wait(5);
|
wait(5);
|
||||||
|
|
||||||
|
if (return_to_main_menu_requested) {
|
||||||
|
game_paused = false;
|
||||||
|
menuBackgroundUpdatesEnabled = true;
|
||||||
|
p.resume_all();
|
||||||
|
reset_game_state();
|
||||||
|
return_to_main_menu_requested = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
// Pause toggle
|
// Pause toggle
|
||||||
if(key_pressed(KEY_BACK))
|
if(key_pressed(KEY_BACK))
|
||||||
{
|
{
|
||||||
@@ -152,7 +161,8 @@ void run_game()
|
|||||||
{
|
{
|
||||||
int really_exit = ui_question("", "Really exit?");
|
int really_exit = ui_question("", "Really exit?");
|
||||||
if (really_exit == 1) {
|
if (really_exit == 1) {
|
||||||
exit();
|
return_to_main_menu_requested = true;
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -198,7 +208,8 @@ void run_game()
|
|||||||
if (!try_consume_heal_scroll()) {
|
if (!try_consume_heal_scroll()) {
|
||||||
speak_with_history("You have died.", true);
|
speak_with_history("You have died.", true);
|
||||||
wait(2000);
|
wait(2000);
|
||||||
exit();
|
return_to_main_menu_requested = true;
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -486,6 +497,7 @@ void run_game()
|
|||||||
p.update_listener_1d(x);
|
p.update_listener_1d(x);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -35,7 +35,9 @@ void run_barricade_menu() {
|
|||||||
|
|
||||||
while(true) {
|
while(true) {
|
||||||
wait(5);
|
wait(5);
|
||||||
menu_background_tick();
|
if (menu_background_tick()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (key_pressed(KEY_ESCAPE)) {
|
if (key_pressed(KEY_ESCAPE)) {
|
||||||
speak_with_history("Closed.", true);
|
speak_with_history("Closed.", true);
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -98,7 +98,9 @@ void run_buildings_menu() {
|
|||||||
|
|
||||||
while(true) {
|
while(true) {
|
||||||
wait(5);
|
wait(5);
|
||||||
menu_background_tick();
|
if (menu_background_tick()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (key_pressed(KEY_ESCAPE)) {
|
if (key_pressed(KEY_ESCAPE)) {
|
||||||
speak_with_history("Closed.", true);
|
speak_with_history("Closed.", true);
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -58,7 +58,9 @@ void run_clothing_menu() {
|
|||||||
|
|
||||||
while(true) {
|
while(true) {
|
||||||
wait(5);
|
wait(5);
|
||||||
menu_background_tick();
|
if (menu_background_tick()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (key_pressed(KEY_ESCAPE)) {
|
if (key_pressed(KEY_ESCAPE)) {
|
||||||
speak_with_history("Closed.", true);
|
speak_with_history("Closed.", true);
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -13,7 +13,9 @@ void run_materials_menu() {
|
|||||||
|
|
||||||
while(true) {
|
while(true) {
|
||||||
wait(5);
|
wait(5);
|
||||||
menu_background_tick();
|
if (menu_background_tick()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (key_pressed(KEY_ESCAPE)) {
|
if (key_pressed(KEY_ESCAPE)) {
|
||||||
speak_with_history("Closed.", true);
|
speak_with_history("Closed.", true);
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -98,7 +98,9 @@ void run_runes_menu() {
|
|||||||
|
|
||||||
while(true) {
|
while(true) {
|
||||||
wait(5);
|
wait(5);
|
||||||
menu_background_tick();
|
if (menu_background_tick()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (key_pressed(KEY_ESCAPE)) {
|
if (key_pressed(KEY_ESCAPE)) {
|
||||||
speak_with_history("Closed.", true);
|
speak_with_history("Closed.", true);
|
||||||
break;
|
break;
|
||||||
@@ -154,7 +156,9 @@ void run_rune_equipment_menu(int rune_type) {
|
|||||||
|
|
||||||
while(true) {
|
while(true) {
|
||||||
wait(5);
|
wait(5);
|
||||||
menu_background_tick();
|
if (menu_background_tick()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (key_pressed(KEY_ESCAPE)) {
|
if (key_pressed(KEY_ESCAPE)) {
|
||||||
speak_with_history("Closed.", true);
|
speak_with_history("Closed.", true);
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -17,7 +17,9 @@ void run_tools_menu() {
|
|||||||
|
|
||||||
while(true) {
|
while(true) {
|
||||||
wait(5);
|
wait(5);
|
||||||
menu_background_tick();
|
if (menu_background_tick()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (key_pressed(KEY_ESCAPE)) {
|
if (key_pressed(KEY_ESCAPE)) {
|
||||||
speak_with_history("Closed.", true);
|
speak_with_history("Closed.", true);
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -11,7 +11,9 @@ void run_weapons_menu() {
|
|||||||
|
|
||||||
while(true) {
|
while(true) {
|
||||||
wait(5);
|
wait(5);
|
||||||
menu_background_tick();
|
if (menu_background_tick()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (key_pressed(KEY_ESCAPE)) {
|
if (key_pressed(KEY_ESCAPE)) {
|
||||||
speak_with_history("Closed.", true);
|
speak_with_history("Closed.", true);
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -38,7 +38,9 @@ void run_crafting_menu() {
|
|||||||
|
|
||||||
while(true) {
|
while(true) {
|
||||||
wait(5);
|
wait(5);
|
||||||
menu_background_tick();
|
if (menu_background_tick()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (key_pressed(KEY_ESCAPE)) {
|
if (key_pressed(KEY_ESCAPE)) {
|
||||||
speak_with_history("Closed.", true);
|
speak_with_history("Closed.", true);
|
||||||
break;
|
break;
|
||||||
@@ -86,7 +88,9 @@ void simulate_crafting(int item_count) {
|
|||||||
timer t;
|
timer t;
|
||||||
while(t.elapsed < 800) {
|
while(t.elapsed < 800) {
|
||||||
wait(5);
|
wait(5);
|
||||||
menu_background_tick();
|
if (menu_background_tick()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
p.play_stationary("sounds/crafting_complete.ogg", false);
|
p.play_stationary("sounds/crafting_complete.ogg", false);
|
||||||
|
|||||||
@@ -136,7 +136,9 @@ void run_fylgja_menu() {
|
|||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
wait(5);
|
wait(5);
|
||||||
menu_background_tick();
|
if (menu_background_tick()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (key_pressed(KEY_ESCAPE)) {
|
if (key_pressed(KEY_ESCAPE)) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -263,7 +263,9 @@ void run_action_menu(int x) {
|
|||||||
|
|
||||||
while(true) {
|
while(true) {
|
||||||
wait(5);
|
wait(5);
|
||||||
menu_background_tick();
|
if (menu_background_tick()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (key_pressed(KEY_ESCAPE)) {
|
if (key_pressed(KEY_ESCAPE)) {
|
||||||
speak_with_history("Closed.", true);
|
speak_with_history("Closed.", true);
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -88,7 +88,9 @@ void run_altar_menu() {
|
|||||||
|
|
||||||
while(true) {
|
while(true) {
|
||||||
wait(5);
|
wait(5);
|
||||||
menu_background_tick();
|
if (menu_background_tick()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (key_pressed(KEY_ESCAPE)) {
|
if (key_pressed(KEY_ESCAPE)) {
|
||||||
speak_with_history("Closed.", true);
|
speak_with_history("Closed.", true);
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -56,7 +56,9 @@ void run_base_info_menu() {
|
|||||||
|
|
||||||
while(true) {
|
while(true) {
|
||||||
wait(5);
|
wait(5);
|
||||||
menu_background_tick();
|
if (menu_background_tick()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (key_pressed(KEY_ESCAPE)) {
|
if (key_pressed(KEY_ESCAPE)) {
|
||||||
speak_with_history("Closed.", true);
|
speak_with_history("Closed.", true);
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -160,7 +160,9 @@ void run_equipment_menu() {
|
|||||||
|
|
||||||
while(true) {
|
while(true) {
|
||||||
wait(5);
|
wait(5);
|
||||||
menu_background_tick();
|
if (menu_background_tick()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (key_pressed(KEY_ESCAPE)) {
|
if (key_pressed(KEY_ESCAPE)) {
|
||||||
speak_with_history("Closed.", true);
|
speak_with_history("Closed.", true);
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -81,7 +81,9 @@ void run_inventory_root_menu() {
|
|||||||
|
|
||||||
while(true) {
|
while(true) {
|
||||||
wait(5);
|
wait(5);
|
||||||
menu_background_tick();
|
if (menu_background_tick()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (key_pressed(KEY_ESCAPE)) {
|
if (key_pressed(KEY_ESCAPE)) {
|
||||||
speak_with_history("Closed.", true);
|
speak_with_history("Closed.", true);
|
||||||
break;
|
break;
|
||||||
@@ -124,7 +126,9 @@ void run_inventory_menu(bool allow_deposit) {
|
|||||||
|
|
||||||
while(true) {
|
while(true) {
|
||||||
wait(5);
|
wait(5);
|
||||||
menu_background_tick();
|
if (menu_background_tick()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (key_pressed(KEY_ESCAPE)) {
|
if (key_pressed(KEY_ESCAPE)) {
|
||||||
speak_with_history("Closed.", true);
|
speak_with_history("Closed.", true);
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -1,9 +1,12 @@
|
|||||||
// Menu utility functions
|
// Menu utility functions
|
||||||
// Helper functions used across multiple menu systems
|
// Helper functions used across multiple menu systems
|
||||||
|
|
||||||
void menu_background_tick() {
|
bool menu_background_tick() {
|
||||||
|
if (return_to_main_menu_requested) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
if (!menuBackgroundUpdatesEnabled) {
|
if (!menuBackgroundUpdatesEnabled) {
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
// Keep this list in sync with the main game loop to avoid pausing ambience/weather/time.
|
// Keep this list in sync with the main game loop to avoid pausing ambience/weather/time.
|
||||||
update_time();
|
update_time();
|
||||||
@@ -47,9 +50,12 @@ void menu_background_tick() {
|
|||||||
if (!try_consume_heal_scroll()) {
|
if (!try_consume_heal_scroll()) {
|
||||||
speak_with_history("You have died.", true);
|
speak_with_history("You have died.", true);
|
||||||
wait(2000);
|
wait(2000);
|
||||||
exit();
|
return_to_main_menu_requested = true;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void play_menu_move_sound() {
|
void play_menu_move_sound() {
|
||||||
|
|||||||
@@ -305,7 +305,9 @@ void run_storage_menu() {
|
|||||||
|
|
||||||
while(true) {
|
while(true) {
|
||||||
wait(5);
|
wait(5);
|
||||||
menu_background_tick();
|
if (menu_background_tick()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (key_pressed(KEY_ESCAPE)) {
|
if (key_pressed(KEY_ESCAPE)) {
|
||||||
speak_with_history("Closed.", true);
|
speak_with_history("Closed.", true);
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -96,6 +96,7 @@ int last_adventure_day = -1;
|
|||||||
// Pause state
|
// Pause state
|
||||||
bool game_paused = false;
|
bool game_paused = false;
|
||||||
bool menuBackgroundUpdatesEnabled = true;
|
bool menuBackgroundUpdatesEnabled = true;
|
||||||
|
bool return_to_main_menu_requested = false;
|
||||||
|
|
||||||
// Restart all game timers when resuming from pause
|
// Restart all game timers when resuming from pause
|
||||||
// Prevents time from accumulating while paused
|
// Prevents time from accumulating while paused
|
||||||
|
|||||||
@@ -50,8 +50,8 @@ int get_quest_chance_from_favor() {
|
|||||||
return chance;
|
return chance;
|
||||||
}
|
}
|
||||||
|
|
||||||
void quest_menu_background_tick() {
|
bool quest_menu_background_tick() {
|
||||||
menu_background_tick();
|
return menu_background_tick();
|
||||||
}
|
}
|
||||||
|
|
||||||
void quest_boomerang_hit_sound() {
|
void quest_boomerang_hit_sound() {
|
||||||
@@ -163,6 +163,10 @@ void run_quest(int quest_type) {
|
|||||||
else if (quest_type == QUEST_ENCHANTED_MELODY) score = run_enchanted_melody();
|
else if (quest_type == QUEST_ENCHANTED_MELODY) score = run_enchanted_melody();
|
||||||
else if (quest_type == QUEST_ESCAPE_FROM_HEL) score = run_escape_from_hel();
|
else if (quest_type == QUEST_ESCAPE_FROM_HEL) score = run_escape_from_hel();
|
||||||
else if (quest_type == QUEST_SKELETAL_BARD) score = run_skeletal_bard();
|
else if (quest_type == QUEST_SKELETAL_BARD) score = run_skeletal_bard();
|
||||||
|
if (return_to_main_menu_requested) {
|
||||||
|
p.resume_all();
|
||||||
|
return;
|
||||||
|
}
|
||||||
apply_quest_reward(score);
|
apply_quest_reward(score);
|
||||||
p.resume_all();
|
p.resume_all();
|
||||||
}
|
}
|
||||||
@@ -178,7 +182,9 @@ void run_quest_menu() {
|
|||||||
|
|
||||||
while(true) {
|
while(true) {
|
||||||
wait(5);
|
wait(5);
|
||||||
menu_background_tick();
|
if (menu_background_tick()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (key_pressed(KEY_ESCAPE)) {
|
if (key_pressed(KEY_ESCAPE)) {
|
||||||
speak_with_history("Closed.", true);
|
speak_with_history("Closed.", true);
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -21,7 +21,9 @@ int select_note_count(int minNotes, int maxNotes, int startValue) {
|
|||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
wait(5);
|
wait(5);
|
||||||
quest_menu_background_tick();
|
if (quest_menu_background_tick()) {
|
||||||
|
return selection;
|
||||||
|
}
|
||||||
|
|
||||||
if (key_pressed(KEY_UP)) {
|
if (key_pressed(KEY_UP)) {
|
||||||
if (selection < maxNotes) selection++;
|
if (selection < maxNotes) selection++;
|
||||||
@@ -72,6 +74,9 @@ int run_skeletal_bard() {
|
|||||||
wait(400);
|
wait(400);
|
||||||
|
|
||||||
int guess = select_note_count(5, 20, 5);
|
int guess = select_note_count(5, 20, 5);
|
||||||
|
if (return_to_main_menu_requested) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
int diff = length - guess;
|
int diff = length - guess;
|
||||||
if (diff < 0) diff = -diff;
|
if (diff < 0) diff = -diff;
|
||||||
|
|
||||||
@@ -82,6 +87,9 @@ int run_skeletal_bard() {
|
|||||||
speak_with_history("You entered " + guess + " notes and the actual number was " + length + ". " + points + " points. Press Enter to continue.", true);
|
speak_with_history("You entered " + guess + " notes and the actual number was " + length + ". " + points + " points. Press Enter to continue.", true);
|
||||||
while (true) {
|
while (true) {
|
||||||
wait(5);
|
wait(5);
|
||||||
|
if (return_to_main_menu_requested) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
if (key_pressed(KEY_RETURN)) {
|
if (key_pressed(KEY_RETURN)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user