diff options
author | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2005-01-15 23:45:39 +0000 |
---|---|---|
committer | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2005-01-15 23:45:39 +0000 |
commit | 7b81d4151ef4fe04a5aabcc4fe258ee40115ef0b (patch) | |
tree | 711ad9a5597de3014921b9fb36206f21595cdf05 /src | |
parent | 13f82f10d92816d0239db56b7936fd2403f50897 (diff) | |
download | mana-client-7b81d4151ef4fe04a5aabcc4fe258ee40115ef0b.tar.gz mana-client-7b81d4151ef4fe04a5aabcc4fe258ee40115ef0b.tar.bz2 mana-client-7b81d4151ef4fe04a5aabcc4fe258ee40115ef0b.tar.xz mana-client-7b81d4151ef4fe04a5aabcc4fe258ee40115ef0b.zip |
Fixed screenshot taking and changed chat box in Guichan widget.
Diffstat (limited to 'src')
-rw-r--r-- | src/game.cpp | 29 | ||||
-rw-r--r-- | src/graphic/graphic.cpp | 33 | ||||
-rw-r--r-- | src/graphic/graphic.h | 2 | ||||
-rw-r--r-- | src/gui/chat.cpp | 176 | ||||
-rw-r--r-- | src/gui/chat.h | 83 | ||||
-rw-r--r-- | src/gui/status.cpp | 20 |
6 files changed, 164 insertions, 179 deletions
diff --git a/src/game.cpp b/src/game.cpp index b38f1368..84e642dd 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -140,6 +140,7 @@ void game() { do_input(); engine->draw(); + gui->logic(); graphics->updateScreen(); do_parse(); flush(); @@ -402,7 +403,7 @@ void do_parse() { being->speech = temp; being->speech_time = SPEECH_TIME; being->speech_color = makecol(255, 255, 255); - chatlog.chat_log(being->speech, BY_OTHER, font); + chatBox->chat_log(being->speech, BY_OTHER); } break; case 0x008e: @@ -421,10 +422,10 @@ void do_parse() { player_node->speech_color = makecol(255, 255, 255); if(id==0x008e) { - chatlog.chat_log(player_node->speech, BY_PLAYER, font); + chatBox->chat_log(player_node->speech, BY_PLAYER); } else { - chatlog.chat_log(player_node->speech, BY_GM, font); + chatBox->chat_log(player_node->speech, BY_GM); } } break; @@ -637,7 +638,7 @@ void do_parse() { action.bskill == BSKILL_EMOTE ) { printf("Action: %d/%d", action.bskill, action.success); } - chatlog.chat_log(action, font); + chatBox->chat_log(action); break; // Update stat values case 0x00b0: @@ -842,27 +843,27 @@ void do_parse() { } } else { - chatlog.chat_log("Nothing to sell", BY_SERVER, font); + chatBox->chat_log("Nothing to sell", BY_SERVER); } break; // Answer to buy case 0x00ca: - if(RFIFOB(2)==0) - chatlog.chat_log("Thanks for buying", BY_SERVER, font); + if (RFIFOB(2) == 0) + chatBox->chat_log("Thanks for buying", BY_SERVER); else - chatlog.chat_log("Unable to buy", BY_SERVER, font); + chatBox->chat_log("Unable to buy", BY_SERVER); break; // Answer to sell case 0x00cb: - if(RFIFOB(2)==0) - chatlog.chat_log("Thanks for selling", BY_SERVER, font); + if (RFIFOB(2) == 0) + chatBox->chat_log("Thanks for selling", BY_SERVER); else - chatlog.chat_log("Unable to sell", BY_SERVER, font); + chatBox->chat_log("Unable to sell", BY_SERVER); break; // Add item to inventory after you bought it case 0x00a0: - if(RFIFOB(22)>0) - chatlog.chat_log("Unable to pick up item", BY_SERVER, font); + if (RFIFOB(22) > 0) + chatBox->chat_log("Unable to pick up item", BY_SERVER); else inventoryWindow->addItem(RFIFOW(2), RFIFOW(6), RFIFOW(4)); break; @@ -909,7 +910,7 @@ void do_parse() { break; // Display MVP payer case 0x010c: - chatlog.chat_log("MVP player", BY_SERVER, font); + chatBox->chat_log("MVP player", BY_SERVER); break; // Item drop case 0x009e: diff --git a/src/graphic/graphic.cpp b/src/graphic/graphic.cpp index 8383526a..b5dce7a2 100644 --- a/src/graphic/graphic.cpp +++ b/src/graphic/graphic.cpp @@ -27,20 +27,21 @@ #include "../gui/status.h" #include "../main.h" -BITMAP *buffer, *chat_background; +BITMAP *buffer; char itemCurrenyQ[10] = "0"; int map_x, map_y, camera_x, camera_y; char npc_text[1000] = ""; char statsString2[255] = "n/a"; char skill_points[10] = ""; -Chat chatlog("./docs/chatlog.txt", 20); bool show_skill_dialog = false; bool show_skill_list_dialog = false; char npc_button[10] = "Close"; gcn::TextField *chatInput; +gcn::Label *debugInfo; +ChatBox *chatBox; StatusWindow *statusWindow; BuyDialog *buyDialog; SellDialog *sellDialog; @@ -57,7 +58,7 @@ void ChatListener::action(const std::string& eventId) std::string message = chatInput->getText(); if (message.length() > 0) { - chatlog.chat_send(char_info[0].name, message.c_str()); + chatBox->chat_send(char_info[0].name, message.c_str()); chatInput->setText(""); } } @@ -168,8 +169,6 @@ void Graphics::updateScreen() Engine::Engine() { // Initializes GUI - chat_background = create_bitmap(592, 100); - clear_to_color(chat_background, makecol(0, 0, 0)); chatInput = new TextField(); chatInput->setPosition(chatInput->getBorderSize(), SCREEN_H - chatInput->getHeight() - chatInput->getBorderSize() -1); @@ -179,8 +178,17 @@ Engine::Engine() chatInput->setEventId("chatinput"); chatInput->addActionListener(chatListener); + debugInfo = new gcn::Label(); + + chatBox = new ChatBox("./docs/chatlog.txt", 20); + chatBox->setSize(592, 100); + chatBox->setPosition(0, chatInput->getY() - 1 - chatBox->getHeight()); + + guiTop->add(chatBox); + guiTop->add(debugInfo); guiTop->add(chatInput); + // Create dialogs statusWindow = new StatusWindow(); @@ -235,6 +243,7 @@ Engine::Engine() Engine::~Engine() { + delete chatBox; delete statusWindow; delete buyDialog; delete sellDialog; @@ -480,11 +489,6 @@ void Engine::draw() beingIterator++; } - set_trans_blender(0, 0, 0, 110); - draw_trans_sprite(buffer, chat_background, 0, SCREEN_H - 125); - - chatlog.chat_draw(buffer, 8, font); - if (statsWindow->isVisible()) { statsWindow->update(); } @@ -492,10 +496,11 @@ void Engine::draw() statusWindow->update(); } - gui->logic(); gui->draw(); - textprintf_ex(buffer, font, 0, 0, makecol(255, 255, 255), -1, - "[%i fps] %i,%i", fps, - mouse_x / 32 + camera_x, mouse_y / 32 + camera_y); + std::stringstream debugStream; + debugStream << "[" << fps << " fps] " << + (mouse_x / 32 + camera_x) << ", " << (mouse_y / 32 + camera_y); + debugInfo->setCaption(debugStream.str()); + debugInfo->adjustSize(); } diff --git a/src/graphic/graphic.h b/src/graphic/graphic.h index 7de6bd3a..a3701531 100644 --- a/src/graphic/graphic.h +++ b/src/graphic/graphic.h @@ -52,7 +52,7 @@ extern BITMAP *buffer; extern char speech[255]; extern char npc_text[1000]; extern char skill_points[10]; -extern Chat chatlog; +extern ChatBox *chatBox; extern bool show_skill_dialog, show_skill_list_dialog; extern int show_npc_dialog; extern int map_x, map_y, camera_x, camera_y; diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp index a1bbfd8c..29a6a5bb 100644 --- a/src/gui/chat.cpp +++ b/src/gui/chat.cpp @@ -22,47 +22,24 @@ */ #include "chat.h" +#include "../graphic/graphic.h" +#include <iostream> -/* - * Simple ChatLog Object v0.5 (i'd say...) - * - * Author: kth5 aka Alexander Baldeck - * pipe your questions, suggestions and flames to: kth5@gawab.com - */ - -/* - */ -Chat::Chat(const char * logfile, int item_num) { +ChatBox::ChatBox(const char *logfile, int item_num) +{ chatlog_file.open(logfile, std::ios::out | std::ios::app); items = 0; items_keep = item_num; } -/* - */ -Chat::~Chat() { +ChatBox::~ChatBox() +{ chatlog_file.flush(); chatlog_file.close(); } -/* - */ -void Chat::chat_dlgrsize(int) { -} - -/* - * Adds a line of text to our message list. Parameters: - * - * line: message text - * own: type of message (usually the owner-type) - * font: font that'll be used to draw the text later - * - * NOTE: - * To all of you who wonder why the font needs to be passed, simple. - * i already store the width in pixel in the list rather than - * calculating it again and again on every draw event. ;-) -*/ -void Chat::chat_log(std::string line, int own, FONT * font) { +void ChatBox::chat_log(std::string line, int own) +{ int pos; CHATLOG tmp; @@ -77,7 +54,7 @@ void Chat::chat_log(std::string line, int own, FONT * font) { pos = (int)line.find(" : ", 0); if (pos > 0) { tmp.nick = line.substr(0,pos); - switch(own) { + switch (own) { case ACT_IS : tmp.nick += CAT_IS; break; @@ -87,11 +64,9 @@ void Chat::chat_log(std::string line, int own, FONT * font) { default : tmp.nick += CAT_NORMAL; } - tmp.width = TEXT_GETWIDTH(tmp.nick.c_str())+2; - line.erase(0,pos+3); + line.erase(0, pos + 3); } else { tmp.nick = ""; - tmp.width = 1; } tmp.own = own; tmp.text = line; @@ -102,98 +77,82 @@ void Chat::chat_log(std::string line, int own, FONT * font) { chatlog.push_front(tmp); } -/* - * function overload -> calls original chat_log() after processing the packet - */ -void Chat::chat_log(CHATSKILL action, FONT * font) { - chat_log(const_msg(action), BY_SERVER, font); +void ChatBox::chat_log(CHATSKILL action) { + chat_log(const_msg(action), BY_SERVER); } -/* - * Draw first n lines of the list onto a Allegro type bitmap buffer using - * Alfont. - * - * BITMAP * bmp: Allegro type bitmap buffer to draw onto - * int n: number of lines to be drawn - * FONT * font: Allegro's system font - * - * NOTE: - * take great care using this, make sure the buffer passed is - * empty! ;-) anyway, line wrapping is not supported yet. -*/ -void Chat::chat_draw(BITMAP * bmp, int n, FONT * font) { - int y = 600-35, i = 0; +void ChatBox::draw(gcn::Graphics *graphics) +{ + int x, y; + int n = 8; + int texty = getHeight() - 5, 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())); + + getAbsolutePosition(x, y); + set_trans_blender(0, 0, 0, 100); + drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0); + rectfill(buffer, x, y, x + getWidth(), y + getHeight(), + makecol(255, 255, 255)); + drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0); + for (iter = chatlog.begin(); iter != chatlog.end(); iter++) { line = *iter; - y -=11; + texty -= getFont()->getHeight() - 2; switch (line.own) { - case BY_GM : - textprintf_ex(bmp, font, 1, y, COLOR_BLUE, -1, "Global announcement: "); - textprintf_ex(bmp, font, TEXT_GETWIDTH("Global announcement: "), y, -1, COLOR_GREEN, line.text.c_str()); - break; - case BY_PLAYER : - textprintf_ex(bmp, font, 1, y, COLOR_YELLOW, -1, line.nick.c_str()); - textprintf_ex(bmp, font, line.width, y, COLOR_WHITE, -1, line.text.c_str()); - break; - case BY_OTHER : - textprintf_ex(bmp, font, 1, y, COLOR_GREEN, -1, line.nick.c_str()); - textprintf_ex(bmp, font, line.width, y, COLOR_WHITE, -1, line.text.c_str()); - break; - default : - textprintf_ex(bmp, font, 1, y, COLOR_LIGHTBLUE, -1, line.text.c_str()); + case BY_GM: + graphics->setColor(gcn::Color(97, 156, 236)); // GM Bue + graphics->drawText("Global announcement: ", 1, texty); + graphics->setColor(gcn::Color(39, 197, 39)); // Green + graphics->drawText(line.text, 100, texty); + break; + case BY_PLAYER: + graphics->setColor(gcn::Color(255, 246, 98)); // Yellow + graphics->drawText(line.nick, 1, texty); + graphics->setColor(gcn::Color(255, 255, 255)); // White + graphics->drawText(line.text, 100, texty); + break; + case BY_OTHER: + graphics->setColor(gcn::Color(97, 156, 236)); // GM Bue + graphics->drawText(line.nick, 1, texty); + graphics->setColor(gcn::Color(39, 197, 39)); // Green + graphics->drawText(line.text, 100, texty); + break; + default: + graphics->setColor(gcn::Color(83, 233, 246)); // Light blue + graphics->drawText(line.text, 1, texty); } - if (i>=n) { + if (i >= n) { return; } i++; } } -/* - * Determines wether to send a command or an ordinary message, then - * contructs packets & sends them - * - * string nick -> the character's name to display infront - * string msg -> the message's text which is to be send. - * - * NOTE: - * the nickname is required by the server, if not specified - * the message may not be sent unless a command was intended - * which requires another packet to be constructed! you can - * achieve this by putting a slash ("/") infront of the - * message followed by the command name and the message. - * of course all slash-commands need implemented handler- - * routines. ;-) - * remember, a line starting w/ "@" is not a command that needs - * to be parsed rather is sent using the normal chat-packet. - * - * EXAMPLE: - * // for an global announcement /- command - * chatlog.chat_send("", "/announce Hello to all logged in users!"); - * // for simple message by a user /- message - * chatlog.chat_send("Zaeiru", "Hello to all users on the screen!"); - */ -char * Chat::chat_send(std::string nick, std::string msg) { +char *ChatBox::chat_send(std::string nick, std::string msg) +{ short packid = 0x008c; // prepare command - if(msg.substr(0,1)=="/") { + if (msg.substr(0, 1) == "/") { // global announcement - if(msg.substr(0,IS_ANNOUNCE_LENGTH) == IS_ANNOUNCE) { - msg.erase(0,IS_ANNOUNCE_LENGTH); + if(msg.substr(0, IS_ANNOUNCE_LENGTH) == IS_ANNOUNCE) { + msg.erase(0, IS_ANNOUNCE_LENGTH); packid = 0x0099; } // prepare ordinary message - } else { + } + else { // temporary hack to make messed-up-keyboard-ppl able to send GM commands - if(msg.substr(0,1)=="#") - msg.replace(0,1,"@"); + if (msg.substr(0, 1) == "#") + msg.replace(0, 1, "@"); // end temp. hack XD nick += " : "; nick += msg; @@ -212,15 +171,7 @@ char * Chat::chat_send(std::string nick, std::string msg) { return ""; } -/* - * PRIVATE : - * NOTE: - * these usually will be left undocumented coz u can't call them - * directly anyway. ;-) - */ - -/** constructs failed messages for actions */ -std::string Chat::const_msg(CHATSKILL action) { +std::string ChatBox::const_msg(CHATSKILL action) { std::string msg; if (action.success == SKILL_FAILED && action.skill == SKILL_BASIC) { switch (action.bskill) { @@ -295,8 +246,3 @@ std::string Chat::const_msg(CHATSKILL action) { return msg; } - -std::string const_msg(int own) { - std::string msg; - return msg; -} diff --git a/src/gui/chat.h b/src/gui/chat.h index 424a0d0b..9723535e 100644 --- a/src/gui/chat.h +++ b/src/gui/chat.h @@ -25,6 +25,7 @@ #define _TMW_CHAT_H #include "../net/network.h" +#include <guichan.hpp> #include <allegro.h> #include <list> #include <string> @@ -51,18 +52,6 @@ #define CAT_IS "" #define CAT_WHISPER " says: " -/** some generic color macros */ -#define COLOR_WHITE (makecol(255,255,255)) // plain white -#define COLOR_BLUE (makecol( 97,156,236)) // cold gm blue :P -#define COLOR_YELLOW (makecol(255,246, 98)) // sexy yellow -#define COLOR_GREEN (makecol( 39,197, 39)) // cool green -#define COLOR_RED (makecol(255, 0, 0)) // ack red XD -#define COLOR_LIGHTBLUE (makecol( 83,223,246)) // bright blue - -/** calculate text-width in pixel */ -#define TEXT_GETWIDTH(str) (text_length(font, str)) -#define TEXT_OUT(bmp, col, str) (textprintf_ex(bmp, font, 1, y, col, str, 1)) - /** job dependend identifiers (?) */ #define SKILL_BASIC 0x0001 #define SKILL_WARP 0x001b @@ -106,17 +95,62 @@ struct CHATSKILL { /** * Simple chatlog object. */ -class Chat { - public : - Chat(const char *, int); - void chat_dlgrsize(int); - - void chat_log(std::string, int, FONT *); - void chat_log(CHATSKILL, FONT *); +class ChatBox : public gcn::Widget { + public: + /** + * Constructor. + */ + ChatBox(const char *logfile, int item_num); + + /** + * Destructor. + */ + ~ChatBox(); + + /* + * Adds a line of text to our message list. Parameters: + * + * @param line Text message. + * @parem own Type of message (usually the owner-type). + */ + void chat_log(std::string line, int own); + + /* + * Calls original chat_log() after processing the packet. + */ + void chat_log(CHATSKILL); + + /* + * Draws the chat box. + */ + void draw(gcn::Graphics *graphics); + + /* + * Determines wether to send a command or an ordinary message, then + * contructs packets & sends them + * + * @param nick The character's name to display in front. + * @param msg The message text which is to be send. + * + * NOTE: + * the nickname is required by the server, if not specified + * the message may not be sent unless a command was intended + * which requires another packet to be constructed! you can + * achieve this by putting a slash ("/") infront of the + * message followed by the command name and the message. + * of course all slash-commands need implemented handler- + * routines. ;-) + * remember, a line starting with "@" is not a command that needs + * to be parsed rather is sent using the normal chat-packet. + * + * EXAMPLE: + * // for an global announcement /- command + * chatlog.chat_send("", "/announce Hello to all logged in users!"); + * // for simple message by a user /- message + * chatlog.chat_send("Zaeiru", "Hello to all users on the screen!"); + */ + char *chat_send(std::string nick, std::string msg); - void chat_draw(BITMAP *, int, FONT *); - char * chat_send(std::string, std::string); - ~Chat(); private : std::ofstream chatlog_file; @@ -124,7 +158,6 @@ class Chat { std::string nick; std::string text; int own; - int width; }; std::list<CHATLOG> chatlog; // list object ready to accept out CHATLOG struct :) @@ -133,8 +166,8 @@ class Chat { int items; int items_keep; - std::string const_msg(CHATSKILL); // contructs action-fail messages - std::string const_msg(int); // constructs normal messages (not implemented yet) + /** constructs failed messages for actions */ + std::string const_msg(CHATSKILL); }; #endif diff --git a/src/gui/status.cpp b/src/gui/status.cpp index fa31919d..8465082f 100644 --- a/src/gui/status.cpp +++ b/src/gui/status.cpp @@ -46,7 +46,7 @@ StatusWindow::StatusWindow(): jobExpLabel->setPosition(106, 40); //xpBar->setDimension(gcn::Rectangle(16, 55, 60, 18)); //jobXpBar->setDimension(gcn::Rectangle(116, 55, 60, 18)); - + healthBar = new ProgressBar(1.0f, 20, 8, 80, 0, 255, 0); manaBar = new ProgressBar(1.0f, 20, 26, 80, 0, 0, 255); xpBar = new ProgressBar(1.0f, 6, 55, 70, 12, 194, 255); @@ -109,18 +109,18 @@ void StatusWindow::update() if ( char_info->hp < int(char_info->max_hp / 3) ) { - healthBar->setColor(255, 0, 0); // Red + healthBar->setColor(255, 0, 0); // Red } else { - if ( char_info->hp < int( (char_info->max_hp / 3)*2 ) ) - { - healthBar->setColor(255, 181, 9); // orange - } - else - { - healthBar->setColor(0, 255, 0); // Green - } + if ( char_info->hp < int( (char_info->max_hp / 3)*2 ) ) + { + healthBar->setColor(255, 181, 9); // orange + } + else + { + healthBar->setColor(0, 255, 0); // Green + } } |