diff options
author | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2005-03-13 11:37:47 +0000 |
---|---|---|
committer | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2005-03-13 11:37:47 +0000 |
commit | cd2c4f5861c89f0925a1a706e38535d6c11cc3a0 (patch) | |
tree | 232273a1d853305deea6e3101dd7ceef9fb76930 /src/gui/chat.cpp | |
parent | a03175439e5abaae8603a85be0db173daa543f6b (diff) | |
download | mana-cd2c4f5861c89f0925a1a706e38535d6c11cc3a0.tar.gz mana-cd2c4f5861c89f0925a1a706e38535d6c11cc3a0.tar.bz2 mana-cd2c4f5861c89f0925a1a706e38535d6c11cc3a0.tar.xz mana-cd2c4f5861c89f0925a1a706e38535d6c11cc3a0.zip |
Converted ChatBox into a proper ChatWindow in response to changes by Chetic.
Diffstat (limited to 'src/gui/chat.cpp')
-rw-r--r-- | src/gui/chat.cpp | 88 |
1 files changed, 52 insertions, 36 deletions
diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp index 82c808be..95f29dbd 100644 --- a/src/gui/chat.cpp +++ b/src/gui/chat.cpp @@ -22,29 +22,39 @@ */ #include "chat.h" +#include "textfield.h" #include "../graphics.h" +#include "../main.h" #include <iostream> -ChatBox::ChatBox(const char *logfile, int item_num) +ChatWindow::ChatWindow(const char *logfile, int item_num): + Window("") { chatlog_file.open(logfile, std::ios::out | std::ios::app); items = 0; items_keep = item_num; - - chatBoxBackground = Image::create(200, 200); - if (chatBoxBackground) { - chatBoxBackground->fillWithColor(255, 255, 255); - chatBoxBackground->setAlpha(0.7f); - } + + setSize(600, 100); + + chatInput = new TextField(); + chatInput->setPosition( + chatInput->getBorderSize(), + 100 - chatInput->getHeight() - chatInput->getBorderSize()); + chatInput->setWidth(600 - 2 * chatInput->getBorderSize()); + chatInput->setEventId("chatinput"); + chatInput->addActionListener(this); + add(chatInput); } -ChatBox::~ChatBox() +ChatWindow::~ChatWindow() { + delete chatInput; + chatlog_file.flush(); chatlog_file.close(); } -void ChatBox::chat_log(std::string line, int own) +void ChatWindow::chat_log(std::string line, int own) { int pos; CHATLOG tmp; @@ -78,7 +88,7 @@ void ChatBox::chat_log(std::string line, int own) // A try to get text sentences no too long... bool finished = false; - int maxLength = 80; + unsigned int maxLength = 80; while (!finished) { @@ -113,44 +123,31 @@ void ChatBox::chat_log(std::string line, int own) } } -void ChatBox::chat_log(CHATSKILL action) { +void ChatWindow::chat_log(CHATSKILL action) +{ chat_log(const_msg(action), BY_SERVER); } -void ChatBox::draw(gcn::Graphics *graphics) +void ChatWindow::draw(gcn::Graphics *graphics) { + // Draw the window border/background and children + Window::draw(graphics); + + // Draw the chat log int x, y; int n = 8; - int texty = getHeight() - 5, i = 0; + int texty = getHeight() - 5 - chatInput->getHeight() - + 2 * chatInput->getBorderSize(); + int i = 0; CHATLOG line; n -= 1; graphics->setColor(gcn::Color(203, 203, 203)); - graphics->drawLine(95, 5, 95, getHeight() - 5); - graphics->drawRectangle(gcn::Rectangle(0, 0, getWidth(), getHeight())); + graphics->drawLine(95, 5, 95, texty); getAbsolutePosition(x, y); - // Potentially recreate background with new size - if (chatBoxBackground) { - if ((chatBoxBackground->getWidth() != getWidth()) || - (chatBoxBackground->getHeight() != getHeight())) - { - delete chatBoxBackground; - chatBoxBackground = Image::create(getWidth(), getHeight()); - if (chatBoxBackground) { - chatBoxBackground->fillWithColor(255, 255, 255); - chatBoxBackground->setAlpha(0.7f); - } - } - } - - // Draw background image - if (chatBoxBackground) { - chatBoxBackground->draw(screen, x, y); - } - for (iter = chatlog.begin(); iter != chatlog.end(); iter++) { line = *iter; texty -= getFont()->getHeight() - 2; @@ -186,7 +183,25 @@ void ChatBox::draw(gcn::Graphics *graphics) } } -char *ChatBox::chat_send(std::string nick, std::string msg) +void ChatWindow::action(const std::string& eventId) +{ + if (eventId == "chatinput") { + std::string message = chatInput->getText(); + + if (message.length() > 0) { + chat_send(char_info[0].name, message.c_str()); + chatInput->setText(""); + } + } +} + +void ChatWindow::requestFocus() +{ + // Give focus to the chat input + chatInput->requestFocus(); +} + +char *ChatWindow::chat_send(std::string nick, std::string msg) { short packid = 0x008c; @@ -221,7 +236,8 @@ char *ChatBox::chat_send(std::string nick, std::string msg) return ""; } -std::string ChatBox::const_msg(CHATSKILL action) { +std::string ChatWindow::const_msg(CHATSKILL action) +{ std::string msg; if (action.success == SKILL_FAILED && action.skill == SKILL_BASIC) { switch (action.bskill) { |