From effa24737d6997dc40508533635accca3ed099e9 Mon Sep 17 00:00:00 2001 From: "Esteban I. Ruiz Moreno" Date: Sun, 2 Jun 2013 21:16:32 -0300 Subject: Use the console instead of a dedicated window when pressing keymap_chat/cmd keymap_console opens a full window for chat history browsing. --- src/guiChatConsole.cpp | 56 +++++++++++++++++++++++++++++++++----------------- 1 file changed, 37 insertions(+), 19 deletions(-) (limited to 'src/guiChatConsole.cpp') diff --git a/src/guiChatConsole.cpp b/src/guiChatConsole.cpp index 3937e405c..4c0039e5e 100644 --- a/src/guiChatConsole.cpp +++ b/src/guiChatConsole.cpp @@ -55,6 +55,7 @@ GUIChatConsole::GUIChatConsole( m_screensize(v2u32(0,0)), m_animate_time_old(0), m_open(false), + m_close_on_enter(false), m_height(0), m_desired_height(0), m_desired_height_fraction(0.0), @@ -148,6 +149,14 @@ f32 GUIChatConsole::getDesiredHeight() const return m_desired_height_fraction; } +void GUIChatConsole::replaceAndAddToHistory(std::wstring line) +{ + ChatPrompt& prompt = m_chat_backend->getPrompt(); + prompt.addToHistory(prompt.getLine()); + prompt.replace(line); +} + + void GUIChatConsole::setCursor( bool visible, bool blinking, f32 blink_speed, f32 relative_height) { @@ -381,6 +390,9 @@ void GUIChatConsole::drawPrompt() bool GUIChatConsole::OnEvent(const SEvent& event) { + + ChatPrompt &prompt = m_chat_backend->getPrompt(); + if(event.EventType == EET_KEY_INPUT_EVENT && event.KeyInput.PressedDown) { // Key input @@ -391,13 +403,16 @@ bool GUIChatConsole::OnEvent(const SEvent& event) // inhibit open so the_game doesn't reopen immediately m_open_inhibited = 50; + m_close_on_enter = false; return true; } else if(event.KeyInput.Key == KEY_ESCAPE) { closeConsoleAtOnce(); Environment->removeFocus(this); - // the_game will open the pause menu + m_close_on_enter = false; + // inhibit open so the_game doesn't reopen immediately + m_open_inhibited = 1; // so the ESCAPE button doesn't open the "pause menu" return true; } else if(event.KeyInput.Key == KEY_PRIOR) @@ -412,22 +427,28 @@ bool GUIChatConsole::OnEvent(const SEvent& event) } else if(event.KeyInput.Key == KEY_RETURN) { - std::wstring text = m_chat_backend->getPrompt().submit(); + prompt.addToHistory(prompt.getLine()); + std::wstring text = prompt.replace(L""); m_client->typeChatMessage(text); + if (m_close_on_enter) { + closeConsoleAtOnce(); + Environment->removeFocus(this); + m_close_on_enter = false; + } return true; } else if(event.KeyInput.Key == KEY_UP) { // Up pressed // Move back in history - m_chat_backend->getPrompt().historyPrev(); + prompt.historyPrev(); return true; } else if(event.KeyInput.Key == KEY_DOWN) { // Down pressed // Move forward in history - m_chat_backend->getPrompt().historyNext(); + prompt.historyNext(); return true; } else if(event.KeyInput.Key == KEY_LEFT) @@ -438,7 +459,7 @@ bool GUIChatConsole::OnEvent(const SEvent& event) event.KeyInput.Control ? ChatPrompt::CURSOROP_SCOPE_WORD : ChatPrompt::CURSOROP_SCOPE_CHARACTER; - m_chat_backend->getPrompt().cursorOperation( + prompt.cursorOperation( ChatPrompt::CURSOROP_MOVE, ChatPrompt::CURSOROP_DIR_LEFT, scope); @@ -452,7 +473,7 @@ bool GUIChatConsole::OnEvent(const SEvent& event) event.KeyInput.Control ? ChatPrompt::CURSOROP_SCOPE_WORD : ChatPrompt::CURSOROP_SCOPE_CHARACTER; - m_chat_backend->getPrompt().cursorOperation( + prompt.cursorOperation( ChatPrompt::CURSOROP_MOVE, ChatPrompt::CURSOROP_DIR_RIGHT, scope); @@ -462,7 +483,7 @@ bool GUIChatConsole::OnEvent(const SEvent& event) { // Home pressed // move to beginning of line - m_chat_backend->getPrompt().cursorOperation( + prompt.cursorOperation( ChatPrompt::CURSOROP_MOVE, ChatPrompt::CURSOROP_DIR_LEFT, ChatPrompt::CURSOROP_SCOPE_LINE); @@ -472,7 +493,7 @@ bool GUIChatConsole::OnEvent(const SEvent& event) { // End pressed // move to end of line - m_chat_backend->getPrompt().cursorOperation( + prompt.cursorOperation( ChatPrompt::CURSOROP_MOVE, ChatPrompt::CURSOROP_DIR_RIGHT, ChatPrompt::CURSOROP_SCOPE_LINE); @@ -486,7 +507,7 @@ bool GUIChatConsole::OnEvent(const SEvent& event) event.KeyInput.Control ? ChatPrompt::CURSOROP_SCOPE_WORD : ChatPrompt::CURSOROP_SCOPE_CHARACTER; - m_chat_backend->getPrompt().cursorOperation( + prompt.cursorOperation( ChatPrompt::CURSOROP_DELETE, ChatPrompt::CURSOROP_DIR_LEFT, scope); @@ -500,7 +521,7 @@ bool GUIChatConsole::OnEvent(const SEvent& event) event.KeyInput.Control ? ChatPrompt::CURSOROP_SCOPE_WORD : ChatPrompt::CURSOROP_SCOPE_CHARACTER; - m_chat_backend->getPrompt().cursorOperation( + prompt.cursorOperation( ChatPrompt::CURSOROP_DELETE, ChatPrompt::CURSOROP_DIR_RIGHT, scope); @@ -513,17 +534,14 @@ bool GUIChatConsole::OnEvent(const SEvent& event) IOSOperator *os_operator = Environment->getOSOperator(); const c8 *text = os_operator->getTextFromClipboard(); if (text) - { - std::wstring wtext = narrow_to_wide(text); - m_chat_backend->getPrompt().input(wtext); - } + prompt.input(narrow_to_wide(text)); return true; } else if(event.KeyInput.Key == KEY_KEY_U && event.KeyInput.Control) { // Ctrl-U pressed // kill line to left end - m_chat_backend->getPrompt().cursorOperation( + prompt.cursorOperation( ChatPrompt::CURSOROP_DELETE, ChatPrompt::CURSOROP_DIR_LEFT, ChatPrompt::CURSOROP_SCOPE_LINE); @@ -533,7 +551,7 @@ bool GUIChatConsole::OnEvent(const SEvent& event) { // Ctrl-K pressed // kill line to right end - m_chat_backend->getPrompt().cursorOperation( + prompt.cursorOperation( ChatPrompt::CURSOROP_DELETE, ChatPrompt::CURSOROP_DIR_RIGHT, ChatPrompt::CURSOROP_SCOPE_LINE); @@ -545,7 +563,7 @@ bool GUIChatConsole::OnEvent(const SEvent& event) // Nick completion std::list names = m_client->getConnectedPlayerNames(); bool backwards = event.KeyInput.Shift; - m_chat_backend->getPrompt().nickCompletion(names, backwards); + prompt.nickCompletion(names, backwards); return true; } else if(event.KeyInput.Char != 0 && !event.KeyInput.Control) @@ -553,9 +571,9 @@ bool GUIChatConsole::OnEvent(const SEvent& event) #if (defined(linux) || defined(__linux)) wchar_t wc = L'_'; mbtowc( &wc, (char *) &event.KeyInput.Char, sizeof(event.KeyInput.Char) ); - m_chat_backend->getPrompt().input(wc); + prompt.input(wc); #else - m_chat_backend->getPrompt().input(event.KeyInput.Char); + prompt.input(event.KeyInput.Char); #endif return true; } -- cgit v1.2.3