summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2012-04-08 19:41:19 +0300
committerAndrei Karas <akaras@inbox.ru>2012-04-08 19:41:19 +0300
commit30ef016b0a14f36dc480284e2d775295b5501dd4 (patch)
treea269c0983efb8dc9160bfe10b1dba26a302aff0c /src
parent25a6eae7f4fb561bbf930be28ee09510b40ebc80 (diff)
downloadmv-30ef016b0a14f36dc480284e2d775295b5501dd4.tar.gz
mv-30ef016b0a14f36dc480284e2d775295b5501dd4.tar.bz2
mv-30ef016b0a14f36dc480284e2d775295b5501dd4.tar.xz
mv-30ef016b0a14f36dc480284e2d775295b5501dd4.zip
Move most input code from keyboardconfig to inputmanager.
Diffstat (limited to 'src')
-rw-r--r--src/actionmanager.cpp31
-rw-r--r--src/client.cpp2
-rw-r--r--src/game.cpp52
-rw-r--r--src/gui/chatwindow.cpp9
-rw-r--r--src/gui/inventorywindow.cpp7
-rw-r--r--src/gui/outfitwindow.cpp3
-rw-r--r--src/gui/setup_keyboard.cpp23
-rw-r--r--src/gui/socialwindow.cpp1
-rw-r--r--src/gui/statuspopup.cpp5
-rw-r--r--src/gui/viewport.cpp13
-rw-r--r--src/gui/widgets/emoteshortcutcontainer.cpp3
-rw-r--r--src/gui/widgets/itemshortcutcontainer.cpp3
-rw-r--r--src/gui/windowmenu.cpp4
-rw-r--r--src/inputevent.h2
-rw-r--r--src/inputmanager.cpp317
-rw-r--r--src/inputmanager.h84
-rw-r--r--src/keyboardconfig.cpp313
-rw-r--r--src/keyboardconfig.h101
-rw-r--r--src/keydata.h2
-rw-r--r--src/net/ea/beinghandler.cpp1
20 files changed, 510 insertions, 466 deletions
diff --git a/src/actionmanager.cpp b/src/actionmanager.cpp
index 5f80f4269..b913f7d15 100644
--- a/src/actionmanager.cpp
+++ b/src/actionmanager.cpp
@@ -25,6 +25,7 @@
#include "game.h"
#include "inputevent.h"
#include "itemshortcut.h"
+#include "inputmanager.h"
#include "keyboardconfig.h"
#include "localplayer.h"
#include "logger.h"
@@ -85,7 +86,7 @@ impHandler0(moveUp)
dialog->refocus();
return false;
}
- if (keyboard.isActionActive(Input::KEY_EMOTE))
+ if (inputManager.isActionActive(Input::KEY_EMOTE))
return directUp(event);
return false;
}
@@ -97,42 +98,42 @@ impHandler0(moveDown)
dialog->refocus();
return false;
}
- if (keyboard.isActionActive(Input::KEY_EMOTE))
+ if (inputManager.isActionActive(Input::KEY_EMOTE))
return directDown(event);
return false;
}
impHandler0(moveLeft)
{
- if (outfitWindow && keyboard.isActionActive(Input::KEY_WEAR_OUTFIT))
+ if (outfitWindow && inputManager.isActionActive(Input::KEY_WEAR_OUTFIT))
{
outfitWindow->wearPreviousOutfit();
if (Game::instance())
Game::instance()->setValidSpeed();
return true;
}
- if (keyboard.isActionActive(Input::KEY_EMOTE))
+ if (inputManager.isActionActive(Input::KEY_EMOTE))
return directLeft(event);
return false;
}
impHandler0(moveRight)
{
- if (outfitWindow && keyboard.isActionActive(Input::KEY_WEAR_OUTFIT))
+ if (outfitWindow && inputManager.isActionActive(Input::KEY_WEAR_OUTFIT))
{
outfitWindow->wearNextOutfit();
if (Game::instance())
Game::instance()->setValidSpeed();
return true;
}
- if (keyboard.isActionActive(Input::KEY_EMOTE))
+ if (inputManager.isActionActive(Input::KEY_EMOTE))
return directRight(event);
return false;
}
impHandler(emote)
{
- if (keyboard.isActionActive(Input::KEY_EMOTE))
+ if (inputManager.isActionActive(Input::KEY_EMOTE))
{
// emote keys
int emotion = 1 + event.action - Input::KEY_EMOTE_1;
@@ -145,7 +146,7 @@ impHandler(emote)
return true;
}
}
- else if (keyboard.isActionActive(Input::KEY_MOVE_TO_POINT))
+ else if (inputManager.isActionActive(Input::KEY_MOVE_TO_POINT))
{
// move to point keys
int num = event.action - Input::KEY_EMOTE_1;
@@ -155,7 +156,7 @@ impHandler(emote)
return true;
}
}
- else if (keyboard.isActionActive(Input::KEY_WEAR_OUTFIT))
+ else if (inputManager.isActionActive(Input::KEY_WEAR_OUTFIT))
{
int num = event.action - Input::KEY_EMOTE_1;
if (outfitWindow && num >= 0)
@@ -166,7 +167,7 @@ impHandler(emote)
return true;
}
}
- else if (keyboard.isActionActive(Input::KEY_COPY_OUTFIT))
+ else if (inputManager.isActionActive(Input::KEY_COPY_OUTFIT))
{
int num = event.action - Input::KEY_EMOTE_1;
if (outfitWindow && num >= 0)
@@ -412,8 +413,8 @@ impHandler0(changePickupType)
impHandler0(moveToTarget)
{
- if (player_node && !keyboard.isActionActive(Input::KEY_TARGET_ATTACK)
- && !keyboard.isActionActive(Input::KEY_ATTACK))
+ if (player_node && !inputManager.isActionActive(Input::KEY_TARGET_ATTACK)
+ && !inputManager.isActionActive(Input::KEY_ATTACK))
{
player_node->moveToTarget();
return true;
@@ -423,8 +424,8 @@ impHandler0(moveToTarget)
impHandler0(moveToHome)
{
- if (player_node && !keyboard.isActionActive(Input::KEY_TARGET_ATTACK)
- && !keyboard.isActionActive(Input::KEY_ATTACK))
+ if (player_node && !inputManager.isActionActive(Input::KEY_TARGET_ATTACK)
+ && !inputManager.isActionActive(Input::KEY_ATTACK))
{
player_node->moveToHome();
if (Game::instance())
@@ -617,7 +618,7 @@ impHandler0(sit)
{
if (player_node)
{
- if (keyboard.isActionActive(Input::KEY_EMOTE))
+ if (inputManager.isActionActive(Input::KEY_EMOTE))
player_node->updateSit();
else
player_node->toggleSit();
diff --git a/src/client.cpp b/src/client.cpp
index 875d70a46..12415c6e4 100644
--- a/src/client.cpp
+++ b/src/client.cpp
@@ -35,6 +35,7 @@
#include "graphicsvertexes.h"
#include "itemshortcut.h"
#include "joystick.h"
+#include "inputmanager.h"
#include "keyboardconfig.h"
#ifdef USE_OPENGL
#include "openglgraphics.h"
@@ -602,6 +603,7 @@ void Client::gameInit()
// Initialize keyboard
keyboard.init();
+ inputManager.init();
// Initialise player relations
player_relations.init();
diff --git a/src/game.cpp b/src/game.cpp
index eda5fd638..250028b88 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -722,8 +722,8 @@ void Game::handleMoveAndAttack()
// Ignore input if either "ignore" key is pressed
// Stops the character moving about if the user's window manager
// uses "ignore+arrow key" to switch virtual desktops.
- if (keyboard.isActionActive(Input::KEY_IGNORE_INPUT_1) ||
- keyboard.isActionActive(Input::KEY_IGNORE_INPUT_2))
+ if (inputManager.isActionActive(Input::KEY_IGNORE_INPUT_1) ||
+ inputManager.isActionActive(Input::KEY_IGNORE_INPUT_2))
{
return;
}
@@ -731,14 +731,14 @@ void Game::handleMoveAndAttack()
unsigned char direction = 0;
// Translate pressed keys to movement and direction
- if (keyboard.isActionActive(Input::KEY_MOVE_UP) ||
+ if (inputManager.isActionActive(Input::KEY_MOVE_UP) ||
(joystick && joystick->isUp()))
{
direction |= Being::UP;
setValidSpeed();
player_node->cancelFollow();
}
- else if (keyboard.isActionActive(Input::KEY_MOVE_DOWN) ||
+ else if (inputManager.isActionActive(Input::KEY_MOVE_DOWN) ||
(joystick && joystick->isDown()))
{
direction |= Being::DOWN;
@@ -746,14 +746,14 @@ void Game::handleMoveAndAttack()
player_node->cancelFollow();
}
- if (keyboard.isActionActive(Input::KEY_MOVE_LEFT) ||
+ if (inputManager.isActionActive(Input::KEY_MOVE_LEFT) ||
(joystick && joystick->isLeft()))
{
direction |= Being::LEFT;
setValidSpeed();
player_node->cancelFollow();
}
- else if (keyboard.isActionActive(Input::KEY_MOVE_RIGHT) ||
+ else if (inputManager.isActionActive(Input::KEY_MOVE_RIGHT) ||
(joystick && joystick->isRight()))
{
direction |= Being::RIGHT;
@@ -761,7 +761,7 @@ void Game::handleMoveAndAttack()
player_node->cancelFollow();
}
- if (!keyboard.isActionActive(Input::KEY_EMOTE) || direction == 0)
+ if (!inputManager.isActionActive(Input::KEY_EMOTE) || direction == 0)
{
if (!viewport->getCameraMode())
{
@@ -791,20 +791,20 @@ void Game::handleMoveAndAttack()
if ((player_node->getFollow().empty() || joyAttack) && mValidSpeed)
{
// Attacking monsters
- if (keyboard.isActionActive(Input::KEY_ATTACK))
+ if (inputManager.isActionActive(Input::KEY_ATTACK))
{
if (player_node->getTarget())
player_node->attack(player_node->getTarget(), true);
}
- if ((keyboard.isActionActive(Input::KEY_TARGET_ATTACK)
+ if ((inputManager.isActionActive(Input::KEY_TARGET_ATTACK)
|| joyAttack)
- /*&& !keyboard.isActionActive(Input::KEY_MOVE_TO_TARGET)*/
+ /*&& !inputManager.isActionActive(Input::KEY_MOVE_TO_TARGET)*/
)
{
Being *target = nullptr;
- bool newTarget = !keyboard.isActionActive(Input::KEY_TARGET);
+ bool newTarget = !inputManager.isActionActive(Input::KEY_TARGET);
// A set target has highest priority
if (!player_node->getTarget())
{
@@ -821,27 +821,27 @@ void Game::handleMoveAndAttack()
}
}
- if (!keyboard.isActionActive(Input::KEY_EMOTE))
+ if (!inputManager.isActionActive(Input::KEY_EMOTE))
{
// Target the nearest player/monster/npc
- if ((keyboard.isActionActive(Input::KEY_TARGET_PLAYER) ||
- keyboard.isActionActive(Input::KEY_TARGET_CLOSEST) ||
- keyboard.isActionActive(Input::KEY_TARGET_NPC) ||
+ if ((inputManager.isActionActive(Input::KEY_TARGET_PLAYER) ||
+ inputManager.isActionActive(Input::KEY_TARGET_CLOSEST) ||
+ inputManager.isActionActive(Input::KEY_TARGET_NPC) ||
(joystick && joystick->buttonPressed(3))) &&
- !keyboard.isActionActive(Input::KEY_TARGET) &&
- !keyboard.isActionActive(Input::KEY_UNTARGET))
+ !inputManager.isActionActive(Input::KEY_TARGET) &&
+ !inputManager.isActionActive(Input::KEY_UNTARGET))
{
ActorSprite::Type currentTarget = ActorSprite::UNKNOWN;
- if (keyboard.isActionActive(Input::KEY_TARGET_CLOSEST) ||
+ if (inputManager.isActionActive(Input::KEY_TARGET_CLOSEST) ||
(joystick && joystick->buttonPressed(3)))
{
currentTarget = ActorSprite::MONSTER;
}
- else if (keyboard.isActionActive(Input::KEY_TARGET_PLAYER))
+ else if (inputManager.isActionActive(Input::KEY_TARGET_PLAYER))
{
currentTarget = ActorSprite::PLAYER;
}
- else if (keyboard.isActionActive(Input::KEY_TARGET_NPC))
+ else if (inputManager.isActionActive(Input::KEY_TARGET_NPC))
{
currentTarget = ActorSprite::NPC;
}
@@ -863,15 +863,15 @@ void Game::handleMoveAndAttack()
}
// Stop attacking if the right key is pressed
- if (!keyboard.isActionActive(Input::KEY_ATTACK)
- && !keyboard.isActionActive(Input::KEY_EMOTE))
+ if (!inputManager.isActionActive(Input::KEY_ATTACK)
+ && !inputManager.isActionActive(Input::KEY_EMOTE))
{
- if (keyboard.isActionActive(Input::KEY_TARGET)
+ if (inputManager.isActionActive(Input::KEY_TARGET)
|| (joystick && joystick->buttonPressed(4)))
{
player_node->stopAttack();
}
- else if (keyboard.isActionActive(Input::KEY_UNTARGET))
+ else if (inputManager.isActionActive(Input::KEY_UNTARGET))
{
player_node->untarget();
}
@@ -982,8 +982,8 @@ void Game::handleInput()
return;
// If pressed outfits keys, stop processing keys.
- if (keyboard.isActionActive(Input::KEY_WEAR_OUTFIT)
- || keyboard.isActionActive(Input::KEY_COPY_OUTFIT)
+ if (inputManager.isActionActive(Input::KEY_WEAR_OUTFIT)
+ || inputManager.isActionActive(Input::KEY_COPY_OUTFIT)
|| (setupWindow && setupWindow->isVisible()))
{
return;
diff --git a/src/gui/chatwindow.cpp b/src/gui/chatwindow.cpp
index 4040c3ce0..3832e5850 100644
--- a/src/gui/chatwindow.cpp
+++ b/src/gui/chatwindow.cpp
@@ -27,6 +27,7 @@
#include "commandhandler.h"
#include "configuration.h"
#include "guild.h"
+#include "inputmanager.h"
#include "keyboardconfig.h"
#include "localplayer.h"
#include "party.h"
@@ -783,18 +784,18 @@ void ChatWindow::keyPressed(gcn::KeyEvent &event)
mCurHist = mHistory.end();
mChatInput->setText("");
}
- else if (keyboard.isActionActive(Input::KEY_AUTOCOMPLETE_CHAT) &&
+ else if (inputManager.isActionActive(Input::KEY_AUTOCOMPLETE_CHAT) &&
mChatInput->getText() != "")
{
autoComplete();
return;
}
- else if (keyboard.isActionActive(Input::KEY_DEACTIVATE_CHAT) &&
+ else if (inputManager.isActionActive(Input::KEY_DEACTIVATE_CHAT) &&
mChatInput->isVisible())
{
mChatInput->processVisible(false);
}
- else if (keyboard.isActionActive(Input::KEY_CHAT_PREV_HISTORY) &&
+ else if (inputManager.isActionActive(Input::KEY_CHAT_PREV_HISTORY) &&
mChatInput->isVisible())
{
ChatTab *tab = getFocused();
@@ -826,7 +827,7 @@ void ChatWindow::keyPressed(gcn::KeyEvent &event)
mChatInput->getText().length()));
}
}
- else if (keyboard.isActionActive(Input::KEY_CHAT_NEXT_HISTORY) &&
+ else if (inputManager.isActionActive(Input::KEY_CHAT_NEXT_HISTORY) &&
mChatInput->isVisible())
{
ChatTab *tab = getFocused();
diff --git a/src/gui/inventorywindow.cpp b/src/gui/inventorywindow.cpp
index 54b1801b8..f905bb5b9 100644
--- a/src/gui/inventorywindow.cpp
+++ b/src/gui/inventorywindow.cpp
@@ -26,6 +26,7 @@
#include "inventory.h"
#include "item.h"
#include "units.h"
+#include "inputmanager.h"
#include "keyboardconfig.h"
#include "playerinfo.h"
@@ -344,7 +345,7 @@ void InventoryWindow::action(const gcn::ActionEvent &event)
}
else
{
- if (keyboard.isActionActive(Input::KEY_MOD))
+ if (inputManager.isActionActive(Input::KEY_MOD))
{
Net::getInventoryHandler()->dropItem(
item, item->getQuantity());
@@ -389,11 +390,11 @@ void InventoryWindow::mouseClicked(gcn::MouseEvent &event)
{
Window::mouseClicked(event);
- const bool mod = (isStorageActive() && keyboard.isActionActive(
+ const bool mod = (isStorageActive() && inputManager.isActionActive(
Input::KEY_MOD));
const bool mod2 = (tradeWindow && tradeWindow->isVisible()
- && keyboard.isActionActive(Input::KEY_MOD));
+ && inputManager.isActionActive(Input::KEY_MOD));
if (!mod && !mod2 && event.getButton() == gcn::MouseEvent::RIGHT)
{
diff --git a/src/gui/outfitwindow.cpp b/src/gui/outfitwindow.cpp
index 6168af665..1552d793f 100644
--- a/src/gui/outfitwindow.cpp
+++ b/src/gui/outfitwindow.cpp
@@ -26,6 +26,7 @@
#include "emoteshortcut.h"
#include "equipment.h"
#include "graphics.h"
+#include "inputmanager.h"
#include "inventory.h"
#include "item.h"
#include "keyboardconfig.h"
@@ -506,7 +507,7 @@ std::string OutfitWindow::keyName(int number)
{
if (number < 0 || number >= SHORTCUT_EMOTES)
return "";
- return keyboard.getKeyStringLong(Input::KEY_EMOTE_1 + number);
+ return inputManager.getKeyStringLong(Input::KEY_EMOTE_1 + number);
}
void OutfitWindow::next()
diff --git a/src/gui/setup_keyboard.cpp b/src/gui/setup_keyboard.cpp
index 2d8c1c28d..ee06fa4a7 100644
--- a/src/gui/setup_keyboard.cpp
+++ b/src/gui/setup_keyboard.cpp
@@ -23,6 +23,7 @@
#include "gui/setup_keyboard.h"
+#include "inputmanager.h"
#include "keyboardconfig.h"
#include "gui/okdialog.h"
@@ -747,7 +748,7 @@ Setup_Keyboard::Setup_Keyboard():
mKeyList(new ListBox(mKeyListModel)),
mKeySetting(false)
{
- keyboard.setSetupKeyboard(this);
+ inputManager.setSetupKeyboard(this);
setName(_("Keyboard"));
refreshKeys();
@@ -800,7 +801,7 @@ void Setup_Keyboard::apply()
keyUnresolved();
int key1, key2;
- if (keyboard.hasConflicts(key1, key2))
+ if (inputManager.hasConflicts(key1, key2))
{
int s1 = keyToSetupData(key1);
int s2 = keyToSetupData(key2);
@@ -812,14 +813,14 @@ void Setup_Keyboard::apply()
setupActionData[s2].name.c_str()), DIALOG_ERROR);
}
keyboard.setEnabled(true);
- keyboard.store();
+ inputManager.store();
}
void Setup_Keyboard::cancel()
{
keyUnresolved();
- keyboard.retrieve();
+ inputManager.retrieve();
keyboard.setEnabled(true);
refreshKeys();
@@ -858,7 +859,7 @@ void Setup_Keyboard::action(const gcn::ActionEvent &event)
{
const SetupActionData &key = setupActionData[i];
int ik = key.actionId;
- keyboard.setNewKeyIndex(ik);
+ inputManager.setNewKeyIndex(ik);
mKeyListModel->setElementAt(i, std::string(
gettext(key.name.c_str())) + ": ?");
}
@@ -870,15 +871,15 @@ void Setup_Keyboard::action(const gcn::ActionEvent &event)
{
const SetupActionData &key = setupActionData[i];
int ik = key.actionId;
- keyboard.setNewKeyIndex(ik);
+ inputManager.setNewKeyIndex(ik);
refreshAssignedKey(mKeyList->getSelected());
- keyboard.unassignKey();
+ inputManager.unassignKey();
}
mAssignKeyButton->setEnabled(true);
}
else if (event.getId() == "makeDefault")
{
- keyboard.makeDefault();
+ inputManager.makeDefault();
refreshKeys();
}
}
@@ -897,7 +898,7 @@ void Setup_Keyboard::refreshAssignedKey(int index)
{
mKeyListModel->setElementAt(index, strprintf("%s: %s",
gettext(key.name.c_str()),
- keyboard.getKeyStringLong(key.actionId).c_str()));
+ inputManager.getKeyStringLong(key.actionId).c_str()));
}
}
@@ -931,7 +932,7 @@ void Setup_Keyboard::keyUnresolved()
{
if (mKeySetting)
{
- newKeyCallback(keyboard.getNewKeyIndex());
- keyboard.setNewKeyIndex(Input::KEY_NO_VALUE);
+ newKeyCallback(inputManager.getNewKeyIndex());
+ inputManager.setNewKeyIndex(Input::KEY_NO_VALUE);
}
}
diff --git a/src/gui/socialwindow.cpp b/src/gui/socialwindow.cpp
index 361e94037..458fe1450 100644
--- a/src/gui/socialwindow.cpp
+++ b/src/gui/socialwindow.cpp
@@ -24,6 +24,7 @@
#include "actorspritemanager.h"
#include "guild.h"
#include "guildmanager.h"
+#include "inputmanager.h"
#include "keyboardconfig.h"
#include "localplayer.h"
#include "logger.h"
diff --git a/src/gui/statuspopup.cpp b/src/gui/statuspopup.cpp
index 420ffaf3d..cc0f5c030 100644
--- a/src/gui/statuspopup.cpp
+++ b/src/gui/statuspopup.cpp
@@ -32,6 +32,7 @@
#include "gui/widgets/textbox.h"
#include "graphics.h"
+#include "inputmanager.h"
#include "localplayer.h"
#include "units.h"
#include "keyboardconfig.h"
@@ -188,13 +189,13 @@ void StatusPopup::view(int x, int y)
void StatusPopup::setLabelText(gcn::Label *label, const char *text, int key)
{
label->setCaption(strprintf("%s %s", text,
- keyboard.getKeyValueString(key).c_str()));
+ inputManager.getKeyValueString(key).c_str()));
}
void StatusPopup::setLabelText2(gcn::Label *label, std::string text, int key)
{
label->setCaption(strprintf("%s %s", text.c_str(),
- keyboard.getKeyValueString(key).c_str()));
+ inputManager.getKeyValueString(key).c_str()));
label->adjustSize();
}
diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp
index 6c6580f21..59b7377f4 100644
--- a/src/gui/viewport.cpp
+++ b/src/gui/viewport.cpp
@@ -28,6 +28,7 @@
#include "configuration.h"
#include "graphics.h"
#include "itemshortcut.h"
+#include "inputmanager.h"
#include "keyboardconfig.h"
#include "localplayer.h"
#include "map.h"
@@ -504,17 +505,17 @@ void Viewport::mousePressed(gcn::MouseEvent &event)
}
}
else if (player_node->withinAttackRange(mHoverBeing) ||
- keyboard.isActionActive(Input::KEY_ATTACK))
+ inputManager.isActionActive(Input::KEY_ATTACK))
{
validateSpeed();
if (player_node != mHoverBeing)
{
player_node->attack(mHoverBeing,
- !keyboard.isActionActive(Input::KEY_TARGET));
+ !inputManager.isActionActive(Input::KEY_TARGET));
return;
}
}
- else if (!keyboard.isActionActive(Input::KEY_ATTACK))
+ else if (!inputManager.isActionActive(Input::KEY_ATTACK))
{
validateSpeed();
if (player_node != mHoverBeing)
@@ -532,7 +533,7 @@ void Viewport::mousePressed(gcn::MouseEvent &event)
player_node->pickUp(mHoverItem);
}
// Just walk around
- else if (!keyboard.isActionActive(Input::KEY_ATTACK))
+ else if (!inputManager.isActionActive(Input::KEY_ATTACK))
{
validateSpeed();
player_node->stopAttack();
@@ -933,8 +934,8 @@ void Viewport::returnCamera()
void Viewport::validateSpeed()
{
- if (!keyboard.isActionActive(Input::KEY_TARGET_ATTACK)
- && !keyboard.isActionActive(Input::KEY_ATTACK))
+ if (!inputManager.isActionActive(Input::KEY_TARGET_ATTACK)
+ && !inputManager.isActionActive(Input::KEY_ATTACK))
{
if (Game::instance())
Game::instance()->setValidSpeed();
diff --git a/src/gui/widgets/emoteshortcutcontainer.cpp b/src/gui/widgets/emoteshortcutcontainer.cpp
index f46ee579c..f1f040966 100644
--- a/src/gui/widgets/emoteshortcutcontainer.cpp
+++ b/src/gui/widgets/emoteshortcutcontainer.cpp
@@ -25,6 +25,7 @@
#include "configuration.h"
#include "emoteshortcut.h"
#include "graphics.h"
+#include "inputmanager.h"
#include "inventory.h"
#include "item.h"
#include "itemshortcut.h"
@@ -117,7 +118,7 @@ void EmoteShortcutContainer::draw(gcn::Graphics *graphics)
g->drawImage(mBackgroundImg, emoteX, emoteY);
// Draw emote keyboard shortcut.
- std::string key = keyboard.getKeyValueString(
+ std::string key = inputManager.getKeyValueString(
Input::KEY_EMOTE_1 + i);
graphics->setColor(getForegroundColor());
diff --git a/src/gui/widgets/itemshortcutcontainer.cpp b/src/gui/widgets/itemshortcutcontainer.cpp
index 981491dd7..a6f7f60a3 100644
--- a/src/gui/widgets/itemshortcutcontainer.cpp
+++ b/src/gui/widgets/itemshortcutcontainer.cpp
@@ -25,6 +25,7 @@
#include "configuration.h"
#include "graphics.h"
#include "inventory.h"
+#include "inputmanager.h"
#include "item.h"
#include "itemshortcut.h"
#include "spellshortcut.h"
@@ -121,7 +122,7 @@ void ItemShortcutContainer::draw(gcn::Graphics *graphics)
g->drawImage(mBackgroundImg, itemX, itemY);
// Draw item keyboard shortcut.
- std::string key = keyboard.getKeyValueString(
+ std::string key = inputManager.getKeyValueString(
Input::KEY_SHORTCUT_1 + i);
graphics->setColor(getForegroundColor());
diff --git a/src/gui/windowmenu.cpp b/src/gui/windowmenu.cpp
index bb7a989ea..12085578b 100644
--- a/src/gui/windowmenu.cpp
+++ b/src/gui/windowmenu.cpp
@@ -24,6 +24,7 @@
#include "emoteshortcut.h"
#include "graphics.h"
+#include "inputmanager.h"
#include "keyboardconfig.h"
#include "gui/didyouknowwindow.h"
@@ -308,7 +309,8 @@ void WindowMenu::mouseMoved(gcn::MouseEvent &event)
if (key != Input::KEY_NO_VALUE)
{
mTextPopup->show(x + getX(), y + getY(), btn->getDescription(),
- strprintf(_("Key: %s"), keyboard.getKeyValueString(key).c_str()));
+ strprintf(_("Key: %s"), inputManager.getKeyValueString(
+ key).c_str()));
}
else
{
diff --git a/src/inputevent.h b/src/inputevent.h
index 056a14e90..7b73bba11 100644
--- a/src/inputevent.h
+++ b/src/inputevent.h
@@ -30,6 +30,4 @@ struct InputEvent
int mask;
};
-typedef bool (*ActionFuncPtr) (InputEvent &event);
-
#endif
diff --git a/src/inputmanager.cpp b/src/inputmanager.cpp
index 7610acf29..3a0b22f3e 100644
--- a/src/inputmanager.cpp
+++ b/src/inputmanager.cpp
@@ -20,9 +20,10 @@
#include "inputmanager.h"
+#include "configuration.h"
#include "game.h"
#include "keyboardconfig.h"
-#include "keydata.h"
+#include "keyboarddata.h"
#include "localplayer.h"
#include "gui/chatwindow.h"
@@ -31,6 +32,7 @@
#include "gui/npcdialog.h"
#include "gui/npcpostdialog.h"
#include "gui/setup.h"
+#include "gui/setup_keyboard.h"
#include "gui/textdialog.h"
#include "gui/tradewindow.h"
@@ -43,20 +45,317 @@ InputManager inputManager;
extern QuitDialog *quitDialog;
-InputManager::InputManager()
+InputManager::InputManager() :
+ mSetupKey(nullptr),
+ mNewKeyIndex(Input::KEY_NO_VALUE)
{
}
+void InputManager::init()
+{
+ for (int i = 0; i < Input::KEY_TOTAL; i++)
+ {
+ for (int f = 0; f < KeyFunctionSize; f ++)
+ {
+ mKey[i].values[f].type = INPUT_UNKNOWN;
+ mKey[i].values[f].value = -1;
+ }
+ }
+
+ mNewKeyIndex = Input::KEY_NO_VALUE;
+
+ makeDefault();
+ retrieve();
+ keyboard.updateKeyActionMap();
+}
+
+void InputManager::retrieve()
+{
+ for (int i = 0; i < Input::KEY_TOTAL; i++)
+ {
+ if (*keyData[i].configField)
+ {
+ KeyFunction &kf = mKey[i];
+ std::string keyStr = config.getValue(keyData[i].configField,
+ toString(keyData[i].defaultValue));
+ StringVect keys;
+ splitToStringVector(keys, keyStr, ',');
+ StringVectCIter it = keys.begin();
+ StringVectCIter it_end = keys.end();
+ int i2 = 0;
+ for (; it != it_end && i2 < KeyFunctionSize; ++ it)
+ {
+ std::string keyStr2 = *it;
+ if (keyStr.size() < 2)
+ continue;
+ int type = INPUT_KEYBOARD;
+ if ((keyStr2[0] < '0' || keyStr2[0] > '9')
+ && keyStr2[0] != '-')
+ {
+ switch (keyStr2[0])
+ {
+ case 'm':
+ type = INPUT_MOUSE;
+ break;
+ case 'j':
+ type = INPUT_JOYSTICK;
+ break;
+ default:
+ break;
+ }
+ keyStr2 = keyStr2.substr(1);
+ }
+ int key = atoi(keyStr2.c_str());
+ if (key >= -255 && key < SDLK_LAST)
+ {
+ kf.values[i2] = KeyItem(type, key);
+ i2 ++;
+ }
+ }
+ }
+ }
+}
+
+void InputManager::store()
+{
+ for (int i = 0; i < Input::KEY_TOTAL; i++)
+ {
+ if (*keyData[i].configField)
+ {
+ std::string keyStr;
+
+ for (size_t i2 = 0; i2 < KeyFunctionSize; i2 ++)
+ {
+ const KeyItem &key = mKey[i].values[i2];
+ if (key.type != INPUT_UNKNOWN)
+ {
+ std::string tmp = "k";
+ switch(key.type)
+ {
+ case INPUT_MOUSE:
+ tmp = "m";
+ break;
+ case INPUT_JOYSTICK:
+ tmp = "j";
+ break;
+ default:
+ break;
+ }
+ if (key.value >= 0)
+ {
+ if (keyStr.empty())
+ {
+ keyStr = tmp + toString(key.value);
+ }
+ else
+ {
+ keyStr += strprintf(",%s%d", tmp.c_str(), key.value);
+ }
+ }
+ }
+ }
+ if (keyStr.empty())
+ keyStr = "-1";
+
+ config.setValue(keyData[i].configField, keyStr);
+ }
+ }
+}
+
+void InputManager::makeDefault()
+{
+ for (int i = 0; i < Input::KEY_TOTAL; i++)
+ {
+ for (size_t i2 = 1; i2 < KeyFunctionSize; i2 ++)
+ {
+ mKey[i].values[i2].type = INPUT_UNKNOWN;
+ mKey[i].values[i2].value = -1;
+ }
+ mKey[i].values[0].type = INPUT_KEYBOARD;
+ mKey[i].values[0].value = keyData[i].defaultValue;
+ }
+}
+
+bool InputManager::hasConflicts(int &key1, int &key2)
+{
+ size_t i;
+ size_t j;
+ /**
+ * No need to parse the square matrix: only check one triangle
+ * that's enough to detect conflicts
+ */
+ for (i = 0; i < Input::KEY_TOTAL; i++)
+ {
+ if (!*keyData[i].configField)
+ continue;
+
+ for (size_t i2 = 0; i2 < KeyFunctionSize; i2 ++)
+ {
+ if (mKey[i].values[i2].value == Input::KEY_NO_VALUE)
+ continue;
+
+ for (j = i, j++; j < Input::KEY_TOTAL; j++)
+ {
+
+ if ((keyData[i].grp & keyData[j].grp) == 0 ||
+ !*keyData[i].configField)
+ {
+ continue;
+ }
+
+ for (size_t j2 = 0; j2 < KeyFunctionSize; j2 ++)
+ {
+ // Allow for item shortcut and emote keys to overlap
+ // as well as emote and ignore keys, but no other keys
+ if (mKey[j].values[j2].type != INPUT_UNKNOWN
+ && mKey[i].values[i2].value == mKey[j].values[j2].value
+ && mKey[i].values[i2].type == mKey[j].values[j2].type)
+ {
+ key1 = i;
+ key2 = j;
+ return true;
+ }
+ }
+ }
+ }
+ }
+ return false;
+}
+
+void InputManager::callbackNewKey()
+{
+ mSetupKey->newKeyCallback(mNewKeyIndex);
+}
+
+bool InputManager::isActionActive(int index) const
+{
+ return keyboard.isActionActive(index);
+}
+
+KeyFunction &InputManager::getKey(int index)
+{
+ if (index < 0 || index >= Input::KEY_TOTAL)
+ index = 0;
+ return mKey[index];
+}
+
+std::string InputManager::getKeyStringLong(int index) const
+{
+ std::string keyStr;
+
+ for (size_t i = 0; i < KeyFunctionSize; i ++)
+ {
+ const KeyItem &key = mKey[index].values[i];
+ if (key.type == INPUT_KEYBOARD)
+ {
+ if (key.value >= 0)
+ {
+ std::string str = keyboard.getKeyName(key.value);
+ if (!str.empty())
+ {
+ if (keyStr.empty())
+ keyStr = str;
+ else
+ keyStr += std::string(" ") + str;
+ }
+ }
+ }
+ }
+
+ if (keyStr.empty())
+ return _("unknown key");
+ return keyStr;
+}
+
+std::string InputManager::getKeyValueString(int index) const
+{
+ std::string keyStr;
+
+ for (size_t i = 0; i < KeyFunctionSize; i ++)
+ {
+ const KeyItem &key = mKey[index].values[i];
+ if (key.type == INPUT_KEYBOARD)
+ {
+ if (key.value >= 0)
+ {
+ std::string str = keyboard.getKeyShortString(
+ keyboard.getKeyName(key.value));
+ if (!str.empty())
+ {
+ if (keyStr.empty())
+ keyStr = str;
+ else
+ keyStr += std::string(" ") + str;
+ }
+ }
+ }
+ }
+
+ if (keyStr.empty())
+ return _("u key");
+ return keyStr;
+}
+
+void InputManager::addActionKey(int action, int type, int val)
+{
+ if (action < 0 || action >= Input::KEY_TOTAL)
+ return;
+
+ int idx = -1;
+ KeyFunction &key = mKey[action];
+ for (size_t i = 0; i < KeyFunctionSize; i ++)
+ {
+ if (key.values[i].type == INPUT_UNKNOWN
+ || (key.values[i].type == INPUT_KEYBOARD
+ && key.values[i].value == val))
+ {
+ idx = i;
+ break;
+ }
+ }
+ if (idx == -1)
+ {
+ for (size_t i = 1; i < KeyFunctionSize; i ++)
+ {
+ key.values[i - 1].type = key.values[i].type;
+ key.values[i - 1].value = key.values[i].value;
+ }
+ idx = KeyFunctionSize - 1;
+ }
+
+ key.values[idx] = KeyItem(type, val);
+}
+
+void InputManager::setNewKey(const SDL_Event &event)
+{
+ int val = keyboard.getKeyValueFromEvent(event);
+
+ addActionKey(mNewKeyIndex, INPUT_KEYBOARD, val);
+
+ keyboard.updateKeyActionMap();
+}
+
+void InputManager::unassignKey()
+{
+ KeyFunction &key = mKey[mNewKeyIndex];
+ for (size_t i = 0; i < KeyFunctionSize; i ++)
+ {
+ key.values[i].type = INPUT_UNKNOWN;
+ key.values[i].value = -1;
+ }
+ keyboard.updateKeyActionMap();
+}
+
bool InputManager::handleEvent(const SDL_Event &event)
{
if (event.type == SDL_KEYDOWN)
{
if (setupWindow && setupWindow->isVisible() &&
- keyboard.getNewKeyIndex() > Input::KEY_NO_VALUE)
+ getNewKeyIndex() > Input::KEY_NO_VALUE)
{
- keyboard.setNewKey(event);
- keyboard.callbackNewKey();
- keyboard.setNewKeyIndex(Input::KEY_NO_VALUE);
+ setNewKey(event);
+ callbackNewKey();
+ setNewKeyIndex(Input::KEY_NO_VALUE);
return true;
}
@@ -143,8 +442,8 @@ int InputManager::getInputConditionMask()
if (!player_node || !player_node->getDisableGameModifiers())
mask += COND_EMODS;
- if (!keyboard.isActionActive(Input::KEY_TARGET)
- && !keyboard.isActionActive(Input::KEY_UNTARGET))
+ if (!isActionActive(Input::KEY_TARGET)
+ && !isActionActive(Input::KEY_UNTARGET))
{
mask += COND_NOTARGET;
}
@@ -158,5 +457,5 @@ bool InputManager::checkKey(const KeyData *key, int mask)
return false;
return (key->modKeyIndex == Input::KEY_NO_VALUE
- || keyboard.isActionActive(key->modKeyIndex));
+ || isActionActive(key->modKeyIndex));
}
diff --git a/src/inputmanager.h b/src/inputmanager.h
index 635e27a33..b04f15726 100644
--- a/src/inputmanager.h
+++ b/src/inputmanager.h
@@ -21,13 +21,44 @@
#ifndef INPUTMANAGER_H
#define INPUTMANAGER_H
+#include "keydata.h"
+
#include "gui/sdlinput.h"
#include <string>
#include <map>
+#define KeyFunctionSize 3
+
struct KeyData;
-//struct KeyFunction;
+
+class Setup_Keyboard;
+
+enum KeyTypes
+{
+ INPUT_UNKNOWN = 0,
+ INPUT_KEYBOARD = 1,
+ INPUT_MOUSE = 2,
+ INPUT_JOYSTICK = 3
+};
+
+struct KeyItem
+{
+ KeyItem() : type(-1), value(-1)
+ { }
+
+ KeyItem(int type0, int value0) : type(type0), value(value0)
+ { }
+
+ int type;
+
+ int value;
+};
+
+struct KeyFunction
+{
+ KeyItem values[KeyFunctionSize];
+};
enum KeyCondition
{
@@ -51,6 +82,8 @@ class InputManager
public:
InputManager();
+ void init();
+
bool handleEvent(const SDL_Event &event);
bool handleKeyEvent(const SDL_Event &event);
@@ -58,6 +91,55 @@ class InputManager
int getInputConditionMask();
bool checkKey(const KeyData *key, int mask);
+
+ void retrieve();
+
+ void store();
+
+ void makeDefault();
+
+ bool hasConflicts(int &key1, int &key2);
+
+ void callbackNewKey();
+
+ KeyFunction &getKey(int index);
+
+ std::string getKeyValueString(int index) const;
+
+ std::string getKeyStringLong(int index) const;
+
+ void addActionKey(int action, int type, int val);
+
+ void setNewKey(const SDL_Event &event);
+
+ void unassignKey();
+
+ bool isActionActive(int index) const;
+
+ /**
+ * Set the index of the new key to be assigned.
+ */
+ void setNewKeyIndex(int value)
+ { mNewKeyIndex = value; }
+
+ /**
+ * Set a reference to the key setup window.
+ */
+ void setSetupKeyboard(Setup_Keyboard *setupKey)
+ { mSetupKey = setupKey; }
+
+ /**
+ * Get the index of the new key to be assigned.
+ */
+ int getNewKeyIndex() const
+ { return mNewKeyIndex; }
+
+ protected:
+ Setup_Keyboard *mSetupKey; /**< Reference to setup window */
+
+ int mNewKeyIndex; /**< Index of new key to be assigned */
+
+ KeyFunction mKey[Input::KEY_TOTAL]; /**< Pointer to all the key data */
};
extern InputManager inputManager;
diff --git a/src/keyboardconfig.cpp b/src/keyboardconfig.cpp
index 988229cd3..a56f2cfa6 100644
--- a/src/keyboardconfig.cpp
+++ b/src/keyboardconfig.cpp
@@ -29,7 +29,6 @@
#include "logger.h"
#include "gui/sdlinput.h"
-#include "gui/setup_keyboard.h"
#include "utils/gettext.h"
#include "utils/stringutils.h"
@@ -54,181 +53,11 @@ class KeyFunctor
void KeyboardConfig::init()
{
- for (int i = 0; i < Input::KEY_TOTAL; i++)
- {
- for (int f = 0; f < KeyFunctionSize; f ++)
- {
- mKey[i].values[f].type = INPUT_UNKNOWN;
- mKey[i].values[f].value = -1;
- }
- }
-
- mNewKeyIndex = Input::KEY_NO_VALUE;
mEnabled = true;
- makeDefault();
- retrieve();
updateKeyActionMap();
}
-void KeyboardConfig::retrieve()
-{
- for (int i = 0; i < Input::KEY_TOTAL; i++)
- {
- if (*keyData[i].configField)
- {
- KeyFunction &kf = mKey[i];
- std::string keyStr = config.getValue(keyData[i].configField,
- toString(keyData[i].defaultValue));
- StringVect keys;
- splitToStringVector(keys, keyStr, ',');
- StringVectCIter it = keys.begin();
- StringVectCIter it_end = keys.end();
- int i2 = 0;
- for (; it != it_end && i2 < KeyFunctionSize; ++ it)
- {
- std::string keyStr2 = *it;
- if (keyStr.size() < 2)
- continue;
- int type = INPUT_KEYBOARD;
- if ((keyStr2[0] < '0' || keyStr2[0] > '9')
- && keyStr2[0] != '-')
- {
- switch (keyStr2[0])
- {
- case 'm':
- type = INPUT_MOUSE;
- break;
- case 'j':
- type = INPUT_JOYSTICK;
- break;
- default:
- break;
- }
- keyStr2 = keyStr2.substr(1);
- }
- int key = atoi(keyStr2.c_str());
- if (key >= -255 && key < SDLK_LAST)
- {
- kf.values[i2] = KeyItem(type, key);
- i2 ++;
- }
- }
- }
- }
-}
-
-void KeyboardConfig::store()
-{
- for (int i = 0; i < Input::KEY_TOTAL; i++)
- {
- if (*keyData[i].configField)
- {
- std::string keyStr;
-
- for (size_t i2 = 0; i2 < KeyFunctionSize; i2 ++)
- {
- const KeyItem &key = mKey[i].values[i2];
- if (key.type != INPUT_UNKNOWN)
- {
- std::string tmp = "k";
- switch(key.type)
- {
- case INPUT_MOUSE:
- tmp = "m";
- break;
- case INPUT_JOYSTICK:
- tmp = "j";
- break;
- default:
- break;
- }
- if (key.value >= 0)
- {
- if (keyStr.empty())
- {
- keyStr = tmp + toString(key.value);
- }
- else
- {
- keyStr += strprintf(",%s%d", tmp.c_str(), key.value);
- }
- }
- }
- }
- if (keyStr.empty())
- keyStr = "-1";
-
- config.setValue(keyData[i].configField, keyStr);
- }
- }
-}
-
-void KeyboardConfig::makeDefault()
-{
- for (int i = 0; i < Input::KEY_TOTAL; i++)
- {
- for (size_t i2 = 1; i2 < KeyFunctionSize; i2 ++)
- {
- mKey[i].values[i2].type = INPUT_UNKNOWN;
- mKey[i].values[i2].value = -1;
- }
- mKey[i].values[0].type = INPUT_KEYBOARD;
- mKey[i].values[0].value = keyData[i].defaultValue;
- }
-}
-
-bool KeyboardConfig::hasConflicts(int &key1, int &key2)
-{
- size_t i;
- size_t j;
- /**
- * No need to parse the square matrix: only check one triangle
- * that's enough to detect conflicts
- */
- for (i = 0; i < Input::KEY_TOTAL; i++)
- {
- if (!*keyData[i].configField)
- continue;
-
- for (size_t i2 = 0; i2 < KeyFunctionSize; i2 ++)
- {
- if (mKey[i].values[i2].value == Input::KEY_NO_VALUE)
- continue;
-
- for (j = i, j++; j < Input::KEY_TOTAL; j++)
- {
-
- if ((keyData[i].grp & keyData[j].grp) == 0 ||
- !*keyData[i].configField)
- {
- continue;
- }
-
- for (size_t j2 = 0; j2 < KeyFunctionSize; j2 ++)
- {
- // Allow for item shortcut and emote keys to overlap
- // as well as emote and ignore keys, but no other keys
- if (mKey[j].values[j2].type != INPUT_UNKNOWN
- && mKey[i].values[i2].value == mKey[j].values[j2].value
- && mKey[i].values[i2].type == mKey[j].values[j2].type)
- {
- key1 = i;
- key2 = j;
- return true;
- }
- }
- }
- }
- }
- return false;
-}
-
-void KeyboardConfig::callbackNewKey()
-{
- mSetupKey->newKeyCallback(mNewKeyIndex);
-}
-
int KeyboardConfig::getKeyValueFromEvent(const SDL_Event &event) const
{
if (event.key.keysym.sym)
@@ -243,11 +72,12 @@ int KeyboardConfig::getKeyIndex(const SDL_Event &event, int grp) const
const int keyValue = getKeyValueFromEvent(event);
for (size_t i = 0; i < Input::KEY_TOTAL; i++)
{
+ KeyFunction &key = inputManager.getKey(i);
for (size_t i2 = 0; i2 < KeyFunctionSize; i2 ++)
{
- if (keyValue == mKey[i].values[i2].value
+ if (keyValue == key.values[i2].value
&& (grp & keyData[i].grp) != 0
- && mKey[i].values[i2].type == INPUT_KEYBOARD)
+ && key.values[i2].type == INPUT_KEYBOARD)
{
return i;
}
@@ -256,82 +86,19 @@ int KeyboardConfig::getKeyIndex(const SDL_Event &event, int grp) const
return Input::KEY_NO_VALUE;
}
-bool KeyboardConfig::isActionActive(int index) const
-{
- if (!mActiveKeys)
- return false;
-
- for (size_t i = 0; i < KeyFunctionSize; i ++)
- {
- const int value = mKey[index].values[i].value;
- if (value >= 0 && mActiveKeys[value])
- return true;
- }
- return false;
-}
-
void KeyboardConfig::refreshActiveKeys()
{
mActiveKeys = SDL_GetKeyState(nullptr);
}
-std::string KeyboardConfig::getKeyStringLong(int index) const
+std::string KeyboardConfig::getKeyName(int key)
{
- std::string keyStr;
-
- for (size_t i = 0; i < KeyFunctionSize; i ++)
- {
- const KeyItem &key = mKey[index].values[i];
- if (key.type == INPUT_KEYBOARD)
- {
- if (key.value >= 0)
- {
- if (keyStr.empty())
- {
- keyStr = SDL_GetKeyName(static_cast<SDLKey>(key.value));
- }
- else
- {
- keyStr += std::string(" ") + SDL_GetKeyName(
- static_cast<SDLKey>(key.value));
- }
- }
- }
- }
+ if (key == Input::KEY_NO_VALUE)
+ return "";
+ if (key >= 0)
+ return SDL_GetKeyName(static_cast<SDLKey>(key));
- if (keyStr.empty())
- return _("unknown key");
- return keyStr;
-}
-
-std::string KeyboardConfig::getKeyValueString(int index) const
-{
- std::string keyStr;
-
- for (size_t i = 0; i < KeyFunctionSize; i ++)
- {
- const KeyItem &key = mKey[index].values[i];
- if (key.type == INPUT_KEYBOARD)
- {
- if (key.value >= 0)
- {
- if (keyStr.empty())
- {
- keyStr = getKeyShortString(SDL_GetKeyName(
- static_cast<SDLKey>(key.value)));
- }
- else
- {
- keyStr += " " + getKeyShortString(SDL_GetKeyName(
- static_cast<SDLKey>(key.value)));
- }
- }
- }
- }
-
- if (keyStr.empty())
- return _("u key");
- return keyStr;
+ return strprintf(_("key_%d"), key);
}
std::string KeyboardConfig::getKeyShortString(const std::string &key) const
@@ -353,59 +120,19 @@ SDLKey KeyboardConfig::getKeyFromEvent(const SDL_Event &event) const
return event.key.keysym.sym;
}
-void KeyboardConfig::setNewKey(const SDL_Event &event)
-{
- int idx = -1;
- KeyFunction &key = mKey[mNewKeyIndex];
- int val = getKeyValueFromEvent(event);
-
- for (size_t i = 0; i < KeyFunctionSize; i ++)
- {
- if (key.values[i].type == INPUT_UNKNOWN
- || (key.values[i].type == INPUT_KEYBOARD
- && key.values[i].value == val))
- {
- idx = i;
- break;
- }
- }
- if (idx == -1)
- {
- for (size_t i = 1; i < KeyFunctionSize; i ++)
- {
- key.values[i - 1].type = key.values[i].type;
- key.values[i - 1].value = key.values[i].value;
- }
- idx = KeyFunctionSize - 1;
- }
-
- key.values[idx] = KeyItem(INPUT_KEYBOARD, val);
- updateKeyActionMap();
-}
-
-void KeyboardConfig::unassignKey()
-{
- KeyFunction &key = mKey[mNewKeyIndex];
- for (size_t i = 0; i < KeyFunctionSize; i ++)
- {
- key.values[i].type = INPUT_UNKNOWN;
- key.values[i].value = -1;
- }
- updateKeyActionMap();
-}
-
void KeyboardConfig::updateKeyActionMap()
{
mKeyToAction.clear();
- for (size_t i = 0; i < Input::KEY_TOTAL; i++)
+ for (size_t i = 0; i < Input::KEY_TOTAL; i ++)
{
if (keyData[i].action)
{
+ KeyFunction &key = inputManager.getKey(i);
for (size_t i2 = 0; i2 < KeyFunctionSize; i2 ++)
{
- if (mKey[i].values[i2].type == INPUT_KEYBOARD)
- mKeyToAction[mKey[i].values[i2].value].push_back(i);
+ if (key.values[i2].type == INPUT_KEYBOARD)
+ mKeyToAction[key.values[i2].value].push_back(i);
}
}
}
@@ -452,3 +179,17 @@ bool KeyboardConfig::triggerAction(const SDL_Event &event)
}
return false;
}
+
+bool KeyboardConfig::isActionActive(int index) const
+{
+ if (!mActiveKeys)
+ return false;
+
+ for (size_t i = 0; i < KeyFunctionSize; i ++)
+ {
+ const int value = inputManager.getKey(index).values[i].value;
+ if (value >= 0 && mActiveKeys[value])
+ return true;
+ }
+ return false;
+}
diff --git a/src/keyboardconfig.h b/src/keyboardconfig.h
index 79719518b..3f3e5f95d 100644
--- a/src/keyboardconfig.h
+++ b/src/keyboardconfig.h
@@ -42,39 +42,6 @@ typedef KeysVector::const_iterator KeysVectorCIter;
typedef std::map<int, KeysVector> KeyToActionMap;
typedef KeyToActionMap::iterator KeyToActionMapIter;
-enum KeyTypes
-{
- INPUT_UNKNOWN = 0,
- INPUT_KEYBOARD = 1,
- INPUT_MOUSE = 2,
- INPUT_JOYSTICK = 3
-};
-
-struct KeyItem
-{
- KeyItem() : type(-1), value(-1)
- { }
-
- KeyItem(int type0, int value0) : type(type0), value(value0)
- { }
-
- int type;
-
- int value;
-};
-
-#define KeyFunctionSize 3
-
-/**
- * Each key represents a key function. Such as 'Move up', 'Attack' etc.
- */
-struct KeyFunction
-{
- KeyItem values[KeyFunctionSize];
-};
-
-class Setup_Keyboard;
-
class KeyboardConfig
{
public:
@@ -84,37 +51,6 @@ class KeyboardConfig
void init();
/**
- * Retrieve the key values from config file.
- */
- void retrieve();
-
- /**
- * Store the key values to config file.
- */
- void store();
-
- /**
- * Make the keys their default values.
- */
- void makeDefault();
-
- /**
- * Determines if any key assignments are the same as each other.
- */
- bool hasConflicts(int &key1, int &key2);
-
- /**
- * Calls a function back so the key re-assignment(s) can be seen.
- */
- void callbackNewKey();
-
- /**
- * Get the index of the new key to be assigned.
- */
- int getNewKeyIndex() const
- { return mNewKeyIndex; }
-
- /**
* Get the enable flag, which will stop the user from doing actions.
*/
bool isEnabled() const
@@ -132,55 +68,26 @@ class KeyboardConfig
{ mEnabled = flag; }
/**
- * Set the index of the new key to be assigned.
- */
- void setNewKeyIndex(int value)
- { mNewKeyIndex = value; }
-
- /**
- * Set the value of the new key.
- */
- void setNewKey(const SDL_Event &event);
-
- /**
- * Set a reference to the key setup window.
- */
- void setSetupKeyboard(Setup_Keyboard *setupKey)
- { mSetupKey = setupKey; }
-
- /**
- * Checks if the key is active, by providing the key function index.
- */
- bool isActionActive(int index) const;
-
- /**
* Takes a snapshot of all the active keys.
*/
void refreshActiveKeys();
- std::string getKeyValueString(int index) const;
-
std::string getKeyShortString(const std::string &key) const;
- std::string getKeyStringLong(int index) const;
-
SDLKey getKeyFromEvent(const SDL_Event &event) const;
int getKeyValueFromEvent(const SDL_Event &event) const;
- void unassignKey();
-
void updateKeyActionMap();
bool triggerAction(const SDL_Event &event);
- private:
- int mNewKeyIndex; /**< Index of new key to be assigned */
- bool mEnabled; /**< Flag to respond to key input */
+ std::string getKeyName(int key);
- Setup_Keyboard *mSetupKey; /**< Reference to setup window */
+ bool isActionActive(int index) const;
- KeyFunction mKey[Input::KEY_TOTAL]; /**< Pointer to all the key data */
+ private:
+ bool mEnabled; /**< Flag to respond to key input */
Uint8 *mActiveKeys; /**< Stores a list of all the keys */
diff --git a/src/keydata.h b/src/keydata.h
index 8f918b667..993bae74e 100644
--- a/src/keydata.h
+++ b/src/keydata.h
@@ -27,6 +27,8 @@
#include <string>
+typedef bool (*ActionFuncPtr) (InputEvent &event);
+
struct KeyData
{
const char *configField;
diff --git a/src/net/ea/beinghandler.cpp b/src/net/ea/beinghandler.cpp
index f669163be..0c928f9fe 100644
--- a/src/net/ea/beinghandler.cpp
+++ b/src/net/ea/beinghandler.cpp
@@ -30,6 +30,7 @@
#include "effectmanager.h"
#include "guild.h"
#include "guildmanager.h"
+#include "inputmanager.h"
#include "keyboardconfig.h"
#include "localplayer.h"
#include "logger.h"