Volume controls changed to sliders from "0..10" value list

This commit is contained in:
makise-homura 2017-01-31 00:55:53 +03:00
parent 881521d8c7
commit 0ad5a46c75
8 changed files with 35 additions and 40 deletions

View file

@ -31,8 +31,8 @@ ConfigEntry configdefs[] = {
{CFGT_INT, NO_SHADER, "disable_shader"},
{CFGT_INT, NO_AUDIO, "disable_audio"},
{CFGT_INT, NO_MUSIC, "disable_bgm"},
{CFGT_INT, SFX_VOLUME, "sfx_volume"},
{CFGT_INT, BGM_VOLUME, "bgm_volume"},
{CFGT_FLOAT, SFX_VOLUME, "sfx_volume"},
{CFGT_FLOAT, BGM_VOLUME, "bgm_volume"},
{CFGT_INT, NO_STAGEBG, "disable_stagebg"},
{CFGT_INT, NO_STAGEBG_FPSLIMIT, "disable_stagebg_auto_fpslimit"},
{CFGT_INT, SAVE_RPY, "save_rpy"},

View file

@ -123,8 +123,8 @@ int main(int argc, char** argv) {
MenuData menu;
create_main_menu(&menu);
printf("-- menu\n");
set_sfx_volume(tconfig.intval[SFX_VOLUME]);
set_bgm_volume(tconfig.intval[BGM_VOLUME]);
set_sfx_volume(tconfig.fltval[SFX_VOLUME]);
set_bgm_volume(tconfig.fltval[BGM_VOLUME]);
start_bgm("bgm_menu");
main_menu_loop(&menu);

View file

@ -121,6 +121,14 @@ OptionBinding* bind_scale(int cfgentry, float smin, float smax, float step) {
return bind;
}
// BT_ScaleCallback: float values clamped to a range with callback
OptionBinding* bind_scale_call(int cfgentry, float smin, float smax, float step, FloatSetter callback) {
OptionBinding *bind = bind_scale(cfgentry, smin, smax, step);
bind->type = BT_ScaleCallback;
bind->callback = callback;
return bind;
}
// Returns a pointer to the first found binding that blocks input. If none found, returns NULL.
OptionBinding* bind_getinputblocking(MenuData *m) {
int i;
@ -621,39 +629,17 @@ void create_options_menu(MenuData *m) {
); bind_onoff(b);
add_menu_entry(m, "SFX volume level", do_nothing,
b = bind_option(SFX_VOLUME, bind_common_intget,
bind_sfxvol_intset)
); bind_addvalue(b, "0");
bind_addvalue(b, "1");
bind_addvalue(b, "2");
bind_addvalue(b, "3");
bind_addvalue(b, "4");
bind_addvalue(b, "5");
bind_addvalue(b, "6");
bind_addvalue(b, "7");
bind_addvalue(b, "8");
bind_addvalue(b, "9");
bind_addvalue(b, "10");
bind_scale_call(SFX_VOLUME, 0, 1, 0.1, set_sfx_volume)
);
add_menu_entry(m, "Background music", do_nothing,
b = bind_option(NO_MUSIC, bind_common_onoffget_inverted,
bind_nomusic_set)
); bind_onoff(b);
add_menu_entry(m, "Music volume level", do_nothing,
b = bind_option(BGM_VOLUME, bind_common_intget,
bind_musvol_intset)
); bind_addvalue(b, "0");
bind_addvalue(b, "1");
bind_addvalue(b, "2");
bind_addvalue(b, "3");
bind_addvalue(b, "4");
bind_addvalue(b, "5");
bind_addvalue(b, "6");
bind_addvalue(b, "7");
bind_addvalue(b, "8");
bind_addvalue(b, "9");
bind_addvalue(b, "10");
bind_scale_call(BGM_VOLUME, 0, 1, 0.1, set_bgm_volume)
);
add_menu_separator(m);
add_menu_entry(m, "Video options...", options_sub_video, m);
@ -796,7 +782,8 @@ void draw_options_menu(MenuData *menu) {
break;
}
case BT_Scale: {
case BT_Scale:
case BT_ScaleCallback: {
int w = 200;
int h = 5;
int cw = 5;
@ -931,8 +918,11 @@ static void options_input_event(EventType type, int state, void *arg) {
if(bind) {
if(bind->type == BT_IntValue || bind->type == BT_Resolution)
bind_setprev(bind);
else if(bind->type == BT_Scale)
else if((bind->type == BT_Scale) || (bind->type == BT_ScaleCallback)) {
tconfig.fltval[bind->configentry] = clamp(tconfig.fltval[bind->configentry] - bind->scale_step, bind->scale_min, bind->scale_max);
if (bind->type == BT_ScaleCallback)
bind->callback(tconfig.fltval[bind->configentry]);
}
}
break;
@ -941,8 +931,11 @@ static void options_input_event(EventType type, int state, void *arg) {
if(bind) {
if(bind->type == BT_IntValue || bind->type == BT_Resolution)
bind_setnext(bind);
else if(bind->type == BT_Scale)
else if((bind->type == BT_Scale) || (bind->type == BT_ScaleCallback)) {
tconfig.fltval[bind->configentry] = clamp(tconfig.fltval[bind->configentry] + bind->scale_step, bind->scale_min, bind->scale_max);
if (bind->type == BT_ScaleCallback)
bind->callback(tconfig.fltval[bind->configentry]);
}
}
break;

View file

@ -20,12 +20,15 @@ typedef int (*BindingGetter)(void*);
typedef int (*BindingSetter)(void*, int);
typedef int (*BindingDependence)(void);
typedef void (*FloatSetter)(float);
typedef enum BindingType {
BT_IntValue,
BT_KeyBinding,
BT_StrValue,
BT_Resolution,
BT_Scale,
BT_ScaleCallback,
BT_GamepadKeyBinding
} BindingType;
@ -40,6 +43,7 @@ typedef struct OptionBinding {
float scale_step;
BindingGetter getter;
BindingSetter setter;
FloatSetter callback;
BindingDependence dependence;
int selected;
int configentry;

View file

@ -191,10 +191,9 @@ void play_sound_p(char *name, int unconditional)
}
}
void set_sfx_volume(int value)
void set_sfx_volume(float gain)
{
if(tconfig.intval[NO_AUDIO]) return;
float gain = 0.1f * value;
printf("SFX volume: %f\n", gain);
int i;
for(i = 0; i < SNDSRC_COUNT; i++) {

View file

@ -35,7 +35,7 @@ Sound *get_snd(Sound *source, char *name);
void delete_sound(void **snds, void *snd);
void delete_sounds(void);
void set_sfx_volume(int value);
void set_sfx_volume(float gain);
int init_sfx(int *argc, char *argv[]);
void shutdown_sfx(void);

View file

@ -201,10 +201,9 @@ void restore_bgm(void)
saved_bgm = NULL;
}
void set_bgm_volume(int value)
void set_bgm_volume(float gain)
{
if(tconfig.intval[NO_MUSIC]) return;
float gain = 0.1f * value;
printf("BGM volume: %f\n", gain);
alSourcef(resources.bgmsrc,AL_GAIN, gain);
warn_alut_error("changing gain of music source");

View file

@ -42,6 +42,6 @@ void load_bgm_descriptions(const char *path);
void delete_music(void);
void set_bgm_volume(int value);
void set_bgm_volume(float gain);
#endif