Skip to content

Commit

Permalink
Work on the menus regarding binds.
Browse files Browse the repository at this point in the history
  • Loading branch information
XerTheSquirrel committed Dec 25, 2023
1 parent da49581 commit f802658
Show file tree
Hide file tree
Showing 11 changed files with 103 additions and 54 deletions.
18 changes: 18 additions & 0 deletions config.def.keybinds.h
Original file line number Diff line number Diff line change
Expand Up @@ -1927,6 +1927,16 @@ static const struct retro_keybind retro_keybinds_1[] = {
RARCH_OSK, NO_BTN, NO_BTN, 0,
true
},


{
NULL, NULL,
AXIS_NONE, AXIS_NONE, AXIS_NONE,
MENU_ENUM_LABEL_INPUT_ANALOG_SENSITIVITY, RETROK_UNKNOWN,
RARCH_EXTRA_CORE_COMMAND_START, NO_BTN, NO_BTN, 0,
true
},

#if 0
/* Deprecated */
{
Expand Down Expand Up @@ -2194,6 +2204,14 @@ static const struct retro_keybind retro_keybinds_rest[] = {
RARCH_TURBO_ENABLE, NO_BTN, NO_BTN, 0,
true
},

{
NULL, NULL,
AXIS_NONE, AXIS_NONE, AXIS_NONE,
MENU_ENUM_LABEL_INPUT_SMALL_KEYBOARD_ENABLE, RETROK_UNKNOWN,
RARCH_EXTRA_CORE_COMMAND_START, NO_BTN, NO_BTN, 0,
true
},
};

#endif
Expand Down
3 changes: 2 additions & 1 deletion input/input_defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,8 @@ static INLINE rarch_bind_id rarch_logical_to_bind_game_controller(rarch_logical_
/**
* Returns the number of binds that are part of game controllers.
*
* Use this instead of @c RARCH_FIRST_CUSTOM_BIND .
* Use this instead of @c RARCH_FIRST_CUSTOM_BIND;
* Use this instead of @code RARCH_FIRST_CUSTOM_BIND + 8 @endcode.
*
* @return The number of binds that are part of game controllers.
* @since 2023/12/24
Expand Down
11 changes: 9 additions & 2 deletions input/input_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -6188,6 +6188,7 @@ void input_remapping_set_defaults(bool clear_cache)
unsigned usernum, logical;
settings_t *settings = config_get_ptr();
const struct retro_keybind *keybind;
bool is_ext;

for (usernum = 0; usernum < MAX_USERS; usernum++)
{
Expand All @@ -6198,12 +6199,18 @@ void input_remapping_set_defaults(bool clear_cache)
if (!rarch_logical_bind_is_basic(logical))
continue;

keybind = &input_config_binds[usernum][logical];
is_ext = rarch_logical_bind_is_extended_basic(logical);

keybind = &input_config_binds[usernum][logical];

/* Debug. */
RARCH_LOG("Keybind user %d log %d -> %p %d\n",
usernum, logical, keybind, (keybind != NULL ? keybind->id : -1));

/* Force defaults for extended keys to be unmapped by default. */
configuration_set_uint(settings,
settings->uints.input_remap_ids[usernum][logical],
(!rarch_logical_bind_is_extended_basic(logical) && keybind) ?
(/*!rarch_logical_bind_is_extended_basic(logical) &&*/ keybind) ?
keybind->id : RARCH_UNMAPPED);

configuration_set_uint(settings,
Expand Down
6 changes: 3 additions & 3 deletions menu/cbs/menu_cbs_get_value.c
Original file line number Diff line number Diff line change
Expand Up @@ -828,8 +828,8 @@ static void menu_action_setting_disp_set_label_input_desc(
{
unsigned remap_idx;
settings_t *settings = config_get_ptr();
unsigned user_idx = (type - MENU_SETTINGS_INPUT_DESC_BEGIN) / (RARCH_FIRST_CUSTOM_BIND + 8);
unsigned btn_idx = (type - MENU_SETTINGS_INPUT_DESC_BEGIN) - (RARCH_FIRST_CUSTOM_BIND + 8) * user_idx;
unsigned user_idx = (type - MENU_SETTINGS_INPUT_DESC_BEGIN) / (rarch_num_bind_game_controller());
unsigned btn_idx = (type - MENU_SETTINGS_INPUT_DESC_BEGIN) - (rarch_num_bind_game_controller()) * user_idx;

if (!settings)
return;
Expand All @@ -845,7 +845,7 @@ static void menu_action_setting_disp_set_label_input_desc(
if (!string_is_empty(descriptor))
{
size_t _len = strlcpy(s, descriptor, len);
if (remap_idx < RARCH_FIRST_CUSTOM_BIND) { }
if (rarch_logical_bind_is_basic(remap_idx)) { }
else if (remap_idx % 2 == 0)
{
s[ _len] = ' ';
Expand Down
8 changes: 4 additions & 4 deletions menu/cbs/menu_cbs_ok.c
Original file line number Diff line number Diff line change
Expand Up @@ -7137,17 +7137,17 @@ static int action_ok_push_dropdown_item_input_description(const char *path,

if ( !settings
|| (entry_type < MENU_SETTINGS_INPUT_DESC_BEGIN)
|| ((remap_idx >= RARCH_CUSTOM_BIND_LIST_END)
|| ((remap_idx >= rarch_num_bind_game_controller())
&& (remap_idx != RARCH_UNMAPPED)))
return -1;

/* Determine user/button indices */
user_idx = (entry_type - MENU_SETTINGS_INPUT_DESC_BEGIN)
/ (RARCH_FIRST_CUSTOM_BIND + 8);
/ (rarch_num_bind_game_controller());
btn_idx = (entry_type - MENU_SETTINGS_INPUT_DESC_BEGIN)
- (RARCH_FIRST_CUSTOM_BIND + 8) * user_idx;
- (rarch_num_bind_game_controller()) * user_idx;

if ((user_idx >= MAX_USERS) || (btn_idx >= RARCH_CUSTOM_BIND_LIST_END))
if ((user_idx >= MAX_USERS) || (btn_idx >= rarch_num_bind_game_controller()))
return -1;

/* Assign new mapping */
Expand Down
2 changes: 1 addition & 1 deletion menu/cbs/menu_cbs_sublabel.c
Original file line number Diff line number Diff line change
Expand Up @@ -1579,7 +1579,7 @@ static int action_bind_sublabel_remap_sublabel(
{
settings_t *settings = config_get_ptr();
unsigned port = (type - MENU_SETTINGS_INPUT_DESC_BEGIN)
/ (RARCH_FIRST_CUSTOM_BIND + 8);
/ (rarch_num_bind_game_controller());

if (settings && (port < MAX_USERS))
{
Expand Down
2 changes: 1 addition & 1 deletion menu/cbs/menu_cbs_title.c
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ static int action_get_title_dropdown_input_description(
const char *path, const char *label, unsigned menu_type, char *s, size_t len)
{
unsigned port = (menu_type - MENU_SETTINGS_INPUT_DESC_BEGIN) /
(RARCH_FIRST_CUSTOM_BIND + 8);
(rarch_num_bind_game_controller());

return action_get_title_dropdown_input_description_common(
path, port, s, len);
Expand Down
14 changes: 7 additions & 7 deletions menu/menu_displaylist.c
Original file line number Diff line number Diff line change
Expand Up @@ -5466,11 +5466,11 @@ static int menu_displaylist_parse_input_description_list(
return 0;

/* Determine user/button indices */
user_idx = (info->type - MENU_SETTINGS_INPUT_DESC_BEGIN) / (RARCH_FIRST_CUSTOM_BIND + 8);
btn_idx = (info->type - MENU_SETTINGS_INPUT_DESC_BEGIN) - (RARCH_FIRST_CUSTOM_BIND + 8) * user_idx;
user_idx = (info->type - MENU_SETTINGS_INPUT_DESC_BEGIN) / (rarch_num_bind_game_controller());
btn_idx = (info->type - MENU_SETTINGS_INPUT_DESC_BEGIN) - (rarch_num_bind_game_controller()) * user_idx;

if ( (user_idx >= MAX_USERS)
|| (btn_idx >= RARCH_CUSTOM_BIND_LIST_END))
|| (btn_idx >= rarch_num_bind_game_controller()))
return 0;

mapped_port = settings->uints.input_remap_ports[user_idx];
Expand All @@ -5481,7 +5481,7 @@ static int menu_displaylist_parse_input_description_list(
/* Get current mapping for selected button */
current_remap_idx = settings->uints.input_remap_ids[user_idx][btn_idx];

if (current_remap_idx >= RARCH_CUSTOM_BIND_LIST_END)
if (current_remap_idx < 0 || current_remap_idx >= rarch_num_bind_game_controller())
current_remap_idx = RARCH_UNMAPPED;

/* An annoyance: Menu entries do not have
Expand All @@ -5494,11 +5494,11 @@ static int menu_displaylist_parse_input_description_list(
snprintf(entry_label, sizeof(entry_label), "%u", info->type);

/* Loop over core input definitions */
for (j = 0; j < RARCH_CUSTOM_BIND_LIST_END; j++)
for (j = 0; j < rarch_num_bind_game_controller(); j++)
{
const char *input_desc_btn;

i = (j < RARCH_ANALOG_BIND_LIST_END) ? input_config_bind_order[j] : j;
i = (rarch_logical_bind_is_basic(j) ? input_config_bind_order[j] : j);
input_desc_btn = sys_info->input_desc_btn[mapped_port][i];

/* Check whether an input is defined for
Expand All @@ -5514,7 +5514,7 @@ static int menu_displaylist_parse_input_description_list(
* indicators */
size_t _len = strlcpy(input_description, input_desc_btn,
sizeof(input_description));
if (i >= RARCH_FIRST_CUSTOM_BIND)
if (!rarch_logical_bind_is_basic(i))
{
input_description [ _len] = ' ';
if ((i % 2) == 0)
Expand Down
3 changes: 2 additions & 1 deletion menu/menu_driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ enum menu_settings_type

/* Binds in the menu, note that every single bind needs to fit! */
MENU_SETTINGS_BIND_BEGIN,
MENU_SETTINGS_BIND_LAST = MENU_SETTINGS_BIND_BEGIN + RARCH_EXTRA_CORE_COMMAND_COUNT + RARCH_ANALOG_RIGHT_Y_MINUS,
MENU_SETTINGS_BIND_LAST = MENU_SETTINGS_BIND_BEGIN + rarch_num_bind_game_controller(),
MENU_SETTINGS_BIND_ALL_LAST = MENU_SETTINGS_BIND_BEGIN + RARCH_EXTRA_CORE_COMMAND_COUNT + RARCH_MENU_TOGGLE,

MENU_SETTINGS_CUSTOM_BIND,
Expand All @@ -234,6 +234,7 @@ enum menu_settings_type
MENU_SETTINGS_CHEAT_BEGIN,
MENU_SETTINGS_CHEAT_END = MENU_SETTINGS_CHEAT_BEGIN + (MAX_CHEAT_COUNTERS - 1),

/* Within @c MENU_SETTINGS_INPUT_END , the + 6 are these following keys. */
MENU_SETTINGS_INPUT_LIBRETRO_DEVICE,
MENU_SETTINGS_INPUT_ANALOG_DPAD_MODE,
MENU_SETTINGS_INPUT_INPUT_REMAP_PORT,
Expand Down
3 changes: 3 additions & 0 deletions menu/menu_setting.c
Original file line number Diff line number Diff line change
Expand Up @@ -9254,6 +9254,9 @@ static bool setting_append_list_input_player_options(
{
const char *value_na =
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NOT_AVAILABLE);

RARCH_LOG("Filling in bind menu for user %d.\n", user);

for (bindid = 0; bindid < RARCH_BIND_LIST_END; bindid++)
{
char label[NAME_MAX_LENGTH];
Expand Down
87 changes: 53 additions & 34 deletions runloop.c
Original file line number Diff line number Diff line change
Expand Up @@ -1433,55 +1433,74 @@ static void rarch_set_core_extended_retropad(rarch_system_info_t *sys_info,
const struct retro_core_extended_retropad_button* action;
unsigned at, bind, usernum;
const char** user_inputs;
bool did_standard;

/* Debug. */
RARCH_LOG("[Environ]: Setting extended retropad buttons.\n");

/* Check if standard inputs were set. */
did_standard = (runloop_st->current_core.flags & RETRO_CORE_FLAG_HAS_SET_INPUT_DESCRIPTORS) != 0;
if (!did_standard)
RARCH_LOG("[Environ]: Standard was not previously set.\n");

/* Erase all the previous extended binds for all users. */
rarch_erase_input_desc_btn(sys_info,
rarch_first_logical_bind_game_controller(),
rarch_num_bind_game_controller());
if (did_standard)
rarch_erase_input_desc_btn(sys_info,
rarch_first_logical_bind_game_controller(),
rarch_num_bind_game_controller());

/* Otherwise erase everything as it has never been set before. */
else
rarch_erase_input_desc_btn(sys_info, 0, rarch_num_bind_game_controller());

/* Set output details, if requested. */
if (input->out_info != NULL) {
input->out_info->out_num_extra = RARCH_EXTRA_CORE_COMMAND_COUNT;
}

/* Go through the commands and process them. */
for (at = 0; input->actions[at].description != NULL; at++)
if (input->actions != NULL)
{
/* Get base action. */
action = &input->actions[at];

/* Map player. */
usernum = action->port;
if (usernum < 0 || usernum >= MAX_USERS)
continue;

/* We only care about gamepads and their analog equivalents. */
if (action->device != RETRO_DEVICE_JOYPAD &&
action->device != RETRO_DEVICE_ANALOG)
continue;

/* Ignore logical binds which are out of bounds. */
bind = action->logical_id;
if (bind < 0 || bind >= RARCH_EXTRA_CORE_COMMAND_COUNT)
continue;

/* Map to logical button internally. */
bind = rarch_first_logical_bind_game_controller() + bind;

/* Set description. */
sys_info->input_desc_btn[usernum][bind] = action->description;
for (at = 0; input->actions[at].description != NULL; at++)
{
/* Get base action. */
action = &input->actions[at];

/* Debug. */
RARCH_LOG("[Environ]: Wanting extra button %d %d %d %d %d %s %s.\n",
at, action->port, action->device, action->port, action->logical_id,
action->description, action->glyph);

/* Map player. */
usernum = action->port;
if (usernum < 0 || usernum >= MAX_USERS)
continue;

/* We only care about gamepads and their analog equivalents. */
if (action->device != RETRO_DEVICE_JOYPAD &&
action->device != RETRO_DEVICE_ANALOG)
continue;

/* Ignore logical binds which are out of bounds. */
bind = action->logical_id;
if (bind < 0 || bind >= RARCH_EXTRA_CORE_COMMAND_COUNT)
continue;

/* Map to logical button internally. */
bind = rarch_first_logical_bind_game_controller() + bind;

/* Set description. */
sys_info->input_desc_btn[usernum][bind] = action->description;

/* Debug. */
RARCH_LOG("[Environ]: Bound %d to %s.\n",
bind, action->description);
}

/* Debug. */
RARCH_LOG("[Environ]: Bound %d to %s.\n",
bind, action->description);
RARCH_LOG("[Environ]: Set %d extended buttons.\n", at);
}

/* Debug. */
RARCH_LOG("[Environ]: Set %d extended buttons.\n", at);

/* Indicate that the input descriptors changed. */
runloop_st->current_core.flags |=
RETRO_CORE_FLAG_HAS_SET_EXTENDED_INPUT;
Expand Down Expand Up @@ -7910,8 +7929,8 @@ bool core_has_set_input_descriptor(void)
{
runloop_state_t *runloop_st = &runloop_state;
return ((runloop_st->current_core.flags &
RETRO_CORE_FLAG_HAS_SET_INPUT_DESCRIPTORS |
RETRO_CORE_FLAG_HAS_SET_EXTENDED_INPUT) > 0);
(RETRO_CORE_FLAG_HAS_SET_INPUT_DESCRIPTORS |
RETRO_CORE_FLAG_HAS_SET_EXTENDED_INPUT)) != 0);
}

void runloop_path_set_basename(const char *path)
Expand Down

0 comments on commit f802658

Please sign in to comment.