Menu music added.

This commit is contained in:
Storm Dragon
2026-02-10 19:20:38 -05:00
parent 9ad65a8ac5
commit 7c63bee50d
4 changed files with 86 additions and 12 deletions

View File

@@ -1,5 +1,6 @@
#include "sound_pool.nvgt" #include "sound_pool.nvgt"
#include "virtual_dialogs.nvgt" #include "virtual_dialogs.nvgt"
#include "music.nvgt"
// Audio // Audio
// Increased pool size to 300 to prevent sound cutoffs and missing sounds // Increased pool size to 300 to prevent sound cutoffs and missing sounds
@@ -41,18 +42,79 @@ sound_pool p(300);
#include "src/learn_sounds.nvgt" #include "src/learn_sounds.nvgt"
#include "src/bosses/adventure_system.nvgt" #include "src/bosses/adventure_system.nvgt"
const string MAIN_MENU_MUSIC_TRACK = "sounds/menu/Draugnorak.ogg; loop; f=1";
const int MAIN_MENU_MUSIC_FADE_IN_MS = 1;
const int MAIN_MENU_MUSIC_FADE_OUT_MS = 800;
music_manager mainMenuMusic;
const int MAIN_MENU_NEW_GAME = 0;
const int MAIN_MENU_LOAD_GAME = 1;
const int MAIN_MENU_LEARN_SOUNDS = 2;
const int MAIN_MENU_EXIT = 3;
void start_main_menu_music() {
if (mainMenuMusic.resume(MAIN_MENU_MUSIC_FADE_IN_MS)) return;
if (mainMenuMusic.playing) {
mainMenuMusic.pause(0);
mainMenuMusic.resume(MAIN_MENU_MUSIC_FADE_IN_MS);
return;
}
mainMenuMusic.play(MAIN_MENU_MUSIC_TRACK);
}
void stop_main_menu_music() {
if (!mainMenuMusic.playing) return;
mainMenuMusic.pause(MAIN_MENU_MUSIC_FADE_OUT_MS);
}
int run_main_menu() { int run_main_menu() {
start_main_menu_music();
speak_with_history("Draugnorak. Main menu.", true); speak_with_history("Draugnorak. Main menu.", true);
int selection = 0; int selection = 0;
string load_label = has_save_game() ? "Load Game" : "Load Game (no saves found)"; string load_label = has_save_game() ? "Load Game" : "Load Game (no saves found)";
string[] options = {"New Game", load_label, "Learn Sounds", "Exit"}; string[] options;
int exit_index = options.length() - 1; string[] entry_paths;
int[] entry_types; // 0 = action, 1 = document
int[] action_ids;
options.insert_last("New Game");
entry_paths.insert_last("");
entry_types.insert_last(0);
action_ids.insert_last(MAIN_MENU_NEW_GAME);
options.insert_last(load_label);
entry_paths.insert_last("");
entry_types.insert_last(0);
action_ids.insert_last(MAIN_MENU_LOAD_GAME);
options.insert_last("Learn Sounds");
entry_paths.insert_last("");
entry_types.insert_last(0);
action_ids.insert_last(MAIN_MENU_LEARN_SOUNDS);
string[] doc_labels;
string[] doc_paths;
int[] doc_types;
add_doc_entries(doc_labels, doc_paths, doc_types);
for (uint i = 0; i < doc_labels.length(); i++) {
options.insert_last(doc_labels[i]);
entry_paths.insert_last(doc_paths[i]);
entry_types.insert_last(1);
action_ids.insert_last(-1);
}
options.insert_last("Exit");
entry_paths.insert_last("");
entry_types.insert_last(0);
action_ids.insert_last(MAIN_MENU_EXIT);
int exit_action = MAIN_MENU_EXIT;
speak_with_history(options[selection], true); speak_with_history(options[selection], true);
while(true) { while(true) {
wait(5); wait(5);
mainMenuMusic.loop();
if (key_pressed(KEY_DOWN)) { if (key_pressed(KEY_DOWN)) {
play_menu_move_sound(); play_menu_move_sound();
@@ -70,15 +132,24 @@ int run_main_menu() {
if (key_pressed(KEY_RETURN)) { if (key_pressed(KEY_RETURN)) {
play_menu_select_sound(); play_menu_select_sound();
return selection; if (entry_types[selection] == 1) {
stop_main_menu_music();
text_reader_file(entry_paths[selection], options[selection], true);
start_main_menu_music();
speak_with_history(options[selection], true);
continue;
}
stop_main_menu_music();
return action_ids[selection];
} }
if (key_pressed(KEY_ESCAPE)) { if (key_pressed(KEY_ESCAPE)) {
return exit_index; stop_main_menu_music();
return exit_action;
} }
} }
return exit_index; return exit_action;
} }
void run_game() void run_game()
@@ -97,14 +168,14 @@ void run_game()
while (!game_started) { while (!game_started) {
int selection = run_main_menu(); int selection = run_main_menu();
if (selection == 0) { if (selection == MAIN_MENU_NEW_GAME) {
if (!setup_new_character()) { if (!setup_new_character()) {
continue; continue;
} }
start_new_game(); start_new_game();
speak_with_history("New game started.", true); speak_with_history("New game started.", true);
game_started = true; game_started = true;
} else if (selection == 1) { } else if (selection == MAIN_MENU_LOAD_GAME) {
if (!has_save_game()) { if (!has_save_game()) {
ui_info_box("Draugnorak", "Load Game", "No saves found."); ui_info_box("Draugnorak", "Load Game", "No saves found.");
continue; continue;
@@ -121,7 +192,7 @@ void run_game()
if (message == "") message = "Unable to load save."; if (message == "") message = "Unable to load save.";
ui_info_box("Draugnorak", "Load Game", message); ui_info_box("Draugnorak", "Load Game", message);
} }
} else if (selection == 2) { } else if (selection == MAIN_MENU_LEARN_SOUNDS) {
run_learn_sounds_menu(); run_learn_sounds_menu();
continue; continue;
} else { } else {

BIN
sounds/menu/Draugnorak.ogg LFS Normal file

Binary file not shown.

Binary file not shown.

View File

@@ -12,6 +12,7 @@ string[] learnSoundSkipList = {
"sounds/quests/bone8.ogg", "sounds/quests/bone8.ogg",
"sounds/actions/fishpole.ogg", "sounds/actions/fishpole.ogg",
"sounds/actions/hit_ground.ogg", "sounds/actions/hit_ground.ogg",
"sounds/menu/",
"sounds/nature/" "sounds/nature/"
}; };
@@ -206,9 +207,8 @@ void run_learn_sounds_menu() {
string[] labels; string[] labels;
string[] entryPaths; string[] entryPaths;
int[] entryTypes; // 0 = sound, 1 = document int[] entryTypes; // 0 = sound
add_doc_entries(labels, entryPaths, entryTypes);
add_sound_entries(labels, entryPaths, entryTypes); add_sound_entries(labels, entryPaths, entryTypes);
if (labels.length() == 0) { if (labels.length() == 0) {