mirror of
https://github.com/libretro/scummvm.git
synced 2024-12-15 06:08:35 +00:00
PSP2: Add controller config, remove joystick event handling
This commit is contained in:
parent
1522fc8e2f
commit
dafadbc8c7
@ -36,242 +36,6 @@
|
||||
|
||||
#include "math.h"
|
||||
|
||||
#define JOY_DEADZONE 2000
|
||||
#define JOY_XAXIS 0
|
||||
#define JOY_YAXIS 1
|
||||
#define JOY_XAXISR 2
|
||||
#define JOY_YAXISR 3
|
||||
|
||||
enum {
|
||||
BTN_LEFT = 7,
|
||||
BTN_DOWN = 6,
|
||||
BTN_RIGHT = 9,
|
||||
BTN_UP = 8,
|
||||
|
||||
BTN_START = 11,
|
||||
BTN_SELECT = 10,
|
||||
|
||||
BTN_SQUARE = 3,
|
||||
BTN_CROSS = 2,
|
||||
BTN_CIRCLE = 1,
|
||||
BTN_TRIANGLE = 0,
|
||||
|
||||
BTN_R1 = 5,
|
||||
BTN_L1 = 4
|
||||
};
|
||||
|
||||
bool PSP2EventSource::handleJoyButtonDown(SDL_Event &ev, Common::Event &event) {
|
||||
|
||||
event.kbd.flags = 0;
|
||||
|
||||
switch (ev.jbutton.button) {
|
||||
// Dpad
|
||||
case BTN_LEFT: // Left (+R_trigger: Up+Left)
|
||||
if (!_km.modifier) {
|
||||
event.type = Common::EVENT_KEYDOWN;
|
||||
event.kbd.keycode = Common::KEYCODE_KP4;
|
||||
event.kbd.ascii = mapKey(SDLK_KP4, (SDLMod) ev.key.keysym.mod, 0);
|
||||
} else {
|
||||
event.type = Common::EVENT_KEYDOWN;
|
||||
event.kbd.keycode = Common::KEYCODE_KP7;
|
||||
event.kbd.ascii = mapKey(SDLK_KP7, (SDLMod) ev.key.keysym.mod, 0);
|
||||
}
|
||||
break;
|
||||
case BTN_RIGHT: // Right (+R_trigger: Down+Right)
|
||||
if (!_km.modifier) {
|
||||
event.type = Common::EVENT_KEYDOWN;
|
||||
event.kbd.keycode = Common::KEYCODE_KP6;
|
||||
event.kbd.ascii = mapKey(SDLK_KP6, (SDLMod) ev.key.keysym.mod, 0);
|
||||
} else {
|
||||
event.type = Common::EVENT_KEYDOWN;
|
||||
event.kbd.keycode = Common::KEYCODE_KP3;
|
||||
event.kbd.ascii = mapKey(SDLK_KP3, (SDLMod) ev.key.keysym.mod, 0);
|
||||
}
|
||||
break;
|
||||
case BTN_UP: // Up (+R_trigger: Up+Right)
|
||||
if (!_km.modifier) {
|
||||
event.type = Common::EVENT_KEYDOWN;
|
||||
event.kbd.keycode = Common::KEYCODE_KP8;
|
||||
event.kbd.ascii = mapKey(SDLK_KP8, (SDLMod) ev.key.keysym.mod, 0);
|
||||
} else {
|
||||
event.type = Common::EVENT_KEYDOWN;
|
||||
event.kbd.keycode = Common::KEYCODE_KP9;
|
||||
event.kbd.ascii = mapKey(SDLK_KP9, (SDLMod) ev.key.keysym.mod, 0);
|
||||
}
|
||||
break;
|
||||
case BTN_DOWN: // Down (+R_trigger: Down+Left)
|
||||
if (!_km.modifier) {
|
||||
event.type = Common::EVENT_KEYDOWN;
|
||||
event.kbd.keycode = Common::KEYCODE_KP2;
|
||||
event.kbd.ascii = mapKey(SDLK_KP2, (SDLMod) ev.key.keysym.mod, 0);
|
||||
} else {
|
||||
event.type = Common::EVENT_KEYDOWN;
|
||||
event.kbd.keycode = Common::KEYCODE_KP1;
|
||||
event.kbd.ascii = mapKey(SDLK_KP1, (SDLMod) ev.key.keysym.mod, 0);
|
||||
}
|
||||
break;
|
||||
// Buttons
|
||||
case BTN_CROSS: // Left mouse button
|
||||
event.type = Common::EVENT_LBUTTONDOWN;
|
||||
processMouseEvent(event, _km.x / MULTIPLIER, _km.y / MULTIPLIER);
|
||||
break;
|
||||
case BTN_CIRCLE: // Right mouse button
|
||||
event.type = Common::EVENT_RBUTTONDOWN;
|
||||
processMouseEvent(event, _km.x / MULTIPLIER, _km.y / MULTIPLIER);
|
||||
break;
|
||||
case BTN_TRIANGLE: // Escape (+R_trigger: Return)
|
||||
if (!_km.modifier) {
|
||||
event.type = Common::EVENT_KEYDOWN;
|
||||
event.kbd.keycode = Common::KEYCODE_ESCAPE;
|
||||
event.kbd.ascii = mapKey(SDLK_ESCAPE, (SDLMod) ev.key.keysym.mod, 0);
|
||||
} else {
|
||||
event.type = Common::EVENT_KEYDOWN;
|
||||
event.kbd.keycode = Common::KEYCODE_RETURN;
|
||||
event.kbd.ascii = mapKey(SDLK_RETURN, (SDLMod) ev.key.keysym.mod, 0);
|
||||
}
|
||||
break;
|
||||
case BTN_SQUARE: // Period (+R_trigger: Space)
|
||||
if (!_km.modifier) {
|
||||
event.type = Common::EVENT_KEYDOWN;
|
||||
event.kbd.keycode = Common::KEYCODE_PERIOD;
|
||||
event.kbd.ascii = mapKey(SDLK_PERIOD, (SDLMod) ev.key.keysym.mod, 0);
|
||||
} else {
|
||||
event.type = Common::EVENT_KEYDOWN;
|
||||
event.kbd.keycode = Common::KEYCODE_SPACE;
|
||||
event.kbd.ascii = mapKey(SDLK_SPACE, (SDLMod) ev.key.keysym.mod, 0);
|
||||
}
|
||||
break;
|
||||
case BTN_L1: // Game menu
|
||||
event.type = Common::EVENT_KEYDOWN;
|
||||
event.kbd.keycode = Common::KEYCODE_F5;
|
||||
event.kbd.ascii = mapKey(SDLK_F5, (SDLMod) ev.key.keysym.mod, 0);
|
||||
break;
|
||||
case BTN_R1: // Modifier + Shift
|
||||
_km.modifier=true; // slow mouse
|
||||
event.type = Common::EVENT_KEYDOWN;
|
||||
event.kbd.keycode = Common::KEYCODE_INVALID;
|
||||
event.kbd.ascii = 0;
|
||||
event.kbd.flags = Common::KBD_SHIFT;
|
||||
break;
|
||||
case BTN_START: // ScummVM in game menu
|
||||
event.type = Common::EVENT_MAINMENU;
|
||||
break;
|
||||
case BTN_SELECT: // Virtual keyboard (+R_trigger: Predictive Input Dialog)
|
||||
if (!_km.modifier) {
|
||||
#ifdef ENABLE_VKEYBD
|
||||
event.type = Common::EVENT_VIRTUAL_KEYBOARD;
|
||||
#endif
|
||||
} else {
|
||||
event.type = Common::EVENT_PREDICTIVE_DIALOG;
|
||||
}
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PSP2EventSource::handleJoyButtonUp(SDL_Event &ev, Common::Event &event) {
|
||||
|
||||
event.kbd.flags = 0;
|
||||
|
||||
switch (ev.jbutton.button) {
|
||||
// Dpad
|
||||
case BTN_LEFT: // Left (+R_trigger: Up+Left)
|
||||
if (!_km.modifier) {
|
||||
event.type = Common::EVENT_KEYUP;
|
||||
event.kbd.keycode = Common::KEYCODE_KP4;
|
||||
event.kbd.ascii = mapKey(SDLK_KP4, (SDLMod) ev.key.keysym.mod, 0);
|
||||
} else {
|
||||
event.type = Common::EVENT_KEYUP;
|
||||
event.kbd.keycode = Common::KEYCODE_KP7;
|
||||
event.kbd.ascii = mapKey(SDLK_KP7, (SDLMod) ev.key.keysym.mod, 0);
|
||||
}
|
||||
break;
|
||||
case BTN_RIGHT: // Right (+R_trigger: Down+Right)
|
||||
if (!_km.modifier) {
|
||||
event.type = Common::EVENT_KEYUP;
|
||||
event.kbd.keycode = Common::KEYCODE_KP6;
|
||||
event.kbd.ascii = mapKey(SDLK_KP6, (SDLMod) ev.key.keysym.mod, 0);
|
||||
} else {
|
||||
event.type = Common::EVENT_KEYUP;
|
||||
event.kbd.keycode = Common::KEYCODE_KP3;
|
||||
event.kbd.ascii = mapKey(SDLK_KP3, (SDLMod) ev.key.keysym.mod, 0);
|
||||
}
|
||||
break;
|
||||
case BTN_UP: // Up (+R_trigger: Up+Right)
|
||||
if (!_km.modifier) {
|
||||
event.type = Common::EVENT_KEYUP;
|
||||
event.kbd.keycode = Common::KEYCODE_KP8;
|
||||
event.kbd.ascii = mapKey(SDLK_KP8, (SDLMod) ev.key.keysym.mod, 0);
|
||||
} else {
|
||||
event.type = Common::EVENT_KEYUP;
|
||||
event.kbd.keycode = Common::KEYCODE_KP9;
|
||||
event.kbd.ascii = mapKey(SDLK_KP9, (SDLMod) ev.key.keysym.mod, 0);
|
||||
}
|
||||
break;
|
||||
case BTN_DOWN: // Down (+R_trigger: Down+Left)
|
||||
if (!_km.modifier) {
|
||||
event.type = Common::EVENT_KEYUP;
|
||||
event.kbd.keycode = Common::KEYCODE_KP2;
|
||||
event.kbd.ascii = mapKey(SDLK_KP2, (SDLMod) ev.key.keysym.mod, 0);
|
||||
} else {
|
||||
event.type = Common::EVENT_KEYUP;
|
||||
event.kbd.keycode = Common::KEYCODE_KP1;
|
||||
event.kbd.ascii = mapKey(SDLK_KP1, (SDLMod) ev.key.keysym.mod, 0);
|
||||
}
|
||||
break;
|
||||
// Buttons
|
||||
case BTN_CROSS: // Left mouse button
|
||||
event.type = Common::EVENT_LBUTTONUP;
|
||||
processMouseEvent(event, _km.x / MULTIPLIER, _km.y / MULTIPLIER);
|
||||
break;
|
||||
case BTN_CIRCLE: // Right mouse button
|
||||
event.type = Common::EVENT_RBUTTONUP;
|
||||
processMouseEvent(event, _km.x / MULTIPLIER, _km.y / MULTIPLIER);
|
||||
break;
|
||||
case BTN_TRIANGLE: // Escape (+R_trigger: Return)
|
||||
if (!_km.modifier) {
|
||||
event.type = Common::EVENT_KEYUP;
|
||||
event.kbd.keycode = Common::KEYCODE_ESCAPE;
|
||||
event.kbd.ascii = mapKey(SDLK_ESCAPE, (SDLMod) ev.key.keysym.mod, 0);
|
||||
} else {
|
||||
event.type = Common::EVENT_KEYUP;
|
||||
event.kbd.keycode = Common::KEYCODE_RETURN;
|
||||
event.kbd.ascii = mapKey(SDLK_RETURN, (SDLMod) ev.key.keysym.mod, 0);
|
||||
}
|
||||
break;
|
||||
case BTN_SQUARE: // Period (+R_trigger: Space)
|
||||
if (!_km.modifier) {
|
||||
event.type = Common::EVENT_KEYUP;
|
||||
event.kbd.keycode = Common::KEYCODE_PERIOD;
|
||||
event.kbd.ascii = mapKey(SDLK_PERIOD, (SDLMod) ev.key.keysym.mod, 0);
|
||||
} else {
|
||||
event.type = Common::EVENT_KEYUP;
|
||||
event.kbd.keycode = Common::KEYCODE_SPACE;
|
||||
event.kbd.ascii = mapKey(SDLK_SPACE, (SDLMod) ev.key.keysym.mod, 0);
|
||||
}
|
||||
break;
|
||||
case BTN_L1: // Game menu
|
||||
event.type = Common::EVENT_KEYUP;
|
||||
event.kbd.keycode = Common::KEYCODE_F5;
|
||||
event.kbd.ascii = mapKey(SDLK_F5, (SDLMod) ev.key.keysym.mod, 0);
|
||||
break;
|
||||
case BTN_R1: // Modifier + SHIFT Key
|
||||
_km.modifier = false; // slow mouse
|
||||
event.type = Common::EVENT_KEYUP;
|
||||
event.kbd.keycode = Common::KEYCODE_INVALID;
|
||||
event.kbd.ascii = 0;
|
||||
event.kbd.flags = 0;
|
||||
break;
|
||||
case BTN_START: // ScummVM in game menu
|
||||
// Handled in key down
|
||||
break;
|
||||
case BTN_SELECT: // Virtual keyboard (+R_trigger: Predictive Input Dialog)
|
||||
// Handled in key down
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void PSP2EventSource::preprocessEvents(SDL_Event *event) {
|
||||
|
||||
// prevent suspend (scummvm games contains a lot of cutscenes..)
|
||||
|
@ -30,8 +30,6 @@
|
||||
*/
|
||||
class PSP2EventSource : public SdlEventSource {
|
||||
protected:
|
||||
bool handleJoyButtonDown(SDL_Event &ev, Common::Event &event);
|
||||
bool handleJoyButtonUp(SDL_Event &ev, Common::Event &event);
|
||||
void preprocessEvents(SDL_Event *event);
|
||||
};
|
||||
|
||||
|
@ -102,6 +102,14 @@ void OSystem_PSP2::initBackend() {
|
||||
if (_savefileManager == 0)
|
||||
_savefileManager = new DefaultSaveFileManager("ux0:data/scummvm/saves");
|
||||
|
||||
// Controller mappings for Vita, various names have been used in various SDL versions
|
||||
SDL_GameControllerAddMapping("50535669746120436f6e74726f6c6c65,PSVita Controller,y:b0,b:b1,a:b2,x:b3,leftshoulder:b4,rightshoulder:b5,dpdown:b6,dpleft:b7,dpup:b8,dpright:b9,back:b10,start:b11,leftx:a0,lefty:a1,rightx:a2,righty:a3,");
|
||||
SDL_GameControllerAddMapping("50535669746120636f6e74726f6c6c65,PSVita controller,y:b0,b:b1,a:b2,x:b3,leftshoulder:b4,rightshoulder:b5,dpdown:b6,dpleft:b7,dpup:b8,dpright:b9,back:b10,start:b11,leftx:a0,lefty:a1,rightx:a2,righty:a3,");
|
||||
SDL_GameControllerAddMapping("50535669746120636f6e74726f6c6c65,PSVita controller 2,y:b0,b:b1,a:b2,x:b3,leftshoulder:b4,rightshoulder:b5,dpdown:b6,dpleft:b7,dpup:b8,dpright:b9,back:b10,start:b11,leftx:a0,lefty:a1,rightx:a2,righty:a3,");
|
||||
SDL_GameControllerAddMapping("50535669746120636f6e74726f6c6c65,PSVita controller 3,y:b0,b:b1,a:b2,x:b3,leftshoulder:b4,rightshoulder:b5,dpdown:b6,dpleft:b7,dpup:b8,dpright:b9,back:b10,start:b11,leftx:a0,lefty:a1,rightx:a2,righty:a3,");
|
||||
SDL_GameControllerAddMapping("50535669746120636f6e74726f6c6c65,PSVita controller 4,y:b0,b:b1,a:b2,x:b3,leftshoulder:b4,rightshoulder:b5,dpdown:b6,dpleft:b7,dpup:b8,dpright:b9,back:b10,start:b11,leftx:a0,lefty:a1,rightx:a2,righty:a3,");
|
||||
SDL_GameControllerAddMapping("505356697461206275696c74696e206a,PSVita builtin joypad,y:b0,b:b1,a:b2,x:b3,leftshoulder:b4,rightshoulder:b5,dpdown:b6,dpleft:b7,dpup:b8,dpright:b9,back:b10,start:b11,leftx:a0,lefty:a1,rightx:a2,righty:a3,");
|
||||
|
||||
// Event source
|
||||
if (_eventSource == 0)
|
||||
_eventSource = new PSP2EventSource();
|
||||
|
Loading…
Reference in New Issue
Block a user