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

@ -29,6 +29,8 @@
#include "disk.h" #include "disk.h"
#include "sd-pandora/sound.h" #include "sd-pandora/sound.h"
#include "SDL_keysym.h"
static int config_newfilesystem; static int config_newfilesystem;
static struct strlist *temp_lines; static struct strlist *temp_lines;
static struct zfile *default_file; static struct zfile *default_file;
@ -385,6 +387,9 @@ void cfgfile_save_options (struct zfile *f, struct uae_prefs *p, int type)
cfgfile_write_bool (f, _T("synchronize_clock"), p->tod_hack); cfgfile_write_bool (f, _T("synchronize_clock"), p->tod_hack);
cfgfile_dwrite_str (f, _T("absolute_mouse"), abspointers[p->input_tablet]); cfgfile_dwrite_str (f, _T("absolute_mouse"), abspointers[p->input_tablet]);
cfgfile_write (f, _T("key_for_menu"), _T("%d"), p->key_for_menu);
cfgfile_write (f, _T("key_for_input_switching"), _T("%d"), p->key_for_input_switching);
cfgfile_write (f, _T("gfx_framerate"), _T("%d"), p->gfx_framerate); cfgfile_write (f, _T("gfx_framerate"), _T("%d"), p->gfx_framerate);
cfgfile_write (f, _T("gfx_width"), _T("%d"), p->gfx_size.width); cfgfile_write (f, _T("gfx_width"), _T("%d"), p->gfx_size.width);
cfgfile_write (f, _T("gfx_height"), _T("%d"), p->gfx_size.height); cfgfile_write (f, _T("gfx_height"), _T("%d"), p->gfx_size.height);
@ -730,6 +735,13 @@ static int cfgfile_parse_host (struct uae_prefs *p, TCHAR *option, TCHAR *value)
|| cfgfile_strval (option, value, _T("gfx_lores"), &p->gfx_resolution, lorestype2, 0) || cfgfile_strval (option, value, _T("gfx_lores"), &p->gfx_resolution, lorestype2, 0)
|| cfgfile_strval (option, value, _T("absolute_mouse"), &p->input_tablet, abspointers, 0)) || cfgfile_strval (option, value, _T("absolute_mouse"), &p->input_tablet, abspointers, 0))
return 1; return 1;
if (cfgfile_intval (option, value, "key_for_menu", &p->key_for_menu, 1)
|| cfgfile_intval (option, value, "key_for_input_switching", &p->key_for_input_switching, 1));
return 1;
if(cfgfile_yesno (option, value, _T("show_leds"), &vb)) { if(cfgfile_yesno (option, value, _T("show_leds"), &vb)) {
p->leds_on_screen = vb; p->leds_on_screen = vb;
@ -1818,6 +1830,9 @@ void default_prefs (struct uae_prefs *p, int type)
p->input_tablet = TABLET_OFF; p->input_tablet = TABLET_OFF;
p->key_for_menu = SDLK_F12;
p->key_for_input_switching = SDLK_F11;
target_default_options (p, type); target_default_options (p, type);
inputdevice_default_prefs (p); inputdevice_default_prefs (p);

View file

@ -159,6 +159,9 @@ struct uae_prefs {
int pandora_autofireButton1; int pandora_autofireButton1;
int pandora_jump; int pandora_jump;
int key_for_menu;
int key_for_input_switching;
/* input */ /* input */
int input_joymouse_multiplier; int input_joymouse_multiplier;

View file

@ -428,6 +428,9 @@ void inputdevice_copyconfig (struct uae_prefs *src, struct uae_prefs *dst)
dst->pandora_autofireButton1 = src->pandora_autofireButton1; dst->pandora_autofireButton1 = src->pandora_autofireButton1;
dst->pandora_jump = src->pandora_jump; dst->pandora_jump = src->pandora_jump;
dst->key_for_menu = src->key_for_menu;
dst->key_for_input_switching = src->key_for_input_switching;
inputdevice_updateconfig (dst); inputdevice_updateconfig (dst);
} }

View file

@ -61,6 +61,11 @@ static gcn::Label *lblLeft;
static gcn::UaeDropDown* cboLeft; static gcn::UaeDropDown* cboLeft;
static gcn::Label *lblRight; static gcn::Label *lblRight;
static gcn::UaeDropDown* cboRight; 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 class StringListModel : public gcn::ListModel
@ -109,6 +114,12 @@ const char *dPADValues[] = { "Joystick", "Keyboard", "Custom" };
#endif #endif
StringListModel dPADList(dPADValues, 3); 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[] = { const char *mappingValues[] = {
"Joystick Right", "Joystick Left", "Joystick Down", "Joystick Up", "Joystick Right", "Joystick Left", "Joystick Down", "Joystick Up",
"Joystick fire but.2", "Joystick fire but.1", "Mouse right button", "Mouse left button", "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) else if (actionEvent.getSource() == cboRight)
changed_prefs.pandora_custom_right = cboRight->getSelected() - 8; 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; static InputActionListener* inputActionListener;
@ -371,6 +389,26 @@ void InitPanelInput(const struct _ConfigCategory& category)
cboRight->setId("cboRight"); cboRight->setId("cboRight");
cboRight->addActionListener(inputActionListener); 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; int posY = DISTANCE_BORDER;
category.panel->add(lblCtrlConfig, DISTANCE_BORDER, posY); category.panel->add(lblCtrlConfig, DISTANCE_BORDER, posY);
category.panel->add(cboCtrlConfig, DISTANCE_BORDER + lblCtrlConfig->getWidth() + 8, 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(cboLeft, DISTANCE_BORDER + lblLeft->getWidth() + 8, posY);
category.panel->add(lblRight, 300, posY); category.panel->add(lblRight, 300, posY);
category.panel->add(cboRight, 300 + lblRight->getWidth() + 8, 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(); RefreshPanelInput();
} }
@ -467,6 +513,12 @@ void ExitPanelInput(void)
delete lblRight; delete lblRight;
delete cboRight; delete cboRight;
delete lblKeyForMenu;
delete KeyForMenu;
delete lblKeyForSwitching;
delete KeyForSwitching;
delete inputActionListener; delete inputActionListener;
} }
@ -516,4 +568,21 @@ void RefreshPanelInput(void)
cboDown->setSelected(changed_prefs.pandora_custom_down + 8); cboDown->setSelected(changed_prefs.pandora_custom_down + 8);
cboLeft->setSelected(changed_prefs.pandora_custom_left + 8); cboLeft->setSelected(changed_prefs.pandora_custom_left + 8);
cboRight->setSelected(changed_prefs.pandora_custom_right + 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::FocusHandler* focusHdl;
gcn::Widget* activeWidget; 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) switch(event.key.keysym.sym)
{ {
case SDLK_q: case SDLK_q:
@ -209,27 +228,9 @@ namespace sdl
//------------------------------------------------- //-------------------------------------------------
// Reset Amiga // Reset Amiga
//------------------------------------------------- //-------------------------------------------------
uae_reset(1); uae_reset(1);
gui_running = false; gui_running = false;
break; 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;
case SDLK_PAGEDOWN: case SDLK_PAGEDOWN:
case SDLK_HOME: case SDLK_HOME:

View file

@ -41,9 +41,10 @@ static int delay=0;
#endif #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) void read_joystick(int nr, unsigned int *dir, int *button)
{ {
@ -293,17 +294,32 @@ void init_joystick(void)
if (nr_joysticks > 0) if (nr_joysticks > 0)
{ {
uae4all_joy0 = SDL_JoystickOpen (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)); printf(" Buttons: %i Axis: %i Hats: %i\n",SDL_JoystickNumButtons(uae4all_joy0),SDL_JoystickNumAxes(uae4all_joy0),SDL_JoystickNumHats(uae4all_joy0));
} }
if (nr_joysticks > 1) if (nr_joysticks > 1)
{ {
uae4all_joy1 = SDL_JoystickOpen (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)); printf(" Buttons: %i Axis: %i Hats: %i\n",SDL_JoystickNumButtons(uae4all_joy1),SDL_JoystickNumAxes(uae4all_joy1),SDL_JoystickNumHats(uae4all_joy1));
} }
else if (nr_joysticks > 2)
uae4all_joy1 = NULL; {
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) void close_joystick(void)
@ -312,4 +328,8 @@ void close_joystick(void)
SDL_JoystickClose (uae4all_joy0); SDL_JoystickClose (uae4all_joy0);
if (nr_joysticks > 1) if (nr_joysticks > 1)
SDL_JoystickClose (uae4all_joy1); 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 #endif
if (rEvent.key.keysym.sym==SDLK_F11) if (rEvent.key.keysym.sym==currprefs.key_for_input_switching)
{ {
// state moves thus: // state moves thus:
// joystick mode // joystick mode
@ -1012,7 +1012,7 @@ void handle_events (void)
buttonstate[2] = 0; buttonstate[2] = 0;
} }
if (rEvent.key.keysym.sym==SDLK_F11) if (rEvent.key.keysym.sym==currprefs.key_for_input_switching)
{ {
show_inputmode = 0; show_inputmode = 0;
} }

View file

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