summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/gui/setup_input.cpp34
-rw-r--r--src/gui/setup_input.h3
-rw-r--r--src/inputmanager.cpp36
-rw-r--r--src/inputmanager.h6
4 files changed, 60 insertions, 19 deletions
diff --git a/src/gui/setup_input.cpp b/src/gui/setup_input.cpp
index a85a35975..e88098ff3 100644
--- a/src/gui/setup_input.cpp
+++ b/src/gui/setup_input.cpp
@@ -127,8 +127,11 @@ Setup_Input::Setup_Input():
mUnassignKeyButton->addActionListener(this);
mUnassignKeyButton->setEnabled(false);
- mMakeDefaultButton = new Button(_("Default"), "makeDefault", this);
- mMakeDefaultButton->addActionListener(this);
+ mResetKeysButton = new Button(_("Reset all keys"), "resetkeys", this);
+ mResetKeysButton->addActionListener(this);
+
+ mDefaultButton = new Button(_("Default"), "default", this);
+ mDefaultButton->addActionListener(this);
mTabs = new TabStrip(config.getIntValue("fontSize") + 10);
mTabs->addActionListener(this);
@@ -144,11 +147,12 @@ Setup_Input::Setup_Input():
LayoutHelper h(this);
ContainerPlacer place = h.getPlacer(0, 0);
- place(0, 0, mTabs, 4);
- place(0, 1, scrollArea, 4, 5).setPadding(2);
- place(0, 6, mMakeDefaultButton);
+ place(0, 0, mTabs, 5);
+ place(0, 1, scrollArea, 5, 5).setPadding(2);
+ place(0, 6, mResetKeysButton);
place(2, 6, mAssignKeyButton);
place(3, 6, mUnassignKeyButton);
+ place(4, 6, mDefaultButton);
setDimension(gcn::Rectangle(0, 0, 500, 350));
}
@@ -164,8 +168,8 @@ Setup_Input::~Setup_Input()
mAssignKeyButton = nullptr;
delete mUnassignKeyButton;
mUnassignKeyButton = nullptr;
- delete mMakeDefaultButton;
- mMakeDefaultButton = nullptr;
+ delete mResetKeysButton;
+ mResetKeysButton = nullptr;
}
void Setup_Input::apply()
@@ -252,11 +256,23 @@ void Setup_Input::action(const gcn::ActionEvent &event)
}
mAssignKeyButton->setEnabled(true);
}
- else if (id == "makeDefault")
+ else if (id == "resetKeys")
{
- inputManager.makeDefault();
+ inputManager.resetKeys();
+ inputManager.update();
refreshKeys();
}
+ else if (id == "default")
+ {
+ int i(mKeyList->getSelected());
+ if (i >= 0 && i < mActionDataSize[selectedData])
+ {
+ const SetupActionData &key = setupActionData[selectedData][i];
+ int ik = key.actionId;
+ inputManager.makeDefault(ik);
+ refreshKeys();
+ }
+ }
else if (!id.find("tabs_"))
{
int k = 0;
diff --git a/src/gui/setup_input.h b/src/gui/setup_input.h
index b2e2d64c0..aacdba366 100644
--- a/src/gui/setup_input.h
+++ b/src/gui/setup_input.h
@@ -83,7 +83,8 @@ class Setup_Input : public SetupTab
gcn::Button *mAssignKeyButton;
gcn::Button *mUnassignKeyButton;
- gcn::Button *mMakeDefaultButton;
+ gcn::Button *mDefaultButton;
+ gcn::Button *mResetKeysButton;
TabStrip *mTabs;
bool mKeySetting; /**< flag to check if key being set. */
diff --git a/src/inputmanager.cpp b/src/inputmanager.cpp
index e7ac40cf0..51eca37f7 100644
--- a/src/inputmanager.cpp
+++ b/src/inputmanager.cpp
@@ -80,8 +80,13 @@ void InputManager::init()
mNewKeyIndex = Input::KEY_NO_VALUE;
- makeDefault();
+ resetKeys();
retrieve();
+ update();
+}
+
+void InputManager::update()
+{
keyboard.update();
if (joystick)
joystick->update();
@@ -183,7 +188,7 @@ void InputManager::store()
}
}
-void InputManager::makeDefault()
+void InputManager::resetKeys()
{
for (int i = 0; i < Input::KEY_TOTAL; i++)
{
@@ -200,6 +205,25 @@ void InputManager::makeDefault()
}
}
+void InputManager::makeDefault(int i)
+{
+ if (i >= 0 && i < Input::KEY_TOTAL)
+ {
+ KeyFunction &key = mKey[i];
+ for (size_t i2 = 1; i2 < KeyFunctionSize; i2 ++)
+ {
+ key.values[i2].type = INPUT_UNKNOWN;
+ key.values[i2].value = -1;
+ }
+ key.values[0].type = keyData[i].defaultType1;
+ key.values[0].value = keyData[i].defaultValue1;
+ key.values[1].type = keyData[i].defaultType2;
+ key.values[1].value = keyData[i].defaultValue2;
+
+ update();
+ }
+}
+
bool InputManager::hasConflicts(int &key1, int &key2)
{
size_t i;
@@ -381,9 +405,7 @@ void InputManager::setNewKey(const SDL_Event &event, int type)
if (val != -1)
{
addActionKey(mNewKeyIndex, type, val);
- keyboard.update();
- if (joystick)
- joystick->update();
+ update();
}
}
@@ -395,9 +417,7 @@ void InputManager::unassignKey()
key.values[i].type = INPUT_UNKNOWN;
key.values[i].value = -1;
}
- keyboard.update();
- if (joystick)
- joystick->update();
+ update();
}
bool InputManager::handleAssignKey(const SDL_Event &event, int type)
diff --git a/src/inputmanager.h b/src/inputmanager.h
index 0738fbebb..be0acc23e 100644
--- a/src/inputmanager.h
+++ b/src/inputmanager.h
@@ -96,7 +96,9 @@ class InputManager
void store();
- void makeDefault();
+ void resetKeys();
+
+ void makeDefault(int i);
bool hasConflicts(int &key1, int &key2);
@@ -144,6 +146,8 @@ class InputManager
int getKeyIndex(int value, int grp, int type) const;
+ void update();
+
protected:
Setup_Input *mSetupInput; /**< Reference to setup window */