diff options
author | Reid <reidyaro@gmail.com> | 2012-01-30 15:27:30 +0100 |
---|---|---|
committer | Reid <reidyaro@gmail.com> | 2012-01-30 15:27:30 +0100 |
commit | 502a0a0163e702af7334979a2eabfc4826a94091 (patch) | |
tree | 5e80ef76585b1718d7e74a411117c725fe3cb0e9 /src | |
parent | 8dea62750ab3a44e0f35f2543bbb6ccf2a9470ce (diff) | |
parent | 193ea898e5f549c14c0e4cd0d060785de4fb4bcf (diff) | |
download | manaplus-502a0a0163e702af7334979a2eabfc4826a94091.tar.gz manaplus-502a0a0163e702af7334979a2eabfc4826a94091.tar.bz2 manaplus-502a0a0163e702af7334979a2eabfc4826a94091.tar.xz manaplus-502a0a0163e702af7334979a2eabfc4826a94091.zip |
Merge branch 'master' of gitorious.org:manaplus/manaplus
Diffstat (limited to 'src')
52 files changed, 506 insertions, 588 deletions
diff --git a/src/being.cpp b/src/being.cpp index 39d0bd450..9edfaad7b 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -2517,26 +2517,31 @@ void Being::saveComment(const std::string &name, resman->saveTextFile(dir, "comment.txt", name + "\n" + comment); } +void Being::setState(Uint8 state) +{ + mAdvanced = true; + bool shop = (state & FLAG_SHOP); + bool away = (state & FLAG_AWAY); + bool inactive = (state & FLAG_INACTIVE); + bool needUpdate = (shop != mShop || away != mAway + || inactive != mInactive); + + mShop = shop; + mAway = away; + mInactive = inactive; + + if (needUpdate) + { + updateName(); + addToCache(); + } +} + void Being::setEmote(Uint8 emotion, int emote_time) { if ((emotion & FLAG_SPECIAL) == FLAG_SPECIAL) { - mAdvanced = true; - bool shop = (emotion & FLAG_SHOP); - bool away = (emotion & FLAG_AWAY); - bool inactive = (emotion & FLAG_INACTIVE); - bool needUpdate = (shop != mShop || away != mAway - || inactive != mInactive); - - mShop = shop; - mAway = away; - mInactive = inactive; - - if (needUpdate) - { - updateName(); - addToCache(); - } + setState(emotion); } else { diff --git a/src/being.h b/src/being.h index 6052644c9..f34c192cb 100644 --- a/src/being.h +++ b/src/being.h @@ -102,6 +102,7 @@ class Being : public ActorSprite, public ConfigListener FLAG_SHOP = 1, FLAG_AWAY = 2, FLAG_INACTIVE = 4, + FLAG_GENDER = 128, FLAG_SPECIAL = 128 + 64 }; @@ -546,6 +547,8 @@ class Being : public ActorSprite, public ConfigListener */ void setEmote(Uint8 emotion, int emote_time); + void setState(Uint8 state); + /** * Get the current Emoticon type displayed above * the being. @@ -749,6 +752,9 @@ class Being : public ActorSprite, public ConfigListener bool isShopEnabled() { return mShop; } + void enableShop(bool b) + { mShop = b; } + /** * Sets the attack range. */ diff --git a/src/client.cpp b/src/client.cpp index c51dffa9e..017bcadb4 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -1232,6 +1232,10 @@ int Client::gameExec() CharSelectDialog::Focus); } + // Choosing character on the command line should work only + // once, clear it so that 'switch character' works. + mOptions.character.clear(); + break; case STATE_CONNECT_GAME: diff --git a/src/commandhandler.cpp b/src/commandhandler.cpp index 0f1e60a25..7a588dc09 100644 --- a/src/commandhandler.cpp +++ b/src/commandhandler.cpp @@ -54,6 +54,7 @@ #include "net/guildhandler.h" #include "net/net.h" #include "net/partyhandler.h" +#include "net/playerhandler.h" #include "net/tradehandler.h" #ifdef DEBUG_DUMP_LEAKS @@ -748,7 +749,10 @@ void CommandHandler::handlePseudoAway(const std::string &args, ChatTab *tab A_UNUSED) { if (player_node) + { player_node->setPseudoAway(args); + player_node->updateStatus(); + } } void CommandHandler::handleFollow(const std::string &args, ChatTab *tab) diff --git a/src/compoundsprite.cpp b/src/compoundsprite.cpp index e76a55dcf..61fb3d4e0 100644 --- a/src/compoundsprite.cpp +++ b/src/compoundsprite.cpp @@ -61,10 +61,6 @@ CompoundSprite::CompoundSprite() : CompoundSprite::~CompoundSprite() { - SpriteIterator it, it_end; - for (it = begin(), it_end = end(); it != it_end; ++it) - delete (*it); - clear(); // delete mImage; @@ -78,7 +74,7 @@ bool CompoundSprite::reset() bool ret = false; SpriteIterator it, it_end; - for (it = begin(), it_end = end(); it != it_end; ++it) + for (it = mSprites.begin(), it_end = mSprites.end(); it != it_end; ++ it) { if (*it) ret |= (*it)->reset(); @@ -93,7 +89,7 @@ bool CompoundSprite::play(std::string action) bool ret = false; SpriteIterator it, it_end; - for (it = begin(), it_end = end(); it != it_end; ++it) + for (it = mSprites.begin(), it_end = mSprites.end(); it != it_end; ++ it) { if (*it) ret |= (*it)->play(action); @@ -108,7 +104,7 @@ bool CompoundSprite::update(int time) bool ret = false; SpriteIterator it, it_end; - for (it = begin(), it_end = end(); it != it_end; ++it) + for (it = mSprites.begin(), it_end = mSprites.end(); it != it_end; ++ it) { if (*it) ret |= (*it)->update(time); @@ -118,11 +114,14 @@ bool CompoundSprite::update(int time) return ret; } -bool CompoundSprite::draw(Graphics* graphics, int posX, int posY) const +bool CompoundSprite::draw(Graphics *graphics, int posX, int posY) const { if (mNeedsRedraw) updateImages(); + if (mSprites.empty()) // Nothing to draw + return false; + if (mAlpha == 1.0f && mImage) { return graphics->drawImage(mImage, posX + mOffsetX, posY + mOffsetY); @@ -144,7 +143,7 @@ bool CompoundSprite::draw(Graphics* graphics, int posX, int posY) const void CompoundSprite::drawSprites(Graphics* graphics, int posX, int posY) const { SpriteConstIterator it, it_end; - for (it = begin(), it_end = end(); it != it_end; ++it) + for (it = mSprites.begin(), it_end = mSprites.end(); it != it_end; ++ it) { if (*it) { @@ -158,7 +157,7 @@ void CompoundSprite::drawSpritesSDL(Graphics* graphics, int posX, int posY) const { SpriteConstIterator it, it_end; - for (it = begin(), it_end = end(); it != it_end; ++it) + for (it = mSprites.begin(), it_end = mSprites.end(); it != it_end; ++ it) { if (*it) (*it)->draw(graphics, posX, posY); @@ -170,7 +169,7 @@ int CompoundSprite::getWidth() const Sprite *base = nullptr; SpriteConstIterator it, it_end; - for (it = begin(), it_end = end(); it != it_end; ++it) + for (it = mSprites.begin(), it_end = mSprites.end(); it != it_end; ++ it) { if ((base = (*it))) break; @@ -187,7 +186,7 @@ int CompoundSprite::getHeight() const Sprite *base = nullptr; SpriteConstIterator it, it_end; - for (it = begin(), it_end = end(); it != it_end; ++it) + for (it = mSprites.begin(), it_end = mSprites.end(); it != it_end; ++ it) { if ((base = (*it))) break; @@ -199,7 +198,7 @@ int CompoundSprite::getHeight() const return 0; } -const Image* CompoundSprite::getImage() const +const Image *CompoundSprite::getImage() const { return mImage; } @@ -209,7 +208,7 @@ bool CompoundSprite::setSpriteDirection(SpriteDirection direction) bool ret = false; SpriteIterator it, it_end; - for (it = begin(), it_end = end(); it != it_end; ++it) + for (it = mSprites.begin(), it_end = mSprites.end(); it != it_end; ++ it) { if (*it) ret |= (*it)->setSpriteDirection(direction); @@ -230,7 +229,7 @@ int CompoundSprite::getNumberOfLayers() const unsigned int CompoundSprite::getCurrentFrame() const { SpriteConstIterator it, it_end; - for (it = begin(), it_end = end(); it != it_end; ++it) + for (it = mSprites.begin(), it_end = mSprites.end(); it != it_end; ++ it) { if (*it) return (*it)->getCurrentFrame(); @@ -242,7 +241,7 @@ unsigned int CompoundSprite::getCurrentFrame() const unsigned int CompoundSprite::getFrameCount() const { SpriteConstIterator it, it_end; - for (it = begin(), it_end = end(); it != it_end; ++it) + for (it = mSprites.begin(), it_end = mSprites.end(); it != it_end; ++ it) { if (*it) return (*it)->getFrameCount(); @@ -251,42 +250,43 @@ unsigned int CompoundSprite::getFrameCount() const return 0; } -void CompoundSprite::addSprite(Sprite* sprite) +void CompoundSprite::addSprite(Sprite *sprite) { - push_back(sprite); + mSprites.push_back(sprite); mNeedsRedraw = true; } void CompoundSprite::setSprite(int layer, Sprite* sprite) { // Skip if it won't change anything - if (at(layer) == sprite) + if (mSprites.at(layer) == sprite) return; - if (at(layer)) - delete at(layer); - at(layer) = sprite; + if (mSprites.at(layer)) + delete mSprites.at(layer); + mSprites[layer] = sprite; mNeedsRedraw = true; } void CompoundSprite::removeSprite(int layer) { // Skip if it won't change anything - if (at(layer) == nullptr) + if (!mSprites.at(layer)) return; - delete at(layer); - at(layer) = nullptr; + delete mSprites.at(layer); + mSprites.at(layer) = nullptr; mNeedsRedraw = true; } void CompoundSprite::clear() { // Skip if it won't change anything - if (empty()) - return; - - std::vector<Sprite*>::clear(); + if (!mSprites.empty()) + { + delete_all(mSprites); + mSprites.clear(); + } mNeedsRedraw = true; delete_all(imagesCache); imagesCache.clear(); @@ -297,10 +297,11 @@ void CompoundSprite::clear() void CompoundSprite::ensureSize(size_t layerCount) { // Skip if it won't change anything - if (size() >= layerCount) + if (mSprites.size() >= layerCount) return; - resize(layerCount, nullptr); +// resize(layerCount, nullptr); + mSprites.resize(layerCount); } /** @@ -308,7 +309,7 @@ void CompoundSprite::ensureSize(size_t layerCount) */ unsigned int CompoundSprite::getCurrentFrame(unsigned int layer) { - if (layer >= size()) + if (layer >= mSprites.size()) return 0; Sprite *s = getSprite(layer); @@ -323,7 +324,7 @@ unsigned int CompoundSprite::getCurrentFrame(unsigned int layer) */ unsigned int CompoundSprite::getFrameCount(unsigned int layer) { - if (layer >= size()) + if (layer >= mSprites.size()) return 0; Sprite *s = getSprite(layer); @@ -418,7 +419,8 @@ void CompoundSprite::setAlpha(float alpha) #endif { SpriteConstIterator it, it_end; - for (it = begin(), it_end = end(); it != it_end; ++ it) + for (it = mSprites.begin(), it_end = mSprites.end(); + it != it_end; ++ it) { if (*it) (*it)->setAlpha(alpha); @@ -490,8 +492,8 @@ bool CompoundSprite::updateFromCache() const if (ic && ic->data.size() == size()) { bool fail(false); - SpriteConstIterator it1 = begin(); - SpriteConstIterator it1_end = end(); + SpriteConstIterator it1 = mSprites.begin(); + SpriteConstIterator it1_end = mSprites.end(); VectorPointers::const_iterator it2 = ic->data.begin(); VectorPointers::const_iterator it2_end = ic->data.end(); @@ -535,7 +537,7 @@ void CompoundSprite::initCurrentCacheItem() const // mCacheItem->alpha = mAlpha; SpriteConstIterator it, it_end; - for (it = begin(), it_end = end(); it != it_end; ++ it) + for (it = mSprites.begin(), it_end = mSprites.end(); it != it_end; ++ it) { if (*it) mCacheItem->data.push_back((*it)->getHash()); @@ -548,7 +550,7 @@ bool CompoundSprite::updateNumber(unsigned num) { SpriteConstIterator it, it_end; bool res(false); - for (it = begin(), it_end = end(); it != it_end; ++ it) + for (it = mSprites.begin(), it_end = mSprites.end(); it != it_end; ++ it) { if (*it) { diff --git a/src/compoundsprite.h b/src/compoundsprite.h index 1c04e44d2..1b9eeca34 100644 --- a/src/compoundsprite.h +++ b/src/compoundsprite.h @@ -44,11 +44,11 @@ class CompoundItem Image *alphaImage; }; -class CompoundSprite : public Sprite, private std::vector<Sprite*> +class CompoundSprite : public Sprite { public: - typedef CompoundSprite::iterator SpriteIterator; - typedef CompoundSprite::const_iterator SpriteConstIterator; + typedef std::vector<Sprite*>::iterator SpriteIterator; + typedef std::vector<Sprite*>::const_iterator SpriteConstIterator; CompoundSprite(); @@ -60,7 +60,7 @@ public: virtual bool update(int time); - virtual bool draw(Graphics* graphics, int posX, int posY) const; + virtual bool draw(Graphics *graphics, int posX, int posY) const; /** * Gets the width in pixels of the first sprite in the list. @@ -72,7 +72,7 @@ public: */ virtual int getHeight() const; - virtual const Image* getImage() const; + virtual const Image *getImage() const; virtual bool setSpriteDirection(SpriteDirection direction); @@ -83,17 +83,17 @@ public: unsigned int getFrameCount() const; size_t size() const - { return std::vector<Sprite*>::size(); } + { return mSprites.size(); } bool empty() const - { return std::vector<Sprite*>::empty(); } + { return mSprites.empty(); } - void addSprite(Sprite* sprite); + void addSprite(Sprite *sprite); - void setSprite(int layer, Sprite* sprite); + void setSprite(int layer, Sprite *sprite); Sprite *getSprite(int layer) const - { return at(layer); } + { return mSprites.at(layer); } void removeSprite(int layer); @@ -144,6 +144,7 @@ private: bool mEnableAlphaFix; bool mDisableAdvBeingCaching; bool mDisableBeingCaching; + std::vector<Sprite*> mSprites; }; #endif // COMPOUNDSPRITE_H diff --git a/src/defaults.cpp b/src/defaults.cpp index 8444fafff..8933cddec 100644 --- a/src/defaults.cpp +++ b/src/defaults.cpp @@ -235,7 +235,7 @@ DefaultsData* getBrandingDefaults() AddDEF(brandingData, "wallpapersPath", ""); AddDEF(brandingData, "wallpapersFile", ""); AddDEF(brandingData, "appName", "ManaPlus"); - AddDEF(brandingData, "appIcon", "icons/manaplus.png"); + AddDEF(brandingData, "appIcon", "icons/manaplus"); AddDEF(brandingData, "loginMusic", "Magick - Real.ogg"); AddDEF(brandingData, "defaultServer", ""); AddDEF(brandingData, "defaultPort", DEFAULT_PORT); diff --git a/src/game.cpp b/src/game.cpp index aa9ba1536..e48b37ebc 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -287,6 +287,9 @@ static void createGuiWindows() if (setupWindow) setupWindow->externalUpdate(); + if (player_node) + player_node->updateStatus(); + Mana::Event::trigger(CHANNEL_GAME, Mana::Event(EVENT_GUIWINDOWSLOADED)); } @@ -1077,6 +1080,7 @@ bool Game::handleSwitchKeys(SDL_Event &event, bool &used) if (player_node) { player_node->changeAwayMode(); + player_node->updateStatus(); setValidSpeed(); } break; @@ -1585,6 +1589,8 @@ void Game::handleActive(SDL_Event &event) player_node->setHalfAway(true); } } + if (player_node) + player_node->updateStatus(); } if (player_node) player_node->updateName(); diff --git a/src/gui/charcreatedialog.cpp b/src/gui/charcreatedialog.cpp index a1233fdcc..641e07db6 100644 --- a/src/gui/charcreatedialog.cpp +++ b/src/gui/charcreatedialog.cpp @@ -47,6 +47,7 @@ #include "resources/chardb.h" #include "resources/colordb.h" #include "resources/itemdb.h" +#include "resources/iteminfo.h" #include "utils/gettext.h" #include "utils/stringutils.h" @@ -99,6 +100,7 @@ CharCreateDialog::CharCreateDialog(CharSelectDialog *parent, int slot): mNextRaceButton = new Button(_(">"), "nextrace", this); mPrevRaceButton = new Button(_("<"), "prevrace", this); mRaceLabel = new Label(_("Race:")); + mRaceNameLabel = new Label("qwerty"); } mCreateButton = new Button(_("Create"), "create", this); @@ -143,6 +145,7 @@ CharCreateDialog::CharCreateDialog(CharSelectDialog *parent, int slot): mPrevRaceButton->setPosition(155, 93); mNextRaceButton->setPosition(230, 93); mRaceLabel->setPosition(5, 100); + mRaceNameLabel->setPosition(5, 118); } mAttributesLeft->setPosition(15, 280); @@ -172,6 +175,7 @@ CharCreateDialog::CharCreateDialog(CharSelectDialog *parent, int slot): add(mNextRaceButton); add(mPrevRaceButton); add(mRaceLabel); + add(mRaceNameLabel); } add(mAttributesLeft); @@ -184,6 +188,8 @@ CharCreateDialog::CharCreateDialog(CharSelectDialog *parent, int slot): center(); setVisible(true); mNameField->requestFocus(); + if (serverVersion >= 2) + updateRace(); } CharCreateDialog::~CharCreateDialog() @@ -448,4 +454,6 @@ void CharCreateDialog::updateRace() } mPlayer->setSubtype(mRace); + const ItemInfo &item = ItemDB::get(id); + mRaceNameLabel->setCaption(item.getName()); } diff --git a/src/gui/charcreatedialog.h b/src/gui/charcreatedialog.h index e369f1777..065b532c4 100644 --- a/src/gui/charcreatedialog.h +++ b/src/gui/charcreatedialog.h @@ -101,6 +101,7 @@ class CharCreateDialog : public Window, public gcn::ActionListener gcn::Button *mNextRaceButton; gcn::Button *mPrevRaceButton; gcn::Label *mRaceLabel; + gcn::Label *mRaceNameLabel; gcn::RadioButton *mMale; gcn::RadioButton *mFemale; diff --git a/src/gui/inventorywindow.cpp b/src/gui/inventorywindow.cpp index 01e2bdd17..4a54f5fb2 100644 --- a/src/gui/inventorywindow.cpp +++ b/src/gui/inventorywindow.cpp @@ -340,7 +340,7 @@ void InventoryWindow::action(const gcn::ActionEvent &event) { if (isStorageActive()) { - Net::getInventoryHandler()->moveItem(Inventory::INVENTORY, + Net::getInventoryHandler()->moveItem2(Inventory::INVENTORY, item->getInvIndex(), item->getQuantity(), Inventory::STORAGE); } @@ -431,7 +431,7 @@ void InventoryWindow::mouseClicked(gcn::MouseEvent &event) } else { - Net::getInventoryHandler()->moveItem(Inventory::INVENTORY, + Net::getInventoryHandler()->moveItem2(Inventory::INVENTORY, item->getInvIndex(), item->getQuantity(), Inventory::STORAGE); } @@ -445,7 +445,7 @@ void InventoryWindow::mouseClicked(gcn::MouseEvent &event) } else { - Net::getInventoryHandler()->moveItem(Inventory::STORAGE, + Net::getInventoryHandler()->moveItem2(Inventory::STORAGE, item->getInvIndex(), item->getQuantity(), Inventory::INVENTORY); } diff --git a/src/gui/itemamountwindow.cpp b/src/gui/itemamountwindow.cpp index 9e2a97681..3b01b559f 100644 --- a/src/gui/itemamountwindow.cpp +++ b/src/gui/itemamountwindow.cpp @@ -113,14 +113,12 @@ void ItemAmountWindow::finish(Item *item, int amount, int price, Usage usage) Net::getInventoryHandler()->splitItem(item, amount); break; case StoreAdd: - Net::getInventoryHandler()->moveItem(Inventory::INVENTORY, - item->getInvIndex(), amount, - Inventory::STORAGE); + Net::getInventoryHandler()->moveItem2(Inventory::INVENTORY, + item->getInvIndex(), amount, Inventory::STORAGE); break; case StoreRemove: - Net::getInventoryHandler()->moveItem(Inventory::STORAGE, - item->getInvIndex(), amount, - Inventory::INVENTORY); + Net::getInventoryHandler()->moveItem2(Inventory::STORAGE, + item->getInvIndex(), amount, Inventory::INVENTORY); break; case ShopBuyAdd: if (shopWindow) diff --git a/src/gui/outfitwindow.cpp b/src/gui/outfitwindow.cpp index 74e8dbe46..73484f1d5 100644 --- a/src/gui/outfitwindow.cpp +++ b/src/gui/outfitwindow.cpp @@ -491,375 +491,32 @@ void OutfitWindow::unequipNotInOutfit(int outfit) } } +static const SDLKey numsTbl[] = +{ + SDLK_1, SDLK_2, SDLK_3, SDLK_4, SDLK_5, SDLK_6, SDLK_7, SDLK_8, SDLK_9, + SDLK_0, SDLK_MINUS, SDLK_EQUALS, SDLK_BACKSPACE, SDLK_INSERT, SDLK_HOME, + SDLK_q, SDLK_w, SDLK_e, SDLK_r, SDLK_t, SDLK_y, SDLK_u, SDLK_i, SDLK_o, + SDLK_p, SDLK_LEFTBRACKET, SDLK_RIGHTBRACKET, SDLK_BACKSLASH, SDLK_a, + SDLK_s, SDLK_d, SDLK_f, SDLK_g, SDLK_h, SDLK_j, SDLK_k, SDLK_l, + SDLK_SEMICOLON, SDLK_QUOTE, SDLK_z, SDLK_x, SDLK_c, SDLK_v, SDLK_b, SDLK_n, + SDLK_m, SDLK_COMMA, SDLK_PERIOD, SDLK_SLASH +}; + int OutfitWindow::keyToNumber(SDLKey key) const { - int outfitNum = -1; - switch (key) + for (unsigned f = 0; f < sizeof(numsTbl) / sizeof(SDLKey); f ++) { - case SDLK_1: - case SDLK_2: - case SDLK_3: - case SDLK_4: - case SDLK_5: - case SDLK_6: - case SDLK_7: - case SDLK_8: - case SDLK_9: - outfitNum = key - SDLK_1; - break; - - case SDLK_0: - outfitNum = 9; - break; - - case SDLK_MINUS: - outfitNum = 10; - break; - - case SDLK_EQUALS: - outfitNum = 11; - break; - - case SDLK_BACKSPACE: - outfitNum = 12; - break; - - case SDLK_INSERT: - outfitNum = 13; - break; - - case SDLK_HOME: - outfitNum = 14; - break; - - case SDLK_q: - outfitNum = 15; - break; - - case SDLK_w: - outfitNum = 16; - break; - - case SDLK_e: - outfitNum = 17; - break; - - case SDLK_r: - outfitNum = 18; - break; - - case SDLK_t: - outfitNum = 19; - break; - - case SDLK_y: - outfitNum = 20; - break; - - case SDLK_u: - outfitNum = 21; - break; - - case SDLK_i: - outfitNum = 22; - break; - - case SDLK_o: - outfitNum = 23; - break; - - case SDLK_p: - outfitNum = 24; - break; - - case SDLK_LEFTBRACKET: - outfitNum = 25; - break; - - case SDLK_RIGHTBRACKET: - outfitNum = 26; - break; - - case SDLK_BACKSLASH: - outfitNum = 27; - break; - - case SDLK_a: - outfitNum = 28; - break; - - case SDLK_s: - outfitNum = 29; - break; - - case SDLK_d: - outfitNum = 30; - break; - - case SDLK_f: - outfitNum = 31; - break; - - case SDLK_g: - outfitNum = 32; - break; - - case SDLK_h: - outfitNum = 33; - break; - - case SDLK_j: - outfitNum = 34; - break; - - case SDLK_k: - outfitNum = 35; - break; - - case SDLK_l: - outfitNum = 36; - break; - - case SDLK_SEMICOLON: - outfitNum = 37; - break; - - case SDLK_QUOTE: - outfitNum = 38; - break; - - case SDLK_z: - outfitNum = 39; - break; - - - case SDLK_x: - outfitNum = 40; - break; - - case SDLK_c: - outfitNum = 41; - break; - - case SDLK_v: - outfitNum = 42; - break; - - case SDLK_b: - outfitNum = 43; - break; - - case SDLK_n: - outfitNum = 44; - break; - - case SDLK_m: - outfitNum = 45; - break; - - case SDLK_COMMA: - outfitNum = 46; - break; - - case SDLK_PERIOD: - outfitNum = 47; - break; - - case SDLK_SLASH: - outfitNum = 48; - break; - - default: - break; + if (numsTbl[f] == key) + return f; } - - return outfitNum; + return -1; } -SDLKey OutfitWindow::numberToKey(int number) const +SDLKey OutfitWindow::numberToKey(unsigned number) const { - SDLKey key = SDLK_UNKNOWN; - switch (number) - { - case 0: - case 1: - case 2: - case 3: - case 4: - case 5: - case 6: - case 7: - case 8: - key = static_cast<SDLKey>( - static_cast<unsigned int>(SDLK_1) + number); - break; - - case 9: - key = SDLK_0; - break; - - case 10: - key = SDLK_MINUS; - break; - - case 11: - key = SDLK_EQUALS; - break; - - case 12: - key = SDLK_BACKSPACE; - break; - - case 13: - key = SDLK_INSERT; - break; - - case 14: - key = SDLK_HOME; - break; - - case 15: - key = SDLK_q; - break; - - case 16: - key = SDLK_w; - break; - - case 17: - key = SDLK_e; - break; - - case 18: - key = SDLK_r; - break; - - case 19: - key = SDLK_t; - break; - - case 20: - key = SDLK_y; - break; - - case 21: - key = SDLK_u; - break; - - case 22: - key = SDLK_i; - break; - - case 23: - key = SDLK_o; - break; - - case 24: - key = SDLK_p; - break; - - case 25: - key = SDLK_LEFTBRACKET; - break; - - case 26: - key = SDLK_RIGHTBRACKET; - break; - - case 27: - key = SDLK_BACKSLASH; - break; - - case 28: - key = SDLK_a; - break; - - case 29: - key = SDLK_s; - break; - - case 30: - key = SDLK_d; - break; - - case 31: - key = SDLK_f; - break; - - case 32: - key = SDLK_g; - break; - - case 33: - key = SDLK_h; - break; - - case 34: - key = SDLK_j; - break; - - case 35: - key = SDLK_k; - break; - - case 36: - key = SDLK_l; - break; - - case 37: - key = SDLK_SEMICOLON; - break; - - case 38: - key = SDLK_QUOTE; - break; - - case 39: - key = SDLK_z; - break; - - - case 40: - key = SDLK_x; - break; - - case 41: - key = SDLK_c; - break; - - case 42: - key = SDLK_v; - break; - - case 43: - key = SDLK_b; - break; - - case 44: - key = SDLK_n; - break; - - case 45: - key = SDLK_m; - break; - - case 46: - key = SDLK_COMMA; - break; - - case 47: - key = SDLK_PERIOD; - break; - - case 48: - key = SDLK_SLASH; - break; - - default: - break; - } - - return key; + if (number >= sizeof(numsTbl) / sizeof(SDLKey)) + return SDLK_UNKNOWN; + return numsTbl[number]; } std::string OutfitWindow::keyName(int number) diff --git a/src/gui/outfitwindow.h b/src/gui/outfitwindow.h index b2b46c7e7..a663f3657 100644 --- a/src/gui/outfitwindow.h +++ b/src/gui/outfitwindow.h @@ -90,7 +90,7 @@ class OutfitWindow : public Window, gcn::ActionListener int keyToNumber(SDLKey key) const A_PURE; - SDLKey numberToKey(int number) const A_PURE; + SDLKey numberToKey(unsigned number) const A_PURE; void next(); diff --git a/src/gui/popupmenu.cpp b/src/gui/popupmenu.cpp index cd3a4c5ad..142acc69c 100644 --- a/src/gui/popupmenu.cpp +++ b/src/gui/popupmenu.cpp @@ -1184,19 +1184,19 @@ void PopupMenu::handleLink(const std::string &link, int cnt = 10; if (cnt > mItem->getQuantity()) cnt = mItem->getQuantity(); - Net::getInventoryHandler()->moveItem(Inventory::INVENTORY, + Net::getInventoryHandler()->moveItem2(Inventory::INVENTORY, mItem->getInvIndex(), cnt, Inventory::STORAGE); } else if (link == "store half" && mItem) { - Net::getInventoryHandler()->moveItem(Inventory::INVENTORY, + Net::getInventoryHandler()->moveItem2(Inventory::INVENTORY, mItem->getInvIndex(), mItem->getQuantity() / 2, Inventory::STORAGE); } else if (link == "store all" && mItem) { - Net::getInventoryHandler()->moveItem(Inventory::INVENTORY, + Net::getInventoryHandler()->moveItem2(Inventory::INVENTORY, mItem->getInvIndex(), mItem->getQuantity(), Inventory::STORAGE); } @@ -1235,19 +1235,19 @@ void PopupMenu::handleLink(const std::string &link, int cnt = 10; if (cnt > mItem->getQuantity()) cnt = mItem->getQuantity(); - Net::getInventoryHandler()->moveItem(Inventory::STORAGE, + Net::getInventoryHandler()->moveItem2(Inventory::STORAGE, mItem->getInvIndex(), cnt, Inventory::INVENTORY); } else if (link == "retrieve half" && mItem) { - Net::getInventoryHandler()->moveItem(Inventory::STORAGE, + Net::getInventoryHandler()->moveItem2(Inventory::STORAGE, mItem->getInvIndex(), mItem->getQuantity() / 2, Inventory::INVENTORY); } else if (link == "retrieve all" && mItem) { - Net::getInventoryHandler()->moveItem(Inventory::STORAGE, + Net::getInventoryHandler()->moveItem2(Inventory::STORAGE, mItem->getInvIndex(), mItem->getQuantity(), Inventory::INVENTORY); } diff --git a/src/gui/shopwindow.cpp b/src/gui/shopwindow.cpp index b6b87edb7..1a27b8b0c 100644 --- a/src/gui/shopwindow.cpp +++ b/src/gui/shopwindow.cpp @@ -55,6 +55,7 @@ #include "net/net.h" #include "net/chathandler.h" #include "net/npchandler.h" +#include "net/playerhandler.h" #include "net/tradehandler.h" #include "resources/iteminfo.h" @@ -206,11 +207,15 @@ void ShopWindow::action(const gcn::ActionEvent &event) && mBuyShopItemList->getSelected() >= 0) { mBuyShopItems->del(mBuyShopItemList->getSelected()); + if (isShopEmpty() && player_node) + player_node->updateStatus(); } else if (event.getId() == "delete sell" && mSellShopItemList && mSellShopItemList->getSelected() >= 0) { mSellShopItems->del(mSellShopItemList->getSelected()); + if (isShopEmpty() && player_node) + player_node->updateStatus(); } else if (event.getId() == "announce buy" && mBuyShopItems && mBuyShopItems->getNumberOfElements() > 0) @@ -306,8 +311,12 @@ void ShopWindow::addBuyItem(Item *item, int amount, int price) { if (!mBuyShopItems || !item) return; + bool emp = isShopEmpty(); mBuyShopItems->addItemNoDup(item->getId(), item->getColor(), amount, price); + if (emp && player_node) + player_node->updateStatus(); + updateButtonsAndLabels(); } @@ -315,8 +324,12 @@ void ShopWindow::addSellItem(Item *item, int amount, int price) { if (!mBuyShopItems || !item) return; + bool emp = isShopEmpty(); mSellShopItems->addItemNoDup(item->getId(), item->getColor(), amount, price); + if (emp && player_node) + player_node->updateStatus(); + updateButtonsAndLabels(); } diff --git a/src/gui/socialwindow.cpp b/src/gui/socialwindow.cpp index a1a6c1cee..59ace1685 100644 --- a/src/gui/socialwindow.cpp +++ b/src/gui/socialwindow.cpp @@ -1143,7 +1143,7 @@ public: std::vector<std::string> *players = player_relations.getPlayersByRelation(PlayerRelation::FRIEND); - std::set<std::string> players2 = whoIsOnline->getOnlinePlayers(); + const std::set<std::string> &players2 = whoIsOnline->getOnlineNicks(); if (!players) return; diff --git a/src/gui/statuswindow.cpp b/src/gui/statuswindow.cpp index a5fd12d40..57c81bc04 100644 --- a/src/gui/statuswindow.cpp +++ b/src/gui/statuswindow.cpp @@ -424,12 +424,12 @@ void StatusWindow::addAttribute(int id, const std::string &name, if (modifiable) { disp = new ChangeDisplay(id, name); - mAttrCont->add(disp); + mAttrCont->add1(disp); } else { disp = new DerDisplay(id, name); - mDAttrCont->add(disp); + mDAttrCont->add1(disp); } mAttrs[id] = disp; } diff --git a/src/gui/whoisonline.cpp b/src/gui/whoisonline.cpp index a80fb4c89..7965221e4 100644 --- a/src/gui/whoisonline.cpp +++ b/src/gui/whoisonline.cpp @@ -48,6 +48,7 @@ #include "gui/chatwindow.h" +#include "utils/dtor.h" #include "utils/gettext.h" #include "utils/stringutils.h" @@ -68,21 +69,10 @@ class NameFunctuator { public: - bool operator()(const std::string &left, - const std::string &right) const + bool operator()(const OnlinePlayer *left, + const OnlinePlayer *right) const { - for (std::string::const_iterator lit = left.begin(), - rit = right.begin(); - lit != left.end() && rit != right.end(); ++lit, ++rit) - { - if (tolower(*lit) < tolower(*rit)) - return true; - else if (tolower(*lit) > tolower(*rit)) - return false; - } - if (left.size() < right.size()) - return true; - return false; + return (compareStrI(left->getNick(), right->getNick()) < 0); } } nameCompare; @@ -149,6 +139,14 @@ WhoIsOnline::~WhoIsOnline() // Remove possibly leftover temporary download delete[] mCurlError; + + std::set<OnlinePlayer*>::iterator itd = mOnlinePlayers.begin(); + std::set<OnlinePlayer*>::iterator itd_end = mOnlinePlayers.end(); + + for (; itd != itd_end; ++ itd) + delete *itd; + mOnlinePlayers.clear(); + mOnlineNicks.clear(); } void WhoIsOnline::handleLink(const std::string& link, gcn::MouseEvent *event) @@ -186,10 +184,10 @@ void WhoIsOnline::handleLink(const std::string& link, gcn::MouseEvent *event) } } -void WhoIsOnline::updateWindow(std::vector<std::string> &friends, - std::vector<std::string> &neutral, - std::vector<std::string> &disregard, - std::vector<std::string> enemy, +void WhoIsOnline::updateWindow(std::vector<OnlinePlayer*> &friends, + std::vector<OnlinePlayer*> &neutral, + std::vector<OnlinePlayer*> &disregard, + std::vector<OnlinePlayer*> enemy, int numOnline) { //Set window caption @@ -202,7 +200,7 @@ void WhoIsOnline::updateWindow(std::vector<std::string> &friends, bool addedFromSection(false); for (int i = 0; i < static_cast<int>(friends.size()); i++) { - mBrowserBox->addRow(friends.at(i)); + mBrowserBox->addRow(friends.at(i)->getText()); addedFromSection = true; } if (addedFromSection == true) @@ -212,7 +210,7 @@ void WhoIsOnline::updateWindow(std::vector<std::string> &friends, } for (int i = 0; i < static_cast<int>(enemy.size()); i++) { - mBrowserBox->addRow(enemy.at(i)); + mBrowserBox->addRow(enemy.at(i)->getText()); addedFromSection = true; } if (addedFromSection == true) @@ -222,7 +220,7 @@ void WhoIsOnline::updateWindow(std::vector<std::string> &friends, } for (int i = 0; i < static_cast<int>(neutral.size()); i++) { - mBrowserBox->addRow(neutral.at(i)); + mBrowserBox->addRow(neutral.at(i)->getText()); addedFromSection = true; } if (addedFromSection == true && !disregard.empty()) @@ -232,7 +230,7 @@ void WhoIsOnline::updateWindow(std::vector<std::string> &friends, } for (int i = 0; i < static_cast<int>(disregard.size()); i++) { - mBrowserBox->addRow(disregard.at(i)); + mBrowserBox->addRow(disregard.at(i)->getText()); } if (mScrollArea->getVerticalMaxScroll() < @@ -243,43 +241,59 @@ void WhoIsOnline::updateWindow(std::vector<std::string> &friends, } } -void WhoIsOnline::loadList(std::vector<std::string> &list) +void WhoIsOnline::loadList(std::vector<OnlinePlayer*> &list) { mBrowserBox->clearRows(); int numOnline = list.size(); - std::vector<std::string> friends; - std::vector<std::string> neutral; - std::vector<std::string> disregard; - std::vector<std::string> enemy; + std::vector<OnlinePlayer*> friends; + std::vector<OnlinePlayer*> neutral; + std::vector<OnlinePlayer*> disregard; + std::vector<OnlinePlayer*> enemy; + + std::set<OnlinePlayer*>::iterator itd = mOnlinePlayers.begin(); + std::set<OnlinePlayer*>::iterator itd_end = mOnlinePlayers.end(); + for (; itd != itd_end; ++ itd) + delete *itd; mOnlinePlayers.clear(); + mOnlineNicks.clear(); + mShowLevel = config.getBoolValue("showlevel"); - std::vector<std::string>::const_iterator it = list.begin(); - std::vector<std::string>::const_iterator it_end = list.end(); + std::vector<OnlinePlayer*>::iterator it = list.begin(); + std::vector<OnlinePlayer*>::iterator it_end = list.end(); for (; it != it_end; ++ it) { - std::string nick = *it; - mOnlinePlayers.insert(nick); + OnlinePlayer *player = *it; + std::string nick = player->getNick(); + mOnlinePlayers.insert(player); + mOnlineNicks.insert(nick); + + if (!mShowLevel) + player->setLevel(0); switch (player_relations.getRelation(nick)) { case PlayerRelation::NEUTRAL: default: - neutral.push_back(prepareNick(nick, 0, "0")); + player->setText("0"); + neutral.push_back(player); break; case PlayerRelation::FRIEND: - friends.push_back(prepareNick(nick, 0, "2")); + player->setText("2"); + friends.push_back(player); break; case PlayerRelation::DISREGARDED: case PlayerRelation::BLACKLISTED: - disregard.push_back(prepareNick(nick, 0, "8")); + player->setText("8"); + disregard.push_back(player); break; case PlayerRelation::ENEMY2: - enemy.push_back(prepareNick(nick, 0, "1")); + player->setText("1"); + enemy.push_back(player); break; case PlayerRelation::IGNORED: @@ -290,10 +304,10 @@ void WhoIsOnline::loadList(std::vector<std::string> &list) } updateWindow(friends, neutral, disregard, enemy, numOnline); - if (!mOnlinePlayers.empty()) + if (!mOnlineNicks.empty()) { if (chatWindow) - chatWindow->updateOnline(mOnlinePlayers); + chatWindow->updateOnline(mOnlineNicks); if (socialWindow) socialWindow->updateActiveList(); } @@ -313,15 +327,23 @@ void WhoIsOnline::loadWebList() bool listStarted(false); std::string lineStr; int numOnline(0); - std::vector<std::string> friends; - std::vector<std::string> neutral; - std::vector<std::string> disregard; - std::vector<std::string> enemy; + std::vector<OnlinePlayer*> friends; + std::vector<OnlinePlayer*> neutral; + std::vector<OnlinePlayer*> disregard; + std::vector<OnlinePlayer*> enemy; // Tokenize and add each line separately char *line = strtok(mMemoryBuffer, "\n"); const std::string gmText = "(GM)"; + + std::set<OnlinePlayer*>::iterator itd = mOnlinePlayers.begin(); + std::set<OnlinePlayer*>::iterator itd_end = mOnlinePlayers.end(); + + for (; itd != itd_end; ++ itd) + delete *itd; + mOnlinePlayers.clear(); + mOnlineNicks.clear(); mShowLevel = config.getBoolValue("showlevel"); @@ -383,27 +405,38 @@ void WhoIsOnline::loadWebList() } } - mOnlinePlayers.insert(nick); + + if (!mShowLevel) + level = 0; + + OnlinePlayer *player = new OnlinePlayer(nick, 255, level, + GENDER_UNSPECIFIED, -1); + mOnlinePlayers.insert(player); + mOnlineNicks.insert(nick); numOnline++; switch (player_relations.getRelation(nick)) { case PlayerRelation::NEUTRAL: default: - neutral.push_back(prepareNick(nick, level, "0")); + player->setText("0"); + neutral.push_back(player); break; case PlayerRelation::FRIEND: - friends.push_back(prepareNick(nick, level, "2")); + player->setText("2"); + friends.push_back(player); break; case PlayerRelation::DISREGARDED: case PlayerRelation::BLACKLISTED: - disregard.push_back(prepareNick(nick, level, "8")); + player->setText("8"); + disregard.push_back(player); break; case PlayerRelation::ENEMY2: - enemy.push_back(prepareNick(nick, level, "1")); + player->setText("1"); + enemy.push_back(player); break; case PlayerRelation::IGNORED: @@ -472,8 +505,8 @@ int WhoIsOnline::downloadThread(void *ptr) curl_easy_setopt(curl, CURLOPT_WRITEDATA, ptr); curl_easy_setopt(curl, CURLOPT_USERAGENT, - strprintf(PACKAGE_EXTENDED_VERSION, branding - .getValue("appShort", "mana").c_str()).c_str()); + strprintf(PACKAGE_EXTENDED_VERSION, + branding.getStringValue("appName").c_str()).c_str()); curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, wio->mCurlError); curl_easy_setopt(curl, CURLOPT_URL, url.c_str()); @@ -596,10 +629,10 @@ void WhoIsOnline::logic() mUpdateButton->setEnabled(true); mUpdateTimer = 0; updateSize(); - if (!mOnlinePlayers.empty()) + if (!mOnlineNicks.empty()) { if (chatWindow) - chatWindow->updateOnline(mOnlinePlayers); + chatWindow->updateOnline(mOnlineNicks); if (socialWindow) socialWindow->updateActiveList(); } @@ -681,3 +714,46 @@ void WhoIsOnline::optionChanged(const std::string &name) if (name == "updateOnlineList") mUpdateOnlineList = config.getBoolValue("updateOnlineList"); } + +void OnlinePlayer::setText(std::string color) +{ + mText = strprintf("@@%s|##%s%s ", mNick.c_str(), + color.c_str(), mNick.c_str()); + + if (mStatus != 255 && actorSpriteManager) + { + Being *being = actorSpriteManager->findBeingByName( + mNick, Being::PLAYER); + if (being) + being->setState(mStatus); + } + + if (mLevel > 0) + mText += strprintf("%d", mLevel); + + if (mGender == GENDER_FEMALE) + mText += "\u2640"; + else if (mGender == GENDER_MALE) + mText += "\u2642"; + + if (mStatus > 0 && mStatus != 255) + { + if (mStatus & Being::FLAG_SHOP) + mText += "$"; + if (mStatus & Being::FLAG_AWAY) + { + // TRANSLATORS: this away status writed in player nick + mText += _("A"); + } + if (mStatus & Being::FLAG_INACTIVE) + { + // TRANSLATORS: this inactive status writed in player nick + mText += _("I"); + } + } + + if (mVersion > 0) + mText += strprintf(" - %d", mVersion); + + mText += strprintf("@@"); +} diff --git a/src/gui/whoisonline.h b/src/gui/whoisonline.h index ade391d5a..d2f0c30d0 100644 --- a/src/gui/whoisonline.h +++ b/src/gui/whoisonline.h @@ -42,6 +42,54 @@ class ScrollArea; struct SDL_Thread; +class OnlinePlayer +{ + public: + OnlinePlayer(std::string nick, unsigned char status, + char level, unsigned char gender, char version) : + mNick(nick), + mText(""), + mStatus(status), + mLevel(level), + mVersion(version), + mGender(gender) + { + } + + const std::string getNick() const + { return mNick; } + + unsigned char getStaus() const + { return mStatus; } + + char getVersion() const + { return mVersion; } + + char getLevel() const + { return mLevel; } + + const std::string getText() + { return mText; } + + void setText(std::string str); + + void setLevel(char level) + { mLevel = level; } + + private: + std::string mNick; + + std::string mText; + + unsigned char mStatus; + + char mLevel; + + char mVersion; + + unsigned char mGender; +}; + /** * Update progress window GUI * @@ -52,7 +100,7 @@ class WhoIsOnline : public Window, public gcn::ActionListener, public ConfigListener { - public: +public: /** * Constructor. */ @@ -68,7 +116,7 @@ class WhoIsOnline : public Window, */ void loadWebList(); - void loadList(std::vector<std::string> &list); + void loadList(std::vector<OnlinePlayer*> &list); void handleLink(const std::string& link, gcn::MouseEvent *event); @@ -78,9 +126,12 @@ class WhoIsOnline : public Window, void widgetResized(const gcn::Event &event); - std::set<std::string> &getOnlinePlayers() + const std::set<OnlinePlayer*> &getOnlinePlayers() { return mOnlinePlayers; } + const std::set<std::string> &getOnlineNicks() + { return mOnlineNicks; } + void setAllowUpdate(bool n) { mAllowUpdate = n; } @@ -109,10 +160,10 @@ private: const std::string prepareNick(std::string nick, int level, std::string color) const; - void updateWindow(std::vector<std::string> &friends, - std::vector<std::string> &neutral, - std::vector<std::string> &disregard, - std::vector<std::string> enemy, + void updateWindow(std::vector<OnlinePlayer*> &friends, + std::vector<OnlinePlayer*> &neutral, + std::vector<OnlinePlayer*> &disregard, + std::vector<OnlinePlayer*> enemy, int numOnline); enum DownloadStatus @@ -143,7 +194,8 @@ private: BrowserBox *mBrowserBox; ScrollArea *mScrollArea; time_t mUpdateTimer; - std::set<std::string> mOnlinePlayers; + std::set<OnlinePlayer*> mOnlinePlayers; + std::set<std::string> mOnlineNicks; gcn::Button *mUpdateButton; bool mAllowUpdate; diff --git a/src/gui/widgets/setupitem.cpp b/src/gui/widgets/setupitem.cpp index 92ff625c2..059b05ba2 100644 --- a/src/gui/widgets/setupitem.cpp +++ b/src/gui/widgets/setupitem.cpp @@ -192,7 +192,7 @@ void SetupItemCheckBox::createControls() load(); mCheckBox = new CheckBox(mText, mValue != "0", mParent, mEventName); mWidget = mCheckBox; - mParent->getContainer()->add(mWidget); + mParent->getContainer()->add1(mWidget); mParent->addControl(this); mParent->addActionListener(this); mWidget->addActionListener(this); @@ -275,7 +275,7 @@ void SetupItemTextField::createControls() mHorizont->add(mTextField); mHorizont->add(mButton); - mParent->getContainer()->add(mHorizont, true, 4); + mParent->getContainer()->add2(mHorizont, true, 4); mParent->addControl(this); mParent->addControl(this, mEventName + "_EDIT"); mParent->addControl(this, mEventName + "_EDIT_OK"); @@ -398,7 +398,7 @@ void SetupItemIntTextField::createControls() mHorizont->add(mTextField); mHorizont->add(mButton); - mParent->getContainer()->add(mHorizont, true, 4); + mParent->getContainer()->add2(mHorizont, true, 4); mParent->addControl(this); mParent->addControl(this, mEventName + "_EDIT"); mParent->addControl(this, mEventName + "_EDIT_OK"); @@ -486,7 +486,7 @@ void SetupItemLabel::createControls() } mWidget = mLabel; - mParent->getContainer()->add(mWidget); + mParent->getContainer()->add1(mWidget); mParent->addControl(this); mParent->addActionListener(this); mWidget->addActionListener(this); @@ -568,7 +568,7 @@ void SetupItemDropDown::createControls() mHorizont->add(mLabel); mHorizont->add(mDropDown); - mParent->getContainer()->add(mHorizont, true, 4); + mParent->getContainer()->add2(mHorizont, true, 4); mParent->addControl(this); mParent->addActionListener(this); mWidget->addActionListener(this); diff --git a/src/gui/widgets/vertcontainer.cpp b/src/gui/widgets/vertcontainer.cpp index 42ae97802..0eb59c8f9 100644 --- a/src/gui/widgets/vertcontainer.cpp +++ b/src/gui/widgets/vertcontainer.cpp @@ -35,12 +35,12 @@ VertContainer::VertContainer(int verticalItemSize, bool resizable, addWidgetListener(this); } -void VertContainer::add(gcn::Widget *widget, int spacing) +void VertContainer::add1(gcn::Widget *widget, int spacing) { - add(widget, mResizable, spacing); + add2(widget, mResizable, spacing); } -void VertContainer::add(gcn::Widget *widget, bool resizable, int spacing) +void VertContainer::add2(gcn::Widget *widget, bool resizable, int spacing) { if (!widget) return; diff --git a/src/gui/widgets/vertcontainer.h b/src/gui/widgets/vertcontainer.h index 6e1305a06..b4e43d31d 100644 --- a/src/gui/widgets/vertcontainer.h +++ b/src/gui/widgets/vertcontainer.h @@ -39,10 +39,10 @@ class VertContainer : public Container, public gcn::WidgetListener VertContainer(int verticalItemSize, bool resizable = true, int leftSpacing = 0); - virtual void add(gcn::Widget *widget, bool resizable, - int spacing = -1); + virtual void add2(gcn::Widget *widget, bool resizable, + int spacing = -1); - virtual void add(gcn::Widget *widget, int spacing = -1); + virtual void add1(gcn::Widget *widget, int spacing = -1); virtual void clear(); diff --git a/src/localplayer.cpp b/src/localplayer.cpp index 3df4a3214..bd69d785f 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -354,7 +354,8 @@ void LocalPlayer::logic() } } - if (mEnableAdvert && !mBlockAdvert && mAdvertTime < cur_time) + if (serverVersion < 4 && mEnableAdvert && !mBlockAdvert + && mAdvertTime < cur_time) { Uint8 smile = FLAG_SPECIAL; if (mTradebot && shopWindow && !shopWindow->isShopEmpty()) @@ -3442,6 +3443,7 @@ void LocalPlayer::setAway(const std::string &message) if (!message.empty()) config.setValue("afkMessage", message); changeAwayMode(); + updateStatus(); } void LocalPlayer::setPseudoAway(const std::string &message) @@ -4207,11 +4209,30 @@ const char *LocalPlayer::getVarItem(const char **arr, unsigned index, return arr[sz]; } +void LocalPlayer::updateStatus() +{ + if (serverVersion >= 4 && mEnableAdvert) + { + Uint8 status = 0; + if (mTradebot && shopWindow && !shopWindow->isShopEmpty()) + status += FLAG_SHOP; + + if (mAwayMode || mPseudoAwayMode) + status += FLAG_AWAY; + + if (mInactive) + status += FLAG_INACTIVE; + + Net::getPlayerHandler()->updateStatus(status); + } +} + void AwayListener::action(const gcn::ActionEvent &event) { if (event.getId() == "ok" && player_node && player_node->getAway()) { player_node->changeAwayMode(); + player_node->updateStatus(); if (outfitWindow) outfitWindow->unwearAwayOutfit(); if (miniStatusWindow) diff --git a/src/localplayer.h b/src/localplayer.h index ed181e3d0..ede073abf 100644 --- a/src/localplayer.h +++ b/src/localplayer.h @@ -477,6 +477,8 @@ class LocalPlayer : public Being, public ActorSpriteListener, bool checAttackPermissions(Being *target); + void updateStatus(); + std::string getInvertDirectionString(); std::string getCrazyMoveTypeString(); diff --git a/src/manaplus.rc b/src/manaplus.rc index b7720e2cc..1a6513bd6 100644 --- a/src/manaplus.rc +++ b/src/manaplus.rc @@ -3,6 +3,7 @@ #include "winver.h" A ICON MOVEABLE PURE LOADONCALL DISCARDABLE "../data/icons/manaplus.ico" +evol ICON MOVEABLE PURE LOADONCALL DISCARDABLE "../data/evol/icons/manaplus.ico" 1 VERSIONINFO FILEVERSION VER_MAJOR,VER_MINOR,VER_RELEASE,VER_BUILD @@ -11,10 +12,10 @@ PRODUCTVERSION VER_MAJOR,VER_MINOR,VER_RELEASE,VER_BUILD { BLOCK "StringFileInfo" { BLOCK "040904E4" { - VALUE "CompanyName", "The Mana Development Team" + VALUE "CompanyName", "The ManaPlus Development Team" VALUE "FileVersion", PACKAGE_VERSION "4144" VALUE "FileDescription", "ManaPlus" - VALUE "LegalCopyright", "2004-2010 (C)" + VALUE "LegalCopyright", "2004-2012 (C)" VALUE "OriginalFilename", "manaplus.exe" VALUE "ProductName", "ManaPlus MMORPG Client" VALUE "ProductVersion", PACKAGE_VERSION "4144" diff --git a/src/mumblemanager.cpp b/src/mumblemanager.cpp index 766f4085e..14ca7d527 100644 --- a/src/mumblemanager.cpp +++ b/src/mumblemanager.cpp @@ -78,7 +78,6 @@ void MumbleManager::init() #if defined BSD4_4 return; #endif - if (mLinkedMem || !config.getBoolValue("enableMumble")) return; diff --git a/src/net/adminhandler.h b/src/net/adminhandler.h index f6d8606ce..2ac462834 100644 --- a/src/net/adminhandler.h +++ b/src/net/adminhandler.h @@ -42,15 +42,15 @@ class AdminHandler virtual void kick(int playerId) = 0; - virtual void kick(const std::string &name) = 0; + virtual void kickName(const std::string &name) = 0; virtual void ban(int playerId) = 0; - virtual void ban(const std::string &name) = 0; + virtual void banName(const std::string &name) = 0; virtual void unban(int playerId) = 0; - virtual void unban(const std::string &name) = 0; + virtual void unbanName(const std::string &name) = 0; virtual void mute(int playerId, int type, int limit) = 0; diff --git a/src/net/download.cpp b/src/net/download.cpp index 22af389f3..d20713dfa 100644 --- a/src/net/download.cpp +++ b/src/net/download.cpp @@ -239,7 +239,7 @@ int Download::downloadThread(void *ptr) curl_easy_setopt(d->mCurl, CURLOPT_USERAGENT, strprintf(PACKAGE_EXTENDED_VERSION, - branding.getStringValue("appShort").c_str()).c_str()); + branding.getStringValue("appName").c_str()).c_str()); curl_easy_setopt(d->mCurl, CURLOPT_ERRORBUFFER, d->mError); curl_easy_setopt(d->mCurl, CURLOPT_URL, d->mUrl.c_str()); curl_easy_setopt(d->mCurl, CURLOPT_NOPROGRESS, 0); diff --git a/src/net/ea/adminhandler.cpp b/src/net/ea/adminhandler.cpp index 556629458..f70be3cc8 100644 --- a/src/net/ea/adminhandler.cpp +++ b/src/net/ea/adminhandler.cpp @@ -32,7 +32,7 @@ namespace Ea { -void AdminHandler::kick(const std::string &name) +void AdminHandler::kickName(const std::string &name) { Net::getChatHandler()->talk("@kick " + name); } @@ -42,7 +42,7 @@ void AdminHandler::ban(int playerId A_UNUSED) // Not supported } -void AdminHandler::ban(const std::string &name) +void AdminHandler::banName(const std::string &name) { Net::getChatHandler()->talk("@ban " + name); } @@ -52,7 +52,7 @@ void AdminHandler::unban(int playerId A_UNUSED) // Not supported } -void AdminHandler::unban(const std::string &name) +void AdminHandler::unbanName(const std::string &name) { Net::getChatHandler()->talk("@unban " + name); } diff --git a/src/net/ea/adminhandler.h b/src/net/ea/adminhandler.h index 70c458514..5b5224174 100644 --- a/src/net/ea/adminhandler.h +++ b/src/net/ea/adminhandler.h @@ -35,15 +35,15 @@ class AdminHandler : public Net::AdminHandler virtual ~AdminHandler() { } - virtual void kick(const std::string &name); + virtual void kickName(const std::string &name); virtual void ban(int playerId); - virtual void ban(const std::string &name); + virtual void banName(const std::string &name); virtual void unban(int playerId); - virtual void unban(const std::string &name); + virtual void unbanName(const std::string &name); virtual void mute(int playerId, int type, int limit); diff --git a/src/net/ea/playerhandler.cpp b/src/net/ea/playerhandler.cpp index 6a841415f..76a7b0dbc 100644 --- a/src/net/ea/playerhandler.cpp +++ b/src/net/ea/playerhandler.cpp @@ -645,4 +645,5 @@ int PlayerHandler::getAttackLocation() const { return EA_ATK; } + } // namespace Ea diff --git a/src/net/inventoryhandler.h b/src/net/inventoryhandler.h index ec2f3db47..642d6f1c1 100644 --- a/src/net/inventoryhandler.h +++ b/src/net/inventoryhandler.h @@ -57,8 +57,8 @@ class InventoryHandler //void changeCart() = 0; - virtual void moveItem(int source, int slot, int amount, - int destination) = 0; + virtual void moveItem2(int source, int slot, int amount, + int destination) = 0; // TODO: fix/remove me virtual size_t getSize(int type) const = 0; diff --git a/src/net/manaserv/adminhandler.cpp b/src/net/manaserv/adminhandler.cpp index 609c9e4f1..f44da97ff 100644 --- a/src/net/manaserv/adminhandler.cpp +++ b/src/net/manaserv/adminhandler.cpp @@ -62,7 +62,7 @@ void AdminHandler::kick(int playerId A_UNUSED) // TODO } -void AdminHandler::kick(const std::string &name A_UNUSED) +void AdminHandler::kickName(const std::string &name A_UNUSED) { // TODO } @@ -72,7 +72,7 @@ void AdminHandler::ban(int playerId A_UNUSED) // TODO } -void AdminHandler::ban(const std::string &name A_UNUSED) +void AdminHandler::banName(const std::string &name A_UNUSED) { // TODO } @@ -82,7 +82,7 @@ void AdminHandler::unban(int playerId A_UNUSED) // TODO } -void AdminHandler::unban(const std::string &name A_UNUSED) +void AdminHandler::unbanName(const std::string &name A_UNUSED) { // TODO } diff --git a/src/net/manaserv/adminhandler.h b/src/net/manaserv/adminhandler.h index a4157b3b0..87c536c31 100644 --- a/src/net/manaserv/adminhandler.h +++ b/src/net/manaserv/adminhandler.h @@ -42,15 +42,15 @@ class AdminHandler : public Net::AdminHandler void kick(int playerId); - void kick(const std::string &name); + void kickName(const std::string &name); void ban(int playerId); - void ban(const std::string &name); + void banName(const std::string &name); void unban(int playerId); - void unban(const std::string &name); + void unbanName(const std::string &name); void mute(int playerId, int type, int limit); diff --git a/src/net/manaserv/playerhandler.cpp b/src/net/manaserv/playerhandler.cpp index 5ebf840bc..aa79d4d41 100644 --- a/src/net/manaserv/playerhandler.cpp +++ b/src/net/manaserv/playerhandler.cpp @@ -448,4 +448,9 @@ void PlayerHandler::requestOnlineList() } +void PlayerHandler::updateStatus(Uint8 status) +{ + +} + } // namespace ManaServ diff --git a/src/net/manaserv/playerhandler.h b/src/net/manaserv/playerhandler.h index 0255406a8..23d2f5e32 100644 --- a/src/net/manaserv/playerhandler.h +++ b/src/net/manaserv/playerhandler.h @@ -74,6 +74,8 @@ class PlayerHandler : public MessageHandler, public Net::PlayerHandler Vector getDefaultWalkSpeed() const; + void updateStatus(Uint8 status); + private: void handleMapChangeMessage(Net::MessageIn &msg); }; diff --git a/src/net/manaserv/specialhandler.cpp b/src/net/manaserv/specialhandler.cpp index 13c6f7613..c168afd7c 100644 --- a/src/net/manaserv/specialhandler.cpp +++ b/src/net/manaserv/specialhandler.cpp @@ -53,19 +53,19 @@ void SpecialHandler::use(int id) gameServerConnection->send(msg); } -void SpecialHandler::use(int id A_UNUSED, int level A_UNUSED, - int beingId A_UNUSED) +void SpecialHandler::useBeing(int id A_UNUSED, int level A_UNUSED, + int beingId A_UNUSED) { // TODO } -void SpecialHandler::use(int id A_UNUSED, int level A_UNUSED, int x A_UNUSED, - int y A_UNUSED) +void SpecialHandler::usePos(int id A_UNUSED, int level A_UNUSED, + int x A_UNUSED, int y A_UNUSED) { // TODO } -void SpecialHandler::use(int id A_UNUSED, const std::string &map A_UNUSED) +void SpecialHandler::useMap(int id A_UNUSED, const std::string &map A_UNUSED) { // TODO } diff --git a/src/net/manaserv/specialhandler.h b/src/net/manaserv/specialhandler.h index f6a20e4ac..2f1ce4d07 100644 --- a/src/net/manaserv/specialhandler.h +++ b/src/net/manaserv/specialhandler.h @@ -39,11 +39,11 @@ class SpecialHandler : public MessageHandler, public Net::SpecialHandler void use(int id); - void use(int id, int level, int beingId); + void useBeing(int id, int level, int beingId); - void use(int id, int level, int x, int y); + void usePos(int id, int level, int x, int y); - void use(int id, const std::string &map); + void useMap(int id, const std::string &map); }; } // namespace ManaServ diff --git a/src/net/messagein.cpp b/src/net/messagein.cpp index 4fb61dc6a..0547ed337 100644 --- a/src/net/messagein.cpp +++ b/src/net/messagein.cpp @@ -241,7 +241,7 @@ std::string MessageIn::readRawString(int length) return str; } -char *MessageIn::readBytes(int length) +unsigned char *MessageIn::readBytes(int length) { // Get string length if (length < 0) @@ -255,13 +255,28 @@ char *MessageIn::readBytes(int length) return nullptr; } - char *buf = new char[length + 2]; + unsigned char *buf = new unsigned char[length + 2]; memcpy (buf, mData + mPos, length); buf[length] = 0; buf[length + 1] = 0; mPos += length; +#ifdef ENABLEDEBUGLOG + std::string str; + for (int f = 0; f < length; f ++) + str += strprintf ("%02x", (unsigned)buf[f]); + str += " "; + for (int f = 0; f < length; f ++) + { + if (buf[f]) + str += strprintf ("%c", buf[f]); + else + str += "_"; + } + logger->log("ReadBytes: " + str); +#endif + PacketCounters::incInBytes(length); return buf; } diff --git a/src/net/messagein.h b/src/net/messagein.h index 8dd43a1a0..1eb5bf232 100644 --- a/src/net/messagein.h +++ b/src/net/messagein.h @@ -95,7 +95,7 @@ class MessageIn virtual std::string readRawString(int length); - char *readBytes(int length); + unsigned char *readBytes(int length); virtual ~MessageIn() { } diff --git a/src/net/playerhandler.h b/src/net/playerhandler.h index f62acc0c9..6ae912102 100644 --- a/src/net/playerhandler.h +++ b/src/net/playerhandler.h @@ -73,6 +73,8 @@ class PlayerHandler virtual Vector getDefaultWalkSpeed() const = 0; virtual void requestOnlineList() = 0; + + virtual void updateStatus(Uint8 status) = 0; }; } // namespace Net diff --git a/src/net/specialhandler.h b/src/net/specialhandler.h index 7ed3673cf..f385f47f9 100644 --- a/src/net/specialhandler.h +++ b/src/net/specialhandler.h @@ -35,11 +35,11 @@ class SpecialHandler virtual void use(int id) = 0; - virtual void use(int id, int level, int beingId) = 0; + virtual void useBeing(int id, int level, int beingId) = 0; - virtual void use(int id, int level, int x, int y) = 0; + virtual void usePos(int id, int level, int x, int y) = 0; - virtual void use(int id, const std::string &map) = 0; + virtual void useMap(int id, const std::string &map) = 0; }; } diff --git a/src/net/tmwa/beinghandler.cpp b/src/net/tmwa/beinghandler.cpp index 627db1402..8d279fc32 100644 --- a/src/net/tmwa/beinghandler.cpp +++ b/src/net/tmwa/beinghandler.cpp @@ -590,7 +590,7 @@ void BeingHandler::processPlayerMoveUpdate(Net::MessageIn &msg, int msgType) if (gmstatus & 0x80) dstBeing->setGM(true); - if (msgType == 1) + if (msgType == 1 || msgType == 2) { int type = msg.readInt8(); switch (type) diff --git a/src/net/tmwa/inventoryhandler.cpp b/src/net/tmwa/inventoryhandler.cpp index 7fa26f5ed..db670a17b 100644 --- a/src/net/tmwa/inventoryhandler.cpp +++ b/src/net/tmwa/inventoryhandler.cpp @@ -186,8 +186,8 @@ void InventoryHandler::closeStorage(int type A_UNUSED) MessageOut outMsg(CMSG_CLOSE_STORAGE); } -void InventoryHandler::moveItem(int source, int slot, int amount, - int destination) +void InventoryHandler::moveItem2(int source, int slot, int amount, + int destination) { if (source == Inventory::INVENTORY && destination == Inventory::STORAGE) { diff --git a/src/net/tmwa/inventoryhandler.h b/src/net/tmwa/inventoryhandler.h index d2ecc4b6d..c6e000b3a 100644 --- a/src/net/tmwa/inventoryhandler.h +++ b/src/net/tmwa/inventoryhandler.h @@ -53,7 +53,7 @@ class InventoryHandler : public MessageHandler, public Ea::InventoryHandler void closeStorage(int type); - void moveItem(int source, int slot, int amount, int destination); + void moveItem2(int source, int slot, int amount, int destination); }; } // namespace TmwAthena diff --git a/src/net/tmwa/playerhandler.cpp b/src/net/tmwa/playerhandler.cpp index d5f0641eb..8747cf9c4 100644 --- a/src/net/tmwa/playerhandler.cpp +++ b/src/net/tmwa/playerhandler.cpp @@ -22,6 +22,7 @@ #include "net/tmwa/playerhandler.h" +#include "configuration.h" #include "logger.h" #include "net/messagein.h" @@ -218,7 +219,7 @@ void PlayerHandler::processOnlineList(Net::MessageIn &msg) return; int size = msg.readInt16() - 4; - std::vector<std::string> arr; + std::vector<OnlinePlayer*> arr; if (!size) { @@ -227,14 +228,41 @@ void PlayerHandler::processOnlineList(Net::MessageIn &msg) return; } - const char *start = msg.readBytes(size); - const char *buf = start; + char *start = (char*)msg.readBytes(size); + char *buf = start; - while (buf - start + 1 < size && *(buf + 1)) + int addVal = 1; + if (serverVersion >= 4) + addVal = 3; + + while (buf - start + 1 < size && *(buf + addVal)) { -// char status = *buf; // now unused + unsigned char status = 255; + unsigned char ver = 0; + unsigned char level = 0; + if (serverVersion >= 4) + { + status = *buf; + buf ++; + level = *buf; + buf ++; + ver = *buf; + } buf ++; - arr.push_back(buf); + + int gender = GENDER_UNSPECIFIED; + if (serverVersion >= 4) + { + if (config.getBoolValue("showgender")) + { + if (status & Being::FLAG_GENDER) + gender = GENDER_MALE; + else + gender = GENDER_FEMALE; + } + } + arr.push_back(new OnlinePlayer((char*)buf, + status, level, gender, ver)); buf += strlen(buf) + 1; } @@ -243,4 +271,11 @@ void PlayerHandler::processOnlineList(Net::MessageIn &msg) delete [] start; } +void PlayerHandler::updateStatus(Uint8 status) +{ + MessageOut outMsg(CMSG_SET_STATUS); + outMsg.writeInt8(status); + outMsg.writeInt8(0); +} + } // namespace TmwAthena diff --git a/src/net/tmwa/playerhandler.h b/src/net/tmwa/playerhandler.h index 0fa524d51..14aa191f6 100644 --- a/src/net/tmwa/playerhandler.h +++ b/src/net/tmwa/playerhandler.h @@ -53,6 +53,7 @@ class PlayerHandler : public MessageHandler, public Ea::PlayerHandler void changeAction(Being::Action action); void processOnlineList(Net::MessageIn &msg); void requestOnlineList(); + void updateStatus(Uint8 status); void respawn(); }; diff --git a/src/net/tmwa/protocol.h b/src/net/tmwa/protocol.h index ddc642101..256f1dce4 100644 --- a/src/net/tmwa/protocol.h +++ b/src/net/tmwa/protocol.h @@ -336,5 +336,6 @@ enum #define CMSG_ONLINE_LIST 0x0210 #define SMSG_ONLINE_LIST 0x0211 #define SMSG_NPC_COMMAND 0x0212 +#define CMSG_SET_STATUS 0x0213 #endif diff --git a/src/net/tmwa/specialhandler.cpp b/src/net/tmwa/specialhandler.cpp index 9fa7b6dfa..129f0b47e 100644 --- a/src/net/tmwa/specialhandler.cpp +++ b/src/net/tmwa/specialhandler.cpp @@ -69,7 +69,7 @@ void SpecialHandler::handleMessage(Net::MessageIn &msg) } } -void SpecialHandler::use(int id, int level, int beingId) +void SpecialHandler::useBeing(int id, int level, int beingId) { MessageOut outMsg(CMSG_SKILL_USE_BEING); outMsg.writeInt16(static_cast<Sint16>(level)); @@ -77,7 +77,7 @@ void SpecialHandler::use(int id, int level, int beingId) outMsg.writeInt16(static_cast<Sint16>(beingId)); } -void SpecialHandler::use(int id, int level, int x, int y) +void SpecialHandler::usePos(int id, int level, int x, int y) { MessageOut outMsg(CMSG_SKILL_USE_POSITION); outMsg.writeInt16(static_cast<Sint16>(level)); @@ -86,7 +86,7 @@ void SpecialHandler::use(int id, int level, int x, int y) outMsg.writeInt16(static_cast<Sint16>(y)); } -void SpecialHandler::use(int id, const std::string &map) +void SpecialHandler::useMap(int id, const std::string &map) { MessageOut outMsg(CMSG_SKILL_USE_MAP); outMsg.writeInt16(static_cast<Sint16>(id)); diff --git a/src/net/tmwa/specialhandler.h b/src/net/tmwa/specialhandler.h index f17ef4c44..216adddc6 100644 --- a/src/net/tmwa/specialhandler.h +++ b/src/net/tmwa/specialhandler.h @@ -40,11 +40,11 @@ class SpecialHandler : public MessageHandler, public Ea::SpecialHandler void handleMessage(Net::MessageIn &msg); - void use(int id, int level, int beingId); + void useBeing(int id, int level, int beingId); - void use(int id, int level, int x, int y); + void usePos(int id, int level, int x, int y); - void use(int id, const std::string &map); + void useMap(int id, const std::string &map); }; } // namespace TmwAthena diff --git a/src/resources/image.cpp b/src/resources/image.cpp index 9e9124ab6..6f9042029 100644 --- a/src/resources/image.cpp +++ b/src/resources/image.cpp @@ -79,6 +79,8 @@ Image::Image(SDL_Surface *image, bool hasAlphaChannel0, Uint8 *alphaChannel): { logger->log( "Image::Image(SDL_Surface*): Couldn't load invalid Surface!"); + mBounds.w = 0; + mBounds.h = 0; } } @@ -159,7 +161,7 @@ Resource *Image::load(SDL_RWops *rw, Dye const &dye) SDL_Surface *surf = SDL_ConvertSurface(tmpImage, &rgba, SDL_SWSURFACE); SDL_FreeSurface(tmpImage); - Uint32 *pixels = static_cast< Uint32 * >(surf->pixels); + Uint32 *pixels = static_cast<Uint32 *>(surf->pixels); for (Uint32 *p_end = pixels + surf->w * surf->h; pixels != p_end; ++pixels) { const Uint32 p = *pixels; @@ -207,10 +209,11 @@ Image *Image::createTextSurface(SDL_Surface *tmpImage, float alpha) bool hasAlpha = false; bool converted = false; + const int sz = tmpImage->w * tmpImage->h; + // The alpha channel to be filled with alpha values - Uint8 *alphaChannel = new Uint8[tmpImage->w * tmpImage->h]; + Uint8 *alphaChannel = new Uint8[sz]; - const int sz = tmpImage->w * tmpImage->h; const SDL_PixelFormat * const fmt = tmpImage->format; if (fmt->Amask) { @@ -463,7 +466,7 @@ Image* Image::SDLmerge(Image *image, int x, int y) SDL_LockSurface(surface); SDL_LockSurface(mSDLSurface); - const int x0 = (y * getWidth()) + x; + const int x0 = (y * mBounds.w) + x; const int maxX = std::min(image->mBounds.w, static_cast<Uint16>(mBounds.w - x)); const int maxY = std::min(image->mBounds.w, @@ -476,7 +479,7 @@ Image* Image::SDLmerge(Image *image, int x, int y) for (offset_y = ((y > 0) ? 0 : -y); offset_y < maxY; offset_y++) { // Computing offset on both images - current_offset = (offset_y * getWidth()) + x1; + current_offset = (offset_y * mBounds.w) + x1; surface_offset = offset_y * surface->w + offset_x; // Retrieving a pixel to merge @@ -543,7 +546,7 @@ Image* Image::SDLgetScaledImage(int width, int height) return nullptr; // No scaling when there is ... no different given size ... - if (width == getWidth() && height == getHeight()) + if (width == mBounds.w && height == mBounds.h) return nullptr; Image* scaledImage = nullptr; @@ -552,8 +555,8 @@ Image* Image::SDLgetScaledImage(int width, int height) if (mSDLSurface) { scaledSurface = zoomSurface(mSDLSurface, - static_cast<double>(width) / getWidth(), - static_cast<double>(height) / getHeight(), + static_cast<double>(width) / mBounds.w, + static_cast<double>(height) / mBounds.h, 1); // The load function takes care of the SDL<->OpenGL implementation @@ -623,22 +626,20 @@ Image *Image::_SDLload(SDL_Surface *tmpImage) bool hasAlpha = false; bool converted = false; - // The alpha channel to be filled with alpha values - Uint8 *alphaChannel = new Uint8[tmpImage->w * tmpImage->h]; - if (tmpImage->format->BitsPerPixel != 32) { tmpImage = convertTo32Bit(tmpImage); if (!tmpImage) - { - delete[] alphaChannel; return nullptr; - } converted = true; } const int sz = tmpImage->w * tmpImage->h; + + // The alpha channel to be filled with alpha values + Uint8 *alphaChannel = new Uint8[sz]; + // Figure out whether the image uses its alpha layer if (!tmpImage->format->palette) { @@ -660,19 +661,19 @@ Image *Image::_SDLload(SDL_Surface *tmpImage) else { if (SDL_ALPHA_OPAQUE != 255) + { hasAlpha = true; - memset(alphaChannel, SDL_ALPHA_OPAQUE, sz); -// for (int i = 0; i < sz; ++ i) -// alphaChannel[i] = SDL_ALPHA_OPAQUE; + memset(alphaChannel, SDL_ALPHA_OPAQUE, sz); + } } } else { if (SDL_ALPHA_OPAQUE != 255) + { hasAlpha = true; - memset(alphaChannel, SDL_ALPHA_OPAQUE, sz); -// for (int i = 0; i < sz; ++ i) -// alphaChannel[i] = SDL_ALPHA_OPAQUE; + memset(alphaChannel, SDL_ALPHA_OPAQUE, sz); + } } SDL_Surface *image; @@ -702,7 +703,6 @@ Image *Image::_SDLload(SDL_Surface *tmpImage) if (converted) SDL_FreeSurface(tmpImage); -// SDL_SetColorKey(image, SDL_SRCCOLORKEY | SDL_RLEACCEL, 0); return new Image(image, hasAlpha, alphaChannel); } |