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/buy.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/gui/buy.cpp') diff --git a/src/gui/buy.cpp b/src/gui/buy.cpp index 86bd5413..e96cc04f 100644 --- a/src/gui/buy.cpp +++ b/src/gui/buy.cpp @@ -216,11 +216,11 @@ void BuyDialog::action(const std::string& eventId) // there a better way to ensure this fails in an _obivous_ way in C++? else if (eventId == "buy" && (mAmountItems > 0 && mAmountItems <= mMaxItems)) { - MessageOut outMsg(mNetwork); - outMsg.writeInt16(CMSG_NPC_BUY_REQUEST); - outMsg.writeInt16(8); - outMsg.writeInt16(mAmountItems); - outMsg.writeInt16(mShopItems->at(selectedItem).id); + MessageOut outMsg; + outMsg.writeShort(CMSG_NPC_BUY_REQUEST); + outMsg.writeShort(8); + outMsg.writeShort(mAmountItems); + outMsg.writeShort(mShopItems->at(selectedItem).id); // update money ! mMoney -= mAmountItems * mShopItems->at(selectedItem).price; -- cgit v1.2.3-60-g2f50 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/buy.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-60-g2f50 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/buy.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-60-g2f50 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/buy.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-60-g2f50 From e8f94fe7ca5e7e7838eaa84f1792b4b42b4bada3 Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Fri, 29 Sep 2006 23:59:08 +0000 Subject: Merged trunk changes from revision 2618 to 2716 into the 0.1.0 branch. --- ChangeLog | 339 ++++++++++++++++++++++++++++++--------- NEWS | 10 +- README | 3 +- data/graphics/images/Makefile.am | 9 +- data/help/changes.txt | 31 ++++ data/help/commands.txt | 1 + data/help/header.txt | 2 +- debian/changelog | 8 + debian/tmw-music.install | 2 + src/Makefile.am | 3 + src/animatedsprite.cpp | 87 +++++++--- src/animatedsprite.h | 16 +- src/animation.cpp | 33 +++- src/animation.h | 16 ++ src/being.cpp | 25 +-- src/beingmanager.cpp | 29 +++- src/beingmanager.h | 19 ++- src/engine.cpp | 4 +- src/floor_item.cpp | 4 +- src/game.cpp | 77 ++++++--- src/game.h | 17 +- src/gui/buy.cpp | 47 +++--- src/gui/buy.h | 12 +- src/gui/char_select.cpp | 22 +++ src/gui/char_select.h | 2 + src/gui/equipmentwindow.cpp | 4 +- src/gui/gui.cpp | 13 ++ src/gui/inventorywindow.cpp | 58 ++++--- src/gui/inventorywindow.h | 20 ++- src/gui/itemcontainer.cpp | 35 +++- src/gui/itemcontainer.h | 35 +++- src/gui/listbox.cpp | 57 ++++++- src/gui/listbox.h | 41 ++++- src/gui/minimap.cpp | 4 +- src/gui/playerbox.cpp | 2 +- src/gui/popupmenu.cpp | 2 +- src/gui/selectionlistener.h | 78 +++++++++ src/gui/sell.cpp | 40 +++-- src/gui/sell.h | 13 +- src/gui/setup.cpp | 4 +- src/gui/setup_video.cpp | 52 +++++- src/gui/setup_video.h | 4 + src/gui/trade.cpp | 63 ++++---- src/gui/trade.h | 10 +- src/gui/updatewindow.cpp | 18 ++- src/gui/updatewindow.h | 5 + src/gui/window.cpp | 12 +- src/item.h | 2 +- src/localplayer.h | 7 +- src/main.cpp | 108 +++++++------ src/map.cpp | 24 ++- src/net/inventoryhandler.cpp | 11 +- src/resources/image.cpp | 21 ++- src/resources/image.h | 7 + src/resources/iteminfo.cpp | 31 ++-- src/resources/iteminfo.h | 34 ++-- src/resources/itemmanager.cpp | 9 +- src/resources/itemmanager.h | 8 +- src/tmw.rc | 8 +- tools/Reorganize.java | 128 ++++++++++----- 60 files changed, 1336 insertions(+), 450 deletions(-) create mode 100644 src/gui/selectionlistener.h (limited to 'src/gui/buy.cpp') diff --git a/ChangeLog b/ChangeLog index aa54e32e..33fab8df 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,10 +1,148 @@ -2006-08-30 Yohann Ferreira +2006-09-28 Björn Steinbrink + + * src/map.cpp: Fix random crashes when map tiles are missing. + +2006-09-28 Bjørn Lindeijer + + * data/graphics/maps/new_2-1.tmx.gz: Matt Howe fixed up cave map. + +2006-09-26 Eugenio Favalli + + * data/graphics/maps/new_6-1.tmx.gz: Alderan fixed a map issue. + +2006-09-25 Bjørn Lindeijer + + * data/graphics/sprites/hairstyle*.png, + data/graphics/sprites/hairstyle*.xml, tools/Reorganize.java: Removed + unused frames from the hairsets. + * src/resources/image.h: Defined NO_SDL_GLEXT to prevent a + redefinition when gl.h also tries to define OpenGL extensions (patch + accepted from Rogier Polak). + +2006-09-23 Bjørn Lindeijer + + * data/maps/new_5-1.tmx.gz: Accepted new version by Matt Howe, fixing + several mapping issues. + +2006-09-21 Eugenio Favalli + + * data/graphics/tiles/Makefile.am: Added missing tileset. + * src/gui/updatewindow.cpp, src/gui/updatewindow.h: Made canceling the + update process non-blocking (Patch by VictorSan). + +2006-09-21 Philipp Sehmisch + + * src/animation.cpp, src/animation.h, src/animatedsprite.cpp, + src/animatedsprite.h: Removed some obsolete code and implemented + the posibility to define an token in the s + that allows to define an animation that doesn't loop and returns + to the STAND animation when finished. + * data/graphics/sprites/hairstyle*.xml, + data/graphics/sprites/item0*.xml, + data/graphics/sprites/monster*.xml, + data/graphics/sprites/weapons.xml: Used the token for all + attack animations fixing the problem with looping monster attack + animations. + +2006-09-20 Philipp Sehmisch + + * data/graphics/items/generic-whitefur.png, + data/graphics/items/generic-cavesnakelamp.png, + data/graphics/items/generic-hardspike.png, + data/graphics/items/generic-pinkantennae.png, + data/graphics/items/Makefile.am, data/items.xml: Added drops for new + monsters. + * src/gui/setup.cpp, src/gui/setup_video.cpp, + src/gui/setup_video.h: Added a slider for controlling the overlay + detail to the video setup dialog based on a patch by VictorSan. + * data/maps/new_14-1.tmx.gz, data/maps/new_16-1.tmx.gz: Added cloud + effect and minimap. + * data/images/Makefile.am: Updated makefile. + +2006-09-19 Bjørn Lindeijer + + * data/graphics/sprites/Makefile.am: Added missing monster19 sprite. + +2006-09-17 Eugenio Favalli + + * data/maps/Makefile.am: Added missing maps. + * data/maps/new_10-1.tmx.gz: Disabled layer compression. + +2006-09-18 Philipp Sehmisch + + * data/maps/new_9-1.tmx.gz: Fixed some mapping bugs (new walkmap + required). + +2006-09-17 Eugenio Favalli + + * data/maps/new_10-1.tmx.gz: Fixed transparent snow issue (Fix by + Pajarico). + +2006-09-17 Björn Steinbrink + + * src/game.cpp: Stop using the sticky window attribute which is + unneeded for the current implementation, instead adjust the set of + affected windows by the 'hide' shortcut. + +2006-09-17 Philipp Sehmisch + + * data/maps/new_14-1.tmx.gz, data/maps/new_15-1.tmx.gz, + data/maps/new_16-1.tmx.gz: fixed some mapping errors. + +2006-09-16 Philipp Sehmisch + + * src/animatedsprite.cpp, src/animatedsprite.h: Fixed the crash when + attacking without a weapon, some additional stability improvements and + more descriptive variable names in the parsing algorithmn. + +2006-09-16 Eugenio Favalli + + * data/help/changes.txt, data/help/header.txt, NEWS, README, + src/tmw.rc: Updated release infos. + +2006-09-14 Philipp Sehmisch + + * src/animation.h, src/animatedsprite.h, + data/graphics/sprites/weapon.xml: Some modifications at the animation + system. No more "undefined action foo" warnings in the tmw.log. Not + visible actions must now be declared explicitely. + * data/graphics/images/ambient/sandstorm.png, + data/graphics/images/ambient/clouds.png: Improved quality of the overlay + graphics. + +2006-09-14 Björn Steinbrink + + * src/gui/char_select.cpp: Remove debug output. + * src/gui/char_select.cpp, src/main.cpp: Fix the character name + matching loop and add support for saving the last used character + (based on a patch by Andrew Harrison). + * src/gui/char_select.cpp, src/gui/char_select.h, src/main.cpp: Clean + up the player selection stuff, it's a bit nicer now. + * src/main.cpp: Fix up the player selection command line option. + +2006-09-13 Yohann Ferreira * src/Makefile.am, src/gui/widgets, src/gui/widgets/dropdown.h, src/gui/widgets/dropdown.cpp, src/gui/serverdialog.h, src/gui/serverdialog.cpp: Added a reusable skinned dropdown widget in the new widgets folder. Other widgets will be be moved there later. +2006-09-12 Bjørn Lindeijer + + * src/game.cpp, src/game.h: Simplified fps limiting a bit and added + some comments. Now based on ConfigListener so that the fpslimit option + doesn't need to be queried the whole time. + * NEWS: Updated with some items. + +2006-09-11 Eugenio Favalli + + * src/game.cpp: Fixed more fps issues. + +2006-09-09 Bjørn Lindeijer + + * src/gui/gui.cpp: Removed easy targeting functionality since it + interferes with walking around too much. Targeting can still be rather + conveniently done with 'a' or the middle mouse button. 2006-09-09 Guillaume Melquiond @@ -13,6 +151,72 @@ * src/localplayer.h, src/being.cpp, src/net/beinghandler.cpp, src/being.h: Fitted being trajectories to synchronization messages. +2006-09-07 Björn Steinbrink + + * src/resources/image.cpp: Fixed a typo. + * src/resources/image.cpp: Worked around a memory leak when using + OpenGL. + +2006-09-06 Philipp Sehmisch + + * data/graphics/sprites/item010.png, data/graphics/sprites/item010.xml, + data/graphics/sprites/Makefile.am: Added santa hat sprites and updated + makefile. + +2006-09-06 Eugenio Favalli + + * src/game.cpp, src/gui/setup_video.cpp, src/main.cpp: Fixed fps + limiter issues and increased default limit to 60. + * src/game.cpp: Fixed fps limiter when disabled. + +2006-09-05 Philipp Sehmisch + * data/graphics/tiles/Woodland_ground.png, + data/graphics/tiles/Woodland_x2.png, + data/graphics/tiles/Woodland_x3.png: Some minor improvements and + additions at my tilesets. + * data/graphics/sprites/monster0.xml, + data/graphics/sprites/monster1.xml, + data/graphics/sprites/monster2.xml, + data/graphics/sprites/monster3.xml, + data/graphics/sprites/monster4.xml, + data/graphics/sprites/monster5.xml, + data/graphics/sprites/monster6.xml, + data/graphics/sprites/monster8.xml, + data/graphics/sprites/monster9.xml, + data/graphics/sprites/monster11.xml, + data/graphics/sprites/monster13.xml, + data/graphics/sprites/monster0.xml: Adjusted the animation speed of + several monsters. + +2006-09-03 Bjørn Lindeijer + + * src/floor_item.cpp, src/gui/equipmentwindow.cpp, src/gui/sell.cpp, + src/gui/trade.cpp, src/gui/inventorywindow.h, + src/gui/selectionlistener.h, src/gui/itemcontainer.h, + src/gui/inventorywindow.cpp, src/gui/buy.cpp, + src/gui/itemcontainer.cpp, src/gui/popupmenu.cpp, src/item.h, + src/net/inventoryhandler.cpp, src/Makefile.am, + src/resources/itemmanager.h, src/resources/iteminfo.cpp, + src/resources/iteminfo.h, src/resources/itemmanager.cpp: Introduced + SelectionListener to fix updating problem in inventory window (should + also be used to fix similar problem in trade, buy and sell dialogs). + Made the ItemInfo be passed around as a reference instead of a pointer, + since it is never NULL. + * src/gui/trade.cpp, src/gui/trade.h: Fixed updating of labels in + trade window. + * src/gui/sell.cpp, src/gui/listbox.h, src/gui/inventorywindow.h, + src/gui/buy.h, src/gui/buy.cpp, src/gui/sell.h, src/gui/listbox.cpp: + Fixed updating of labels in buy and sell dialogs. Also made our + listbox respond to mouse dragging to change the selection. + +2006-09-02 Bernard Lidicky + + * src/game.cpp, src/beingmanager.h, src/gui/gui.cpp, + src/beingmanager.cpp, src/localplayer.h, README, + data/help/commands.txt, NEWS: Added targeting nearest monster with + either keyboard or mouse. Also made clicking beings in general a bit + easier (patch applied by Bjørn Lindeijer). + 2006-09-02 Bjørn Lindeijer * src/gui/serverdialog.cpp, src/main.cpp: Fixed crash when using short @@ -32,10 +236,22 @@ 2006-09-01 Eugenio Favalli + * data/graphics/sprites/monster19.png, + data/graphics/sprites/monster19.xml, data/graphics/tiles/arena.png, + data/graphics/tiles/cave.png, data/maps/new_17-1.tmx.gz, + data/maps/new_6-1.tmx.gz: Added new big cave map, lamp-snake monster, + improved arena map. * src/gui/serverdialog.cpp, src/gui/serverdialog.h, src/net/network.h: Fixed some header issues. * The Mana World.dev, tmw.cbp: Updated project files. +2006-08-30 Philipp Sehmisch + + * data/graphics/sprites/item007.png, + data/graphics/sprites/item007.xml, data/graphics/sprites/item009.png, + data/graphics/sprites/item009.xml: + Added sprites for miners helm and standard headband. + 2006-08-30 Yohann Ferreira * src/main.cpp, src/main.h, src/Makefile.am, src/gui/connection.h, @@ -44,17 +260,29 @@ with an unskinned dropdown. Upgraded also the connection window a bit to handle Cancelling more gracefully. -2006-08-27 Guillaume Melquiond +2006-08-29 Bjørn Lindeijer - * src/engine.cpp, src/gui/gui.cpp: Fixed merge issues: printfs and - inconsistency between view and camera variables. Fixed lazy scrolling: - there is no "freaking out" when the correct function is used. + * src/map.cpp, src/beingmanager.h, src/gui/minimap.cpp, + src/engine.cpp, src/beingmanager.cpp: It's better to use a reference + when you don't need a pointer. + * NEWS: Updated with addition of config file option. -2006-08-28 Bjørn Lindeijer +2006-08-29 Andrew Harrison - * src/gui/gui.cpp: Fixed crash when map is not loaded yet. - * src/net/beinghandler.cpp, src/net/protocol.h: Added support for - entering monsters. + * src/main.cpp: Added command line option to specify which + configuration file to use (patch applied by Bjørn Lindeijer). + +2006-08-29 Matthias Hartmann + + * data/graphics/sprites/item006.png, + data/graphics/sprites/item006.xml, data/graphics/sprites/item008.xml: + Fixed fancy hat + silk headband positions. + +2006-08-29 Philipp Sehmisch + + * data/graphics/sprites/item008.png, + data/graphics/sprites/item008.xml, data/graphics/sprites/Makefile.am: + Added fancy hat sprite. 2006-08-28 Philipp Sehmisch @@ -70,6 +298,12 @@ data/graphics/sprites/item006.xml, data/graphics/sprites/Makefile.am: Added headband and fixed svn properties. +2006-08-28 Bjørn Lindeijer + + * src/gui/gui.cpp: Fixed crash when map is not loaded yet. + * src/net/beinghandler.cpp, src/net/protocol.h: Added support for + entering monsters. + 2006-08-27 Guillaume Melquiond * src/localplayer.cpp, src/net/protocol.h: Send move message @@ -89,11 +323,14 @@ src/monster.cpp, src/player.h: Cleaned the logic members. * src/engine.cpp, src/localplayer.cpp, src/gui/gui.cpp, src/being.cpp, src/being.h: Implemented pixel-grained movements. + * src/engine.cpp, src/gui/gui.cpp: Fixed merge issues: printfs and + inconsistency between view and camera variables. Fixed lazy scrolling: + there is no "freaking out" when the correct function is used. 2006-08-27 Bjørn Lindeijer - * src/net/inventoryhandler.cpp: Applied patch by AHarrison that adds - item pickup messages to the chat window. + * src/net/inventoryhandler.cpp: Applied patch by Andrew Harrison 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, @@ -173,7 +410,7 @@ * 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. + as discussed with doener. Patch by Andrew Harrison. * data/items.xml: Added jeans shorts. 2006-08-24 Philipp Sehmisch @@ -235,11 +472,11 @@ 2006-08-20 Yohann Ferreira - * data/graphics/sprites/Makefile.am : Following the splitting from + * 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 + * debian/control, debian/tmw-data.install: Updated debian package creation process. - * src/Makefile.am : Added iteminfo.cpp to avoid an undefined reference + * 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 @@ -288,13 +525,13 @@ * 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/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 + 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 + * data/graphics/tiles/trans_desert-woodland.png: Added transmission tileset between desert and woodland. 2006-08-15 Bjørn Lindeijer @@ -527,8 +764,8 @@ 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. + 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, @@ -704,8 +941,8 @@ 2006-07-12 Frode Lindeijer - * /tmw/trunk/data/graphics/sprites/item001.png: Completed the cotton - shirt equipment graphic. + * data/graphics/sprites/item001.png: Completed the cotton shirt + equipment graphic. 2006-07-06 Philipp Sehmisch @@ -755,68 +992,20 @@ * src/being.h, src/being.cpp, src/npc.cpp, src/npc.h, src/monster.cpp, src/monster.h: Moved all drawing code from the Being based classes into Being. - * data/graphics/sprites/monster0.png, - data/graphics/sprites/monster1.png, - data/graphics/sprites/monster2.png, - data/graphics/sprites/monster3.png, - data/graphics/sprites/monster4.png, - data/graphics/sprites/monster5.png, - data/graphics/sprites/monster6.png, - data/graphics/sprites/monster7.png, - data/graphics/sprites/monster8.png, - data/graphics/sprites/monster9.png, - data/graphics/sprites/monster10.png, - data/graphics/sprites/monster11.png, - data/graphics/sprites/monster12.png, - data/graphics/sprites/monster13.png, - data/graphics/sprites/monster14.png, - data/graphics/sprites/monster15.png, - data/graphics/sprites/monster16.png, - data/graphics/sprites/monster17.png: Resized and reorganized the + * data/graphics/sprites/monster*.png: Resized and reorganized the monster spritesets to fit the new animation system (thanks, Bjørn). - * data/graphics/sprites/monster0.xml, - data/graphics/sprites/monster1.xml, - data/graphics/sprites/monster2.xml, - data/graphics/sprites/monster3.xml, - data/graphics/sprites/monster4.xml, - data/graphics/sprites/monster5.xml, - data/graphics/sprites/monster6.xml, - data/graphics/sprites/monster7.xml, - data/graphics/sprites/monster8.xml, - data/graphics/sprites/monster9.xml, - data/graphics/sprites/monster10.xml, - data/graphics/sprites/monster11.xml, - data/graphics/sprites/monster12.xml, - data/graphics/sprites/monster13.xml, - data/graphics/sprites/monster14.xml, - data/graphics/sprites/monster15.xml, - data/graphics/sprites/monster16.xml, - data/graphics/sprites/monster17.xml: Added animation files for all + * data/graphics/sprites/monster*.xml: Added animation files for all monsters. * src/animation.cpp: The offset values of the Frames of animated sprites are now modified so every frame is drawn centered. - * data/graphics/sprites/hairstyle0.xml, - data/graphics/sprites/hairstyle1.xml, - data/graphics/sprites/hairstyle2.xml, - data/graphics/sprites/hairstyle3.xml, - data/graphics/sprites/hairstyle4.xml, - data/graphics/sprites/hairstyle5.xml, - data/graphics/sprites/hairstyle6.xml, - data/graphics/sprites/hairstyle7.xml: Retuned the offsets of the hair - sprites. + * data/graphics/sprites/hairstyle*.xml: Retuned the offsets of the + hair sprites. * src/animation.cpp: Small stability fix. * src/being.cpp, src/being.h: weapon animation now uses the new animation system. * data/graphics/sprites/player_male_base.xml data/graphics/sprites/player_female_base.xml - data/graphics/sprites/hairstyle0.xml, - data/graphics/sprites/hairstyle1.xml, - data/graphics/sprites/hairstyle2.xml, - data/graphics/sprites/hairstyle3.xml, - data/graphics/sprites/hairstyle4.xml, - data/graphics/sprites/hairstyle5.xml, - data/graphics/sprites/hairstyle6.xml, - data/graphics/sprites/hairstyle7.xml: Tuned walk speed and added bow + data/graphics/sprites/hairstyle*.xml: Tuned walk speed and added bow animations. 2006-07-03 Eugenio Favalli diff --git a/NEWS b/NEWS index cf837a25..2b77dca3 100644 --- a/NEWS +++ b/NEWS @@ -1,12 +1,18 @@ -0.0.21 (.. September 2006) +0.0.21 (17 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 +- Added --playername option for automatic character picking +- Added --configfile option for specifying which configuration file to use +- Added shortcut and middle mouse button for targetting nearest monster +- Added support for map effect overlays +- Fixed FPS limiter - 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 +- Fixed big memory leak when using OpenGL +- Updated to work with Guichan 0.5.0 (older versions no longer supported) 0.0.20 (24 July 2006) - Added new hairstyle, and some fixes to the old ones diff --git a/README b/README index 5fad4312..0313fac3 100644 --- a/README +++ b/README @@ -1,7 +1,7 @@ THE MANA WORLD ============== - Version: 0.0.20 Date: 23/07/2006 + Version: 0.0.21 Date: 17/09/2006 Development team: @@ -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 +- A target nearest monster - H hide all non-sticky windows - G or Z pick up item - Enter focus chat window / send message diff --git a/data/graphics/images/Makefile.am b/data/graphics/images/Makefile.am index e0707698..fb54cb95 100644 --- a/data/graphics/images/Makefile.am +++ b/data/graphics/images/Makefile.am @@ -7,7 +7,12 @@ images_DATA = \ minimap_new_1-1.png \ minimap_new_2-1.png \ minimap_new_3-1.png \ - minimap_new_5-1.png + minimap_new_5-1.png \ + minimap_new_7-1.png \ + minimap_new_9-1.png \ + minimap_new_14-1.png \ + minimap_new_15-1.png \ + minimap_new_16-1.png EXTRA_DIST = \ - $(images_DATA) + $(images_DATA) \ No newline at end of file diff --git a/data/help/changes.txt b/data/help/changes.txt index 2d0f9d86..f8a3eb67 100644 --- a/data/help/changes.txt +++ b/data/help/changes.txt @@ -3,6 +3,37 @@ ##3 === RECENT CHANGES === + 0.0.21 (17 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 option for automatic character picking + - Added --configfile option for specifying which configuration file to use + - Added shortcut and middle mouse button for targetting nearest monster + - Added support for map effect overlays + - Fixed FPS limiter + - 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 + - Fixed big memory leak when using OpenGL + - Updated to work with Guichan 0.5.0 (older versions no longer supported) + + 0.0.20 (24 July 2006) + - Added new hairstyle, and some fixes to the old ones + - Added slider to set FPS limit + - Added visible equipments + - Added new maps and monsters + - Added female characters + - Implemented a new animation system + - Updated the updating system + - Reduced size of textures to stay within the limits of some OpenGL drivers + - Fixed connection not being shut down completely in case of an error + - Fixed min size of a window when resizing + - Fixed some maps issues + - Some fixes to monsters and player graphics + - Minor bug fixes and lots of code cleanups + 0.0.19 (6 March 2006) - Added --username, --password and --defaults command line options diff --git a/data/help/commands.txt b/data/help/commands.txt index 37c77df2..ab93b54e 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 + ##2A##P target nearest monster ##2H##P hide all non-sticky windows ##2G or Z##P pick up item ##2Enter##P focus chat window / send message diff --git a/data/help/header.txt b/data/help/header.txt index d9188a3b..30c1dc93 100644 --- a/data/help/header.txt +++ b/data/help/header.txt @@ -2,7 +2,7 @@ ##1 T H E M A N A W O R L D ##1 ========================================== - ##2Version:##6 0.0.20 ##2Date:##6 23 July 2006 + ##2Version:##6 0.0.21 ##2Date:##6 17 September 2006 ##2 Website: http://themanaworld.org diff --git a/debian/changelog b/debian/changelog index eb420daf..5e71e51e 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,11 @@ +tmw (0.0.21-1) unstable; urgency=low + + * New upstream release: + * Now linked against libguichan-0.5.0. + * Readded the correct music package. + + -- FERREIRA Yohann Wed, 27 Sep 2006 21:40:33 +0200 + tmw (0.0.20-1) unstable; urgency=low * Make use of a own desktop file for the Debian Package. Close the missing icon bug. diff --git a/debian/tmw-music.install b/debian/tmw-music.install index b3494726..b4a17199 100644 --- a/debian/tmw-music.install +++ b/debian/tmw-music.install @@ -1 +1,3 @@ data/music/*.ogg usr/share/games/tmw/data/music +data/music/*.mp3 usr/share/games/tmw/data/music + diff --git a/src/Makefile.am b/src/Makefile.am index 01f8a3b2..b621c63e 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -2,6 +2,8 @@ AUTOMAKE_OPTIONS = subdir-objects bin_PROGRAMS = tmw tmw_SOURCES = graphic/imagerect.h \ + gui/widgets/dropdown.cpp \ + gui/widgets/dropdown.h \ gui/browserbox.cpp \ gui/browserbox.h \ gui/buddywindow.cpp \ @@ -77,6 +79,7 @@ tmw_SOURCES = graphic/imagerect.h \ gui/register.h \ gui/scrollarea.cpp \ gui/scrollarea.h \ + gui/selectionlistener.h \ gui/sell.cpp \ gui/sell.h \ gui/serverdialog.cpp \ diff --git a/src/animatedsprite.cpp b/src/animatedsprite.cpp index f984d13f..3815f04a 100644 --- a/src/animatedsprite.cpp +++ b/src/animatedsprite.cpp @@ -18,7 +18,7 @@ * 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 $ + * $Id$ */ #include "animatedsprite.h" @@ -90,14 +90,9 @@ AnimatedSprite::AnimatedSprite(const std::string& animationFile, int variant): // get action else if (xmlStrEqual(node->name, BAD_CAST "action")) { - std::string name = getProperty(node, "name", ""); + std::string actionName = 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(), @@ -107,10 +102,25 @@ AnimatedSprite::AnimatedSprite(const std::string& animationFile, int variant): continue; } - Action *action = new Action(); + SpriteAction actionType = makeSpriteAction(actionName); + if (actionType == ACTION_INVALID) + { + logger->log("Warning: Unknown action \"%s\" defined in %s", + actionName.c_str(), + animationFile.c_str()); + continue; + } + Action *action = new Action(); action->setSpriteset(mSpritesets[imageset]); - mActions[makeSpriteAction(name)] = action; + mActions[actionType] = action; + + // When first action set it as default direction + if (mActions.empty()) + { + mActions[ACTION_DEFAULT] = action; + } + // get animations for (xmlNodePtr animationNode = node->xmlChildrenNode; @@ -121,9 +131,20 @@ AnimatedSprite::AnimatedSprite(const std::string& animationFile, int variant): if (!xmlStrEqual(animationNode->name, BAD_CAST "animation")) continue; - std::string dir = getProperty(animationNode, "direction", ""); + std::string directionName = getProperty(animationNode, "direction", ""); + + SpriteDirection directionType = makeSpriteDirection(directionName); + if (directionType == DIRECTION_INVALID) + { + logger->log("Warning: Unknown direction \"%s\" defined for action %s in %s", + directionName.c_str(), + actionName.c_str(), + animationFile.c_str()); + continue; + } + Animation *animation = new Animation(); - action->setAnimation(makeSpriteDirection(dir), animation); + action->setAnimation(directionType, animation); // Get animation phases for (xmlNodePtr phaseNode = animationNode->xmlChildrenNode; @@ -156,12 +177,17 @@ AnimatedSprite::AnimatedSprite(const std::string& animationFile, int variant): start++; } } + else if (xmlStrEqual(phaseNode->name, BAD_CAST "end")) + { + animation->addTerminator(); + }; } // for phaseNode } // for animationNode } // if "" else if "" } // for node // Complete missing actions + substituteAction(ACTION_STAND, ACTION_DEFAULT); substituteAction(ACTION_WALK, ACTION_STAND); substituteAction(ACTION_WALK, ACTION_RUN); substituteAction(ACTION_ATTACK, ACTION_STAND); @@ -247,7 +273,7 @@ AnimatedSprite::reset() } void -AnimatedSprite::play(SpriteAction action, int time) +AnimatedSprite::play(SpriteAction action) { ActionIterator i = mActions.find(action); @@ -262,31 +288,31 @@ AnimatedSprite::play(SpriteAction action, int time) 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; + //mAction->reset(); } } void AnimatedSprite::update(int time) { + bool notFinished = true; // 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 not enough time has passed yet, do nothing if (time > mLastTime && mAction) { Animation *animation = mAction->getAnimation(mDirection); - animation->update((unsigned int)((time - mLastTime) * mSpeed)); + if (animation != NULL) { + notFinished = animation->update((unsigned int)(time - mLastTime));} mLastTime = time; } + + if (!notFinished) + { + play(ACTION_STAND); + } } bool @@ -296,6 +322,8 @@ AnimatedSprite::draw(Graphics* graphics, Sint32 posX, Sint32 posY) const return false; Animation *animation = mAction->getAnimation(mDirection); + if (animation == NULL) return false; + int phase = animation->getCurrentPhase(); if (phase < 0) return false; @@ -322,6 +350,9 @@ AnimatedSprite::getHeight() const SpriteAction AnimatedSprite::makeSpriteAction(const std::string& action) { + if (action == "" || action == "default") { + return ACTION_DEFAULT; + } if (action == "stand") { return ACTION_STAND; } @@ -365,14 +396,17 @@ AnimatedSprite::makeSpriteAction(const std::string& action) return ACTION_DEAD; } else { - return ACTION_DEFAULT; + return ACTION_INVALID; } } SpriteDirection AnimatedSprite::makeSpriteDirection(const std::string& direction) { - if (direction == "up") { + if (direction == "" || direction == "default") { + return DIRECTION_DEFAULT; + } + else if (direction == "up") { return DIRECTION_UP; } else if (direction == "left") { @@ -381,7 +415,10 @@ AnimatedSprite::makeSpriteDirection(const std::string& direction) else if (direction == "right") { return DIRECTION_RIGHT; } - else { + else if (direction == "down") { return DIRECTION_DOWN; } + else { + return DIRECTION_INVALID; + }; } diff --git a/src/animatedsprite.h b/src/animatedsprite.h index b73bdb5c..bda612ab 100644 --- a/src/animatedsprite.h +++ b/src/animatedsprite.h @@ -18,7 +18,7 @@ * 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 $ + * $Id$ */ #ifndef _TMW_ANIMATEDSPRITE_H @@ -50,15 +50,18 @@ enum SpriteAction ACTION_SIT, ACTION_SLEEP, ACTION_HURT, - ACTION_DEAD + ACTION_DEAD, + ACTION_INVALID }; enum SpriteDirection { - DIRECTION_DOWN = 0, + DIRECTION_DEFAULT = 0, + DIRECTION_DOWN, DIRECTION_UP, DIRECTION_LEFT, - DIRECTION_RIGHT + DIRECTION_RIGHT, + DIRECTION_INVALID }; /** @@ -85,11 +88,10 @@ class AnimatedSprite reset(); /** - * Plays an action using the current direction that will have a - * duration of the specified time, 0 means default. + * Plays an action using the current direction */ void - play(SpriteAction action, int time = 0); + play(SpriteAction action); /** * Inform the animation of the passed time so that it can output the diff --git a/src/animation.cpp b/src/animation.cpp index c1b27ebd..98a4abb8 100644 --- a/src/animation.cpp +++ b/src/animation.cpp @@ -39,45 +39,68 @@ Animation::reset() iCurrentPhase = mAnimationPhases.begin(); } -void + +bool Animation::update(unsigned int time) { mTime += time; if (mAnimationPhases.empty()) - return; + return true; + if (isTerminator(*iCurrentPhase)) + return false; unsigned int delay = iCurrentPhase->delay; - if (!delay) - return; while (mTime > delay) { + if (!delay) + return true; mTime -= delay; iCurrentPhase++; if (iCurrentPhase == mAnimationPhases.end()) { iCurrentPhase = mAnimationPhases.begin(); } + if (isTerminator(*iCurrentPhase)) + return false; + delay = iCurrentPhase->delay; } + return true; } + int Animation::getCurrentPhase() const { 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 = { image, delay, offsetX, offsetY }; + AnimationPhase newPhase = { image, delay, offsetX, offsetY}; mAnimationPhases.push_back(newPhase); //reset animation circle iCurrentPhase = mAnimationPhases.begin(); } +void +Animation::addTerminator() +{ + AnimationPhase terminator = { -1, 0, 0, 0}; + mAnimationPhases.push_back(terminator); + iCurrentPhase = mAnimationPhases.begin(); +} + +bool +Animation::isTerminator(AnimationPhase candidate) +{ + return (candidate.image < 0); +} + int Animation::getLength() { diff --git a/src/animation.h b/src/animation.h index 60dcd287..605d8cb1 100644 --- a/src/animation.h +++ b/src/animation.h @@ -61,10 +61,25 @@ class Animation void reset(); + /** + * Appends a new animation at the end of the sequence + */ void addPhase(int image, unsigned int delay, int offsetX, int offsetY); + /** + * Appends an animation terminator that states that the animation + * should not loop + */ void + addTerminator(); + + /** + * Updates animation phase. + * true indicates a still running animation while false indicates a + * finished animation + */ + bool update(unsigned int time); int @@ -89,6 +104,7 @@ class Animation getLength(); protected: + static bool isTerminator(AnimationPhase); std::list mAnimationPhases; std::list::iterator iCurrentPhase; unsigned int mTime; diff --git a/src/being.cpp b/src/being.cpp index 982b0ebf..4d542753 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -331,10 +331,24 @@ Being::setAction(Uint8 action) currentAction = ACTION_ATTACK; break; } + for (int i = 0; i < VECTOREND_SPRITE; i++) + { + if (mSprites[i]) + { + mSprites[i]->reset(); + } + } }; break; case MONSTER_ATTACK: currentAction = ACTION_ATTACK; + for (int i = 0; i < VECTOREND_SPRITE; i++) + { + if (mSprites[i]) + { + mSprites[i]->reset(); + } + } break; case DEAD: currentAction = ACTION_DEAD; @@ -346,16 +360,7 @@ Being::setAction(Uint8 action) 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 + if (mSprites[i]) { mSprites[i]->play(currentAction); } diff --git a/src/beingmanager.cpp b/src/beingmanager.cpp index d2db055a..30b68ee2 100644 --- a/src/beingmanager.cpp +++ b/src/beingmanager.cpp @@ -113,9 +113,9 @@ Being* BeingManager::findBeing(Uint16 x, Uint16 y, Being::Type type) return (i == mBeings.end()) ? NULL : *i; } -Beings* BeingManager::getAll() +Beings& BeingManager::getAll() { - return &mBeings; + return mBeings; } void BeingManager::logic() @@ -153,3 +153,28 @@ void BeingManager::clear() mBeings.push_back(player_node); } } + +Being* BeingManager::findNearestLivingBeing(Uint16 x, Uint16 y, int maxdist, + Being::Type type) +{ + Being *closestBeing = NULL; + int dist = 0; + + for (BeingIterator i = mBeings.begin(); i != mBeings.end(); i++) + { + Being *being = (*i); + int d = abs(being->mX - x) + abs(being->mY - y); + + if ((being->getType() == type || type == Being::UNKNOWN) + && (d < dist || closestBeing == NULL) // it is closer + && being->mAction != Being::DEAD // no dead beings + && being->mAction != Being::MONSTER_DEAD + ) + { + dist = d; + closestBeing = being; + } + } + + return (maxdist >= dist) ? closestBeing : NULL; +} diff --git a/src/beingmanager.h b/src/beingmanager.h index c32884a0..15a347de 100644 --- a/src/beingmanager.h +++ b/src/beingmanager.h @@ -46,29 +46,38 @@ class BeingManager void setPlayer(LocalPlayer *player); /** - * Create a being and add it to the list of beings + * Create a being and add it to the list of beings. */ Being* createBeing(Uint16 id, Uint16 job); /** - * Remove a Being + * Remove a Being. */ void destroyBeing(Being *being); /** - * Return a specific id Being + * Return a specific id Being. */ Being* findBeing(Uint16 id); /** - * Return a being at specific coordinates + * Return a being at specific coordinates. */ Being* findBeing(Uint16 x, Uint16 y, Being::Type type = Being::UNKNOWN); + /** + * Return a being nearest to specific coordinates. + * + * \param maxdist maximal distance. If minimal distance is larger, + * no being is returned + */ + Being* findNearestLivingBeing(Uint16 x, Uint16 y, int maxdist, + Being::Type type = Being::UNKNOWN); + /** * Returns the whole list of beings */ - Beings* getAll(); + Beings& getAll(); /** * Logic. diff --git a/src/engine.cpp b/src/engine.cpp index 253a8288..231313c4 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -266,8 +266,8 @@ void Engine::draw(Graphics *graphics) } // Draw player nickname, speech, and emotion sprite as needed - Beings *beings = beingManager->getAll(); - for (BeingIterator i = beings->begin(); i != beings->end(); i++) + Beings &beings = beingManager->getAll(); + for (BeingIterator i = beings.begin(); i != beings.end(); i++) { (*i)->drawSpeech(graphics, -camera_x, -camera_y); (*i)->drawName(graphics, -camera_x, -camera_y); diff --git a/src/floor_item.cpp b/src/floor_item.cpp index edd5d4a7..9a179a21 100644 --- a/src/floor_item.cpp +++ b/src/floor_item.cpp @@ -42,7 +42,7 @@ FloorItem::FloorItem(unsigned int id, mMap(map) { // Retrieve item image from item info - mImage = itemDb->getItemInfo(itemId)->getImage(); + mImage = itemDb->getItemInfo(itemId).getImage(); // Add ourselves to the map mSpriteIterator = mMap->addSprite(this); @@ -50,6 +50,6 @@ FloorItem::FloorItem(unsigned int id, FloorItem::~FloorItem() { - // Remove and delete the representative sprite + // Remove ourselves from the map mMap->removeSprite(mSpriteIterator); } diff --git a/src/game.cpp b/src/game.cpp index f5ebe095..5e4c24c2 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -202,9 +202,9 @@ void createGuiWindows() minimap->getHeight() + 30);*/ // Set initial window visibility - chatWindow->setSticky(true); - miniStatusWindow->setSticky(true); - menuWindow->setSticky(true); +// chatWindow->setSticky(true); +// miniStatusWindow->setSticky(true); +// menuWindow->setSticky(true); chatWindow->setVisible(true); miniStatusWindow->setVisible(true); @@ -277,6 +277,10 @@ Game::Game(): SDL_AddTimer(10, nextTick, NULL); // Logic counter SDL_AddTimer(1000, nextSecond, NULL); // Seconds counter + // Initialize frame limiting + config.addListener("fpslimit", this); + optionChanged("fpslimit"); + // Initialize beings beingManager->setPlayer(player_node); @@ -339,12 +343,23 @@ bool saveScreenshot(SDL_Surface *screenshot) return ImageWriter::writePNG(screenshot, filename.str()); } +void Game::optionChanged(const std::string &name) +{ + int fpsLimit = (int) config.getValue("fpslimit", 0); + + // Calculate new minimum frame time + mMinFrameTime = fpsLimit ? 1000 / fpsLimit : 0; + + // Reset draw time to current time + mDrawTime = tick_time * 10; +} + void Game::logic() { + // mDrawTime has a higher granularity than gameTime in order to be able to + // work with minimum frame durations in milliseconds. int gameTime = tick_time; - int drawTime = tick_time * 10; - int delta = 0; - int fpsLimit = 0; + mDrawTime = tick_time * 10; while (!done) { @@ -356,23 +371,35 @@ void Game::logic() gameTime++; } + // This is done because at some point tick_time will wrap. gameTime = tick_time; - fpsLimit = (int)config.getValue("fpslimit", 50); - delta = fpsLimit ? 1000 / fpsLimit : 0; - - // Update the screen when application is active, delay otherwise - if (SDL_GetAppState() & SDL_APPACTIVE && - (abs(tick_time * 10 - drawTime) >= delta)) + // Update the screen when application is active, delay otherwise. + if (SDL_GetAppState() & SDL_APPACTIVE) { - frame++; - engine->draw(graphics); - graphics->updateScreen(); - drawTime += delta; + // Draw a frame if either frames are not limited or enough time has + // passed since the last frame. + if (!mMinFrameTime || + get_elapsed_time(mDrawTime / 10) > mMinFrameTime) + { + frame++; + engine->draw(graphics); + graphics->updateScreen(); + mDrawTime += mMinFrameTime; + + // Make sure to wrap mDrawTime, since tick_time will wrap. + if (mDrawTime > MAX_TIME * 10) + mDrawTime -= MAX_TIME * 10; + } + else + { + SDL_Delay(10); + } } else { SDL_Delay(10); + mDrawTime = tick_time * 10; } // Handle network stuff @@ -463,10 +490,7 @@ void Game::handleInput() // 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); @@ -474,12 +498,9 @@ void Game::handleInput() 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; @@ -679,6 +700,18 @@ void Game::handleInput() player_node->attack(target, newTarget); } + // Target the nearest monster if 'a' pressed + if (keys[SDLK_a]) + { + Being *target = + beingManager->findNearestLivingBeing(x, y, 20, Being::MONSTER); + + if (target) + { + player_node->setTarget(target); + } + } + if (joystick) { if (joystick->buttonPressed(1)) diff --git a/src/game.h b/src/game.h index 7330052a..19a6054a 100644 --- a/src/game.h +++ b/src/game.h @@ -27,6 +27,8 @@ #include #include +#include "configlistener.h" + #define SPEECH_TIME 80 #define SPEECH_MAX_TIME 100 @@ -36,7 +38,7 @@ extern std::string map_path; extern volatile int fps; extern volatile int tick_time; -class Game +class Game : public ConfigListener { public: Game(); @@ -46,7 +48,15 @@ class Game void handleInput(); - protected: + void optionChanged(const std::string &name); + + private: + /** Used to determine whether to draw the next frame. */ + int mDrawTime; + + /** The minimum frame time (used for frame limiting). */ + int mMinFrameTime; + typedef std::auto_ptr MessageHandlerPtr; MessageHandlerPtr mBeingHandler; MessageHandlerPtr mBuySellHandler; @@ -61,8 +71,7 @@ class Game }; /** - * Returns elapsed time. (Warning: very unsafe function, it supposes the delay - * is always < 10 seconds) + * Returns elapsed time. (Warning: supposes the delay is always < 100 seconds) */ int get_elapsed_time(int start_time); diff --git a/src/gui/buy.cpp b/src/gui/buy.cpp index 165fa7dc..ae779503 100644 --- a/src/gui/buy.cpp +++ b/src/gui/buy.cpp @@ -91,6 +91,7 @@ BuyDialog::BuyDialog(): mSlider->setEventId("slider"); mItemList->addActionListener(this); + mItemList->addSelectionListener(this); mSlider->addActionListener(this); add(mScrollArea); @@ -140,7 +141,8 @@ void BuyDialog::addItem(short id, int price) { ITEM_SHOP item_shop; - item_shop.name = itemDb->getItemInfo(id)->getName() + " " + toString(price) + " GP"; + item_shop.name = itemDb->getItemInfo(id).getName() + " " + + toString(price) + " GP"; item_shop.price = price; item_shop.id = id; @@ -152,7 +154,8 @@ void BuyDialog::action(const std::string &eventId, gcn::Widget *widget) { int selectedItem = mItemList->getSelected(); - if (eventId == "item") { + if (eventId == "item") + { // Reset amount of items and update labels mAmountItems = 0; mSlider->setValue(0); @@ -175,23 +178,27 @@ void BuyDialog::action(const std::string &eventId, gcn::Widget *widget) mIncreaseButton->setEnabled(mMaxItems > 0); mSlider->setEnabled(mMaxItems > 0); } - else if (eventId == "quit") { + else if (eventId == "quit") + { setVisible(false); current_npc = 0; } // The following actions require a valid selection - if (selectedItem < 0 || selectedItem >= int(mShopItems->size())) { + if (selectedItem < 0 || selectedItem >= int(mShopItems->size())) + { return; } bool updateButtonsAndLabels = false; - if (eventId == "slider") { + if (eventId == "slider") + { mAmountItems = (int)(mSlider->getValue() * mMaxItems); updateButtonsAndLabels = true; } - else if (eventId == "+") { + else if (eventId == "+") + { if (mAmountItems < mMaxItems) { mAmountItems++; } else { @@ -201,7 +208,8 @@ void BuyDialog::action(const std::string &eventId, gcn::Widget *widget) mSlider->setValue(double(mAmountItems)/double(mMaxItems)); updateButtonsAndLabels = true; } - else if (eventId == "-") { + else if (eventId == "-") + { if (mAmountItems > 0) { mAmountItems--; } else { @@ -211,7 +219,7 @@ void BuyDialog::action(const std::string &eventId, gcn::Widget *widget) mSlider->setValue(double(mAmountItems)/double(mMaxItems)); updateButtonsAndLabels = true; } - // TODO Actually we'd have a bug elsewhere if this check for the number + // TODO: Actually we'd have a bug elsewhere if this check for the number // 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 && @@ -239,7 +247,8 @@ void BuyDialog::action(const std::string &eventId, gcn::Widget *widget) } // If anything has changed, we have to update the buttons and labels - if (updateButtonsAndLabels) { + if (updateButtonsAndLabels) + { // Update buttons mIncreaseButton->setEnabled(mAmountItems < mMaxItems); mDecreaseButton->setEnabled(mAmountItems > 0); @@ -255,19 +264,21 @@ void BuyDialog::action(const std::string &eventId, gcn::Widget *widget) } } -void BuyDialog::mouseClick(int x, int y, int button, int count) +void BuyDialog::selectionChanged(const SelectionEvent &event) { - Window::mouseClick(x, y, button, count); - int selectedItem = mItemList->getSelected(); + if (selectedItem > -1) { - int itemId = mShopItems->at(selectedItem).id; - ItemInfo *itemInfo = itemDb->getItemInfo(itemId); + const ItemInfo &info = + itemDb->getItemInfo(mShopItems->at(selectedItem).id); - mItemDescLabel->setCaption("Description: " + - itemInfo->getDescription()); - mItemEffectLabel->setCaption("Effect: " + - itemInfo->getEffect()); + mItemDescLabel->setCaption("Description: " + info.getDescription()); + mItemEffectLabel->setCaption("Effect: " + info.getEffect()); + } + else + { + mItemDescLabel->setCaption("Description:"); + mItemEffectLabel->setCaption("Effect:"); } } diff --git a/src/gui/buy.h b/src/gui/buy.h index 0ddea4c4..f5c163e1 100644 --- a/src/gui/buy.h +++ b/src/gui/buy.h @@ -27,17 +27,19 @@ #include #include "window.h" +#include "selectionlistener.h" #include "../guichanfwd.h" class ShopItems; +class ListBox; /** * The buy dialog. * * \ingroup Interface */ -class BuyDialog : public Window, public gcn::ActionListener +class BuyDialog : public Window, public gcn::ActionListener, SelectionListener { public: /** @@ -78,9 +80,11 @@ class BuyDialog : public Window, public gcn::ActionListener int getNumberOfElements(); /** - * Mouse callback + * Updates the labels according to the selected item. + * + * @see SelectionListener::selectionChanged */ - void mouseClick(int x, int y, int buton, int count); + void selectionChanged(const SelectionEvent &event); /** * Returns the name of item number i in the shop inventory. @@ -92,7 +96,7 @@ class BuyDialog : public Window, public gcn::ActionListener gcn::Button *mQuitButton; gcn::Button *mIncreaseButton; gcn::Button *mDecreaseButton; - gcn::ListBox *mItemList; + ListBox *mItemList; gcn::ScrollArea *mScrollArea; gcn::Label *mItemDescLabel; gcn::Label *mItemEffectLabel; diff --git a/src/gui/char_select.cpp b/src/gui/char_select.cpp index 042a5be8..3e6c4a5f 100644 --- a/src/gui/char_select.cpp +++ b/src/gui/char_select.cpp @@ -224,6 +224,28 @@ void CharSelectDialog::logic() updatePlayerInfo(); } +bool CharSelectDialog::selectByName(const std::string &name) +{ + if (mCharInfo->isLocked()) + return false; + + unsigned int oldPos = mCharInfo->getPos(); + + mCharInfo->select(0); + do { + LocalPlayer *player = mCharInfo->getEntry(); + + if (player && player->getName() == name) + return true; + + mCharInfo->next(); + } while (mCharInfo->getPos()); + + mCharInfo->select(oldPos); + + return false; +} + std::string CharSelectDialog::getName() { return mNameLabel->getCaption(); diff --git a/src/gui/char_select.h b/src/gui/char_select.h index 06881bb5..6d9d1a83 100644 --- a/src/gui/char_select.h +++ b/src/gui/char_select.h @@ -54,6 +54,8 @@ class CharSelectDialog : public Window, public gcn::ActionListener void logic(); + bool selectByName(const std::string &name); + /** * Returns name of selected player */ diff --git a/src/gui/equipmentwindow.cpp b/src/gui/equipmentwindow.cpp index 2cbffde4..ec525c47 100644 --- a/src/gui/equipmentwindow.cpp +++ b/src/gui/equipmentwindow.cpp @@ -65,7 +65,7 @@ void EquipmentWindow::draw(gcn::Graphics *graphics) continue; } - image = item->getInfo()->getImage(); + image = item->getInfo().getImage(); dynamic_cast(graphics)->drawImage( image, 36 * (i % 4) + 10, 36 * (i / 4) + 25); } @@ -76,7 +76,7 @@ void EquipmentWindow::draw(gcn::Graphics *graphics) return; } - image = item->getInfo()->getImage(); + image = item->getInfo().getImage(); dynamic_cast(graphics)->drawImage(image, 160, 25); graphics->drawText(toString(item->getQuantity()), 170, 62, diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index ecf81712..33852f2b 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -322,6 +322,19 @@ Gui::mousePress(int mx, int my, int button) } } } + + if (button == gcn::MouseInput::MIDDLE) + { + // Find the being nearest to the clicked position + Being *target = beingManager->findNearestLivingBeing( + tilex, tiley, + 20, Being::MONSTER); + + if (target) + { + player_node->setTarget(target); + } + } } void diff --git a/src/gui/inventorywindow.cpp b/src/gui/inventorywindow.cpp index 063e8836..ea0fd8c0 100644 --- a/src/gui/inventorywindow.cpp +++ b/src/gui/inventorywindow.cpp @@ -55,6 +55,8 @@ InventoryWindow::InventoryWindow(): mDropButton = new Button("Drop", "drop", this); mItems = new ItemContainer(player_node->mInventory.get()); + mItems->addSelectionListener(this); + mInvenScroll = new ScrollArea(mItems); mInvenScroll->setPosition(8, 8); mInvenScroll->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER); @@ -123,33 +125,46 @@ void InventoryWindow::action(const std::string &eventId, gcn::Widget *widget) } } -void InventoryWindow::mouseClick(int x, int y, int button, int count) +void InventoryWindow::selectionChanged(const SelectionEvent &event) { - Window::mouseClick(x, y, button, count); - Item *item = mItems->getItem(); - if (!item) { - return; + // Update name, effect and description + if (!item) + { + mItemNameLabel->setCaption("Name:"); + mItemEffectLabel->setCaption("Effect:"); + mItemDescriptionLabel->setCaption("Description:"); + } + else + { + const ItemInfo& itemInfo = item->getInfo(); + std::string SomeText; + SomeText = "Name: " + itemInfo.getName(); + mItemNameLabel->setCaption(SomeText); + SomeText = "Effect: " + itemInfo.getEffect(); + mItemEffectLabel->setCaption(SomeText); + SomeText = "Description: " + itemInfo.getDescription(); + mItemDescriptionLabel->setCaption(SomeText); + + mItemNameLabel->adjustSize(); + mItemEffectLabel->adjustSize(); + mItemDescriptionLabel->adjustSize(); } +} - // Show Name and Description - std::string SomeText; - SomeText = "Name: " + item->getInfo()->getName(); - mItemNameLabel->setCaption(SomeText); - mItemNameLabel->adjustSize(); - SomeText = "Effect: " + item->getInfo()->getEffect(); - mItemEffectLabel->setCaption(SomeText); - mItemEffectLabel->adjustSize(); - SomeText = "Description: " + item->getInfo()->getDescription(); - mItemDescriptionLabel->setCaption(SomeText); - mItemDescriptionLabel->adjustSize(); +void InventoryWindow::mouseClick(int x, int y, int button, int count) +{ + Window::mouseClick(x, y, button, count); if (button == gcn::MouseInput::RIGHT) { - /* - * convert relative to the window coordinates to - * absolute screen coordinates + Item *item = mItems->getItem(); + + if (!item) return; + + /* Convert relative to the window coordinates to + * absolute screen coordinates. */ int mx = x + getX(); int my = y + getY(); @@ -223,11 +238,6 @@ void InventoryWindow::loadWindowState() updateWidgets(); } -void InventoryWindow::setDefaultSize(int defaultX, int defaultY, int defaultWidth, int defaultHeight) -{ - Window::setDefaultSize(defaultX, defaultY, defaultWidth, defaultHeight); -} - void InventoryWindow::resetToDefaultSize() { Window::resetToDefaultSize(); diff --git a/src/gui/inventorywindow.h b/src/gui/inventorywindow.h index da7a7ef2..d46e91e7 100644 --- a/src/gui/inventorywindow.h +++ b/src/gui/inventorywindow.h @@ -27,6 +27,7 @@ #include #include "window.h" +#include "selectionlistener.h" #include "../guichanfwd.h" @@ -38,7 +39,7 @@ class ItemContainer; * * \ingroup Interface */ -class InventoryWindow : public Window, gcn::ActionListener +class InventoryWindow : public Window, gcn::ActionListener, SelectionListener { public: /** @@ -47,14 +48,14 @@ class InventoryWindow : public Window, gcn::ActionListener InventoryWindow(); /** - * Logic (updates buttons and weight information) + * Logic (updates buttons and weight information). */ void logic(); /** * Called when receiving actions from the widgets. */ - void action(const std::string& eventId, gcn::Widget* widget); + void action(const std::string &eventId, gcn::Widget *widget); void mouseClick(int x, int y, int button, int count); @@ -64,14 +65,19 @@ class InventoryWindow : public Window, gcn::ActionListener void loadWindowState(); - void setDefaultSize(int defaultX, int defaultY, int defaultWidth, int defaultHeight); - void resetToDefaultSize(); + /** + * Updates labels to currently selected item. + * + * @see SelectionListener::selectionChanged. + */ + void selectionChanged(const SelectionEvent &event); + private: - void updateButtons(); /** Updates button states */ + void updateButtons(); /**< Updates button states. */ - void updateWidgets(); /** Updates widgets size/position */ + void updateWidgets(); /**< Updates widgets size/position. */ ItemContainer *mItems; diff --git a/src/gui/itemcontainer.cpp b/src/gui/itemcontainer.cpp index c7c55fd9..5bcd000d 100644 --- a/src/gui/itemcontainer.cpp +++ b/src/gui/itemcontainer.cpp @@ -25,6 +25,8 @@ #include +#include "selectionlistener.h" + #include "../graphics.h" #include "../inventory.h" #include "../item.h" @@ -38,14 +40,14 @@ #include "../utils/tostring.h" ItemContainer::ItemContainer(Inventory *inventory): - mInventory(inventory) + mInventory(inventory), + mSelectedItem(NULL) { ResourceManager *resman = ResourceManager::getInstance(); mSelImg = resman->getImage("graphics/gui/selection.png"); if (!mSelImg) logger->error("Unable to load selection.png"); - mSelectedItem = 0; // No item selected mMaxItems = mInventory->getLastUsedSlot() - 1; // Count from 0, usage from 2 addMouseListener(this); @@ -84,7 +86,7 @@ void ItemContainer::draw(gcn::Graphics* graphics) // sure somewhere else) if (mSelectedItem && mSelectedItem->getQuantity() <= 0) { - mSelectedItem = 0; + selectNone(); } /* @@ -111,7 +113,7 @@ void ItemContainer::draw(gcn::Graphics* graphics) // Draw item icon Image* image; - if ((image = item->getInfo()->getImage()) != NULL) + if ((image = item->getInfo().getImage()) != NULL) { dynamic_cast(graphics)->drawImage( image, itemX, itemY); @@ -150,7 +152,28 @@ Item* ItemContainer::getItem() void ItemContainer::selectNone() { - mSelectedItem = 0; + setSelectedItem(NULL); +} + +void ItemContainer::setSelectedItem(Item *item) +{ + if (mSelectedItem != item) + { + mSelectedItem = item; + fireSelectionChangedEvent(); + } +} + +void ItemContainer::fireSelectionChangedEvent() +{ + SelectionEvent event(this); + SelectionListeners::iterator i_end = mListeners.end(); + SelectionListeners::iterator i; + + for (i = mListeners.begin(); i != i_end; ++i) + { + (*i)->selectionChanged(event); + } } void ItemContainer::mousePress(int mx, int my, int button) @@ -166,6 +189,6 @@ void ItemContainer::mousePress(int mx, int my, int button) if (index > INVENTORY_SIZE) { index = INVENTORY_SIZE - 1; } - mSelectedItem = mInventory->getItem(index); + setSelectedItem(mInventory->getItem(index)); } } diff --git a/src/gui/itemcontainer.h b/src/gui/itemcontainer.h index f52f37ec..a2d5f0f7 100644 --- a/src/gui/itemcontainer.h +++ b/src/gui/itemcontainer.h @@ -27,9 +27,12 @@ #include #include +#include + class Image; class Inventory; class Item; +class SelectionListener; /** * An item container. Used to show items in inventory and trade dialog. @@ -76,16 +79,46 @@ class ItemContainer : public gcn::Widget, public gcn::MouseListener Item* getItem(); /** - * Set selected item to -1. + * Sets selected item to NULL. */ void selectNone(); + /** + * Adds a listener to the list that's notified each time a change to + * the selection occurs. + */ + void addSelectionListener(SelectionListener *listener) + { + mListeners.push_back(listener); + } + + /** + * Removes a listener from the list that's notified each time a change + * to the selection occurs. + */ + void removeSelectionListener(SelectionListener *listener) + { + mListeners.remove(listener); + } + private: + /** + * Sets the currently selected item. + */ + void setSelectedItem(Item *item); + + /** + * Sends out selection events to the list of selection listeners. + */ + void fireSelectionChangedEvent(); + Inventory *mInventory; Image *mSelImg; Item *mSelectedItem; int mMaxItems; + + std::list mListeners; }; #endif diff --git a/src/gui/listbox.cpp b/src/gui/listbox.cpp index df03b81b..14626d06 100644 --- a/src/gui/listbox.cpp +++ b/src/gui/listbox.cpp @@ -23,12 +23,16 @@ #include "listbox.h" +#include "selectionlistener.h" + #include #include #include +#include ListBox::ListBox(gcn::ListModel *listModel): - gcn::ListBox(listModel) + gcn::ListBox(listModel), + mMousePressed(false) { } @@ -45,8 +49,8 @@ void ListBox::draw(gcn::Graphics *graphics) // Draw rectangle below the selected list element if (mSelected >= 0) { - graphics->fillRectangle( - gcn::Rectangle(0, fontHeight * mSelected, getWidth(), fontHeight)); + graphics->fillRectangle(gcn::Rectangle(0, fontHeight * mSelected, + getWidth(), fontHeight)); } // Draw the list elements @@ -55,3 +59,50 @@ void ListBox::draw(gcn::Graphics *graphics) graphics->drawText(mListModel->getElementAt(i), 1, y); } } + +void ListBox::setSelected(int selected) +{ + gcn::ListBox::setSelected(selected); + fireSelectionChangedEvent(); +} + +void ListBox::mousePress(int x, int y, int button) +{ + gcn::ListBox::mousePress(x, y, button); + + if (button == gcn::MouseInput::LEFT && hasMouse()) + { + mMousePressed = true; + } +} + +void ListBox::mouseRelease(int x, int y, int button) +{ + gcn::ListBox::mouseRelease(x, y, button); + + mMousePressed = false; +} + +void ListBox::mouseMotion(int x, int y) +{ + gcn::ListBox::mouseMotion(x, y); + + // Pretend mouse is pressed continuously while dragged. Causes list + // selection to be updated as is default in many GUIs. + if (mMousePressed) + { + mousePress(x, y, gcn::MouseInput::LEFT); + } +} + +void ListBox::fireSelectionChangedEvent() +{ + SelectionEvent event(this); + SelectionListeners::iterator i_end = mListeners.end(); + SelectionListeners::iterator i; + + for (i = mListeners.begin(); i != i_end; ++i) + { + (*i)->selectionChanged(event); + } +} diff --git a/src/gui/listbox.h b/src/gui/listbox.h index 5999f7a7..c1932f54 100644 --- a/src/gui/listbox.h +++ b/src/gui/listbox.h @@ -26,10 +26,12 @@ #include +class SelectionListener; + /** * A list box, meant to be used inside a scroll area. Same as the Guichan list * box except this one doesn't have a background, instead completely relying - * on the scroll area. + * on the scroll area. It also adds selection listener functionality. * * \ingroup GUI */ @@ -45,6 +47,43 @@ class ListBox : public gcn::ListBox * Draws the list box. */ void draw(gcn::Graphics *graphics); + + void mousePress(int x, int y, int button); + void mouseRelease(int x, int y, int button); + void mouseMotion(int x, int y); + + /** + * Adds a listener to the list that's notified each time a change to + * the selection occurs. + */ + void addSelectionListener(SelectionListener *listener) + { + mListeners.push_back(listener); + } + + /** + * Removes a listener from the list that's notified each time a change + * to the selection occurs. + */ + void removeSelectionListener(SelectionListener *listener) + { + mListeners.remove(listener); + } + + /** + * Sets the index of the selected element. + */ + void setSelected(int selected); + + private: + /** + * Sends out selection events to the list of selection listeners. + */ + void fireSelectionChangedEvent(); + + bool mMousePressed; /**< Keeps track of mouse pressed status. */ + + std::list mListeners; }; #endif diff --git a/src/gui/minimap.cpp b/src/gui/minimap.cpp index db6d4f15..69c5eb6e 100644 --- a/src/gui/minimap.cpp +++ b/src/gui/minimap.cpp @@ -76,10 +76,10 @@ void Minimap::draw(gcn::Graphics *graphics) mMapImage, getPadding(), getTitleBarHeight()); } - Beings *beings = beingManager->getAll(); + Beings &beings = beingManager->getAll(); BeingIterator bi; - for (bi = beings->begin(); bi != beings->end(); bi++) + for (bi = beings.begin(); bi != beings.end(); bi++) { Being *being = (*bi); int dotSize = 1; diff --git a/src/gui/playerbox.cpp b/src/gui/playerbox.cpp index ba97d54c..46cd7e85 100644 --- a/src/gui/playerbox.cpp +++ b/src/gui/playerbox.cpp @@ -97,7 +97,7 @@ void PlayerBox::draw(gcn::Graphics *graphics) if (mHairStyle > 0 && mHairColor < NR_HAIR_COLORS && mHairStyle < NR_HAIR_STYLES) { - int hf = 9 * mHairColor; + int hf = 5 * mHairColor; if (hf >= 0 && hf < (int)hairset[mHairStyle]->size()) { dynamic_cast(graphics)->drawImage( hairset[mHairStyle - 1]->get(hf), 35, 7); diff --git a/src/gui/popupmenu.cpp b/src/gui/popupmenu.cpp index 59316de1..ab81f7d0 100644 --- a/src/gui/popupmenu.cpp +++ b/src/gui/popupmenu.cpp @@ -106,7 +106,7 @@ void PopupMenu::showPopup(int x, int y, FloorItem *floorItem) mBrowserBox->clearRows(); // Floor item can be picked up (single option, candidate for removal) - std::string name = itemDb->getItemInfo(mFloorItem->getItemId())->getName(); + std::string name = itemDb->getItemInfo(mFloorItem->getItemId()).getName(); mBrowserBox->addRow("@@pickup|Pick Up " + name + "@@"); //browserBox->addRow("@@look|Look To@@"); diff --git a/src/gui/selectionlistener.h b/src/gui/selectionlistener.h new file mode 100644 index 00000000..a2fc6533 --- /dev/null +++ b/src/gui/selectionlistener.h @@ -0,0 +1,78 @@ +/* + * 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: selectionlistener.h 2651 2006-09-03 16:47:48Z b_lindeijer $ + */ + +#ifndef _TMW_SELECTIONLISTENER_H__ +#define _TMW_SELECTIONLISTENER_H__ + +#include + +/** + * An event that characterizes a change in the current selection. + * + * \ingroup GUI + */ +class SelectionEvent +{ + public: + /** + * Constructor. + */ + SelectionEvent(gcn::Widget *source): + mSource(source) + { + } + + /** + * The widget from which the event originated. + */ + gcn::Widget* getSource() const + { + return mSource; + } + + private: + gcn::Widget *mSource; +}; + +/** + * The listener that's notified when a selection value changes. + * + * \ingroup GUI + */ +class SelectionListener +{ + public: + /** + * Virtual destructor. + */ + virtual ~SelectionListener() {} + + /** + * Called whenever the value of the selection changes. + */ + virtual void selectionChanged(const SelectionEvent &event) = 0; +}; + +typedef std::list SelectionListeners; + +#endif diff --git a/src/gui/sell.cpp b/src/gui/sell.cpp index 33813271..d6d8cad5 100644 --- a/src/gui/sell.cpp +++ b/src/gui/sell.cpp @@ -94,6 +94,7 @@ SellDialog::SellDialog(): mSlider->setEventId("mSlider"); mItemList->addActionListener(this); + mItemList->addSelectionListener(this); mSlider->addActionListener(this); add(scrollArea); @@ -141,7 +142,7 @@ void SellDialog::addItem(Item *item, int price) ITEM_SHOP item_shop; - item_shop.name = item->getInfo()->getName() + " " + toString(price) + " GP"; + item_shop.name = item->getInfo().getName() + " " + toString(price) + " GP"; item_shop.price = price; item_shop.index = item->getInvIndex(); item_shop.id = item->getId(); @@ -155,7 +156,8 @@ void SellDialog::action(const std::string &eventId, gcn::Widget *widget) { int selectedItem = mItemList->getSelected(); - if (eventId == "item") { + if (eventId == "item") + { mAmountItems = 0; mSlider->setValue(0); mDecreaseButton->setEnabled(false); @@ -188,19 +190,22 @@ void SellDialog::action(const std::string &eventId, gcn::Widget *widget) bool updateButtonsAndLabels = false; - if (eventId == "mSlider") { + if (eventId == "mSlider") + { mAmountItems = (int)(mSlider->getValue() * mMaxItems); updateButtonsAndLabels = true; } - else if (eventId == "+") { + else if (eventId == "+") + { assert(mAmountItems < mMaxItems); mAmountItems++; mSlider->setValue(double(mAmountItems)/double(mMaxItems)); updateButtonsAndLabels = true; } - else if (eventId == "-") { + else if (eventId == "-") + { assert(mAmountItems > 0); mAmountItems--; @@ -208,7 +213,8 @@ void SellDialog::action(const std::string &eventId, gcn::Widget *widget) updateButtonsAndLabels = true; } - else if (eventId == "sell") { + else if (eventId == "sell") + { // Attempt sell assert(mAmountItems > 0 && mAmountItems <= mMaxItems); @@ -234,7 +240,8 @@ void SellDialog::action(const std::string &eventId, gcn::Widget *widget) } // If anything changed, we need to update the buttons and labels - if (updateButtonsAndLabels) { + if (updateButtonsAndLabels) + { // Update labels mQuantityLabel->setCaption(toString(mAmountItems)); mQuantityLabel->adjustSize(); @@ -250,16 +257,21 @@ void SellDialog::action(const std::string &eventId, gcn::Widget *widget) } } -void SellDialog::mouseClick(int x, int y, int button, int count) +void SellDialog::selectionChanged(const SelectionEvent &event) { - Window::mouseClick(x, y, button, count); - int selectedItem = mItemList->getSelected(); + if (selectedItem > -1) { - mItemDescLabel->setCaption("Description: " + - itemDb->getItemInfo(mShopItems->at(selectedItem).id)->getDescription()); - mItemEffectLabel->setCaption("Effect: " + - itemDb->getItemInfo(mShopItems->at(selectedItem).id)->getEffect()); + const ItemInfo &info = + itemDb->getItemInfo(mShopItems->at(selectedItem).id); + + mItemDescLabel->setCaption("Description: " + info.getDescription()); + mItemEffectLabel->setCaption("Effect: " + info.getEffect()); + } + else + { + mItemDescLabel->setCaption("Description"); + mItemEffectLabel->setCaption("Effect"); } } diff --git a/src/gui/sell.h b/src/gui/sell.h index be5185bd..69f8b089 100644 --- a/src/gui/sell.h +++ b/src/gui/sell.h @@ -27,19 +27,20 @@ #include #include "window.h" +#include "selectionlistener.h" #include "../guichanfwd.h" class Item; class ShopItems; - +class ListBox; /** * The sell dialog. * * \ingroup Interface */ -class SellDialog : public Window, public gcn::ActionListener +class SellDialog : public Window, gcn::ActionListener, SelectionListener { public: /** @@ -70,15 +71,17 @@ class SellDialog : public Window, public gcn::ActionListener void action(const std::string& eventId, gcn::Widget* widget); /** - * Mouse callback + * Updates labels according to selected item. + * + * @see SelectionListener::selectionChanged */ - void mouseClick(int x, int y, int buton, int count); + void selectionChanged(const SelectionEvent &event); private: gcn::Button *mSellButton; gcn::Button *mIncreaseButton; gcn::Button *mDecreaseButton; - gcn::ListBox *mItemList; + ListBox *mItemList; gcn::Label *mMoneyLabel; gcn::Label *mItemDescLabel; gcn::Label *mItemEffectLabel; diff --git a/src/gui/setup.cpp b/src/gui/setup.cpp index d12ace75..78b10498 100644 --- a/src/gui/setup.cpp +++ b/src/gui/setup.cpp @@ -43,7 +43,7 @@ Setup::Setup(): Window("Setup") { int width = 230; - int height = 225; + int height = 245; setContentSize(width, height); const char *buttonNames[] = { @@ -58,7 +58,7 @@ Setup::Setup(): } TabbedContainer *panel = new TabbedContainer(); - panel->setDimension(gcn::Rectangle(5, 5, 220, 185)); + panel->setDimension(gcn::Rectangle(5, 5, 220, 205)); panel->setOpaque(false); SetupTab *tab; diff --git a/src/gui/setup_video.cpp b/src/gui/setup_video.cpp index 7c72975a..7a4aae03 100644 --- a/src/gui/setup_video.cpp +++ b/src/gui/setup_video.cpp @@ -106,7 +106,7 @@ Setup_Video::Setup_Video(): mOpenGLEnabled(config.getValue("opengl", 0)), mCustomCursorEnabled(config.getValue("customcursor", 1)), mOpacity(config.getValue("guialpha", 0.8)), - mFps((int)config.getValue("fpslimit", 50)), + mFps((int)config.getValue("fpslimit", 60)), mModeListModel(new ModeListModel()), mModeList(new ListBox(mModeListModel)), mFsCheckBox(new CheckBox("Full screen", mFullScreenEnabled)), @@ -121,7 +121,10 @@ Setup_Video::Setup_Video(): mScrollLazinessField(new TextField()), mOriginalScrollRadius((int) config.getValue("ScrollRadius", 32)), mScrollRadiusSlider(new Slider(0, 128)), - mScrollRadiusField(new TextField()) + mScrollRadiusField(new TextField()), + mOverlayDetail((int) config.getValue("OverlayDetail", 2)), + mOverlayDetailSlider(new Slider(0, 2)), + mOverlayDetailField(new gcn::Label("")) { setOpaque(false); @@ -163,6 +166,8 @@ Setup_Video::Setup_Video(): mScrollRadiusField->setEventId("scrollradiusfield"); mScrollLazinessSlider->setEventId("scrolllazinessslider"); mScrollLazinessField->setEventId("scrolllazinessfield"); + mOverlayDetailSlider->setEventId("overlaydetailslider"); + mOverlayDetailField->setEventId("overlaydetailfield"); mCustomCursorCheckBox->addActionListener(this); mAlphaSlider->addActionListener(this); @@ -173,6 +178,8 @@ Setup_Video::Setup_Video(): mScrollRadiusField->addKeyListener(this); mScrollLazinessSlider->addActionListener(this); mScrollLazinessField->addKeyListener(this); + mOverlayDetailSlider->addActionListener(this); + mOverlayDetailField->addKeyListener(this); mScrollRadiusSlider->setDimension(gcn::Rectangle(10, 120, 75, 10)); gcn::Label *scrollRadiusLabel = new gcn::Label("Scroll radius"); @@ -190,6 +197,25 @@ Setup_Video::Setup_Video(): mScrollLazinessField->setText(toString(mOriginalScrollLaziness)); mScrollLazinessSlider->setValue(mOriginalScrollLaziness); + mOverlayDetailSlider->setDimension(gcn::Rectangle(10, 160, 75, 10)); + gcn::Label *overlayDetailLabel = new gcn::Label("Ambient FX"); + overlayDetailLabel->setPosition(90, 160); + mOverlayDetailField->setPosition(180, 160); + mOverlayDetailField->setWidth(30); + switch (mOverlayDetail) + { + case 0: + mOverlayDetailField->setCaption("off"); + break; + case 1: + mOverlayDetailField->setCaption("low"); + break; + case 2: + mOverlayDetailField->setCaption("high"); + break; + } + mOverlayDetailSlider->setValue(mOverlayDetail); + add(scrollArea); add(mFsCheckBox); add(mOpenGLCheckBox); @@ -205,6 +231,9 @@ Setup_Video::Setup_Video(): add(mScrollLazinessSlider); add(scrollLazinessLabel); add(mScrollLazinessField); + add(mOverlayDetailSlider); + add(overlayDetailLabel); + add(mOverlayDetailField); } Setup_Video::~Setup_Video() @@ -258,6 +287,7 @@ void Setup_Video::apply() mFullScreenEnabled = config.getValue("screen", 0); mCustomCursorEnabled = config.getValue("customcursor", 1); mOpacity = config.getValue("guialpha", 0.8); + mOverlayDetail = (int)config.getValue("OverlayDetail", 2); mOpenGLEnabled = config.getValue("opengl", 0); } @@ -288,6 +318,7 @@ void Setup_Video::cancel() mOpenGLCheckBox->setMarked(mOpenGLEnabled); mCustomCursorCheckBox->setMarked(mCustomCursorEnabled); mAlphaSlider->setValue(mOpacity); + mOverlayDetailSlider->setValue(mOverlayDetail); mScrollRadiusField->setText(toString(mOriginalScrollRadius)); mScrollLazinessField->setText(toString(mOriginalScrollLaziness)); @@ -328,6 +359,23 @@ void Setup_Video::action(const std::string &event, gcn::Widget *widget) mScrollLazinessField->setText(toString(val)); config.setValue("ScrollLaziness", val); } + else if (event == "overlaydetailslider") + { + int val = (int)mOverlayDetailSlider->getValue(); + switch (val) + { + case 0: + mOverlayDetailField->setCaption("off"); + break; + case 1: + mOverlayDetailField->setCaption("low"); + break; + case 2: + mOverlayDetailField->setCaption("high"); + break; + } + config.setValue("OverlayDetail", val); + } else if (event == "fpslimitcheckbox") { if (mFpsCheckBox->isMarked()) diff --git a/src/gui/setup_video.h b/src/gui/setup_video.h index a3fd8884..482d1c65 100644 --- a/src/gui/setup_video.h +++ b/src/gui/setup_video.h @@ -73,6 +73,10 @@ class Setup_Video : public SetupTab, public gcn::ActionListener, gcn::Slider *mScrollRadiusSlider; gcn::TextField *mScrollRadiusField; + int mOverlayDetail; + gcn::Slider *mOverlayDetailSlider; + gcn::Label *mOverlayDetailField; + void updateSliders(bool originalValues); diff --git a/src/gui/trade.cpp b/src/gui/trade.cpp index 0cd49013..44efbdb1 100644 --- a/src/gui/trade.cpp +++ b/src/gui/trade.cpp @@ -58,12 +58,14 @@ TradeWindow::TradeWindow(): mTradeButton = new Button("Trade", "trade", this); mMyItemContainer = new ItemContainer(mMyInventory.get()); + mMyItemContainer->addSelectionListener(this); mMyItemContainer->setPosition(2, 2); mMyScroll = new ScrollArea(mMyItemContainer); mMyScroll->setPosition(8, 8); mPartnerItemContainer = new ItemContainer(mPartnerInventory.get()); + mPartnerItemContainer->addSelectionListener(this); mPartnerItemContainer->setPosition(2, 58); mPartnerScroll = new ScrollArea(mPartnerItemContainer); @@ -219,53 +221,54 @@ void TradeWindow::tradeItem(Item *item, int quantity) outMsg.writeLong(quantity); } -void TradeWindow::mouseClick(int x, int y, int button, int count) +void TradeWindow::selectionChanged(const SelectionEvent &event) { - Window::mouseClick(x, y, button, count); - Item *item; - // mMyItems selected - if (x >= mMyScroll->getX() + 3 - && x <= mMyScroll->getX() + mMyScroll->getWidth() - 10 - && y >= mMyScroll->getY() + 16 - && y <= mMyScroll->getY() + mMyScroll->getHeight() + 15 - && (item = mMyItemContainer->getItem())) + /* If an item is selected in one container, make sure no item is selected + * in the other container. + */ + if (event.getSource() == mMyItemContainer && + (item = mMyItemContainer->getItem())) { - mPartnerItemContainer->selectNone(); - // mPartnerItems selected + mPartnerItemContainer->selectNone(); } - else if (x >= mPartnerScroll->getX() + 3 - && x <= mPartnerScroll->getX() + mPartnerScroll->getWidth() - 20 - && y >= mPartnerScroll->getY() + 16 - && y <= mPartnerScroll->getY() + mPartnerScroll->getHeight() + 15 - && (item = mPartnerItemContainer->getItem())) + else if ((item = mPartnerItemContainer->getItem())) { - mMyItemContainer->selectNone(); - } else { - return; + mMyItemContainer->selectNone(); } - // Show Name and Description - std::string SomeText; - SomeText = "Name: " + item->getInfo()->getName(); - mItemNameLabel->setCaption(SomeText); - mItemNameLabel->adjustSize(); - SomeText = "Description: " + item->getInfo()->getDescription(); - mItemDescriptionLabel->setCaption(SomeText); - mItemDescriptionLabel->adjustSize(); + // Update name and description + if (!item) + { + mItemNameLabel->setCaption("Name:"); + mItemDescriptionLabel->setCaption("Description:"); + } + else + { + std::string SomeText; + SomeText = "Name: " + item->getInfo().getName(); + mItemNameLabel->setCaption(SomeText); + mItemNameLabel->adjustSize(); + SomeText = "Description: " + item->getInfo().getDescription(); + mItemDescriptionLabel->setCaption(SomeText); + mItemDescriptionLabel->adjustSize(); + } } void TradeWindow::action(const std::string &eventId, gcn::Widget *widget) { Item *item = inventoryWindow->getItem(); - if (eventId == "add") { - if (!item) { + if (eventId == "add") + { + if (!item) + { return; } - if (mMyInventory->getFreeSlot() < 1) { + if (mMyInventory->getFreeSlot() < 1) + { return; } diff --git a/src/gui/trade.h b/src/gui/trade.h index fe60aac5..ebd05a52 100644 --- a/src/gui/trade.h +++ b/src/gui/trade.h @@ -29,6 +29,7 @@ #include #include "window.h" +#include "selectionlistener.h" #include "../guichanfwd.h" @@ -42,7 +43,7 @@ class ScrollArea; * * \ingroup Interface */ -class TradeWindow : public Window, gcn::ActionListener +class TradeWindow : public Window, gcn::ActionListener, SelectionListener { public: /** @@ -102,14 +103,15 @@ class TradeWindow : public Window, gcn::ActionListener tradeItem(Item *item, int quantity); /** - * Called on mouse click. + * Updates the labels and makes sure only one item is selected in + * either my inventory or partner inventory. */ - void mouseClick(int x, int y, int button, int count); + void selectionChanged(const SelectionEvent &event); /** * Called when receiving actions from the widgets. */ - void action(const std::string& eventId, gcn::Widget* widget); + void action(const std::string &eventId, gcn::Widget *widget); private: typedef std::auto_ptr InventoryPtr; diff --git a/src/gui/updatewindow.cpp b/src/gui/updatewindow.cpp index 77a026fe..00b10406 100644 --- a/src/gui/updatewindow.cpp +++ b/src/gui/updatewindow.cpp @@ -48,9 +48,9 @@ UpdaterWindow::UpdaterWindow(): Window("Updating..."), mThread(NULL), mMutex(NULL), mDownloadStatus(UPDATE_NEWS), mUpdateHost(""), mCurrentFile("news.txt"), mBasePath(""), - mStoreInMemory(true), mDownloadComplete(true), mDownloadedBytes(0), - mMemoryBuffer(NULL), mCurlError(new char[CURL_ERROR_SIZE]), - mFileIndex(0) + mStoreInMemory(true), mDownloadComplete(true), mUserCancel(false), + mDownloadedBytes(0), mMemoryBuffer(NULL), + mCurlError(new char[CURL_ERROR_SIZE]), mFileIndex(0) { mCurlError[0] = 0; @@ -133,6 +133,8 @@ void UpdaterWindow::action(const std::string &eventId, gcn::Widget *widget) { if (eventId == "cancel") { + // Register the user cancel + mUserCancel=true; // Skip the updating process if (mDownloadStatus == UPDATE_COMPLETE) { @@ -329,7 +331,15 @@ void UpdaterWindow::logic() case UPDATE_ERROR: if (mThread) { - SDL_WaitThread(mThread, NULL); + if(mUserCancel){ + // Kill the thread, because user has canceled + SDL_KillThread(mThread); + // Set the flag to false again + mUserCancel = false; + } + else{ + SDL_WaitThread(mThread, NULL); + } mThread = NULL; } addRow(""); diff --git a/src/gui/updatewindow.h b/src/gui/updatewindow.h index 8a168be8..5016036d 100644 --- a/src/gui/updatewindow.h +++ b/src/gui/updatewindow.h @@ -161,6 +161,11 @@ class UpdaterWindow : public Window, public gcn::ActionListener */ bool mDownloadComplete; + /** + * Flag that show if the user has canceled the update + */ + bool mUserCancel; + /** * Byte count currently downloaded in mMemoryBuffer. */ diff --git a/src/gui/window.cpp b/src/gui/window.cpp index 2172baa8..c7860021 100644 --- a/src/gui/window.cpp +++ b/src/gui/window.cpp @@ -249,16 +249,18 @@ void Window::setSticky(bool sticky) mSticky = sticky; } -bool Window::isSticky() { +bool Window::isSticky() +{ return mSticky; } -void Window::setVisible(bool visible) { - if(isSticky()) +void Window::setVisible(bool visible) +{ + if (isSticky()) { gcn::Window::setVisible(true); - } - else + } + else { gcn::Window::setVisible(visible); } diff --git a/src/item.h b/src/item.h index c21f5ddf..1375886e 100644 --- a/src/item.h +++ b/src/item.h @@ -118,7 +118,7 @@ class Item /** * Returns information about this item type. */ - ItemInfo* + const ItemInfo& getInfo() const { return itemDb->getItemInfo(mId); } protected: diff --git a/src/localplayer.h b/src/localplayer.h index 7d5aef87..dbf2a147 100644 --- a/src/localplayer.h +++ b/src/localplayer.h @@ -96,12 +96,17 @@ class LocalPlayer : public Player * Sets the trading state of the player, i.e. whether or not he is * currently involved into some trade. */ - void setTrading(bool trading) { mTrading = trading; }; + void setTrading(bool trading) { mTrading = trading; } void attack(Being *target=NULL, bool keep=false); void stopAttack(); Being* getTarget() const; + /** + * Sets the target being of the player. + */ + void setTarget(Being* target) { mTarget = target; } + void walk(unsigned char dir); /** diff --git a/src/main.cpp b/src/main.cpp index 9d2a1e64..f881ddad 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -107,6 +107,33 @@ namespace { } errorListener; } +/** + * A structure holding the values of various options that can be passed from + * the command line. + */ +struct Options +{ + /** + * Constructor. + */ + Options(): + printHelp(false), + skipUpdate(false), + chooseDefault(false), + serverPort(0) + {}; + + bool printHelp; + bool skipUpdate; + bool chooseDefault; + std::string playername; + std::string password; + std::string configPath; + + std::string serverName; + short serverPort; +}; + /** * Initializes the home directory. On UNIX and FreeBSD, ~/.tmw is used. On * Windows and other systems we use the current working directory. @@ -133,7 +160,7 @@ void initHomeDir() /** * Initialize configuration. */ -void initConfiguration() +void initConfiguration(const Options &options) { // Fill configuration with defaults config.setValue("host", "animesites.de"); @@ -158,7 +185,10 @@ void initConfiguration() // Checking if the configuration file exists... otherwise create it with // default options. FILE *tmwFile = 0; - std::string configPath = homeDir + "/config.xml"; + std::string configPath = options.configPath; + if (configPath == "") { + configPath = homeDir + "/config.xml"; + } tmwFile = fopen(configPath.c_str(), "r"); // If we can't read it, it doesn't exist ! @@ -176,7 +206,7 @@ void initConfiguration() } /** - * Do all initialization stuff + * Do all initialization stuff. */ void init_engine() { @@ -279,7 +309,8 @@ void init_engine() sound.init(); } sound.setSfxVolume((int)config.getValue("sfxVolume", defaultSfxVolume)); - sound.setMusicVolume((int)config.getValue("musicVolume", defaultMusicVolume)); + sound.setMusicVolume((int)config.getValue("musicVolume", + defaultMusicVolume)); } catch (const char *err) { state = STATE_ERROR; @@ -311,33 +342,6 @@ void exit_engine() ResourceManager::deleteInstance(); } -/** - * A structure holding the values of various options that can be passed from - * the command line. - */ -struct Options -{ - /** - * Constructor. - */ - Options(): - printHelp(false), - skipUpdate(false), - chooseDefault(false), - serverPort(0) - {}; - - bool printHelp; - bool skipUpdate; - bool chooseDefault; - std::string playername; - std::string password; - - std::string serverName; - short serverPort; - -}; - void printHelp() { std::cout @@ -351,12 +355,13 @@ void printHelp() << std::endl << " -s --server : Login Server name or IP" << std::endl << " -o --port : Login Server Port" << std::endl - << " -p --playername : Login with this player" << std::endl; + << " -p --playername : Login with this player" << std::endl + << " -C --configfile : Configuration file to use" << std::endl; } void parseOptions(int argc, char *argv[], Options &options) { - const char *optstring = "huU:P:Dp:s:o:"; + const char *optstring = "huU:P:Dp:s:o:C:"; const struct option long_options[] = { { "help", no_argument, 0, 'h' }, @@ -367,6 +372,7 @@ void parseOptions(int argc, char *argv[], Options &options) { "server", required_argument, 0, 's' }, { "port", required_argument, 0, 'o' }, { "playername", required_argument, 0, 'p' }, + { "configfile", required_argument, 0, 'C' }, { 0 } }; @@ -403,6 +409,9 @@ void parseOptions(int argc, char *argv[], Options &options) case 'p': options.playername = optarg; break; + case 'C': + options.configPath = optarg; + break; } } } @@ -480,6 +489,10 @@ void mapLogin(LoginData *loginData) { Network::registerHandler(&mapLoginHandler); + logger->log("Memorizing selected character %s", + player_node->getName().c_str()); + config.setValue("lastCharacter", player_node->getName()); + // Send connect messages with the magic token to game and chat servers MessageOut gameServerConnect(PGMSG_CONNECT); gameServerConnect.writeString(token, 32); @@ -510,7 +523,7 @@ int main(int argc, char *argv[]) PHYSFS_init(argv[0]); initHomeDir(); - initConfiguration(); + initConfiguration(options); // Configure logger logger = new Logger(); @@ -721,23 +734,16 @@ int main(int argc, char *argv[]) case STATE_CHAR_SELECT: logger->log("State: CHAR_SELECT"); currentDialog = new CharSelectDialog(&charInfo); - 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); - } + + if (((CharSelectDialog*)currentDialog)-> + selectByName(options.playername)) + options.chooseDefault = true; + else + ((CharSelectDialog*)currentDialog)->selectByName( + config.getValue("lastCharacter", "")); + + if (options.chooseDefault) + ((CharSelectDialog*)currentDialog)->action("ok", NULL); break; case STATE_ERROR: diff --git a/src/map.cpp b/src/map.cpp index 5063a754..3ccaafc0 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -63,8 +63,11 @@ Map::Map(int width, int height, int tileWidth, int tileHeight): mOnClosedList(1), mOnOpenList(2), mLastScrollX(0.0f), mLastScrollY(0.0f) { - mMetaTiles = new MetaTile[mWidth * mHeight]; - mTiles = new Image*[mWidth * mHeight * 3]; + int size = mWidth * mHeight; + + mMetaTiles = new MetaTile[size]; + mTiles = new Image*[size * 3]; + std::fill_n(mTiles, size * 3, (Image*)0); } Map::~Map() @@ -86,12 +89,17 @@ Map::~Map() void Map::setSize(int width, int height) { - mWidth = width; - mHeight = height; delete[] mMetaTiles; delete[] mTiles; - mMetaTiles = new MetaTile[mWidth * mHeight]; - mTiles = new Image*[mWidth * mHeight * 3]; + + mWidth = width; + mHeight = height; + + int size = width * height; + + mMetaTiles = new MetaTile[size]; + mTiles = new Image*[size * 3]; + std::fill_n(mTiles, size * 3, (Image*)0); } void @@ -330,8 +338,8 @@ Map::getWalk(int x, int y) /* // Check for collision with a being - Beings *beings = beingManager->getAll(); - for (BeingIterator i = beings->begin(); i != beings->end(); i++) { + Beings &beings = beingManager->getAll(); + for (BeingIterator i = beings.begin(); i != beings.end(); i++) { // job 45 is a portal, they don't collide if ((*i)->mX / 32 == x && (*i)->mY / 32 == y && (*i)->mJob != 45) { return false; diff --git a/src/net/inventoryhandler.cpp b/src/net/inventoryhandler.cpp index c4192bc5..3f7e8709 100644 --- a/src/net/inventoryhandler.cpp +++ b/src/net/inventoryhandler.cpp @@ -92,14 +92,9 @@ 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); - } + const ItemInfo &itemInfo = itemDb->getItemInfo(itemId); + chatWindow->chatLog("You picked up a " + + itemInfo.getName(), BY_SERVER); player_node->addInvItem(index, itemId, amount, equipType != 0); } break; diff --git a/src/resources/image.cpp b/src/resources/image.cpp index 51899d3f..eb3a2409 100644 --- a/src/resources/image.cpp +++ b/src/resources/image.cpp @@ -260,11 +260,18 @@ void Image::unload() { mLoaded = false; - if (!mImage) return; + if (mImage) { + // Free the image surface. + SDL_FreeSurface(mImage); + mImage = NULL; + } - // Free the image surface. - SDL_FreeSurface(mImage); - mImage = NULL; +#ifdef USE_OPENGL + if (mGLImage) { + glDeleteTextures(1, &mGLImage); + mGLImage = 0; + } +#endif } Image *Image::getSubImage(int x, int y, int width, int height) @@ -341,7 +348,11 @@ SubImage::SubImage(Image *parent, GLuint image, SubImage::~SubImage() { - mImage = 0; // Avoid destruction of the image + // Avoid destruction of the image + mImage = 0; +#ifdef USE_OPENGL + mGLImage = 0; +#endif mParent->decRef(); } diff --git a/src/resources/image.h b/src/resources/image.h index 78751394..a1ab7f48 100644 --- a/src/resources/image.h +++ b/src/resources/image.h @@ -28,6 +28,13 @@ #include #ifdef USE_OPENGL + +/* The definition of OpenGL extensions by SDL is giving problems with recent + * gl.h headers, since they also include these definitions. As we're not using + * extensions anyway it's safe to just disable the SDL version. + */ +#define NO_SDL_GLEXT + #include #endif diff --git a/src/resources/iteminfo.cpp b/src/resources/iteminfo.cpp index 5d39d832..b09d1cc0 100644 --- a/src/resources/iteminfo.cpp +++ b/src/resources/iteminfo.cpp @@ -23,22 +23,33 @@ #include "iteminfo.h" #include "resourcemanager.h" +#include "image.h" -Image* -ItemInfo::getImage() { - if (mImage == NULL && mImageName != "") { - mImage = ResourceManager::getInstance()->getImage(mImageName); + +ItemInfo::~ItemInfo() +{ + if (mImage != NULL) + { + mImage->decRef(); } - return mImage; } void -ItemInfo::setImage(const std::string &image) { +ItemInfo::setImage(const std::string &image) +{ mImageName = "graphics/items/" + image; -} -ItemInfo::~ItemInfo() { - if (mImage != NULL){ - mImage->decRef(); + if (mImageName != "") + { + if (mImage != NULL) + { + mImage->decRef(); + } + + mImage = ResourceManager::getInstance()->getImage(mImageName); + } + else + { + mImage = NULL; } } diff --git a/src/resources/iteminfo.h b/src/resources/iteminfo.h index afa2e857..9a04bb2e 100644 --- a/src/resources/iteminfo.h +++ b/src/resources/iteminfo.h @@ -26,7 +26,7 @@ #include -#include "image.h" +class Image; /** * Defines a class for storing item infos. @@ -40,8 +40,8 @@ class ItemInfo * Constructor. */ ItemInfo(): - mImage(NULL), mImageName(""), + mImage(NULL), mArt(0), mType(0), mWeight(0), @@ -53,19 +53,19 @@ class ItemInfo setArt(short art) { mArt = art; } short - getArt() { return mArt; } + getArt() const { return mArt; } void setName(const std::string &name) { mName = name; } - std::string - getName() { return mName; } + const std::string& + getName() const { return mName; } void setImage(const std::string &image); Image* - getImage(); + getImage() const { return mImage; } void setDescription(const std::string &description) @@ -73,32 +73,32 @@ class ItemInfo mDescription = description; } - std::string - getDescription() { return mDescription; } + const std::string& + getDescription() const { return mDescription; } void setEffect(const std::string &effect) { mEffect = effect; } - std::string - getEffect() { return mEffect; } + const std::string& + getEffect() const { return mEffect; } void setType(short type) { mType = type; } short - getType() { return mType; } + getType() const { return mType; } void setWeight(short weight) { mWeight = weight; } short - getWeight() { return mWeight; } + getWeight() const { return mWeight; } void setSlot(char slot) { mSlot = slot; } char - getSlot() { return mSlot; } + getSlot() const { return mSlot; } protected: /** @@ -106,8 +106,14 @@ class ItemInfo */ ~ItemInfo(); - Image* mImage; std::string mImageName; + + /* TODO (BL): I do not think the item info should keep a reference to + * the item icon. It would probably be better if this was kept in the + * Item class, so that the images can be lazily instantiated and also + * unloaded when no longer used. + */ + Image *mImage; short mArt; std::string mName; std::string mDescription; diff --git a/src/resources/itemmanager.cpp b/src/resources/itemmanager.cpp index a497b3c8..7d0b13f2 100644 --- a/src/resources/itemmanager.cpp +++ b/src/resources/itemmanager.cpp @@ -41,8 +41,7 @@ ItemManager::ItemManager() { - mUnknown = new ItemInfo(); - mUnknown->setName("Unknown item"); + mUnknown.setName("Unknown item"); ResourceManager *resman = ResourceManager::getInstance(); int size; @@ -163,14 +162,12 @@ ItemManager::~ItemManager() delete i->second; } mItemInfos.clear(); - - delete mUnknown; } -ItemInfo* +const ItemInfo& ItemManager::getItemInfo(int id) { ItemInfoIterator i = mItemInfos.find(id); - return (i != mItemInfos.end()) ? i->second : mUnknown; + return (i != mItemInfos.end()) ? *(i->second) : mUnknown; } diff --git a/src/resources/itemmanager.h b/src/resources/itemmanager.h index 06eee507..b1f2b95c 100644 --- a/src/resources/itemmanager.h +++ b/src/resources/itemmanager.h @@ -24,9 +24,9 @@ #ifndef _TMW_ITEM_MANAGER_H #define _TMW_ITEM_MANAGER_H -#include +#include "iteminfo.h" -class ItemInfo; +#include /** * Defines a class to load items database. @@ -44,14 +44,14 @@ class ItemManager */ ~ItemManager(); - ItemInfo *getItemInfo(int id); + const ItemInfo& getItemInfo(int id); protected: // Items database typedef std::map ItemInfos; typedef ItemInfos::iterator ItemInfoIterator; ItemInfos mItemInfos; - ItemInfo *mUnknown; + ItemInfo mUnknown; }; extern ItemManager *itemDb; diff --git a/src/tmw.rc b/src/tmw.rc index 31411b61..388b643d 100644 --- a/src/tmw.rc +++ b/src/tmw.rc @@ -7,8 +7,8 @@ A ICON MOVEABLE PURE LOADONCALL DISCARDABLE "data/icons/tmw-icon.ico" // TO CHANGE VERSION INFORMATION, EDIT PROJECT OPTIONS... // 1 VERSIONINFO -FILEVERSION 0,0,20,0 -PRODUCTVERSION 0,0,20,0 +FILEVERSION 0,0,21,0 +PRODUCTVERSION 0,0,21,0 FILETYPE VFT_APP { BLOCK "StringFileInfo" @@ -16,14 +16,14 @@ FILETYPE VFT_APP BLOCK "040904E4" { VALUE "CompanyName", "The Mana World Development Team" - VALUE "FileVersion", "0.0.20" + VALUE "FileVersion", "0.0.21" VALUE "FileDescription", "The Mana World" VALUE "InternalName", "tmw.exe" VALUE "LegalCopyright", "2004-2006 (C)" VALUE "LegalTrademarks", "" VALUE "OriginalFilename", "tmw.exe" VALUE "ProductName", "The Mana World MMORPG" - VALUE "ProductVersion", "0.0.20" + VALUE "ProductVersion", "0.0.21" } } BLOCK "VarFileInfo" diff --git a/tools/Reorganize.java b/tools/Reorganize.java index 19a17b99..22f42604 100644 --- a/tools/Reorganize.java +++ b/tools/Reorganize.java @@ -12,7 +12,7 @@ import java.io.File; import javax.imageio.ImageIO; /** - * Very simple tool to reorganize the monster spritesets. + * Tool to reorganize the hair spritesets. */ public class Reorganize { @@ -20,6 +20,12 @@ public class Reorganize private static final int SPRITE_HEIGHT = 60; private static final int FRAMES = 10; private static final int DIRECTIONS = 4; + + private static final int HAIR_COLORS = 10; + private static final int HAIR_FRAMES = 9; + private static final int HAIR_SPRITE_WIDTH = 40; + private static final int HAIR_SPRITE_HEIGHT = 40; + private static final int TRANSPARENT = new Color(255, 0, 255).getRGB(); public static void main(String[] arg) @@ -38,30 +44,15 @@ public class Reorganize System.exit(1); } - Rectangle cropRect = null; - - // Read the existing frames into a vector and determine minimal - // rectangle that still can contain the contents of any frame. - Vector spriteSet = new Vector(); - for (int x = 0; x < DIRECTIONS; x++) { - for (int y = 0; y < FRAMES; y++) { - BufferedImage sprite = source.getSubimage( - x * SPRITE_WIDTH, - y * SPRITE_HEIGHT, - SPRITE_WIDTH, - SPRITE_HEIGHT); - - spriteSet.add(sprite); + // Read the existing frames into a vector + Vector spriteSet = gridCut(source, + HAIR_SPRITE_WIDTH, HAIR_SPRITE_HEIGHT, + HAIR_FRAMES, HAIR_COLORS); - Rectangle frameCropRect = determineCropRect(sprite); - - if (cropRect == null) { - cropRect = frameCropRect; - } else { - cropRect.add(frameCropRect); - } - } - } + // Determine minimal rectangle that can still contain the contents of + // any frame + /* + Rectangle cropRect = minimumCropRect(spriteSet); if (cropRect == null) { System.out.println( @@ -76,19 +67,61 @@ public class Reorganize System.out.println(arg[0] + ": width=\"" + cropRect.width + "\" height=\"" + cropRect.height + "\""); + */ + + filterHairstyle(spriteSet); + + BufferedImage target = gridDraw( + spriteSet, + new Rectangle(0, 0, HAIR_SPRITE_WIDTH, HAIR_SPRITE_HEIGHT), + HAIR_FRAMES - 4, HAIR_COLORS); - // Create a new image (with frame direction flipped) + // Save the target image + try { + ImageIO.write(target, "png", new File(arg[1])); + } catch (IOException e) { + System.out.println("Error while trying to write " + arg[1] + "."); + e.printStackTrace(); + System.exit(1); + } + } + + private static Vector gridCut( + BufferedImage source, + int width, int height, int xFrames, int yFrames) + { + Vector spriteSet = new Vector(); + + for (int y = 0; y < yFrames; y++) { + for (int x = 0; x < xFrames; x++) { + BufferedImage sprite = source.getSubimage( + x * width, + y * height, + width, + height); + + spriteSet.add(sprite); + } + } + + return spriteSet; + } + + private static BufferedImage gridDraw(Vector spriteSet, + Rectangle cropRect, int xFrames, int yFrames) + { + // Create a new image BufferedImage target = new BufferedImage( - FRAMES * cropRect.width, - DIRECTIONS * cropRect.height, + xFrames * cropRect.width, + yFrames * cropRect.height, BufferedImage.TYPE_INT_ARGB); // Draw the frames onto the target image Graphics g = target.getGraphics(); - for (int y = 0; y < DIRECTIONS; y++) { - for (int x = 0; x < FRAMES; x++) { + for (int y = 0; y < yFrames; y++) { + for (int x = 0; x < xFrames; x++) { g.drawImage( - spriteSet.get(x + FRAMES * y).getSubimage( + spriteSet.get(x + xFrames * y).getSubimage( cropRect.x, cropRect.y, cropRect.width, @@ -99,14 +132,24 @@ public class Reorganize } } - // Save the target image - try { - ImageIO.write(target, "png", new File(arg[1])); - } catch (IOException e) { - System.out.println("Error while trying to write " + arg[1] + "."); - e.printStackTrace(); - System.exit(1); + return target; + } + + private static Rectangle minimumCropRect(Vector spriteSet) + { + Rectangle cropRect = null; + + for (BufferedImage sprite : spriteSet) { + Rectangle frameCropRect = determineCropRect(sprite); + + if (cropRect == null) { + cropRect = frameCropRect; + } else { + cropRect.add(frameCropRect); + } } + + return cropRect; } private static Rectangle determineCropRect(BufferedImage image) @@ -130,4 +173,15 @@ public class Reorganize return rect; } + + private static void filterHairstyle(Vector spriteSet) + { + // Remove frame 1, 2, 6 and 7 from each color + for (int i = HAIR_COLORS - 1; i >= 0; i--) { + spriteSet.remove(i * HAIR_FRAMES + 7); + spriteSet.remove(i * HAIR_FRAMES + 6); + spriteSet.remove(i * HAIR_FRAMES + 2); + spriteSet.remove(i * HAIR_FRAMES + 1); + } + } } -- cgit v1.2.3-60-g2f50 From 5f0ebee0d4d75fa91d417f4f352abdbc7502c2f0 Mon Sep 17 00:00:00 2001 From: Björn Steinbrink Date: Thu, 2 Nov 2006 12:43:49 +0000 Subject: Network layer refactoring. --- ChangeLog | 22 ++++ src/CMakeLists.txt | 20 ++++ src/Makefile.am | 18 +++ src/beingmanager.cpp | 6 +- src/game.cpp | 22 ++-- src/gui/buy.cpp | 6 +- src/gui/char_select.cpp | 50 +++----- src/gui/chat.cpp | 17 ++- src/gui/sell.cpp | 6 +- src/gui/serverdialog.cpp | 3 - src/gui/status.cpp | 12 +- src/gui/trade.cpp | 19 ++- src/localplayer.cpp | 53 +++++++-- src/main.cpp | 100 ++++++++-------- src/net/accountserver/account.cpp | 116 +++++++++++++++++++ src/net/accountserver/account.h | 60 ++++++++++ src/net/accountserver/accountserver.cpp | 68 +++++++++++ src/net/accountserver/accountserver.h | 46 ++++++++ src/net/accountserver/internal.cpp | 34 ++++++ src/net/accountserver/internal.h | 37 ++++++ src/net/charserverhandler.cpp | 11 +- src/net/chatserver/chatserver.cpp | 116 +++++++++++++++++++ src/net/chatserver/chatserver.h | 55 +++++++++ src/net/chatserver/internal.cpp | 34 ++++++ src/net/chatserver/internal.h | 37 ++++++ src/net/connection.cpp | 104 +++++++++++++++++ src/net/connection.h | 78 +++++++++++++ src/net/gameserver/gameserver.cpp | 42 +++++++ src/net/gameserver/gameserver.h | 39 +++++++ src/net/gameserver/internal.cpp | 34 ++++++ src/net/gameserver/internal.h | 37 ++++++ src/net/gameserver/player.cpp | 68 +++++++++++ src/net/gameserver/player.h | 46 ++++++++ src/net/internal.cpp | 29 +++++ src/net/internal.h | 32 ++++++ src/net/messagehandler.cpp | 2 +- src/net/network.cpp | 198 ++++++++++---------------------- src/net/network.h | 125 +++++++------------- src/npc.cpp | 18 ++- 39 files changed, 1443 insertions(+), 377 deletions(-) create mode 100644 src/net/accountserver/account.cpp create mode 100644 src/net/accountserver/account.h create mode 100644 src/net/accountserver/accountserver.cpp create mode 100644 src/net/accountserver/accountserver.h create mode 100644 src/net/accountserver/internal.cpp create mode 100644 src/net/accountserver/internal.h create mode 100644 src/net/chatserver/chatserver.cpp create mode 100644 src/net/chatserver/chatserver.h create mode 100644 src/net/chatserver/internal.cpp create mode 100644 src/net/chatserver/internal.h create mode 100644 src/net/connection.cpp create mode 100644 src/net/connection.h create mode 100644 src/net/gameserver/gameserver.cpp create mode 100644 src/net/gameserver/gameserver.h create mode 100644 src/net/gameserver/internal.cpp create mode 100644 src/net/gameserver/internal.h create mode 100644 src/net/gameserver/player.cpp create mode 100644 src/net/gameserver/player.h create mode 100644 src/net/internal.cpp create mode 100644 src/net/internal.h (limited to 'src/gui/buy.cpp') diff --git a/ChangeLog b/ChangeLog index 9623800f..b5964c36 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,25 @@ +2006-11-02 Björn Steinbrink + + * src/localplayer.cpp, src/game.cpp, src/gui/trade.cpp, + src/gui/sell.cpp, src/gui/char_select.cpp, src/gui/serverdialog.cpp, + src/gui/chat.cpp, src/gui/buy.cpp, src/gui/status.cpp, + src/beingmanager.cpp, src/npc.cpp, src/main.cpp, src/CMakeLists.txt, + src/net/connection.cpp, src/net/accountserver, + src/net/accountserver/account.h, src/net/accountserver/internal.h, + src/net/accountserver/accountserver.cpp, + src/net/accountserver/accountserver.h, + src/net/accountserver/account.cpp, src/net/accountserver/internal.cpp, + src/net/internal.cpp, src/net/network.h, + src/net/charserverhandler.cpp, src/net/connection.h, + src/net/gameserver, src/net/gameserver/gameserver.cpp, + src/net/gameserver/player.h, src/net/gameserver/internal.h, + src/net/gameserver/gameserver.h, src/net/gameserver/internal.cpp, + src/net/gameserver/player.cpp, src/net/internal.h, + src/net/messagehandler.cpp, src/net/chatserver, + src/net/chatserver/internal.h, src/net/chatserver/chatserver.cpp, + src/net/chatserver/chatserver.h, src/net/chatserver/internal.cpp, + src/net/network.cpp, src/Makefile.am: Network layer refactoring. + 2006-11-01 Björn Steinbrink * CMake/Modules/FindLibXml2.cmake, CMake/Modules/FindENet.cmake, diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b3bf323e..f99ded75 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -166,8 +166,12 @@ SET(SRCS net/charserverhandler.h net/chathandler.cpp net/chathandler.h + net/connection.cpp + net/connection.h net/equipmenthandler.cpp net/equipmenthandler.h + net/internal.cpp + net/internal.h net/inventoryhandler.cpp net/inventoryhandler.h net/itemhandler.cpp @@ -193,6 +197,22 @@ SET(SRCS net/skillhandler.h net/tradehandler.cpp net/tradehandler.h + net/accountserver/account.cpp + net/accountserver/account.h + net/accountserver/accountserver.cpp + net/accountserver/accountserver.h + net/accountserver/internal.cpp + net/accountserver/internal.h + net/chatserver/chatserver.cpp + net/chatserver/chatserver.h + net/chatserver/internal.cpp + net/chatserver/internal.h + net/gameserver/gameserver.cpp + net/gameserver/gameserver.h + net/gameserver/internal.cpp + net/gameserver/internal.h + net/gameserver/player.cpp + net/gameserver/player.h resources/buddylist.cpp resources/buddylist.h resources/image.cpp diff --git a/src/Makefile.am b/src/Makefile.am index b621c63e..655c10de 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -131,6 +131,8 @@ tmw_SOURCES = graphic/imagerect.h \ net/charserverhandler.cpp \ net/chathandler.h \ net/chathandler.cpp \ + net/connection.h \ + net/connection.cpp \ net/equipmenthandler.h \ net/equipmenthandler.cpp \ net/inventoryhandler.h \ @@ -158,6 +160,22 @@ tmw_SOURCES = graphic/imagerect.h \ net/skillhandler.h \ net/tradehandler.cpp \ net/tradehandler.h \ + net/accountserver/account.cpp \ + net/accountserver/account.h \ + net/accountserver/accountserver.cpp \ + net/accountserver/accountserver.h \ + net/accountserver/internal.cpp \ + net/accountserver/internal.h \ + net/chatserver/chatserver.cpp \ + net/chatserver/chatserver.h \ + net/chatserver/internal.cpp \ + net/chatserver/internal.h \ + net/gameserver/gameserver.cpp \ + net/gameserver/gameserver.h \ + net/gameserver/internal.cpp \ + net/gameserver/internal.h \ + net/gameserver/player.cpp \ + net/gameserver/player.h \ resources/image.cpp \ resources/image.h \ resources/imagewriter.cpp \ diff --git a/src/beingmanager.cpp b/src/beingmanager.cpp index 30b68ee2..923283b5 100644 --- a/src/beingmanager.cpp +++ b/src/beingmanager.cpp @@ -28,9 +28,6 @@ #include "npc.h" #include "player.h" -#include "net/messageout.h" -#include "net/protocol.h" - #include "utils/dtor.h" class FindBeingFunctor @@ -69,8 +66,11 @@ Being* BeingManager::createBeing(Uint16 id, Uint16 job) if (job < 10) { being = new Player(id, job, mMap); + // XXX Convert for new server + /* MessageOut outMsg(0x0094); outMsg.writeLong(id); + */ } else if (job >= 100 & job < 200) being = new NPC(id, job, mMap); diff --git a/src/game.cpp b/src/game.cpp index 5e4c24c2..2abd9e26 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -292,16 +292,16 @@ Game::Game(): 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()); + Net::registerHandler(mBeingHandler.get()); + Net::registerHandler(mBuySellHandler.get()); + Net::registerHandler(mChatHandler.get()); + Net::registerHandler(mEquipmentHandler.get()); + Net::registerHandler(mInventoryHandler.get()); + Net::registerHandler(mItemHandler.get()); + Net::registerHandler(mNpcHandler.get()); + Net::registerHandler(mPlayerHandler.get()); + Net::registerHandler(mSkillHandler.get()); + Net::registerHandler(mTradeHandler.get()); } Game::~Game() @@ -403,7 +403,7 @@ void Game::logic() } // Handle network stuff - Network::flush(); + Net::flush(); } } diff --git a/src/gui/buy.cpp b/src/gui/buy.cpp index ae779503..41bdd67e 100644 --- a/src/gui/buy.cpp +++ b/src/gui/buy.cpp @@ -36,9 +36,6 @@ #include "../resources/iteminfo.h" #include "../resources/itemmanager.h" -#include "../net/messageout.h" -#include "../net/protocol.h" - #include "../utils/tostring.h" @@ -225,10 +222,13 @@ void BuyDialog::action(const std::string &eventId, gcn::Widget *widget) else if (eventId == "buy" && (mAmountItems > 0 && mAmountItems <= mMaxItems)) { + // XXX Convert for new server + /* MessageOut outMsg(CMSG_NPC_BUY_REQUEST); outMsg.writeShort(8); outMsg.writeShort(mAmountItems); outMsg.writeShort(mShopItems->at(selectedItem).id); + */ // update money ! mMoney -= mAmountItems * mShopItems->at(selectedItem).price; diff --git a/src/gui/char_select.cpp b/src/gui/char_select.cpp index 3e6c4a5f..d825db31 100644 --- a/src/gui/char_select.cpp +++ b/src/gui/char_select.cpp @@ -37,9 +37,7 @@ #include "../localplayer.h" #include "../main.h" -#include "../net/messageout.h" -#include "../net/network.h" -#include "../net/protocol.h" +#include "../net/accountserver/account.h" #include "../utils/tostring.h" @@ -134,7 +132,8 @@ void CharSelectDialog::action(const std::string &eventId, gcn::Widget *widget) mPreviousButton->setEnabled(false); mNextButton->setEnabled(false); mCharSelected = true; - attemptCharSelect(); + Net::AccountServer::Account::selectCharacter(mCharInfo->getPos()); + mCharInfo->lock(); } else if (eventId == "cancel") { @@ -202,20 +201,7 @@ void CharSelectDialog::updatePlayerInfo() void CharSelectDialog::attemptCharDelete() { - // Request character deletion - MessageOut msg(PAMSG_CHAR_DELETE); - // TODO: Send the selected slot - msg.writeByte(0); - Network::send(Network::ACCOUNT, msg); - mCharInfo->lock(); -} - -void CharSelectDialog::attemptCharSelect() -{ - // Request character selection - MessageOut msg(PAMSG_CHAR_SELECT); - msg.writeByte(mCharInfo->getPos()); - Network::send(Network::ACCOUNT, msg); + Net::AccountServer::Account::deleteCharacter(mCharInfo->getPos()); mCharInfo->lock(); } @@ -312,7 +298,15 @@ void CharCreateDialog::action(const std::string &eventId, gcn::Widget *widget) if (getName().length() >= 4) { // Attempt to create the character mCreateButton->setEnabled(false); - attemptCharCreate(); + Net::AccountServer::Account::createCharacter( + getName(), mPlayerBox->mHairStyle, mPlayerBox->mHairColor, + 0, // gender + 10, // STR + 10, // AGI + 10, // VIT + 10, // INT + 10, // DEX + 10); // LUK scheduleDelete(); } else { @@ -344,21 +338,3 @@ std::string CharCreateDialog::getName() { return mNameField->getText(); } - -void CharCreateDialog::attemptCharCreate() -{ - // Send character infos - MessageOut outMsg(PAMSG_CHAR_CREATE); - outMsg.writeString(getName()); - outMsg.writeByte(mPlayerBox->mHairStyle); - outMsg.writeByte(mPlayerBox->mHairColor); - // TODO: send selected sex - outMsg.writeByte(0); // Player sex - outMsg.writeShort(10); // STR - outMsg.writeShort(10); // AGI - outMsg.writeShort(10); // VIT - outMsg.writeShort(10); // INT - outMsg.writeShort(10); // DEX - outMsg.writeShort(10); // LUK - Network::send(Network::ACCOUNT, outMsg); -} diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp index 9a5d60b0..3dc252ab 100644 --- a/src/gui/chat.cpp +++ b/src/gui/chat.cpp @@ -36,9 +36,9 @@ #include "../game.h" #include "../localplayer.h" -#include "../net/messageout.h" -#include "../net/network.h" -#include "../net/protocol.h" +#include "../net/chatserver/chatserver.h" + +#include "../net/gameserver/player.h" ChatWindow::ChatWindow(): Window(""), @@ -249,16 +249,12 @@ ChatWindow::chatSend(const std::string &nick, std::string msg) // Prepare ordinary message if (msg.substr(0, 1) != "/") { - MessageOut outMsg(PGMSG_SAY); - outMsg.writeString(msg); - Network::send(Network::GAME, outMsg); + Net::GameServer::Player::say(msg); } else if (msg.substr(0, IS_ANNOUNCE_LENGTH) == IS_ANNOUNCE) { msg.erase(0, IS_ANNOUNCE_LENGTH); - MessageOut outMsg(0x0099); - outMsg.writeShort(msg.length() + 4); - outMsg.writeString(msg, msg.length()); + Net::ChatServer::announce(msg); } else if (msg.substr(0, IS_HELP_LENGTH) == IS_HELP) { @@ -274,7 +270,10 @@ ChatWindow::chatSend(const std::string &nick, std::string msg) } else if (msg.substr(0, IS_WHO_LENGTH) == IS_WHO) { + // XXX Convert for new server + /* MessageOut outMsg(0x00c1); + */ } else { diff --git a/src/gui/sell.cpp b/src/gui/sell.cpp index d6d8cad5..9c25aced 100644 --- a/src/gui/sell.cpp +++ b/src/gui/sell.cpp @@ -39,9 +39,6 @@ #include "../resources/iteminfo.h" #include "../resources/itemmanager.h" -#include "../net/messageout.h" -#include "../net/protocol.h" - #include "../utils/tostring.h" SellDialog::SellDialog(): @@ -218,10 +215,13 @@ void SellDialog::action(const std::string &eventId, gcn::Widget *widget) // Attempt sell assert(mAmountItems > 0 && mAmountItems <= mMaxItems); + // XXX Convert for new server + /* MessageOut outMsg(CMSG_NPC_SELL_REQUEST); outMsg.writeShort(8); outMsg.writeShort(mShopItems->at(selectedItem).index); outMsg.writeShort(mAmountItems); + */ mMaxItems -= mAmountItems; mAmountItems = 0; diff --git a/src/gui/serverdialog.cpp b/src/gui/serverdialog.cpp index 450ae809..39abd5ed 100644 --- a/src/gui/serverdialog.cpp +++ b/src/gui/serverdialog.cpp @@ -236,9 +236,6 @@ ServerDialog::action(const std::string &eventId, gcn::Widget *widget) currentConfig = "MostUsedServerPort" + toString(i); config.setValue(currentConfig, toString(currentServer.port)); } - logger->log("Trying to connect to account server..."); - Network::connect(Network::ACCOUNT, - mLoginData->hostname, mLoginData->port); state = STATE_CONNECT_ACCOUNT; } } diff --git a/src/gui/status.cpp b/src/gui/status.cpp index 2b61ed35..b53e0942 100644 --- a/src/gui/status.cpp +++ b/src/gui/status.cpp @@ -368,27 +368,27 @@ void StatusWindow::action(const std::string &eventId, gcn::Widget *widget) { if (eventId == "STR") { - player_node->raiseAttribute(LocalPlayer::STR); + mPlayer->raiseAttribute(LocalPlayer::STR); } if (eventId == "AGI") { - player_node->raiseAttribute(LocalPlayer::AGI); + mPlayer->raiseAttribute(LocalPlayer::AGI); } if (eventId == "VIT") { - player_node->raiseAttribute(LocalPlayer::VIT); + mPlayer->raiseAttribute(LocalPlayer::VIT); } if (eventId == "INT") { - player_node->raiseAttribute(LocalPlayer::INT); + mPlayer->raiseAttribute(LocalPlayer::INT); } if (eventId == "DEX") { - player_node->raiseAttribute(LocalPlayer::DEX); + mPlayer->raiseAttribute(LocalPlayer::DEX); } if (eventId == "LUK") { - player_node->raiseAttribute(LocalPlayer::LUK); + mPlayer->raiseAttribute(LocalPlayer::LUK); } } } diff --git a/src/gui/trade.cpp b/src/gui/trade.cpp index 44efbdb1..630881ea 100644 --- a/src/gui/trade.cpp +++ b/src/gui/trade.cpp @@ -38,9 +38,6 @@ #include "../inventory.h" #include "../item.h" -#include "../net/messageout.h" -#include "../net/protocol.h" - #include "../resources/iteminfo.h" #include "../utils/tostring.h" @@ -216,9 +213,12 @@ void TradeWindow::receivedOk(bool own) void TradeWindow::tradeItem(Item *item, int quantity) { + // XXX Convert for new server + /* MessageOut outMsg(CMSG_TRADE_ITEM_ADD_REQUEST); outMsg.writeShort(item->getInvIndex()); outMsg.writeLong(quantity); + */ } void TradeWindow::selectionChanged(const SelectionEvent &event) @@ -288,7 +288,10 @@ void TradeWindow::action(const std::string &eventId, gcn::Widget *widget) } else if (eventId == "cancel") { + // XXX Convert for new server + /* MessageOut outMsg(CMSG_TRADE_CANCEL_REQUEST); + */ } else if (eventId == "ok") { @@ -298,17 +301,27 @@ void TradeWindow::action(const std::string &eventId, gcn::Widget *widget) { mMoneyField->setText(toString(tempInt)); + // XXX Convert for new server + /* MessageOut outMsg(CMSG_TRADE_ITEM_ADD_REQUEST); outMsg.writeShort(0); outMsg.writeLong(tempInt); + */ } else { mMoneyField->setText(""); } mMoneyField->setEnabled(false); + + // XXX Convert for new server + /* MessageOut outMsg(CMSG_TRADE_ADD_COMPLETE); + */ } else if (eventId == "trade") { + // XXX Convert for new server + /* MessageOut outMsg(CMSG_TRADE_OK); + */ } } diff --git a/src/localplayer.cpp b/src/localplayer.cpp index 87a55744..6898dfb7 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -31,9 +31,7 @@ #include "main.h" #include "sound.h" -#include "net/messageout.h" -#include "net/network.h" -#include "net/protocol.h" +#include "net/gameserver/player.h" LocalPlayer *player_node = NULL; @@ -100,9 +98,10 @@ Item* LocalPlayer::getInvItem(int index) void LocalPlayer::equipItem(Item *item) { - MessageOut outMsg(CMSG_PLAYER_EQUIP); - outMsg.writeShort(item->getInvIndex()); - outMsg.writeShort(0); + // XXX What's itemId and slot exactly? Same as eAthena? + /* + Net::GameServer::Player::equip(itemId, slot)); + */ } void LocalPlayer::unequipItem(Item *item) @@ -110,8 +109,11 @@ void LocalPlayer::unequipItem(Item *item) if (!item) return; + // XXX Convert for new server + /* MessageOut outMsg(CMSG_PLAYER_UNEQUIP); outMsg.writeShort(item->getInvIndex()); + */ // Tidy equipment directly to avoid weapon still shown bug, by instance mEquipment->removeEquipment(item); @@ -119,18 +121,23 @@ void LocalPlayer::unequipItem(Item *item) void LocalPlayer::useItem(Item *item) { + // XXX Convert for new server + /* 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 ?? + */ } void LocalPlayer::dropItem(Item *item, int quantity) { - // TODO: Fix wrong coordinates of drops, serverside? + // XXX Convert for new server + /* MessageOut outMsg(CMSG_PLAYER_INVENTORY_DROP); outMsg.writeShort(item->getInvIndex()); outMsg.writeShort(quantity); + */ } void LocalPlayer::pickUp(FloorItem *item) @@ -139,8 +146,11 @@ void LocalPlayer::pickUp(FloorItem *item) int dy = item->getY() - mY / 32; if (dx * dx + dy * dy < 4) { + // XXX Convert for new server + /* MessageOut outMsg(CMSG_ITEM_PICKUP); outMsg.writeLong(item->getId()); + */ mPickUpTarget = NULL; } else { setDestination(item->getX() * 32 + 16, item->getY() * 32 + 16); @@ -206,10 +216,7 @@ void LocalPlayer::setDestination(Uint16 x, Uint16 y) x = tx * 32 + fx; y = ty * 32 + fy; - MessageOut msg(PGMSG_WALK); - msg.writeShort(x); - msg.writeShort(y); - Network::send(Network::GAME, msg); + Net::GameServer::Player::walk(x, y); mPickUpTarget = NULL; @@ -218,6 +225,8 @@ void LocalPlayer::setDestination(Uint16 x, Uint16 y) void LocalPlayer::raiseAttribute(Attribute attr) { + // XXX Convert for new server + /* MessageOut outMsg(CMSG_STAT_UPDATE_REQUEST); switch (attr) @@ -247,6 +256,7 @@ void LocalPlayer::raiseAttribute(Attribute attr) break; } outMsg.writeByte(1); + */ } void LocalPlayer::raiseSkill(Uint16 skillId) @@ -254,8 +264,11 @@ void LocalPlayer::raiseSkill(Uint16 skillId) if (mSkillPoint <= 0) return; + // XXX Convert for new server + /* MessageOut outMsg(CMSG_SKILL_LEVELUP_REQUEST); outMsg.writeShort(skillId); + */ } void LocalPlayer::toggleSit() @@ -272,9 +285,12 @@ void LocalPlayer::toggleSit() default: return; } + // XXX Convert for new server + /* MessageOut outMsg(0x0089); outMsg.writeLong(0); outMsg.writeByte(type); + */ } void LocalPlayer::emote(Uint8 emotion) @@ -283,8 +299,11 @@ void LocalPlayer::emote(Uint8 emotion) return; mLastAction = tick_time; + // XXX Convert for new server + /* MessageOut outMsg(0x00bf); outMsg.writeByte(emotion); + */ } void LocalPlayer::tradeReply(bool accept) @@ -292,14 +311,20 @@ void LocalPlayer::tradeReply(bool accept) if (!accept) mTrading = false; + // XXX Convert for new server + /* MessageOut outMsg(CMSG_TRADE_RESPONSE); outMsg.writeByte(accept ? 3 : 4); + */ } void LocalPlayer::trade(Being *being) const { + // XXX Convert for new server + /* MessageOut outMsg(CMSG_TRADE_REQUEST); outMsg.writeLong(being->getId()); + */ } bool LocalPlayer::tradeRequestOk() const @@ -349,9 +374,12 @@ void LocalPlayer::attack(Being *target, bool keep) else sound.playSfx("sfx/fist-swish.ogg"); + // XXX Convert for new server + /* MessageOut outMsg(0x0089); outMsg.writeLong(target->getId()); outMsg.writeByte(0); + */ } void LocalPlayer::stopAttack() @@ -366,6 +394,9 @@ Being* LocalPlayer::getTarget() const void LocalPlayer::revive() { + // XXX Convert for new server + /* MessageOut outMsg(0x00b2); outMsg.writeByte(0); + */ } diff --git a/src/main.cpp b/src/main.cpp index f881ddad..41d49b43 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -66,11 +66,16 @@ #include "gui/textfield.h" #include "net/charserverhandler.h" +#include "net/connection.h" #include "net/loginhandler.h" #include "net/maploginhandler.h" -#include "net/messageout.h" #include "net/network.h" -#include "net/protocol.h" + +#include "net/accountserver/accountserver.h" + +#include "net/chatserver/chatserver.h" + +#include "net/gameserver/gameserver.h" #include "resources/image.h" #include "resources/resourcemanager.h" @@ -98,6 +103,10 @@ Music *bgm; Configuration config; /**< Xml file configuration reader */ Logger *logger; /**< Log object */ +Net::Connection *accountServerConnection = 0; +Net::Connection *gameServerConnection = 0; +Net::Connection *chatServerConnection = 0; + namespace { struct ErrorListener : public gcn::ActionListener { @@ -443,18 +452,15 @@ MapLoginHandler mapLoginHandler; void accountLogin(LoginData *loginData) { logger->log("Username is %s", loginData->username.c_str()); - Network::registerHandler(&loginHandler); - Network::registerHandler(&charServerHandler); + Net::registerHandler(&loginHandler); + Net::registerHandler(&charServerHandler); loginHandler.setLoginData(loginData); charServerHandler.setLoginData(loginData); charServerHandler.setCharInfo(&charInfo); // Send login infos - MessageOut msg(PAMSG_LOGIN); - msg.writeLong(0); // client version - msg.writeString(loginData->username); - msg.writeString(loginData->password); - Network::send(Network::ACCOUNT, msg); + Net::AccountServer::login(accountServerConnection, 0, + loginData->username, loginData->password); // Clear the password, avoids auto login when returning to login loginData->password = ""; @@ -471,36 +477,25 @@ void accountLogin(LoginData *loginData) void accountRegister(LoginData *loginData) { logger->log("Username is %s", loginData->username.c_str()); - Network::registerHandler(&loginHandler); + Net::registerHandler(&loginHandler); loginHandler.setLoginData(loginData); charServerHandler.setLoginData(loginData); charServerHandler.setCharInfo(&charInfo); - // Send login infos - MessageOut msg(PAMSG_REGISTER); - msg.writeLong(0); // client version - msg.writeString(loginData->username); - msg.writeString(loginData->password); - msg.writeString(loginData->email); - Network::send(Network::ACCOUNT, msg); + Net::AccountServer::registerAccount(accountServerConnection, 0, + loginData->username, loginData->password, loginData->email); } void mapLogin(LoginData *loginData) { - Network::registerHandler(&mapLoginHandler); + Net::registerHandler(&mapLoginHandler); logger->log("Memorizing selected character %s", player_node->getName().c_str()); config.setValue("lastCharacter", player_node->getName()); - // 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); - - MessageOut chatServerConnect(PCMSG_CONNECT); - chatServerConnect.writeString(token, 32); - Network::send(Network::CHAT, chatServerConnect); + Net::GameServer::connect(gameServerConnection, token); + Net::ChatServer::connect(chatServerConnection, token); } /** Main */ @@ -582,12 +577,10 @@ int main(int argc, char *argv[]) loginData.remember = config.getValue("remember", 0); - if (enet_initialize() != 0) - { - logger->error("An error occurred while initializing ENet."); - } - Network::initialize(); - + Net::initialize(); + accountServerConnection = Net::getConnection(); + gameServerConnection = Net::getConnection(); + chatServerConnection = Net::getConnection(); SDL_Event event; @@ -610,12 +603,15 @@ int main(int argc, char *argv[]) } gui->logic(); - Network::flush(); + Net::flush(); - if (Network::getState() == Network::NET_ERROR) + if (state > STATE_CONNECT_ACCOUNT && state < STATE_GAME) { - state = STATE_ERROR; - errorMessage = "Got disconnected from server!"; + if (!accountServerConnection->isConnected()) + { + state = STATE_ERROR; + errorMessage = "Got disconnected from account server!"; + } } if (!login_wallpaper) @@ -638,7 +634,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)) + accountServerConnection->isConnected()) { if (options.skipUpdate) { state = STATE_LOGIN; @@ -647,10 +643,10 @@ int main(int argc, char *argv[]) } } else if (state == STATE_CONNECT_GAME && - Network::isConnected(Network::GAME) && - Network::isConnected(Network::CHAT)) + gameServerConnection->isConnected() && + chatServerConnection->isConnected()) { - // TODO: Somehow send the token + accountServerConnection->disconnect(); state = STATE_GAME; } @@ -661,12 +657,6 @@ int main(int argc, char *argv[]) loadUpdates(); } - // Disconnect from account server once connected to game server - if (oldstate == STATE_CONNECT_GAME && state == STATE_GAME) - { - Network::disconnect(Network::ACCOUNT); - } - oldstate = state; // Get rid of the dialog of the previous state @@ -685,9 +675,6 @@ int main(int argc, char *argv[]) if (options.serverName.empty() && options.serverPort == 0) { currentDialog = new ServerDialog(&loginData); } else { - logger->log("Trying to connect to account server..."); - Network::connect(Network::ACCOUNT, - loginData.hostname, loginData.port); state = STATE_CONNECT_ACCOUNT; // Reset options so that cancelling or connect timeout @@ -699,6 +686,9 @@ int main(int argc, char *argv[]) case STATE_CONNECT_ACCOUNT: logger->log("State: CONNECT_ACCOUNT"); + logger->log("Trying to connect to account server..."); + accountServerConnection->connect(loginData.hostname, + loginData.port); currentDialog = new ConnectionDialog(STATE_CHOOSE_SERVER); break; @@ -751,9 +741,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(); + gameServerConnection->disconnect(); + chatServerConnection->disconnect(); + Net::clearHandlers(); break; case STATE_CONNECT_GAME: @@ -783,8 +773,10 @@ int main(int argc, char *argv[]) } } - Network::finalize(); - enet_deinitialize(); + delete accountServerConnection; + delete gameServerConnection; + delete chatServerConnection; + Net::finalize(); if (nullFile) { diff --git a/src/net/accountserver/account.cpp b/src/net/accountserver/account.cpp new file mode 100644 index 00000000..385cd77a --- /dev/null +++ b/src/net/accountserver/account.cpp @@ -0,0 +1,116 @@ +/* + * 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$ + */ + +#include "account.h" + +#include "internal.h" + +#include "../connection.h" +#include "../messageout.h" +#include "../protocol.h" + +void Net::AccountServer::Account::createCharacter( + const std::string &name, char hairColor, char hairStyle, char gender, + short strength, short agility, short vitality, + short intelligence, short dexterity, short luck) +{ + MessageOut msg(PAMSG_CHAR_CREATE); + + msg.writeString(name); + msg.writeByte(hairStyle); + msg.writeByte(hairColor); + msg.writeByte(gender); + msg.writeShort(strength); + msg.writeShort(agility); + msg.writeShort(vitality); + msg.writeShort(intelligence); + msg.writeShort(dexterity); + msg.writeShort(luck); + + Net::AccountServer::connection->send(msg); +} + +void Net::AccountServer::Account::deleteCharacter(char slot) +{ + MessageOut msg(PAMSG_CHAR_DELETE); + + msg.writeByte(slot); + + Net::AccountServer::connection->send(msg); +} + +void Net::AccountServer::Account::selectCharacter(char slot) +{ + MessageOut msg(PAMSG_CHAR_SELECT); + + msg.writeByte(slot); + + Net::AccountServer::connection->send(msg); +} + +void Net::AccountServer::Account::unregister() +{ + MessageOut msg(PAMSG_UNREGISTER); + Net::AccountServer::connection->send(msg); +} + +void Net::AccountServer::Account::changeEmail(const std::string &email) +{ + MessageOut msg(PAMSG_EMAIL_CHANGE); + + msg.writeString(email); + + Net::AccountServer::connection->send(msg); +} + +void Net::AccountServer::Account::getEmail() +{ + MessageOut msg(PAMSG_EMAIL_GET); + + Net::AccountServer::connection->send(msg); +} + +void Net::AccountServer::Account::changePassword( + const std::string &oldPassword, const std::string &newPassword) +{ + MessageOut msg(PAMSG_PASSWORD_CHANGE); + + msg.writeString(oldPassword); + msg.writeString(newPassword); + + Net::AccountServer::connection->send(msg); +} + +void Net::AccountServer::Account::enterWorld() +{ + MessageOut msg(PAMSG_ENTER_WORLD); + + Net::AccountServer::connection->send(msg); +} + +void Net::AccountServer::Account::enterChat() +{ + MessageOut msg(PAMSG_ENTER_CHAT); + + Net::AccountServer::connection->send(msg); +} diff --git a/src/net/accountserver/account.h b/src/net/accountserver/account.h new file mode 100644 index 00000000..8e46eaa5 --- /dev/null +++ b/src/net/accountserver/account.h @@ -0,0 +1,60 @@ +/* + * 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$ + */ + +#ifndef _TMW_NET_ACCOUNTSERVER_CHARACTER_H +#define _TMW_NET_ACCOUNTSERVER_CHARACTER_H + +#include + +namespace Net +{ + namespace AccountServer + { + namespace Account + { + void createCharacter(const std::string &name, + char hairColor, char hairStyle, char gender, + short strength, short agility, short vitality, + short intelligence, short dexterity, short luck); + + void deleteCharacter(char slot); + + void selectCharacter(char slot); + + void unregister(); + + void changeEmail(const std::string &email); + + void getEmail(); + + void changePassword(const std::string &oldPassowrd, + const std::string &newPassword); + + void enterWorld(); + + void enterChat(); + } + } +} + +#endif diff --git a/src/net/accountserver/accountserver.cpp b/src/net/accountserver/accountserver.cpp new file mode 100644 index 00000000..8fde6d5e --- /dev/null +++ b/src/net/accountserver/accountserver.cpp @@ -0,0 +1,68 @@ +/* + * 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$ + */ + +#include "accountserver.h" + +#include "internal.h" + +#include "../connection.h" +#include "../messageout.h" +#include "../protocol.h" + +void Net::AccountServer::login(Net::Connection *connection, int version, + const std::string &username, const std::string &password) +{ + Net::AccountServer::connection = connection; + + MessageOut msg(PAMSG_LOGIN); + + msg.writeLong(version); + msg.writeString(username); + msg.writeString(password); + + Net::AccountServer::connection->send(msg); +} + +void Net::AccountServer::registerAccount(Net::Connection *connection, + int version, const std::string &username, const std::string &password, + const std::string &email) +{ + Net::AccountServer::connection = connection; + + MessageOut msg(PAMSG_REGISTER); + + msg.writeLong(version); // client version + msg.writeString(username); + msg.writeString(password); + msg.writeString(email); + + Net::AccountServer::connection->send(msg); +} + +void Net::AccountServer::logout() +{ + MessageOut msg(PAMSG_LOGOUT); + Net::AccountServer::connection->send(msg); + + Net::AccountServer::connection = 0; +} diff --git a/src/net/accountserver/accountserver.h b/src/net/accountserver/accountserver.h new file mode 100644 index 00000000..c05b5317 --- /dev/null +++ b/src/net/accountserver/accountserver.h @@ -0,0 +1,46 @@ +/* + * 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$ + */ + +#ifndef _TMW_NET_ACCOUNTSERVER_ACCOUNTSERVER_H +#define _TMW_NET_ACCOUNTSERVER_ACCOUNTSERVER_H + +#include + +namespace Net +{ + class Connection; + + namespace AccountServer + { + void login(Net::Connection *connection, int version, + const std::string &username, const std::string &password); + + void registerAccount(Net::Connection *connection, int version, + const std::string &username, const std::string &password, + const std::string &email); + + void logout(); + } +} + +#endif diff --git a/src/net/accountserver/internal.cpp b/src/net/accountserver/internal.cpp new file mode 100644 index 00000000..28a9695e --- /dev/null +++ b/src/net/accountserver/internal.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$ + */ + +#include "internal.h" + +namespace Net +{ + class Connection; + + namespace AccountServer + { + Connection *connection = 0; + } +} diff --git a/src/net/accountserver/internal.h b/src/net/accountserver/internal.h new file mode 100644 index 00000000..8af5ec04 --- /dev/null +++ b/src/net/accountserver/internal.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$ + */ + +#ifndef _TMW_NET_ACCOUNTSERVER_INTERNAL_H +#define _TMW_NET_ACCOUNTSERVER_INTERNAL_H + +namespace Net +{ + class Connection; + + namespace AccountServer + { + extern Connection *connection; + } +} + +#endif diff --git a/src/net/charserverhandler.cpp b/src/net/charserverhandler.cpp index 4e251524..f715b434 100644 --- a/src/net/charserverhandler.cpp +++ b/src/net/charserverhandler.cpp @@ -23,9 +23,9 @@ #include "charserverhandler.h" -#include "messagein.h" -#include "network.h" +#include "connection.h" #include "protocol.h" +#include "messagein.h" #include "../game.h" #include "../localplayer.h" @@ -35,6 +35,9 @@ #include "../gui/ok_dialog.h" +extern Net::Connection *gameServerConnection; +extern Net::Connection *chatServerConnection; + CharServerHandler::CharServerHandler() { static const Uint16 _messages[] = { @@ -174,8 +177,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); + gameServerConnection->connect(gameServer, gameServerPort); + chatServerConnection->connect(chatServer, chatServerPort); // Keep the selected character and delete the others player_node = mCharInfo->getEntry(); diff --git a/src/net/chatserver/chatserver.cpp b/src/net/chatserver/chatserver.cpp new file mode 100644 index 00000000..e6a3331d --- /dev/null +++ b/src/net/chatserver/chatserver.cpp @@ -0,0 +1,116 @@ +/* + * 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$ + */ + +#include "chatserver.h" + +#include "internal.h" + +#include "../connection.h" +#include "../messageout.h" +#include "../protocol.h" + +using Net::ChatServer::connection; + +void Net::ChatServer::connect(Net::Connection *connection, + const std::string &token) +{ + Net::ChatServer::connection = connection; + + MessageOut msg(PCMSG_CONNECT); + + msg.writeString(token, 32); + + connection->send(msg); +} + +void Net::ChatServer::chat(short channel, const std::string &text) +{ + MessageOut msg(PCMSG_CHAT); + + msg.writeString(text); + msg.writeShort(channel); + + connection->send(msg); +} + +void Net::ChatServer::announce(const std::string &text) +{ + MessageOut msg(PCMSG_ANNOUNCE); + + msg.writeString(text); + + connection->send(msg); +} + +void Net::ChatServer::privMsg(const std::string &recipient, + const std::string &text) +{ + MessageOut msg(PCMSG_PRIVMSG); + + msg.writeString(recipient); + msg.writeString(text); + + connection->send(msg); +} + +void Net::ChatServer::registerChannel(const std::string &name, + const std::string &annoucement, const std::string &password, + char isPrivate) +{ + MessageOut msg(PCMSG_REGISTER_CHANNEL); + + msg.writeByte(isPrivate); + msg.writeString(name); + msg.writeString(annoucement); + msg.writeString(password); + + connection->send(msg); +} + +void Net::ChatServer::unregisterChannel(short channel) +{ + MessageOut msg(PCMSG_UNREGISTER_CHANNEL); + + msg.writeShort(channel); + + connection->send(msg); +} + +void Net::ChatServer::enterChannel(short channel, const std::string &password) +{ + MessageOut msg(PCMSG_ENTER_CHANNEL); + + msg.writeShort(channel); + msg.writeString(password); + + connection->send(msg); +} + +void Net::ChatServer::quitChannel(short channel) +{ + MessageOut msg(PCMSG_QUIT_CHANNEL); + + msg.writeShort(channel); + + connection->send(msg); +} diff --git a/src/net/chatserver/chatserver.h b/src/net/chatserver/chatserver.h new file mode 100644 index 00000000..93fe17c4 --- /dev/null +++ b/src/net/chatserver/chatserver.h @@ -0,0 +1,55 @@ +/* + * 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$ + */ + +#ifndef _TMW_NET_CHATSERVER_CHATSERVER_H +#define _TMW_NET_CHATSERVER_CHATSERVER_H + +#include + +namespace Net +{ + class Connection; + + namespace ChatServer + { + void connect(Net::Connection *connection, const std::string &token); + + void chat(short channel, const std::string &text); + + void announce(const std::string &text); + + void privMsg(const std::string &recipient, const std::string &text); + + void registerChannel(const std::string &name, + const std::string &announcement, const std::string &password, + char isPrivate); + + void unregisterChannel(short channel); + + void enterChannel(short channel, const std::string &password); + + void quitChannel(short channel); + } +} + +#endif diff --git a/src/net/chatserver/internal.cpp b/src/net/chatserver/internal.cpp new file mode 100644 index 00000000..c1f7a3f7 --- /dev/null +++ b/src/net/chatserver/internal.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$ + */ + +#include "internal.h" + +namespace Net +{ + class Connection; + + namespace ChatServer + { + Connection *connection = 0; + } +} diff --git a/src/net/chatserver/internal.h b/src/net/chatserver/internal.h new file mode 100644 index 00000000..7579972b --- /dev/null +++ b/src/net/chatserver/internal.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$ + */ + +#ifndef _TMW_NET_CHATSERVER_INTERNAL_H +#define _TMW_NET_CHATSERVER_INTERNAL_H + +namespace Net +{ + class Connection; + + namespace ChatServer + { + extern Connection *connection; + } +} + +#endif diff --git a/src/net/connection.cpp b/src/net/connection.cpp new file mode 100644 index 00000000..a17bc727 --- /dev/null +++ b/src/net/connection.cpp @@ -0,0 +1,104 @@ +/* + * 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$ + */ + +#include "connection.h" + +#include + +#include "internal.h" +#include "messageout.h" + +#include "../log.h" + +Net::Connection::Connection(ENetHost *client): + mConnection(0), mClient(client) +{ + Net::connections++; +} + +Net::Connection::~Connection() +{ + Net::connections--; +} + +bool Net::Connection::connect(const std::string &address, short port) +{ + logger->log("Net::Connection::connect(%s, %i)", address.c_str(), port); + + if (address.empty()) + { + logger->log("Net::Connection::connect() got empty address!"); + mState = ERROR; + return false; + } + + ENetAddress enetAddress; + + enet_address_set_host(&enetAddress, address.c_str()); + enetAddress.port = port; + + // Initiate the connection, allocating channel 0. + mConnection = enet_host_connect(mClient, &enetAddress, 1); + + if (!mConnection) + { + logger->log("Unable to initiate connection to the server."); + mState = ERROR; + return false; + } + + return true; +} + +void Net::Connection::disconnect() +{ + if (!mConnection) + return; + + enet_peer_disconnect(mConnection, 0); + enet_host_flush(mClient); + enet_peer_reset(mConnection); + + mConnection = 0; +} + +bool Net::Connection::isConnected() +{ + return mConnection && mConnection->state == ENET_PEER_STATE_CONNECTED; +} + +void Net::Connection::send(const MessageOut &msg) +{ + if (!isConnected()) + { + logger->log("Warning: cannot send message to not connected server!"); + return; + } + + logger->log("Sending message of size %d...", msg.getDataSize()); + + ENetPacket *packet = enet_packet_create(msg.getData(), + msg.getDataSize(), + ENET_PACKET_FLAG_RELIABLE); + enet_peer_send(mConnection, 0, packet); +} diff --git a/src/net/connection.h b/src/net/connection.h new file mode 100644 index 00000000..179367c6 --- /dev/null +++ b/src/net/connection.h @@ -0,0 +1,78 @@ +/* + * 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$ + */ + +#ifndef _TMW_NET_CONNECTION_H +#define _TMW_NET_CONNECTION_H + +#include + +#include + +class MessageOut; + +namespace Net +{ + class Connection + { + public: + enum State { + OK, ERROR + }; + + ~Connection(); + + /** + * 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 connect(const std::string &address, short port); + + /** + * Disconnects from the given server. + */ + void disconnect(); + + State getState() { return mState; } + + /** + * Returns whether the server is connected. + */ + bool isConnected(); + + /** + * Sends a message. + */ + void send(const MessageOut &msg); + + private: + friend Connection *Net::getConnection(); + Connection(ENetHost *client); + + ENetPeer *mConnection; + ENetHost *mClient; + State mState; + }; +} + +#endif diff --git a/src/net/gameserver/gameserver.cpp b/src/net/gameserver/gameserver.cpp new file mode 100644 index 00000000..04e5bb08 --- /dev/null +++ b/src/net/gameserver/gameserver.cpp @@ -0,0 +1,42 @@ +/* + * 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$ + */ + +#include "gameserver.h" + +#include "internal.h" + +#include "../connection.h" +#include "../messageout.h" +#include "../protocol.h" + +void Net::GameServer::connect(Net::Connection *connection, + const std::string &token) +{ + Net::GameServer::connection = connection; + + MessageOut msg(PGMSG_CONNECT); + + msg.writeString(token, 32); + + Net::GameServer::connection->send(msg); +} diff --git a/src/net/gameserver/gameserver.h b/src/net/gameserver/gameserver.h new file mode 100644 index 00000000..ee49d7e3 --- /dev/null +++ b/src/net/gameserver/gameserver.h @@ -0,0 +1,39 @@ +/* + * 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$ + */ + +#ifndef _TMW_NET_GAMESERVER_GAMESERVER_H +#define _TMW_NET_GAMESERVER_GAMESERVER_H + +#include + +namespace Net +{ + class Connection; + + namespace GameServer + { + void connect(Net::Connection *connection, const std::string &token); + } +} + +#endif diff --git a/src/net/gameserver/internal.cpp b/src/net/gameserver/internal.cpp new file mode 100644 index 00000000..328b4863 --- /dev/null +++ b/src/net/gameserver/internal.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$ + */ + +#include "internal.h" + +namespace Net +{ + class Connection; + + namespace GameServer + { + Connection *connection = 0; + } +} diff --git a/src/net/gameserver/internal.h b/src/net/gameserver/internal.h new file mode 100644 index 00000000..567e15d2 --- /dev/null +++ b/src/net/gameserver/internal.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$ + */ + +#ifndef _TMW_NET_GAMESERVER_INTERNAL_H +#define _TMW_NET_GAMESERVER_INTERNAL_H + +namespace Net +{ + class Connection; + + namespace GameServer + { + extern Connection *connection; + } +} + +#endif diff --git a/src/net/gameserver/player.cpp b/src/net/gameserver/player.cpp new file mode 100644 index 00000000..1f27276a --- /dev/null +++ b/src/net/gameserver/player.cpp @@ -0,0 +1,68 @@ +/* + * 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$ + */ + +#include "player.h" + +#include "internal.h" + +#include "../connection.h" +#include "../messageout.h" +#include "../protocol.h" + +void Net::GameServer::Player::say(const std::string &text) +{ + MessageOut msg(PGMSG_SAY); + + msg.writeString(text); + + Net::GameServer::connection->send(msg); +} + +void Net::GameServer::Player::walk(short x, short y) +{ + MessageOut msg(PGMSG_WALK); + + msg.writeShort(x); + msg.writeShort(y); + + Net::GameServer::connection->send(msg); +} + +void Net::GameServer::Player::useItem(int itemId) +{ + MessageOut msg(PGMSG_USE_ITEM); + + msg.writeLong(itemId); + + Net::GameServer::connection->send(msg); +} + +void Net::GameServer::Player::equip(int itemId, char slot) +{ + MessageOut msg(PGMSG_EQUIP); + + msg.writeLong(itemId); + msg.writeByte(slot); + + Net::GameServer::connection->send(msg); +} diff --git a/src/net/gameserver/player.h b/src/net/gameserver/player.h new file mode 100644 index 00000000..34d5bb45 --- /dev/null +++ b/src/net/gameserver/player.h @@ -0,0 +1,46 @@ +/* + * 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$ + */ + +#ifndef _TMW_NET_GAMESERVER_PLAYER_H +#define _TMW_NET_GAMESERVER_PLAYER_H + +#include + +namespace Net +{ + class Connection; + + namespace GameServer + { + namespace Player + { + void say(const std::string &text); + void walk(short x, short y); +// void pickUp(...); + void useItem(int itemId); + void equip(int itemId, char slot); + } + } +} + +#endif diff --git a/src/net/internal.cpp b/src/net/internal.cpp new file mode 100644 index 00000000..358aa143 --- /dev/null +++ b/src/net/internal.cpp @@ -0,0 +1,29 @@ +/* + * 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$ + */ + +#include "internal.h" + +namespace Net +{ + int connections = 0; +} diff --git a/src/net/internal.h b/src/net/internal.h new file mode 100644 index 00000000..e1ef648a --- /dev/null +++ b/src/net/internal.h @@ -0,0 +1,32 @@ +/* + * 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$ + */ + +#ifndef _TMW_NET_INTERNAL_H +#define _TMW_NET_INTERNAL_H + +namespace Net +{ + extern int connections; +} + +#endif diff --git a/src/net/messagehandler.cpp b/src/net/messagehandler.cpp index 0b5cd87c..b6074690 100644 --- a/src/net/messagehandler.cpp +++ b/src/net/messagehandler.cpp @@ -29,5 +29,5 @@ MessageHandler::~MessageHandler() { - Network::unregisterHandler(this); + Net::unregisterHandler(this); } diff --git a/src/net/network.cpp b/src/net/network.cpp index e56f6df0..b94c9eb8 100644 --- a/src/net/network.cpp +++ b/src/net/network.cpp @@ -23,107 +23,70 @@ #include "network.h" +#include + +#include + +#include "connection.h" +#include "internal.h" #include "messagehandler.h" #include "messagein.h" -#include "messageout.h" #include "../log.h" -static Network::State mState; - /** - * The local host. + * The local host which is shared for all outgoing connections. */ -static ENetHost *mClient; - -/** - * An array holding the peers of the account, game and chat servers. - */ -static ENetPeer *mServers[3]; +namespace { + ENetHost *client; +} typedef std::map MessageHandlers; typedef MessageHandlers::iterator MessageHandlerIterator; static MessageHandlers mMessageHandlers; -Network::State Network::getState() { return mState; } - -void Network::initialize() +void Net::initialize() { - // Initialize server peers - for (int i = 0; i < 3; ++i) - mServers[i] = NULL; - - mClient = enet_host_create(NULL, 3, 0, 0); - - if (!mClient) + if (enet_initialize()) { - logger->error( - "An error occurred while trying to create an ENet client."); - mState = NET_ERROR; + logger->error("Failed to initialize ENet."); } -} - -void Network::finalize() -{ - clearHandlers(); - disconnect(ACCOUNT); - disconnect(GAME); - disconnect(CHAT); -} - -bool -Network::connect(Server server, const std::string &address, short port) -{ - logger->log("Network::connect(%d, %s, %i)", server, address.c_str(), port); + client = enet_host_create(NULL, 3, 0, 0); - if (address.empty()) + if (!client) { - logger->log("Network::connect() got empty address!"); - mState = NET_ERROR; - return false; + logger->error("Failed to create the local host."); } +} - if (mServers[server] != NULL) - { - logger->log("Network::connect() already connected (or connecting) to " - "this server!"); - return false; - } - - ENetAddress enetAddress; - - enet_address_set_host(&enetAddress, address.c_str()); - enetAddress.port = port; - - // Initiate the connection, allocating channel 0. - mServers[server] = enet_host_connect(mClient, &enetAddress, 1); +void Net::finalize() +{ + if (!client) + return; // Wasn't initialized at all - if (mServers[server] == NULL) - { - logger->log("Unable to initiate connection to the server."); - mState = NET_ERROR; - return false; + if (Net::connections) { + logger->error("Tried to shutdown the network subsystem while there " + "are network connections left!"); } - return true; + clearHandlers(); + enet_deinitialize(); } -void -Network::disconnect(Server server) +Net::Connection *Net::getConnection() { - if (mServers[server]) + if (!client) { - enet_peer_disconnect(mServers[server], 0); - enet_host_flush(mClient); - enet_peer_reset(mServers[server]); - - mServers[server] = NULL; + logger->error("Tried to instantiate a network object before " + "initializing the network subsystem!"); } + + return new Net::Connection(client); } void -Network::registerHandler(MessageHandler *handler) +Net::registerHandler(MessageHandler *handler) { for (const Uint16 *i = handler->handledMessages; *i; i++) { @@ -132,7 +95,7 @@ Network::registerHandler(MessageHandler *handler) } void -Network::unregisterHandler(MessageHandler *handler) +Net::unregisterHandler(MessageHandler *handler) { for (const Uint16 *i = handler->handledMessages; *i; i++) { @@ -141,54 +104,46 @@ Network::unregisterHandler(MessageHandler *handler) } void -Network::clearHandlers() +Net::clearHandlers() { mMessageHandlers.clear(); } -bool -Network::isConnected(Server server) -{ - return mServers[server] != NULL && - mServers[server]->state == ENET_PEER_STATE_CONNECTED; -} /** * Dispatches a message to the appropriate message handler and * destroys it afterwards. */ -static void -dispatchMessage(ENetPacket *packet) +namespace { - MessageIn msg((const char *)packet->data, packet->dataLength); - - MessageHandlerIterator iter = mMessageHandlers.find(msg.getId()); - - if (iter != mMessageHandlers.end()) { - logger->log("Received packet %x (%i B)", - msg.getId(), msg.getLength()); - iter->second->handleMessage(msg); - } - else { - logger->log("Unhandled packet %x (%i B)", - msg.getId(), msg.getLength()); - } - - // Clean up the packet now that we're done using it. - enet_packet_destroy(packet); + void + dispatchMessage(ENetPacket *packet) + { + MessageIn msg((const char *)packet->data, packet->dataLength); + + MessageHandlerIterator iter = mMessageHandlers.find(msg.getId()); + + if (iter != mMessageHandlers.end()) { + logger->log("Received packet %x (%i B)", + msg.getId(), msg.getLength()); + iter->second->handleMessage(msg); + } + else { + logger->log("Unhandled packet %x (%i B)", + msg.getId(), msg.getLength()); + } + + // Clean up the packet now that we're done using it. + enet_packet_destroy(packet); + } } -void Network::flush() +void Net::flush() { - if (mState == NET_ERROR) - { - return; - } - ENetEvent event; // Wait up to 10 milliseconds for an event. - while (enet_host_service(mClient, &event, 10) > 0) + while (enet_host_service(client, &event, 10) > 0) { switch (event.type) { @@ -218,40 +173,3 @@ void Network::flush() } } } - -void Network::send(Server server, const MessageOut &msg) -{ - if (mState == NET_ERROR) - { - logger->log("Warning: attempt to send a message while network not " - "ready."); - return; - } - else if (!isConnected(server)) - { - logger->log("Warning: cannot send message to not connected server %d!", - server); - return; - } - - logger->log("Sending message of size %d to server %d...", - msg.getDataSize(), server); - - ENetPacket *packet = enet_packet_create(msg.getData(), - msg.getDataSize(), - ENET_PACKET_FLAG_RELIABLE); - enet_peer_send(mServers[server], 0, packet); -} - -char *iptostring(int address) -{ - static char asciiIP[16]; - - sprintf(asciiIP, "%i.%i.%i.%i", - (unsigned char)(address), - (unsigned char)(address >> 8), - (unsigned char)(address >> 16), - (unsigned char)(address >> 24)); - - return asciiIP; -} diff --git a/src/net/network.h b/src/net/network.h index 1e403c24..819115dd 100644 --- a/src/net/network.h +++ b/src/net/network.h @@ -21,98 +21,51 @@ * $Id$ */ -#ifndef _TMW_NETWORK_ -#define _TMW_NETWORK_ +#ifndef _TMW_NET_NETWORK_H +#define _TMW_NET_NETWORK_H -#include -#include - -#include +#include class MessageHandler; class MessageOut; -/** - * The client network layer. Facilitates connecting and communicating to the - * account, game and chat servers. Also routes incoming message to the - * appropriate message handlers. - */ -class Network +namespace Net { - public: - /** - * Sets up the local host. - */ - static void - initialize(); - - /** - * Closes the connections. - */ - static void - finalize(); - - enum Server { - ACCOUNT, - GAME, - CHAT - }; - - 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. - */ - static bool - connect(Server server, const std::string &address, short port); - - /** - * Disconnects from the given server. - */ - static void - disconnect(Server server); - - /** - * Registers a message handler. A message handler handles a certain - * subset of incoming messages. - */ - static void - registerHandler(MessageHandler *handler); - - /** - * Unregisters a message handler. - */ - static void - unregisterHandler(MessageHandler *handler); - - static void - clearHandlers(); - - static State - getState(); - - /** - * Returns whether the given server is connected. - */ - static bool - isConnected(Server server); - - static void - flush(); - - /** - * Sends a message to a given server. The server should be connected. - */ - static void - send(Server server, const MessageOut &msg); + class Connection; + + /** + * Initializes the network subsystem. + */ + void initialize(); + + /** + * Finalizes the network subsystem. + */ + void finalize(); + + Connection *getConnection(); + + /** + * Registers a message handler. A message handler handles a certain + * subset of incoming messages. + */ + void registerHandler(MessageHandler *handler); + + /** + * Unregisters a message handler. + */ + void unregisterHandler(MessageHandler *handler); + + /** + * Clears all registered message handlers. + */ + void clearHandlers(); + + /* + * Handles all events and dispatches incoming messages to the + * registered handlers + */ + void flush(); }; -/** Convert an address from int format to string */ -char *iptostring(int address); - #endif diff --git a/src/npc.cpp b/src/npc.cpp index b2b426dd..3bd4371b 100644 --- a/src/npc.cpp +++ b/src/npc.cpp @@ -25,9 +25,6 @@ #include "animatedsprite.h" -#include "net/messageout.h" -#include "net/protocol.h" - class Spriteset; extern Spriteset *npcset; @@ -48,25 +45,34 @@ NPC::getType() const void NPC::talk() { + // XXX Convert for new server + /* MessageOut outMsg(CMSG_NPC_TALK); outMsg.writeLong(mId); outMsg.writeByte(0); current_npc = this; + */ } void NPC::nextDialog() { + // XXX Convert for new server + /* MessageOut outMsg(CMSG_NPC_NEXT_REQUEST); outMsg.writeLong(mId); + */ } void NPC::dialogChoice(char choice) { + // XXX Convert for new server + /* MessageOut outMsg(CMSG_NPC_LIST_CHOICE); outMsg.writeLong(mId); outMsg.writeByte(choice); + */ } /* @@ -76,15 +82,21 @@ NPC::dialogChoice(char choice) void NPC::buy() { + // XXX Convert for new server + /* MessageOut outMsg(CMSG_NPC_BUY_SELL_REQUEST); outMsg.writeLong(mId); outMsg.writeByte(0); + */ } void NPC::sell() { + // XXX Convert for new server + /* MessageOut outMsg(CMSG_NPC_BUY_SELL_REQUEST); outMsg.writeLong(mId); outMsg.writeByte(1); + */ } -- cgit v1.2.3-60-g2f50 From 19e15c87a1fc74f71fd6f9a743201a24ac582997 Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Thu, 2 Nov 2006 21:26:57 +0000 Subject: Merged trunk changes from revision 2716 to 2756 into the 0.1.0 branch. --- ChangeLog | 150 +++++++++++++++++++++++++++--------- NEWS | 6 ++ The Mana World.dev | 27 ++++++- configure.ac | 3 + debian/rules | 8 +- debian/tmw-data.dirs | 1 + debian/tmw-data.install | 1 + debian/tmw-music.install | 2 - src/CMakeLists.txt | 2 + src/Makefile.am | 2 + src/game.cpp | 29 +++---- src/gui/buy.cpp | 11 ++- src/gui/buysell.cpp | 2 + src/gui/inventorywindow.cpp | 1 + src/gui/trade.cpp | 10 +-- src/map.cpp | 137 +++++++++++---------------------- src/map.h | 32 +++----- src/net/network.h | 2 +- src/properties.h | 29 ++++++- src/resources/ambientoverlay.cpp | 73 ++++++++++++++++++ src/resources/ambientoverlay.h | 57 ++++++++++++++ src/resources/mapreader.cpp | 128 ++++++++++++++++++------------- tmw.cbp | 41 +++++++++- tools/Purger.java | 159 +++++++++++++++++++++++++++++++++++++++ tools/Reorganize.java | 29 ++++--- 25 files changed, 689 insertions(+), 253 deletions(-) create mode 100644 src/resources/ambientoverlay.cpp create mode 100644 src/resources/ambientoverlay.h create mode 100644 tools/Purger.java (limited to 'src/gui/buy.cpp') diff --git a/ChangeLog b/ChangeLog index a650bcb9..ce76ecdb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,43 +1,123 @@ 2006-11-02 Björn Steinbrink - * src/gui/register.cpp, src/gui/register.h: Fixed a memory leak and a - double deletion. - * src/main.cpp, src/CMakeLists.txt, src/net/loginhandler.cpp, - src/net/charserverhandler.h, src/net/maploginhandler.h, - src/net/maploginhandler.cpp, src/net/loginhandler.h, src/Makefile.am: - Removed some cruft that was needed for eAthena. - * src/localplayer.cpp, src/game.cpp, src/gui/trade.cpp, - src/gui/sell.cpp, src/gui/char_select.cpp, src/gui/serverdialog.cpp, - src/gui/chat.cpp, src/gui/buy.cpp, src/gui/status.cpp, - src/beingmanager.cpp, src/npc.cpp, src/main.cpp, src/CMakeLists.txt, - src/net/connection.cpp, src/net/accountserver, - src/net/accountserver/account.h, src/net/accountserver/internal.h, - src/net/accountserver/accountserver.cpp, - src/net/accountserver/accountserver.h, - src/net/accountserver/account.cpp, src/net/accountserver/internal.cpp, - src/net/internal.cpp, src/net/network.h, - src/net/charserverhandler.cpp, src/net/connection.h, - src/net/gameserver, src/net/gameserver/gameserver.cpp, - src/net/gameserver/player.h, src/net/gameserver/internal.h, - src/net/gameserver/gameserver.h, src/net/gameserver/internal.cpp, - src/net/gameserver/player.cpp, src/net/internal.h, - src/net/messagehandler.cpp, src/net/chatserver, - src/net/chatserver/internal.h, src/net/chatserver/chatserver.cpp, - src/net/chatserver/chatserver.h, src/net/chatserver/internal.cpp, - src/net/network.cpp, src/Makefile.am: Network layer refactoring. + * src/gui/register.cpp, src/gui/register.h: Fixed a memory leak and a + double deletion. + * src/main.cpp, src/CMakeLists.txt, src/net/loginhandler.cpp, + src/net/charserverhandler.h, src/net/maploginhandler.h, + src/net/maploginhandler.cpp, src/net/loginhandler.h, src/Makefile.am: + Removed some cruft that was needed for eAthena. + * src/localplayer.cpp, src/game.cpp, src/gui/trade.cpp, + src/gui/sell.cpp, src/gui/char_select.cpp, src/gui/serverdialog.cpp, + src/gui/chat.cpp, src/gui/buy.cpp, src/gui/status.cpp, + src/beingmanager.cpp, src/npc.cpp, src/main.cpp, src/CMakeLists.txt, + src/net/connection.cpp, src/net/accountserver, + src/net/accountserver/account.h, src/net/accountserver/internal.h, + src/net/accountserver/accountserver.cpp, + src/net/accountserver/accountserver.h, + src/net/accountserver/account.cpp, src/net/accountserver/internal.cpp, + src/net/internal.cpp, src/net/network.h, + src/net/charserverhandler.cpp, src/net/connection.h, + src/net/gameserver, src/net/gameserver/gameserver.cpp, + src/net/gameserver/player.h, src/net/gameserver/internal.h, + src/net/gameserver/gameserver.h, src/net/gameserver/internal.cpp, + src/net/gameserver/player.cpp, src/net/internal.h, + src/net/messagehandler.cpp, src/net/chatserver, + src/net/chatserver/internal.h, src/net/chatserver/chatserver.cpp, + src/net/chatserver/chatserver.h, src/net/chatserver/internal.cpp, + src/net/network.cpp, src/Makefile.am: Network layer refactoring. 2006-11-01 Björn Steinbrink - * CMake/Modules/FindLibXml2.cmake, CMake/Modules/FindENet.cmake, - CMake/Modules/FindLibcurl.cmake, CMake/Modules/FindGuichan.cmake, - src/CMakeLists.txt, src/main.h, data/graphics/tiles/CMakeLists.txt, - data/graphics/items/CMakeLists.txt, data/graphics/gui/CMakeLists.txt, - data/graphics/images/ambient/CMakeLists.txt, - data/graphics/images/CMakeLists.txt, - data/graphics/sprites/CMakeLists.txt, data/graphics/CMakeLists.txt, - data/maps/CMakeLists.txt, data/sfx/CMakeLists.txt, - data/help/CMakeLists.txt, data/icons/CMakeLists.txt, - data/CMakeLists.txt, CMakeLists.txt: Added CMake support. + * CMake/Modules/FindLibXml2.cmake, CMake/Modules/FindENet.cmake, + CMake/Modules/FindLibcurl.cmake, CMake/Modules/FindGuichan.cmake, + src/CMakeLists.txt, src/main.h, data/graphics/tiles/CMakeLists.txt, + data/graphics/items/CMakeLists.txt, data/graphics/gui/CMakeLists.txt, + data/graphics/images/ambient/CMakeLists.txt, + data/graphics/images/CMakeLists.txt, + data/graphics/sprites/CMakeLists.txt, data/graphics/CMakeLists.txt, + data/maps/CMakeLists.txt, data/sfx/CMakeLists.txt, + data/help/CMakeLists.txt, data/icons/CMakeLists.txt, + data/CMakeLists.txt, CMakeLists.txt: Added CMake support. + +2006-10-24 Philipp Sehmisch + + * /data/graphics/images/ambient/night.png: Added graphic for night + ambient effect. + +2006-10-23 Bjørn Lindeijer + + * configure.ac: Added zlib check before PhysFS check. The PhysFS check + was failing on MSYS because of a missing -lz. + +2006-10-12 Yohann Ferreira + + * debian/rules, debian/tmw-data.install, debian/tmw-data.dirs, + debian/tmw-music.install: Updating debian files for bug fixing. + +2006-10-12 Frode Lindeijer + + * /data/graphics/sprites/npcs.png: Updated the clothes salesman, + it was way out of date. + +2006-10-12 Cédric Borgese + + * data/graphics/tiles/Woodland_x3.png : Enlarge the trunk and the + base of the trees in the woodland tileset. + +2006-10-09 Yohann Ferreira + + * src/gui/buysell.cpp, src/gui/buy.cpp : A little tweak to the buy + dialogs. + +2006-10-07 Bjørn Lindeijer + + * src/resources/mapreader.cpp: Added support for gzip compressed map + layers. + * configure.ac, The Mana World.dev: Increased version to 0.0.22. + * src/map.cpp: Removed unused setSize method. Also introduced + initializeOverlays method and removed the confusing setOverlay (which + actually added one). + * src/properties.h: Added convenience method to read a property as a + float. + * src/map.cpp, src/resources/ambientoverlay.cpp, + src/resources/ambientoverlay.h: Resolved some weirdness involving + the terms scroll and speed. + +2006-10-07 Eugenio Favalli + + * The Mana World.dev, tmw.cbp: Updated project files. + +2006-10-03 Bjørn Lindeijer + + * data/graphics/sprites/item006.xml, + data/graphics/sprites/item007.xml, + data/graphics/sprites/item008.xml, + data/graphics/sprites/item009.xml, + data/graphics/sprites/item006.png, + data/graphics/sprites/item007.png, + data/graphics/sprites/item008.png, + data/graphics/sprites/item009.png, + data/graphics/sprites/item010.xml, + data/graphics/sprites/item010.png: Removed empty frames from + headgears. + +2006-10-03 Björn Steinbrink + + * src/map.cpp, src/map.h, src/Makefile.am, + src/resources/mapreader.cpp, src/resources/ambientoverlay.cpp, + src/resources/ambientoverlay.h: Turned AmbientOverlay into a class. + Cleaned up the associated code. + +2006-10-01 Eugenio Favalli + + * tools/Purger.java: Added a tool to purge old accounts from eAthena's + database files. + +2006-10-01 Bjørn Lindeijer + + * src/game.cpp, src/gui/trade.cpp, src/gui/inventorywindow.cpp: + Accepted patches by GDO and VictorSan that fix problems with hiding + windows using h and problems with trade window positioning. 2006-09-28 Björn Steinbrink diff --git a/NEWS b/NEWS index 2b77dca3..4cb3dbb8 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,9 @@ +0.0.22 (...) +- Added support for gzip compressed map layer data +- Fixed problem with OpenGL related redefinition +- Fixed problems with hiding windows using h +- Fixed trade window positioning + 0.0.21 (17 September 2006) - Added item pickup messages to the chat dialog - Added XP bar to ministatus in the top left diff --git a/The Mana World.dev b/The Mana World.dev index c449291e..bff3b310 100644 --- a/The Mana World.dev +++ b/The Mana World.dev @@ -31,20 +31,20 @@ CompilerSettings=0010001001000001001101 [VersionInfo] Major=0 -Minor=0 -Release=20 +Minor=1 +Release=0 Build=0 LanguageID=1033 CharsetID=1252 CompanyName=The Mana World Development Team -FileVersion=0.0.20 +FileVersion=0.1.0 FileDescription=The Mana World InternalName=tmw.exe LegalCopyright=2004-2006 (C) LegalTrademarks= OriginalFilename=tmw.exe ProductName=The Mana World MMORPG -ProductVersion=0.0.20 +ProductVersion=0.1.0 AutoIncBuildNr=0 [Unit8] @@ -2457,3 +2457,22 @@ Priority=1000 OverrideBuildCmd=0 BuildCmd= +[Unit236] +FileName=src\resources\ambientoverlay.cpp +CompileCpp=1 +Folder=resources +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit237] +FileName=src\resources\ambientoverlay.h +CompileCpp=1 +Folder=resources +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= diff --git a/configure.ac b/configure.ac index ce4c6cc5..d32aee08 100755 --- a/configure.ac +++ b/configure.ac @@ -47,6 +47,9 @@ AC_MSG_ERROR([ *** Unable to find SDL library (http://www.libsdl.org/)])) AC_CHECK_HEADERS([SDL.h], , AC_MSG_ERROR([ *** SDL library found but cannot find headers (http://www.libsdl.org/)])) +AC_CHECK_LIB([z], [inflate], , +AC_MSG_ERROR([ *** Unable to find zlib (http://www.gzip.org/zlib/)])) + AC_CHECK_LIB([physfs], [PHYSFS_init], , AC_MSG_ERROR([ *** Unable to find PhysFS library (http://icculus.org/physfs/)])) AC_CHECK_HEADERS([physfs.h], , diff --git a/debian/rules b/debian/rules index da8deaba..b44be0bc 100755 --- a/debian/rules +++ b/debian/rules @@ -17,7 +17,13 @@ DEB_BUILD_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE) config.status: dh_testdir - ./autogen.sh + + echo "Generating build information using aclocal, autoheader, automake and autoconf." +# Regerate configuration files + aclocal + autoheader + automake --gnu --add-missing --copy + autoconf CFLAGS="$(CFLAGS)" ./configure --host=$(DEB_HOST_GNU_TYPE) --build=$(DEB_BUILD_GNU_TYPE) --prefix=/usr --mandir=/usr/share/man6/man --infodir=/usr/share/doc/tmw --datadir=/usr/share/games --bindir=/usr/games --with-opengl diff --git a/debian/tmw-data.dirs b/debian/tmw-data.dirs index aebeb3f8..654af36d 100644 --- a/debian/tmw-data.dirs +++ b/debian/tmw-data.dirs @@ -7,6 +7,7 @@ usr/share/games/tmw/data/graphics usr/share/games/tmw/data/graphics/gui usr/share/games/tmw/data/graphics/sprites usr/share/games/tmw/data/graphics/images +usr/share/games/tmw/data/graphics/items usr/share/games/tmw/data/graphics/tiles usr/share/games/tmw/data/maps usr/share/games/tmw/data/sfx diff --git a/debian/tmw-data.install b/debian/tmw-data.install index 71b34a98..74499687 100644 --- a/debian/tmw-data.install +++ b/debian/tmw-data.install @@ -4,6 +4,7 @@ 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/items/*.png usr/share/games/tmw/data/graphics/items data/graphics/tiles/*.png usr/share/games/tmw/data/graphics/tiles data/maps/*.tmx.gz usr/share/games/tmw/data/maps data/sfx/*.ogg usr/share/games/tmw/data/sfx diff --git a/debian/tmw-music.install b/debian/tmw-music.install index b4a17199..b3494726 100644 --- a/debian/tmw-music.install +++ b/debian/tmw-music.install @@ -1,3 +1 @@ data/music/*.ogg usr/share/games/tmw/data/music -data/music/*.mp3 usr/share/games/tmw/data/music - diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9d1be555..6a46aba4 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -211,6 +211,8 @@ SET(SRCS net/gameserver/internal.h net/gameserver/player.cpp net/gameserver/player.h + resources/ambientoverlay.cpp + resources/ambientoverlay.h resources/buddylist.cpp resources/buddylist.h resources/image.cpp diff --git a/src/Makefile.am b/src/Makefile.am index fc59329d..8ab16e32 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -174,6 +174,8 @@ tmw_SOURCES = graphic/imagerect.h \ net/gameserver/internal.h \ net/gameserver/player.cpp \ net/gameserver/player.h \ + resources/ambientoverlay.cpp \ + resources/ambientoverlay.h \ resources/image.cpp \ resources/image.h \ resources/imagewriter.cpp \ diff --git a/src/game.cpp b/src/game.cpp index 2abd9e26..5052f2ce 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -195,9 +195,7 @@ void createGuiWindows() chargeDialog->setPosition( screenW - 5 - chargeDialog->getWidth(), screenH - chargeDialog->getHeight() - 15); - tradeWindow->setPosition(screenW - statusWindow->getWidth() - - tradeWindow->getWidth() - 10, - inventoryWindow->getY() + inventoryWindow->getHeight()); + /*buddyWindow->setPosition(10, minimap->getHeight() + 30);*/ @@ -488,21 +486,18 @@ void Game::handleInput() } break; - // Attempt to hide all windows + // Hide certain windows case SDLK_h: - statusWindow->setVisible(false); - buyDialog->setVisible(false); - sellDialog->setVisible(false); - buySellDialog->setVisible(false); - inventoryWindow->setVisible(false); - npcTextDialog->setVisible(false); - npcListDialog->setVisible(false); - skillDialog->setVisible(false); - setupWindow->setVisible(false); - equipmentWindow->setVisible(false); - chargeDialog->setVisible(false); - helpWindow->setVisible(false); - debugWindow->setVisible(false); + if (!chatWindow->isFocused()) + { + statusWindow->setVisible(false); + inventoryWindow->setVisible(false); + skillDialog->setVisible(false); + setupWindow->setVisible(false); + equipmentWindow->setVisible(false); + helpWindow->setVisible(false); + debugWindow->setVisible(false); + } break; // Picking up items on the floor diff --git a/src/gui/buy.cpp b/src/gui/buy.cpp index 41bdd67e..73f696b7 100644 --- a/src/gui/buy.cpp +++ b/src/gui/buy.cpp @@ -49,7 +49,7 @@ BuyDialog::BuyDialog(): mScrollArea = new ScrollArea(mItemList); mSlider = new Slider(1.0); mQuantityLabel = new gcn::Label("0"); - mMoneyLabel = new gcn::Label("Price: 0 GP"); + mMoneyLabel = new gcn::Label("Price : 0 GP / 0 GP"); mIncreaseButton = new Button("+", "+", this); mDecreaseButton = new Button("-", "-", this); mBuyButton = new Button("Buy", "buy", this); @@ -113,6 +113,8 @@ BuyDialog::~BuyDialog() void BuyDialog::setMoney(int amount) { mMoney = amount; + mMoneyLabel->setCaption("Price : 0 GP / " + toString(mMoney) + " GP"); + mMoneyLabel->adjustSize(); } void BuyDialog::reset() @@ -128,7 +130,7 @@ void BuyDialog::reset() mDecreaseButton->setEnabled(false); mQuantityLabel->setCaption("0"); mQuantityLabel->adjustSize(); - mMoneyLabel->setCaption("Price: 0"); + mMoneyLabel->setCaption("Price : 0 GP / " + toString(mMoney) + " GP"); mMoneyLabel->adjustSize(); mItemDescLabel->setCaption(""); mItemEffectLabel->setCaption(""); @@ -158,7 +160,7 @@ void BuyDialog::action(const std::string &eventId, gcn::Widget *widget) mSlider->setValue(0); mQuantityLabel->setCaption("0"); mQuantityLabel->adjustSize(); - mMoneyLabel->setCaption("Price : 0 GP"); + mMoneyLabel->setCaption("Price : 0 GP / " + toString(mMoney) + " GP"); mMoneyLabel->adjustSize(); // Disable buttons for buying and decreasing @@ -259,7 +261,8 @@ void BuyDialog::action(const std::string &eventId, gcn::Widget *widget) mQuantityLabel->adjustSize(); int price = mAmountItems * mShopItems->at(selectedItem).price; - mMoneyLabel->setCaption("Price : " + toString(price) + " GP"); + mMoneyLabel->setCaption("Price : " + toString(price) + " GP / " + + toString(mMoney) + " GP" ); mMoneyLabel->adjustSize(); } } diff --git a/src/gui/buysell.cpp b/src/gui/buysell.cpp index ac0dcc84..4bbbb2ff 100644 --- a/src/gui/buysell.cpp +++ b/src/gui/buysell.cpp @@ -48,6 +48,8 @@ BuySellDialog::BuySellDialog(): setContentSize(x, 2 * y + buyButton->getHeight()); setLocationRelativeTo(getParent()); + + requestFocus(); } void BuySellDialog::action(const std::string &eventId, gcn::Widget *widget) diff --git a/src/gui/inventorywindow.cpp b/src/gui/inventorywindow.cpp index ea0fd8c0..452b7c16 100644 --- a/src/gui/inventorywindow.cpp +++ b/src/gui/inventorywindow.cpp @@ -49,6 +49,7 @@ InventoryWindow::InventoryWindow(): setResizable(true); setMinWidth(240); setMinHeight(172); + // If you adjust these defaults, don't forget to adjust the trade window's. setDefaultSize(115, 25, 322, 172); mUseButton = new Button("Use", "use", this); diff --git a/src/gui/trade.cpp b/src/gui/trade.cpp index 630881ea..2ac56ae5 100644 --- a/src/gui/trade.cpp +++ b/src/gui/trade.cpp @@ -47,7 +47,8 @@ TradeWindow::TradeWindow(): mMyInventory(new Inventory()), mPartnerInventory(new Inventory()) { - setContentSize(322, 150); + setWindowName("Trade"); + setDefaultSize(115, 197, 322, 150); mAddButton = new Button("Add", "add", this); mOkButton = new Button("Ok", "ok", this); @@ -100,12 +101,12 @@ TradeWindow::TradeWindow(): mMoneyLabel->setPosition(8 + 60 + 50 + 6, getHeight() - 20); mMoneyLabel2->setPosition(8, getHeight() - 20); - mCancelButton->setPosition(getWidth() - 48, getHeight() - 49); - mTradeButton->setPosition(mCancelButton->getX() - 40 + mCancelButton->setPosition(getWidth() - 54, getHeight() - 49); + mTradeButton->setPosition(mCancelButton->getX() - 41 , getHeight() - 49); mOkButton->setPosition(mTradeButton->getX() - 24, getHeight() - 49); - mAddButton->setPosition(mOkButton->getX() - 32, + mAddButton->setPosition(mOkButton->getX() - 31, getHeight() - 49); mMyItemContainer->setSize(getWidth() - 24 - 12 - 1, @@ -121,7 +122,6 @@ TradeWindow::TradeWindow(): mItemDescriptionLabel->setPosition(8, mItemNameLabel->getY() + mItemNameLabel->getHeight() + 4); - setContentSize(getWidth(), getHeight()); } TradeWindow::~TradeWindow() diff --git a/src/map.cpp b/src/map.cpp index 3ccaafc0..1cdc1077 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -27,13 +27,17 @@ #include #include "beingmanager.h" +#include "game.h" #include "graphics.h" #include "sprite.h" #include "tileset.h" +#include "resources/resourcemanager.h" +#include "resources/ambientoverlay.h" #include "resources/image.h" #include "utils/dtor.h" +#include "utils/tostring.h" /** * A location on a tile map. Used for pathfinding, open list. @@ -79,27 +83,34 @@ Map::~Map() 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(); - } + for_each(mOverlays.begin(), mOverlays.end(), make_dtor(mOverlays)); } void -Map::setSize(int width, int height) +Map::initializeOverlays() { - delete[] mMetaTiles; - delete[] mTiles; + ResourceManager *resman = ResourceManager::getInstance(); + + for (int i = 0; + hasProperty("overlay" + toString(i) + "image"); + i++) + { + const std::string name = "overlay" + toString(i); - mWidth = width; - mHeight = height; + Image *img = resman->getImage(getProperty(name + "image")); + float speedX = getFloatProperty(name + "scrollX"); + float speedY = getFloatProperty(name + "scrollY"); + float parallax = getFloatProperty(name + "parallax"); - int size = width * height; + if (img) + { + mOverlays.push_back( + new AmbientOverlay(img, parallax, speedX, speedY)); - mMetaTiles = new MetaTile[size]; - mTiles = new Image*[size * 3]; - std::fill_n(mTiles, size * 3, (Image*)0); + // The AmbientOverlay takes control over the image. + img->decRef(); + } + } } void @@ -179,99 +190,39 @@ Map::drawOverlay(Graphics *graphics, float scrollX, float scrollY, int detail) { static int lastTick = tick_time; - // detail 0: no overlays + // 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 + // 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; - } + // Update Overlays + int timePassed = get_elapsed_time(lastTick); + float dx = scrollX - mLastScrollX; + float dy = scrollY - mLastScrollY; - //draw overlays + std::list::iterator i; 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; - }; -} + (*i)->update(timePassed, dx, dy); + } + mLastScrollX = scrollX; + mLastScrollY = scrollY; + lastTick = tick_time; -void -Map::setOverlay(Image *image, float speedX, float speedY, float parallax) -{ - if (image != NULL) + // Draw overlays + for (i = mOverlays.begin(); i != mOverlays.end(); i++) { - AmbientOverlay newOverlay; - - newOverlay.image = image; - newOverlay.parallax = parallax; - newOverlay.scrollSpeedX = speedX; - newOverlay.scrollSpeedY = speedY; - newOverlay.scrollX = 0; - newOverlay.scrollY = 0; + (*i)->draw(graphics, graphics->getWidth(), graphics->getHeight()); - mOverlays.push_back(newOverlay); - } + // Detail 1: only one overlay, higher: all overlays + if (detail == 1) + break; + }; } void diff --git a/src/map.h b/src/map.h index 317a0b59..961326b8 100644 --- a/src/map.h +++ b/src/map.h @@ -29,6 +29,7 @@ #include "properties.h" +class AmbientOverlay; class Graphics; class Image; class Tileset; @@ -65,16 +66,6 @@ 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. */ @@ -92,24 +83,22 @@ class Map : public Properties ~Map(); /** - * Draws a map layer to the given graphics output. + * Initialize map overlays. Should be called after all the properties + * are set. */ - void draw(Graphics *graphics, int scrollX, int scrollY, int layer); + void initializeOverlays(); /** - * Sets Overlay Graphic and Scrollspeed + * Draws a map layer to the given graphics output. */ - void setOverlay(Image *image, float speedX, float speedY, float parallax); + void draw(Graphics *graphics, int scrollX, int scrollY, int layer); /** * 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. - */ - void setSize(int width, int height); + void + drawOverlay(Graphics *graphics, float scrollX, float scrollY, + int detail); /** * Adds a tileset to this map. @@ -222,8 +211,7 @@ class Map : public Properties int mOnClosedList, mOnOpenList; //overlay Data - AmbientOverlay mFoo; - std::list mOverlays; + std::list mOverlays; float mLastScrollX; float mLastScrollY; }; diff --git a/src/net/network.h b/src/net/network.h index 819115dd..9ffcbb6d 100644 --- a/src/net/network.h +++ b/src/net/network.h @@ -66,6 +66,6 @@ namespace Net * registered handlers */ void flush(); -}; +} #endif diff --git a/src/properties.h b/src/properties.h index 92690cd3..56e90c0e 100644 --- a/src/properties.h +++ b/src/properties.h @@ -26,6 +26,7 @@ #include #include +#include /** * A class holding a set of properties. @@ -39,16 +40,36 @@ class Properties /** * Get a map property. * - * @return the value of the given property or an empty string when it + * @param def default value, empty string by default + * @return the value of the given property or the given default when it * doesn't exist. */ const std::string& - getProperty(const std::string &name) + getProperty(const std::string &name, const std::string &def = "") { - const static std::string undefined = ""; PropertyMap::const_iterator i = mProperties.find(name); + return (i != mProperties.end()) ? i->second : def; + } - return (i != mProperties.end()) ? i->second : undefined; + /** + * Gets a map property as a float. + * + * @param def default value, 0.0f by default + * @return the value of the given property, or 0.0f when it doesn't + * exist. + */ + const float + getFloatProperty(const std::string &name, float def = 0.0f) + { + PropertyMap::const_iterator i = mProperties.find(name); + float ret = def; + if (i != mProperties.end()) + { + std::stringstream ss; + ss.str(i->second); + ss >> ret; + } + return ret; } /** diff --git a/src/resources/ambientoverlay.cpp b/src/resources/ambientoverlay.cpp new file mode 100644 index 00000000..058b6083 --- /dev/null +++ b/src/resources/ambientoverlay.cpp @@ -0,0 +1,73 @@ +/* + * 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$ + */ + +#include "ambientoverlay.h" + +#include "image.h" + +#include "../graphics.h" + +AmbientOverlay::AmbientOverlay(Image *img, float parallax, + float speedX, float speedY): + mImage(img), mParallax(parallax), + mPosX(0), mPosY(0), + mSpeedX(speedX), mSpeedY(speedY) +{ + mImage->incRef(); +} + +AmbientOverlay::~AmbientOverlay() +{ + mImage->decRef(); +} + +void AmbientOverlay::update(int timePassed, float dx, float dy) +{ + // Self scrolling of the overlay + mPosX -= mSpeedX * timePassed / 10; + mPosY -= mSpeedY * timePassed / 10; + + // Parallax scrolling + mPosX += dx * mParallax; + mPosY += dy * mParallax; + + int imgW = mImage->getWidth(); + int imgH = mImage->getHeight(); + + // Wrap values + while (mPosX > imgW) + mPosX -= imgW; + while (mPosX < 0) + mPosX += imgW; + + while (mPosY > imgH) + mPosY -= imgH; + while (mPosY < 0) + mPosY += imgH; +} + +void AmbientOverlay::draw(Graphics *graphics, int x, int y) +{ + graphics->drawImagePattern(mImage, + (int) -mPosX, (int) -mPosY, x + (int) mPosX, y + (int) mPosY); +} diff --git a/src/resources/ambientoverlay.h b/src/resources/ambientoverlay.h new file mode 100644 index 00000000..a939cbb4 --- /dev/null +++ b/src/resources/ambientoverlay.h @@ -0,0 +1,57 @@ +/* + * 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$ + */ + +#ifndef _TMW_RESOURCES_AMBIENTOVERLAY_H_ +#define _TMW_RESOURCES_AMBIENTOVERLAY_H_ + +class Graphics; +class Image; + +class AmbientOverlay +{ + public: + /** + * Constructor. + */ + AmbientOverlay(Image *img, float parallax, + float speedX, float speedY); + + /** + * Destructor. + */ + ~AmbientOverlay(); + + void update(int timePassed, float dx, float dy); + + void draw(Graphics *graphics, int x, int y); + + private: + Image *mImage; + float mParallax; + float mPosX; /**< Current layer X position. */ + float mPosY; /**< Current layer Y position. */ + float mSpeedX; /**< Scroll speed in X direction. */ + float mSpeedY; /**< Scroll speed in Y direction. */ +}; + +#endif diff --git a/src/resources/mapreader.cpp b/src/resources/mapreader.cpp index c1ae911c..2aea3dc5 100644 --- a/src/resources/mapreader.cpp +++ b/src/resources/mapreader.cpp @@ -24,6 +24,7 @@ #include "mapreader.h" #include +#include #include #include "resourcemanager.h" @@ -51,7 +52,7 @@ inflateMemory(unsigned char *in, unsigned int inLength, int ret; z_stream strm; - out = (unsigned char*)malloc(bufferSize); + out = (unsigned char*) malloc(bufferSize); strm.zalloc = Z_NULL; strm.zfree = Z_NULL; @@ -82,13 +83,13 @@ inflateMemory(unsigned char *in, unsigned int inLength, ret = Z_DATA_ERROR; case Z_DATA_ERROR: case Z_MEM_ERROR: - (void)inflateEnd(&strm); + (void) inflateEnd(&strm); return ret; } if (ret != Z_STREAM_END) { - out = (unsigned char*)realloc(out, bufferSize * 2); + out = (unsigned char*) realloc(out, bufferSize * 2); if (out == NULL) { @@ -105,10 +106,44 @@ inflateMemory(unsigned char *in, unsigned int inLength, assert(strm.avail_in == 0); outLength = bufferSize - strm.avail_out; - (void)inflateEnd(&strm); + (void) inflateEnd(&strm); return ret == Z_STREAM_END ? Z_OK : Z_DATA_ERROR; } +int +inflateMemory(unsigned char *in, unsigned int inLength, + unsigned char *&out) +{ + unsigned int outLength = 0; + int ret = inflateMemory(in, inLength, out, outLength); + + if (ret != Z_OK || out == NULL) + { + if (ret == Z_MEM_ERROR) + { + logger->log("Error: Out of memory while decompressing map data!"); + } + else if (ret == Z_VERSION_ERROR) + { + logger->log("Error: Incompatible zlib version!"); + } + else if (ret == Z_DATA_ERROR) + { + logger->log("Error: Incorrect zlib compressed data!"); + } + else + { + logger->log("Error: Unknown error while decompressing map data!"); + } + + free(out); + out = NULL; + outLength = 0; + } + + return outLength; +} + Map* MapReader::readMap(const std::string &filename) { @@ -126,33 +161,17 @@ MapReader::readMap(const std::string &filename) // Inflate the gzipped map data unsigned char *inflated; - unsigned int inflatedSize = 0; - int ret = inflateMemory((unsigned char*)buffer, - fileSize, inflated, inflatedSize); + unsigned int inflatedSize = inflateMemory((unsigned char*) buffer, + fileSize, inflated); free(buffer); - if (ret == Z_MEM_ERROR) + if (inflated == NULL) { - logger->log("Error: Out of memory while decompressing map data!"); - return NULL; - } - else if (ret == Z_VERSION_ERROR) - { - logger->log("Error: Incompatible zlib version!"); - return NULL; - } - else if (ret == Z_DATA_ERROR) - { - logger->log("Error: Incorrect zlib compressed data!"); - return NULL; - } - else if (ret != Z_OK || inflated == NULL) - { - logger->log("Error: Unknown error while decompressing map data!"); + logger->log("Could not decompress map file (%s)\n", filename.c_str()); return NULL; } - xmlDocPtr doc = xmlParseMemory((char*)inflated, inflatedSize); + xmlDocPtr doc = xmlParseMemory((char*) inflated, inflatedSize); free(inflated); // Parse the inflated map data @@ -214,31 +233,7 @@ 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++; - } + map->initializeOverlays(); return map; } @@ -284,8 +279,8 @@ MapReader::readLayer(xmlNodePtr node, Map *map, int layer) { xmlFree(encoding); - if (compression) { - logger->log("Warning: no layer compression supported!"); + if (compression && !xmlStrEqual(compression, BAD_CAST "gzip")) { + logger->log("Warning: only gzip layer compression supported!"); xmlFree(compression); return; } @@ -313,12 +308,32 @@ MapReader::readLayer(xmlNodePtr node, Map *map, int layer) int binLen; unsigned char *binData = - php_base64_decode(charData, strlen((char*)charData), - &binLen); + php_base64_decode(charData, strlen((char*)charData), &binLen); delete[] charData; if (binData) { + if (compression) { + if (xmlStrEqual(compression, BAD_CAST "gzip")) { + // Inflate the gzipped layer data + unsigned char *inflated; + unsigned int inflatedSize = + inflateMemory(binData, binLen, inflated); + + free(binData); + binData = inflated; + binLen = inflatedSize; + + if (inflated == NULL) + { + logger->log("Error: Could not decompress layer!"); + xmlFree(compression); + return; + } + } + xmlFree(compression); + } + for (int i = 0; i < binLen - 3; i += 4) { int gid = binData[i] | binData[i + 1] << 8 | @@ -351,6 +366,11 @@ MapReader::readLayer(xmlNodePtr node, Map *map, int layer) } } + if (y < h) + std::cerr << "TOO SMALL!\n"; + if (x) + std::cerr << "TOO SMALL!\n"; + // There can be only one data element break; } diff --git a/tmw.cbp b/tmw.cbp index 89a38bcb..492ace6f 100644 --- a/tmw.cbp +++ b/tmw.cbp @@ -28,8 +28,6 @@ - - @@ -42,6 +40,11 @@ + + + + + + + + + + + + + + + + + + +