summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2005-03-13 11:37:47 +0000
committerBjørn Lindeijer <bjorn@lindeijer.nl>2005-03-13 11:37:47 +0000
commitcd2c4f5861c89f0925a1a706e38535d6c11cc3a0 (patch)
tree232273a1d853305deea6e3101dd7ceef9fb76930 /src
parenta03175439e5abaae8603a85be0db173daa543f6b (diff)
downloadmana-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')
-rw-r--r--src/engine.cpp57
-rw-r--r--src/engine.h10
-rw-r--r--src/game.cpp60
-rw-r--r--src/gui/chat.cpp88
-rw-r--r--src/gui/chat.h27
-rw-r--r--src/resources/image.cpp7
-rw-r--r--src/resources/image.h7
-rw-r--r--src/resources/resourcemanager.cpp2
-rw-r--r--src/resources/resourcemanager.h3
9 files changed, 118 insertions, 143 deletions
diff --git a/src/engine.cpp b/src/engine.cpp
index f19ccd05..0359e19f 100644
--- a/src/engine.cpp
+++ b/src/engine.cpp
@@ -42,11 +42,9 @@ bool show_skill_dialog = false;
bool show_skill_list_dialog = false;
char npc_button[10] = "Close";
-gcn::TextField *chatInput;
gcn::Label *debugInfo;
-Window *chatWindow;
-ChatBox *chatBox;
+ChatWindow *chatWindow;
StatusWindow *statusWindow;
BuyDialog *buyDialog;
SellDialog *sellDialog;
@@ -63,18 +61,6 @@ Minimap *minimap;
EquipmentWindow *equipmentWindow;
ChargeDialog *chargeDialog;
-void ChatListener::action(const std::string& eventId)
-{
- if (eventId == "chatinput") {
- std::string message = chatInput->getText();
-
- if (message.length() > 0) {
- chatBox->chat_send(char_info[0].name, message.c_str());
- chatInput->setText("");
- }
- }
-}
-
char hairtable[16][4][2] = {
// S(x,y) W(x,y) N(x,y) E(x,y)
{ { 0, 0}, {-1, 2}, {-1, 2}, {0, 2} }, // STAND
@@ -135,38 +121,14 @@ int get_y_offset(Being *being) {
Engine::Engine()
{
// Initializes GUI
- chatWindow = new Window("Chat");
- chatWindow->setSize(600, 100);
-
- chatInput = new TextField();
- //chatInput->setPosition(chatInput->getBorderSize(),
- // screen->h - chatInput->getHeight() -
- // chatInput->getBorderSize());
- chatInput->setPosition(chatInput->getBorderSize(),
- chatWindow->getY() + 85);
-
- chatInput->setWidth(592 - 2 * chatInput->getBorderSize());
-
- ChatListener *chatListener = new ChatListener();
- 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());
-
- chatWindow->add(chatBox);
- //chatWindow->add(debugInfo);
- chatWindow->add(chatInput);
-
- chatWindow->setPosition(0, screen->h-12 - chatInput->getHeight() - chatBox->getHeight());
-
- guiTop->add(chatWindow);
+ guiTop->add(debugInfo);
// Create dialogs
+ chatWindow = new ChatWindow("./docs/chatlog.txt", 20);
+ chatWindow->setPosition(0, screen->h - chatWindow->getHeight());
+
statusWindow = new StatusWindow();
statusWindow->setPosition(screen->w - statusWindow->getWidth() - 5, 5);
@@ -202,7 +164,6 @@ Engine::Engine()
newSkillWindow = new NewSkillDialog();
newSkillWindow->setVisible(false);
-
statsWindow = new StatsWindow();
statsWindow->setVisible(false);
statsWindow->setPosition(
@@ -222,10 +183,10 @@ Engine::Engine()
chargeDialog->setPosition(
screen->w - 5 - chargeDialog->getWidth(),
screen->h - chargeDialog->getHeight() - 15);
-
- // Give focus to the chat input
- chatInput->requestFocus();
+ // Give focus to chat window
+ chatWindow->requestFocus();
+
// Load the sprite sets
ResourceManager *resman = ResourceManager::getInstance();
Image *npcbmp = resman->getImage(
@@ -254,7 +215,7 @@ Engine::Engine()
Engine::~Engine()
{
- delete chatBox;
+ delete chatWindow;
delete statusWindow;
delete buyDialog;
delete sellDialog;
diff --git a/src/engine.h b/src/engine.h
index df25af69..6454e890 100644
--- a/src/engine.h
+++ b/src/engine.h
@@ -49,12 +49,12 @@
extern char speech[255];
extern char npc_text[1000];
extern char skill_points[10];
-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;
extern char npc_button[10];
+extern ChatWindow *chatWindow;
extern StatusWindow *statusWindow;
extern BuyDialog *buyDialog;
extern SellDialog *sellDialog;
@@ -74,14 +74,6 @@ char get_x_offset(char, char);
char get_y_offset(char, char);
/**
- * The action listener for the chat field.
- */
-class ChatListener : public gcn::ActionListener {
- public:
- void action(const std::string& eventId);
-};
-
-/**
* Game engine that does the main drawing.
*/
class Engine {
diff --git a/src/game.cpp b/src/game.cpp
index f217f356..00ad352d 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -508,7 +508,7 @@ void do_parse() {
if (being != NULL) {
// White
being->setSpeech(temp, SPEECH_TIME);
- chatBox->chat_log(temp, BY_OTHER);
+ chatWindow->chat_log(temp, BY_OTHER);
}
free(temp);
break;
@@ -525,10 +525,10 @@ void do_parse() {
player_node->setSpeech(temp, SPEECH_TIME);
if (id == 0x008e) {
- chatBox->chat_log(temp, BY_PLAYER);
+ chatWindow->chat_log(temp, BY_PLAYER);
}
else {
- chatBox->chat_log(temp, BY_GM);
+ chatWindow->chat_log(temp, BY_GM);
}
free(temp);
@@ -683,7 +683,7 @@ void do_parse() {
RFIFOW(4 + loop * 18), true);
/*char info[40];
sprintf(info, "1ee %i", RFIFOW(4+loop*18+2));
- chatBox->chat_log(info, BY_SERVER);*/
+ chatWindow->chat_log(info, BY_SERVER);*/
}
break;
// Get the equipments
@@ -697,7 +697,7 @@ void do_parse() {
RFIFOB(4+loop*20+4), RFIFOB(4+loop*20+5),
RFIFOW(4+loop*20+6), RFIFOW(4+loop*20+8),
RFIFOB(4+loop*20+10), RFIFOB(4+loop*20+11));
- chatBox->chat_log(info, BY_SERVER);*/
+ chatWindow->chat_log(info, BY_SERVER);*/
if(RFIFOW(4+loop*20+8)) {
int mask = 1;
int position = 0;
@@ -706,7 +706,7 @@ void do_parse() {
position++;
}
/*sprintf(info, "%i %i", mask, position);
- chatBox->chat_log(info, BY_SERVER);*/
+ chatWindow->chat_log(info, BY_SERVER);*/
equipmentWindow->addEquipment(position - 1,
RFIFOW(4+loop*20+2));
equipmentWindow->equipments[position - 1].inventoryIndex =
@@ -719,7 +719,7 @@ void do_parse() {
// Can I use the item?
case 0x00a8:
if (RFIFOB(6) == 0) {
- chatBox->chat_log("Failed to use item", BY_OTHER);
+ chatWindow->chat_log("Failed to use item", BY_OTHER);
} else {
inventoryWindow->changeQuantity(RFIFOW(2), RFIFOW(4));
}
@@ -780,7 +780,7 @@ void do_parse() {
action.bskill == BSKILL_EMOTE ) {
printf("Action: %d/%d", action.bskill, action.success);
}
- chatBox->chat_log(action);
+ chatWindow->chat_log(action);
break;
// Update stat values
case 0x00b0:
@@ -814,12 +814,12 @@ void do_parse() {
char_info->statsPointsToAttribute = RFIFOW(4);
/*char points[20];
sprintf(points, "b0 0x0009 %i", RFIFOL(4));
- chatBox->chat_log(points, BY_SERVER);*/
+ chatWindow->chat_log(points, BY_SERVER);*/
break;
default:
/*char unknown[20];
sprintf(unknown, "b0 %x %i", RFIFOW(2),RFIFOL(4));
- chatBox->chat_log(unknown, BY_SERVER);*/
+ chatWindow->chat_log(unknown, BY_SERVER);*/
break;
}
statusWindow->update();
@@ -951,7 +951,7 @@ void do_parse() {
}
/*char unknown2[20];
sprintf(unknown2, "141 %i %i %i", RFIFOL(2),RFIFOL(6),RFIFOL(10));
- chatBox->chat_log(unknown2, BY_SERVER);*/
+ chatWindow->chat_log(unknown2, BY_SERVER);*/
break;
// Buy/Sell dialog
case 0x00c4:
@@ -982,27 +982,27 @@ void do_parse() {
}
}
else {
- chatBox->chat_log("Nothing to sell", BY_SERVER);
+ chatWindow->chat_log("Nothing to sell", BY_SERVER);
}
break;
// Answer to buy
case 0x00ca:
if (RFIFOB(2) == 0)
- chatBox->chat_log("Thanks for buying", BY_SERVER);
+ chatWindow->chat_log("Thanks for buying", BY_SERVER);
else
- chatBox->chat_log("Unable to buy", BY_SERVER);
+ chatWindow->chat_log("Unable to buy", BY_SERVER);
break;
// Answer to sell
case 0x00cb:
if (RFIFOB(2) == 0)
- chatBox->chat_log("Thanks for selling", BY_SERVER);
+ chatWindow->chat_log("Thanks for selling", BY_SERVER);
else
- chatBox->chat_log("Unable to sell", BY_SERVER);
+ chatWindow->chat_log("Unable to sell", BY_SERVER);
break;
// Add item to inventory after you bought it
case 0x00a0:
if (RFIFOB(22) > 0)
- chatBox->chat_log("Unable to pick up item", BY_SERVER);
+ chatWindow->chat_log("Unable to pick up item", BY_SERVER);
else {
if(RFIFOW(19)) {
inventoryWindow->addItem(RFIFOW(2), RFIFOW(6),
@@ -1017,7 +1017,7 @@ void do_parse() {
RFIFOW(2), RFIFOW(4), RFIFOW(6),
RFIFOB(8), RFIFOB(9), RFIFOB(10),
RFIFOW(19), RFIFOB(21));
- chatBox->chat_log(info, BY_SERVER);*/
+ chatWindow->chat_log(info, BY_SERVER);*/
}
break;
// Decrease quantity of an item in inventory
@@ -1063,7 +1063,7 @@ void do_parse() {
break;
// Display MVP player
case 0x010c:
- chatBox->chat_log("MVP player", BY_SERVER);
+ chatWindow->chat_log("MVP player", BY_SERVER);
break;
// Item is found
case 0x009d:
@@ -1126,7 +1126,7 @@ void do_parse() {
// Answer to equip item
case 0x00aa:
if (RFIFOB(6) == 0)
- chatBox->chat_log("Unable to equip.", BY_SERVER);
+ chatWindow->chat_log("Unable to equip.", BY_SERVER);
else {
if(RFIFOW(4)) {
int mask = 1;
@@ -1142,7 +1142,7 @@ void do_parse() {
false);
/*char info3[40];
sprintf(info3, "info3 %i %i", position-1,equippedId);
- chatBox->chat_log(info3, BY_SERVER);*/
+ chatWindow->chat_log(info3, BY_SERVER);*/
inventoryWindow->items->setEquipped(RFIFOW(2),
true);
@@ -1164,18 +1164,18 @@ void do_parse() {
}
/*char info[40];
sprintf(info, "aa %i %i %i", RFIFOW(2),RFIFOW(4),RFIFOB(6));
- chatBox->chat_log(info, BY_SERVER);*/
+ chatWindow->chat_log(info, BY_SERVER);*/
break;
// Equipment related
case 0x01d7:
/*char content[40];
sprintf(content, "1d7 %i %i %i", RFIFOB(6), RFIFOW(7), RFIFOW(9));
- chatBox->chat_log(content, BY_SERVER);*/
+ chatWindow->chat_log(content, BY_SERVER);*/
break;
// Answer to unequip item
case 0x00ac:
if (RFIFOB(6) == 0)
- chatBox->chat_log("Unable to unequip.", BY_SERVER);
+ chatWindow->chat_log("Unable to unequip.", BY_SERVER);
else {
if(RFIFOW(4)) {
int mask = 1;
@@ -1196,28 +1196,28 @@ void do_parse() {
}
/*char info2[40];
sprintf(info2, "ac %i %i %i", RFIFOW(2),RFIFOW(4),RFIFOB(6));
- chatBox->chat_log(info2, BY_SERVER);*/
+ chatWindow->chat_log(info2, BY_SERVER);*/
break;
// Arrows equipped
case 0x013c:
/*char info3[40];
sprintf(info3, "13c %i", RFIFOW(2));
- chatBox->chat_log(info3, BY_SERVER);*/
+ chatWindow->chat_log(info3, BY_SERVER);*/
inventoryWindow->items->setEquipped(RFIFOW(2), true);
break;
// Various messages
case 0x013b:
/*char msg[40];
sprintf(msg, "13b %i", RFIFOW(2));
- chatBox->chat_log(msg, BY_SERVER);*/
+ chatWindow->chat_log(msg, BY_SERVER);*/
if (RFIFOW(2) == 0)
- chatBox->chat_log("Equip arrows first", BY_SERVER);
+ chatWindow->chat_log("Equip arrows first", BY_SERVER);
break;
// Updates a stat value
case 0x00bc:
/*char stat[20];
sprintf(stat, "bc %x %i %i", RFIFOW(2),RFIFOB(4),RFIFOB(5));
- chatBox->chat_log(stat, BY_SERVER);*/
+ chatWindow->chat_log(stat, BY_SERVER);*/
if(RFIFOB(4)) {
switch(RFIFOW(2)) {
case 0x000d:
@@ -1260,7 +1260,7 @@ void do_parse() {
sprintf(stats, "%i %i %i %i %i %i %i %i %i %i %i %i",
RFIFOB(4),RFIFOB(5),RFIFOB(6),RFIFOB(7),RFIFOB(8),RFIFOB(9),
RFIFOB(10),RFIFOB(11),RFIFOB(12),RFIFOB(13),RFIFOB(14),RFIFOB(15));
- chatBox->chat_log(stats,BY_SERVER);*/
+ chatWindow->chat_log(stats,BY_SERVER);*/
statusWindow->update();
break;
// Updates status point
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) {
diff --git a/src/gui/chat.h b/src/gui/chat.h
index 39f9ab1c..3102e3bc 100644
--- a/src/gui/chat.h
+++ b/src/gui/chat.h
@@ -26,11 +26,12 @@
#include <guichan.hpp>
#include "../resources/image.h"
+#include "../net/network.h"
+#include "window.h"
#include <SDL.h>
#include <list>
#include <string>
#include <fstream>
-#include "../net/network.h"
#define BY_GM 0 // those should be self-explanatory =)
#define BY_PLAYER 1
@@ -96,17 +97,17 @@ struct CHATSKILL {
/**
* Simple chatlog object.
*/
-class ChatBox : public gcn::Widget {
+class ChatWindow : public Window, public gcn::ActionListener {
public:
/**
* Constructor.
*/
- ChatBox(const char *logfile, int item_num);
+ ChatWindow(const char *logfile, int item_num);
/**
* Destructor.
*/
- ~ChatBox();
+ ~ChatWindow();
/*
* Adds a line of text to our message list. Parameters:
@@ -126,6 +127,16 @@ class ChatBox : public gcn::Widget {
*/
void draw(gcn::Graphics *graphics);
+ /**
+ * Performs action.
+ */
+ void action(const std::string &actionId);
+
+ /**
+ * Request focus.
+ */
+ void requestFocus();
+
/*
* Determines wether to send a command or an ordinary message, then
* contructs packets & sends them
@@ -167,11 +178,11 @@ class ChatBox : public gcn::Widget {
int items;
int items_keep;
- /** constructs failed messages for actions */
+ /** Constructs failed messages for actions */
std::string const_msg(CHATSKILL);
-
- // The Alpha-Blended Surface for the background transluency effect.
- Image *chatBoxBackground;
+
+ /** Input box for chat messages */
+ gcn::TextField *chatInput;
};
#endif
diff --git a/src/resources/image.cpp b/src/resources/image.cpp
index f985b759..f976466e 100644
--- a/src/resources/image.cpp
+++ b/src/resources/image.cpp
@@ -201,11 +201,8 @@ Image* Image::load(const std::string &filePath, int flags)
Image* Image::load(void* buffer, unsigned int bufferSize)
{
- // Define our RWops structure
- SDL_RWops* rw = NULL;
-
- // Load the raw file data from the buffer
- rw = SDL_RWFromMem(buffer, bufferSize);
+ // Load the raw file data from the buffer in an RWops structure
+ SDL_RWops *rw = SDL_RWFromMem(buffer, bufferSize);
// Use SDL_Image to load the raw image data
SDL_Surface* texture = IMG_Load_RW(rw, 1);
diff --git a/src/resources/image.h b/src/resources/image.h
index ebee50d3..a257678b 100644
--- a/src/resources/image.h
+++ b/src/resources/image.h
@@ -26,10 +26,8 @@
#include "resource.h"
#include <SDL.h>
-
-#ifdef USE_OPENGL
#include <SDL_opengl.h>
-#endif
+#include <string>
// This flag causes image alpha channel to be preserved, otherwise masking is
// used.
@@ -97,8 +95,9 @@ class Image : public Resource
/**
* Creates a new image with the desired clipping rectangle.
+ *
* @return <code>NULL</code> if creation failed and a valid
- * object otherwise.
+ * object otherwise.
*/
virtual Image* getSubImage(int x, int y, int width, int height);
diff --git a/src/resources/resourcemanager.cpp b/src/resources/resourcemanager.cpp
index 12123c0a..eab6845e 100644
--- a/src/resources/resourcemanager.cpp
+++ b/src/resources/resourcemanager.cpp
@@ -119,7 +119,7 @@ Resource* ResourceManager::get(const E_RESOURCE_TYPE &type,
fileSize));
// Cleanup
- if(buffer != NULL) {
+ if (buffer != NULL) {
delete[] buffer;
}
}
diff --git a/src/resources/resourcemanager.h b/src/resources/resourcemanager.h
index ce28bc78..5c80b1a8 100644
--- a/src/resources/resourcemanager.h
+++ b/src/resources/resourcemanager.h
@@ -103,8 +103,7 @@ class ResourceManager
private:
/**
- * Searches for zip files and adds them to the PhsysicsFS search
- * path.
+ * Searches for zip files and adds them to the PhysicsFS search path.
*/
void searchAndAddZipFiles();