summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2005-01-15 23:45:39 +0000
committerBjørn Lindeijer <bjorn@lindeijer.nl>2005-01-15 23:45:39 +0000
commit7b81d4151ef4fe04a5aabcc4fe258ee40115ef0b (patch)
tree711ad9a5597de3014921b9fb36206f21595cdf05 /src/gui
parent13f82f10d92816d0239db56b7936fd2403f50897 (diff)
downloadmana-7b81d4151ef4fe04a5aabcc4fe258ee40115ef0b.tar.gz
mana-7b81d4151ef4fe04a5aabcc4fe258ee40115ef0b.tar.bz2
mana-7b81d4151ef4fe04a5aabcc4fe258ee40115ef0b.tar.xz
mana-7b81d4151ef4fe04a5aabcc4fe258ee40115ef0b.zip
Fixed screenshot taking and changed chat box in Guichan widget.
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/chat.cpp176
-rw-r--r--src/gui/chat.h83
-rw-r--r--src/gui/status.cpp20
3 files changed, 129 insertions, 150 deletions
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
+ }
}