Add key selection for go to menu and switching between mouse/joystick

This commit is contained in:
Chips 2016-06-19 10:13:28 +00:00
parent c6b19aab20
commit d67a720e34
8 changed files with 143 additions and 32 deletions

View file

@ -61,6 +61,11 @@ static gcn::Label *lblLeft;
static gcn::UaeDropDown* cboLeft;
static gcn::Label *lblRight;
static gcn::UaeDropDown* cboRight;
static gcn::Label *lblKeyForMenu;
static gcn::UaeDropDown* KeyForMenu;
static gcn::Label *lblKeyForSwitching;
static gcn::UaeDropDown* KeyForSwitching;
class StringListModel : public gcn::ListModel
@ -109,6 +114,12 @@ const char *dPADValues[] = { "Joystick", "Keyboard", "Custom" };
#endif
StringListModel dPADList(dPADValues, 3);
static const int ControlKey_SDLKeyValues[] = { SDLK_F11 , SDLK_F12, SDLK_LALT , SDLK_LCTRL };
const char *ControlKeyValues[] = { "F11", "F12", "LeftAlt", "LeftCtrl" };
StringListModel ControlKeyList(ControlKeyValues, 4);
const char *mappingValues[] = {
"Joystick Right", "Joystick Left", "Joystick Down", "Joystick Up",
"Joystick fire but.2", "Joystick fire but.1", "Mouse right button", "Mouse left button",
@ -207,6 +218,13 @@ class InputActionListener : public gcn::ActionListener
else if (actionEvent.getSource() == cboRight)
changed_prefs.pandora_custom_right = cboRight->getSelected() - 8;
else if (actionEvent.getSource() == KeyForMenu)
changed_prefs.key_for_menu = ControlKey_SDLKeyValues[KeyForMenu->getSelected()] ;
else if (actionEvent.getSource() == KeyForSwitching)
changed_prefs.key_for_input_switching = ControlKey_SDLKeyValues[KeyForSwitching->getSelected()] ;
}
};
static InputActionListener* inputActionListener;
@ -371,6 +389,26 @@ void InitPanelInput(const struct _ConfigCategory& category)
cboRight->setId("cboRight");
cboRight->addActionListener(inputActionListener);
lblKeyForMenu = new gcn::Label("Key for Menu:");
lblKeyForMenu->setSize(100, LABEL_HEIGHT);
lblKeyForMenu->setAlignment(gcn::Graphics::RIGHT);
KeyForMenu = new gcn::UaeDropDown(&ControlKeyList);
KeyForMenu->setSize(150, DROPDOWN_HEIGHT);
KeyForMenu->setBaseColor(gui_baseCol);
KeyForMenu->setId("CKeyMenu");
KeyForMenu->addActionListener(inputActionListener);
lblKeyForSwitching = new gcn::Label("Mouse/joy sw:");
lblKeyForSwitching->setSize(100, LABEL_HEIGHT);
lblKeyForSwitching->setAlignment(gcn::Graphics::RIGHT);
KeyForSwitching = new gcn::UaeDropDown(&ControlKeyList);
KeyForSwitching->setSize(150, DROPDOWN_HEIGHT);
KeyForSwitching->setBaseColor(gui_baseCol);
KeyForSwitching->setId("CKeySwitching");
KeyForSwitching->addActionListener(inputActionListener);
int posY = DISTANCE_BORDER;
category.panel->add(lblCtrlConfig, DISTANCE_BORDER, posY);
category.panel->add(cboCtrlConfig, DISTANCE_BORDER + lblCtrlConfig->getWidth() + 8, posY);
@ -421,8 +459,16 @@ void InitPanelInput(const struct _ConfigCategory& category)
category.panel->add(cboLeft, DISTANCE_BORDER + lblLeft->getWidth() + 8, posY);
category.panel->add(lblRight, 300, posY);
category.panel->add(cboRight, 300 + lblRight->getWidth() + 8, posY);
posY += cboLeft->getHeight() + 4;
posY += cboLeft->getHeight() + DISTANCE_NEXT_Y;
category.panel->add(lblKeyForMenu, DISTANCE_BORDER, posY);
category.panel->add(KeyForMenu, DISTANCE_BORDER + lblLeft->getWidth() + 8, posY);
posY += KeyForMenu->getHeight() + 4;
category.panel->add(lblKeyForSwitching, DISTANCE_BORDER, posY);
category.panel->add(KeyForSwitching, DISTANCE_BORDER + lblLeft->getWidth() + 8, posY);
posY += KeyForSwitching->getHeight() + DISTANCE_NEXT_Y;
RefreshPanelInput();
}
@ -467,6 +513,12 @@ void ExitPanelInput(void)
delete lblRight;
delete cboRight;
delete lblKeyForMenu;
delete KeyForMenu;
delete lblKeyForSwitching;
delete KeyForSwitching;
delete inputActionListener;
}
@ -516,4 +568,21 @@ void RefreshPanelInput(void)
cboDown->setSelected(changed_prefs.pandora_custom_down + 8);
cboLeft->setSelected(changed_prefs.pandora_custom_left + 8);
cboRight->setSelected(changed_prefs.pandora_custom_right + 8);
for(i=0; i<4; ++i)
{
if(changed_prefs.key_for_menu == ControlKey_SDLKeyValues[i])
{
KeyForMenu->setSelected(i);
break;
}
}
for(i=0; i<4; ++i)
{
if(changed_prefs.key_for_input_switching == ControlKey_SDLKeyValues[i])
{
KeyForSwitching->setSelected(i);
break;
}
}
}

View file

@ -188,7 +188,26 @@ namespace sdl
{
gcn::FocusHandler* focusHdl;
gcn::Widget* activeWidget;
if (event.key.keysym.sym == currprefs.key_for_menu)
{
if(emulating && widgets::cmdStart->isEnabled())
{
//------------------------------------------------
// Continue emulation
//------------------------------------------------
gui_running = false;
}
else
{
//------------------------------------------------
// First start of emulator -> reset Amiga
//------------------------------------------------
uae_reset(0);
gui_running = false;
}
} else
switch(event.key.keysym.sym)
{
case SDLK_q:
@ -209,27 +228,9 @@ namespace sdl
//-------------------------------------------------
// Reset Amiga
//-------------------------------------------------
uae_reset(1);
gui_running = false;
break;
case SDLK_F12:
if(emulating && widgets::cmdStart->isEnabled())
{
//------------------------------------------------
// Continue emulation
//------------------------------------------------
gui_running = false;
}
else
{
//------------------------------------------------
// First start of emulator -> reset Amiga
//------------------------------------------------
uae_reset(0);
gui_running = false;
}
break;
uae_reset(1);
gui_running = false;
break;
case SDLK_PAGEDOWN:
case SDLK_HOME:

View file

@ -41,9 +41,10 @@ static int delay=0;
#endif
static int nr_joysticks;
int nr_joysticks;
const char* JoystickName[4];
static SDL_Joystick *uae4all_joy0, *uae4all_joy1;
static SDL_Joystick *uae4all_joy0 = 0, *uae4all_joy1 = 0 , *uae4all_joy2 = 0, *uae4all_joy3 = 0;
void read_joystick(int nr, unsigned int *dir, int *button)
{
@ -293,17 +294,32 @@ void init_joystick(void)
if (nr_joysticks > 0)
{
uae4all_joy0 = SDL_JoystickOpen (0);
printf("Joystick0 : %s\n",SDL_JoystickName(0));
JoystickName[0] = SDL_JoystickName(0);
printf("Joystick0 : %s\n",JoystickName[0]);
printf(" Buttons: %i Axis: %i Hats: %i\n",SDL_JoystickNumButtons(uae4all_joy0),SDL_JoystickNumAxes(uae4all_joy0),SDL_JoystickNumHats(uae4all_joy0));
}
if (nr_joysticks > 1)
{
uae4all_joy1 = SDL_JoystickOpen (1);
printf("Joystick1 : %s\n",SDL_JoystickName(1));
JoystickName[1] = SDL_JoystickName(1);
printf("Joystick1 : %s\n",JoystickName[1]);
printf(" Buttons: %i Axis: %i Hats: %i\n",SDL_JoystickNumButtons(uae4all_joy1),SDL_JoystickNumAxes(uae4all_joy1),SDL_JoystickNumHats(uae4all_joy1));
}
else
uae4all_joy1 = NULL;
if (nr_joysticks > 2)
{
uae4all_joy2 = SDL_JoystickOpen (2);
JoystickName[2] = SDL_JoystickName(2);
printf("Joystick2 : %s\n",JoystickName[2]);
printf(" Buttons: %i Axis: %i Hats: %i\n",SDL_JoystickNumButtons(uae4all_joy2),SDL_JoystickNumAxes(uae4all_joy2),SDL_JoystickNumHats(uae4all_joy2));
}
if (nr_joysticks > 3)
{
uae4all_joy3 = SDL_JoystickOpen (3);
JoystickName[3] = SDL_JoystickName(3);
printf("Joystick3 : %s\n",JoystickName[3]);
printf(" Buttons: %i Axis: %i Hats: %i\n",SDL_JoystickNumButtons(uae4all_joy3),SDL_JoystickNumAxes(uae4all_joy3),SDL_JoystickNumHats(uae4all_joy3));
}
}
void close_joystick(void)
@ -312,4 +328,8 @@ void close_joystick(void)
SDL_JoystickClose (uae4all_joy0);
if (nr_joysticks > 1)
SDL_JoystickClose (uae4all_joy1);
if (nr_joysticks > 2)
SDL_JoystickClose (uae4all_joy2);
if (nr_joysticks > 3)
SDL_JoystickClose (uae4all_joy3);
}

View file

@ -912,7 +912,7 @@ void handle_events (void)
}
}
#endif
if (rEvent.key.keysym.sym==SDLK_F11)
if (rEvent.key.keysym.sym==currprefs.key_for_input_switching)
{
// state moves thus:
// joystick mode
@ -1012,7 +1012,7 @@ void handle_events (void)
buttonstate[2] = 0;
}
if (rEvent.key.keysym.sym==SDLK_F11)
if (rEvent.key.keysym.sym==currprefs.key_for_input_switching)
{
show_inputmode = 0;
}

View file

@ -608,7 +608,7 @@ void gui_handle_events (void)
dpadRight = 1; else dpadRight = 0;
#endif
if(keystate[SDLK_F12])
if(keystate[currprefs.key_for_menu])
goMenu();
if(uae4all_keystate[AK_CTRL] && uae4all_keystate[AK_LAMI] && uae4all_keystate[AK_RAMI])
uae_reset(0);