Skip to content

Commit d18adfd

Browse files
authored
Refactor remap menu left-right callbacks (#18340)
1 parent 6217684 commit d18adfd

7 files changed

Lines changed: 115 additions & 119 deletions

File tree

input/input_defines.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#define RARCH_FIRST_META_KEY RARCH_CUSTOM_BIND_LIST_END
3535

3636
#define RARCH_UNMAPPED 1024
37+
#define RARCH_NO_BIND "---"
3738

3839
/* Specialized _MOUSE that targets the full screen regardless of viewport.
3940
*/

input/input_driver.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3941,7 +3941,7 @@ size_t input_config_get_bind_string(
39413941

39423942
/*completely empty?*/
39433943
if (*s == '\0')
3944-
_len += strlcpy(s + _len, "---", len - _len);
3944+
_len += strlcpy(s + _len, RARCH_NO_BIND, len - _len);
39453945
return _len;
39463946
}
39473947

menu/cbs/menu_cbs_get_value.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -823,7 +823,7 @@ static size_t menu_action_setting_disp_set_label_input_desc(
823823
}
824824
}
825825
/* If descriptor was not found, set this instead */
826-
return strlcpy(s, "---", len);
826+
return strlcpy(s, RARCH_NO_BIND, len);
827827
}
828828

829829
static size_t menu_action_setting_disp_set_label_input_desc_kbd(
@@ -860,7 +860,7 @@ static size_t menu_action_setting_disp_set_label_input_desc_kbd(
860860
_len += strlcpy(s + _len, key_descriptors[key_id].desc, len - _len);
861861
}
862862
else
863-
_len = strlcpy(s, "---", len);
863+
_len = strlcpy(s, RARCH_NO_BIND, len);
864864

865865
*w = 19;
866866

menu/cbs/menu_cbs_left.c

Lines changed: 33 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -136,60 +136,56 @@ static int action_left_cheat(unsigned type, const char *label,
136136
#endif
137137

138138
static int action_left_input_desc(unsigned type, const char *label,
139-
bool wraparound)
139+
bool wraparound)
140140
{
141-
unsigned user_idx;
142-
unsigned btn_idx;
143-
unsigned remap_idx;
144-
unsigned bind_idx;
145-
unsigned mapped_port;
146-
settings_t *settings = config_get_ptr();
147-
rarch_system_info_t *sys_info = &runloop_state_get_ptr()->system;
148-
149-
if (!settings || !sys_info)
150-
return 0;
151-
152-
user_idx = (type - MENU_SETTINGS_INPUT_DESC_BEGIN) / (RARCH_FIRST_CUSTOM_BIND + 8);
153-
btn_idx = (type - MENU_SETTINGS_INPUT_DESC_BEGIN) - (RARCH_FIRST_CUSTOM_BIND + 8) * user_idx;
154-
mapped_port = settings->uints.input_remap_ports[user_idx];
155-
remap_idx = settings->uints.input_remap_ids[user_idx][btn_idx];
156-
for (bind_idx = 0; bind_idx < RARCH_ANALOG_BIND_LIST_END; bind_idx++)
157-
{
158-
if (input_config_bind_order[bind_idx] == remap_idx)
159-
break;
160-
}
141+
settings_t *settings = config_get_ptr();
142+
rarch_system_info_t *sys_info = &runloop_state_get_ptr()->system;
161143

162-
/* Search for the last input desc bind */
163-
if (remap_idx == RARCH_UNMAPPED)
144+
if (settings && sys_info)
164145
{
165-
uint8_t i;
146+
unsigned bind_idx;
147+
unsigned user_idx = (type - MENU_SETTINGS_INPUT_DESC_BEGIN) / (RARCH_FIRST_CUSTOM_BIND + 8);
148+
unsigned btn_idx = (type - MENU_SETTINGS_INPUT_DESC_BEGIN) - (RARCH_FIRST_CUSTOM_BIND + 8) * user_idx;
149+
unsigned mapped_port = settings->uints.input_remap_ports[user_idx];
150+
unsigned remap_idx = settings->uints.input_remap_ids[user_idx][btn_idx];
166151

167-
for (i = 0; i < RARCH_ANALOG_BIND_LIST_END; i++)
152+
for (bind_idx = 0; bind_idx < RARCH_ANALOG_BIND_LIST_END; bind_idx++)
168153
{
169-
if (string_is_empty(sys_info->input_desc_btn[mapped_port][i]))
154+
if (input_config_bind_order[bind_idx] == remap_idx)
170155
break;
171156
}
172-
settings->uints.input_remap_ids[user_idx][btn_idx] = input_config_bind_order[i - 1];
173-
}
174-
else if (bind_idx > 0)
175-
{
176-
if (bind_idx > RARCH_ANALOG_BIND_LIST_END)
177-
settings->uints.input_remap_ids[user_idx][btn_idx]--;
178-
else
157+
158+
/* If pressed from unmapped bind, start from the bottom */
159+
if (label)
160+
{
161+
struct menu_state *menu_st = menu_state_get_ptr();
162+
menu_entry_t entry;
163+
MENU_ENTRY_INITIALIZE(entry);
164+
entry.flags |= MENU_ENTRY_FLAG_VALUE_ENABLED;
165+
menu_entry_get(&entry, 0, menu_st->selection_ptr, NULL, true);
166+
if (string_is_equal(entry.value, RARCH_NO_BIND))
167+
bind_idx = RARCH_ANALOG_BIND_LIST_END;
168+
}
169+
170+
if (bind_idx > 0)
179171
{
180172
bind_idx--;
181173
bind_idx = input_config_bind_order[bind_idx];
182174
settings->uints.input_remap_ids[user_idx][btn_idx] = bind_idx;
175+
176+
/* Skip empty descs */
177+
if (string_is_empty(sys_info->input_desc_btn[mapped_port][bind_idx]))
178+
return action_left_input_desc(type, NULL, wraparound);
183179
}
180+
else
181+
settings->uints.input_remap_ids[user_idx][btn_idx] = RARCH_UNMAPPED;
184182
}
185-
else if (bind_idx == 0)
186-
settings->uints.input_remap_ids[user_idx][btn_idx] = RARCH_UNMAPPED;
187183

188184
return 0;
189185
}
190186

191187
static int action_left_input_desc_kbd(unsigned type, const char *label,
192-
bool wraparound)
188+
bool wraparound)
193189
{
194190
unsigned remap_id;
195191
unsigned key_id, user_idx, btn_idx;
@@ -201,8 +197,7 @@ static int action_left_input_desc_kbd(unsigned type, const char *label,
201197
user_idx = (type - MENU_SETTINGS_INPUT_DESC_KBD_BEGIN) / RARCH_ANALOG_BIND_LIST_END;
202198
btn_idx = (type - MENU_SETTINGS_INPUT_DESC_KBD_BEGIN) - RARCH_ANALOG_BIND_LIST_END * user_idx;
203199

204-
remap_id =
205-
settings->uints.input_keymapper_ids[user_idx][btn_idx];
200+
remap_id = settings->uints.input_keymapper_ids[user_idx][btn_idx];
206201

207202
for (key_id = 0; key_id < RARCH_MAX_KEYS; key_id++)
208203
{

menu/cbs/menu_cbs_right.c

Lines changed: 52 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,57 @@ static int action_right_cheat_num_passes(unsigned type, const char *label,
139139
}
140140
#endif
141141

142+
static int action_right_input_desc(unsigned type, const char *label,
143+
bool wraparound)
144+
{
145+
settings_t *settings = config_get_ptr();
146+
rarch_system_info_t *sys_info = &runloop_state_get_ptr()->system;
147+
148+
if (settings && sys_info)
149+
{
150+
unsigned bind_idx;
151+
unsigned user_idx = (type - MENU_SETTINGS_INPUT_DESC_BEGIN) / (RARCH_FIRST_CUSTOM_BIND + 8);
152+
unsigned btn_idx = (type - MENU_SETTINGS_INPUT_DESC_BEGIN) - (RARCH_FIRST_CUSTOM_BIND + 8) * user_idx;
153+
unsigned mapped_port = settings->uints.input_remap_ports[user_idx];
154+
unsigned remap_idx = settings->uints.input_remap_ids[user_idx][btn_idx];
155+
156+
for (bind_idx = 0; bind_idx < RARCH_ANALOG_BIND_LIST_END; bind_idx++)
157+
{
158+
if (input_config_bind_order[bind_idx] == remap_idx)
159+
break;
160+
}
161+
162+
/* If pressed from unmapped bind, start from the top */
163+
if (label)
164+
{
165+
struct menu_state *menu_st = menu_state_get_ptr();
166+
menu_entry_t entry;
167+
MENU_ENTRY_INITIALIZE(entry);
168+
entry.flags |= MENU_ENTRY_FLAG_VALUE_ENABLED;
169+
menu_entry_get(&entry, 0, menu_st->selection_ptr, NULL, true);
170+
if (string_is_equal(entry.value, RARCH_NO_BIND))
171+
bind_idx = RARCH_UNMAPPED;
172+
}
173+
174+
if (bind_idx < RARCH_ANALOG_BIND_LIST_END - 1)
175+
{
176+
bind_idx++;
177+
bind_idx = input_config_bind_order[bind_idx];
178+
settings->uints.input_remap_ids[user_idx][btn_idx] = bind_idx;
179+
180+
/* Skip empty descs */
181+
if (string_is_empty(sys_info->input_desc_btn[mapped_port][bind_idx]))
182+
return action_right_input_desc(type, NULL, wraparound);
183+
}
184+
else if (bind_idx == RARCH_ANALOG_BIND_LIST_END - 1)
185+
settings->uints.input_remap_ids[user_idx][btn_idx] = RARCH_UNMAPPED;
186+
else
187+
settings->uints.input_remap_ids[user_idx][btn_idx] = input_config_bind_order[0];
188+
}
189+
190+
return 0;
191+
}
192+
142193
static int action_right_input_desc_kbd(unsigned type, const char *label,
143194
bool wraparound)
144195
{
@@ -152,8 +203,7 @@ static int action_right_input_desc_kbd(unsigned type, const char *label,
152203
user_idx = (type - MENU_SETTINGS_INPUT_DESC_KBD_BEGIN) / RARCH_ANALOG_BIND_LIST_END;
153204
btn_idx = (type - MENU_SETTINGS_INPUT_DESC_KBD_BEGIN) - RARCH_ANALOG_BIND_LIST_END * user_idx;
154205

155-
remap_id =
156-
settings->uints.input_keymapper_ids[user_idx][btn_idx];
206+
remap_id = settings->uints.input_keymapper_ids[user_idx][btn_idx];
157207

158208
for (key_id = 0; key_id < RARCH_MAX_KEYS; key_id++)
159209
{
@@ -171,49 +221,6 @@ static int action_right_input_desc_kbd(unsigned type, const char *label,
171221
return 0;
172222
}
173223

174-
static int action_right_input_desc(unsigned type, const char *label,
175-
bool wraparound)
176-
{
177-
settings_t *settings = config_get_ptr();
178-
rarch_system_info_t *sys_info = &runloop_state_get_ptr()->system;
179-
if (settings && sys_info)
180-
{
181-
unsigned bind_idx;
182-
unsigned user_idx = (type - MENU_SETTINGS_INPUT_DESC_BEGIN) / (RARCH_FIRST_CUSTOM_BIND + 8);
183-
unsigned btn_idx = (type - MENU_SETTINGS_INPUT_DESC_BEGIN) - (RARCH_FIRST_CUSTOM_BIND + 8) * user_idx;
184-
unsigned mapped_port = settings->uints.input_remap_ports[user_idx];
185-
unsigned remap_idx = settings->uints.input_remap_ids[user_idx][btn_idx];
186-
for (bind_idx = 0; bind_idx < RARCH_ANALOG_BIND_LIST_END; bind_idx++)
187-
{
188-
if (input_config_bind_order[bind_idx] == remap_idx)
189-
break;
190-
}
191-
192-
if (bind_idx > RARCH_ANALOG_BIND_LIST_END)
193-
settings->uints.input_remap_ids[user_idx][btn_idx]++;
194-
else
195-
{
196-
if (bind_idx < RARCH_ANALOG_BIND_LIST_END - 1)
197-
{
198-
bind_idx++;
199-
bind_idx = input_config_bind_order[bind_idx];
200-
}
201-
else if (bind_idx == RARCH_ANALOG_BIND_LIST_END - 1)
202-
bind_idx = RARCH_UNMAPPED;
203-
else
204-
bind_idx = input_config_bind_order[0];
205-
206-
settings->uints.input_remap_ids[user_idx][btn_idx] = bind_idx;
207-
}
208-
209-
/* Empty is always last, so right jumps to first */
210-
if (string_is_empty(sys_info->input_desc_btn[mapped_port][remap_idx]))
211-
settings->uints.input_remap_ids[user_idx][btn_idx] = input_config_bind_order[0];
212-
}
213-
214-
return 0;
215-
}
216-
217224
static int action_right_scroll(unsigned type, const char *label,
218225
bool wraparound)
219226
{

menu/menu_displaylist.c

Lines changed: 25 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5751,7 +5751,7 @@ static int menu_displaylist_parse_input_retropad_bind_list(
57515751
return 0;
57525752

57535753
if (turbo_bind && menu_entries_append(info_list,
5754-
"---",
5754+
RARCH_NO_BIND,
57555755
"-1",
57565756
MENU_ENUM_LABEL_NO_ITEMS,
57575757
MENU_SETTING_DROPDOWN_ITEM_INPUT_RETROPAD_BIND,
@@ -6134,7 +6134,6 @@ static int menu_displaylist_parse_input_description_list(
61346134
unsigned count = 0;
61356135
rarch_system_info_t *sys_info = &runloop_state_get_ptr()->system;
61366136
size_t menu_index = 0;
6137-
bool current_input_mapped = false;
61386137
struct menu_state *menu_st = menu_state_get_ptr();
61396138

61406139
entry_lbl[0] = '\0';
@@ -6157,8 +6156,8 @@ static int menu_displaylist_parse_input_description_list(
61576156

61586157
/* Get current mapping for selected button */
61596158
current_remap_idx = settings->uints.input_remap_ids[user_idx][btn_idx];
6160-
6161-
if (current_remap_idx >= RARCH_CUSTOM_BIND_LIST_END)
6159+
if ( current_remap_idx >= RARCH_CUSTOM_BIND_LIST_END
6160+
|| string_is_empty(sys_info->input_desc_btn[mapped_port][current_remap_idx]))
61626161
current_remap_idx = RARCH_UNMAPPED;
61636162

61646163
/* An annoyance: Menu entries do not have
@@ -6170,6 +6169,27 @@ static int menu_displaylist_parse_input_description_list(
61706169
* and pass it as the entry label... */
61716170
snprintf(entry_lbl, sizeof(entry_lbl), "%u", info->type);
61726171

6172+
/* Add 'unmapped' entry */
6173+
if (menu_entries_append(info->list,
6174+
RARCH_NO_BIND,
6175+
entry_lbl,
6176+
MENU_ENUM_LABEL_INPUT_DESCRIPTION,
6177+
MENU_SETTING_DROPDOWN_ITEM_INPUT_DESCRIPTION,
6178+
0, RARCH_UNMAPPED, NULL))
6179+
{
6180+
/* Add checkmark if input is currently unmapped */
6181+
if (current_remap_idx == RARCH_UNMAPPED)
6182+
{
6183+
menu_file_list_cbs_t *cbs = (menu_file_list_cbs_t*)info->list->list[menu_index].actiondata;
6184+
if (cbs)
6185+
cbs->checked = true;
6186+
menu_st->selection_ptr = menu_index;
6187+
}
6188+
6189+
count++;
6190+
menu_index++;
6191+
}
6192+
61736193
/* Loop over core input definitions */
61746194
for (j = 0; j < RARCH_CUSTOM_BIND_LIST_END; j++)
61756195
{
@@ -6219,7 +6239,6 @@ static int menu_displaylist_parse_input_description_list(
62196239
if (cbs)
62206240
cbs->checked = true;
62216241
menu_st->selection_ptr = menu_index;
6222-
current_input_mapped = true;
62236242
}
62246243

62256244
count++;
@@ -6228,27 +6247,6 @@ static int menu_displaylist_parse_input_description_list(
62286247
}
62296248
}
62306249

6231-
/* Add 'unmapped' entry at end of list */
6232-
if (menu_entries_append(info->list,
6233-
"---",
6234-
entry_lbl,
6235-
MENU_ENUM_LABEL_INPUT_DESCRIPTION,
6236-
MENU_SETTING_DROPDOWN_ITEM_INPUT_DESCRIPTION,
6237-
0, RARCH_UNMAPPED, NULL))
6238-
{
6239-
/* Add checkmark if input is currently unmapped */
6240-
if (!current_input_mapped)
6241-
{
6242-
menu_file_list_cbs_t *cbs = (menu_file_list_cbs_t*)info->list->list[menu_index].actiondata;
6243-
if (cbs)
6244-
cbs->checked = true;
6245-
menu_st->selection_ptr = menu_index;
6246-
}
6247-
6248-
count++;
6249-
menu_index++;
6250-
}
6251-
62526250
return count;
62536251
}
62546252

@@ -6337,12 +6335,7 @@ static int menu_displaylist_parse_input_description_kbd_list(
63376335
continue;
63386336

63396337
if (key_id == RETROK_FIRST)
6340-
{
6341-
input_description[0] = '-';
6342-
input_description[1] = '-';
6343-
input_description[2] = '-';
6344-
input_description[3] = '\0';
6345-
}
6338+
strlcpy(input_description, RARCH_NO_BIND, sizeof(input_description));
63466339
else
63476340
{
63486341
/* TODO/FIXME: Localize 'Keyboard' */

menu/menu_setting.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6866,7 +6866,7 @@ static size_t setting_get_string_representation_retropad_bind(
68666866
int retro_id = *setting->value.target.integer;
68676867

68686868
if (retro_id < 0)
6869-
return strlcpy(s, "---", len);
6869+
return strlcpy(s, RARCH_NO_BIND, len);
68706870
else
68716871
{
68726872
const struct retro_keybind *keyptr =

0 commit comments

Comments
 (0)