From ef2e1bafa7c5f19b0353e0bf01a7ad9d7f8cddf5 Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Sat, 28 Mar 2009 07:55:54 -0600 Subject: Allow changing chat tabs with the keyboard Defaults to: [ for previous tab ] for next tab --- src/game.cpp | 11 +++++++++++ src/gui/chat.cpp | 22 ++++++++++++++++++++++ src/gui/chat.h | 10 ++++++++++ src/keyboardconfig.cpp | 2 ++ src/keyboardconfig.h | 2 ++ 5 files changed, 47 insertions(+) diff --git a/src/game.cpp b/src/game.cpp index ba756df3..2dc62b05 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -722,6 +722,17 @@ void Game::handleInput() used = true; } + if (keyboard.isKeyActive(keyboard.KEY_PREV_CHAT_TAB)) + { + chatWindow->prevTab(); + return; + } + else if (keyboard.isKeyActive(keyboard.KEY_NEXT_CHAT_TAB)) + { + chatWindow->nextTab(); + return; + } + const int tKey = keyboard.getKeyIndex(event.key.keysym.sym); switch (tKey) { diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp index 987de11e..398b5792 100644 --- a/src/gui/chat.cpp +++ b/src/gui/chat.cpp @@ -159,6 +159,28 @@ void ChatWindow::clearTab() clearTab(getFocused()); } +void ChatWindow::prevTab() +{ + int tab = mChatTabs->getSelectedTabIndex(); + + if (tab == 0) + tab = mChatTabs->getNumberOfTabs(); + tab--; + + mChatTabs->setSelectedTab(tab); +} + +void ChatWindow::nextTab() +{ + int tab = mChatTabs->getSelectedTabIndex(); + + tab++; + if (tab == mChatTabs->getNumberOfTabs()) + tab = 0; + + mChatTabs->setSelectedTab(tab); +} + void ChatWindow::action(const gcn::ActionEvent &event) { if (event.getId() == "chatinput") diff --git a/src/gui/chat.h b/src/gui/chat.h index 54270055..3a2f7fdb 100644 --- a/src/gui/chat.h +++ b/src/gui/chat.h @@ -102,6 +102,16 @@ class ChatWindow : public Window, */ void clearTab(); + /** + * Switch to the previous tab in order + */ + void prevTab(); + + /** + * Switch to the next tab in order + */ + void nextTab(); + /** * Performs action. */ diff --git a/src/keyboardconfig.cpp b/src/keyboardconfig.cpp index 06ce4ac7..e13af147 100644 --- a/src/keyboardconfig.cpp +++ b/src/keyboardconfig.cpp @@ -94,6 +94,8 @@ static KeyData const keyData[KeyboardConfig::KEY_TOTAL] = { {"keyChat", SDLK_RETURN, _("Toggle Chat")}, {"keyChatScrollUp", SDLK_PAGEUP, _("Scroll Chat Up")}, {"keyChatScrollDown", SDLK_PAGEDOWN, _("Scroll Chat Down")}, + {"keyChatPrevTab", SDLK_LEFTBRACKET, _("Previous Chat Tab")}, + {"keyChatNextTab", SDLK_RIGHTBRACKET, _("Next Chat Tab")}, {"keyOK", SDLK_RETURN, _("Select OK")}, {"keyQuit", SDLK_ESCAPE, _("Quit")}, {"keyIgnoreInput1", SDLK_LSUPER, _("Ignore input 1")}, diff --git a/src/keyboardconfig.h b/src/keyboardconfig.h index f7750b30..ecbe5de5 100644 --- a/src/keyboardconfig.h +++ b/src/keyboardconfig.h @@ -205,6 +205,8 @@ class KeyboardConfig KEY_TOGGLE_CHAT, KEY_SCROLL_CHAT_UP, KEY_SCROLL_CHAT_DOWN, + KEY_PREV_CHAT_TAB, + KEY_NEXT_CHAT_TAB, KEY_OK, KEY_QUIT, KEY_IGNORE_INPUT_1, -- cgit v1.2.3-70-g09d2