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
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
keys

View File

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

View File

@ -627,6 +627,9 @@ uint8 C64::poll_joystick(int port)
if (wpad->exp.type == WPAD_EXP_CLASSIC)
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_DOWN] = held & WPAD_BUTTON_DOWN;
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) |
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++)
{
static bool is_pressed[2][N_WIIMOTE_BINDINGS];
int kc = ThePrefs.JoystickKeyBinding[i];
int kc = active_binded_keys[i];
if ( kc >= 0)
{