From 8ac483f4f3f1c3a6e284462fff2df4a9576a1f0e Mon Sep 17 00:00:00 2001 From: En Yi Date: Sat, 23 Aug 2025 23:31:49 +0800 Subject: [PATCH] Add volume adjustment + change selection symbol --- scenes/options_scene.c | 26 ++++++++++++++++++++------ scenes/scene_impl.h | 2 ++ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/scenes/options_scene.c b/scenes/options_scene.c index 3978dc6..aeb3a32 100644 --- a/scenes/options_scene.c +++ b/scenes/options_scene.c @@ -57,6 +57,7 @@ static void options_scene_render_func(Scene_t* scene) #define TITLE_FONT_SIZE 40 #define FONT_SIZE 22 #define FONT_COLOUR BLACK +#define SELECTION_SYMBOL "=>" float start_x = scene->engine->intended_window_size.x / 2; start_x -= level_board->frame_size.x / 2; Font* menu_font = get_font(&scene->engine->assets, "MenuFont"); @@ -71,18 +72,18 @@ static void options_scene_render_func(Scene_t* scene) start_x += 32; if (line == data->curr_selection) { - DrawTextEx(*menu_font, ">>", (Vector2){start_x,y_offset}, FONT_SIZE, 4, BLACK); + DrawTextEx(*menu_font, SELECTION_SYMBOL, (Vector2){start_x,y_offset}, FONT_SIZE, 4, BLACK); } - float vol = GetMasterVolume(); + float vol = data->volume_value; sprintf(buffer, "Volume : %.1f", vol); - DrawTextEx(*menu_font, buffer, (Vector2){start_x+32, y_offset}, FONT_SIZE, 4, BLACK); + DrawTextEx(*menu_font, buffer, (Vector2){start_x+32, y_offset}, FONT_SIZE, 4, (data->old_volume_value == data->volume_value) ? BLACK : BLUE); y_offset += FONT_SIZE; line++; sc_array_foreach(&data->keybinds_info, keybind_info) { if (line == data->curr_selection) { - DrawTextEx(*menu_font, ">>", (Vector2){start_x,y_offset}, FONT_SIZE, 4, BLACK); + DrawTextEx(*menu_font, SELECTION_SYMBOL, (Vector2){start_x,y_offset}, FONT_SIZE, 4, BLACK); } bool changed = false; @@ -112,7 +113,7 @@ static void options_scene_render_func(Scene_t* scene) y_offset += FONT_SIZE; if (line == data->curr_selection) { - DrawTextEx(*menu_font, ">>", (Vector2){start_x, y_offset}, FONT_SIZE, 4, BLACK); + DrawTextEx(*menu_font, SELECTION_SYMBOL, (Vector2){start_x, y_offset}, FONT_SIZE, 4, BLACK); } DrawTextEx(*menu_font, "Apply", (Vector2){start_x+32, y_offset}, FONT_SIZE, 4, BLACK); y_offset += FONT_SIZE; @@ -120,7 +121,7 @@ static void options_scene_render_func(Scene_t* scene) if (line == data->curr_selection) { - DrawTextEx(*menu_font, ">>", (Vector2){start_x,y_offset}, FONT_SIZE, 4, BLACK); + DrawTextEx(*menu_font, SELECTION_SYMBOL, (Vector2){start_x,y_offset}, FONT_SIZE, 4, BLACK); } DrawTextEx(*menu_font, "Return", (Vector2){start_x+32, y_offset}, FONT_SIZE, 4, BLACK); y_offset += FONT_SIZE; @@ -241,12 +242,15 @@ static void exec_component_function(Scene_t* scene, uint16_t sel) remap_scene_keys(scene->engine); scene->reset_function(scene); data->curr_selection = sel + n_binds + 1; + data->old_volume_value = data->volume_value; } else { // Need to reset action map, otherwise will preserve over scene change scene->action_remap_function(scene); change_scene(scene->engine, MAIN_MENU_SCENE); + + SetMasterVolume(data->old_volume_value); } } else @@ -285,11 +289,19 @@ static void options_do_action(Scene_t* scene, ActionType_t action, bool pressed) // Left and right only works on volume option if (new_selection == 0) { + data->volume_value -= 0.1f; + data->volume_value = (data->volume_value < 0.0f) ? 0.0f : data->volume_value; + SetMasterVolume(data->volume_value); + play_sfx(scene->engine, BOULDER_DESTROY_SFX); } break; case ACTION_RIGHT: if (new_selection == 0) { + data->volume_value += 0.1f; + data->volume_value = (data->volume_value > 1.0f) ? 1.0f : data->volume_value; + SetMasterVolume(data->volume_value); + play_sfx(scene->engine, BOULDER_DESTROY_SFX); } break; case ACTION_CONFIRM: @@ -335,6 +347,8 @@ static void reset_options_scene(Scene_t* scene) data->curr_selection = 0; data->mode = OPTIONS_NORMAL_MODE; data->keybind_status = 0; + data->volume_value = GetMasterVolume(); + data->old_volume_value = data->volume_value; } static void options_action_remap_func(Scene_t* scene) diff --git a/scenes/scene_impl.h b/scenes/scene_impl.h index 67d9192..570e6bd 100644 --- a/scenes/scene_impl.h +++ b/scenes/scene_impl.h @@ -156,6 +156,8 @@ sc_array_def(KeyBindInfo_t, keybinds); typedef struct OptionSceneData { struct sc_array_keybinds keybinds_info; // Selection index -> keybind info int keybind_status; + float volume_value; + float old_volume_value; uint16_t n_selections; uint16_t curr_selection; OptionSceneMode_t mode;