From c7e7b62aa94bf295ca1dc556762ad6070221e0cd Mon Sep 17 00:00:00 2001 From: Eugenio Favalli Date: Tue, 25 Jul 2006 18:04:38 +0000 Subject: Switched client to use enet and modified login sequence to work with the new protocol from tmwserv. --- src/gui/chat.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'src/gui/chat.cpp') diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp index 64b56caf..870582df 100644 --- a/src/gui/chat.cpp +++ b/src/gui/chat.cpp @@ -261,9 +261,9 @@ ChatWindow::chatSend(const std::string &nick, std::string msg) if (msg.substr(0, IS_ANNOUNCE_LENGTH) == IS_ANNOUNCE) { msg.erase(0, IS_ANNOUNCE_LENGTH); - MessageOut outMsg(mNetwork); - outMsg.writeInt16(0x0099); - outMsg.writeInt16(msg.length() + 4); + MessageOut outMsg; + outMsg.writeShort(0x0099); + outMsg.writeShort(msg.length() + 4); outMsg.writeString(msg, msg.length()); } else if (msg.substr(0, IS_HELP_LENGTH) == IS_HELP) @@ -280,8 +280,8 @@ ChatWindow::chatSend(const std::string &nick, std::string msg) } else if (msg.substr(0, IS_WHO_LENGTH) == IS_WHO) { - MessageOut outMsg(mNetwork); - outMsg.writeInt16(0x00c1); + MessageOut outMsg; + outMsg.writeShort(0x00c1); } else { @@ -292,9 +292,9 @@ ChatWindow::chatSend(const std::string &nick, std::string msg) else { msg = nick + " : " + msg; - MessageOut outMsg(mNetwork); - outMsg.writeInt16(CMSG_CHAT_MESSAGE); - outMsg.writeInt16(msg.length() + 4); + MessageOut outMsg; + outMsg.writeShort(CMSG_CHAT_MESSAGE); + outMsg.writeShort(msg.length() + 4); outMsg.writeString(msg, msg.length()); } } -- cgit v1.2.3-70-g09d2 From aff167beefadc32add4b44626cc2f1cbef800c7b Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Sun, 30 Jul 2006 14:33:28 +0000 Subject: Updated TMW to be compatible with Guichan 0.5.0 (merged from guichan-0.5.0 branch). --- ChangeLog | 33 +++++++++++++++++++++ INSTALL | 6 ++-- src/Makefile.am | 4 +-- src/game.cpp | 4 +-- src/gui/box.h | 27 +++++++++-------- src/gui/buddywindow.cpp | 2 +- src/gui/buddywindow.h | 2 +- src/gui/buy.cpp | 2 +- src/gui/buy.h | 2 +- src/gui/buysell.cpp | 2 +- src/gui/buysell.h | 2 +- src/gui/char_select.cpp | 10 +++---- src/gui/char_select.h | 6 ++-- src/gui/chat.cpp | 27 +++++++++-------- src/gui/chat.h | 2 +- src/gui/confirm_dialog.cpp | 4 +-- src/gui/confirm_dialog.h | 2 +- src/gui/connection.cpp | 2 +- src/gui/debugwindow.cpp | 2 +- src/gui/debugwindow.h | 2 +- src/gui/gui.cpp | 10 +++---- src/gui/help.cpp | 2 +- src/gui/help.h | 2 +- src/gui/inventorywindow.cpp | 7 +++-- src/gui/inventorywindow.h | 2 +- src/gui/item_amount.cpp | 2 +- src/gui/item_amount.h | 2 +- src/gui/login.cpp | 4 +-- src/gui/login.h | 4 +-- src/gui/menuwindow.cpp | 8 ++--- src/gui/ministatus.cpp | 2 +- src/gui/newskill.cpp | 2 +- src/gui/newskill.h | 2 +- src/gui/npc_text.cpp | 2 +- src/gui/npc_text.h | 2 +- src/gui/npclistdialog.cpp | 2 +- src/gui/npclistdialog.h | 2 +- src/gui/ok_dialog.cpp | 4 +-- src/gui/ok_dialog.h | 2 +- src/gui/register.cpp | 2 +- src/gui/register.h | 2 +- src/gui/scrollarea.cpp | 37 +++++++++++++----------- src/gui/sell.cpp | 2 +- src/gui/sell.h | 2 +- src/gui/setup.cpp | 2 +- src/gui/setup.h | 2 +- src/gui/setup_audio.cpp | 2 +- src/gui/setup_audio.h | 2 +- src/gui/setup_joystick.cpp | 2 +- src/gui/setup_joystick.h | 2 +- src/gui/setup_video.cpp | 2 +- src/gui/setup_video.h | 2 +- src/gui/skill.cpp | 2 +- src/gui/skill.h | 2 +- src/gui/status.cpp | 2 +- src/gui/status.h | 2 +- src/gui/tabbedcontainer.cpp | 2 +- src/gui/tabbedcontainer.h | 4 +-- src/gui/textfield.cpp | 2 +- src/gui/trade.cpp | 2 +- src/gui/trade.h | 2 +- src/gui/updatewindow.cpp | 6 ++-- src/gui/updatewindow.h | 2 +- src/gui/vbox.cpp | 18 +++++++----- src/gui/window.cpp | 34 ++++++++-------------- src/main.cpp | 8 +++-- src/net/network.cpp | 11 +++++-- src/net/playerhandler.cpp | 4 +-- src/net/tradehandler.cpp | 2 +- src/openglgraphics.cpp | 28 +++++++++--------- src/resources/openglsdlimageloader.cpp | 34 ++++++++++++++++++++++ src/resources/openglsdlimageloader.h | 37 ++++++++++++++++++++++++ src/resources/resourcemanager.cpp | 17 +++++++++++ src/resources/resourcemanager.h | 8 +++++ src/resources/sdlimageloader.cpp | 53 ++-------------------------------- src/resources/sdlimageloader.h | 4 +-- src/sound.cpp | 2 +- 77 files changed, 320 insertions(+), 235 deletions(-) create mode 100644 src/resources/openglsdlimageloader.cpp create mode 100644 src/resources/openglsdlimageloader.h (limited to 'src/gui/chat.cpp') diff --git a/ChangeLog b/ChangeLog index f98cea5c..9105dbe7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,36 @@ +2006-07-30 Bjørn Lindeijer + + * src/openglgraphics.cpp, src/game.cpp, src/main.cpp, + src/gui/buddywindow.cpp, src/gui/connection.cpp, src/gui/sell.cpp, + src/gui/trade.cpp, src/gui/char_server.cpp, src/gui/window.cpp, + src/gui/login.cpp, src/gui/skill.h, src/gui/gui.cpp, + src/gui/item_amount.h, src/gui/setup_audio.h, src/gui/newskill.cpp, + src/gui/register.h, src/gui/setup.cpp, src/gui/npclistdialog.h, + src/gui/updatewindow.cpp, src/gui/char_select.cpp, src/gui/login.h, + src/gui/item_amount.cpp, src/gui/setup_audio.cpp, + src/gui/npc_text.cpp, src/gui/chat.h, src/gui/setup_joystick.h, + src/gui/setup_video.cpp, src/gui/ok_dialog.cpp, src/gui/textfield.cpp, + src/gui/inventorywindow.h, src/gui/newskill.h, src/gui/box.h, + src/gui/ministatus.cpp, src/gui/buy.h, src/gui/setup.h, + src/gui/confirm_dialog.cpp, src/gui/debugwindow.cpp, src/gui/vbox.cpp, + src/gui/chat.cpp, src/gui/setup_joystick.cpp, src/gui/updatewindow.h, + src/gui/char_select.h, src/gui/buysell.h, src/gui/tabbedcontainer.cpp, + src/gui/inventorywindow.cpp, src/gui/help.cpp, src/gui/status.h, + src/gui/npc_text.h, src/gui/setup_video.h, src/gui/menuwindow.cpp, + src/gui/ok_dialog.h, src/gui/buy.cpp, src/gui/buddywindow.h, + src/gui/sell.h, src/gui/trade.h, src/gui/char_server.h, + src/gui/skill.cpp, src/gui/buysell.cpp, src/gui/confirm_dialog.h, + src/gui/debugwindow.h, src/gui/status.cpp, src/gui/register.cpp, + src/gui/scrollarea.cpp, src/gui/tabbedcontainer.h, + src/gui/npclistdialog.cpp, src/gui/help.h, src/net/tradehandler.cpp, + src/net/playerhandler.cpp, src/Makefile.am, + src/resources/sdlimageloader.cpp, src/resources/sdlimageloader.h, + src/resources/openglsdlimageloader.cpp, + src/resources/resourcemanager.cpp, + src/resources/openglsdlimageloader.h, src/resources/resourcemanager.h: + Updated TMW to be compatible with Guichan 0.5.0 (merged from + guichan-0.5.0 branch). + 2006-07-27 Eugenio Favalli * src/gui/main.cpp: Modified client version to be an int. diff --git a/INSTALL b/INSTALL index 6cf5b6e5..9779a37a 100644 --- a/INSTALL +++ b/INSTALL @@ -48,11 +48,9 @@ It should have installed The Mana World on your system now, and you can run it with "tmw". By default all files are installed to /usr/local, you can pass a different prefix to configure as usual. - NOTE: For those people with modern video cards and fast OpenGL performance, - we have been working on OpenGL support. At the moment there is no way to - switch between SDL and OpenGL dynamically and you need to do this at compile - time. To try this perform step 3 as follows: + we have been working on OpenGL support. To enable this perform step 3 as + follows: "./configure --with-opengl" diff --git a/src/Makefile.am b/src/Makefile.am index 1bb1d538..42e72829 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -12,8 +12,6 @@ tmw_SOURCES = graphic/imagerect.h \ gui/buysell.h \ gui/chargedialog.cpp \ gui/chargedialog.h \ - gui/char_server.cpp \ - gui/char_server.h \ gui/char_select.cpp \ gui/char_select.h \ gui/chat.cpp \ @@ -167,6 +165,8 @@ tmw_SOURCES = graphic/imagerect.h \ resources/mapreader.h \ resources/music.h \ resources/music.cpp \ + resources/openglsdlimageloader.h \ + resources/openglsdlimageloader.cpp \ resources/resource.cpp \ resources/resource.h \ resources/resourcemanager.cpp \ diff --git a/src/game.cpp b/src/game.cpp index 51b541a6..fab88aa9 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -122,7 +122,7 @@ const int MAX_TIME = 10000; */ namespace { struct ExitListener : public gcn::ActionListener { - void action(const std::string &eventId) { + void action(const std::string &eventId, gcn::Widget *widget) { if (eventId == "yes") { done = true; } @@ -465,7 +465,7 @@ void Game::handleInput() // Close the config window, cancelling changes if opened else if (setupWindow->isVisible()) { - setupWindow->action("cancel"); + setupWindow->action("cancel", NULL); } // Else, open the chat edit box else diff --git a/src/gui/box.h b/src/gui/box.h index dccbfc78..ed1a7163 100644 --- a/src/gui/box.h +++ b/src/gui/box.h @@ -31,27 +31,30 @@ class Box : public gcn::Container { + public: + /** + * Returns padding. + */ + unsigned int getPadding(); + + /** + * Sets padding between widgets. + */ + void setPadding(unsigned int); + protected: Box(); virtual ~Box(); - /* - * Spacing between client widgets + /** + * Spacing between client widgets. */ unsigned int padding; virtual void draw(gcn::Graphics *) = 0; - public: - /* - * Returns padding - */ - unsigned int getPadding(); - - /* - * Sets padding between widgets - */ - void setPadding(unsigned int); + typedef std::list Widgets; + typedef Widgets::iterator WidgetIterator; }; #endif diff --git a/src/gui/buddywindow.cpp b/src/gui/buddywindow.cpp index 19a2f1e0..145f0ad2 100644 --- a/src/gui/buddywindow.cpp +++ b/src/gui/buddywindow.cpp @@ -61,7 +61,7 @@ BuddyWindow::BuddyWindow(): add(cancel); } -void BuddyWindow::action(const std::string& eventId) +void BuddyWindow::action(const std::string &eventId, gcn::Widget *widget) { if (eventId == "Talk") { int selected = mListbox->getSelected(); diff --git a/src/gui/buddywindow.h b/src/gui/buddywindow.h index 6eeb7999..8764d008 100644 --- a/src/gui/buddywindow.h +++ b/src/gui/buddywindow.h @@ -48,7 +48,7 @@ class BuddyWindow : public Window, public gcn::ActionListener /** * Performs action. */ - void action(const std::string &actionId); + void action(const std::string& eventId, gcn::Widget* widget); private: BuddyList *mBuddyList; diff --git a/src/gui/buy.cpp b/src/gui/buy.cpp index e96cc04f..e7bfef58 100644 --- a/src/gui/buy.cpp +++ b/src/gui/buy.cpp @@ -148,7 +148,7 @@ void BuyDialog::addItem(short id, int price) mItemList->adjustSize(); } -void BuyDialog::action(const std::string& eventId) +void BuyDialog::action(const std::string &eventId, gcn::Widget *widget) { int selectedItem = mItemList->getSelected(); diff --git a/src/gui/buy.h b/src/gui/buy.h index 0349be4a..b09b648b 100644 --- a/src/gui/buy.h +++ b/src/gui/buy.h @@ -71,7 +71,7 @@ class BuyDialog : public Window, public gcn::ActionListener /** * Called when receiving actions from the widgets. */ - void action(const std::string& eventId); + void action(const std::string& eventId, gcn::Widget* widget); /** * Returns the number of items in the shop inventory. diff --git a/src/gui/buysell.cpp b/src/gui/buysell.cpp index 6e338f08..ac0dcc84 100644 --- a/src/gui/buysell.cpp +++ b/src/gui/buysell.cpp @@ -50,7 +50,7 @@ BuySellDialog::BuySellDialog(): setLocationRelativeTo(getParent()); } -void BuySellDialog::action(const std::string& eventId) +void BuySellDialog::action(const std::string &eventId, gcn::Widget *widget) { if (eventId == "Buy") { current_npc->buy(); diff --git a/src/gui/buysell.h b/src/gui/buysell.h index 2d3c7bd3..7a90a869 100644 --- a/src/gui/buysell.h +++ b/src/gui/buysell.h @@ -47,7 +47,7 @@ class BuySellDialog : public Window, public gcn::ActionListener /** * Called when receiving actions from the widgets. */ - void action(const std::string& eventId); + void action(const std::string& eventId, gcn::Widget* widget); }; #endif diff --git a/src/gui/char_select.cpp b/src/gui/char_select.cpp index e8aa84e0..934988f4 100644 --- a/src/gui/char_select.cpp +++ b/src/gui/char_select.cpp @@ -48,7 +48,7 @@ class CharDeleteConfirm : public ConfirmDialog { public: CharDeleteConfirm(CharSelectDialog *master); - void action(const std::string &eventId); + void action(const std::string &eventId, gcn::Widget *widget); private: CharSelectDialog *master; }; @@ -60,13 +60,13 @@ CharDeleteConfirm::CharDeleteConfirm(CharSelectDialog *m): { } -void CharDeleteConfirm::action(const std::string &eventId) +void CharDeleteConfirm::action(const std::string &eventId, gcn::Widget *widget) { //ConfirmDialog::action(eventId); if (eventId == "yes") { master->attemptCharDelete(); } - ConfirmDialog::action(eventId); + ConfirmDialog::action(eventId, widget); } CharSelectDialog::CharSelectDialog(Network *network, @@ -126,7 +126,7 @@ CharSelectDialog::CharSelectDialog(Network *network, updatePlayerInfo(); } -void CharSelectDialog::action(const std::string& eventId) +void CharSelectDialog::action(const std::string &eventId, gcn::Widget *widget) { if (eventId == "ok" && n_character > 0) { @@ -284,7 +284,7 @@ CharCreateDialog::CharCreateDialog(Window *parent, int slot, Network *network, setLocationRelativeTo(getParent()); } -void CharCreateDialog::action(const std::string& eventId) +void CharCreateDialog::action(const std::string &eventId, gcn::Widget *widget) { if (eventId == "create") { if (getName().length() >= 4) { diff --git a/src/gui/char_select.h b/src/gui/char_select.h index 8fc7cd01..20105516 100644 --- a/src/gui/char_select.h +++ b/src/gui/char_select.h @@ -29,6 +29,8 @@ #include "../guichanfwd.h" #include "../lockedarray.h" +#include + class LocalPlayer; class Network; class PlayerBox; @@ -49,7 +51,7 @@ class CharSelectDialog : public Window, public gcn::ActionListener LockedArray *charInfo, unsigned char sex); - void action(const std::string& eventId); + void action(const std::string& eventId, gcn::Widget* widget); void updatePlayerInfo(); @@ -101,7 +103,7 @@ class CharCreateDialog : public Window, public gcn::ActionListener CharCreateDialog(Window *parent, int slot, Network *network, unsigned char sex); - void action(const std::string& eventId); + void action(const std::string& eventId, gcn::Widget* widget); std::string getName(); diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp index 870582df..133e5e3a 100644 --- a/src/gui/chat.cpp +++ b/src/gui/chat.cpp @@ -85,18 +85,17 @@ ChatWindow::~ChatWindow() void ChatWindow::logic() { - mChatInput->setPosition( - mChatInput->getBorderSize(), - getContent()->getHeight() - mChatInput->getHeight() - - mChatInput->getBorderSize()); - mChatInput->setWidth( - getContent()->getWidth() - 2 * mChatInput->getBorderSize()); - - mScrollArea->setWidth( - getContent()->getWidth() - 2 * mScrollArea->getBorderSize()); - mScrollArea->setHeight( - getContent()->getHeight() - 2 * mScrollArea->getBorderSize() - - mChatInput->getHeight() - 5); + // todo: only do this when the size changes (updateWidgets?) + + const gcn::Rectangle area = getChildrenArea(); + + mChatInput->setPosition(mChatInput->getBorderSize(), + area.height - mChatInput->getHeight() - + mChatInput->getBorderSize()); + mChatInput->setWidth(area.width - 2 * mChatInput->getBorderSize()); + mScrollArea->setWidth(area.width - 2 * mScrollArea->getBorderSize()); + mScrollArea->setHeight(area.height - 2 * mScrollArea->getBorderSize() - + mChatInput->getHeight() - 5); mScrollArea->logic(); } @@ -189,7 +188,7 @@ ChatWindow::chatLog(CHATSKILL act) } void -ChatWindow::action(const std::string& eventId) +ChatWindow::action(const std::string &eventId, gcn::Widget *widget) { if (eventId == "chatinput") { @@ -246,7 +245,7 @@ ChatWindow::requestChatFocus() bool ChatWindow::isFocused() { - return mChatInput->hasFocus(); + return mChatInput->isFocused(); } void diff --git a/src/gui/chat.h b/src/gui/chat.h index 80e57a84..addfb6b5 100644 --- a/src/gui/chat.h +++ b/src/gui/chat.h @@ -145,7 +145,7 @@ class ChatWindow : public Window, public gcn::ActionListener, /** * Performs action. */ - void action(const std::string &actionId); + void action(const std::string& actionId, gcn::Widget* widget); /** * Request focus for typing chat message. diff --git a/src/gui/confirm_dialog.cpp b/src/gui/confirm_dialog.cpp index 2d574157..ed2f8680 100644 --- a/src/gui/confirm_dialog.cpp +++ b/src/gui/confirm_dialog.cpp @@ -64,13 +64,13 @@ ConfirmDialog::ConfirmDialog(const std::string &title, const std::string &msg, yesButton->requestFocus(); } -void ConfirmDialog::action(const std::string &eventId) +void ConfirmDialog::action(const std::string &eventId, gcn::Widget *widget) { // Proxy button events to our listeners ActionListenerIterator i; for (i = mActionListeners.begin(); i != mActionListeners.end(); ++i) { - (*i)->action(eventId); + (*i)->action(eventId, widget); } // Can we receive anything else anyway? diff --git a/src/gui/confirm_dialog.h b/src/gui/confirm_dialog.h index 3a05494f..1c206b03 100644 --- a/src/gui/confirm_dialog.h +++ b/src/gui/confirm_dialog.h @@ -47,7 +47,7 @@ class ConfirmDialog : public Window, public gcn::ActionListener { /** * Called when receiving actions from the widgets. */ - void action(const std::string& eventId); + void action(const std::string& eventId, gcn::Widget* widget); }; #endif diff --git a/src/gui/connection.cpp b/src/gui/connection.cpp index 4bd619ea..f7fdaca6 100644 --- a/src/gui/connection.cpp +++ b/src/gui/connection.cpp @@ -35,7 +35,7 @@ namespace { struct ConnectionActionListener : public gcn::ActionListener { - void action(const std::string& eventId) { state = EXIT_STATE; } + void action(const std::string &eventId, gcn::Widget *widget) { state = EXIT_STATE; } } listener; } diff --git a/src/gui/debugwindow.cpp b/src/gui/debugwindow.cpp index 66681a8b..d467d4d3 100644 --- a/src/gui/debugwindow.cpp +++ b/src/gui/debugwindow.cpp @@ -98,7 +98,7 @@ DebugWindow::logic() } void -DebugWindow::action(const std::string& eventId) +DebugWindow::action(const std::string &eventId, gcn::Widget *widget) { if (eventId == "close") { diff --git a/src/gui/debugwindow.h b/src/gui/debugwindow.h index 80524ffa..61ef44e6 100644 --- a/src/gui/debugwindow.h +++ b/src/gui/debugwindow.h @@ -53,7 +53,7 @@ class DebugWindow : public Window, public gcn::ActionListener /** * Performs action. */ - void action(const std::string &actionId); + void action(const std::string& eventId, gcn::Widget* widget); private: gcn::Label *mMusicFileLabel, *mMapFileLabel; diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index cb79e54b..c980389f 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -28,7 +28,7 @@ #include #ifdef USE_OPENGL -#include +#include "../resources/openglsdlimageloader.h" #endif #include @@ -92,16 +92,14 @@ Gui::Gui(Graphics *graphics): { // Set graphics setGraphics(graphics); + + // Set image loader #ifdef USE_OPENGL if (config.getValue("opengl", 0)) { - - // Set image loader - mHostImageLoader = new SDLImageLoader(); - mImageLoader = new gcn::OpenGLImageLoader(mHostImageLoader); + mImageLoader = new OpenGLSDLImageLoader(); } else #endif { - // Set image loader mImageLoader = new SDLImageLoader(); } diff --git a/src/gui/help.cpp b/src/gui/help.cpp index dfb814db..e7429b29 100644 --- a/src/gui/help.cpp +++ b/src/gui/help.cpp @@ -54,7 +54,7 @@ HelpWindow::HelpWindow(): setLocationRelativeTo(getParent()); } -void HelpWindow::action(const std::string& eventId) +void HelpWindow::action(const std::string &eventId, gcn::Widget *widget) { if (eventId == "close") { diff --git a/src/gui/help.h b/src/gui/help.h index 44c3d6fc..539ab31b 100644 --- a/src/gui/help.h +++ b/src/gui/help.h @@ -48,7 +48,7 @@ class HelpWindow : public Window, public LinkHandler, /** * Called when receiving actions from the widgets. */ - void action(const std::string& eventId); + void action(const std::string& eventId, gcn::Widget* widget); /** * Handles link action. diff --git a/src/gui/inventorywindow.cpp b/src/gui/inventorywindow.cpp index 8f672bc9..063e8836 100644 --- a/src/gui/inventorywindow.cpp +++ b/src/gui/inventorywindow.cpp @@ -95,7 +95,7 @@ void InventoryWindow::logic() mWeightLabel->adjustSize(); } -void InventoryWindow::action(const std::string &eventId) +void InventoryWindow::action(const std::string &eventId, gcn::Widget *widget) { Item *item = mItems->getItem(); @@ -168,8 +168,9 @@ void InventoryWindow::mouseMotion(int mx, int my) void InventoryWindow::updateWidgets() { - int width = getContent()->getWidth(); - int height = getContent()->getHeight(); + gcn::Rectangle area = getChildrenArea(); + int width = area.width; + int height = area.height; int columns = width / 24; if (columns < 1) diff --git a/src/gui/inventorywindow.h b/src/gui/inventorywindow.h index 179e5314..da7a7ef2 100644 --- a/src/gui/inventorywindow.h +++ b/src/gui/inventorywindow.h @@ -54,7 +54,7 @@ class InventoryWindow : public Window, gcn::ActionListener /** * Called when receiving actions from the widgets. */ - void action(const std::string& eventId); + void action(const std::string& eventId, gcn::Widget* widget); void mouseClick(int x, int y, int button, int count); diff --git a/src/gui/item_amount.cpp b/src/gui/item_amount.cpp index b1b01c3f..30c899a8 100644 --- a/src/gui/item_amount.cpp +++ b/src/gui/item_amount.cpp @@ -94,7 +94,7 @@ void ItemAmountWindow::resetAmount() mItemAmountTextBox->setInt(1); } -void ItemAmountWindow::action(const std::string& eventId) +void ItemAmountWindow::action(const std::string &eventId, gcn::Widget *widget) { int amount = mItemAmountTextBox->getInt(); diff --git a/src/gui/item_amount.h b/src/gui/item_amount.h index ad1e18d6..a2a17575 100644 --- a/src/gui/item_amount.h +++ b/src/gui/item_amount.h @@ -54,7 +54,7 @@ class ItemAmountWindow : public Window, public gcn::ActionListener /** * Called when receiving actions from widget. */ - void action(const std::string& eventId); + void action(const std::string& eventId, gcn::Widget* widget); /** * Sets default amount value. diff --git a/src/gui/login.cpp b/src/gui/login.cpp index c0dd9245..2f646bd1 100644 --- a/src/gui/login.cpp +++ b/src/gui/login.cpp @@ -43,7 +43,7 @@ WrongDataNoticeListener::setTarget(gcn::TextField *textField) } void -WrongDataNoticeListener::action(const std::string &eventId) +WrongDataNoticeListener::action(const std::string &eventId, gcn::Widget *widget) { if (eventId == "ok") { @@ -128,7 +128,7 @@ LoginDialog::~LoginDialog() } void -LoginDialog::action(const std::string& eventId) +LoginDialog::action(const std::string &eventId, gcn::Widget *widget) { if (eventId == "ok") { diff --git a/src/gui/login.h b/src/gui/login.h index 39548950..7218dca8 100644 --- a/src/gui/login.h +++ b/src/gui/login.h @@ -38,7 +38,7 @@ class LoginData; class WrongDataNoticeListener : public gcn::ActionListener { public: void setTarget(gcn::TextField *textField); - void action(const std::string &eventId); + void action(const std::string& eventId, gcn::Widget* widget); private: gcn::TextField *mTarget; }; @@ -65,7 +65,7 @@ class LoginDialog : public Window, public gcn::ActionListener { /** * Called when receiving actions from the widgets. */ - void action(const std::string& eventId); + void action(const std::string& eventId, gcn::Widget* widget); private: gcn::TextField *mUserField; diff --git a/src/gui/menuwindow.cpp b/src/gui/menuwindow.cpp index 503f7ba8..a1b342f0 100644 --- a/src/gui/menuwindow.cpp +++ b/src/gui/menuwindow.cpp @@ -39,7 +39,7 @@ namespace { /** * Called when receiving actions from widget. */ - void action(const std::string& eventId); + void action(const std::string &eventId, gcn::Widget *widget); } listener; } @@ -69,13 +69,13 @@ MenuWindow::MenuWindow(): setDefaultSize((windowContainer->getWidth() - x - 2), 0, x, (y + h)); } -void MenuWindow::draw(gcn::Graphics *g) +void MenuWindow::draw(gcn::Graphics *graphics) { - Window::drawContent(g); + drawChildren(graphics); } -void MenuWindowListener::action(const std::string& eventId) +void MenuWindowListener::action(const std::string &eventId, gcn::Widget *widget) { Window *window = NULL; if (eventId == "Status") diff --git a/src/gui/ministatus.cpp b/src/gui/ministatus.cpp index be089b68..53849550 100644 --- a/src/gui/ministatus.cpp +++ b/src/gui/ministatus.cpp @@ -96,5 +96,5 @@ void MiniStatusWindow::update() void MiniStatusWindow::draw(gcn::Graphics *graphics) { update(); - Window::drawContent(graphics); + drawChildren(graphics); } diff --git a/src/gui/newskill.cpp b/src/gui/newskill.cpp index 498186ba..7f5de543 100644 --- a/src/gui/newskill.cpp +++ b/src/gui/newskill.cpp @@ -121,7 +121,7 @@ NewSkillDialog::NewSkillDialog(): setLocationRelativeTo(getParent()); } -void NewSkillDialog::action(const std::string& eventId) +void NewSkillDialog::action(const std::string &eventId, gcn::Widget *widget) { int osp = startPoint; if (eventId == "close") diff --git a/src/gui/newskill.h b/src/gui/newskill.h index 764019f5..224574bd 100644 --- a/src/gui/newskill.h +++ b/src/gui/newskill.h @@ -55,7 +55,7 @@ class NewSkillDialog : public Window, public gcn::ActionListener NewSkillDialog(); // action listener - void action(const std::string&); + void action(const std::string& eventId, gcn::Widget* widget); private: void resetNSD(); // updates the values in the dialog box diff --git a/src/gui/npc_text.cpp b/src/gui/npc_text.cpp index 1a6bb5ce..5b7ca439 100644 --- a/src/gui/npc_text.cpp +++ b/src/gui/npc_text.cpp @@ -67,7 +67,7 @@ NpcTextDialog::addText(const std::string &text) } void -NpcTextDialog::action(const std::string& eventId) +NpcTextDialog::action(const std::string &eventId, gcn::Widget *widget) { if (eventId == "ok") { diff --git a/src/gui/npc_text.h b/src/gui/npc_text.h index a1d75aab..3ce1215d 100644 --- a/src/gui/npc_text.h +++ b/src/gui/npc_text.h @@ -49,7 +49,7 @@ class NpcTextDialog : public Window, public gcn::ActionListener * Called when receiving actions from the widgets. */ void - action(const std::string &eventId); + action(const std::string& eventId, gcn::Widget* widget); /** * Sets the text shows in the dialog. diff --git a/src/gui/npclistdialog.cpp b/src/gui/npclistdialog.cpp index 2d12986d..d1c3ddcb 100644 --- a/src/gui/npclistdialog.cpp +++ b/src/gui/npclistdialog.cpp @@ -91,7 +91,7 @@ NpcListDialog::reset() } void -NpcListDialog::action(const std::string& eventId) +NpcListDialog::action(const std::string &eventId, gcn::Widget *widget) { int choice = 0; diff --git a/src/gui/npclistdialog.h b/src/gui/npclistdialog.h index 7d649450..03b76681 100644 --- a/src/gui/npclistdialog.h +++ b/src/gui/npclistdialog.h @@ -54,7 +54,7 @@ class NpcListDialog : public Window, public gcn::ActionListener, * Called when receiving actions from the widgets. */ void - action(const std::string& eventId); + action(const std::string& eventId, gcn::Widget* widget); /** * Returns the number of items in the choices list. diff --git a/src/gui/ok_dialog.cpp b/src/gui/ok_dialog.cpp index 2f3f21c5..906fd61f 100644 --- a/src/gui/ok_dialog.cpp +++ b/src/gui/ok_dialog.cpp @@ -54,13 +54,13 @@ OkDialog::OkDialog(const std::string &title, const std::string &msg, okButton->requestFocus(); } -void OkDialog::action(const std::string &eventId) +void OkDialog::action(const std::string &eventId, gcn::Widget *widget) { // Proxy button events to our listeners ActionListenerIterator i; for (i = mActionListeners.begin(); i != mActionListeners.end(); ++i) { - (*i)->action(eventId); + (*i)->action(eventId, widget); } // Can we receive anything else anyway? diff --git a/src/gui/ok_dialog.h b/src/gui/ok_dialog.h index eb0da2c0..06f703cc 100644 --- a/src/gui/ok_dialog.h +++ b/src/gui/ok_dialog.h @@ -46,7 +46,7 @@ class OkDialog : public Window, public gcn::ActionListener { /** * Called when receiving actions from the widgets. */ - void action(const std::string& eventId); + void action(const std::string& eventId, gcn::Widget* widget); }; #endif diff --git a/src/gui/register.cpp b/src/gui/register.cpp index b99568a8..38136b87 100644 --- a/src/gui/register.cpp +++ b/src/gui/register.cpp @@ -116,7 +116,7 @@ RegisterDialog::~RegisterDialog() } void -RegisterDialog::action(const std::string& eventId) +RegisterDialog::action(const std::string &eventId, gcn::Widget *widget) { if (eventId == "cancel") { diff --git a/src/gui/register.h b/src/gui/register.h index b46eb1ce..5d3f6cd5 100644 --- a/src/gui/register.h +++ b/src/gui/register.h @@ -56,7 +56,7 @@ class RegisterDialog : public Window, public gcn::ActionListener { /** * Called when receiving actions from the widgets. */ - void action(const std::string& eventId); + void action(const std::string& eventId, gcn::Widget* widget); // Made them public to have the possibility to request focus // from external functions. diff --git a/src/gui/scrollarea.cpp b/src/gui/scrollarea.cpp index 3703ead8..18a1dfb4 100644 --- a/src/gui/scrollarea.cpp +++ b/src/gui/scrollarea.cpp @@ -55,7 +55,7 @@ ScrollArea::~ScrollArea() { // Garbage collection if (mGC) { - delete mContent; + delete getContent(); } instances--; @@ -144,20 +144,21 @@ void ScrollArea::init() void ScrollArea::logic() { gcn::ScrollArea::logic(); + gcn::Widget *content = getContent(); // When no scrollbar in a certain direction, adapt content size to match // the content dimension exactly. - if (mContent != NULL) + if (content != NULL) { if (getHorizontalScrollPolicy() == gcn::ScrollArea::SHOW_NEVER) { - mContent->setWidth(getContentDimension().width - - 2 * mContent->getBorderSize()); + content->setWidth(getChildrenArea().width - + 2 * content->getBorderSize()); } if (getVerticalScrollPolicy() == gcn::ScrollArea::SHOW_NEVER) { - mContent->setHeight(getContentDimension().height - - 2 * mContent->getBorderSize()); + content->setHeight(getChildrenArea().height - + 2 * content->getBorderSize()); } } } @@ -197,24 +198,26 @@ void ScrollArea::draw(gcn::Graphics *graphics) mScrollbarWidth)); } - if (mContent) + gcn::Widget *content = getContent(); + + if (content != NULL) { - graphics->pushClipArea(getContentDimension()); + graphics->pushClipArea(getChildrenArea()); - if (mContent->getBorderSize() > 0) + if (content->getBorderSize() > 0) { - gcn::Rectangle rec = mContent->getDimension(); - rec.x -= mContent->getBorderSize(); - rec.y -= mContent->getBorderSize(); - rec.width += 2 * mContent->getBorderSize(); - rec.height += 2 * mContent->getBorderSize(); + gcn::Rectangle rec = content->getDimension(); + rec.x -= content->getBorderSize(); + rec.y -= content->getBorderSize(); + rec.width += 2 * content->getBorderSize(); + rec.height += 2 * content->getBorderSize(); graphics->pushClipArea(rec); - mContent->drawBorder(graphics); + content->drawBorder(graphics); graphics->popClipArea(); } - graphics->pushClipArea(mContent->getDimension()); - mContent->draw(graphics); + graphics->pushClipArea(content->getDimension()); + content->draw(graphics); graphics->popClipArea(); graphics->popClipArea(); } diff --git a/src/gui/sell.cpp b/src/gui/sell.cpp index 0b7abf6f..e820d42f 100644 --- a/src/gui/sell.cpp +++ b/src/gui/sell.cpp @@ -152,7 +152,7 @@ void SellDialog::addItem(Item *item, int price) mItemList->adjustSize(); } -void SellDialog::action(const std::string& eventId) +void SellDialog::action(const std::string &eventId, gcn::Widget *widget) { int selectedItem = mItemList->getSelected(); diff --git a/src/gui/sell.h b/src/gui/sell.h index 59bc58c2..423fea26 100644 --- a/src/gui/sell.h +++ b/src/gui/sell.h @@ -68,7 +68,7 @@ class SellDialog : public Window, public gcn::ActionListener /** * Called when receiving actions from the widgets. */ - void action(const std::string& eventId); + void action(const std::string& eventId, gcn::Widget* widget); /** * Mouse callback diff --git a/src/gui/setup.cpp b/src/gui/setup.cpp index e0e0e81b..6af9119b 100644 --- a/src/gui/setup.cpp +++ b/src/gui/setup.cpp @@ -85,7 +85,7 @@ Setup::~Setup() for_each(mTabs.begin(), mTabs.end(), make_dtor(mTabs)); } -void Setup::action(const std::string &event) +void Setup::action(const std::string& event, gcn::Widget *widget) { if (event == "Apply") { diff --git a/src/gui/setup.h b/src/gui/setup.h index 611633c5..6601ce3d 100644 --- a/src/gui/setup.h +++ b/src/gui/setup.h @@ -54,7 +54,7 @@ class Setup : public Window, public gcn::ActionListener * Event handling method. */ void - action(const std::string& eventId); + action(const std::string& eventId, gcn::Widget* widget); private: std::list mTabs; diff --git a/src/gui/setup_audio.cpp b/src/gui/setup_audio.cpp index 6f884e2f..db88ff64 100644 --- a/src/gui/setup_audio.cpp +++ b/src/gui/setup_audio.cpp @@ -108,7 +108,7 @@ void Setup_Audio::cancel() config.setValue("musicVolume", mMusicVolume); } -void Setup_Audio::action(const std::string &event) +void Setup_Audio::action(const std::string& event, gcn::Widget *widget) { if (event == "sfx") { diff --git a/src/gui/setup_audio.h b/src/gui/setup_audio.h index 706d6a50..f09f62da 100644 --- a/src/gui/setup_audio.h +++ b/src/gui/setup_audio.h @@ -38,7 +38,7 @@ class Setup_Audio : public SetupTab, public gcn::ActionListener void apply(); void cancel(); - void action(const std::string&); + void action(const std::string& eventId, gcn::Widget* widget); private: int mMusicVolume, mSfxVolume; diff --git a/src/gui/setup_joystick.cpp b/src/gui/setup_joystick.cpp index fdf50980..36b0ee20 100644 --- a/src/gui/setup_joystick.cpp +++ b/src/gui/setup_joystick.cpp @@ -44,7 +44,7 @@ Setup_Joystick::Setup_Joystick(): add(mCalibrateButton); } -void Setup_Joystick::action(const std::string &event) +void Setup_Joystick::action(const std::string &event, gcn::Widget *widget) { if (!joystick) { return; diff --git a/src/gui/setup_joystick.h b/src/gui/setup_joystick.h index 2abe9678..da773c8f 100644 --- a/src/gui/setup_joystick.h +++ b/src/gui/setup_joystick.h @@ -38,7 +38,7 @@ class Setup_Joystick : public SetupTab, public gcn::ActionListener void apply() {} void cancel() {} - void action(const std::string&); + void action(const std::string& eventId, gcn::Widget* widget); private: gcn::Label *mCalibrateLabel; diff --git a/src/gui/setup_video.cpp b/src/gui/setup_video.cpp index 05543092..9eb94520 100644 --- a/src/gui/setup_video.cpp +++ b/src/gui/setup_video.cpp @@ -237,7 +237,7 @@ void Setup_Video::cancel() config.setValue("opengl", mOpenGLEnabled ? 1 : 0); } -void Setup_Video::action(const std::string &event) +void Setup_Video::action(const std::string &event, gcn::Widget *widget) { if (event == "guialpha") { diff --git a/src/gui/setup_video.h b/src/gui/setup_video.h index b021ead4..d0a10925 100644 --- a/src/gui/setup_video.h +++ b/src/gui/setup_video.h @@ -41,7 +41,7 @@ class Setup_Video : public SetupTab, public gcn::ActionListener, void apply(); void cancel(); - void action(const std::string&); + void action(const std::string &eventId, gcn::Widget *widget); /** Called when key is pressed */ void keyPress(const gcn::Key& key); diff --git a/src/gui/skill.cpp b/src/gui/skill.cpp index 604a19cc..4f552fd7 100644 --- a/src/gui/skill.cpp +++ b/src/gui/skill.cpp @@ -103,7 +103,7 @@ SkillDialog::~SkillDialog() cleanList(); } -void SkillDialog::action(const std::string& eventId) +void SkillDialog::action(const std::string &eventId, gcn::Widget *widget) { if (eventId == "inc") { diff --git a/src/gui/skill.h b/src/gui/skill.h index fe80347d..5555fec4 100644 --- a/src/gui/skill.h +++ b/src/gui/skill.h @@ -57,7 +57,7 @@ class SkillDialog : public Window, public gcn::ActionListener, */ ~SkillDialog(); - void action(const std::string&); + void action(const std::string& eventId, gcn::Widget* widget); void update(); diff --git a/src/gui/status.cpp b/src/gui/status.cpp index 7d6cabac..bf109460 100644 --- a/src/gui/status.cpp +++ b/src/gui/status.cpp @@ -361,7 +361,7 @@ void StatusWindow::draw(gcn::Graphics *g) Window::draw(g); } -void StatusWindow::action(const std::string& eventId) +void StatusWindow::action(const std::string &eventId, gcn::Widget *widget) { // Stats Part if (eventId.length() == 3) diff --git a/src/gui/status.h b/src/gui/status.h index 52ece323..6b963d24 100644 --- a/src/gui/status.h +++ b/src/gui/status.h @@ -51,7 +51,7 @@ class StatusWindow : public Window, public gcn::ActionListener { /** * Called when receiving actions from widget. */ - void action(const std::string& eventId); + void action(const std::string& eventId, gcn::Widget* widget); /** * Draw this window diff --git a/src/gui/tabbedcontainer.cpp b/src/gui/tabbedcontainer.cpp index f1927c6f..e3d2527b 100644 --- a/src/gui/tabbedcontainer.cpp +++ b/src/gui/tabbedcontainer.cpp @@ -78,7 +78,7 @@ void TabbedContainer::logic() Container::logic(); } -void TabbedContainer::action(const std::string &event) +void TabbedContainer::action(const std::string &event, gcn::Widget *widget) { std::stringstream ss(event); int tabNo; diff --git a/src/gui/tabbedcontainer.h b/src/gui/tabbedcontainer.h index 24c8c425..453d8374 100644 --- a/src/gui/tabbedcontainer.h +++ b/src/gui/tabbedcontainer.h @@ -43,7 +43,7 @@ class TabbedContainer : public gcn::Container, public gcn::ActionListener void logic(); - void action(const std::string &event); + void action(const std::string &event, gcn::Widget *widget); void setOpaque(bool opaque); @@ -53,7 +53,7 @@ class TabbedContainer : public gcn::Container, public gcn::ActionListener Widgets mTabs; // The actual tabs at the top Widgets mContents; // The contents of the tabs - Widget *mActiveContent; + gcn::Widget *mActiveContent; }; #endif diff --git a/src/gui/textfield.cpp b/src/gui/textfield.cpp index aa9d04fd..2e083d5a 100644 --- a/src/gui/textfield.cpp +++ b/src/gui/textfield.cpp @@ -82,7 +82,7 @@ TextField::~TextField() void TextField::draw(gcn::Graphics *graphics) { - if (hasFocus()) { + if (isFocused()) { drawCaret(graphics, getFont()->getWidth(mText.substr(0, mCaretPosition)) - mXScroll); diff --git a/src/gui/trade.cpp b/src/gui/trade.cpp index 4efdb06c..73193c88 100644 --- a/src/gui/trade.cpp +++ b/src/gui/trade.cpp @@ -258,7 +258,7 @@ void TradeWindow::mouseClick(int x, int y, int button, int count) mItemDescriptionLabel->adjustSize(); } -void TradeWindow::action(const std::string &eventId) +void TradeWindow::action(const std::string &eventId, gcn::Widget *widget) { Item *item = inventoryWindow->getItem(); diff --git a/src/gui/trade.h b/src/gui/trade.h index 8bf4b86d..eb3c0f97 100644 --- a/src/gui/trade.h +++ b/src/gui/trade.h @@ -110,7 +110,7 @@ class TradeWindow : public Window, gcn::ActionListener /** * Called when receiving actions from the widgets. */ - void action(const std::string& eventId); + void action(const std::string& eventId, gcn::Widget* widget); private: Network *mNetwork; diff --git a/src/gui/updatewindow.cpp b/src/gui/updatewindow.cpp index 3f5fe7bb..9188b6de 100644 --- a/src/gui/updatewindow.cpp +++ b/src/gui/updatewindow.cpp @@ -107,7 +107,7 @@ UpdaterWindow::~UpdaterWindow() } // Remove possibly leftover temporary download - remove((mBasePath + "/updates/download.temp").c_str()); + ::remove((mBasePath + "/updates/download.temp").c_str()); delete[] mCurlError; } @@ -129,7 +129,7 @@ void UpdaterWindow::enable() mPlayButton->requestFocus(); } -void UpdaterWindow::action(const std::string& eventId) +void UpdaterWindow::action(const std::string &eventId, gcn::Widget *widget) { if (eventId == "cancel") { @@ -299,7 +299,7 @@ int UpdaterWindow::downloadThread(void *ptr) // Any existing file with this name is deleted first, otherwise the // rename will fail on Windows. - remove(newName.c_str()); + ::remove(newName.c_str()); rename(outFilename.c_str(), newName.c_str()); } } diff --git a/src/gui/updatewindow.h b/src/gui/updatewindow.h index 5f049e18..8a168be8 100644 --- a/src/gui/updatewindow.h +++ b/src/gui/updatewindow.h @@ -79,7 +79,7 @@ class UpdaterWindow : public Window, public gcn::ActionListener */ void loadNews(); - void action(const std::string& eventId); + void action(const std::string& eventId, gcn::Widget* widget); /** * Add a row to the message field. diff --git a/src/gui/vbox.cpp b/src/gui/vbox.cpp index d79fbba2..eb838ead 100644 --- a/src/gui/vbox.cpp +++ b/src/gui/vbox.cpp @@ -25,17 +25,21 @@ void VBox::draw(gcn::Graphics *graphics) { - int widgetCount = mWidgets.size(); - int childWidth = getWidth(); - if (widgetCount == 0) - return; - int childHeight = getHeight() / widgetCount; + if (mWidgets.size() == 0) + { + return; + } + int childWidth = getWidth(); + int childHeight = getHeight() / mWidgets.size(); int i = 0; - for (WidgetIterator w = mWidgets.begin(); w != mWidgets.end(); w++) { - (*w)->setPosition(0, childHeight * i - padding); + + for (WidgetIterator w = mWidgets.begin(); w != mWidgets.end(); w++) + { + (*w)->setPosition(0, childHeight * i - padding); (*w)->setSize(childWidth, childHeight); i++; } + gcn::Container::draw(graphics); } diff --git a/src/gui/window.cpp b/src/gui/window.cpp index 974a1d73..9a07111f 100644 --- a/src/gui/window.cpp +++ b/src/gui/window.cpp @@ -105,7 +105,7 @@ Window::Window(const std::string& caption, bool modal, Window *parent): // Add chrome mChrome = new GCContainer(); mChrome->setOpaque(false); - setContent(mChrome); + gcn::Window::add(mChrome); // Add this window to the window container windowContainer->add(this); @@ -180,7 +180,7 @@ void Window::draw(gcn::Graphics* graphics) graphics->drawText(getCaption(), 7, 5, gcn::Graphics::LEFT); } - drawContent(graphics); + drawChildren(graphics); } void Window::setContentWidth(int width) @@ -195,7 +195,7 @@ void Window::setContentHeight(int height) resizeToContent(); } -void Window::setLocationRelativeTo(gcn::Widget* widget) +void Window::setLocationRelativeTo(gcn::Widget *widget) { int wx, wy; int x, y; @@ -267,7 +267,7 @@ void Window::mousePress(int x, int y, int button) // border, and is a candidate for a resize. if (isResizable() && button == 1 && getGripDimension().isPointInRect(x, y) && - !getContentDimension().isPointInRect(x, y) && + !getChildrenArea().isPointInRect(x, y) && hasMouse() && !(mMouseDrag && y > (int)getPadding())) { @@ -374,11 +374,8 @@ void Window::mouseMotion(int x, int y) // Set the new window and content dimensions setDimension(newDim); - - if (mContent != NULL && mMouseResize) - { - mContent->setDimension(getContentDimension()); - } + const gcn::Rectangle area = getChildrenArea(); + mChrome->setSize(area.width, area.height); } } @@ -406,18 +403,16 @@ Window::loadWindowState() { const std::string &name = mWindowName; - setPosition((int)config.getValue(name + "WinX", getX()), - (int)config.getValue(name + "WinY", getY())); + setPosition((int) config.getValue(name + "WinX", getX()), + (int) config.getValue(name + "WinY", getY())); if (mResizable) { - setWidth((int)config.getValue(name + "WinWidth", getWidth())); - setHeight((int)config.getValue(name + "WinHeight", getHeight())); + setSize((int) config.getValue(name + "WinWidth", getWidth()), + (int) config.getValue(name + "WinHeight", getHeight())); - if (mContent != NULL) - { - mContent->setDimension(getContentDimension()); - } + const gcn::Rectangle area = getChildrenArea(); + mChrome->setSize(area.width, area.height); } } @@ -437,9 +432,4 @@ void Window::resetToDefaultSize() { setPosition(mDefaultX, mDefaultY); setContentSize(mDefaultWidth, mDefaultHeight); - - if (mContent != NULL) - { - mContent->setDimension(getContentDimension()); - } } diff --git a/src/main.cpp b/src/main.cpp index 8cd6eeb6..1bec709f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -100,7 +100,7 @@ Logger *logger; /**< Log object */ namespace { struct ErrorListener : public gcn::ActionListener { - void action(const std::string& eventId) { state = LOGIN_STATE; } + void action(const std::string &eventId, gcn::Widget *widget) { state = LOGIN_STATE; } } errorListener; } @@ -606,7 +606,8 @@ int main(int argc, char *argv[]) oldstate = state; - if (currentDialog && state != ACCOUNT_STATE && state != CHAR_CONNECT_STATE) { + if (currentDialog && state != ACCOUNT_STATE && + state != CHAR_CONNECT_STATE) { delete currentDialog; currentDialog = NULL; } @@ -631,7 +632,8 @@ int main(int argc, char *argv[]) currentDialog = new CharSelectDialog(network, &charInfo, 1 - loginData.sex); if (options.chooseDefault) { - ((CharSelectDialog*)currentDialog)->action("ok"); + ((CharSelectDialog*)currentDialog)->action("ok", + NULL); } break; diff --git a/src/net/network.cpp b/src/net/network.cpp index aa18e888..64cbf331 100644 --- a/src/net/network.cpp +++ b/src/net/network.cpp @@ -66,7 +66,7 @@ bool Network::connect(const std::string &address, short port) mState = CONNECTING; - mClient = enet_host_create (0, 1, 0, 0); + mClient = enet_host_create(0, 1, 0, 0); if (!mClient) { @@ -160,8 +160,10 @@ void Network::dispatchMessages() void Network::flush() { + logger->log("Network::flush()"); if (mState == IDLE || mState == NET_ERROR) { + logger->log("Idle or error, returning"); return; } @@ -173,20 +175,25 @@ void Network::flush() switch (event.type) { case ENET_EVENT_TYPE_CONNECT: + logger->log("Connected."); mState = CONNECTED; // Store any relevant server information here. event.peer->data = 0; break; case ENET_EVENT_TYPE_RECEIVE: + logger->log("Incoming data..."); mIncomingPackets.push(event.packet); break; case ENET_EVENT_TYPE_DISCONNECT: mState = IDLE; - printf("Disconnected\n"); + logger->log("Disconnected."); // Reset the server information. event.peer->data = 0; break; + case ENET_EVENT_TYPE_NONE: + logger->log("No event during 10 milliseconds."); + break; default: logger->log("Unhandled enet event."); break; diff --git a/src/net/playerhandler.cpp b/src/net/playerhandler.cpp index 5453eae4..c70eada3 100644 --- a/src/net/playerhandler.cpp +++ b/src/net/playerhandler.cpp @@ -46,7 +46,7 @@ OkDialog *deathNotice = NULL; namespace { struct WeightListener : public gcn::ActionListener { - void action(const std::string &eventId) { weightNotice = NULL; } + void action(const std::string &eventId, gcn::Widget *widget) { weightNotice = NULL; } } weightListener; } @@ -56,7 +56,7 @@ namespace { // TODO Move somewhere else namespace { struct DeathListener : public gcn::ActionListener { - void action(const std::string &eventId) { + void action(const std::string &eventId, gcn::Widget *widget) { player_node->revive(); deathNotice = NULL; } diff --git a/src/net/tradehandler.cpp b/src/net/tradehandler.cpp index 0f5bdcdc..b0baa5ea 100644 --- a/src/net/tradehandler.cpp +++ b/src/net/tradehandler.cpp @@ -41,7 +41,7 @@ std::string tradePartnerName; namespace { struct RequestTradeListener : public gcn::ActionListener { - void action(const std::string& eventId) + void action(const std::string &eventId, gcn::Widget *widget) { player_node->tradeReply(eventId == "yes"); }; diff --git a/src/openglgraphics.cpp b/src/openglgraphics.cpp index dc14b6c6..2a6c931d 100644 --- a/src/openglgraphics.cpp +++ b/src/openglgraphics.cpp @@ -31,7 +31,9 @@ #include #endif +#include #include +#include #include "log.h" @@ -227,28 +229,24 @@ void OpenGLGraphics::drawImage(const gcn::Image* image, int dstX, int dstY, int width, int height) { - // The following code finds the real width and height of the texture. - // OpenGL only supports texture sizes that are powers of two - int realImageWidth = 1; - int realImageHeight = 1; - while (realImageWidth < image->getWidth()) - { - realImageWidth *= 2; - } - while (realImageHeight < image->getHeight()) + const gcn::OpenGLImage* srcImage = + dynamic_cast(image); + + if (srcImage == NULL) { - realImageHeight *= 2; + throw GCN_EXCEPTION("Trying to draw an image of unknown format, " + "must be an SDLImage."); } // Find OpenGL texture coordinates - float texX1 = srcX / (float)realImageWidth; - float texY1 = srcY / (float)realImageHeight; - float texX2 = (srcX + width) / (float)realImageWidth; - float texY2 = (srcY + height) / (float)realImageHeight; + float texX1 = srcX / (float)srcImage->getTextureWidth(); + float texY1 = srcY / (float)srcImage->getTextureHeight(); + float texX2 = (srcX + width) / (float)srcImage->getTextureWidth(); + float texY2 = (srcY + height) / (float)srcImage->getTextureHeight(); // Please dont look too closely at the next line, it is not pretty. // It uses the image data as a pointer to a GLuint - glBindTexture(GL_TEXTURE_2D, *((GLuint *)(image->_getData()))); + glBindTexture(GL_TEXTURE_2D, srcImage->getTextureHandle()); drawTexedQuad(dstX, dstY, width, height, texX1, texY1, texX2, texY2); } diff --git a/src/resources/openglsdlimageloader.cpp b/src/resources/openglsdlimageloader.cpp new file mode 100644 index 00000000..f3ddbd84 --- /dev/null +++ b/src/resources/openglsdlimageloader.cpp @@ -0,0 +1,34 @@ +/* + * The Mana World + * Copyright 2004 The Mana World Development Team + * + * This file is part of The Mana World. + * + * The Mana World is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * The Mana World is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with The Mana World; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * $Id: sdlimageloader.cpp 2121 2006-01-31 02:55:26Z der_doener $ + */ + +#include "openglsdlimageloader.h" + +#include + +#include "resourcemanager.h" + +SDL_Surface* OpenGLSDLImageLoader::loadSDLSurface(const std::string& filename) +{ + ResourceManager *resman = ResourceManager::getInstance(); + return resman->loadSDLSurface(filename); +} diff --git a/src/resources/openglsdlimageloader.h b/src/resources/openglsdlimageloader.h new file mode 100644 index 00000000..29be294c --- /dev/null +++ b/src/resources/openglsdlimageloader.h @@ -0,0 +1,37 @@ +/* + * The Mana World + * Copyright 2004 The Mana World Development Team + * + * This file is part of The Mana World. + * + * The Mana World is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * The Mana World is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with The Mana World; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * $Id: sdlimageloader.h 1724 2005-09-12 22:15:35Z der_doener $ + */ + +#ifndef _TMW_OPENGLSDLIMAGELOADER_H +#define _TMW_OPENGLSDLIMAGELOADER_H + +#include + +#include + +class OpenGLSDLImageLoader : public gcn::OpenGLSDLImageLoader +{ + protected: + SDL_Surface* loadSDLSurface(const std::string& filename); +}; + +#endif diff --git a/src/resources/resourcemanager.cpp b/src/resources/resourcemanager.cpp index 6353afac..23a73497 100644 --- a/src/resources/resourcemanager.cpp +++ b/src/resources/resourcemanager.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include "image.h" #include "music.h" @@ -300,3 +301,19 @@ ResourceManager::loadTextFile(const std::string &fileName) free(fileContents); return lines; } + +SDL_Surface* +ResourceManager::loadSDLSurface(const std::string& filename) +{ + int fileSize; + void *buffer = loadFile(filename, fileSize); + SDL_Surface *tmp = NULL; + + if (buffer) { + SDL_RWops *rw = SDL_RWFromMem(buffer, fileSize); + tmp = IMG_Load_RW(rw, 1); + ::free(buffer); + } + + return tmp; +} diff --git a/src/resources/resourcemanager.h b/src/resources/resourcemanager.h index f254a8b4..0086b167 100644 --- a/src/resources/resourcemanager.h +++ b/src/resources/resourcemanager.h @@ -27,6 +27,7 @@ #include #include #include +#include class Resource; class Image; @@ -163,6 +164,13 @@ class ResourceManager std::vector loadTextFile(const std::string &fileName); + /** + * Loads the given filename as an SDL surface. The returned surface is + * expected to be freed by the caller using SDL_FreeSurface. + */ + SDL_Surface* + loadSDLSurface(const std::string& filename); + /** * Returns an instance of the class, creating one if it does not * already exist. diff --git a/src/resources/sdlimageloader.cpp b/src/resources/sdlimageloader.cpp index 88c4143e..ae4f4dcb 100644 --- a/src/resources/sdlimageloader.cpp +++ b/src/resources/sdlimageloader.cpp @@ -24,60 +24,11 @@ #include "sdlimageloader.h" #include -#include - -#include #include "resourcemanager.h" -void SDLImageLoader::prepare(const std::string &filename) +SDL_Surface* SDLImageLoader::loadSDLSurface(const std::string& filename) { - if (mCurrentImage) - { - throw GCN_EXCEPTION("Function called before finalizing or discarding last loaded image."); - } - ResourceManager *resman = ResourceManager::getInstance(); - - int fileSize; - void *buffer = resman->loadFile(filename, fileSize); - - SDL_Surface *tmp = NULL; - if (buffer) { - SDL_RWops *rw = SDL_RWFromMem(buffer, fileSize); - tmp = IMG_Load_RW(rw, 1); - ::free(buffer); - } - - if (!tmp) - { - throw GCN_EXCEPTION(std::string("Unable to load image file: ")+filename); - } - - Uint32 rmask, gmask, bmask, amask; -#if SDL_BYTEORDER == SDL_BIG_ENDIAN - rmask = 0xff000000; - gmask = 0x00ff0000; - bmask = 0x0000ff00; - amask = 0x000000ff; -#else - rmask = 0x000000ff; - gmask = 0x0000ff00; - bmask = 0x00ff0000; - amask = 0xff000000; -#endif - - mCurrentImage = SDL_CreateRGBSurface(SDL_SWSURFACE, 0, 0, 32, - rmask, gmask, bmask, amask); - - if (!mCurrentImage) - { - throw GCN_EXCEPTION(std::string("Not enough memory to load: ")+filename); - } - - SDL_Surface* tmp2 = SDL_ConvertSurface(tmp, mCurrentImage->format, SDL_SWSURFACE); - SDL_FreeSurface(tmp); - SDL_FreeSurface(mCurrentImage); - - mCurrentImage = tmp2; + return resman->loadSDLSurface(filename); } diff --git a/src/resources/sdlimageloader.h b/src/resources/sdlimageloader.h index b34b98fe..50b1d4f1 100644 --- a/src/resources/sdlimageloader.h +++ b/src/resources/sdlimageloader.h @@ -30,8 +30,8 @@ class SDLImageLoader : public gcn::SDLImageLoader { - public: - void prepare(const std::string &filename); + protected: + SDL_Surface* loadSDLSurface(const std::string& filename); }; #endif diff --git a/src/sound.cpp b/src/sound.cpp index 8b012176..182be3d6 100644 --- a/src/sound.cpp +++ b/src/sound.cpp @@ -208,6 +208,6 @@ void Sound::close() stopMusic(); mInstalled = false; - Mix_CloseAudio(); logger->log("Sound::close() Shutting down sound..."); + Mix_CloseAudio(); } -- cgit v1.2.3-70-g09d2 From afc770043be553998555e9ac1cffca68dc482d48 Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Sun, 13 Aug 2006 11:36:36 +0000 Subject: Merged cleanups and content changes from the trunk. Also fixed compiling with OpenGL enabled. --- ChangeLog | 161 ++++++++++++-- src/Makefile.am | 2 + src/animatedsprite.cpp | 382 ++++++++++++++++++++++++++++++++ src/animatedsprite.h | 178 +++++++++++++++ src/animation.cpp | 387 +++------------------------------ src/animation.h | 135 +++--------- src/being.cpp | 169 +++++++------- src/being.h | 11 +- src/configuration.cpp | 56 +++-- src/engine.cpp | 15 +- src/game.cpp | 30 +-- src/gui/browserbox.h | 1 + src/gui/chat.cpp | 81 +++---- src/gui/chat.h | 9 +- src/gui/gui.cpp | 7 +- src/gui/setup_video.cpp | 1 + src/gui/updatewindow.cpp | 2 +- src/main.cpp | 29 +-- src/monster.cpp | 4 +- src/npc.cpp | 2 + src/openglgraphics.cpp | 2 + src/player.cpp | 47 +++- src/resources/image.h | 2 + src/resources/itemmanager.cpp | 4 +- src/resources/mapreader.cpp | 214 +++++++++--------- src/resources/openglsdlimageloader.cpp | 6 +- 26 files changed, 1086 insertions(+), 851 deletions(-) create mode 100644 src/animatedsprite.cpp create mode 100644 src/animatedsprite.h (limited to 'src/gui/chat.cpp') diff --git a/ChangeLog b/ChangeLog index b1731b9f..8bf385c6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,11 +1,82 @@ +2006-08-13 Bjørn Lindeijer + + * src/openglgraphics.cpp, src/gui/browserbox.h, src/gui/gui.cpp, + src/gui/chat.cpp, src/resources/image.h: Added include main.h in order + to have USE_OPENGL defined correctly, since it is no longer passed as + a compiler parameter. + +2006-08-12 Philipp Sehmisch + + * data/maps/new_9-1.tmx.gz, data/maps/new_14-1.tmx.gz, + data/maps/new_15-1.tmx.gz, data/maps/new_16-1.tmx.gz: Fixed some + inaccessible areas. + +2006-08-07 Philipp Sehmisch + * data/maps/new_9-1.tmx.gz, data/maps/new_14-1.tmx.gz, + data/maps/new_15-1.tmx.gz, data/maps/new_16-1.tmx.gz, + data/graphics/images/minimap_new_9-1.png, + data/graphics/images/minimap_new_14-1.png, + data/graphics/images/minimap_new_15-1.png, + data/graphics/images/minimap_new_16-1.png: Added minimaps for woodland + maps. + +2006-08-07 Philipp Sehmisch + + * data/maps/new_1-1.tmx.gz, data/maps/new_14-1.tmx.gz, + data/maps/new_15-1.tmx.gz, data/maps/new_16-1.tmx.gz: Added a new + woodland map and a connection map between desert and woodland. + * data/graphics/woodland_ground.png: Added some new rocks. + +2006-08-07 Björn Steinbrink + + * src/game.cpp, src/gui/chat.h, src/gui/chat.cpp, src/main.cpp: A + bunch of cleanups. + 2006-08-06 Bjørn Lindeijer * INSTALL: Updated required Guichan to version 0.5.0. +2006-08-05 Björn Steinbrink + + * src/configuration.cpp, src/game.cpp, src/engine.cpp, src/player.cpp, + src/being.cpp, src/resources/mapreader.cpp, + src/resources/itemmanager.cpp: Some cleanups, mostly lowering + indentation. + * src/being.cpp: Small code cleanup. + 2006-08-04 Guillaume Melquiond * src/gui/char_select.cpp: Fixed character gender in selection dialog. +2006-08-04 Björn Steinbrink + + * src/animatedsprite.cpp: Fix enum being treated as string. + * src/animation.cpp: Small code cleanups. Removed unused headers. + * src/animatedsprite.cpp: Small code cleanup/lower indentation. + +2006-08-04 Bjørn Lindeijer + + * src/animatedsprite.cpp: Fixed presence of NULL actions. This is + doener's version of the fix, because it was more efficient in the more + common case. + +2006-08-04 Frode Lindeijer + + * data/graphics/tiles/desert_x3.png: Replaced the old cactus with + a nice new high-res one. + +2006-08-03 Bjørn Lindeijer + + * src/player.cpp, src/being.cpp, src/being.h: Removed three + setDirection(mDirection) calls by instead specifically setting the + current direction on the newly added animated sprite. The same might + be done for the action later. + * src/animatedsprite.h, src/animatedsprite.cpp: Since this class isn't + subclassed and has no virtual functions, make protected members + private. Also added a start of a reset function which could be a + solution to unsynchronized animated sprites. + * src/net/network.cpp: Fixed two delete/delete[] errors. + 2006-08-02 Guillaume Melquiond * configure.ac, src/Makefile.am: Put object files in subdirectories. @@ -37,10 +108,26 @@ * src/gui/gui.cpp, The Mana World.dev, tmw.cbp: Fixed compilation issues in windows. +2006-08-01 Philipp Sehmisch + + * src/animation.h, src/animation.cpp, src/animatedsprite.h, + src/animatedsprite.cpp, src/being.cpp: Animations and directions + are now passed and stored as enums and no longer as strings. + 2006-07-31 Bjørn Lindeijer * src/net/network.cpp: Corrected an off by one error in packet size. +2006-07-30 Björn Steinbrink + + * src/animatedsprite.h, src/animatedsprite.cpp: Unified the play + methods. + +2006-07-30 Philipp Sehmisch + + * data/maps/new_5-1.tmx.gz: Fixed two minor mapping errors (no new + walkmap required). + 2006-07-30 Bjørn Lindeijer * src/openglgraphics.cpp, src/game.cpp, src/main.cpp, @@ -74,6 +161,21 @@ Updated TMW to be compatible with Guichan 0.5.0 (merged from guichan-0.5.0 branch). +2006-07-29 Björn Steinbrink + + * src/animatedsprite.h, src/animatedsprite.cpp, src/animation.cpp: A + bunch of cleanups. + * src/animation.h, src/animatedsprite.cpp: Moved included from header + to source file. + +2006-07-28 Björn Steinbrink + + * src/npc.cpp, src/player.cpp, src/animatedsprite.h, src/animation.h, + src/being.cpp, src/main.cpp, src/monster.cpp, src/animatedsprite.cpp, + src/animation.cpp, src/Makefile.am, src/being.h: Moved AnimatedSprite + into its own files, removed useless includes. + * src/engine.cpp: Removed an unused var. + 2006-07-27 Eugenio Favalli * src/gui/main.cpp: Modified client version to be an int. @@ -81,20 +183,32 @@ 2006-07-26 Eugenio Favalli * src/gui/char_server.cpp, src/gui/char_sever.h, src/main.cpp, - src/net/loginhandler.cpp, src/net/loginhandler.h, tmw,cbp: Removed char - server selection dialog, and added character visualization in character - selection dialog. - -2006-07-25 Bjørn Lindeijer - - * src/gui/updatewindow.cpp: Fixed updating on Windows. - * src/net/beinghandler.cpp, src/net/network.cpp, configure.ac: Fixed - Linux compiling issues. - * src/configuration.cpp: Reduced amount of logging. - * src/log.cpp, src/log.h: Added support for writing log to standard - output. - * src/main.cpp: Reorganized initialization somewhat. - * src/resources/resourcemanager.cpp: Take into account singular form. + src/net/loginhandler.cpp, src/net/loginhandler.h, tmw,cbp: Removed + char server selection dialog, and added character visualization in + character selection dialog. + * data/graphics/sprites/Makefile.am, data/graphics/tiles/Makefile.am, + data/maps/Makefile.am, data/maps/new_13-1.tmx.gz: Added map with inside + of snow village buildings and fixed makefiles. + * src/being.cpp, src/being.h, src/player.cpp: Fixed direction and + action issues when changing appeareance, frames are still out of sync. + * data/maps/Makefile.am, data/maps/new_14-1.tmx.gz, + data/maps/new_9-1.tmx.gz: Added new woodland map by Crush and fixed + connection with the old one. + +2006-07-26 Bjørn Lindeijer + + * data/maps/new_4-1.tmx.gz: Fixes to the collision layer. + +2006-07-26 Frode Lindeijer + + * data/graphics/tiles/snowset.png, data/graphics/tiles/snow_x2.png, + data/graphics/tiles/snow_x3.png: Moved the lamppost, the rock and the + bench to seperate tall tilebitmaps. + * data/maps/new_11-1.tmx.gz: Improved the snow village map, main + changes are that the player can now walk better behind houses, + lampposts, rocks and benches. + * data/graphics/sprites/item003.png, data/graphics/sprites/item003.xml: + Added the leather shirt 2006-07-25 Eugenio Favalli @@ -113,6 +227,17 @@ tmw.cbp: Switched client to use enet and modified login sequence to work with the new protocol from tmwserv. +2006-07-25 Bjørn Lindeijer + + * src/gui/updatewindow.cpp: Fixed updating on Windows. + * src/net/beinghandler.cpp, src/net/network.cpp, configure.ac: Fixed + Linux compiling issues. + * src/configuration.cpp: Reduced amount of logging. + * src/log.cpp, src/log.h: Added support for writing log to standard + output. + * src/main.cpp: Reorganized initialization somewhat. + * src/resources/resourcemanager.cpp: Take into account singular form. + 2006-07-24 Bjørn Lindeijer * src/main.cpp: Fixed the loading of updates and made skipping the @@ -126,10 +251,10 @@ 2006-07-24 Frode Lindeijer * data/graphics/sprites/npcs.png: Added the organdealer to - the NPCs + the NPCs. * data/graphics/sprites/player_male_base.png, data/graphics/sprites/player_female_base.png: Fixed some - transparency issues + transparency issues. 2006-07-24 Eugenio Favalli @@ -144,7 +269,7 @@ * data/help/about.txt, data/help/changes.txt, data/help/commands.txt, data/help/header.txt, data/help/index.txt, data/help/skills.txt, data/help/support.txt, data/help/team.txt: Forced to use UNIX end of - line character. + line character. * src/net/equipmenthandler.cpp: Equipments now use real slot positions. 2006-07-24 Bjørn Lindeijer @@ -230,7 +355,7 @@ 2006-07-17 Frode Lindeijer - * Added shorts to items.png + * data/graphics/sprites/items.png: Added shorts' icon to items.png 2006-07-12 Bjørn Lindeijer diff --git a/src/Makefile.am b/src/Makefile.am index 13ec7308..42671f64 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -183,6 +183,8 @@ tmw_SOURCES = graphic/imagerect.h \ resources/buddylist.cpp \ utils/dtor.h \ utils/tostring.h \ + animatedsprite.cpp \ + animatedsprite.h \ animation.cpp \ animation.h \ base64.cpp \ diff --git a/src/animatedsprite.cpp b/src/animatedsprite.cpp new file mode 100644 index 00000000..d1201042 --- /dev/null +++ b/src/animatedsprite.cpp @@ -0,0 +1,382 @@ +/* + * The Mana World + * Copyright 2004 The Mana World Development Team + * + * This file is part of The Mana World. + * + * The Mana World is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * The Mana World is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with The Mana World; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * $Id: animation.cpp 2430 2006-07-24 00:13:24Z b_lindeijer $ + */ + +#include "animatedsprite.h" + +#include "animation.h" +#include "graphics.h" +#include "log.h" + +#include "resources/resourcemanager.h" +#include "resources/spriteset.h" + +AnimatedSprite::AnimatedSprite(const std::string& animationFile, int variant): + mAction(NULL), + mDirection(DIRECTION_DOWN), + mLastTime(0), + mSpeed(1.0f) +{ + int size; + ResourceManager *resman = ResourceManager::getInstance(); + char *data = (char*)resman->loadFile(animationFile.c_str(), size); + + if (!data) { + logger->error("Animation: Could not find " + animationFile + "!"); + } + + xmlDocPtr doc = xmlParseMemory(data, size); + free(data); + + if (!doc) { + logger->error("Animation: Error while parsing animation definition file!"); + } + + xmlNodePtr node = xmlDocGetRootElement(doc); + if (!node || !xmlStrEqual(node->name, BAD_CAST "sprite")) { + logger->error("Animation: this is not a valid animation definition file!"); + } + + // Get the variant + int variant_num = getProperty(node, "variants", 0); + int variant_offset = getProperty(node, "variant_offset", 0); + + if (variant_num > 0 && variant < variant_num ) { + variant_offset *= variant; + } else { + variant_offset = 0; + } + + for (node = node->xmlChildrenNode; node != NULL; node = node->next) + { + if (xmlStrEqual(node->name, BAD_CAST "imageset")) + { + int width = getProperty(node, "width", 0); + int height = getProperty(node, "height", 0); + std::string name = getProperty(node, "name", ""); + std::string imageSrc = getProperty(node, "src", ""); + + Spriteset *spriteset = + resman->getSpriteset(imageSrc, width, height); + + if (!spriteset) { + logger->error("Couldn't load spriteset!"); + } + + mSpritesets[name] = spriteset; + } + // get action + else if (xmlStrEqual(node->name, BAD_CAST "action")) + { + std::string name = getProperty(node, "name", ""); + std::string imageset = getProperty(node, "imageset", ""); + + if (name.empty()) + { + logger->log("Warning: unnamed action in %s", + animationFile.c_str()); + } + if (mSpritesets.find(imageset) == mSpritesets.end()) { + logger->log("Warning: imageset \"%s\" not defined in %s", + imageset.c_str(), + animationFile.c_str()); + + // skip loading animations + continue; + } + + Action *action = new Action(); + + action->setSpriteset(mSpritesets[imageset]); + mActions[makeSpriteAction(name)] = action; + + // get animations + for (xmlNodePtr animationNode = node->xmlChildrenNode; + animationNode != NULL; + animationNode = animationNode->next) + { + // We're only interested in animations + if (!xmlStrEqual(animationNode->name, BAD_CAST "animation")) + continue; + + std::string dir = getProperty(animationNode, "direction", ""); + Animation *animation = new Animation(); + action->setAnimation(makeSpriteDirection(dir), animation); + + // Get animation phases + for (xmlNodePtr phaseNode = animationNode->xmlChildrenNode; + phaseNode != NULL; + phaseNode = phaseNode->next) + { + int delay = getProperty(phaseNode, "delay", 0); + + if (xmlStrEqual(phaseNode->name, BAD_CAST "frame")) + { + int index = getProperty(phaseNode, "index", -1); + int offsetX = getProperty(phaseNode, "offsetX", 0); + int offsetY = getProperty(phaseNode, "offsetY", 0); + + offsetY -= mSpritesets[imageset]->getHeight() - 32; + offsetX -= mSpritesets[imageset]->getWidth() / 2 - 16; + animation->addPhase(index + variant_offset, delay, + offsetX, offsetY); + } + else if (xmlStrEqual(phaseNode->name, BAD_CAST "sequence")) + { + int start = getProperty(phaseNode, "start", 0); + int end = getProperty(phaseNode, "end", 0); + int offsetY = -mSpritesets[imageset]->getHeight() + 32; + int offsetX = -mSpritesets[imageset]->getWidth() / 2 + 16; + while (end >= start) + { + animation->addPhase(start + variant_offset, + delay, offsetX, offsetY); + start++; + } + } + } // for phaseNode + } // for animationNode + } // if "" else if "" + } // for node + + // Complete missing actions + substituteAction(ACTION_WALK, ACTION_STAND); + substituteAction(ACTION_WALK, ACTION_RUN); + substituteAction(ACTION_ATTACK, ACTION_STAND); + substituteAction(ACTION_ATTACK_SWING, ACTION_ATTACK); + substituteAction(ACTION_ATTACK_STAB, ACTION_ATTACK_SWING); + substituteAction(ACTION_ATTACK_BOW, ACTION_ATTACK_STAB); + substituteAction(ACTION_ATTACK_THROW, ACTION_ATTACK_SWING); + substituteAction(ACTION_CAST_MAGIC, ACTION_ATTACK_SWING); + substituteAction(ACTION_USE_ITEM, ACTION_CAST_MAGIC); + substituteAction(ACTION_SIT, ACTION_STAND); + substituteAction(ACTION_SLEEP, ACTION_SIT); + substituteAction(ACTION_HURT, ACTION_STAND); + substituteAction(ACTION_DEAD, ACTION_HURT); + + // Play the stand animation by default + play(ACTION_STAND); + + xmlFreeDoc(doc); +} + +int +AnimatedSprite::getProperty(xmlNodePtr node, const char* name, int def) +{ + int &ret = def; + + xmlChar *prop = xmlGetProp(node, BAD_CAST name); + if (prop) { + ret = atoi((char*)prop); + xmlFree(prop); + } + + return ret; +} + +std::string +AnimatedSprite::getProperty(xmlNodePtr node, const char* name, + const std::string& def) +{ + xmlChar *prop = xmlGetProp(node, BAD_CAST name); + if (prop) { + std::string val = (char*)prop; + xmlFree(prop); + return val; + } + + return def; +} + +void +AnimatedSprite::substituteAction(SpriteAction complete, + SpriteAction with) +{ + if (mActions.find(complete) == mActions.end()) + { + ActionIterator i = mActions.find(with); + if (i != mActions.end()) { + mActions[complete] = i->second; + } + } +} + +AnimatedSprite::~AnimatedSprite() +{ + for (SpritesetIterator i = mSpritesets.begin(); i != mSpritesets.end(); ++i) + { + i->second->decRef(); + } + mSpritesets.clear(); +} + +void +AnimatedSprite::reset() +{ + // Reset all defined actions (because of aliases, some will be resetted + // multiple times) + for (ActionIterator i = mActions.begin(); i != mActions.end(); ++i) + { + //TODO: If resetting everything is really a nice way of fixing the + // synchronization issues, finish implementing this. + //i->second->reset(); + } +} + +void +AnimatedSprite::play(SpriteAction action, int time) +{ + ActionIterator i = mActions.find(action); + + if (i == mActions.end()) + { + logger->log("Warning: no action \"%u\" defined!", action); + mAction = NULL; + return; + } + + if (mAction != i->second) + { + mAction = i->second; + mLastTime = 0; + } + + if (!mAction || !time) + mSpeed = 1.0f; + else { + int animationLength = mAction->getAnimation(mDirection)->getLength(); + mSpeed = (float) animationLength / time; + } +} + +void +AnimatedSprite::update(int time) +{ + // Avoid freaking out at first frame or when tick_time overflows + if (time < mLastTime || mLastTime == 0) + mLastTime = time; + + // If not enough time have passed yet, do nothing + if (time > mLastTime && mAction) + { + Animation *animation = mAction->getAnimation(mDirection); + animation->update((unsigned int)((time - mLastTime) * mSpeed)); + mLastTime = time; + } +} + +bool +AnimatedSprite::draw(Graphics* graphics, Sint32 posX, Sint32 posY) const +{ + if (!mAction) + return false; + + Animation *animation = mAction->getAnimation(mDirection); + int phase = animation->getCurrentPhase(); + if (phase < 0) + return false; + + Spriteset *spriteset = mAction->getSpriteset(); + Image *image = spriteset->get(phase); + Sint32 offsetX = animation->getOffsetX(); + Sint32 offsetY = animation->getOffsetY(); + return graphics->drawImage(image, posX + offsetX, posY + offsetY); +} + +int +AnimatedSprite::getWidth() const +{ + return mAction ? mAction->getSpriteset()->getWidth() : 0; +} + +int +AnimatedSprite::getHeight() const +{ + return mAction ? mAction->getSpriteset()->getHeight() : 0; +} + +SpriteAction +AnimatedSprite::makeSpriteAction(const std::string& action) +{ + if (action == "stand") { + return ACTION_STAND; + } + else if (action == "walk") { + return ACTION_WALK; + } + else if (action == "run") { + return ACTION_RUN; + } + else if (action == "attack") { + return ACTION_ATTACK; + } + else if (action == "attack_swing") { + return ACTION_ATTACK_SWING; + } + else if (action == "attack_stab") { + return ACTION_ATTACK_STAB; + } + else if (action == "attack_bow") { + return ACTION_ATTACK_BOW; + } + else if (action == "attack_throw") { + return ACTION_ATTACK_THROW; + } + else if (action == "cast_magic") { + return ACTION_CAST_MAGIC; + } + else if (action == "use_item") { + return ACTION_USE_ITEM; + } + else if (action == "sit") { + return ACTION_SIT; + } + else if (action == "sleep") { + return ACTION_SLEEP; + } + else if (action == "hurt") { + return ACTION_HURT; + } + else if (action == "dead") { + return ACTION_DEAD; + } + else { + return ACTION_DEFAULT; + } +} + +SpriteDirection +AnimatedSprite::makeSpriteDirection(const std::string& direction) +{ + if (direction == "up") { + return DIRECTION_UP; + } + else if (direction == "left") { + return DIRECTION_LEFT; + } + else if (direction == "right") { + return DIRECTION_RIGHT; + } + else { + return DIRECTION_DOWN; + } +} diff --git a/src/animatedsprite.h b/src/animatedsprite.h new file mode 100644 index 00000000..89394d6c --- /dev/null +++ b/src/animatedsprite.h @@ -0,0 +1,178 @@ +/* + * The Mana World + * Copyright 2004 The Mana World Development Team + * + * This file is part of The Mana World. + * + * The Mana World is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * The Mana World is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with The Mana World; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * $Id: animation.h 2430 2006-07-24 00:13:24Z b_lindeijer $ + */ + +#ifndef _TMW_ANIMATEDSPRITE_H +#define _TMW_ANIMATEDSPRITE_H + +#include +#include +#include + +#include + +class Action; +class Graphics; +class Spriteset; + +enum SpriteAction +{ + ACTION_DEFAULT = 0, + ACTION_STAND, + ACTION_WALK, + ACTION_RUN, + ACTION_ATTACK, + ACTION_ATTACK_SWING, + ACTION_ATTACK_STAB, + ACTION_ATTACK_BOW, + ACTION_ATTACK_THROW, + ACTION_CAST_MAGIC, + ACTION_USE_ITEM, + ACTION_SIT, + ACTION_SLEEP, + ACTION_HURT, + ACTION_DEAD +}; + +enum SpriteDirection +{ + DIRECTION_DOWN = 0, + DIRECTION_UP, + DIRECTION_LEFT, + DIRECTION_RIGHT +}; + +/** + * Defines a class to load an animation. + */ +class AnimatedSprite +{ + public: + /** + * Constructor. + */ + AnimatedSprite(const std::string& animationFile, int variant); + + /** + * Destructor. + */ + ~AnimatedSprite(); + + /** + * Resets the animated sprite. This is used to synchronize several + * animated sprites. + */ + void + reset(); + + /** + * Plays an action using the current direction that will have a + * duration of the specified time, 0 means default. + */ + void + play(SpriteAction action, int time = 0); + + /** + * Inform the animation of the passed time so that it can output the + * correct animation phase. + */ + void update(int time); + + /** + * Draw the current animation phase at the coordinates given in screen + * pixels. + */ + bool + draw(Graphics* graphics, Sint32 posX, Sint32 posY) const; + + /** + * gets the width in pixels of the current animation phase. + */ + int + getWidth() const; + + /** + * gets the height in pixels of the current animation phase. + */ + int + getHeight() const; + + /** + * Sets the direction. + */ + void + setDirection(SpriteDirection direction) + { + mDirection = direction; + } + + private: + /** + * When there are no animations defined for the action "complete", its + * animations become a copy of those of the action "with". + */ + void + substituteAction(SpriteAction complete, SpriteAction with); + + /** + * Gets an integer property from an xmlNodePtr. + * + * TODO: Same function is present in MapReader. Should probably be + * TODO: shared in a static utility class. + */ + static int + getProperty(xmlNodePtr node, const char *name, int def); + + /** + * Gets a string property from an xmlNodePtr. + */ + static std::string + getProperty(xmlNodePtr node, const char *name, const std::string &def); + + /** + * Converts a string into a SpriteAction enum. + */ + static SpriteAction + makeSpriteAction(const std::string &action); + + /** + * Converts a string into a SpriteDirection enum. + */ + static SpriteDirection + makeSpriteDirection(const std::string &direction); + + + typedef std::map Spritesets; + typedef Spritesets::iterator SpritesetIterator; + + typedef std::map Actions; + typedef Actions::iterator ActionIterator; + + Spritesets mSpritesets; + Actions mActions; + Action *mAction; + SpriteDirection mDirection; + int mLastTime; + float mSpeed; +}; + +#endif diff --git a/src/animation.cpp b/src/animation.cpp index 313fd25c..1213d0d6 100644 --- a/src/animation.cpp +++ b/src/animation.cpp @@ -23,13 +23,9 @@ #include "animation.h" -#include +#include -#include "log.h" - -#include "resources/image.h" -#include "resources/resourcemanager.h" -#include "resources/spriteset.h" +#include "utils/dtor.h" Animation::Animation(): mTime(0) @@ -41,17 +37,20 @@ void Animation::update(unsigned int time) { mTime += time; - if (!mAnimationPhases.empty()) + if (mAnimationPhases.empty()) + return; + + unsigned int delay = iCurrentPhase->delay; + if (!delay) + return; + + while (mTime > delay) { - unsigned int delay = iCurrentPhase->delay; - while (mTime > delay && delay > 0) + mTime -= delay; + iCurrentPhase++; + if (iCurrentPhase == mAnimationPhases.end()) { - mTime -= delay; - iCurrentPhase++; - if (iCurrentPhase == mAnimationPhases.end()) - { - iCurrentPhase = mAnimationPhases.begin(); - } + iCurrentPhase = mAnimationPhases.begin(); } } } @@ -59,25 +58,15 @@ Animation::update(unsigned int time) int Animation::getCurrentPhase() const { - if (mAnimationPhases.empty()) - { - return -1; - } - else - { - return iCurrentPhase->image; - } + return mAnimationPhases.empty() ? -1 : iCurrentPhase->image; } void Animation::addPhase(int image, unsigned int delay, int offsetX, int offsetY) { //add new phase to animation list - AnimationPhase newPhase; - newPhase.image = image; - newPhase.delay = delay; - newPhase.offsetX = offsetX; - newPhase.offsetY = offsetY; + AnimationPhase newPhase = { image, delay, offsetX, offsetY }; + mAnimationPhases.push_back(newPhase); //reset animation circle iCurrentPhase = mAnimationPhases.begin(); @@ -86,14 +75,14 @@ Animation::addPhase(int image, unsigned int delay, int offsetX, int offsetY) int Animation::getLength() { + if (mAnimationPhases.empty()) + return 0; + std::list::iterator i; int length = 0; - if (!mAnimationPhases.empty()) + for (i = mAnimationPhases.begin(); i != mAnimationPhases.end(); i++) { - for (i = mAnimationPhases.begin(); i != mAnimationPhases.end(); i++) - { - length += (*i).delay; - } + length += i->delay; } return length; } @@ -105,352 +94,32 @@ Action::Action(): Action::~Action() { - for (AnimationIterator i = mAnimations.begin(); i != mAnimations.end(); i++) - { - delete i->second; - } + std::for_each(mAnimations.begin(), mAnimations.end(), make_dtor(mAnimations)); mAnimations.clear(); } Animation* -Action::getAnimation(const std::string& direction) const +Action::getAnimation(int direction) const { - Animation *animation = NULL; Animations::const_iterator i = mAnimations.find(direction); // When the direction isn't defined, try the default if (i == mAnimations.end()) { - i = mAnimations.find("default"); + i = mAnimations.find(0); } - if (i != mAnimations.end()) - { - animation = i->second; - } - - return animation; + return (i == mAnimations.end()) ? NULL : i->second; } void -Action::setAnimation(const std::string& direction, Animation *animation) +Action::setAnimation(int direction, Animation *animation) { // Set first direction as default direction if (mAnimations.empty()) { - mAnimations["default"] = animation; + mAnimations[0] = animation; } mAnimations[direction] = animation; } - - -AnimatedSprite::AnimatedSprite(const std::string& animationFile, int variant): - mAction(NULL), - mDirection("down"), - mLastTime(0), - mSpeed(1.0f) -{ - int size; - ResourceManager *resman = ResourceManager::getInstance(); - char *data = (char*)resman->loadFile(animationFile.c_str(), size); - - if (!data) { - logger->error("Animation: Could not find " + animationFile + "!"); - } - - xmlDocPtr doc = xmlParseMemory(data, size); - free(data); - - if (!doc) - { - logger->error("Animation: Error while parsing animation definition file!"); - return; - } - - xmlNodePtr node = xmlDocGetRootElement(doc); - if (!node || !xmlStrEqual(node->name, BAD_CAST "sprite")) - { - logger->error("Animation: this is not a valid animation definition file!"); - return; - } - - // Get the variant - int variant_num = getProperty(node, "variants", 0); - int variant_offset = getProperty(node, "variant_offset", 0); - - if (variant_num > 0 && variant < variant_num ) - { - variant_offset *= variant; - } - else - { - variant_offset = 0; - } - - for (node = node->xmlChildrenNode; node != NULL; node = node->next) - { - if (xmlStrEqual(node->name, BAD_CAST "imageset")) - { - int width = getProperty(node, "width", 0); - int height = getProperty(node, "height", 0); - std::string name = getProperty(node, "name", ""); - std::string imageSrc = getProperty(node, "src", ""); - - Spriteset *spriteset = - resman->getSpriteset(imageSrc, width, height); - - if (!spriteset) - { - logger->error("Couldn't load spriteset!"); - } - else - { - mSpritesets[name] = spriteset; - } - } - // get action - else if (xmlStrEqual(node->name, BAD_CAST "action")) - { - std::string name = getProperty(node, "name", ""); - std::string imageset = getProperty(node, "imageset", ""); - - if (name.length() == 0) - { - logger->log("Warning: unnamed action in %s", - animationFile.c_str()); - } - - Action *action = new Action(); - - if (mSpritesets.find(imageset) != mSpritesets.end()) - { - action->setSpriteset(mSpritesets[imageset]); - mActions[name] = action; - } - else - { - logger->log("Warning: imageset \"%s\" not defined in %s", - imageset.c_str(), - animationFile.c_str()); - - // Discard action and skip loading animations - delete action; - continue; - } - - // get animations - for (xmlNodePtr animationNode = node->xmlChildrenNode; - animationNode != NULL; - animationNode = animationNode->next) - { - if (xmlStrEqual(animationNode->name, BAD_CAST "animation")) - { - std::string direction = - getProperty(animationNode, "direction", ""); - - Animation *animation = new Animation(); - - // Get animation phases - for (xmlNodePtr phaseNode = animationNode->xmlChildrenNode; - phaseNode != NULL; - phaseNode = phaseNode->next) - { - int delay = getProperty(phaseNode, "delay", 0); - - if (xmlStrEqual(phaseNode->name, BAD_CAST "frame")) - { - int index = getProperty(phaseNode, "index", -1); - int offsetX = getProperty(phaseNode, "offsetX", 0); - int offsetY = getProperty(phaseNode, "offsetY", 0); - - offsetY = offsetY - mSpritesets[imageset]->getHeight() + 32; - offsetX = offsetX - mSpritesets[imageset]->getWidth() / 2 + 16; - animation->addPhase(index + variant_offset, delay, - offsetX, offsetY); - } - else if (xmlStrEqual(phaseNode->name, BAD_CAST "sequence")) - { - int start = getProperty(phaseNode, "start", 0); - int end = getProperty(phaseNode, "end", 0); - int offsetY = 0 - mSpritesets[imageset]->getHeight() + 32; - int offsetX = 0 - mSpritesets[imageset]->getWidth() / 2 + 16; - while (end >= start) - { - animation->addPhase(start + variant_offset, - delay, offsetX, offsetY); - start++; - } - } - } // for phaseNode - action->setAnimation(direction, animation); - } // if "" - } // for animationNode - } // if "" else if "" - } // for node - - // Complete missing actions - substituteAction("walk", "stand"); - substituteAction("walk", "run"); - substituteAction("attack", "stand"); - substituteAction("attack_swing", "attack"); - substituteAction("attack_stab", "attack_swing"); - substituteAction("attack_bow", "attack_stab"); - substituteAction("attack_throw", "attack_swing"); - substituteAction("cast_magic", "attack_swing"); - substituteAction("use_item", "cast_magic"); - substituteAction("sit", "stand"); - substituteAction("sleeping", "sit"); - substituteAction("hurt", "stand"); - substituteAction("dead", "hurt"); - - // Play the stand animation by default - play("stand"); - - xmlFreeDoc(doc); -} - -int -AnimatedSprite::getProperty(xmlNodePtr node, const char* name, int def) -{ - xmlChar *prop = xmlGetProp(node, BAD_CAST name); - if (prop) { - int val = atoi((char*)prop); - xmlFree(prop); - return val; - } - else { - return def; - } -} - -std::string -AnimatedSprite::getProperty(xmlNodePtr node, const char* name, - const std::string& def) -{ - xmlChar *prop = xmlGetProp(node, BAD_CAST name); - if (prop) { - std::string val = (char*)prop; - xmlFree(prop); - return val; - } - else { - return def; - } -} - -void -AnimatedSprite::substituteAction(const std::string& complete, - const std::string& with) -{ - if (mActions.find(complete) == mActions.end()) - { - mActions[complete] = mActions[with]; - } -} - -AnimatedSprite::~AnimatedSprite() -{ - for (SpritesetIterator i = mSpritesets.begin(); i != mSpritesets.end(); ++i) - { - i->second->decRef(); - } - mSpritesets.clear(); -} - -void -AnimatedSprite::play(const std::string& action) -{ - Actions::iterator iAction; - iAction = mActions.find(action); - - if (iAction == mActions.end()) - { - logger->log("Warning: no action \"%s\" defined!", action.c_str()); - mAction = NULL; - return; - } - - if (mAction != iAction->second) - { - mAction = iAction->second; - mLastTime = 0; - } - - mSpeed = 1.0f; -} - -void -AnimatedSprite::play(const std::string& action, int time) -{ - play(action); - - if (mAction != NULL) - { - Animation *animation = mAction->getAnimation(mDirection); - int animationLength = animation->getLength(); - mSpeed = (float) animationLength / time; - } -} - -void -AnimatedSprite::update(int time) -{ - // Avoid freaking out at first frame or when tick_time overflows - if (time < mLastTime || mLastTime == 0) mLastTime = time; - - // If not enough time have passed yet, do nothing - if (time > mLastTime) - { - if (mAction != NULL) - { - Animation *animation = mAction->getAnimation(mDirection); - animation->update((unsigned int)((time - mLastTime) * mSpeed)); - mLastTime = time; - } - } -} - -bool -AnimatedSprite::draw(Graphics* graphics, Sint32 posX, Sint32 posY) const -{ - if (mAction != NULL) - { - Animation *animation = mAction->getAnimation(mDirection); - - if (animation->getCurrentPhase() >= 0) - { - Spriteset *spriteset = mAction->getSpriteset(); - Image *image = spriteset->get(animation->getCurrentPhase()); - Sint32 offsetX = animation->getOffsetX(); - Sint32 offsetY = animation->getOffsetY(); - return graphics->drawImage(image, posX + offsetX, posY + offsetY); - } - } - - return false; -} - -int -AnimatedSprite::getWidth() const -{ - if (mAction != NULL) - { - Spriteset *spriteset = mAction->getSpriteset(); - return spriteset->getWidth(); - } - - return 0; -} - -int -AnimatedSprite::getHeight() const -{ - if (mAction != NULL) - { - Spriteset *spriteset = mAction->getSpriteset(); - return spriteset->getHeight(); - } - - return 0; -} diff --git a/src/animation.h b/src/animation.h index c5adb873..c5b277b7 100644 --- a/src/animation.h +++ b/src/animation.h @@ -26,12 +26,9 @@ #include #include -#include #include -#include "graphics.h" - class Image; class Spriteset; @@ -58,16 +55,32 @@ class Animation */ Animation(); - void addPhase(int image, unsigned int delay, int offsetX, int offsetY); + void + addPhase(int image, unsigned int delay, int offsetX, int offsetY); + + void + update(unsigned int time); - void update(unsigned int time); + int + getCurrentPhase() const; - int getCurrentPhase() const; + /** + * Returns the x offset of the current frame. + */ + int + getOffsetX() const { return (*iCurrentPhase).offsetX; }; - int getOffsetX() const { return (*iCurrentPhase).offsetX; }; - int getOffsetY() const { return (*iCurrentPhase).offsetY; }; + /** + * Returns the y offset of the current frame. + */ + int + getOffsetY() const { return (*iCurrentPhase).offsetY; }; - int getLength(); + /** + * Returns the length of this animation. + */ + int + getLength(); protected: std::list mAnimationPhases; @@ -104,114 +117,16 @@ class Action getSpriteset() const { return mSpriteset; } void - setAnimation(const std::string& direction, Animation *animation); + setAnimation(int direction, Animation *animation); Animation* - getAnimation(const std::string& direction) const; + getAnimation(int direction) const; protected: Spriteset *mSpriteset; - typedef std::map Animations; + typedef std::map Animations; typedef Animations::iterator AnimationIterator; Animations mAnimations; }; -/** - * Defines a class to load an animation. - */ -class AnimatedSprite -{ - public: - /** - * Constructor. - */ - AnimatedSprite(const std::string& animationFile, int variant); - - /** - * Destructor. - */ - ~AnimatedSprite(); - - /** - * Sets a new action using the current direction. - */ - void - play(const std::string& action); - - /** - * Plays an action in a specified time. - */ - void - play(const std::string& action, int time); - - /** - * Inform the animation of the passed time so that it can output the - * correct animation phase. - */ - void update(int time); - - /** - * Draw the current animation phase at the coordinates given in screen - * pixels. - */ - bool - draw(Graphics* graphics, Sint32 posX, Sint32 posY) const; - - /** - * gets the width in pixels of the current animation phase. - */ - int - getWidth() const; - - /** - * gets the height in pixels of the current animation phase. - */ - int - getHeight() const; - - /** - * Sets the direction. - */ - void - setDirection(const std::string& direction) - { - mDirection = direction; - } - - protected: - /** - * When there are no animations defined for the action "complete", its - * animations become a copy of those of the action "with". - */ - void - substituteAction(const std::string& complete, - const std::string& with); - - typedef std::map Spritesets; - typedef Spritesets::iterator SpritesetIterator; - Spritesets mSpritesets; - typedef std::map Actions; - Actions mActions; - Action *mAction; - std::string mDirection; - int mLastTime; - float mSpeed; - - private: - /** - * Gets an integer property from an xmlNodePtr. - * - * TODO: Same function is present in MapReader. Should probably be - * TODO: shared in a static utility class. - */ - static int - getProperty(xmlNodePtr node, const char* name, int def); - - /** - * Gets a string property from an xmlNodePtr. - */ - static std::string - getProperty(xmlNodePtr node, const char* name, const std::string& def); -}; - #endif diff --git a/src/being.cpp b/src/being.cpp index 8a55f2e2..1ca8929a 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -22,6 +22,9 @@ */ #include "being.h" +#include + +#include "animatedsprite.h" #include "equipment.h" #include "game.h" #include "graphics.h" @@ -32,6 +35,7 @@ #include "gui/gui.h" +#include "utils/dtor.h" #include "utils/tostring.h" extern Spriteset *emotionset; @@ -65,14 +69,7 @@ Being::Being(Uint32 id, Uint16 job, Map *map): Being::~Being() { - for (int i = 0; i < VECTOREND_SPRITE; i++) - { - if (mSprites[i] != NULL) - { - delete mSprites[i]; - } - } - + std::for_each(mSprites.begin(), mSprites.end(), make_dtor(mSprites)); clearPath(); setMap(NULL); } @@ -164,66 +161,65 @@ Being::setMap(Map *map) } void -Being::setAction(Action action) +Being::setAction(Uint8 action) { - if (action != mAction) + SpriteAction currentAction = ACTION_STAND; + switch (action) { - std::string currentAction = "stand"; - switch (action) - { - case WALK: - currentAction = "walk"; - break; - case SIT: - currentAction = "sit"; - break; - case ATTACK: - if (getType() == MONSTER) - { - currentAction = "dead"; - }else{ - switch (getWeapon()) - { - case 2: - currentAction = "attack_bow"; - break; - case 1: - currentAction = "attack_stab"; - break; - case 0: - currentAction = "attack"; - break; - } - }; - break; - case MONSTER_ATTACK: - currentAction = "attack"; - break; - case DEAD: - currentAction = "dead"; - break; - default: - currentAction = "stand"; - break; - } - - for (int i = 0; i < VECTOREND_SPRITE; i++) - { - if (mSprites[i] != NULL) + case WALK: + currentAction = ACTION_WALK; + break; + case SIT: + currentAction = ACTION_SIT; + break; + case ATTACK: + if (getType() == MONSTER) { - if (currentAction == "attack" || - currentAction == "attack_stab" || - currentAction == "attack_bow") - { - mSprites[i]->play(currentAction, mAttackSpeed); - } - else + currentAction = ACTION_DEAD; + } + else { + switch (getWeapon()) { - mSprites[i]->play(currentAction); + case 2: + currentAction = ACTION_ATTACK_BOW; + break; + case 1: + currentAction = ACTION_ATTACK_STAB; + break; + case 0: + currentAction = ACTION_ATTACK; + break; } - } + }; + break; + case MONSTER_ATTACK: + currentAction = ACTION_ATTACK; + break; + case DEAD: + currentAction = ACTION_DEAD; + break; + default: + currentAction = ACTION_STAND; + break; + } + + for (int i = 0; i < VECTOREND_SPRITE; i++) + { + if (!mSprites[i]) + continue; + + if (currentAction == ACTION_ATTACK || + currentAction == ACTION_ATTACK_STAB || + currentAction == ACTION_ATTACK_BOW) + { + mSprites[i]->play(currentAction, mAttackSpeed); + } + else + { + mSprites[i]->play(currentAction); } } + mAction = action; } @@ -231,29 +227,37 @@ void Being::setDirection(Uint8 direction) { mDirection = direction; - std::string dir; + SpriteDirection dir = getSpriteDirection(); - if (direction & UP) + for (int i = 0; i < VECTOREND_SPRITE; i++) { - dir = "up"; + if (mSprites[i] != NULL) + mSprites[i]->setDirection(dir); } - else if (direction & RIGHT) +} + +SpriteDirection +Being::getSpriteDirection() const +{ + SpriteDirection dir; + + if (mDirection & UP) { - dir = "right"; + dir = DIRECTION_UP; } - else if (direction & DOWN) + else if (mDirection & RIGHT) { - dir = "down"; + dir = DIRECTION_RIGHT; } - else + else if (mDirection & DOWN) { - dir = "left"; + dir = DIRECTION_DOWN; } - - for (int i = 0; i < VECTOREND_SPRITE; i++) - { - if (mSprites[i] != NULL) mSprites[i]->setDirection(dir); + else { + dir = DIRECTION_LEFT; } + + return dir; } void @@ -329,10 +333,6 @@ Being::draw(Graphics *graphics, int offsetX, int offsetY) int px = mPx + offsetX; int py = mPy + offsetY; - //what are these two lines good for? please add a comment. - unsigned char dir = 0; - while (!(mDirection & (1 << dir))) dir++; - for (int i = 0; i < VECTOREND_SPRITE; i++) { if (mSprites[i] != NULL) @@ -345,14 +345,13 @@ Being::draw(Graphics *graphics, int offsetX, int offsetY) void Being::drawEmotion(Graphics *graphics, Sint32 offsetX, Sint32 offsetY) { - int px = mPx + offsetX; - int py = mPy + offsetY; + if (!mEmotion) + return; - if (mEmotion) - { - graphics->drawImage(emotionset->get(mEmotion - 1), - px + 3, py - 60); - } + int px = mPx + offsetX + 3; + int py = mPy + offsetY - 60; + + graphics->drawImage(emotionset->get(mEmotion - 1), px, py); } void diff --git a/src/being.h b/src/being.h index 478bc018..0735efe9 100644 --- a/src/being.h +++ b/src/being.h @@ -29,13 +29,14 @@ #include #include -#include "animation.h" #include "sprite.h" #include "map.h" +#include "animatedsprite.h" #define NR_HAIR_STYLES 7 #define NR_HAIR_COLORS 10 +class AnimatedSprite; class Equipment; class Item; class Map; @@ -290,7 +291,7 @@ class Being : public Sprite /** * Sets the current action. */ - void setAction(Action action); + void setAction(Uint8 action); /** * Sets the current direction. @@ -347,6 +348,12 @@ class Being : public Sprite */ int getOffset(char pos, char neg) const; + /** + * Returns the sprite direction of this being. + */ + SpriteDirection + getSpriteDirection() const; + Uint32 mId; /**< Unique sprite id */ Uint16 mWeapon; /**< Weapon picture id */ Uint16 mWalkSpeed; /**< Walking speed */ diff --git a/src/configuration.cpp b/src/configuration.cpp index 9c3ff008..8bb0b8ca 100644 --- a/src/configuration.cpp +++ b/src/configuration.cpp @@ -57,18 +57,18 @@ void Configuration::init(const std::string &filename) for (node = node->xmlChildrenNode; node != NULL; node = node->next) { - if (xmlStrEqual(node->name, BAD_CAST "option")) - { - xmlChar *name = xmlGetProp(node, BAD_CAST "name"); - xmlChar *value = xmlGetProp(node, BAD_CAST "value"); + if (!xmlStrEqual(node->name, BAD_CAST "option")) + continue; - if (name && value) { - mOptions[(const char*)name] = (const char*)value; - } + xmlChar *name = xmlGetProp(node, BAD_CAST "name"); + xmlChar *value = xmlGetProp(node, BAD_CAST "value"); - if (name) xmlFree(name); - if (value) xmlFree(value); + if (name && value) { + mOptions[(const char*)name] = (const char*)value; } + + if (name) xmlFree(name); + if (value) xmlFree(value); } xmlFreeDoc(doc); @@ -89,31 +89,29 @@ void Configuration::write() xmlTextWriterPtr writer = xmlNewTextWriterFilename(mConfigPath.c_str(), 0); - if (writer) - { - logger->log("Configuration::write() writing configuration..."); + if (!writer) { + logger->log("Configuration::write() error while creating writer"); + return; + } - xmlTextWriterSetIndent(writer, 1); - xmlTextWriterStartDocument(writer, NULL, NULL, NULL); - xmlTextWriterStartElement(writer, BAD_CAST "configuration"); + logger->log("Configuration::write() writing configuration..."); - for (OptionIterator i = mOptions.begin(); i != mOptions.end(); i++) - { - xmlTextWriterStartElement(writer, BAD_CAST "option"); - xmlTextWriterWriteAttribute(writer, - BAD_CAST "name", BAD_CAST i->first.c_str()); - xmlTextWriterWriteAttribute(writer, - BAD_CAST "value", BAD_CAST i->second.c_str()); - xmlTextWriterEndElement(writer); - } + xmlTextWriterSetIndent(writer, 1); + xmlTextWriterStartDocument(writer, NULL, NULL, NULL); + xmlTextWriterStartElement(writer, BAD_CAST "configuration"); - xmlTextWriterEndDocument(writer); - xmlFreeTextWriter(writer); - } - else + for (OptionIterator i = mOptions.begin(); i != mOptions.end(); i++) { - logger->log("Configuration::write() error while creating writer"); + xmlTextWriterStartElement(writer, BAD_CAST "option"); + xmlTextWriterWriteAttribute(writer, + BAD_CAST "name", BAD_CAST i->first.c_str()); + xmlTextWriterWriteAttribute(writer, + BAD_CAST "value", BAD_CAST i->second.c_str()); + xmlTextWriterEndElement(writer); } + + xmlTextWriterEndDocument(writer); + xmlFreeTextWriter(writer); } void Configuration::setValue(const std::string &key, std::string value) diff --git a/src/engine.cpp b/src/engine.cpp index c6a4e55c..84574b26 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -25,7 +25,6 @@ #include -#include "animation.h" #include "being.h" #include "beingmanager.h" #include "flooritemmanager.h" @@ -34,7 +33,6 @@ #include "main.h" #include "localplayer.h" #include "log.h" -#include "main.h" #include "map.h" #include "sound.h" @@ -63,8 +61,6 @@ Spriteset *itemset; Spriteset *emotionset; Spriteset *npcset; std::vector weaponset; -AnimatedSprite *animatedSprite; - Engine::Engine(Network *network): mShowDebugPath(false), @@ -104,16 +100,11 @@ Engine::~Engine() emotionset->decRef(); itemset->decRef(); - std::vector::iterator iter; - for (iter = weaponset.begin(); iter != weaponset.end(); ++iter) - { - (*iter)->decRef(); - } + std::for_each(weaponset.begin(), weaponset.end(), + std::mem_fun(&Spriteset::decRef)); weaponset.clear(); delete itemDb; - - delete animatedSprite; } void Engine::changeMap(const std::string &mapPath) @@ -219,12 +210,12 @@ void Engine::draw(Graphics *graphics) player_node->mX, player_node->mY, mouseTileX, mouseTileY); + graphics->setColor(gcn::Color(255, 0, 0)); for (PathIterator i = debugPath.begin(); i != debugPath.end(); i++) { int squareX = i->x * 32 - map_x + 12; int squareY = i->y * 32 - map_y + 12; - graphics->setColor(gcn::Color(255, 0, 0)); graphics->fillRectangle(gcn::Rectangle(squareX, squareY, 8, 8)); graphics->drawText( toString(mCurrentMap->getMetaTile(i->x, i->y)->Gcost), diff --git a/src/game.cpp b/src/game.cpp index fab88aa9..eada1128 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -167,8 +167,7 @@ int get_elapsed_time(int start_time) void createGuiWindows(Network *network) { // Create dialogs - chatWindow = new ChatWindow( - config.getValue("homeDir", "") + std::string("/chatlog.txt"), network); + chatWindow = new ChatWindow(network); menuWindow = new MenuWindow(); statusWindow = new StatusWindow(player_node); miniStatusWindow = new MiniStatusWindow(); @@ -359,29 +358,16 @@ void Game::logic() gameTime = tick_time; fpsLimit = (int)config.getValue("fpslimit", 50); - if (fpsLimit) - { - delta = 1000 / fpsLimit; - } - else - { - delta = 0; - } + delta = fpsLimit ? 1000 / fpsLimit : 0; // Update the screen when application is active, delay otherwise - if (SDL_GetAppState() & SDL_APPACTIVE) + if (SDL_GetAppState() & SDL_APPACTIVE && + (abs(tick_time * 10 - drawTime) >= delta)) { - if (abs(tick_time * 10 - drawTime) >= delta) - { - frame++; - engine->draw(graphics); - graphics->updateScreen(); - drawTime += delta; - } - else - { - SDL_Delay(10); - } + frame++; + engine->draw(graphics); + graphics->updateScreen(); + drawTime += delta; } else { diff --git a/src/gui/browserbox.h b/src/gui/browserbox.h index 95b181ad..a2c9dd9b 100644 --- a/src/gui/browserbox.h +++ b/src/gui/browserbox.h @@ -31,6 +31,7 @@ #include #include "../guichanfwd.h" +#include "../main.h" class LinkHandler; diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp index 133e5e3a..592439fc 100644 --- a/src/gui/chat.cpp +++ b/src/gui/chat.cpp @@ -35,18 +35,16 @@ #include "../game.h" #include "../localplayer.h" -#include "../log.h" #include "../net/messageout.h" #include "../net/protocol.h" -ChatWindow::ChatWindow(const std::string &logfile, Network *network): +ChatWindow::ChatWindow(Network *network): Window(""), mNetwork(network), mTmpVisible(false) { setWindowName("Chat"); - mChatlogFile.open(logfile.c_str(), std::ios::out | std::ios::app); mItems = 0; mItemsKeep = 20; @@ -76,12 +74,6 @@ ChatWindow::ChatWindow(const std::string &logfile, Network *network): mCurHist = mHistory.end(); } -ChatWindow::~ChatWindow() -{ - mChatlogFile.flush(); - mChatlogFile.close(); -} - void ChatWindow::logic() { @@ -251,44 +243,12 @@ ChatWindow::isFocused() void ChatWindow::chatSend(const std::string &nick, std::string msg) { - // Prepare command - if (msg.substr(0, 1) == "/") - { - /* Some messages are managed client side, while others - * require server handling by proper packet. Probably - * those if elses should be replaced by protocol calls */ - if (msg.substr(0, IS_ANNOUNCE_LENGTH) == IS_ANNOUNCE) - { - msg.erase(0, IS_ANNOUNCE_LENGTH); - MessageOut outMsg; - outMsg.writeShort(0x0099); - outMsg.writeShort(msg.length() + 4); - outMsg.writeString(msg, msg.length()); - } - else if (msg.substr(0, IS_HELP_LENGTH) == IS_HELP) - { - chatLog("-- Help --", BY_SERVER); - chatLog("/help : Display this help.", BY_SERVER); - chatLog("/announce : Global announcement (GM only)", BY_SERVER); - chatLog("/where : Display map name", BY_SERVER); - chatLog("/who : Display number of online users", BY_SERVER); - } - else if (msg.substr(0, IS_WHERE_LENGTH) == IS_WHERE) - { - chatLog(map_path, BY_SERVER); - } - else if (msg.substr(0, IS_WHO_LENGTH) == IS_WHO) - { - MessageOut outMsg; - outMsg.writeShort(0x00c1); - } - else - { - chatLog("Unknown command", BY_SERVER); - } - } + /* Some messages are managed client side, while others + * require server handling by proper packet. Probably + * those if elses should be replaced by protocol calls */ + // Prepare ordinary message - else { + if (msg.substr(0, 1) != "/") { msg = nick + " : " + msg; MessageOut outMsg; @@ -296,6 +256,35 @@ ChatWindow::chatSend(const std::string &nick, std::string msg) outMsg.writeShort(msg.length() + 4); outMsg.writeString(msg, msg.length()); } + else if (msg.substr(0, IS_ANNOUNCE_LENGTH) == IS_ANNOUNCE) + { + msg.erase(0, IS_ANNOUNCE_LENGTH); + MessageOut outMsg; + outMsg.writeShort(0x0099); + outMsg.writeShort(msg.length() + 4); + outMsg.writeString(msg, msg.length()); + } + else if (msg.substr(0, IS_HELP_LENGTH) == IS_HELP) + { + chatLog("-- Help --", BY_SERVER); + chatLog("/help : Display this help.", BY_SERVER); + chatLog("/announce : Global announcement (GM only)", BY_SERVER); + chatLog("/where : Display map name", BY_SERVER); + chatLog("/who : Display number of online users", BY_SERVER); + } + else if (msg.substr(0, IS_WHERE_LENGTH) == IS_WHERE) + { + chatLog(map_path, BY_SERVER); + } + else if (msg.substr(0, IS_WHO_LENGTH) == IS_WHO) + { + MessageOut outMsg; + outMsg.writeShort(0x00c1); + } + else + { + chatLog("Unknown command", BY_SERVER); + } } std::string diff --git a/src/gui/chat.h b/src/gui/chat.h index addfb6b5..20841873 100644 --- a/src/gui/chat.h +++ b/src/gui/chat.h @@ -24,7 +24,6 @@ #ifndef _TMW_CHAT_H #define _TMW_CHAT_H -#include #include #include @@ -117,12 +116,7 @@ class ChatWindow : public Window, public gcn::ActionListener, /** * Constructor. */ - ChatWindow(const std::string &logfile, Network *network); - - /** - * Destructor. - */ - ~ChatWindow(); + ChatWindow(Network *network); /** * Logic (updates components' size) @@ -195,7 +189,6 @@ class ChatWindow : public Window, public gcn::ActionListener, private: Network *mNetwork; - std::ofstream mChatlogFile; bool mTmpVisible; /** One item in the chat log */ diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index 88998f7a..026f24bd 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -32,10 +32,6 @@ // constant as well as guichan does #include -#ifdef USE_OPENGL -#include "../resources/openglsdlimageloader.h" -#endif - #include "focushandler.h" #include "popupmenu.h" #include "window.h" @@ -57,6 +53,9 @@ #include "../resources/image.h" #include "../resources/resourcemanager.h" #include "../resources/sdlimageloader.h" +#ifdef USE_OPENGL +#include "../resources/openglsdlimageloader.h" +#endif // Guichan stuff Gui *gui; diff --git a/src/gui/setup_video.cpp b/src/gui/setup_video.cpp index 9eb94520..7ac226d3 100644 --- a/src/gui/setup_video.cpp +++ b/src/gui/setup_video.cpp @@ -42,6 +42,7 @@ #include "../configuration.h" #include "../graphics.h" #include "../log.h" +#include "../main.h" #include "../utils/tostring.h" diff --git a/src/gui/updatewindow.cpp b/src/gui/updatewindow.cpp index 9188b6de..8c69d3ef 100644 --- a/src/gui/updatewindow.cpp +++ b/src/gui/updatewindow.cpp @@ -300,7 +300,7 @@ int UpdaterWindow::downloadThread(void *ptr) // Any existing file with this name is deleted first, otherwise the // rename will fail on Windows. ::remove(newName.c_str()); - rename(outFilename.c_str(), newName.c_str()); + ::rename(outFilename.c_str(), newName.c_str()); } } diff --git a/src/main.cpp b/src/main.cpp index ce68b7bb..a4ef29ee 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -43,7 +43,6 @@ #define NOGDI #endif -#include "animation.h" #include "configuration.h" #include "game.h" #include "graphics.h" @@ -216,15 +215,6 @@ void init_engine() resman->addToSearchPath("data", true); resman->addToSearchPath(TMW_DATADIR "data", true); - int width, height, bpp; - bool fullscreen, hwaccel; - - width = (int)config.getValue("screenwidth", 800); - height = (int)config.getValue("screenheight", 600); - bpp = 0; - fullscreen = ((int)config.getValue("screen", 0) == 1); - hwaccel = ((int)config.getValue("hwaccel", 0) == 1); - #ifdef USE_OPENGL bool useOpenGL = (config.getValue("opengl", 0) == 1); @@ -232,16 +222,18 @@ void init_engine() Image::setLoadAsOpenGL(useOpenGL); // Create the graphics context - if (useOpenGL) { - graphics = new OpenGLGraphics(); - } else { - graphics = new Graphics(); - } + graphics = useOpenGL ? new OpenGLGraphics() : new Graphics(); #else // Create the graphics context graphics = new Graphics(); #endif + int width = (int)config.getValue("screenwidth", 800); + int height = (int)config.getValue("screenheight", 600); + int bpp = 0; + bool fullscreen = ((int)config.getValue("screen", 0) == 1); + bool hwaccel = ((int)config.getValue("hwaccel", 0) == 1); + // Try to set the desired video mode if (!graphics->setVideoMode(width, height, bpp, fullscreen, hwaccel)) { @@ -299,11 +291,8 @@ void exit_engine() delete gui; delete graphics; - std::vector::iterator iter; - for (iter = hairset.begin(); iter != hairset.end(); ++iter) - { - (*iter)->decRef(); - } + std::for_each(hairset.begin(), hairset.end(), + std::mem_fun(&Spriteset::decRef)); hairset.clear(); playerset[0]->decRef(); diff --git a/src/monster.cpp b/src/monster.cpp index 43823e50..8a7e2f32 100644 --- a/src/monster.cpp +++ b/src/monster.cpp @@ -23,10 +23,8 @@ #include "monster.h" +#include "animatedsprite.h" #include "game.h" -#include "log.h" - -#include "resources/resourcemanager.h" #include "utils/tostring.h" diff --git a/src/npc.cpp b/src/npc.cpp index 54205ad3..a82490ae 100644 --- a/src/npc.cpp +++ b/src/npc.cpp @@ -23,6 +23,8 @@ #include "npc.h" +#include "animatedsprite.h" + #include "net/messageout.h" #include "net/protocol.h" diff --git a/src/openglgraphics.cpp b/src/openglgraphics.cpp index 2a6c931d..05bbb6b3 100644 --- a/src/openglgraphics.cpp +++ b/src/openglgraphics.cpp @@ -21,6 +21,8 @@ * $Id$ */ +#include "main.h" + #ifdef USE_OPENGL #include "openglgraphics.h" diff --git a/src/player.cpp b/src/player.cpp index 05825f6e..3fe608c7 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -23,8 +23,7 @@ #include "player.h" -#include "animation.h" -#include "equipment.h" +#include "animatedsprite.h" #include "game.h" #include "graphics.h" @@ -91,11 +90,13 @@ Player::setSex(Uint8 sex) delete mSprites[BASE_SPRITE]; if (sex == 0) { - mSprites[BASE_SPRITE] = new AnimatedSprite("graphics/sprites/player_male_base.xml", 0); + mSprites[BASE_SPRITE] = new AnimatedSprite( + "graphics/sprites/player_male_base.xml", 0); } else { - mSprites[BASE_SPRITE] = new AnimatedSprite("graphics/sprites/player_female_base.xml", 0); + mSprites[BASE_SPRITE] = new AnimatedSprite( + "graphics/sprites/player_female_base.xml", 0); } } Being::setSex(sex); @@ -107,8 +108,16 @@ Player::setHairColor(Uint16 color) if (color != mHairColor && mHairStyle > 0) { delete mSprites[HAIR_SPRITE]; - mSprites[HAIR_SPRITE] = new AnimatedSprite("graphics/sprites/hairstyle"+toString(mHairStyle)+".xml", color - 1); + AnimatedSprite *newHairSprite = new AnimatedSprite( + "graphics/sprites/hairstyle" + toString(mHairStyle) + ".xml", + color - 1); + newHairSprite->setDirection(getSpriteDirection()); + + mSprites[HAIR_SPRITE] = newHairSprite; + + setAction(mAction); } + Being::setHairColor(color); } @@ -118,8 +127,16 @@ Player::setHairStyle(Uint16 style) if (style != mHairStyle && mHairColor > 0) { delete mSprites[HAIR_SPRITE]; - mSprites[HAIR_SPRITE] = new AnimatedSprite("graphics/sprites/hairstyle"+toString(style)+".xml", mHairColor - 1); + AnimatedSprite *newHairSprite = new AnimatedSprite( + "graphics/sprites/hairstyle" + toString(style) + ".xml", + mHairColor - 1); + newHairSprite->setDirection(getSpriteDirection()); + + mSprites[HAIR_SPRITE] = newHairSprite; + + setAction(mAction); } + Being::setHairStyle(style); } @@ -139,18 +156,24 @@ Player::setVisibleEquipment(Uint8 slot, Uint8 id) position = TOPCLOTHES_SPRITE; break; } + + delete mSprites[position]; + mSprites[position] = NULL; + // id = 0 means unequip - if (mSprites[position]) { - delete mSprites[position]; - mSprites[position] = 0; - } if (id) { char stringId[4]; sprintf(stringId, "%03i", id); - printf("Id: %i %i %s\n", id, slot, stringId); - mSprites[position] = new AnimatedSprite( + + AnimatedSprite *equipmentSprite = new AnimatedSprite( "graphics/sprites/item" + toString(stringId) + ".xml", 0); + equipmentSprite->setDirection(getSpriteDirection()); + + mSprites[position] = equipmentSprite; + + setAction(mAction); } + Being::setVisibleEquipment(slot, id); } diff --git a/src/resources/image.h b/src/resources/image.h index 1f67fcae..78751394 100644 --- a/src/resources/image.h +++ b/src/resources/image.h @@ -24,6 +24,8 @@ #ifndef _TMW_IMAGE_H #define _TMW_IMAGE_H +#include "../main.h" + #include #ifdef USE_OPENGL #include diff --git a/src/resources/itemmanager.cpp b/src/resources/itemmanager.cpp index 56ac6354..63c0b036 100644 --- a/src/resources/itemmanager.cpp +++ b/src/resources/itemmanager.cpp @@ -30,6 +30,8 @@ #include "../log.h" +#include "../utils/dtor.h" + #define READ_PROP(node, prop, name, target, cast) \ prop = xmlGetProp(node, BAD_CAST name); \ if (prop) { \ @@ -56,14 +58,12 @@ ItemManager::ItemManager() if (!doc) { logger->error("Item Manager: Error while parsing item database (items.xml)!"); - return; } xmlNodePtr node = xmlDocGetRootElement(doc); if (!node || !xmlStrEqual(node->name, BAD_CAST "items")) { logger->error("Item Manager: items.xml is not a valid database file!"); - return; } for (node = node->xmlChildrenNode; node != NULL; node = node->next) diff --git a/src/resources/mapreader.cpp b/src/resources/mapreader.cpp index af79480a..382b0797 100644 --- a/src/resources/mapreader.cpp +++ b/src/resources/mapreader.cpp @@ -28,7 +28,6 @@ #include "resourcemanager.h" #include "image.h" -#include "spriteset.h" #include "../base64.h" #include "../log.h" @@ -220,34 +219,26 @@ MapReader::readMap(xmlNodePtr node, const std::string &path) void MapReader::readProperties(xmlNodePtr node, Properties* props) { - node = node->xmlChildrenNode; + for (node = node->xmlChildrenNode; node; node = node->next) { + if (!xmlStrEqual(node->name, BAD_CAST "property")) + continue; - while (node != NULL) - { - if (xmlStrEqual(node->name, BAD_CAST "property")) - { - // Example: - - xmlChar *name = xmlGetProp(node, BAD_CAST "name"); - xmlChar *value = xmlGetProp(node, BAD_CAST "value"); + // Example: + xmlChar *name = xmlGetProp(node, BAD_CAST "name"); + xmlChar *value = xmlGetProp(node, BAD_CAST "value"); - if (name && value) - { - props->setProperty((const char*) name, (const char*) value); - } - - if (name) xmlFree(name); - if (value) xmlFree(value); + if (name && value) { + props->setProperty((const char*)name, (const char*)value); } - node = node->next; + if (name) xmlFree(name); + if (value) xmlFree(value); } } void MapReader::readLayer(xmlNodePtr node, Map *map, int layer) { - node = node->xmlChildrenNode; int h = map->getHeight(); int w = map->getWidth(); int x = 0; @@ -255,89 +246,86 @@ MapReader::readLayer(xmlNodePtr node, Map *map, int layer) // Load the tile data. Layers are assumed to be map size, with (0,0) as // origin. - while (node != NULL) - { - if (xmlStrEqual(node->name, BAD_CAST "data")) + for (node = node->xmlChildrenNode; node; node = node->next) { + if (!xmlStrEqual(node->name, BAD_CAST "data")) + continue; + + xmlChar *encoding = xmlGetProp(node, BAD_CAST "encoding"); + xmlChar *compression = xmlGetProp(node, BAD_CAST "compression"); + + if (encoding && xmlStrEqual(encoding, BAD_CAST "base64")) { - xmlChar *encoding = xmlGetProp(node, BAD_CAST "encoding"); - xmlChar *compression = xmlGetProp(node, BAD_CAST "compression"); + xmlFree(encoding); - if (encoding && xmlStrEqual(encoding, BAD_CAST "base64")) - { - xmlFree(encoding); + if (compression) { + logger->log("Warning: no layer compression supported!"); + xmlFree(compression); + return; + } - if (compression) { - logger->log("Warning: no layer compression supported!"); - xmlFree(compression); - return; - } + // Read base64 encoded map file + xmlNodePtr dataChild = node->xmlChildrenNode; + if (!dataChild) + continue; - // Read base64 encoded map file - xmlNodePtr dataChild = node->xmlChildrenNode; - if (!dataChild) continue; - - int len = strlen((const char*)dataChild->content) + 1; - unsigned char *charData = new unsigned char[len + 1]; - const char *charStart = (const char*)dataChild->content; - unsigned char *charIndex = charData; - - while (*charStart) { - if (*charStart != ' ' && *charStart != '\t' && - *charStart != '\n') - { - *charIndex = *charStart; - charIndex++; - } - charStart++; + int len = strlen((const char*)dataChild->content) + 1; + unsigned char *charData = new unsigned char[len + 1]; + const char *charStart = (const char*)dataChild->content; + unsigned char *charIndex = charData; + + while (*charStart) { + if (*charStart != ' ' && *charStart != '\t' && + *charStart != '\n') + { + *charIndex = *charStart; + charIndex++; } - *charIndex = '\0'; + charStart++; + } + *charIndex = '\0'; - int binLen; - unsigned char *binData = - php_base64_decode(charData, strlen((char*)charData), - &binLen); + int binLen; + unsigned char *binData = + php_base64_decode(charData, strlen((char*)charData), + &binLen); - delete[] charData; + delete[] charData; - if (binData) { - for (int i = 0; i < binLen - 3; i += 4) { - int gid = binData[i] | - binData[i + 1] << 8 | - binData[i + 2] << 16 | - binData[i + 3] << 24; + if (binData) { + for (int i = 0; i < binLen - 3; i += 4) { + int gid = binData[i] | + binData[i + 1] << 8 | + binData[i + 2] << 16 | + binData[i + 3] << 24; - map->setTileWithGid(x, y, layer, gid); + map->setTileWithGid(x, y, layer, gid); - x++; - if (x == w) {x = 0; y++;} - } - free(binData); + x++; + if (x == w) {x = 0; y++;} } + free(binData); } - else { - // Read plain XML map file - xmlNodePtr n2 = node->xmlChildrenNode; - - while (n2 != NULL) - { - if (xmlStrEqual(n2->name, BAD_CAST "tile") && y < h) - { - int gid = getProperty(n2, "gid", -1); - map->setTileWithGid(x, y, layer, gid); - - x++; - if (x == w) {x = 0; y++;} - } - - n2 = n2->next; + } + else { + // Read plain XML map file + for (xmlNodePtr n2 = node->xmlChildrenNode; n2; n2 = n2->next) { + if (!xmlStrEqual(n2->name, BAD_CAST "tile")) + continue; + + int gid = getProperty(n2, "gid", -1); + map->setTileWithGid(x, y, layer, gid); + + x++; + if (x == w) { + x = 0; y++; + if (y >= h) + break; } } - - // There can be only one data element - break; } - node = node->next; + // There can be only one data element + break; } } @@ -356,38 +344,33 @@ MapReader::readTileset(xmlNodePtr node, int tw = getProperty(node, "tilewidth", map->getTileWidth()); int th = getProperty(node, "tileheight", map->getTileHeight()); - node = node->xmlChildrenNode; + for (node = node->xmlChildrenNode; node; node = node->next) { + if (!xmlStrEqual(node->name, BAD_CAST "image")) + continue; - while (node != NULL) - { - if (xmlStrEqual(node->name, BAD_CAST "image")) - { - xmlChar* source = xmlGetProp(node, BAD_CAST "source"); + xmlChar* source = xmlGetProp(node, BAD_CAST "source"); - if (source) - { - std::string sourceStr = std::string((const char*)source); - sourceStr.erase(0, 3); // Remove "../" + if (source) + { + std::string sourceStr = std::string((const char*)source); + sourceStr.erase(0, 3); // Remove "../" - ResourceManager *resman = ResourceManager::getInstance(); - Image* tilebmp = resman->getImage(sourceStr); + ResourceManager *resman = ResourceManager::getInstance(); + Image* tilebmp = resman->getImage(sourceStr); - if (tilebmp) - { - Tileset *set = new Tileset(tilebmp, tw, th, firstGid); - tilebmp->decRef(); - xmlFree(source); - return set; - } - else { - logger->log("Warning: Failed to load tileset (%s)", source); - } + if (tilebmp) + { + Tileset *set = new Tileset(tilebmp, tw, th, firstGid); + tilebmp->decRef(); + xmlFree(source); + return set; + } + else { + logger->log("Warning: Failed to load tileset (%s)", source); } - - break; } - node = node->next; + break; } return NULL; @@ -396,13 +379,12 @@ MapReader::readTileset(xmlNodePtr node, int MapReader::getProperty(xmlNodePtr node, const char* name, int def) { + int &ret = def; + xmlChar *prop = xmlGetProp(node, BAD_CAST name); if (prop) { - int val = atoi((char*)prop); + ret = atoi((char*)prop); xmlFree(prop); - return val; - } - else { - return def; } + return ret; } diff --git a/src/resources/openglsdlimageloader.cpp b/src/resources/openglsdlimageloader.cpp index c7ddec74..b3e1601e 100644 --- a/src/resources/openglsdlimageloader.cpp +++ b/src/resources/openglsdlimageloader.cpp @@ -21,14 +21,16 @@ * $Id: sdlimageloader.cpp 2121 2006-01-31 02:55:26Z der_doener $ */ -#ifdef USE_OPENGL - #include "openglsdlimageloader.h" #include #include "resourcemanager.h" +#include "../main.h" + +#ifdef USE_OPENGL + SDL_Surface* OpenGLSDLImageLoader::loadSDLSurface(const std::string& filename) { ResourceManager *resman = ResourceManager::getInstance(); -- cgit v1.2.3-70-g09d2 From 5cc5c903df7b535c6bf27987b89a405812d89735 Mon Sep 17 00:00:00 2001 From: Guillaume Melquiond Date: Sat, 26 Aug 2006 13:28:35 +0000 Subject: Implemented "say around" chat. --- ChangeLog | 7 +++++++ src/gui/chat.cpp | 9 ++++----- src/net/beinghandler.cpp | 27 ++++++++++++++++----------- src/net/chathandler.cpp | 17 +++++++++++++++++ src/net/protocol.h | 2 +- 5 files changed, 45 insertions(+), 17 deletions(-) (limited to 'src/gui/chat.cpp') diff --git a/ChangeLog b/ChangeLog index 035f2688..3406dbdc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2006-08-26 Guillaume Melquiond + + * src/net/chathandler.cpp, src/gui/chat.cpp, src/net/protocol.h: Added + support for "say around" messages. + * src/net/beinghandler.cpp: Partly implemented being creation, so that + chat works. + 2006-08-21 Eugenio Favalli * The Mana World.dev, tmw.cbp: Updated project files. diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp index 592439fc..e8bb1cc6 100644 --- a/src/gui/chat.cpp +++ b/src/gui/chat.cpp @@ -37,6 +37,7 @@ #include "../localplayer.h" #include "../net/messageout.h" +#include "../net/network.h" #include "../net/protocol.h" ChatWindow::ChatWindow(Network *network): @@ -249,12 +250,10 @@ ChatWindow::chatSend(const std::string &nick, std::string msg) // Prepare ordinary message if (msg.substr(0, 1) != "/") { - msg = nick + " : " + msg; - MessageOut outMsg; - outMsg.writeShort(CMSG_CHAT_MESSAGE); - outMsg.writeShort(msg.length() + 4); - outMsg.writeString(msg, msg.length()); + outMsg.writeShort(PGMSG_SAY); + outMsg.writeString(msg); + network->send(Network::GAME, outMsg); } else if (msg.substr(0, IS_ANNOUNCE_LENGTH) == IS_ANNOUNCE) { diff --git a/src/net/beinghandler.cpp b/src/net/beinghandler.cpp index ed0fc4b2..10de5351 100644 --- a/src/net/beinghandler.cpp +++ b/src/net/beinghandler.cpp @@ -383,17 +383,22 @@ void BeingHandler::handleMessage(MessageIn &msg) void BeingHandler::handleBeingEnterMessage(MessageIn &msg) { - // Not sure what do to exactly with this message yet. - /* - unsigned char type = msg.readByte(); - unsigned long id = msg.readLong(); - - if (type == OBJECT_PLAYER) + msg.readByte(); // type + int id = msg.readLong(); + std::string name = msg.readString(); + Being *being; + if (player_node->getName() == name) + { + being = player_node; + being->setId(id); + } + else { - std::string name = msg.readString(); - unsigned char hairStyle = msg.readByte(); - unsigned char hairColor = msg.readByte(); - unsigned char gender = msg.readByte(); + // assume type is player for now, so job 0, TODO + being = beingManager->createBeing(id, 0); + being->setName(name); } - */ + being->setHairStyle(msg.readByte() + 1); + being->setHairColor(msg.readByte() + 1); + being->setSex(msg.readByte()); } diff --git a/src/net/chathandler.cpp b/src/net/chathandler.cpp index 795b2a27..02f99c41 100644 --- a/src/net/chathandler.cpp +++ b/src/net/chathandler.cpp @@ -42,11 +42,14 @@ extern Being *player_node; ChatHandler::ChatHandler() { static const Uint16 _messages[] = { + GPMSG_SAY, + /* SMSG_BEING_CHAT, SMSG_PLAYER_CHAT, SMSG_GM_CHAT, SMSG_WHO_ANSWER, 0x10c, // MVP + */ 0 }; handledMessages = _messages; @@ -60,6 +63,20 @@ void ChatHandler::handleMessage(MessageIn &msg) switch (msg.getId()) { + case GPMSG_SAY: + being = beingManager->findBeing(msg.readLong()); + chatMsg = msg.readString(); + if (being) + { + chatWindow->chatLog(being->getName() + " : " + chatMsg, being == player_node ? BY_PLAYER : BY_OTHER); + being->setSpeech(chatMsg, SPEECH_TIME); + } + else + { + chatWindow->chatLog("John Doe : " + chatMsg, BY_OTHER); + } + break; + // Received speech from being case SMSG_BEING_CHAT: chatMsgLength = msg.readShort() - 8; diff --git a/src/net/protocol.h b/src/net/protocol.h index 6927f3fd..33d72c96 100644 --- a/src/net/protocol.h +++ b/src/net/protocol.h @@ -157,7 +157,7 @@ enum { GPMSG_BEING_LEAVE = 0x0201, // B type, L being id PGMSG_WALK = 0x0260, // L*2 destination PGMSG_SAY = 0x02A0, // S text - GPMSG_SAY = 0x02A1, // S being, S text + GPMSG_SAY = 0x02A1, // L being id, S text PGMSG_USE_ITEM = 0x0300, // L item id GPMSG_USE_RESPONSE = 0x0301, // B error PGMSG_EQUIP = 0x0302, // L item id, B slot -- cgit v1.2.3-70-g09d2 From 07b6070c25faedd78c2e26825bd700dc294f00cf Mon Sep 17 00:00:00 2001 From: Guillaume Melquiond Date: Sat, 26 Aug 2006 17:24:43 +0000 Subject: Made the Network class a purely static interface, as there is only one instance. --- ChangeLog | 9 +++++ src/beingmanager.cpp | 7 +--- src/beingmanager.h | 4 --- src/engine.cpp | 5 ++- src/engine.h | 4 +-- src/game.cpp | 42 +++++++++++------------ src/game.h | 5 +-- src/gui/buy.cpp | 4 +-- src/gui/buy.h | 4 +-- src/gui/char_select.cpp | 17 +++++----- src/gui/char_select.h | 8 ++--- src/gui/chat.cpp | 5 ++- src/gui/chat.h | 4 +-- src/gui/sell.cpp | 3 +- src/gui/sell.h | 4 +-- src/gui/trade.cpp | 3 +- src/gui/trade.h | 5 +-- src/localplayer.h | 4 --- src/main.cpp | 48 +++++++++++++------------- src/net/charserverhandler.cpp | 4 +-- src/net/messagehandler.cpp | 14 +------- src/net/messagehandler.h | 7 ---- src/net/network.cpp | 47 ++++++++++++++----------- src/net/network.h | 79 ++++++++++++++----------------------------- src/net/tradehandler.h | 2 -- src/npc.cpp | 4 +-- src/npc.h | 7 +--- 27 files changed, 136 insertions(+), 213 deletions(-) (limited to 'src/gui/chat.cpp') diff --git a/ChangeLog b/ChangeLog index 8e10286f..97782a6e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -15,6 +15,15 @@ support for "say around" messages. * src/net/beinghandler.cpp: Partly implemented being creation, so that chat works. + * src/game.cpp, src/engine.h, src/beingmanager.h, src/gui/trade.cpp, + src/gui/sell.cpp, src/gui/char_select.cpp, src/gui/chat.h, + src/gui/buy.h, src/gui/chat.cpp, src/gui/char_select.h, + src/gui/buy.cpp, src/gui/sell.h, src/gui/trade.h, src/engine.cpp, + src/beingmanager.cpp, src/npc.cpp, src/main.cpp, src/npc.h, + src/net/tradehandler.h, src/net/messagehandler.h, src/net/network.h, + src/net/charserverhandler.cpp, src/net/messagehandler.cpp, + src/net/network.cpp, src/localplayer.h, src/game.h: Made the Network + class a purely static interface, as there is only one instance. 2006-08-21 Eugenio Favalli diff --git a/src/beingmanager.cpp b/src/beingmanager.cpp index 7a94859a..caecd88e 100644 --- a/src/beingmanager.cpp +++ b/src/beingmanager.cpp @@ -49,11 +49,6 @@ class FindBeingFunctor Being::Type type; } beingFinder; -BeingManager::BeingManager(Network *network): - mNetwork(network) -{ -} - void BeingManager::setMap(Map *map) { mMap = map; @@ -79,7 +74,7 @@ Being* BeingManager::createBeing(Uint32 id, Uint16 job) outMsg.writeLong(id); } else if (job >= 100 & job < 200) - being = new NPC(id, job, mMap, mNetwork); + being = new NPC(id, job, mMap); else if (job >= 1000 && job < 1200) being = new Monster(id, job, mMap); else diff --git a/src/beingmanager.h b/src/beingmanager.h index bb6fc99b..0dbafcc6 100644 --- a/src/beingmanager.h +++ b/src/beingmanager.h @@ -28,7 +28,6 @@ class LocalPlayer; class Map; -class Network; typedef std::list Beings; typedef Beings::iterator BeingIterator; @@ -36,8 +35,6 @@ typedef Beings::iterator BeingIterator; class BeingManager { public: - BeingManager(Network *network); - /** * Sets the map on which beings are created */ @@ -86,7 +83,6 @@ class BeingManager protected: Beings mBeings; Map *mMap; - Network *mNetwork; }; extern BeingManager *beingManager; diff --git a/src/engine.cpp b/src/engine.cpp index a6ce9533..3e6b091a 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -62,10 +62,9 @@ Spriteset *emotionset; Spriteset *npcset; std::vector weaponset; -Engine::Engine(Network *network): +Engine::Engine(): mShowDebugPath(false), - mCurrentMap(NULL), - mNetwork(network) + mCurrentMap(NULL) { // Load the sprite sets ResourceManager *resman = ResourceManager::getInstance(); diff --git a/src/engine.h b/src/engine.h index ff39cfba..bdf8419a 100644 --- a/src/engine.h +++ b/src/engine.h @@ -30,7 +30,6 @@ extern int camera_x, camera_y; class Graphics; class Map; -class Network; /** * Game engine that does the main drawing. @@ -41,7 +40,7 @@ class Engine /** * Constructor. */ - Engine(Network *network); + Engine(); /** * Destructor. @@ -77,7 +76,6 @@ class Engine bool mShowDebugPath; Map *mCurrentMap; - Network *mNetwork; }; extern Engine *engine; diff --git a/src/game.cpp b/src/game.cpp index b6428103..f83e9c1f 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -164,15 +164,15 @@ int get_elapsed_time(int start_time) /** * Create all the various globally accessible gui windows */ -void createGuiWindows(Network *network) +void createGuiWindows() { // Create dialogs - chatWindow = new ChatWindow(network); + chatWindow = new ChatWindow; menuWindow = new MenuWindow(); statusWindow = new StatusWindow(player_node); miniStatusWindow = new MiniStatusWindow(); - buyDialog = new BuyDialog(network); - sellDialog = new SellDialog(network); + buyDialog = new BuyDialog; + sellDialog = new SellDialog; buySellDialog = new BuySellDialog(); inventoryWindow = new InventoryWindow(); npcTextDialog = new NpcTextDialog(); @@ -183,7 +183,7 @@ void createGuiWindows(Network *network) minimap = new Minimap(); equipmentWindow = new EquipmentWindow(player_node->mEquipment.get()); chargeDialog = new ChargeDialog(); - tradeWindow = new TradeWindow(network); + tradeWindow = new TradeWindow; //buddyWindow = new BuddyWindow(); helpWindow = new HelpWindow(); debugWindow = new DebugWindow(); @@ -250,8 +250,7 @@ void destroyGuiWindows() delete debugWindow; } -Game::Game(Network *network): - mNetwork(network), +Game::Game(): mBeingHandler(new BeingHandler()), mBuySellHandler(new BuySellHandler()), mChatHandler(new ChatHandler()), @@ -263,10 +262,10 @@ Game::Game(Network *network): mSkillHandler(new SkillHandler()), mTradeHandler(new TradeHandler()) { - createGuiWindows(network); - engine = new Engine(network); + createGuiWindows(); + engine = new Engine; - beingManager = new BeingManager(network); + beingManager = new BeingManager; floorItemManager = new FloorItemManager(); // Initialize timers @@ -276,7 +275,6 @@ Game::Game(Network *network): // Initialize beings beingManager->setPlayer(player_node); - player_node->setNetwork(network); Joystick::init(); // TODO: The user should be able to choose which one to use @@ -286,16 +284,16 @@ Game::Game(Network *network): joystick = new Joystick(0); } - network->registerHandler(mBeingHandler.get()); - network->registerHandler(mBuySellHandler.get()); - network->registerHandler(mChatHandler.get()); - network->registerHandler(mEquipmentHandler.get()); - network->registerHandler(mInventoryHandler.get()); - network->registerHandler(mItemHandler.get()); - network->registerHandler(mNpcHandler.get()); - network->registerHandler(mPlayerHandler.get()); - network->registerHandler(mSkillHandler.get()); - network->registerHandler(mTradeHandler.get()); + Network::registerHandler(mBeingHandler.get()); + Network::registerHandler(mBuySellHandler.get()); + Network::registerHandler(mChatHandler.get()); + Network::registerHandler(mEquipmentHandler.get()); + Network::registerHandler(mInventoryHandler.get()); + Network::registerHandler(mItemHandler.get()); + Network::registerHandler(mNpcHandler.get()); + Network::registerHandler(mPlayerHandler.get()); + Network::registerHandler(mSkillHandler.get()); + Network::registerHandler(mTradeHandler.get()); } Game::~Game() @@ -374,7 +372,7 @@ void Game::logic() } // Handle network stuff - mNetwork->flush(); + Network::flush(); } } diff --git a/src/game.h b/src/game.h index a44c8970..7330052a 100644 --- a/src/game.h +++ b/src/game.h @@ -31,7 +31,6 @@ #define SPEECH_MAX_TIME 100 class MessageHandler; -class Network; extern std::string map_path; extern volatile int fps; @@ -40,7 +39,7 @@ extern volatile int tick_time; class Game { public: - Game(Network *network); + Game(); ~Game(); void logic(); @@ -48,8 +47,6 @@ class Game void handleInput(); protected: - Network *mNetwork; - typedef std::auto_ptr MessageHandlerPtr; MessageHandlerPtr mBeingHandler; MessageHandlerPtr mBuySellHandler; diff --git a/src/gui/buy.cpp b/src/gui/buy.cpp index e7bfef58..63a6e20e 100644 --- a/src/gui/buy.cpp +++ b/src/gui/buy.cpp @@ -42,8 +42,8 @@ #include "../utils/tostring.h" -BuyDialog::BuyDialog(Network *network): - Window("Buy"), mNetwork(network), +BuyDialog::BuyDialog(): + Window("Buy"), mMoney(0), mAmountItems(0), mMaxItems(0) { mShopItems = new ShopItems; diff --git a/src/gui/buy.h b/src/gui/buy.h index b09b648b..0ddea4c4 100644 --- a/src/gui/buy.h +++ b/src/gui/buy.h @@ -30,7 +30,6 @@ #include "../guichanfwd.h" -class Network; class ShopItems; /** @@ -46,7 +45,7 @@ class BuyDialog : public Window, public gcn::ActionListener * * @see Window::Window */ - BuyDialog(Network *network); + BuyDialog(); /** * Destructor @@ -89,7 +88,6 @@ class BuyDialog : public Window, public gcn::ActionListener std::string getElementAt(int i); private: - Network *mNetwork; gcn::Button *mBuyButton; gcn::Button *mQuitButton; gcn::Button *mIncreaseButton; diff --git a/src/gui/char_select.cpp b/src/gui/char_select.cpp index 3db82287..7e0a1a29 100644 --- a/src/gui/char_select.cpp +++ b/src/gui/char_select.cpp @@ -71,9 +71,8 @@ void CharDeleteConfirm::action(const std::string &eventId, gcn::Widget *widget) ConfirmDialog::action(eventId, widget); } -CharSelectDialog::CharSelectDialog(Network *network, - LockedArray *charInfo): - Window("Select Character"), mNetwork(network), +CharSelectDialog::CharSelectDialog(LockedArray *charInfo): + Window("Select Character"), mCharInfo(charInfo), mCharSelected(false) { mSelectButton = new Button("Ok", "ok", this); @@ -147,7 +146,7 @@ void CharSelectDialog::action(const std::string &eventId, gcn::Widget *widget) { // Start new character dialog mCharInfo->lock(); - new CharCreateDialog(this, mCharInfo->getPos(), mNetwork); + new CharCreateDialog(this, mCharInfo->getPos()); mCharInfo->unlock(); } } @@ -208,7 +207,7 @@ void CharSelectDialog::attemptCharDelete() msg.writeShort(PAMSG_CHAR_DELETE); // TODO: Send the selected slot msg.writeByte(0); - network->send(Network::ACCOUNT, msg); + Network::send(Network::ACCOUNT, msg); mCharInfo->lock(); } @@ -218,7 +217,7 @@ void CharSelectDialog::attemptCharSelect() MessageOut msg; msg.writeShort(PAMSG_CHAR_SELECT); msg.writeByte(mCharInfo->getPos()); - network->send(Network::ACCOUNT, msg); + Network::send(Network::ACCOUNT, msg); mCharInfo->lock(); } @@ -227,8 +226,8 @@ void CharSelectDialog::logic() updatePlayerInfo(); } -CharCreateDialog::CharCreateDialog(Window *parent, int slot, Network *network): - Window("Create Character", true, parent), mNetwork(network), mSlot(slot) +CharCreateDialog::CharCreateDialog(Window *parent, int slot): + Window("Create Character", true, parent), mSlot(slot) { mNameField = new TextField(""); mNameLabel = new gcn::Label("Name:"); @@ -336,5 +335,5 @@ void CharCreateDialog::attemptCharCreate() outMsg.writeShort(10); // INT outMsg.writeShort(10); // DEX outMsg.writeShort(10); // LUK - network->send(Network::ACCOUNT, outMsg); + Network::send(Network::ACCOUNT, outMsg); } diff --git a/src/gui/char_select.h b/src/gui/char_select.h index e65f400d..73fc8b2d 100644 --- a/src/gui/char_select.h +++ b/src/gui/char_select.h @@ -32,7 +32,6 @@ #include class LocalPlayer; -class Network; class PlayerBox; /** @@ -47,8 +46,7 @@ class CharSelectDialog : public Window, public gcn::ActionListener /** * Constructor. */ - CharSelectDialog(Network *network, - LockedArray *charInfo); + CharSelectDialog(LockedArray *charInfo); void action(const std::string& eventId, gcn::Widget* widget); @@ -57,7 +55,6 @@ class CharSelectDialog : public Window, public gcn::ActionListener void logic(); private: - Network *mNetwork; LockedArray *mCharInfo; gcn::Button *mSelectButton; @@ -97,14 +94,13 @@ class CharCreateDialog : public Window, public gcn::ActionListener /** * Constructor. */ - CharCreateDialog(Window *parent, int slot, Network *network); + CharCreateDialog(Window *parent, int slot); void action(const std::string& eventId, gcn::Widget* widget); std::string getName(); private: - Network *mNetwork; gcn::TextField *mNameField; gcn::Label *mNameLabel; gcn::Button *mNextHairColorButton; diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp index e8bb1cc6..04ac3996 100644 --- a/src/gui/chat.cpp +++ b/src/gui/chat.cpp @@ -40,9 +40,8 @@ #include "../net/network.h" #include "../net/protocol.h" -ChatWindow::ChatWindow(Network *network): +ChatWindow::ChatWindow(): Window(""), - mNetwork(network), mTmpVisible(false) { setWindowName("Chat"); @@ -253,7 +252,7 @@ ChatWindow::chatSend(const std::string &nick, std::string msg) MessageOut outMsg; outMsg.writeShort(PGMSG_SAY); outMsg.writeString(msg); - network->send(Network::GAME, outMsg); + Network::send(Network::GAME, outMsg); } else if (msg.substr(0, IS_ANNOUNCE_LENGTH) == IS_ANNOUNCE) { diff --git a/src/gui/chat.h b/src/gui/chat.h index 20841873..a0a3d1ec 100644 --- a/src/gui/chat.h +++ b/src/gui/chat.h @@ -35,7 +35,6 @@ #include "../guichanfwd.h" class BrowserBox; -class Network; class ScrollArea; #define BY_GM 0 // those should be self-explanatory =) @@ -116,7 +115,7 @@ class ChatWindow : public Window, public gcn::ActionListener, /** * Constructor. */ - ChatWindow(Network *network); + ChatWindow(); /** * Logic (updates components' size) @@ -188,7 +187,6 @@ class ChatWindow : public Window, public gcn::ActionListener, void setVisible(bool visible); private: - Network *mNetwork; bool mTmpVisible; /** One item in the chat log */ diff --git a/src/gui/sell.cpp b/src/gui/sell.cpp index e820d42f..3aa7c889 100644 --- a/src/gui/sell.cpp +++ b/src/gui/sell.cpp @@ -44,9 +44,8 @@ #include "../utils/tostring.h" -SellDialog::SellDialog(Network *network): +SellDialog::SellDialog(): Window("Sell"), - mNetwork(network), mMaxItems(0), mAmountItems(0) { mShopItems = new ShopItems(); diff --git a/src/gui/sell.h b/src/gui/sell.h index 423fea26..be5185bd 100644 --- a/src/gui/sell.h +++ b/src/gui/sell.h @@ -31,7 +31,6 @@ #include "../guichanfwd.h" class Item; -class Network; class ShopItems; @@ -48,7 +47,7 @@ class SellDialog : public Window, public gcn::ActionListener * * @see Window::Window */ - SellDialog(Network *network); + SellDialog(); /** * Destructor @@ -76,7 +75,6 @@ class SellDialog : public Window, public gcn::ActionListener void mouseClick(int x, int y, int buton, int count); private: - Network *mNetwork; gcn::Button *mSellButton; gcn::Button *mIncreaseButton; gcn::Button *mDecreaseButton; diff --git a/src/gui/trade.cpp b/src/gui/trade.cpp index 73193c88..6b247901 100644 --- a/src/gui/trade.cpp +++ b/src/gui/trade.cpp @@ -45,9 +45,8 @@ #include "../utils/tostring.h" -TradeWindow::TradeWindow(Network *network): +TradeWindow::TradeWindow(): Window("Trade: You"), - mNetwork(network), mMyInventory(new Inventory()), mPartnerInventory(new Inventory()) { diff --git a/src/gui/trade.h b/src/gui/trade.h index eb3c0f97..fe60aac5 100644 --- a/src/gui/trade.h +++ b/src/gui/trade.h @@ -35,7 +35,6 @@ class Inventory; class Item; class ItemContainer; -class Network; class ScrollArea; /** @@ -49,7 +48,7 @@ class TradeWindow : public Window, gcn::ActionListener /** * Constructor. */ - TradeWindow(Network *network); + TradeWindow(); /** * Destructor. @@ -113,8 +112,6 @@ class TradeWindow : public Window, gcn::ActionListener void action(const std::string& eventId, gcn::Widget* widget); private: - Network *mNetwork; - typedef std::auto_ptr InventoryPtr; InventoryPtr mMyInventory; InventoryPtr mPartnerInventory; diff --git a/src/localplayer.h b/src/localplayer.h index fdef6ba1..613f196a 100644 --- a/src/localplayer.h +++ b/src/localplayer.h @@ -34,7 +34,6 @@ class FloorItem; class Inventory; class Item; -class Network; class LocalPlayer : public Player { @@ -47,8 +46,6 @@ class LocalPlayer : public Player virtual ~LocalPlayer(); - void setNetwork(Network *network) { mNetwork = network; } - virtual void logic(); virtual void nextStep(); @@ -145,7 +142,6 @@ class LocalPlayer : public Player std::auto_ptr mInventory; protected: - Network *mNetwork; Being *mTarget; FloorItem *mPickUpTarget; diff --git a/src/main.cpp b/src/main.cpp index 4e65e4fc..573b1a79 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -413,8 +413,8 @@ MapLoginHandler mapLoginHandler; void accountLogin(LoginData *loginData) { logger->log("Username is %s", loginData->username.c_str()); - network->registerHandler(&loginHandler); - network->registerHandler(&charServerHandler); + Network::registerHandler(&loginHandler); + Network::registerHandler(&charServerHandler); loginHandler.setLoginData(loginData); charServerHandler.setLoginData(loginData); charServerHandler.setCharInfo(&charInfo); @@ -424,7 +424,7 @@ void accountLogin(LoginData *loginData) msg.writeLong(0); // client version msg.writeString(loginData->username); msg.writeString(loginData->password); - network->send(Network::ACCOUNT, msg); + Network::send(Network::ACCOUNT, msg); // Clear the password, avoids auto login when returning to login loginData->password = ""; @@ -441,7 +441,7 @@ void accountLogin(LoginData *loginData) void accountRegister(LoginData *loginData) { logger->log("Username is %s", loginData->username.c_str()); - network->registerHandler(&loginHandler); + Network::registerHandler(&loginHandler); loginHandler.setLoginData(loginData); charServerHandler.setLoginData(loginData); charServerHandler.setCharInfo(&charInfo); @@ -452,21 +452,21 @@ void accountRegister(LoginData *loginData) msg.writeString(loginData->username); msg.writeString(loginData->password); msg.writeString(loginData->email); - network->send(Network::ACCOUNT, msg); + Network::send(Network::ACCOUNT, msg); } -void mapLogin(Network *network, LoginData *loginData) +void mapLogin(LoginData *loginData) { - network->registerHandler(&mapLoginHandler); + Network::registerHandler(&mapLoginHandler); // Send connect messages with the magic token to game and chat servers MessageOut gameServerConnect(PGMSG_CONNECT); gameServerConnect.writeString(token, 32); - network->send(Network::GAME, gameServerConnect); + Network::send(Network::GAME, gameServerConnect); MessageOut chatServerConnect(PCMSG_CONNECT); chatServerConnect.writeString(token, 32); - network->send(Network::CHAT, chatServerConnect); + Network::send(Network::CHAT, chatServerConnect); } /** Main */ @@ -533,7 +533,7 @@ int main(int argc, char *argv[]) { logger->error("An error occurred while initializing ENet."); } - network = new Network(); + Network::initialize(); SDL_Event event; @@ -557,9 +557,9 @@ int main(int argc, char *argv[]) } gui->logic(); - network->flush(); + Network::flush(); - if (network->getState() == Network::NET_ERROR) + if (Network::getState() == Network::NET_ERROR) { state = STATE_ERROR; errorMessage = "Got disconnected from server!"; @@ -585,7 +585,7 @@ int main(int argc, char *argv[]) // TODO: Add connect timeout to go back to choose server if (state == STATE_CONNECT_ACCOUNT && - network->isConnected(Network::ACCOUNT)) + Network::isConnected(Network::ACCOUNT)) { if (options.skipUpdate) { state = STATE_LOGIN; @@ -594,8 +594,8 @@ int main(int argc, char *argv[]) } } else if (state == STATE_CONNECT_GAME && - network->isConnected(Network::GAME) && - network->isConnected(Network::CHAT)) + Network::isConnected(Network::GAME) && + Network::isConnected(Network::CHAT)) { // TODO: Somehow send the token state = STATE_GAME; @@ -611,7 +611,7 @@ int main(int argc, char *argv[]) // Disconnect from account server once connected to game server if (oldstate == STATE_CONNECT_GAME && state == STATE_GAME) { - network->disconnect(Network::ACCOUNT); + Network::disconnect(Network::ACCOUNT); } oldstate = state; @@ -627,7 +627,7 @@ int main(int argc, char *argv[]) logger->log("State: CHOOSE_SERVER"); // TODO: Allow changing this using a server choice dialog logger->log("Trying to connect to account server..."); - network->connect(Network::ACCOUNT, + Network::connect(Network::ACCOUNT, loginData.hostname, loginData.port); state = STATE_CONNECT_ACCOUNT; break; @@ -667,7 +667,7 @@ int main(int argc, char *argv[]) case STATE_CHAR_SELECT: logger->log("State: CHAR_SELECT"); - currentDialog = new CharSelectDialog(network, &charInfo); + currentDialog = new CharSelectDialog(&charInfo); if (options.chooseDefault) { ((CharSelectDialog*)currentDialog)->action("ok", NULL); @@ -679,9 +679,9 @@ int main(int argc, char *argv[]) currentDialog = new OkDialog("Error", errorMessage); currentDialog->addActionListener(&errorListener); currentDialog = NULL; // OkDialog deletes itself - network->disconnect(Network::GAME); - network->disconnect(Network::CHAT); - network->clearHandlers(); + Network::disconnect(Network::GAME); + Network::disconnect(Network::CHAT); + Network::clearHandlers(); break; case STATE_CONNECT_GAME: @@ -690,7 +690,7 @@ int main(int argc, char *argv[]) break; case STATE_GAME: - mapLogin(network, &loginData); + mapLogin(&loginData); sound.fadeOutMusic(1000); currentDialog = NULL; @@ -698,7 +698,7 @@ int main(int argc, char *argv[]) login_wallpaper = NULL; logger->log("State: GAME"); - game = new Game(network); + game = new Game; game->logic(); delete game; state = STATE_EXIT; @@ -711,7 +711,7 @@ int main(int argc, char *argv[]) } } - delete network; + Network::finalize(); enet_deinitialize(); if (nullFile) diff --git a/src/net/charserverhandler.cpp b/src/net/charserverhandler.cpp index 1eea29b8..d67949cc 100644 --- a/src/net/charserverhandler.cpp +++ b/src/net/charserverhandler.cpp @@ -174,8 +174,8 @@ CharServerHandler::handleCharSelectResponse(MessageIn &msg) logger->log("Game server: %s:%d", gameServer.c_str(), gameServerPort); logger->log("Chat server: %s:%d", chatServer.c_str(), chatServerPort); - network->connect(Network::GAME, gameServer, gameServerPort); - network->connect(Network::CHAT, chatServer, chatServerPort); + Network::connect(Network::GAME, gameServer, gameServerPort); + Network::connect(Network::CHAT, chatServer, chatServerPort); // Keep the selected character and delete the others player_node = mCharInfo->getEntry(); diff --git a/src/net/messagehandler.cpp b/src/net/messagehandler.cpp index 849b6716..0b5cd87c 100644 --- a/src/net/messagehandler.cpp +++ b/src/net/messagehandler.cpp @@ -27,19 +27,7 @@ #include "network.h" -MessageHandler::MessageHandler(): - mNetwork(0) -{ -} - MessageHandler::~MessageHandler() { - if (mNetwork) - mNetwork->unregisterHandler(this); -} - -void MessageHandler::setNetwork(Network *network) -{ - assert(!(network && mNetwork)); - mNetwork = network; + Network::unregisterHandler(this); } diff --git a/src/net/messagehandler.h b/src/net/messagehandler.h index 9f92636d..b21abd72 100644 --- a/src/net/messagehandler.h +++ b/src/net/messagehandler.h @@ -27,22 +27,15 @@ #include class MessageIn; -class Network; class MessageHandler { public: const Uint16 *handledMessages; - MessageHandler(); virtual ~MessageHandler(); virtual void handleMessage(MessageIn &msg) = 0; - - void setNetwork(Network *network); - - protected: - Network *mNetwork; }; #endif diff --git a/src/net/network.cpp b/src/net/network.cpp index 08b5fe92..e56f6df0 100644 --- a/src/net/network.cpp +++ b/src/net/network.cpp @@ -29,10 +29,25 @@ #include "../log.h" -Network *network; +static Network::State mState; -Network::Network(): - mState(NET_OK) +/** + * The local host. + */ +static ENetHost *mClient; + +/** + * An array holding the peers of the account, game and chat servers. + */ +static ENetPeer *mServers[3]; + +typedef std::map MessageHandlers; +typedef MessageHandlers::iterator MessageHandlerIterator; +static MessageHandlers mMessageHandlers; + +Network::State Network::getState() { return mState; } + +void Network::initialize() { // Initialize server peers for (int i = 0; i < 3; ++i) @@ -48,7 +63,7 @@ Network::Network(): } } -Network::~Network() +void Network::finalize() { clearHandlers(); @@ -110,15 +125,10 @@ Network::disconnect(Server server) void Network::registerHandler(MessageHandler *handler) { - const Uint16 *i = handler->handledMessages; - - while(*i) + for (const Uint16 *i = handler->handledMessages; *i; i++) { mMessageHandlers[*i] = handler; - i++; } - - handler->setNetwork(this); } void @@ -128,30 +138,27 @@ Network::unregisterHandler(MessageHandler *handler) { mMessageHandlers.erase(*i); } - - handler->setNetwork(0); } void Network::clearHandlers() { - MessageHandlerIterator i; - for (i = mMessageHandlers.begin(); i != mMessageHandlers.end(); i++) - { - i->second->setNetwork(0); - } mMessageHandlers.clear(); } bool -Network::isConnected(Server server) const +Network::isConnected(Server server) { return mServers[server] != NULL && mServers[server]->state == ENET_PEER_STATE_CONNECTED; } -void -Network::dispatchMessage(ENetPacket *packet) +/** + * Dispatches a message to the appropriate message handler and + * destroys it afterwards. + */ +static void +dispatchMessage(ENetPacket *packet) { MessageIn msg((const char *)packet->data, packet->dataLength); diff --git a/src/net/network.h b/src/net/network.h index 40255e44..861fa2b3 100644 --- a/src/net/network.h +++ b/src/net/network.h @@ -42,108 +42,79 @@ class MessageOut; class Network { public: - friend class MessageOut; - /** - * Constructor. Sets up the local host. + * Sets up the local host. */ - Network(); + static void + initialize(); /** - * Destructor. + * Closes the connections. */ - ~Network(); + static void + finalize(); - typedef enum { + enum Server { ACCOUNT, GAME, CHAT - } Server; + }; + + enum State { + NET_OK, + NET_ERROR + }; /** * Connects to the given server with the specified address and port. * This method is non-blocking, use isConnected to check whether the * server is connected. */ - bool + static bool connect(Server server, const std::string &address, short port); /** * Disconnects from the given server. */ - void + static void disconnect(Server server); /** * Registers a message handler. A message handler handles a certain * subset of incoming messages. */ - void + static void registerHandler(MessageHandler *handler); /** * Unregisters a message handler. */ - void + static void unregisterHandler(MessageHandler *handler); - void + static void clearHandlers(); - int - getState() const { return mState; } + static State + getState(); /** * Returns whether the given server is connected. */ - bool - isConnected(Server server) const; + static bool + isConnected(Server server); - void + static void flush(); /** - * Send a message to a given server. The server should be connected. + * Sends a message to a given server. The server should be connected. */ - void + static void send(Server server, const MessageOut &msg); - - enum State { - NET_OK, - NET_ERROR - }; - - private: - /** - * The local host. - */ - ENetHost *mClient; - - /** - * An array holding the peers of the account, game and chat servers. - */ - ENetPeer *mServers[3]; - - /** - * Dispatches a message to the appropriate message handler and - * destroys it afterwards. - */ - void - dispatchMessage(ENetPacket *packet); - - unsigned int mToSkip; - - int mState; - - typedef std::map MessageHandlers; - typedef MessageHandlers::iterator MessageHandlerIterator; - MessageHandlers mMessageHandlers; }; /** Convert an address from int format to string */ char *iptostring(int address); -// TODO: remove this global, just a temp solution. -extern Network *network; - #endif diff --git a/src/net/tradehandler.h b/src/net/tradehandler.h index 0b73c871..1ab3c2e4 100644 --- a/src/net/tradehandler.h +++ b/src/net/tradehandler.h @@ -26,8 +26,6 @@ #include "messagehandler.h" -class Network; - class TradeHandler : public MessageHandler { public: diff --git a/src/npc.cpp b/src/npc.cpp index a82490ae..a14b6d24 100644 --- a/src/npc.cpp +++ b/src/npc.cpp @@ -33,8 +33,8 @@ extern Spriteset *npcset; NPC *current_npc = 0; -NPC::NPC(Uint32 id, Uint16 job, Map *map, Network *network): - Being(id, job, map), mNetwork(network) +NPC::NPC(Uint32 id, Uint16 job, Map *map): + Being(id, job, map) { mSprites[BASE_SPRITE] = new AnimatedSprite("graphics/sprites/npc.xml", job-100); } diff --git a/src/npc.h b/src/npc.h index b08c315c..bbc86d9c 100644 --- a/src/npc.h +++ b/src/npc.h @@ -26,12 +26,10 @@ #include "being.h" -class Network; - class NPC : public Being { public: - NPC(Uint32 id, Uint16 job, Map *map, Network *network); + NPC(Uint32 id, Uint16 job, Map *map); virtual Type getType() const; @@ -41,9 +39,6 @@ class NPC : public Being void buy(); void sell(); - - protected: - Network *mNetwork; }; extern NPC *current_npc; -- cgit v1.2.3-70-g09d2 From 40339bebb026cd553aacbbff6f2fe1aa14816d5a Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Sat, 26 Aug 2006 22:09:04 +0000 Subject: Got rid of the default MessageOut constructor, since all messages should have an ID. --- ChangeLog | 12 ++++++++++-- src/beingmanager.cpp | 3 +-- src/engine.cpp | 7 ------- src/gui/buy.cpp | 13 ++++++++----- src/gui/char_select.cpp | 6 ++---- src/gui/chat.cpp | 9 +++------ src/gui/sell.cpp | 3 +-- src/gui/trade.cpp | 15 +++++---------- src/localplayer.cpp | 42 ++++++++++++++---------------------------- src/net/messageout.cpp | 7 ------- src/net/messageout.h | 5 ----- src/npc.cpp | 15 +++++---------- 12 files changed, 49 insertions(+), 88 deletions(-) (limited to 'src/gui/chat.cpp') diff --git a/ChangeLog b/ChangeLog index de1d030c..6850a45e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2006-08-27 Bjørn Lindeijer + + * src/localplayer.cpp, src/gui/sell.cpp, src/gui/trade.cpp, + src/gui/char_select.cpp, src/gui/chat.cpp, src/gui/buy.cpp, + src/engine.cpp, src/beingmanager.cpp, src/npc.cpp, + src/net/messageout.cpp, src/net/messageout.h: Got rid of the default + MessageOut constructor, since all messages should have an ID. + 2006-08-26 Bjørn Lindeijer * src/gui/char_select.cpp, src/gui/playerbox.cpp, src/player.cpp, @@ -24,8 +32,8 @@ src/net/charserverhandler.cpp, src/net/messagehandler.cpp, src/net/network.cpp, src/localplayer.h, src/game.h: Made the Network class a purely static interface, as there is only one instance. - * src/net/beinghandler.cpp, src/net/beinghandler.h, src/net/protocol.h: - Added support for "beings move" messages. + * src/net/beinghandler.cpp, src/net/beinghandler.h, + src/net/protocol.h: Added support for "beings move" messages. 2006-08-21 Eugenio Favalli diff --git a/src/beingmanager.cpp b/src/beingmanager.cpp index caecd88e..a6c7974d 100644 --- a/src/beingmanager.cpp +++ b/src/beingmanager.cpp @@ -69,8 +69,7 @@ Being* BeingManager::createBeing(Uint32 id, Uint16 job) if (job < 10) { being = new Player(id, job, mMap); - MessageOut outMsg; - outMsg.writeShort(0x0094); + MessageOut outMsg(0x0094); outMsg.writeLong(id); } else if (job >= 100 & job < 200) diff --git a/src/engine.cpp b/src/engine.cpp index 3e6b091a..7a33dd3d 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -39,9 +39,6 @@ #include "gui/gui.h" #include "gui/minimap.h" -#include "net/messageout.h" -#include "net/protocol.h" - #include "resources/itemmanager.h" #include "resources/mapreader.h" #include "resources/resourcemanager.h" @@ -148,10 +145,6 @@ void Engine::changeMap(const std::string &mapPath) } mCurrentMap = newMap; - - // Send "map loaded" - MessageOut outMsg; - outMsg.writeShort(CMSG_MAP_LOADED); } void Engine::logic() diff --git a/src/gui/buy.cpp b/src/gui/buy.cpp index 63a6e20e..165fa7dc 100644 --- a/src/gui/buy.cpp +++ b/src/gui/buy.cpp @@ -215,9 +215,9 @@ void BuyDialog::action(const std::string &eventId, gcn::Widget *widget) // of items to be bought ever fails, Bertram removed the assertions, is // there a better way to ensure this fails in an _obivous_ way in C++? else if (eventId == "buy" && (mAmountItems > 0 && - mAmountItems <= mMaxItems)) { - MessageOut outMsg; - outMsg.writeShort(CMSG_NPC_BUY_REQUEST); + mAmountItems <= mMaxItems)) + { + MessageOut outMsg(CMSG_NPC_BUY_REQUEST); outMsg.writeShort(8); outMsg.writeShort(mAmountItems); outMsg.writeShort(mShopItems->at(selectedItem).id); @@ -262,9 +262,12 @@ void BuyDialog::mouseClick(int x, int y, int button, int count) int selectedItem = mItemList->getSelected(); if (selectedItem > -1) { + int itemId = mShopItems->at(selectedItem).id; + ItemInfo *itemInfo = itemDb->getItemInfo(itemId); + mItemDescLabel->setCaption("Description: " + - itemDb->getItemInfo(mShopItems->at(selectedItem).id)->getDescription()); + itemInfo->getDescription()); mItemEffectLabel->setCaption("Effect: " + - itemDb->getItemInfo(mShopItems->at(selectedItem).id)->getEffect()); + itemInfo->getEffect()); } } diff --git a/src/gui/char_select.cpp b/src/gui/char_select.cpp index 7e0a1a29..adcbe290 100644 --- a/src/gui/char_select.cpp +++ b/src/gui/char_select.cpp @@ -203,8 +203,7 @@ void CharSelectDialog::updatePlayerInfo() void CharSelectDialog::attemptCharDelete() { // Request character deletion - MessageOut msg; - msg.writeShort(PAMSG_CHAR_DELETE); + MessageOut msg(PAMSG_CHAR_DELETE); // TODO: Send the selected slot msg.writeByte(0); Network::send(Network::ACCOUNT, msg); @@ -214,8 +213,7 @@ void CharSelectDialog::attemptCharDelete() void CharSelectDialog::attemptCharSelect() { // Request character selection - MessageOut msg; - msg.writeShort(PAMSG_CHAR_SELECT); + MessageOut msg(PAMSG_CHAR_SELECT); msg.writeByte(mCharInfo->getPos()); Network::send(Network::ACCOUNT, msg); mCharInfo->lock(); diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp index 04ac3996..9098f9f0 100644 --- a/src/gui/chat.cpp +++ b/src/gui/chat.cpp @@ -249,16 +249,14 @@ ChatWindow::chatSend(const std::string &nick, std::string msg) // Prepare ordinary message if (msg.substr(0, 1) != "/") { - MessageOut outMsg; - outMsg.writeShort(PGMSG_SAY); + MessageOut outMsg(PGMSG_SAY); outMsg.writeString(msg); Network::send(Network::GAME, outMsg); } else if (msg.substr(0, IS_ANNOUNCE_LENGTH) == IS_ANNOUNCE) { msg.erase(0, IS_ANNOUNCE_LENGTH); - MessageOut outMsg; - outMsg.writeShort(0x0099); + MessageOut outMsg(0x0099); outMsg.writeShort(msg.length() + 4); outMsg.writeString(msg, msg.length()); } @@ -276,8 +274,7 @@ ChatWindow::chatSend(const std::string &nick, std::string msg) } else if (msg.substr(0, IS_WHO_LENGTH) == IS_WHO) { - MessageOut outMsg; - outMsg.writeShort(0x00c1); + MessageOut outMsg(0x00c1); } else { diff --git a/src/gui/sell.cpp b/src/gui/sell.cpp index 3aa7c889..33813271 100644 --- a/src/gui/sell.cpp +++ b/src/gui/sell.cpp @@ -212,8 +212,7 @@ void SellDialog::action(const std::string &eventId, gcn::Widget *widget) // Attempt sell assert(mAmountItems > 0 && mAmountItems <= mMaxItems); - MessageOut outMsg; - outMsg.writeShort(CMSG_NPC_SELL_REQUEST); + MessageOut outMsg(CMSG_NPC_SELL_REQUEST); outMsg.writeShort(8); outMsg.writeShort(mShopItems->at(selectedItem).index); outMsg.writeShort(mAmountItems); diff --git a/src/gui/trade.cpp b/src/gui/trade.cpp index 6b247901..0cd49013 100644 --- a/src/gui/trade.cpp +++ b/src/gui/trade.cpp @@ -214,8 +214,7 @@ void TradeWindow::receivedOk(bool own) void TradeWindow::tradeItem(Item *item, int quantity) { - MessageOut outMsg; - outMsg.writeShort(CMSG_TRADE_ITEM_ADD_REQUEST); + MessageOut outMsg(CMSG_TRADE_ITEM_ADD_REQUEST); outMsg.writeShort(item->getInvIndex()); outMsg.writeLong(quantity); } @@ -286,8 +285,7 @@ void TradeWindow::action(const std::string &eventId, gcn::Widget *widget) } else if (eventId == "cancel") { - MessageOut outMsg; - outMsg.writeShort(CMSG_TRADE_CANCEL_REQUEST); + MessageOut outMsg(CMSG_TRADE_CANCEL_REQUEST); } else if (eventId == "ok") { @@ -297,20 +295,17 @@ void TradeWindow::action(const std::string &eventId, gcn::Widget *widget) { mMoneyField->setText(toString(tempInt)); - MessageOut outMsg; - outMsg.writeShort(CMSG_TRADE_ITEM_ADD_REQUEST); + MessageOut outMsg(CMSG_TRADE_ITEM_ADD_REQUEST); outMsg.writeShort(0); outMsg.writeLong(tempInt); } else { mMoneyField->setText(""); } mMoneyField->setEnabled(false); - MessageOut outMsg; - outMsg.writeShort(CMSG_TRADE_ADD_COMPLETE); + MessageOut outMsg(CMSG_TRADE_ADD_COMPLETE); } else if (eventId == "trade") { - MessageOut outMsg; - outMsg.writeShort(CMSG_TRADE_OK); + MessageOut outMsg(CMSG_TRADE_OK); } } diff --git a/src/localplayer.cpp b/src/localplayer.cpp index 83884b6f..f157f04c 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -116,8 +116,7 @@ Item* LocalPlayer::getInvItem(int index) void LocalPlayer::equipItem(Item *item) { - MessageOut outMsg; - outMsg.writeShort(CMSG_PLAYER_EQUIP); + MessageOut outMsg(CMSG_PLAYER_EQUIP); outMsg.writeShort(item->getInvIndex()); outMsg.writeShort(0); } @@ -127,8 +126,7 @@ void LocalPlayer::unequipItem(Item *item) if (!item) return; - MessageOut outMsg; - outMsg.writeShort(CMSG_PLAYER_UNEQUIP); + MessageOut outMsg(CMSG_PLAYER_UNEQUIP); outMsg.writeShort(item->getInvIndex()); // Tidy equipment directly to avoid weapon still shown bug, by instance @@ -137,8 +135,7 @@ void LocalPlayer::unequipItem(Item *item) void LocalPlayer::useItem(Item *item) { - MessageOut outMsg; - outMsg.writeShort(CMSG_PLAYER_INVENTORY_USE); + MessageOut outMsg(CMSG_PLAYER_INVENTORY_USE); outMsg.writeShort(item->getInvIndex()); outMsg.writeLong(item->getId()); // Note: id is dest of item, usually player_node->account_ID ?? @@ -147,8 +144,7 @@ void LocalPlayer::useItem(Item *item) void LocalPlayer::dropItem(Item *item, int quantity) { // TODO: Fix wrong coordinates of drops, serverside? - MessageOut outMsg; - outMsg.writeShort(CMSG_PLAYER_INVENTORY_DROP); + MessageOut outMsg(CMSG_PLAYER_INVENTORY_DROP); outMsg.writeShort(item->getInvIndex()); outMsg.writeShort(quantity); } @@ -159,8 +155,7 @@ void LocalPlayer::pickUp(FloorItem *item) int dy = item->getY() - mY; if (dx * dx + dy * dy < 4) { - MessageOut outMsg; - outMsg.writeShort(CMSG_ITEM_PICKUP); + MessageOut outMsg(CMSG_ITEM_PICKUP); outMsg.writeLong(item->getId()); mPickUpTarget = NULL; } else { @@ -220,9 +215,8 @@ void LocalPlayer::walk(unsigned char dir) void LocalPlayer::setDestination(Uint16 x, Uint16 y) { char temp[3]; - MessageOut outMsg; + MessageOut outMsg(0x0085); set_coordinates(temp, x, y, mDirection); - outMsg.writeShort(0x0085); outMsg.writeString(temp, 3); mPickUpTarget = NULL; @@ -232,8 +226,7 @@ void LocalPlayer::setDestination(Uint16 x, Uint16 y) void LocalPlayer::raiseAttribute(Attribute attr) { - MessageOut outMsg; - outMsg.writeShort(CMSG_STAT_UPDATE_REQUEST); + MessageOut outMsg(CMSG_STAT_UPDATE_REQUEST); switch (attr) { @@ -269,8 +262,7 @@ void LocalPlayer::raiseSkill(Uint16 skillId) if (mSkillPoint <= 0) return; - MessageOut outMsg; - outMsg.writeShort(CMSG_SKILL_LEVELUP_REQUEST); + MessageOut outMsg(CMSG_SKILL_LEVELUP_REQUEST); outMsg.writeShort(skillId); } @@ -288,8 +280,7 @@ void LocalPlayer::toggleSit() default: return; } - MessageOut outMsg; - outMsg.writeShort(0x0089); + MessageOut outMsg(0x0089); outMsg.writeLong(0); outMsg.writeByte(type); } @@ -300,8 +291,7 @@ void LocalPlayer::emote(Uint8 emotion) return; mLastAction = tick_time; - MessageOut outMsg; - outMsg.writeShort(0x00bf); + MessageOut outMsg(0x00bf); outMsg.writeByte(emotion); } @@ -310,15 +300,13 @@ void LocalPlayer::tradeReply(bool accept) if (!accept) mTrading = false; - MessageOut outMsg; - outMsg.writeShort(CMSG_TRADE_RESPONSE); + MessageOut outMsg(CMSG_TRADE_RESPONSE); outMsg.writeByte(accept ? 3 : 4); } void LocalPlayer::trade(Being *being) const { - MessageOut outMsg; - outMsg.writeShort(CMSG_TRADE_REQUEST); + MessageOut outMsg(CMSG_TRADE_REQUEST); outMsg.writeLong(being->getId()); } @@ -369,8 +357,7 @@ void LocalPlayer::attack(Being *target, bool keep) else sound.playSfx("sfx/fist-swish.ogg"); - MessageOut outMsg; - outMsg.writeShort(0x0089); + MessageOut outMsg(0x0089); outMsg.writeLong(target->getId()); outMsg.writeByte(0); } @@ -387,7 +374,6 @@ Being* LocalPlayer::getTarget() const void LocalPlayer::revive() { - MessageOut outMsg; - outMsg.writeShort(0x00b2); + MessageOut outMsg(0x00b2); outMsg.writeByte(0); } diff --git a/src/net/messageout.cpp b/src/net/messageout.cpp index 4fca662a..4d68c14f 100644 --- a/src/net/messageout.cpp +++ b/src/net/messageout.cpp @@ -27,13 +27,6 @@ #include -MessageOut::MessageOut(): - mData(0), - mDataSize(0), - mPos(0) -{ -} - MessageOut::MessageOut(short id): mData(0), mDataSize(0), diff --git a/src/net/messageout.h b/src/net/messageout.h index 81369c0e..af25e4b4 100644 --- a/src/net/messageout.h +++ b/src/net/messageout.h @@ -32,11 +32,6 @@ class MessageOut { public: - /** - * Constructor. - */ - MessageOut(); - /** * Constructor. */ diff --git a/src/npc.cpp b/src/npc.cpp index a14b6d24..13025469 100644 --- a/src/npc.cpp +++ b/src/npc.cpp @@ -48,8 +48,7 @@ NPC::getType() const void NPC::talk() { - MessageOut outMsg; - outMsg.writeShort(CMSG_NPC_TALK); + MessageOut outMsg(CMSG_NPC_TALK); outMsg.writeLong(mId); outMsg.writeByte(0); current_npc = this; @@ -58,16 +57,14 @@ NPC::talk() void NPC::nextDialog() { - MessageOut outMsg; - outMsg.writeShort(CMSG_NPC_NEXT_REQUEST); + MessageOut outMsg(CMSG_NPC_NEXT_REQUEST); outMsg.writeLong(mId); } void NPC::dialogChoice(char choice) { - MessageOut outMsg; - outMsg.writeShort(CMSG_NPC_LIST_CHOICE); + MessageOut outMsg(CMSG_NPC_LIST_CHOICE); outMsg.writeLong(mId); outMsg.writeByte(choice); } @@ -79,8 +76,7 @@ NPC::dialogChoice(char choice) void NPC::buy() { - MessageOut outMsg; - outMsg.writeShort(CMSG_NPC_BUY_SELL_REQUEST); + MessageOut outMsg(CMSG_NPC_BUY_SELL_REQUEST); outMsg.writeLong(mId); outMsg.writeByte(0); } @@ -88,8 +84,7 @@ NPC::buy() void NPC::sell() { - MessageOut outMsg; - outMsg.writeShort(CMSG_NPC_BUY_SELL_REQUEST); + MessageOut outMsg(CMSG_NPC_BUY_SELL_REQUEST); outMsg.writeLong(mId); outMsg.writeByte(1); } -- cgit v1.2.3-70-g09d2 From 391203d83ed7a72b54fb7d7c72dbe35db14f0ea9 Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Mon, 28 Aug 2006 23:04:08 +0000 Subject: Merged trunk development between revisions 2530 and 2618 to the 0.1.0 branch. --- AUTHORS | 2 +- ChangeLog | 171 +++++++++++++++++++++++++++++++++++---- NEWS | 9 ++- README | 1 + configure.ac | 13 +-- data/graphics/Makefile.am | 2 +- data/graphics/images/Makefile.am | 1 + data/help/commands.txt | 1 + debian/control | 2 +- debian/tmw-data.install | 1 + src/Makefile.am | 1 + src/animatedsprite.cpp | 17 ++-- src/animation.cpp | 20 ++++- src/animation.h | 16 +++- src/engine.cpp | 104 +++++++++++++++++------- src/engine.h | 5 ++ src/floor_item.cpp | 5 +- src/floor_item.h | 1 + src/game.cpp | 29 ++++++- src/gui/char_select.cpp | 5 ++ src/gui/char_select.h | 5 ++ src/gui/chat.cpp | 2 +- src/gui/equipmentwindow.cpp | 9 +-- src/gui/equipmentwindow.h | 3 - src/gui/gui.cpp | 10 ++- src/gui/itemcontainer.cpp | 21 +++-- src/gui/itemcontainer.h | 2 - src/gui/ministatus.cpp | 42 ++++++++-- src/gui/ministatus.h | 10 ++- src/gui/setup.cpp | 4 +- src/gui/setup_joystick.cpp | 57 ++++++++++--- src/gui/setup_joystick.h | 6 +- src/gui/setup_video.cpp | 78 +++++++++++++++++- src/gui/setup_video.h | 16 ++++ src/gui/window.cpp | 21 +++++ src/gui/window.h | 20 +++++ src/joystick.cpp | 20 ++--- src/joystick.h | 39 ++++++--- src/main.cpp | 25 +++++- src/map.cpp | 113 +++++++++++++++++++++++++- src/map.h | 30 ++++++- src/net/inventoryhandler.cpp | 9 +++ src/player.cpp | 16 +++- src/player.h | 8 ++ src/resources/iteminfo.cpp | 44 ++++++++++ src/resources/iteminfo.h | 16 ++-- src/resources/itemmanager.cpp | 12 +-- src/resources/mapreader.cpp | 27 +++++++ tmw.cbp | 14 ++++ 49 files changed, 924 insertions(+), 161 deletions(-) create mode 100644 src/resources/iteminfo.cpp (limited to 'src/gui/chat.cpp') diff --git a/AUTHORS b/AUTHORS index 2a0628cf..19d28884 100644 --- a/AUTHORS +++ b/AUTHORS @@ -25,7 +25,7 @@ The Mana World Dev Team Magick (music and sound effects) Neko-mon (player sprites, various things) Neorice (monster sprites, tiles) - Modanung (mohawk) + Modanung (pixel art, concept art) Pajarico (concepts) Rotonen (backstory, art director, music, sound) Talaroc (sprites) diff --git a/ChangeLog b/ChangeLog index fccfe4b8..5f20fdb0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,20 +4,19 @@ * src/net/beinghandler.cpp, src/net/protocol.h: Added support for entering monsters. -2006-08-27 Bjørn Lindeijer +2006-08-28 Philipp Sehmisch - * src/localplayer.cpp, src/gui/sell.cpp, src/gui/trade.cpp, - src/gui/char_select.cpp, src/gui/chat.cpp, src/gui/buy.cpp, - src/engine.cpp, src/beingmanager.cpp, src/npc.cpp, - src/net/messageout.cpp, src/net/messageout.h: Got rid of the default - MessageOut constructor, since all messages should have an ID. - * src/net/protocol.cpp, src/net/protocol.h, src/net/messagein.cpp, - src/net/playerhandler.cpp, src/Makefile.am: Got rid of no longer used - protocol.cpp. - * src/gui/login.cpp, src/gui/register.h, src/gui/login.h, - src/gui/register.cpp: Got rid of server input field since connecting - to the account server now happens before the login and register - dialogs. + * src/gui/setup_video.cpp: Modified the ranges of the ScrollLaziness + and ScrollRadius sliders. + +2006-08-28 Eugenio Favalli + + * data/graphics/items/*: Changed svn properties. + * data/graphics/sprites/item001.xml, data/graphics/sprites/item002.xml, + data/graphics/sprites/item003.xml, data/graphics/sprites/item004.xml, + data/graphics/sprites/item005.xml, data/graphics/sprites/item006.png, + data/graphics/sprites/item006.xml, data/graphics/sprites/Makefile.am: + Added headband and fixed svn properties. 2006-08-27 Guillaume Melquiond @@ -39,6 +38,35 @@ * src/engine.cpp, src/localplayer.cpp, src/gui/gui.cpp, src/being.cpp, src/being.h: Implemented pixel-grained movements. +2006-08-27 Bjørn Lindeijer + + * src/net/inventoryhandler.cpp: Applied patch by AHarrison that adds + item pickup messages to the chat window. + * NEWS: Updated with some recently added and fixed issues. Doesn't + mention any of the recent content updates yet. + * src/localplayer.cpp, src/gui/sell.cpp, src/gui/trade.cpp, + src/gui/char_select.cpp, src/gui/chat.cpp, src/gui/buy.cpp, + src/engine.cpp, src/beingmanager.cpp, src/npc.cpp, + src/net/messageout.cpp, src/net/messageout.h: Got rid of the default + MessageOut constructor, since all messages should have an ID. + * src/net/protocol.cpp, src/net/protocol.h, src/net/messagein.cpp, + src/net/playerhandler.cpp, src/Makefile.am: Got rid of no longer used + protocol.cpp. + * src/gui/login.cpp, src/gui/register.h, src/gui/login.h, + src/gui/register.cpp: Got rid of server input field since connecting + to the account server now happens before the login and register + dialogs. + +2006-08-26 Pascal Ganaye + + * src/joystick.h, src/joystick.cpp, src/gui/setup.cpp, + src/gui/setup_joystick.h, src/gui/setup_video.cpp, + src/gui/setup_joystick.cpp, src/gui/setup_video.h: Added sliders to + the video section of the setup window to configure the laziness and + radius of the scrolling behaviour. Added a checkbox to the joystick + section to allow enabling/disabling the joystick (patch applied by + Bjørn Lindeijer). + 2006-08-26 Bjørn Lindeijer * src/gui/char_select.cpp, src/gui/playerbox.cpp, src/player.cpp, @@ -49,6 +77,15 @@ defined as being bald (so bald is no longer a hardcoded style). * src/player.cpp, src/being.cpp, src/net/charserverhandler.cpp, src/being.h: Fixed player sprite not showing up. + * src/gui/ministatus.cpp, src/gui/ministatus.h: Applied patch by mrha + (Herbi), adding experience bar to the ministatus in the top left. + * configure.ac, data/graphics/items/Makefile.am, + data/graphics/Makefile.am: Added Makefile.am to make sure the item + icons are installed. + * src/player.cpp, src/animation.h, src/player.h, + src/animatedsprite.cpp, src/animation.cpp: Applied patch by Bahamut81 + which implements resetting of Animation, Action and AnimatedSprite. + This fixes the animation synchronization issues. 2006-08-26 Guillaume Melquiond @@ -68,10 +105,91 @@ * src/net/beinghandler.cpp, src/net/beinghandler.h, src/net/protocol.h: Added support for "beings move" messages. +2006-08-25 Matthias Hartmann + + * src/gui/char_select.cpp, src/gui/char_select.h, src/main.cpp: Added + --playername command line option for selecting the character you want + to play with (patch applied by Bjørn Lindeijer). + +2006-08-25 Philipp Sehmisch + + * src/engine.cpp, src/map.h, src/map.cpp: Addded new config variable + "OverlayDetail" to control the number of drawn overlays. + 2 (or more) = all (default), 1 = only the first one, 0 = none. + +2006-08-24 Eugenio Favalli + + * data/help/commands.txt, README, src/game.cpp, src/gui/chat.cpp, + src/gui/window.cpp, src/gui/window.h: Added support for sticky windows + as discussed with doener. Patch by AHarrison. + * data/items.xml: Added jeans shorts. + +2006-08-24 Philipp Sehmisch + + * src/engine.cpp: Scrolling speed no longer affected by framerate. + * src/map.cpp, scr/map.h: Overlay speed no longer affected by + framerate. + * data/maps/new_1-1.tmx.gz, data/graphics/new_7-1.tmx.gz, + data/graphics/images/ambient/sandstorm.png: Redone sandstorm effect + (larger and more transparent image, tripple layer parallax scrolling) + +2006-08-24 Frode Lindeijer + + * data/graphics/sprites/item004.png, + data/graphics/sprites/item005.png, data/graphics/sprites/Makefile.am, + data/graphics/items/armor-legs-cottonshorts, + data/graphics/items/armor-legs-jeanshorts: Added the equip graphics of + the short jeans and the cotton shorts and an inventory icon of the + cotton shorts. Also added all added files to the makefile. + +2006-08-23 Philipp Sehmisch + + * data/maps/new_7-1.tmx.gz: Fixed a minor mapping bug reported on the + forum (no new walkmap required). + * data/maps/new_9-1.tmx.gz: Fixed two minor mapping bugs (new walkmap + required). + +2006-08-22 Bjørn Lindeijer + + * configure.ac, data/graphics/images/ambient, + data/graphics/images/ambient/Makefile.am, + data/graphics/images/Makefile.am: Updated makefiles to account for new + ambient images and changed the version from 0.0.20.1 to 0.0.21. + 2006-08-21 Eugenio Favalli * The Mana World.dev, tmw.cbp: Updated project files. +2006-08-21 Philipp Sehmisch + + * src/mapreader.cpp: Added logic for initialisation of the overlays. + * src/map.cpp, src/map.h: Code for updating and drawing the overlays. + * src/engine.cpp, src/engine.h: Added smooth scrolling and the call + to draw the overlays. + * data/maps/new_1-1.tmx.gz, data/graphics/new_7-1.tmx.gz, + data/graphics/images/ambient/sandstorm.png: Added sandstorm effect + to the desert maps outside of the city (feedback, please). + * data/maps/new_2-1.tmx.gz, data/maps/new_4-1.tmx.gz, + data/maps/new_5-1.tmx.gz, data/graphics/images/ambient/spotlight.png + Added spotlight effect to the cave maps (feedback, please) + * data/graphics/maps/new_9-1.tmx.gz, + data/graphics/images/ambient/clouds.png: + Added cloudshadow effect to the woodland map (feedback, please). + +2006-08-20 Bjørn Lindeijer + + * configure.ac: Moved libpng check before SDL_image check, since the + latter requires the former. + +2006-08-20 Yohann Ferreira + + * data/graphics/sprites/Makefile.am : Following the splitting from + Philipp, moved out the items.png file from the Makefile.am. + * debian/control, debian/tmw-data.install : Updated debian package + creation process. + * src/Makefile.am : Added iteminfo.cpp to avoid an undefined reference + with gcc 4.1.2. Happy to be back :) + 2006-08-20 Bjørn Lindeijer * src/gui/connection.cpp, src/gui/login.cpp, src/gui/gui.cpp, @@ -111,6 +229,22 @@ * src/game.cpp, src/net/network.h, src/net/network.cpp: Removed incoming packets queue. Messages are now processed as they come in. +2006-08-17 Philipp Sehmisch + + * data/graphics/items/*: Splitted the items.png into separate images + with more distinctive names. (no, i won't list all 114) + * src/itemmanager.cpp, data/items.xml: Replaced indices on the item + spriteset with filenames. added names and descriptions for all missing + items. Changed names and dascriptions of some items. + * src/engine.cpp: removed global item spriteset. + * src/floor_item.cpp, src/floor_item.h, src/iteminfo.cpp, + src/iteminfo.h, src/equipmentwindow.cpp, src/equipmentwindow.h, + src/itemcontainer.cpp, src/itemcontainer.h: the iteminfo class now + provides a pointer to the item icon image instead of providing the + index on the item spriteset. + * data/graphics/tiles/trans_desert-woodland.png: added transmission + tileset between desert and woodland. + 2006-08-15 Bjørn Lindeijer * src/gui/char_select.cpp, src/net/charserverhandler.h, @@ -143,6 +277,15 @@ * src/player.cpp: Verify the gender to prevent crashing when something is wrong with the communication. +2006-08-13 Eugenio Favalli + + * data/graphics/sprites/Makefile.am, + data/graphics/sprites/monster18.png, + data/graphics/sprites/monster18.xml, + data/graphics/sprites/npcs.png: Added new monster and npcs. + * src/gui.cpp, tmw.cbp, The Mana World.dev: Fixed Guichan 0.5.0 + compilation issues. + 2006-08-13 Bjørn Lindeijer * src/openglgraphics.cpp, src/gui/browserbox.h, src/gui/gui.cpp, @@ -672,7 +815,7 @@ * data/items.xml, src/being.cpp, src/being.h src/net/beinghandler.cpp, src/player.cpp: Clients get notified of equipping visible items. * src/net/beinghandler.cpp: GCC 4 fix. - + 2006-06-28 Philipp Sehmisch * src/animation.cpp, src/animation.h: Parser now works like described diff --git a/NEWS b/NEWS index ad78fc4f..cf837a25 100644 --- a/NEWS +++ b/NEWS @@ -1,5 +1,12 @@ -0.0.20.1 (25 July 2006) +0.0.21 (.. September 2006) +- Added item pickup messages to the chat dialog +- Added XP bar to ministatus in the top left +- Added configurable smooth and lazy scrolling +- Added option to turn off the joystick +- Added --playername command line option for automatic character picking - Fixed updating system on Windows +- Fixed player animations going out of sync on changing equipment or hairstyle +- Fixed SDL_image configure check on some systems by first checking for libpng 0.0.20 (24 July 2006) - Added new hairstyle, and some fixes to the old ones diff --git a/README b/README index 8fdd2b72..5fad4312 100644 --- a/README +++ b/README @@ -53,6 +53,7 @@ Use arrow keys to move around. Other keys: - Alt + S sit down / stand up - Alt + F toggle debug pathfinding feature - Alt + P take screenshot +- H hide all non-sticky windows - G or Z pick up item - Enter focus chat window / send message - Shift hold it when attacking to lock target for auto attack diff --git a/configure.ac b/configure.ac index 4c5a492a..ce4c6cc5 100755 --- a/configure.ac +++ b/configure.ac @@ -70,8 +70,12 @@ AC_MSG_ERROR([ *** Unable to find libxml2 library (http://xmlsoft.org/)])) AC_CHECK_HEADERS([libxml/xmlreader.h], , AC_MSG_ERROR([ *** libxml2 library found but cannot find headers (http://xmlsoft.org/)])) -AC_CHECK_LIB([SDL_image], [IMG_LoadPNG_RW], , -AC_MSG_ERROR([ *** Unable to find SDL_image library with PNG support (http://www.libsdl.org/projects/SDL_image/)])) +AC_CHECK_LIB(png, png_write_info, , +AC_MSG_ERROR([ *** Unable to find png library])) + +AC_CHECK_LIB(SDL_image, IMG_LoadPNG_RW, , +AC_MSG_ERROR([ *** Unable to find SDL_image library with PNG support +(http://www.libsdl.org/projects/SDL_image/)])) AC_CHECK_LIB([guichan_sdl], [gcnSDL], , AC_MSG_ERROR([ *** Unable to find Guichan SDL library (http://guichan.sf.net/)])) @@ -82,9 +86,6 @@ AC_MSG_ERROR([ *** Unable to find SDL_mixer library (http://www.libsdl.org/proje AC_CHECK_LIB([enet], [enet_initialize], , AC_MSG_ERROR([ *** Unable to find enet library (http://enet.bespin.org/)])) -AC_CHECK_LIB(png, png_write_info, , -AC_MSG_ERROR([ *** Unable to find png library (http://www.libpng.org/)])) - # Checks for header files. AC_HEADER_STDC AC_CHECK_HEADERS([arpa/inet.h fcntl.h malloc.h netdb.h netinet/in.h stdlib.h string.h sys/socket.h unistd.h]) @@ -108,6 +109,8 @@ data/Makefile data/graphics/Makefile data/graphics/gui/Makefile data/graphics/images/Makefile +data/graphics/images/ambient/Makefile +data/graphics/items/Makefile data/graphics/sprites/Makefile data/graphics/tiles/Makefile data/help/Makefile diff --git a/data/graphics/Makefile.am b/data/graphics/Makefile.am index 43354894..19e95869 100644 --- a/data/graphics/Makefile.am +++ b/data/graphics/Makefile.am @@ -1,2 +1,2 @@ -SUBDIRS = gui images sprites tiles +SUBDIRS = gui images items sprites tiles diff --git a/data/graphics/images/Makefile.am b/data/graphics/images/Makefile.am index 8fbe3694..e0707698 100644 --- a/data/graphics/images/Makefile.am +++ b/data/graphics/images/Makefile.am @@ -1,3 +1,4 @@ +SUBDIRS = ambient imagesdir = $(pkgdatadir)/data/graphics/images diff --git a/data/help/commands.txt b/data/help/commands.txt index dbb37195..37c77df2 100644 --- a/data/help/commands.txt +++ b/data/help/commands.txt @@ -23,6 +23,7 @@ ##2Alt + S##P sit down / stand up ##2Alt + F##P toggle debug pathfinding feature ##2Alt + P##P take screenshot + ##2H##P hide all non-sticky windows ##2G or Z##P pick up item ##2Enter##P focus chat window / send message ##2Shift##P hold it when attacking to lock target for auto diff --git a/debian/control b/debian/control index ad079b7d..45a906b6 100644 --- a/debian/control +++ b/debian/control @@ -1,7 +1,7 @@ Source: tmw Priority: optional Maintainer: FERREIRA Yohann -Build-Depends: debhelper (>= 4.0.0), autotools-dev, docbook-to-man, libsdl1.2-dev (>= 1.2.7), libsdl-image1.2-dev (>= 1.2.3), libsdl-mixer1.2-dev (>= 1.2.5), libguichan0-dev (>= 0.4.0-4), libcurl3-gnutls-dev (>= 7.15.0-1), libxml2-dev (>= 2.4.19), libphysfs-dev (>= 1.0.0-1), libgl1-mesa-dev (>= 6.4.1), libpng12-dev (>= 1.2.5), libsdl-net1.2-dev (>= 1.2.5) +Build-Depends: debhelper (>= 4.0.0), autotools-dev, docbook-to-man, libsdl1.2-dev (>= 1.2.7), libsdl-image1.2-dev (>= 1.2.3), libsdl-mixer1.2-dev (>= 1.2.5), libguichan0-dev (>= 0.5.0-1), libcurl3-gnutls-dev (>= 7.15.0-1), libxml2-dev (>= 2.4.19), libphysfs-dev (>= 1.0.0-1), libgl1-mesa-dev (>= 6.4.1), libpng12-dev (>= 1.2.5), libsdl-net1.2-dev (>= 1.2.5) Standards-Version: 3.6.2 Package: tmw diff --git a/debian/tmw-data.install b/debian/tmw-data.install index 5e2e537e..71b34a98 100644 --- a/debian/tmw-data.install +++ b/debian/tmw-data.install @@ -2,6 +2,7 @@ data/items.xml usr/share/games/tmw/data data/help/*.txt usr/share/games/tmw/data/help data/graphics/gui/*.png usr/share/games/tmw/data/graphics/gui data/graphics/sprites/*.png usr/share/games/tmw/data/graphics/sprites +data/graphics/sprites/*.xml usr/share/games/tmw/data/graphics/sprites data/graphics/images/*.png usr/share/games/tmw/data/graphics/images data/graphics/tiles/*.png usr/share/games/tmw/data/graphics/tiles data/maps/*.tmx.gz usr/share/games/tmw/data/maps diff --git a/src/Makefile.am b/src/Makefile.am index aac3a8d3..1e8a1424 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -158,6 +158,7 @@ tmw_SOURCES = graphic/imagerect.h \ resources/imagewriter.cpp \ resources/imagewriter.h \ resources/iteminfo.h \ + resources/iteminfo.cpp \ resources/itemmanager.cpp \ resources/itemmanager.h \ resources/mapreader.cpp \ diff --git a/src/animatedsprite.cpp b/src/animatedsprite.cpp index 8f9c0600..f984d13f 100644 --- a/src/animatedsprite.cpp +++ b/src/animatedsprite.cpp @@ -49,12 +49,14 @@ AnimatedSprite::AnimatedSprite(const std::string& animationFile, int variant): free(data); if (!doc) { - logger->error("Animation: Error while parsing animation definition file!"); + logger->error( + "Animation: Error while parsing animation definition file!"); } xmlNodePtr node = xmlDocGetRootElement(doc); if (!node || !xmlStrEqual(node->name, BAD_CAST "sprite")) { - logger->error("Animation: this is not a valid animation definition file!"); + logger->error( + "Animation: this is not a valid animation definition file!"); } // Get the variant @@ -233,13 +235,14 @@ AnimatedSprite::~AnimatedSprite() void AnimatedSprite::reset() { - // Reset all defined actions (because of aliases, some will be resetted - // multiple times) + // Reset all defined actions (because of aliases some will be resetted + // multiple times, but this doesn't matter) for (ActionIterator i = mActions.begin(); i != mActions.end(); ++i) { - //TODO: If resetting everything is really a nice way of fixing the - // synchronization issues, finish implementing this. - //i->second->reset(); + if (i->second) + { + i->second->reset(); + } } } diff --git a/src/animation.cpp b/src/animation.cpp index 1213d0d6..c1b27ebd 100644 --- a/src/animation.cpp +++ b/src/animation.cpp @@ -27,9 +27,15 @@ #include "utils/dtor.h" -Animation::Animation(): - mTime(0) +Animation::Animation() { + reset(); +} + +void +Animation::reset() +{ + mTime = 0; iCurrentPhase = mAnimationPhases.begin(); } @@ -123,3 +129,13 @@ Action::setAnimation(int direction, Animation *animation) mAnimations[direction] = animation; } + +void +Action::reset() +{ + for (AnimationIterator i = mAnimations.begin(); + i != mAnimations.end(); ++i) + { + i->second->reset(); + } +} diff --git a/src/animation.h b/src/animation.h index c5b277b7..60dcd287 100644 --- a/src/animation.h +++ b/src/animation.h @@ -55,6 +55,12 @@ class Animation */ Animation(); + /** + * Restarts the animation from the first frame. + */ + void + reset(); + void addPhase(int image, unsigned int delay, int offsetX, int offsetY); @@ -68,13 +74,13 @@ class Animation * Returns the x offset of the current frame. */ int - getOffsetX() const { return (*iCurrentPhase).offsetX; }; + getOffsetX() const { return iCurrentPhase->offsetX; }; /** * Returns the y offset of the current frame. */ int - getOffsetY() const { return (*iCurrentPhase).offsetY; }; + getOffsetY() const { return iCurrentPhase->offsetY; }; /** * Returns the length of this animation. @@ -119,6 +125,12 @@ class Action void setAnimation(int direction, Animation *animation); + /** + * Resets all animations associated with this action. + */ + void + reset(); + Animation* getAnimation(int direction) const; diff --git a/src/engine.cpp b/src/engine.cpp index eda154f3..28410748 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -27,6 +27,7 @@ #include "being.h" #include "beingmanager.h" +#include "configuration.h" #include "flooritemmanager.h" #include "game.h" #include "graphics.h" @@ -54,7 +55,6 @@ int camera_x, camera_y; ItemManager *itemDb; /**< Item database object */ -Spriteset *itemset; Spriteset *emotionset; Spriteset *npcset; std::vector weaponset; @@ -79,11 +79,9 @@ Engine::Engine(): weaponset.push_back(tmp); } } - itemset = resman->getSpriteset("graphics/sprites/items.png", 32, 32); if (!npcset) logger->error("Unable to load NPC spriteset!"); if (!emotionset) logger->error("Unable to load emotions spriteset!"); - if (!itemset) logger->error("Unable to load item spriteset!"); // Initialize item manager itemDb = new ItemManager(); @@ -94,7 +92,6 @@ Engine::~Engine() // Delete sprite sets npcset->decRef(); emotionset->decRef(); - itemset->decRef(); std::for_each(weaponset.begin(), weaponset.end(), std::mem_fun(&Spriteset::decRef)); @@ -157,34 +154,85 @@ void Engine::draw(Graphics *graphics) { int midTileX = graphics->getWidth() / 2; int midTileY = graphics->getHeight() / 2; + static int lastTick = tick_time; - int map_x = (player_node->mX - midTileX) + player_node->getXOffset(); - int map_y = (player_node->mY - midTileY) + player_node->getYOffset(); + // Avoid freaking out when tick_time overflows + if (tick_time < lastTick) + { + lastTick = tick_time; + } + + int player_x = player_node->mX - midTileX + player_node->getXOffset(); + int player_y = player_node->mY - midTileY + player_node->getYOffset(); + + scrollLaziness = (int)config.getValue("ScrollLaziness", 32); + scrollRadius = (int)config.getValue("ScrollRadius", 32); + + if (scrollLaziness < 1) + scrollLaziness = 1; //avoids division by zero + + //apply lazy scrolling + while (lastTick < tick_time) + { + if (player_x > view_x + scrollRadius) + { + view_x += (player_x - view_x - scrollRadius) / scrollLaziness; + } + if (player_x < view_x - scrollRadius) + { + view_x += (player_x - view_x + scrollRadius) / scrollLaziness; + } + if (player_y > view_y + scrollRadius) + { + view_y += (player_y - view_y - scrollRadius) / scrollLaziness; + } + if (player_y < view_y - scrollRadius) + { + view_y += (player_y - view_y + scrollRadius) / scrollLaziness; + } + lastTick++; + } + + //auto center when player is off screen + if ( player_x - view_x > graphics->getWidth() / 2 + || view_x - player_x > graphics->getWidth() / 2 + || view_y - player_y > graphics->getHeight() / 2 + || player_y - view_y > graphics->getHeight() / 2 + ) + { + view_x = player_x; + view_y = player_y; + }; if (mCurrentMap) { - if (map_x < 0) { - map_x = 0; + if (view_x < 0) { + view_x = 0; } - if (map_y < 0) { - map_y = 0; + if (view_y < 0) { + view_y = 0; } - if (map_x > mCurrentMap->getWidth() * 32 - midTileX) { - map_x = mCurrentMap->getWidth() * 32 - midTileX; + if (view_x > mCurrentMap->getWidth() * 32 - midTileX) { + view_x = mCurrentMap->getWidth() * 32 - midTileX; } - if (map_y > mCurrentMap->getHeight() * 32 - midTileY) { - map_y = mCurrentMap->getHeight() * 32 - midTileY; + if (view_y > mCurrentMap->getHeight() * 32 - midTileY) { + view_y = mCurrentMap->getHeight() * 32 - midTileY; } } - camera_x = map_x; - camera_y = map_y; + camera_x = (int)(view_x + 16); + camera_y = (int)(view_y + 16); // Draw tiles and sprites if (mCurrentMap != NULL) { - mCurrentMap->draw(graphics, map_x, map_y, 0); - mCurrentMap->draw(graphics, map_x, map_y, 1); - mCurrentMap->draw(graphics, map_x, map_y, 2); + mCurrentMap->draw(graphics, (int)view_x, (int)view_y, 0); + mCurrentMap->draw(graphics, (int)view_x, (int)view_y, 1); + mCurrentMap->draw(graphics, (int)view_x, (int)view_y, 2); + mCurrentMap->drawOverlay( graphics, + view_x, + view_y, + (int)config.getValue("OverlayDetail", 2) + ); } else { @@ -202,8 +250,8 @@ void Engine::draw(Graphics *graphics) int mouseX, mouseY; SDL_GetMouseState(&mouseX, &mouseY); - int mouseTileX = (mouseX + map_x) / 32; - int mouseTileY = (mouseY + map_y) / 32; + int mouseTileX = (int)(mouseX + view_x) / 32; + int mouseTileY = (int)(mouseY + view_y) / 32; Path debugPath = mCurrentMap->findPath( player_node->mX / 32, player_node->mY / 32, @@ -212,8 +260,8 @@ void Engine::draw(Graphics *graphics) graphics->setColor(gcn::Color(255, 0, 0)); for (PathIterator i = debugPath.begin(); i != debugPath.end(); i++) { - int squareX = i->x * 32 - map_x + 12; - int squareY = i->y * 32 - map_y + 12; + int squareX = i->x * 32 - int(view_x) + 12; + int squareY = i->y * 32 - int(view_y) + 12; graphics->fillRectangle(gcn::Rectangle(squareX, squareY, 8, 8)); graphics->drawText( @@ -226,9 +274,9 @@ void Engine::draw(Graphics *graphics) Beings *beings = beingManager->getAll(); for (BeingIterator i = beings->begin(); i != beings->end(); i++) { - (*i)->drawSpeech(graphics, -map_x, -map_y); - (*i)->drawName(graphics, -map_x, -map_y); - (*i)->drawEmotion(graphics, -map_x, -map_y); + (*i)->drawSpeech(graphics, -(int)view_x, -(int)view_y); + (*i)->drawName(graphics, -(int)view_x, -(int)view_y); + (*i)->drawEmotion(graphics, -(int)view_x, -(int)view_y); } // Draw target marker if needed @@ -239,8 +287,8 @@ void Engine::draw(Graphics *graphics) graphics->setColor(gcn::Color(255, 255, 255)); int dy = (target->getType() == Being::PLAYER) ? 90 : 52; - graphics->drawText("[TARGET]", target->getPixelX() - map_x + 15, - target->getPixelY() - map_y - dy, gcn::Graphics::CENTER); + graphics->drawText("[TARGET]", target->getPixelX() - (int)view_x + 15, + target->getPixelY() - (int)view_y - dy, gcn::Graphics::CENTER); } gui->draw(); diff --git a/src/engine.h b/src/engine.h index bdf8419a..e8ef7e33 100644 --- a/src/engine.h +++ b/src/engine.h @@ -76,6 +76,11 @@ class Engine bool mShowDebugPath; Map *mCurrentMap; + + int scrollRadius; + int scrollLaziness; + float view_x; // current viewpoint in pixels + float view_y; // current viewpoint in pixels }; extern Engine *engine; diff --git a/src/floor_item.cpp b/src/floor_item.cpp index 1581b201..edd5d4a7 100644 --- a/src/floor_item.cpp +++ b/src/floor_item.cpp @@ -29,7 +29,6 @@ #include "resources/iteminfo.h" #include "resources/spriteset.h" -extern Spriteset *itemset; FloorItem::FloorItem(unsigned int id, unsigned int itemId, @@ -42,8 +41,8 @@ FloorItem::FloorItem(unsigned int id, mY(y), mMap(map) { - // Retrieve item image using a global itemset and itemDb (alternative?) - mImage = itemset->get(itemDb->getItemInfo(itemId)->getImage() - 1); + // Retrieve item image from item info + mImage = itemDb->getItemInfo(itemId)->getImage(); // Add ourselves to the map mSpriteIterator = mMap->addSprite(this); diff --git a/src/floor_item.h b/src/floor_item.h index 24eb495d..386d0759 100644 --- a/src/floor_item.h +++ b/src/floor_item.h @@ -27,6 +27,7 @@ #include "graphics.h" #include "map.h" #include "sprite.h" +#include "resources/image.h" /** * An item lying on the floor. diff --git a/src/game.cpp b/src/game.cpp index 3e789728..f5ebe095 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -202,6 +202,10 @@ void createGuiWindows() minimap->getHeight() + 30);*/ // Set initial window visibility + chatWindow->setSticky(true); + miniStatusWindow->setSticky(true); + menuWindow->setSticky(true); + chatWindow->setVisible(true); miniStatusWindow->setVisible(true); statusWindow->setVisible(false); @@ -457,7 +461,30 @@ void Game::handleInput() } break; - // Picking up items on the floor + // Attempt to hide all windows + case SDLK_h: + chatWindow->setVisible(false); + miniStatusWindow->setVisible(false); + statusWindow->setVisible(false); + menuWindow->setVisible(false); + buyDialog->setVisible(false); + sellDialog->setVisible(false); + buySellDialog->setVisible(false); + inventoryWindow->setVisible(false); + npcTextDialog->setVisible(false); + npcListDialog->setVisible(false); + skillDialog->setVisible(false); + //newSkillWindow->setVisible(false); + setupWindow->setVisible(false); + equipmentWindow->setVisible(false); + chargeDialog->setVisible(false); + tradeWindow->setVisible(false); + //buddyWindow->setVisible(false); + helpWindow->setVisible(false); + debugWindow->setVisible(false); + break; + + // Picking up items on the floor case SDLK_g: case SDLK_z: if (!chatWindow->isFocused()) diff --git a/src/gui/char_select.cpp b/src/gui/char_select.cpp index adcbe290..042a5be8 100644 --- a/src/gui/char_select.cpp +++ b/src/gui/char_select.cpp @@ -224,6 +224,11 @@ void CharSelectDialog::logic() updatePlayerInfo(); } +std::string CharSelectDialog::getName() +{ + return mNameLabel->getCaption(); +} + CharCreateDialog::CharCreateDialog(Window *parent, int slot): Window("Create Character", true, parent), mSlot(slot) { diff --git a/src/gui/char_select.h b/src/gui/char_select.h index 73fc8b2d..06881bb5 100644 --- a/src/gui/char_select.h +++ b/src/gui/char_select.h @@ -54,6 +54,11 @@ class CharSelectDialog : public Window, public gcn::ActionListener void logic(); + /** + * Returns name of selected player + */ + std::string getName(); + private: LockedArray *mCharInfo; diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp index 9098f9f0..9a5d60b0 100644 --- a/src/gui/chat.cpp +++ b/src/gui/chat.cpp @@ -395,7 +395,7 @@ ChatWindow::setInputText(std::string input_str) void ChatWindow::setVisible(bool isVisible) { - Widget::setVisible(isVisible); + Window::setVisible(isVisible); /* * For whatever reason, if setVisible is called, the mTmpVisible effect diff --git a/src/gui/equipmentwindow.cpp b/src/gui/equipmentwindow.cpp index bef39dff..2cbffde4 100644 --- a/src/gui/equipmentwindow.cpp +++ b/src/gui/equipmentwindow.cpp @@ -40,15 +40,10 @@ EquipmentWindow::EquipmentWindow(Equipment *equipment): setWindowName("Equipment"); setDefaultSize(5, 230, 200, 120); loadWindowState(); - - mItemset = ResourceManager::getInstance()->getSpriteset( - "graphics/sprites/items.png", 32, 32); - if (!mItemset) logger->error("Unable to load items.png"); } EquipmentWindow::~EquipmentWindow() { - mItemset->decRef(); } void EquipmentWindow::draw(gcn::Graphics *graphics) @@ -70,7 +65,7 @@ void EquipmentWindow::draw(gcn::Graphics *graphics) continue; } - image = mItemset->get(item->getInfo()->getImage() - 1); + image = item->getInfo()->getImage(); dynamic_cast(graphics)->drawImage( image, 36 * (i % 4) + 10, 36 * (i / 4) + 25); } @@ -81,7 +76,7 @@ void EquipmentWindow::draw(gcn::Graphics *graphics) return; } - image = mItemset->get(item->getInfo()->getImage() - 1); + image = item->getInfo()->getImage(); dynamic_cast(graphics)->drawImage(image, 160, 25); graphics->drawText(toString(item->getQuantity()), 170, 62, diff --git a/src/gui/equipmentwindow.h b/src/gui/equipmentwindow.h index aeaae58c..99a3cc60 100644 --- a/src/gui/equipmentwindow.h +++ b/src/gui/equipmentwindow.h @@ -27,7 +27,6 @@ #include "window.h" class Equipment; -class Spriteset; /** * Equipment dialog. @@ -53,8 +52,6 @@ class EquipmentWindow : public Window void draw(gcn::Graphics *graphics); private: - Spriteset *mItemset; - Equipment *mEquipment; }; diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index 69563dc1..b27868e3 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -27,11 +27,13 @@ #include #include - -// Moved up because of nested inclusion of winnt.h which defines DELETE -// constant as well as guichan does +// Should stay here because of Guichan being sensitive to headers order #include +#ifdef USE_OPENGL +#include "../resources/openglsdlimageloader.h" +#endif + #include "focushandler.h" #include "popupmenu.h" #include "window.h" @@ -231,6 +233,7 @@ Gui::draw() void Gui::mousePress(int mx, int my, int button) { + printf("Gui::mousePress(%d,%d)\n", mx, my); // Mouse pressed on window container (basically, the map) // Are we in-game yet? @@ -247,6 +250,7 @@ Gui::mousePress(int mx, int my, int button) int tilex = (mx + camera_x) / 32; int tiley = (my + camera_y) / 32; + printf("tilex,tiley: %d,%d\n", tilex, tiley); // Right click might open a popup if (button == gcn::MouseInput::RIGHT) diff --git a/src/gui/itemcontainer.cpp b/src/gui/itemcontainer.cpp index edcf9764..c7c55fd9 100644 --- a/src/gui/itemcontainer.cpp +++ b/src/gui/itemcontainer.cpp @@ -41,8 +41,6 @@ ItemContainer::ItemContainer(Inventory *inventory): mInventory(inventory) { ResourceManager *resman = ResourceManager::getInstance(); - mItemset = resman->getSpriteset("graphics/sprites/items.png", 32, 32); - if (!mItemset) logger->error("Unable to load items.png"); mSelImg = resman->getImage("graphics/gui/selection.png"); if (!mSelImg) logger->error("Unable to load selection.png"); @@ -55,7 +53,6 @@ ItemContainer::ItemContainer(Inventory *inventory): ItemContainer::~ItemContainer() { - mItemset->decRef(); mSelImg->decRef(); } @@ -73,8 +70,8 @@ void ItemContainer::logic() void ItemContainer::draw(gcn::Graphics* graphics) { - int gridWidth = mItemset->get(0)->getWidth() + 4; - int gridHeight = mItemset->get(0)->getHeight() + 10; + int gridWidth = 36; //(item icon width + 4) + int gridHeight = 42; //(item icon height + 10) int columns = getWidth() / gridWidth; // Have at least 1 column @@ -113,11 +110,11 @@ void ItemContainer::draw(gcn::Graphics* graphics) } // Draw item icon - int idx; - if ((idx = item->getInfo()->getImage()) > 0) + Image* image; + if ((image = item->getInfo()->getImage()) != NULL) { dynamic_cast(graphics)->drawImage( - mItemset->get(idx - 1), itemX, itemY); + image, itemX, itemY); } // Draw item caption @@ -133,8 +130,8 @@ void ItemContainer::setWidth(int width) { gcn::Widget::setWidth(width); - int gridWidth = mItemset->get(0)->getWidth() + 4; - int gridHeight = mItemset->get(0)->getHeight() + 14; + int gridWidth = 36; //item icon width + 4 + int gridHeight = 46; //item icon height + 14 int columns = getWidth() / gridWidth; if (columns < 1) @@ -158,8 +155,8 @@ void ItemContainer::selectNone() void ItemContainer::mousePress(int mx, int my, int button) { - int gridWidth = mItemset->get(0)->getWidth() + 4; - int gridHeight = mItemset->get(0)->getHeight() + 10; + int gridWidth = 36; //(item icon width + 4) + int gridHeight = 42; //(item icon height + 10) int columns = getWidth() / gridWidth; if (button == gcn::MouseInput::LEFT || gcn::MouseInput::RIGHT) diff --git a/src/gui/itemcontainer.h b/src/gui/itemcontainer.h index 63e8bf47..f52f37ec 100644 --- a/src/gui/itemcontainer.h +++ b/src/gui/itemcontainer.h @@ -30,7 +30,6 @@ class Image; class Inventory; class Item; -class Spriteset; /** * An item container. Used to show items in inventory and trade dialog. @@ -83,7 +82,6 @@ class ItemContainer : public gcn::Widget, public gcn::MouseListener private: Inventory *mInventory; - Spriteset *mItemset; Image *mSelImg; Item *mSelectedItem; diff --git a/src/gui/ministatus.cpp b/src/gui/ministatus.cpp index 53849550..932b1f22 100644 --- a/src/gui/ministatus.cpp +++ b/src/gui/ministatus.cpp @@ -29,6 +29,8 @@ #include "progressbar.h" #include "../localplayer.h" +#include "../configuration.h" +#include "../graphics.h" #include "../utils/tostring.h" @@ -42,31 +44,40 @@ MiniStatusWindow::MiniStatusWindow(): mHpBar = new ProgressBar(1.0f, 100, 20, 0, 171, 34); mMpBar = new ProgressBar(1.0f, 100, 20, 26, 102, 230); + mXpBar = new ProgressBar(1.0f, 100, 20, 143, 192, 211); mHpLabel = new gcn::Label(""); mMpLabel = new gcn::Label(""); + mXpLabel = new gcn::Label(""); mHpBar->setPosition(0, 3); mMpBar->setPosition(mHpBar->getWidth() + 3, 3); + mXpBar->setPosition(mMpBar->getX() + mMpBar->getWidth() + 3, 3); mHpLabel->setDimension(mHpBar->getDimension()); mMpLabel->setDimension(mMpBar->getDimension()); + mXpLabel->setDimension(mXpBar->getDimension()); mHpLabel->setForegroundColor(gcn::Color(255, 255, 255)); mMpLabel->setForegroundColor(gcn::Color(255, 255, 255)); + mXpLabel->setForegroundColor(gcn::Color(255, 255, 255)); mHpLabel->setFont(speechFont); mMpLabel->setFont(speechFont); + mXpLabel->setFont(speechFont); mHpLabel->setAlignment(gcn::Graphics::CENTER); mMpLabel->setAlignment(gcn::Graphics::CENTER); + mXpLabel->setAlignment(gcn::Graphics::CENTER); add(mHpBar); add(mMpBar); + add(mXpBar); add(mHpLabel); add(mMpLabel); + add(mXpLabel); - setDefaultSize(0, 0, mMpBar->getX() + mMpBar->getWidth(), - mMpBar->getY() + mMpBar->getHeight()); + setDefaultSize(0, 0, mXpBar->getX() + mXpBar->getWidth(), + mXpBar->getY() + mXpBar->getHeight()); } void MiniStatusWindow::update() @@ -85,12 +96,33 @@ void MiniStatusWindow::update() mHpBar->setColor(0, 171, 34); // Green } - mHpBar->setProgress((float)player_node->mHp / (float)player_node->mMaxHp); - // mpBar->setProgress((float)player_node->mp / (float)player_node->maxMp); + mHpBar->setProgress((float) player_node->mHp / player_node->mMaxHp); + // mMpBar->setProgress((float) player_node->mMp / player_node->mMaxMp); + mXpBar->setProgress((float) player_node->mXp / player_node->mXpForNextLevel); - // Update and center labels + // Update labels mHpLabel->setCaption(toString(player_node->mHp)); mMpLabel->setCaption(toString(player_node->mMp)); + + std::stringstream updatedText; + updatedText << (int) ( + (float) player_node->mXp / + player_node->mXpForNextLevel * 100) << "%"; + + // Displays the number of monsters to next lvl + // (disabled for now but interesting idea) + /* + if(config.getValue("xpBarMonsterCounterExp", 0)!=0) + { + updatedText << " | " + << (int)(((float)player_node->mXpForNextLevel - (float)player_node->mXp) + / (float)config.getValue("xpBarMonsterCounterExp", 0)) + << " " + << config.getValue("xpBarMonsterCounterName", "Monsters") <<" left..."; + } + */ + + mXpLabel->setCaption(updatedText.str()); } void MiniStatusWindow::draw(gcn::Graphics *graphics) diff --git a/src/gui/ministatus.h b/src/gui/ministatus.h index f56f847c..718fe140 100644 --- a/src/gui/ministatus.h +++ b/src/gui/ministatus.h @@ -56,11 +56,15 @@ class MiniStatusWindow : public Window */ void update(); - /** + /* * Mini Status Bars */ - ProgressBar *mHpBar, *mMpBar; - gcn::Label *mHpLabel, *mMpLabel; + ProgressBar *mHpBar; + ProgressBar *mMpBar; + ProgressBar *mXpBar; + gcn::Label *mHpLabel; + gcn::Label *mMpLabel; + gcn::Label *mXpLabel; }; #endif diff --git a/src/gui/setup.cpp b/src/gui/setup.cpp index 6af9119b..d12ace75 100644 --- a/src/gui/setup.cpp +++ b/src/gui/setup.cpp @@ -43,7 +43,7 @@ Setup::Setup(): Window("Setup") { int width = 230; - int height = 185; + int height = 225; setContentSize(width, height); const char *buttonNames[] = { @@ -58,7 +58,7 @@ Setup::Setup(): } TabbedContainer *panel = new TabbedContainer(); - panel->setDimension(gcn::Rectangle(5, 5, 220, 150)); + panel->setDimension(gcn::Rectangle(5, 5, 220, 185)); panel->setOpaque(false); SetupTab *tab; diff --git a/src/gui/setup_joystick.cpp b/src/gui/setup_joystick.cpp index 36b0ee20..d9212728 100644 --- a/src/gui/setup_joystick.cpp +++ b/src/gui/setup_joystick.cpp @@ -26,22 +26,31 @@ #include #include "button.h" - +#include "checkbox.h" +#include "../configuration.h" #include "../joystick.h" extern Joystick *joystick; Setup_Joystick::Setup_Joystick(): mCalibrateLabel(new gcn::Label("Press the button to start calibration")), - mCalibrateButton(new Button("Calibrate", "calibrate", this)) + mCalibrateButton(new Button("Calibrate", "calibrate", this)), + mJoystickEnabled(new CheckBox("Enable joystick")) { setOpaque(false); + mJoystickEnabled->setPosition(10, 10); + mCalibrateLabel->setPosition(10, 25); + mCalibrateButton->setPosition(10, 30 + mCalibrateLabel->getHeight()); + + mOriginalJoystickEnabled = (joystick ? joystick->isEnabled() : false); + mJoystickEnabled->setMarked(mOriginalJoystickEnabled); - mCalibrateLabel->setPosition(5, 10); - mCalibrateButton->setPosition(10, 20 + mCalibrateLabel->getHeight()); + mJoystickEnabled->setEventId("joystickEnabled"); + mJoystickEnabled->addActionListener(this); add(mCalibrateLabel); add(mCalibrateButton); + add(mJoystickEnabled); } void Setup_Joystick::action(const std::string &event, gcn::Widget *widget) @@ -50,13 +59,37 @@ void Setup_Joystick::action(const std::string &event, gcn::Widget *widget) return; } - if (joystick->isCalibrating()) { - mCalibrateButton->setCaption("Calibrate"); - mCalibrateLabel->setCaption("Press the button to start calibration"); - joystick->finishCalibration(); - } else { - mCalibrateButton->setCaption("Stop"); - mCalibrateLabel->setCaption("Rotate the stick"); - joystick->startCalibration(); + if (event == "joystickEnabled") + { + joystick->setEnabled(mJoystickEnabled->isMarked()); + } + else + { + if (joystick->isCalibrating()) { + mCalibrateButton->setCaption("Calibrate"); + mCalibrateLabel->setCaption( + "Press the button to start calibration"); + joystick->finishCalibration(); + } else { + mCalibrateButton->setCaption("Stop"); + mCalibrateLabel->setCaption("Rotate the stick"); + joystick->startCalibration(); + } } } + +void Setup_Joystick::cancel() +{ + if (joystick) + { + joystick->setEnabled(mOriginalJoystickEnabled); + } + mJoystickEnabled->setMarked(mOriginalJoystickEnabled); +} + +void Setup_Joystick::apply() +{ + config.setValue("joystickEnabled", + joystick ? joystick->isEnabled() : false); +} + diff --git a/src/gui/setup_joystick.h b/src/gui/setup_joystick.h index da773c8f..4cc2b3d9 100644 --- a/src/gui/setup_joystick.h +++ b/src/gui/setup_joystick.h @@ -35,14 +35,16 @@ class Setup_Joystick : public SetupTab, public gcn::ActionListener public: Setup_Joystick(); - void apply() {} - void cancel() {} + void apply(); + void cancel(); void action(const std::string& eventId, gcn::Widget* widget); private: gcn::Label *mCalibrateLabel; gcn::Button *mCalibrateButton; + bool mOriginalJoystickEnabled; + gcn::CheckBox *mJoystickEnabled; }; #endif diff --git a/src/gui/setup_video.cpp b/src/gui/setup_video.cpp index 7ac226d3..7c72975a 100644 --- a/src/gui/setup_video.cpp +++ b/src/gui/setup_video.cpp @@ -115,7 +115,13 @@ Setup_Video::Setup_Video(): mAlphaSlider(new Slider(0.2, 1.0)), mFpsCheckBox(new CheckBox("FPS Limit: ")), mFpsSlider(new Slider(10, 200)), - mFpsField(new TextField()) + mFpsField(new TextField()), + mOriginalScrollLaziness((int) config.getValue("ScrollLaziness", 32)), + mScrollLazinessSlider(new Slider(1, 64)), + mScrollLazinessField(new TextField()), + mOriginalScrollRadius((int) config.getValue("ScrollRadius", 32)), + mScrollRadiusSlider(new Slider(0, 128)), + mScrollRadiusField(new TextField()) { setOpaque(false); @@ -153,12 +159,36 @@ Setup_Video::Setup_Video(): mAlphaSlider->setEventId("guialpha"); mFpsCheckBox->setEventId("fpslimitcheckbox"); mFpsSlider->setEventId("fpslimitslider"); + mScrollRadiusSlider->setEventId("scrollradiusslider"); + mScrollRadiusField->setEventId("scrollradiusfield"); + mScrollLazinessSlider->setEventId("scrolllazinessslider"); + mScrollLazinessField->setEventId("scrolllazinessfield"); mCustomCursorCheckBox->addActionListener(this); mAlphaSlider->addActionListener(this); mFpsCheckBox->addActionListener(this); mFpsSlider->addActionListener(this); mFpsField->addKeyListener(this); + mScrollRadiusSlider->addActionListener(this); + mScrollRadiusField->addKeyListener(this); + mScrollLazinessSlider->addActionListener(this); + mScrollLazinessField->addKeyListener(this); + + mScrollRadiusSlider->setDimension(gcn::Rectangle(10, 120, 75, 10)); + gcn::Label *scrollRadiusLabel = new gcn::Label("Scroll radius"); + scrollRadiusLabel->setPosition(90, 120); + mScrollRadiusField->setPosition(180, 120); + mScrollRadiusField->setWidth(30); + mScrollRadiusField->setText(toString(mOriginalScrollRadius)); + mScrollRadiusSlider->setValue(mOriginalScrollRadius); + + mScrollLazinessSlider->setDimension(gcn::Rectangle(10, 140, 75, 10)); + gcn::Label *scrollLazinessLabel = new gcn::Label("Scroll laziness"); + scrollLazinessLabel->setPosition(90, 140); + mScrollLazinessField->setPosition(180, 140); + mScrollLazinessField->setWidth(30); + mScrollLazinessField->setText(toString(mOriginalScrollLaziness)); + mScrollLazinessSlider->setValue(mOriginalScrollLaziness); add(scrollArea); add(mFsCheckBox); @@ -169,6 +199,12 @@ Setup_Video::Setup_Video(): add(mFpsCheckBox); add(mFpsSlider); add(mFpsField); + add(mScrollRadiusSlider); + add(scrollRadiusLabel); + add(mScrollRadiusField); + add(mScrollLazinessSlider); + add(scrollLazinessLabel); + add(mScrollLazinessField); } Setup_Video::~Setup_Video() @@ -225,6 +261,27 @@ void Setup_Video::apply() mOpenGLEnabled = config.getValue("opengl", 0); } +int +Setup_Video::updateSlider(gcn::Slider *slider, gcn::TextField *field, + const std::string &configName) +{ + int value; + std::stringstream temp(field->getText()); + temp >> value; + if (value < slider->getScaleStart()) + { + value = (int) slider->getScaleStart(); + } + else if (value > slider->getScaleEnd()) + { + value = (int) slider->getScaleEnd(); + } + field->setText(toString(value)); + slider->setValue(value); + config.setValue(configName, value); + return value; +} + void Setup_Video::cancel() { mFsCheckBox->setMarked(mFullScreenEnabled); @@ -232,6 +289,11 @@ void Setup_Video::cancel() mCustomCursorCheckBox->setMarked(mCustomCursorEnabled); mAlphaSlider->setValue(mOpacity); + mScrollRadiusField->setText(toString(mOriginalScrollRadius)); + mScrollLazinessField->setText(toString(mOriginalScrollLaziness)); + updateSlider(mScrollRadiusSlider, mScrollRadiusField, "ScrollRadius"); + updateSlider(mScrollLazinessSlider, mScrollLazinessField, "ScrollLaziness"); + config.setValue("screen", mFullScreenEnabled ? 1 : 0); config.setValue("customcursor", mCustomCursorEnabled ? 1 : 0); config.setValue("guialpha", mOpacity); @@ -254,6 +316,18 @@ void Setup_Video::action(const std::string &event, gcn::Widget *widget) mFps = (int)mFpsSlider->getValue(); mFpsField->setText(toString(mFps)); } + else if (event == "scrollradiusslider") + { + int val = (int)mScrollRadiusSlider->getValue(); + mScrollRadiusField->setText(toString(val)); + config.setValue("ScrollRadius", val); + } + else if (event == "scrolllazinessslider") + { + int val = (int)mScrollLazinessSlider->getValue(); + mScrollLazinessField->setText(toString(val)); + config.setValue("ScrollLaziness", val); + } else if (event == "fpslimitcheckbox") { if (mFpsCheckBox->isMarked()) @@ -293,4 +367,6 @@ void Setup_Video::keyPress(const gcn::Key &key) mFpsField->setText(""); mFps = 0; } + updateSlider(mScrollRadiusSlider, mScrollRadiusField, "ScrollRadius"); + updateSlider(mScrollLazinessSlider, mScrollLazinessField, "ScrollLaziness"); } diff --git a/src/gui/setup_video.h b/src/gui/setup_video.h index d0a10925..a3fd8884 100644 --- a/src/gui/setup_video.h +++ b/src/gui/setup_video.h @@ -59,10 +59,26 @@ class Setup_Video : public SetupTab, public gcn::ActionListener, gcn::CheckBox *mFsCheckBox; gcn::CheckBox *mOpenGLCheckBox; gcn::CheckBox *mCustomCursorCheckBox; + gcn::Slider *mAlphaSlider; gcn::CheckBox *mFpsCheckBox; gcn::Slider *mFpsSlider; gcn::TextField *mFpsField; + + int mOriginalScrollLaziness; + gcn::Slider *mScrollLazinessSlider; + gcn::TextField *mScrollLazinessField; + + int mOriginalScrollRadius; + gcn::Slider *mScrollRadiusSlider; + gcn::TextField *mScrollRadiusField; + + void + updateSliders(bool originalValues); + + int + updateSlider(gcn::Slider *slider, gcn::TextField *field, + const std::string &configName); }; #endif diff --git a/src/gui/window.cpp b/src/gui/window.cpp index 9a07111f..2172baa8 100644 --- a/src/gui/window.cpp +++ b/src/gui/window.cpp @@ -63,6 +63,7 @@ Window::Window(const std::string& caption, bool modal, Window *parent): mModal(modal), mResizable(false), mMouseResize(false), + mSticky(false), mMinWinWidth(100), mMinWinHeight(28), mMaxWinWidth(INT_MAX), @@ -243,6 +244,26 @@ bool Window::isResizable() return mResizable; } +void Window::setSticky(bool sticky) +{ + mSticky = sticky; +} + +bool Window::isSticky() { + return mSticky; +} + +void Window::setVisible(bool visible) { + if(isSticky()) + { + gcn::Window::setVisible(true); + } + else + { + gcn::Window::setVisible(visible); + } +} + void Window::scheduleDelete() { windowContainer->scheduleDelete(this); diff --git a/src/gui/window.h b/src/gui/window.h index 42ce444c..51c876e3 100644 --- a/src/gui/window.h +++ b/src/gui/window.h @@ -133,6 +133,25 @@ class Window : public gcn::Window */ void setMaxHeight(unsigned int height); + /** + * Sets whether the window is sticky. + * A sticky window will not have its visibility set to false + * on a general setVisible(false) call. + */ + void setSticky(bool sticky); + + /** + * Returns whether the window is sticky. + */ + bool isSticky(); + + /** + * Overloads window setVisible by guichan to allow sticky window + * Handling + */ + + void setVisible(bool visible); + /** * Returns the parent window. * @@ -204,6 +223,7 @@ class Window : public gcn::Window bool mModal; /**< Window is modal */ bool mResizable; /**< Window can be resized */ bool mMouseResize; /**< Window is being resized */ + bool mSticky; /**< Window resists minimzation */ int mMinWinWidth; /**< Minimum window width */ int mMinWinHeight; /**< Minimum window height */ int mMaxWinWidth; /**< Maximum window width */ diff --git a/src/joystick.cpp b/src/joystick.cpp index bb6e887b..a5dab4f4 100644 --- a/src/joystick.cpp +++ b/src/joystick.cpp @@ -59,10 +59,11 @@ Joystick::Joystick(int no): logger->log("Hats: %i", SDL_JoystickNumHats(mJoystick)); logger->log("Buttons: %i", SDL_JoystickNumButtons(mJoystick)); - mUpTolerance = (int)config.getValue("upTolerance", 100); - mDownTolerance = (int)config.getValue("downTolerance", 100); - mLeftTolerance = (int)config.getValue("leftTolerance", 100); - mRightTolerance = (int)config.getValue("rightTolerance", 100); + mEnabled = (int) config.getValue("joystickEnabled", 0) != 0; + mUpTolerance = (int) config.getValue("upTolerance", 100); + mDownTolerance = (int) config.getValue("downTolerance", 100); + mLeftTolerance = (int) config.getValue("leftTolerance", 100); + mRightTolerance = (int) config.getValue("rightTolerance", 100); } Joystick::~Joystick() @@ -73,6 +74,7 @@ Joystick::~Joystick() void Joystick::update() { mDirection = 0; + SDL_JoystickUpdate(); // When calibrating, don't bother the outside with our state @@ -81,6 +83,8 @@ void Joystick::update() return; }; + if (!mEnabled) return; + // X-Axis int position = SDL_JoystickGetAxis(mJoystick, 0); if (position >= mRightTolerance) @@ -144,7 +148,6 @@ void Joystick::doCalibration() } } - void Joystick::finishCalibration() { config.setValue("leftTolerance", mLeftTolerance); @@ -154,10 +157,7 @@ void Joystick::finishCalibration() mCalibrating = false; } -bool Joystick::buttonPressed(unsigned char no) +bool Joystick::buttonPressed(unsigned char no) const { - if (no > MAX_BUTTONS) - return false; - - return mButtons[no]; + return (no < MAX_BUTTONS) ? mButtons[no] : false; } diff --git a/src/joystick.h b/src/joystick.h index ebdfabeb..f0759add 100644 --- a/src/joystick.h +++ b/src/joystick.h @@ -30,12 +30,12 @@ class Joystick { public: /** - * Number of buttons we can handle + * Number of buttons we can handle. */ static const unsigned char MAX_BUTTONS = 6; /** - * Directions, to be used as bitmask values + * Directions, to be used as bitmask values. */ static const char UP = 1; static const char DOWN = 2; @@ -43,12 +43,12 @@ class Joystick static const char RIGHT = 8; /** - * Initializes the joystick subsystem + * Initializes the joystick subsystem. */ static void init(); /** - * Returns the number of available joysticks + * Returns the number of available joysticks. */ static int getNumberOfJoysticks() { return joystickCount; } @@ -60,21 +60,33 @@ class Joystick ~Joystick(); + bool + isEnabled() const { return mEnabled; } + + void + setEnabled(bool enabled) { mEnabled = enabled; } + /** * Updates the direction and button information. */ - void update(); + void + update(); + + void + startCalibration(); + + void + finishCalibration(); - void startCalibration(); - void finishCalibration(); - bool isCalibrating() { return mCalibrating; }; + bool + isCalibrating() const { return mCalibrating; } - bool buttonPressed(unsigned char no); + bool buttonPressed(unsigned char no) const; - bool isUp() { return mDirection & UP; }; - bool isDown() { return mDirection & DOWN; }; - bool isLeft() { return mDirection & LEFT; }; - bool isRight() { return mDirection & RIGHT; }; + bool isUp() const { return mDirection & UP; }; + bool isDown() const { return mDirection & DOWN; }; + bool isLeft() const { return mDirection & LEFT; }; + bool isRight() const { return mDirection & RIGHT; }; protected: unsigned char mDirection; @@ -83,6 +95,7 @@ class Joystick int mUpTolerance, mDownTolerance, mLeftTolerance, mRightTolerance; bool mCalibrating; + bool mEnabled; static int joystickCount; diff --git a/src/main.cpp b/src/main.cpp index 573b1a79..f540dacd 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -330,6 +330,7 @@ struct Options bool chooseDefault; std::string username; std::string password; + std::string playername; }; void printHelp() @@ -341,13 +342,14 @@ void printHelp() << " -u --skipupdate : Skip the update process" << std::endl << " -U --username : Login with this username" << std::endl << " -P --password : Login with this password" << std::endl - << " -D --default : Bypass the login process with default settings" + << " -D --default : Bypass the login process with default settings" << std::endl + << " -p --playername : Login with this player" << std::endl; } void parseOptions(int argc, char *argv[], Options &options) { - const char *optstring = "huU:P:D"; + const char *optstring = "huU:P:Dp:"; const struct option long_options[] = { { "help", no_argument, 0, 'h' }, @@ -355,6 +357,7 @@ void parseOptions(int argc, char *argv[], Options &options) { "username", required_argument, 0, 'U' }, { "password", required_argument, 0, 'P' }, { "default", no_argument, 0, 'D' }, + { "playername", required_argument, 0, 'p' }, { 0 } }; @@ -382,6 +385,9 @@ void parseOptions(int argc, char *argv[], Options &options) case 'D': options.chooseDefault = true; break; + case 'p': + options.playername = optarg; + break; } } } @@ -668,7 +674,20 @@ int main(int argc, char *argv[]) case STATE_CHAR_SELECT: logger->log("State: CHAR_SELECT"); currentDialog = new CharSelectDialog(&charInfo); - if (options.chooseDefault) { + if (options.playername != "") { + n_character = 0; + while (((CharSelectDialog*) currentDialog)->getName() + != options.playername && + n_character < MAX_SLOT + 1) + { + ((CharSelectDialog*) currentDialog)->action("next", + NULL); + ((CharSelectDialog*) currentDialog)->updatePlayerInfo(); + n_character++; + } + n_character = MAX_SLOT + 1; + } + if (options.chooseDefault || options.playername != "") { ((CharSelectDialog*)currentDialog)->action("ok", NULL); } diff --git a/src/map.cpp b/src/map.cpp index 1b2ce1e8..cbebc41c 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -60,7 +60,8 @@ struct Location Map::Map(int width, int height, int tileWidth, int tileHeight): mWidth(width), mHeight(height), mTileWidth(tileWidth), mTileHeight(tileHeight), - mOnClosedList(1), mOnOpenList(2) + mOnClosedList(1), mOnOpenList(2), + mLastScrollX(0.0f), mLastScrollY(0.0f) { mMetaTiles = new MetaTile[mWidth * mHeight]; mTiles = new Image*[mWidth * mHeight * 3]; @@ -68,12 +69,18 @@ Map::Map(int width, int height, int tileWidth, int tileHeight): Map::~Map() { + // clean up map data delete[] mMetaTiles; delete[] mTiles; - - // Clean up tilesets + // clean up tilesets for_each(mTilesets.begin(), mTilesets.end(), make_dtor(mTilesets)); mTilesets.clear(); + // clean up overlays + std::list::iterator i; + for (i = mOverlays.begin(); i != mOverlays.end(); i++) + { + (*i).image->decRef(); + } } void @@ -159,6 +166,106 @@ Map::draw(Graphics *graphics, int scrollX, int scrollY, int layer) } } +void +Map::drawOverlay(Graphics *graphics, float scrollX, float scrollY, int detail) +{ + static int lastTick = tick_time; + + // detail 0: no overlays + if (detail <= 0) return; + + std::list::iterator i; + + // Avoid freaking out when tick_time overflows + if (tick_time < lastTick) + { + lastTick = tick_time; + } + + if (mLastScrollX == 0.0f && mLastScrollY == 0.0f) + { + // first call - initialisation + mLastScrollX = scrollX; + mLastScrollY = scrollY; + } + + //update Overlays + while (lastTick < tick_time) + { + for (i = mOverlays.begin(); i != mOverlays.end(); i++) + { + if ((*i).image != NULL) + { + //apply self scrolling + (*i).scrollX -= (*i).scrollSpeedX; + (*i).scrollY -= (*i).scrollSpeedY; + + //apply parallaxing + (*i).scrollX += (scrollX - mLastScrollX) * (*i).parallax; + (*i).scrollY += (scrollY - mLastScrollY) * (*i).parallax; + + //keep the image pattern on the screen + while ((*i).scrollX > (*i).image->getWidth()) + { + (*i).scrollX -= (*i).image->getWidth(); + } + while ((*i).scrollY > (*i).image->getHeight()) + { + (*i).scrollY -= (*i).image->getHeight(); + } + while ((*i).scrollX < 0) + { + (*i).scrollX += (*i).image->getWidth(); + } + while ((*i).scrollY < 0) + { + (*i).scrollY += (*i).image->getHeight(); + } + } + } + mLastScrollX = scrollX; + mLastScrollY = scrollY; + lastTick++; + + // detail 1: only one overlay, higher: all overlays + if (detail == 1) break; + } + + //draw overlays + for (i = mOverlays.begin(); i != mOverlays.end(); i++) + { + if ((*i).image != NULL) + { + graphics->drawImagePattern ( (*i).image, + 0 - (int)(*i).scrollX, + 0 - (int)(*i).scrollY, + graphics->getWidth() + (int)(*i).scrollX, + graphics->getHeight() + (int)(*i).scrollY + ); + }; + // detail 1: only one overlay, higher: all overlays + if (detail == 1) break; + }; +} + +void +Map::setOverlay(Image *image, float speedX, float speedY, float parallax) +{ + if (image != NULL) + { + AmbientOverlay newOverlay; + + newOverlay.image = image; + newOverlay.parallax = parallax; + newOverlay.scrollSpeedX = speedX; + newOverlay.scrollSpeedY = speedY; + newOverlay.scrollX = 0; + newOverlay.scrollY = 0; + + mOverlays.push_back(newOverlay); + } +} + void Map::setTileWithGid(int x, int y, int layer, int gid) { diff --git a/src/map.h b/src/map.h index a91b815f..317a0b59 100644 --- a/src/map.h +++ b/src/map.h @@ -41,6 +41,8 @@ typedef Tilesets::iterator TilesetIterator; typedef std::list Sprites; typedef Sprites::iterator SpriteIterator; +extern volatile int tick_time; + /** * A meta tile stores additional information about a location on a tile map. * This is information that doesn't need to be repeated for each tile in each @@ -63,6 +65,16 @@ struct MetaTile bool walkable; /**< Can beings walk on this tile */ }; +struct AmbientOverlay +{ + Image *image; + float parallax; + float scrollX; + float scrollY; + float scrollSpeedX; + float scrollSpeedY; +}; + /** * A tile map. */ @@ -80,10 +92,20 @@ class Map : public Properties ~Map(); /** - * Draws the map to the given graphics output. + * Draws a map layer to the given graphics output. */ void draw(Graphics *graphics, int scrollX, int scrollY, int layer); + /** + * Sets Overlay Graphic and Scrollspeed + */ + void setOverlay(Image *image, float speedX, float speedY, float parallax); + + /** + * Draws the overlay graphic to the given graphics output. + */ + void drawOverlay(Graphics *graphics, float scrollX, float scrollY, int detail); + /** * Sets the size of the map. This will destroy any existing map data. */ @@ -198,6 +220,12 @@ class Map : public Properties // Pathfinding members int mOnClosedList, mOnOpenList; + + //overlay Data + AmbientOverlay mFoo; + std::list mOverlays; + float mLastScrollX; + float mLastScrollY; }; #endif diff --git a/src/net/inventoryhandler.cpp b/src/net/inventoryhandler.cpp index cb1883b0..c4192bc5 100644 --- a/src/net/inventoryhandler.cpp +++ b/src/net/inventoryhandler.cpp @@ -28,6 +28,7 @@ #include "messagein.h" #include "protocol.h" +#include "../resources/iteminfo.h" #include "../item.h" #include "../localplayer.h" @@ -91,6 +92,14 @@ void InventoryHandler::handleMessage(MessageIn &msg) if (msg.readByte()> 0) { chatWindow->chatLog("Unable to pick up item", BY_SERVER); } else { + ItemInfo *itemInfo = itemDb->getItemInfo(itemId); + if (itemInfo) { + chatWindow->chatLog("You picked up a " + + itemInfo->getName(), BY_SERVER); + } else { + chatWindow->chatLog("You picked up an unknown item", + BY_SERVER); + } player_node->addInvItem(index, itemId, amount, equipType != 0); } break; diff --git a/src/player.cpp b/src/player.cpp index b635397e..af9a3344 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -84,6 +84,7 @@ Player::setSex(Uint8 sex) } Being::setSex(sex); + resetAnimations(); } } @@ -99,6 +100,7 @@ Player::setHairColor(Uint16 color) newHairSprite->setDirection(getSpriteDirection()); mSprites[HAIR_SPRITE] = newHairSprite; + resetAnimations(); setAction(mAction); } @@ -118,6 +120,7 @@ Player::setHairStyle(Uint16 style) newHairSprite->setDirection(getSpriteDirection()); mSprites[HAIR_SPRITE] = newHairSprite; + resetAnimations(); setAction(mAction); } @@ -155,6 +158,7 @@ Player::setVisibleEquipment(Uint8 slot, Uint8 id) equipmentSprite->setDirection(getSpriteDirection()); mSprites[position] = equipmentSprite; + resetAnimations(); setAction(mAction); } @@ -162,4 +166,14 @@ Player::setVisibleEquipment(Uint8 slot, Uint8 id) Being::setVisibleEquipment(slot, id); } - +void +Player::resetAnimations() +{ + for (int i = 0; i < VECTOREND_SPRITE; i++) + { + if (mSprites[i] != NULL) + { + mSprites[i]->reset(); + } + } +} diff --git a/src/player.h b/src/player.h index d0d55cc8..65b0303d 100644 --- a/src/player.h +++ b/src/player.h @@ -57,6 +57,14 @@ class Player : public Being virtual void setVisibleEquipment(Uint8 slot, Uint8 id); + + private: + /** + * Resets all animations associated with this player. This is used to + * synchronize the animations after a new one has been added. + */ + void + resetAnimations(); }; #endif diff --git a/src/resources/iteminfo.cpp b/src/resources/iteminfo.cpp new file mode 100644 index 00000000..5d39d832 --- /dev/null +++ b/src/resources/iteminfo.cpp @@ -0,0 +1,44 @@ +/* + * The Mana World + * Copyright 2004 The Mana World Development Team + * + * This file is part of The Mana World. + * + * The Mana World is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * The Mana World is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with The Mana World; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#include "iteminfo.h" + +#include "resourcemanager.h" + +Image* +ItemInfo::getImage() { + if (mImage == NULL && mImageName != "") { + mImage = ResourceManager::getInstance()->getImage(mImageName); + } + return mImage; +} + +void +ItemInfo::setImage(const std::string &image) { + mImageName = "graphics/items/" + image; +} + +ItemInfo::~ItemInfo() { + if (mImage != NULL){ + mImage->decRef(); + } +} diff --git a/src/resources/iteminfo.h b/src/resources/iteminfo.h index 54e7907b..afa2e857 100644 --- a/src/resources/iteminfo.h +++ b/src/resources/iteminfo.h @@ -26,6 +26,8 @@ #include +#include "image.h" + /** * Defines a class for storing item infos. */ @@ -38,7 +40,8 @@ class ItemInfo * Constructor. */ ItemInfo(): - mImage(0), + mImage(NULL), + mImageName(""), mArt(0), mType(0), mWeight(0), @@ -59,10 +62,10 @@ class ItemInfo getName() { return mName; } void - setImage(short image) { mImage = image; } + setImage(const std::string &image); - short - getImage() { return mImage; } + Image* + getImage(); void setDescription(const std::string &description) @@ -101,9 +104,10 @@ class ItemInfo /** * Destructor. */ - ~ItemInfo() {} + ~ItemInfo(); - short mImage; + Image* mImage; + std::string mImageName; short mArt; std::string mName; std::string mDescription; diff --git a/src/resources/itemmanager.cpp b/src/resources/itemmanager.cpp index 63c0b036..a497b3c8 100644 --- a/src/resources/itemmanager.cpp +++ b/src/resources/itemmanager.cpp @@ -68,8 +68,8 @@ ItemManager::ItemManager() for (node = node->xmlChildrenNode; node != NULL; node = node->next) { - int id = 0, image = 0, art = 0, type = 0, weight = 0, slot = 0; - std::string name = "", description = "", effect = ""; + int id = 0, art = 0, type = 0, weight = 0, slot = 0; + std::string name = "", description = "", effect = "", image = ""; if (!xmlStrEqual(node->name, BAD_CAST "item")) { continue; @@ -77,7 +77,7 @@ ItemManager::ItemManager() xmlChar *prop = NULL; READ_PROP(node, prop, "id", id, atoi); - READ_PROP(node, prop, "image", image, atoi); + READ_PROP(node, prop, "image", image, ); READ_PROP(node, prop, "art", art, atoi); READ_PROP(node, prop, "name", name, ); READ_PROP(node, prop, "description", description, ); @@ -86,6 +86,7 @@ ItemManager::ItemManager() READ_PROP(node, prop, "weight", weight, atoi); READ_PROP(node, prop, "slot", slot, atoi); + if (id && name != "") { ItemInfo *itemInfo = new ItemInfo(); @@ -100,6 +101,7 @@ ItemManager::ItemManager() mItemInfos[id] = itemInfo; } + if (id == 0) { logger->log("Item Manager: An item has no ID in items.xml!"); @@ -109,7 +111,7 @@ ItemManager::ItemManager() logger->log("Item Manager: An item has no name in items.xml!"); } - if (image == 0) + if (image == "") { logger->log("Item Manager: Missing image parameter for item: %i. %s", id, name.c_str()); @@ -141,7 +143,7 @@ ItemManager::ItemManager() } if (slot == 0) { - logger->log("Item Manager: Missing image parameter for item: %i. %s", + logger->log("Item Manager: Missing slot parameter for item: %i. %s", id, name.c_str()); } diff --git a/src/resources/mapreader.cpp b/src/resources/mapreader.cpp index 382b0797..c1ae911c 100644 --- a/src/resources/mapreader.cpp +++ b/src/resources/mapreader.cpp @@ -34,6 +34,7 @@ #include "../map.h" #include "../tileset.h" +#include "../utils/tostring.h" const unsigned int DEFAULT_TILE_WIDTH = 32; const unsigned int DEFAULT_TILE_HEIGHT = 32; @@ -213,6 +214,32 @@ MapReader::readMap(xmlNodePtr node, const std::string &path) } } + //set Overlays + int i = 0; + ResourceManager *resman = ResourceManager::getInstance(); + + while (map->hasProperty("overlay" + toString(i) + "image")) + { + Image *overlayImage = resman->getImage(map->getProperty("overlay" + toString(i) + "image")); + float scrollX = 0.0f; + float scrollY = 0.0f; + float parallax = 0.0f; + if (map->hasProperty("overlay" + toString(i) + "scrollX")) + { + scrollX = atof(map->getProperty("overlay" + toString(i) + "scrollX").c_str()); + } + if (map->hasProperty("overlay" + toString(i) + "scrollY")) + { + scrollY = atof(map->getProperty("overlay" + toString(i) + "scrollY").c_str()); + } + if (map->hasProperty("overlay" + toString(i) + "parallax")) + { + parallax = atof(map->getProperty("overlay" + toString(i) + "parallax").c_str()); + } + map->setOverlay (overlayImage, scrollX, scrollY, parallax); + i++; + } + return map; } diff --git a/tmw.cbp b/tmw.cbp index d80ebe55..ff060fe4 100644 --- a/tmw.cbp +++ b/tmw.cbp @@ -48,6 +48,16 @@