diff options
author | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2005-12-30 16:50:12 +0000 |
---|---|---|
committer | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2005-12-30 16:50:12 +0000 |
commit | 83f7d9ff9f83cca80b5f72564ee3496e8a30cce3 (patch) | |
tree | 95ba60d15ca46c9c5bb1696fbb45dc900070521a /src/gui | |
parent | ea653b2e9e1b46a07440833f96b3d2b788592c61 (diff) | |
download | mana-83f7d9ff9f83cca80b5f72564ee3496e8a30cce3.tar.gz mana-83f7d9ff9f83cca80b5f72564ee3496e8a30cce3.tar.bz2 mana-83f7d9ff9f83cca80b5f72564ee3496e8a30cce3.tar.xz mana-83f7d9ff9f83cca80b5f72564ee3496e8a30cce3.zip |
Applied pcloud's patch that enhances chat window functionality while hidden.
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/chat.cpp | 83 | ||||
-rw-r--r-- | src/gui/chat.h | 7 |
2 files changed, 68 insertions, 22 deletions
diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp index 731cc0d0..664ba5cd 100644 --- a/src/gui/chat.cpp +++ b/src/gui/chat.cpp @@ -42,7 +42,8 @@ extern Graphics *graphics; #include "../net/protocol.h" ChatWindow::ChatWindow(const std::string &logfile): - Window("") + Window(""), + mTmpVisible(false) { setWindowName("Chat"); chatlog_file.open(logfile.c_str(), std::ios::out | std::ios::app); @@ -81,7 +82,8 @@ ChatWindow::~ChatWindow() chatlog_file.close(); } -void ChatWindow::logic() +void +ChatWindow::logic() { chatInput->setPosition( chatInput->getBorderSize(), @@ -98,7 +100,8 @@ void ChatWindow::logic() scrollArea->logic(); } -void ChatWindow::chat_log(std::string line, int own) +void +ChatWindow::chat_log(std::string line, int own) { // Delete overhead from the end of the list while ((int)chatlog.size() > items_keep) { @@ -114,13 +117,13 @@ void ChatWindow::chat_log(std::string line, int own) { own = BY_SERVER; } - + int pos = line.find(" : "); if (pos > 0) { tmp.nick = line.substr(0, pos); line.erase(0, pos + 3); } - + std::string lineColor = "##0"; // Equiv. to BrowserBox::BLACK switch (own) { case BY_GM: @@ -148,21 +151,21 @@ void ChatWindow::chat_log(std::string line, int own) lineColor = "##5"; // Equiv. to BrowserBox::YELLOW break; } - + // Get the current system time time_t t; time(&t); // Format the time string properly std::stringstream timeStr; - timeStr << "["; - timeStr << ((((t / 60) / 60) % 24 < 10) ? "0" : ""); - timeStr << (int)(((t / 60) / 60) % 24); - timeStr << ":"; - timeStr << (((t / 60) % 60 < 10) ? "0" : ""); - timeStr << (int)((t / 60) % 60); - timeStr << "] "; - + timeStr << "[" + << ((((t / 60) / 60) % 24 < 10) ? "0" : "") + << (int)(((t / 60) / 60) % 24) + << ":" + << (((t / 60) % 60 < 10) ? "0" : "") + << (int)((t / 60) % 60) + << "] "; + line = lineColor + timeStr.str() + tmp.nick + line; // We look if the Vertical Scroll Bar is set at the max before @@ -179,12 +182,14 @@ void ChatWindow::chat_log(std::string line, int own) } } -void ChatWindow::chat_log(CHATSKILL act) +void +ChatWindow::chat_log(CHATSKILL act) { chat_log(const_msg(act), BY_SERVER); } -void ChatWindow::action(const std::string& eventId) +void +ChatWindow::action(const std::string& eventId) { if (eventId == "chatinput") { @@ -208,17 +213,38 @@ void ChatWindow::action(const std::string& eventId) // Remove focus and hide input mFocusHandler->focusNone(); + + // If the chatWindow is shown up because you want to send a message + // It should hide now + if (mTmpVisible) { + setVisible(false); + } } } -void ChatWindow::requestChatFocus() +void +ChatWindow::requestChatFocus() { + // Make sure chatWindow is visible + if (!isVisible()) + { + setVisible(true); + + /* + * This is used to hide chatWindow after sending the message. There is + * a trick here, because setVisible will set mTmpVisible to false, you + * have to put this sentence *after* setVisible, not before it + */ + mTmpVisible = true; + } + // Give focus to the chat input chatInput->setVisible(true); chatInput->requestFocus(); } -bool ChatWindow::isFocused() +bool +ChatWindow::isFocused() { return chatInput->hasFocus(); } @@ -252,7 +278,8 @@ ChatWindow::chat_send(std::string nick, std::string msg) outMsg.writeString(msg, msg.length()); } -std::string ChatWindow::const_msg(CHATSKILL act) +std::string +ChatWindow::const_msg(CHATSKILL act) { std::string msg; if (act.success == SKILL_FAILED && act.skill == SKILL_BASIC) { @@ -329,7 +356,8 @@ std::string ChatWindow::const_msg(CHATSKILL act) return msg; } -void ChatWindow::keyPress(const gcn::Key &key) +void +ChatWindow::keyPress(const gcn::Key &key) { if (key.getValue() == key.DOWN && curHist != history.end()) { @@ -353,8 +381,21 @@ void ChatWindow::keyPress(const gcn::Key &key) } } -void ChatWindow::setInputText(std::string input_str) +void +ChatWindow::setInputText(std::string input_str) { chatInput->setText(input_str + " "); requestChatFocus(); } + +void +ChatWindow::setVisible(bool isVisible) +{ + Widget::setVisible(isVisible); + + /* + * For whatever reason, if setVisible is called, the mTmpVisible effect + * should be disabled. + */ + mTmpVisible = false; +} diff --git a/src/gui/chat.h b/src/gui/chat.h index e648eda5..a4547d86 100644 --- a/src/gui/chat.h +++ b/src/gui/chat.h @@ -185,11 +185,16 @@ class ChatWindow : public Window, public gcn::ActionListener, /** Called to set current text */ void setInputText(std::string input_str); + /** Override to reset mTmpVisible */ + void setVisible(bool visible); + private: std::ofstream chatlog_file; + bool mTmpVisible; /** One item in the chat log */ - typedef struct CHATLOG { + typedef struct CHATLOG + { std::string nick; std::string text; int own; |