Skip to content

Commit a92202c

Browse files
sonninnosLibretroAdmin
authored andcommitted
Binds+remaps clearing rewrite
1 parent 7524366 commit a92202c

10 files changed

Lines changed: 53 additions & 44 deletions

configuration.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6262,7 +6262,7 @@ bool input_remapping_load_file(void *data, const char *path)
62626262
config_file_t *conf = (config_file_t*)data;
62636263
settings_t *settings = config_st;
62646264
runloop_state_t *runloop_st = runloop_state_get_ptr();
6265-
char key_strings[RARCH_FIRST_CUSTOM_BIND + 8][8] =
6265+
char key_strings[RARCH_ANALOG_BIND_LIST_END][8] =
62666266
{
62676267
"b", "y", "select", "start",
62686268
"up", "down", "left", "right",
@@ -6299,7 +6299,7 @@ bool input_remapping_load_file(void *data, const char *path)
62996299
_len = strlcpy(s3, prefix, sizeof(s3));
63006300
strlcpy(s3 + _len, "_stk", sizeof(s3) - _len);
63016301

6302-
for (j = 0; j < RARCH_FIRST_CUSTOM_BIND + 8; j++)
6302+
for (j = 0; j < RARCH_ANALOG_BIND_LIST_END; j++)
63036303
{
63046304
const char *key_string = key_strings[j];
63056305

@@ -6406,7 +6406,7 @@ bool input_remapping_save_file(const char *path)
64066406
bool ret;
64076407
unsigned i, j;
64086408
char remap_file_dir[DIR_MAX_LENGTH];
6409-
char key_strings[RARCH_FIRST_CUSTOM_BIND + 8][8] =
6409+
char key_strings[RARCH_ANALOG_BIND_LIST_END][8] =
64106410
{
64116411
"b", "y", "select", "start",
64126412
"up", "down", "left", "right",
@@ -6521,7 +6521,7 @@ bool input_remapping_save_file(const char *path)
65216521
settings->uints.input_keymapper_ids[i][j]);
65226522
}
65236523

6524-
for (j = RARCH_FIRST_CUSTOM_BIND; j < (RARCH_FIRST_CUSTOM_BIND + 8); j++)
6524+
for (j = RARCH_FIRST_CUSTOM_BIND; j < RARCH_ANALOG_BIND_LIST_END; j++)
65256525
{
65266526
char _ident[128];
65276527
const char *key_string = key_strings[j];

input/input_driver.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7076,7 +7076,7 @@ void input_remapping_set_defaults(bool clear_cache)
70767076
}
70777077

70787078
/* Analog stick remaps */
7079-
for (j = RARCH_FIRST_CUSTOM_BIND; j < (RARCH_FIRST_CUSTOM_BIND + 8); j++)
7079+
for (j = RARCH_FIRST_CUSTOM_BIND; j < RARCH_ANALOG_BIND_LIST_END; j++)
70807080
configuration_set_uint(settings,
70817081
settings->uints.input_remap_ids[i][j], j);
70827082

menu/cbs/menu_cbs_get_value.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -778,8 +778,8 @@ static size_t menu_action_setting_disp_set_label_input_desc(
778778
{
779779
unsigned remap_idx;
780780
settings_t *settings = config_get_ptr();
781-
unsigned user_idx = (type - MENU_SETTINGS_INPUT_DESC_BEGIN) / (RARCH_FIRST_CUSTOM_BIND + 8);
782-
unsigned btn_idx = (type - MENU_SETTINGS_INPUT_DESC_BEGIN) - (RARCH_FIRST_CUSTOM_BIND + 8) * user_idx;
781+
unsigned user_idx = (type - MENU_SETTINGS_INPUT_DESC_BEGIN) / RARCH_ANALOG_BIND_LIST_END;
782+
unsigned btn_idx = (type - MENU_SETTINGS_INPUT_DESC_BEGIN) - RARCH_ANALOG_BIND_LIST_END * user_idx;
783783

784784
if (!settings)
785785
return 0;

menu/cbs/menu_cbs_left.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,8 @@ static int action_left_input_desc(unsigned type, const char *label,
144144
if (settings && sys_info)
145145
{
146146
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;
147+
unsigned user_idx = (type - MENU_SETTINGS_INPUT_DESC_BEGIN) / RARCH_ANALOG_BIND_LIST_END;
148+
unsigned btn_idx = (type - MENU_SETTINGS_INPUT_DESC_BEGIN) - RARCH_ANALOG_BIND_LIST_END * user_idx;
149149
unsigned mapped_port = settings->uints.input_remap_ports[user_idx];
150150
unsigned remap_idx = settings->uints.input_remap_ids[user_idx][btn_idx];
151151

menu/cbs/menu_cbs_ok.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7806,10 +7806,8 @@ static int action_ok_push_dropdown_item_input_description(const char *path,
78067806
return -1;
78077807

78087808
/* Determine user/button indices */
7809-
user_idx = (entry_type - MENU_SETTINGS_INPUT_DESC_BEGIN)
7810-
/ (RARCH_FIRST_CUSTOM_BIND + 8);
7811-
btn_idx = (entry_type - MENU_SETTINGS_INPUT_DESC_BEGIN)
7812-
- (RARCH_FIRST_CUSTOM_BIND + 8) * user_idx;
7809+
user_idx = (entry_type - MENU_SETTINGS_INPUT_DESC_BEGIN) / RARCH_ANALOG_BIND_LIST_END;
7810+
btn_idx = (entry_type - MENU_SETTINGS_INPUT_DESC_BEGIN) - RARCH_ANALOG_BIND_LIST_END * user_idx;
78137811

78147812
if ((user_idx >= MAX_USERS) || (btn_idx >= RARCH_CUSTOM_BIND_LIST_END))
78157813
return -1;
@@ -7836,10 +7834,8 @@ static int action_ok_push_dropdown_item_input_description_kbd(
78367834
return -1;
78377835

78387836
/* Determine user/button indices */
7839-
user_idx = (entry_type - MENU_SETTINGS_INPUT_DESC_KBD_BEGIN)
7840-
/ RARCH_ANALOG_BIND_LIST_END;
7841-
btn_idx = (entry_type - MENU_SETTINGS_INPUT_DESC_KBD_BEGIN)
7842-
- RARCH_ANALOG_BIND_LIST_END * user_idx;
7837+
user_idx = (entry_type - MENU_SETTINGS_INPUT_DESC_KBD_BEGIN) / RARCH_ANALOG_BIND_LIST_END;
7838+
btn_idx = (entry_type - MENU_SETTINGS_INPUT_DESC_KBD_BEGIN) - RARCH_ANALOG_BIND_LIST_END * user_idx;
78437839

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

menu/cbs/menu_cbs_right.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,8 @@ static int action_right_input_desc(unsigned type, const char *label,
137137
if (settings && sys_info)
138138
{
139139
unsigned bind_idx;
140-
unsigned user_idx = (type - MENU_SETTINGS_INPUT_DESC_BEGIN) / (RARCH_FIRST_CUSTOM_BIND + 8);
141-
unsigned btn_idx = (type - MENU_SETTINGS_INPUT_DESC_BEGIN) - (RARCH_FIRST_CUSTOM_BIND + 8) * user_idx;
140+
unsigned user_idx = (type - MENU_SETTINGS_INPUT_DESC_BEGIN) / RARCH_ANALOG_BIND_LIST_END;
141+
unsigned btn_idx = (type - MENU_SETTINGS_INPUT_DESC_BEGIN) - RARCH_ANALOG_BIND_LIST_END * user_idx;
142142
unsigned mapped_port = settings->uints.input_remap_ports[user_idx];
143143
unsigned remap_idx = settings->uints.input_remap_ids[user_idx][btn_idx];
144144

menu/cbs/menu_cbs_scan.c

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ static int action_scan_input_desc(const char *path,
163163
{
164164
const char *menu_label = NULL;
165165
unsigned key = 0;
166-
unsigned inp_desc_user = 0;
166+
unsigned user_idx = 0;
167167
struct retro_keybind *target = NULL;
168168

169169
menu_entries_get_last_stack(NULL, &menu_label, NULL, NULL, NULL);
@@ -172,39 +172,52 @@ static int action_scan_input_desc(const char *path,
172172
msg_hash_to_str(MENU_ENUM_LABEL_DEFERRED_REMAPPINGS_PORT_LIST)))
173173
{
174174
settings_t *settings = config_get_ptr();
175-
inp_desc_user = atoi(label);
176-
/* Skip 'Device Type', 'Analog to Digital Type' and 'Mapped Port' */
177-
key = (unsigned)(idx - 3);
178-
/* Select the reorderer bind */
179-
key =
180-
(key < RARCH_ANALOG_BIND_LIST_END) ? input_config_bind_order[key] : key;
175+
int type_begin = (type >= MENU_SETTINGS_INPUT_DESC_KBD_BEGIN)
176+
? MENU_SETTINGS_INPUT_DESC_KBD_BEGIN : MENU_SETTINGS_INPUT_DESC_BEGIN;
177+
178+
user_idx = (type - type_begin) / RARCH_ANALOG_BIND_LIST_END;
179+
key = (type - type_begin) - RARCH_ANALOG_BIND_LIST_END * user_idx;
181180

182-
if (type >= MENU_SETTINGS_INPUT_DESC_BEGIN
181+
if ( type >= MENU_SETTINGS_INPUT_DESC_BEGIN
183182
&& type <= MENU_SETTINGS_INPUT_DESC_END)
184-
settings->uints.input_remap_ids[inp_desc_user][key] = RARCH_UNMAPPED;
183+
settings->uints.input_remap_ids[user_idx][key] = RARCH_UNMAPPED;
185184
else if (type >= MENU_SETTINGS_INPUT_DESC_KBD_BEGIN
186185
&& type <= MENU_SETTINGS_INPUT_DESC_KBD_END)
187-
settings->uints.input_keymapper_ids[inp_desc_user][key] = RETROK_UNKNOWN;
186+
settings->uints.input_keymapper_ids[user_idx][key] = RETROK_UNKNOWN;
188187

189188
return 0;
190189
}
191190
else if (string_is_equal(menu_label,
192191
msg_hash_to_str(MENU_ENUM_LABEL_DEFERRED_USER_BINDS_LIST)))
193192
{
194-
unsigned char player_no_str = atoi(&label[1]);
193+
size_t first_bind = 0;
194+
char port_str = atoi(&label[1]);
195+
menu_entry_t entry;
196+
197+
user_idx = (unsigned)(port_str - 1);
198+
199+
/* Skip non-bind menu elements */
200+
MENU_ENTRY_INITIALIZE(entry);
201+
202+
while (first_bind < idx)
203+
{
204+
menu_entry_get(&entry, 0, first_bind, NULL, false);
205+
206+
if (entry.setting_type == ST_BIND)
207+
break;
208+
209+
first_bind++;
210+
}
211+
212+
key = (unsigned)(idx - first_bind);
195213

196-
inp_desc_user = (unsigned)(player_no_str - 1);
197-
/* This hardcoded value may cause issues if any entries are added on
198-
top of the input binds */
199-
key = (unsigned)(idx - 8);
200214
/* Select the reorderer bind */
201-
key =
202-
(key < RARCH_ANALOG_BIND_LIST_END) ? input_config_bind_order[key] : key;
215+
key = (key < RARCH_ANALOG_BIND_LIST_END) ? input_config_bind_order[key] : key;
203216
}
204217
else
205218
key = input_config_translate_str_to_bind_id(label);
206219

207-
target = &input_config_binds[inp_desc_user][key];
220+
target = &input_config_binds[user_idx][key];
208221

209222
if (target)
210223
{
@@ -335,7 +348,7 @@ static int menu_cbs_init_bind_scan_compare_type(menu_file_list_cbs_t *cbs,
335348
break;
336349
}
337350

338-
if (type >= MENU_SETTINGS_INPUT_DESC_BEGIN
351+
if ( type >= MENU_SETTINGS_INPUT_DESC_BEGIN
339352
&& type <= MENU_SETTINGS_INPUT_DESC_END)
340353
{
341354
BIND_ACTION_SCAN(cbs, action_scan_input_desc);

menu/cbs/menu_cbs_start.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,8 @@ static int action_start_input_desc(
226226

227227
if (settings && sys_info)
228228
{
229-
unsigned user_idx = (type - MENU_SETTINGS_INPUT_DESC_BEGIN) / (RARCH_FIRST_CUSTOM_BIND + 8);
230-
unsigned btn_idx = (type - MENU_SETTINGS_INPUT_DESC_BEGIN) - (RARCH_FIRST_CUSTOM_BIND + 8) * user_idx;
229+
unsigned user_idx = (type - MENU_SETTINGS_INPUT_DESC_BEGIN) / RARCH_ANALOG_BIND_LIST_END;
230+
unsigned btn_idx = (type - MENU_SETTINGS_INPUT_DESC_BEGIN) - RARCH_ANALOG_BIND_LIST_END * user_idx;
231231
unsigned mapped_port = settings->uints.input_remap_ports[user_idx];
232232

233233
if ( (user_idx >= MAX_USERS)

menu/menu_displaylist.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6235,8 +6235,8 @@ static int menu_displaylist_parse_input_description_list(
62356235
return 0;
62366236

62376237
/* Determine user/button indices */
6238-
user_idx = (info->type - MENU_SETTINGS_INPUT_DESC_BEGIN) / (RARCH_FIRST_CUSTOM_BIND + 8);
6239-
btn_idx = (info->type - MENU_SETTINGS_INPUT_DESC_BEGIN) - (RARCH_FIRST_CUSTOM_BIND + 8) * user_idx;
6238+
user_idx = (info->type - MENU_SETTINGS_INPUT_DESC_BEGIN) / RARCH_ANALOG_BIND_LIST_END;
6239+
btn_idx = (info->type - MENU_SETTINGS_INPUT_DESC_BEGIN) - RARCH_ANALOG_BIND_LIST_END * user_idx;
62406240

62416241
if ( (user_idx >= MAX_USERS)
62426242
|| (btn_idx >= RARCH_CUSTOM_BIND_LIST_END))
@@ -12852,7 +12852,7 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type,
1285212852
if (menu_entries_append(list, descriptor, name,
1285312853
MSG_UNKNOWN,
1285412854
MENU_SETTINGS_INPUT_DESC_BEGIN +
12855-
(port * (RARCH_FIRST_CUSTOM_BIND + 8)) + retro_id, 0, 0, NULL))
12855+
(port * RARCH_ANALOG_BIND_LIST_END) + retro_id, 0, 0, NULL))
1285612856
count++;
1285712857
}
1285812858
else if (device == RETRO_DEVICE_KEYBOARD)

menu/menu_driver.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ enum menu_settings_type
252252
MENU_SETTINGS_INPUT_BEGIN,
253253
MENU_SETTINGS_INPUT_END = MENU_SETTINGS_INPUT_BEGIN + RARCH_CUSTOM_BIND_LIST_END + 7,
254254
MENU_SETTINGS_INPUT_DESC_BEGIN,
255-
MENU_SETTINGS_INPUT_DESC_END = MENU_SETTINGS_INPUT_DESC_BEGIN + ((RARCH_FIRST_CUSTOM_BIND + 8) * MAX_USERS),
255+
MENU_SETTINGS_INPUT_DESC_END = MENU_SETTINGS_INPUT_DESC_BEGIN + (RARCH_ANALOG_BIND_LIST_END * MAX_USERS),
256256
MENU_SETTINGS_INPUT_DESC_KBD_BEGIN,
257257
MENU_SETTINGS_INPUT_DESC_KBD_END = MENU_SETTINGS_INPUT_DESC_KBD_BEGIN + (RARCH_MAX_KEYS * MAX_USERS),
258258
MENU_SETTINGS_REMAPPING_PORT_BEGIN,

0 commit comments

Comments
 (0)