diff options
Diffstat (limited to 'src')
157 files changed, 1876 insertions, 2249 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 66ec51a6c..d4ae8079b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -401,6 +401,8 @@ SET(SRCS resources/animation.h resources/beinginfo.cpp resources/beinginfo.h + resources/chardb.cpp + resources/chardb.h resources/colordb.cpp resources/colordb.h resources/dye.cpp diff --git a/src/Makefile.am b/src/Makefile.am index 4b1d224bc..6ab63bc70 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -309,6 +309,8 @@ manaplus_SOURCES += gui/widgets/avatarlistbox.cpp \ resources/animation.h \ resources/beinginfo.cpp \ resources/beinginfo.h \ + resources/chardb.cpp \ + resources/chardb.h \ resources/colordb.cpp \ resources/colordb.h \ resources/dye.cpp \ diff --git a/src/actor.cpp b/src/actor.cpp index 095f3d959..150f6042b 100644 --- a/src/actor.cpp +++ b/src/actor.cpp @@ -29,7 +29,8 @@ #include "debug.h" Actor::Actor(): - mMap(nullptr) + mMap(nullptr), + mYDiff(0) {} Actor::~Actor() diff --git a/src/actor.h b/src/actor.h index 654141221..9afaff93d 100644 --- a/src/actor.h +++ b/src/actor.h @@ -88,6 +88,12 @@ public: { return static_cast<int>(mPos.y); } /** + * Returns the pixel Y coordinate of the actor for sorting only. + */ + virtual int getSortPixelY() const + { return static_cast<int>(mPos.y) - mYDiff; } + + /** * Returns the x coordinate in tiles of the actor. */ virtual int getTileX() const; @@ -121,6 +127,7 @@ public: protected: Map *mMap; Vector mPos; /**< Position in pixels relative to map. */ + int mYDiff; private: Actors::iterator mMapActor; diff --git a/src/actorspritemanager.h b/src/actorspritemanager.h index d2d9af108..f1f83634d 100644 --- a/src/actorspritemanager.h +++ b/src/actorspritemanager.h @@ -30,12 +30,6 @@ #include <vector> -#ifdef __GNUC__ -#define A_UNUSED __attribute__ ((unused)) -#else -#define A_UNUSED -#endif - class LocalPlayer; class Map; diff --git a/src/animatedsprite.cpp b/src/animatedsprite.cpp index c1f1cac85..5277ddf33 100644 --- a/src/animatedsprite.cpp +++ b/src/animatedsprite.cpp @@ -42,7 +42,9 @@ AnimatedSprite::AnimatedSprite(SpriteDef *sprite): mSprite(sprite), mAction(nullptr), mAnimation(nullptr), - mFrame(nullptr) + mFrame(nullptr), + mNumber(100), + mNumber1(100) { mAlpha = 1.0f; @@ -90,7 +92,7 @@ bool AnimatedSprite::play(std::string spriteAction) if (!mSprite) return false; - Action *action = mSprite->getAction(spriteAction); + Action *action = mSprite->getAction(spriteAction, mNumber); if (!action) return false; @@ -313,3 +315,19 @@ void *AnimatedSprite::getHash() // return mAnimation; return this; } + +bool AnimatedSprite::updateNumber(unsigned num) +{ + if (mNumber1 != num) + { + mNumber1 = num; + mNumber = mSprite->findNumber(num); + if (!mNumber) + { + mNumber = 100; + return false; + } + return true; + } + return false; +} diff --git a/src/animatedsprite.h b/src/animatedsprite.h index 2a2cfb8d8..16bcdf2da 100644 --- a/src/animatedsprite.h +++ b/src/animatedsprite.h @@ -84,6 +84,8 @@ class AnimatedSprite : public Sprite virtual void *getHash(); + bool updateNumber(unsigned num); + private: bool updateCurrentAnimation(unsigned int dt); @@ -97,6 +99,8 @@ class AnimatedSprite : public Sprite Action *mAction; /**< The currently active action. */ Animation *mAnimation; /**< The currently active animation. */ Frame *mFrame; /**< The currently active frame. */ + unsigned mNumber; + unsigned mNumber1; }; #endif diff --git a/src/being.cpp b/src/being.cpp index b344e9709..736d64f1a 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -253,7 +253,8 @@ Being::Being(int id, Type type, Uint16 subtype, Map *map): mAdvanced(false), mShop(false), mAway(false), - mInactive(false) + mInactive(false), + mNumber(100) { mSpriteRemap = new int[20]; mSpriteHide = new int[20]; @@ -287,6 +288,7 @@ Being::Being(int id, Type type, Uint16 subtype, Map *map): updateColors(); resetCounters(); + updatePercentHP(); } Being::~Being() @@ -660,7 +662,10 @@ void Being::takeDamage(Being *attacker, int amount, AttackType type) } if (mType == MONSTER) + { + updatePercentHP(); updateName(); + } else if (mType == PLAYER && socialWindow && getName() != "") socialWindow->updateAvatar(getName()); @@ -899,9 +904,6 @@ void Being::setGuild(Guild *guild) if (old) old->removeMember(mName); -// if (guild) -// guild->addMember(mId, mName); - updateColors(); if (this == player_node && socialWindow) @@ -1017,6 +1019,8 @@ void Being::setAction(Action action, int attackType A_UNUSED) currentAction = SpriteAction::DEAD; if (mInfo) sound.playSfx(mInfo->getSound(SOUND_EVENT_DIE), mX, mY); + if (mType == MONSTER) + mYDiff = 31; break; case STAND: currentAction = SpriteAction::STAND; @@ -2100,6 +2104,8 @@ void Being::setHP(int hp) mHP = hp; if (mMaxHP < mHP) mMaxHP = mHP; + if (mType == MONSTER) + updatePercentHP(); } void Being::setMaxHP(int hp) @@ -2131,7 +2137,6 @@ void Being::recalcSpritesOrder() std::vector<int> slotRemap; std::map<int, int> itemSlotRemap; -// logger->log("preparation start"); std::vector<int>::iterator it; int oldHide[20]; int dir = mSpriteDirection; @@ -2171,22 +2176,48 @@ void Being::recalcSpritesOrder() { int remSprite = itr->first; const std::map<int, int> &itemReplacer = itr->second; - if (itemReplacer.empty()) - { - mSpriteHide[remSprite] = 1; + if (remSprite >= 0) + { // slot known + if (itemReplacer.empty()) + { + mSpriteHide[remSprite] = 1; + } + else + { + std::map<int, int>::const_iterator repIt + = itemReplacer.find(mSpriteIDs[remSprite]); + if (repIt != itemReplacer.end()) + { + mSpriteHide[remSprite] = repIt->second; + if (repIt->second != 1) + { + setSprite(remSprite, repIt->second, + mSpriteColors[remSprite], + 1, false, true); + } + } + } } else - { + { // slot unknown. Search for real slot, this can be slow std::map<int, int>::const_iterator repIt - = itemReplacer.find(mSpriteIDs[remSprite]); - if (repIt != itemReplacer.end()) + = itemReplacer.begin(); + std::map<int, int>::const_iterator repIt_end + = itemReplacer.end(); + for (; repIt != repIt_end; ++ repIt) { - mSpriteHide[remSprite] = repIt->second; - if (repIt->second != 1) + for (unsigned slot2 = 0; slot2 < sz; slot2 ++) { - setSprite(remSprite, repIt->second, - mSpriteColors[remSprite], - 1, false, true); + if (mSpriteIDs[slot2] == repIt->first) + { + mSpriteHide[slot2] = repIt->second; + if (repIt->second != 1) + { + setSprite(slot2, repIt->second, + mSpriteColors[slot2], + 1, false, true); + } + } } } } @@ -2459,7 +2490,6 @@ void Being::saveComment(const std::string &name, return; } dir += stringToHexPath(name); -// logger->log("save to: %s", dir.c_str()); ResourceManager *resman = ResourceManager::getInstance(); resman->saveTextFile(dir, "comment.txt", name + "\n" + comment); } @@ -2484,7 +2514,6 @@ void Being::setEmote(Uint8 emotion, int emote_time) updateName(); addToCache(); } -// logger->log("flags: %d", emotion - FLAG_SPECIAL); } else { @@ -2493,6 +2522,23 @@ void Being::setEmote(Uint8 emotion, int emote_time) } } +void Being::updatePercentHP() +{ + if (!mMaxHP || !serverVersion) + return; + unsigned num = 0; + if (mHP) + { + num = mHP * 100 / mMaxHP; + if (num != mNumber) + { + mNumber = num; + if (updateNumber(mNumber)) + setAction(mAction); + } + } +} + BeingEquipBackend::BeingEquipBackend(Being *being): mBeing(being) { diff --git a/src/being.h b/src/being.h index 9ee60fcdf..f1cae8df7 100644 --- a/src/being.h +++ b/src/being.h @@ -23,12 +23,6 @@ #ifndef BEING_H #define BEING_H -#ifdef __GNUC__ -#define A_UNUSED __attribute__ ((unused)) -#else -#define A_UNUSED -#endif - #include "actorsprite.h" #include "configlistener.h" #include "equipment.h" @@ -767,6 +761,8 @@ class Being : public ActorSprite, public ConfigListener void attack2(Being *target = nullptr, bool keep = false, bool dontChangeEquipment = false); + void updatePercentHP(); + protected: /** * Sets the new path for this being. @@ -909,6 +905,7 @@ class Being : public ActorSprite, public ConfigListener bool mShop; bool mAway; bool mInactive; + unsigned mNumber; }; extern std::list<BeingCacheEntry*> beingInfoCache; diff --git a/src/chatlogger.cpp b/src/chatlogger.cpp index 067265138..0299a6fe3 100644 --- a/src/chatlogger.cpp +++ b/src/chatlogger.cpp @@ -40,11 +40,16 @@ #include "logger.h" #include "configuration.h" +#include "utils/mkdir.h" #include "utils/stringutils.h" #include "debug.h" -ChatLogger::ChatLogger() +ChatLogger::ChatLogger() : + mLogDir(""), + mBaseLogDir(""), + mServerName(""), + mLogFileName("") { } @@ -60,6 +65,7 @@ void ChatLogger::setLogFile(const std::string &logFilename) mLogFile.close(); mLogFile.open(logFilename.c_str(), std::ios_base::app); + mLogFileName = logFilename; if (!mLogFile.is_open()) { @@ -77,19 +83,19 @@ void ChatLogger::setLogDir(const std::string &logDir) DIR *dir = opendir(mLogDir.c_str()); if (!dir) - makeDir(mLogDir); + mkdir_r(mLogDir.c_str()); else closedir(dir); } void ChatLogger::log(std::string str) { - std::string dateStr = getDateString(); - if (!mLogFile.is_open() || dateStr != mLogDate) + std::string dateStr = getDir(); + std::string logFileName = strprintf("%s/#General.log", dateStr.c_str()); + if (!mLogFile.is_open() || logFileName != mLogFileName) { - mLogDate = dateStr; - setLogFile(strprintf("%s/%s/#General_%s.log", mLogDir.c_str(), - mServerName.c_str(), dateStr.c_str())); + setLogDir(dateStr); + setLogFile(logFileName); } str = removeColors(str); @@ -99,21 +105,21 @@ void ChatLogger::log(std::string str) void ChatLogger::log(std::string name, std::string str) { std::ofstream logFile; - logFile.open(strprintf("%s/%s/%s_%s.log", mLogDir.c_str(), - mServerName.c_str(), secureName(name).c_str(), - getDateString().c_str()).c_str(), std::ios_base::app); + std::string dateStr = getDir(); + std::string logFileName = strprintf("%s/%s.log", + dateStr.c_str(), secureName(name).c_str()); - if (!logFile.is_open()) - return; + if (!mLogFile.is_open() || logFileName != mLogFileName) + { + setLogDir(dateStr); + setLogFile(logFileName); + } str = removeColors(str); - writeTo(logFile, str); - - if (logFile.is_open()) - logFile.close(); + writeTo(mLogFile, str); } -std::string ChatLogger::getDateString() const +std::string ChatLogger::getDir() const { std::string date; @@ -124,8 +130,11 @@ std::string ChatLogger::getDateString() const time (&rawtime); timeinfo = localtime(&rawtime); - strftime(buffer, 79, "%y-%m-%d", timeinfo); - date = buffer; + strftime(buffer, 79, "%Y-%m/%d", timeinfo); + + date = strprintf("%s/%s/%s", mBaseLogDir.c_str(), + mServerName.c_str(), buffer); + return date; } @@ -164,29 +173,20 @@ void ChatLogger::setServerName(const std::string &serverName) { DIR *dir = opendir((mLogDir + "/" + mServerName).c_str()); if (!dir) - makeDir(mLogDir + "/" + mServerName); + mkdir_r((mLogDir + "/" + mServerName).c_str()); else closedir(dir); } } -void ChatLogger::makeDir(const std::string &dir) -{ -#ifdef WIN32 - mkdir(dir.c_str()); -#else - mkdir(dir.c_str(), 0750); -#endif -} - void ChatLogger::loadLast(std::string name, std::list<std::string> &list, unsigned n) { std::ifstream logFile; + std::string fileName = strprintf("%s/%s.log", getDir().c_str(), + secureName(name).c_str()); - logFile.open(strprintf("%s/%s/%s_%s.log", mLogDir.c_str(), - mServerName.c_str(), secureName(name).c_str(), - getDateString().c_str()).c_str(), std::ios::in); + logFile.open(fileName.c_str(), std::ios::in); if (!logFile.is_open()) return; diff --git a/src/chatlogger.h b/src/chatlogger.h index 6e096ac89..23d5d4a86 100644 --- a/src/chatlogger.h +++ b/src/chatlogger.h @@ -40,8 +40,6 @@ class ChatLogger */ ~ChatLogger(); - void setLogDir(const std::string &logDir); - /** * Enters a message in the log. The message will be timestamped. */ @@ -52,26 +50,30 @@ class ChatLogger void loadLast(std::string name, std::list<std::string> &list, unsigned n); - std::string getDateString() const; + std::string getDir() const; std::string secureName(std::string &str) const; void setServerName(const std::string &serverName); + void setBaseLogDir(const std::string &logDir) + { mBaseLogDir = logDir; } + private: /** * Sets the file to log to and opens it */ void setLogFile(const std::string &logFilename); - void writeTo(std::ofstream &file, const std::string &str) const; + void setLogDir(const std::string &logDir); - void makeDir(const std::string &dir); + void writeTo(std::ofstream &file, const std::string &str) const; std::ofstream mLogFile; std::string mLogDir; + std::string mBaseLogDir; std::string mServerName; - std::string mLogDate; + std::string mLogFileName; }; extern ChatLogger *chatLogger; diff --git a/src/client.cpp b/src/client.cpp index 8a6ec2116..d8bb747fb 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -85,6 +85,7 @@ #include "net/worldinfo.h" #include "resources/beinginfo.h" +#include "resources/chardb.h" #include "resources/colordb.h" #include "resources/emotedb.h" #include "resources/image.h" @@ -322,9 +323,9 @@ Client::Client(const Options &options): chatLogger = new ChatLogger; if (mOptions.chatLogDir == "") - chatLogger->setLogDir(mLocalDataDir + std::string("/logs/")); + chatLogger->setBaseLogDir(mLocalDataDir + std::string("/logs/")); else - chatLogger->setLogDir(mOptions.chatLogDir); + chatLogger->setBaseLogDir(mOptions.chatLogDir); logger->setLogToStandardOut(config.getBoolValue("logToStandardOut")); @@ -368,6 +369,8 @@ Client::Client(const Options &options): Image::setEnableAlpha(config.getFloatValue("guialpha") != 1.0f); #endif + resman->addToSearchPath(PKG_DATADIR "data/perserver/default", false); + #if defined __APPLE__ CFBundleRef mainBundle = CFBundleGetMainBundle(); CFURLRef resourcesURL = CFBundleCopyResourcesDirectoryURL(mainBundle); @@ -649,6 +652,7 @@ Client::~Client() SDL_RemoveTimer(mSecondsCounterId); // Unload XML databases + CharDB::unload(); ColorDB::unload(); EmoteDB::unload(); ItemDB::unload(); @@ -1111,6 +1115,7 @@ int Client::exec() Mana::Event::trigger(CHANNEL_CLIENT, evt2); // Load XML databases + CharDB::load(); ColorDB::load(); MapDB::load(); ItemDB::load(); diff --git a/src/client.h b/src/client.h index 776e9aa3d..b3fc0d676 100644 --- a/src/client.h +++ b/src/client.h @@ -36,12 +36,6 @@ #include <sys/time.h> -#ifdef __GNUC__ -#define A_UNUSED __attribute__ ((unused)) -#else -#define A_UNUSED -#endif - class Button; class Desktop; class LoginData; diff --git a/src/commandhandler.h b/src/commandhandler.h index 809e9e517..f8b44e04f 100644 --- a/src/commandhandler.h +++ b/src/commandhandler.h @@ -31,12 +31,6 @@ class ChatTab; extern ChatTab *localChatTab; -#ifdef __GNUC__ -#define A_UNUSED __attribute__ ((unused)) -#else -#define A_UNUSED -#endif - #define BOOLEAN_OPTIONS _("Options to /%s are \"yes\", \"no\", \"true\", "\ "\"false\", \"1\", \"0\".") @@ -263,23 +257,21 @@ class CommandHandler */ void handleNavigate(const std::string &args, ChatTab *tab); - void handleMail(const std::string &args, ChatTab *tab A_UNUSED); + void handleMail(const std::string &args, ChatTab *tab); void handleHack(const std::string &args, ChatTab *tab); - void handlePriceLoad(const std::string &args A_UNUSED, - ChatTab *tab A_UNUSED); + void handlePriceLoad(const std::string &args, ChatTab *tab); - void handlePriceSave(const std::string &args A_UNUSED, - ChatTab *tab A_UNUSED); + void handlePriceSave(const std::string &args, ChatTab *tab); - void handleTrade(const std::string &args, ChatTab *tab A_UNUSED); + void handleTrade(const std::string &args, ChatTab *tab); - void handleDisconnect(const std::string &args, ChatTab *tab A_UNUSED); + void handleDisconnect(const std::string &args, ChatTab *tab); - void handleUndress(const std::string &args, ChatTab *tab A_UNUSED); + void handleUndress(const std::string &args, ChatTab *tab); - void handleAttack(const std::string &args, ChatTab *tab A_UNUSED); + void handleAttack(const std::string &args, ChatTab *tab); void handleDirs(const std::string &args, ChatTab *tab); @@ -289,22 +281,17 @@ class CommandHandler void handleUptime(const std::string &args, ChatTab *tab); - void handleAddAttack(const std::string &args, ChatTab *tab A_UNUSED); + void handleAddAttack(const std::string &args, ChatTab *tab); - void handleAddPriorityAttack(const std::string &args, - ChatTab *tab A_UNUSED); + void handleAddPriorityAttack(const std::string &args, ChatTab *tab); - void handleRemoveAttack(const std::string &args, - ChatTab *tab A_UNUSED); + void handleRemoveAttack(const std::string &args, ChatTab *tab); - void handleAddIgnoreAttack(const std::string &args, - ChatTab *tab A_UNUSED); + void handleAddIgnoreAttack(const std::string &args, ChatTab *tab); - void handleServerIgnoreAll(const std::string &args, - ChatTab *tab A_UNUSED); + void handleServerIgnoreAll(const std::string &args, ChatTab *tab); - void handleServerUnIgnoreAll(const std::string &args, - ChatTab *tab A_UNUSED); + void handleServerUnIgnoreAll(const std::string &args, ChatTab *tab); void handleDump(const std::string &args, ChatTab *tab); @@ -313,7 +300,7 @@ class CommandHandler void outString(ChatTab *tab, const std::string &str, const std::string &def); - void handleCacheInfo(const std::string &args, ChatTab *tab A_UNUSED); + void handleCacheInfo(const std::string &args, ChatTab *tab); bool parse2Int(const std::string &args, int *x, int *y); }; diff --git a/src/compoundsprite.cpp b/src/compoundsprite.cpp index 3ee988cec..912c51404 100644 --- a/src/compoundsprite.cpp +++ b/src/compoundsprite.cpp @@ -544,6 +544,21 @@ void CompoundSprite::initCurrentCacheItem() const } } +bool CompoundSprite::updateNumber(unsigned num) +{ + SpriteConstIterator it, it_end; + bool res(false); + for (it = begin(), it_end = end(); it != it_end; ++ it) + { + if (*it) + { + if ((*it)->updateNumber(num)) + res = true; + } + } + return res; +} + CompoundItem::CompoundItem() : // alpha(1.0f), image(nullptr), diff --git a/src/compoundsprite.h b/src/compoundsprite.h index d1b019057..f29bece7f 100644 --- a/src/compoundsprite.h +++ b/src/compoundsprite.h @@ -119,6 +119,8 @@ public: virtual void setAlpha(float alpha); + bool updateNumber(unsigned num); + private: void redraw() const; diff --git a/src/flooritem.cpp b/src/flooritem.cpp index fa6cbf618..cf1ee16dc 100644 --- a/src/flooritem.cpp +++ b/src/flooritem.cpp @@ -80,6 +80,7 @@ FloorItem::FloorItem(int id, const ItemInfo &info = ItemDB::get(itemId); setupSpriteDisplay(info.getDisplay(), true, 1, info.getDyeColorsString(mColor)); + mYDiff = 31; } const ItemInfo &FloorItem::getInfo() const diff --git a/src/game.cpp b/src/game.cpp index 042bd2423..683ba418b 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -702,753 +702,599 @@ void Game::resetAdjustLevel() mAdjustLevel = 0; } -/** - * The huge input handling method. - */ -void Game::handleInput() +bool Game::handleOutfitsKeys(SDL_Event &event, bool &used) { - if (joystick) - joystick->update(); - - bool wasDown(false); - // Events - SDL_Event event; - while (SDL_PollEvent(&event)) + if (keyboard.isEnabled() + && !chatWindow->isInputFocused() + && !setupWindow->isVisible() + && !player_node->getAway() + && !NpcDialog::isAnyInputFocused() + && !InventoryWindow::isAnyInputFocused()) { - bool used = false; + bool wearOutfit = false; + bool copyOutfit = false; + if (keyboard.isKeyActive(keyboard.KEY_WEAR_OUTFIT)) + wearOutfit = true; - updateHistory(event); - checkKeys(); + if (keyboard.isKeyActive(keyboard.KEY_COPY_OUTFIT)) + copyOutfit = true; - // Keyboard events (for discontinuous keys) - if (event.type == SDL_KEYDOWN) + if (wearOutfit || copyOutfit) { - wasDown = true; - gcn::Window *requestedWindow = nullptr; + int outfitNum = outfitWindow->keyToNumber( + event.key.keysym.sym); + if (outfitNum >= 0) + { + used = true; + if (wearOutfit) + outfitWindow->wearOutfit(outfitNum); + else if (copyOutfit) + outfitWindow->copyOutfit(outfitNum); + } + else + { + if (keyboard.isKeyActive(keyboard.KEY_MOVE_RIGHT)) + outfitWindow->wearNextOutfit(); + else if (keyboard.isKeyActive(keyboard.KEY_MOVE_LEFT)) + outfitWindow->wearPreviousOutfit(); + } + setValidSpeed(); + return true; + } + else if (keyboard.isKeyActive(keyboard.KEY_MOVE_TO_POINT)) + { + int num = outfitWindow->keyToNumber( + event.key.keysym.sym); + if (socialWindow && num >= 0) + { + socialWindow->selectPortal(num); + return true; + } + } + } + return false; +} - if (setupWindow && setupWindow->isVisible() && - keyboard.getNewKeyIndex() > keyboard.KEY_NO_VALUE) +bool Game::handleSwitchKeys(SDL_Event &event, bool &used) +{ + if ((!chatWindow || !chatWindow->isInputFocused()) + && !gui->getFocusHandler()->getModalFocused() + && !player_node->getAway()) + { + NpcDialog *dialog = NpcDialog::getActive(); + if (keyboard.isKeyActive(keyboard.KEY_OK) + && (!dialog || !dialog->isTextInputFocused())) + { + // Close the Browser if opened + if (helpWindow->isVisible()) + helpWindow->setVisible(false); + // Close the config window, cancelling changes if opened + else if (setupWindow->isVisible()) { - keyboard.setNewKey(static_cast<int>(event.key.keysym.sym)); - keyboard.callbackNewKey(); - keyboard.setNewKeyIndex(keyboard.KEY_NO_VALUE); - return; + setupWindow->action(gcn::ActionEvent( + nullptr, "cancel")); + } + else if (dialog) + { + dialog->action(gcn::ActionEvent(nullptr, "ok")); + } + } + if (chatWindow && keyboard.isKeyActive( + keyboard.KEY_TOGGLE_CHAT)) + { + if (!InventoryWindow::isAnyInputFocused()) + { + if (chatWindow->requestChatFocus()) + used = true; } + } + if (dialog) + { + if (keyboard.isKeyActive(keyboard.KEY_MOVE_UP)) + dialog->move(1); + else if (keyboard.isKeyActive(keyboard.KEY_MOVE_DOWN)) + dialog->move(-1); + } + } - // send straight to gui for certain windows - if (quitDialog || TextDialog::isActive() || - NpcPostDialog::isActive()) + if (chatWindow && ((!chatWindow->isInputFocused() && + !NpcDialog::isAnyInputFocused() && + !InventoryWindow::isAnyInputFocused()) + || (event.key.keysym.mod & KMOD_ALT))) + { + if (keyboard.isKeyActive(keyboard.KEY_PREV_CHAT_TAB)) + { + chatWindow->prevTab(); + return true; + } + else if (keyboard.isKeyActive(keyboard.KEY_NEXT_CHAT_TAB)) + { + chatWindow->nextTab(); + return true; + } + else if (keyboard.isKeyActive(keyboard.KEY_PREV_SOCIAL_TAB)) + { + socialWindow->prevTab(); + return true; + } + else if (keyboard.isKeyActive(keyboard.KEY_NEXT_SOCIAL_TAB)) + { + socialWindow->nextTab(); + return true; + } + else if (keyboard.isKeyActive(keyboard.KEY_CLOSE_CHAT_TAB)) + { + chatWindow->closeTab(); + return true; + } + } + + const int tKey = keyboard.getKeyIndex(event.key.keysym.sym); + switch (tKey) + { + case KeyboardConfig::KEY_SCROLL_CHAT_UP: + if (chatWindow && chatWindow->isVisible()) { - try + chatWindow->scroll(-DEFAULT_CHAT_WINDOW_SCROLL); + used = true; + } + break; + case KeyboardConfig::KEY_SCROLL_CHAT_DOWN: + if (chatWindow && chatWindow->isVisible()) + { + chatWindow->scroll(DEFAULT_CHAT_WINDOW_SCROLL); + used = true; + return true; + } + break; + case KeyboardConfig::KEY_WINDOW_HELP: + // In-game Help + if (helpWindow) + { + if (helpWindow->isVisible()) { - guiInput->pushInput(event); + helpWindow->setVisible(false); } - catch (const gcn::Exception &e) + else { - const char* err = e.getMessage().c_str(); - logger->log("Warning: guichan input exception: %s", err); + helpWindow->loadHelp("index"); + helpWindow->requestMoveToTop(); } - return; - } - - if (chatWindow && !chatWindow->isInputFocused() - && keyboard.isKeyActive(keyboard.KEY_RIGHT_CLICK)) - { - int mouseX, mouseY; - SDL_GetMouseState(&mouseX, &mouseY); - - gcn::MouseEvent event2(viewport, false, false, false, false, - 0, gcn::MouseEvent::RIGHT, mouseX, mouseY, 1); - if (viewport) - viewport->mousePressed(event2); - continue; } - - // Mode switch to emotes - if (keyboard.isKeyActive(keyboard.KEY_EMOTE)) + used = true; + break; + // Quitting confirmation dialog + case KeyboardConfig::KEY_QUIT: + if (!chatWindow || !chatWindow->isInputFocused()) { - // Emotions - int emotion = keyboard.getKeyEmoteOffset(event.key.keysym.sym); - if (emotion) + if (viewport && viewport->isPopupMenuVisible()) { - if (emoteShortcut) - emoteShortcut->useEmote(emotion); - used = true; - setValidSpeed(); - return; + viewport->closePopupMenu(); + } + else + { + quitDialog = new QuitDialog(&quitDialog); + quitDialog->requestMoveToTop(); } + return true; } + break; + default: + break; + } - if (keyboard.isEnabled() - && !chatWindow->isInputFocused() - && !setupWindow->isVisible() - && !player_node->getAway() - && !NpcDialog::isAnyInputFocused() - && !InventoryWindow::isAnyInputFocused()) + if (keyboard.isEnabled() + && (!chatWindow || !chatWindow->isInputFocused()) + && !NpcDialog::isAnyInputFocused() + && (!player_node || !player_node->getAway())) + { + if (!gui->getFocusHandler()->getModalFocused() + && mValidSpeed + && (!setupWindow || !setupWindow->isVisible()) + && !InventoryWindow::isAnyInputFocused()) + { + switch (tKey) { - bool wearOutfit = false; - bool copyOutfit = false; - if (keyboard.isKeyActive(keyboard.KEY_WEAR_OUTFIT)) - wearOutfit = true; + case KeyboardConfig::KEY_QUICK_DROP: + if (dropShortcut) + dropShortcut->dropFirst(); + break; - if (keyboard.isKeyActive(keyboard.KEY_COPY_OUTFIT)) - copyOutfit = true; + case KeyboardConfig::KEY_QUICK_DROPN: + if (dropShortcut) + dropShortcut->dropItems(); + break; - if (wearOutfit || copyOutfit) - { - int outfitNum = outfitWindow->keyToNumber( - event.key.keysym.sym); - if (outfitNum >= 0) + case KeyboardConfig::KEY_SWITCH_QUICK_DROP: + if (player_node) { - used = true; - if (wearOutfit) - outfitWindow->wearOutfit(outfitNum); - else if (copyOutfit) - outfitWindow->copyOutfit(outfitNum); + if (!player_node->getDisableGameModifiers()) + player_node->changeQuickDropCounter(); } - else + break; + + case KeyboardConfig::KEY_MAGIC_INMA1: + if (actorSpriteManager) + actorSpriteManager->healTarget(); + setValidSpeed(); + break; + + case KeyboardConfig::KEY_MAGIC_ITENPLZ: + if (Net::getPlayerHandler()->canUseMagic() + && PlayerInfo::getAttribute(MP) >= 3) { - if (keyboard.isKeyActive(keyboard.KEY_MOVE_RIGHT)) - outfitWindow->wearNextOutfit(); - else if (keyboard.isKeyActive(keyboard.KEY_MOVE_LEFT)) - outfitWindow->wearPreviousOutfit(); + actorSpriteManager->itenplz(); } setValidSpeed(); - continue; - } - else if (keyboard.isKeyActive(keyboard.KEY_MOVE_TO_POINT)) - { - int num = outfitWindow->keyToNumber( - event.key.keysym.sym); - if (socialWindow && num >= 0) + break; + + case KeyboardConfig::KEY_CRAZY_MOVES: + if (player_node) + player_node->crazyMove(); + break; + + case KeyboardConfig::KEY_CHANGE_CRAZY_MOVES_TYPE: + if (player_node) { - socialWindow->selectPortal(num); - continue; + if (!player_node->getDisableGameModifiers()) + player_node->changeCrazyMoveType(); } - } - } + break; - if ((!chatWindow || !chatWindow->isInputFocused()) - && !gui->getFocusHandler()->getModalFocused() - && !player_node->getAway()) - { - NpcDialog *dialog = NpcDialog::getActive(); - if (keyboard.isKeyActive(keyboard.KEY_OK) - && (!dialog || !dialog->isTextInputFocused())) - { - // Close the Browser if opened - if (helpWindow->isVisible()) - helpWindow->setVisible(false); - // Close the config window, cancelling changes if opened - else if (setupWindow->isVisible()) + case KeyboardConfig::KEY_CHANGE_PICKUP_TYPE: + if (player_node) { - setupWindow->action(gcn::ActionEvent( - nullptr, "cancel")); + if (!player_node->getDisableGameModifiers()) + player_node->changePickUpType(); } - else if (dialog) + break; + + case KeyboardConfig::KEY_MOVE_TO_TARGET: + if (player_node) { - dialog->action(gcn::ActionEvent(nullptr, "ok")); + if (!keyboard.isKeyActive( + keyboard.KEY_TARGET_ATTACK) + && !keyboard.isKeyActive(keyboard.KEY_ATTACK)) + { + player_node->moveToTarget(); + } } - } - if (chatWindow && keyboard.isKeyActive( - keyboard.KEY_TOGGLE_CHAT)) - { - if (!InventoryWindow::isAnyInputFocused()) + break; + + case KeyboardConfig::KEY_MOVE_TO_HOME: + if (player_node) { - if (chatWindow->requestChatFocus()) - used = true; + if (!keyboard.isKeyActive( + keyboard.KEY_TARGET_ATTACK) + && !keyboard.isKeyActive(keyboard.KEY_ATTACK)) + { + player_node->moveToHome(); + } + setValidSpeed(); } - } - if (dialog) - { - if (keyboard.isKeyActive(keyboard.KEY_MOVE_UP)) - dialog->move(1); - else if (keyboard.isKeyActive(keyboard.KEY_MOVE_DOWN)) - dialog->move(-1); - } - } + break; - if (chatWindow && ((!chatWindow->isInputFocused() && - !NpcDialog::isAnyInputFocused() && - !InventoryWindow::isAnyInputFocused()) - || (event.key.keysym.mod & KMOD_ALT))) - { - if (keyboard.isKeyActive(keyboard.KEY_PREV_CHAT_TAB)) - { - chatWindow->prevTab(); - return; - } - else if (keyboard.isKeyActive(keyboard.KEY_NEXT_CHAT_TAB)) - { - chatWindow->nextTab(); - return; - } - else if (keyboard.isKeyActive(keyboard.KEY_PREV_SOCIAL_TAB)) - { - socialWindow->prevTab(); - return; - } - else if (keyboard.isKeyActive(keyboard.KEY_NEXT_SOCIAL_TAB)) - { - socialWindow->nextTab(); - return; - } - else if (keyboard.isKeyActive(keyboard.KEY_CLOSE_CHAT_TAB)) - { - chatWindow->closeTab(); - return; - } - } + case KeyboardConfig::KEY_SET_HOME: + if (player_node) + player_node->setHome(); + break; - const int tKey = keyboard.getKeyIndex(event.key.keysym.sym); - switch (tKey) - { - case KeyboardConfig::KEY_SCROLL_CHAT_UP: - if (chatWindow && chatWindow->isVisible()) + case KeyboardConfig::KEY_INVERT_DIRECTION: + if (player_node) { - chatWindow->scroll(-DEFAULT_CHAT_WINDOW_SCROLL); - used = true; + if (!player_node->getDisableGameModifiers()) + player_node->invertDirection(); } break; - case KeyboardConfig::KEY_SCROLL_CHAT_DOWN: - if (chatWindow && chatWindow->isVisible()) + + case KeyboardConfig::KEY_CHANGE_ATTACK_WEAPON_TYPE: + if (player_node) { - chatWindow->scroll(DEFAULT_CHAT_WINDOW_SCROLL); - used = true; - return; + if (!player_node->getDisableGameModifiers()) + player_node->changeAttackWeaponType(); } break; - case KeyboardConfig::KEY_WINDOW_HELP: - // In-game Help - if (helpWindow) + + case KeyboardConfig::KEY_CHANGE_ATTACK_TYPE: + if (player_node) { - if (helpWindow->isVisible()) - { - helpWindow->setVisible(false); - } - else - { - helpWindow->loadHelp("index"); - helpWindow->requestMoveToTop(); - } + if (!player_node->getDisableGameModifiers()) + player_node->changeAttackType(); } - used = true; break; - // Quitting confirmation dialog - case KeyboardConfig::KEY_QUIT: - if (!chatWindow || !chatWindow->isInputFocused()) + + case KeyboardConfig::KEY_CHANGE_FOLLOW_MODE: + if (player_node) { - if (viewport && viewport->isPopupMenuVisible()) - { - viewport->closePopupMenu(); - } - else - { - quitDialog = new QuitDialog(&quitDialog); - quitDialog->requestMoveToTop(); - } - return; + if (!player_node->getDisableGameModifiers()) + player_node->changeFollowMode(); } break; - default: + + case KeyboardConfig::KEY_CHANGE_IMITATION_MODE: + if (player_node) + { + if (!player_node->getDisableGameModifiers()) + player_node->changeImitationMode(); + } break; - } - if (keyboard.isEnabled() && (!chatWindow - || !chatWindow->isInputFocused()) - && !gui->getFocusHandler()->getModalFocused() - && mValidSpeed - && (!setupWindow || !setupWindow->isVisible()) - && (!player_node || !player_node->getAway()) - && !NpcDialog::isAnyInputFocused() - && !InventoryWindow::isAnyInputFocused()) - { - switch (tKey) - { - case KeyboardConfig::KEY_QUICK_DROP: - if (dropShortcut) - dropShortcut->dropFirst(); - break; + case KeyboardConfig::KEY_MAGIC_ATTACK: + if (player_node) + player_node->magicAttack(); + break; - case KeyboardConfig::KEY_QUICK_DROPN: - if (dropShortcut) - dropShortcut->dropItems(); - break; + case KeyboardConfig::KEY_SWITCH_MAGIC_ATTACK: + if (player_node) + { + if (!player_node->getDisableGameModifiers()) + player_node->switchMagicAttack(); + } + break; - case KeyboardConfig::KEY_SWITCH_QUICK_DROP: - if (player_node) - { - if (!player_node->getDisableGameModifiers()) - player_node->changeQuickDropCounter(); - } - break; + case KeyboardConfig::KEY_SWITCH_PVP_ATTACK: + if (player_node) + { + if (!player_node->getDisableGameModifiers()) + player_node->switchPvpAttack(); + } + break; - case KeyboardConfig::KEY_MAGIC_INMA1: - if (actorSpriteManager) - actorSpriteManager->healTarget(); - setValidSpeed(); - break; + case KeyboardConfig::KEY_CHANGE_MOVE_TO_TARGET: + if (player_node) + { + if (!player_node->getDisableGameModifiers()) + player_node->changeMoveToTargetType(); + } + break; - case KeyboardConfig::KEY_MAGIC_ITENPLZ: - if (Net::getPlayerHandler()->canUseMagic() - && PlayerInfo::getAttribute(MP) >= 3) - { - actorSpriteManager->itenplz(); - } - setValidSpeed(); - break; + case KeyboardConfig::KEY_COPY_EQUIPED_OUTFIT: + if (outfitWindow) + outfitWindow->copyFromEquiped(); + break; - case KeyboardConfig::KEY_CRAZY_MOVES: - if (player_node) - player_node->crazyMove(); - break; + case KeyboardConfig::KEY_DISABLE_GAME_MODIFIERS: + if (player_node) + player_node->switchGameModifiers(); + break; - case KeyboardConfig::KEY_CHANGE_CRAZY_MOVES_TYPE: - if (player_node) - { - if (!player_node->getDisableGameModifiers()) - player_node->changeCrazyMoveType(); - } - break; + case KeyboardConfig::KEY_CHANGE_AUDIO: + sound.changeAudio(); + break; - case KeyboardConfig::KEY_CHANGE_PICKUP_TYPE: - if (player_node) - { - if (!player_node->getDisableGameModifiers()) - player_node->changePickUpType(); - } - break; + case KeyboardConfig::KEY_AWAY: + if (player_node) + { + player_node->changeAwayMode(); + setValidSpeed(); + } + break; - case KeyboardConfig::KEY_MOVE_TO_TARGET: - if (player_node) - { - if (!keyboard.isKeyActive( - keyboard.KEY_TARGET_ATTACK) - && !keyboard.isKeyActive(keyboard.KEY_ATTACK)) - { - player_node->moveToTarget(); - } - } - break; + case KeyboardConfig::KEY_CAMERA: + if (player_node && viewport) + { + if (!player_node->getDisableGameModifiers()) + viewport->toggleCameraMode(); + setValidSpeed(); + } + break; - case KeyboardConfig::KEY_MOVE_TO_HOME: - if (player_node) + default: + break; + } + } + + gcn::Window *requestedWindow = nullptr; + + if (!NpcDialog::isAnyInputFocused() + && !keyboard.isKeyActive(keyboard.KEY_TARGET) + && !keyboard.isKeyActive(keyboard.KEY_UNTARGET)) + { + if (setupWindow && setupWindow->isVisible()) + { + if (tKey == KeyboardConfig::KEY_WINDOW_SETUP) + { + setupWindow->doCancel(); + used = true; + } + } + else + { + // Do not activate shortcuts if tradewindow is visible + if (itemShortcutWindow && tradeWindow + && !tradeWindow->isVisible() + && !setupWindow->isVisible()) + { + int num = itemShortcutWindow->getTabIndex(); + if (num >= 0 && num < SHORTCUT_TABS) + { + // Checks if any item shortcut is pressed. + for (int i = KeyboardConfig::KEY_SHORTCUT_1; + i <= KeyboardConfig::KEY_SHORTCUT_20; + i ++) { - if (!keyboard.isKeyActive( - keyboard.KEY_TARGET_ATTACK) - && !keyboard.isKeyActive(keyboard.KEY_ATTACK)) + if (tKey == i && !used) { - player_node->moveToHome(); + itemShortcut[num]->useItem( + i - KeyboardConfig::KEY_SHORTCUT_1); + break; } - setValidSpeed(); } - break; + } + } - case KeyboardConfig::KEY_SET_HOME: + switch (tKey) + { + case KeyboardConfig::KEY_PICKUP: if (player_node) - player_node->setHome(); + player_node->pickUpItems(); + used = true; break; - - case KeyboardConfig::KEY_INVERT_DIRECTION: + case KeyboardConfig::KEY_SIT: + // Player sit action if (player_node) { - if (!player_node->getDisableGameModifiers()) - player_node->invertDirection(); + if (keyboard.isKeyActive(keyboard.KEY_EMOTE)) + player_node->updateSit(); + else + player_node->toggleSit(); } + used = true; break; - - case KeyboardConfig::KEY_CHANGE_ATTACK_WEAPON_TYPE: - if (player_node) + case KeyboardConfig::KEY_HIDE_WINDOWS: + // Hide certain windows + if (!chatWindow || !chatWindow->isInputFocused()) { - if (!player_node->getDisableGameModifiers()) - player_node->changeAttackWeaponType(); + if (statusWindow) + statusWindow->setVisible(false); + if (inventoryWindow) + inventoryWindow->setVisible(false); + if (shopWindow) + shopWindow->setVisible(false); + if (skillDialog) + skillDialog->setVisible(false); + if (setupWindow) + setupWindow->setVisible(false); + if (equipmentWindow) + equipmentWindow->setVisible(false); + if (helpWindow) + helpWindow->setVisible(false); + if (debugWindow) + debugWindow->setVisible(false); + if (outfitWindow) + outfitWindow->setVisible(false); + if (dropShortcutWindow) + dropShortcutWindow->setVisible(false); + if (spellShortcutWindow) + spellShortcutWindow->setVisible(false); + if (botCheckerWindow) + botCheckerWindow->setVisible(false); + if (socialWindow) + socialWindow->setVisible(false); } break; - - case KeyboardConfig::KEY_CHANGE_ATTACK_TYPE: - if (player_node) - { - if (!player_node->getDisableGameModifiers()) - player_node->changeAttackType(); - } + case KeyboardConfig::KEY_WINDOW_STATUS: + requestedWindow = statusWindow; break; - - case KeyboardConfig::KEY_CHANGE_FOLLOW_MODE: - if (player_node) - { - if (!player_node->getDisableGameModifiers()) - player_node->changeFollowMode(); - } + case KeyboardConfig::KEY_WINDOW_INVENTORY: + requestedWindow = inventoryWindow; break; - - case KeyboardConfig::KEY_CHANGE_IMITATION_MODE: - if (player_node) - { - if (!player_node->getDisableGameModifiers()) - player_node->changeImitationMode(); - } + case KeyboardConfig::KEY_WINDOW_SHOP: + requestedWindow = shopWindow; break; - - case KeyboardConfig::KEY_MAGIC_ATTACK: - if (player_node) - player_node->magicAttack(); + case KeyboardConfig::KEY_WINDOW_EQUIPMENT: + requestedWindow = equipmentWindow; break; - - case KeyboardConfig::KEY_SWITCH_MAGIC_ATTACK: - if (player_node) - { - if (!player_node->getDisableGameModifiers()) - player_node->switchMagicAttack(); - } + case KeyboardConfig::KEY_WINDOW_SKILL: + requestedWindow = skillDialog; break; - - case KeyboardConfig::KEY_SWITCH_PVP_ATTACK: - if (player_node) - { - if (!player_node->getDisableGameModifiers()) - player_node->switchPvpAttack(); - } + case KeyboardConfig::KEY_WINDOW_KILLS: + requestedWindow = killStats; break; - - case KeyboardConfig::KEY_CHANGE_MOVE_TO_TARGET: - if (player_node) - { - if (!player_node->getDisableGameModifiers()) - player_node->changeMoveToTargetType(); - } + case KeyboardConfig::KEY_WINDOW_MINIMAP: + minimap->toggle(); break; - - case KeyboardConfig::KEY_COPY_EQUIPED_OUTFIT: - if (outfitWindow) - outfitWindow->copyFromEquiped(); + case KeyboardConfig::KEY_WINDOW_CHAT: + requestedWindow = chatWindow; break; - - case KeyboardConfig::KEY_DISABLE_GAME_MODIFIERS: - if (player_node) - player_node->switchGameModifiers(); + case KeyboardConfig::KEY_WINDOW_SHORTCUT: + requestedWindow = itemShortcutWindow; break; - - case KeyboardConfig::KEY_CHANGE_AUDIO: - sound.changeAudio(); + case KeyboardConfig::KEY_WINDOW_SETUP: + requestedWindow = setupWindow; break; - - case KeyboardConfig::KEY_AWAY: - if (player_node) - { - player_node->changeAwayMode(); - setValidSpeed(); - } + case KeyboardConfig::KEY_WINDOW_DEBUG: + requestedWindow = debugWindow; break; - - case KeyboardConfig::KEY_CAMERA: - if (player_node && viewport) - { - if (!player_node->getDisableGameModifiers()) - viewport->toggleCameraMode(); - setValidSpeed(); - } + case KeyboardConfig::KEY_WINDOW_SOCIAL: + requestedWindow = socialWindow; break; - - default: + case KeyboardConfig::KEY_WINDOW_EMOTE_SHORTCUT: + requestedWindow = emoteShortcutWindow; break; - } - } - - if (keyboard.isEnabled() - && (!chatWindow || !chatWindow->isInputFocused()) - && !NpcDialog::isAnyInputFocused() - && (!player_node || !player_node->getAway()) - && !keyboard.isKeyActive(keyboard.KEY_TARGET) - && !keyboard.isKeyActive(keyboard.KEY_UNTARGET) - && !InventoryWindow::isAnyInputFocused()) - { -// const int tKey = keyboard.getKeyIndex(event.key.keysym.sym); - - if (setupWindow && setupWindow->isVisible()) - { - if (tKey == KeyboardConfig::KEY_WINDOW_SETUP) - { - setupWindow->doCancel(); + case KeyboardConfig::KEY_WINDOW_OUTFIT: + requestedWindow = outfitWindow; + break; + case KeyboardConfig::KEY_WINDOW_DROP: + requestedWindow = dropShortcutWindow; + break; + case KeyboardConfig::KEY_WINDOW_SPELLS: + requestedWindow = spellShortcutWindow; + break; + case KeyboardConfig::KEY_WINDOW_BOT_CHECKER: + requestedWindow = botCheckerWindow; + break; + case KeyboardConfig::KEY_WINDOW_ONLINE: + requestedWindow = whoIsOnline; + break; + case KeyboardConfig::KEY_SCREENSHOT: + // Screenshot (picture, hence the p) + saveScreenshot(); used = true; - } - } - else - { - // Do not activate shortcuts if tradewindow is visible - if (itemShortcutWindow && tradeWindow - && !tradeWindow->isVisible() - && !setupWindow->isVisible()) - { - int num = itemShortcutWindow->getTabIndex(); - if (num >= 0 && num < SHORTCUT_TABS) + break; + case KeyboardConfig::KEY_PATHFIND: + // Find path to mouse (debug purpose) + if (!player_node || !player_node-> + getDisableGameModifiers()) { - // Checks if any item shortcut is pressed. - for (int i = KeyboardConfig::KEY_SHORTCUT_1; - i <= KeyboardConfig::KEY_SHORTCUT_20; - i ++) - { - if (tKey == i && !used) - { - itemShortcut[num]->useItem( - i - KeyboardConfig::KEY_SHORTCUT_1); - break; - } - } + if (viewport) + viewport->toggleDebugPath(); + if (miniStatusWindow) + miniStatusWindow->updateStatus(); + if (mCurrentMap) + mCurrentMap->redrawMap(); + used = true; } - } - - switch (tKey) + break; + case KeyboardConfig::KEY_TRADE: { - case KeyboardConfig::KEY_PICKUP: - if (player_node) - player_node->pickUpItems(); - used = true; - break; - case KeyboardConfig::KEY_SIT: - // Player sit action - if (player_node) - { - if (keyboard.isKeyActive(keyboard.KEY_EMOTE)) - player_node->updateSit(); - else - player_node->toggleSit(); - } - used = true; - break; - case KeyboardConfig::KEY_HIDE_WINDOWS: - // Hide certain windows - if (!chatWindow || !chatWindow->isInputFocused()) - { - if (statusWindow) - statusWindow->setVisible(false); - if (inventoryWindow) - inventoryWindow->setVisible(false); - if (shopWindow) - shopWindow->setVisible(false); - if (skillDialog) - skillDialog->setVisible(false); - if (setupWindow) - setupWindow->setVisible(false); - if (equipmentWindow) - equipmentWindow->setVisible(false); - if (helpWindow) - helpWindow->setVisible(false); - if (debugWindow) - debugWindow->setVisible(false); - if (outfitWindow) - outfitWindow->setVisible(false); - if (dropShortcutWindow) - dropShortcutWindow->setVisible(false); - if (spellShortcutWindow) - spellShortcutWindow->setVisible(false); - if (botCheckerWindow) - botCheckerWindow->setVisible(false); - if (socialWindow) - socialWindow->setVisible(false); - } - break; - case KeyboardConfig::KEY_WINDOW_STATUS: - requestedWindow = statusWindow; - break; - case KeyboardConfig::KEY_WINDOW_INVENTORY: - requestedWindow = inventoryWindow; - break; - case KeyboardConfig::KEY_WINDOW_SHOP: - requestedWindow = shopWindow; - break; - case KeyboardConfig::KEY_WINDOW_EQUIPMENT: - requestedWindow = equipmentWindow; - break; - case KeyboardConfig::KEY_WINDOW_SKILL: - requestedWindow = skillDialog; - break; - case KeyboardConfig::KEY_WINDOW_KILLS: - requestedWindow = killStats; - break; - case KeyboardConfig::KEY_WINDOW_MINIMAP: - minimap->toggle(); - break; - case KeyboardConfig::KEY_WINDOW_CHAT: - requestedWindow = chatWindow; - break; - case KeyboardConfig::KEY_WINDOW_SHORTCUT: - requestedWindow = itemShortcutWindow; - break; - case KeyboardConfig::KEY_WINDOW_SETUP: - requestedWindow = setupWindow; - break; - case KeyboardConfig::KEY_WINDOW_DEBUG: - requestedWindow = debugWindow; - break; - case KeyboardConfig::KEY_WINDOW_SOCIAL: - requestedWindow = socialWindow; - break; - case KeyboardConfig::KEY_WINDOW_EMOTE_SHORTCUT: - requestedWindow = emoteShortcutWindow; - break; - case KeyboardConfig::KEY_WINDOW_OUTFIT: - requestedWindow = outfitWindow; - break; - case KeyboardConfig::KEY_WINDOW_DROP: - requestedWindow = dropShortcutWindow; - break; - case KeyboardConfig::KEY_WINDOW_SPELLS: - requestedWindow = spellShortcutWindow; - break; - case KeyboardConfig::KEY_WINDOW_BOT_CHECKER: - requestedWindow = botCheckerWindow; - break; - case KeyboardConfig::KEY_WINDOW_ONLINE: - requestedWindow = whoIsOnline; - break; - case KeyboardConfig::KEY_SCREENSHOT: - // Screenshot (picture, hence the p) - saveScreenshot(); - used = true; - break; - case KeyboardConfig::KEY_PATHFIND: - // Find path to mouse (debug purpose) - if (!player_node || !player_node-> - getDisableGameModifiers()) - { - if (viewport) - viewport->toggleDebugPath(); - if (miniStatusWindow) - miniStatusWindow->updateStatus(); - if (mCurrentMap) - mCurrentMap->redrawMap(); - used = true; - } - break; - case KeyboardConfig::KEY_TRADE: + // Toggle accepting of incoming trade requests + unsigned int deflt = player_relations.getDefault(); + if (deflt & PlayerRelation::TRADE) { - // Toggle accepting of incoming trade requests - unsigned int deflt = player_relations.getDefault(); - if (deflt & PlayerRelation::TRADE) + if (localChatTab) { - if (localChatTab) - { - localChatTab->chatLog( - _("Ignoring incoming trade requests"), - BY_SERVER); - } - deflt &= ~PlayerRelation::TRADE; + localChatTab->chatLog( + _("Ignoring incoming trade requests"), + BY_SERVER); } - else + deflt &= ~PlayerRelation::TRADE; + } + else + { + if (localChatTab) { - if (localChatTab) - { - localChatTab->chatLog( - _("Accepting incoming trade requests"), - BY_SERVER); - } - deflt |= PlayerRelation::TRADE; + localChatTab->chatLog( + _("Accepting incoming trade requests"), + BY_SERVER); } - - player_relations.setDefault(deflt); - - used = true; + deflt |= PlayerRelation::TRADE; } - break; - default: - break; - } - } - if (requestedWindow) - { - requestedWindow->setVisible(!requestedWindow->isVisible()); - if (requestedWindow->isVisible()) - requestedWindow->requestMoveToTop(); - used = true; - } - } - } - // Active event - else if (event.type == SDL_ACTIVEEVENT) - { -// logger->log("SDL_ACTIVEEVENT"); -// logger->log("state: %d", (int)event.active.state); -// logger->log("gain: %d", (int)event.active.gain); + player_relations.setDefault(deflt); - int fpsLimit = 0; - if (event.active.state & SDL_APPACTIVE) - { - if (event.active.gain) - { // window restore - Client::setIsMinimized(false); - if (!player_node && !player_node->getAway()) - fpsLimit = config.getIntValue("fpslimit"); - if (player_node) - player_node->setHalfAway(false); - } - else - { // window minimisation - Client::setIsMinimized(true); - if (player_node && !player_node->getAway()) - { - fpsLimit = config.getIntValue("altfpslimit"); - player_node->setHalfAway(true); + used = true; } + break; + default: + break; } - Client::setFramerate(fpsLimit); - } - if (player_node) - player_node->updateName(); - - if (event.active.state & SDL_APPINPUTFOCUS) - Client::setInputFocused(event.active.gain); - if (event.active.state & SDL_APPMOUSEFOCUS) - Client::setMouseFocused(event.active.gain); - - if (player_node && player_node->getAway()) - { - if (Client::getInputFocused() || Client::getMouseFocused()) - fpsLimit = config.getIntValue("fpslimit"); - else - fpsLimit = config.getIntValue("altfpslimit"); - Client::setFramerate(fpsLimit); - } - else - { - fpsLimit = config.getIntValue("fpslimit"); - Client::setFramerate(fpsLimit); } - } - // Quit event - else if (event.type == SDL_QUIT) - { - Client::setState(STATE_EXIT); - } - // Push input to GUI when not used - if (!used) - { - try - { - if (guiInput) - guiInput->pushInput(event); - } - catch (const gcn::Exception &e) + if (requestedWindow) { - const char *err = e.getMessage().c_str(); - logger->log("Warning: guichan input exception: %s", err); + requestedWindow->setVisible(!requestedWindow->isVisible()); + if (requestedWindow->isVisible()) + requestedWindow->requestMoveToTop(); + used = true; } } - - } // End while - - // If the user is configuring the keys then don't respond. - if (!player_node || !keyboard.isEnabled() || player_node->getAway()) - return; - - if (keyboard.isKeyActive(keyboard.KEY_WEAR_OUTFIT) - || keyboard.isKeyActive(keyboard.KEY_COPY_OUTFIT) - || (setupWindow && setupWindow->isVisible())) - { - return; } + return false; +} +void Game::handleMoveAndAttack(SDL_Event &event, bool wasDown) +{ // Moving player around if (player_node->isAlive() && (!Being::isTalking() || keyboard.getKeyIndex(event.key.keysym.sym) @@ -1702,6 +1548,183 @@ void Game::handleInput() } } +void Game::handleActive(SDL_Event &event) +{ +// logger->log("SDL_ACTIVEEVENT"); +// logger->log("state: %d", (int)event.active.state); +// logger->log("gain: %d", (int)event.active.gain); + + int fpsLimit = 0; + if (event.active.state & SDL_APPACTIVE) + { + if (event.active.gain) + { // window restore + Client::setIsMinimized(false); + if (!player_node && !player_node->getAway()) + fpsLimit = config.getIntValue("fpslimit"); + if (player_node) + player_node->setHalfAway(false); + } + else + { // window minimisation + Client::setIsMinimized(true); + if (player_node && !player_node->getAway()) + { + fpsLimit = config.getIntValue("altfpslimit"); + player_node->setHalfAway(true); + } + } + Client::setFramerate(fpsLimit); + } + if (player_node) + player_node->updateName(); + + if (event.active.state & SDL_APPINPUTFOCUS) + Client::setInputFocused(event.active.gain); + if (event.active.state & SDL_APPMOUSEFOCUS) + Client::setMouseFocused(event.active.gain); + + if (player_node && player_node->getAway()) + { + if (Client::getInputFocused() || Client::getMouseFocused()) + fpsLimit = config.getIntValue("fpslimit"); + else + fpsLimit = config.getIntValue("altfpslimit"); + Client::setFramerate(fpsLimit); + } + else + { + fpsLimit = config.getIntValue("fpslimit"); + Client::setFramerate(fpsLimit); + } +} + +/** + * The huge input handling method. + */ +void Game::handleInput() +{ + if (joystick) + joystick->update(); + + bool wasDown(false); + // Events + SDL_Event event; + while (SDL_PollEvent(&event)) + { + bool used = false; + + updateHistory(event); + checkKeys(); + + // Keyboard events (for discontinuous keys) + if (event.type == SDL_KEYDOWN) + { + wasDown = true; + + if (setupWindow && setupWindow->isVisible() && + keyboard.getNewKeyIndex() > keyboard.KEY_NO_VALUE) + { + keyboard.setNewKey(static_cast<int>(event.key.keysym.sym)); + keyboard.callbackNewKey(); + keyboard.setNewKeyIndex(keyboard.KEY_NO_VALUE); + return; + } + + // send straight to gui for certain windows + if (quitDialog || TextDialog::isActive() || + NpcPostDialog::isActive()) + { + try + { + guiInput->pushInput(event); + } + catch (const gcn::Exception &e) + { + const char* err = e.getMessage().c_str(); + logger->log("Warning: guichan input exception: %s", err); + } + return; + } + + if (chatWindow && !chatWindow->isInputFocused() + && keyboard.isKeyActive(keyboard.KEY_RIGHT_CLICK)) + { + int mouseX, mouseY; + SDL_GetMouseState(&mouseX, &mouseY); + + gcn::MouseEvent event2(viewport, false, false, false, false, + 0, gcn::MouseEvent::RIGHT, mouseX, mouseY, 1); + if (viewport) + viewport->mousePressed(event2); + continue; + } + + // Mode switch to emotes + if (keyboard.isKeyActive(keyboard.KEY_EMOTE)) + { + // Emotions + int emotion = keyboard.getKeyEmoteOffset(event.key.keysym.sym); + if (emotion) + { + if (emoteShortcut) + emoteShortcut->useEmote(emotion); + used = true; + setValidSpeed(); + return; + } + } + + if (handleOutfitsKeys(event, used)) + continue; + + if (handleSwitchKeys(event, used)) + return; + + } + // Active event + else if (event.type == SDL_ACTIVEEVENT) + { + handleActive(event); + } + // Quit event + else if (event.type == SDL_QUIT) + { + Client::setState(STATE_EXIT); + } + + // Push input to GUI when not used + if (!used) + { + try + { + if (guiInput) + guiInput->pushInput(event); + } + catch (const gcn::Exception &e) + { + const char *err = e.getMessage().c_str(); + logger->log("Warning: guichan input exception: %s", err); + } + } + + } // End while + + // If the user is configuring the keys then don't respond. + if (!player_node || !keyboard.isEnabled() || player_node->getAway()) + return; + + // If pressed outfits keys, stop processing keys. + if (keyboard.isKeyActive(keyboard.KEY_WEAR_OUTFIT) + || keyboard.isKeyActive(keyboard.KEY_COPY_OUTFIT) + || (setupWindow && setupWindow->isVisible())) + { + return; + } + + handleMoveAndAttack(event, wasDown); +} + /** * Changes the currently active map. Should only be called while the game is * running. diff --git a/src/game.h b/src/game.h index 2205e30de..4e5337d29 100644 --- a/src/game.h +++ b/src/game.h @@ -78,6 +78,14 @@ class Game void handleInput(); + bool handleOutfitsKeys(SDL_Event &event, bool &used); + + bool handleSwitchKeys(SDL_Event &event, bool &used); + + void handleMoveAndAttack(SDL_Event &event, bool wasDown); + + void handleActive(SDL_Event &event); + void changeMap(const std::string &mapName); /** diff --git a/src/graphics.h b/src/graphics.h index 4a4676b26..2502c0418 100644 --- a/src/graphics.h +++ b/src/graphics.h @@ -25,14 +25,6 @@ #include <guichan/sdl/sdlgraphics.hpp> -//include "graphicsvertexes.h" - -#ifdef __GNUC__ -#define A_UNUSED __attribute__ ((unused)) -#else -#define A_UNUSED -#endif - class GraphicsVertexes; class Image; class ImageVertexes; diff --git a/src/gui/botcheckerwindow.h b/src/gui/botcheckerwindow.h index 6af9c91d6..86d5ef290 100644 --- a/src/gui/botcheckerwindow.h +++ b/src/gui/botcheckerwindow.h @@ -32,12 +32,6 @@ #include <vector> -#ifdef __GNUC__ -#define A_UNUSED __attribute__ ((unused)) -#else -#define A_UNUSED -#endif - struct BOTCHK { short id; /**< Index into "botchecker_db" array */ diff --git a/src/gui/buydialog.h b/src/gui/buydialog.h index 53d20e1e5..6bc10a103 100644 --- a/src/gui/buydialog.h +++ b/src/gui/buydialog.h @@ -30,12 +30,6 @@ #include <guichan/actionlistener.hpp> #include <guichan/selectionlistener.hpp> -#ifdef __GNUC__ -#define A_UNUSED __attribute__ ((unused)) -#else -#define A_UNUSED -#endif - class ShopItems; class ShopListBox; class IntTextField; diff --git a/src/gui/charcreatedialog.cpp b/src/gui/charcreatedialog.cpp index 42435f036..d621caa96 100644 --- a/src/gui/charcreatedialog.cpp +++ b/src/gui/charcreatedialog.cpp @@ -44,6 +44,7 @@ #include "net/messageout.h" #include "net/net.h" +#include "resources/chardb.h" #include "resources/colordb.h" #include "resources/itemdb.h" @@ -66,10 +67,18 @@ CharCreateDialog::CharCreateDialog(CharSelectDialog *parent, int slot): mPlayer = new Being(0, ActorSprite::PLAYER, mRace, nullptr); mPlayer->setGender(GENDER_MALE); - int numberOfHairColors = ColorDB::getHairSize(); + maxHairColor = CharDB::getMaxHairColor(); + minHairColor = CharDB::getMinHairColor(); + if (!maxHairColor) + maxHairColor = ColorDB::getHairSize(); - mHairStyle = rand() % mPlayer->getNumOfHairstyles(); - mHairColor = rand() % numberOfHairColors; + maxHairStyle = CharDB::getMaxHairStyle(); + minHairStyle = CharDB::getMinHairStyle(); + if (!maxHairStyle) + maxHairStyle = mPlayer->getNumOfHairstyles(); + + mHairStyle = (rand() % maxHairStyle) + minHairStyle; + mHairColor = (rand() % maxHairColor) + minHairColor; updateHair(); mNameField = new TextField(""); @@ -408,10 +417,14 @@ void CharCreateDialog::updateHair() mHairStyle %= Being::getNumOfHairstyles(); if (mHairStyle < 0) mHairStyle += Being::getNumOfHairstyles(); + if (mHairStyle < (signed)minHairStyle || mHairStyle > (signed)maxHairStyle) + mHairStyle = minHairStyle; mHairColor %= ColorDB::getHairSize(); if (mHairColor < 0) mHairColor += ColorDB::getHairSize(); + if (mHairColor < (signed)minHairColor || mHairColor > (signed)maxHairColor) + mHairColor = minHairColor; mPlayer->setSprite(Net::getCharHandler()->hairSprite(), mHairStyle * -1, ColorDB::getHairColor(mHairColor)); diff --git a/src/gui/charcreatedialog.h b/src/gui/charcreatedialog.h index 2f0f83513..c7010d6b1 100644 --- a/src/gui/charcreatedialog.h +++ b/src/gui/charcreatedialog.h @@ -124,6 +124,11 @@ class CharCreateDialog : public Window, public gcn::ActionListener int mRace; int mSlot; + + unsigned maxHairColor; + unsigned minHairColor; + unsigned maxHairStyle; + unsigned minHairStyle; }; #endif // CHAR_CREATE_DIALOG_H diff --git a/src/gui/charselectdialog.cpp b/src/gui/charselectdialog.cpp index 93302e0ff..15d1e6e0e 100644 --- a/src/gui/charselectdialog.cpp +++ b/src/gui/charselectdialog.cpp @@ -186,6 +186,7 @@ CharSelectDialog::CharSelectDialog(LoginData *data): CharSelectDialog::~CharSelectDialog() { + Net::getCharHandler()->clear(); } void CharSelectDialog::action(const gcn::ActionEvent &event) diff --git a/src/gui/chatwindow.h b/src/gui/chatwindow.h index 1ad468a3b..ad5229ffe 100644 --- a/src/gui/chatwindow.h +++ b/src/gui/chatwindow.h @@ -38,12 +38,6 @@ #include <vector> #include <set> -#ifdef __GNUC__ -#define A_UNUSED __attribute__ ((unused)) -#else -#define A_UNUSED -#endif - class BrowserBox; class ChatTab; class Channel; diff --git a/src/gui/didyouknowwindow.h b/src/gui/didyouknowwindow.h index b135103e8..d9734e8fe 100644 --- a/src/gui/didyouknowwindow.h +++ b/src/gui/didyouknowwindow.h @@ -28,12 +28,6 @@ #include <guichan/actionlistener.hpp> -#ifdef __GNUC__ -#define A_UNUSED __attribute__ ((unused)) -#else -#define A_UNUSED -#endif - class Button; class BrowserBox; class CheckBox; @@ -59,8 +53,7 @@ class DidYouKnowWindow : public Window, public LinkHandler, /** * Handles link action. */ - void handleLink(const std::string &link, - gcn::MouseEvent *event A_UNUSED); + void handleLink(const std::string &link, gcn::MouseEvent *event); void loadData(int num = 0); diff --git a/src/gui/equipmentwindow.cpp b/src/gui/equipmentwindow.cpp index d3d230922..cb3ace0c7 100644 --- a/src/gui/equipmentwindow.cpp +++ b/src/gui/equipmentwindow.cpp @@ -42,6 +42,7 @@ #include "net/net.h" #include "resources/image.h" +#include "resources/imageset.h" #include "resources/iteminfo.h" #include "resources/resourcemanager.h" @@ -55,13 +56,16 @@ static const int BOX_WIDTH = 36; static const int BOX_HEIGHT = 36; +static const int BOX_X_PAD = (BOX_WIDTH - 32) / 2; +static const int BOX_Y_PAD = (BOX_HEIGHT - 32) / 2; EquipmentWindow::EquipmentWindow(Equipment *equipment, Being *being, bool foring): Window(_("Equipment"), false, nullptr, "equipment.xml"), mEquipment(equipment), mSelected(-1), - mForing(foring) + mForing(foring), + mImageSet(0) { mBeing = being; mItemPopup = new ItemPopup; @@ -119,6 +123,11 @@ EquipmentWindow::~EquipmentWindow() } delete_all(mBoxes); mBoxes.clear(); + if (mImageSet) + { + mImageSet->decRef(); + mImageSet = nullptr; + } } void EquipmentWindow::draw(gcn::Graphics *graphics) @@ -133,12 +142,12 @@ void EquipmentWindow::draw(gcn::Graphics *graphics) int i = 0; const int fontHeight = getFont()->getHeight(); - std::vector<std::pair<int, int>*>::const_iterator it; - std::vector<std::pair<int, int>*>::const_iterator it_end = mBoxes.end(); + std::vector<EquipmentBox*>::const_iterator it; + std::vector<EquipmentBox*>::const_iterator it_end = mBoxes.end(); for (it = mBoxes.begin(); it != it_end; ++ it, ++ i) { - std::pair<int, int> *box = *it; + EquipmentBox *box = *it; if (!box) continue; if (i == mSelected) @@ -146,14 +155,14 @@ void EquipmentWindow::draw(gcn::Graphics *graphics) mHighlightColor.a = getGuiAlpha(); // Set color to the highlight color g->setColor(mHighlightColor); - g->fillRectangle(gcn::Rectangle(box->first, - box->second, BOX_WIDTH, BOX_HEIGHT)); + g->fillRectangle(gcn::Rectangle(box->x, box->y, + BOX_WIDTH, BOX_HEIGHT)); } // Set color black g->setColor(mBorderColor); // Draw box border - g->drawRectangle(gcn::Rectangle(box->first, box->second, + g->drawRectangle(gcn::Rectangle(box->x, box->y, BOX_WIDTH, BOX_HEIGHT)); if (!mEquipment) @@ -168,17 +177,21 @@ void EquipmentWindow::draw(gcn::Graphics *graphics) { image->setAlpha(1.0f); // Ensure the image is drawn // with maximum opacity - g->drawImage(image, box->first + 2, box->second + 2); + g->drawImage(image, box->x + 2, box->y + 2); if (i == EQUIP_PROJECTILE_SLOT) { g->setColor(getForegroundColor()); graphics->drawText(toString(item->getQuantity()), - box->first + (BOX_WIDTH / 2), - box->second - fontHeight, + box->x + (BOX_WIDTH / 2), box->y - fontHeight, gcn::Graphics::CENTER); } } } + else if (box->image) + { + g->drawImage(box->image, box->x + BOX_X_PAD, + box->y + BOX_Y_PAD); + } } } @@ -200,16 +213,16 @@ Item *EquipmentWindow::getItem(int x, int y) const if (!mEquipment) return nullptr; - std::vector<std::pair<int, int>*>::const_iterator it; - std::vector<std::pair<int, int>*>::const_iterator it_end = mBoxes.end(); + std::vector<EquipmentBox*>::const_iterator it; + std::vector<EquipmentBox*>::const_iterator it_end = mBoxes.end(); int i = 0; for (it = mBoxes.begin(); it != it_end; ++ it, ++ i) { - std::pair<int, int> *box = *it; + EquipmentBox *box = *it; if (!box) continue; - const gcn::Rectangle tRect(box->first, box->second, + const gcn::Rectangle tRect(box->x, box->y, BOX_WIDTH, BOX_HEIGHT); if (tRect.isPointInRect(x, y)) @@ -233,18 +246,17 @@ void EquipmentWindow::mousePressed(gcn::MouseEvent& mouseEvent) if (mForing) return; // Checks if any of the presses were in the equip boxes. - std::vector<std::pair<int, int>*>::const_iterator it; - std::vector<std::pair<int, int>*>::const_iterator - it_end = mBoxes.end(); + std::vector<EquipmentBox*>::const_iterator it; + std::vector<EquipmentBox*>::const_iterator it_end = mBoxes.end(); int i = 0; for (it = mBoxes.begin(); it != it_end; ++ it, ++ i) { - std::pair<int, int> *box = *it; + EquipmentBox *box = *it; if (!box) continue; Item *item = mEquipment->getEquipment(i); - const gcn::Rectangle tRect(box->first, box->second, + const gcn::Rectangle tRect(box->x, box->y, BOX_WIDTH, BOX_HEIGHT); if (tRect.isPointInRect(x, y) && item) @@ -351,6 +363,12 @@ void EquipmentWindow::fillBoxes() return; } + if (mImageSet) + mImageSet->decRef(); + + mImageSet = Theme::getImageSetFromTheme(XML::getProperty( + root, "image", "equipmentbox.png"), 32, 32); + for_each_xml_child_node(node, root) { if (xmlStrEqual(node->name, BAD_CAST "window")) @@ -358,7 +376,7 @@ void EquipmentWindow::fillBoxes() else if (xmlStrEqual(node->name, BAD_CAST "playerbox")) loadPlayerBox(node); else if (xmlStrEqual(node->name, BAD_CAST "slot")) - loadSlot(node); + loadSlot(node, mImageSet); } delete doc; } @@ -378,7 +396,7 @@ void EquipmentWindow::loadPlayerBox(xmlNodePtr playerBoxNode) XML::getProperty(playerBoxNode, "height", 168))); } -void EquipmentWindow::loadSlot(xmlNodePtr slotNode) +void EquipmentWindow::loadSlot(xmlNodePtr slotNode, ImageSet *imageset) { int slot = parseSlotName(XML::getProperty(slotNode, "name", "")); if (slot < 0) @@ -386,16 +404,22 @@ void EquipmentWindow::loadSlot(xmlNodePtr slotNode) const int x = XML::getProperty(slotNode, "x", 0) + getPadding(); const int y = XML::getProperty(slotNode, "y", 0) + getTitleBarHeight(); + const int imageIndex = XML::getProperty(slotNode, "image", -1); + Image *image = nullptr; + + if (imageset && imageIndex >= 0 && imageIndex < (signed)imageset->size()) + image = imageset->get(imageIndex); if (mBoxes[slot]) { - std::pair<int, int> *pair = mBoxes[slot]; - pair->first = x; - pair->second = y; + EquipmentBox *box = mBoxes[slot]; + box->x = x; + box->y = y; + box->image = image; } else { - mBoxes[slot] = new std::pair<int, int>(x, y); + mBoxes[slot] = new EquipmentBox(x, y, image); } } @@ -461,23 +485,34 @@ int EquipmentWindow::parseSlotName(std::string name) void EquipmentWindow::fillDefault() { - addBox(0, 90, 40); // torso - addBox(1, 8, 78); // gloves - addBox(2, 70, 0); // hat - addBox(3, 50, 253); // pants - addBox(4, 90, 253); // boots - addBox(5, 8, 213); // FREE - addBox(6, 129, 213); // wings - addBox(7, 50, 40); // scarf - addBox(8, 8, 168); // weapon - addBox(9, 129, 168); // shield - addBox(10, 129, 78); // ammo - addBox(11, 8, 123); // amulet - addBox(12, 129, 123); // ring + if (mImageSet) + mImageSet->decRef(); + + mImageSet = Theme::getImageSetFromTheme( + "equipmentbox.png", 32, 32); + + addBox(0, 90, 40, 0); // torso + addBox(1, 8, 78, 1); // gloves + addBox(2, 70, 0, 2); // hat + addBox(3, 50, 253, 3); // pants + addBox(4, 90, 253, 4); // boots + addBox(5, 8, 213, 5); // FREE + addBox(6, 129, 213, 6); // wings + addBox(7, 50, 40, 5); // scarf + addBox(8, 8, 168, 7); // weapon + addBox(9, 129, 168, 8); // shield + addBox(10, 129, 78, 9); // ammo + addBox(11, 8, 123, 5); // amulet + addBox(12, 129, 123, 5); // ring } -void EquipmentWindow::addBox(int idx, int x, int y) +void EquipmentWindow::addBox(int idx, int x, int y, int imageIndex) { - mBoxes[idx] = new std::pair<int, int>( - x + getPadding(), y + getTitleBarHeight()); + Image *image = nullptr; + + if (mImageSet && imageIndex >= 0 && imageIndex < (signed)mImageSet->size()) + image = mImageSet->get(imageIndex); + + mBoxes[idx] = new EquipmentBox(x + getPadding(), y + getTitleBarHeight(), + image); } diff --git a/src/gui/equipmentwindow.h b/src/gui/equipmentwindow.h index cadf27620..0a3c2da20 100644 --- a/src/gui/equipmentwindow.h +++ b/src/gui/equipmentwindow.h @@ -25,27 +25,37 @@ #include "equipment.h" #include "guichanfwd.h" +#include "localconsts.h" #include "gui/widgets/window.h" #include "utils/xml.h" +#include "resources/image.h" + #include <guichan/actionlistener.hpp> #include <vector> -#ifdef __GNUC__ -#define A_UNUSED __attribute__ ((unused)) -#else -#define A_UNUSED -#endif - class Being; class Inventory; +class Image; +class ImageSet; class Item; class ItemPopup; class PlayerBox; +struct EquipmentBox +{ + EquipmentBox(int x0, int y0, Image *img) : + x(x0), y(y0), image(img) + { } + + int x; + int y; + Image *image; +}; + /** * Equipment dialog. * @@ -96,13 +106,13 @@ class EquipmentWindow : public Window, public gcn::ActionListener void fillDefault(); - void addBox(int idx, int x, int y); + void addBox(int idx, int x, int y, int imageIndex); void loadWindow(xmlNodePtr windowNode); void loadPlayerBox(xmlNodePtr playerBoxNode); - void loadSlot(xmlNodePtr slotNode); + void loadSlot(xmlNodePtr slotNode, ImageSet *imageset); int parseSlotName(std::string name); @@ -114,8 +124,9 @@ class EquipmentWindow : public Window, public gcn::ActionListener int mSelected; /**< Index of selected item. */ bool mForing; + ImageSet *mImageSet; Being *mBeing; - std::vector<std::pair<int, int>*> mBoxes; + std::vector<EquipmentBox*> mBoxes; gcn::Color mHighlightColor; gcn::Color mBorderColor; }; diff --git a/src/gui/helpwindow.h b/src/gui/helpwindow.h index d59289db0..178ae1e16 100644 --- a/src/gui/helpwindow.h +++ b/src/gui/helpwindow.h @@ -28,11 +28,7 @@ #include <guichan/actionlistener.hpp> -#ifdef __GNUC__ -#define A_UNUSED __attribute__ ((unused)) -#else -#define A_UNUSED -#endif +#include "localconsts.h" class BrowserBox; class LinkHandler; diff --git a/src/gui/inventorywindow.h b/src/gui/inventorywindow.h index 9dadeb5a8..aa78705b8 100644 --- a/src/gui/inventorywindow.h +++ b/src/gui/inventorywindow.h @@ -35,12 +35,6 @@ #include <guichan/keylistener.hpp> #include <guichan/selectionlistener.hpp> -#ifdef __GNUC__ -#define A_UNUSED __attribute__ ((unused)) -#else -#define A_UNUSED -#endif - class DropDown; class Item; class ItemContainer; @@ -48,7 +42,6 @@ class InventoryFilter; class LayoutCell; class ProgressBar; class SortListModel; -//class TextBox; class TextField; /** diff --git a/src/gui/itemamountwindow.h b/src/gui/itemamountwindow.h index 2dffdc286..bacd4cfd0 100644 --- a/src/gui/itemamountwindow.h +++ b/src/gui/itemamountwindow.h @@ -28,12 +28,6 @@ #include <guichan/keylistener.hpp> #include <guichan/actionlistener.hpp> -#ifdef __GNUC__ -#define A_UNUSED __attribute__ ((unused)) -#else -#define A_UNUSED -#endif - class Icon; class IntTextField; class Item; diff --git a/src/gui/ministatuswindow.h b/src/gui/ministatuswindow.h index 5e1b442dc..6fb8f7652 100644 --- a/src/gui/ministatuswindow.h +++ b/src/gui/ministatuswindow.h @@ -31,12 +31,6 @@ #include <vector> -#ifdef __GNUC__ -#define A_UNUSED __attribute__ ((unused)) -#else -#define A_UNUSED -#endif - class AnimatedSprite; class Graphics; class ProgressBar; diff --git a/src/gui/popupmenu.h b/src/gui/popupmenu.h index 3a7f27d4b..4bbe2c46c 100644 --- a/src/gui/popupmenu.h +++ b/src/gui/popupmenu.h @@ -28,11 +28,7 @@ #include <guichan/actionlistener.hpp> -#ifdef __GNUC__ -#define A_UNUSED __attribute__ ((unused)) -#else -#define A_UNUSED -#endif +#include "localconsts.h" class Being; class BrowserBox; diff --git a/src/gui/register.h b/src/gui/register.h index 34bcadd6d..b0137f141 100644 --- a/src/gui/register.h +++ b/src/gui/register.h @@ -30,12 +30,6 @@ #include <string> -#ifdef __GNUC__ -#define A_UNUSED __attribute__ ((unused)) -#else -#define A_UNUSED -#endif - class LoginData; class OkDialog; diff --git a/src/gui/selldialog.h b/src/gui/selldialog.h index 46cb077e1..a775cf0e0 100644 --- a/src/gui/selldialog.h +++ b/src/gui/selldialog.h @@ -30,12 +30,6 @@ #include <SDL_types.h> -#ifdef __GNUC__ -#define A_UNUSED __attribute__ ((unused)) -#else -#define A_UNUSED -#endif - class Item; class ShopItems; class ShopListBox; diff --git a/src/gui/setup_colors.h b/src/gui/setup_colors.h index 850f23897..b6d5209e2 100644 --- a/src/gui/setup_colors.h +++ b/src/gui/setup_colors.h @@ -31,12 +31,6 @@ #include <string> -#ifdef __GNUC__ -#define A_UNUSED __attribute__ ((unused)) -#else -#define A_UNUSED -#endif - class BrowserBox; class TextField; class TextPreview; diff --git a/src/gui/setup_relations.h b/src/gui/setup_relations.h index a6627a06d..2c23d4dba 100644 --- a/src/gui/setup_relations.h +++ b/src/gui/setup_relations.h @@ -30,12 +30,6 @@ #include <guichan/actionlistener.hpp> -#ifdef __GNUC__ -#define A_UNUSED __attribute__ ((unused)) -#else -#define A_UNUSED -#endif - class EditDialog; class GuiTable; class PlayerTableModel; diff --git a/src/gui/shopwindow.h b/src/gui/shopwindow.h index 8b170f31e..e1fd8a2a0 100644 --- a/src/gui/shopwindow.h +++ b/src/gui/shopwindow.h @@ -30,12 +30,6 @@ #include <guichan/actionlistener.hpp> #include <guichan/selectionlistener.hpp> -#ifdef __GNUC__ -#define A_UNUSED __attribute__ ((unused)) -#else -#define A_UNUSED -#endif - class CheckBox; class Item; class ListBox; diff --git a/src/gui/skilldialog.h b/src/gui/skilldialog.h index 21ee56f5e..63f7d1790 100644 --- a/src/gui/skilldialog.h +++ b/src/gui/skilldialog.h @@ -42,12 +42,6 @@ class TabbedArea; struct SkillInfo; -#ifdef __GNUC__ -#define A_UNUSED __attribute__ ((unused)) -#else -#define A_UNUSED -#endif - /** * The skill dialog. * diff --git a/src/gui/socialwindow.h b/src/gui/socialwindow.h index 7dc962316..dec8a6c26 100644 --- a/src/gui/socialwindow.h +++ b/src/gui/socialwindow.h @@ -30,12 +30,6 @@ #include <string> #include <map> -#ifdef __GNUC__ -#define A_UNUSED __attribute__ ((unused)) -#else -#define A_UNUSED -#endif - class AttackTab; class Button; class ConfirmDialog; diff --git a/src/gui/specialswindow.h b/src/gui/specialswindow.h index 030c1343b..4350a656b 100644 --- a/src/gui/specialswindow.h +++ b/src/gui/specialswindow.h @@ -34,12 +34,6 @@ #include <map> -#ifdef __GNUC__ -#define A_UNUSED __attribute__ ((unused)) -#else -#define A_UNUSED -#endif - class Label; class ScrollArea; class Tab; diff --git a/src/gui/statuspopup.cpp b/src/gui/statuspopup.cpp index 5f2ec71e3..3e1f68d09 100644 --- a/src/gui/statuspopup.cpp +++ b/src/gui/statuspopup.cpp @@ -37,7 +37,6 @@ #include "units.h" #include "keyboardconfig.h" -#include "utils/gettext.h" #include "utils/stringutils.h" #include <guichan/font.hpp> @@ -187,387 +186,52 @@ void StatusPopup::view(int x, int y) requestMoveToTop(); } -void StatusPopup::setLabelText(gcn::Label *label, char *text, int key) +void StatusPopup::setLabelText(gcn::Label *label, const char *text, int key) { label->setCaption(strprintf("%s %s", text, keyboard.getKeyValueString(key).c_str())); } +void StatusPopup::setLabelText2(gcn::Label *label, std::string text, int key) +{ + label->setCaption(strprintf("%s %s", text.c_str(), + keyboard.getKeyValueString(key).c_str())); + label->adjustSize(); +} + void StatusPopup::updateLabels() { if (!player_node || !viewport) return; - switch (player_node->getInvertDirection()) - { - case 0: - setLabelText(mMoveType, _("(D) default moves"), - keyboard.KEY_INVERT_DIRECTION); - break; - - case 1: - setLabelText(mMoveType, _("(I) invert moves"), - keyboard.KEY_INVERT_DIRECTION); - break; - - case 2: - setLabelText(mMoveType, _("(c) moves with some crazy moves"), - keyboard.KEY_INVERT_DIRECTION); - break; - - case 3: - setLabelText(mMoveType, _("(C) moves with crazy moves"), - keyboard.KEY_INVERT_DIRECTION); - break; - - case 4: - setLabelText(mMoveType, _("(d) double normal + crazy"), - keyboard.KEY_INVERT_DIRECTION); - break; - - default: - setLabelText(mMoveType, _("(?) move"), - keyboard.KEY_INVERT_DIRECTION); - break; - } - mMoveType->adjustSize(); - - if (player_node->getCrazyMoveType() < 10) - { - mCrazyMoveType->setCaption(strprintf("(%d) crazy move number %d %s", - player_node->getCrazyMoveType(), player_node->getCrazyMoveType(), - keyboard.getKeyValueString( - keyboard.KEY_CHANGE_CRAZY_MOVES_TYPE).c_str())); - } - else - { - switch (player_node->getCrazyMoveType()) - { - case 10: - setLabelText(mCrazyMoveType, _("(a) custom crazy move"), - keyboard.KEY_CHANGE_CRAZY_MOVES_TYPE); - break; - default: - setLabelText(mCrazyMoveType, _("(?) crazy move"), - keyboard.KEY_CHANGE_CRAZY_MOVES_TYPE); - break; - } - } - mCrazyMoveType->adjustSize(); - - switch (player_node->getMoveToTargetType()) - { - case 0: - setLabelText(mMoveToTargetType, _("(0) default moves to target"), - keyboard.KEY_CHANGE_MOVE_TO_TARGET); - break; - case 1: - setLabelText(mMoveToTargetType, - _("(1) moves to target in distance 1"), - keyboard.KEY_CHANGE_MOVE_TO_TARGET); - break; - case 2: - setLabelText(mMoveToTargetType, - _("(2) moves to target in distance 2"), - keyboard.KEY_CHANGE_MOVE_TO_TARGET); - break; - case 3: - setLabelText(mMoveToTargetType, - _("(3) moves to target in distance 3"), - keyboard.KEY_CHANGE_MOVE_TO_TARGET); - break; - case 4: - setLabelText(mMoveToTargetType, - _("(5) moves to target in distance 5"), - keyboard.KEY_CHANGE_MOVE_TO_TARGET); - break; - case 5: - setLabelText(mMoveToTargetType, - _("(7) moves to target in distance 7"), - keyboard.KEY_CHANGE_MOVE_TO_TARGET); - break; - case 6: - setLabelText(mMoveToTargetType, - _("(A) moves to target in attack range"), - keyboard.KEY_CHANGE_MOVE_TO_TARGET); - break; - case 7: - setLabelText(mMoveToTargetType, - _("(a) archer attack range"), - keyboard.KEY_CHANGE_MOVE_TO_TARGET); - break; - default: - setLabelText(mMoveToTargetType, - _("(?) move to target"), keyboard.KEY_CHANGE_MOVE_TO_TARGET); - break; - } - mMoveToTargetType->adjustSize(); - - switch (player_node->getFollowMode()) - { - case 0: - setLabelText(mFollowMode, _("(D) default follow"), - keyboard.KEY_CHANGE_FOLLOW_MODE); - break; - case 1: - setLabelText(mFollowMode, _("(R) relative follow"), - keyboard.KEY_CHANGE_FOLLOW_MODE); - break; - case 2: - setLabelText(mFollowMode, _("(M) mirror follow"), - keyboard.KEY_CHANGE_FOLLOW_MODE); - break; - case 3: - setLabelText(mFollowMode, _("(P) pet follow"), - keyboard.KEY_CHANGE_FOLLOW_MODE); - break; - default: - setLabelText(mFollowMode, _("(?) unknown follow"), - keyboard.KEY_CHANGE_FOLLOW_MODE); - break; - } - mFollowMode->adjustSize(); - - switch (player_node->getAttackWeaponType()) - { - case 1: - setLabelText(mAttackWeaponType, _("(D) default attack"), - keyboard.KEY_CHANGE_ATTACK_WEAPON_TYPE); - break; - case 2: - setLabelText(mAttackWeaponType, - _("(s) switch attack without shield"), - keyboard.KEY_CHANGE_ATTACK_WEAPON_TYPE); - break; - case 3: - setLabelText(mAttackWeaponType, - _("(S) switch attack with shield"), - keyboard.KEY_CHANGE_ATTACK_WEAPON_TYPE); - break; - default: - setLabelText(mAttackWeaponType, _("(?) attack"), - keyboard.KEY_CHANGE_ATTACK_WEAPON_TYPE); - break; - } - mAttackWeaponType->adjustSize(); - - switch (player_node->getAttackType()) - { - case 0: - setLabelText(mAttackType, _("(D) default attack"), - keyboard.KEY_CHANGE_ATTACK_TYPE); - break; - case 1: - setLabelText(mAttackType, _("(G) go and attack"), - keyboard.KEY_CHANGE_ATTACK_TYPE); - break; - case 2: - setLabelText(mAttackType, _("(A) go, attack, pickup"), - keyboard.KEY_CHANGE_ATTACK_TYPE); - break; - case 3: - setLabelText(mAttackType, _("(d) without auto attack"), - keyboard.KEY_CHANGE_ATTACK_TYPE); - break; - default: - setLabelText(mAttackType, _("(?) attack"), - keyboard.KEY_CHANGE_ATTACK_TYPE); - break; - } - mAttackType->adjustSize(); - - mDropCounter->setCaption(strprintf("(%d) drop counter %d %s", - player_node->getQuickDropCounter(), player_node->getQuickDropCounter(), - keyboard.getKeyValueString(keyboard.KEY_SWITCH_QUICK_DROP).c_str())); - mDropCounter->adjustSize(); - - switch (player_node->getPickUpType()) - { - case 0: - setLabelText(mPickUpType, _("(S) small pick up 1x1 cells"), - keyboard.KEY_CHANGE_PICKUP_TYPE); - break; - case 1: - setLabelText(mPickUpType, _("(D) default pick up 2x1 cells"), - keyboard.KEY_CHANGE_PICKUP_TYPE); - break; - case 2: - setLabelText(mPickUpType, _("(F) forward pick up 2x3 cells"), - keyboard.KEY_CHANGE_PICKUP_TYPE); - break; - case 3: - setLabelText(mPickUpType, _("(3) pick up 3x3 cells"), - keyboard.KEY_CHANGE_PICKUP_TYPE); - break; - case 4: - setLabelText(mPickUpType, _("(g) go and pick up in distance 4"), - keyboard.KEY_CHANGE_PICKUP_TYPE); - break; - case 5: - setLabelText(mPickUpType, _("(G) go and pick up in distance 8"), - keyboard.KEY_CHANGE_PICKUP_TYPE); - break; - case 6: - setLabelText(mPickUpType, _("(A) go and pick up in max distance"), - keyboard.KEY_CHANGE_PICKUP_TYPE); - break; - default: - setLabelText(mPickUpType, _("(?) pick up"), - keyboard.KEY_CHANGE_PICKUP_TYPE); - break; - } - mPickUpType->adjustSize(); - - switch (viewport->getDebugPath()) - { - case 0: - setLabelText(mMapType, _("(N) normal map view"), - keyboard.KEY_PATHFIND); - break; - case 1: - setLabelText(mMapType, _("(D) debug map view"), - keyboard.KEY_PATHFIND); - break; - case 2: - setLabelText(mMapType, _("(u) ultra map view"), - keyboard.KEY_PATHFIND); - break; - case 3: - setLabelText(mMapType, _("(U) ultra map view 2"), - keyboard.KEY_PATHFIND); - break; - case 4: - setLabelText(mMapType, _("(e) empty map view"), - keyboard.KEY_PATHFIND); - break; - case 5: - setLabelText(mMapType, _("(b) black & white map view"), - keyboard.KEY_PATHFIND); - break; - default: - setLabelText(mMapType, _("(?) map view"), keyboard.KEY_PATHFIND); - break; - } - mMapType->adjustSize(); - - switch (player_node->getMagicAttackType()) - { - case 0: - setLabelText(mMagicAttackType, _("(f) use #flar for magic attack"), - keyboard.KEY_SWITCH_MAGIC_ATTACK); - break; - case 1: - setLabelText(mMagicAttackType, - _("(c) use #chiza for magic attack"), - keyboard.KEY_SWITCH_MAGIC_ATTACK); - break; - case 2: - setLabelText(mMagicAttackType, - _("(I) use #ingrav for magic attack"), - keyboard.KEY_SWITCH_MAGIC_ATTACK); - break; - case 3: - setLabelText(mMagicAttackType, - _("(F) use #frillyar for magic attack"), - keyboard.KEY_SWITCH_MAGIC_ATTACK); - break; - case 4: - setLabelText(mMagicAttackType, - _("(U) use #upmarmu for magic attack"), - keyboard.KEY_SWITCH_MAGIC_ATTACK); - break; - default: - setLabelText(mMagicAttackType, _("(?) magic attack"), - keyboard.KEY_SWITCH_MAGIC_ATTACK); - break; - } - mMagicAttackType->adjustSize(); - - switch (player_node->getPvpAttackType()) - { - case 0: - setLabelText(mPvpAttackType, _("(a) attack all players"), - keyboard.KEY_SWITCH_PVP_ATTACK); - break; - case 1: - setLabelText(mPvpAttackType, _("(f) attack not friends"), - keyboard.KEY_SWITCH_PVP_ATTACK); - break; - case 2: - setLabelText(mPvpAttackType, _("(b) attack bad relations"), - keyboard.KEY_SWITCH_PVP_ATTACK); - break; - case 3: - setLabelText(mPvpAttackType, _("(d) dont attack players"), - keyboard.KEY_SWITCH_PVP_ATTACK); - break; - default: - setLabelText(mMagicAttackType, _("(?) pvp attack"), - keyboard.KEY_SWITCH_MAGIC_ATTACK); - break; - } - mPvpAttackType->adjustSize(); - - switch (player_node->getImitationMode()) - { - case 0: - setLabelText(mImitationMode, _("(D) default imitation"), - keyboard.KEY_CHANGE_IMITATION_MODE); - break; - case 1: - setLabelText(mImitationMode, _("(O) outfits imitation"), - keyboard.KEY_CHANGE_IMITATION_MODE); - break; - default: - setLabelText(mImitationMode, _("(?) imitation"), - keyboard.KEY_CHANGE_IMITATION_MODE); - break; - } - mImitationMode->adjustSize(); - - switch ((int)player_node->getAway()) - { - case 0: - setLabelText(mAwayMode, _("(O) on keyboard"), keyboard.KEY_AWAY); - break; - case 1: - setLabelText(mAwayMode, _("(A) away"), keyboard.KEY_AWAY); - break; - default: - setLabelText(mAwayMode, _("(?) away"), keyboard.KEY_AWAY); - break; - } - mAwayMode->adjustSize(); - - switch (viewport->getCameraMode()) - { - case 0: - setLabelText(mCameraMode, _("(G) game camera mode"), - keyboard.KEY_CAMERA); - break; - case 1: - setLabelText(mCameraMode, _("(F) free camera mode"), - keyboard.KEY_CAMERA); - break; - case 2: - setLabelText(mCameraMode, _("(D) design camera mode"), - keyboard.KEY_CAMERA); - break; - default: - setLabelText(mCameraMode, _("(?) away"), keyboard.KEY_CAMERA); - break; - } - mCameraMode->adjustSize(); - - if (player_node->getDisableGameModifiers()) - { - setLabelText(mDisableGameModifiers, _("Game modifiers are disabled"), - keyboard.KEY_DISABLE_GAME_MODIFIERS); - } - else - { - setLabelText(mDisableGameModifiers, _("Game modifiers are enabled"), - keyboard.KEY_DISABLE_GAME_MODIFIERS); - } - mDisableGameModifiers->adjustSize(); + setLabelText2(mMoveType, player_node->getInvertDirectionString(), + keyboard.KEY_INVERT_DIRECTION); + setLabelText2(mCrazyMoveType, player_node->getCrazyMoveTypeString(), + keyboard.KEY_CHANGE_CRAZY_MOVES_TYPE); + setLabelText2(mMoveToTargetType, player_node->getMoveToTargetTypeString(), + keyboard.KEY_CHANGE_MOVE_TO_TARGET); + setLabelText2(mFollowMode, player_node->getFollowModeString(), + keyboard.KEY_CHANGE_FOLLOW_MODE); + setLabelText2(mAttackWeaponType, player_node->getAttackWeaponTypeString(), + keyboard.KEY_CHANGE_ATTACK_WEAPON_TYPE); + setLabelText2(mAttackType, player_node->getAttackTypeString(), + keyboard.KEY_CHANGE_ATTACK_TYPE); + setLabelText2(mDropCounter, player_node->getQuickDropCounterString(), + keyboard.KEY_SWITCH_QUICK_DROP); + setLabelText2(mPickUpType, player_node->getPickUpTypeString(), + keyboard.KEY_CHANGE_PICKUP_TYPE); + setLabelText2(mMapType, player_node->getDebugPathString(), + keyboard.KEY_PATHFIND); + setLabelText2(mMagicAttackType, player_node->getMagicAttackString(), + keyboard.KEY_SWITCH_MAGIC_ATTACK); + setLabelText2(mPvpAttackType, player_node->getPvpAttackString(), + keyboard.KEY_SWITCH_PVP_ATTACK); + setLabelText2(mImitationMode, player_node->getImitationModeString(), + keyboard.KEY_CHANGE_IMITATION_MODE); + setLabelText2(mAwayMode, player_node->getAwayModeString(), + keyboard.KEY_AWAY); + setLabelText2(mCameraMode, player_node->getCameraModeString(), + keyboard.KEY_CAMERA); + setLabelText2(mDisableGameModifiers, player_node->getGameModifiersString(), + keyboard.KEY_DISABLE_GAME_MODIFIERS); } diff --git a/src/gui/statuspopup.h b/src/gui/statuspopup.h index 2af8064c5..976b5e57b 100644 --- a/src/gui/statuspopup.h +++ b/src/gui/statuspopup.h @@ -60,7 +60,10 @@ class StatusPopup : public Popup private: void updateLabels(); - void setLabelText(gcn::Label *label, char *text, int key); + + void setLabelText(gcn::Label *label, const char *text, int key); + + void setLabelText2(gcn::Label *label, std::string text, int key); gcn::Label *mMoveType; gcn::Label *mCrazyMoveType; diff --git a/src/gui/statuswindow.cpp b/src/gui/statuswindow.cpp index 37a706baf..5ac14d132 100644 --- a/src/gui/statuswindow.cpp +++ b/src/gui/statuswindow.cpp @@ -624,7 +624,7 @@ void StatusWindow::updateInvSlotsBar(ProgressBar *bar) bar->setText(strprintf("%d", usedSlots)); } -std::string StatusWindow::translateLetter(char* letters) +std::string StatusWindow::translateLetter(const char* letters) { char buf[2]; char *str = gettext(letters); @@ -636,277 +636,34 @@ std::string StatusWindow::translateLetter(char* letters) return std::string(buf); } +std::string StatusWindow::translateLetter2(std::string letters) +{ + if (letters.size() < 5) + return ""; + + return std::string(gettext(letters.substr(1, 1).c_str())); +} + void StatusWindow::updateStatusBar(ProgressBar *bar, bool percent A_UNUSED) { if (!player_node || !viewport) return; - std::string str; - - switch (player_node->getInvertDirection()) - { - case 0: - str = translateLetter(N_("(D)")); - break; - case 1: - str = translateLetter(N_("(I)")); - break; - case 2: - str = translateLetter(N_("(c)")); - break; - case 3: - str = translateLetter(N_("(C)")); - break; - case 4: - str = translateLetter(N_("(d)")); - break; - default: - str = translateLetter(N_("(?)")); - break; - } - - if (player_node->getCrazyMoveType() < 10) - str += toString(player_node->getCrazyMoveType()); - else - { - switch (player_node->getCrazyMoveType()) - { - case 10: - str += translateLetter(N_("(a)")); - break; - default: - str += translateLetter(N_("(?)")); - break; - } - } - - switch (player_node->getMoveToTargetType()) - { - case 0: - str += translateLetter(N_("(0)")); - break; - case 1: - str += translateLetter(N_("(1)")); - break; - case 2: - str += translateLetter(N_("(2)")); - break; - case 3: - str += translateLetter(N_("(3)")); - break; - case 4: - str += translateLetter(N_("(5)")); - break; - case 5: - str += translateLetter(N_("(7)")); - break; - case 6: - str += translateLetter(N_("(A)")); - break; - case 7: - str += translateLetter(N_("(a)")); - break; - default: - str += translateLetter(N_("(?)")); - break; - } - - switch (player_node->getFollowMode()) - { - case 0: - str += translateLetter(N_("(D)")); - break; - case 1: - str += translateLetter(N_("(R)")); - break; - case 2: - str += translateLetter(N_("(M)")); - break; - case 3: - str += translateLetter(N_("(P)")); - break; - default: - str += translateLetter(N_("(?)")); - break; - } - - str += " "; - switch (player_node->getAttackWeaponType()) - { - case 1: - str += translateLetter(N_("(D)")); - break; - case 2: - str += translateLetter(N_("(s)")); - break; - case 3: - str += translateLetter(N_("(S)")); - break; - default: - str += translateLetter(N_("(?)")); - break; - } - - switch (player_node->getAttackType()) - { - case 0: - str += translateLetter(N_("(D)")); - break; - case 1: - str += translateLetter(N_("(G)")); - break; - case 2: - str += translateLetter(N_("(A)")); - break; - case 3: - str += translateLetter(N_("(d)")); - break; - default: - str += translateLetter(N_("(?)")); - break; - } - - switch (player_node->getMagicAttackType()) - { - case 0: - str += translateLetter(N_("(f)")); - break; - case 1: - str += translateLetter(N_("(c)")); - break; - case 2: - str += translateLetter(N_("(I)")); - break; - case 3: - str += translateLetter(N_("(F)")); - break; - case 4: - str += translateLetter(N_("(U)")); - break; - default: - str += translateLetter(N_("(?)")); - break; - } - - switch (player_node->getPvpAttackType()) - { - case 0: - str += translateLetter(N_("(a)")); - break; - case 1: - str += translateLetter(N_("(f)")); - break; - case 2: - str += translateLetter(N_("(b)")); - break; - case 3: - str += translateLetter(N_("(d)")); - break; - default: - str += translateLetter(N_("(?)")); - break; - } - - str += " " + toString(player_node->getQuickDropCounter()); - - switch (player_node->getPickUpType()) - { - case 0: - str += translateLetter(N_("(S)")); - break; - case 1: - str += translateLetter(N_("(D)")); - break; - case 2: - str += translateLetter(N_("(F)")); - break; - case 3: - str += translateLetter(N_("(3)")); - break; - case 4: - str += translateLetter(N_("(g)")); - break; - case 5: - str += translateLetter(N_("(G)")); - break; - case 6: - str += translateLetter(N_("(A)")); - break; - default: - str += translateLetter(N_("(?)")); - break; - } - - str += " "; - switch (viewport->getDebugPath()) - { - case 0: - str += translateLetter(N_("(N)")); - break; - case 1: - str += translateLetter(N_("(D)")); - break; - case 2: - str += translateLetter(N_("(u)")); - break; - case 3: - str += translateLetter(N_("(U)")); - break; - case 4: - str += translateLetter(N_("(e)")); - break; - case 5: - str += translateLetter(N_("(b)")); - break; - default: - str += translateLetter(N_("(?)")); - break; - } - - str += " "; - switch (player_node->getImitationMode()) - { - case 0: - str += translateLetter(N_("(D)")); - break; - case 1: - str += translateLetter(N_("(O)")); - break; - default: - str += translateLetter(N_("(?)")); - break; - } - - switch (viewport->getCameraMode()) - { - case 0: - str += translateLetter(N_("(G)")); - break; - case 1: - str += translateLetter(N_("(F)")); - break; - case 2: - str += translateLetter(N_("(D)")); - break; - default: - str += translateLetter(N_("(?)")); - break; - } - - switch ((int)player_node->getAway()) - { - case 0: - str += translateLetter(N_("(O)")); - break; - case 1: - str += translateLetter(N_("(A)")); - break; - default: - str += translateLetter(N_("(?)")); - break; - } + bar->setText(translateLetter2(player_node->getInvertDirectionString()) + += translateLetter2(player_node->getCrazyMoveTypeString()) + += translateLetter2(player_node->getMoveToTargetTypeString()) + += translateLetter2(player_node->getFollowModeString()) + += " " + translateLetter2(player_node->getAttackWeaponTypeString()) + += translateLetter2(player_node->getAttackTypeString()) + += translateLetter2(player_node->getMagicAttackString()) + += translateLetter2(player_node->getPvpAttackString()) + += " " + translateLetter2(player_node->getQuickDropCounterString()) + += translateLetter2(player_node->getPickUpTypeString()) + += " " + translateLetter2(player_node->getDebugPathString()) + += " " + translateLetter2(player_node->getImitationModeString()) + += translateLetter2(player_node->getCameraModeString()) + += translateLetter2(player_node->getAwayModeString())); - bar->setText(str); bar->setProgress(50); if (player_node->getDisableGameModifiers()) { diff --git a/src/gui/statuswindow.h b/src/gui/statuswindow.h index fa957d059..d3a619bcb 100644 --- a/src/gui/statuswindow.h +++ b/src/gui/statuswindow.h @@ -37,12 +37,6 @@ class ProgressBar; class ScrollArea; class VertContainer; -#ifdef __GNUC__ -#define A_UNUSED __attribute__ ((unused)) -#else -#define A_UNUSED -#endif - /** * The player status dialog. * @@ -82,7 +76,9 @@ class StatusWindow : public Window, void action(const gcn::ActionEvent &event); private: - static std::string translateLetter(char* letters); + static std::string translateLetter(const char* letters); + + static std::string translateLetter2(std::string letters); /** * Status Part diff --git a/src/gui/theme.cpp b/src/gui/theme.cpp index 0246a5b62..9aa6bb956 100644 --- a/src/gui/theme.cpp +++ b/src/gui/theme.cpp @@ -599,12 +599,17 @@ std::string Theme::resolveThemePath(const std::string &path) else file = path; - // Might be a valid path already - if (PHYSFS_exists(file.c_str())) - return path; + // File with path + if (file.find('/') != std::string::npos) + { + // Might be a valid path already + if (PHYSFS_exists(file.c_str())) + return path; + } // Try the theme file = getThemePath() + "/" + file; + if (PHYSFS_exists(file.c_str())) return getThemePath() + "/" + path; diff --git a/src/gui/viewport.h b/src/gui/viewport.h index 8823928a3..938988198 100644 --- a/src/gui/viewport.h +++ b/src/gui/viewport.h @@ -31,12 +31,6 @@ #include <guichan/mouselistener.hpp> -#ifdef __GNUC__ -#define A_UNUSED __attribute__ ((unused)) -#else -#define A_UNUSED -#endif - class ActorSprite; class Button; class Being; diff --git a/src/gui/whoisonline.cpp b/src/gui/whoisonline.cpp index ead38f42b..e0fa4ebcf 100644 --- a/src/gui/whoisonline.cpp +++ b/src/gui/whoisonline.cpp @@ -198,6 +198,7 @@ void WhoIsOnline::loadList() std::vector<std::string> friends; std::vector<std::string> neutral; std::vector<std::string> disregard; + std::vector<std::string> enemy; // Tokenize and add each line separately char *line = strtok(mMemoryBuffer, "\n"); @@ -270,6 +271,7 @@ void WhoIsOnline::loadList() switch (player_relations.getRelation(nick)) { case PlayerRelation::NEUTRAL: + default: neutral.push_back(prepareNick(nick, level, "0")); break; @@ -282,9 +284,12 @@ void WhoIsOnline::loadList() disregard.push_back(prepareNick(nick, level, "8")); break; + case PlayerRelation::ENEMY2: + enemy.push_back(prepareNick(nick, level, "1")); + break; + case PlayerRelation::IGNORED: case PlayerRelation::ERASED: - default: //Ignore the ignored. break; } @@ -316,6 +321,16 @@ void WhoIsOnline::loadList() mBrowserBox->addRow("---"); addedFromSection = false; } + for (int i = 0; i < static_cast<int>(enemy.size()); i++) + { + mBrowserBox->addRow(enemy.at(i)); + addedFromSection = true; + } + if (addedFromSection == true) + { + mBrowserBox->addRow("---"); + addedFromSection = false; + } for (int i = 0; i < static_cast<int>(neutral.size()); i++) { mBrowserBox->addRow(neutral.at(i)); diff --git a/src/gui/widgets/chattab.h b/src/gui/widgets/chattab.h index 4e077fafb..962c0b363 100644 --- a/src/gui/widgets/chattab.h +++ b/src/gui/widgets/chattab.h @@ -28,11 +28,7 @@ #include "gui/widgets/browserbox.h" #include "gui/widgets/tab.h" -#ifdef __GNUC__ -#define A_UNUSED __attribute__ ((unused)) -#else -#define A_UNUSED -#endif +#include "localconsts.h" class ScrollArea; @@ -58,6 +54,7 @@ class ChatTab : public Tab * Constructor. */ ChatTab(const std::string &name); + ~ChatTab(); /** @@ -106,7 +103,8 @@ class ChatTab : public Tab * Add any extra help text to the output. Allows tabs to define help * for commands defined by the tab itself. */ - virtual void showHelp() {} + virtual void showHelp() + { } /** * Handle special commands. Allows a tab to handle commands it diff --git a/src/gui/widgets/checkbox.h b/src/gui/widgets/checkbox.h index 4e293aad6..af38065f5 100644 --- a/src/gui/widgets/checkbox.h +++ b/src/gui/widgets/checkbox.h @@ -27,12 +27,6 @@ #include "localconsts.h" -#ifdef __GNUC__ -#define A_UNUSED __attribute__ ((unused)) -#else -#define A_UNUSED -#endif - class Image; /** diff --git a/src/gui/widgets/desktop.h b/src/gui/widgets/desktop.h index 6364ecfe9..b1f059ffe 100644 --- a/src/gui/widgets/desktop.h +++ b/src/gui/widgets/desktop.h @@ -27,12 +27,6 @@ #include <guichan/widgetlistener.hpp> -#ifdef __GNUC__ -#define A_UNUSED __attribute__ ((unused)) -#else -#define A_UNUSED -#endif - class Image; /** diff --git a/src/gui/widgets/dropshortcutcontainer.h b/src/gui/widgets/dropshortcutcontainer.h index 348f48567..1f03fd53b 100644 --- a/src/gui/widgets/dropshortcutcontainer.h +++ b/src/gui/widgets/dropshortcutcontainer.h @@ -28,12 +28,6 @@ #include "gui/widgets/shortcutcontainer.h" -#ifdef __GNUC__ -#define A_UNUSED __attribute__ ((unused)) -#else -#define A_UNUSED -#endif - class Image; class Item; class ItemPopup; diff --git a/src/gui/widgets/emoteshortcutcontainer.h b/src/gui/widgets/emoteshortcutcontainer.h index 06c009f0b..743ca4e87 100644 --- a/src/gui/widgets/emoteshortcutcontainer.h +++ b/src/gui/widgets/emoteshortcutcontainer.h @@ -27,12 +27,6 @@ #include <vector> -#ifdef __GNUC__ -#define A_UNUSED __attribute__ ((unused)) -#else -#define A_UNUSED -#endif - class AnimatedSprite; class Image; class TextPopup; diff --git a/src/gui/widgets/flowcontainer.h b/src/gui/widgets/flowcontainer.h index 2ef6035f0..d1f276b3c 100644 --- a/src/gui/widgets/flowcontainer.h +++ b/src/gui/widgets/flowcontainer.h @@ -26,12 +26,6 @@ #include <guichan/widgetlistener.hpp> -#ifdef __GNUC__ -#define A_UNUSED __attribute__ ((unused)) -#else -#define A_UNUSED -#endif - /** * A container that arranges its contents like words on a page. * diff --git a/src/gui/widgets/guitable.h b/src/gui/widgets/guitable.h index cf3cb8ad8..17f517644 100644 --- a/src/gui/widgets/guitable.h +++ b/src/gui/widgets/guitable.h @@ -33,12 +33,6 @@ #include <vector> -#ifdef __GNUC__ -#define A_UNUSED __attribute__ ((unused)) -#else -#define A_UNUSED -#endif - class GuiTableActionListener; /** diff --git a/src/gui/widgets/horizontcontainer.h b/src/gui/widgets/horizontcontainer.h index 80014c171..2a3f77d2b 100644 --- a/src/gui/widgets/horizontcontainer.h +++ b/src/gui/widgets/horizontcontainer.h @@ -26,12 +26,6 @@ #include <guichan/widgetlistener.hpp> -#ifdef __GNUC__ -#define A_UNUSED __attribute__ ((unused)) -#else -#define A_UNUSED -#endif - /** * A widget container. * diff --git a/src/gui/widgets/inventoryfilter.h b/src/gui/widgets/inventoryfilter.h index be69489a8..c3762189e 100644 --- a/src/gui/widgets/inventoryfilter.h +++ b/src/gui/widgets/inventoryfilter.h @@ -27,12 +27,6 @@ #include "gui/widgets/horizontcontainer.h" -#ifdef __GNUC__ -#define A_UNUSED __attribute__ ((unused)) -#else -#define A_UNUSED -#endif - class InventoryFilter : public HorizontContainer, public gcn::ActionListener { public: diff --git a/src/gui/widgets/itemcontainer.h b/src/gui/widgets/itemcontainer.h index e4188f54b..2c465fdee 100644 --- a/src/gui/widgets/itemcontainer.h +++ b/src/gui/widgets/itemcontainer.h @@ -31,12 +31,6 @@ #include <list> #include <algorithm> -#ifdef __GNUC__ -#define A_UNUSED __attribute__ ((unused)) -#else -#define A_UNUSED -#endif - class Image; class Inventory; class Item; diff --git a/src/gui/widgets/itemlinkhandler.h b/src/gui/widgets/itemlinkhandler.h index 8dd2f62f5..bc3bdc51c 100644 --- a/src/gui/widgets/itemlinkhandler.h +++ b/src/gui/widgets/itemlinkhandler.h @@ -25,21 +25,16 @@ #include "gui/widgets/linkhandler.h" -#ifdef __GNUC__ -#define A_UNUSED __attribute__ ((unused)) -#else -#define A_UNUSED -#endif - class ItemPopup; class ItemLinkHandler : public LinkHandler { public: ItemLinkHandler(); + ~ItemLinkHandler(); - void handleLink(const std::string &link, - gcn::MouseEvent *event A_UNUSED); + + void handleLink(const std::string &link, gcn::MouseEvent *event); private: ItemPopup *mItemPopup; diff --git a/src/gui/widgets/itemshortcutcontainer.h b/src/gui/widgets/itemshortcutcontainer.h index 473cef350..587723279 100644 --- a/src/gui/widgets/itemshortcutcontainer.h +++ b/src/gui/widgets/itemshortcutcontainer.h @@ -29,12 +29,6 @@ #include <guichan/mouselistener.hpp> -#ifdef __GNUC__ -#define A_UNUSED __attribute__ ((unused)) -#else -#define A_UNUSED -#endif - class Image; class Item; class ItemPopup; diff --git a/src/gui/widgets/layout.cpp b/src/gui/widgets/layout.cpp index 7f2f1f621..f0359062e 100644 --- a/src/gui/widgets/layout.cpp +++ b/src/gui/widgets/layout.cpp @@ -222,11 +222,15 @@ LayoutCell &LayoutArray::place(gcn::Widget *widget, int x, int y, int w, int h) return cell; } -void LayoutArray::align(int &pos, int &size, int dim, - LayoutCell const &cell, int *sizes) const +void LayoutArray::align(int &pos, int &size, int dim, LayoutCell const &cell, + int *sizes, int sizeCount) const { int size_max = sizes[0]; - for (int i = 1; i < cell.mExtent[dim]; ++i) + int cnt = cell.mExtent[dim]; + if (sizeCount && cell.mExtent[dim] > sizeCount) + cnt = sizeCount; + + for (int i = 1; i < cnt; ++i) size_max += sizes[i] + mSpacing; size = std::min<int>(cell.mSize[dim], size_max); @@ -274,7 +278,8 @@ std::vector<int> LayoutArray::getSizes(int dim, int upp) const } } - if (upp == Layout::AUTO_DEF) return sizes; + if (upp == Layout::AUTO_DEF) + return sizes; // Compute the FILL sizes. int nb = static_cast<int>(sizes.size()); @@ -343,8 +348,10 @@ void LayoutArray::reflow(int nx, int ny, int nw, int nh) if (cell && cell->mType != LayoutCell::NONE) { int dx = x, dy = y, dw = 0, dh = 0; - align(dx, dw, 0, *cell, &widths[gridX]); - align(dy, dh, 1, *cell, &heights[gridY]); + align(dx, dw, 0, *cell, &widths[gridX], + widths.size() - gridX); + align(dy, dh, 1, *cell, &heights[gridY], + heights.size() - gridY); cell->reflow(dx, dy, dw, dh); } x += widths[gridX] + mSpacing; diff --git a/src/gui/widgets/layout.h b/src/gui/widgets/layout.h index c4c703644..754d13a0b 100644 --- a/src/gui/widgets/layout.h +++ b/src/gui/widgets/layout.h @@ -127,8 +127,8 @@ class LayoutArray /** * Gets the position and size of a widget along a given axis */ - void align(int &pos, int &size, int dim, - LayoutCell const &cell, int *sizes) const; + void align(int &pos, int &size, int dim, LayoutCell const &cell, + int *sizes, int sizeCount) const; /** * Ensures the private vectors are large enough. diff --git a/src/gui/widgets/layouthelper.h b/src/gui/widgets/layouthelper.h index c38356c07..a01051595 100644 --- a/src/gui/widgets/layouthelper.h +++ b/src/gui/widgets/layouthelper.h @@ -27,12 +27,6 @@ #include <guichan/widgetlistener.hpp> -#ifdef __GNUC__ -#define A_UNUSED __attribute__ ((unused)) -#else -#define A_UNUSED -#endif - /** * A helper class for adding a layout to a Guichan container widget. The layout * will register itself as a widget listener and relayout the widgets in the diff --git a/src/gui/widgets/listbox.h b/src/gui/widgets/listbox.h index 418b83f58..8ac0bbc3b 100644 --- a/src/gui/widgets/listbox.h +++ b/src/gui/widgets/listbox.h @@ -25,12 +25,6 @@ #include <guichan/widgets/listbox.hpp> -#ifdef __GNUC__ -#define A_UNUSED __attribute__ ((unused)) -#else -#define A_UNUSED -#endif - class SelectionListener; /** diff --git a/src/gui/widgets/popup.h b/src/gui/widgets/popup.h index 9d4343ba3..64e4b52ac 100644 --- a/src/gui/widgets/popup.h +++ b/src/gui/widgets/popup.h @@ -32,12 +32,6 @@ #include <guichan/mouselistener.hpp> #include <guichan/widgetlistener.hpp> -#ifdef __GNUC__ -#define A_UNUSED __attribute__ ((unused)) -#else -#define A_UNUSED -#endif - class GraphicsVertexes; class Skin; class WindowContainer; diff --git a/src/gui/widgets/radiobutton.h b/src/gui/widgets/radiobutton.h index 677195bd6..d1c347acb 100644 --- a/src/gui/widgets/radiobutton.h +++ b/src/gui/widgets/radiobutton.h @@ -25,12 +25,6 @@ #include <guichan/widgets/radiobutton.hpp> -#ifdef __GNUC__ -#define A_UNUSED __attribute__ ((unused)) -#else -#define A_UNUSED -#endif - class Image; /** diff --git a/src/gui/widgets/scrollarea.h b/src/gui/widgets/scrollarea.h index 56e21c58c..105791080 100644 --- a/src/gui/widgets/scrollarea.h +++ b/src/gui/widgets/scrollarea.h @@ -26,12 +26,6 @@ #include <guichan/widgets/scrollarea.hpp> #include <guichan/widgetlistener.hpp> -#ifdef __GNUC__ -#define A_UNUSED __attribute__ ((unused)) -#else -#define A_UNUSED -#endif - class GraphicsVertexes; class Image; class ImageRect; diff --git a/src/gui/widgets/setupitem.h b/src/gui/widgets/setupitem.h index 15d2d41ea..5b8a9df87 100644 --- a/src/gui/widgets/setupitem.h +++ b/src/gui/widgets/setupitem.h @@ -33,12 +33,6 @@ #include <list> -#ifdef __GNUC__ -#define A_UNUSED __attribute__ ((unused)) -#else -#define A_UNUSED -#endif - class CheckBox; class Configuration; class ContainerPlacer; diff --git a/src/gui/widgets/setuptabscroll.h b/src/gui/widgets/setuptabscroll.h index d2aa7002f..2b0c6f65e 100644 --- a/src/gui/widgets/setuptabscroll.h +++ b/src/gui/widgets/setuptabscroll.h @@ -26,11 +26,7 @@ #include <map> #include <set> -#ifdef __GNUC__ -#define A_UNUSED __attribute__ ((unused)) -#else -#define A_UNUSED -#endif +#include "localconsts.h" class SetupItem; class ScrollArea; diff --git a/src/gui/widgets/shoplistbox.h b/src/gui/widgets/shoplistbox.h index 38e238f20..c5acbbefc 100644 --- a/src/gui/widgets/shoplistbox.h +++ b/src/gui/widgets/shoplistbox.h @@ -25,12 +25,6 @@ #include "gui/widgets/listbox.h" -#ifdef __GNUC__ -#define A_UNUSED __attribute__ ((unused)) -#else -#define A_UNUSED -#endif - class ShopItems; class ItemPopup; @@ -82,7 +76,7 @@ class ShopListBox : public ListBox void mouseMoved(gcn::MouseEvent &event); - void mouseExited(gcn::MouseEvent& mouseEvent A_UNUSED); + void mouseExited(gcn::MouseEvent& mouseEvent); private: void init(); diff --git a/src/gui/widgets/shortcutcontainer.h b/src/gui/widgets/shortcutcontainer.h index df8529bd5..8587950c6 100644 --- a/src/gui/widgets/shortcutcontainer.h +++ b/src/gui/widgets/shortcutcontainer.h @@ -29,12 +29,6 @@ #include "gui/widgets/tab.h" -#ifdef __GNUC__ -#define A_UNUSED __attribute__ ((unused)) -#else -#define A_UNUSED -#endif - class Image; /** @@ -55,7 +49,8 @@ class ShortcutContainer : public gcn::Widget, /** * Destructor. */ - ~ShortcutContainer() {} + ~ShortcutContainer() + { } /** * Draws the shortcuts diff --git a/src/gui/widgets/slider.h b/src/gui/widgets/slider.h index 619c0c795..9ac45d0a0 100644 --- a/src/gui/widgets/slider.h +++ b/src/gui/widgets/slider.h @@ -25,12 +25,6 @@ #include <guichan/widgets/slider.hpp> -#ifdef __GNUC__ -#define A_UNUSED __attribute__ ((unused)) -#else -#define A_UNUSED -#endif - class Image; /** diff --git a/src/gui/widgets/spellshortcutcontainer.h b/src/gui/widgets/spellshortcutcontainer.h index 88b00338a..4191f9921 100644 --- a/src/gui/widgets/spellshortcutcontainer.h +++ b/src/gui/widgets/spellshortcutcontainer.h @@ -27,13 +27,6 @@ #include <guichan/mouselistener.hpp> #include "gui/widgets/shortcutcontainer.h" -//#include "textcommand.h" - -#ifdef __GNUC__ -#define A_UNUSED __attribute__ ((unused)) -#else -#define A_UNUSED -#endif class Image; class SpellPopup; diff --git a/src/gui/widgets/tabbedarea.h b/src/gui/widgets/tabbedarea.h index af241d7c5..d71109dd3 100644 --- a/src/gui/widgets/tabbedarea.h +++ b/src/gui/widgets/tabbedarea.h @@ -32,12 +32,6 @@ #include <string> -#ifdef __GNUC__ -#define A_UNUSED __attribute__ ((unused)) -#else -#define A_UNUSED -#endif - class Tab; /** diff --git a/src/gui/widgets/vertcontainer.h b/src/gui/widgets/vertcontainer.h index 3b0ceeca7..08546aa47 100644 --- a/src/gui/widgets/vertcontainer.h +++ b/src/gui/widgets/vertcontainer.h @@ -28,12 +28,6 @@ #include <vector> -#ifdef __GNUC__ -#define A_UNUSED __attribute__ ((unused)) -#else -#define A_UNUSED -#endif - /** * A widget container. * diff --git a/src/gui/widgets/whispertab.cpp b/src/gui/widgets/whispertab.cpp index c99c4e0c5..33859d8be 100644 --- a/src/gui/widgets/whispertab.cpp +++ b/src/gui/widgets/whispertab.cpp @@ -165,3 +165,8 @@ void WhisperTab::saveToLogFile(std::string &msg) if (chatLogger) chatLogger->log(getNick(), msg); } + +void WhisperTab::getAutoCompleteList(std::vector<std::string> &names) const +{ + names.push_back(mNick); +} diff --git a/src/gui/widgets/whispertab.h b/src/gui/widgets/whispertab.h index 5bca422a6..8678c932c 100644 --- a/src/gui/widgets/whispertab.h +++ b/src/gui/widgets/whispertab.h @@ -33,7 +33,8 @@ class Channel; class WhisperTab : public ChatTab { public: - const std::string &getNick() const { return mNick; } + const std::string &getNick() const + { return mNick; } void showHelp(); @@ -45,6 +46,8 @@ class WhisperTab : public ChatTab void saveToLogFile(std::string &msg); + void getAutoCompleteList(std::vector<std::string> &names) const; + protected: friend class ChatWindow; diff --git a/src/gui/widgets/window.h b/src/gui/widgets/window.h index 5ace2328e..6249626d3 100644 --- a/src/gui/widgets/window.h +++ b/src/gui/widgets/window.h @@ -31,12 +31,6 @@ #include <guichan/widgets/window.hpp> -#ifdef __GNUC__ -#define A_UNUSED __attribute__ ((unused)) -#else -#define A_UNUSED -#endif - class ContainerPlacer; class GraphicsVertexes; class Layout; diff --git a/src/gui/windowmenu.h b/src/gui/windowmenu.h index 739a302ba..3f02ea851 100644 --- a/src/gui/windowmenu.h +++ b/src/gui/windowmenu.h @@ -29,15 +29,11 @@ #include <guichan/actionlistener.hpp> #include <guichan/selectionlistener.hpp> +#include "localconsts.h" + #include <map> #include <vector> -#ifdef __GNUC__ -#define A_UNUSED __attribute__ ((unused)) -#else -#define A_UNUSED -#endif - class EmotePopup; class TextPopup; diff --git a/src/imagesprite.h b/src/imagesprite.h index 21705c812..9dad0f743 100644 --- a/src/imagesprite.h +++ b/src/imagesprite.h @@ -22,12 +22,6 @@ #ifndef IMAGESPRITE_H #define IMAGESPRITE_H -#ifdef __GNUC__ -#define A_UNUSED __attribute__ ((unused)) -#else -#define A_UNUSED -#endif - #include "sprite.h" #include "resources/image.h" @@ -73,6 +67,9 @@ public: unsigned int getFrameCount() const { return 1; } + bool updateNumber(unsigned num A_UNUSED) + { return false; } + private: Image *mImage; }; diff --git a/src/localconsts.h b/src/localconsts.h index cd7fcd955..e135a4108 100644 --- a/src/localconsts.h +++ b/src/localconsts.h @@ -22,3 +22,9 @@ #undef nullptr #define nullptr 0 #endif + +#ifdef __GNUC__ +#define A_UNUSED __attribute__ ((unused)) +#else +#define A_UNUSED +#endif
\ No newline at end of file diff --git a/src/localplayer.cpp b/src/localplayer.cpp index 0739ab538..cbf75a5f9 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -190,7 +190,6 @@ LocalPlayer::LocalPlayer(int id, int subtype): PlayerInfo::setStatMod(WALK_SPEED, 0); loadHomes(); -// initTargetCursor(); config.addListener("showownname", this); config.addListener("targetDeadPlayers", this); @@ -278,16 +277,12 @@ void LocalPlayer::logic() { if (mMessageTime == 0) { - //const Vector &pos = getPosition(); - MessagePair info = mMessages.front(); if (particleEngine) { particleEngine->addTextRiseFadeOutEffect( info.first, - /*(int) pos.x, - (int) pos.y - 48,*/ getPixelX(), getPixelY() - 48, &userPalette->getColor(info.second), @@ -818,8 +813,6 @@ void LocalPlayer::nextTile(unsigned char dir A_UNUSED = 0) if (Net::getNetworkType() != ServerInfo::MANASERV) #endif { -// updatePos(); - if (Party::getParty(1)) { PartyMember *pm = Party::getParty(1)->getMember(getName()); @@ -973,7 +966,6 @@ bool LocalPlayer::pickUp(FloorItem *item) mPickUpTarget = item; mPickUpTarget->addActorSpriteListener(this); -// stopAttack(); } } return true; @@ -1867,84 +1859,384 @@ void LocalPlayer::moveToHome() } } -void LocalPlayer::changeAttackWeaponType() -{ - mAttackWeaponType++; - if (mAttackWeaponType > 3) - mAttackWeaponType = 1; - - config.setValue("attackWeaponType", mAttackWeaponType); - if (miniStatusWindow) - miniStatusWindow->updateStatus(); -} +static const unsigned invertDirectionSize = 5; -void LocalPlayer::changeAttackType() +void LocalPlayer::changeMode(unsigned *var, unsigned limit, const char *conf, + std::string (LocalPlayer::*func)(), unsigned def) { - mAttackType++; - if (mAttackType > 3) - mAttackType = 0; - - config.setValue("attackType", mAttackType); + (*var) ++; + if (*var >= limit) + *var = def; + config.setValue(conf, *var); if (miniStatusWindow) miniStatusWindow->updateStatus(); + const std::string str = (this->*func)(); + if (str.size() > 4) + debugMsg(str.substr(4)); } void LocalPlayer::invertDirection() { mMoveState = 0; - mInvertDirection ++; - if (mInvertDirection > 4) - mInvertDirection = 0; - config.setValue("invertMoveDirection", mInvertDirection); - if (miniStatusWindow) - miniStatusWindow->updateStatus(); + changeMode(&mInvertDirection, invertDirectionSize, "invertMoveDirection", + &LocalPlayer::getInvertDirectionString); +} + +static const char *invertDirectionStrings[] = +{ + N_("(D) default moves"), + N_("(I) invert moves"), + N_("(c) moves with some crazy moves"), + N_("(C) moves with crazy moves"), + N_("(d) double normal + crazy"), + N_("(?) unknown move") +}; + +std::string LocalPlayer::getInvertDirectionString() +{ + return gettext(getVarItem(&invertDirectionStrings[0], + mInvertDirection, invertDirectionSize)); } +static const unsigned crazyMoveTypeSize = 11; + void LocalPlayer::changeCrazyMoveType() { mCrazyMoveState = 0; - mCrazyMoveType++; - if (mCrazyMoveType > 10) - mCrazyMoveType = 1; + changeMode(&mCrazyMoveType, crazyMoveTypeSize, "crazyMoveType", + &LocalPlayer::getCrazyMoveTypeString, 1); +} - config.setValue("crazyMoveType", mCrazyMoveType); - if (miniStatusWindow) - miniStatusWindow->updateStatus(); +std::string LocalPlayer::getCrazyMoveTypeString() +{ + if (mCrazyMoveType < crazyMoveTypeSize - 1) + { + return strprintf(_("(%d) crazy move number %d"), + mCrazyMoveType, mCrazyMoveType); + } + else if (mCrazyMoveType == crazyMoveTypeSize - 1) + { + return _("(a) custom crazy move"); + } + else + { + return _("(?) crazy move"); + } } -void LocalPlayer::changePickUpType() +static const unsigned moveToTargetTypeSize = 8; + +void LocalPlayer::changeMoveToTargetType() { - mPickUpType++; - if (mPickUpType > 6) - mPickUpType = 0; + changeMode(&mMoveToTargetType, moveToTargetTypeSize, "moveToTargetType", + &LocalPlayer::getMoveToTargetTypeString); +} - config.setValue("pickUpType", mPickUpType); - if (miniStatusWindow) - miniStatusWindow->updateStatus(); +static const char *moveToTargetTypeStrings[] = +{ + N_("(0) default moves to target"), + N_("(1) moves to target in distance 1"), + N_("(2) moves to target in distance 2"), + N_("(3) moves to target in distance 3"), + N_("(5) moves to target in distance 5"), + N_("(7) moves to target in distance 7"), + N_("(A) moves to target in attack range"), + N_("(a) archer attack range"), + N_("(?) move to target") +}; + +std::string LocalPlayer::getMoveToTargetTypeString() +{ + return gettext(getVarItem(&moveToTargetTypeStrings[0], + mMoveToTargetType, moveToTargetTypeSize)); } +static const unsigned followModeSize = 4; + void LocalPlayer::changeFollowMode() { - mFollowMode++; - if (mFollowMode > 3) - mFollowMode = 0; + changeMode(&mFollowMode, followModeSize, "followMode", + &LocalPlayer::getFollowModeString); +} - config.setValue("followMode", mFollowMode); - if (miniStatusWindow) - miniStatusWindow->updateStatus(); +static const char *followModeStrings[] = +{ + N_("(D) default follow"), + N_("(R) relative follow"), + N_("(M) mirror follow"), + N_("(P) pet follow"), + N_("(?) unknown follow") +}; + +std::string LocalPlayer::getFollowModeString() +{ + return gettext(getVarItem(&followModeStrings[0], + mFollowMode, followModeSize)); +} + +const unsigned attackWeaponTypeSize = 4; + +void LocalPlayer::changeAttackWeaponType() +{ + changeMode(&mAttackWeaponType, attackWeaponTypeSize, "attackWeaponType", + &LocalPlayer::getAttackWeaponTypeString, 1); +} + +static const char *attackWeaponTypeStrings[] = +{ + N_("(?) attack"), + N_("(D) default attack"), + N_("(s) switch attack without shield"), + N_("(S) switch attack with shield"), + N_("(?) attack") +}; + +std::string LocalPlayer::getAttackWeaponTypeString() +{ + return gettext(getVarItem(&attackWeaponTypeStrings[0], + mAttackWeaponType, attackWeaponTypeSize)); +} + +const unsigned attackTypeSize = 4; + +void LocalPlayer::changeAttackType() +{ + changeMode(&mAttackType, attackTypeSize, "attackType", + &LocalPlayer::getAttackTypeString); +} + +static const char *attackTypeStrings[] = +{ + N_("(D) default attack"), + N_("(G) go and attack"), + N_("(A) go, attack, pickup"), + N_("(d) without auto attack"), + N_("(?) attack") +}; + +std::string LocalPlayer::getAttackTypeString() +{ + return gettext(getVarItem(&attackTypeStrings[0], + mAttackType, attackTypeSize)); } +const unsigned quickDropCounterSize = 10; + +void LocalPlayer::changeQuickDropCounter() +{ + changeMode(&mQuickDropCounter, quickDropCounterSize, "quickDropCounter", + &LocalPlayer::getQuickDropCounterString, 1); +} + +std::string LocalPlayer::getQuickDropCounterString() +{ + return strprintf("(%d) drop counter %d", + mQuickDropCounter, mQuickDropCounter); +} + +const unsigned pickUpTypeSize = 7; + +void LocalPlayer::changePickUpType() +{ + changeMode(&mPickUpType, pickUpTypeSize, "pickUpType", + &LocalPlayer::getPickUpTypeString); +} + +static const char *pickUpTypeStrings[] = +{ + N_("(S) small pick up 1x1 cells"), + N_("(D) default pick up 2x1 cells"), + N_("(F) forward pick up 2x3 cells"), + N_("(3) pick up 3x3 cells"), + N_("(g) go and pick up in distance 4"), + N_("(G) go and pick up in distance 8"), + N_("(A) go and pick up in max distance"), + N_("(?) pick up") +}; + +std::string LocalPlayer::getPickUpTypeString() +{ + return gettext(getVarItem(&pickUpTypeStrings[0], + mPickUpType, pickUpTypeSize)); +} + +const unsigned debugPathSize = 5; + +static const char *debugPathStrings[] = +{ + N_("(N) normal map view"), + N_("(D) debug map view"), + N_("(u) ultra map view"), + N_("(U) ultra map view 2"), + N_("(e) empty map view"), + N_("(b) black & white map view") +}; + +std::string LocalPlayer::getDebugPathString() +{ + return gettext(getVarItem(&debugPathStrings[0], + viewport->getDebugPath(), debugPathSize)); +} + +const unsigned magicAttackSize = 5; + +void LocalPlayer::switchMagicAttack() +{ + changeMode(&mMagicAttackType, magicAttackSize, "magicAttackType", + &LocalPlayer::getMagicAttackString); +} + +static const char *magicAttackStrings[] = +{ + N_("(f) use #flar for magic attack"), + N_("(c) use #chiza for magic attack"), + N_("(I) use #ingrav for magic attack"), + N_("(F) use #frillyar for magic attack"), + N_("(U) use #upmarmu for magic attack"), + N_("(?) magic attack") +}; + +std::string LocalPlayer::getMagicAttackString() +{ + return gettext(getVarItem(&magicAttackStrings[0], + mMagicAttackType, magicAttackSize)); +} + +const unsigned pvpAttackSize = 4; + +void LocalPlayer::switchPvpAttack() +{ + changeMode(&mPvpAttackType, pvpAttackSize, "pvpAttackType", + &LocalPlayer::getPvpAttackString); +} + +static const char *pvpAttackStrings[] = +{ + N_("(a) attack all players"), + N_("(f) attack not friends"), + N_("(b) attack bad relations"), + N_("(d) dont attack players"), + N_("(?) pvp attack") +}; + +std::string LocalPlayer::getPvpAttackString() +{ + return gettext(getVarItem(&pvpAttackStrings[0], + mPvpAttackType, pvpAttackSize)); +} + +const unsigned imitationModeSize = 2; + void LocalPlayer::changeImitationMode() { - mImitationMode++; - if (mImitationMode > 1) - mImitationMode = 0; + changeMode(&mImitationMode, imitationModeSize, "imitationMode", + &LocalPlayer::getImitationModeString); +} - config.setValue("imitationMode", mImitationMode); +static const char *imitationModeStrings[] = +{ + N_("(D) default imitation"), + N_("(O) outfits imitation"), + N_("(?) imitation") +}; + +std::string LocalPlayer::getImitationModeString() +{ + return gettext(getVarItem(&imitationModeStrings[0], + mImitationMode, imitationModeSize)); +} + +const unsigned awayModeSize = 2; + +void LocalPlayer::changeAwayMode() +{ + mAwayMode = !mAwayMode; + mAfkTime = 0; + mInactive = false; + updateName(); if (miniStatusWindow) miniStatusWindow->updateStatus(); + if (mAwayMode) + { + if (chatWindow) + chatWindow->clearAwayLog(); + + cancelFollow(); + navigateClean(); + if (outfitWindow) + outfitWindow->wearAwayOutfit(); + mAwayDialog = new OkDialog(_("Away"), + config.getStringValue("afkMessage"), true, false); + mAwayDialog->addActionListener(mAwayListener); + sound.volumeOff(); + } + else + { + mAwayDialog = nullptr; + sound.volumeRestore(); + if (chatWindow) + { + chatWindow->displayAwayLog(); + chatWindow->clearAwayLog(); + } + } +} + +static const char *awayModeStrings[] = +{ + N_("(O) on keyboard"), + N_("(A) away"), + N_("(?) away") +}; + +std::string LocalPlayer::getAwayModeString() +{ + return gettext(getVarItem(&awayModeStrings[0], + mAwayMode, awayModeSize)); +} + +const unsigned cameraModeSize = 2; + +static const char *cameraModeStrings[] = +{ + N_("(G) game camera mode"), + N_("(F) free camera mode"), + N_("(?) away") +}; + +std::string LocalPlayer::getCameraModeString() +{ + return gettext(getVarItem(&cameraModeStrings[0], + viewport->getCameraMode(), cameraModeSize)); } +const unsigned gameModifiersSize = 2; + +void LocalPlayer::switchGameModifiers() +{ + mDisableGameModifiers = !mDisableGameModifiers; + config.setValue("disableGameModifiers", mDisableGameModifiers); + miniStatusWindow->updateStatus(); + + const std::string str = getGameModifiersString(); + if (str.size() > 4) + debugMsg(str.substr(4)); +} + +static const char *gameModifiersStrings[] = +{ + _("Game modifiers are enabled"), + _("Game modifiers are disabled"), + _("Game modifiers are unknown") +}; + +std::string LocalPlayer::getGameModifiersString() +{ + return gettext(getVarItem(&gameModifiersStrings[0], + mDisableGameModifiers, gameModifiersSize)); +} + + void LocalPlayer::changeEquipmentBeforeAttack(Being* target) { if (mAttackWeaponType == 1 || !target || !PlayerInfo::getInventory()) @@ -2742,10 +3034,7 @@ bool LocalPlayer::pickUpItems(int pickUpType) } item = actorSpriteManager->findItem(x, y); if (item) - { status = pickUp(item); -// status = true; - } break; case 2: switch (mDirection) @@ -2806,15 +3095,6 @@ bool LocalPlayer::pickUpItems(int pickUpType) return status; } -void LocalPlayer::changeQuickDropCounter() -{ - mQuickDropCounter++; - if (mQuickDropCounter > 9) - mQuickDropCounter = 1; - - config.setValue("quickDropCounter", mQuickDropCounter); - miniStatusWindow->updateStatus(); -} void LocalPlayer::moveByDirection(unsigned char dir) { @@ -2891,28 +3171,6 @@ void LocalPlayer::debugMsg(std::string str) debugChatTab->chatLog(str); } -void LocalPlayer::switchMagicAttack() -{ - mMagicAttackType++; - if (mMagicAttackType > 4) - mMagicAttackType = 0; - - config.setValue("magicAttackType", mMagicAttackType); - if (miniStatusWindow) - miniStatusWindow->updateStatus(); -} - -void LocalPlayer::switchPvpAttack() -{ - mPvpAttackType++; - if (mPvpAttackType > 3) - mPvpAttackType = 0; - - config.setValue("pvpAttackType", mPvpAttackType); - if (miniStatusWindow) - miniStatusWindow->updateStatus(); -} - void LocalPlayer::magicAttack() { if (!chatWindow || !isAlive() @@ -2970,17 +3228,6 @@ void LocalPlayer::tryMagic(std::string spell, int baseMagic, } } -void LocalPlayer::changeMoveToTargetType() -{ - mMoveToTargetType++; - if (mMoveToTargetType > 7) - mMoveToTargetType = 0; - - config.setValue("moveToTargetType", mMoveToTargetType); - if (miniStatusWindow) - miniStatusWindow->updateStatus(); -} - void LocalPlayer::loadHomes() { std::string homeStr = serverConfig.getValue("playerHomes", @@ -3136,14 +3383,6 @@ void LocalPlayer::saveHomes() serverConfig.setValue("playerHomes", ss.str()); } - -void LocalPlayer::switchGameModifiers() -{ - mDisableGameModifiers = !mDisableGameModifiers; - config.setValue("disableGameModifiers", mDisableGameModifiers); - miniStatusWindow->updateStatus(); -} - void LocalPlayer::pingRequest() { if (mWaitPing == true && mPingSendTick != 0) @@ -3186,39 +3425,6 @@ void LocalPlayer::tryPingRequest() } } -void LocalPlayer::changeAwayMode() -{ - mAwayMode = !mAwayMode; - mAfkTime = 0; - mInactive = false; - updateName(); - if (miniStatusWindow) - miniStatusWindow->updateStatus(); - if (mAwayMode) - { - if (chatWindow) - chatWindow->clearAwayLog(); - - cancelFollow(); - navigateClean(); - if (outfitWindow) - outfitWindow->wearAwayOutfit(); - mAwayDialog = new OkDialog(_("Away"), - config.getStringValue("afkMessage"), true, false); - mAwayDialog->addActionListener(mAwayListener); - sound.volumeOff(); - } - else - { - mAwayDialog = nullptr; - sound.volumeRestore(); - if (chatWindow) - { - chatWindow->displayAwayLog(); - chatWindow->clearAwayLog(); - } - } -} void LocalPlayer::setAway(const std::string &message) { @@ -3424,7 +3630,6 @@ void LocalPlayer::updateCoords() tmpLayer->clean(); tmpLayer->addRoad(mNavigatePath); } -// navigateTo(mNavigateX, mNavigateY); } } } @@ -3981,6 +4186,15 @@ bool LocalPlayer::checAttackPermissions(Being *target) } } + +const char *LocalPlayer::getVarItem(const char **arr, unsigned index, + unsigned sz) +{ + if (index < sz) + return arr[index]; + return arr[sz]; +} + void AwayListener::action(const gcn::ActionEvent &event) { if (event.getId() == "ok" && player_node && player_node->getAway()) diff --git a/src/localplayer.h b/src/localplayer.h index 08ebbe841..5b755e4f6 100644 --- a/src/localplayer.h +++ b/src/localplayer.h @@ -37,12 +37,6 @@ #include <memory> #include <vector> -#ifdef __GNUC__ -#define A_UNUSED __attribute__ ((unused)) -#else -#define A_UNUSED -#endif - class ChatTab; class FloorItem; class ImageSet; @@ -483,6 +477,36 @@ class LocalPlayer : public Being, public ActorSpriteListener, bool checAttackPermissions(Being *target); + std::string getInvertDirectionString(); + + std::string getCrazyMoveTypeString(); + + std::string getMoveToTargetTypeString(); + + std::string getFollowModeString(); + + std::string getAttackWeaponTypeString(); + + std::string getAttackTypeString(); + + std::string getQuickDropCounterString(); + + std::string getPickUpTypeString(); + + std::string getDebugPathString(); + + std::string getMagicAttackString(); + + std::string getPvpAttackString(); + + std::string getImitationModeString(); + + std::string getAwayModeString(); + + std::string getCameraModeString(); + + std::string getGameModifiersString(); + protected: /** Whether or not the name settings have changed */ bool mUpdateName; @@ -496,6 +520,11 @@ class LocalPlayer : public Being, public ActorSpriteListener, void tryMagic(std::string spell, int baseMagic, int schoolMagic, int mana); + const char *getVarItem(const char **arr, unsigned index, unsigned sz); + + void changeMode(unsigned *var, unsigned limit, const char *conf, + std::string (LocalPlayer::*func)(), unsigned def = 0); + void crazyMove1(); void crazyMove2(); void crazyMove3(); diff --git a/src/main.h b/src/main.h index f0f3b8c2c..6f7c0980a 100644 --- a/src/main.h +++ b/src/main.h @@ -45,8 +45,8 @@ * different interfaces, which have different implementations for each server. */ -#define SMALL_VERSION "1.1.11.12" -#define CHECK_VERSION "01.01.11.12" +#define SMALL_VERSION "1.1.11.27" +#define CHECK_VERSION "01.01.11.27" #ifdef HAVE_CONFIG_H #include "../config.h" @@ -98,10 +98,4 @@ #define PKG_DATADIR "" #endif -#ifdef __GNUC__ -#define A_UNUSED __attribute__ ((unused)) -#else -#define A_UNUSED -#endif - #endif diff --git a/src/map.cpp b/src/map.cpp index bcf2b22fe..e706f120b 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -85,7 +85,7 @@ class ActorFunctuator { if (!a || !b) return false; - return a->getPixelY() < b->getPixelY(); + return a->getSortPixelY() < b->getSortPixelY(); } } actorCompare; @@ -32,12 +32,6 @@ #include <string> #include <vector> -#ifdef __GNUC__ -#define A_UNUSED __attribute__ ((unused)) -#else -#define A_UNUSED -#endif - class Animation; class AmbientLayer; class Graphics; diff --git a/src/net/charhandler.h b/src/net/charhandler.h index 72a81684c..848354e96 100644 --- a/src/net/charhandler.h +++ b/src/net/charhandler.h @@ -90,6 +90,8 @@ class CharHandler virtual unsigned int maxSprite() const = 0; + virtual void clear() = 0; + protected: CharHandler() : mSelectedCharacter(0), diff --git a/src/net/download.h b/src/net/download.h index 12c0c07d7..8339dee30 100644 --- a/src/net/download.h +++ b/src/net/download.h @@ -28,12 +28,6 @@ #include <stdio.h> #include <string> -#ifdef __GNUC__ -#define A_UNUSED __attribute__ ((unused)) -#else -#define A_UNUSED -#endif - enum DownloadStatus { DOWNLOAD_STATUS_CANCELLED = -3, diff --git a/src/net/ea/adminhandler.h b/src/net/ea/adminhandler.h index 2e311881f..5d1b7aa14 100644 --- a/src/net/ea/adminhandler.h +++ b/src/net/ea/adminhandler.h @@ -26,12 +26,6 @@ #include "net/adminhandler.h" #include "net/net.h" -#ifdef __GNUC__ -#define A_UNUSED __attribute__ ((unused)) -#else -#define A_UNUSED -#endif - namespace Ea { diff --git a/src/net/ea/beinghandler.cpp b/src/net/ea/beinghandler.cpp index 5c3c694b3..1c2983137 100644 --- a/src/net/ea/beinghandler.cpp +++ b/src/net/ea/beinghandler.cpp @@ -215,10 +215,10 @@ void BeingHandler::processBeingVisibleOrMove(Net::MessageIn &msg, bool visible) int maxHP = msg.readInt32(); if (hp && maxHP) { + dstBeing->setMaxHP(maxHP); int oldHP = dstBeing->getHP(); if (!oldHP || oldHP > hp) dstBeing->setHP(hp); - dstBeing->setMaxHP(maxHP); } } else diff --git a/src/net/ea/beinghandler.h b/src/net/ea/beinghandler.h index f3769943d..f47385a61 100644 --- a/src/net/ea/beinghandler.h +++ b/src/net/ea/beinghandler.h @@ -26,12 +26,6 @@ #include "net/beinghandler.h" #include "net/net.h" -#ifdef __GNUC__ -#define A_UNUSED __attribute__ ((unused)) -#else -#define A_UNUSED -#endif - namespace Ea { diff --git a/src/net/ea/charserverhandler.cpp b/src/net/ea/charserverhandler.cpp index 0c01959f2..63e267584 100644 --- a/src/net/ea/charserverhandler.cpp +++ b/src/net/ea/charserverhandler.cpp @@ -33,8 +33,11 @@ #include "net/ea/loginhandler.h" #include "net/ea/eaprotocol.h" +#include "utils/dtor.h" #include "utils/gettext.h" +#include "resources/chardb.h" + #include "debug.h" extern Net::CharHandler *charHandler; @@ -70,7 +73,17 @@ void CharServerHandler::setCharCreateDialog(CharCreateDialog *window) const Token &token = static_cast<LoginHandler*>(Net::getLoginHandler())->getToken(); - mCharCreateDialog->setAttributes(attributes, 30, 1, 9); + int minStat = CharDB::getMinStat(); + if (!minStat) + minStat = 1; + int maxStat = CharDB::getMaxStat(); + if (!maxStat) + maxStat = 9; + int sumStat = CharDB::getSumStat(); + if (!sumStat) + sumStat = 30; + + mCharCreateDialog->setAttributes(attributes, sumStat, minStat, maxStat); mCharCreateDialog->setFixedGender(true, token.sex); } @@ -172,4 +185,10 @@ void CharServerHandler::processCharDeleteFailed(Net::MessageIn &msg A_UNUSED) new OkDialog(_("Error"), _("Failed to delete character.")); } +void CharServerHandler::clear() +{ + delete_all(mCharacters); + mCharacters.clear(); +} + } // namespace Ea diff --git a/src/net/ea/charserverhandler.h b/src/net/ea/charserverhandler.h index bd39781cd..bacde67b6 100644 --- a/src/net/ea/charserverhandler.h +++ b/src/net/ea/charserverhandler.h @@ -28,12 +28,6 @@ #include "net/net.h" #include "net/serverinfo.h" -#ifdef __GNUC__ -#define A_UNUSED __attribute__ ((unused)) -#else -#define A_UNUSED -#endif - class LoginData; namespace Ea @@ -78,6 +72,8 @@ class CharServerHandler : public Net::CharHandler virtual void processCharDeleteFailed(Net::MessageIn &msg); + virtual void clear(); + protected: virtual void readPlayerData(Net::MessageIn &msg, Net::Character *character, diff --git a/src/net/ea/chathandler.h b/src/net/ea/chathandler.h index cff9bf589..d39e6788a 100644 --- a/src/net/ea/chathandler.h +++ b/src/net/ea/chathandler.h @@ -30,12 +30,6 @@ #include <queue> -#ifdef __GNUC__ -#define A_UNUSED __attribute__ ((unused)) -#else -#define A_UNUSED -#endif - namespace Ea { diff --git a/src/net/ea/gamehandler.h b/src/net/ea/gamehandler.h index 6d8b88bd4..511efe357 100644 --- a/src/net/ea/gamehandler.h +++ b/src/net/ea/gamehandler.h @@ -29,12 +29,6 @@ #include "net/messagein.h" #include "net/net.h" -#ifdef __GNUC__ -#define A_UNUSED __attribute__ ((unused)) -#else -#define A_UNUSED -#endif - namespace Ea { diff --git a/src/net/ea/guildhandler.h b/src/net/ea/guildhandler.h index 06edb2e89..5b090ec41 100644 --- a/src/net/ea/guildhandler.h +++ b/src/net/ea/guildhandler.h @@ -27,12 +27,6 @@ #include "net/ea/gui/guildtab.h" -#ifdef __GNUC__ -#define A_UNUSED __attribute__ ((unused)) -#else -#define A_UNUSED -#endif - namespace Ea { diff --git a/src/net/ea/inventoryhandler.h b/src/net/ea/inventoryhandler.h index d99e34fc6..6db6b18ed 100644 --- a/src/net/ea/inventoryhandler.h +++ b/src/net/ea/inventoryhandler.h @@ -38,12 +38,6 @@ #include <vector> #include <queue> -#ifdef __GNUC__ -#define A_UNUSED __attribute__ ((unused)) -#else -#define A_UNUSED -#endif - namespace Ea { diff --git a/src/net/ea/loginhandler.h b/src/net/ea/loginhandler.h index 06c47ad5d..62ace31c8 100644 --- a/src/net/ea/loginhandler.h +++ b/src/net/ea/loginhandler.h @@ -31,12 +31,6 @@ #include <string> -#ifdef __GNUC__ -#define A_UNUSED __attribute__ ((unused)) -#else -#define A_UNUSED -#endif - class LoginData; namespace Ea diff --git a/src/net/ea/npchandler.h b/src/net/ea/npchandler.h index 44c1c5fb3..3e68c2321 100644 --- a/src/net/ea/npchandler.h +++ b/src/net/ea/npchandler.h @@ -29,12 +29,6 @@ #include <map> -#ifdef __GNUC__ -#define A_UNUSED __attribute__ ((unused)) -#else -#define A_UNUSED -#endif - class NpcDialog; namespace Ea diff --git a/src/net/ea/partyhandler.cpp b/src/net/ea/partyhandler.cpp index 5fa0df29b..8373cb1c4 100644 --- a/src/net/ea/partyhandler.cpp +++ b/src/net/ea/partyhandler.cpp @@ -225,6 +225,7 @@ void PartyHandler::processPartySettings(Net::MessageIn &msg) return; Ea::partyTab = new PartyTab(); + Ea::partyTab->loadFromLogFile("#Party"); } // These seem to indicate the sharing mode for exp and items diff --git a/src/net/ea/partyhandler.h b/src/net/ea/partyhandler.h index 6ba0d0b82..596fda4f7 100644 --- a/src/net/ea/partyhandler.h +++ b/src/net/ea/partyhandler.h @@ -29,12 +29,6 @@ #include "party.h" -#ifdef __GNUC__ -#define A_UNUSED __attribute__ ((unused)) -#else -#define A_UNUSED -#endif - namespace Ea { diff --git a/src/net/ea/playerhandler.h b/src/net/ea/playerhandler.h index 57bcbdcd5..ceb4aba0b 100644 --- a/src/net/ea/playerhandler.h +++ b/src/net/ea/playerhandler.h @@ -27,12 +27,6 @@ #include "net/net.h" #include "net/playerhandler.h" -#ifdef __GNUC__ -#define A_UNUSED __attribute__ ((unused)) -#else -#define A_UNUSED -#endif - namespace Ea { diff --git a/src/net/ea/specialhandler.h b/src/net/ea/specialhandler.h index 06e8f8893..47b412f3e 100644 --- a/src/net/ea/specialhandler.h +++ b/src/net/ea/specialhandler.h @@ -27,12 +27,6 @@ #include "net/net.h" #include "net/specialhandler.h" -#ifdef __GNUC__ -#define A_UNUSED __attribute__ ((unused)) -#else -#define A_UNUSED -#endif - namespace Ea { diff --git a/src/net/ea/tradehandler.h b/src/net/ea/tradehandler.h index 2a27f8c31..6d623f60d 100644 --- a/src/net/ea/tradehandler.h +++ b/src/net/ea/tradehandler.h @@ -27,12 +27,6 @@ #include "net/net.h" #include "net/tradehandler.h" -#ifdef __GNUC__ -#define A_UNUSED __attribute__ ((unused)) -#else -#define A_UNUSED -#endif - namespace Ea { diff --git a/src/net/manaserv/adminhandler.cpp b/src/net/manaserv/adminhandler.cpp index a8860d73b..a7bcf6355 100644 --- a/src/net/manaserv/adminhandler.cpp +++ b/src/net/manaserv/adminhandler.cpp @@ -26,6 +26,8 @@ #include "net/manaserv/messageout.h" #include "net/manaserv/protocol.h" +#include "debug.h" + extern Net::AdminHandler *adminHandler; namespace ManaServ diff --git a/src/net/manaserv/adminhandler.h b/src/net/manaserv/adminhandler.h index 17d296bd6..5a71db35e 100644 --- a/src/net/manaserv/adminhandler.h +++ b/src/net/manaserv/adminhandler.h @@ -26,12 +26,6 @@ #include "net/adminhandler.h" #include "string" -#ifdef __GNUC__ -#define A_UNUSED __attribute__ ((unused)) -#else -#define A_UNUSED -#endif - namespace ManaServ { diff --git a/src/net/manaserv/beinghandler.h b/src/net/manaserv/beinghandler.h index 512d3e58f..59797f8f5 100644 --- a/src/net/manaserv/beinghandler.h +++ b/src/net/manaserv/beinghandler.h @@ -30,12 +30,6 @@ #include "vector.h" #include "map.h" -#ifdef __GNUC__ -#define A_UNUSED __attribute__ ((unused)) -#else -#define A_UNUSED -#endif - namespace ManaServ { diff --git a/src/net/manaserv/buysellhandler.h b/src/net/manaserv/buysellhandler.h index b38fdd9e7..e1a9c91e5 100644 --- a/src/net/manaserv/buysellhandler.h +++ b/src/net/manaserv/buysellhandler.h @@ -27,12 +27,6 @@ #include "net/buysellhandler.h" -#ifdef __GNUC__ -#define A_UNUSED __attribute__ ((unused)) -#else -#define A_UNUSED -#endif - namespace ManaServ { diff --git a/src/net/manaserv/chathandler.h b/src/net/manaserv/chathandler.h index 3ed7717ad..e93c2dd87 100644 --- a/src/net/manaserv/chathandler.h +++ b/src/net/manaserv/chathandler.h @@ -28,12 +28,6 @@ #include "net/manaserv/messagehandler.h" -#ifdef __GNUC__ -#define A_UNUSED __attribute__ ((unused)) -#else -#define A_UNUSED -#endif - namespace ManaServ { diff --git a/src/net/manaserv/gamehandler.h b/src/net/manaserv/gamehandler.h index a38052205..323b2566a 100644 --- a/src/net/manaserv/gamehandler.h +++ b/src/net/manaserv/gamehandler.h @@ -28,12 +28,6 @@ #include "net/manaserv/messagehandler.h" -#ifdef __GNUC__ -#define A_UNUSED __attribute__ ((unused)) -#else -#define A_UNUSED -#endif - namespace ManaServ { diff --git a/src/net/manaserv/generalhandler.h b/src/net/manaserv/generalhandler.h index ccdddbbe6..c6614707f 100644 --- a/src/net/manaserv/generalhandler.h +++ b/src/net/manaserv/generalhandler.h @@ -30,12 +30,6 @@ #include "net/manaserv/messagehandler.h" -#ifdef __GNUC__ -#define A_UNUSED __attribute__ ((unused)) -#else -#define A_UNUSED -#endif - namespace ManaServ { diff --git a/src/net/manaserv/guildhandler.h b/src/net/manaserv/guildhandler.h index 023e60b08..6a8db27c8 100644 --- a/src/net/manaserv/guildhandler.h +++ b/src/net/manaserv/guildhandler.h @@ -27,12 +27,6 @@ #include "net/manaserv/messagehandler.h" -#ifdef __GNUC__ -#define A_UNUSED __attribute__ ((unused)) -#else -#define A_UNUSED -#endif - namespace ManaServ { @@ -62,7 +56,7 @@ public: void memberList(int guildId); - void info(int guildId A_UNUSED); + void info(int guildId); void changeMemberPostion(GuildMember *member, int level); diff --git a/src/net/manaserv/inventoryhandler.h b/src/net/manaserv/inventoryhandler.h index fbe53d735..ba4535d79 100644 --- a/src/net/manaserv/inventoryhandler.h +++ b/src/net/manaserv/inventoryhandler.h @@ -29,12 +29,6 @@ #include "net/manaserv/messagehandler.h" -#ifdef __GNUC__ -#define A_UNUSED __attribute__ ((unused)) -#else -#define A_UNUSED -#endif - namespace ManaServ { diff --git a/src/net/manaserv/loginhandler.h b/src/net/manaserv/loginhandler.h index e60f00d92..0e8f2a4e6 100644 --- a/src/net/manaserv/loginhandler.h +++ b/src/net/manaserv/loginhandler.h @@ -28,12 +28,6 @@ #include "net/manaserv/messagehandler.h" -#ifdef __GNUC__ -#define A_UNUSED __attribute__ ((unused)) -#else -#define A_UNUSED -#endif - class LoginData; namespace ManaServ diff --git a/src/net/manaserv/npchandler.h b/src/net/manaserv/npchandler.h index f48e92ecb..f91858614 100644 --- a/src/net/manaserv/npchandler.h +++ b/src/net/manaserv/npchandler.h @@ -29,12 +29,6 @@ #include <map> -#ifdef __GNUC__ -#define A_UNUSED __attribute__ ((unused)) -#else -#define A_UNUSED -#endif - class NpcDialog; namespace ManaServ diff --git a/src/net/manaserv/partyhandler.h b/src/net/manaserv/partyhandler.h index 89924c962..087936d72 100644 --- a/src/net/manaserv/partyhandler.h +++ b/src/net/manaserv/partyhandler.h @@ -27,16 +27,11 @@ #include "net/manaserv/messagehandler.h" +#include "localconsts.h" #include "party.h" #include <string> -#ifdef __GNUC__ -#define A_UNUSED __attribute__ ((unused)) -#else -#define A_UNUSED -#endif - namespace ManaServ { diff --git a/src/net/manaserv/playerhandler.h b/src/net/manaserv/playerhandler.h index f00fea42a..21bbac516 100644 --- a/src/net/manaserv/playerhandler.h +++ b/src/net/manaserv/playerhandler.h @@ -29,12 +29,6 @@ #include <guichan/actionlistener.hpp> -#ifdef __GNUC__ -#define A_UNUSED __attribute__ ((unused)) -#else -#define A_UNUSED -#endif - namespace ManaServ { diff --git a/src/net/manaserv/specialhandler.cpp b/src/net/manaserv/specialhandler.cpp index de45c2144..85fe7271f 100644 --- a/src/net/manaserv/specialhandler.cpp +++ b/src/net/manaserv/specialhandler.cpp @@ -27,6 +27,8 @@ #include "net/manaserv/messageout.h" #include "net/manaserv/protocol.h" +#include "debug.h" + extern Net::SpecialHandler *specialHandler; namespace ManaServ diff --git a/src/net/manaserv/specialhandler.h b/src/net/manaserv/specialhandler.h index e7931f8ea..ccbe59fd9 100644 --- a/src/net/manaserv/specialhandler.h +++ b/src/net/manaserv/specialhandler.h @@ -27,12 +27,6 @@ #include "net/manaserv/messagehandler.h" -#ifdef __GNUC__ -#define A_UNUSED __attribute__ ((unused)) -#else -#define A_UNUSED -#endif - namespace ManaServ { diff --git a/src/net/manaserv/tradehandler.cpp b/src/net/manaserv/tradehandler.cpp index be38e4019..383da9fe6 100644 --- a/src/net/manaserv/tradehandler.cpp +++ b/src/net/manaserv/tradehandler.cpp @@ -100,9 +100,9 @@ TradeHandler::TradeHandler(): tradeHandler = this; } -void TradeHandler::setAcceptTradeRequests(bool acceptTradeRequests) +void TradeHandler::setAcceptTradeRequests(bool acceptRequests) { - mAcceptTradeRequests = acceptTradeRequests; + mAcceptTradeRequests = acceptRequests; if (mAcceptTradeRequests) SERVER_NOTICE(_("Accepting incoming trade requests.")) else diff --git a/src/net/manaserv/tradehandler.h b/src/net/manaserv/tradehandler.h index 35c260a8e..2ca542f78 100644 --- a/src/net/manaserv/tradehandler.h +++ b/src/net/manaserv/tradehandler.h @@ -27,12 +27,6 @@ #include "net/manaserv/messagehandler.h" -#ifdef __GNUC__ -#define A_UNUSED __attribute__ ((unused)) -#else -#define A_UNUSED -#endif - namespace ManaServ { @@ -56,7 +50,7 @@ class TradeHandler : public MessageHandler, public Net::TradeHandler * requests are automatically denied. When true, a popup will ask the * player whether he wants to trade. */ - void setAcceptTradeRequests(bool acceptTradeRequests); + void setAcceptTradeRequests(bool acceptRequests); void request(Being *being); diff --git a/src/net/messageout.h b/src/net/messageout.h index 4445bbbe8..a169bfe2d 100644 --- a/src/net/messageout.h +++ b/src/net/messageout.h @@ -27,12 +27,6 @@ #include <iosfwd> -#ifdef __GNUC__ -#define A_UNUSED __attribute__ ((unused)) -#else -#define A_UNUSED -#endif - namespace Net { diff --git a/src/net/tmwa/adminhandler.h b/src/net/tmwa/adminhandler.h index 53fd4831f..d81e2421a 100644 --- a/src/net/tmwa/adminhandler.h +++ b/src/net/tmwa/adminhandler.h @@ -30,12 +30,6 @@ #include "net/tmwa/messagehandler.h" -#ifdef __GNUC__ -#define A_UNUSED __attribute__ ((unused)) -#else -#define A_UNUSED -#endif - namespace TmwAthena { diff --git a/src/net/tmwa/charserverhandler.h b/src/net/tmwa/charserverhandler.h index 4bd3153e8..f1256e409 100644 --- a/src/net/tmwa/charserverhandler.h +++ b/src/net/tmwa/charserverhandler.h @@ -33,12 +33,6 @@ #include "net/ea/token.h" -#ifdef __GNUC__ -#define A_UNUSED __attribute__ ((unused)) -#else -#define A_UNUSED -#endif - class LoginData; namespace TmwAthena diff --git a/src/net/tmwa/chathandler.h b/src/net/tmwa/chathandler.h index 197ba12b3..9a88b7478 100644 --- a/src/net/tmwa/chathandler.h +++ b/src/net/tmwa/chathandler.h @@ -30,12 +30,6 @@ #include "net/tmwa/messagehandler.h" -#ifdef __GNUC__ -#define A_UNUSED __attribute__ ((unused)) -#else -#define A_UNUSED -#endif - namespace TmwAthena { diff --git a/src/net/tmwa/gamehandler.h b/src/net/tmwa/gamehandler.h index 6824ee672..ddb381058 100644 --- a/src/net/tmwa/gamehandler.h +++ b/src/net/tmwa/gamehandler.h @@ -31,12 +31,6 @@ #include "net/ea/gamehandler.h" -#ifdef __GNUC__ -#define A_UNUSED __attribute__ ((unused)) -#else -#define A_UNUSED -#endif - namespace TmwAthena { diff --git a/src/net/tmwa/generalhandler.h b/src/net/tmwa/generalhandler.h index 9ab8d64b4..e0f29fd1d 100644 --- a/src/net/tmwa/generalhandler.h +++ b/src/net/tmwa/generalhandler.h @@ -30,12 +30,6 @@ #include "net/tmwa/messagehandler.h" -#ifdef __GNUC__ -#define A_UNUSED __attribute__ ((unused)) -#else -#define A_UNUSED -#endif - namespace TmwAthena { diff --git a/src/net/tmwa/guildhandler.h b/src/net/tmwa/guildhandler.h index d8a1cc9e7..d8d291bdd 100644 --- a/src/net/tmwa/guildhandler.h +++ b/src/net/tmwa/guildhandler.h @@ -30,12 +30,6 @@ #include "net/tmwa/messagehandler.h" -#ifdef __GNUC__ -#define A_UNUSED __attribute__ ((unused)) -#else -#define A_UNUSED -#endif - namespace TmwAthena { @@ -64,7 +58,7 @@ class GuildHandler : public Ea::GuildHandler, public MessageHandler void memberList(int guildId); - void info(int guildId A_UNUSED); + void info(int guildId); void changeMemberPostion(GuildMember *member, int level); diff --git a/src/net/tmwa/inventoryhandler.h b/src/net/tmwa/inventoryhandler.h index 989ced27a..d924e8713 100644 --- a/src/net/tmwa/inventoryhandler.h +++ b/src/net/tmwa/inventoryhandler.h @@ -31,12 +31,6 @@ #include "net/tmwa/messagehandler.h" -#ifdef __GNUC__ -#define A_UNUSED __attribute__ ((unused)) -#else -#define A_UNUSED -#endif - namespace TmwAthena { diff --git a/src/net/tmwa/loginhandler.h b/src/net/tmwa/loginhandler.h index 1e73d3c99..c13c882a7 100644 --- a/src/net/tmwa/loginhandler.h +++ b/src/net/tmwa/loginhandler.h @@ -33,12 +33,6 @@ #include <string> -#ifdef __GNUC__ -#define A_UNUSED __attribute__ ((unused)) -#else -#define A_UNUSED -#endif - class LoginData; namespace TmwAthena diff --git a/src/net/tmwa/npchandler.h b/src/net/tmwa/npchandler.h index 624f64cbc..548346205 100644 --- a/src/net/tmwa/npchandler.h +++ b/src/net/tmwa/npchandler.h @@ -32,12 +32,6 @@ #include <map> -#ifdef __GNUC__ -#define A_UNUSED __attribute__ ((unused)) -#else -#define A_UNUSED -#endif - class NpcDialog; namespace TmwAthena diff --git a/src/net/tmwa/partyhandler.h b/src/net/tmwa/partyhandler.h index 209ea5047..4d727a986 100644 --- a/src/net/tmwa/partyhandler.h +++ b/src/net/tmwa/partyhandler.h @@ -30,12 +30,6 @@ #include "party.h" -#ifdef __GNUC__ -#define A_UNUSED __attribute__ ((unused)) -#else -#define A_UNUSED -#endif - namespace TmwAthena { diff --git a/src/net/tmwa/playerhandler.h b/src/net/tmwa/playerhandler.h index 4fd108e94..bf8e861ff 100644 --- a/src/net/tmwa/playerhandler.h +++ b/src/net/tmwa/playerhandler.h @@ -30,12 +30,6 @@ #include "net/tmwa/messagehandler.h" -#ifdef __GNUC__ -#define A_UNUSED __attribute__ ((unused)) -#else -#define A_UNUSED -#endif - namespace TmwAthena { diff --git a/src/net/tmwa/specialhandler.h b/src/net/tmwa/specialhandler.h index 21c1b9026..50bf31c0b 100644 --- a/src/net/tmwa/specialhandler.h +++ b/src/net/tmwa/specialhandler.h @@ -30,12 +30,6 @@ #include "net/tmwa/messagehandler.h" -#ifdef __GNUC__ -#define A_UNUSED __attribute__ ((unused)) -#else -#define A_UNUSED -#endif - namespace TmwAthena { diff --git a/src/net/tmwa/tradehandler.h b/src/net/tmwa/tradehandler.h index 85c153743..3a4c8c1fc 100644 --- a/src/net/tmwa/tradehandler.h +++ b/src/net/tmwa/tradehandler.h @@ -30,12 +30,6 @@ #include "net/tmwa/messagehandler.h" -#ifdef __GNUC__ -#define A_UNUSED __attribute__ ((unused)) -#else -#define A_UNUSED -#endif - namespace TmwAthena { diff --git a/src/net/tradehandler.h b/src/net/tradehandler.h index f099efe53..57219e675 100644 --- a/src/net/tradehandler.h +++ b/src/net/tradehandler.h @@ -27,11 +27,7 @@ #include <iosfwd> -#ifdef __GNUC__ -#define A_UNUSED __attribute__ ((unused)) -#else -#define A_UNUSED -#endif +#include "localconsts.h" namespace Net { @@ -43,7 +39,6 @@ class TradeHandler virtual void request(Being *being A_UNUSED) { } -// virtual ~TradeHandler() {} virtual void respond(bool accept A_UNUSED) { } diff --git a/src/opengl1graphics.h b/src/opengl1graphics.h index 3943a82fb..11df607f8 100644 --- a/src/opengl1graphics.h +++ b/src/opengl1graphics.h @@ -33,12 +33,6 @@ #include <SDL_opengl.h> #endif -#ifdef __GNUC__ -#define A_UNUSED __attribute__ ((unused)) -#else -#define A_UNUSED -#endif - class OpenGL1Graphics : public Graphics { public: diff --git a/src/openglgraphics.h b/src/openglgraphics.h index 12eb2d9f8..d12810203 100644 --- a/src/openglgraphics.h +++ b/src/openglgraphics.h @@ -33,12 +33,6 @@ #include <SDL_opengl.h> #endif -#ifdef __GNUC__ -#define A_UNUSED __attribute__ ((unused)) -#else -#define A_UNUSED -#endif - class OpenGLGraphics : public Graphics { public: diff --git a/src/particle.h b/src/particle.h index 0a4a2253d..ad448a054 100644 --- a/src/particle.h +++ b/src/particle.h @@ -25,17 +25,12 @@ #include "actor.h" #include "guichanfwd.h" +#include "localconsts.h" #include "vector.h" #include <list> #include <string> -#ifdef __GNUC__ -#define A_UNUSED __attribute__ ((unused)) -#else -#define A_UNUSED -#endif - class Map; class Particle; class ParticleEmitter; @@ -114,6 +109,12 @@ class Particle : public Actor { return static_cast<int>(mPos.y) - 16; } /** + * Necessary for sorting with the other sprites for sorting only. + */ + virtual int getSortPixelY() const + { return static_cast<int>(mPos.y) - 16; } + + /** * Creates a blank particle as a child of the current particle * Useful for creating target particles */ @@ -274,7 +275,8 @@ class Particle : public Actor virtual float getAlpha() const { return 1.0f; } - virtual void setAlpha(float alpha A_UNUSED) {} + virtual void setAlpha(float alpha A_UNUSED) + { } virtual void setDeathEffect(const std::string &effectFile, char conditions) diff --git a/src/particlecontainer.h b/src/particlecontainer.h index 937c4dd63..2219bd67c 100644 --- a/src/particlecontainer.h +++ b/src/particlecontainer.h @@ -45,7 +45,7 @@ public: * delParent means that the destructor should also free the parent. */ ParticleContainer(ParticleContainer *parent = nullptr, - bool delParent = true); + bool delParent = true); virtual ~ParticleContainer(); diff --git a/src/playerrelations.cpp b/src/playerrelations.cpp index 324dac065..1bf63aa81 100644 --- a/src/playerrelations.cpp +++ b/src/playerrelations.cpp @@ -282,6 +282,7 @@ unsigned int PlayerRelationsManager::checkPermissionSilently( case PlayerRelation::IGNORED: case PlayerRelation::ERASED: case PlayerRelation::BLACKLISTED: + case PlayerRelation::ENEMY2: default: permissions &= mDefaultPermissions; // narrow } diff --git a/src/playerrelations.h b/src/playerrelations.h index 5fabb3d0e..5eb1b3c64 100644 --- a/src/playerrelations.h +++ b/src/playerrelations.h @@ -28,12 +28,6 @@ #include <string> #include <vector> -#ifdef __GNUC__ -#define A_UNUSED __attribute__ ((unused)) -#else -#define A_UNUSED -#endif - class Being; struct PlayerRelation diff --git a/src/resources/action.cpp b/src/resources/action.cpp index c2af3ff9b..f940bffcb 100644 --- a/src/resources/action.cpp +++ b/src/resources/action.cpp @@ -29,7 +29,8 @@ #include "debug.h" -Action::Action() +Action::Action() : + mNumber(100) { } diff --git a/src/resources/action.h b/src/resources/action.h index 05b326d8f..9ab6f98d5 100644 --- a/src/resources/action.h +++ b/src/resources/action.h @@ -43,10 +43,17 @@ class Action Animation *getAnimation(int direction) const; + unsigned getNumber() + { return mNumber; } + + void setNumber(unsigned n) + { mNumber = n; } + protected: typedef std::map<int, Animation*> Animations; typedef Animations::iterator AnimationIterator; Animations mAnimations; + unsigned mNumber; }; #endif diff --git a/src/resources/chardb.cpp b/src/resources/chardb.cpp new file mode 100644 index 000000000..d944f280e --- /dev/null +++ b/src/resources/chardb.cpp @@ -0,0 +1,129 @@ +/* + * Color database + * Copyright (C) 2008 Aethyra Development Team + * Copyright (C) 2011 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program 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. + * + * This program 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 this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#include "resources/chardb.h" + +#include "client.h" +#include "logger.h" + +#include "utils/xml.h" + +#include <libxml/tree.h> + +#include "debug.h" + +namespace +{ + bool mLoaded = false; + unsigned mMinHairColor = 0; + unsigned mMaxHairColor = 0; + unsigned mMinHairStyle = 0; + unsigned mMaxHairStyle = 0; + unsigned mMinStat = 0; + unsigned mMaxStat = 0; + unsigned mSumStat = 0; +} + +void CharDB::load() +{ + if (mLoaded) + unload(); + + XML::Document *doc = new XML::Document("charcreation.xml"); + xmlNodePtr root = doc->rootNode(); + + if (!root || !xmlStrEqual(root->name, BAD_CAST "chars")) + { + logger->log1("CharDB: Failed to parse charcreation.xml."); + + delete doc; + return; + } + + for_each_xml_child_node(node, root) + { + if (xmlStrEqual(node->name, BAD_CAST "haircolor")) + { + loadMinMax(node, &mMinHairColor, &mMaxHairColor); + } + else if (xmlStrEqual(node->name, BAD_CAST "hairstyle")) + { + loadMinMax(node, &mMinHairStyle, &mMaxHairStyle); + } + else if (xmlStrEqual(node->name, BAD_CAST "stat")) + { + loadMinMax(node, &mMinStat, &mMaxStat); + mSumStat = XML::getProperty(node, "sum", 0); + } + } + + delete doc; + + mLoaded = true; +} + +void CharDB::loadMinMax(xmlNodePtr node, unsigned *min, unsigned *max) +{ + *min = XML::getProperty(node, "min", 1); + *max = XML::getProperty(node, "max", 10); +} + +void CharDB::unload() +{ + logger->log1("Unloading chars database..."); + + mLoaded = false; +} + +unsigned CharDB::getMinHairColor() +{ + return mMinHairColor; +} + +unsigned CharDB::getMaxHairColor() +{ + return mMaxHairColor; +} + +unsigned CharDB::getMinHairStyle() +{ + return mMinHairStyle; +} + +unsigned CharDB::getMaxHairStyle() +{ + return mMaxHairStyle; +} + +unsigned CharDB::getMinStat() +{ + return mMinStat; +} + +unsigned CharDB::getMaxStat() +{ + return mMaxStat; +} + +unsigned CharDB::getSumStat() +{ + return mSumStat; +} diff --git a/src/resources/chardb.h b/src/resources/chardb.h new file mode 100644 index 000000000..769dedb56 --- /dev/null +++ b/src/resources/chardb.h @@ -0,0 +1,62 @@ +/* + * Color database + * Copyright (C) 2008 Aethyra Development Team + * Copyright (C) 2011 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program 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. + * + * This program 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 this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef CHARDB_MANAGER_H +#define CHARDB_MANAGER_H + +#include <map> +#include <string> + +#include <libxml/tree.h> + +/** + * Char information database. + */ +namespace CharDB +{ + /** + * Loads the chars data. + */ + void load(); + + /** + * Clear the chars data + */ + void unload(); + + void loadMinMax(xmlNodePtr node, unsigned *min, unsigned *max); + + unsigned getMinHairColor(); + + unsigned getMaxHairColor(); + + unsigned getMinHairStyle(); + + unsigned getMaxHairStyle(); + + unsigned getMinStat(); + + unsigned getMaxStat(); + + unsigned getSumStat(); +} + +#endif diff --git a/src/resources/colordb.cpp b/src/resources/colordb.cpp index 225abef91..3b8c9d573 100644 --- a/src/resources/colordb.cpp +++ b/src/resources/colordb.cpp @@ -1,6 +1,7 @@ /* * Color database * Copyright (C) 2008 Aethyra Development Team + * Copyright (C) 2011 The ManaPlus Developers * * This file is part of The ManaPlus Client. * diff --git a/src/resources/colordb.h b/src/resources/colordb.h index 83bff57da..f4cc88a59 100644 --- a/src/resources/colordb.h +++ b/src/resources/colordb.h @@ -1,6 +1,7 @@ /* * Color database * Copyright (C) 2008 Aethyra Development Team + * Copyright (C) 2011 The ManaPlus Developers * * This file is part of The ManaPlus Client. * diff --git a/src/resources/itemdb.cpp b/src/resources/itemdb.cpp index 3e53dd6e7..2911fa06f 100644 --- a/src/resources/itemdb.cpp +++ b/src/resources/itemdb.cpp @@ -546,25 +546,51 @@ int parseDirectionName(std::string name) { int id = -1; if (name == "down") - id = DIRECTION_DOWN; + { + if (serverVersion > 0) + id = DIRECTION_DOWN; + else + id = -2; + } else if (name == "downleft" || name == "leftdown") + { id = DIRECTION_DOWNLEFT; + } else if (name == "left") + { id = DIRECTION_LEFT; + } else if (name == "upleft" || name == "leftup") + { id = DIRECTION_UPLEFT; + } else if (name == "up") - id = DIRECTION_UP; + { + if (serverVersion > 0) + id = DIRECTION_UP; + else + id = -3; + } else if (name == "upright" || name == "rightup") + { id = DIRECTION_UPRIGHT; + } else if (name == "right") + { id = DIRECTION_RIGHT; + } else if (name == "downright" || name == "rightdown") + { id = DIRECTION_DOWNRIGHT; + } else if (name == "downall") + { id = -2; + } else if (name == "upall") + { id = -3; + } return id; } diff --git a/src/resources/itemdb.h b/src/resources/itemdb.h index c20961eff..71f0a490e 100644 --- a/src/resources/itemdb.h +++ b/src/resources/itemdb.h @@ -28,12 +28,6 @@ #include <map> #include <string> -#ifdef __GNUC__ -#define A_UNUSED __attribute__ ((unused)) -#else -#define A_UNUSED -#endif - class ItemInfo; /** diff --git a/src/resources/mapreader.h b/src/resources/mapreader.h index b10f35d89..c15a83b6f 100644 --- a/src/resources/mapreader.h +++ b/src/resources/mapreader.h @@ -27,12 +27,6 @@ #include <string> -#ifdef __GNUC__ -#define A_UNUSED __attribute__ ((unused)) -#else -#define A_UNUSED -#endif - class Map; class Properties; class Tileset; diff --git a/src/resources/spritedef.cpp b/src/resources/spritedef.cpp index 3e2aac785..32d18b6b8 100644 --- a/src/resources/spritedef.cpp +++ b/src/resources/spritedef.cpp @@ -35,23 +35,44 @@ #include "utils/xml.h" -#include <set> - #include "debug.h" SpriteReference *SpriteReference::Empty = nullptr; -Action *SpriteDef::getAction(std::string action) const +Action *SpriteDef::getAction(std::string action, unsigned num) const { - Actions::const_iterator i = mActions.find(action); + Actions::const_iterator i = mActions.find(num); + if (i == mActions.end() && num != 100) + i = mActions.find(100); - if (i == mActions.end()) + if (i == mActions.end() || !(*i).second) + return nullptr; + + ActionMap::const_iterator it = ((*i).second)->find(action); + + if (it == ((*i).second)->end()) { logger->log("Warning: no action \"%s\" defined!", action.c_str()); return nullptr; } - return i->second; + return (*it).second; +} + +unsigned SpriteDef::findNumber(unsigned num) const +{ + unsigned min = 101; + Actions::const_iterator it = mActions.begin(); + Actions::const_iterator it_end = mActions.end(); + for (; it != it_end; ++ it) + { + unsigned n = (*it).first; + if (n >= num && n < min) + min = n; + } + if (min == 101) + return 0; + return min; } SpriteDef *SpriteDef::load(const std::string &animationFile, int variant) @@ -77,6 +98,7 @@ SpriteDef *SpriteDef::load(const std::string &animationFile, int variant) } SpriteDef *def = new SpriteDef; + def->mProcessedFiles.insert(animationFile); def->loadSprite(rootNode, variant, palettes); def->substituteActions(); return def; @@ -84,11 +106,19 @@ SpriteDef *SpriteDef::load(const std::string &animationFile, int variant) void SpriteDef::substituteAction(std::string complete, std::string with) { - if (mActions.find(complete) == mActions.end()) + Actions::const_iterator it = mActions.begin(); + Actions::const_iterator it_end = mActions.end(); + for (; it != it_end; ++ it) { - Actions::const_iterator i = mActions.find(with); - if (i != mActions.end()) - mActions[complete] = i->second; + ActionMap *d = (*it).second; + if (!d) + continue; + if (d->find(complete) == d->end()) + { + ActionMap::iterator i = d->find(with); + if (i != d->end()) + (*d)[complete] = i->second; + } } } @@ -162,12 +192,13 @@ void SpriteDef::loadAction(xmlNodePtr node, int variant_offset) { const std::string actionName = XML::getProperty(node, "name", ""); const std::string imageSetName = XML::getProperty(node, "imageset", ""); + const unsigned hp = XML::getProperty(node, "hp", 100); ImageSetIterator si = mImageSets.find(imageSetName); if (si == mImageSets.end()) { logger->log("Warning: imageset \"%s\" not defined in %s", - imageSetName.c_str(), getIdPath().c_str()); + imageSetName.c_str(), getIdPath().c_str()); return; } ImageSet *imageSet = si->second; @@ -175,19 +206,21 @@ void SpriteDef::loadAction(xmlNodePtr node, int variant_offset) if (actionName == SpriteAction::INVALID) { logger->log("Warning: Unknown action \"%s\" defined in %s", - actionName.c_str(), getIdPath().c_str()); + actionName.c_str(), getIdPath().c_str()); return; } Action *action = new Action; - mActions[actionName] = action; + action->setNumber(hp); + addAction(hp, actionName, action); // dirty hack to fix bad resources in tmw server if (actionName == "attack_stab") - mActions["attack"] = action; + addAction(hp, "attack", action); // When first action set it as default direction - if (mActions.size() == 1) - mActions[SpriteAction::DEFAULT] = action; + Actions::const_iterator i = mActions.find(hp); + if ((*i).second->size() == 1) + addAction(hp, SpriteAction::DEFAULT, action); // Load animations for_each_xml_child_node(animationNode, node) @@ -280,7 +313,7 @@ void SpriteDef::loadAnimation(xmlNodePtr animationNode, if (!img) { logger->log("No image at index %d", - pos + variant_offset); + pos + variant_offset); pos ++; continue; } @@ -317,14 +350,21 @@ void SpriteDef::loadAnimation(xmlNodePtr animationNode, void SpriteDef::includeSprite(xmlNodePtr includeNode) { - // TODO: Perform circular dependency check, since it's easy to crash the - // client this way. - const std::string filename = XML::getProperty(includeNode, "file", ""); + std::string filename = XML::getProperty(includeNode, "file", ""); if (filename.empty()) return; + filename = paths.getStringValue("sprites") + filename; + + if (mProcessedFiles.find(filename) != mProcessedFiles.end()) + { + logger->log("Error, Tried to include %s which already is included.", + filename.c_str()); + return; + } + mProcessedFiles.insert(filename); - XML::Document doc(paths.getStringValue("sprites") + filename); + XML::Document doc(filename); xmlNodePtr rootNode = doc.rootNode(); if (!rootNode || !xmlStrEqual(rootNode->name, BAD_CAST "sprite")) @@ -339,14 +379,18 @@ void SpriteDef::includeSprite(xmlNodePtr includeNode) SpriteDef::~SpriteDef() { // Actions are shared, so ensure they are deleted only once. - std::set< Action * > actions; - for (Actions::const_iterator i = mActions.begin(), + std::set<Action*> actions; + for (Actions::iterator i = mActions.begin(), i_end = mActions.end(); i != i_end; ++i) { - actions.insert(i->second); + ActionMap::iterator it = (*i).second->begin(); + ActionMap::iterator it_end = (*i).second->end(); + for (; it != it_end; ++ it) + actions.insert(it->second); + delete (*i).second; } - for (std::set< Action * >::const_iterator i = actions.begin(), + for (std::set<Action*>::const_iterator i = actions.begin(), i_end = actions.end(); i != i_end; ++i) { delete *i; @@ -355,7 +399,7 @@ SpriteDef::~SpriteDef() mActions.clear(); for (ImageSetIterator i = mImageSets.begin(); - i != mImageSets.end(); ++i) + i != mImageSets.end(); ++i) { if (i->second) { @@ -388,3 +432,12 @@ SpriteDirection SpriteDef::makeSpriteDirection(const std::string &direction) else return DIRECTION_INVALID; } + +void SpriteDef::addAction(unsigned hp, std::string name, Action *action) +{ + Actions::const_iterator i = mActions.find(hp); + if (i == mActions.end()) + mActions[hp] = new ActionMap(); + + (*mActions[hp])[name] = action; +} diff --git a/src/resources/spritedef.h b/src/resources/spritedef.h index b2939fca1..3aa6369dd 100644 --- a/src/resources/spritedef.h +++ b/src/resources/spritedef.h @@ -29,6 +29,7 @@ #include <list> #include <map> +#include <set> #include <string> #include <vector> @@ -117,7 +118,9 @@ class SpriteDef : public Resource /** * Returns the specified action. */ - Action *getAction(std::string action) const; + Action *getAction(std::string action, unsigned num) const; + + unsigned findNumber(unsigned num) const; /** * Converts a string into a SpriteDirection enum. @@ -125,11 +128,14 @@ class SpriteDef : public Resource static SpriteDirection makeSpriteDirection(const std::string &direction); + void addAction(unsigned hp, std::string name, Action *action); + private: /** * Constructor. */ - SpriteDef() {} + SpriteDef() + { } /** * Destructor. @@ -177,11 +183,12 @@ class SpriteDef : public Resource typedef std::map<std::string, ImageSet*> ImageSets; typedef ImageSets::iterator ImageSetIterator; - - typedef std::map<std::string, Action*> Actions; + typedef std::map<std::string, Action*> ActionMap; + typedef std::map<unsigned, ActionMap*> Actions; ImageSets mImageSets; Actions mActions; + std::set<std::string> mProcessedFiles; }; #endif // SPRITEDEF_H diff --git a/src/sprite.h b/src/sprite.h index 52752619b..64721b740 100644 --- a/src/sprite.h +++ b/src/sprite.h @@ -112,6 +112,8 @@ class Sprite virtual void *getHash2() { return this; } + virtual bool updateNumber(unsigned num) = 0; + protected: float mAlpha; /**< The alpha opacity used to draw */ }; diff --git a/src/textmanager.h b/src/textmanager.h index 019214bb6..1ed88883a 100644 --- a/src/textmanager.h +++ b/src/textmanager.h @@ -25,12 +25,6 @@ #include "guichanfwd.h" -#ifdef __GNUC__ -#define A_UNUSED __attribute__ ((unused)) -#else -#define A_UNUSED -#endif - class Text; class TextManager diff --git a/src/textparticle.h b/src/textparticle.h index db9dc1766..b37f25732 100644 --- a/src/textparticle.h +++ b/src/textparticle.h @@ -45,6 +45,10 @@ class TextParticle : public Particle virtual int getPixelY() const { return static_cast<int>(mPos.y + mPos.z); } + // hack to improve text visibility (for sorting only) + virtual int getSortPixelY() const + { return static_cast<int>(mPos.y + mPos.z); } + private: std::string mText; /**< Text of the particle. */ gcn::Font *mTextFont; /**< Font used for drawing the text. */ |