(FCEUGX) Add B/1 button press to cancel button remapping prompt (#480)

* Add B/1 button press to cancel button remapping prompt

* Typo fix
This commit is contained in:
InfiniteBlueGX 2022-10-27 10:57:02 -05:00 committed by GitHub
parent ac24682c24
commit 145490bff9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -90,6 +90,7 @@ static char progressTitle[101];
static char progressMsg[201]; static char progressMsg[201];
static int progressDone = 0; static int progressDone = 0;
static int progressTotal = 0; static int progressTotal = 0;
static bool buttonMappingCancelled = false;
u8 * bg_music; u8 * bg_music;
u32 bg_music_size; u32 bg_music_size;
@ -2865,7 +2866,8 @@ ButtonMappingWindow()
u32 pressed = 0; u32 pressed = 0;
while(pressed == 0) buttonMappingCancelled = false;
while(pressed == 0 && !buttonMappingCancelled)
{ {
usleep(THREAD_SLEEP); usleep(THREAD_SLEEP);
@ -2881,10 +2883,22 @@ ButtonMappingWindow()
if(userInput[0].wpad->btns_d == WPAD_BUTTON_HOME) if(userInput[0].wpad->btns_d == WPAD_BUTTON_HOME)
pressed = WPAD_BUTTON_HOME; pressed = WPAD_BUTTON_HOME;
if(userInput[0].wpad->btns_d & WPAD_CLASSIC_BUTTON_B ||
userInput[0].wpad->btns_d & WPAD_BUTTON_B ||
userInput[0].wpad->btns_d & WPAD_BUTTON_1 ||
userInput[0].wiidrcdata.btns_d & WIIDRC_BUTTON_B)
buttonMappingCancelled = true;
} }
else if(mapMenuCtrl == CTRLR_WIIDRC) else if(mapMenuCtrl == CTRLR_WIIDRC)
{ {
pressed = userInput[0].wiidrcdata.btns_d; pressed = userInput[0].wiidrcdata.btns_d;
if(userInput[0].wpad->btns_d & WPAD_CLASSIC_BUTTON_B ||
userInput[0].wpad->btns_d & WPAD_BUTTON_B ||
userInput[0].wpad->btns_d & WPAD_BUTTON_1 ||
userInput[0].pad.btns_d & PAD_BUTTON_B)
buttonMappingCancelled = true;
} }
else else
{ {
@ -2898,24 +2912,47 @@ ButtonMappingWindow()
case CTRLR_WIIMOTE: case CTRLR_WIIMOTE:
if(pressed > 0x1000) if(pressed > 0x1000)
pressed = 0; // not a valid input pressed = 0; // not a valid input
if(userInput[0].pad.btns_d & PAD_BUTTON_B ||
userInput[0].wiidrcdata.btns_d & WIIDRC_BUTTON_B ||
userInput[0].wpad->btns_d & WPAD_CLASSIC_BUTTON_B)
buttonMappingCancelled = true;
break; break;
case CTRLR_CLASSIC: case CTRLR_CLASSIC:
if(userInput[0].wpad->exp.type != WPAD_EXP_CLASSIC && userInput[0].wpad->exp.classic.type < 2) if(userInput[0].wpad->exp.type != WPAD_EXP_CLASSIC && userInput[0].wpad->exp.classic.type < 2)
pressed = 0; // not a valid input pressed = 0; // not a valid input
else if(userInput[0].wpad->exp.type == WPAD_EXP_NUNCHUK)
pressed = 0; // not a valid input (Nunchuk Z/C is assigned as Classic Controller Up/Left for some reason)
else if(pressed <= 0x1000) else if(pressed <= 0x1000)
pressed = 0; pressed = 0;
if(userInput[0].pad.btns_d & PAD_BUTTON_B ||
userInput[0].wiidrcdata.btns_d & WIIDRC_BUTTON_B ||
userInput[0].wpad->btns_d & WPAD_BUTTON_B ||
userInput[0].wpad->btns_d & WPAD_BUTTON_1)
buttonMappingCancelled = true;
break; break;
case CTRLR_WUPC: case CTRLR_WUPC:
if(userInput[0].wpad->exp.type != WPAD_EXP_CLASSIC && userInput[0].wpad->exp.classic.type == 2) if(userInput[0].wpad->exp.type != WPAD_EXP_CLASSIC && userInput[0].wpad->exp.classic.type == 2)
pressed = 0; // not a valid input pressed = 0; // not a valid input
else if(pressed <= 0x1000) else if(pressed <= 0x1000)
pressed = 0; pressed = 0;
if(userInput[0].pad.btns_d & PAD_BUTTON_B ||
userInput[0].wiidrcdata.btns_d & WIIDRC_BUTTON_B ||
userInput[0].wpad->btns_d & WPAD_BUTTON_B ||
userInput[0].wpad->btns_d & WPAD_BUTTON_1)
buttonMappingCancelled = true;
break; break;
case CTRLR_NUNCHUK: case CTRLR_NUNCHUK:
if(userInput[0].wpad->exp.type != WPAD_EXP_NUNCHUK) if(userInput[0].wpad->exp.type != WPAD_EXP_NUNCHUK)
pressed = 0; // not a valid input pressed = 0; // not a valid input
if((userInput[0].wpad->exp.type != WPAD_EXP_NUNCHUK && userInput[0].wpad->btns_d & WPAD_BUTTON_B) ||
(userInput[0].wpad->exp.type != WPAD_EXP_NUNCHUK && userInput[0].wpad->btns_d & WPAD_BUTTON_1) ||
userInput[0].pad.btns_d & PAD_BUTTON_B ||
userInput[0].wiidrcdata.btns_d & WIIDRC_BUTTON_B ||
userInput[0].wpad->btns_d & WPAD_CLASSIC_BUTTON_B)
buttonMappingCancelled = true;
break; break;
} }
} }
@ -3068,8 +3105,13 @@ static int MenuSettingsMappingsMap()
if(ret >= 0) if(ret >= 0)
{ {
// get a button selection from user int buttonPressed = ButtonMappingWindow();
btnmap[mapMenuCtrlNES][mapMenuCtrl][ret] = ButtonMappingWindow();
if (!buttonMappingCancelled)
{
// get a button selection from user if the remap wasn't cancelled
btnmap[mapMenuCtrlNES][mapMenuCtrl][ret] = buttonPressed;
}
} }
if(ret >= 0 || firstRun) if(ret >= 0 || firstRun)