(BlackBery10) Button Map clean up, and add support for up to 4 players.

This commit is contained in:
CatalystG 2013-07-07 14:49:50 -04:00
parent 314947844d
commit 271db20cf8
6 changed files with 162 additions and 165 deletions

View File

@ -28,6 +28,11 @@ Page
value: 3
}
]
onSelectedValueChanged:
{
ButtonMap.refreshButtonMap(selectedValue)
}
}
actions: [
@ -36,7 +41,7 @@ Page
ActionBar.placement: ActionBarPlacement.OnBar
imageSource: "asset:///images/search.png"
onTriggered: {
RetroArch.discoverController();
RetroArch.discoverController(players.selectedValue);
}
}
]
@ -52,13 +57,18 @@ Page
{
objectName: "dropdown_devices"
title: "Device"
onSelectedValueChanged:
{
ButtonMap.mapDevice(selectedValue, players.selectedValue);
}
}
ListView
{
id: buttonMapList
objectName: "buttonMapList"
listItemComponents: [
ListItemComponent
{
@ -109,14 +119,13 @@ Page
}
}
]
//TODO: Map specific devices instead of 0.
onTriggered:
{
var sym, data;
data = dataModel.data(indexPath);
sym = RetroArch.mapButton(0, players.selectedValue, data["index"]);
data["button"] = RetroArch.buttonToString(0, sym);
sym = ButtonMap.mapButton(0, players.selectedValue, data["index"]);
data["button"] = ButtonMap.buttonToString(players.selectedValue, sym);
dataModel.replace(indexPath, data);
}

View File

@ -65,7 +65,7 @@ ButtonMap::ButtonMap(screen_context_t screen_ctx, QString groupId, int coid)
buttonDataModel = new ArrayDataModel();
refreshButtonMap();
refreshButtonMap(0);
}
ButtonMap::~ButtonMap()
@ -78,100 +78,75 @@ QString ButtonMap::getLabel(int button)
return QString((uint)platform_keys[button].joykey);
}
//pass in RARCH button enum for button, map to g_setting
int ButtonMap::mapNextButtonPressed()
{
bps_event_t *event = NULL;
int sym;
int ButtonMap::mapNextButtonPressed()
{
bps_event_t *event = NULL;
int sym;
//use in frontend run loop, get key pressed back, and map
int z = 10;
if (screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_ZORDER, &z) != 0)
{
return -1;
}
//use in frontend run loop, get key pressed back, and map
int z = 10;
if (screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_ZORDER, &z) != 0)
{
return -1;
}
screen_post_window(screen_win, screen_buf, 1, screen_resolution, 0);
screen_post_window(screen_win, screen_buf, 1, screen_resolution, 0);
while(1){
if (BPS_SUCCESS != bps_get_event(&event, -1))
{
fprintf(stderr, "bps_get_event failed\n");
break;
}
while(1)
{
if (BPS_SUCCESS != bps_get_event(&event, -1))
{
fprintf(stderr, "bps_get_event failed\n");
break;
}
if (event)
{
int domain = bps_event_get_domain(event);
if (event)
{
int domain = bps_event_get_domain(event);
if (domain == screen_get_domain())
{
screen_event_t screen_event = screen_event_get_event(event);
int screen_val;
screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_TYPE, &screen_val);
if (domain == screen_get_domain())
{
screen_event_t screen_event = screen_event_get_event(event);
int screen_val;
screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_TYPE, &screen_val);
//TODO: Should we only let the buttons through that we are trying to map?
if(screen_val == SCREEN_EVENT_MTOUCH_TOUCH)
{
//This is touch screen event
sym = -1;
break;
}
else if(screen_val == SCREEN_EVENT_KEYBOARD)
{
screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_KEY_SYM, &sym);
sym &= 0xFF;
break;
}
else if( (screen_val == SCREEN_EVENT_GAMEPAD) || (screen_val == SCREEN_EVENT_JOYSTICK) )
{
screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_BUTTONS, &sym);
break;
}
}
}
}
//TODO: Should we only let the buttons through that we are trying to map?
if(screen_val == SCREEN_EVENT_MTOUCH_TOUCH)
{
//This is touch screen event
sym = NO_BTN;
break;
}
else if(screen_val == SCREEN_EVENT_KEYBOARD)
{
screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_KEY_SYM, &sym);
sym &= 0xFF;
break;
}
else if( (screen_val == SCREEN_EVENT_GAMEPAD) || (screen_val == SCREEN_EVENT_JOYSTICK) )
{
screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_BUTTONS, &sym);
break;
}
}
}
}
z = -10;
if (screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_ZORDER, &z) != 0) {
return -1;
}
z = -10;
if (screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_ZORDER, &z) != 0)
{
return -1;
}
screen_post_window(screen_win, screen_buf, 1, screen_resolution, 0);
screen_post_window(screen_win, screen_buf, 1, screen_resolution, 0);
return (g_settings.input.binds[player][button].joykey = sym);
}
return (g_settings.input.binds[player][button].joykey = sym);
}
int ButtonMap::getButtonMapping(int player, int button)
{
return g_settings.input.binds[player][button].joykey;
}
QString ButtonMap::buttonToString(int button)
{
for(int i=0;i<20;++i)
{
if(platform_keys[i].joykey == (uint)button)
{
return QString(platform_keys[i].desc);
}
}
return (button!=NO_BTN) ? QString(button) : QString("Not Mapped");
}
int ButtonMap::requestButtonMapping(screen_device_t device, int player, int button)
{
//Send message to run thread to start mapping, wait for reply.
recv_msg msg;
msg.code = RETROARCH_BUTTON_MAP;
this->device = device;
this->player = player;
this->button = button;
return MsgSend(coid, (void*)&msg, sizeof(msg), (void*)NULL, 0);
}
int ButtonMap::getButtonMapping(int player, int button)
{
return g_settings.input.binds[player][button].joykey;
}
void ButtonMap::mapDevice(int index, int player)
{
@ -179,16 +154,16 @@ void ButtonMap::mapDevice(int index, int player)
input_qnx.set_keybinds((void*)&devices[index], devices[index].device, player, 0,
(1ULL << KEYBINDS_ACTION_SET_DEFAULT_BINDS));
refreshButtonMap();
refreshButtonMap(player);
}
void ButtonMap::refreshButtonMap()
{
void ButtonMap::refreshButtonMap(int player)
{
QVariantMap map;
buttonDataModel->clear();
for(int i=0; i<16; ++i)
for (int i=0; i<16; ++i)
{
QString desc = QString(input_config_bind_map[i].desc);
int index = desc.indexOf("(");
@ -198,15 +173,47 @@ void ButtonMap::mapDevice(int index, int player)
}
map.insert("label",QVariant(desc));
map.insert("button", buttonToString(g_settings.input.binds[0][i].joykey));
map.insert("button", buttonToString(player, g_settings.input.binds[player][i].joykey));
map.insert("type", QVariant("item"));
map.insert("index", QVariant(i));
buttonDataModel->append(map);
}
map.insert("label",QVariant("RetroArch Menu"));
map.insert("button", buttonToString(g_settings.input.binds[0][RARCH_MENU_TOGGLE].joykey));
map.insert("button", buttonToString(player, g_settings.input.binds[player][RARCH_MENU_TOGGLE].joykey));
map.insert("type", QVariant("item"));
map.insert("index", QVariant(RARCH_MENU_TOGGLE));
buttonDataModel->append(map);
}
}
//Button map
int ButtonMap::mapButton(int player, int button)
{
recv_msg msg;
msg.code = RETROARCH_BUTTON_MAP;
this->player = player;
this->button = button;
return MsgSend(coid, (void*)&msg, sizeof(msg), (void*)NULL, 0);
}
QString ButtonMap::buttonToString(int player, int button)
{
if(g_settings.input.device[player] == DEVICE_KEYPAD || g_settings.input.device[player] == DEVICE_KEYBOARD)
{
return QString(button);
}
else
{
for(int i=0;i<20;++i)
{
if(platform_keys[i].joykey == (uint)button)
{
return QString(platform_keys[i].desc);
}
}
return (button!=NO_BTN) ? QString(button) : QString("Not Mapped");
}
}

View File

@ -19,8 +19,9 @@ typedef struct {
using namespace bb::cascades;
class ButtonMap
class ButtonMap: public QObject
{
Q_OBJECT
public:
ButtonMap(screen_context_t screen_cxt, QString groupId, int coid);
@ -33,10 +34,12 @@ public:
int getButtonMapping(int player, int button);
//Call from frontend
int requestButtonMapping(screen_device_t device, int player, int button);
void refreshButtonMap();
void mapDevice(int index, int player);
QString buttonToString(int button);
Q_INVOKABLE int mapButton(int player, int button);
Q_INVOKABLE QString buttonToString(int player, int button);
Q_INVOKABLE void refreshButtonMap(int player);
Q_INVOKABLE void mapDevice(int index, int player);
ArrayDataModel *buttonDataModel;

View File

@ -95,9 +95,10 @@ RetroArch::RetroArch()
screen_create_context(&screen_ctx, 0);
input_qnx.init();
buttonMap = new ButtonMap(screen_ctx, (const char*)Application::instance()->mainWindow()->groupId().toAscii().constData(), coid);
qml->setContextProperty("ButtonMap", buttonMap);
deviceSelection = mAppPane->findChild<DropDown*>("dropdown_devices");
connect(deviceSelection, SIGNAL(selectedValueChanged(QVariant)), this, SLOT(onDeviceSelected(QVariant)));
//connect(deviceSelection, SIGNAL(selectedValueChanged(QVariant)), this, SLOT(onDeviceSelected(QVariant)));
findDevices();
//Setup the datamodel for button mapping.
@ -257,13 +258,6 @@ void RetroArch::onCoreSelected(QVariant value)
qDebug() << "Supported Extensions: " << romExtensions;
}
void RetroArch::onDeviceSelected(QVariant value)
{
//Change the binds for current player to device[value]
//TODO: Don't hardcode player 0
buttonMap->mapDevice(value.toInt(), 0);
}
/*
* Functions
*/
@ -327,6 +321,16 @@ void RetroArch::findDevices()
}
}
extern "C" void discoverControllers();
void RetroArch::discoverController(int player)
{
//TODO: Check device, gamepad/keyboard and return accordingly.
discoverControllers();
findDevices();
buttonMap->refreshButtonMap(player);
return;
}
void RetroArch::initRASettings()
{
strlcpy(g_settings.libretro,(char *)core.toAscii().constData(), sizeof(g_settings.libretro));
@ -339,28 +343,3 @@ void RetroArch::initRASettings()
if(hwInfo->isPhysicalKeyboardDevice() || port_device[0])
*g_settings.input.overlay = '\0';
}
int RetroArch::mapButton(void* deviceVp, int player, int button)
{
screen_device_t device = (screen_device_t)deviceVp;
return buttonMap->requestButtonMapping(device, player, button);
}
QString RetroArch::buttonToString(void* deviceVp, int button)
{
//TODO: Check deviceVp, gamepad/keyboard and return accordingly.
if(g_settings.input.device[0] == DEVICE_KEYPAD || g_settings.input.device[0] == DEVICE_KEYBOARD)
return QString(button);
else
return buttonMap->buttonToString(button);
}
extern "C" void discoverControllers();
void RetroArch::discoverController()
{
//TODO: Check device, gamepad/keyboard and return accordingly.
discoverControllers();
findDevices();
buttonMap->refreshButtonMap();
return;
}

View File

@ -35,9 +35,7 @@ public:
Q_INVOKABLE void startEmulator();
Q_INVOKABLE void findDevices();
Q_INVOKABLE int mapButton(void* device, int player, int button);
Q_INVOKABLE QString buttonToString(void* deviceVp, int button);
Q_INVOKABLE void discoverController();
Q_INVOKABLE void discoverController(int player);
void populateCores(core_info_list_t * info);
signals:
@ -49,7 +47,6 @@ public slots:
void aboutToQuit();
void onRotationCompleted();
void onCoreSelected(QVariant);
void onDeviceSelected(QVariant);
private:
/**

View File

@ -131,6 +131,8 @@ void discoverControllers()
{
// Get an array of all available devices.
int deviceCount;
screen_event_t *event;
screen_get_context_property_iv(screen_ctx, SCREEN_PROPERTY_DEVICE_COUNT, &deviceCount);
screen_device_t* devices_found = (screen_device_t*)calloc(deviceCount, sizeof(screen_device_t));
screen_get_context_property_pv(screen_ctx, SCREEN_PROPERTY_DEVICES, (void**)devices_found);
@ -730,10 +732,10 @@ static void qnx_input_set_keybinds(void *data, unsigned device, unsigned port,
g_settings.input.binds[port][RETRO_DEVICE_ID_JOYPAD_X].def_joykey = KEYCODE_K & 0xFF;
g_settings.input.binds[port][RETRO_DEVICE_ID_JOYPAD_L].def_joykey = KEYCODE_U & 0xFF;
g_settings.input.binds[port][RETRO_DEVICE_ID_JOYPAD_R].def_joykey = KEYCODE_I & 0xFF;
g_settings.input.binds[port][RETRO_DEVICE_ID_JOYPAD_L2].def_joykey = 0;
g_settings.input.binds[port][RETRO_DEVICE_ID_JOYPAD_R2].def_joykey = 0;
g_settings.input.binds[port][RETRO_DEVICE_ID_JOYPAD_L3].def_joykey = 0;
g_settings.input.binds[port][RETRO_DEVICE_ID_JOYPAD_R3].def_joykey = 0;
g_settings.input.binds[port][RETRO_DEVICE_ID_JOYPAD_L2].def_joykey = NO_BTN;
g_settings.input.binds[port][RETRO_DEVICE_ID_JOYPAD_R2].def_joykey = NO_BTN;
g_settings.input.binds[port][RETRO_DEVICE_ID_JOYPAD_L3].def_joykey = NO_BTN;
g_settings.input.binds[port][RETRO_DEVICE_ID_JOYPAD_R3].def_joykey = NO_BTN;
g_settings.input.binds[port][RARCH_MENU_TOGGLE].def_joykey = KEYCODE_P & 0xFF;
g_settings.input.dpad_emulation[port] = ANALOG_DPAD_NONE;
controller->port = port;
@ -756,10 +758,10 @@ static void qnx_input_set_keybinds(void *data, unsigned device, unsigned port,
g_settings.input.binds[port][RETRO_DEVICE_ID_JOYPAD_X].def_joykey = KEYCODE_S & 0xFF;
g_settings.input.binds[port][RETRO_DEVICE_ID_JOYPAD_L].def_joykey = KEYCODE_Q & 0xFF;
g_settings.input.binds[port][RETRO_DEVICE_ID_JOYPAD_R].def_joykey = KEYCODE_W & 0xFF;
g_settings.input.binds[port][RETRO_DEVICE_ID_JOYPAD_L2].def_joykey = 0;
g_settings.input.binds[port][RETRO_DEVICE_ID_JOYPAD_R2].def_joykey = 0;
g_settings.input.binds[port][RETRO_DEVICE_ID_JOYPAD_L3].def_joykey = 0;
g_settings.input.binds[port][RETRO_DEVICE_ID_JOYPAD_R3].def_joykey = 0;
g_settings.input.binds[port][RETRO_DEVICE_ID_JOYPAD_L2].def_joykey = NO_BTN;
g_settings.input.binds[port][RETRO_DEVICE_ID_JOYPAD_R2].def_joykey = NO_BTN;
g_settings.input.binds[port][RETRO_DEVICE_ID_JOYPAD_L3].def_joykey = NO_BTN;
g_settings.input.binds[port][RETRO_DEVICE_ID_JOYPAD_R3].def_joykey = NO_BTN;
g_settings.input.binds[port][RARCH_MENU_TOGGLE].def_joykey = KEYCODE_TILDE;
g_settings.input.dpad_emulation[port] = ANALOG_DPAD_NONE;
controller->port = port;
@ -811,7 +813,7 @@ static void qnx_input_set_keybinds(void *data, unsigned device, unsigned port,
g_settings.input.binds[port][RETRO_DEVICE_ID_JOYPAD_R2].def_joykey = SCREEN_R2_GAME_BUTTON;
g_settings.input.binds[port][RETRO_DEVICE_ID_JOYPAD_L3].def_joykey = SCREEN_L3_GAME_BUTTON;
g_settings.input.binds[port][RETRO_DEVICE_ID_JOYPAD_R3].def_joykey = SCREEN_R3_GAME_BUTTON;
g_settings.input.binds[port][RARCH_MENU_TOGGLE].def_joykey = 0; //TODO: Find a good mappnig
g_settings.input.binds[port][RARCH_MENU_TOGGLE].def_joykey = NO_BTN; //TODO: Find a good mappnig
g_settings.input.dpad_emulation[port] = ANALOG_DPAD_NONE;
controller->port = port;
port_device[port] = controller;
@ -821,23 +823,23 @@ static void qnx_input_set_keybinds(void *data, unsigned device, unsigned port,
strlcpy(g_settings.input.device_names[port], "None",
sizeof(g_settings.input.device_names[port]));
g_settings.input.device[port] = device;
g_settings.input.binds[port][RETRO_DEVICE_ID_JOYPAD_B].def_joykey = 0;
g_settings.input.binds[port][RETRO_DEVICE_ID_JOYPAD_Y].def_joykey = 0;
g_settings.input.binds[port][RETRO_DEVICE_ID_JOYPAD_SELECT].def_joykey = 0;
g_settings.input.binds[port][RETRO_DEVICE_ID_JOYPAD_START].def_joykey = 0;
g_settings.input.binds[port][RETRO_DEVICE_ID_JOYPAD_UP].def_joykey = 0;
g_settings.input.binds[port][RETRO_DEVICE_ID_JOYPAD_DOWN].def_joykey = 0;
g_settings.input.binds[port][RETRO_DEVICE_ID_JOYPAD_LEFT].def_joykey = 0;
g_settings.input.binds[port][RETRO_DEVICE_ID_JOYPAD_RIGHT].def_joykey = 0;
g_settings.input.binds[port][RETRO_DEVICE_ID_JOYPAD_A].def_joykey = 0;
g_settings.input.binds[port][RETRO_DEVICE_ID_JOYPAD_X].def_joykey = 0;
g_settings.input.binds[port][RETRO_DEVICE_ID_JOYPAD_L].def_joykey = 0;
g_settings.input.binds[port][RETRO_DEVICE_ID_JOYPAD_R].def_joykey = 0;
g_settings.input.binds[port][RETRO_DEVICE_ID_JOYPAD_L2].def_joykey = 0;
g_settings.input.binds[port][RETRO_DEVICE_ID_JOYPAD_R2].def_joykey = 0;
g_settings.input.binds[port][RETRO_DEVICE_ID_JOYPAD_L3].def_joykey = 0;
g_settings.input.binds[port][RETRO_DEVICE_ID_JOYPAD_R3].def_joykey = 0;
g_settings.input.binds[port][RARCH_MENU_TOGGLE].def_joykey = 0;
g_settings.input.binds[port][RETRO_DEVICE_ID_JOYPAD_B].def_joykey = NO_BTN;
g_settings.input.binds[port][RETRO_DEVICE_ID_JOYPAD_Y].def_joykey = NO_BTN;
g_settings.input.binds[port][RETRO_DEVICE_ID_JOYPAD_SELECT].def_joykey = NO_BTN;
g_settings.input.binds[port][RETRO_DEVICE_ID_JOYPAD_START].def_joykey = NO_BTN;
g_settings.input.binds[port][RETRO_DEVICE_ID_JOYPAD_UP].def_joykey = NO_BTN;
g_settings.input.binds[port][RETRO_DEVICE_ID_JOYPAD_DOWN].def_joykey = NO_BTN;
g_settings.input.binds[port][RETRO_DEVICE_ID_JOYPAD_LEFT].def_joykey = NO_BTN;
g_settings.input.binds[port][RETRO_DEVICE_ID_JOYPAD_RIGHT].def_joykey = NO_BTN;
g_settings.input.binds[port][RETRO_DEVICE_ID_JOYPAD_A].def_joykey = NO_BTN;
g_settings.input.binds[port][RETRO_DEVICE_ID_JOYPAD_X].def_joykey = NO_BTN;
g_settings.input.binds[port][RETRO_DEVICE_ID_JOYPAD_L].def_joykey = NO_BTN;
g_settings.input.binds[port][RETRO_DEVICE_ID_JOYPAD_R].def_joykey = NO_BTN;
g_settings.input.binds[port][RETRO_DEVICE_ID_JOYPAD_L2].def_joykey = NO_BTN;
g_settings.input.binds[port][RETRO_DEVICE_ID_JOYPAD_R2].def_joykey = NO_BTN;
g_settings.input.binds[port][RETRO_DEVICE_ID_JOYPAD_L3].def_joykey = NO_BTN;
g_settings.input.binds[port][RETRO_DEVICE_ID_JOYPAD_R3].def_joykey = NO_BTN;
g_settings.input.binds[port][RARCH_MENU_TOGGLE].def_joykey = NO_BTN;
controller->port = -1;
port_device[port] = 0;
break;