From 0b7e752bd177c90a05ca752fa31810f9e34c432c Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Thu, 19 Apr 2012 23:48:29 +0300 Subject: Dehardcode keys in gui widgets. Add new tab with keys settings in input settings tab. --- src/client.cpp | 10 +- src/gui/charselectdialog.cpp | 7 +- src/gui/chatwindow.cpp | 18 +-- src/gui/editserverdialog.cpp | 9 +- src/gui/gui.cpp | 5 +- src/gui/inventorywindow.cpp | 27 ++-- src/gui/logindialog.cpp | 15 ++- src/gui/quitdialog.cpp | 15 ++- src/gui/sdlinput.cpp | 8 +- src/gui/serverdialog.cpp | 13 +- src/gui/setup_input.cpp | 27 +++- src/gui/setup_input.h | 2 + src/gui/setupactiondata.h | 113 +++++++++++++++-- src/gui/updaterwindow.cpp | 9 +- src/gui/widgets/button.cpp | 10 +- src/gui/widgets/checkbox.cpp | 7 +- src/gui/widgets/dropdown.cpp | 48 ++++--- src/gui/widgets/guitable.cpp | 18 +-- src/gui/widgets/inttextfield.cpp | 10 +- src/gui/widgets/itemcontainer.cpp | 35 ------ src/gui/widgets/listbox.cpp | 16 +-- src/gui/widgets/radiobutton.cpp | 7 +- src/gui/widgets/slider.cpp | 12 +- src/gui/widgets/tabbedarea.cpp | 19 ++- src/gui/widgets/textbox.cpp | 259 +++++++++++++++++++++----------------- src/gui/widgets/textfield.cpp | 130 ++++++++++++++----- src/gui/worldselectdialog.cpp | 9 +- src/inputmanager.cpp | 6 +- src/keyboarddata.h | 130 ++++++++++++++++--- src/keydata.h | 21 +++- 30 files changed, 684 insertions(+), 331 deletions(-) (limited to 'src') diff --git a/src/client.cpp b/src/client.cpp index f068e4304..077b195c1 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -863,7 +863,15 @@ int Client::gameExec() break; case SDL_KEYDOWN: - inputManager.handleAssignKey(event, INPUT_KEYBOARD); + if (inputManager.handleAssignKey(event, INPUT_KEYBOARD)) + continue; + inputManager.updateConditionMask(); + break; + + case SDL_KEYUP: + if (inputManager.handleAssignKey(event, INPUT_KEYBOARD)) + continue; + inputManager.updateConditionMask(); break; case SDL_JOYBUTTONDOWN: diff --git a/src/gui/charselectdialog.cpp b/src/gui/charselectdialog.cpp index b1b8009a4..a148376fb 100644 --- a/src/gui/charselectdialog.cpp +++ b/src/gui/charselectdialog.cpp @@ -26,6 +26,8 @@ #include "game.h" #include "localplayer.h" #include "units.h" +#include "keydata.h" +#include "keyevent.h" #include "logger.h" #include "gui/changeemaildialog.h" @@ -261,9 +263,8 @@ void CharSelectDialog::action(const gcn::ActionEvent &event) void CharSelectDialog::keyPressed(gcn::KeyEvent &keyEvent) { - gcn::Key key = keyEvent.getKey(); - - if (key.getValue() == Key::ESCAPE) + if (static_cast(&keyEvent)->getActionId() + == Input::KEY_GUI_CANCEL) { action(gcn::ActionEvent(mSwitchLoginButton, mSwitchLoginButton->getActionEventId())); diff --git a/src/gui/chatwindow.cpp b/src/gui/chatwindow.cpp index 3832e5850..a91a8fc82 100644 --- a/src/gui/chatwindow.cpp +++ b/src/gui/chatwindow.cpp @@ -28,7 +28,8 @@ #include "configuration.h" #include "guild.h" #include "inputmanager.h" -#include "keyboardconfig.h" +#include "keydata.h" +#include "keyevent.h" #include "localplayer.h" #include "party.h" #include "playerinfo.h" @@ -742,7 +743,8 @@ void ChatWindow::mouseReleased(gcn::MouseEvent &event A_UNUSED) void ChatWindow::keyPressed(gcn::KeyEvent &event) { const int key = event.getKey().getValue(); - if (key == Key::DOWN) + int actionId = static_cast(&event)->getActionId(); + if (actionId == Input::KEY_GUI_DOWN) { if (mCurHist != mHistory.end()) { @@ -766,7 +768,7 @@ void ChatWindow::keyPressed(gcn::KeyEvent &event) mChatInput->setText(""); } } - else if (key == Key::UP && + else if (actionId == Input::KEY_GUI_UP && mCurHist != mHistory.begin() && !mHistory.empty()) { // Move backward through the history @@ -775,7 +777,7 @@ void ChatWindow::keyPressed(gcn::KeyEvent &event) mChatInput->setCaretPosition(static_cast( mChatInput->getText().length())); } - else if (key == Key::INSERT && + else if (actionId == Input::KEY_GUI_INSERT && mChatInput->getText() != "") { // Add the current message to the history and clear the text @@ -784,18 +786,18 @@ void ChatWindow::keyPressed(gcn::KeyEvent &event) mCurHist = mHistory.end(); mChatInput->setText(""); } - else if (inputManager.isActionActive(Input::KEY_AUTOCOMPLETE_CHAT) && + else if (actionId == Input::KEY_GUI_TAB && mChatInput->getText() != "") { autoComplete(); return; } - else if (inputManager.isActionActive(Input::KEY_DEACTIVATE_CHAT) && + else if (actionId == Input::KEY_GUI_CANCEL && mChatInput->isVisible()) { mChatInput->processVisible(false); } - else if (inputManager.isActionActive(Input::KEY_CHAT_PREV_HISTORY) && + else if (actionId == Input::KEY_CHAT_PREV_HISTORY && mChatInput->isVisible()) { ChatTab *tab = getFocused(); @@ -827,7 +829,7 @@ void ChatWindow::keyPressed(gcn::KeyEvent &event) mChatInput->getText().length())); } } - else if (inputManager.isActionActive(Input::KEY_CHAT_NEXT_HISTORY) && + else if (actionId == Input::KEY_CHAT_NEXT_HISTORY && mChatInput->isVisible()) { ChatTab *tab = getFocused(); diff --git a/src/gui/editserverdialog.cpp b/src/gui/editserverdialog.cpp index ca1afeaba..b52559ecc 100644 --- a/src/gui/editserverdialog.cpp +++ b/src/gui/editserverdialog.cpp @@ -22,6 +22,8 @@ #include "gui/editserverdialog.h" #include "configuration.h" +#include "keydata.h" +#include "keyevent.h" #include "gui/okdialog.h" #include "gui/sdlinput.h" @@ -227,13 +229,14 @@ void EditServerDialog::action(const gcn::ActionEvent &event) void EditServerDialog::keyPressed(gcn::KeyEvent &keyEvent) { - gcn::Key key = keyEvent.getKey(); + int actionId = static_cast(&keyEvent)->getActionId(); - if (key.getValue() == Key::ESCAPE) + if (actionId == Input::KEY_GUI_CANCEL) { scheduleDelete(); } - else if (key.getValue() == Key::ENTER) + else if (actionId == Input::KEY_GUI_SELECT + || actionId == Input::KEY_GUI_SELECT2) { action(gcn::ActionEvent(nullptr, mOkButton->getActionEventId())); } diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index 61e434d77..1536feb68 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -24,9 +24,9 @@ #include "gui/focushandler.h" #include "gui/palette.h" +#include "gui/sdlfont.h" #include "gui/sdlinput.h" #include "gui/theme.h" -#include "gui/sdlfont.h" #include "gui/widgets/mouseevent.h" #include "gui/widgets/window.h" @@ -35,6 +35,7 @@ #include "configlistener.h" #include "configuration.h" #include "graphics.h" +#include "keydata.h" #include "keyevent.h" #include "keyinput.h" #include "logger.h" @@ -343,7 +344,7 @@ bool Gui::handleKeyInput2() // tabbing is enable check for tab press and // change focus. if (!keyEventConsumed && mTabbing - && keyInput.getKey().getValue() == Key::TAB + && keyInput.getActionId() == Input::KEY_GUI_TAB && keyInput.getType() == gcn::KeyInput::PRESSED) { if (keyInput.isShiftPressed()) diff --git a/src/gui/inventorywindow.cpp b/src/gui/inventorywindow.cpp index 425130b57..5fe44f2bd 100644 --- a/src/gui/inventorywindow.cpp +++ b/src/gui/inventorywindow.cpp @@ -25,10 +25,11 @@ #include "configuration.h" #include "inventory.h" #include "item.h" -#include "units.h" #include "inputmanager.h" -#include "keyboardconfig.h" +#include "keydata.h" +#include "keyevent.h" #include "playerinfo.h" +#include "units.h" #include "gui/itemamountwindow.h" #include "gui/setup.h" @@ -473,28 +474,14 @@ void InventoryWindow::mouseClicked(gcn::MouseEvent &event) void InventoryWindow::keyPressed(gcn::KeyEvent &event) { - switch (event.getKey().getValue()) - { - case Key::LEFT_SHIFT: - case Key::RIGHT_SHIFT: - mSplit = true; - break; - default: - break; - } + if (static_cast(&event)->getActionId() == Input::KEY_GUI_MOD) + mSplit = true; } void InventoryWindow::keyReleased(gcn::KeyEvent &event) { - switch (event.getKey().getValue()) - { - case Key::LEFT_SHIFT: - case Key::RIGHT_SHIFT: - mSplit = false; - break; - default: - break; - } + if (static_cast(&event)->getActionId() == Input::KEY_GUI_MOD) + mSplit = false; } void InventoryWindow::valueChanged(const gcn::SelectionEvent &event A_UNUSED) diff --git a/src/gui/logindialog.cpp b/src/gui/logindialog.cpp index e089c53fa..63073e9d5 100644 --- a/src/gui/logindialog.cpp +++ b/src/gui/logindialog.cpp @@ -24,6 +24,8 @@ #include "client.h" #include "configuration.h" +#include "keydata.h" +#include "keyevent.h" #include "gui/okdialog.h" #include "gui/sdlinput.h" @@ -312,14 +314,21 @@ void LoginDialog::action(const gcn::ActionEvent &event) void LoginDialog::keyPressed(gcn::KeyEvent &keyEvent) { - gcn::Key key = keyEvent.getKey(); + int actionId = static_cast(&keyEvent)->getActionId(); - if (key.getValue() == Key::ESCAPE) + if (actionId == Input::KEY_GUI_CANCEL) + { action(gcn::ActionEvent(nullptr, mServerButton->getActionEventId())); - else if (key.getValue() == Key::ENTER) + } + else if (actionId == Input::KEY_GUI_SELECT + || actionId == Input::KEY_GUI_SELECT2) + { action(gcn::ActionEvent(nullptr, mLoginButton->getActionEventId())); + } else + { mLoginButton->setEnabled(canSubmit()); + } } bool LoginDialog::canSubmit() const diff --git a/src/gui/quitdialog.cpp b/src/gui/quitdialog.cpp index a0f734adf..51458cb08 100644 --- a/src/gui/quitdialog.cpp +++ b/src/gui/quitdialog.cpp @@ -23,6 +23,8 @@ #include "gui/quitdialog.h" #include "client.h" +#include "keydata.h" +#include "keyevent.h" #include "gui/chatwindow.h" #include "gui/npcdialog.h" @@ -157,22 +159,23 @@ void QuitDialog::action(const gcn::ActionEvent &event) void QuitDialog::keyPressed(gcn::KeyEvent &keyEvent) { - const gcn::Key &key = keyEvent.getKey(); + int actionId = static_cast(&keyEvent)->getActionId(); int dir = 0; - switch (key.getValue()) + switch (actionId) { - case Key::ENTER: + case Input::KEY_GUI_SELECT: + case Input::KEY_GUI_SELECT2: action(gcn::ActionEvent(nullptr, mOkButton->getActionEventId())); break; - case Key::ESCAPE: + case Input::KEY_GUI_CANCEL: action(gcn::ActionEvent(nullptr, mCancelButton->getActionEventId())); break; - case Key::UP: + case Input::KEY_GUI_UP: dir = -1; break; - case Key::DOWN: + case Input::KEY_GUI_DOWN: dir = 1; break; default: diff --git a/src/gui/sdlinput.cpp b/src/gui/sdlinput.cpp index 94519469b..6828158d2 100644 --- a/src/gui/sdlinput.cpp +++ b/src/gui/sdlinput.cpp @@ -127,7 +127,7 @@ void SDLInput::pushInput(const SDL_Event &event) keyInput.setMetaPressed(event.key.keysym.mod & KMOD_META); keyInput.setNumericPad(event.key.keysym.sym >= SDLK_KP0 && event.key.keysym.sym <= SDLK_KP_EQUALS); - int actionId = inputManager.getActionByKey(event); + const int actionId = inputManager.getActionByKey(event); if (actionId >= 0) keyInput.setActionId(actionId); mKeyInputQueue.push(keyInput); @@ -135,6 +135,7 @@ void SDLInput::pushInput(const SDL_Event &event) } case SDL_KEYUP: + { keyInput.setKey(gcn::Key(convertKeyCharacter(event))); keyInput.setType(gcn::KeyInput::RELEASED); keyInput.setShiftPressed(event.key.keysym.mod & KMOD_SHIFT); @@ -143,9 +144,12 @@ void SDLInput::pushInput(const SDL_Event &event) keyInput.setMetaPressed(event.key.keysym.mod & KMOD_META); keyInput.setNumericPad(event.key.keysym.sym >= SDLK_KP0 && event.key.keysym.sym <= SDLK_KP_EQUALS); - + const int actionId = inputManager.getActionByKey(event); + if (actionId >= 0) + keyInput.setActionId(actionId); mKeyInputQueue.push(keyInput); break; + } case SDL_MOUSEBUTTONDOWN: mMouseDown = true; diff --git a/src/gui/serverdialog.cpp b/src/gui/serverdialog.cpp index bae1154e3..cde56875f 100644 --- a/src/gui/serverdialog.cpp +++ b/src/gui/serverdialog.cpp @@ -25,6 +25,8 @@ #include "chatlogger.h" #include "client.h" #include "configuration.h" +#include "keydata.h" +#include "keyevent.h" #include "logger.h" #include "main.h" @@ -396,12 +398,17 @@ void ServerDialog::action(const gcn::ActionEvent &event) void ServerDialog::keyPressed(gcn::KeyEvent &keyEvent) { - gcn::Key key = keyEvent.getKey(); + int actionId = static_cast(&keyEvent)->getActionId(); - if (key.getValue() == Key::ESCAPE) + if (actionId == Input::KEY_GUI_CANCEL) + { Client::setState(STATE_EXIT); - else if (key.getValue() == Key::ENTER) + } + else if (actionId == Input::KEY_GUI_SELECT + || actionId == Input::KEY_GUI_SELECT2) + { action(gcn::ActionEvent(nullptr, mConnectButton->getActionEventId())); + } } void ServerDialog::valueChanged(const gcn::SelectionEvent &) diff --git a/src/gui/setup_input.cpp b/src/gui/setup_input.cpp index 3c512ecc9..3bbdfcee4 100644 --- a/src/gui/setup_input.cpp +++ b/src/gui/setup_input.cpp @@ -46,6 +46,8 @@ #include "debug.h" +const int setupGroups = 9; + /** * The list model for key function list. * @@ -100,9 +102,9 @@ Setup_Input::Setup_Input(): setName(_("Input")); selectedData = 0; - mActionDataSize = new int [8]; + mActionDataSize = new int [9]; - for (int f = 0; f < 8; f ++) + for (int f = 0; f < setupGroups; f ++) { int cnt = 0; while (!setupActionData[f][cnt].name.empty()) @@ -179,14 +181,13 @@ void Setup_Input::apply() if (inputManager.hasConflicts(key1, key2)) { - int s1 = keyToSetupData(key1); - int s2 = keyToSetupData(key2); + std::string str1 = keyToString(key1); + std::string str2 = keyToString(key2); new OkDialog(_("Key Conflict(s) Detected."), strprintf(_("Conflict \"%s\" and \"%s\" keys. " "Resolve them, or gameplay may result in strange behaviour."), - setupActionData[selectedData][s1].name.c_str(), - setupActionData[selectedData][s2].name.c_str()), DIALOG_ERROR); + str1.c_str(), str2.c_str()), DIALOG_ERROR); } keyboard.setEnabled(true); inputManager.store(); @@ -331,6 +332,20 @@ int Setup_Input::keyToSetupData(int index) return -1; } +std::string Setup_Input::keyToString(int index) +{ + for (int f = 0; f < setupGroups; f ++) + { + for (int i = 0; i < mActionDataSize[f]; i++) + { + const SetupActionData &key = setupActionData[f][i]; + if (key.actionId == index) + return key.name; + } + } + return _("unknown"); +} + void Setup_Input::refreshKeys() { for (int i = 0; i < mActionDataSize[selectedData]; i++) diff --git a/src/gui/setup_input.h b/src/gui/setup_input.h index aacdba366..645f6f6a5 100644 --- a/src/gui/setup_input.h +++ b/src/gui/setup_input.h @@ -77,6 +77,8 @@ class Setup_Input : public SetupTab int keyToSetupData(int index); + std::string keyToString(int index); + private: class KeyListModel *mKeyListModel; gcn::ListBox *mKeyList; diff --git a/src/gui/setupactiondata.h b/src/gui/setupactiondata.h index af0b25cfb..1403f1f5b 100644 --- a/src/gui/setupactiondata.h +++ b/src/gui/setupactiondata.h @@ -994,16 +994,6 @@ static SetupActionData setupActionData5[] = Input::KEY_CHAT_NEXT_HISTORY, "", }, - { - N_("Chat Auto Complete"), - Input::KEY_AUTOCOMPLETE_CHAT, - "", - }, - { - N_("Deactivate Chat Input"), - Input::KEY_DEACTIVATE_CHAT, - "", - }, { "", Input::KEY_NO_VALUE, @@ -1434,6 +1424,105 @@ static SetupActionData setupActionData7[] = } }; +static SetupActionData setupActionData8[] = +{ + { + N_("Move selecttion"), + Input::KEY_NO_VALUE, + "", + }, + { + N_("Move Up"), + Input::KEY_GUI_UP, + "", + }, + { + N_("Move Down"), + Input::KEY_GUI_DOWN, + "", + }, + { + N_("Move Left"), + Input::KEY_GUI_LEFT, + "", + }, + { + N_("Move Right"), + Input::KEY_GUI_RIGHT, + "", + }, + { + N_("Move Home"), + Input::KEY_GUI_HOME, + "", + }, + { + N_("Move End"), + Input::KEY_GUI_END, + "", + }, + { + N_("Page up"), + Input::KEY_GUI_PAGE_UP, + "", + }, + { + N_("Page down"), + Input::KEY_GUI_PAGE_DOWN, + "", + }, + { + N_("Other"), + Input::KEY_NO_VALUE, + "", + }, + { + N_("Select"), + Input::KEY_GUI_SELECT, + "", + }, + { + N_("Select2"), + Input::KEY_GUI_SELECT2, + "", + }, + { + N_("Cancel"), + Input::KEY_GUI_CANCEL, + "", + }, + { + N_("Delete"), + Input::KEY_GUI_DELETE, + "", + }, + { + N_("Backspace"), + Input::KEY_GUI_BACKSPACE, + "", + }, + { + N_("Insert"), + Input::KEY_GUI_INSERT, + "", + }, + { + N_("Tab"), + Input::KEY_GUI_TAB, + "", + }, + { + N_("Mod"), + Input::KEY_GUI_MOD, + "", + }, + { + "", + Input::KEY_NO_VALUE, + "" + } +}; + static SetupActionData *setupActionData[] = { setupActionData0, @@ -1443,7 +1532,8 @@ static SetupActionData *setupActionData[] = setupActionData3, setupActionData4, setupActionData5, - setupActionData6 + setupActionData6, + setupActionData8 }; static const char *pages[] = @@ -1456,6 +1546,7 @@ static const char *pages[] = N_("Outfits"), N_("Chat"), N_("Other"), + N_("Gui"), nullptr }; diff --git a/src/gui/updaterwindow.cpp b/src/gui/updaterwindow.cpp index e6ad1818e..a1c625c32 100644 --- a/src/gui/updaterwindow.cpp +++ b/src/gui/updaterwindow.cpp @@ -24,6 +24,8 @@ #include "client.h" #include "configuration.h" +#include "keydata.h" +#include "keyevent.h" #include "logger.h" #include "main.h" @@ -258,14 +260,15 @@ void UpdaterWindow::action(const gcn::ActionEvent &event) void UpdaterWindow::keyPressed(gcn::KeyEvent &keyEvent) { - gcn::Key key = keyEvent.getKey(); + int actionId = static_cast(&keyEvent)->getActionId(); - if (key.getValue() == Key::ESCAPE) + if (actionId == Input::KEY_GUI_CANCEL) { action(gcn::ActionEvent(nullptr, mCancelButton->getActionEventId())); Client::setState(STATE_LOGIN); } - else if (key.getValue() == Key::ENTER) + else if (actionId == Input::KEY_GUI_SELECT + || actionId == Input::KEY_GUI_SELECT2) { if (mDownloadStatus == UPDATE_COMPLETE || mDownloadStatus == UPDATE_ERROR) diff --git a/src/gui/widgets/button.cpp b/src/gui/widgets/button.cpp index 88d9311b9..15af963b0 100644 --- a/src/gui/widgets/button.cpp +++ b/src/gui/widgets/button.cpp @@ -26,6 +26,8 @@ #include "configuration.h" #include "graphics.h" #include "graphicsvertexes.h" +#include "keydata.h" +#include "keyevent.h" #include "logger.h" #include "gui/palette.h" @@ -462,9 +464,9 @@ void Button::setCaption(const std::string& caption) void Button::keyPressed(gcn::KeyEvent& keyEvent) { - gcn::Key key = keyEvent.getKey(); + int action = static_cast(&keyEvent)->getActionId(); - if (key.getValue() == gcn::Key::SPACE) + if (action == Input::KEY_GUI_SELECT) { mKeyPressed = true; keyEvent.consume(); @@ -473,9 +475,9 @@ void Button::keyPressed(gcn::KeyEvent& keyEvent) void Button::keyReleased(gcn::KeyEvent& keyEvent) { - gcn::Key key = keyEvent.getKey(); + int action = static_cast(&keyEvent)->getActionId(); - if (key.getValue() == gcn::Key::SPACE && mKeyPressed) + if (action == Input::KEY_GUI_SELECT && mKeyPressed) { mKeyPressed = false; if (mStick) diff --git a/src/gui/widgets/checkbox.cpp b/src/gui/widgets/checkbox.cpp index f599e7831..133a5da1d 100644 --- a/src/gui/widgets/checkbox.cpp +++ b/src/gui/widgets/checkbox.cpp @@ -25,6 +25,8 @@ #include "client.h" #include "configuration.h" #include "graphics.h" +#include "keydata.h" +#include "keyevent.h" #include "gui/palette.h" #include "gui/theme.h" @@ -193,10 +195,9 @@ void CheckBox::mouseExited(gcn::MouseEvent& event A_UNUSED) void CheckBox::keyPressed(gcn::KeyEvent& keyEvent) { - gcn::Key key = keyEvent.getKey(); + int action = static_cast(&keyEvent)->getActionId(); - if (key.getValue() == gcn::Key::ENTER || - key.getValue() == gcn::Key::SPACE) + if (action == Input::KEY_GUI_SELECT) { toggleSelected(); keyEvent.consume(); diff --git a/src/gui/widgets/dropdown.cpp b/src/gui/widgets/dropdown.cpp index 91c983f26..5ecfba84d 100644 --- a/src/gui/widgets/dropdown.cpp +++ b/src/gui/widgets/dropdown.cpp @@ -25,6 +25,8 @@ #include "client.h" #include "configuration.h" #include "graphics.h" +#include "keydata.h" +#include "keyevent.h" #include "gui/palette.h" #include "gui/sdlinput.h" @@ -233,20 +235,38 @@ void DropDown::keyPressed(gcn::KeyEvent& keyEvent) if (keyEvent.isConsumed()) return; - gcn::Key key = keyEvent.getKey(); - - if (key.getValue() == Key::ENTER || key.getValue() == Key::SPACE) - dropDown(); - else if (key.getValue() == Key::UP) - setSelected(getSelected() - 1); - else if (key.getValue() == Key::DOWN) - setSelected(getSelected() + 1); - else if (key.getValue() == Key::HOME) - setSelected(0); - else if (key.getValue() == Key::END && mListBox->getListModel()) - setSelected(mListBox->getListModel()->getNumberOfElements() - 1); - else - return; + int actionId = static_cast(&keyEvent)->getActionId(); + + switch(actionId) + { + case Input::KEY_GUI_SELECT: + case Input::KEY_GUI_SELECT2: + dropDown(); + break; + + case Input::KEY_GUI_UP: + setSelected(getSelected() - 1); + break; + + case Input::KEY_GUI_DOWN: + setSelected(getSelected() + 1); + break; + + case Input::KEY_GUI_HOME: + setSelected(0); + break; + + case Input::KEY_GUI_END: + if (mListBox->getListModel()) + { + setSelected(mListBox->getListModel()-> + getNumberOfElements() - 1); + } + break; + + default: + return; + } keyEvent.consume(); } diff --git a/src/gui/widgets/guitable.cpp b/src/gui/widgets/guitable.cpp index 6434f5453..910ee1910 100644 --- a/src/gui/widgets/guitable.cpp +++ b/src/gui/widgets/guitable.cpp @@ -24,6 +24,8 @@ #include "client.h" #include "configuration.h" +#include "keyevent.h" +#include "keydata.h" #include "gui/sdlinput.h" #include "gui/theme.h" @@ -403,40 +405,40 @@ gcn::Rectangle GuiTable::getChildrenArea() // -- KeyListener notifications void GuiTable::keyPressed(gcn::KeyEvent& keyEvent) { - gcn::Key key = keyEvent.getKey(); + int action = static_cast(&keyEvent)->getActionId(); - if (key.getValue() == Key::ENTER || key.getValue() == Key::SPACE) + if (action == Input::KEY_GUI_SELECT) { distributeActionEvent(); keyEvent.consume(); } - else if (key.getValue() == Key::UP) + else if (action == Input::KEY_GUI_UP) { setSelectedRow(mSelectedRow - 1); keyEvent.consume(); } - else if (key.getValue() == Key::DOWN) + else if (action == Input::KEY_GUI_DOWN) { setSelectedRow(mSelectedRow + 1); keyEvent.consume(); } - else if (key.getValue() == Key::LEFT) + else if (action == Input::KEY_GUI_LEFT) { setSelectedColumn(mSelectedColumn - 1); keyEvent.consume(); } - else if (key.getValue() == Key::RIGHT) + else if (action == Input::KEY_GUI_RIGHT) { setSelectedColumn(mSelectedColumn + 1); keyEvent.consume(); } - else if (key.getValue() == Key::HOME) + else if (action == Input::KEY_GUI_HOME) { setSelectedRow(0); setSelectedColumn(0); keyEvent.consume(); } - else if (key.getValue() == Key::END && mModel) + else if (action == Input::KEY_GUI_END && mModel) { setSelectedRow(mModel->getRows() - 1); setSelectedColumn(mModel->getColumns() - 1); diff --git a/src/gui/widgets/inttextfield.cpp b/src/gui/widgets/inttextfield.cpp index 8a075000b..fbc51ee3d 100644 --- a/src/gui/widgets/inttextfield.cpp +++ b/src/gui/widgets/inttextfield.cpp @@ -22,6 +22,9 @@ #include "gui/widgets/inttextfield.h" +#include "keydata.h" +#include "keyevent.h" + #include "gui/sdlinput.h" #include "utils/stringutils.h" @@ -44,10 +47,9 @@ IntTextField::IntTextField(int def, int min, int max, void IntTextField::keyPressed(gcn::KeyEvent &event) { - const gcn::Key &key = event.getKey(); + int action = static_cast(&event)->getActionId(); - if (key.getValue() == Key::BACKSPACE || - key.getValue() == Key::DELETE) + if (action == Input::KEY_GUI_DELETE || action == Input::KEY_GUI_BACKSPACE) { setText(std::string()); if (mSendAlwaysEvents) @@ -56,7 +58,7 @@ void IntTextField::keyPressed(gcn::KeyEvent &event) event.consume(); } - if (!key.isNumber()) + if (!event.getKey().isNumber()) return; TextField::keyPressed(event); diff --git a/src/gui/widgets/itemcontainer.cpp b/src/gui/widgets/itemcontainer.cpp index 6438f5deb..0aabcd297 100644 --- a/src/gui/widgets/itemcontainer.cpp +++ b/src/gui/widgets/itemcontainer.cpp @@ -337,45 +337,10 @@ void ItemContainer::hidePopup() void ItemContainer::keyPressed(gcn::KeyEvent &event A_UNUSED) { - /*switch (event.getKey().getValue()) - { - case Key::LEFT: - moveHighlight(Left); - break; - case Key::RIGHT: - moveHighlight(Right); - break; - case Key::UP: - moveHighlight(Up); - break; - case Key::DOWN: - moveHighlight(Down); - break; - case Key::SPACE: - keyAction(); - break; - case Key::LEFT_ALT: - case Key::RIGHT_ALT: - mSwapItems = true; - break; - case Key::RIGHT_CONTROL: - mDescItems = true; - break; - }*/ } void ItemContainer::keyReleased(gcn::KeyEvent &event A_UNUSED) { - /*switch (event.getKey().getValue()) - { - case Key::LEFT_ALT: - case Key::RIGHT_ALT: - mSwapItems = false; - break; - case Key::RIGHT_CONTROL: - mDescItems = false; - break; - }*/ } void ItemContainer::mousePressed(gcn::MouseEvent &event) diff --git a/src/gui/widgets/listbox.cpp b/src/gui/widgets/listbox.cpp index 2944c5be6..267f2c8cc 100644 --- a/src/gui/widgets/listbox.cpp +++ b/src/gui/widgets/listbox.cpp @@ -24,6 +24,8 @@ #include "client.h" #include "configuration.h" +#include "keyevent.h" +#include "keydata.h" #include "gui/palette.h" #include "gui/sdlinput.h" @@ -88,16 +90,16 @@ void ListBox::draw(gcn::Graphics *graphics) } } -void ListBox::keyPressed(gcn::KeyEvent& keyEvent) +void ListBox::keyPressed(gcn::KeyEvent &keyEvent) { - gcn::Key key = keyEvent.getKey(); + int action = static_cast(&keyEvent)->getActionId(); - if (key.getValue() == Key::ENTER || key.getValue() == Key::SPACE) + if (action == Input::KEY_GUI_SELECT) { distributeActionEvent(); keyEvent.consume(); } - else if (key.getValue() == Key::UP) + else if (action == Input::KEY_GUI_UP) { if (getSelected() > 0) setSelected(mSelected - 1); @@ -105,7 +107,7 @@ void ListBox::keyPressed(gcn::KeyEvent& keyEvent) setSelected(getListModel()->getNumberOfElements() - 1); keyEvent.consume(); } - else if (key.getValue() == Key::DOWN) + else if (action == Input::KEY_GUI_DOWN) { if (getSelected() < (getListModel()->getNumberOfElements() - 1)) { @@ -118,12 +120,12 @@ void ListBox::keyPressed(gcn::KeyEvent& keyEvent) } keyEvent.consume(); } - else if (key.getValue() == Key::HOME) + else if (action == Input::KEY_GUI_HOME) { setSelected(0); keyEvent.consume(); } - else if (key.getValue() == Key::END && getListModel()) + else if (action == Input::KEY_GUI_END && getListModel()) { setSelected(getListModel()->getNumberOfElements() - 1); keyEvent.consume(); diff --git a/src/gui/widgets/radiobutton.cpp b/src/gui/widgets/radiobutton.cpp index 4a9a912b1..e2a3483fc 100644 --- a/src/gui/widgets/radiobutton.cpp +++ b/src/gui/widgets/radiobutton.cpp @@ -25,6 +25,8 @@ #include "client.h" #include "configuration.h" #include "graphics.h" +#include "keydata.h" +#include "keyevent.h" #include "gui/theme.h" @@ -161,10 +163,9 @@ void RadioButton::mouseExited(gcn::MouseEvent& event A_UNUSED) void RadioButton::keyPressed(gcn::KeyEvent& keyEvent) { - gcn::Key key = keyEvent.getKey(); + int action = static_cast(&keyEvent)->getActionId(); - if (key.getValue() == gcn::Key::ENTER || - key.getValue() == gcn::Key::SPACE) + if (action == Input::KEY_GUI_SELECT) { setSelected(true); distributeActionEvent(); diff --git a/src/gui/widgets/slider.cpp b/src/gui/widgets/slider.cpp index 24a2a5128..69df4c289 100644 --- a/src/gui/widgets/slider.cpp +++ b/src/gui/widgets/slider.cpp @@ -25,6 +25,8 @@ #include "client.h" #include "configuration.h" #include "graphics.h" +#include "keyevent.h" +#include "keydata.h" #include "gui/theme.h" @@ -300,17 +302,17 @@ void Slider::mouseExited(gcn::MouseEvent& event A_UNUSED) void Slider::keyPressed(gcn::KeyEvent& keyEvent) { - gcn::Key key = keyEvent.getKey(); + int action = static_cast(&keyEvent)->getActionId(); if (getOrientation() == HORIZONTAL) { - if (key.getValue() == gcn::Key::RIGHT) + if (action == Input::KEY_GUI_RIGHT) { setValue(getValue() + getStepLength()); distributeActionEvent(); keyEvent.consume(); } - else if (key.getValue() == gcn::Key::LEFT) + else if (action == Input::KEY_GUI_LEFT) { setValue(getValue() - getStepLength()); distributeActionEvent(); @@ -319,13 +321,13 @@ void Slider::keyPressed(gcn::KeyEvent& keyEvent) } else { - if (key.getValue() == gcn::Key::UP) + if (action == Input::KEY_GUI_UP) { setValue(getValue() + getStepLength()); distributeActionEvent(); keyEvent.consume(); } - else if (key.getValue() == gcn::Key::DOWN) + else if (action == Input::KEY_GUI_DOWN) { setValue(getValue() - getStepLength()); distributeActionEvent(); diff --git a/src/gui/widgets/tabbedarea.cpp b/src/gui/widgets/tabbedarea.cpp index bb8ea063b..b24ae32e5 100644 --- a/src/gui/widgets/tabbedarea.cpp +++ b/src/gui/widgets/tabbedarea.cpp @@ -22,6 +22,9 @@ #include "gui/widgets/tabbedarea.h" +#include "keydata.h" +#include "keyevent.h" + #include "gui/widgets/scrollarea.h" #include "gui/widgets/tab.h" @@ -482,7 +485,9 @@ void TabbedArea::keyPressed(gcn::KeyEvent& keyEvent) if (keyEvent.isConsumed() || !isFocused()) return; - if (keyEvent.getKey().getValue() == gcn::Key::LEFT) + int actionId = static_cast(&keyEvent)->getActionId(); + + if (actionId == Input::KEY_GUI_LEFT) { int index = getSelectedTabIndex(); index--; @@ -494,7 +499,7 @@ void TabbedArea::keyPressed(gcn::KeyEvent& keyEvent) keyEvent.consume(); } - else if (keyEvent.getKey().getValue() == gcn::Key::RIGHT) + else if (actionId == Input::KEY_GUI_RIGHT) { int index = getSelectedTabIndex(); index++; @@ -507,13 +512,3 @@ void TabbedArea::keyPressed(gcn::KeyEvent& keyEvent) keyEvent.consume(); } } - -/* -void TabbedArea::moveLeft(gcn::Tab *tab) -{ -} - -void TabbedArea::moveRight(gcn::Tab *tab) -{ -} -*/ diff --git a/src/gui/widgets/textbox.cpp b/src/gui/widgets/textbox.cpp index 3f3c9fb9e..b40a7dcb1 100644 --- a/src/gui/widgets/textbox.cpp +++ b/src/gui/widgets/textbox.cpp @@ -22,6 +22,9 @@ #include "gui/widgets/textbox.h" +#include "keydata.h" +#include "keyevent.h" + #include "gui/theme.h" #include @@ -156,144 +159,176 @@ void TextBox::setTextWrapped(const std::string &text, int minDimension) void TextBox::keyPressed(gcn::KeyEvent& keyEvent) { gcn::Key key = keyEvent.getKey(); + int action = static_cast(&keyEvent)->getActionId(); - if (key.getValue() == gcn::Key::LEFT) + switch (action) { - --mCaretColumn; - if (mCaretColumn < 0) + case Input::KEY_GUI_LEFT: + { + --mCaretColumn; + if (mCaretColumn < 0) + { + --mCaretRow; + + if (mCaretRow < 0) + { + mCaretRow = 0; + mCaretColumn = 0; + } + else + { + mCaretColumn = mTextRows[mCaretRow].size(); + } + } + break; + } + + case Input::KEY_GUI_RIGHT: + { + ++mCaretColumn; + if (mCaretColumn > static_cast(mTextRows[mCaretRow].size())) + { + ++ mCaretRow; + + if (mCaretRow >= static_cast(mTextRows.size())) + { + mCaretRow = mTextRows.size() - 1; + if (mCaretRow < 0) + mCaretRow = 0; + + mCaretColumn = mTextRows[mCaretRow].size(); + } + else + { + mCaretColumn = 0; + } + } + break; + } + + case Input::KEY_GUI_DOWN: + { + setCaretRow(mCaretRow + 1); + break; + } + case Input::KEY_GUI_UP: + { + setCaretRow(mCaretRow - 1); + break; + } + case Input::KEY_GUI_HOME: + { + mCaretColumn = 0; + break; + } + case Input::KEY_GUI_END: { - --mCaretRow; + mCaretColumn = mTextRows[mCaretRow].size(); + break; + } - if (mCaretRow < 0) + case Input::KEY_GUI_SELECT2: + { + if (mEditable) { - mCaretRow = 0; + mTextRows.insert(mTextRows.begin() + mCaretRow + 1, + mTextRows[mCaretRow].substr(mCaretColumn, + mTextRows[mCaretRow].size() - mCaretColumn)); + mTextRows[mCaretRow].resize(mCaretColumn); + ++mCaretRow; mCaretColumn = 0; } - else + break; + } + + case Input::KEY_GUI_BACKSPACE: + { + if (mCaretColumn != 0 && mEditable) { - mCaretColumn = mTextRows[mCaretRow].size(); + mTextRows[mCaretRow].erase(mCaretColumn - 1, 1); + --mCaretColumn; } + else if (mCaretColumn == 0 && mCaretRow != 0 && mEditable) + { + mCaretColumn = mTextRows[mCaretRow - 1].size(); + mTextRows[mCaretRow - 1] += mTextRows[mCaretRow]; + mTextRows.erase(mTextRows.begin() + mCaretRow); + --mCaretRow; + } + break; } - } - else if (key.getValue() == gcn::Key::RIGHT) - { - ++mCaretColumn; - if (mCaretColumn > static_cast(mTextRows[mCaretRow].size())) + + case Input::KEY_GUI_DELETE: { - ++ mCaretRow; + if (mCaretColumn < static_cast( + mTextRows[mCaretRow].size()) && mEditable) + { + mTextRows[mCaretRow].erase(mCaretColumn, 1); + } + else if (mCaretColumn == static_cast( + mTextRows[mCaretRow].size()) && + mCaretRow < (static_cast(mTextRows.size()) - 1) && + mEditable) + { + mTextRows[mCaretRow] += mTextRows[mCaretRow + 1]; + mTextRows.erase(mTextRows.begin() + mCaretRow + 1); + } + break; + } + + case Input::KEY_GUI_PAGE_UP: + { + gcn::Widget* par = getParent(); - if (mCaretRow >= static_cast(mTextRows.size())) + if (par) { - mCaretRow = mTextRows.size() - 1; + int rowsPerPage = par->getChildrenArea().height + / getFont()->getHeight(); + mCaretRow -= rowsPerPage; + if (mCaretRow < 0) mCaretRow = 0; - - mCaretColumn = mTextRows[mCaretRow].size(); - } - else - { - mCaretColumn = 0; } + break; } - } - else if (key.getValue() == gcn::Key::DOWN) - { - setCaretRow(mCaretRow + 1); - } - else if (key.getValue() == gcn::Key::UP) - { - setCaretRow(mCaretRow - 1); - } - else if (key.getValue() == gcn::Key::HOME) - { - mCaretColumn = 0; - } - else if (key.getValue() == gcn::Key::END) - { - mCaretColumn = mTextRows[mCaretRow].size(); - } - else if (key.getValue() == gcn::Key::ENTER && mEditable) - { - mTextRows.insert(mTextRows.begin() + mCaretRow + 1, - mTextRows[mCaretRow].substr(mCaretColumn, - mTextRows[mCaretRow].size() - mCaretColumn)); - mTextRows[mCaretRow].resize(mCaretColumn); - ++mCaretRow; - mCaretColumn = 0; - } - else if (key.getValue() == gcn::Key::BACKSPACE - && mCaretColumn != 0 - && mEditable) - { - mTextRows[mCaretRow].erase(mCaretColumn - 1, 1); - --mCaretColumn; - } - else if (key.getValue() == gcn::Key::BACKSPACE - && mCaretColumn == 0 - && mCaretRow != 0 - && mEditable) - { - mCaretColumn = mTextRows[mCaretRow - 1].size(); - mTextRows[mCaretRow - 1] += mTextRows[mCaretRow]; - mTextRows.erase(mTextRows.begin() + mCaretRow); - --mCaretRow; - } - else if (key.getValue() == gcn::Key::DELETE - && mCaretColumn < static_cast( - mTextRows[mCaretRow].size()) && mEditable) - { - mTextRows[mCaretRow].erase(mCaretColumn, 1); - } - else if (key.getValue() == gcn::Key::DELETE - && mCaretColumn == static_cast( - mTextRows[mCaretRow].size()) - && mCaretRow < (static_cast(mTextRows.size()) - 1) - && mEditable) - { - mTextRows[mCaretRow] += mTextRows[mCaretRow + 1]; - mTextRows.erase(mTextRows.begin() + mCaretRow + 1); - } - else if (key.getValue() == gcn::Key::PAGE_UP) - { - gcn::Widget* par = getParent(); - if (par) + case Input::KEY_GUI_PAGE_DOWN: { - int rowsPerPage = par->getChildrenArea().height - / getFont()->getHeight(); - mCaretRow -= rowsPerPage; + gcn::Widget* par = getParent(); + + if (par) + { + int rowsPerPage = par->getChildrenArea().height + / getFont()->getHeight(); + mCaretRow += rowsPerPage; - if (mCaretRow < 0) - mCaretRow = 0; + if (mCaretRow >= static_cast(mTextRows.size())) + mCaretRow = mTextRows.size() - 1; + } + break; } - } - else if (key.getValue() == gcn::Key::PAGE_DOWN) - { - gcn::Widget* par = getParent(); - if (par) + case Input::KEY_GUI_TAB: { - int rowsPerPage = par->getChildrenArea().height - / getFont()->getHeight(); - mCaretRow += rowsPerPage; + if (mEditable) + { + mTextRows[mCaretRow].insert(mCaretColumn, std::string(" ")); + mCaretColumn += 4; + } + break; + } - if (mCaretRow >= static_cast(mTextRows.size())) - mCaretRow = mTextRows.size() - 1; + default: + { + if (key.isCharacter() && mEditable) + { + mTextRows[mCaretRow].insert(mCaretColumn, + std::string(1, static_cast(key.getValue()))); + ++ mCaretColumn; + } + break; } } - else if (key.getValue() == gcn::Key::TAB - && mEditable) - { - mTextRows[mCaretRow].insert(mCaretColumn, std::string(" ")); - mCaretColumn += 4; - } - else if (key.isCharacter() - && mEditable) - { - mTextRows[mCaretRow].insert(mCaretColumn, - std::string(1, static_cast(key.getValue()))); - ++ mCaretColumn; - } adjustSize(); scrollToCaret(); diff --git a/src/gui/widgets/textfield.cpp b/src/gui/widgets/textfield.cpp index 7892b3c0d..99cc93fd1 100644 --- a/src/gui/widgets/textfield.cpp +++ b/src/gui/widgets/textfield.cpp @@ -25,6 +25,8 @@ #include "client.h" #include "configuration.h" #include "graphics.h" +#include "keyevent.h" +#include "keydata.h" #include "logger.h" #include "gui/palette.h" @@ -241,10 +243,10 @@ void TextField::keyPressed(gcn::KeyEvent &keyEvent) if (val != 22) mLastEventPaste = 0; + bool consumed(false); switch (val) { case 2: // Ctrl+b - case Key::LEFT: { while (mCaretPosition > 0) { @@ -252,10 +254,11 @@ void TextField::keyPressed(gcn::KeyEvent &keyEvent) if ((mText[mCaretPosition] & 192) != 128) break; } - } break; + consumed = true; + break; + } case 6: // Ctrl+f - case Key::RIGHT: { unsigned sz = static_cast(mText.size()); while (mCaretPosition < sz) @@ -267,10 +270,11 @@ void TextField::keyPressed(gcn::KeyEvent &keyEvent) break; } } - } break; + consumed = true; + break; + } case 4: // Ctrl+d - case Key::DELETE: { unsigned sz = static_cast(mText.size()); while (mCaretPosition < sz) @@ -283,41 +287,24 @@ void TextField::keyPressed(gcn::KeyEvent &keyEvent) break; } } - } break; + consumed = true; + break; + } case 8: // Ctrl+h - case Key::BACKSPACE: deleteCharLeft(mText, &mCaretPosition); - break; - - case Key::ENTER: - distributeActionEvent(); - keyEvent.consume(); - fixScroll(); - return; - - case Key::HOME: - mCaretPosition = 0; - break; - - case Key::END: - mCaretPosition = static_cast(mText.size()); - break; - - case Key::TAB: - if (mLoseFocusOnTab) - return; + consumed = true; break; case 5: // Ctrl+e mCaretPosition = mText.size(); + consumed = true; break; case 11: // Ctrl+k mText = mText.substr(0, mCaretPosition); + consumed = true; break; -// case 16: // Ctrl+p -// break; case 21: // Ctrl+u if (mCaretPosition > 0) @@ -325,10 +312,12 @@ void TextField::keyPressed(gcn::KeyEvent &keyEvent) mText = mText.substr(mCaretPosition); mCaretPosition = 0; } + consumed = true; break; case 3: handleCopy(); + consumed = true; break; case 22: // Control code 22, SYNCHRONOUS IDLE, sent on Ctrl+v @@ -337,6 +326,7 @@ void TextField::keyPressed(gcn::KeyEvent &keyEvent) break; handlePaste(); mLastEventPaste = cur_time + 2; + consumed = true; break; case 23: // Ctrl+w @@ -349,6 +339,90 @@ void TextField::keyPressed(gcn::KeyEvent &keyEvent) break; } } + consumed = true; + break; + + default: + break; + } + + if (consumed) + { + if (mSendAlwaysEvents) + distributeActionEvent(); + + keyEvent.consume(); + fixScroll(); + return; + } + + int action = static_cast(&keyEvent)->getActionId(); + + switch (action) + { + case Input::KEY_GUI_LEFT: + { + while (mCaretPosition > 0) + { + --mCaretPosition; + if ((mText[mCaretPosition] & 192) != 128) + break; + } + break; + } + + case Input::KEY_GUI_RIGHT: + { + unsigned sz = static_cast(mText.size()); + while (mCaretPosition < sz) + { + ++mCaretPosition; + if (mCaretPosition == sz || + (mText[mCaretPosition] & 192) != 128) + { + break; + } + } + break; + } + + case Input::KEY_GUI_DELETE: + { + unsigned sz = static_cast(mText.size()); + while (mCaretPosition < sz) + { + --sz; + mText.erase(mCaretPosition, 1); + if (mCaretPosition == sz || + (mText[mCaretPosition] & 192) != 128) + { + break; + } + } + break; + } + + case Input::KEY_GUI_BACKSPACE: + deleteCharLeft(mText, &mCaretPosition); + break; + + case Input::KEY_GUI_SELECT2: + distributeActionEvent(); + keyEvent.consume(); + fixScroll(); + return; + + case Input::KEY_GUI_HOME: + mCaretPosition = 0; + break; + + case Input::KEY_GUI_END: + mCaretPosition = static_cast(mText.size()); + break; + + case Input::KEY_GUI_TAB: + if (mLoseFocusOnTab) + return; break; default: diff --git a/src/gui/worldselectdialog.cpp b/src/gui/worldselectdialog.cpp index 26fd19208..d1b97c82f 100644 --- a/src/gui/worldselectdialog.cpp +++ b/src/gui/worldselectdialog.cpp @@ -23,6 +23,8 @@ #include "gui/worldselectdialog.h" #include "client.h" +#include "keydata.h" +#include "keyevent.h" #include "gui/sdlinput.h" @@ -138,14 +140,15 @@ void WorldSelectDialog::action(const gcn::ActionEvent &event) void WorldSelectDialog::keyPressed(gcn::KeyEvent &keyEvent) { - gcn::Key key = keyEvent.getKey(); + int actionId = static_cast(&keyEvent)->getActionId(); - if (key.getValue() == Key::ESCAPE) + if (actionId == Input::KEY_GUI_CANCEL) { action(gcn::ActionEvent(nullptr, mChangeLoginButton->getActionEventId())); } - else if (key.getValue() == Key::ENTER) + else if (actionId == Input::KEY_GUI_SELECT + || actionId == Input::KEY_GUI_SELECT2) { action(gcn::ActionEvent(nullptr, mChooseWorld->getActionEventId())); } diff --git a/src/inputmanager.cpp b/src/inputmanager.cpp index fcb40d4ea..4617bed19 100644 --- a/src/inputmanager.cpp +++ b/src/inputmanager.cpp @@ -546,7 +546,7 @@ void InputManager::updateConditionMask() if (!setupWindow || !setupWindow->isVisible()) mMask += COND_NOSETUP; - if (Game::instance()->getValidSpeed()) + if (Game::instance() && Game::instance()->getValidSpeed()) mMask += COND_VALIDSPEED; if (gui && !gui->getFocusHandler()->getModalFocused()) @@ -607,7 +607,7 @@ void InputManager::updateKeyActionMap(KeyToActionMap &actionMap, actionMap[ki.value].push_back(i); } } - if (keyData[i].configField && (keyData[i].grp & Input::GRP_GUI)) + if (keyData[i].configField && (keyData[i].grp & Input::GRP_GUICHAN)) { for (size_t i2 = 0; i2 < KeyFunctionSize; i2 ++) { @@ -671,7 +671,7 @@ int InputManager::getKeyIndex(int value, int grp, int type) const int InputManager::getActionByKey(const SDL_Event &event) { // for now support only keyboard events - if (event.type == SDL_KEYDOWN) + if (event.type == SDL_KEYDOWN || event.type == SDL_KEYUP) { int idx = keyboard.getActionId(event); if (idx >= 0 && checkKey(&keyData[idx])) diff --git a/src/keyboarddata.h b/src/keyboarddata.h index 8c3df1878..856781391 100644 --- a/src/keyboarddata.h +++ b/src/keyboarddata.h @@ -1578,14 +1578,14 @@ static KeyData const keyData[Input::KEY_TOTAL] = { {"keyChatPrevTab", INPUT_KEYBOARD, SDLK_KP7, INPUT_UNKNOWN, Input::KEY_NO_VALUE, - Input::GRP_DEFAULT | Input::GRP_GUI, + Input::GRP_DEFAULT | Input::GRP_GUI | Input::GRP_GUICHAN, &ActionManager::prevChatTab, Input::KEY_NO_VALUE, 50, COND_NOINPUT}, {"keyChatNextTab", INPUT_KEYBOARD, SDLK_KP9, INPUT_UNKNOWN, Input::KEY_NO_VALUE, - Input::GRP_DEFAULT | Input::GRP_GUI, + Input::GRP_DEFAULT | Input::GRP_GUI | Input::GRP_GUICHAN, &ActionManager::nextChatTab, Input::KEY_NO_VALUE, 50, COND_NOINPUT}, @@ -1610,20 +1610,6 @@ static KeyData const keyData[Input::KEY_TOTAL] = { nullptr, Input::KEY_NO_VALUE, 50, COND_DEFAULT}, - {"keyAutoCompleteChat", - INPUT_KEYBOARD, SDLK_TAB, - INPUT_UNKNOWN, Input::KEY_NO_VALUE, - Input::GRP_CHAT, - nullptr, - Input::KEY_NO_VALUE, 50, - COND_DEFAULT}, - {"keyDeActivateChat", - INPUT_KEYBOARD, SDLK_ESCAPE, - INPUT_UNKNOWN, Input::KEY_NO_VALUE, - Input::GRP_CHAT, - nullptr, - Input::KEY_NO_VALUE, 50, - COND_DEFAULT}, {"keyIgnoreInput1", INPUT_KEYBOARD, SDLK_LSUPER, INPUT_UNKNOWN, Input::KEY_NO_VALUE, @@ -1812,6 +1798,118 @@ static KeyData const keyData[Input::KEY_TOTAL] = { Input::GRP_GUI, nullptr, Input::KEY_NO_VALUE, 50, + COND_DEFAULT}, + {"keyGUIUp", + INPUT_KEYBOARD, SDLK_UP, + INPUT_UNKNOWN, Input::KEY_NO_VALUE, + Input::GRP_GUICHAN, + nullptr, + Input::KEY_NO_VALUE, 50, + COND_DEFAULT}, + {"keyGUIDown", + INPUT_KEYBOARD, SDLK_DOWN, + INPUT_UNKNOWN, Input::KEY_NO_VALUE, + Input::GRP_GUICHAN, + nullptr, + Input::KEY_NO_VALUE, 50, + COND_DEFAULT}, + {"keyGUILeft", + INPUT_KEYBOARD, SDLK_LEFT, + INPUT_UNKNOWN, Input::KEY_NO_VALUE, + Input::GRP_GUICHAN, + nullptr, + Input::KEY_NO_VALUE, 50, + COND_DEFAULT}, + {"keyGUIRight", + INPUT_KEYBOARD, SDLK_RIGHT, + INPUT_UNKNOWN, Input::KEY_NO_VALUE, + Input::GRP_GUICHAN, + nullptr, + Input::KEY_NO_VALUE, 50, + COND_DEFAULT}, + {"keyGUISelect", + INPUT_KEYBOARD, SDLK_SPACE, + INPUT_UNKNOWN, Input::KEY_NO_VALUE, + Input::GRP_GUICHAN, + nullptr, + Input::KEY_NO_VALUE, 50, + COND_DEFAULT}, + {"keyGUISelect2", + INPUT_KEYBOARD, SDLK_RETURN, + INPUT_UNKNOWN, Input::KEY_NO_VALUE, + Input::GRP_GUICHAN, + nullptr, + Input::KEY_NO_VALUE, 50, + COND_DEFAULT}, + {"keyGUICancel", + INPUT_KEYBOARD, SDLK_ESCAPE, + INPUT_UNKNOWN, Input::KEY_NO_VALUE, + Input::GRP_GUICHAN, + nullptr, + Input::KEY_NO_VALUE, 50, + COND_DEFAULT}, + {"keyGUIHome", + INPUT_KEYBOARD, SDLK_HOME, + INPUT_UNKNOWN, Input::KEY_NO_VALUE, + Input::GRP_GUICHAN, + nullptr, + Input::KEY_NO_VALUE, 50, + COND_DEFAULT}, + {"keyGUIEnd", + INPUT_KEYBOARD, SDLK_END, + INPUT_UNKNOWN, Input::KEY_NO_VALUE, + Input::GRP_GUICHAN, + nullptr, + Input::KEY_NO_VALUE, 50, + COND_DEFAULT}, + {"keyGUIDelete", + INPUT_KEYBOARD, SDLK_DELETE, + INPUT_UNKNOWN, Input::KEY_NO_VALUE, + Input::GRP_GUICHAN, + nullptr, + Input::KEY_NO_VALUE, 50, + COND_DEFAULT}, + {"keyGUIBackSpace", + INPUT_KEYBOARD, SDLK_BACKSPACE, + INPUT_UNKNOWN, Input::KEY_NO_VALUE, + Input::GRP_GUICHAN, + nullptr, + Input::KEY_NO_VALUE, 50, + COND_DEFAULT}, + {"keyGUITab", + INPUT_KEYBOARD, SDLK_TAB, + INPUT_UNKNOWN, Input::KEY_NO_VALUE, + Input::GRP_GUICHAN, + nullptr, + Input::KEY_NO_VALUE, 50, + COND_DEFAULT}, + {"keyGUIPageUp", + INPUT_KEYBOARD, SDLK_PAGEUP, + INPUT_UNKNOWN, Input::KEY_NO_VALUE, + Input::GRP_GUICHAN, + nullptr, + Input::KEY_NO_VALUE, 50, + COND_DEFAULT}, + {"keyGUIPageDown", + INPUT_KEYBOARD, SDLK_PAGEDOWN, + INPUT_UNKNOWN, Input::KEY_NO_VALUE, + Input::GRP_GUICHAN, + nullptr, + Input::KEY_NO_VALUE, 50, + COND_DEFAULT}, + {"keyGUIInsert", + INPUT_KEYBOARD, SDLK_INSERT, + INPUT_UNKNOWN, Input::KEY_NO_VALUE, + Input::GRP_GUICHAN, + nullptr, + Input::KEY_NO_VALUE, 50, + COND_DEFAULT}, + {"keyGUIMod", + INPUT_KEYBOARD, SDLK_LSHIFT, + INPUT_KEYBOARD, SDLK_RSHIFT, + Input::GRP_GUICHAN, + nullptr, + Input::KEY_NO_VALUE, 50, COND_DEFAULT} }; diff --git a/src/keydata.h b/src/keydata.h index 39b2de69c..d9d584a6b 100644 --- a/src/keydata.h +++ b/src/keydata.h @@ -52,7 +52,8 @@ namespace Input GRP_EMOTION = 4, // emotions key GRP_OUTFIT = 8, // outfit key GRP_GUI = 16, // gui key - GRP_MOVETOPOINT = 32 // move to point key + GRP_MOVETOPOINT = 32, // move to point key + GRP_GUICHAN = 64 // for guichan based controls }; /** @@ -290,8 +291,6 @@ namespace Input KEY_CLOSE_CHAT_TAB, KEY_CHAT_PREV_HISTORY, KEY_CHAT_NEXT_HISTORY, - KEY_AUTOCOMPLETE_CHAT, - KEY_DEACTIVATE_CHAT, KEY_IGNORE_INPUT_1, KEY_IGNORE_INPUT_2, KEY_DIRECT_UP, @@ -319,6 +318,22 @@ namespace Input KEY_RIGHT_CLICK, KEY_CAMERA, KEY_MOD, + KEY_GUI_UP, + KEY_GUI_DOWN, + KEY_GUI_LEFT, + KEY_GUI_RIGHT, + KEY_GUI_SELECT, + KEY_GUI_SELECT2, + KEY_GUI_CANCEL, + KEY_GUI_HOME, + KEY_GUI_END, + KEY_GUI_DELETE, + KEY_GUI_BACKSPACE, + KEY_GUI_TAB, + KEY_GUI_PAGE_UP, + KEY_GUI_PAGE_DOWN, + KEY_GUI_INSERT, + KEY_GUI_MOD, KEY_TOTAL }; } -- cgit v1.2.3-60-g2f50