Fix case when multiple buttons are bound to the same key

This commit is contained in:
simon.kagstrom 2009-02-21 09:01:33 +00:00
parent ed13ce7073
commit f02a2d7055
3 changed files with 31 additions and 5 deletions

View File

@ -6,6 +6,9 @@
TODO: Crash on + in "Other" menu TODO: Crash on + in "Other" menu
version 7: version 7:
* Fix bug when multiple buttons are bound to the same keys, we now
simply skip one of the bindings.
* Wiimote direction keys and "fire" can now be bound to keyboard * Wiimote direction keys and "fire" can now be bound to keyboard
keys keys

View File

@ -249,10 +249,11 @@ void C64::select_disc(Prefs *np)
char *C64::bind_one_key(Prefs *np, int which) char *C64::bind_one_key(Prefs *np, int which)
{ {
static const char *which_to_button_name[] = { "up", "down", "left", "right", static const char *which_to_button_name[N_WIIMOTE_BINDINGS] = {
"fire","A", "B", "+", "-", "1", "up", "down", "left", "right",
"classic up", "classic down", "classic left", "classic right", "classic fire", "2","A", "B", "+", "-", "1",
"classic X", "classic Y", "classic B", "classic L", "classic up", "classic down", "classic left", "classic right", "classic a",
"classic X", "classic Y", "classic b", "classic L",
"classic R", "classic ZR", "classic ZL" }; "classic R", "classic ZR", "classic ZL" };
static char strs[N_WIIMOTE_BINDINGS][255]; static char strs[N_WIIMOTE_BINDINGS][255];
char *out = strs[which]; char *out = strs[which];

View File

@ -627,6 +627,9 @@ uint8 C64::poll_joystick(int port)
if (wpad->exp.type == WPAD_EXP_CLASSIC) if (wpad->exp.type == WPAD_EXP_CLASSIC)
held_classic = wpad->exp.classic.btns_held; held_classic = wpad->exp.classic.btns_held;
if ( (held & WPAD_BUTTON_HOME) || (held_classic & CLASSIC_CTRL_BUTTON_HOME) )
TheC64->enter_menu();
extra_keys[WIIMOTE_UP] = held & WPAD_BUTTON_UP; extra_keys[WIIMOTE_UP] = held & WPAD_BUTTON_UP;
extra_keys[WIIMOTE_DOWN] = held & WPAD_BUTTON_DOWN; extra_keys[WIIMOTE_DOWN] = held & WPAD_BUTTON_DOWN;
extra_keys[WIIMOTE_LEFT] = held & WPAD_BUTTON_LEFT; extra_keys[WIIMOTE_LEFT] = held & WPAD_BUTTON_LEFT;
@ -657,10 +660,29 @@ uint8 C64::poll_joystick(int port)
extra_keys[WIIMOTE_MINUS] = (held_classic & CLASSIC_CTRL_BUTTON_PLUS) | extra_keys[WIIMOTE_MINUS] = (held_classic & CLASSIC_CTRL_BUTTON_PLUS) |
held & WPAD_BUTTON_MINUS; held & WPAD_BUTTON_MINUS;
/* Merge common keys */
int active_binded_keys[N_WIIMOTE_BINDINGS];
memcpy(active_binded_keys, ThePrefs.JoystickKeyBinding, sizeof(active_binded_keys));
for (int first = 0; first <= N_WIIMOTE_BINDINGS; first++)
{
if (!extra_keys[first])
continue;
for (int second = 0; second <= N_WIIMOTE_BINDINGS; second++)
{
if (first != second &&
active_binded_keys[first] ==
active_binded_keys[second]) {
/* Unbind this */
extra_keys[second] = 0;
active_binded_keys[second] = -1;
}
}
}
for (int i = 0; i < N_WIIMOTE_BINDINGS; i++) for (int i = 0; i < N_WIIMOTE_BINDINGS; i++)
{ {
static bool is_pressed[2][N_WIIMOTE_BINDINGS]; static bool is_pressed[2][N_WIIMOTE_BINDINGS];
int kc = ThePrefs.JoystickKeyBinding[i]; int kc = active_binded_keys[i];
if ( kc >= 0) if ( kc >= 0)
{ {