mirror of
https://github.com/citra-emu/citra.git
synced 2024-11-23 09:00:10 +00:00
Bindings are now editable
This commit is contained in:
parent
5dc4223a62
commit
9b6c4ac77d
@ -1,4 +1,5 @@
|
||||
#include <QKeySequence>
|
||||
#include <QStyledItemDelegate>
|
||||
#include <QSettings>
|
||||
#include <QKeyEvent>
|
||||
#include "key_bindings.hxx"
|
||||
@ -9,7 +10,19 @@ typedef std::map<QKeySequence, HID::PAD> BindingsMap;
|
||||
|
||||
BindingsMap bindings;
|
||||
|
||||
std::map<HID::PAD, QString> nameMap;
|
||||
|
||||
typedef std::map<HID::PAD, QKeySequence> ReverseBindingsMap;
|
||||
|
||||
ReverseBindingsMap reverseBindings;
|
||||
|
||||
|
||||
typedef std::map<HID::PAD, QString> NameMap;
|
||||
|
||||
NameMap names;
|
||||
|
||||
typedef std::map<QString, HID::PAD> ReverseNameMap;
|
||||
|
||||
ReverseNameMap reverseNames;
|
||||
|
||||
void SaveKeyBindings(QSettings& settings)
|
||||
{
|
||||
@ -47,32 +60,84 @@ HID::PAD GetKeyBinding(QKeyEvent * event)
|
||||
void RegisterKeyBinding(const QKeySequence keySeq, const HID::PAD pad)
|
||||
{
|
||||
bindings[keySeq] = pad;
|
||||
reverseBindings[pad] = keySeq;
|
||||
}
|
||||
|
||||
void createNameMap() {
|
||||
for (int i = 0; i < HID::numPadItems; i++){
|
||||
nameMap[(HID::PAD)(1 << i)] = QString(HID::PAD_NAMES[i]);
|
||||
names[(HID::PAD)(1 << i)] = QString(HID::PAD_NAMES[i]);
|
||||
reverseNames[QString(HID::PAD_NAMES[i])] = (HID::PAD)(1 << i);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void setDefaultKeyBindings() {
|
||||
RegisterKeyBinding(QKeySequence("Y"), HID::PAD::PAD_A);
|
||||
RegisterKeyBinding(QKeySequence("H"), HID::PAD::PAD_B);
|
||||
RegisterKeyBinding(QKeySequence("Z"), HID::PAD::PAD_SELECT);
|
||||
RegisterKeyBinding(QKeySequence("X"), HID::PAD::PAD_START);
|
||||
|
||||
RegisterKeyBinding(QKeySequence("W"), HID::PAD::PAD_UP);
|
||||
RegisterKeyBinding(QKeySequence("A"), HID::PAD::PAD_LEFT);
|
||||
RegisterKeyBinding(QKeySequence("S"), HID::PAD::PAD_DOWN);
|
||||
RegisterKeyBinding(QKeySequence("D"), HID::PAD::PAD_RIGHT);
|
||||
|
||||
RegisterKeyBinding(QKeySequence("6"), HID::PAD::PAD_R);
|
||||
RegisterKeyBinding(QKeySequence("7"), HID::PAD::PAD_L);
|
||||
RegisterKeyBinding(QKeySequence("U"), HID::PAD::PAD_X);
|
||||
RegisterKeyBinding(QKeySequence("J"), HID::PAD::PAD_Y);
|
||||
|
||||
}
|
||||
|
||||
//class makes single columns uneditable
|
||||
class NoEditDelegate : public QStyledItemDelegate {
|
||||
public:
|
||||
NoEditDelegate(QObject* parent = 0) : QStyledItemDelegate(parent) {}
|
||||
virtual QWidget* createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const {
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
void GKeyBindingsDialog::updateItem(QTreeWidgetItem * item, int column) {
|
||||
bindings[item->text(1)] = reverseNames[item->text(0)]; //sanitise
|
||||
reverseBindings[reverseNames[item->text(0)]] = item->text(1);
|
||||
return;
|
||||
}
|
||||
|
||||
GKeyBindingsDialog::GKeyBindingsDialog(QWidget* parent) : QDialog(parent)
|
||||
{
|
||||
ui.setupUi(this);
|
||||
|
||||
createNameMap();
|
||||
|
||||
for (BindingsMap::iterator key = bindings.begin(); key != bindings.end(); ++key)
|
||||
for (NameMap::iterator key = names.begin(); key != names.end(); ++key)
|
||||
{
|
||||
QKeySequence keySeq = reverseBindings[key->first];
|
||||
QStringList columns;
|
||||
columns << key->first.toString() << nameMap[key->second];
|
||||
columns << key->second << keySeq.toString();
|
||||
QTreeWidgetItem* item = new QTreeWidgetItem(columns);
|
||||
item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsSelectable);
|
||||
ui.treeWidget->addTopLevelItem(item);
|
||||
|
||||
}
|
||||
// TODO: Make context configurable as well (hiding the column for now)
|
||||
|
||||
ui.treeWidget->setEditTriggers(
|
||||
QAbstractItemView::EditKeyPressed
|
||||
| QAbstractItemView::SelectedClicked
|
||||
| QAbstractItemView::AnyKeyPressed
|
||||
);
|
||||
connect(
|
||||
this, SIGNAL(itemDoubleClicked(QTreeWidgetItem*, int)),
|
||||
this, SLOT(OnMouseDoubleClicked(QTreeWidgetItem*, int))
|
||||
);
|
||||
ui.treeWidget->setColumnCount(2);
|
||||
|
||||
ui.treeWidget->resizeColumnToContents(0);
|
||||
ui.treeWidget->resizeColumnToContents(1);
|
||||
|
||||
connect(ui.treeWidget, SIGNAL(itemChanged(QTreeWidgetItem *, int)),
|
||||
this, SLOT(updateItem(QTreeWidgetItem *, int)));
|
||||
ui.treeWidget->setItemDelegateForColumn(0, new NoEditDelegate(this));
|
||||
|
||||
}
|
||||
|
@ -38,6 +38,15 @@ HID::PAD GetKeyBinding(QKeyEvent * event);
|
||||
*/
|
||||
void LoadKeyBindings(QSettings& settings);
|
||||
|
||||
|
||||
/**
|
||||
* Sets default key bindings.
|
||||
*
|
||||
*
|
||||
*/
|
||||
void setDefaultKeyBindings();
|
||||
|
||||
|
||||
class GKeyBindingsDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
@ -47,4 +56,7 @@ public:
|
||||
|
||||
private:
|
||||
Ui::key_bindings ui;
|
||||
|
||||
private slots:
|
||||
void updateItem(QTreeWidgetItem * item, int column);
|
||||
};
|
||||
|
@ -98,10 +98,7 @@ GMainWindow::GMainWindow()
|
||||
connect(GetHotkey("Main Window", "Start Emulation", this), SIGNAL(activated()), this, SLOT(OnStartGame()));
|
||||
|
||||
// Setup key bindings
|
||||
RegisterKeyBinding(QKeySequence("W"), HID::PAD::PAD_UP);
|
||||
RegisterKeyBinding(QKeySequence("A"), HID::PAD::PAD_LEFT);
|
||||
RegisterKeyBinding(QKeySequence("S"), HID::PAD::PAD_DOWN);
|
||||
RegisterKeyBinding(QKeySequence("D"), HID::PAD::PAD_RIGHT);
|
||||
setDefaultKeyBindings();
|
||||
LoadKeyBindings(settings);
|
||||
|
||||
|
||||
|
@ -99,6 +99,9 @@
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
<ClCompile />
|
||||
<ClCompile>
|
||||
<ObjectFileName>$(IntDir)%(RelativeDir)</ObjectFileName>
|
||||
</ClCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile />
|
||||
@ -106,6 +109,9 @@
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
<ClCompile />
|
||||
<ClCompile>
|
||||
<ObjectFileName>$(IntDir)%(RelativeDir)</ObjectFileName>
|
||||
</ClCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile />
|
||||
@ -131,6 +137,9 @@
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
</Link>
|
||||
<ClCompile />
|
||||
<ClCompile>
|
||||
<ObjectFileName>$(IntDir)%(RelativeDir)</ObjectFileName>
|
||||
</ClCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\common\common.vcxproj">
|
||||
|
Loading…
Reference in New Issue
Block a user