Add volume adjustment + change selection symbol

main
En Yi 2025-08-23 23:31:49 +08:00
parent 95c38549b6
commit 8ac483f4f3
2 changed files with 22 additions and 6 deletions

View File

@ -57,6 +57,7 @@ static void options_scene_render_func(Scene_t* scene)
#define TITLE_FONT_SIZE 40 #define TITLE_FONT_SIZE 40
#define FONT_SIZE 22 #define FONT_SIZE 22
#define FONT_COLOUR BLACK #define FONT_COLOUR BLACK
#define SELECTION_SYMBOL "=>"
float start_x = scene->engine->intended_window_size.x / 2; float start_x = scene->engine->intended_window_size.x / 2;
start_x -= level_board->frame_size.x / 2; start_x -= level_board->frame_size.x / 2;
Font* menu_font = get_font(&scene->engine->assets, "MenuFont"); 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; start_x += 32;
if (line == data->curr_selection) 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); 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; y_offset += FONT_SIZE;
line++; line++;
sc_array_foreach(&data->keybinds_info, keybind_info) { sc_array_foreach(&data->keybinds_info, keybind_info) {
if (line == data->curr_selection) 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; bool changed = false;
@ -112,7 +113,7 @@ static void options_scene_render_func(Scene_t* scene)
y_offset += FONT_SIZE; y_offset += FONT_SIZE;
if (line == data->curr_selection) 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); DrawTextEx(*menu_font, "Apply", (Vector2){start_x+32, y_offset}, FONT_SIZE, 4, BLACK);
y_offset += FONT_SIZE; y_offset += FONT_SIZE;
@ -120,7 +121,7 @@ static void options_scene_render_func(Scene_t* scene)
if (line == data->curr_selection) 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); DrawTextEx(*menu_font, "Return", (Vector2){start_x+32, y_offset}, FONT_SIZE, 4, BLACK);
y_offset += FONT_SIZE; y_offset += FONT_SIZE;
@ -241,12 +242,15 @@ static void exec_component_function(Scene_t* scene, uint16_t sel)
remap_scene_keys(scene->engine); remap_scene_keys(scene->engine);
scene->reset_function(scene); scene->reset_function(scene);
data->curr_selection = sel + n_binds + 1; data->curr_selection = sel + n_binds + 1;
data->old_volume_value = data->volume_value;
} }
else else
{ {
// Need to reset action map, otherwise will preserve over scene change // Need to reset action map, otherwise will preserve over scene change
scene->action_remap_function(scene); scene->action_remap_function(scene);
change_scene(scene->engine, MAIN_MENU_SCENE); change_scene(scene->engine, MAIN_MENU_SCENE);
SetMasterVolume(data->old_volume_value);
} }
} }
else 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 // Left and right only works on volume option
if (new_selection == 0) 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; break;
case ACTION_RIGHT: case ACTION_RIGHT:
if (new_selection == 0) 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; break;
case ACTION_CONFIRM: case ACTION_CONFIRM:
@ -335,6 +347,8 @@ static void reset_options_scene(Scene_t* scene)
data->curr_selection = 0; data->curr_selection = 0;
data->mode = OPTIONS_NORMAL_MODE; data->mode = OPTIONS_NORMAL_MODE;
data->keybind_status = 0; data->keybind_status = 0;
data->volume_value = GetMasterVolume();
data->old_volume_value = data->volume_value;
} }
static void options_action_remap_func(Scene_t* scene) static void options_action_remap_func(Scene_t* scene)

View File

@ -156,6 +156,8 @@ sc_array_def(KeyBindInfo_t, keybinds);
typedef struct OptionSceneData { typedef struct OptionSceneData {
struct sc_array_keybinds keybinds_info; // Selection index -> keybind info struct sc_array_keybinds keybinds_info; // Selection index -> keybind info
int keybind_status; int keybind_status;
float volume_value;
float old_volume_value;
uint16_t n_selections; uint16_t n_selections;
uint16_t curr_selection; uint16_t curr_selection;
OptionSceneMode_t mode; OptionSceneMode_t mode;