Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions ball/st_conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ enum
CONF_VIDEO = GUI_LAST,
CONF_LANGUAGE,
CONF_MOUSE_SENSE,
CONF_JOYSTICK_RESPONSE,
CONF_JOYSTICK,
CONF_SOUND_VOLUME,
CONF_MUSIC_VOLUME,
Expand All @@ -55,6 +56,7 @@ enum
static int mouse_id[11];
static int music_id[11];
static int sound_id[11];
static int joystick_id[11];

/*
* This maps mouse_sense 300 (default) to the 7th of an 11 button
Expand All @@ -78,11 +80,26 @@ static int sound_id[11];
#define MOUSE_RANGE_UNMAP(i) \
(MOUSE_RANGE_MAX - (i * MOUSE_RANGE_INC))

/*
* Tilt responsiveness configuration: [50, 75 .. 300].
*/

#define JOYSTICK_RANGE_MIN 50
#define JOYSTICK_RANGE_INC 25
#define JOYSTICK_RANGE_MAX (JOYSTICK_RANGE_MIN + (JOYSTICK_RANGE_INC * 10))

#define JOYSTICK_RANGE_MAP(m) \
CLAMP(0, (JOYSTICK_RANGE_MAX - m) / JOYSTICK_RANGE_INC, 10)

#define JOYSTICK_RANGE_UNMAP(i) \
(JOYSTICK_RANGE_MAX - (i * JOYSTICK_RANGE_INC))

static int conf_action(int tok, int val)
{
int sound = config_get_d(CONFIG_SOUND_VOLUME);
int music = config_get_d(CONFIG_MUSIC_VOLUME);
int mouse = MOUSE_RANGE_MAP(config_get_d(CONFIG_MOUSE_SENSE));
int joystick = JOYSTICK_RANGE_MAP(config_get_d(CONFIG_JOYSTICK_RESPONSE));
int r = 1;

audio_play(AUD_MENU, 1.0f);
Expand Down Expand Up @@ -120,6 +137,13 @@ static int conf_action(int tok, int val)
gui_toggle(mouse_id[mouse]);
break;

case CONF_JOYSTICK_RESPONSE:
config_set_d(CONFIG_JOYSTICK_RESPONSE, JOYSTICK_RANGE_UNMAP(val));

gui_toggle(joystick_id[val]);
gui_toggle(joystick_id[joystick]);
break;

case CONF_SOUND_VOLUME:
config_set_d(CONFIG_SOUND_VOLUME, val);
audio_volume(val, music);
Expand Down Expand Up @@ -158,6 +182,7 @@ static int conf_gui(void)
int sound = config_get_d(CONFIG_SOUND_VOLUME);
int music = config_get_d(CONFIG_MUSIC_VOLUME);
int mouse = MOUSE_RANGE_MAP(config_get_d(CONFIG_MOUSE_SENSE));
int joystick = JOYSTICK_RANGE_MAP(config_get_d(CONFIG_JOYSTICK_RESPONSE));

const char *player = config_get_s(CONFIG_PLAYER);
const char *ball = config_get_s(CONFIG_BALL_FILE);
Expand All @@ -173,6 +198,9 @@ static int conf_gui(void)
conf_slider(id, _("Mouse Sensitivity"), CONF_MOUSE_SENSE, mouse,
mouse_id, ARRAYSIZE(mouse_id));

conf_slider(id, _("Tilt Responsiveness"), CONF_JOYSTICK_RESPONSE, joystick,
joystick_id, ARRAYSIZE(joystick_id));

gui_space(id);

conf_state(id, _("Gamepad"), _("Configure"), CONF_JOYSTICK);
Expand Down