Add window to config key bindings

Save the bindings in the conf file in a map.
This commit is contained in:
Xele02 2013-02-02 00:36:35 +01:00
parent f7205f6543
commit d5c2560212
15 changed files with 367 additions and 120 deletions

View File

@ -148,7 +148,7 @@ void IniFile::Section::Set(const char* key, const std::vector<std::string>& newV
std::vector<std::string>::const_iterator it;
for (it = newValues.begin(); it != newValues.end(); ++it)
{
temp = (*it) + ",";
temp += (*it) + ",";
}
// remove last ,
if (temp.length())

View File

@ -20,6 +20,7 @@
#include <string>
#include <vector>
#include <map>
#include "StringUtil.h"
@ -68,12 +69,48 @@ public:
}
void Set(const char* key, const std::vector<std::string>& newValues);
template<typename U, typename V>
void Set(const char* key, const std::map<U,V>& newValues)
{
std::vector<std::string> temp;
for(typename std::map<U,V>::const_iterator it = newValues.begin(); it != newValues.end(); it++)
{
temp.push_back(ValueToString<U>(it->first)+"_"+ValueToString<V>(it->second));
}
Set(key,temp);
}
bool Get(const char* key, int* value, int defaultValue = 0);
bool Get(const char* key, u32* value, u32 defaultValue = 0);
bool Get(const char* key, bool* value, bool defaultValue = false);
bool Get(const char* key, float* value, float defaultValue = false);
bool Get(const char* key, double* value, double defaultValue = false);
bool Get(const char* key, std::vector<std::string>& values);
template<typename U, typename V>
bool Get(const char* key, std::map<U,V>& values)
{
std::vector<std::string> temp;
if(!Get(key,temp))
{
return false;
}
values.clear();
for(int i = 0; i < temp.size(); i++)
{
std::vector<std::string> key_val;
SplitString(temp[i],'_',key_val);
if(key_val.size() < 2)
continue;
U mapKey;
V mapValue;
if(!TryParse<U>(key_val[0],&mapKey))
continue;
if(!TryParse<V>(key_val[1],&mapValue))
continue;
values[mapKey] = mapValue;
}
return true;
}
bool operator < (const Section& other) const {
return name < other.name;

View File

@ -118,6 +118,14 @@ static bool TryParse(const std::string &str, N *const output)
return false;
}
template <typename N>
static std::string ValueToString(const N value)
{
std::stringstream string;
string << value;
return string.str();
}
// TODO: kill this
bool AsciiToHex(const char* _szValue, u32& result);

View File

@ -83,6 +83,7 @@ void CConfig::Load(const char *iniFileName)
false);
#endif
control->Get("LargeControls", &bLargeControls, false);
control->Get("KeyMapping",iMappingMap);
IniFile::Section *pspConfig = iniFile.GetOrCreateSection("SystemParam");
pspConfig->Get("Language", &ilanguage, PSP_SYSTEMPARAM_LANGUAGE_ENGLISH);
@ -133,6 +134,7 @@ void CConfig::Save()
control->Set("ShowStick", bShowAnalogStick);
control->Set("ShowTouchControls", bShowTouchControls);
control->Set("LargeControls", bLargeControls);
control->Set("KeyMapping",iMappingMap);
IniFile::Section *pspConfig = iniFile.GetOrCreateSection("SystemParam");
pspConfig->Set("Language", ilanguage);

View File

@ -18,6 +18,7 @@
#pragma once
#include <string>
#include <map>
#define PPSSPP_VERSION_STR "0.6.1"
@ -73,6 +74,9 @@ public:
bool bShowDebugStats;
bool bLargeControls;
// Control
std::map<int,int> iMappingMap; // Can be used differently depending on systems
// SystemParam
int ilanguage;
int itimeformat;

View File

@ -109,27 +109,12 @@ void EmuThread::run()
UpdateInputState(input_state);
static const int mapping[12][2] = {
{PAD_BUTTON_A, CTRL_CROSS},
{PAD_BUTTON_B, CTRL_CIRCLE},
{PAD_BUTTON_X, CTRL_SQUARE},
{PAD_BUTTON_Y, CTRL_TRIANGLE},
{PAD_BUTTON_UP, CTRL_UP},
{PAD_BUTTON_DOWN, CTRL_DOWN},
{PAD_BUTTON_LEFT, CTRL_LEFT},
{PAD_BUTTON_RIGHT, CTRL_RIGHT},
{PAD_BUTTON_LBUMPER, CTRL_LTRIGGER},
{PAD_BUTTON_RBUMPER, CTRL_RTRIGGER},
{PAD_BUTTON_START, CTRL_START},
{PAD_BUTTON_SELECT, CTRL_SELECT},
};
for (int i = 0; i < 12; i++) {
if (input_state->pad_buttons_down & mapping[i][0]) {
__CtrlButtonDown(mapping[i][1]);
for (int i = 0; i < controllistCount; i++) {
if (input_state->pad_buttons_down & controllist[i].emu_id) {
__CtrlButtonDown(controllist[i].psp_id);
}
if (input_state->pad_buttons_up & mapping[i][0]) {
__CtrlButtonUp(mapping[i][1]);
if (input_state->pad_buttons_up & controllist[i].emu_id) {
__CtrlButtonUp(controllist[i].psp_id);
}
}
__CtrlSetAnalog(input_state->pad_lstick_x, input_state->pad_lstick_y);

View File

@ -21,8 +21,10 @@ linux: LIBS += -L. -lCore -lCommon -lNative
linux: PRE_TARGETDEPS += ./libCommon.a ./libCore.a ./libNative.a
# Main
SOURCES += ../native/base/QtMain.cpp
HEADERS += ../native/base/QtMain.h
SOURCES += ../native/base/QtMain.cpp \
qkeyedit.cpp
HEADERS += ../native/base/QtMain.h \
qkeyedit.h
# Native
SOURCES += ../android/jni/EmuScreen.cpp \
@ -73,4 +75,7 @@ linux:!mobile_platform {
FORMS += mainwindow.ui \
debugger_disasm.ui \
controls.ui
RESOURCES += \
resources.qrc
}

View File

@ -1,29 +1,24 @@
#include "controls.h"
#include "ui_controls.h"
#include "Core/Config.h"
struct Controls_
{
char* command;
char* key;
};
const Controls_ controllist[] = {
{"Start","1"},
{"Select","2"},
{"Square","Z"},
{"Triangle","A"},
{"Circle","S"},
{"Cross","X"},
{"Left Trigger","Q"},
{"Right Trigger","W"},
{"Up","Arrow Up"},
{"Down","Arrow Down"},
{"Left","Arrow Left"},
{"Right","Arrow Right"},
{"Analog Up","I"},
{"Analog Down","K"},
{"Analog Left","J"},
{"Analog Right","L"},
Controls_ controllist[] = {
{"Edit_Start", "Start", Qt::Key_1, PAD_BUTTON_START, CTRL_START},
{"Edit_Select", "Select", Qt::Key_2, PAD_BUTTON_SELECT, CTRL_SELECT},
{"Edit_S", "Square", Qt::Key_Z, PAD_BUTTON_X, CTRL_SQUARE},
{"Edit_T", "Triangle", Qt::Key_A, PAD_BUTTON_Y, CTRL_TRIANGLE},
{"Edit_O", "Circle", Qt::Key_S, PAD_BUTTON_B, CTRL_CIRCLE},
{"Edit_X", "Cross", Qt::Key_X, PAD_BUTTON_A, CTRL_CROSS},
{"Edit_LT", "Left Trigger", Qt::Key_Q, PAD_BUTTON_LBUMPER, CTRL_LTRIGGER},
{"Edit_RT", "Right Trigger", Qt::Key_W, PAD_BUTTON_RBUMPER, CTRL_RTRIGGER},
{"Edit_Up", "Up", Qt::Key_Up, PAD_BUTTON_UP, CTRL_UP},
{"Edit_Down", "Down", Qt::Key_Down, PAD_BUTTON_DOWN, CTRL_DOWN},
{"Edit_Left", "Left", Qt::Key_Left, PAD_BUTTON_LEFT, CTRL_LEFT},
{"Edit_Right", "Right", Qt::Key_Right, PAD_BUTTON_RIGHT, CTRL_RIGHT},
{"", "Analog Up", Qt::Key_I, PAD_BUTTON_JOY_UP, 0},
{"", "Analog Down", Qt::Key_K, PAD_BUTTON_JOY_DOWN,0},
{"", "Analog Left", Qt::Key_J, PAD_BUTTON_JOY_LEFT,0},
{"", "Analog Right", Qt::Key_L, PAD_BUTTON_JOY_RIGHT,0},
};
Controls::Controls(QWidget *parent) :
@ -31,25 +26,47 @@ Controls::Controls(QWidget *parent) :
ui(new Ui::Controls)
{
ui->setupUi(this);
int numRows = sizeof(controllist)/sizeof(Controls_);
ui->listControls->setRowCount(numRows);
for(int i = 0; i < numRows; i++)
{
QTableWidgetItem* item = new QTableWidgetItem();
item->setText(controllist[i].command);
ui->listControls->setItem(i,0,item);
item = new QTableWidgetItem();
item->setText(controllist[i].key);
ui->listControls->setItem(i,1,item);
ui->listControls->setRowHeight(i,15);
}
}
Controls::~Controls()
{
delete ui;
}
void Controls::showEvent(QShowEvent*)
{
for(int i = 0; i < controllistCount; i++)
{
if(g_Config.iMappingMap.find(i) != g_Config.iMappingMap.end())
{
controllist[i].key = (Qt::Key)g_Config.iMappingMap[i];
}
if(controllist[i].editName != "")
{
QLineEdit* edit = findChild<QLineEdit*>(controllist[i].editName);
if(edit)
{
QKeySequence sec(controllist[i].key);
edit->setText(sec.toString());
}
}
}
}
void Controls::on_buttonBox_accepted()
{
for(int i = 0; i < controllistCount; i++)
{
if(controllist[i].editName != "")
{
QLineEdit* edit = findChild<QLineEdit*>(controllist[i].editName);
if(edit)
{
QKeySequence sec(edit->text());
controllist[i].key = (Qt::Key)sec[0];
g_Config.iMappingMap[i] = sec[0];
}
}
}
}

View File

@ -2,11 +2,26 @@
#define CONTROLS_H
#include <QDialog>
#include "native/input/input_state.h"
#include "Core/HLE/sceCtrl.h"
namespace Ui {
class Controls;
}
struct Controls_
{
public:
QString editName;
QString command;
Qt::Key key;
int emu_id;
int psp_id;
};
const int controllistCount = 16;
extern Controls_ controllist[];
class Controls : public QDialog
{
Q_OBJECT
@ -14,7 +29,11 @@ class Controls : public QDialog
public:
explicit Controls(QWidget *parent = 0);
~Controls();
void showEvent(QShowEvent *);
private slots:
void on_buttonBox_accepted();
private:
Ui::Controls *ui;
};

View File

@ -6,43 +6,180 @@
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
<width>618</width>
<height>351</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Note : Currently controls are NOT configurable.</string>
<widget class="QWidget" name="widget" native="true">
<property name="minimumSize">
<size>
<width>600</width>
<height>300</height>
</size>
</property>
</widget>
</item>
<item>
<widget class="QTableWidget" name="listControls">
<property name="selectionMode">
<enum>QAbstractItemView::SingleSelection</enum>
<property name="maximumSize">
<size>
<width>600</width>
<height>300</height>
</size>
</property>
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectRows</enum>
</property>
<property name="showGrid">
<bool>false</bool>
</property>
<property name="columnCount">
<number>2</number>
</property>
<attribute name="horizontalHeaderVisible">
<bool>false</bool>
</attribute>
<attribute name="verticalHeaderVisible">
<bool>false</bool>
</attribute>
<column/>
<column/>
<widget class="QLabel" name="PSP_Img">
<property name="geometry">
<rect>
<x>50</x>
<y>50</y>
<width>501</width>
<height>191</height>
</rect>
</property>
<property name="text">
<string/>
</property>
<property name="pixmap">
<pixmap resource="resources.qrc">:/images/resources/psp.png</pixmap>
</property>
</widget>
<widget class="QKeyEdit" name="Edit_Up">
<property name="geometry">
<rect>
<x>50</x>
<y>100</y>
<width>41</width>
<height>25</height>
</rect>
</property>
</widget>
<widget class="QKeyEdit" name="Edit_Left">
<property name="geometry">
<rect>
<x>30</x>
<y>130</y>
<width>41</width>
<height>25</height>
</rect>
</property>
</widget>
<widget class="QKeyEdit" name="Edit_Right">
<property name="geometry">
<rect>
<x>80</x>
<y>130</y>
<width>41</width>
<height>25</height>
</rect>
</property>
</widget>
<widget class="QKeyEdit" name="Edit_Down">
<property name="geometry">
<rect>
<x>50</x>
<y>160</y>
<width>41</width>
<height>25</height>
</rect>
</property>
</widget>
<widget class="QKeyEdit" name="Edit_Home">
<property name="geometry">
<rect>
<x>150</x>
<y>240</y>
<width>41</width>
<height>25</height>
</rect>
</property>
</widget>
<widget class="QKeyEdit" name="Edit_Start">
<property name="geometry">
<rect>
<x>410</x>
<y>240</y>
<width>41</width>
<height>25</height>
</rect>
</property>
</widget>
<widget class="QKeyEdit" name="Edit_Select">
<property name="geometry">
<rect>
<x>360</x>
<y>240</y>
<width>41</width>
<height>25</height>
</rect>
</property>
</widget>
<widget class="QKeyEdit" name="Edit_X">
<property name="geometry">
<rect>
<x>510</x>
<y>160</y>
<width>41</width>
<height>25</height>
</rect>
</property>
</widget>
<widget class="QKeyEdit" name="Edit_S">
<property name="geometry">
<rect>
<x>480</x>
<y>130</y>
<width>41</width>
<height>25</height>
</rect>
</property>
</widget>
<widget class="QKeyEdit" name="Edit_O">
<property name="geometry">
<rect>
<x>530</x>
<y>130</y>
<width>41</width>
<height>25</height>
</rect>
</property>
</widget>
<widget class="QKeyEdit" name="Edit_T">
<property name="geometry">
<rect>
<x>510</x>
<y>100</y>
<width>41</width>
<height>25</height>
</rect>
</property>
</widget>
<widget class="QKeyEdit" name="Edit_RT">
<property name="geometry">
<rect>
<x>440</x>
<y>20</y>
<width>41</width>
<height>25</height>
</rect>
</property>
</widget>
<widget class="QKeyEdit" name="Edit_LT">
<property name="geometry">
<rect>
<x>120</x>
<y>20</y>
<width>41</width>
<height>25</height>
</rect>
</property>
</widget>
</widget>
</item>
<item>
@ -57,7 +194,16 @@
</item>
</layout>
</widget>
<resources/>
<customwidgets>
<customwidget>
<class>QKeyEdit</class>
<extends>QLineEdit</extends>
<header>qkeyedit.h</header>
</customwidget>
</customwidgets>
<resources>
<include location="resources.qrc"/>
</resources>
<connections>
<connection>
<sender>buttonBox</sender>

View File

@ -20,28 +20,6 @@
#include "QtHost.h"
#include "EmuThread.h"
// Input
const int buttonMappings[18] = {
Qt::Key_X, //A
Qt::Key_S, //B
Qt::Key_Z, //X
Qt::Key_A, //Y
Qt::Key_W, //LBUMPER
Qt::Key_Q, //RBUMPER
Qt::Key_1, //START
Qt::Key_2, //SELECT
Qt::Key_Up, //UP
Qt::Key_Down, //DOWN
Qt::Key_Left, //LEFT
Qt::Key_Right, //RIGHT
0, //MENU (event)
Qt::Key_Backspace, //BACK
Qt::Key_I, //JOY UP
Qt::Key_K, //JOY DOWN
Qt::Key_J, //JOY LEFT
Qt::Key_L, //JOY RIGHT
};
const char *stateToLoad = NULL;
MainWindow::MainWindow(QWidget *parent) :
@ -673,20 +651,20 @@ void MainWindow::keyPressEvent(QKeyEvent *e)
return;
}
for (int b = 0; b < 14; b++) {
if (e->key() == buttonMappings[b])
for (int b = 0; b < controllistCount; b++) {
if (e->key() == controllist[b].key)
{
input_state.pad_buttons |= (1<<b);
input_state.pad_buttons |= (controllist[b].emu_id);
}
}
}
void MainWindow::keyReleaseEvent(QKeyEvent *e)
{
for (int b = 0; b < 14; b++) {
if (e->key() == buttonMappings[b])
for (int b = 0; b < controllistCount; b++) {
if (e->key() == controllist[b].key)
{
input_state.pad_buttons &= ~(1<<b);
input_state.pad_buttons &= ~(controllist[b].emu_id);
}
}
}

21
Qt/qkeyedit.cpp Normal file
View File

@ -0,0 +1,21 @@
#include "qkeyedit.h"
#include <QKeySequence>
#include <QKeyEvent>
QKeyEdit::QKeyEdit(QWidget *parent) :
QLineEdit(parent)
{
}
bool QKeyEdit::event(QEvent *e)
{
if(e->type() == QEvent::KeyPress)
{
QKeyEvent *ke = static_cast<QKeyEvent *>(e);
QKeySequence seq(ke->key());
setText(seq.toString());
return true;
}
return QLineEdit::event(e);
}

20
Qt/qkeyedit.h Normal file
View File

@ -0,0 +1,20 @@
#ifndef QKEYEDIT_H
#define QKEYEDIT_H
#include <QLineEdit>
class QKeyEdit : public QLineEdit
{
Q_OBJECT
public:
explicit QKeyEdit(QWidget *parent = 0);
protected:
bool event(QEvent *e);
signals:
public slots:
};
#endif // QKEYEDIT_H

5
Qt/resources.qrc Normal file
View File

@ -0,0 +1,5 @@
<RCC>
<qresource prefix="/images">
<file>resources/psp.png</file>
</qresource>
</RCC>

BIN
Qt/resources/psp.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB