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/char_select.cpp | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) (limited to 'src/gui/char_select.cpp') diff --git a/src/gui/char_select.cpp b/src/gui/char_select.cpp index 801b0ffe..e8aa84e0 100644 --- a/src/gui/char_select.cpp +++ b/src/gui/char_select.cpp @@ -207,9 +207,9 @@ void CharSelectDialog::updatePlayerInfo() void CharSelectDialog::attemptCharDelete() { // Request character deletion - MessageOut outMsg(mNetwork); - outMsg.writeInt16(0x0068); - outMsg.writeInt32(mCharInfo->getEntry()->mCharId); + MessageOut outMsg; + outMsg.writeShort(0x0068); + outMsg.writeLong(mCharInfo->getEntry()->mCharId); outMsg.writeString("a@a.com", 40); mCharInfo->lock(); } @@ -217,9 +217,9 @@ void CharSelectDialog::attemptCharDelete() void CharSelectDialog::attemptCharSelect() { // Request character selection - MessageOut outMsg(mNetwork); - outMsg.writeInt16(0x0066); - outMsg.writeInt8(mCharInfo->getPos()); + MessageOut outMsg; + outMsg.writeShort(0x0066); + outMsg.writeByte(mCharInfo->getPos()); mCharInfo->lock(); } @@ -326,16 +326,16 @@ std::string CharCreateDialog::getName() void CharCreateDialog::attemptCharCreate() { // Send character infos - MessageOut outMsg(mNetwork); - outMsg.writeInt16(0x0067); + MessageOut outMsg; + outMsg.writeShort(0x0067); outMsg.writeString(getName(), 24); - outMsg.writeInt8(5); - outMsg.writeInt8(5); - outMsg.writeInt8(5); - outMsg.writeInt8(5); - outMsg.writeInt8(5); - outMsg.writeInt8(5); - outMsg.writeInt8(mSlot); - outMsg.writeInt16(mPlayerBox->mHairColor + 1); - outMsg.writeInt16(mPlayerBox->mHairStyle + 1); + outMsg.writeByte(5); + outMsg.writeByte(5); + outMsg.writeByte(5); + outMsg.writeByte(5); + outMsg.writeByte(5); + outMsg.writeByte(5); + outMsg.writeByte(mSlot); + outMsg.writeShort(mPlayerBox->mHairColor + 1); + outMsg.writeShort(mPlayerBox->mHairStyle + 1); } -- cgit v1.2.3-70-g09d2 From aff167beefadc32add4b44626cc2f1cbef800c7b Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Sun, 30 Jul 2006 14:33:28 +0000 Subject: Updated TMW to be compatible with Guichan 0.5.0 (merged from guichan-0.5.0 branch). --- ChangeLog | 33 +++++++++++++++++++++ INSTALL | 6 ++-- src/Makefile.am | 4 +-- src/game.cpp | 4 +-- src/gui/box.h | 27 +++++++++-------- src/gui/buddywindow.cpp | 2 +- src/gui/buddywindow.h | 2 +- src/gui/buy.cpp | 2 +- src/gui/buy.h | 2 +- src/gui/buysell.cpp | 2 +- src/gui/buysell.h | 2 +- src/gui/char_select.cpp | 10 +++---- src/gui/char_select.h | 6 ++-- src/gui/chat.cpp | 27 +++++++++-------- src/gui/chat.h | 2 +- src/gui/confirm_dialog.cpp | 4 +-- src/gui/confirm_dialog.h | 2 +- src/gui/connection.cpp | 2 +- src/gui/debugwindow.cpp | 2 +- src/gui/debugwindow.h | 2 +- src/gui/gui.cpp | 10 +++---- src/gui/help.cpp | 2 +- src/gui/help.h | 2 +- src/gui/inventorywindow.cpp | 7 +++-- src/gui/inventorywindow.h | 2 +- src/gui/item_amount.cpp | 2 +- src/gui/item_amount.h | 2 +- src/gui/login.cpp | 4 +-- src/gui/login.h | 4 +-- src/gui/menuwindow.cpp | 8 ++--- src/gui/ministatus.cpp | 2 +- src/gui/newskill.cpp | 2 +- src/gui/newskill.h | 2 +- src/gui/npc_text.cpp | 2 +- src/gui/npc_text.h | 2 +- src/gui/npclistdialog.cpp | 2 +- src/gui/npclistdialog.h | 2 +- src/gui/ok_dialog.cpp | 4 +-- src/gui/ok_dialog.h | 2 +- src/gui/register.cpp | 2 +- src/gui/register.h | 2 +- src/gui/scrollarea.cpp | 37 +++++++++++++----------- src/gui/sell.cpp | 2 +- src/gui/sell.h | 2 +- src/gui/setup.cpp | 2 +- src/gui/setup.h | 2 +- src/gui/setup_audio.cpp | 2 +- src/gui/setup_audio.h | 2 +- src/gui/setup_joystick.cpp | 2 +- src/gui/setup_joystick.h | 2 +- src/gui/setup_video.cpp | 2 +- src/gui/setup_video.h | 2 +- src/gui/skill.cpp | 2 +- src/gui/skill.h | 2 +- src/gui/status.cpp | 2 +- src/gui/status.h | 2 +- src/gui/tabbedcontainer.cpp | 2 +- src/gui/tabbedcontainer.h | 4 +-- src/gui/textfield.cpp | 2 +- src/gui/trade.cpp | 2 +- src/gui/trade.h | 2 +- src/gui/updatewindow.cpp | 6 ++-- src/gui/updatewindow.h | 2 +- src/gui/vbox.cpp | 18 +++++++----- src/gui/window.cpp | 34 ++++++++-------------- src/main.cpp | 8 +++-- src/net/network.cpp | 11 +++++-- src/net/playerhandler.cpp | 4 +-- src/net/tradehandler.cpp | 2 +- src/openglgraphics.cpp | 28 +++++++++--------- src/resources/openglsdlimageloader.cpp | 34 ++++++++++++++++++++++ src/resources/openglsdlimageloader.h | 37 ++++++++++++++++++++++++ src/resources/resourcemanager.cpp | 17 +++++++++++ src/resources/resourcemanager.h | 8 +++++ src/resources/sdlimageloader.cpp | 53 ++-------------------------------- src/resources/sdlimageloader.h | 4 +-- src/sound.cpp | 2 +- 77 files changed, 320 insertions(+), 235 deletions(-) create mode 100644 src/resources/openglsdlimageloader.cpp create mode 100644 src/resources/openglsdlimageloader.h (limited to 'src/gui/char_select.cpp') diff --git a/ChangeLog b/ChangeLog index f98cea5c..9105dbe7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,36 @@ +2006-07-30 Bjørn Lindeijer + + * src/openglgraphics.cpp, src/game.cpp, src/main.cpp, + src/gui/buddywindow.cpp, src/gui/connection.cpp, src/gui/sell.cpp, + src/gui/trade.cpp, src/gui/char_server.cpp, src/gui/window.cpp, + src/gui/login.cpp, src/gui/skill.h, src/gui/gui.cpp, + src/gui/item_amount.h, src/gui/setup_audio.h, src/gui/newskill.cpp, + src/gui/register.h, src/gui/setup.cpp, src/gui/npclistdialog.h, + src/gui/updatewindow.cpp, src/gui/char_select.cpp, src/gui/login.h, + src/gui/item_amount.cpp, src/gui/setup_audio.cpp, + src/gui/npc_text.cpp, src/gui/chat.h, src/gui/setup_joystick.h, + src/gui/setup_video.cpp, src/gui/ok_dialog.cpp, src/gui/textfield.cpp, + src/gui/inventorywindow.h, src/gui/newskill.h, src/gui/box.h, + src/gui/ministatus.cpp, src/gui/buy.h, src/gui/setup.h, + src/gui/confirm_dialog.cpp, src/gui/debugwindow.cpp, src/gui/vbox.cpp, + src/gui/chat.cpp, src/gui/setup_joystick.cpp, src/gui/updatewindow.h, + src/gui/char_select.h, src/gui/buysell.h, src/gui/tabbedcontainer.cpp, + src/gui/inventorywindow.cpp, src/gui/help.cpp, src/gui/status.h, + src/gui/npc_text.h, src/gui/setup_video.h, src/gui/menuwindow.cpp, + src/gui/ok_dialog.h, src/gui/buy.cpp, src/gui/buddywindow.h, + src/gui/sell.h, src/gui/trade.h, src/gui/char_server.h, + src/gui/skill.cpp, src/gui/buysell.cpp, src/gui/confirm_dialog.h, + src/gui/debugwindow.h, src/gui/status.cpp, src/gui/register.cpp, + src/gui/scrollarea.cpp, src/gui/tabbedcontainer.h, + src/gui/npclistdialog.cpp, src/gui/help.h, src/net/tradehandler.cpp, + src/net/playerhandler.cpp, src/Makefile.am, + src/resources/sdlimageloader.cpp, src/resources/sdlimageloader.h, + src/resources/openglsdlimageloader.cpp, + src/resources/resourcemanager.cpp, + src/resources/openglsdlimageloader.h, src/resources/resourcemanager.h: + Updated TMW to be compatible with Guichan 0.5.0 (merged from + guichan-0.5.0 branch). + 2006-07-27 Eugenio Favalli * src/gui/main.cpp: Modified client version to be an int. diff --git a/INSTALL b/INSTALL index 6cf5b6e5..9779a37a 100644 --- a/INSTALL +++ b/INSTALL @@ -48,11 +48,9 @@ It should have installed The Mana World on your system now, and you can run it with "tmw". By default all files are installed to /usr/local, you can pass a different prefix to configure as usual. - NOTE: For those people with modern video cards and fast OpenGL performance, - we have been working on OpenGL support. At the moment there is no way to - switch between SDL and OpenGL dynamically and you need to do this at compile - time. To try this perform step 3 as follows: + we have been working on OpenGL support. To enable this perform step 3 as + follows: "./configure --with-opengl" diff --git a/src/Makefile.am b/src/Makefile.am index 1bb1d538..42e72829 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -12,8 +12,6 @@ tmw_SOURCES = graphic/imagerect.h \ gui/buysell.h \ gui/chargedialog.cpp \ gui/chargedialog.h \ - gui/char_server.cpp \ - gui/char_server.h \ gui/char_select.cpp \ gui/char_select.h \ gui/chat.cpp \ @@ -167,6 +165,8 @@ tmw_SOURCES = graphic/imagerect.h \ resources/mapreader.h \ resources/music.h \ resources/music.cpp \ + resources/openglsdlimageloader.h \ + resources/openglsdlimageloader.cpp \ resources/resource.cpp \ resources/resource.h \ resources/resourcemanager.cpp \ diff --git a/src/game.cpp b/src/game.cpp index 51b541a6..fab88aa9 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -122,7 +122,7 @@ const int MAX_TIME = 10000; */ namespace { struct ExitListener : public gcn::ActionListener { - void action(const std::string &eventId) { + void action(const std::string &eventId, gcn::Widget *widget) { if (eventId == "yes") { done = true; } @@ -465,7 +465,7 @@ void Game::handleInput() // Close the config window, cancelling changes if opened else if (setupWindow->isVisible()) { - setupWindow->action("cancel"); + setupWindow->action("cancel", NULL); } // Else, open the chat edit box else diff --git a/src/gui/box.h b/src/gui/box.h index dccbfc78..ed1a7163 100644 --- a/src/gui/box.h +++ b/src/gui/box.h @@ -31,27 +31,30 @@ class Box : public gcn::Container { + public: + /** + * Returns padding. + */ + unsigned int getPadding(); + + /** + * Sets padding between widgets. + */ + void setPadding(unsigned int); + protected: Box(); virtual ~Box(); - /* - * Spacing between client widgets + /** + * Spacing between client widgets. */ unsigned int padding; virtual void draw(gcn::Graphics *) = 0; - public: - /* - * Returns padding - */ - unsigned int getPadding(); - - /* - * Sets padding between widgets - */ - void setPadding(unsigned int); + typedef std::list Widgets; + typedef Widgets::iterator WidgetIterator; }; #endif diff --git a/src/gui/buddywindow.cpp b/src/gui/buddywindow.cpp index 19a2f1e0..145f0ad2 100644 --- a/src/gui/buddywindow.cpp +++ b/src/gui/buddywindow.cpp @@ -61,7 +61,7 @@ BuddyWindow::BuddyWindow(): add(cancel); } -void BuddyWindow::action(const std::string& eventId) +void BuddyWindow::action(const std::string &eventId, gcn::Widget *widget) { if (eventId == "Talk") { int selected = mListbox->getSelected(); diff --git a/src/gui/buddywindow.h b/src/gui/buddywindow.h index 6eeb7999..8764d008 100644 --- a/src/gui/buddywindow.h +++ b/src/gui/buddywindow.h @@ -48,7 +48,7 @@ class BuddyWindow : public Window, public gcn::ActionListener /** * Performs action. */ - void action(const std::string &actionId); + void action(const std::string& eventId, gcn::Widget* widget); private: BuddyList *mBuddyList; diff --git a/src/gui/buy.cpp b/src/gui/buy.cpp index e96cc04f..e7bfef58 100644 --- a/src/gui/buy.cpp +++ b/src/gui/buy.cpp @@ -148,7 +148,7 @@ void BuyDialog::addItem(short id, int price) mItemList->adjustSize(); } -void BuyDialog::action(const std::string& eventId) +void BuyDialog::action(const std::string &eventId, gcn::Widget *widget) { int selectedItem = mItemList->getSelected(); diff --git a/src/gui/buy.h b/src/gui/buy.h index 0349be4a..b09b648b 100644 --- a/src/gui/buy.h +++ b/src/gui/buy.h @@ -71,7 +71,7 @@ class BuyDialog : public Window, public gcn::ActionListener /** * Called when receiving actions from the widgets. */ - void action(const std::string& eventId); + void action(const std::string& eventId, gcn::Widget* widget); /** * Returns the number of items in the shop inventory. diff --git a/src/gui/buysell.cpp b/src/gui/buysell.cpp index 6e338f08..ac0dcc84 100644 --- a/src/gui/buysell.cpp +++ b/src/gui/buysell.cpp @@ -50,7 +50,7 @@ BuySellDialog::BuySellDialog(): setLocationRelativeTo(getParent()); } -void BuySellDialog::action(const std::string& eventId) +void BuySellDialog::action(const std::string &eventId, gcn::Widget *widget) { if (eventId == "Buy") { current_npc->buy(); diff --git a/src/gui/buysell.h b/src/gui/buysell.h index 2d3c7bd3..7a90a869 100644 --- a/src/gui/buysell.h +++ b/src/gui/buysell.h @@ -47,7 +47,7 @@ class BuySellDialog : public Window, public gcn::ActionListener /** * Called when receiving actions from the widgets. */ - void action(const std::string& eventId); + void action(const std::string& eventId, gcn::Widget* widget); }; #endif diff --git a/src/gui/char_select.cpp b/src/gui/char_select.cpp index e8aa84e0..934988f4 100644 --- a/src/gui/char_select.cpp +++ b/src/gui/char_select.cpp @@ -48,7 +48,7 @@ class CharDeleteConfirm : public ConfirmDialog { public: CharDeleteConfirm(CharSelectDialog *master); - void action(const std::string &eventId); + void action(const std::string &eventId, gcn::Widget *widget); private: CharSelectDialog *master; }; @@ -60,13 +60,13 @@ CharDeleteConfirm::CharDeleteConfirm(CharSelectDialog *m): { } -void CharDeleteConfirm::action(const std::string &eventId) +void CharDeleteConfirm::action(const std::string &eventId, gcn::Widget *widget) { //ConfirmDialog::action(eventId); if (eventId == "yes") { master->attemptCharDelete(); } - ConfirmDialog::action(eventId); + ConfirmDialog::action(eventId, widget); } CharSelectDialog::CharSelectDialog(Network *network, @@ -126,7 +126,7 @@ CharSelectDialog::CharSelectDialog(Network *network, updatePlayerInfo(); } -void CharSelectDialog::action(const std::string& eventId) +void CharSelectDialog::action(const std::string &eventId, gcn::Widget *widget) { if (eventId == "ok" && n_character > 0) { @@ -284,7 +284,7 @@ CharCreateDialog::CharCreateDialog(Window *parent, int slot, Network *network, setLocationRelativeTo(getParent()); } -void CharCreateDialog::action(const std::string& eventId) +void CharCreateDialog::action(const std::string &eventId, gcn::Widget *widget) { if (eventId == "create") { if (getName().length() >= 4) { diff --git a/src/gui/char_select.h b/src/gui/char_select.h index 8fc7cd01..20105516 100644 --- a/src/gui/char_select.h +++ b/src/gui/char_select.h @@ -29,6 +29,8 @@ #include "../guichanfwd.h" #include "../lockedarray.h" +#include + class LocalPlayer; class Network; class PlayerBox; @@ -49,7 +51,7 @@ class CharSelectDialog : public Window, public gcn::ActionListener LockedArray *charInfo, unsigned char sex); - void action(const std::string& eventId); + void action(const std::string& eventId, gcn::Widget* widget); void updatePlayerInfo(); @@ -101,7 +103,7 @@ class CharCreateDialog : public Window, public gcn::ActionListener CharCreateDialog(Window *parent, int slot, Network *network, unsigned char sex); - void action(const std::string& eventId); + void action(const std::string& eventId, gcn::Widget* widget); std::string getName(); diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp index 870582df..133e5e3a 100644 --- a/src/gui/chat.cpp +++ b/src/gui/chat.cpp @@ -85,18 +85,17 @@ ChatWindow::~ChatWindow() void ChatWindow::logic() { - mChatInput->setPosition( - mChatInput->getBorderSize(), - getContent()->getHeight() - mChatInput->getHeight() - - mChatInput->getBorderSize()); - mChatInput->setWidth( - getContent()->getWidth() - 2 * mChatInput->getBorderSize()); - - mScrollArea->setWidth( - getContent()->getWidth() - 2 * mScrollArea->getBorderSize()); - mScrollArea->setHeight( - getContent()->getHeight() - 2 * mScrollArea->getBorderSize() - - mChatInput->getHeight() - 5); + // todo: only do this when the size changes (updateWidgets?) + + const gcn::Rectangle area = getChildrenArea(); + + mChatInput->setPosition(mChatInput->getBorderSize(), + area.height - mChatInput->getHeight() - + mChatInput->getBorderSize()); + mChatInput->setWidth(area.width - 2 * mChatInput->getBorderSize()); + mScrollArea->setWidth(area.width - 2 * mScrollArea->getBorderSize()); + mScrollArea->setHeight(area.height - 2 * mScrollArea->getBorderSize() - + mChatInput->getHeight() - 5); mScrollArea->logic(); } @@ -189,7 +188,7 @@ ChatWindow::chatLog(CHATSKILL act) } void -ChatWindow::action(const std::string& eventId) +ChatWindow::action(const std::string &eventId, gcn::Widget *widget) { if (eventId == "chatinput") { @@ -246,7 +245,7 @@ ChatWindow::requestChatFocus() bool ChatWindow::isFocused() { - return mChatInput->hasFocus(); + return mChatInput->isFocused(); } void diff --git a/src/gui/chat.h b/src/gui/chat.h index 80e57a84..addfb6b5 100644 --- a/src/gui/chat.h +++ b/src/gui/chat.h @@ -145,7 +145,7 @@ class ChatWindow : public Window, public gcn::ActionListener, /** * Performs action. */ - void action(const std::string &actionId); + void action(const std::string& actionId, gcn::Widget* widget); /** * Request focus for typing chat message. diff --git a/src/gui/confirm_dialog.cpp b/src/gui/confirm_dialog.cpp index 2d574157..ed2f8680 100644 --- a/src/gui/confirm_dialog.cpp +++ b/src/gui/confirm_dialog.cpp @@ -64,13 +64,13 @@ ConfirmDialog::ConfirmDialog(const std::string &title, const std::string &msg, yesButton->requestFocus(); } -void ConfirmDialog::action(const std::string &eventId) +void ConfirmDialog::action(const std::string &eventId, gcn::Widget *widget) { // Proxy button events to our listeners ActionListenerIterator i; for (i = mActionListeners.begin(); i != mActionListeners.end(); ++i) { - (*i)->action(eventId); + (*i)->action(eventId, widget); } // Can we receive anything else anyway? diff --git a/src/gui/confirm_dialog.h b/src/gui/confirm_dialog.h index 3a05494f..1c206b03 100644 --- a/src/gui/confirm_dialog.h +++ b/src/gui/confirm_dialog.h @@ -47,7 +47,7 @@ class ConfirmDialog : public Window, public gcn::ActionListener { /** * Called when receiving actions from the widgets. */ - void action(const std::string& eventId); + void action(const std::string& eventId, gcn::Widget* widget); }; #endif diff --git a/src/gui/connection.cpp b/src/gui/connection.cpp index 4bd619ea..f7fdaca6 100644 --- a/src/gui/connection.cpp +++ b/src/gui/connection.cpp @@ -35,7 +35,7 @@ namespace { struct ConnectionActionListener : public gcn::ActionListener { - void action(const std::string& eventId) { state = EXIT_STATE; } + void action(const std::string &eventId, gcn::Widget *widget) { state = EXIT_STATE; } } listener; } diff --git a/src/gui/debugwindow.cpp b/src/gui/debugwindow.cpp index 66681a8b..d467d4d3 100644 --- a/src/gui/debugwindow.cpp +++ b/src/gui/debugwindow.cpp @@ -98,7 +98,7 @@ DebugWindow::logic() } void -DebugWindow::action(const std::string& eventId) +DebugWindow::action(const std::string &eventId, gcn::Widget *widget) { if (eventId == "close") { diff --git a/src/gui/debugwindow.h b/src/gui/debugwindow.h index 80524ffa..61ef44e6 100644 --- a/src/gui/debugwindow.h +++ b/src/gui/debugwindow.h @@ -53,7 +53,7 @@ class DebugWindow : public Window, public gcn::ActionListener /** * Performs action. */ - void action(const std::string &actionId); + void action(const std::string& eventId, gcn::Widget* widget); private: gcn::Label *mMusicFileLabel, *mMapFileLabel; diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index cb79e54b..c980389f 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -28,7 +28,7 @@ #include #ifdef USE_OPENGL -#include +#include "../resources/openglsdlimageloader.h" #endif #include @@ -92,16 +92,14 @@ Gui::Gui(Graphics *graphics): { // Set graphics setGraphics(graphics); + + // Set image loader #ifdef USE_OPENGL if (config.getValue("opengl", 0)) { - - // Set image loader - mHostImageLoader = new SDLImageLoader(); - mImageLoader = new gcn::OpenGLImageLoader(mHostImageLoader); + mImageLoader = new OpenGLSDLImageLoader(); } else #endif { - // Set image loader mImageLoader = new SDLImageLoader(); } diff --git a/src/gui/help.cpp b/src/gui/help.cpp index dfb814db..e7429b29 100644 --- a/src/gui/help.cpp +++ b/src/gui/help.cpp @@ -54,7 +54,7 @@ HelpWindow::HelpWindow(): setLocationRelativeTo(getParent()); } -void HelpWindow::action(const std::string& eventId) +void HelpWindow::action(const std::string &eventId, gcn::Widget *widget) { if (eventId == "close") { diff --git a/src/gui/help.h b/src/gui/help.h index 44c3d6fc..539ab31b 100644 --- a/src/gui/help.h +++ b/src/gui/help.h @@ -48,7 +48,7 @@ class HelpWindow : public Window, public LinkHandler, /** * Called when receiving actions from the widgets. */ - void action(const std::string& eventId); + void action(const std::string& eventId, gcn::Widget* widget); /** * Handles link action. diff --git a/src/gui/inventorywindow.cpp b/src/gui/inventorywindow.cpp index 8f672bc9..063e8836 100644 --- a/src/gui/inventorywindow.cpp +++ b/src/gui/inventorywindow.cpp @@ -95,7 +95,7 @@ void InventoryWindow::logic() mWeightLabel->adjustSize(); } -void InventoryWindow::action(const std::string &eventId) +void InventoryWindow::action(const std::string &eventId, gcn::Widget *widget) { Item *item = mItems->getItem(); @@ -168,8 +168,9 @@ void InventoryWindow::mouseMotion(int mx, int my) void InventoryWindow::updateWidgets() { - int width = getContent()->getWidth(); - int height = getContent()->getHeight(); + gcn::Rectangle area = getChildrenArea(); + int width = area.width; + int height = area.height; int columns = width / 24; if (columns < 1) diff --git a/src/gui/inventorywindow.h b/src/gui/inventorywindow.h index 179e5314..da7a7ef2 100644 --- a/src/gui/inventorywindow.h +++ b/src/gui/inventorywindow.h @@ -54,7 +54,7 @@ class InventoryWindow : public Window, gcn::ActionListener /** * Called when receiving actions from the widgets. */ - void action(const std::string& eventId); + void action(const std::string& eventId, gcn::Widget* widget); void mouseClick(int x, int y, int button, int count); diff --git a/src/gui/item_amount.cpp b/src/gui/item_amount.cpp index b1b01c3f..30c899a8 100644 --- a/src/gui/item_amount.cpp +++ b/src/gui/item_amount.cpp @@ -94,7 +94,7 @@ void ItemAmountWindow::resetAmount() mItemAmountTextBox->setInt(1); } -void ItemAmountWindow::action(const std::string& eventId) +void ItemAmountWindow::action(const std::string &eventId, gcn::Widget *widget) { int amount = mItemAmountTextBox->getInt(); diff --git a/src/gui/item_amount.h b/src/gui/item_amount.h index ad1e18d6..a2a17575 100644 --- a/src/gui/item_amount.h +++ b/src/gui/item_amount.h @@ -54,7 +54,7 @@ class ItemAmountWindow : public Window, public gcn::ActionListener /** * Called when receiving actions from widget. */ - void action(const std::string& eventId); + void action(const std::string& eventId, gcn::Widget* widget); /** * Sets default amount value. diff --git a/src/gui/login.cpp b/src/gui/login.cpp index c0dd9245..2f646bd1 100644 --- a/src/gui/login.cpp +++ b/src/gui/login.cpp @@ -43,7 +43,7 @@ WrongDataNoticeListener::setTarget(gcn::TextField *textField) } void -WrongDataNoticeListener::action(const std::string &eventId) +WrongDataNoticeListener::action(const std::string &eventId, gcn::Widget *widget) { if (eventId == "ok") { @@ -128,7 +128,7 @@ LoginDialog::~LoginDialog() } void -LoginDialog::action(const std::string& eventId) +LoginDialog::action(const std::string &eventId, gcn::Widget *widget) { if (eventId == "ok") { diff --git a/src/gui/login.h b/src/gui/login.h index 39548950..7218dca8 100644 --- a/src/gui/login.h +++ b/src/gui/login.h @@ -38,7 +38,7 @@ class LoginData; class WrongDataNoticeListener : public gcn::ActionListener { public: void setTarget(gcn::TextField *textField); - void action(const std::string &eventId); + void action(const std::string& eventId, gcn::Widget* widget); private: gcn::TextField *mTarget; }; @@ -65,7 +65,7 @@ class LoginDialog : public Window, public gcn::ActionListener { /** * Called when receiving actions from the widgets. */ - void action(const std::string& eventId); + void action(const std::string& eventId, gcn::Widget* widget); private: gcn::TextField *mUserField; diff --git a/src/gui/menuwindow.cpp b/src/gui/menuwindow.cpp index 503f7ba8..a1b342f0 100644 --- a/src/gui/menuwindow.cpp +++ b/src/gui/menuwindow.cpp @@ -39,7 +39,7 @@ namespace { /** * Called when receiving actions from widget. */ - void action(const std::string& eventId); + void action(const std::string &eventId, gcn::Widget *widget); } listener; } @@ -69,13 +69,13 @@ MenuWindow::MenuWindow(): setDefaultSize((windowContainer->getWidth() - x - 2), 0, x, (y + h)); } -void MenuWindow::draw(gcn::Graphics *g) +void MenuWindow::draw(gcn::Graphics *graphics) { - Window::drawContent(g); + drawChildren(graphics); } -void MenuWindowListener::action(const std::string& eventId) +void MenuWindowListener::action(const std::string &eventId, gcn::Widget *widget) { Window *window = NULL; if (eventId == "Status") diff --git a/src/gui/ministatus.cpp b/src/gui/ministatus.cpp index be089b68..53849550 100644 --- a/src/gui/ministatus.cpp +++ b/src/gui/ministatus.cpp @@ -96,5 +96,5 @@ void MiniStatusWindow::update() void MiniStatusWindow::draw(gcn::Graphics *graphics) { update(); - Window::drawContent(graphics); + drawChildren(graphics); } diff --git a/src/gui/newskill.cpp b/src/gui/newskill.cpp index 498186ba..7f5de543 100644 --- a/src/gui/newskill.cpp +++ b/src/gui/newskill.cpp @@ -121,7 +121,7 @@ NewSkillDialog::NewSkillDialog(): setLocationRelativeTo(getParent()); } -void NewSkillDialog::action(const std::string& eventId) +void NewSkillDialog::action(const std::string &eventId, gcn::Widget *widget) { int osp = startPoint; if (eventId == "close") diff --git a/src/gui/newskill.h b/src/gui/newskill.h index 764019f5..224574bd 100644 --- a/src/gui/newskill.h +++ b/src/gui/newskill.h @@ -55,7 +55,7 @@ class NewSkillDialog : public Window, public gcn::ActionListener NewSkillDialog(); // action listener - void action(const std::string&); + void action(const std::string& eventId, gcn::Widget* widget); private: void resetNSD(); // updates the values in the dialog box diff --git a/src/gui/npc_text.cpp b/src/gui/npc_text.cpp index 1a6bb5ce..5b7ca439 100644 --- a/src/gui/npc_text.cpp +++ b/src/gui/npc_text.cpp @@ -67,7 +67,7 @@ NpcTextDialog::addText(const std::string &text) } void -NpcTextDialog::action(const std::string& eventId) +NpcTextDialog::action(const std::string &eventId, gcn::Widget *widget) { if (eventId == "ok") { diff --git a/src/gui/npc_text.h b/src/gui/npc_text.h index a1d75aab..3ce1215d 100644 --- a/src/gui/npc_text.h +++ b/src/gui/npc_text.h @@ -49,7 +49,7 @@ class NpcTextDialog : public Window, public gcn::ActionListener * Called when receiving actions from the widgets. */ void - action(const std::string &eventId); + action(const std::string& eventId, gcn::Widget* widget); /** * Sets the text shows in the dialog. diff --git a/src/gui/npclistdialog.cpp b/src/gui/npclistdialog.cpp index 2d12986d..d1c3ddcb 100644 --- a/src/gui/npclistdialog.cpp +++ b/src/gui/npclistdialog.cpp @@ -91,7 +91,7 @@ NpcListDialog::reset() } void -NpcListDialog::action(const std::string& eventId) +NpcListDialog::action(const std::string &eventId, gcn::Widget *widget) { int choice = 0; diff --git a/src/gui/npclistdialog.h b/src/gui/npclistdialog.h index 7d649450..03b76681 100644 --- a/src/gui/npclistdialog.h +++ b/src/gui/npclistdialog.h @@ -54,7 +54,7 @@ class NpcListDialog : public Window, public gcn::ActionListener, * Called when receiving actions from the widgets. */ void - action(const std::string& eventId); + action(const std::string& eventId, gcn::Widget* widget); /** * Returns the number of items in the choices list. diff --git a/src/gui/ok_dialog.cpp b/src/gui/ok_dialog.cpp index 2f3f21c5..906fd61f 100644 --- a/src/gui/ok_dialog.cpp +++ b/src/gui/ok_dialog.cpp @@ -54,13 +54,13 @@ OkDialog::OkDialog(const std::string &title, const std::string &msg, okButton->requestFocus(); } -void OkDialog::action(const std::string &eventId) +void OkDialog::action(const std::string &eventId, gcn::Widget *widget) { // Proxy button events to our listeners ActionListenerIterator i; for (i = mActionListeners.begin(); i != mActionListeners.end(); ++i) { - (*i)->action(eventId); + (*i)->action(eventId, widget); } // Can we receive anything else anyway? diff --git a/src/gui/ok_dialog.h b/src/gui/ok_dialog.h index eb0da2c0..06f703cc 100644 --- a/src/gui/ok_dialog.h +++ b/src/gui/ok_dialog.h @@ -46,7 +46,7 @@ class OkDialog : public Window, public gcn::ActionListener { /** * Called when receiving actions from the widgets. */ - void action(const std::string& eventId); + void action(const std::string& eventId, gcn::Widget* widget); }; #endif diff --git a/src/gui/register.cpp b/src/gui/register.cpp index b99568a8..38136b87 100644 --- a/src/gui/register.cpp +++ b/src/gui/register.cpp @@ -116,7 +116,7 @@ RegisterDialog::~RegisterDialog() } void -RegisterDialog::action(const std::string& eventId) +RegisterDialog::action(const std::string &eventId, gcn::Widget *widget) { if (eventId == "cancel") { diff --git a/src/gui/register.h b/src/gui/register.h index b46eb1ce..5d3f6cd5 100644 --- a/src/gui/register.h +++ b/src/gui/register.h @@ -56,7 +56,7 @@ class RegisterDialog : public Window, public gcn::ActionListener { /** * Called when receiving actions from the widgets. */ - void action(const std::string& eventId); + void action(const std::string& eventId, gcn::Widget* widget); // Made them public to have the possibility to request focus // from external functions. diff --git a/src/gui/scrollarea.cpp b/src/gui/scrollarea.cpp index 3703ead8..18a1dfb4 100644 --- a/src/gui/scrollarea.cpp +++ b/src/gui/scrollarea.cpp @@ -55,7 +55,7 @@ ScrollArea::~ScrollArea() { // Garbage collection if (mGC) { - delete mContent; + delete getContent(); } instances--; @@ -144,20 +144,21 @@ void ScrollArea::init() void ScrollArea::logic() { gcn::ScrollArea::logic(); + gcn::Widget *content = getContent(); // When no scrollbar in a certain direction, adapt content size to match // the content dimension exactly. - if (mContent != NULL) + if (content != NULL) { if (getHorizontalScrollPolicy() == gcn::ScrollArea::SHOW_NEVER) { - mContent->setWidth(getContentDimension().width - - 2 * mContent->getBorderSize()); + content->setWidth(getChildrenArea().width - + 2 * content->getBorderSize()); } if (getVerticalScrollPolicy() == gcn::ScrollArea::SHOW_NEVER) { - mContent->setHeight(getContentDimension().height - - 2 * mContent->getBorderSize()); + content->setHeight(getChildrenArea().height - + 2 * content->getBorderSize()); } } } @@ -197,24 +198,26 @@ void ScrollArea::draw(gcn::Graphics *graphics) mScrollbarWidth)); } - if (mContent) + gcn::Widget *content = getContent(); + + if (content != NULL) { - graphics->pushClipArea(getContentDimension()); + graphics->pushClipArea(getChildrenArea()); - if (mContent->getBorderSize() > 0) + if (content->getBorderSize() > 0) { - gcn::Rectangle rec = mContent->getDimension(); - rec.x -= mContent->getBorderSize(); - rec.y -= mContent->getBorderSize(); - rec.width += 2 * mContent->getBorderSize(); - rec.height += 2 * mContent->getBorderSize(); + gcn::Rectangle rec = content->getDimension(); + rec.x -= content->getBorderSize(); + rec.y -= content->getBorderSize(); + rec.width += 2 * content->getBorderSize(); + rec.height += 2 * content->getBorderSize(); graphics->pushClipArea(rec); - mContent->drawBorder(graphics); + content->drawBorder(graphics); graphics->popClipArea(); } - graphics->pushClipArea(mContent->getDimension()); - mContent->draw(graphics); + graphics->pushClipArea(content->getDimension()); + content->draw(graphics); graphics->popClipArea(); graphics->popClipArea(); } diff --git a/src/gui/sell.cpp b/src/gui/sell.cpp index 0b7abf6f..e820d42f 100644 --- a/src/gui/sell.cpp +++ b/src/gui/sell.cpp @@ -152,7 +152,7 @@ void SellDialog::addItem(Item *item, int price) mItemList->adjustSize(); } -void SellDialog::action(const std::string& eventId) +void SellDialog::action(const std::string &eventId, gcn::Widget *widget) { int selectedItem = mItemList->getSelected(); diff --git a/src/gui/sell.h b/src/gui/sell.h index 59bc58c2..423fea26 100644 --- a/src/gui/sell.h +++ b/src/gui/sell.h @@ -68,7 +68,7 @@ class SellDialog : public Window, public gcn::ActionListener /** * Called when receiving actions from the widgets. */ - void action(const std::string& eventId); + void action(const std::string& eventId, gcn::Widget* widget); /** * Mouse callback diff --git a/src/gui/setup.cpp b/src/gui/setup.cpp index e0e0e81b..6af9119b 100644 --- a/src/gui/setup.cpp +++ b/src/gui/setup.cpp @@ -85,7 +85,7 @@ Setup::~Setup() for_each(mTabs.begin(), mTabs.end(), make_dtor(mTabs)); } -void Setup::action(const std::string &event) +void Setup::action(const std::string& event, gcn::Widget *widget) { if (event == "Apply") { diff --git a/src/gui/setup.h b/src/gui/setup.h index 611633c5..6601ce3d 100644 --- a/src/gui/setup.h +++ b/src/gui/setup.h @@ -54,7 +54,7 @@ class Setup : public Window, public gcn::ActionListener * Event handling method. */ void - action(const std::string& eventId); + action(const std::string& eventId, gcn::Widget* widget); private: std::list mTabs; diff --git a/src/gui/setup_audio.cpp b/src/gui/setup_audio.cpp index 6f884e2f..db88ff64 100644 --- a/src/gui/setup_audio.cpp +++ b/src/gui/setup_audio.cpp @@ -108,7 +108,7 @@ void Setup_Audio::cancel() config.setValue("musicVolume", mMusicVolume); } -void Setup_Audio::action(const std::string &event) +void Setup_Audio::action(const std::string& event, gcn::Widget *widget) { if (event == "sfx") { diff --git a/src/gui/setup_audio.h b/src/gui/setup_audio.h index 706d6a50..f09f62da 100644 --- a/src/gui/setup_audio.h +++ b/src/gui/setup_audio.h @@ -38,7 +38,7 @@ class Setup_Audio : public SetupTab, public gcn::ActionListener void apply(); void cancel(); - void action(const std::string&); + void action(const std::string& eventId, gcn::Widget* widget); private: int mMusicVolume, mSfxVolume; diff --git a/src/gui/setup_joystick.cpp b/src/gui/setup_joystick.cpp index fdf50980..36b0ee20 100644 --- a/src/gui/setup_joystick.cpp +++ b/src/gui/setup_joystick.cpp @@ -44,7 +44,7 @@ Setup_Joystick::Setup_Joystick(): add(mCalibrateButton); } -void Setup_Joystick::action(const std::string &event) +void Setup_Joystick::action(const std::string &event, gcn::Widget *widget) { if (!joystick) { return; diff --git a/src/gui/setup_joystick.h b/src/gui/setup_joystick.h index 2abe9678..da773c8f 100644 --- a/src/gui/setup_joystick.h +++ b/src/gui/setup_joystick.h @@ -38,7 +38,7 @@ class Setup_Joystick : public SetupTab, public gcn::ActionListener void apply() {} void cancel() {} - void action(const std::string&); + void action(const std::string& eventId, gcn::Widget* widget); private: gcn::Label *mCalibrateLabel; diff --git a/src/gui/setup_video.cpp b/src/gui/setup_video.cpp index 05543092..9eb94520 100644 --- a/src/gui/setup_video.cpp +++ b/src/gui/setup_video.cpp @@ -237,7 +237,7 @@ void Setup_Video::cancel() config.setValue("opengl", mOpenGLEnabled ? 1 : 0); } -void Setup_Video::action(const std::string &event) +void Setup_Video::action(const std::string &event, gcn::Widget *widget) { if (event == "guialpha") { diff --git a/src/gui/setup_video.h b/src/gui/setup_video.h index b021ead4..d0a10925 100644 --- a/src/gui/setup_video.h +++ b/src/gui/setup_video.h @@ -41,7 +41,7 @@ class Setup_Video : public SetupTab, public gcn::ActionListener, void apply(); void cancel(); - void action(const std::string&); + void action(const std::string &eventId, gcn::Widget *widget); /** Called when key is pressed */ void keyPress(const gcn::Key& key); diff --git a/src/gui/skill.cpp b/src/gui/skill.cpp index 604a19cc..4f552fd7 100644 --- a/src/gui/skill.cpp +++ b/src/gui/skill.cpp @@ -103,7 +103,7 @@ SkillDialog::~SkillDialog() cleanList(); } -void SkillDialog::action(const std::string& eventId) +void SkillDialog::action(const std::string &eventId, gcn::Widget *widget) { if (eventId == "inc") { diff --git a/src/gui/skill.h b/src/gui/skill.h index fe80347d..5555fec4 100644 --- a/src/gui/skill.h +++ b/src/gui/skill.h @@ -57,7 +57,7 @@ class SkillDialog : public Window, public gcn::ActionListener, */ ~SkillDialog(); - void action(const std::string&); + void action(const std::string& eventId, gcn::Widget* widget); void update(); diff --git a/src/gui/status.cpp b/src/gui/status.cpp index 7d6cabac..bf109460 100644 --- a/src/gui/status.cpp +++ b/src/gui/status.cpp @@ -361,7 +361,7 @@ void StatusWindow::draw(gcn::Graphics *g) Window::draw(g); } -void StatusWindow::action(const std::string& eventId) +void StatusWindow::action(const std::string &eventId, gcn::Widget *widget) { // Stats Part if (eventId.length() == 3) diff --git a/src/gui/status.h b/src/gui/status.h index 52ece323..6b963d24 100644 --- a/src/gui/status.h +++ b/src/gui/status.h @@ -51,7 +51,7 @@ class StatusWindow : public Window, public gcn::ActionListener { /** * Called when receiving actions from widget. */ - void action(const std::string& eventId); + void action(const std::string& eventId, gcn::Widget* widget); /** * Draw this window diff --git a/src/gui/tabbedcontainer.cpp b/src/gui/tabbedcontainer.cpp index f1927c6f..e3d2527b 100644 --- a/src/gui/tabbedcontainer.cpp +++ b/src/gui/tabbedcontainer.cpp @@ -78,7 +78,7 @@ void TabbedContainer::logic() Container::logic(); } -void TabbedContainer::action(const std::string &event) +void TabbedContainer::action(const std::string &event, gcn::Widget *widget) { std::stringstream ss(event); int tabNo; diff --git a/src/gui/tabbedcontainer.h b/src/gui/tabbedcontainer.h index 24c8c425..453d8374 100644 --- a/src/gui/tabbedcontainer.h +++ b/src/gui/tabbedcontainer.h @@ -43,7 +43,7 @@ class TabbedContainer : public gcn::Container, public gcn::ActionListener void logic(); - void action(const std::string &event); + void action(const std::string &event, gcn::Widget *widget); void setOpaque(bool opaque); @@ -53,7 +53,7 @@ class TabbedContainer : public gcn::Container, public gcn::ActionListener Widgets mTabs; // The actual tabs at the top Widgets mContents; // The contents of the tabs - Widget *mActiveContent; + gcn::Widget *mActiveContent; }; #endif diff --git a/src/gui/textfield.cpp b/src/gui/textfield.cpp index aa9d04fd..2e083d5a 100644 --- a/src/gui/textfield.cpp +++ b/src/gui/textfield.cpp @@ -82,7 +82,7 @@ TextField::~TextField() void TextField::draw(gcn::Graphics *graphics) { - if (hasFocus()) { + if (isFocused()) { drawCaret(graphics, getFont()->getWidth(mText.substr(0, mCaretPosition)) - mXScroll); diff --git a/src/gui/trade.cpp b/src/gui/trade.cpp index 4efdb06c..73193c88 100644 --- a/src/gui/trade.cpp +++ b/src/gui/trade.cpp @@ -258,7 +258,7 @@ void TradeWindow::mouseClick(int x, int y, int button, int count) mItemDescriptionLabel->adjustSize(); } -void TradeWindow::action(const std::string &eventId) +void TradeWindow::action(const std::string &eventId, gcn::Widget *widget) { Item *item = inventoryWindow->getItem(); diff --git a/src/gui/trade.h b/src/gui/trade.h index 8bf4b86d..eb3c0f97 100644 --- a/src/gui/trade.h +++ b/src/gui/trade.h @@ -110,7 +110,7 @@ class TradeWindow : public Window, gcn::ActionListener /** * Called when receiving actions from the widgets. */ - void action(const std::string& eventId); + void action(const std::string& eventId, gcn::Widget* widget); private: Network *mNetwork; diff --git a/src/gui/updatewindow.cpp b/src/gui/updatewindow.cpp index 3f5fe7bb..9188b6de 100644 --- a/src/gui/updatewindow.cpp +++ b/src/gui/updatewindow.cpp @@ -107,7 +107,7 @@ UpdaterWindow::~UpdaterWindow() } // Remove possibly leftover temporary download - remove((mBasePath + "/updates/download.temp").c_str()); + ::remove((mBasePath + "/updates/download.temp").c_str()); delete[] mCurlError; } @@ -129,7 +129,7 @@ void UpdaterWindow::enable() mPlayButton->requestFocus(); } -void UpdaterWindow::action(const std::string& eventId) +void UpdaterWindow::action(const std::string &eventId, gcn::Widget *widget) { if (eventId == "cancel") { @@ -299,7 +299,7 @@ int UpdaterWindow::downloadThread(void *ptr) // Any existing file with this name is deleted first, otherwise the // rename will fail on Windows. - remove(newName.c_str()); + ::remove(newName.c_str()); rename(outFilename.c_str(), newName.c_str()); } } diff --git a/src/gui/updatewindow.h b/src/gui/updatewindow.h index 5f049e18..8a168be8 100644 --- a/src/gui/updatewindow.h +++ b/src/gui/updatewindow.h @@ -79,7 +79,7 @@ class UpdaterWindow : public Window, public gcn::ActionListener */ void loadNews(); - void action(const std::string& eventId); + void action(const std::string& eventId, gcn::Widget* widget); /** * Add a row to the message field. diff --git a/src/gui/vbox.cpp b/src/gui/vbox.cpp index d79fbba2..eb838ead 100644 --- a/src/gui/vbox.cpp +++ b/src/gui/vbox.cpp @@ -25,17 +25,21 @@ void VBox::draw(gcn::Graphics *graphics) { - int widgetCount = mWidgets.size(); - int childWidth = getWidth(); - if (widgetCount == 0) - return; - int childHeight = getHeight() / widgetCount; + if (mWidgets.size() == 0) + { + return; + } + int childWidth = getWidth(); + int childHeight = getHeight() / mWidgets.size(); int i = 0; - for (WidgetIterator w = mWidgets.begin(); w != mWidgets.end(); w++) { - (*w)->setPosition(0, childHeight * i - padding); + + for (WidgetIterator w = mWidgets.begin(); w != mWidgets.end(); w++) + { + (*w)->setPosition(0, childHeight * i - padding); (*w)->setSize(childWidth, childHeight); i++; } + gcn::Container::draw(graphics); } diff --git a/src/gui/window.cpp b/src/gui/window.cpp index 974a1d73..9a07111f 100644 --- a/src/gui/window.cpp +++ b/src/gui/window.cpp @@ -105,7 +105,7 @@ Window::Window(const std::string& caption, bool modal, Window *parent): // Add chrome mChrome = new GCContainer(); mChrome->setOpaque(false); - setContent(mChrome); + gcn::Window::add(mChrome); // Add this window to the window container windowContainer->add(this); @@ -180,7 +180,7 @@ void Window::draw(gcn::Graphics* graphics) graphics->drawText(getCaption(), 7, 5, gcn::Graphics::LEFT); } - drawContent(graphics); + drawChildren(graphics); } void Window::setContentWidth(int width) @@ -195,7 +195,7 @@ void Window::setContentHeight(int height) resizeToContent(); } -void Window::setLocationRelativeTo(gcn::Widget* widget) +void Window::setLocationRelativeTo(gcn::Widget *widget) { int wx, wy; int x, y; @@ -267,7 +267,7 @@ void Window::mousePress(int x, int y, int button) // border, and is a candidate for a resize. if (isResizable() && button == 1 && getGripDimension().isPointInRect(x, y) && - !getContentDimension().isPointInRect(x, y) && + !getChildrenArea().isPointInRect(x, y) && hasMouse() && !(mMouseDrag && y > (int)getPadding())) { @@ -374,11 +374,8 @@ void Window::mouseMotion(int x, int y) // Set the new window and content dimensions setDimension(newDim); - - if (mContent != NULL && mMouseResize) - { - mContent->setDimension(getContentDimension()); - } + const gcn::Rectangle area = getChildrenArea(); + mChrome->setSize(area.width, area.height); } } @@ -406,18 +403,16 @@ Window::loadWindowState() { const std::string &name = mWindowName; - setPosition((int)config.getValue(name + "WinX", getX()), - (int)config.getValue(name + "WinY", getY())); + setPosition((int) config.getValue(name + "WinX", getX()), + (int) config.getValue(name + "WinY", getY())); if (mResizable) { - setWidth((int)config.getValue(name + "WinWidth", getWidth())); - setHeight((int)config.getValue(name + "WinHeight", getHeight())); + setSize((int) config.getValue(name + "WinWidth", getWidth()), + (int) config.getValue(name + "WinHeight", getHeight())); - if (mContent != NULL) - { - mContent->setDimension(getContentDimension()); - } + const gcn::Rectangle area = getChildrenArea(); + mChrome->setSize(area.width, area.height); } } @@ -437,9 +432,4 @@ void Window::resetToDefaultSize() { setPosition(mDefaultX, mDefaultY); setContentSize(mDefaultWidth, mDefaultHeight); - - if (mContent != NULL) - { - mContent->setDimension(getContentDimension()); - } } diff --git a/src/main.cpp b/src/main.cpp index 8cd6eeb6..1bec709f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -100,7 +100,7 @@ Logger *logger; /**< Log object */ namespace { struct ErrorListener : public gcn::ActionListener { - void action(const std::string& eventId) { state = LOGIN_STATE; } + void action(const std::string &eventId, gcn::Widget *widget) { state = LOGIN_STATE; } } errorListener; } @@ -606,7 +606,8 @@ int main(int argc, char *argv[]) oldstate = state; - if (currentDialog && state != ACCOUNT_STATE && state != CHAR_CONNECT_STATE) { + if (currentDialog && state != ACCOUNT_STATE && + state != CHAR_CONNECT_STATE) { delete currentDialog; currentDialog = NULL; } @@ -631,7 +632,8 @@ int main(int argc, char *argv[]) currentDialog = new CharSelectDialog(network, &charInfo, 1 - loginData.sex); if (options.chooseDefault) { - ((CharSelectDialog*)currentDialog)->action("ok"); + ((CharSelectDialog*)currentDialog)->action("ok", + NULL); } break; diff --git a/src/net/network.cpp b/src/net/network.cpp index aa18e888..64cbf331 100644 --- a/src/net/network.cpp +++ b/src/net/network.cpp @@ -66,7 +66,7 @@ bool Network::connect(const std::string &address, short port) mState = CONNECTING; - mClient = enet_host_create (0, 1, 0, 0); + mClient = enet_host_create(0, 1, 0, 0); if (!mClient) { @@ -160,8 +160,10 @@ void Network::dispatchMessages() void Network::flush() { + logger->log("Network::flush()"); if (mState == IDLE || mState == NET_ERROR) { + logger->log("Idle or error, returning"); return; } @@ -173,20 +175,25 @@ void Network::flush() switch (event.type) { case ENET_EVENT_TYPE_CONNECT: + logger->log("Connected."); mState = CONNECTED; // Store any relevant server information here. event.peer->data = 0; break; case ENET_EVENT_TYPE_RECEIVE: + logger->log("Incoming data..."); mIncomingPackets.push(event.packet); break; case ENET_EVENT_TYPE_DISCONNECT: mState = IDLE; - printf("Disconnected\n"); + logger->log("Disconnected."); // Reset the server information. event.peer->data = 0; break; + case ENET_EVENT_TYPE_NONE: + logger->log("No event during 10 milliseconds."); + break; default: logger->log("Unhandled enet event."); break; diff --git a/src/net/playerhandler.cpp b/src/net/playerhandler.cpp index 5453eae4..c70eada3 100644 --- a/src/net/playerhandler.cpp +++ b/src/net/playerhandler.cpp @@ -46,7 +46,7 @@ OkDialog *deathNotice = NULL; namespace { struct WeightListener : public gcn::ActionListener { - void action(const std::string &eventId) { weightNotice = NULL; } + void action(const std::string &eventId, gcn::Widget *widget) { weightNotice = NULL; } } weightListener; } @@ -56,7 +56,7 @@ namespace { // TODO Move somewhere else namespace { struct DeathListener : public gcn::ActionListener { - void action(const std::string &eventId) { + void action(const std::string &eventId, gcn::Widget *widget) { player_node->revive(); deathNotice = NULL; } diff --git a/src/net/tradehandler.cpp b/src/net/tradehandler.cpp index 0f5bdcdc..b0baa5ea 100644 --- a/src/net/tradehandler.cpp +++ b/src/net/tradehandler.cpp @@ -41,7 +41,7 @@ std::string tradePartnerName; namespace { struct RequestTradeListener : public gcn::ActionListener { - void action(const std::string& eventId) + void action(const std::string &eventId, gcn::Widget *widget) { player_node->tradeReply(eventId == "yes"); }; diff --git a/src/openglgraphics.cpp b/src/openglgraphics.cpp index dc14b6c6..2a6c931d 100644 --- a/src/openglgraphics.cpp +++ b/src/openglgraphics.cpp @@ -31,7 +31,9 @@ #include #endif +#include #include +#include #include "log.h" @@ -227,28 +229,24 @@ void OpenGLGraphics::drawImage(const gcn::Image* image, int dstX, int dstY, int width, int height) { - // The following code finds the real width and height of the texture. - // OpenGL only supports texture sizes that are powers of two - int realImageWidth = 1; - int realImageHeight = 1; - while (realImageWidth < image->getWidth()) - { - realImageWidth *= 2; - } - while (realImageHeight < image->getHeight()) + const gcn::OpenGLImage* srcImage = + dynamic_cast(image); + + if (srcImage == NULL) { - realImageHeight *= 2; + throw GCN_EXCEPTION("Trying to draw an image of unknown format, " + "must be an SDLImage."); } // Find OpenGL texture coordinates - float texX1 = srcX / (float)realImageWidth; - float texY1 = srcY / (float)realImageHeight; - float texX2 = (srcX + width) / (float)realImageWidth; - float texY2 = (srcY + height) / (float)realImageHeight; + float texX1 = srcX / (float)srcImage->getTextureWidth(); + float texY1 = srcY / (float)srcImage->getTextureHeight(); + float texX2 = (srcX + width) / (float)srcImage->getTextureWidth(); + float texY2 = (srcY + height) / (float)srcImage->getTextureHeight(); // Please dont look too closely at the next line, it is not pretty. // It uses the image data as a pointer to a GLuint - glBindTexture(GL_TEXTURE_2D, *((GLuint *)(image->_getData()))); + glBindTexture(GL_TEXTURE_2D, srcImage->getTextureHandle()); drawTexedQuad(dstX, dstY, width, height, texX1, texY1, texX2, texY2); } diff --git a/src/resources/openglsdlimageloader.cpp b/src/resources/openglsdlimageloader.cpp new file mode 100644 index 00000000..f3ddbd84 --- /dev/null +++ b/src/resources/openglsdlimageloader.cpp @@ -0,0 +1,34 @@ +/* + * The Mana World + * Copyright 2004 The Mana World Development Team + * + * This file is part of The Mana World. + * + * The Mana World is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * The Mana World is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with The Mana World; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * $Id: sdlimageloader.cpp 2121 2006-01-31 02:55:26Z der_doener $ + */ + +#include "openglsdlimageloader.h" + +#include + +#include "resourcemanager.h" + +SDL_Surface* OpenGLSDLImageLoader::loadSDLSurface(const std::string& filename) +{ + ResourceManager *resman = ResourceManager::getInstance(); + return resman->loadSDLSurface(filename); +} diff --git a/src/resources/openglsdlimageloader.h b/src/resources/openglsdlimageloader.h new file mode 100644 index 00000000..29be294c --- /dev/null +++ b/src/resources/openglsdlimageloader.h @@ -0,0 +1,37 @@ +/* + * The Mana World + * Copyright 2004 The Mana World Development Team + * + * This file is part of The Mana World. + * + * The Mana World is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * The Mana World is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with The Mana World; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * $Id: sdlimageloader.h 1724 2005-09-12 22:15:35Z der_doener $ + */ + +#ifndef _TMW_OPENGLSDLIMAGELOADER_H +#define _TMW_OPENGLSDLIMAGELOADER_H + +#include + +#include + +class OpenGLSDLImageLoader : public gcn::OpenGLSDLImageLoader +{ + protected: + SDL_Surface* loadSDLSurface(const std::string& filename); +}; + +#endif diff --git a/src/resources/resourcemanager.cpp b/src/resources/resourcemanager.cpp index 6353afac..23a73497 100644 --- a/src/resources/resourcemanager.cpp +++ b/src/resources/resourcemanager.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include "image.h" #include "music.h" @@ -300,3 +301,19 @@ ResourceManager::loadTextFile(const std::string &fileName) free(fileContents); return lines; } + +SDL_Surface* +ResourceManager::loadSDLSurface(const std::string& filename) +{ + int fileSize; + void *buffer = loadFile(filename, fileSize); + SDL_Surface *tmp = NULL; + + if (buffer) { + SDL_RWops *rw = SDL_RWFromMem(buffer, fileSize); + tmp = IMG_Load_RW(rw, 1); + ::free(buffer); + } + + return tmp; +} diff --git a/src/resources/resourcemanager.h b/src/resources/resourcemanager.h index f254a8b4..0086b167 100644 --- a/src/resources/resourcemanager.h +++ b/src/resources/resourcemanager.h @@ -27,6 +27,7 @@ #include #include #include +#include class Resource; class Image; @@ -163,6 +164,13 @@ class ResourceManager std::vector loadTextFile(const std::string &fileName); + /** + * Loads the given filename as an SDL surface. The returned surface is + * expected to be freed by the caller using SDL_FreeSurface. + */ + SDL_Surface* + loadSDLSurface(const std::string& filename); + /** * Returns an instance of the class, creating one if it does not * already exist. diff --git a/src/resources/sdlimageloader.cpp b/src/resources/sdlimageloader.cpp index 88c4143e..ae4f4dcb 100644 --- a/src/resources/sdlimageloader.cpp +++ b/src/resources/sdlimageloader.cpp @@ -24,60 +24,11 @@ #include "sdlimageloader.h" #include -#include - -#include #include "resourcemanager.h" -void SDLImageLoader::prepare(const std::string &filename) +SDL_Surface* SDLImageLoader::loadSDLSurface(const std::string& filename) { - if (mCurrentImage) - { - throw GCN_EXCEPTION("Function called before finalizing or discarding last loaded image."); - } - ResourceManager *resman = ResourceManager::getInstance(); - - int fileSize; - void *buffer = resman->loadFile(filename, fileSize); - - SDL_Surface *tmp = NULL; - if (buffer) { - SDL_RWops *rw = SDL_RWFromMem(buffer, fileSize); - tmp = IMG_Load_RW(rw, 1); - ::free(buffer); - } - - if (!tmp) - { - throw GCN_EXCEPTION(std::string("Unable to load image file: ")+filename); - } - - Uint32 rmask, gmask, bmask, amask; -#if SDL_BYTEORDER == SDL_BIG_ENDIAN - rmask = 0xff000000; - gmask = 0x00ff0000; - bmask = 0x0000ff00; - amask = 0x000000ff; -#else - rmask = 0x000000ff; - gmask = 0x0000ff00; - bmask = 0x00ff0000; - amask = 0xff000000; -#endif - - mCurrentImage = SDL_CreateRGBSurface(SDL_SWSURFACE, 0, 0, 32, - rmask, gmask, bmask, amask); - - if (!mCurrentImage) - { - throw GCN_EXCEPTION(std::string("Not enough memory to load: ")+filename); - } - - SDL_Surface* tmp2 = SDL_ConvertSurface(tmp, mCurrentImage->format, SDL_SWSURFACE); - SDL_FreeSurface(tmp); - SDL_FreeSurface(mCurrentImage); - - mCurrentImage = tmp2; + return resman->loadSDLSurface(filename); } diff --git a/src/resources/sdlimageloader.h b/src/resources/sdlimageloader.h index b34b98fe..50b1d4f1 100644 --- a/src/resources/sdlimageloader.h +++ b/src/resources/sdlimageloader.h @@ -30,8 +30,8 @@ class SDLImageLoader : public gcn::SDLImageLoader { - public: - void prepare(const std::string &filename); + protected: + SDL_Surface* loadSDLSurface(const std::string& filename); }; #endif diff --git a/src/sound.cpp b/src/sound.cpp index 8b012176..182be3d6 100644 --- a/src/sound.cpp +++ b/src/sound.cpp @@ -208,6 +208,6 @@ void Sound::close() stopMusic(); mInstalled = false; - Mix_CloseAudio(); logger->log("Sound::close() Shutting down sound..."); + Mix_CloseAudio(); } -- cgit v1.2.3-70-g09d2 From 25fe73f89756cb4102f97bcccdb8635a6a56f35d Mon Sep 17 00:00:00 2001 From: Eugenio Favalli Date: Wed, 2 Aug 2006 09:43:57 +0000 Subject: Ported account registration to tmwserv. There's still a disconnection/reconnection between registration and login. --- ChangeLog | 8 ++++++++ src/gui/char_select.cpp | 14 ++++++-------- src/gui/char_select.h | 7 ++----- src/gui/register.cpp | 20 +++++++++++++++----- src/gui/register.h | 1 + src/logindata.h | 2 +- src/main.cpp | 28 ++++++++++++++++++++++++---- src/main.h | 1 + src/net/charserverhandler.cpp | 2 -- src/net/loginhandler.cpp | 34 ++++++++++++++++++++++++++++++++++ src/net/protocol.h | 7 +++++++ 11 files changed, 99 insertions(+), 25 deletions(-) (limited to 'src/gui/char_select.cpp') diff --git a/ChangeLog b/ChangeLog index d6049d68..45cd2a9a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2006-08-02 Eugenio Favalli + + * src/gui/char_select.cpp, src/gui/char_select.h, src/gui/register.cpp, + src/gui/register.h, src/logindata.h, src/main.cpp, src/main.h, + src/net/charserverhandler.cpp, src/net/loginhandler.cpp, + src/net/protocol.h: Ported account registration to tmwserv. There's + still a disconnection/reconnection between registration and login. + 2006-08-01 Bjørn Lindeijer * configure.ac: Moved some basic checks above the checks on the diff --git a/src/gui/char_select.cpp b/src/gui/char_select.cpp index 934988f4..27b5b55a 100644 --- a/src/gui/char_select.cpp +++ b/src/gui/char_select.cpp @@ -70,10 +70,9 @@ void CharDeleteConfirm::action(const std::string &eventId, gcn::Widget *widget) } CharSelectDialog::CharSelectDialog(Network *network, - LockedArray *charInfo, - unsigned char sex): + LockedArray *charInfo): Window("Select Character"), mNetwork(network), - mCharInfo(charInfo), mSex(sex), mCharSelected(false) + mCharInfo(charInfo), mCharSelected(false) { mSelectButton = new Button("Ok", "ok", this); mCancelButton = new Button("Cancel", "cancel", this); @@ -86,7 +85,7 @@ CharSelectDialog::CharSelectDialog(Network *network, mLevelLabel = new gcn::Label("Level"); mJobLevelLabel = new gcn::Label("Job Level"); mMoneyLabel = new gcn::Label("Money"); - mPlayerBox = new PlayerBox(sex); + mPlayerBox = new PlayerBox(0); int w = 195; int h = 220; @@ -149,7 +148,7 @@ void CharSelectDialog::action(const std::string &eventId, gcn::Widget *widget) { // Start new character dialog mCharInfo->lock(); - new CharCreateDialog(this, mCharInfo->getPos(), mNetwork, mSex); + new CharCreateDialog(this, mCharInfo->getPos(), mNetwork); mCharInfo->unlock(); } } @@ -228,8 +227,7 @@ void CharSelectDialog::logic() updatePlayerInfo(); } -CharCreateDialog::CharCreateDialog(Window *parent, int slot, Network *network, - unsigned char sex): +CharCreateDialog::CharCreateDialog(Window *parent, int slot, Network *network): Window("Create Character", true, parent), mNetwork(network), mSlot(slot) { mNameField = new TextField(""); @@ -242,7 +240,7 @@ CharCreateDialog::CharCreateDialog(Window *parent, int slot, Network *network, mHairStyleLabel = new gcn::Label("Hair Style:"); mCreateButton = new Button("Create", "create", this); mCancelButton = new Button("Cancel", "cancel", this); - mPlayerBox = new PlayerBox(sex); + mPlayerBox = new PlayerBox(0); mPlayerBox->mShowPlayer = true; mNameField->setEventId("create"); diff --git a/src/gui/char_select.h b/src/gui/char_select.h index 20105516..3bf9911e 100644 --- a/src/gui/char_select.h +++ b/src/gui/char_select.h @@ -48,8 +48,7 @@ class CharSelectDialog : public Window, public gcn::ActionListener * Constructor. */ CharSelectDialog(Network *network, - LockedArray *charInfo, - unsigned char sex); + LockedArray *charInfo); void action(const std::string& eventId, gcn::Widget* widget); @@ -75,7 +74,6 @@ class CharSelectDialog : public Window, public gcn::ActionListener PlayerBox *mPlayerBox; - unsigned char mSex; bool mCharSelected; /** @@ -100,8 +98,7 @@ class CharCreateDialog : public Window, public gcn::ActionListener /** * Constructor. */ - CharCreateDialog(Window *parent, int slot, Network *network, - unsigned char sex); + CharCreateDialog(Window *parent, int slot, Network *network); void action(const std::string& eventId, gcn::Widget* widget); diff --git a/src/gui/register.cpp b/src/gui/register.cpp index 38136b87..82e5f716 100644 --- a/src/gui/register.cpp +++ b/src/gui/register.cpp @@ -50,10 +50,12 @@ RegisterDialog::RegisterDialog(LoginData *loginData): gcn::Label *userLabel = new gcn::Label("Name:"); gcn::Label *passwordLabel = new gcn::Label("Password:"); gcn::Label *confirmLabel = new gcn::Label("Confirm:"); + gcn::Label *emailLabel = new gcn::Label("Email:"); gcn::Label *serverLabel = new gcn::Label("Server:"); mUserField = new TextField("player"); mPasswordField = new PasswordField(); mConfirmField = new PasswordField(); + mEmailField = new TextField(); mServerField = new TextField(); mMaleButton = new RadioButton("Male", "sex", true); mFemaleButton = new RadioButton("Female", "sex", false); @@ -61,7 +63,7 @@ RegisterDialog::RegisterDialog(LoginData *loginData): mCancelButton = new Button("Cancel", "cancel", this); int width = 200; - int height = 150; + int height = 170; setContentSize(width, height); mUserField->setPosition(65, 5); @@ -72,17 +74,21 @@ RegisterDialog::RegisterDialog(LoginData *loginData): mConfirmField->setPosition( 65, mPasswordField->getY() + mPasswordField->getHeight() + 7); mConfirmField->setWidth(130); + mEmailField->setPosition( + 65, mConfirmField->getY() + mConfirmField->getHeight() + 7); + mEmailField->setWidth(130); mServerField->setPosition( - 65, 23 + mConfirmField->getY() + mConfirmField->getHeight() + 7); + 65, 23 + mEmailField->getY() + mEmailField->getHeight() + 7); mServerField->setWidth(130); userLabel->setPosition(5, mUserField->getY() + 1); passwordLabel->setPosition(5, mPasswordField->getY() + 1); confirmLabel->setPosition(5, mConfirmField->getY() + 1); + emailLabel->setPosition(5, mEmailField->getY() + 1); serverLabel->setPosition(5, mServerField->getY() + 1); mFemaleButton->setPosition(width - mFemaleButton->getWidth() - 10, - mConfirmField->getY() + mConfirmField->getHeight() + 7); + mEmailField->getY() + mEmailField->getHeight() + 7); mMaleButton->setPosition(mFemaleButton->getX() - mMaleButton->getWidth() - 5, mFemaleButton->getY()); @@ -92,11 +98,13 @@ RegisterDialog::RegisterDialog(LoginData *loginData): add(userLabel); add(passwordLabel); + add(emailLabel); add(serverLabel); add(confirmLabel); add(mUserField); add(mPasswordField); add(mConfirmField); + add(mEmailField); add(mServerField); add(mMaleButton); add(mFemaleButton); @@ -176,6 +184,8 @@ RegisterDialog::action(const std::string &eventId, gcn::Widget *widget) error = 2; } + // TODO: Check if a valid email address was given + if (error > 0) { if (error == 1) @@ -202,9 +212,9 @@ RegisterDialog::action(const std::string &eventId, gcn::Widget *widget) mLoginData->port = (short)config.getValue("port", 0); mLoginData->username = mUserField->getText(); mLoginData->password = mPasswordField->getText(); - mLoginData->username += mFemaleButton->isMarked() ? "_F" : "_M"; + mLoginData->email = mEmailField->getText(); - state = ACCOUNT_STATE; + state = REGISTER_ACCOUNT_STATE; } } } diff --git a/src/gui/register.h b/src/gui/register.h index 5d3f6cd5..30dacd3e 100644 --- a/src/gui/register.h +++ b/src/gui/register.h @@ -65,6 +65,7 @@ class RegisterDialog : public Window, public gcn::ActionListener { gcn::TextField *mUserField; gcn::TextField *mPasswordField; gcn::TextField *mConfirmField; + gcn::TextField *mEmailField; gcn::TextField *mServerField; gcn::Button *mRegisterButton; diff --git a/src/logindata.h b/src/logindata.h index f4fcd1b1..70b80bb7 100644 --- a/src/logindata.h +++ b/src/logindata.h @@ -29,12 +29,12 @@ struct LoginData std::string username; std::string password; std::string hostname; + std::string email; short port; int account_ID; int session_ID1; int session_ID2; - char sex; bool remember; }; diff --git a/src/main.cpp b/src/main.cpp index 1bec709f..ce68b7bb 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -447,6 +447,25 @@ void accountLogin(Network *network, LoginData *loginData) config.setValue("remember", loginData->remember); } +void accountRegister(Network *network, LoginData *loginData) +{ + logger->log("Trying to connect to account server..."); + logger->log("Username is %s", loginData->username.c_str()); + network->connect(loginData->hostname, loginData->port); + network->registerHandler(&loginHandler); + loginHandler.setCharInfo(&charInfo); + loginHandler.setLoginData(loginData); + + // Send login infos + MessageOut *msg = new MessageOut(); + msg->writeShort(PAMSG_REGISTER); + msg->writeLong(0); // client version + msg->writeString(loginData->username); + msg->writeString(loginData->password); + msg->writeString(loginData->email); + network->send(msg); +} + void mapLogin(Network *network, LoginData *loginData) { MessageOut outMsg; @@ -463,7 +482,6 @@ void mapLogin(Network *network, LoginData *loginData) outMsg.writeLong(player_node->mCharId); outMsg.writeLong(loginData->session_ID1); outMsg.writeLong(loginData->session_ID2); - outMsg.writeByte(loginData->sex); } /** Main */ @@ -629,8 +647,7 @@ int main(int argc, char *argv[]) case CHAR_SELECT_STATE: logger->log("State: CHAR_SELECT"); - currentDialog = new CharSelectDialog(network, &charInfo, - 1 - loginData.sex); + currentDialog = new CharSelectDialog(network, &charInfo); if (options.chooseDefault) { ((CharSelectDialog*)currentDialog)->action("ok", NULL); @@ -672,10 +689,13 @@ int main(int argc, char *argv[]) break; case ACCOUNT_STATE: - printf("Account: %i\n", loginData.sex); accountLogin(network, &loginData); break; + case REGISTER_ACCOUNT_STATE: + accountRegister(network, &loginData); + break; + default: state = EXIT_STATE; break; diff --git a/src/main.h b/src/main.h index f8bfb4d9..035b0ec7 100644 --- a/src/main.h +++ b/src/main.h @@ -43,6 +43,7 @@ enum { LOGIN_STATE, ACCOUNT_STATE, REGISTER_STATE, + REGISTER_ACCOUNT_STATE, CHAR_CONNECT_STATE, CHAR_SERVER_STATE, CHAR_SELECT_STATE, diff --git a/src/net/charserverhandler.cpp b/src/net/charserverhandler.cpp index 932a6fbc..36a17acf 100644 --- a/src/net/charserverhandler.cpp +++ b/src/net/charserverhandler.cpp @@ -159,8 +159,6 @@ void CharServerHandler::handleMessage(MessageIn *msg) LocalPlayer* CharServerHandler::readPlayerData(MessageIn *msg, int &slot) { LocalPlayer *tempPlayer = new LocalPlayer(mLoginData->account_ID, 0, NULL); - tempPlayer->setSex(1 - mLoginData->sex); - tempPlayer->mCharId = msg->readLong(); tempPlayer->mTotalWeight = 0; tempPlayer->mMaxWeight = 0; diff --git a/src/net/loginhandler.cpp b/src/net/loginhandler.cpp index 5b8fbd1f..ebc8f535 100644 --- a/src/net/loginhandler.cpp +++ b/src/net/loginhandler.cpp @@ -36,6 +36,7 @@ LoginHandler::LoginHandler() { static const Uint16 _messages[] = { APMSG_LOGIN_RESPONSE, + APMSG_REGISTER_RESPONSE, 0 }; handledMessages = _messages; @@ -46,6 +47,7 @@ void LoginHandler::handleMessage(MessageIn *msg) switch (msg->getId()) { case APMSG_LOGIN_RESPONSE: + { int errMsg = msg->readByte(); // Successful login if (errMsg == ERRMSG_OK) @@ -90,6 +92,38 @@ void LoginHandler::handleMessage(MessageIn *msg) } state = ERROR_STATE; } + } + break; + case APMSG_REGISTER_RESPONSE: + { + int errMsg = msg->readByte(); + // Successful registration + if (errMsg == ERRMSG_OK) + { + state = ACCOUNT_STATE; + } + // Registration failed + else { + switch (errMsg) { + case REGISTER_INVALID_VERSION: + errorMessage = "Client has an insufficient version number to login."; + break; + case ERRMSG_INVALID_ARGUMENT: + errorMessage = "Wrong username, password or email address"; + break; + case REGISTER_EXISTS_USERNAME: + errorMessage = "Username already exists"; + break; + case REGISTER_EXISTS_EMAIL: + errorMessage = "Email address already exists"; + break; + default: + errorMessage = "Unknown error"; + break; + } + state = ERROR_STATE; + } + } break; } } diff --git a/src/net/protocol.h b/src/net/protocol.h index 6a13bbd9..6db3762e 100644 --- a/src/net/protocol.h +++ b/src/net/protocol.h @@ -200,6 +200,13 @@ enum { LOGIN_SERVER_FULL // the server is overloaded }; +// Account register specific return values +enum { + REGISTER_INVALID_VERSION = 0x40, // the user is using an incompatible protocol + REGISTER_EXISTS_USERNAME, // there already is an account with this username + REGISTER_EXISTS_EMAIL // there already is an account with this email address +}; + /** Encodes coords and direction in 3 bytes data */ void set_coordinates(char *data, unsigned short x, unsigned short y, unsigned char direction); -- cgit v1.2.3-70-g09d2 From 680351853a7580df7e441cffa5840e7e6d103c8a Mon Sep 17 00:00:00 2001 From: Guillaume Melquiond Date: Fri, 4 Aug 2006 08:15:22 +0000 Subject: Fixed character gender in selection dialog. --- ChangeLog | 4 ++++ src/gui/char_select.cpp | 1 + 2 files changed, 5 insertions(+) (limited to 'src/gui/char_select.cpp') diff --git a/ChangeLog b/ChangeLog index ea4ac6f6..37de8504 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2006-08-04 Guillaume Melquiond + + * src/gui/char_select.cpp: Fixed character gender in selection dialog. + 2006-08-02 Guillaume Melquiond * configure.ac, src/Makefile.am: Put object files in subdirectories. diff --git a/src/gui/char_select.cpp b/src/gui/char_select.cpp index 27b5b55a..75887b99 100644 --- a/src/gui/char_select.cpp +++ b/src/gui/char_select.cpp @@ -187,6 +187,7 @@ void CharSelectDialog::updatePlayerInfo() } mPlayerBox->mHairStyle = pi->getHairStyle() - 1; mPlayerBox->mHairColor = pi->getHairColor() - 1; + mPlayerBox->mSex = pi->getSex(); mPlayerBox->mShowPlayer = true; } else { mNameLabel->setCaption("Name"); -- cgit v1.2.3-70-g09d2 From c79bf8c82f0a38b574b83be2484eb347852cd833 Mon Sep 17 00:00:00 2001 From: Eugenio Favalli Date: Mon, 14 Aug 2006 08:36:16 +0000 Subject: Completed porting of character creation/deletion, fixed some issues with network code. --- ChangeLog | 12 +++ src/being.cpp | 2 +- src/being.h | 4 +- src/gui/char_select.cpp | 42 ++++---- src/gui/char_select.h | 1 - src/gui/playerbox.cpp | 3 +- src/gui/playerbox.h | 8 +- src/gui/status.cpp | 12 +-- src/gui/status.h | 2 +- src/localplayer.cpp | 1 + src/localplayer.h | 2 +- src/main.cpp | 39 ++++---- src/net/buysellhandler.cpp | 2 +- src/net/charserverhandler.cpp | 216 ++++++++++++++++++------------------------ src/net/loginhandler.cpp | 19 +--- src/net/loginhandler.h | 3 - src/net/messageout.cpp | 4 +- src/net/messageout.h | 4 +- src/net/network.cpp | 8 +- src/net/network.h | 5 +- src/net/playerhandler.cpp | 2 +- src/net/protocol.h | 14 ++- 22 files changed, 191 insertions(+), 214 deletions(-) (limited to 'src/gui/char_select.cpp') diff --git a/ChangeLog b/ChangeLog index 5e958852..3d6a947f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2006-08-14 Eugenio Favalli + + * src/being.cpp, src/being.h, src/gui/char_select.cpp, + src/gui/char_select.h, src/gui/playerbox.cpp, src/gui/playerbox.h, + src/gui/status.cpp, src/gui/status.h, src/localplayer.cpp, + src/localplayer.h, src/main.cpp, src/net/buysellhandler.cpp, + src/net/charserverhandler.cpp, src/net/loginhandler.cpp, + src/net/loginhandler.h, src/net/messageout.cpp, src/net/messageout.h, + src/net/network.cpp, src/net/network.h, src/net/playerhandler.cpp, + src/net/protocol.h: Completed porting of character creation/deletion, + fixed some issues with network code. + 2006-08-14 Bjørn Lindeijer * src/player.cpp: Verify the gender to prevent crashing when something diff --git a/src/being.cpp b/src/being.cpp index 1ca8929a..7755d4e5 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -46,6 +46,7 @@ PATH_NODE::PATH_NODE(Uint16 iX, Uint16 iY): } Being::Being(Uint32 id, Uint16 job, Map *map): + mSex(2), mJob(job), mX(0), mY(0), mDirection(DOWN), mAction(0), @@ -58,7 +59,6 @@ Being::Being(Uint32 id, Uint16 job, Map *map): mWalkSpeed(150), mMap(NULL), mHairStyle(0), mHairColor(0), - mSex(2), mSpeechTime(0), mDamageTime(0), mShowSpeech(false), mShowDamage(false) diff --git a/src/being.h b/src/being.h index 0735efe9..055ea0d4 100644 --- a/src/being.h +++ b/src/being.h @@ -98,6 +98,8 @@ class Being : public Sprite static const char UP = 4; static const char RIGHT = 8; + std::string mName; /**< Name of character */ + Uint8 mSex; /**< Character's gender */ Uint16 mJob; /**< Job (player job, npc, monster, ) */ Uint16 mX, mY; /**< Tile coordinates */ Uint8 mDirection; /**< Facing direction */ @@ -358,14 +360,12 @@ class Being : public Sprite Uint16 mWeapon; /**< Weapon picture id */ Uint16 mWalkSpeed; /**< Walking speed */ Map *mMap; /**< Map on which this being resides */ - std::string mName; /**< Name of character */ SpriteIterator mSpriteIterator; Path mPath; std::string mSpeech; std::string mDamage; Uint16 mHairStyle, mHairColor; - Uint8 mSex; Uint32 mSpeechTime; Uint32 mDamageTime; bool mShowSpeech, mShowDamage; diff --git a/src/gui/char_select.cpp b/src/gui/char_select.cpp index 75887b99..775eea24 100644 --- a/src/gui/char_select.cpp +++ b/src/gui/char_select.cpp @@ -38,6 +38,8 @@ #include "../main.h" #include "../net/messageout.h" +#include "../net/network.h" +#include "../net/protocol.h" #include "../utils/tostring.h" @@ -83,7 +85,6 @@ CharSelectDialog::CharSelectDialog(Network *network, mNameLabel = new gcn::Label("Name"); mLevelLabel = new gcn::Label("Level"); - mJobLevelLabel = new gcn::Label("Job Level"); mMoneyLabel = new gcn::Label("Money"); mPlayerBox = new PlayerBox(0); @@ -93,7 +94,6 @@ CharSelectDialog::CharSelectDialog(Network *network, mPlayerBox->setDimension(gcn::Rectangle(5, 5, w - 10, 90)); mNameLabel->setDimension(gcn::Rectangle(10, 100, 128, 16)); mLevelLabel->setDimension(gcn::Rectangle(10, 116, 128, 16)); - mJobLevelLabel->setDimension(gcn::Rectangle(10, 132, 128, 16)); mMoneyLabel->setDimension(gcn::Rectangle(10, 148, 128, 16)); mPreviousButton->setPosition(5, 170); mNextButton->setPosition(mPreviousButton->getWidth() + 10, 170); @@ -117,7 +117,6 @@ CharSelectDialog::CharSelectDialog(Network *network, add(mNextButton); add(mNameLabel); add(mLevelLabel); - add(mJobLevelLabel); add(mMoneyLabel); mSelectButton->requestFocus(); @@ -177,8 +176,7 @@ void CharSelectDialog::updatePlayerInfo() if (pi) { mNameLabel->setCaption(pi->getName()); mLevelLabel->setCaption("Lvl: " + toString(pi->mLevel)); - mJobLevelLabel->setCaption("Job Lvl: " + toString(pi->mJobLevel)); - mMoneyLabel->setCaption("Gold: " + toString(pi->mGp)); + mMoneyLabel->setCaption("Money: " + toString(pi->mMoney)); if (!mCharSelected) { mNewCharButton->setEnabled(false); @@ -192,7 +190,6 @@ void CharSelectDialog::updatePlayerInfo() } else { mNameLabel->setCaption("Name"); mLevelLabel->setCaption("Level"); - mJobLevelLabel->setCaption("Job Level"); mMoneyLabel->setCaption("Money"); mNewCharButton->setEnabled(true); mDelCharButton->setEnabled(false); @@ -207,10 +204,11 @@ void CharSelectDialog::updatePlayerInfo() void CharSelectDialog::attemptCharDelete() { // Request character deletion - MessageOut outMsg; - outMsg.writeShort(0x0068); - outMsg.writeLong(mCharInfo->getEntry()->mCharId); - outMsg.writeString("a@a.com", 40); + MessageOut msg; + msg.writeShort(PAMSG_CHAR_DELETE); + // TODO: Send the selected slot + msg.writeByte(0); + network->send(msg); mCharInfo->lock(); } @@ -326,15 +324,17 @@ void CharCreateDialog::attemptCharCreate() { // Send character infos MessageOut outMsg; - outMsg.writeShort(0x0067); - outMsg.writeString(getName(), 24); - outMsg.writeByte(5); - outMsg.writeByte(5); - outMsg.writeByte(5); - outMsg.writeByte(5); - outMsg.writeByte(5); - outMsg.writeByte(5); - outMsg.writeByte(mSlot); - outMsg.writeShort(mPlayerBox->mHairColor + 1); - outMsg.writeShort(mPlayerBox->mHairStyle + 1); + outMsg.writeShort(PAMSG_CHAR_CREATE); + outMsg.writeString(getName()); + outMsg.writeByte(mPlayerBox->mHairStyle + 1); + outMsg.writeByte(mPlayerBox->mHairColor + 1); + // 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(outMsg); } diff --git a/src/gui/char_select.h b/src/gui/char_select.h index 3bf9911e..e65f400d 100644 --- a/src/gui/char_select.h +++ b/src/gui/char_select.h @@ -69,7 +69,6 @@ class CharSelectDialog : public Window, public gcn::ActionListener gcn::Label *mNameLabel; gcn::Label *mLevelLabel; - gcn::Label *mJobLevelLabel; gcn::Label *mMoneyLabel; PlayerBox *mPlayerBox; diff --git a/src/gui/playerbox.cpp b/src/gui/playerbox.cpp index f0ed9b71..d8faff99 100644 --- a/src/gui/playerbox.cpp +++ b/src/gui/playerbox.cpp @@ -94,8 +94,7 @@ void PlayerBox::draw(gcn::Graphics *graphics) playerset[mSex]->get(0), 23, 12); // Draw his hair - if (mHairColor >= 0 && mHairStyle >= 0 && - mHairColor < NR_HAIR_COLORS && mHairStyle < NR_HAIR_STYLES) + if (mHairColor < NR_HAIR_COLORS && mHairStyle < NR_HAIR_STYLES) { int hf = 9 * mHairColor; if (hf >= 0 && hf < (int)hairset[mHairStyle]->size()) { diff --git a/src/gui/playerbox.h b/src/gui/playerbox.h index 79f7c2aa..ec04eaf6 100644 --- a/src/gui/playerbox.h +++ b/src/gui/playerbox.h @@ -57,10 +57,10 @@ class PlayerBox : public gcn::ScrollArea */ void drawBorder(gcn::Graphics *graphics); - int mHairColor; /**< The hair color index */ - int mHairStyle; /**< The hair style index */ - unsigned char mSex; /**< Sex */ - bool mShowPlayer; /**< Wether to show the player or not */ + unsigned char mHairColor; /**< The hair color index */ + unsigned char mHairStyle; /**< The hair style index */ + unsigned char mSex; /**< Sex */ + bool mShowPlayer; /**< Wether to show the player or not */ private: static int instances; diff --git a/src/gui/status.cpp b/src/gui/status.cpp index bf109460..2b61ed35 100644 --- a/src/gui/status.cpp +++ b/src/gui/status.cpp @@ -48,7 +48,7 @@ StatusWindow::StatusWindow(LocalPlayer *player): // ---------------------- mLvlLabel = new gcn::Label("Level:"); - mGpLabel = new gcn::Label("Money:"); + mMoneyLabel = new gcn::Label("Money:"); mHpLabel = new gcn::Label("HP:"); mHpBar = new ProgressBar(1.0f, 80, 15, 0, 171, 34); @@ -71,7 +71,7 @@ StatusWindow::StatusWindow(LocalPlayer *player): mLvlLabel->setPosition(x, y); x += mLvlLabel->getWidth() + 40; - mGpLabel->setPosition(x, y); + mMoneyLabel->setPosition(x, y); y += mLvlLabel->getHeight() + 5; // Next Row x = 5; @@ -100,7 +100,7 @@ StatusWindow::StatusWindow(LocalPlayer *player): mJobValueLabel->setPosition(290, y); add(mLvlLabel); - add(mGpLabel); + add(mMoneyLabel); add(mHpLabel); add(mHpValueLabel); add(mMpLabel); @@ -227,8 +227,8 @@ void StatusWindow::update() mLvlLabel->setCaption("Level: " + toString(mPlayer->mLevel)); mLvlLabel->adjustSize(); - mGpLabel->setCaption("Money: " + toString(mPlayer->mGp) + " GP"); - mGpLabel->adjustSize(); + mMoneyLabel->setCaption("Money: " + toString(mPlayer->mMoney) + " GP"); + mMoneyLabel->adjustSize(); mJobXpLabel->setCaption("Job: " + toString(mPlayer->mJobLevel)); mJobXpLabel->adjustSize(); @@ -334,7 +334,7 @@ void StatusWindow::update() mStatsReflexPoints->adjustSize(); // Update Second column widgets position - mGpLabel->setPosition(mLvlLabel->getX() + mLvlLabel->getWidth() + 20, + mMoneyLabel->setPosition(mLvlLabel->getX() + mLvlLabel->getWidth() + 20, mLvlLabel->getY()); mXpLabel->setPosition( diff --git a/src/gui/status.h b/src/gui/status.h index 6b963d24..fe2140e3 100644 --- a/src/gui/status.h +++ b/src/gui/status.h @@ -69,7 +69,7 @@ class StatusWindow : public Window, public gcn::ActionListener { /** * Status Part */ - gcn::Label *mLvlLabel, *mGpLabel, *mHpLabel, *mHpValueLabel; + gcn::Label *mLvlLabel, *mMoneyLabel, *mHpLabel, *mHpValueLabel; gcn::Label *mMpLabel, *mMpValueLabel; gcn::Label *mXpLabel, *mXpValueLabel, *mJobXpLabel, *mJobValueLabel; ProgressBar *mHpBar, *mMpBar; diff --git a/src/localplayer.cpp b/src/localplayer.cpp index 4a15cba3..83884b6f 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -38,6 +38,7 @@ LocalPlayer *player_node = NULL; LocalPlayer::LocalPlayer(Uint32 id, Uint16 job, Map *map): Player(id, job, map), + mLevel(1), mInventory(new Inventory()), mTarget(NULL), mPickUpTarget(NULL), mTrading(false), mLastAction(-1) diff --git a/src/localplayer.h b/src/localplayer.h index 1f8c836f..fdef6ba1 100644 --- a/src/localplayer.h +++ b/src/localplayer.h @@ -127,7 +127,7 @@ class LocalPlayer : public Player Uint32 mJobLevel; Uint32 mXpForNextLevel, mJobXpForNextLevel; Uint16 mHp, mMaxHp, mMp, mMaxMp; - Uint32 mGp; + Uint32 mMoney; Uint32 mTotalWeight, mMaxWeight; diff --git a/src/main.cpp b/src/main.cpp index a4ef29ee..dc76846e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -407,21 +407,23 @@ LockedArray charInfo(MAX_SLOT + 1); MapLoginHandler mapLoginHandler; // TODO Find some nice place for these functions -void accountLogin(Network *network, LoginData *loginData) +void accountLogin(LoginData *loginData) { logger->log("Trying to connect to account server..."); logger->log("Username is %s", loginData->username.c_str()); network->connect(loginData->hostname, loginData->port); network->registerHandler(&loginHandler); - loginHandler.setCharInfo(&charInfo); + network->registerHandler(&charServerHandler); loginHandler.setLoginData(loginData); + charServerHandler.setLoginData(loginData); + charServerHandler.setCharInfo(&charInfo); // Send login infos - MessageOut *msg = new MessageOut(); - msg->writeShort(PAMSG_LOGIN); - msg->writeLong(0); // client version - msg->writeString(loginData->username); - msg->writeString(loginData->password); + MessageOut msg; + msg.writeShort(PAMSG_LOGIN); + msg.writeLong(0); // client version + msg.writeString(loginData->username); + msg.writeString(loginData->password); network->send(msg); // Clear the password, avoids auto login when returning to login @@ -436,22 +438,23 @@ void accountLogin(Network *network, LoginData *loginData) config.setValue("remember", loginData->remember); } -void accountRegister(Network *network, LoginData *loginData) +void accountRegister(LoginData *loginData) { logger->log("Trying to connect to account server..."); logger->log("Username is %s", loginData->username.c_str()); network->connect(loginData->hostname, loginData->port); network->registerHandler(&loginHandler); - loginHandler.setCharInfo(&charInfo); loginHandler.setLoginData(loginData); + charServerHandler.setLoginData(loginData); + charServerHandler.setCharInfo(&charInfo); // Send login infos - MessageOut *msg = new MessageOut(); - msg->writeShort(PAMSG_REGISTER); - msg->writeLong(0); // client version - msg->writeString(loginData->username); - msg->writeString(loginData->password); - msg->writeString(loginData->email); + MessageOut msg; + msg.writeShort(PAMSG_REGISTER); + msg.writeLong(0); // client version + msg.writeString(loginData->username); + msg.writeString(loginData->password); + msg.writeString(loginData->email); network->send(msg); } @@ -544,7 +547,7 @@ int main(int argc, char *argv[]) { logger->error("An error occurred while initializing ENet."); } - Network *network = new Network(); + network = new Network(); SDL_Event event; @@ -678,11 +681,11 @@ int main(int argc, char *argv[]) break; case ACCOUNT_STATE: - accountLogin(network, &loginData); + accountLogin(&loginData); break; case REGISTER_ACCOUNT_STATE: - accountRegister(network, &loginData); + accountRegister(&loginData); break; default: diff --git a/src/net/buysellhandler.cpp b/src/net/buysellhandler.cpp index be636d94..3b5fc87d 100644 --- a/src/net/buysellhandler.cpp +++ b/src/net/buysellhandler.cpp @@ -72,7 +72,7 @@ void BuySellHandler::handleMessage(MessageIn *msg) msg->readShort(); // length n_items = (msg->getLength() - 4) / 11; buyDialog->reset(); - buyDialog->setMoney(player_node->mGp); + buyDialog->setMoney(player_node->mMoney); buyDialog->setVisible(true); for (int k = 0; k < n_items; k++) diff --git a/src/net/charserverhandler.cpp b/src/net/charserverhandler.cpp index 36a17acf..e41ca0f3 100644 --- a/src/net/charserverhandler.cpp +++ b/src/net/charserverhandler.cpp @@ -38,14 +38,9 @@ CharServerHandler::CharServerHandler() { static const Uint16 _messages[] = { - 0x006b, - 0x006c, - 0x006d, - 0x006e, - 0x006f, - 0x0070, - 0x0071, - 0x0081, + APMSG_CHAR_CREATE_RESPONSE, + APMSG_CHAR_DELETE_RESPONSE, + APMSG_CHAR_INFO, 0 }; handledMessages = _messages; @@ -56,145 +51,114 @@ void CharServerHandler::handleMessage(MessageIn *msg) int slot; LocalPlayer *tempPlayer; - logger->log("CharServerHandler: Packet ID: %x, Length: %d", - msg->getId(), msg->getLength()); switch (msg->getId()) { - case 0x006b: - // Derive number of characters from message length - n_character = (msg->getLength() - 24) / 106; - - for (int i = 0; i < n_character; i++) + case APMSG_CHAR_CREATE_RESPONSE: + int errMsg = msg->readByte(); + // Character creation successful + if (errMsg == ERRMSG_OK) { - tempPlayer = readPlayerData(msg, slot); - mCharInfo->select(slot); - mCharInfo->setEntry(tempPlayer); - logger->log("CharServer: Player: %s (%d)", - tempPlayer->getName().c_str(), slot); } - - state = CHAR_SELECT_STATE; + // Character creation failed + else + { + std::string message = ""; + switch (errMsg) + { + case ERRMSG_NO_LOGIN: + message = "Not logged in"; + break; + case CREATE_TOO_MUCH_CHARACTERS: + message = "No empty slot"; + break; + case ERRMSG_INVALID_ARGUMENT: + message = "Invalid name"; + break; + case CREATE_EXISTS_NAME: + message = "Character's name already exists"; + break; + case CREATE_INVALID_HAIRSTYLE: + message = "Invalid hairstyle"; + break; + case CREATE_INVALID_HAIRCOLOR: + message = "Invalid hair color"; + break; + case CREATE_INVALID_GENDER: + message = "Invalid gender"; + break; + case CREATE_RAW_STATS_TOO_HIGH: + message = "Character's stats are too high"; + break; + case CREATE_RAW_STATS_TOO_LOW: + message = "Character's stats are too low"; + break; + case CREATE_RAW_STATS_INVALID_DIFF: + message = "Character's stats difference is too high"; + break; + case CREATE_RAW_STATS_EQUAL_TO_ZERO: + message = "One stat is zero"; + break; + default: + message = "Unknown error"; + break; + } + new OkDialog("Error", message); + } break; - - case 0x006c: - switch (msg->readByte()) { - case 0: - errorMessage = "Access denied"; - break; - case 1: - errorMessage = "Cannot use this ID"; - break; - default: - errorMessage = "Unknown failure to select character"; - break; + case APMSG_CHAR_DELETE_RESPONSE: + { + int errMsg = msg->readByte(); + // Character deletion successful + if (errMsg == ERRMSG_OK) + { + delete mCharInfo->getEntry(); + mCharInfo->setEntry(0); + mCharInfo->unlock(); + n_character--; + new OkDialog("Info", "Player deleted"); } - mCharInfo->unlock(); + // Character deletion failed + else + { + std::string message = ""; + switch (errMsg) + { + case ERRMSG_NO_LOGIN: + message = "Not logged in"; + break; + case ERRMSG_INVALID_ARGUMENT: + message = "Selection out of range"; + break; + default: + message = "Unknown error"; + } + mCharInfo->unlock(); + new OkDialog("Error", message); + } + } break; - - case 0x006d: + case APMSG_CHAR_INFO: tempPlayer = readPlayerData(msg, slot); mCharInfo->unlock(); mCharInfo->select(slot); mCharInfo->setEntry(tempPlayer); n_character++; break; - - case 0x006e: - new OkDialog("Error", "Failed to create character"); - break; - - case 0x006f: - delete mCharInfo->getEntry(); - mCharInfo->setEntry(0); - mCharInfo->unlock(); - n_character--; - new OkDialog("Info", "Player deleted"); - break; - - case 0x0070: - mCharInfo->unlock(); - new OkDialog("Error", "Failed to delete character."); - break; - - case 0x0071: - player_node = mCharInfo->getEntry(); - map_path = msg->readString(16); - mLoginData->hostname = iptostring(msg->readLong()); - mLoginData->port = msg->readShort(); - mCharInfo->unlock(); - mCharInfo->select(0); - // Clear unselected players infos - do - { - LocalPlayer *tmp = mCharInfo->getEntry(); - if (tmp != player_node) - delete tmp; - mCharInfo->next(); - } while (mCharInfo->getPos()); - - state = CONNECTING_STATE; - break; - - case 0x0081: - switch (msg->readByte()) { - case 1: - errorMessage = "Map server offline"; - break; - case 3: - errorMessage = "Speed hack detected"; - break; - case 8: - errorMessage = "Duplicated login"; - break; - default: - errorMessage = "Unkown error with 0x0081"; - break; - } - mCharInfo->unlock(); - state = ERROR_STATE; - break; } } LocalPlayer* CharServerHandler::readPlayerData(MessageIn *msg, int &slot) { LocalPlayer *tempPlayer = new LocalPlayer(mLoginData->account_ID, 0, NULL); - tempPlayer->mCharId = msg->readLong(); - tempPlayer->mTotalWeight = 0; - tempPlayer->mMaxWeight = 0; - tempPlayer->mLastAttackTime = 0; - tempPlayer->mXp = msg->readLong(); - tempPlayer->mGp = msg->readLong(); - tempPlayer->mJobXp = msg->readLong(); - tempPlayer->mJobLevel = msg->readLong(); - msg->readLong(); // option - msg->readLong(); // karma - msg->readLong(); // manner - tempPlayer->mHp = msg->readShort(); - tempPlayer->mMaxHp = msg->readShort(); - tempPlayer->mMp = msg->readShort(); - tempPlayer->mMaxMp = msg->readShort(); - msg->readShort(); // speed - msg->readShort(); // class - tempPlayer->setHairStyle(msg->readShort()); - Uint16 weapon = msg->readShort(); - if (weapon == 11) - weapon = 2; - tempPlayer->setWeapon(weapon); - tempPlayer->mLevel = msg->readShort(); - msg->readShort(); // skill point - tempPlayer->setVisibleEquipment(3, msg->readShort()); // head bottom - msg->readShort(); // shield - tempPlayer->setVisibleEquipment(4, msg->readShort()); // head option top - tempPlayer->setVisibleEquipment(5, msg->readShort()); // head option mid - tempPlayer->setHairColor(msg->readShort()); - msg->readShort(); // unknown - tempPlayer->setName(msg->readString(24)); + slot = msg->readByte(); // character slot + tempPlayer->mName = msg->readString(); + tempPlayer->mSex = msg->readByte(); + tempPlayer->setHairStyle(msg->readByte()); + tempPlayer->setHairColor(msg->readByte()); + tempPlayer->mLevel = msg->readByte(); + tempPlayer->mMoney = msg->readShort(); for (int i = 0; i < 6; i++) { tempPlayer->mAttr[i] = msg->readByte(); } - slot = msg->readByte(); // character slot - msg->readByte(); // unknown - return tempPlayer; } diff --git a/src/net/loginhandler.cpp b/src/net/loginhandler.cpp index 324c33cd..27d8eed5 100644 --- a/src/net/loginhandler.cpp +++ b/src/net/loginhandler.cpp @@ -27,7 +27,6 @@ #include "network.h" #include "protocol.h" -#include "../localplayer.h" #include "../log.h" #include "../logindata.h" #include "../main.h" @@ -52,21 +51,6 @@ void LoginHandler::handleMessage(MessageIn *msg) // Successful login if (errMsg == ERRMSG_OK) { - unsigned char charNumber = msg->readByte(); - printf("Account has %i characters:\n", charNumber); - for (unsigned int i = 0; i < charNumber; i++) { - // Create a temp empty player to show up in character - // selection dialog - LocalPlayer *temp = new LocalPlayer(0, 0, 0); - temp->setName(msg->readString()); - temp->setSex(msg->readByte()); - temp->setHairStyle(msg->readByte()); - temp->setHairColor(msg->readByte()); - temp->mLevel = msg->readByte(); - temp->mGp = msg->readShort(); - mCharInfo->select(i); - mCharInfo->setEntry(temp); - } state = CHAR_SELECT_STATE; } // Login failed @@ -102,7 +86,8 @@ void LoginHandler::handleMessage(MessageIn *msg) state = ACCOUNT_STATE; } // Registration failed - else { + else + { switch (errMsg) { case REGISTER_INVALID_VERSION: errorMessage = "Client has an insufficient version number to login."; diff --git a/src/net/loginhandler.h b/src/net/loginhandler.h index 7d5d6f75..1b15b736 100644 --- a/src/net/loginhandler.h +++ b/src/net/loginhandler.h @@ -38,13 +38,10 @@ class LoginHandler : public MessageHandler void handleMessage(MessageIn *msg); - void setCharInfo(LockedArray *charInfo) { mCharInfo = charInfo; }; - void setLoginData(LoginData *loginData) { mLoginData = loginData; }; protected: LoginData *mLoginData; - LockedArray *mCharInfo; }; #endif diff --git a/src/net/messageout.cpp b/src/net/messageout.cpp index 5e8a5d72..7f5fadcb 100644 --- a/src/net/messageout.cpp +++ b/src/net/messageout.cpp @@ -104,13 +104,13 @@ MessageOut::writeString(const std::string &string, int length) } char* -MessageOut::getData() +MessageOut::getData() const { return mData; } unsigned int -MessageOut::getDataSize() +MessageOut::getDataSize() const { return mDataSize; } diff --git a/src/net/messageout.h b/src/net/messageout.h index 8431d887..22754f60 100644 --- a/src/net/messageout.h +++ b/src/net/messageout.h @@ -55,12 +55,12 @@ class MessageOut /** * Returns the content of the message. */ - char *getData(); + char *getData() const; /** * Returns the length of the data. */ - unsigned int getDataSize(); + unsigned int getDataSize() const; private: /** diff --git a/src/net/network.cpp b/src/net/network.cpp index dcfbc8f1..39a632a2 100644 --- a/src/net/network.cpp +++ b/src/net/network.cpp @@ -29,6 +29,8 @@ #include "../log.h" +Network *network; + Network::Network(): mClient(0), mServer(0), mAddress(), mPort(0), @@ -216,7 +218,7 @@ void Network::flush() } } -void Network::send(MessageOut *msg) +void Network::send(const MessageOut &msg) { if (mState == IDLE || mState == NET_ERROR) { @@ -225,8 +227,8 @@ void Network::send(MessageOut *msg) return; } - ENetPacket *packet = enet_packet_create(msg->getData(), - msg->getDataSize(), + ENetPacket *packet = enet_packet_create(msg.getData(), + msg.getDataSize(), ENET_PACKET_FLAG_RELIABLE); mOutgoingPackets.push(packet); } diff --git a/src/net/network.h b/src/net/network.h index 50ee9af7..f91c926b 100644 --- a/src/net/network.h +++ b/src/net/network.h @@ -59,7 +59,7 @@ class Network void dispatchMessages(); void flush(); - void send(MessageOut *msg); + void send(const MessageOut &msg); enum State { IDLE, @@ -96,4 +96,7 @@ class Network /** 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/playerhandler.cpp b/src/net/playerhandler.cpp index c70eada3..d8ff81f4 100644 --- a/src/net/playerhandler.cpp +++ b/src/net/playerhandler.cpp @@ -177,7 +177,7 @@ void PlayerHandler::handleMessage(MessageIn *msg) player_node->mJobXp = msg->readLong(); break; case 0x0014: - player_node->mGp = msg->readLong(); + player_node->mMoney = msg->readLong(); break; case 0x0016: player_node->mXpForNextLevel = msg->readLong(); diff --git a/src/net/protocol.h b/src/net/protocol.h index 6db3762e..528b2fd5 100644 --- a/src/net/protocol.h +++ b/src/net/protocol.h @@ -128,7 +128,7 @@ enum { APMSG_CHAR_CREATE_RESPONSE = 0x0021, // B error PAMSG_CHAR_DELETE = 0x0022, // B index APMSG_CHAR_DELETE_RESPONSE = 0x0023, // B error - PAMSG_CHAR_LIST = 0x0024, // - + APMSG_CHAR_INFO = 0x0024, // B index, S name, B gender, B hair style, B hair color, B level, W money, W*6 stats, S mapname, W*2 position APMSG_CHAR_LIST_RESPONSE = 0x0025, // B number, { B index, S name, B gender, B hair style, B hair color, B level, W money, W*6 stats, S mapname, W*2 position }* PAMSG_CHAR_SELECT = 0x0026, // B index APMSG_CHAR_SELECT_RESPONSE = 0x0027, // B error, S mapname, W*2 position @@ -207,6 +207,18 @@ enum { REGISTER_EXISTS_EMAIL // there already is an account with this email address }; +// Character creation specific return values +enum { + CREATE_INVALID_HAIRSTYLE = 0x40, + CREATE_INVALID_HAIRCOLOR, + CREATE_INVALID_GENDER, + CREATE_RAW_STATS_TOO_HIGH, + CREATE_RAW_STATS_TOO_LOW, + CREATE_RAW_STATS_INVALID_DIFF, + CREATE_RAW_STATS_EQUAL_TO_ZERO, + CREATE_EXISTS_NAME, + CREATE_TOO_MUCH_CHARACTERS +}; /** Encodes coords and direction in 3 bytes data */ void set_coordinates(char *data, unsigned short x, unsigned short y, unsigned char direction); -- cgit v1.2.3-70-g09d2 From ca5d91316c8a1ba72b5e0f3c7a697e7879987f93 Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Mon, 14 Aug 2006 22:28:34 +0000 Subject: Some preparations towards supporting character select and response handling. --- ChangeLog | 6 ++++++ src/gui/char_select.cpp | 7 ++++--- src/net/charserverhandler.cpp | 30 +++++++++++++++++++++++++----- src/net/charserverhandler.h | 3 +++ 4 files changed, 38 insertions(+), 8 deletions(-) (limited to 'src/gui/char_select.cpp') diff --git a/ChangeLog b/ChangeLog index cfa79aa5..c3638190 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2006-08-15 Bjørn Lindeijer + + * src/gui/char_select.cpp, src/net/charserverhandler.h, + src/net/charserverhandler.cpp: Some preparations towards supporting + character select and response handling. + 2006-08-14 Bjørn Lindeijer * src/net/charserverhandler.h, src/net/charserverhandler.cpp: Fix diff --git a/src/gui/char_select.cpp b/src/gui/char_select.cpp index 775eea24..775ecc6f 100644 --- a/src/gui/char_select.cpp +++ b/src/gui/char_select.cpp @@ -215,9 +215,10 @@ void CharSelectDialog::attemptCharDelete() void CharSelectDialog::attemptCharSelect() { // Request character selection - MessageOut outMsg; - outMsg.writeShort(0x0066); - outMsg.writeByte(mCharInfo->getPos()); + MessageOut msg; + msg.writeShort(PAMSG_CHAR_SELECT); + msg.writeByte(mCharInfo->getPos()); + network->send(msg); mCharInfo->lock(); } diff --git a/src/net/charserverhandler.cpp b/src/net/charserverhandler.cpp index b4715315..eb7eb34d 100644 --- a/src/net/charserverhandler.cpp +++ b/src/net/charserverhandler.cpp @@ -57,6 +57,7 @@ CharServerHandler::handleMessage(MessageIn *msg) case APMSG_CHAR_CREATE_RESPONSE: handleCharCreateResponse(*msg); break; + case APMSG_CHAR_DELETE_RESPONSE: { int errMsg = msg->readByte(); @@ -89,6 +90,7 @@ CharServerHandler::handleMessage(MessageIn *msg) } } break; + case APMSG_CHAR_INFO: tempPlayer = readPlayerData(msg, slot); mCharInfo->unlock(); @@ -96,6 +98,10 @@ CharServerHandler::handleMessage(MessageIn *msg) mCharInfo->setEntry(tempPlayer); n_character++; break; + + case PMSG_CHAR_SELECT_RESPONSE: + handleCharSelectResponse(*msg); + break; } } @@ -104,12 +110,8 @@ CharServerHandler::handleCharCreateResponse(MessageIn &msg) { int errMsg = msg.readByte(); - // Character creation successful - if (errMsg == ERRMSG_OK) - { - } // Character creation failed - else + if (errMsg != ERRMSG_OK) { std::string message = ""; switch (errMsg) @@ -155,6 +157,24 @@ CharServerHandler::handleCharCreateResponse(MessageIn &msg) } } +void +CharServerHandler::handleCharSelectResponse(MessageIn &msg) +{ + int errMsg = msg.readByte(); + + if (errMsg == 0) + { + //std::string token = msg.readString(32); + //std::string gameServer = msg.readString(); + //unsigned short gameServerPort = msg.readShort(); + //std::string chatServer = msg.readString(); + //unsigned short chatServerPort = msg.readShort(); + + // TODO: Connect to game and chat servers, and login using the given + // TODO: token. + } +} + LocalPlayer* CharServerHandler::readPlayerData(MessageIn *msg, int &slot) { diff --git a/src/net/charserverhandler.h b/src/net/charserverhandler.h index ec5df3f8..b034b513 100644 --- a/src/net/charserverhandler.h +++ b/src/net/charserverhandler.h @@ -52,6 +52,9 @@ class CharServerHandler : public MessageHandler void handleCharCreateResponse(MessageIn &msg); + void + handleCharSelectResponse(MessageIn &msg); + LoginData *mLoginData; LockedArray *mCharInfo; -- cgit v1.2.3-70-g09d2 From 01591924a4f33d5a5e4a86db6c256c8ce797a820 Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Sun, 20 Aug 2006 00:56:23 +0000 Subject: The Network can now connect to the three servers and affected methods now take the server type as a parameter. The MessageOut gained a convenience constructor (same as was added server side). The game states during login sequence have been renamed and redone in order to ensure no communication is attempted to unconnected servers. This allowed the removal of the outgoing message queue. Connecting to the account server has been moved before the login/register phase (dialogs will still need to be updated). Quite a few things are expected to be broken since I'm rather tired at the moment. I've left many TODO entries in the code. --- ChangeLog | 19 +++++ src/gui/char_select.cpp | 8 +- src/gui/connection.cpp | 4 +- src/gui/gui.cpp | 2 +- src/gui/login.cpp | 7 +- src/gui/register.cpp | 4 +- src/gui/updatewindow.cpp | 6 +- src/main.cpp | 189 +++++++++++++++++++++++------------------- src/main.h | 30 +++---- src/net/charserverhandler.cpp | 22 +++-- src/net/loginhandler.cpp | 8 +- src/net/maploginhandler.cpp | 4 +- src/net/messageout.cpp | 8 ++ src/net/messageout.h | 5 ++ src/net/network.cpp | 153 ++++++++++++++++++++++------------ src/net/network.h | 59 +++++++------ 16 files changed, 323 insertions(+), 205 deletions(-) (limited to 'src/gui/char_select.cpp') diff --git a/ChangeLog b/ChangeLog index a9596e29..c4cb401c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,22 @@ +2006-08-20 Bjørn Lindeijer + + * src/gui/connection.cpp, src/gui/login.cpp, src/gui/gui.cpp, + src/gui/updatewindow.cpp, src/gui/char_select.cpp, + src/gui/register.cpp, src/main.cpp, src/net/loginhandler.cpp, + src/net/messageout.cpp, src/net/network.h, + src/net/charserverhandler.cpp, src/net/maploginhandler.cpp, + src/net/messageout.h, src/net/network.cpp, src/main.h: The Network + can now connect to the three servers and affected methods now take the + server type as a parameter. The MessageOut gained a convenience + constructor (same as was added server side). The game states during + login sequence have been renamed and redone in order to ensure no + communication is attempted to unconnected servers. This allowed the + removal of the outgoing message queue. Connecting to the account + server has been moved before the login/register phase (dialogs will + still need to be updated). Quite a few things are expected to be + broken since I'm rather tired at the moment. I've left many TODO + entries in the code. + 2006-08-19 Bjørn Lindeijer * src/game.cpp, src/net/network.h, src/net/network.cpp: Removed diff --git a/src/gui/char_select.cpp b/src/gui/char_select.cpp index 775ecc6f..2fa6c68e 100644 --- a/src/gui/char_select.cpp +++ b/src/gui/char_select.cpp @@ -139,7 +139,7 @@ void CharSelectDialog::action(const std::string &eventId, gcn::Widget *widget) } else if (eventId == "cancel") { - state = EXIT_STATE; + state = STATE_EXIT; } else if (eventId == "new") { @@ -208,7 +208,7 @@ void CharSelectDialog::attemptCharDelete() msg.writeShort(PAMSG_CHAR_DELETE); // TODO: Send the selected slot msg.writeByte(0); - network->send(msg); + network->send(Network::ACCOUNT, msg); mCharInfo->lock(); } @@ -218,7 +218,7 @@ void CharSelectDialog::attemptCharSelect() MessageOut msg; msg.writeShort(PAMSG_CHAR_SELECT); msg.writeByte(mCharInfo->getPos()); - network->send(msg); + network->send(Network::ACCOUNT, msg); mCharInfo->lock(); } @@ -337,5 +337,5 @@ void CharCreateDialog::attemptCharCreate() outMsg.writeShort(10); // INT outMsg.writeShort(10); // DEX outMsg.writeShort(10); // LUK - network->send(outMsg); + network->send(Network::ACCOUNT, outMsg); } diff --git a/src/gui/connection.cpp b/src/gui/connection.cpp index f7fdaca6..a29008c3 100644 --- a/src/gui/connection.cpp +++ b/src/gui/connection.cpp @@ -35,7 +35,9 @@ namespace { struct ConnectionActionListener : public gcn::ActionListener { - void action(const std::string &eventId, gcn::Widget *widget) { state = EXIT_STATE; } + void action(const std::string &eventId, gcn::Widget *widget) { + state = STATE_EXIT; + } } listener; } diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index 026f24bd..0e200db3 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -234,7 +234,7 @@ Gui::mousePress(int mx, int my, int button) // Mouse pressed on window container (basically, the map) // Are we in-game yet? - if (state != GAME_STATE) + if (state != STATE_GAME) return; // Check if we are alive and kickin' diff --git a/src/gui/login.cpp b/src/gui/login.cpp index 2f646bd1..cb16dcb4 100644 --- a/src/gui/login.cpp +++ b/src/gui/login.cpp @@ -147,18 +147,17 @@ LoginDialog::action(const std::string &eventId, gcn::Widget *widget) mLoginData->remember = mKeepCheck->isMarked(); mOkButton->setEnabled(false); - //mCancelButton->setEnabled(false); mRegisterButton->setEnabled(false); - state = ACCOUNT_STATE; + state = STATE_LOGIN_ATTEMPT; } } else if (eventId == "cancel") { - state = EXIT_STATE; + state = STATE_EXIT; } else if (eventId == "register") { - state = REGISTER_STATE; + state = STATE_REGISTER; } } diff --git a/src/gui/register.cpp b/src/gui/register.cpp index 49da10b6..52833aea 100644 --- a/src/gui/register.cpp +++ b/src/gui/register.cpp @@ -119,7 +119,7 @@ RegisterDialog::action(const std::string &eventId, gcn::Widget *widget) { if (eventId == "cancel") { - state = EXIT_STATE; + state = STATE_EXIT; } else if (eventId == "register") { @@ -205,7 +205,7 @@ RegisterDialog::action(const std::string &eventId, gcn::Widget *widget) mLoginData->password = mPasswordField->getText(); mLoginData->email = mEmailField->getText(); - state = REGISTER_ACCOUNT_STATE; + state = STATE_REGISTER_ATTEMPT; } } } diff --git a/src/gui/updatewindow.cpp b/src/gui/updatewindow.cpp index 8c69d3ef..77a026fe 100644 --- a/src/gui/updatewindow.cpp +++ b/src/gui/updatewindow.cpp @@ -136,7 +136,7 @@ void UpdaterWindow::action(const std::string &eventId, gcn::Widget *widget) // Skip the updating process if (mDownloadStatus == UPDATE_COMPLETE) { - state = EXIT_STATE; + state = STATE_EXIT; } else { @@ -145,7 +145,7 @@ void UpdaterWindow::action(const std::string &eventId, gcn::Widget *widget) } else if (eventId == "play") { - state = LOGIN_STATE; + state = STATE_LOGIN; } } @@ -198,7 +198,7 @@ int UpdaterWindow::updateProgress(void *ptr, uw->mCurrentFile + " (" + toString((int)progress * 100) + "%)"); uw->setProgress(progress); - if (state != UPDATE_STATE || uw->mDownloadStatus == UPDATE_ERROR) + if (state != STATE_UPDATE || uw->mDownloadStatus == UPDATE_ERROR) { // If the action was canceled return an error code to stop the mThread return -1; diff --git a/src/main.cpp b/src/main.cpp index dc76846e..d62594c9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -99,7 +99,9 @@ Logger *logger; /**< Log object */ namespace { struct ErrorListener : public gcn::ActionListener { - void action(const std::string &eventId, gcn::Widget *widget) { state = LOGIN_STATE; } + void action(const std::string &eventId, gcn::Widget *widget) { + state = STATE_CHOOSE_SERVER; + } } errorListener; } @@ -267,7 +269,7 @@ void init_engine() } gui = new Gui(graphics); - state = UPDATE_STATE; /**< Initial game state */ + state = STATE_CHOOSE_SERVER; /**< Initial game state */ // Initialize sound engine try { @@ -278,7 +280,7 @@ void init_engine() sound.setMusicVolume((int)config.getValue("musicVolume", 60)); } catch (const char *err) { - state = ERROR_STATE; + state = STATE_ERROR; errorMessage = err; logger->log("Warning: %s", err); } @@ -409,9 +411,7 @@ MapLoginHandler mapLoginHandler; // TODO Find some nice place for these functions void accountLogin(LoginData *loginData) { - logger->log("Trying to connect to account server..."); logger->log("Username is %s", loginData->username.c_str()); - network->connect(loginData->hostname, loginData->port); network->registerHandler(&loginHandler); network->registerHandler(&charServerHandler); loginHandler.setLoginData(loginData); @@ -419,12 +419,11 @@ void accountLogin(LoginData *loginData) charServerHandler.setCharInfo(&charInfo); // Send login infos - MessageOut msg; - msg.writeShort(PAMSG_LOGIN); + MessageOut msg(PAMSG_LOGIN); msg.writeLong(0); // client version msg.writeString(loginData->username); msg.writeString(loginData->password); - network->send(msg); + network->send(Network::ACCOUNT, msg); // Clear the password, avoids auto login when returning to login loginData->password = ""; @@ -440,40 +439,37 @@ void accountLogin(LoginData *loginData) void accountRegister(LoginData *loginData) { - logger->log("Trying to connect to account server..."); logger->log("Username is %s", loginData->username.c_str()); - network->connect(loginData->hostname, loginData->port); network->registerHandler(&loginHandler); loginHandler.setLoginData(loginData); charServerHandler.setLoginData(loginData); charServerHandler.setCharInfo(&charInfo); // Send login infos - MessageOut msg; - msg.writeShort(PAMSG_REGISTER); + MessageOut msg(PAMSG_REGISTER); msg.writeLong(0); // client version msg.writeString(loginData->username); msg.writeString(loginData->password); msg.writeString(loginData->email); - network->send(msg); + network->send(Network::ACCOUNT, msg); } void mapLogin(Network *network, LoginData *loginData) { - MessageOut outMsg; - - logger->log("Trying to connect to map server..."); + // TODO: Before the client has been identified using the magic token, the + // map path is not known yet. logger->log("Map: %s", map_path.c_str()); - network->connect(loginData->hostname, loginData->port); network->registerHandler(&mapLoginHandler); // Send login infos - outMsg.writeShort(0x0072); - outMsg.writeLong(loginData->account_ID); - outMsg.writeLong(player_node->mCharId); - outMsg.writeLong(loginData->session_ID1); - outMsg.writeLong(loginData->session_ID2); + // TODO: The token would need to be sent to complete client identification + // for the game server + //MessageOut outMsg(0x0072); + //outMsg.writeLong(loginData->account_ID); + //outMsg.writeLong(player_node->mCharId); + //outMsg.writeLong(loginData->session_ID1); + //outMsg.writeLong(loginData->session_ID2); } /** Main */ @@ -515,13 +511,6 @@ int main(int argc, char *argv[]) init_engine(); - if (options.skipUpdate && state != ERROR_STATE) { - state = LOGIN_STATE; - } - else { - state = UPDATE_STATE; - } - unsigned int oldstate = !state; // We start with a status change. Window *currentDialog = NULL; @@ -549,20 +538,21 @@ int main(int argc, char *argv[]) } network = new Network(); + SDL_Event event; - while (state != EXIT_STATE) + while (state != STATE_EXIT) { // Handle SDL events while (SDL_PollEvent(&event)) { switch (event.type) { case SDL_QUIT: - state = EXIT_STATE; + state = STATE_EXIT; break; case SDL_KEYDOWN: if (event.key.keysym.sym == SDLK_ESCAPE) - state = EXIT_STATE; + state = STATE_EXIT; break; } @@ -574,7 +564,7 @@ int main(int argc, char *argv[]) if (network->getState() == Network::NET_ERROR) { - state = ERROR_STATE; + state = STATE_ERROR; errorMessage = "Got disconnected from server!"; } @@ -596,48 +586,89 @@ int main(int argc, char *argv[]) gui->draw(); graphics->updateScreen(); + // TODO: Add connect timeout to go back to choose server + if (state == STATE_CONNECT_ACCOUNT && + network->isConnected(Network::ACCOUNT)) + { + if (options.skipUpdate) { + state = STATE_LOGIN; + } else { + state = STATE_UPDATE; + } + } + else if (state == STATE_CONNECT_GAME && + network->isConnected(Network::GAME) && + network->isConnected(Network::CHAT)) + { + // TODO: Somehow send the token + state = STATE_GAME; + } + if (state != oldstate) { - switch (oldstate) + // Load updates after exiting the update state + if (oldstate == STATE_UPDATE) { - case UPDATE_STATE: - loadUpdates(); - break; - - // Those states don't cause a network disconnect - case ACCOUNT_STATE: - case CONNECTING_STATE: - break; + loadUpdates(); + } - default: - network->disconnect(); - network->clearHandlers(); - break; + // Disconnect from account server once connected to game server + if (oldstate == STATE_CONNECT_GAME && state == STATE_GAME) + { + network->disconnect(Network::ACCOUNT); } oldstate = state; - if (currentDialog && state != ACCOUNT_STATE && - state != CHAR_CONNECT_STATE) { + // Get rid of the dialog of the previous state + if (currentDialog) { delete currentDialog; currentDialog = NULL; } switch (state) { - case LOGIN_STATE: + case STATE_CHOOSE_SERVER: + 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, + loginData.hostname, loginData.port); + state = STATE_CONNECT_ACCOUNT; + break; + + case STATE_CONNECT_ACCOUNT: + logger->log("State: CONNECT_ACCOUNT"); + break; + + case STATE_UPDATE: + logger->log("State: UPDATE"); + // TODO: Revive later + //currentDialog = new UpdaterWindow(); + state = STATE_LOGIN; + break; + + case STATE_LOGIN: logger->log("State: LOGIN"); - if (!loginData.password.empty()) { - state = ACCOUNT_STATE; - } else { - currentDialog = new LoginDialog(&loginData); - } + currentDialog = new LoginDialog(&loginData); + // TODO: Restore autologin + //if (!loginData.password.empty()) { + // accountLogin(&loginData); + //} + break; + + case STATE_LOGIN_ATTEMPT: + accountLogin(&loginData); break; - case REGISTER_STATE: + case STATE_REGISTER: logger->log("State: REGISTER"); currentDialog = new RegisterDialog(&loginData); break; - case CHAR_SELECT_STATE: + case STATE_REGISTER_ATTEMPT: + accountRegister(&loginData); + break; + + case STATE_CHAR_SELECT: logger->log("State: CHAR_SELECT"); currentDialog = new CharSelectDialog(network, &charInfo); if (options.chooseDefault) { @@ -646,50 +677,38 @@ int main(int argc, char *argv[]) } break; - case GAME_STATE: - sound.fadeOutMusic(1000); - - currentDialog = NULL; - login_wallpaper->decRef(); - login_wallpaper = NULL; - - logger->log("State: GAME"); - game = new Game(network); - game->logic(); - delete game; - state = EXIT_STATE; - break; - - case UPDATE_STATE: - logger->log("State: UPDATE"); - currentDialog = new UpdaterWindow(); - break; - - case ERROR_STATE: + case STATE_ERROR: logger->log("State: ERROR"); currentDialog = new OkDialog("Error", errorMessage); currentDialog->addActionListener(&errorListener); currentDialog = NULL; // OkDialog deletes itself - network->disconnect(); + network->disconnect(Network::GAME); + network->disconnect(Network::CHAT); network->clearHandlers(); break; - case CONNECTING_STATE: - logger->log("State: CONNECTING"); + case STATE_CONNECT_GAME: + logger->log("State: CONNECT_GAME"); mapLogin(network, &loginData); currentDialog = new ConnectionDialog(); break; - case ACCOUNT_STATE: - accountLogin(&loginData); - break; + case STATE_GAME: + sound.fadeOutMusic(1000); - case REGISTER_ACCOUNT_STATE: - accountRegister(&loginData); + currentDialog = NULL; + login_wallpaper->decRef(); + login_wallpaper = NULL; + + logger->log("State: GAME"); + game = new Game(network); + game->logic(); + delete game; + state = STATE_EXIT; break; default: - state = EXIT_STATE; + state = STATE_EXIT; break; } } diff --git a/src/main.h b/src/main.h index 035b0ec7..47c650af 100644 --- a/src/main.h +++ b/src/main.h @@ -39,20 +39,20 @@ enum { - EXIT_STATE, - LOGIN_STATE, - ACCOUNT_STATE, - REGISTER_STATE, - REGISTER_ACCOUNT_STATE, - CHAR_CONNECT_STATE, - CHAR_SERVER_STATE, - CHAR_SELECT_STATE, - CHAR_NEW_STATE, - CHAR_DEL_STATE, - GAME_STATE, - ERROR_STATE, - UPDATE_STATE, - CONNECTING_STATE + STATE_CHOOSE_SERVER, + STATE_CONNECT_ACCOUNT, + STATE_UPDATE, + STATE_LOGIN, + STATE_LOGIN_ATTEMPT, + STATE_REGISTER, + STATE_REGISTER_ATTEMPT, + STATE_CHAR_SELECT, + STATE_CHAR_NEW, + STATE_CHAR_DELETE, + STATE_ERROR, + STATE_CONNECT_GAME, + STATE_GAME, + STATE_EXIT }; /* length definitions for several char[]s in order @@ -66,7 +66,7 @@ enum { LEN_MIN_PASSWORD = 4 }; -extern char n_server, n_character; +extern char n_character; extern unsigned char state; extern std::string errorMessage; diff --git a/src/net/charserverhandler.cpp b/src/net/charserverhandler.cpp index b8cc710e..ea9b3196 100644 --- a/src/net/charserverhandler.cpp +++ b/src/net/charserverhandler.cpp @@ -165,14 +165,20 @@ CharServerHandler::handleCharSelectResponse(MessageIn &msg) if (errMsg == 0) { - //std::string token = msg.readString(32); - //std::string gameServer = msg.readString(); - //unsigned short gameServerPort = msg.readShort(); - //std::string chatServer = msg.readString(); - //unsigned short chatServerPort = msg.readShort(); - - // TODO: Connect to game and chat servers, and login using the given - // TODO: token. + // TODO: Somehow be able to send this token once connected + std::string token = msg.readString(32); + std::string gameServer = msg.readString(); + unsigned short gameServerPort = msg.readShort(); + std::string chatServer = msg.readString(); + unsigned short chatServerPort = msg.readShort(); + + 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); + + state = STATE_CONNECT_GAME; } } diff --git a/src/net/loginhandler.cpp b/src/net/loginhandler.cpp index 27d8eed5..4790d7d1 100644 --- a/src/net/loginhandler.cpp +++ b/src/net/loginhandler.cpp @@ -51,7 +51,7 @@ void LoginHandler::handleMessage(MessageIn *msg) // Successful login if (errMsg == ERRMSG_OK) { - state = CHAR_SELECT_STATE; + state = STATE_CHAR_SELECT; } // Login failed else @@ -73,7 +73,7 @@ void LoginHandler::handleMessage(MessageIn *msg) errorMessage = "Unknown error"; break; } - state = ERROR_STATE; + state = STATE_ERROR; } } break; @@ -83,7 +83,7 @@ void LoginHandler::handleMessage(MessageIn *msg) // Successful registration if (errMsg == ERRMSG_OK) { - state = ACCOUNT_STATE; + state = STATE_CHAR_SELECT; } // Registration failed else @@ -105,7 +105,7 @@ void LoginHandler::handleMessage(MessageIn *msg) errorMessage = "Unknown error"; break; } - state = ERROR_STATE; + state = STATE_ERROR; } } break; diff --git a/src/net/maploginhandler.cpp b/src/net/maploginhandler.cpp index 38ed2203..579e8542 100644 --- a/src/net/maploginhandler.cpp +++ b/src/net/maploginhandler.cpp @@ -50,12 +50,12 @@ void MapLoginHandler::handleMessage(MessageIn *msg) msg->readLong(); // server tick //logger->log("Protocol: Player start position: (%d, %d), Direction: %d", // player_node->mX, player_node->mY, direction); - state = GAME_STATE; + state = STATE_GAME; break; case 0x0081: logger->log("Warning: Map server D/C"); - state = ERROR_STATE; + state = STATE_ERROR; break; } } diff --git a/src/net/messageout.cpp b/src/net/messageout.cpp index 7f5fadcb..426a1c0d 100644 --- a/src/net/messageout.cpp +++ b/src/net/messageout.cpp @@ -36,6 +36,14 @@ MessageOut::MessageOut(): { } +MessageOut::MessageOut(short id): + mData(0), + mDataSize(0), + mPos(0) +{ + writeShort(id); +} + MessageOut::~MessageOut() { if (mData) { diff --git a/src/net/messageout.h b/src/net/messageout.h index 22754f60..81369c0e 100644 --- a/src/net/messageout.h +++ b/src/net/messageout.h @@ -37,6 +37,11 @@ class MessageOut */ MessageOut(); + /** + * Constructor. + */ + MessageOut(short id); + /** * Destructor. */ diff --git a/src/net/network.cpp b/src/net/network.cpp index f543bfb1..23d9e291 100644 --- a/src/net/network.cpp +++ b/src/net/network.cpp @@ -32,47 +32,55 @@ Network *network; Network::Network(): - mClient(0), mServer(0), - mAddress(), mPort(0), - mState(IDLE) + mAccountServer(NULL), + mGameServer(NULL), + mChatServer(NULL), + mState(NET_OK) { + mClient = enet_host_create(NULL, 3, 0, 0); + + if (!mClient) + { + logger->error( + "An error occurred while trying to create an ENet client."); + mState = NET_ERROR; + } } Network::~Network() { clearHandlers(); - if (mState != IDLE && mState != NET_ERROR) - disconnect(); + disconnect(ACCOUNT); + disconnect(GAME); + disconnect(CHAT); } -bool Network::connect(const std::string &address, short port) +bool +Network::connect(Server server, const std::string &address, short port) { - if (mState != IDLE && mState != NET_ERROR) - { - logger->log("Tried to connect an already connected socket!"); - return false; - } + logger->log("Network::connect(%d, %s, %i)", server, address.c_str(), port); if (address.empty()) { - logger->log("Empty address given to Network::connect()!"); + logger->log("Network::connect() got empty address!"); mState = NET_ERROR; return false; } - logger->log("Network::Connecting to %s:%i", address.c_str(), port); - - mAddress = address; - mPort = port; + ENetPeer *peer = NULL; - mState = CONNECTING; - - mClient = enet_host_create(NULL, 1, 0, 0); + switch (server) { + case ACCOUNT: peer = mAccountServer; break; + case GAME: peer = mGameServer; break; + case CHAT: peer = mChatServer; break; + } - if (!mClient) + if (peer != NULL) { - logger->error("An error occurred while trying to create an ENet client."); + logger->log("Network::connect() already connected (or connecting) to " + "this server!"); + return false; } ENetAddress enetAddress; @@ -81,32 +89,51 @@ bool Network::connect(const std::string &address, short port) enetAddress.port = port; // Initiate the connection, allocating channel 0. - mServer = enet_host_connect(mClient, &enetAddress, 1); + peer = enet_host_connect(mClient, &enetAddress, 1); - if (mServer == 0) + if (peer == NULL) { logger->log("Unable to initiate connection to the server."); mState = NET_ERROR; return false; } + switch (server) { + case ACCOUNT: mAccountServer = peer; break; + case GAME: mGameServer = peer; break; + case CHAT: mChatServer = peer; break; + } + return true; } -void Network::disconnect() +void +Network::disconnect(Server server) { - mState = IDLE; + ENetPeer *peer = NULL; - if (mServer) + switch (server) { + case ACCOUNT: peer = mAccountServer; break; + case GAME: peer = mGameServer; break; + case CHAT: peer = mChatServer; break; + } + + if (peer) { - enet_peer_disconnect(mServer, 0); + enet_peer_disconnect(peer, 0); enet_host_flush(mClient); - enet_peer_reset(mServer); - mServer = 0; + enet_peer_reset(peer); + + switch (server) { + case ACCOUNT: mAccountServer = NULL; break; + case GAME: mGameServer = NULL; break; + case CHAT: mChatServer = NULL; break; + } } } -void Network::registerHandler(MessageHandler *handler) +void +Network::registerHandler(MessageHandler *handler) { const Uint16 *i = handler->handledMessages; @@ -119,7 +146,8 @@ void Network::registerHandler(MessageHandler *handler) handler->setNetwork(this); } -void Network::unregisterHandler(MessageHandler *handler) +void +Network::unregisterHandler(MessageHandler *handler) { for (const Uint16 *i = handler->handledMessages; *i; i++) { @@ -129,7 +157,8 @@ void Network::unregisterHandler(MessageHandler *handler) handler->setNetwork(0); } -void Network::clearHandlers() +void +Network::clearHandlers() { MessageHandlerIterator i; for (i = mMessageHandlers.begin(); i != mMessageHandlers.end(); i++) @@ -139,6 +168,20 @@ void Network::clearHandlers() mMessageHandlers.clear(); } +bool +Network::isConnected(Server server) const +{ + ENetPeer *peer = NULL; + + switch (server) { + case ACCOUNT: peer = mAccountServer; break; + case GAME: peer = mGameServer; break; + case CHAT: peer = mChatServer; break; + } + + return peer->state == ENET_PEER_STATE_CONNECTED; +} + void Network::dispatchMessage(ENetPacket *packet) { @@ -162,7 +205,7 @@ Network::dispatchMessage(ENetPacket *packet) void Network::flush() { - if (mState == IDLE || mState == NET_ERROR) + if (mState == NET_ERROR) { return; } @@ -176,7 +219,6 @@ void Network::flush() { case ENET_EVENT_TYPE_CONNECT: logger->log("Connected."); - mState = CONNECTED; // Store any relevant server information here. event.peer->data = 0; break; @@ -185,46 +227,53 @@ void Network::flush() logger->log("Incoming data..."); dispatchMessage(event.packet); break; + case ENET_EVENT_TYPE_DISCONNECT: - mState = IDLE; 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; } } - - // If connected, manage incoming and outcoming packets - if (isConnected()) - { - while (isConnected() && !mOutgoingPackets.empty()) - { - ENetPacket *packet = mOutgoingPackets.front(); - enet_peer_send(mServer, 0, packet); - mOutgoingPackets.pop(); - } - } } -void Network::send(const MessageOut &msg) +void Network::send(Server server, const MessageOut &msg) { - if (mState == IDLE || mState == NET_ERROR) + if (mState == NET_ERROR) { logger->log("Warning: attempt to send a message while network not " "ready."); return; } - ENetPacket *packet = enet_packet_create(msg.getData(), - msg.getDataSize(), - ENET_PACKET_FLAG_RELIABLE); - mOutgoingPackets.push(packet); + ENetPeer *peer = NULL; + + switch (server) { + case ACCOUNT: peer = mAccountServer; break; + case GAME: peer = mGameServer; break; + case CHAT: peer = mChatServer; break; + } + + if (peer) + { + logger->log("Sending message of size %d to server %d...", + msg.getDataSize(), server); + + // Directly send away the packet (TODO: check what ENet does in case + // this is done before connection is ready) + ENetPacket *packet = enet_packet_create(msg.getData(), + msg.getDataSize(), + ENET_PACKET_FLAG_RELIABLE); + enet_peer_send(peer, 0, packet); + } } char *iptostring(int address) diff --git a/src/net/network.h b/src/net/network.h index eb2ce8ab..49583b9d 100644 --- a/src/net/network.h +++ b/src/net/network.h @@ -36,8 +36,6 @@ class MessageHandler; class MessageIn; class MessageOut; -class Network; - class Network { public: @@ -46,35 +44,53 @@ class Network Network(); ~Network(); - bool connect(const std::string &address, short port); - void disconnect(); + typedef enum { + ACCOUNT, + GAME, + CHAT + } Server; + + bool + connect(Server server, const std::string &address, short port); + + void + disconnect(Server server); + + void + registerHandler(MessageHandler *handler); + + void + unregisterHandler(MessageHandler *handler); - void registerHandler(MessageHandler *handler); - void unregisterHandler(MessageHandler *handler); - void clearHandlers(); + void + clearHandlers(); - int getState() const { return mState; } - bool isConnected() const { return mState == CONNECTED; } + int + getState() const { return mState; } - void dispatchMessage(ENetPacket *packet); - void flush(); + bool + isConnected(Server server) const; - void send(const MessageOut &msg); + void + dispatchMessage(ENetPacket *packet); + + void + flush(); + + void + send(Server server, const MessageOut &msg); enum State { - IDLE, - CONNECTED, - CONNECTING, - DATA, + NET_OK, NET_ERROR }; private: ENetHost *mClient; - ENetPeer *mServer; - std::string mAddress; - short mPort; + ENetPeer *mAccountServer; + ENetPeer *mGameServer; + ENetPeer *mChatServer; unsigned int mToSkip; @@ -83,11 +99,6 @@ class Network typedef std::map MessageHandlers; typedef MessageHandlers::iterator MessageHandlerIterator; MessageHandlers mMessageHandlers; - - std::queue mOutgoingPackets; - - bool realConnect(); - void receive(); }; /** Convert an address from int format to string */ -- cgit v1.2.3-70-g09d2 From ef4486580fc7b8293555fcabc398ed0c2b90d78e Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Sat, 26 Aug 2006 16:01:24 +0000 Subject: Got rid of numerous additions and substractions to the hair style and color. Hair style 0 was added and defined as being bald (so bald is no longer a hardcoded style). --- ChangeLog | 9 +++++++++ src/being.cpp | 12 ++---------- src/being.h | 2 +- src/gui/char_select.cpp | 11 +++++------ src/gui/playerbox.cpp | 5 +++-- src/main.cpp | 2 +- src/net/beinghandler.cpp | 4 ++-- src/player.cpp | 8 ++++---- 8 files changed, 27 insertions(+), 26 deletions(-) (limited to 'src/gui/char_select.cpp') diff --git a/ChangeLog b/ChangeLog index 3406dbdc..8b763f7d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2006-08-26 Bjørn Lindeijer + + * src/gui/char_select.cpp, src/gui/playerbox.cpp, src/player.cpp, + src/main.cpp, src/being.cpp, src/net/beinghandler.cpp, src/being.h, + data/graphics/sprites/hairstyle0.xml, + data/graphics/sprites/Makefile.am: Got rid of numerous additions and + substractions to the hair style and color. Hair style 0 was added and + defined as being bald (so bald is no longer a hardcoded style). + 2006-08-26 Guillaume Melquiond * src/net/chathandler.cpp, src/gui/chat.cpp, src/net/protocol.h: Added diff --git a/src/being.cpp b/src/being.cpp index 7755d4e5..70e3eb8e 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -104,21 +104,13 @@ Being::setPath(const Path &path) void Being::setHairColor(Uint16 color) { - mHairColor = color; - if (mHairColor < 1 || mHairColor > NR_HAIR_COLORS + 1) - { - mHairColor = 1; - } + mHairColor = (color < NR_HAIR_COLORS) ? color : 0; } void Being::setHairStyle(Uint16 style) { - mHairStyle = style; - if (mHairStyle < 1 || mHairStyle > NR_HAIR_STYLES) - { - mHairStyle = 1; - } + mHairStyle = (style < NR_HAIR_STYLES) ? style : 0; } void diff --git a/src/being.h b/src/being.h index 055ea0d4..496f183d 100644 --- a/src/being.h +++ b/src/being.h @@ -33,7 +33,7 @@ #include "map.h" #include "animatedsprite.h" -#define NR_HAIR_STYLES 7 +#define NR_HAIR_STYLES 8 #define NR_HAIR_COLORS 10 class AnimatedSprite; diff --git a/src/gui/char_select.cpp b/src/gui/char_select.cpp index 2fa6c68e..3db82287 100644 --- a/src/gui/char_select.cpp +++ b/src/gui/char_select.cpp @@ -183,8 +183,8 @@ void CharSelectDialog::updatePlayerInfo() mDelCharButton->setEnabled(true); mSelectButton->setEnabled(true); } - mPlayerBox->mHairStyle = pi->getHairStyle() - 1; - mPlayerBox->mHairColor = pi->getHairColor() - 1; + mPlayerBox->mHairStyle = pi->getHairStyle(); + mPlayerBox->mHairColor = pi->getHairColor(); mPlayerBox->mSex = pi->getSex(); mPlayerBox->mShowPlayer = true; } else { @@ -324,11 +324,10 @@ std::string CharCreateDialog::getName() void CharCreateDialog::attemptCharCreate() { // Send character infos - MessageOut outMsg; - outMsg.writeShort(PAMSG_CHAR_CREATE); + MessageOut outMsg(PAMSG_CHAR_CREATE); outMsg.writeString(getName()); - outMsg.writeByte(mPlayerBox->mHairStyle + 1); - outMsg.writeByte(mPlayerBox->mHairColor + 1); + outMsg.writeByte(mPlayerBox->mHairStyle); + outMsg.writeByte(mPlayerBox->mHairColor); // TODO: send selected sex outMsg.writeByte(0); // Player sex outMsg.writeShort(10); // STR diff --git a/src/gui/playerbox.cpp b/src/gui/playerbox.cpp index d8faff99..ba97d54c 100644 --- a/src/gui/playerbox.cpp +++ b/src/gui/playerbox.cpp @@ -94,12 +94,13 @@ void PlayerBox::draw(gcn::Graphics *graphics) playerset[mSex]->get(0), 23, 12); // Draw his hair - if (mHairColor < NR_HAIR_COLORS && mHairStyle < NR_HAIR_STYLES) + if (mHairStyle > 0 && mHairColor < NR_HAIR_COLORS && + mHairStyle < NR_HAIR_STYLES) { int hf = 9 * mHairColor; if (hf >= 0 && hf < (int)hairset[mHairStyle]->size()) { dynamic_cast(graphics)->drawImage( - hairset[mHairStyle]->get(hf), 35, 7); + hairset[mHairStyle - 1]->get(hf), 35, 7); } } } diff --git a/src/main.cpp b/src/main.cpp index ef5557ec..4e65e4fc 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -257,7 +257,7 @@ void init_engine() if (!playerset[1]) logger->error("Couldn't load female player spriteset!"); - for (int i = 0; i < NR_HAIR_STYLES; i++) + for (int i = 0; i < NR_HAIR_STYLES - 1; i++) { Spriteset *tmp = ResourceManager::getInstance()->getSpriteset( "graphics/sprites/hairstyle" + toString(i + 1) + ".png", diff --git a/src/net/beinghandler.cpp b/src/net/beinghandler.cpp index 10de5351..c85e8893 100644 --- a/src/net/beinghandler.cpp +++ b/src/net/beinghandler.cpp @@ -398,7 +398,7 @@ BeingHandler::handleBeingEnterMessage(MessageIn &msg) being = beingManager->createBeing(id, 0); being->setName(name); } - being->setHairStyle(msg.readByte() + 1); - being->setHairColor(msg.readByte() + 1); + being->setHairStyle(msg.readByte()); + being->setHairColor(msg.readByte()); being->setSex(msg.readByte()); } diff --git a/src/player.cpp b/src/player.cpp index b864dd0e..3f4abebb 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -114,12 +114,12 @@ Player::setSex(Uint8 sex) void Player::setHairColor(Uint16 color) { - if (color != mHairColor && mHairStyle > 0) + if (color != mHairColor) { delete mSprites[HAIR_SPRITE]; AnimatedSprite *newHairSprite = new AnimatedSprite( "graphics/sprites/hairstyle" + toString(mHairStyle) + ".xml", - color - 1); + color); newHairSprite->setDirection(getSpriteDirection()); mSprites[HAIR_SPRITE] = newHairSprite; @@ -133,12 +133,12 @@ Player::setHairColor(Uint16 color) void Player::setHairStyle(Uint16 style) { - if (style != mHairStyle && mHairColor > 0) + if (style != mHairStyle) { delete mSprites[HAIR_SPRITE]; AnimatedSprite *newHairSprite = new AnimatedSprite( "graphics/sprites/hairstyle" + toString(style) + ".xml", - mHairColor - 1); + mHairColor); newHairSprite->setDirection(getSpriteDirection()); mSprites[HAIR_SPRITE] = newHairSprite; -- cgit v1.2.3-70-g09d2 From 07b6070c25faedd78c2e26825bd700dc294f00cf Mon Sep 17 00:00:00 2001 From: Guillaume Melquiond Date: Sat, 26 Aug 2006 17:24:43 +0000 Subject: Made the Network class a purely static interface, as there is only one instance. --- ChangeLog | 9 +++++ src/beingmanager.cpp | 7 +--- src/beingmanager.h | 4 --- src/engine.cpp | 5 ++- src/engine.h | 4 +-- src/game.cpp | 42 +++++++++++------------ src/game.h | 5 +-- src/gui/buy.cpp | 4 +-- src/gui/buy.h | 4 +-- src/gui/char_select.cpp | 17 +++++----- src/gui/char_select.h | 8 ++--- src/gui/chat.cpp | 5 ++- src/gui/chat.h | 4 +-- src/gui/sell.cpp | 3 +- src/gui/sell.h | 4 +-- src/gui/trade.cpp | 3 +- src/gui/trade.h | 5 +-- src/localplayer.h | 4 --- src/main.cpp | 48 +++++++++++++------------- src/net/charserverhandler.cpp | 4 +-- src/net/messagehandler.cpp | 14 +------- src/net/messagehandler.h | 7 ---- src/net/network.cpp | 47 ++++++++++++++----------- src/net/network.h | 79 ++++++++++++++----------------------------- src/net/tradehandler.h | 2 -- src/npc.cpp | 4 +-- src/npc.h | 7 +--- 27 files changed, 136 insertions(+), 213 deletions(-) (limited to 'src/gui/char_select.cpp') diff --git a/ChangeLog b/ChangeLog index 8e10286f..97782a6e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -15,6 +15,15 @@ support for "say around" messages. * src/net/beinghandler.cpp: Partly implemented being creation, so that chat works. + * src/game.cpp, src/engine.h, src/beingmanager.h, src/gui/trade.cpp, + src/gui/sell.cpp, src/gui/char_select.cpp, src/gui/chat.h, + src/gui/buy.h, src/gui/chat.cpp, src/gui/char_select.h, + src/gui/buy.cpp, src/gui/sell.h, src/gui/trade.h, src/engine.cpp, + src/beingmanager.cpp, src/npc.cpp, src/main.cpp, src/npc.h, + src/net/tradehandler.h, src/net/messagehandler.h, src/net/network.h, + src/net/charserverhandler.cpp, src/net/messagehandler.cpp, + src/net/network.cpp, src/localplayer.h, src/game.h: Made the Network + class a purely static interface, as there is only one instance. 2006-08-21 Eugenio Favalli diff --git a/src/beingmanager.cpp b/src/beingmanager.cpp index 7a94859a..caecd88e 100644 --- a/src/beingmanager.cpp +++ b/src/beingmanager.cpp @@ -49,11 +49,6 @@ class FindBeingFunctor Being::Type type; } beingFinder; -BeingManager::BeingManager(Network *network): - mNetwork(network) -{ -} - void BeingManager::setMap(Map *map) { mMap = map; @@ -79,7 +74,7 @@ Being* BeingManager::createBeing(Uint32 id, Uint16 job) outMsg.writeLong(id); } else if (job >= 100 & job < 200) - being = new NPC(id, job, mMap, mNetwork); + being = new NPC(id, job, mMap); else if (job >= 1000 && job < 1200) being = new Monster(id, job, mMap); else diff --git a/src/beingmanager.h b/src/beingmanager.h index bb6fc99b..0dbafcc6 100644 --- a/src/beingmanager.h +++ b/src/beingmanager.h @@ -28,7 +28,6 @@ class LocalPlayer; class Map; -class Network; typedef std::list Beings; typedef Beings::iterator BeingIterator; @@ -36,8 +35,6 @@ typedef Beings::iterator BeingIterator; class BeingManager { public: - BeingManager(Network *network); - /** * Sets the map on which beings are created */ @@ -86,7 +83,6 @@ class BeingManager protected: Beings mBeings; Map *mMap; - Network *mNetwork; }; extern BeingManager *beingManager; diff --git a/src/engine.cpp b/src/engine.cpp index a6ce9533..3e6b091a 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -62,10 +62,9 @@ Spriteset *emotionset; Spriteset *npcset; std::vector weaponset; -Engine::Engine(Network *network): +Engine::Engine(): mShowDebugPath(false), - mCurrentMap(NULL), - mNetwork(network) + mCurrentMap(NULL) { // Load the sprite sets ResourceManager *resman = ResourceManager::getInstance(); diff --git a/src/engine.h b/src/engine.h index ff39cfba..bdf8419a 100644 --- a/src/engine.h +++ b/src/engine.h @@ -30,7 +30,6 @@ extern int camera_x, camera_y; class Graphics; class Map; -class Network; /** * Game engine that does the main drawing. @@ -41,7 +40,7 @@ class Engine /** * Constructor. */ - Engine(Network *network); + Engine(); /** * Destructor. @@ -77,7 +76,6 @@ class Engine bool mShowDebugPath; Map *mCurrentMap; - Network *mNetwork; }; extern Engine *engine; diff --git a/src/game.cpp b/src/game.cpp index b6428103..f83e9c1f 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -164,15 +164,15 @@ int get_elapsed_time(int start_time) /** * Create all the various globally accessible gui windows */ -void createGuiWindows(Network *network) +void createGuiWindows() { // Create dialogs - chatWindow = new ChatWindow(network); + chatWindow = new ChatWindow; menuWindow = new MenuWindow(); statusWindow = new StatusWindow(player_node); miniStatusWindow = new MiniStatusWindow(); - buyDialog = new BuyDialog(network); - sellDialog = new SellDialog(network); + buyDialog = new BuyDialog; + sellDialog = new SellDialog; buySellDialog = new BuySellDialog(); inventoryWindow = new InventoryWindow(); npcTextDialog = new NpcTextDialog(); @@ -183,7 +183,7 @@ void createGuiWindows(Network *network) minimap = new Minimap(); equipmentWindow = new EquipmentWindow(player_node->mEquipment.get()); chargeDialog = new ChargeDialog(); - tradeWindow = new TradeWindow(network); + tradeWindow = new TradeWindow; //buddyWindow = new BuddyWindow(); helpWindow = new HelpWindow(); debugWindow = new DebugWindow(); @@ -250,8 +250,7 @@ void destroyGuiWindows() delete debugWindow; } -Game::Game(Network *network): - mNetwork(network), +Game::Game(): mBeingHandler(new BeingHandler()), mBuySellHandler(new BuySellHandler()), mChatHandler(new ChatHandler()), @@ -263,10 +262,10 @@ Game::Game(Network *network): mSkillHandler(new SkillHandler()), mTradeHandler(new TradeHandler()) { - createGuiWindows(network); - engine = new Engine(network); + createGuiWindows(); + engine = new Engine; - beingManager = new BeingManager(network); + beingManager = new BeingManager; floorItemManager = new FloorItemManager(); // Initialize timers @@ -276,7 +275,6 @@ Game::Game(Network *network): // Initialize beings beingManager->setPlayer(player_node); - player_node->setNetwork(network); Joystick::init(); // TODO: The user should be able to choose which one to use @@ -286,16 +284,16 @@ Game::Game(Network *network): joystick = new Joystick(0); } - network->registerHandler(mBeingHandler.get()); - network->registerHandler(mBuySellHandler.get()); - network->registerHandler(mChatHandler.get()); - network->registerHandler(mEquipmentHandler.get()); - network->registerHandler(mInventoryHandler.get()); - network->registerHandler(mItemHandler.get()); - network->registerHandler(mNpcHandler.get()); - network->registerHandler(mPlayerHandler.get()); - network->registerHandler(mSkillHandler.get()); - network->registerHandler(mTradeHandler.get()); + Network::registerHandler(mBeingHandler.get()); + Network::registerHandler(mBuySellHandler.get()); + Network::registerHandler(mChatHandler.get()); + Network::registerHandler(mEquipmentHandler.get()); + Network::registerHandler(mInventoryHandler.get()); + Network::registerHandler(mItemHandler.get()); + Network::registerHandler(mNpcHandler.get()); + Network::registerHandler(mPlayerHandler.get()); + Network::registerHandler(mSkillHandler.get()); + Network::registerHandler(mTradeHandler.get()); } Game::~Game() @@ -374,7 +372,7 @@ void Game::logic() } // Handle network stuff - mNetwork->flush(); + Network::flush(); } } diff --git a/src/game.h b/src/game.h index a44c8970..7330052a 100644 --- a/src/game.h +++ b/src/game.h @@ -31,7 +31,6 @@ #define SPEECH_MAX_TIME 100 class MessageHandler; -class Network; extern std::string map_path; extern volatile int fps; @@ -40,7 +39,7 @@ extern volatile int tick_time; class Game { public: - Game(Network *network); + Game(); ~Game(); void logic(); @@ -48,8 +47,6 @@ class Game void handleInput(); protected: - Network *mNetwork; - typedef std::auto_ptr MessageHandlerPtr; MessageHandlerPtr mBeingHandler; MessageHandlerPtr mBuySellHandler; diff --git a/src/gui/buy.cpp b/src/gui/buy.cpp index e7bfef58..63a6e20e 100644 --- a/src/gui/buy.cpp +++ b/src/gui/buy.cpp @@ -42,8 +42,8 @@ #include "../utils/tostring.h" -BuyDialog::BuyDialog(Network *network): - Window("Buy"), mNetwork(network), +BuyDialog::BuyDialog(): + Window("Buy"), mMoney(0), mAmountItems(0), mMaxItems(0) { mShopItems = new ShopItems; diff --git a/src/gui/buy.h b/src/gui/buy.h index b09b648b..0ddea4c4 100644 --- a/src/gui/buy.h +++ b/src/gui/buy.h @@ -30,7 +30,6 @@ #include "../guichanfwd.h" -class Network; class ShopItems; /** @@ -46,7 +45,7 @@ class BuyDialog : public Window, public gcn::ActionListener * * @see Window::Window */ - BuyDialog(Network *network); + BuyDialog(); /** * Destructor @@ -89,7 +88,6 @@ class BuyDialog : public Window, public gcn::ActionListener std::string getElementAt(int i); private: - Network *mNetwork; gcn::Button *mBuyButton; gcn::Button *mQuitButton; gcn::Button *mIncreaseButton; diff --git a/src/gui/char_select.cpp b/src/gui/char_select.cpp index 3db82287..7e0a1a29 100644 --- a/src/gui/char_select.cpp +++ b/src/gui/char_select.cpp @@ -71,9 +71,8 @@ void CharDeleteConfirm::action(const std::string &eventId, gcn::Widget *widget) ConfirmDialog::action(eventId, widget); } -CharSelectDialog::CharSelectDialog(Network *network, - LockedArray *charInfo): - Window("Select Character"), mNetwork(network), +CharSelectDialog::CharSelectDialog(LockedArray *charInfo): + Window("Select Character"), mCharInfo(charInfo), mCharSelected(false) { mSelectButton = new Button("Ok", "ok", this); @@ -147,7 +146,7 @@ void CharSelectDialog::action(const std::string &eventId, gcn::Widget *widget) { // Start new character dialog mCharInfo->lock(); - new CharCreateDialog(this, mCharInfo->getPos(), mNetwork); + new CharCreateDialog(this, mCharInfo->getPos()); mCharInfo->unlock(); } } @@ -208,7 +207,7 @@ void CharSelectDialog::attemptCharDelete() msg.writeShort(PAMSG_CHAR_DELETE); // TODO: Send the selected slot msg.writeByte(0); - network->send(Network::ACCOUNT, msg); + Network::send(Network::ACCOUNT, msg); mCharInfo->lock(); } @@ -218,7 +217,7 @@ void CharSelectDialog::attemptCharSelect() MessageOut msg; msg.writeShort(PAMSG_CHAR_SELECT); msg.writeByte(mCharInfo->getPos()); - network->send(Network::ACCOUNT, msg); + Network::send(Network::ACCOUNT, msg); mCharInfo->lock(); } @@ -227,8 +226,8 @@ void CharSelectDialog::logic() updatePlayerInfo(); } -CharCreateDialog::CharCreateDialog(Window *parent, int slot, Network *network): - Window("Create Character", true, parent), mNetwork(network), mSlot(slot) +CharCreateDialog::CharCreateDialog(Window *parent, int slot): + Window("Create Character", true, parent), mSlot(slot) { mNameField = new TextField(""); mNameLabel = new gcn::Label("Name:"); @@ -336,5 +335,5 @@ void CharCreateDialog::attemptCharCreate() outMsg.writeShort(10); // INT outMsg.writeShort(10); // DEX outMsg.writeShort(10); // LUK - network->send(Network::ACCOUNT, outMsg); + Network::send(Network::ACCOUNT, outMsg); } diff --git a/src/gui/char_select.h b/src/gui/char_select.h index e65f400d..73fc8b2d 100644 --- a/src/gui/char_select.h +++ b/src/gui/char_select.h @@ -32,7 +32,6 @@ #include class LocalPlayer; -class Network; class PlayerBox; /** @@ -47,8 +46,7 @@ class CharSelectDialog : public Window, public gcn::ActionListener /** * Constructor. */ - CharSelectDialog(Network *network, - LockedArray *charInfo); + CharSelectDialog(LockedArray *charInfo); void action(const std::string& eventId, gcn::Widget* widget); @@ -57,7 +55,6 @@ class CharSelectDialog : public Window, public gcn::ActionListener void logic(); private: - Network *mNetwork; LockedArray *mCharInfo; gcn::Button *mSelectButton; @@ -97,14 +94,13 @@ class CharCreateDialog : public Window, public gcn::ActionListener /** * Constructor. */ - CharCreateDialog(Window *parent, int slot, Network *network); + CharCreateDialog(Window *parent, int slot); void action(const std::string& eventId, gcn::Widget* widget); std::string getName(); private: - Network *mNetwork; gcn::TextField *mNameField; gcn::Label *mNameLabel; gcn::Button *mNextHairColorButton; diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp index e8bb1cc6..04ac3996 100644 --- a/src/gui/chat.cpp +++ b/src/gui/chat.cpp @@ -40,9 +40,8 @@ #include "../net/network.h" #include "../net/protocol.h" -ChatWindow::ChatWindow(Network *network): +ChatWindow::ChatWindow(): Window(""), - mNetwork(network), mTmpVisible(false) { setWindowName("Chat"); @@ -253,7 +252,7 @@ ChatWindow::chatSend(const std::string &nick, std::string msg) MessageOut outMsg; outMsg.writeShort(PGMSG_SAY); outMsg.writeString(msg); - network->send(Network::GAME, outMsg); + Network::send(Network::GAME, outMsg); } else if (msg.substr(0, IS_ANNOUNCE_LENGTH) == IS_ANNOUNCE) { diff --git a/src/gui/chat.h b/src/gui/chat.h index 20841873..a0a3d1ec 100644 --- a/src/gui/chat.h +++ b/src/gui/chat.h @@ -35,7 +35,6 @@ #include "../guichanfwd.h" class BrowserBox; -class Network; class ScrollArea; #define BY_GM 0 // those should be self-explanatory =) @@ -116,7 +115,7 @@ class ChatWindow : public Window, public gcn::ActionListener, /** * Constructor. */ - ChatWindow(Network *network); + ChatWindow(); /** * Logic (updates components' size) @@ -188,7 +187,6 @@ class ChatWindow : public Window, public gcn::ActionListener, void setVisible(bool visible); private: - Network *mNetwork; bool mTmpVisible; /** One item in the chat log */ diff --git a/src/gui/sell.cpp b/src/gui/sell.cpp index e820d42f..3aa7c889 100644 --- a/src/gui/sell.cpp +++ b/src/gui/sell.cpp @@ -44,9 +44,8 @@ #include "../utils/tostring.h" -SellDialog::SellDialog(Network *network): +SellDialog::SellDialog(): Window("Sell"), - mNetwork(network), mMaxItems(0), mAmountItems(0) { mShopItems = new ShopItems(); diff --git a/src/gui/sell.h b/src/gui/sell.h index 423fea26..be5185bd 100644 --- a/src/gui/sell.h +++ b/src/gui/sell.h @@ -31,7 +31,6 @@ #include "../guichanfwd.h" class Item; -class Network; class ShopItems; @@ -48,7 +47,7 @@ class SellDialog : public Window, public gcn::ActionListener * * @see Window::Window */ - SellDialog(Network *network); + SellDialog(); /** * Destructor @@ -76,7 +75,6 @@ class SellDialog : public Window, public gcn::ActionListener void mouseClick(int x, int y, int buton, int count); private: - Network *mNetwork; gcn::Button *mSellButton; gcn::Button *mIncreaseButton; gcn::Button *mDecreaseButton; diff --git a/src/gui/trade.cpp b/src/gui/trade.cpp index 73193c88..6b247901 100644 --- a/src/gui/trade.cpp +++ b/src/gui/trade.cpp @@ -45,9 +45,8 @@ #include "../utils/tostring.h" -TradeWindow::TradeWindow(Network *network): +TradeWindow::TradeWindow(): Window("Trade: You"), - mNetwork(network), mMyInventory(new Inventory()), mPartnerInventory(new Inventory()) { diff --git a/src/gui/trade.h b/src/gui/trade.h index eb3c0f97..fe60aac5 100644 --- a/src/gui/trade.h +++ b/src/gui/trade.h @@ -35,7 +35,6 @@ class Inventory; class Item; class ItemContainer; -class Network; class ScrollArea; /** @@ -49,7 +48,7 @@ class TradeWindow : public Window, gcn::ActionListener /** * Constructor. */ - TradeWindow(Network *network); + TradeWindow(); /** * Destructor. @@ -113,8 +112,6 @@ class TradeWindow : public Window, gcn::ActionListener void action(const std::string& eventId, gcn::Widget* widget); private: - Network *mNetwork; - typedef std::auto_ptr InventoryPtr; InventoryPtr mMyInventory; InventoryPtr mPartnerInventory; diff --git a/src/localplayer.h b/src/localplayer.h index fdef6ba1..613f196a 100644 --- a/src/localplayer.h +++ b/src/localplayer.h @@ -34,7 +34,6 @@ class FloorItem; class Inventory; class Item; -class Network; class LocalPlayer : public Player { @@ -47,8 +46,6 @@ class LocalPlayer : public Player virtual ~LocalPlayer(); - void setNetwork(Network *network) { mNetwork = network; } - virtual void logic(); virtual void nextStep(); @@ -145,7 +142,6 @@ class LocalPlayer : public Player std::auto_ptr mInventory; protected: - Network *mNetwork; Being *mTarget; FloorItem *mPickUpTarget; diff --git a/src/main.cpp b/src/main.cpp index 4e65e4fc..573b1a79 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -413,8 +413,8 @@ MapLoginHandler mapLoginHandler; void accountLogin(LoginData *loginData) { logger->log("Username is %s", loginData->username.c_str()); - network->registerHandler(&loginHandler); - network->registerHandler(&charServerHandler); + Network::registerHandler(&loginHandler); + Network::registerHandler(&charServerHandler); loginHandler.setLoginData(loginData); charServerHandler.setLoginData(loginData); charServerHandler.setCharInfo(&charInfo); @@ -424,7 +424,7 @@ void accountLogin(LoginData *loginData) msg.writeLong(0); // client version msg.writeString(loginData->username); msg.writeString(loginData->password); - network->send(Network::ACCOUNT, msg); + Network::send(Network::ACCOUNT, msg); // Clear the password, avoids auto login when returning to login loginData->password = ""; @@ -441,7 +441,7 @@ void accountLogin(LoginData *loginData) void accountRegister(LoginData *loginData) { logger->log("Username is %s", loginData->username.c_str()); - network->registerHandler(&loginHandler); + Network::registerHandler(&loginHandler); loginHandler.setLoginData(loginData); charServerHandler.setLoginData(loginData); charServerHandler.setCharInfo(&charInfo); @@ -452,21 +452,21 @@ void accountRegister(LoginData *loginData) msg.writeString(loginData->username); msg.writeString(loginData->password); msg.writeString(loginData->email); - network->send(Network::ACCOUNT, msg); + Network::send(Network::ACCOUNT, msg); } -void mapLogin(Network *network, LoginData *loginData) +void mapLogin(LoginData *loginData) { - network->registerHandler(&mapLoginHandler); + Network::registerHandler(&mapLoginHandler); // Send connect messages with the magic token to game and chat servers MessageOut gameServerConnect(PGMSG_CONNECT); gameServerConnect.writeString(token, 32); - network->send(Network::GAME, gameServerConnect); + Network::send(Network::GAME, gameServerConnect); MessageOut chatServerConnect(PCMSG_CONNECT); chatServerConnect.writeString(token, 32); - network->send(Network::CHAT, chatServerConnect); + Network::send(Network::CHAT, chatServerConnect); } /** Main */ @@ -533,7 +533,7 @@ int main(int argc, char *argv[]) { logger->error("An error occurred while initializing ENet."); } - network = new Network(); + Network::initialize(); SDL_Event event; @@ -557,9 +557,9 @@ int main(int argc, char *argv[]) } gui->logic(); - network->flush(); + Network::flush(); - if (network->getState() == Network::NET_ERROR) + if (Network::getState() == Network::NET_ERROR) { state = STATE_ERROR; errorMessage = "Got disconnected from server!"; @@ -585,7 +585,7 @@ int main(int argc, char *argv[]) // TODO: Add connect timeout to go back to choose server if (state == STATE_CONNECT_ACCOUNT && - network->isConnected(Network::ACCOUNT)) + Network::isConnected(Network::ACCOUNT)) { if (options.skipUpdate) { state = STATE_LOGIN; @@ -594,8 +594,8 @@ int main(int argc, char *argv[]) } } else if (state == STATE_CONNECT_GAME && - network->isConnected(Network::GAME) && - network->isConnected(Network::CHAT)) + Network::isConnected(Network::GAME) && + Network::isConnected(Network::CHAT)) { // TODO: Somehow send the token state = STATE_GAME; @@ -611,7 +611,7 @@ int main(int argc, char *argv[]) // Disconnect from account server once connected to game server if (oldstate == STATE_CONNECT_GAME && state == STATE_GAME) { - network->disconnect(Network::ACCOUNT); + Network::disconnect(Network::ACCOUNT); } oldstate = state; @@ -627,7 +627,7 @@ int main(int argc, char *argv[]) logger->log("State: CHOOSE_SERVER"); // TODO: Allow changing this using a server choice dialog logger->log("Trying to connect to account server..."); - network->connect(Network::ACCOUNT, + Network::connect(Network::ACCOUNT, loginData.hostname, loginData.port); state = STATE_CONNECT_ACCOUNT; break; @@ -667,7 +667,7 @@ int main(int argc, char *argv[]) case STATE_CHAR_SELECT: logger->log("State: CHAR_SELECT"); - currentDialog = new CharSelectDialog(network, &charInfo); + currentDialog = new CharSelectDialog(&charInfo); if (options.chooseDefault) { ((CharSelectDialog*)currentDialog)->action("ok", NULL); @@ -679,9 +679,9 @@ int main(int argc, char *argv[]) currentDialog = new OkDialog("Error", errorMessage); currentDialog->addActionListener(&errorListener); currentDialog = NULL; // OkDialog deletes itself - network->disconnect(Network::GAME); - network->disconnect(Network::CHAT); - network->clearHandlers(); + Network::disconnect(Network::GAME); + Network::disconnect(Network::CHAT); + Network::clearHandlers(); break; case STATE_CONNECT_GAME: @@ -690,7 +690,7 @@ int main(int argc, char *argv[]) break; case STATE_GAME: - mapLogin(network, &loginData); + mapLogin(&loginData); sound.fadeOutMusic(1000); currentDialog = NULL; @@ -698,7 +698,7 @@ int main(int argc, char *argv[]) login_wallpaper = NULL; logger->log("State: GAME"); - game = new Game(network); + game = new Game; game->logic(); delete game; state = STATE_EXIT; @@ -711,7 +711,7 @@ int main(int argc, char *argv[]) } } - delete network; + Network::finalize(); enet_deinitialize(); if (nullFile) diff --git a/src/net/charserverhandler.cpp b/src/net/charserverhandler.cpp index 1eea29b8..d67949cc 100644 --- a/src/net/charserverhandler.cpp +++ b/src/net/charserverhandler.cpp @@ -174,8 +174,8 @@ CharServerHandler::handleCharSelectResponse(MessageIn &msg) logger->log("Game server: %s:%d", gameServer.c_str(), gameServerPort); logger->log("Chat server: %s:%d", chatServer.c_str(), chatServerPort); - network->connect(Network::GAME, gameServer, gameServerPort); - network->connect(Network::CHAT, chatServer, chatServerPort); + Network::connect(Network::GAME, gameServer, gameServerPort); + Network::connect(Network::CHAT, chatServer, chatServerPort); // Keep the selected character and delete the others player_node = mCharInfo->getEntry(); diff --git a/src/net/messagehandler.cpp b/src/net/messagehandler.cpp index 849b6716..0b5cd87c 100644 --- a/src/net/messagehandler.cpp +++ b/src/net/messagehandler.cpp @@ -27,19 +27,7 @@ #include "network.h" -MessageHandler::MessageHandler(): - mNetwork(0) -{ -} - MessageHandler::~MessageHandler() { - if (mNetwork) - mNetwork->unregisterHandler(this); -} - -void MessageHandler::setNetwork(Network *network) -{ - assert(!(network && mNetwork)); - mNetwork = network; + Network::unregisterHandler(this); } diff --git a/src/net/messagehandler.h b/src/net/messagehandler.h index 9f92636d..b21abd72 100644 --- a/src/net/messagehandler.h +++ b/src/net/messagehandler.h @@ -27,22 +27,15 @@ #include class MessageIn; -class Network; class MessageHandler { public: const Uint16 *handledMessages; - MessageHandler(); virtual ~MessageHandler(); virtual void handleMessage(MessageIn &msg) = 0; - - void setNetwork(Network *network); - - protected: - Network *mNetwork; }; #endif diff --git a/src/net/network.cpp b/src/net/network.cpp index 08b5fe92..e56f6df0 100644 --- a/src/net/network.cpp +++ b/src/net/network.cpp @@ -29,10 +29,25 @@ #include "../log.h" -Network *network; +static Network::State mState; -Network::Network(): - mState(NET_OK) +/** + * The local host. + */ +static ENetHost *mClient; + +/** + * An array holding the peers of the account, game and chat servers. + */ +static ENetPeer *mServers[3]; + +typedef std::map MessageHandlers; +typedef MessageHandlers::iterator MessageHandlerIterator; +static MessageHandlers mMessageHandlers; + +Network::State Network::getState() { return mState; } + +void Network::initialize() { // Initialize server peers for (int i = 0; i < 3; ++i) @@ -48,7 +63,7 @@ Network::Network(): } } -Network::~Network() +void Network::finalize() { clearHandlers(); @@ -110,15 +125,10 @@ Network::disconnect(Server server) void Network::registerHandler(MessageHandler *handler) { - const Uint16 *i = handler->handledMessages; - - while(*i) + for (const Uint16 *i = handler->handledMessages; *i; i++) { mMessageHandlers[*i] = handler; - i++; } - - handler->setNetwork(this); } void @@ -128,30 +138,27 @@ Network::unregisterHandler(MessageHandler *handler) { mMessageHandlers.erase(*i); } - - handler->setNetwork(0); } void Network::clearHandlers() { - MessageHandlerIterator i; - for (i = mMessageHandlers.begin(); i != mMessageHandlers.end(); i++) - { - i->second->setNetwork(0); - } mMessageHandlers.clear(); } bool -Network::isConnected(Server server) const +Network::isConnected(Server server) { return mServers[server] != NULL && mServers[server]->state == ENET_PEER_STATE_CONNECTED; } -void -Network::dispatchMessage(ENetPacket *packet) +/** + * Dispatches a message to the appropriate message handler and + * destroys it afterwards. + */ +static void +dispatchMessage(ENetPacket *packet) { MessageIn msg((const char *)packet->data, packet->dataLength); diff --git a/src/net/network.h b/src/net/network.h index 40255e44..861fa2b3 100644 --- a/src/net/network.h +++ b/src/net/network.h @@ -42,108 +42,79 @@ class MessageOut; class Network { public: - friend class MessageOut; - /** - * Constructor. Sets up the local host. + * Sets up the local host. */ - Network(); + static void + initialize(); /** - * Destructor. + * Closes the connections. */ - ~Network(); + static void + finalize(); - typedef enum { + enum Server { ACCOUNT, GAME, CHAT - } Server; + }; + + enum State { + NET_OK, + NET_ERROR + }; /** * Connects to the given server with the specified address and port. * This method is non-blocking, use isConnected to check whether the * server is connected. */ - bool + static bool connect(Server server, const std::string &address, short port); /** * Disconnects from the given server. */ - void + static void disconnect(Server server); /** * Registers a message handler. A message handler handles a certain * subset of incoming messages. */ - void + static void registerHandler(MessageHandler *handler); /** * Unregisters a message handler. */ - void + static void unregisterHandler(MessageHandler *handler); - void + static void clearHandlers(); - int - getState() const { return mState; } + static State + getState(); /** * Returns whether the given server is connected. */ - bool - isConnected(Server server) const; + static bool + isConnected(Server server); - void + static void flush(); /** - * Send a message to a given server. The server should be connected. + * Sends a message to a given server. The server should be connected. */ - void + static void send(Server server, const MessageOut &msg); - - enum State { - NET_OK, - NET_ERROR - }; - - private: - /** - * The local host. - */ - ENetHost *mClient; - - /** - * An array holding the peers of the account, game and chat servers. - */ - ENetPeer *mServers[3]; - - /** - * Dispatches a message to the appropriate message handler and - * destroys it afterwards. - */ - void - dispatchMessage(ENetPacket *packet); - - unsigned int mToSkip; - - int mState; - - typedef std::map MessageHandlers; - typedef MessageHandlers::iterator MessageHandlerIterator; - MessageHandlers mMessageHandlers; }; /** Convert an address from int format to string */ char *iptostring(int address); -// TODO: remove this global, just a temp solution. -extern Network *network; - #endif diff --git a/src/net/tradehandler.h b/src/net/tradehandler.h index 0b73c871..1ab3c2e4 100644 --- a/src/net/tradehandler.h +++ b/src/net/tradehandler.h @@ -26,8 +26,6 @@ #include "messagehandler.h" -class Network; - class TradeHandler : public MessageHandler { public: diff --git a/src/npc.cpp b/src/npc.cpp index a82490ae..a14b6d24 100644 --- a/src/npc.cpp +++ b/src/npc.cpp @@ -33,8 +33,8 @@ extern Spriteset *npcset; NPC *current_npc = 0; -NPC::NPC(Uint32 id, Uint16 job, Map *map, Network *network): - Being(id, job, map), mNetwork(network) +NPC::NPC(Uint32 id, Uint16 job, Map *map): + Being(id, job, map) { mSprites[BASE_SPRITE] = new AnimatedSprite("graphics/sprites/npc.xml", job-100); } diff --git a/src/npc.h b/src/npc.h index b08c315c..bbc86d9c 100644 --- a/src/npc.h +++ b/src/npc.h @@ -26,12 +26,10 @@ #include "being.h" -class Network; - class NPC : public Being { public: - NPC(Uint32 id, Uint16 job, Map *map, Network *network); + NPC(Uint32 id, Uint16 job, Map *map); virtual Type getType() const; @@ -41,9 +39,6 @@ class NPC : public Being void buy(); void sell(); - - protected: - Network *mNetwork; }; extern NPC *current_npc; -- cgit v1.2.3-70-g09d2 From 40339bebb026cd553aacbbff6f2fe1aa14816d5a Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Sat, 26 Aug 2006 22:09:04 +0000 Subject: Got rid of the default MessageOut constructor, since all messages should have an ID. --- ChangeLog | 12 ++++++++++-- src/beingmanager.cpp | 3 +-- src/engine.cpp | 7 ------- src/gui/buy.cpp | 13 ++++++++----- src/gui/char_select.cpp | 6 ++---- src/gui/chat.cpp | 9 +++------ src/gui/sell.cpp | 3 +-- src/gui/trade.cpp | 15 +++++---------- src/localplayer.cpp | 42 ++++++++++++++---------------------------- src/net/messageout.cpp | 7 ------- src/net/messageout.h | 5 ----- src/npc.cpp | 15 +++++---------- 12 files changed, 49 insertions(+), 88 deletions(-) (limited to 'src/gui/char_select.cpp') diff --git a/ChangeLog b/ChangeLog index de1d030c..6850a45e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2006-08-27 Bjørn Lindeijer + + * src/localplayer.cpp, src/gui/sell.cpp, src/gui/trade.cpp, + src/gui/char_select.cpp, src/gui/chat.cpp, src/gui/buy.cpp, + src/engine.cpp, src/beingmanager.cpp, src/npc.cpp, + src/net/messageout.cpp, src/net/messageout.h: Got rid of the default + MessageOut constructor, since all messages should have an ID. + 2006-08-26 Bjørn Lindeijer * src/gui/char_select.cpp, src/gui/playerbox.cpp, src/player.cpp, @@ -24,8 +32,8 @@ src/net/charserverhandler.cpp, src/net/messagehandler.cpp, src/net/network.cpp, src/localplayer.h, src/game.h: Made the Network class a purely static interface, as there is only one instance. - * src/net/beinghandler.cpp, src/net/beinghandler.h, src/net/protocol.h: - Added support for "beings move" messages. + * src/net/beinghandler.cpp, src/net/beinghandler.h, + src/net/protocol.h: Added support for "beings move" messages. 2006-08-21 Eugenio Favalli diff --git a/src/beingmanager.cpp b/src/beingmanager.cpp index caecd88e..a6c7974d 100644 --- a/src/beingmanager.cpp +++ b/src/beingmanager.cpp @@ -69,8 +69,7 @@ Being* BeingManager::createBeing(Uint32 id, Uint16 job) if (job < 10) { being = new Player(id, job, mMap); - MessageOut outMsg; - outMsg.writeShort(0x0094); + MessageOut outMsg(0x0094); outMsg.writeLong(id); } else if (job >= 100 & job < 200) diff --git a/src/engine.cpp b/src/engine.cpp index 3e6b091a..7a33dd3d 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -39,9 +39,6 @@ #include "gui/gui.h" #include "gui/minimap.h" -#include "net/messageout.h" -#include "net/protocol.h" - #include "resources/itemmanager.h" #include "resources/mapreader.h" #include "resources/resourcemanager.h" @@ -148,10 +145,6 @@ void Engine::changeMap(const std::string &mapPath) } mCurrentMap = newMap; - - // Send "map loaded" - MessageOut outMsg; - outMsg.writeShort(CMSG_MAP_LOADED); } void Engine::logic() diff --git a/src/gui/buy.cpp b/src/gui/buy.cpp index 63a6e20e..165fa7dc 100644 --- a/src/gui/buy.cpp +++ b/src/gui/buy.cpp @@ -215,9 +215,9 @@ void BuyDialog::action(const std::string &eventId, gcn::Widget *widget) // of items to be bought ever fails, Bertram removed the assertions, is // there a better way to ensure this fails in an _obivous_ way in C++? else if (eventId == "buy" && (mAmountItems > 0 && - mAmountItems <= mMaxItems)) { - MessageOut outMsg; - outMsg.writeShort(CMSG_NPC_BUY_REQUEST); + mAmountItems <= mMaxItems)) + { + MessageOut outMsg(CMSG_NPC_BUY_REQUEST); outMsg.writeShort(8); outMsg.writeShort(mAmountItems); outMsg.writeShort(mShopItems->at(selectedItem).id); @@ -262,9 +262,12 @@ void BuyDialog::mouseClick(int x, int y, int button, int count) int selectedItem = mItemList->getSelected(); if (selectedItem > -1) { + int itemId = mShopItems->at(selectedItem).id; + ItemInfo *itemInfo = itemDb->getItemInfo(itemId); + mItemDescLabel->setCaption("Description: " + - itemDb->getItemInfo(mShopItems->at(selectedItem).id)->getDescription()); + itemInfo->getDescription()); mItemEffectLabel->setCaption("Effect: " + - itemDb->getItemInfo(mShopItems->at(selectedItem).id)->getEffect()); + itemInfo->getEffect()); } } diff --git a/src/gui/char_select.cpp b/src/gui/char_select.cpp index 7e0a1a29..adcbe290 100644 --- a/src/gui/char_select.cpp +++ b/src/gui/char_select.cpp @@ -203,8 +203,7 @@ void CharSelectDialog::updatePlayerInfo() void CharSelectDialog::attemptCharDelete() { // Request character deletion - MessageOut msg; - msg.writeShort(PAMSG_CHAR_DELETE); + MessageOut msg(PAMSG_CHAR_DELETE); // TODO: Send the selected slot msg.writeByte(0); Network::send(Network::ACCOUNT, msg); @@ -214,8 +213,7 @@ void CharSelectDialog::attemptCharDelete() void CharSelectDialog::attemptCharSelect() { // Request character selection - MessageOut msg; - msg.writeShort(PAMSG_CHAR_SELECT); + MessageOut msg(PAMSG_CHAR_SELECT); msg.writeByte(mCharInfo->getPos()); Network::send(Network::ACCOUNT, msg); mCharInfo->lock(); diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp index 04ac3996..9098f9f0 100644 --- a/src/gui/chat.cpp +++ b/src/gui/chat.cpp @@ -249,16 +249,14 @@ ChatWindow::chatSend(const std::string &nick, std::string msg) // Prepare ordinary message if (msg.substr(0, 1) != "/") { - MessageOut outMsg; - outMsg.writeShort(PGMSG_SAY); + MessageOut outMsg(PGMSG_SAY); outMsg.writeString(msg); Network::send(Network::GAME, outMsg); } else if (msg.substr(0, IS_ANNOUNCE_LENGTH) == IS_ANNOUNCE) { msg.erase(0, IS_ANNOUNCE_LENGTH); - MessageOut outMsg; - outMsg.writeShort(0x0099); + MessageOut outMsg(0x0099); outMsg.writeShort(msg.length() + 4); outMsg.writeString(msg, msg.length()); } @@ -276,8 +274,7 @@ ChatWindow::chatSend(const std::string &nick, std::string msg) } else if (msg.substr(0, IS_WHO_LENGTH) == IS_WHO) { - MessageOut outMsg; - outMsg.writeShort(0x00c1); + MessageOut outMsg(0x00c1); } else { diff --git a/src/gui/sell.cpp b/src/gui/sell.cpp index 3aa7c889..33813271 100644 --- a/src/gui/sell.cpp +++ b/src/gui/sell.cpp @@ -212,8 +212,7 @@ void SellDialog::action(const std::string &eventId, gcn::Widget *widget) // Attempt sell assert(mAmountItems > 0 && mAmountItems <= mMaxItems); - MessageOut outMsg; - outMsg.writeShort(CMSG_NPC_SELL_REQUEST); + MessageOut outMsg(CMSG_NPC_SELL_REQUEST); outMsg.writeShort(8); outMsg.writeShort(mShopItems->at(selectedItem).index); outMsg.writeShort(mAmountItems); diff --git a/src/gui/trade.cpp b/src/gui/trade.cpp index 6b247901..0cd49013 100644 --- a/src/gui/trade.cpp +++ b/src/gui/trade.cpp @@ -214,8 +214,7 @@ void TradeWindow::receivedOk(bool own) void TradeWindow::tradeItem(Item *item, int quantity) { - MessageOut outMsg; - outMsg.writeShort(CMSG_TRADE_ITEM_ADD_REQUEST); + MessageOut outMsg(CMSG_TRADE_ITEM_ADD_REQUEST); outMsg.writeShort(item->getInvIndex()); outMsg.writeLong(quantity); } @@ -286,8 +285,7 @@ void TradeWindow::action(const std::string &eventId, gcn::Widget *widget) } else if (eventId == "cancel") { - MessageOut outMsg; - outMsg.writeShort(CMSG_TRADE_CANCEL_REQUEST); + MessageOut outMsg(CMSG_TRADE_CANCEL_REQUEST); } else if (eventId == "ok") { @@ -297,20 +295,17 @@ void TradeWindow::action(const std::string &eventId, gcn::Widget *widget) { mMoneyField->setText(toString(tempInt)); - MessageOut outMsg; - outMsg.writeShort(CMSG_TRADE_ITEM_ADD_REQUEST); + MessageOut outMsg(CMSG_TRADE_ITEM_ADD_REQUEST); outMsg.writeShort(0); outMsg.writeLong(tempInt); } else { mMoneyField->setText(""); } mMoneyField->setEnabled(false); - MessageOut outMsg; - outMsg.writeShort(CMSG_TRADE_ADD_COMPLETE); + MessageOut outMsg(CMSG_TRADE_ADD_COMPLETE); } else if (eventId == "trade") { - MessageOut outMsg; - outMsg.writeShort(CMSG_TRADE_OK); + MessageOut outMsg(CMSG_TRADE_OK); } } diff --git a/src/localplayer.cpp b/src/localplayer.cpp index 83884b6f..f157f04c 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -116,8 +116,7 @@ Item* LocalPlayer::getInvItem(int index) void LocalPlayer::equipItem(Item *item) { - MessageOut outMsg; - outMsg.writeShort(CMSG_PLAYER_EQUIP); + MessageOut outMsg(CMSG_PLAYER_EQUIP); outMsg.writeShort(item->getInvIndex()); outMsg.writeShort(0); } @@ -127,8 +126,7 @@ void LocalPlayer::unequipItem(Item *item) if (!item) return; - MessageOut outMsg; - outMsg.writeShort(CMSG_PLAYER_UNEQUIP); + MessageOut outMsg(CMSG_PLAYER_UNEQUIP); outMsg.writeShort(item->getInvIndex()); // Tidy equipment directly to avoid weapon still shown bug, by instance @@ -137,8 +135,7 @@ void LocalPlayer::unequipItem(Item *item) void LocalPlayer::useItem(Item *item) { - MessageOut outMsg; - outMsg.writeShort(CMSG_PLAYER_INVENTORY_USE); + MessageOut outMsg(CMSG_PLAYER_INVENTORY_USE); outMsg.writeShort(item->getInvIndex()); outMsg.writeLong(item->getId()); // Note: id is dest of item, usually player_node->account_ID ?? @@ -147,8 +144,7 @@ void LocalPlayer::useItem(Item *item) void LocalPlayer::dropItem(Item *item, int quantity) { // TODO: Fix wrong coordinates of drops, serverside? - MessageOut outMsg; - outMsg.writeShort(CMSG_PLAYER_INVENTORY_DROP); + MessageOut outMsg(CMSG_PLAYER_INVENTORY_DROP); outMsg.writeShort(item->getInvIndex()); outMsg.writeShort(quantity); } @@ -159,8 +155,7 @@ void LocalPlayer::pickUp(FloorItem *item) int dy = item->getY() - mY; if (dx * dx + dy * dy < 4) { - MessageOut outMsg; - outMsg.writeShort(CMSG_ITEM_PICKUP); + MessageOut outMsg(CMSG_ITEM_PICKUP); outMsg.writeLong(item->getId()); mPickUpTarget = NULL; } else { @@ -220,9 +215,8 @@ void LocalPlayer::walk(unsigned char dir) void LocalPlayer::setDestination(Uint16 x, Uint16 y) { char temp[3]; - MessageOut outMsg; + MessageOut outMsg(0x0085); set_coordinates(temp, x, y, mDirection); - outMsg.writeShort(0x0085); outMsg.writeString(temp, 3); mPickUpTarget = NULL; @@ -232,8 +226,7 @@ void LocalPlayer::setDestination(Uint16 x, Uint16 y) void LocalPlayer::raiseAttribute(Attribute attr) { - MessageOut outMsg; - outMsg.writeShort(CMSG_STAT_UPDATE_REQUEST); + MessageOut outMsg(CMSG_STAT_UPDATE_REQUEST); switch (attr) { @@ -269,8 +262,7 @@ void LocalPlayer::raiseSkill(Uint16 skillId) if (mSkillPoint <= 0) return; - MessageOut outMsg; - outMsg.writeShort(CMSG_SKILL_LEVELUP_REQUEST); + MessageOut outMsg(CMSG_SKILL_LEVELUP_REQUEST); outMsg.writeShort(skillId); } @@ -288,8 +280,7 @@ void LocalPlayer::toggleSit() default: return; } - MessageOut outMsg; - outMsg.writeShort(0x0089); + MessageOut outMsg(0x0089); outMsg.writeLong(0); outMsg.writeByte(type); } @@ -300,8 +291,7 @@ void LocalPlayer::emote(Uint8 emotion) return; mLastAction = tick_time; - MessageOut outMsg; - outMsg.writeShort(0x00bf); + MessageOut outMsg(0x00bf); outMsg.writeByte(emotion); } @@ -310,15 +300,13 @@ void LocalPlayer::tradeReply(bool accept) if (!accept) mTrading = false; - MessageOut outMsg; - outMsg.writeShort(CMSG_TRADE_RESPONSE); + MessageOut outMsg(CMSG_TRADE_RESPONSE); outMsg.writeByte(accept ? 3 : 4); } void LocalPlayer::trade(Being *being) const { - MessageOut outMsg; - outMsg.writeShort(CMSG_TRADE_REQUEST); + MessageOut outMsg(CMSG_TRADE_REQUEST); outMsg.writeLong(being->getId()); } @@ -369,8 +357,7 @@ void LocalPlayer::attack(Being *target, bool keep) else sound.playSfx("sfx/fist-swish.ogg"); - MessageOut outMsg; - outMsg.writeShort(0x0089); + MessageOut outMsg(0x0089); outMsg.writeLong(target->getId()); outMsg.writeByte(0); } @@ -387,7 +374,6 @@ Being* LocalPlayer::getTarget() const void LocalPlayer::revive() { - MessageOut outMsg; - outMsg.writeShort(0x00b2); + MessageOut outMsg(0x00b2); outMsg.writeByte(0); } diff --git a/src/net/messageout.cpp b/src/net/messageout.cpp index 4fca662a..4d68c14f 100644 --- a/src/net/messageout.cpp +++ b/src/net/messageout.cpp @@ -27,13 +27,6 @@ #include -MessageOut::MessageOut(): - mData(0), - mDataSize(0), - mPos(0) -{ -} - MessageOut::MessageOut(short id): mData(0), mDataSize(0), diff --git a/src/net/messageout.h b/src/net/messageout.h index 81369c0e..af25e4b4 100644 --- a/src/net/messageout.h +++ b/src/net/messageout.h @@ -32,11 +32,6 @@ class MessageOut { public: - /** - * Constructor. - */ - MessageOut(); - /** * Constructor. */ diff --git a/src/npc.cpp b/src/npc.cpp index a14b6d24..13025469 100644 --- a/src/npc.cpp +++ b/src/npc.cpp @@ -48,8 +48,7 @@ NPC::getType() const void NPC::talk() { - MessageOut outMsg; - outMsg.writeShort(CMSG_NPC_TALK); + MessageOut outMsg(CMSG_NPC_TALK); outMsg.writeLong(mId); outMsg.writeByte(0); current_npc = this; @@ -58,16 +57,14 @@ NPC::talk() void NPC::nextDialog() { - MessageOut outMsg; - outMsg.writeShort(CMSG_NPC_NEXT_REQUEST); + MessageOut outMsg(CMSG_NPC_NEXT_REQUEST); outMsg.writeLong(mId); } void NPC::dialogChoice(char choice) { - MessageOut outMsg; - outMsg.writeShort(CMSG_NPC_LIST_CHOICE); + MessageOut outMsg(CMSG_NPC_LIST_CHOICE); outMsg.writeLong(mId); outMsg.writeByte(choice); } @@ -79,8 +76,7 @@ NPC::dialogChoice(char choice) void NPC::buy() { - MessageOut outMsg; - outMsg.writeShort(CMSG_NPC_BUY_SELL_REQUEST); + MessageOut outMsg(CMSG_NPC_BUY_SELL_REQUEST); outMsg.writeLong(mId); outMsg.writeByte(0); } @@ -88,8 +84,7 @@ NPC::buy() void NPC::sell() { - MessageOut outMsg; - outMsg.writeShort(CMSG_NPC_BUY_SELL_REQUEST); + MessageOut outMsg(CMSG_NPC_BUY_SELL_REQUEST); outMsg.writeLong(mId); outMsg.writeByte(1); } -- cgit v1.2.3-70-g09d2 From 391203d83ed7a72b54fb7d7c72dbe35db14f0ea9 Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Mon, 28 Aug 2006 23:04:08 +0000 Subject: Merged trunk development between revisions 2530 and 2618 to the 0.1.0 branch. --- AUTHORS | 2 +- ChangeLog | 171 +++++++++++++++++++++++++++++++++++---- NEWS | 9 ++- README | 1 + configure.ac | 13 +-- data/graphics/Makefile.am | 2 +- data/graphics/images/Makefile.am | 1 + data/help/commands.txt | 1 + debian/control | 2 +- debian/tmw-data.install | 1 + src/Makefile.am | 1 + src/animatedsprite.cpp | 17 ++-- src/animation.cpp | 20 ++++- src/animation.h | 16 +++- src/engine.cpp | 104 +++++++++++++++++------- src/engine.h | 5 ++ src/floor_item.cpp | 5 +- src/floor_item.h | 1 + src/game.cpp | 29 ++++++- src/gui/char_select.cpp | 5 ++ src/gui/char_select.h | 5 ++ src/gui/chat.cpp | 2 +- src/gui/equipmentwindow.cpp | 9 +-- src/gui/equipmentwindow.h | 3 - src/gui/gui.cpp | 10 ++- src/gui/itemcontainer.cpp | 21 +++-- src/gui/itemcontainer.h | 2 - src/gui/ministatus.cpp | 42 ++++++++-- src/gui/ministatus.h | 10 ++- src/gui/setup.cpp | 4 +- src/gui/setup_joystick.cpp | 57 ++++++++++--- src/gui/setup_joystick.h | 6 +- src/gui/setup_video.cpp | 78 +++++++++++++++++- src/gui/setup_video.h | 16 ++++ src/gui/window.cpp | 21 +++++ src/gui/window.h | 20 +++++ src/joystick.cpp | 20 ++--- src/joystick.h | 39 ++++++--- src/main.cpp | 25 +++++- src/map.cpp | 113 +++++++++++++++++++++++++- src/map.h | 30 ++++++- src/net/inventoryhandler.cpp | 9 +++ src/player.cpp | 16 +++- src/player.h | 8 ++ src/resources/iteminfo.cpp | 44 ++++++++++ src/resources/iteminfo.h | 16 ++-- src/resources/itemmanager.cpp | 12 +-- src/resources/mapreader.cpp | 27 +++++++ tmw.cbp | 14 ++++ 49 files changed, 924 insertions(+), 161 deletions(-) create mode 100644 src/resources/iteminfo.cpp (limited to 'src/gui/char_select.cpp') diff --git a/AUTHORS b/AUTHORS index 2a0628cf..19d28884 100644 --- a/AUTHORS +++ b/AUTHORS @@ -25,7 +25,7 @@ The Mana World Dev Team Magick (music and sound effects) Neko-mon (player sprites, various things) Neorice (monster sprites, tiles) - Modanung (mohawk) + Modanung (pixel art, concept art) Pajarico (concepts) Rotonen (backstory, art director, music, sound) Talaroc (sprites) diff --git a/ChangeLog b/ChangeLog index fccfe4b8..5f20fdb0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,20 +4,19 @@ * src/net/beinghandler.cpp, src/net/protocol.h: Added support for entering monsters. -2006-08-27 Bjørn Lindeijer +2006-08-28 Philipp Sehmisch - * src/localplayer.cpp, src/gui/sell.cpp, src/gui/trade.cpp, - src/gui/char_select.cpp, src/gui/chat.cpp, src/gui/buy.cpp, - src/engine.cpp, src/beingmanager.cpp, src/npc.cpp, - src/net/messageout.cpp, src/net/messageout.h: Got rid of the default - MessageOut constructor, since all messages should have an ID. - * src/net/protocol.cpp, src/net/protocol.h, src/net/messagein.cpp, - src/net/playerhandler.cpp, src/Makefile.am: Got rid of no longer used - protocol.cpp. - * src/gui/login.cpp, src/gui/register.h, src/gui/login.h, - src/gui/register.cpp: Got rid of server input field since connecting - to the account server now happens before the login and register - dialogs. + * src/gui/setup_video.cpp: Modified the ranges of the ScrollLaziness + and ScrollRadius sliders. + +2006-08-28 Eugenio Favalli + + * data/graphics/items/*: Changed svn properties. + * data/graphics/sprites/item001.xml, data/graphics/sprites/item002.xml, + data/graphics/sprites/item003.xml, data/graphics/sprites/item004.xml, + data/graphics/sprites/item005.xml, data/graphics/sprites/item006.png, + data/graphics/sprites/item006.xml, data/graphics/sprites/Makefile.am: + Added headband and fixed svn properties. 2006-08-27 Guillaume Melquiond @@ -39,6 +38,35 @@ * src/engine.cpp, src/localplayer.cpp, src/gui/gui.cpp, src/being.cpp, src/being.h: Implemented pixel-grained movements. +2006-08-27 Bjørn Lindeijer + + * src/net/inventoryhandler.cpp: Applied patch by AHarrison that adds + item pickup messages to the chat window. + * NEWS: Updated with some recently added and fixed issues. Doesn't + mention any of the recent content updates yet. + * src/localplayer.cpp, src/gui/sell.cpp, src/gui/trade.cpp, + src/gui/char_select.cpp, src/gui/chat.cpp, src/gui/buy.cpp, + src/engine.cpp, src/beingmanager.cpp, src/npc.cpp, + src/net/messageout.cpp, src/net/messageout.h: Got rid of the default + MessageOut constructor, since all messages should have an ID. + * src/net/protocol.cpp, src/net/protocol.h, src/net/messagein.cpp, + src/net/playerhandler.cpp, src/Makefile.am: Got rid of no longer used + protocol.cpp. + * src/gui/login.cpp, src/gui/register.h, src/gui/login.h, + src/gui/register.cpp: Got rid of server input field since connecting + to the account server now happens before the login and register + dialogs. + +2006-08-26 Pascal Ganaye + + * src/joystick.h, src/joystick.cpp, src/gui/setup.cpp, + src/gui/setup_joystick.h, src/gui/setup_video.cpp, + src/gui/setup_joystick.cpp, src/gui/setup_video.h: Added sliders to + the video section of the setup window to configure the laziness and + radius of the scrolling behaviour. Added a checkbox to the joystick + section to allow enabling/disabling the joystick (patch applied by + Bjørn Lindeijer). + 2006-08-26 Bjørn Lindeijer * src/gui/char_select.cpp, src/gui/playerbox.cpp, src/player.cpp, @@ -49,6 +77,15 @@ defined as being bald (so bald is no longer a hardcoded style). * src/player.cpp, src/being.cpp, src/net/charserverhandler.cpp, src/being.h: Fixed player sprite not showing up. + * src/gui/ministatus.cpp, src/gui/ministatus.h: Applied patch by mrha + (Herbi), adding experience bar to the ministatus in the top left. + * configure.ac, data/graphics/items/Makefile.am, + data/graphics/Makefile.am: Added Makefile.am to make sure the item + icons are installed. + * src/player.cpp, src/animation.h, src/player.h, + src/animatedsprite.cpp, src/animation.cpp: Applied patch by Bahamut81 + which implements resetting of Animation, Action and AnimatedSprite. + This fixes the animation synchronization issues. 2006-08-26 Guillaume Melquiond @@ -68,10 +105,91 @@ * src/net/beinghandler.cpp, src/net/beinghandler.h, src/net/protocol.h: Added support for "beings move" messages. +2006-08-25 Matthias Hartmann + + * src/gui/char_select.cpp, src/gui/char_select.h, src/main.cpp: Added + --playername command line option for selecting the character you want + to play with (patch applied by Bjørn Lindeijer). + +2006-08-25 Philipp Sehmisch + + * src/engine.cpp, src/map.h, src/map.cpp: Addded new config variable + "OverlayDetail" to control the number of drawn overlays. + 2 (or more) = all (default), 1 = only the first one, 0 = none. + +2006-08-24 Eugenio Favalli + + * data/help/commands.txt, README, src/game.cpp, src/gui/chat.cpp, + src/gui/window.cpp, src/gui/window.h: Added support for sticky windows + as discussed with doener. Patch by AHarrison. + * data/items.xml: Added jeans shorts. + +2006-08-24 Philipp Sehmisch + + * src/engine.cpp: Scrolling speed no longer affected by framerate. + * src/map.cpp, scr/map.h: Overlay speed no longer affected by + framerate. + * data/maps/new_1-1.tmx.gz, data/graphics/new_7-1.tmx.gz, + data/graphics/images/ambient/sandstorm.png: Redone sandstorm effect + (larger and more transparent image, tripple layer parallax scrolling) + +2006-08-24 Frode Lindeijer + + * data/graphics/sprites/item004.png, + data/graphics/sprites/item005.png, data/graphics/sprites/Makefile.am, + data/graphics/items/armor-legs-cottonshorts, + data/graphics/items/armor-legs-jeanshorts: Added the equip graphics of + the short jeans and the cotton shorts and an inventory icon of the + cotton shorts. Also added all added files to the makefile. + +2006-08-23 Philipp Sehmisch + + * data/maps/new_7-1.tmx.gz: Fixed a minor mapping bug reported on the + forum (no new walkmap required). + * data/maps/new_9-1.tmx.gz: Fixed two minor mapping bugs (new walkmap + required). + +2006-08-22 Bjørn Lindeijer + + * configure.ac, data/graphics/images/ambient, + data/graphics/images/ambient/Makefile.am, + data/graphics/images/Makefile.am: Updated makefiles to account for new + ambient images and changed the version from 0.0.20.1 to 0.0.21. + 2006-08-21 Eugenio Favalli * The Mana World.dev, tmw.cbp: Updated project files. +2006-08-21 Philipp Sehmisch + + * src/mapreader.cpp: Added logic for initialisation of the overlays. + * src/map.cpp, src/map.h: Code for updating and drawing the overlays. + * src/engine.cpp, src/engine.h: Added smooth scrolling and the call + to draw the overlays. + * data/maps/new_1-1.tmx.gz, data/graphics/new_7-1.tmx.gz, + data/graphics/images/ambient/sandstorm.png: Added sandstorm effect + to the desert maps outside of the city (feedback, please). + * data/maps/new_2-1.tmx.gz, data/maps/new_4-1.tmx.gz, + data/maps/new_5-1.tmx.gz, data/graphics/images/ambient/spotlight.png + Added spotlight effect to the cave maps (feedback, please) + * data/graphics/maps/new_9-1.tmx.gz, + data/graphics/images/ambient/clouds.png: + Added cloudshadow effect to the woodland map (feedback, please). + +2006-08-20 Bjørn Lindeijer + + * configure.ac: Moved libpng check before SDL_image check, since the + latter requires the former. + +2006-08-20 Yohann Ferreira + + * data/graphics/sprites/Makefile.am : Following the splitting from + Philipp, moved out the items.png file from the Makefile.am. + * debian/control, debian/tmw-data.install : Updated debian package + creation process. + * src/Makefile.am : Added iteminfo.cpp to avoid an undefined reference + with gcc 4.1.2. Happy to be back :) + 2006-08-20 Bjørn Lindeijer * src/gui/connection.cpp, src/gui/login.cpp, src/gui/gui.cpp, @@ -111,6 +229,22 @@ * src/game.cpp, src/net/network.h, src/net/network.cpp: Removed incoming packets queue. Messages are now processed as they come in. +2006-08-17 Philipp Sehmisch + + * data/graphics/items/*: Splitted the items.png into separate images + with more distinctive names. (no, i won't list all 114) + * src/itemmanager.cpp, data/items.xml: Replaced indices on the item + spriteset with filenames. added names and descriptions for all missing + items. Changed names and dascriptions of some items. + * src/engine.cpp: removed global item spriteset. + * src/floor_item.cpp, src/floor_item.h, src/iteminfo.cpp, + src/iteminfo.h, src/equipmentwindow.cpp, src/equipmentwindow.h, + src/itemcontainer.cpp, src/itemcontainer.h: the iteminfo class now + provides a pointer to the item icon image instead of providing the + index on the item spriteset. + * data/graphics/tiles/trans_desert-woodland.png: added transmission + tileset between desert and woodland. + 2006-08-15 Bjørn Lindeijer * src/gui/char_select.cpp, src/net/charserverhandler.h, @@ -143,6 +277,15 @@ * src/player.cpp: Verify the gender to prevent crashing when something is wrong with the communication. +2006-08-13 Eugenio Favalli + + * data/graphics/sprites/Makefile.am, + data/graphics/sprites/monster18.png, + data/graphics/sprites/monster18.xml, + data/graphics/sprites/npcs.png: Added new monster and npcs. + * src/gui.cpp, tmw.cbp, The Mana World.dev: Fixed Guichan 0.5.0 + compilation issues. + 2006-08-13 Bjørn Lindeijer * src/openglgraphics.cpp, src/gui/browserbox.h, src/gui/gui.cpp, @@ -672,7 +815,7 @@ * data/items.xml, src/being.cpp, src/being.h src/net/beinghandler.cpp, src/player.cpp: Clients get notified of equipping visible items. * src/net/beinghandler.cpp: GCC 4 fix. - + 2006-06-28 Philipp Sehmisch * src/animation.cpp, src/animation.h: Parser now works like described diff --git a/NEWS b/NEWS index ad78fc4f..cf837a25 100644 --- a/NEWS +++ b/NEWS @@ -1,5 +1,12 @@ -0.0.20.1 (25 July 2006) +0.0.21 (.. September 2006) +- Added item pickup messages to the chat dialog +- Added XP bar to ministatus in the top left +- Added configurable smooth and lazy scrolling +- Added option to turn off the joystick +- Added --playername command line option for automatic character picking - Fixed updating system on Windows +- Fixed player animations going out of sync on changing equipment or hairstyle +- Fixed SDL_image configure check on some systems by first checking for libpng 0.0.20 (24 July 2006) - Added new hairstyle, and some fixes to the old ones diff --git a/README b/README index 8fdd2b72..5fad4312 100644 --- a/README +++ b/README @@ -53,6 +53,7 @@ Use arrow keys to move around. Other keys: - Alt + S sit down / stand up - Alt + F toggle debug pathfinding feature - Alt + P take screenshot +- H hide all non-sticky windows - G or Z pick up item - Enter focus chat window / send message - Shift hold it when attacking to lock target for auto attack diff --git a/configure.ac b/configure.ac index 4c5a492a..ce4c6cc5 100755 --- a/configure.ac +++ b/configure.ac @@ -70,8 +70,12 @@ AC_MSG_ERROR([ *** Unable to find libxml2 library (http://xmlsoft.org/)])) AC_CHECK_HEADERS([libxml/xmlreader.h], , AC_MSG_ERROR([ *** libxml2 library found but cannot find headers (http://xmlsoft.org/)])) -AC_CHECK_LIB([SDL_image], [IMG_LoadPNG_RW], , -AC_MSG_ERROR([ *** Unable to find SDL_image library with PNG support (http://www.libsdl.org/projects/SDL_image/)])) +AC_CHECK_LIB(png, png_write_info, , +AC_MSG_ERROR([ *** Unable to find png library])) + +AC_CHECK_LIB(SDL_image, IMG_LoadPNG_RW, , +AC_MSG_ERROR([ *** Unable to find SDL_image library with PNG support +(http://www.libsdl.org/projects/SDL_image/)])) AC_CHECK_LIB([guichan_sdl], [gcnSDL], , AC_MSG_ERROR([ *** Unable to find Guichan SDL library (http://guichan.sf.net/)])) @@ -82,9 +86,6 @@ AC_MSG_ERROR([ *** Unable to find SDL_mixer library (http://www.libsdl.org/proje AC_CHECK_LIB([enet], [enet_initialize], , AC_MSG_ERROR([ *** Unable to find enet library (http://enet.bespin.org/)])) -AC_CHECK_LIB(png, png_write_info, , -AC_MSG_ERROR([ *** Unable to find png library (http://www.libpng.org/)])) - # Checks for header files. AC_HEADER_STDC AC_CHECK_HEADERS([arpa/inet.h fcntl.h malloc.h netdb.h netinet/in.h stdlib.h string.h sys/socket.h unistd.h]) @@ -108,6 +109,8 @@ data/Makefile data/graphics/Makefile data/graphics/gui/Makefile data/graphics/images/Makefile +data/graphics/images/ambient/Makefile +data/graphics/items/Makefile data/graphics/sprites/Makefile data/graphics/tiles/Makefile data/help/Makefile diff --git a/data/graphics/Makefile.am b/data/graphics/Makefile.am index 43354894..19e95869 100644 --- a/data/graphics/Makefile.am +++ b/data/graphics/Makefile.am @@ -1,2 +1,2 @@ -SUBDIRS = gui images sprites tiles +SUBDIRS = gui images items sprites tiles diff --git a/data/graphics/images/Makefile.am b/data/graphics/images/Makefile.am index 8fbe3694..e0707698 100644 --- a/data/graphics/images/Makefile.am +++ b/data/graphics/images/Makefile.am @@ -1,3 +1,4 @@ +SUBDIRS = ambient imagesdir = $(pkgdatadir)/data/graphics/images diff --git a/data/help/commands.txt b/data/help/commands.txt index dbb37195..37c77df2 100644 --- a/data/help/commands.txt +++ b/data/help/commands.txt @@ -23,6 +23,7 @@ ##2Alt + S##P sit down / stand up ##2Alt + F##P toggle debug pathfinding feature ##2Alt + P##P take screenshot + ##2H##P hide all non-sticky windows ##2G or Z##P pick up item ##2Enter##P focus chat window / send message ##2Shift##P hold it when attacking to lock target for auto diff --git a/debian/control b/debian/control index ad079b7d..45a906b6 100644 --- a/debian/control +++ b/debian/control @@ -1,7 +1,7 @@ Source: tmw Priority: optional Maintainer: FERREIRA Yohann -Build-Depends: debhelper (>= 4.0.0), autotools-dev, docbook-to-man, libsdl1.2-dev (>= 1.2.7), libsdl-image1.2-dev (>= 1.2.3), libsdl-mixer1.2-dev (>= 1.2.5), libguichan0-dev (>= 0.4.0-4), libcurl3-gnutls-dev (>= 7.15.0-1), libxml2-dev (>= 2.4.19), libphysfs-dev (>= 1.0.0-1), libgl1-mesa-dev (>= 6.4.1), libpng12-dev (>= 1.2.5), libsdl-net1.2-dev (>= 1.2.5) +Build-Depends: debhelper (>= 4.0.0), autotools-dev, docbook-to-man, libsdl1.2-dev (>= 1.2.7), libsdl-image1.2-dev (>= 1.2.3), libsdl-mixer1.2-dev (>= 1.2.5), libguichan0-dev (>= 0.5.0-1), libcurl3-gnutls-dev (>= 7.15.0-1), libxml2-dev (>= 2.4.19), libphysfs-dev (>= 1.0.0-1), libgl1-mesa-dev (>= 6.4.1), libpng12-dev (>= 1.2.5), libsdl-net1.2-dev (>= 1.2.5) Standards-Version: 3.6.2 Package: tmw diff --git a/debian/tmw-data.install b/debian/tmw-data.install index 5e2e537e..71b34a98 100644 --- a/debian/tmw-data.install +++ b/debian/tmw-data.install @@ -2,6 +2,7 @@ data/items.xml usr/share/games/tmw/data data/help/*.txt usr/share/games/tmw/data/help data/graphics/gui/*.png usr/share/games/tmw/data/graphics/gui data/graphics/sprites/*.png usr/share/games/tmw/data/graphics/sprites +data/graphics/sprites/*.xml usr/share/games/tmw/data/graphics/sprites data/graphics/images/*.png usr/share/games/tmw/data/graphics/images data/graphics/tiles/*.png usr/share/games/tmw/data/graphics/tiles data/maps/*.tmx.gz usr/share/games/tmw/data/maps diff --git a/src/Makefile.am b/src/Makefile.am index aac3a8d3..1e8a1424 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -158,6 +158,7 @@ tmw_SOURCES = graphic/imagerect.h \ resources/imagewriter.cpp \ resources/imagewriter.h \ resources/iteminfo.h \ + resources/iteminfo.cpp \ resources/itemmanager.cpp \ resources/itemmanager.h \ resources/mapreader.cpp \ diff --git a/src/animatedsprite.cpp b/src/animatedsprite.cpp index 8f9c0600..f984d13f 100644 --- a/src/animatedsprite.cpp +++ b/src/animatedsprite.cpp @@ -49,12 +49,14 @@ AnimatedSprite::AnimatedSprite(const std::string& animationFile, int variant): free(data); if (!doc) { - logger->error("Animation: Error while parsing animation definition file!"); + logger->error( + "Animation: Error while parsing animation definition file!"); } xmlNodePtr node = xmlDocGetRootElement(doc); if (!node || !xmlStrEqual(node->name, BAD_CAST "sprite")) { - logger->error("Animation: this is not a valid animation definition file!"); + logger->error( + "Animation: this is not a valid animation definition file!"); } // Get the variant @@ -233,13 +235,14 @@ AnimatedSprite::~AnimatedSprite() void AnimatedSprite::reset() { - // Reset all defined actions (because of aliases, some will be resetted - // multiple times) + // Reset all defined actions (because of aliases some will be resetted + // multiple times, but this doesn't matter) for (ActionIterator i = mActions.begin(); i != mActions.end(); ++i) { - //TODO: If resetting everything is really a nice way of fixing the - // synchronization issues, finish implementing this. - //i->second->reset(); + if (i->second) + { + i->second->reset(); + } } } diff --git a/src/animation.cpp b/src/animation.cpp index 1213d0d6..c1b27ebd 100644 --- a/src/animation.cpp +++ b/src/animation.cpp @@ -27,9 +27,15 @@ #include "utils/dtor.h" -Animation::Animation(): - mTime(0) +Animation::Animation() { + reset(); +} + +void +Animation::reset() +{ + mTime = 0; iCurrentPhase = mAnimationPhases.begin(); } @@ -123,3 +129,13 @@ Action::setAnimation(int direction, Animation *animation) mAnimations[direction] = animation; } + +void +Action::reset() +{ + for (AnimationIterator i = mAnimations.begin(); + i != mAnimations.end(); ++i) + { + i->second->reset(); + } +} diff --git a/src/animation.h b/src/animation.h index c5b277b7..60dcd287 100644 --- a/src/animation.h +++ b/src/animation.h @@ -55,6 +55,12 @@ class Animation */ Animation(); + /** + * Restarts the animation from the first frame. + */ + void + reset(); + void addPhase(int image, unsigned int delay, int offsetX, int offsetY); @@ -68,13 +74,13 @@ class Animation * Returns the x offset of the current frame. */ int - getOffsetX() const { return (*iCurrentPhase).offsetX; }; + getOffsetX() const { return iCurrentPhase->offsetX; }; /** * Returns the y offset of the current frame. */ int - getOffsetY() const { return (*iCurrentPhase).offsetY; }; + getOffsetY() const { return iCurrentPhase->offsetY; }; /** * Returns the length of this animation. @@ -119,6 +125,12 @@ class Action void setAnimation(int direction, Animation *animation); + /** + * Resets all animations associated with this action. + */ + void + reset(); + Animation* getAnimation(int direction) const; diff --git a/src/engine.cpp b/src/engine.cpp index eda154f3..28410748 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -27,6 +27,7 @@ #include "being.h" #include "beingmanager.h" +#include "configuration.h" #include "flooritemmanager.h" #include "game.h" #include "graphics.h" @@ -54,7 +55,6 @@ int camera_x, camera_y; ItemManager *itemDb; /**< Item database object */ -Spriteset *itemset; Spriteset *emotionset; Spriteset *npcset; std::vector weaponset; @@ -79,11 +79,9 @@ Engine::Engine(): weaponset.push_back(tmp); } } - itemset = resman->getSpriteset("graphics/sprites/items.png", 32, 32); if (!npcset) logger->error("Unable to load NPC spriteset!"); if (!emotionset) logger->error("Unable to load emotions spriteset!"); - if (!itemset) logger->error("Unable to load item spriteset!"); // Initialize item manager itemDb = new ItemManager(); @@ -94,7 +92,6 @@ Engine::~Engine() // Delete sprite sets npcset->decRef(); emotionset->decRef(); - itemset->decRef(); std::for_each(weaponset.begin(), weaponset.end(), std::mem_fun(&Spriteset::decRef)); @@ -157,34 +154,85 @@ void Engine::draw(Graphics *graphics) { int midTileX = graphics->getWidth() / 2; int midTileY = graphics->getHeight() / 2; + static int lastTick = tick_time; - int map_x = (player_node->mX - midTileX) + player_node->getXOffset(); - int map_y = (player_node->mY - midTileY) + player_node->getYOffset(); + // Avoid freaking out when tick_time overflows + if (tick_time < lastTick) + { + lastTick = tick_time; + } + + int player_x = player_node->mX - midTileX + player_node->getXOffset(); + int player_y = player_node->mY - midTileY + player_node->getYOffset(); + + scrollLaziness = (int)config.getValue("ScrollLaziness", 32); + scrollRadius = (int)config.getValue("ScrollRadius", 32); + + if (scrollLaziness < 1) + scrollLaziness = 1; //avoids division by zero + + //apply lazy scrolling + while (lastTick < tick_time) + { + if (player_x > view_x + scrollRadius) + { + view_x += (player_x - view_x - scrollRadius) / scrollLaziness; + } + if (player_x < view_x - scrollRadius) + { + view_x += (player_x - view_x + scrollRadius) / scrollLaziness; + } + if (player_y > view_y + scrollRadius) + { + view_y += (player_y - view_y - scrollRadius) / scrollLaziness; + } + if (player_y < view_y - scrollRadius) + { + view_y += (player_y - view_y + scrollRadius) / scrollLaziness; + } + lastTick++; + } + + //auto center when player is off screen + if ( player_x - view_x > graphics->getWidth() / 2 + || view_x - player_x > graphics->getWidth() / 2 + || view_y - player_y > graphics->getHeight() / 2 + || player_y - view_y > graphics->getHeight() / 2 + ) + { + view_x = player_x; + view_y = player_y; + }; if (mCurrentMap) { - if (map_x < 0) { - map_x = 0; + if (view_x < 0) { + view_x = 0; } - if (map_y < 0) { - map_y = 0; + if (view_y < 0) { + view_y = 0; } - if (map_x > mCurrentMap->getWidth() * 32 - midTileX) { - map_x = mCurrentMap->getWidth() * 32 - midTileX; + if (view_x > mCurrentMap->getWidth() * 32 - midTileX) { + view_x = mCurrentMap->getWidth() * 32 - midTileX; } - if (map_y > mCurrentMap->getHeight() * 32 - midTileY) { - map_y = mCurrentMap->getHeight() * 32 - midTileY; + if (view_y > mCurrentMap->getHeight() * 32 - midTileY) { + view_y = mCurrentMap->getHeight() * 32 - midTileY; } } - camera_x = map_x; - camera_y = map_y; + camera_x = (int)(view_x + 16); + camera_y = (int)(view_y + 16); // Draw tiles and sprites if (mCurrentMap != NULL) { - mCurrentMap->draw(graphics, map_x, map_y, 0); - mCurrentMap->draw(graphics, map_x, map_y, 1); - mCurrentMap->draw(graphics, map_x, map_y, 2); + mCurrentMap->draw(graphics, (int)view_x, (int)view_y, 0); + mCurrentMap->draw(graphics, (int)view_x, (int)view_y, 1); + mCurrentMap->draw(graphics, (int)view_x, (int)view_y, 2); + mCurrentMap->drawOverlay( graphics, + view_x, + view_y, + (int)config.getValue("OverlayDetail", 2) + ); } else { @@ -202,8 +250,8 @@ void Engine::draw(Graphics *graphics) int mouseX, mouseY; SDL_GetMouseState(&mouseX, &mouseY); - int mouseTileX = (mouseX + map_x) / 32; - int mouseTileY = (mouseY + map_y) / 32; + int mouseTileX = (int)(mouseX + view_x) / 32; + int mouseTileY = (int)(mouseY + view_y) / 32; Path debugPath = mCurrentMap->findPath( player_node->mX / 32, player_node->mY / 32, @@ -212,8 +260,8 @@ void Engine::draw(Graphics *graphics) graphics->setColor(gcn::Color(255, 0, 0)); for (PathIterator i = debugPath.begin(); i != debugPath.end(); i++) { - int squareX = i->x * 32 - map_x + 12; - int squareY = i->y * 32 - map_y + 12; + int squareX = i->x * 32 - int(view_x) + 12; + int squareY = i->y * 32 - int(view_y) + 12; graphics->fillRectangle(gcn::Rectangle(squareX, squareY, 8, 8)); graphics->drawText( @@ -226,9 +274,9 @@ void Engine::draw(Graphics *graphics) Beings *beings = beingManager->getAll(); for (BeingIterator i = beings->begin(); i != beings->end(); i++) { - (*i)->drawSpeech(graphics, -map_x, -map_y); - (*i)->drawName(graphics, -map_x, -map_y); - (*i)->drawEmotion(graphics, -map_x, -map_y); + (*i)->drawSpeech(graphics, -(int)view_x, -(int)view_y); + (*i)->drawName(graphics, -(int)view_x, -(int)view_y); + (*i)->drawEmotion(graphics, -(int)view_x, -(int)view_y); } // Draw target marker if needed @@ -239,8 +287,8 @@ void Engine::draw(Graphics *graphics) graphics->setColor(gcn::Color(255, 255, 255)); int dy = (target->getType() == Being::PLAYER) ? 90 : 52; - graphics->drawText("[TARGET]", target->getPixelX() - map_x + 15, - target->getPixelY() - map_y - dy, gcn::Graphics::CENTER); + graphics->drawText("[TARGET]", target->getPixelX() - (int)view_x + 15, + target->getPixelY() - (int)view_y - dy, gcn::Graphics::CENTER); } gui->draw(); diff --git a/src/engine.h b/src/engine.h index bdf8419a..e8ef7e33 100644 --- a/src/engine.h +++ b/src/engine.h @@ -76,6 +76,11 @@ class Engine bool mShowDebugPath; Map *mCurrentMap; + + int scrollRadius; + int scrollLaziness; + float view_x; // current viewpoint in pixels + float view_y; // current viewpoint in pixels }; extern Engine *engine; diff --git a/src/floor_item.cpp b/src/floor_item.cpp index 1581b201..edd5d4a7 100644 --- a/src/floor_item.cpp +++ b/src/floor_item.cpp @@ -29,7 +29,6 @@ #include "resources/iteminfo.h" #include "resources/spriteset.h" -extern Spriteset *itemset; FloorItem::FloorItem(unsigned int id, unsigned int itemId, @@ -42,8 +41,8 @@ FloorItem::FloorItem(unsigned int id, mY(y), mMap(map) { - // Retrieve item image using a global itemset and itemDb (alternative?) - mImage = itemset->get(itemDb->getItemInfo(itemId)->getImage() - 1); + // Retrieve item image from item info + mImage = itemDb->getItemInfo(itemId)->getImage(); // Add ourselves to the map mSpriteIterator = mMap->addSprite(this); diff --git a/src/floor_item.h b/src/floor_item.h index 24eb495d..386d0759 100644 --- a/src/floor_item.h +++ b/src/floor_item.h @@ -27,6 +27,7 @@ #include "graphics.h" #include "map.h" #include "sprite.h" +#include "resources/image.h" /** * An item lying on the floor. diff --git a/src/game.cpp b/src/game.cpp index 3e789728..f5ebe095 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -202,6 +202,10 @@ void createGuiWindows() minimap->getHeight() + 30);*/ // Set initial window visibility + chatWindow->setSticky(true); + miniStatusWindow->setSticky(true); + menuWindow->setSticky(true); + chatWindow->setVisible(true); miniStatusWindow->setVisible(true); statusWindow->setVisible(false); @@ -457,7 +461,30 @@ void Game::handleInput() } break; - // Picking up items on the floor + // Attempt to hide all windows + case SDLK_h: + chatWindow->setVisible(false); + miniStatusWindow->setVisible(false); + statusWindow->setVisible(false); + menuWindow->setVisible(false); + buyDialog->setVisible(false); + sellDialog->setVisible(false); + buySellDialog->setVisible(false); + inventoryWindow->setVisible(false); + npcTextDialog->setVisible(false); + npcListDialog->setVisible(false); + skillDialog->setVisible(false); + //newSkillWindow->setVisible(false); + setupWindow->setVisible(false); + equipmentWindow->setVisible(false); + chargeDialog->setVisible(false); + tradeWindow->setVisible(false); + //buddyWindow->setVisible(false); + helpWindow->setVisible(false); + debugWindow->setVisible(false); + break; + + // Picking up items on the floor case SDLK_g: case SDLK_z: if (!chatWindow->isFocused()) diff --git a/src/gui/char_select.cpp b/src/gui/char_select.cpp index adcbe290..042a5be8 100644 --- a/src/gui/char_select.cpp +++ b/src/gui/char_select.cpp @@ -224,6 +224,11 @@ void CharSelectDialog::logic() updatePlayerInfo(); } +std::string CharSelectDialog::getName() +{ + return mNameLabel->getCaption(); +} + CharCreateDialog::CharCreateDialog(Window *parent, int slot): Window("Create Character", true, parent), mSlot(slot) { diff --git a/src/gui/char_select.h b/src/gui/char_select.h index 73fc8b2d..06881bb5 100644 --- a/src/gui/char_select.h +++ b/src/gui/char_select.h @@ -54,6 +54,11 @@ class CharSelectDialog : public Window, public gcn::ActionListener void logic(); + /** + * Returns name of selected player + */ + std::string getName(); + private: LockedArray *mCharInfo; diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp index 9098f9f0..9a5d60b0 100644 --- a/src/gui/chat.cpp +++ b/src/gui/chat.cpp @@ -395,7 +395,7 @@ ChatWindow::setInputText(std::string input_str) void ChatWindow::setVisible(bool isVisible) { - Widget::setVisible(isVisible); + Window::setVisible(isVisible); /* * For whatever reason, if setVisible is called, the mTmpVisible effect diff --git a/src/gui/equipmentwindow.cpp b/src/gui/equipmentwindow.cpp index bef39dff..2cbffde4 100644 --- a/src/gui/equipmentwindow.cpp +++ b/src/gui/equipmentwindow.cpp @@ -40,15 +40,10 @@ EquipmentWindow::EquipmentWindow(Equipment *equipment): setWindowName("Equipment"); setDefaultSize(5, 230, 200, 120); loadWindowState(); - - mItemset = ResourceManager::getInstance()->getSpriteset( - "graphics/sprites/items.png", 32, 32); - if (!mItemset) logger->error("Unable to load items.png"); } EquipmentWindow::~EquipmentWindow() { - mItemset->decRef(); } void EquipmentWindow::draw(gcn::Graphics *graphics) @@ -70,7 +65,7 @@ void EquipmentWindow::draw(gcn::Graphics *graphics) continue; } - image = mItemset->get(item->getInfo()->getImage() - 1); + image = item->getInfo()->getImage(); dynamic_cast(graphics)->drawImage( image, 36 * (i % 4) + 10, 36 * (i / 4) + 25); } @@ -81,7 +76,7 @@ void EquipmentWindow::draw(gcn::Graphics *graphics) return; } - image = mItemset->get(item->getInfo()->getImage() - 1); + image = item->getInfo()->getImage(); dynamic_cast(graphics)->drawImage(image, 160, 25); graphics->drawText(toString(item->getQuantity()), 170, 62, diff --git a/src/gui/equipmentwindow.h b/src/gui/equipmentwindow.h index aeaae58c..99a3cc60 100644 --- a/src/gui/equipmentwindow.h +++ b/src/gui/equipmentwindow.h @@ -27,7 +27,6 @@ #include "window.h" class Equipment; -class Spriteset; /** * Equipment dialog. @@ -53,8 +52,6 @@ class EquipmentWindow : public Window void draw(gcn::Graphics *graphics); private: - Spriteset *mItemset; - Equipment *mEquipment; }; diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index 69563dc1..b27868e3 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -27,11 +27,13 @@ #include #include - -// Moved up because of nested inclusion of winnt.h which defines DELETE -// constant as well as guichan does +// Should stay here because of Guichan being sensitive to headers order #include +#ifdef USE_OPENGL +#include "../resources/openglsdlimageloader.h" +#endif + #include "focushandler.h" #include "popupmenu.h" #include "window.h" @@ -231,6 +233,7 @@ Gui::draw() void Gui::mousePress(int mx, int my, int button) { + printf("Gui::mousePress(%d,%d)\n", mx, my); // Mouse pressed on window container (basically, the map) // Are we in-game yet? @@ -247,6 +250,7 @@ Gui::mousePress(int mx, int my, int button) int tilex = (mx + camera_x) / 32; int tiley = (my + camera_y) / 32; + printf("tilex,tiley: %d,%d\n", tilex, tiley); // Right click might open a popup if (button == gcn::MouseInput::RIGHT) diff --git a/src/gui/itemcontainer.cpp b/src/gui/itemcontainer.cpp index edcf9764..c7c55fd9 100644 --- a/src/gui/itemcontainer.cpp +++ b/src/gui/itemcontainer.cpp @@ -41,8 +41,6 @@ ItemContainer::ItemContainer(Inventory *inventory): mInventory(inventory) { ResourceManager *resman = ResourceManager::getInstance(); - mItemset = resman->getSpriteset("graphics/sprites/items.png", 32, 32); - if (!mItemset) logger->error("Unable to load items.png"); mSelImg = resman->getImage("graphics/gui/selection.png"); if (!mSelImg) logger->error("Unable to load selection.png"); @@ -55,7 +53,6 @@ ItemContainer::ItemContainer(Inventory *inventory): ItemContainer::~ItemContainer() { - mItemset->decRef(); mSelImg->decRef(); } @@ -73,8 +70,8 @@ void ItemContainer::logic() void ItemContainer::draw(gcn::Graphics* graphics) { - int gridWidth = mItemset->get(0)->getWidth() + 4; - int gridHeight = mItemset->get(0)->getHeight() + 10; + int gridWidth = 36; //(item icon width + 4) + int gridHeight = 42; //(item icon height + 10) int columns = getWidth() / gridWidth; // Have at least 1 column @@ -113,11 +110,11 @@ void ItemContainer::draw(gcn::Graphics* graphics) } // Draw item icon - int idx; - if ((idx = item->getInfo()->getImage()) > 0) + Image* image; + if ((image = item->getInfo()->getImage()) != NULL) { dynamic_cast(graphics)->drawImage( - mItemset->get(idx - 1), itemX, itemY); + image, itemX, itemY); } // Draw item caption @@ -133,8 +130,8 @@ void ItemContainer::setWidth(int width) { gcn::Widget::setWidth(width); - int gridWidth = mItemset->get(0)->getWidth() + 4; - int gridHeight = mItemset->get(0)->getHeight() + 14; + int gridWidth = 36; //item icon width + 4 + int gridHeight = 46; //item icon height + 14 int columns = getWidth() / gridWidth; if (columns < 1) @@ -158,8 +155,8 @@ void ItemContainer::selectNone() void ItemContainer::mousePress(int mx, int my, int button) { - int gridWidth = mItemset->get(0)->getWidth() + 4; - int gridHeight = mItemset->get(0)->getHeight() + 10; + int gridWidth = 36; //(item icon width + 4) + int gridHeight = 42; //(item icon height + 10) int columns = getWidth() / gridWidth; if (button == gcn::MouseInput::LEFT || gcn::MouseInput::RIGHT) diff --git a/src/gui/itemcontainer.h b/src/gui/itemcontainer.h index 63e8bf47..f52f37ec 100644 --- a/src/gui/itemcontainer.h +++ b/src/gui/itemcontainer.h @@ -30,7 +30,6 @@ class Image; class Inventory; class Item; -class Spriteset; /** * An item container. Used to show items in inventory and trade dialog. @@ -83,7 +82,6 @@ class ItemContainer : public gcn::Widget, public gcn::MouseListener private: Inventory *mInventory; - Spriteset *mItemset; Image *mSelImg; Item *mSelectedItem; diff --git a/src/gui/ministatus.cpp b/src/gui/ministatus.cpp index 53849550..932b1f22 100644 --- a/src/gui/ministatus.cpp +++ b/src/gui/ministatus.cpp @@ -29,6 +29,8 @@ #include "progressbar.h" #include "../localplayer.h" +#include "../configuration.h" +#include "../graphics.h" #include "../utils/tostring.h" @@ -42,31 +44,40 @@ MiniStatusWindow::MiniStatusWindow(): mHpBar = new ProgressBar(1.0f, 100, 20, 0, 171, 34); mMpBar = new ProgressBar(1.0f, 100, 20, 26, 102, 230); + mXpBar = new ProgressBar(1.0f, 100, 20, 143, 192, 211); mHpLabel = new gcn::Label(""); mMpLabel = new gcn::Label(""); + mXpLabel = new gcn::Label(""); mHpBar->setPosition(0, 3); mMpBar->setPosition(mHpBar->getWidth() + 3, 3); + mXpBar->setPosition(mMpBar->getX() + mMpBar->getWidth() + 3, 3); mHpLabel->setDimension(mHpBar->getDimension()); mMpLabel->setDimension(mMpBar->getDimension()); + mXpLabel->setDimension(mXpBar->getDimension()); mHpLabel->setForegroundColor(gcn::Color(255, 255, 255)); mMpLabel->setForegroundColor(gcn::Color(255, 255, 255)); + mXpLabel->setForegroundColor(gcn::Color(255, 255, 255)); mHpLabel->setFont(speechFont); mMpLabel->setFont(speechFont); + mXpLabel->setFont(speechFont); mHpLabel->setAlignment(gcn::Graphics::CENTER); mMpLabel->setAlignment(gcn::Graphics::CENTER); + mXpLabel->setAlignment(gcn::Graphics::CENTER); add(mHpBar); add(mMpBar); + add(mXpBar); add(mHpLabel); add(mMpLabel); + add(mXpLabel); - setDefaultSize(0, 0, mMpBar->getX() + mMpBar->getWidth(), - mMpBar->getY() + mMpBar->getHeight()); + setDefaultSize(0, 0, mXpBar->getX() + mXpBar->getWidth(), + mXpBar->getY() + mXpBar->getHeight()); } void MiniStatusWindow::update() @@ -85,12 +96,33 @@ void MiniStatusWindow::update() mHpBar->setColor(0, 171, 34); // Green } - mHpBar->setProgress((float)player_node->mHp / (float)player_node->mMaxHp); - // mpBar->setProgress((float)player_node->mp / (float)player_node->maxMp); + mHpBar->setProgress((float) player_node->mHp / player_node->mMaxHp); + // mMpBar->setProgress((float) player_node->mMp / player_node->mMaxMp); + mXpBar->setProgress((float) player_node->mXp / player_node->mXpForNextLevel); - // Update and center labels + // Update labels mHpLabel->setCaption(toString(player_node->mHp)); mMpLabel->setCaption(toString(player_node->mMp)); + + std::stringstream updatedText; + updatedText << (int) ( + (float) player_node->mXp / + player_node->mXpForNextLevel * 100) << "%"; + + // Displays the number of monsters to next lvl + // (disabled for now but interesting idea) + /* + if(config.getValue("xpBarMonsterCounterExp", 0)!=0) + { + updatedText << " | " + << (int)(((float)player_node->mXpForNextLevel - (float)player_node->mXp) + / (float)config.getValue("xpBarMonsterCounterExp", 0)) + << " " + << config.getValue("xpBarMonsterCounterName", "Monsters") <<" left..."; + } + */ + + mXpLabel->setCaption(updatedText.str()); } void MiniStatusWindow::draw(gcn::Graphics *graphics) diff --git a/src/gui/ministatus.h b/src/gui/ministatus.h index f56f847c..718fe140 100644 --- a/src/gui/ministatus.h +++ b/src/gui/ministatus.h @@ -56,11 +56,15 @@ class MiniStatusWindow : public Window */ void update(); - /** + /* * Mini Status Bars */ - ProgressBar *mHpBar, *mMpBar; - gcn::Label *mHpLabel, *mMpLabel; + ProgressBar *mHpBar; + ProgressBar *mMpBar; + ProgressBar *mXpBar; + gcn::Label *mHpLabel; + gcn::Label *mMpLabel; + gcn::Label *mXpLabel; }; #endif diff --git a/src/gui/setup.cpp b/src/gui/setup.cpp index 6af9119b..d12ace75 100644 --- a/src/gui/setup.cpp +++ b/src/gui/setup.cpp @@ -43,7 +43,7 @@ Setup::Setup(): Window("Setup") { int width = 230; - int height = 185; + int height = 225; setContentSize(width, height); const char *buttonNames[] = { @@ -58,7 +58,7 @@ Setup::Setup(): } TabbedContainer *panel = new TabbedContainer(); - panel->setDimension(gcn::Rectangle(5, 5, 220, 150)); + panel->setDimension(gcn::Rectangle(5, 5, 220, 185)); panel->setOpaque(false); SetupTab *tab; diff --git a/src/gui/setup_joystick.cpp b/src/gui/setup_joystick.cpp index 36b0ee20..d9212728 100644 --- a/src/gui/setup_joystick.cpp +++ b/src/gui/setup_joystick.cpp @@ -26,22 +26,31 @@ #include #include "button.h" - +#include "checkbox.h" +#include "../configuration.h" #include "../joystick.h" extern Joystick *joystick; Setup_Joystick::Setup_Joystick(): mCalibrateLabel(new gcn::Label("Press the button to start calibration")), - mCalibrateButton(new Button("Calibrate", "calibrate", this)) + mCalibrateButton(new Button("Calibrate", "calibrate", this)), + mJoystickEnabled(new CheckBox("Enable joystick")) { setOpaque(false); + mJoystickEnabled->setPosition(10, 10); + mCalibrateLabel->setPosition(10, 25); + mCalibrateButton->setPosition(10, 30 + mCalibrateLabel->getHeight()); + + mOriginalJoystickEnabled = (joystick ? joystick->isEnabled() : false); + mJoystickEnabled->setMarked(mOriginalJoystickEnabled); - mCalibrateLabel->setPosition(5, 10); - mCalibrateButton->setPosition(10, 20 + mCalibrateLabel->getHeight()); + mJoystickEnabled->setEventId("joystickEnabled"); + mJoystickEnabled->addActionListener(this); add(mCalibrateLabel); add(mCalibrateButton); + add(mJoystickEnabled); } void Setup_Joystick::action(const std::string &event, gcn::Widget *widget) @@ -50,13 +59,37 @@ void Setup_Joystick::action(const std::string &event, gcn::Widget *widget) return; } - if (joystick->isCalibrating()) { - mCalibrateButton->setCaption("Calibrate"); - mCalibrateLabel->setCaption("Press the button to start calibration"); - joystick->finishCalibration(); - } else { - mCalibrateButton->setCaption("Stop"); - mCalibrateLabel->setCaption("Rotate the stick"); - joystick->startCalibration(); + if (event == "joystickEnabled") + { + joystick->setEnabled(mJoystickEnabled->isMarked()); + } + else + { + if (joystick->isCalibrating()) { + mCalibrateButton->setCaption("Calibrate"); + mCalibrateLabel->setCaption( + "Press the button to start calibration"); + joystick->finishCalibration(); + } else { + mCalibrateButton->setCaption("Stop"); + mCalibrateLabel->setCaption("Rotate the stick"); + joystick->startCalibration(); + } } } + +void Setup_Joystick::cancel() +{ + if (joystick) + { + joystick->setEnabled(mOriginalJoystickEnabled); + } + mJoystickEnabled->setMarked(mOriginalJoystickEnabled); +} + +void Setup_Joystick::apply() +{ + config.setValue("joystickEnabled", + joystick ? joystick->isEnabled() : false); +} + diff --git a/src/gui/setup_joystick.h b/src/gui/setup_joystick.h index da773c8f..4cc2b3d9 100644 --- a/src/gui/setup_joystick.h +++ b/src/gui/setup_joystick.h @@ -35,14 +35,16 @@ class Setup_Joystick : public SetupTab, public gcn::ActionListener public: Setup_Joystick(); - void apply() {} - void cancel() {} + void apply(); + void cancel(); void action(const std::string& eventId, gcn::Widget* widget); private: gcn::Label *mCalibrateLabel; gcn::Button *mCalibrateButton; + bool mOriginalJoystickEnabled; + gcn::CheckBox *mJoystickEnabled; }; #endif diff --git a/src/gui/setup_video.cpp b/src/gui/setup_video.cpp index 7ac226d3..7c72975a 100644 --- a/src/gui/setup_video.cpp +++ b/src/gui/setup_video.cpp @@ -115,7 +115,13 @@ Setup_Video::Setup_Video(): mAlphaSlider(new Slider(0.2, 1.0)), mFpsCheckBox(new CheckBox("FPS Limit: ")), mFpsSlider(new Slider(10, 200)), - mFpsField(new TextField()) + mFpsField(new TextField()), + mOriginalScrollLaziness((int) config.getValue("ScrollLaziness", 32)), + mScrollLazinessSlider(new Slider(1, 64)), + mScrollLazinessField(new TextField()), + mOriginalScrollRadius((int) config.getValue("ScrollRadius", 32)), + mScrollRadiusSlider(new Slider(0, 128)), + mScrollRadiusField(new TextField()) { setOpaque(false); @@ -153,12 +159,36 @@ Setup_Video::Setup_Video(): mAlphaSlider->setEventId("guialpha"); mFpsCheckBox->setEventId("fpslimitcheckbox"); mFpsSlider->setEventId("fpslimitslider"); + mScrollRadiusSlider->setEventId("scrollradiusslider"); + mScrollRadiusField->setEventId("scrollradiusfield"); + mScrollLazinessSlider->setEventId("scrolllazinessslider"); + mScrollLazinessField->setEventId("scrolllazinessfield"); mCustomCursorCheckBox->addActionListener(this); mAlphaSlider->addActionListener(this); mFpsCheckBox->addActionListener(this); mFpsSlider->addActionListener(this); mFpsField->addKeyListener(this); + mScrollRadiusSlider->addActionListener(this); + mScrollRadiusField->addKeyListener(this); + mScrollLazinessSlider->addActionListener(this); + mScrollLazinessField->addKeyListener(this); + + mScrollRadiusSlider->setDimension(gcn::Rectangle(10, 120, 75, 10)); + gcn::Label *scrollRadiusLabel = new gcn::Label("Scroll radius"); + scrollRadiusLabel->setPosition(90, 120); + mScrollRadiusField->setPosition(180, 120); + mScrollRadiusField->setWidth(30); + mScrollRadiusField->setText(toString(mOriginalScrollRadius)); + mScrollRadiusSlider->setValue(mOriginalScrollRadius); + + mScrollLazinessSlider->setDimension(gcn::Rectangle(10, 140, 75, 10)); + gcn::Label *scrollLazinessLabel = new gcn::Label("Scroll laziness"); + scrollLazinessLabel->setPosition(90, 140); + mScrollLazinessField->setPosition(180, 140); + mScrollLazinessField->setWidth(30); + mScrollLazinessField->setText(toString(mOriginalScrollLaziness)); + mScrollLazinessSlider->setValue(mOriginalScrollLaziness); add(scrollArea); add(mFsCheckBox); @@ -169,6 +199,12 @@ Setup_Video::Setup_Video(): add(mFpsCheckBox); add(mFpsSlider); add(mFpsField); + add(mScrollRadiusSlider); + add(scrollRadiusLabel); + add(mScrollRadiusField); + add(mScrollLazinessSlider); + add(scrollLazinessLabel); + add(mScrollLazinessField); } Setup_Video::~Setup_Video() @@ -225,6 +261,27 @@ void Setup_Video::apply() mOpenGLEnabled = config.getValue("opengl", 0); } +int +Setup_Video::updateSlider(gcn::Slider *slider, gcn::TextField *field, + const std::string &configName) +{ + int value; + std::stringstream temp(field->getText()); + temp >> value; + if (value < slider->getScaleStart()) + { + value = (int) slider->getScaleStart(); + } + else if (value > slider->getScaleEnd()) + { + value = (int) slider->getScaleEnd(); + } + field->setText(toString(value)); + slider->setValue(value); + config.setValue(configName, value); + return value; +} + void Setup_Video::cancel() { mFsCheckBox->setMarked(mFullScreenEnabled); @@ -232,6 +289,11 @@ void Setup_Video::cancel() mCustomCursorCheckBox->setMarked(mCustomCursorEnabled); mAlphaSlider->setValue(mOpacity); + mScrollRadiusField->setText(toString(mOriginalScrollRadius)); + mScrollLazinessField->setText(toString(mOriginalScrollLaziness)); + updateSlider(mScrollRadiusSlider, mScrollRadiusField, "ScrollRadius"); + updateSlider(mScrollLazinessSlider, mScrollLazinessField, "ScrollLaziness"); + config.setValue("screen", mFullScreenEnabled ? 1 : 0); config.setValue("customcursor", mCustomCursorEnabled ? 1 : 0); config.setValue("guialpha", mOpacity); @@ -254,6 +316,18 @@ void Setup_Video::action(const std::string &event, gcn::Widget *widget) mFps = (int)mFpsSlider->getValue(); mFpsField->setText(toString(mFps)); } + else if (event == "scrollradiusslider") + { + int val = (int)mScrollRadiusSlider->getValue(); + mScrollRadiusField->setText(toString(val)); + config.setValue("ScrollRadius", val); + } + else if (event == "scrolllazinessslider") + { + int val = (int)mScrollLazinessSlider->getValue(); + mScrollLazinessField->setText(toString(val)); + config.setValue("ScrollLaziness", val); + } else if (event == "fpslimitcheckbox") { if (mFpsCheckBox->isMarked()) @@ -293,4 +367,6 @@ void Setup_Video::keyPress(const gcn::Key &key) mFpsField->setText(""); mFps = 0; } + updateSlider(mScrollRadiusSlider, mScrollRadiusField, "ScrollRadius"); + updateSlider(mScrollLazinessSlider, mScrollLazinessField, "ScrollLaziness"); } diff --git a/src/gui/setup_video.h b/src/gui/setup_video.h index d0a10925..a3fd8884 100644 --- a/src/gui/setup_video.h +++ b/src/gui/setup_video.h @@ -59,10 +59,26 @@ class Setup_Video : public SetupTab, public gcn::ActionListener, gcn::CheckBox *mFsCheckBox; gcn::CheckBox *mOpenGLCheckBox; gcn::CheckBox *mCustomCursorCheckBox; + gcn::Slider *mAlphaSlider; gcn::CheckBox *mFpsCheckBox; gcn::Slider *mFpsSlider; gcn::TextField *mFpsField; + + int mOriginalScrollLaziness; + gcn::Slider *mScrollLazinessSlider; + gcn::TextField *mScrollLazinessField; + + int mOriginalScrollRadius; + gcn::Slider *mScrollRadiusSlider; + gcn::TextField *mScrollRadiusField; + + void + updateSliders(bool originalValues); + + int + updateSlider(gcn::Slider *slider, gcn::TextField *field, + const std::string &configName); }; #endif diff --git a/src/gui/window.cpp b/src/gui/window.cpp index 9a07111f..2172baa8 100644 --- a/src/gui/window.cpp +++ b/src/gui/window.cpp @@ -63,6 +63,7 @@ Window::Window(const std::string& caption, bool modal, Window *parent): mModal(modal), mResizable(false), mMouseResize(false), + mSticky(false), mMinWinWidth(100), mMinWinHeight(28), mMaxWinWidth(INT_MAX), @@ -243,6 +244,26 @@ bool Window::isResizable() return mResizable; } +void Window::setSticky(bool sticky) +{ + mSticky = sticky; +} + +bool Window::isSticky() { + return mSticky; +} + +void Window::setVisible(bool visible) { + if(isSticky()) + { + gcn::Window::setVisible(true); + } + else + { + gcn::Window::setVisible(visible); + } +} + void Window::scheduleDelete() { windowContainer->scheduleDelete(this); diff --git a/src/gui/window.h b/src/gui/window.h index 42ce444c..51c876e3 100644 --- a/src/gui/window.h +++ b/src/gui/window.h @@ -133,6 +133,25 @@ class Window : public gcn::Window */ void setMaxHeight(unsigned int height); + /** + * Sets whether the window is sticky. + * A sticky window will not have its visibility set to false + * on a general setVisible(false) call. + */ + void setSticky(bool sticky); + + /** + * Returns whether the window is sticky. + */ + bool isSticky(); + + /** + * Overloads window setVisible by guichan to allow sticky window + * Handling + */ + + void setVisible(bool visible); + /** * Returns the parent window. * @@ -204,6 +223,7 @@ class Window : public gcn::Window bool mModal; /**< Window is modal */ bool mResizable; /**< Window can be resized */ bool mMouseResize; /**< Window is being resized */ + bool mSticky; /**< Window resists minimzation */ int mMinWinWidth; /**< Minimum window width */ int mMinWinHeight; /**< Minimum window height */ int mMaxWinWidth; /**< Maximum window width */ diff --git a/src/joystick.cpp b/src/joystick.cpp index bb6e887b..a5dab4f4 100644 --- a/src/joystick.cpp +++ b/src/joystick.cpp @@ -59,10 +59,11 @@ Joystick::Joystick(int no): logger->log("Hats: %i", SDL_JoystickNumHats(mJoystick)); logger->log("Buttons: %i", SDL_JoystickNumButtons(mJoystick)); - mUpTolerance = (int)config.getValue("upTolerance", 100); - mDownTolerance = (int)config.getValue("downTolerance", 100); - mLeftTolerance = (int)config.getValue("leftTolerance", 100); - mRightTolerance = (int)config.getValue("rightTolerance", 100); + mEnabled = (int) config.getValue("joystickEnabled", 0) != 0; + mUpTolerance = (int) config.getValue("upTolerance", 100); + mDownTolerance = (int) config.getValue("downTolerance", 100); + mLeftTolerance = (int) config.getValue("leftTolerance", 100); + mRightTolerance = (int) config.getValue("rightTolerance", 100); } Joystick::~Joystick() @@ -73,6 +74,7 @@ Joystick::~Joystick() void Joystick::update() { mDirection = 0; + SDL_JoystickUpdate(); // When calibrating, don't bother the outside with our state @@ -81,6 +83,8 @@ void Joystick::update() return; }; + if (!mEnabled) return; + // X-Axis int position = SDL_JoystickGetAxis(mJoystick, 0); if (position >= mRightTolerance) @@ -144,7 +148,6 @@ void Joystick::doCalibration() } } - void Joystick::finishCalibration() { config.setValue("leftTolerance", mLeftTolerance); @@ -154,10 +157,7 @@ void Joystick::finishCalibration() mCalibrating = false; } -bool Joystick::buttonPressed(unsigned char no) +bool Joystick::buttonPressed(unsigned char no) const { - if (no > MAX_BUTTONS) - return false; - - return mButtons[no]; + return (no < MAX_BUTTONS) ? mButtons[no] : false; } diff --git a/src/joystick.h b/src/joystick.h index ebdfabeb..f0759add 100644 --- a/src/joystick.h +++ b/src/joystick.h @@ -30,12 +30,12 @@ class Joystick { public: /** - * Number of buttons we can handle + * Number of buttons we can handle. */ static const unsigned char MAX_BUTTONS = 6; /** - * Directions, to be used as bitmask values + * Directions, to be used as bitmask values. */ static const char UP = 1; static const char DOWN = 2; @@ -43,12 +43,12 @@ class Joystick static const char RIGHT = 8; /** - * Initializes the joystick subsystem + * Initializes the joystick subsystem. */ static void init(); /** - * Returns the number of available joysticks + * Returns the number of available joysticks. */ static int getNumberOfJoysticks() { return joystickCount; } @@ -60,21 +60,33 @@ class Joystick ~Joystick(); + bool + isEnabled() const { return mEnabled; } + + void + setEnabled(bool enabled) { mEnabled = enabled; } + /** * Updates the direction and button information. */ - void update(); + void + update(); + + void + startCalibration(); + + void + finishCalibration(); - void startCalibration(); - void finishCalibration(); - bool isCalibrating() { return mCalibrating; }; + bool + isCalibrating() const { return mCalibrating; } - bool buttonPressed(unsigned char no); + bool buttonPressed(unsigned char no) const; - bool isUp() { return mDirection & UP; }; - bool isDown() { return mDirection & DOWN; }; - bool isLeft() { return mDirection & LEFT; }; - bool isRight() { return mDirection & RIGHT; }; + bool isUp() const { return mDirection & UP; }; + bool isDown() const { return mDirection & DOWN; }; + bool isLeft() const { return mDirection & LEFT; }; + bool isRight() const { return mDirection & RIGHT; }; protected: unsigned char mDirection; @@ -83,6 +95,7 @@ class Joystick int mUpTolerance, mDownTolerance, mLeftTolerance, mRightTolerance; bool mCalibrating; + bool mEnabled; static int joystickCount; diff --git a/src/main.cpp b/src/main.cpp index 573b1a79..f540dacd 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -330,6 +330,7 @@ struct Options bool chooseDefault; std::string username; std::string password; + std::string playername; }; void printHelp() @@ -341,13 +342,14 @@ void printHelp() << " -u --skipupdate : Skip the update process" << std::endl << " -U --username : Login with this username" << std::endl << " -P --password : Login with this password" << std::endl - << " -D --default : Bypass the login process with default settings" + << " -D --default : Bypass the login process with default settings" << std::endl + << " -p --playername : Login with this player" << std::endl; } void parseOptions(int argc, char *argv[], Options &options) { - const char *optstring = "huU:P:D"; + const char *optstring = "huU:P:Dp:"; const struct option long_options[] = { { "help", no_argument, 0, 'h' }, @@ -355,6 +357,7 @@ void parseOptions(int argc, char *argv[], Options &options) { "username", required_argument, 0, 'U' }, { "password", required_argument, 0, 'P' }, { "default", no_argument, 0, 'D' }, + { "playername", required_argument, 0, 'p' }, { 0 } }; @@ -382,6 +385,9 @@ void parseOptions(int argc, char *argv[], Options &options) case 'D': options.chooseDefault = true; break; + case 'p': + options.playername = optarg; + break; } } } @@ -668,7 +674,20 @@ int main(int argc, char *argv[]) case STATE_CHAR_SELECT: logger->log("State: CHAR_SELECT"); currentDialog = new CharSelectDialog(&charInfo); - if (options.chooseDefault) { + if (options.playername != "") { + n_character = 0; + while (((CharSelectDialog*) currentDialog)->getName() + != options.playername && + n_character < MAX_SLOT + 1) + { + ((CharSelectDialog*) currentDialog)->action("next", + NULL); + ((CharSelectDialog*) currentDialog)->updatePlayerInfo(); + n_character++; + } + n_character = MAX_SLOT + 1; + } + if (options.chooseDefault || options.playername != "") { ((CharSelectDialog*)currentDialog)->action("ok", NULL); } diff --git a/src/map.cpp b/src/map.cpp index 1b2ce1e8..cbebc41c 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -60,7 +60,8 @@ struct Location Map::Map(int width, int height, int tileWidth, int tileHeight): mWidth(width), mHeight(height), mTileWidth(tileWidth), mTileHeight(tileHeight), - mOnClosedList(1), mOnOpenList(2) + mOnClosedList(1), mOnOpenList(2), + mLastScrollX(0.0f), mLastScrollY(0.0f) { mMetaTiles = new MetaTile[mWidth * mHeight]; mTiles = new Image*[mWidth * mHeight * 3]; @@ -68,12 +69,18 @@ Map::Map(int width, int height, int tileWidth, int tileHeight): Map::~Map() { + // clean up map data delete[] mMetaTiles; delete[] mTiles; - - // Clean up tilesets + // clean up tilesets for_each(mTilesets.begin(), mTilesets.end(), make_dtor(mTilesets)); mTilesets.clear(); + // clean up overlays + std::list::iterator i; + for (i = mOverlays.begin(); i != mOverlays.end(); i++) + { + (*i).image->decRef(); + } } void @@ -159,6 +166,106 @@ Map::draw(Graphics *graphics, int scrollX, int scrollY, int layer) } } +void +Map::drawOverlay(Graphics *graphics, float scrollX, float scrollY, int detail) +{ + static int lastTick = tick_time; + + // detail 0: no overlays + if (detail <= 0) return; + + std::list::iterator i; + + // Avoid freaking out when tick_time overflows + if (tick_time < lastTick) + { + lastTick = tick_time; + } + + if (mLastScrollX == 0.0f && mLastScrollY == 0.0f) + { + // first call - initialisation + mLastScrollX = scrollX; + mLastScrollY = scrollY; + } + + //update Overlays + while (lastTick < tick_time) + { + for (i = mOverlays.begin(); i != mOverlays.end(); i++) + { + if ((*i).image != NULL) + { + //apply self scrolling + (*i).scrollX -= (*i).scrollSpeedX; + (*i).scrollY -= (*i).scrollSpeedY; + + //apply parallaxing + (*i).scrollX += (scrollX - mLastScrollX) * (*i).parallax; + (*i).scrollY += (scrollY - mLastScrollY) * (*i).parallax; + + //keep the image pattern on the screen + while ((*i).scrollX > (*i).image->getWidth()) + { + (*i).scrollX -= (*i).image->getWidth(); + } + while ((*i).scrollY > (*i).image->getHeight()) + { + (*i).scrollY -= (*i).image->getHeight(); + } + while ((*i).scrollX < 0) + { + (*i).scrollX += (*i).image->getWidth(); + } + while ((*i).scrollY < 0) + { + (*i).scrollY += (*i).image->getHeight(); + } + } + } + mLastScrollX = scrollX; + mLastScrollY = scrollY; + lastTick++; + + // detail 1: only one overlay, higher: all overlays + if (detail == 1) break; + } + + //draw overlays + for (i = mOverlays.begin(); i != mOverlays.end(); i++) + { + if ((*i).image != NULL) + { + graphics->drawImagePattern ( (*i).image, + 0 - (int)(*i).scrollX, + 0 - (int)(*i).scrollY, + graphics->getWidth() + (int)(*i).scrollX, + graphics->getHeight() + (int)(*i).scrollY + ); + }; + // detail 1: only one overlay, higher: all overlays + if (detail == 1) break; + }; +} + +void +Map::setOverlay(Image *image, float speedX, float speedY, float parallax) +{ + if (image != NULL) + { + AmbientOverlay newOverlay; + + newOverlay.image = image; + newOverlay.parallax = parallax; + newOverlay.scrollSpeedX = speedX; + newOverlay.scrollSpeedY = speedY; + newOverlay.scrollX = 0; + newOverlay.scrollY = 0; + + mOverlays.push_back(newOverlay); + } +} + void Map::setTileWithGid(int x, int y, int layer, int gid) { diff --git a/src/map.h b/src/map.h index a91b815f..317a0b59 100644 --- a/src/map.h +++ b/src/map.h @@ -41,6 +41,8 @@ typedef Tilesets::iterator TilesetIterator; typedef std::list Sprites; typedef Sprites::iterator SpriteIterator; +extern volatile int tick_time; + /** * A meta tile stores additional information about a location on a tile map. * This is information that doesn't need to be repeated for each tile in each @@ -63,6 +65,16 @@ struct MetaTile bool walkable; /**< Can beings walk on this tile */ }; +struct AmbientOverlay +{ + Image *image; + float parallax; + float scrollX; + float scrollY; + float scrollSpeedX; + float scrollSpeedY; +}; + /** * A tile map. */ @@ -80,10 +92,20 @@ class Map : public Properties ~Map(); /** - * Draws the map to the given graphics output. + * Draws a map layer to the given graphics output. */ void draw(Graphics *graphics, int scrollX, int scrollY, int layer); + /** + * Sets Overlay Graphic and Scrollspeed + */ + void setOverlay(Image *image, float speedX, float speedY, float parallax); + + /** + * Draws the overlay graphic to the given graphics output. + */ + void drawOverlay(Graphics *graphics, float scrollX, float scrollY, int detail); + /** * Sets the size of the map. This will destroy any existing map data. */ @@ -198,6 +220,12 @@ class Map : public Properties // Pathfinding members int mOnClosedList, mOnOpenList; + + //overlay Data + AmbientOverlay mFoo; + std::list mOverlays; + float mLastScrollX; + float mLastScrollY; }; #endif diff --git a/src/net/inventoryhandler.cpp b/src/net/inventoryhandler.cpp index cb1883b0..c4192bc5 100644 --- a/src/net/inventoryhandler.cpp +++ b/src/net/inventoryhandler.cpp @@ -28,6 +28,7 @@ #include "messagein.h" #include "protocol.h" +#include "../resources/iteminfo.h" #include "../item.h" #include "../localplayer.h" @@ -91,6 +92,14 @@ void InventoryHandler::handleMessage(MessageIn &msg) if (msg.readByte()> 0) { chatWindow->chatLog("Unable to pick up item", BY_SERVER); } else { + ItemInfo *itemInfo = itemDb->getItemInfo(itemId); + if (itemInfo) { + chatWindow->chatLog("You picked up a " + + itemInfo->getName(), BY_SERVER); + } else { + chatWindow->chatLog("You picked up an unknown item", + BY_SERVER); + } player_node->addInvItem(index, itemId, amount, equipType != 0); } break; diff --git a/src/player.cpp b/src/player.cpp index b635397e..af9a3344 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -84,6 +84,7 @@ Player::setSex(Uint8 sex) } Being::setSex(sex); + resetAnimations(); } } @@ -99,6 +100,7 @@ Player::setHairColor(Uint16 color) newHairSprite->setDirection(getSpriteDirection()); mSprites[HAIR_SPRITE] = newHairSprite; + resetAnimations(); setAction(mAction); } @@ -118,6 +120,7 @@ Player::setHairStyle(Uint16 style) newHairSprite->setDirection(getSpriteDirection()); mSprites[HAIR_SPRITE] = newHairSprite; + resetAnimations(); setAction(mAction); } @@ -155,6 +158,7 @@ Player::setVisibleEquipment(Uint8 slot, Uint8 id) equipmentSprite->setDirection(getSpriteDirection()); mSprites[position] = equipmentSprite; + resetAnimations(); setAction(mAction); } @@ -162,4 +166,14 @@ Player::setVisibleEquipment(Uint8 slot, Uint8 id) Being::setVisibleEquipment(slot, id); } - +void +Player::resetAnimations() +{ + for (int i = 0; i < VECTOREND_SPRITE; i++) + { + if (mSprites[i] != NULL) + { + mSprites[i]->reset(); + } + } +} diff --git a/src/player.h b/src/player.h index d0d55cc8..65b0303d 100644 --- a/src/player.h +++ b/src/player.h @@ -57,6 +57,14 @@ class Player : public Being virtual void setVisibleEquipment(Uint8 slot, Uint8 id); + + private: + /** + * Resets all animations associated with this player. This is used to + * synchronize the animations after a new one has been added. + */ + void + resetAnimations(); }; #endif diff --git a/src/resources/iteminfo.cpp b/src/resources/iteminfo.cpp new file mode 100644 index 00000000..5d39d832 --- /dev/null +++ b/src/resources/iteminfo.cpp @@ -0,0 +1,44 @@ +/* + * The Mana World + * Copyright 2004 The Mana World Development Team + * + * This file is part of The Mana World. + * + * The Mana World is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * The Mana World is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with The Mana World; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#include "iteminfo.h" + +#include "resourcemanager.h" + +Image* +ItemInfo::getImage() { + if (mImage == NULL && mImageName != "") { + mImage = ResourceManager::getInstance()->getImage(mImageName); + } + return mImage; +} + +void +ItemInfo::setImage(const std::string &image) { + mImageName = "graphics/items/" + image; +} + +ItemInfo::~ItemInfo() { + if (mImage != NULL){ + mImage->decRef(); + } +} diff --git a/src/resources/iteminfo.h b/src/resources/iteminfo.h index 54e7907b..afa2e857 100644 --- a/src/resources/iteminfo.h +++ b/src/resources/iteminfo.h @@ -26,6 +26,8 @@ #include +#include "image.h" + /** * Defines a class for storing item infos. */ @@ -38,7 +40,8 @@ class ItemInfo * Constructor. */ ItemInfo(): - mImage(0), + mImage(NULL), + mImageName(""), mArt(0), mType(0), mWeight(0), @@ -59,10 +62,10 @@ class ItemInfo getName() { return mName; } void - setImage(short image) { mImage = image; } + setImage(const std::string &image); - short - getImage() { return mImage; } + Image* + getImage(); void setDescription(const std::string &description) @@ -101,9 +104,10 @@ class ItemInfo /** * Destructor. */ - ~ItemInfo() {} + ~ItemInfo(); - short mImage; + Image* mImage; + std::string mImageName; short mArt; std::string mName; std::string mDescription; diff --git a/src/resources/itemmanager.cpp b/src/resources/itemmanager.cpp index 63c0b036..a497b3c8 100644 --- a/src/resources/itemmanager.cpp +++ b/src/resources/itemmanager.cpp @@ -68,8 +68,8 @@ ItemManager::ItemManager() for (node = node->xmlChildrenNode; node != NULL; node = node->next) { - int id = 0, image = 0, art = 0, type = 0, weight = 0, slot = 0; - std::string name = "", description = "", effect = ""; + int id = 0, art = 0, type = 0, weight = 0, slot = 0; + std::string name = "", description = "", effect = "", image = ""; if (!xmlStrEqual(node->name, BAD_CAST "item")) { continue; @@ -77,7 +77,7 @@ ItemManager::ItemManager() xmlChar *prop = NULL; READ_PROP(node, prop, "id", id, atoi); - READ_PROP(node, prop, "image", image, atoi); + READ_PROP(node, prop, "image", image, ); READ_PROP(node, prop, "art", art, atoi); READ_PROP(node, prop, "name", name, ); READ_PROP(node, prop, "description", description, ); @@ -86,6 +86,7 @@ ItemManager::ItemManager() READ_PROP(node, prop, "weight", weight, atoi); READ_PROP(node, prop, "slot", slot, atoi); + if (id && name != "") { ItemInfo *itemInfo = new ItemInfo(); @@ -100,6 +101,7 @@ ItemManager::ItemManager() mItemInfos[id] = itemInfo; } + if (id == 0) { logger->log("Item Manager: An item has no ID in items.xml!"); @@ -109,7 +111,7 @@ ItemManager::ItemManager() logger->log("Item Manager: An item has no name in items.xml!"); } - if (image == 0) + if (image == "") { logger->log("Item Manager: Missing image parameter for item: %i. %s", id, name.c_str()); @@ -141,7 +143,7 @@ ItemManager::ItemManager() } if (slot == 0) { - logger->log("Item Manager: Missing image parameter for item: %i. %s", + logger->log("Item Manager: Missing slot parameter for item: %i. %s", id, name.c_str()); } diff --git a/src/resources/mapreader.cpp b/src/resources/mapreader.cpp index 382b0797..c1ae911c 100644 --- a/src/resources/mapreader.cpp +++ b/src/resources/mapreader.cpp @@ -34,6 +34,7 @@ #include "../map.h" #include "../tileset.h" +#include "../utils/tostring.h" const unsigned int DEFAULT_TILE_WIDTH = 32; const unsigned int DEFAULT_TILE_HEIGHT = 32; @@ -213,6 +214,32 @@ MapReader::readMap(xmlNodePtr node, const std::string &path) } } + //set Overlays + int i = 0; + ResourceManager *resman = ResourceManager::getInstance(); + + while (map->hasProperty("overlay" + toString(i) + "image")) + { + Image *overlayImage = resman->getImage(map->getProperty("overlay" + toString(i) + "image")); + float scrollX = 0.0f; + float scrollY = 0.0f; + float parallax = 0.0f; + if (map->hasProperty("overlay" + toString(i) + "scrollX")) + { + scrollX = atof(map->getProperty("overlay" + toString(i) + "scrollX").c_str()); + } + if (map->hasProperty("overlay" + toString(i) + "scrollY")) + { + scrollY = atof(map->getProperty("overlay" + toString(i) + "scrollY").c_str()); + } + if (map->hasProperty("overlay" + toString(i) + "parallax")) + { + parallax = atof(map->getProperty("overlay" + toString(i) + "parallax").c_str()); + } + map->setOverlay (overlayImage, scrollX, scrollY, parallax); + i++; + } + return map; } diff --git a/tmw.cbp b/tmw.cbp index d80ebe55..ff060fe4 100644 --- a/tmw.cbp +++ b/tmw.cbp @@ -48,6 +48,16 @@