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). --- src/gui/char_select.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/gui/char_select.h') 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(); -- 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.h') 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 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.h') 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 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.h') 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 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.h') 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 @@