1
0
Fork 0
mirror of https://github.com/TerryCavanagh/VVVVVV.git synced 2024-11-05 18:59:41 +01:00

Slider inputs for audio volume

This commit is contained in:
NyakoFox 2024-04-09 17:39:23 -03:00
parent 2901810269
commit 59c74955ee
5 changed files with 150 additions and 27 deletions

View file

@ -6920,16 +6920,34 @@ void Game::createmenu( enum Menu::MenuName t, bool samemenu/*= false*/ )
maxspacing = 15;
break;
case Menu::audiooptions:
{
int offset = 0;
option(loc::gettext("music volume"));
option(loc::gettext("sound volume"));
if (music.mmmmmm)
{
offset++;
option(loc::gettext("soundtrack"));
}
option(loc::gettext("return"));
menuyoff = 0;
maxspacing = 15;
auto_buttons = false;
touch::create_slider_button((320 - 160) / 2, 120 - 32, 160, 48, loc::gettext("music volume"), &music.user_music_volume, 0, USER_VOLUME_MAX);
touch::create_slider_button((320 - 160) / 2, 120 + 32, 160, 48, loc::gettext("sound volume"), &music.user_sound_volume, 0, USER_VOLUME_MAX);
if (music.mmmmmm)
{
touch::create_toggle_button((320 - 160) / 2, 200 - 48, 160, 12, loc::gettext("MMMMMM soundtrack"), offset, music.usingmmmmmm);
}
touch::create_menu_button(46 - 16, 200, 76, 26, loc::gettext("previous"), -2);
touch::create_menu_button(122, 200, 76, 26, loc::gettext("return"), offset + 2);
touch::create_menu_button(198 + 16, 200, 76, 26, loc::gettext("next"), -1);
break;
}
case Menu::accessibility:
#if !defined(MAKEANDPLAY)
option(loc::gettext("unlock play modes"));

View file

@ -1174,6 +1174,22 @@ void menuactionpress(void)
map.nexttowercolour();
music.playef(Sound_VIRIDIAN);
}
if (game.currentmenuoption == -2)
{
// gameplay menu
music.playef(Sound_VIRIDIAN);
game.createmenu(Menu::graphicoptions, true);
map.nexttowercolour();
}
if (game.currentmenuoption == -1)
{
// audio menu
music.playef(Sound_VIRIDIAN);
game.createmenu(Menu::touch_input, true);
map.nexttowercolour();
}
break;
case Menu::language:
{
@ -2594,6 +2610,7 @@ void titleinput(void)
{
slidermodeinput();
}
touch::update_sliders();
}
if (game.currentmenuoption < 0) game.currentmenuoption = game.menuoptions.size()-1;

View file

@ -512,39 +512,54 @@ static void menurender(void)
break;
}
case Menu::audiooptions:
switch (game.currentmenuoption)
if (key.using_touch)
{
case 0:
font::print(PR_2X | PR_CEN, -1, 30, loc::gettext("Music Volume"), tr, tg, tb);
font::print_wrap(PR_CEN, -1, 65, loc::gettext("Change the volume of the music."), tr, tg, tb);
volumesliderrender();
break;
case 1:
font::print(PR_2X | PR_CEN, -1, 30, loc::gettext("Sound Volume"), tr, tg, tb);
font::print_wrap(PR_CEN, -1, 65, loc::gettext("Change the volume of sound effects."), tr, tg, tb);
volumesliderrender();
break;
case 2:
{
if (!music.mmmmmm)
font::print(PR_2X | PR_CEN, -1, 30, loc::gettext("Audio Options"), tr, tg, tb);
if (music.mmmmmm)
{
break;
}
font::print(PR_2X | PR_CEN, -1, 30, loc::gettext("Soundtrack"), tr, tg, tb);
int next_y = font::print_wrap(PR_CEN, -1, 65, loc::gettext("Toggle between MMMMMM and PPPPPP."), tr, tg, tb);
const char* soundtrack;
if (music.usingmmmmmm)
{
soundtrack = loc::gettext("Current soundtrack: MMMMMM");
font::print_wrap(PR_CEN, -1, 65, loc::gettext("Adjust volume settings and soundtrack."), tr, tg, tb);
}
else
{
soundtrack = loc::gettext("Current soundtrack: PPPPPP");
font::print_wrap(PR_CEN, -1, 65, loc::gettext("Adjust volume settings."), tr, tg, tb);
}
}
else
{
switch (game.currentmenuoption)
{
case 0:
font::print(PR_2X | PR_CEN, -1, 30, loc::gettext("Music Volume"), tr, tg, tb);
font::print_wrap(PR_CEN, -1, 65, loc::gettext("Change the volume of the music."), tr, tg, tb);
volumesliderrender();
break;
case 1:
font::print(PR_2X | PR_CEN, -1, 30, loc::gettext("Sound Volume"), tr, tg, tb);
font::print_wrap(PR_CEN, -1, 65, loc::gettext("Change the volume of sound effects."), tr, tg, tb);
volumesliderrender();
break;
case 2:
{
if (!music.mmmmmm)
{
break;
}
font::print(PR_2X | PR_CEN, -1, 30, loc::gettext("Soundtrack"), tr, tg, tb);
int next_y = font::print_wrap(PR_CEN, -1, 65, loc::gettext("Toggle between MMMMMM and PPPPPP."), tr, tg, tb);
const char* soundtrack;
if (music.usingmmmmmm)
{
soundtrack = loc::gettext("Current soundtrack: MMMMMM");
}
else
{
soundtrack = loc::gettext("Current soundtrack: PPPPPP");
}
font::print_wrap(PR_CEN, -1, next_y, soundtrack, tr, tg, tb);
break;
}
font::print_wrap(PR_CEN, -1, next_y, soundtrack, tr, tg, tb);
break;
}
}

View file

@ -150,6 +150,19 @@ namespace touch
register_button(button);
}
void create_slider_button(int x, int y, int width, int height, std::string text, int* var, int minvalue, int maxvalue)
{
TouchButton button = create_button(x, y, width, height, text);
button.type = TOUCH_BUTTON_TYPE_MENU_SLIDER;
button.id = -1;
button.disabled = false;
button.min = minvalue;
button.max = maxvalue;
button.var = var;
register_button(button);
}
void create_toggle_button(int x, int y, int width, int height, std::string text, int id, bool checked)
{
TouchButton button = create_button(x, y, width, height, text);
@ -186,6 +199,7 @@ namespace touch
menuactionpress();
break;
case TOUCH_BUTTON_TYPE_NONE:
case TOUCH_BUTTON_TYPE_MENU_SLIDER:
default:
break;
}
@ -281,6 +295,38 @@ namespace touch
}
}
void update_sliders()
{
SDL_Rect stretch_rect;
graphics.get_stretch_info(&stretch_rect);
for (int i = 0; i < all_buttons.size(); i++)
{
TouchButton* button = all_buttons[i];
if (button->type == TOUCH_BUTTON_TYPE_MENU_SLIDER && button->pressed)
{
int value = *button->var;
int range = button->max - button->min;
float percent = (float) (value - button->min) / range;
int finger_x = (fingers[button->fingerId].x - stretch_rect.x) * SCREEN_WIDTH_PIXELS / stretch_rect.w;
int newvalue = button->min + (int) ((finger_x - button->x) / (float)button->width * range);
if (newvalue < button->min)
{
newvalue = button->min;
}
if (newvalue > button->max)
{
newvalue = button->max;
}
*button->var = newvalue;
}
}
}
void render_buttons(int scale, bool ui, int r, int g, int b)
{
for (int i = 0; i < all_buttons.size(); i++)
@ -325,6 +371,27 @@ namespace touch
switch (button->type)
{
case TOUCH_BUTTON_TYPE_MENU_SLIDER:
{
// Find where the slider position is!
int value = *button->var;
int range = button->max - button->min;
float percent = (float) (value - button->min) / range;
int sliderpos = (int) ((button->width - 10) * percent);
// Draw track
graphics.fill_rect(button->x * scale + 2, (button->y + (button->height / 2)) * scale, button->width, 4, use_r / shadow_div, use_g / shadow_div, use_b / shadow_div);
graphics.fill_rect(button->x * scale, (button->y + (button->height / 2) - 2) * scale, button->width, 4, use_r / inner_div, use_g / inner_div, use_b / inner_div);
// Draw slider
graphics.fill_rect((button->x + sliderpos + 2) * scale, (button->y + (button->height / 2) - 3) * scale, 10, 10, use_r / shadow_div, use_g / shadow_div, use_b / shadow_div);
graphics.fill_rect((button->x + sliderpos) * scale, (button->y + (button->height / 2) - 5) * scale, 10, 10, use_r, use_g, use_b);
graphics.fill_rect((button->x + sliderpos + 1) * scale, (button->y + (button->height / 2) - 4) * scale, 8, 8, use_r / inner_div, use_g / inner_div, use_b / inner_div);
font::print(PR_CEN | PR_CJK_LOW | font_scale, button->x + (button->width / 2) * scale, button->y * scale, button->text, use_r, use_g, use_b);
break;
}
case TOUCH_BUTTON_TYPE_MENU_TOGGLE:
graphics.draw_rect(button->x + offset * scale, button->y + offset * scale, 10, 10, use_r, use_g, use_b);
if (button->checked)

View file

@ -57,6 +57,7 @@ enum TouchButtonType
TOUCH_BUTTON_TYPE_NONE,
TOUCH_BUTTON_TYPE_MENU,
TOUCH_BUTTON_TYPE_MENU_TOGGLE,
TOUCH_BUTTON_TYPE_MENU_SLIDER,
TOUCH_BUTTON_TYPE_MAP
};
@ -74,6 +75,9 @@ struct TouchButton
int id; // The ID for the button, mainly used for menu buttons
bool disabled; // Whether the button is disabled or not (gray and can't use), different from active
bool checked; // If this is a checkbox, whether it's checked or not
int min; // If this is a slider, this is the minimum value
int max; // If this is a slider, this is the maximum value
int* var; // If this is a slider, this is the variable to modify
std::string text; // The text for the button, if it doesn't have an image
SDL_Texture* image; // The image that gets displayed on the button, can be NULL
SDL_FingerID fingerId;
@ -90,6 +94,7 @@ namespace touch
extern bool scroll;
void refresh_buttons(void);
void update_sliders();
void reset(void);
void on_menu_create(void);
void update_buttons(void);
@ -99,6 +104,7 @@ namespace touch
void create_menu_button(int x, int y, int width, int height, std::string text, int id);
void create_menu_button(int x, int y, int width, int height, std::string text, int id, bool disabled);
void create_slider_button(int x, int y, int width, int height, std::string text, int* var, int minvalue, int maxvalue);
void create_toggle_button(int x, int y, int width, int height, std::string text, int id, bool checked);
void remove_dynamic_buttons(void);