diff options
Diffstat (limited to 'src')
153 files changed, 3129 insertions, 1710 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f389c4364..9af6c6ec0 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -445,6 +445,12 @@ SET(SRCS resources/spritedef.cpp resources/wallpaper.cpp resources/wallpaper.h + utils/translation/podict.cpp + utils/translation/podict.h + utils/translation/poparser.cpp + utils/translation/poparser.h + utils/translation/translationmanager.cpp + utils/translation/translationmanager.h utils/base64.cpp utils/base64.h utils/checkutils.cpp @@ -453,6 +459,8 @@ SET(SRCS utils/copynpaste.h utils/dtor.h utils/gettext.h + utils/langs.cpp + utils/langs.h utils/mathutils.h utils/paths.cpp utils/paths.h @@ -559,6 +567,8 @@ SET(SRCS main.h map.cpp map.h + maplayer.cpp + maplayer.h opengl1graphics.cpp opengl1graphics.h openglgraphics.cpp diff --git a/src/Makefile.am b/src/Makefile.am index a241b60b0..aca581e22 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -353,6 +353,12 @@ manaplus_SOURCES += gui/widgets/avatarlistbox.cpp \ resources/spritedef.cpp \ resources/wallpaper.cpp \ resources/wallpaper.h \ + utils/translation/podict.cpp \ + utils/translation/podict.h \ + utils/translation/poparser.cpp \ + utils/translation/poparser.h \ + utils/translation/translationmanager.cpp \ + utils/translation/translationmanager.h \ utils/base64.cpp \ utils/base64.h \ utils/checkutils.cpp \ @@ -361,6 +367,8 @@ manaplus_SOURCES += gui/widgets/avatarlistbox.cpp \ utils/copynpaste.h \ utils/dtor.h \ utils/gettext.h \ + utils/langs.cpp \ + utils/langs.h \ utils/mathutils.h \ utils/mkdir.cpp \ utils/mkdir.h \ @@ -467,8 +475,10 @@ manaplus_SOURCES += gui/widgets/avatarlistbox.cpp \ logger.h \ main.cpp \ main.h \ - map.cpp\ + map.cpp \ map.h \ + maplayer.cpp \ + maplayer.h \ opengl1graphics.cpp\ opengl1graphics.h \ openglgraphics.cpp\ @@ -658,6 +668,11 @@ manaplus_SOURCES += \ mumblemanager.cpp \ mumblemanager.h +if ENABLE_UNITTESTS +manaplus_CXXFLAGS += -DUNITTESTS +manaplus_SOURCES += \ + utils/stringutils_unittest.cc +endif EXTRA_DIST = CMakeLists.txt \ winver.h.in \ diff --git a/src/actorspritemanager.cpp b/src/actorspritemanager.cpp index fa6d49d38..803a30e7e 100644 --- a/src/actorspritemanager.cpp +++ b/src/actorspritemanager.cpp @@ -31,8 +31,6 @@ #include "gui/chatwindow.h" #include "gui/equipmentwindow.h" -#include "gui/killstats.h" -#include "gui/skilldialog.h" #include "gui/socialwindow.h" #include "gui/viewport.h" @@ -240,10 +238,11 @@ Being *ActorSpriteManager::createBeing(int id, ActorSprite::Type type, } FloorItem *ActorSpriteManager::createItem(int id, int itemId, int x, int y, - int amount, unsigned char color) + int amount, unsigned char color, + int subX, int subY) { FloorItem *floorItem = new FloorItem(id, itemId, x, y, - mMap, amount, color); + mMap, amount, color, subX, subY); mActors.insert(floorItem); return floorItem; diff --git a/src/actorspritemanager.h b/src/actorspritemanager.h index a78e3ad49..d30bad426 100644 --- a/src/actorspritemanager.h +++ b/src/actorspritemanager.h @@ -63,7 +63,8 @@ class ActorSpriteManager: public ConfigListener * Create a FloorItem and add it to the list of ActorSprites. */ FloorItem *createItem(int id, int itemId, int x, int y, - int amount, unsigned char color); + int amount, unsigned char color, + int subX, int subY); /** * Destroys the given ActorSprite at the end of diff --git a/src/animatedsprite.cpp b/src/animatedsprite.cpp index 11329b321..6b791fdd4 100644 --- a/src/animatedsprite.cpp +++ b/src/animatedsprite.cpp @@ -214,7 +214,12 @@ bool AnimatedSprite::updateCurrentAnimation(unsigned int time) } } if (fail) - mFrameTime = mFrame->delay + 1; + { + if (mFrame) + mFrameTime = mFrame->delay + 1; + else + mFrameTime ++; + } } return true; } diff --git a/src/avatar.cpp b/src/avatar.cpp index 9a4831f18..54d7c6e79 100644 --- a/src/avatar.cpp +++ b/src/avatar.cpp @@ -61,4 +61,4 @@ std::string Avatar::getAdditionString() const return " - " + getIp(); else return ""; -}
\ No newline at end of file +} diff --git a/src/being.cpp b/src/being.cpp index 9edfaad7b..e1cb9b0ae 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -40,7 +40,6 @@ #include "sound.h" #include "sprite.h" #include "text.h" -#include "statuseffect.h" #include "gui/buydialog.h" #include "gui/buyselldialog.h" @@ -295,9 +294,9 @@ Being::~Being() { config.removeListener("visiblenames", this); - delete[] mSpriteRemap; + delete [] mSpriteRemap; mSpriteRemap = nullptr; - delete[] mSpriteHide; + delete [] mSpriteHide; mSpriteHide = nullptr; delete mSpeechBubble; @@ -339,7 +338,15 @@ void Being::setSubtype(Uint16 subtype) // Prevent showing errors when sprite doesn't exist if (!ItemDB::exists(id)) + { id = -100; + setRaceName(_("Human")); + } + else + { + const ItemInfo &info = ItemDB::get(id); + setRaceName(info.getName()); + } setSprite(Net::getCharHandler()->baseSprite(), id); } @@ -993,7 +1000,6 @@ void Being::setAction(Action action, int attackType A_UNUSED) case DIRECTION_RIGHT: rotation = 270; break; default: break; } - ; if (particleEngine) { Particle *p = particleEngine->addEffect( @@ -2404,7 +2410,7 @@ void Being::searchSlotValueItr(std::vector<int>::iterator &it, int &idx, // logger->log("searching %d", val); it = slotRemap.begin(); idx = 0; - while(it != slotRemap.end()) + while (it != slotRemap.end()) { // logger->log("testing %d", *it); if (*it == val) diff --git a/src/being.h b/src/being.h index 8b3db1919..859ebf26c 100644 --- a/src/being.h +++ b/src/being.h @@ -27,7 +27,6 @@ #include "configlistener.h" #include "equipment.h" #include "map.h" -#include "particlecontainer.h" #include "position.h" #include "vector.h" @@ -102,6 +101,7 @@ class Being : public ActorSprite, public ConfigListener FLAG_SHOP = 1, FLAG_AWAY = 2, FLAG_INACTIVE = 4, + FLAG_GM = 64, FLAG_GENDER = 128, FLAG_SPECIAL = 128 + 64 }; @@ -769,6 +769,12 @@ class Being : public ActorSprite, public ConfigListener void updatePercentHP(); + void setRaceName(std::string name) + { mRaceName = name; } + + std::string getRaceName() + { return mRaceName; } + protected: /** * Sets the new path for this being. @@ -804,6 +810,7 @@ class Being : public ActorSprite, public ConfigListener Uint8 mSpriteDirection; /**< Facing direction */ std::string mName; /**< Name of character */ + std::string mRaceName; std::string mPartyName; std::string mGuildName; diff --git a/src/chatlogger.cpp b/src/chatlogger.cpp index 33763e561..b8418edda 100644 --- a/src/chatlogger.cpp +++ b/src/chatlogger.cpp @@ -42,6 +42,8 @@ #include "utils/mkdir.h" #include "utils/stringutils.h" +#include <physfs.h> + #include "debug.h" ChatLogger::ChatLogger() : @@ -172,11 +174,17 @@ void ChatLogger::setServerName(const std::string &serverName) secureName(mServerName); if (mLogDir != "") { - DIR *dir = opendir((mLogDir + "/" + mServerName).c_str()); + DIR *dir = opendir((mLogDir + PHYSFS_getDirSeparator() + + mServerName).c_str()); if (!dir) - mkdir_r((mLogDir + "/" + mServerName).c_str()); + { + mkdir_r((mLogDir + PHYSFS_getDirSeparator() + + mServerName).c_str()); + } else + { closedir(dir); + } } } diff --git a/src/client.cpp b/src/client.cpp index c21194834..e6aeb22e2 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -69,7 +69,6 @@ #include "gui/worldselectdialog.h" #include "gui/widgets/button.h" -#include "gui/widgets/chattab.h" #include "gui/widgets/desktop.h" #include "net/charhandler.h" @@ -80,7 +79,6 @@ #include "net/loginhandler.h" #include "net/net.h" #include "net/npchandler.h" -#include "net/packetcounters.h" #include "net/partyhandler.h" #include "net/worldinfo.h" @@ -101,6 +99,8 @@ #include "utils/paths.h" #include "utils/stringutils.h" +#include "utils/translation/translationmanager.h" + #include "test/testlauncher.h" #include "test/testmain.h" @@ -276,7 +276,6 @@ Client::Client(const Options &options): void Client::testsInit() { - printf ("testInit\n"); if (!mOptions.test.empty()) { gameInit(); @@ -342,6 +341,10 @@ void Client::gameInit() textdomain("manaplus"); #endif +#if defined(WIN32) || defined(__APPLE__) + putenv("SDL_VIDEO_CENTERED=1"); +#endif + chatLogger = new ChatLogger; if (mOptions.chatLogDir == "") chatLogger->setBaseLogDir(mLocalDataDir + std::string("/logs/")); @@ -443,7 +446,8 @@ void Client::gameInit() } else { - mOptions.dataPath = branding.getDirectory() + "/" + mOptions.dataPath = branding.getDirectory() + + PHYSFS_getDirSeparator() + branding.getStringValue("dataPath"); } mOptions.skipUpdate = true; @@ -458,6 +462,8 @@ void Client::gameInit() //resman->selectSkin(); + TranslationManager::loadCurrentLang(); + std::string iconFile = branding.getValue("appIcon", "icons/manaplus"); #ifdef WIN32 iconFile += ".ico"; @@ -498,7 +504,7 @@ void Client::gameInit() GraphicsVertexes::setLoadAsOpenGL(useOpenGL); // Create the graphics context - switch(useOpenGL) + switch (useOpenGL) { case 0: mainGraphics = new Graphics; @@ -794,6 +800,8 @@ void Client::gameClear() //delete logger; //logger = nullptr; + TranslationManager::close(); + mInstance = nullptr; } @@ -860,7 +868,8 @@ int Client::gameExec() if (Net::getGeneralHandler()) Net::getGeneralHandler()->flushNetwork(); - while (get_elapsed_time(lastTickTime) > 0) + int k = 0; + while (lastTickTime != tick_time && k < 40) { if (gui) gui->logic(); @@ -870,6 +879,7 @@ int Client::gameExec() sound.logic(); ++lastTickTime; + k ++; } // This is done because at some point tick_time will wrap. @@ -982,10 +992,10 @@ int Client::gameExec() if (mState != mOldState) { - Mana::Event evt(EVENT_STATECHANGE); + Event evt(EVENT_STATECHANGE); evt.setInt("oldState", mOldState); evt.setInt("newState", mState); - Mana::Event::trigger(CHANNEL_CLIENT, evt); + Event::trigger(CHANNEL_CLIENT, evt); if (mOldState == STATE_GAME) { @@ -1050,6 +1060,7 @@ int Client::gameExec() logger->log1("State: CONNECT SERVER"); mCurrentDialog = new ConnectionDialog( _("Connecting to server"), STATE_SWITCH_SERVER); + TranslationManager::loadCurrentLang(); break; case STATE_LOGIN: @@ -1086,6 +1097,7 @@ int Client::gameExec() case STATE_WORLD_SELECT: logger->log1("State: WORLD SELECT"); { + TranslationManager::loadCurrentLang(); Worlds worlds = Net::getLoginHandler()->getWorlds(); if (worlds.empty()) @@ -1130,17 +1142,17 @@ int Client::gameExec() } else if (loginData.updateType & LoginData::Upd_Skip) { - UpdaterWindow::loadLocalUpdates(mLocalDataDir + "/" - + mUpdatesDir); + UpdaterWindow::loadLocalUpdates(mLocalDataDir + + PHYSFS_getDirSeparator() + mUpdatesDir); mState = STATE_LOAD_DATA; } else { logger->log1("State: UPDATE"); mCurrentDialog = new UpdaterWindow(mUpdateHost, - mLocalDataDir + "/" + mUpdatesDir, - mOptions.dataPath.empty(), - loginData.updateType); + mLocalDataDir + PHYSFS_getDirSeparator() + + mUpdatesDir, mOptions.dataPath.empty(), + loginData.updateType); } break; @@ -1168,7 +1180,8 @@ int Client::gameExec() "zip", false); - resman->addToSearchPath(mLocalDataDir + "/" + resman->addToSearchPath(mLocalDataDir + + PHYSFS_getDirSeparator() + mUpdatesDir + "/local/", false); } @@ -1184,10 +1197,12 @@ int Client::gameExec() if (!BeingInfo::unknown) BeingInfo::unknown = new BeingInfo; - Mana::Event evt2(EVENT_STATECHANGE); + TranslationManager::loadCurrentLang(); + + Event evt2(EVENT_STATECHANGE); evt2.setInt("newState", STATE_LOAD_DATA); evt2.setInt("oldState", mOldState); - Mana::Event::trigger(CHANNEL_CLIENT, evt2); + Event::trigger(CHANNEL_CLIENT, evt2); // Load XML databases CharDB::load(); @@ -1603,7 +1618,7 @@ void Client::initConfigDir() if (mConfigDir.empty()) { #ifdef __APPLE__ - mConfigDir = mLocalDataDir + "/" + mConfigDir = mLocalDataDir + PHYSFS_getDirSeparator() + branding.getValue("appShort", "mana"); #elif defined __HAIKU__ mConfigDir = std::string(PHYSFS_getUserDir()) + @@ -1635,7 +1650,7 @@ void Client::initConfigDir() */ void Client::initServerConfig(std::string serverName) { - mServerConfigDir = mConfigDir + "/" + serverName; + mServerConfigDir = mConfigDir + PHYSFS_getDirSeparator() + serverName; if (mkdir_r(mServerConfigDir.c_str())) { @@ -1870,9 +1885,8 @@ void Client::initScreenshotDir() if (!configScreenshotSuffix.empty()) { - mScreenshotDir += "/" + configScreenshotSuffix; -// config.setValue("screenshotDirectorySuffix", -// configScreenshotSuffix); + mScreenshotDir += PHYSFS_getDirSeparator() + + configScreenshotSuffix; } } } diff --git a/src/commandhandler.cpp b/src/commandhandler.cpp index 4022d8d58..9f832c021 100644 --- a/src/commandhandler.cpp +++ b/src/commandhandler.cpp @@ -201,6 +201,8 @@ void CommandHandler::handleCommand(const std::string &command, ChatTab *tab) handleServerIgnoreAll(args, tab); else if (type == "serverunignoreall") handleServerUnIgnoreAll(args, tab); + else if (type == "setdrop") + handleSetDrop(args, tab); else if (type == "dumpg") handleDumpGraphics(args, tab); else if (type == "dumpt") @@ -1187,6 +1189,13 @@ void CommandHandler::outStringNormal(ChatTab *tab, const std::string &str, } } +void CommandHandler::handleSetDrop(const std::string &args, + ChatTab *tab A_UNUSED) +{ + if (player_node) + player_node->setQuickDropCounter(atoi(args.c_str())); +} + #ifdef DEBUG_DUMP_LEAKS void showRes(std::string str, ResourceManager::Resources *res); diff --git a/src/commandhandler.h b/src/commandhandler.h index 16e5e94ce..cd25c234a 100644 --- a/src/commandhandler.h +++ b/src/commandhandler.h @@ -295,6 +295,8 @@ class CommandHandler void handleServerUnIgnoreAll(const std::string &args, ChatTab *tab); + void handleSetDrop(const std::string &args, ChatTab *tab); + void handleDump(const std::string &args, ChatTab *tab); void handleDumpGraphics(const std::string &args, ChatTab *tab); diff --git a/src/compoundsprite.cpp b/src/compoundsprite.cpp index 61fb3d4e0..62ef2d01c 100644 --- a/src/compoundsprite.cpp +++ b/src/compoundsprite.cpp @@ -24,11 +24,12 @@ #include "configuration.h" #include "game.h" #include "graphics.h" + #ifdef USE_OPENGL #include "openglgraphics.h" #include "opengl1graphics.h" #endif -#include "localplayer.h" + #include "map.h" #include "resources/image.h" diff --git a/src/configuration.cpp b/src/configuration.cpp index 39e0c75d4..c4f1cc360 100644 --- a/src/configuration.cpp +++ b/src/configuration.cpp @@ -161,7 +161,7 @@ void Configuration::cleanDefaults() for (DefaultsData::const_iterator iter = mDefaultsData->begin(); iter != mDefaultsData->end(); ++iter) { - delete(iter->second); + delete (iter->second); } mDefaultsData->clear(); delete mDefaultsData; @@ -193,21 +193,21 @@ int Configuration::getIntValue(const std::string &key) const if (itdef != mDefaultsData->end() && itdef->second) { - if (itdef->second->getType() == Mana::VariableData::DATA_INT) + if (itdef->second->getType() == VariableData::DATA_INT) { - defaultValue = (static_cast<Mana::IntData*>( + defaultValue = (static_cast<IntData*>( itdef->second))->getData(); } else if (itdef->second->getType() - == Mana::VariableData::DATA_STRING) + == VariableData::DATA_STRING) { - defaultValue = atoi((static_cast<Mana::StringData*>( + defaultValue = atoi((static_cast<StringData*>( itdef->second))->getData().c_str()); } else if (itdef->second->getType() - == Mana::VariableData::DATA_BOOL) + == VariableData::DATA_BOOL) { - if ((static_cast<Mana::BoolData*>( + if ((static_cast<BoolData*>( itdef->second))->getData()) { defaultValue = 1; @@ -241,9 +241,9 @@ int Configuration::resetIntValue(const std::string &key) DefaultsData::const_iterator itdef = mDefaultsData->find(key); if (itdef != mDefaultsData->end() && itdef->second - && itdef->second->getType() == Mana::VariableData::DATA_INT) + && itdef->second->getType() == VariableData::DATA_INT) { - defaultValue = (static_cast<Mana::IntData*>( + defaultValue = (static_cast<IntData*>( itdef->second))->getData(); } else @@ -270,15 +270,15 @@ std::string Configuration::getStringValue(const std::string &key) const if (itdef != mDefaultsData->end() && itdef->second) { if (itdef->second->getType() - == Mana::VariableData::DATA_STRING) + == VariableData::DATA_STRING) { - defaultValue = (static_cast<Mana::StringData*>( + defaultValue = (static_cast<StringData*>( itdef->second))->getData(); } else if (itdef->second->getType() - == Mana::VariableData::DATA_BOOL) + == VariableData::DATA_BOOL) { - if ((static_cast<Mana::BoolData*>( + if ((static_cast<BoolData*>( itdef->second))->getData()) { defaultValue = "1"; @@ -289,9 +289,9 @@ std::string Configuration::getStringValue(const std::string &key) const } } else if (itdef->second->getType() - == Mana::VariableData::DATA_INT) + == VariableData::DATA_INT) { - defaultValue = toString((static_cast<Mana::IntData*>( + defaultValue = toString((static_cast<IntData*>( itdef->second))->getData()); } } @@ -322,10 +322,10 @@ float Configuration::getFloatValue(const std::string &key) const DefaultsData::const_iterator itdef = mDefaultsData->find(key); if (itdef != mDefaultsData->end() && itdef->second - && itdef->second->getType() == Mana::VariableData::DATA_FLOAT) + && itdef->second->getType() == VariableData::DATA_FLOAT) { defaultValue = static_cast<float>( - (static_cast<Mana::FloatData*>(itdef->second))->getData()); + (static_cast<FloatData*>(itdef->second))->getData()); } else { @@ -354,15 +354,15 @@ bool Configuration::getBoolValue(const std::string &key) const if (itdef != mDefaultsData->end() && itdef->second) { - if (itdef->second->getType() == Mana::VariableData::DATA_BOOL) + if (itdef->second->getType() == VariableData::DATA_BOOL) { - defaultValue = (static_cast<Mana::BoolData*>( + defaultValue = (static_cast<BoolData*>( itdef->second))->getData(); } else if (itdef->second->getType() - == Mana::VariableData::DATA_INT) + == VariableData::DATA_INT) { - if ((static_cast<Mana::IntData*>( + if ((static_cast<IntData*>( itdef->second))->getData() != 0) { defaultValue = true; @@ -373,9 +373,9 @@ bool Configuration::getBoolValue(const std::string &key) const } } else if (itdef->second->getType() - == Mana::VariableData::DATA_STRING) + == VariableData::DATA_STRING) { - if ((static_cast<Mana::StringData*>( + if ((static_cast<StringData*>( itdef->second))->getData() != "0") { defaultValue = true; @@ -410,9 +410,9 @@ bool Configuration::resetBoolValue(const std::string &key) DefaultsData::const_iterator itdef = mDefaultsData->find(key); if (itdef != mDefaultsData->end() && itdef->second - && itdef->second->getType() == Mana::VariableData::DATA_BOOL) + && itdef->second->getType() == VariableData::DATA_BOOL) { - defaultValue = (static_cast<Mana::BoolData*>( + defaultValue = (static_cast<BoolData*>( itdef->second))->getData(); } else diff --git a/src/debug/debug_new.cpp b/src/debug/debug_new.cpp index 3bc02b3e5..fb83cab4a 100644 --- a/src/debug/debug_new.cpp +++ b/src/debug/debug_new.cpp @@ -62,49 +62,49 @@ #endif /** - * @def _DEBUG_NEW_ALIGNMENT + * @def M_DEBUG_NEW_ALIGNMENT * * The alignment requirement of allocated memory blocks. It must be a * power of two. */ -#ifndef _DEBUG_NEW_ALIGNMENT -#define _DEBUG_NEW_ALIGNMENT 16 +#ifndef M_DEBUG_NEW_ALIGNMENT +#define M_DEBUG_NEW_ALIGNMENT 16 #endif /** - * @def _DEBUG_NEW_CALLER_ADDRESS + * @def M_DEBUG_NEW_CALLER_ADDRESS * * The expression to return the caller address. #print_position will * later on use this address to print the position information of memory * operation points. */ -#ifndef _DEBUG_NEW_CALLER_ADDRESS +#ifndef M_DEBUG_NEW_CALLER_ADDRESS #ifdef __GNUC__ -#define _DEBUG_NEW_CALLER_ADDRESS __builtin_return_address(0) +#define M_DEBUG_NEW_CALLER_ADDRESS __builtin_return_address(0) #else -#define _DEBUG_NEW_CALLER_ADDRESS NULL +#define M_DEBUG_NEW_CALLER_ADDRESS NULL #endif #endif /** - * @def _DEBUG_NEW_ERROR_ACTION + * @def M_DEBUG_NEW_ERROR_ACTION * * The action to take when an error occurs. The default behaviour is to - * call \e abort, unless \c _DEBUG_NEW_ERROR_CRASH is defined, in which + * call \e abort, unless \c M_DEBUG_NEW_ERROR_CRASH is defined, in which * case a segmentation fault will be triggered instead (which can be * useful on platforms like Windows that do not generate a core dump * when \e abort is called). */ -#ifndef _DEBUG_NEW_ERROR_ACTION -#ifndef _DEBUG_NEW_ERROR_CRASH -#define _DEBUG_NEW_ERROR_ACTION abort() +#ifndef M_DEBUG_NEW_ERROR_ACTION +#ifndef M_DEBUG_NEW_ERROR_CRASH +#define M_DEBUG_NEW_ERROR_ACTION abort() #else -#define _DEBUG_NEW_ERROR_ACTION do { *((char*)0) = 0; abort(); } while (0) +#define M_DEBUG_NEW_ERROR_ACTION do { *((char*)0) = 0; abort(); } while (0) #endif #endif /** - * @def _DEBUG_NEW_FILENAME_LEN + * @def M_DEBUG_NEW_FILENAME_LEN * * The length of file name stored if greater than zero. If it is zero, * only a const char pointer will be stored. Currently the default @@ -114,70 +114,70 @@ * name in a shared library after a \c SIGINT). The current default * value makes the size of new_ptr_list_t 64 on 32-bit platforms. */ -#ifndef _DEBUG_NEW_FILENAME_LEN -#define _DEBUG_NEW_FILENAME_LEN 100 +#ifndef M_DEBUG_NEW_FILENAME_LEN +#define M_DEBUG_NEW_FILENAME_LEN 100 #endif /** - * @def _DEBUG_NEW_PROGNAME + * @def M_DEBUG_NEW_PROGNAME * * The program (executable) name to be set at compile time. It is * better to assign the full program path to #new_progname in \e main * (at run time) than to use this (compile-time) macro, but this macro * serves well as a quick hack. Note also that double quotation marks * need to be used around the program name, i.e., one should specify a - * command-line option like <code>-D_DEBUG_NEW_PROGNAME=\"a.out\"</code> - * in \e bash, or <code>-D_DEBUG_NEW_PROGNAME=\"a.exe\"</code> in the + * command-line option like <code>-DM_DEBUG_NEW_PROGNAME=\"a.out\"</code> + * in \e bash, or <code>-DM_DEBUG_NEW_PROGNAME=\"a.exe\"</code> in the * Windows command prompt. */ -#ifndef _DEBUG_NEW_PROGNAME -#define _DEBUG_NEW_PROGNAME NULL +#ifndef M_DEBUG_NEW_PROGNAME +#define M_DEBUG_NEW_PROGNAME NULL #endif /** - * @def _DEBUG_NEW_STD_OPER_NEW + * @def M_DEBUG_NEW_STD_OPER_NEW * * Macro to indicate whether the standard-conformant behaviour of * <code>operator new</code> is wanted. It is on by default now, but * the user may set it to \c 0 to revert to the old behaviour. */ -#ifndef _DEBUG_NEW_STD_OPER_NEW -#define _DEBUG_NEW_STD_OPER_NEW 1 +#ifndef M_DEBUG_NEW_STD_OPER_NEW +#define M_DEBUG_NEW_STD_OPER_NEW 1 #endif /** - * @def _DEBUG_NEW_TAILCHECK + * @def M_DEBUG_NEW_TAILCHECK * * Macro to indicate whether a writing-past-end check will be performed. * Define it to a positive integer as the number of padding bytes at the * end of a memory block for checking. */ -#ifndef _DEBUG_NEW_TAILCHECK -#define _DEBUG_NEW_TAILCHECK 0 +#ifndef M_DEBUG_NEW_TAILCHECK +#define M_DEBUG_NEW_TAILCHECK 0 #endif /** - * @def _DEBUG_NEW_TAILCHECK_CHAR + * @def M_DEBUG_NEW_TAILCHECK_CHAR * * Value of the padding bytes at the end of a memory block. */ -#ifndef _DEBUG_NEW_TAILCHECK_CHAR -#define _DEBUG_NEW_TAILCHECK_CHAR 0xCC +#ifndef M_DEBUG_NEW_TAILCHECK_CHAR +#define M_DEBUG_NEW_TAILCHECK_CHAR 0xCC #endif /** - * @def _DEBUG_NEW_USE_ADDR2LINE + * @def M_DEBUG_NEW_USE_ADDR2LINE * * Whether to use \e addr2line to convert a caller address to file/line * information. Defining it to a non-zero value will enable the * conversion (automatically done if GCC is detected). Defining it to * zero will disable the conversion. */ -#ifndef _DEBUG_NEW_USE_ADDR2LINE +#ifndef M_DEBUG_NEW_USE_ADDR2LINE #ifdef __GNUC__ -#define _DEBUG_NEW_USE_ADDR2LINE 1 +#define M_DEBUG_NEW_USE_ADDR2LINE 1 #else -#define _DEBUG_NEW_USE_ADDR2LINE 0 +#define M_DEBUG_NEW_USE_ADDR2LINE 0 #endif #endif @@ -187,20 +187,20 @@ #pragma init_seg(lib) #endif -#undef _DEBUG_NEW_EMULATE_MALLOC -#undef _DEBUG_NEW_REDEFINE_NEW +#undef M_DEBUG_NEW_EMULATE_MALLOC +#undef M_DEBUG_NEW_REDEFINE_NEW /** * Macro to indicate whether redefinition of \c new is wanted. Here it * is defined to \c 0 to disable the redefinition of \c new. */ -#define _DEBUG_NEW_REDEFINE_NEW 0 +#define M_DEBUG_NEW_REDEFINE_NEW 0 #include "debug_new.h" /** * Gets the aligned value of memory block size. */ #define align(s) \ - (((s) + _DEBUG_NEW_ALIGNMENT - 1) & ~(_DEBUG_NEW_ALIGNMENT - 1)) + (((s) + M_DEBUG_NEW_ALIGNMENT - 1) & ~(M_DEBUG_NEW_ALIGNMENT - 1)) /** * Structure to store the position information where \c new occurs. @@ -212,10 +212,10 @@ struct new_ptr_list_t size_t size; union { -#if _DEBUG_NEW_FILENAME_LEN == 0 +#if M_DEBUG_NEW_FILENAME_LEN == 0 const char* file; #else - char file[_DEBUG_NEW_FILENAME_LEN]; + char file[M_DEBUG_NEW_FILENAME_LEN]; #endif void* addr; }; @@ -244,7 +244,7 @@ static new_ptr_list_t new_ptr_list = &new_ptr_list, 0, { -#if _DEBUG_NEW_FILENAME_LEN == 0 +#if M_DEBUG_NEW_FILENAME_LEN == 0 NULL #else "" @@ -291,15 +291,15 @@ FILE* new_output_fp = stderr; /** * Pointer to the program name. Its initial value is the macro - * #_DEBUG_NEW_PROGNAME. You should try to assign the program path to + * #M_DEBUG_NEW_PROGNAME. You should try to assign the program path to * it early in your application. Assigning <code>argv[0]</code> to it * in \e main is one way. If you use \e bash or \e ksh (or similar), * the following statement is probably what you want: * `<code>new_progname = getenv("_");</code>'. */ -const char* new_progname = _DEBUG_NEW_PROGNAME; +const char* new_progname = M_DEBUG_NEW_PROGNAME; -#if _DEBUG_NEW_USE_ADDR2LINE +#if M_DEBUG_NEW_USE_ADDR2LINE /** * Tries printing the position information from an instruction address. * This is the version that uses \e addr2line. @@ -397,11 +397,11 @@ static bool print_position_from_addr(const void*) { return false; } -#endif // _DEBUG_NEW_USE_ADDR2LINE +#endif // M_DEBUG_NEW_USE_ADDR2LINE /** * Prints the position information of a memory operation point. When \c - * _DEBUG_NEW_USE_ADDR2LINE is defined to a non-zero value, this + * M_DEBUG_NEW_USE_ADDR2LINE is defined to a non-zero value, this * function will try to convert a given caller address to file/line * information with \e addr2line. * @@ -427,7 +427,7 @@ static void print_position(const void* ptr, int line) } } -#if _DEBUG_NEW_TAILCHECK +#if M_DEBUG_NEW_TAILCHECK /** * Checks whether the padding bytes at the end of a memory block is * tampered with. @@ -440,9 +440,9 @@ static bool check_tail(new_ptr_list_t* ptr) { const unsigned char* const pointer = (unsigned char*)ptr + ALIGNED_LIST_ITEM_SIZE + ptr->size; - for (int i = 0; i < _DEBUG_NEW_TAILCHECK; ++i) + for (int i = 0; i < M_DEBUG_NEW_TAILCHECK; ++i) { - if (pointer[i] != _DEBUG_NEW_TAILCHECK_CHAR) + if (pointer[i] != M_DEBUG_NEW_TAILCHECK_CHAR) return false; } return true; @@ -462,14 +462,14 @@ static bool check_tail(new_ptr_list_t* ptr) static void* alloc_mem(size_t size, const char* file, int line, bool is_array) { assert(line >= 0); - STATIC_ASSERT((_DEBUG_NEW_ALIGNMENT & (_DEBUG_NEW_ALIGNMENT - 1)) == 0, + STATIC_ASSERT((M_DEBUG_NEW_ALIGNMENT & (M_DEBUG_NEW_ALIGNMENT - 1)) == 0, Alignment_must_be_power_of_two); - STATIC_ASSERT(_DEBUG_NEW_TAILCHECK >= 0, Invalid_tail_check_length); - size_t s = size + ALIGNED_LIST_ITEM_SIZE + _DEBUG_NEW_TAILCHECK; + STATIC_ASSERT(M_DEBUG_NEW_TAILCHECK >= 0, Invalid_tail_check_length); + size_t s = size + ALIGNED_LIST_ITEM_SIZE + M_DEBUG_NEW_TAILCHECK; new_ptr_list_t* ptr = (new_ptr_list_t*)malloc(s); if (ptr == NULL) { -#if _DEBUG_NEW_STD_OPER_NEW +#if M_DEBUG_NEW_STD_OPER_NEW return NULL; #else fast_mutex_autolock lock(new_output_lock); @@ -477,17 +477,17 @@ static void* alloc_mem(size_t size, const char* file, int line, bool is_array) "Out of memory when allocating %u bytes\n", size); fflush(new_output_fp); - _DEBUG_NEW_ERROR_ACTION; + M_DEBUG_NEW_ERROR_ACTION; #endif } void* pointer = (char*)ptr + ALIGNED_LIST_ITEM_SIZE; -#if _DEBUG_NEW_FILENAME_LEN == 0 +#if M_DEBUG_NEW_FILENAME_LEN == 0 ptr->file = file; #else if (line) { - strncpy(ptr->file, file, _DEBUG_NEW_FILENAME_LEN - 1) - [_DEBUG_NEW_FILENAME_LEN - 1] = '\0'; + strncpy(ptr->file, file, M_DEBUG_NEW_FILENAME_LEN - 1) + [M_DEBUG_NEW_FILENAME_LEN - 1] = '\0'; } else { @@ -506,9 +506,9 @@ static void* alloc_mem(size_t size, const char* file, int line, bool is_array) new_ptr_list.prev = ptr; } ptr->dumped = 0; -#if _DEBUG_NEW_TAILCHECK - memset((char*)pointer + size, _DEBUG_NEW_TAILCHECK_CHAR, - _DEBUG_NEW_TAILCHECK); +#if M_DEBUG_NEW_TAILCHECK + memset((char*)pointer + size, M_DEBUG_NEW_TAILCHECK_CHAR, + M_DEBUG_NEW_TAILCHECK); #endif if (new_verbose_flag) { @@ -533,7 +533,7 @@ static void* alloc_mem(size_t size, const char* file, int line, bool is_array) * @param pointer pointer to delete * @param addr pointer to the caller * @param is_array flag indicating whether it is invoked by a - * <code>delete[]</code> call + * <code>delete []</code> call */ static void free_pointer(void* pointer, void* addr, bool is_array) { @@ -552,15 +552,15 @@ static void free_pointer(void* pointer, void* addr, bool is_array) } check_mem_corruption(); fflush(new_output_fp); - _DEBUG_NEW_ERROR_ACTION; + M_DEBUG_NEW_ERROR_ACTION; } if (is_array != ptr->is_array) { const char* msg; if (is_array) - msg = "delete[] after new"; + msg = "delete [] after new"; else - msg = "delete after new[]"; + msg = "delete after new []"; fast_mutex_autolock lock(new_output_lock); fprintf(new_output_fp, "%s: pointer %p (size %u)\n\tat ", @@ -575,14 +575,14 @@ static void free_pointer(void* pointer, void* addr, bool is_array) print_position(ptr->addr, ptr->line); fprintf(new_output_fp, "\n"); fflush(new_output_fp); - _DEBUG_NEW_ERROR_ACTION; + M_DEBUG_NEW_ERROR_ACTION; } -#if _DEBUG_NEW_TAILCHECK +#if M_DEBUG_NEW_TAILCHECK if (!check_tail(ptr)) { check_mem_corruption(); fflush(new_output_fp); - _DEBUG_NEW_ERROR_ACTION; + M_DEBUG_NEW_ERROR_ACTION; } #endif { @@ -630,7 +630,7 @@ int check_leaks() "warning: heap data corrupt near %p\n", pointer); } -#if _DEBUG_NEW_TAILCHECK +#if M_DEBUG_NEW_TAILCHECK if (!check_tail(ptr)) { fprintf(new_output_fp, @@ -687,14 +687,14 @@ int check_mem_corruption() { const char* const pointer = (char*)ptr + ALIGNED_LIST_ITEM_SIZE; if (ptr->magic == MAGIC -#if _DEBUG_NEW_TAILCHECK +#if M_DEBUG_NEW_TAILCHECK && check_tail(ptr) #endif ) { continue; } -#if _DEBUG_NEW_TAILCHECK +#if M_DEBUG_NEW_TAILCHECK if (ptr->magic != MAGIC) { #endif @@ -702,7 +702,7 @@ int check_mem_corruption() "Heap data corrupt near %p (size %u, ", pointer, (unsigned)ptr->size); -#if _DEBUG_NEW_TAILCHECK +#if M_DEBUG_NEW_TAILCHECK } else { @@ -738,19 +738,19 @@ void __debug_new_recorder::_M_process(void* pointer) _M_file, _M_line); return; } -#if _DEBUG_NEW_FILENAME_LEN == 0 +#if M_DEBUG_NEW_FILENAME_LEN == 0 ptr->file = _M_file; #else - strncpy(ptr->file, _M_file, _DEBUG_NEW_FILENAME_LEN - 1) - [_DEBUG_NEW_FILENAME_LEN - 1] = '\0'; + strncpy(ptr->file, _M_file, M_DEBUG_NEW_FILENAME_LEN - 1) + [M_DEBUG_NEW_FILENAME_LEN - 1] = '\0'; #endif ptr->line = _M_line; } -void* operator new(size_t size, const char* file, int line) +void* operator new (size_t size, const char* file, int line) { void* ptr = alloc_mem(size, file, line, false); -#if _DEBUG_NEW_STD_OPER_NEW +#if M_DEBUG_NEW_STD_OPER_NEW if (ptr) return ptr; else @@ -760,10 +760,10 @@ void* operator new(size_t size, const char* file, int line) #endif } -void* operator new[](size_t size, const char* file, int line) +void* operator new [](size_t size, const char* file, int line) { void* ptr = alloc_mem(size, file, line, true); -#if _DEBUG_NEW_STD_OPER_NEW +#if M_DEBUG_NEW_STD_OPER_NEW if (ptr) return ptr; else @@ -773,40 +773,40 @@ void* operator new[](size_t size, const char* file, int line) #endif } -void* operator new(size_t size) throw(std::bad_alloc) +void* operator new (size_t size) throw(std::bad_alloc) { - return operator new(size, (char*)_DEBUG_NEW_CALLER_ADDRESS, 0); + return operator new (size, (char*)M_DEBUG_NEW_CALLER_ADDRESS, 0); } -void* operator new[](size_t size) throw(std::bad_alloc) +void* operator new [](size_t size) throw(std::bad_alloc) { - return operator new[](size, (char*)_DEBUG_NEW_CALLER_ADDRESS, 0); + return operator new [](size, (char*)M_DEBUG_NEW_CALLER_ADDRESS, 0); } #if !defined(__BORLANDC__) || __BORLANDC__ > 0x551 -void* operator new(size_t size, const std::nothrow_t&) throw() +void* operator new (size_t size, const std::nothrow_t&) throw() { - return alloc_mem(size, (char*)_DEBUG_NEW_CALLER_ADDRESS, 0, false); + return alloc_mem(size, (char*)M_DEBUG_NEW_CALLER_ADDRESS, 0, false); } -void* operator new[](size_t size, const std::nothrow_t&) throw() +void* operator new [](size_t size, const std::nothrow_t&) throw() { - return alloc_mem(size, (char*)_DEBUG_NEW_CALLER_ADDRESS, 0, true); + return alloc_mem(size, (char*)M_DEBUG_NEW_CALLER_ADDRESS, 0, true); } #endif -void operator delete(void* pointer) throw() +void operator delete (void* pointer) throw() { - free_pointer(pointer, _DEBUG_NEW_CALLER_ADDRESS, false); + free_pointer(pointer, M_DEBUG_NEW_CALLER_ADDRESS, false); } -void operator delete[](void* pointer) throw() +void operator delete [](void* pointer) throw() { - free_pointer(pointer, _DEBUG_NEW_CALLER_ADDRESS, true); + free_pointer(pointer, M_DEBUG_NEW_CALLER_ADDRESS, true); } #if HAVE_PLACEMENT_DELETE -void operator delete(void* pointer, const char* file, int line) throw() +void operator delete (void* pointer, const char* file, int line) throw() { if (new_verbose_flag) { @@ -817,10 +817,10 @@ void operator delete(void* pointer, const char* file, int line) throw() print_position(file, line); fprintf(new_output_fp, ")\n"); } - operator delete(pointer); + operator delete (pointer); } -void operator delete[](void* pointer, const char* file, int line) throw() +void operator delete [](void* pointer, const char* file, int line) throw() { if (new_verbose_flag) { @@ -831,17 +831,17 @@ void operator delete[](void* pointer, const char* file, int line) throw() print_position(file, line); fprintf(new_output_fp, ")\n"); } - operator delete[](pointer); + operator delete [](pointer); } -void operator delete(void* pointer, const std::nothrow_t&) throw() +void operator delete (void* pointer, const std::nothrow_t&) throw() { - operator delete(pointer, (char*)_DEBUG_NEW_CALLER_ADDRESS, 0); + operator delete (pointer, (char*)M_DEBUG_NEW_CALLER_ADDRESS, 0); } -void operator delete[](void* pointer, const std::nothrow_t&) throw() +void operator delete [](void* pointer, const std::nothrow_t&) throw() { - operator delete[](pointer, (char*)_DEBUG_NEW_CALLER_ADDRESS, 0); + operator delete [](pointer, (char*)M_DEBUG_NEW_CALLER_ADDRESS, 0); } #endif // HAVE_PLACEMENT_DELETE diff --git a/src/debug/debug_new.h b/src/debug/debug_new.h index 0e99b96a7..157f2648a 100644 --- a/src/debug/debug_new.h +++ b/src/debug/debug_new.h @@ -61,7 +61,7 @@ #endif /** - * @def _DEBUG_NEW_REDEFINE_NEW + * @def M_DEBUG_NEW_REDEFINE_NEW * * Macro to indicate whether redefinition of \c new is wanted. If one * wants to define one's own <code>operator new</code>, to call @@ -84,8 +84,8 @@ * # endif * @endcode */ -#ifndef _DEBUG_NEW_REDEFINE_NEW -#define _DEBUG_NEW_REDEFINE_NEW 1 +#ifndef M_DEBUG_NEW_REDEFINE_NEW +#define M_DEBUG_NEW_REDEFINE_NEW 1 #endif /* Prototypes */ @@ -114,16 +114,16 @@ extern const char* new_progname; // default to NULL; should be assigned argv[0] * @def DEBUG_NEW * * Macro to catch file/line information on allocation. If - * #_DEBUG_NEW_REDEFINE_NEW is \c 0, one can use this macro directly; + * #M_DEBUG_NEW_REDEFINE_NEW is \c 0, one can use this macro directly; * otherwise \c new will be defined to it, and one must use \c new * instead. */ #define DEBUG_NEW __debug_new_recorder(__FILE__, __LINE__) ->* new -# if _DEBUG_NEW_REDEFINE_NEW +# if M_DEBUG_NEW_REDEFINE_NEW # define new DEBUG_NEW # endif -# ifdef _DEBUG_NEW_EMULATE_MALLOC +# ifdef M_DEBUG_NEW_EMULATE_MALLOC # include <stdlib.h> # ifdef new # define malloc(s) ((void*)(new char[s])) diff --git a/src/defaults.cpp b/src/defaults.cpp index 1bce806ff..b21941bfb 100644 --- a/src/defaults.cpp +++ b/src/defaults.cpp @@ -31,8 +31,6 @@ #include "debug.h" -using namespace Mana; - VariableData* createData(int defData) { return new IntData(defData); @@ -134,7 +132,7 @@ DefaultsData* getConfigDefaults() AddDEF(configData, "download-music", false); AddDEF(configData, "guialpha", 0.8f); AddDEF(configData, "ChatLogLength", 0); - AddDEF(configData, "enableChatLog", false); + AddDEF(configData, "enableChatLog", true); AddDEF(configData, "whispertab", true); AddDEF(configData, "customcursor", true); AddDEF(configData, "showownname", true); @@ -174,7 +172,7 @@ DefaultsData* getConfigDefaults() AddDEF(configData, "hideShopMessages", true); AddDEF(configData, "showChatHistory", true); AddDEF(configData, "showChatColorsList", true); - AddDEF(configData, "chatMaxLinesLimit", 20); + AddDEF(configData, "chatMaxLinesLimit", 40); AddDEF(configData, "chatColor", 0); AddDEF(configData, "hideShield", true); AddDEF(configData, "showJob", true); @@ -227,6 +225,7 @@ DefaultsData* getConfigDefaults() AddDEF(configData, "testInfo", ""); AddDEF(configData, "enableresize", true); AddDEF(configData, "noframe", false); + AddDEF(configData, "groupFriends", true); return configData; } @@ -244,6 +243,7 @@ DefaultsData* getBrandingDefaults() AddDEF(brandingData, "defaultServerType", "tmwathena"); AddDEF(brandingData, "onlineServerList", "http://manaplus.evolonline.org/serverlist.xml"); + AddDEF(brandingData, "onlineServerFile", "serverlistplus.xml"); AddDEF(brandingData, "appShort", "mana"); AddDEF(brandingData, "defaultUpdateHost", ""); AddDEF(brandingData, "helpPath", ""); diff --git a/src/defaults.h b/src/defaults.h index 1d979e928..fc74f76c8 100644 --- a/src/defaults.h +++ b/src/defaults.h @@ -26,9 +26,7 @@ #include <string> #include "variabledata.h" -using namespace Mana; - -typedef std::map<std::string, Mana::VariableData*> DefaultsData; +typedef std::map<std::string, VariableData*> DefaultsData; VariableData* createData(int defData); VariableData* createData(double defData); diff --git a/src/event.cpp b/src/event.cpp index 4f77967bc..a536bcaea 100644 --- a/src/event.cpp +++ b/src/event.cpp @@ -26,9 +26,6 @@ #include "debug.h" -namespace Mana -{ - ListenMap Event::mBindings; Event::~Event() @@ -142,5 +139,3 @@ void Event::unbind(Listener *listener, Channels channel) { mBindings[channel].erase(listener); } - -} diff --git a/src/event.h b/src/event.h index 61bf31e14..7dffaad21 100644 --- a/src/event.h +++ b/src/event.h @@ -26,10 +26,6 @@ #include <set> #include <string> - -namespace Mana -{ - enum Channels { CHANNEL_ACTORSPRITE = 0, @@ -115,9 +111,9 @@ typedef std::set<Listener *> ListenerSet; typedef std::map<Channels, ListenerSet > ListenMap; #define SERVER_NOTICE(message) { \ -Mana::Event event(Mana::EVENT_SERVERNOTICE); \ +Event event(EVENT_SERVERNOTICE); \ event.setString("message", message); \ -Mana::Event::trigger(Mana::CHANNEL_NOTICES, event); } +Event::trigger(CHANNEL_NOTICES, event); } class Event { @@ -172,6 +168,4 @@ class Event VariableMap mData; }; -} // namespace Mana - #endif diff --git a/src/flooritem.cpp b/src/flooritem.cpp index 6e4926f2e..f126f336b 100644 --- a/src/flooritem.cpp +++ b/src/flooritem.cpp @@ -31,20 +31,15 @@ #include "gui/gui.h" #include "gui/sdlfont.h" -#include "net/net.h" +//#include "net/net.h" #include "resources/itemdb.h" #include "resources/iteminfo.h" #include "debug.h" -FloorItem::FloorItem(int id, - int itemId, - int x, - int y, - Map *map, - int amount, - unsigned char color): +FloorItem::FloorItem(int id, int itemId, int x, int y, Map *map, int amount, + unsigned char color, int subX, int subY): ActorSprite(id), mItemId(itemId), mX(x), @@ -60,16 +55,8 @@ FloorItem::FloorItem(int id, setMap(map); if (map) { - // TODO: Eventually, we probably should fix all sprite offsets so that - // these translations aren't necessary anymore. The sprites know - // best where their base point should be. - mPos.x = static_cast<float>(x * map->getTileWidth() + 16); -#ifdef MANASERV_SUPPORT - mPos.y = static_cast<float>(y * map->getTileHeight() + - ((Net::getNetworkType() == ServerInfo::MANASERV) ? 15 : 32)); -#else - mPos.y = static_cast<float>(y * map->getTileHeight() + 32); -#endif + mPos.x = static_cast<float>(x * map->getTileWidth() + subX); + mPos.y = static_cast<float>(y * map->getTileHeight() + subY); } else { diff --git a/src/flooritem.h b/src/flooritem.h index 95427c252..1f3126078 100644 --- a/src/flooritem.h +++ b/src/flooritem.h @@ -42,14 +42,12 @@ class FloorItem : public ActorSprite * @param y the y position in tiles * @param map the map this item is on * @param amount the item amount + * @param color the item color + * @param subX the x pixel relative position + * @param subY the y pixel relative position */ - FloorItem(int id, - int itemId, - int x, - int y, - Map *map, - int amount, - unsigned char color); + FloorItem(int id, int itemId, int x, int y, Map *map, int amount, + unsigned char color, int subX, int subY); Type getType() const { return FLOOR_ITEM; } diff --git a/src/game.cpp b/src/game.cpp index 0d5c1113e..e016d02ff 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -104,6 +104,8 @@ #include "utils/gettext.h" #include "utils/mkdir.h" +#include "utils/translation/translationmanager.h" + #include <guichan/exception.hpp> #include <guichan/focushandler.hpp> @@ -173,7 +175,7 @@ const unsigned adjustDelay = 10; */ static void initEngines() { - Mana::Event::trigger(CHANNEL_GAME, Mana::Event(EVENT_ENGINESINITALIZING)); + Event::trigger(CHANNEL_GAME, Event(EVENT_ENGINESINITALIZING)); actorSpriteManager = new ActorSpriteManager; commandHandler = new CommandHandler; @@ -185,7 +187,7 @@ static void initEngines() particleEngine = new Particle(nullptr); particleEngine->setupEngine(); - Mana::Event::trigger(CHANNEL_GAME, Mana::Event(EVENT_ENGINESINITALIZED)); + Event::trigger(CHANNEL_GAME, Event(EVENT_ENGINESINITALIZED)); } /** @@ -193,7 +195,7 @@ static void initEngines() */ static void createGuiWindows() { - Mana::Event::trigger(CHANNEL_GAME, Mana::Event(EVENT_GUIWINDOWSLOADING)); + Event::trigger(CHANNEL_GAME, Event(EVENT_GUIWINDOWSLOADING)); if (setupWindow) setupWindow->clearWindowsForReset(); @@ -290,7 +292,7 @@ static void createGuiWindows() if (player_node) player_node->updateStatus(); - Mana::Event::trigger(CHANNEL_GAME, Mana::Event(EVENT_GUIWINDOWSLOADED)); + Event::trigger(CHANNEL_GAME, Event(EVENT_GUIWINDOWSLOADED)); } #define del_0(X) { delete X; X = nullptr; } @@ -300,7 +302,7 @@ static void createGuiWindows() */ static void destroyGuiWindows() { - Mana::Event::trigger(CHANNEL_GAME, Mana::Event(EVENT_GUIWINDOWSUNLOADING)); + Event::trigger(CHANNEL_GAME, Event(EVENT_GUIWINDOWSUNLOADING)); logger->setChatWindow(nullptr); if (whoIsOnline) @@ -343,7 +345,7 @@ static void destroyGuiWindows() del_0(killStats); del_0(didYouKnowWindow); - Mana::Event::trigger(CHANNEL_GAME, Mana::Event(EVENT_GUIWINDOWSUNLOADED)); + Event::trigger(CHANNEL_GAME, Event(EVENT_GUIWINDOWSUNLOADED)); if (auctionManager && AuctionManager::getEnableAuctionBot()) auctionManager->reload(); @@ -414,7 +416,7 @@ Game::Game(): if (guildManager && GuildManager::getEnableGuildBot()) guildManager->requestGuildInfo(); - Mana::Event::trigger(CHANNEL_GAME, Mana::Event(EVENT_CONSTRUCTED)); + Event::trigger(CHANNEL_GAME, Event(EVENT_CONSTRUCTED)); } Game::~Game() @@ -448,7 +450,7 @@ Game::~Game() mInstance = nullptr; - Mana::Event::trigger(CHANNEL_GAME, Mana::Event(EVENT_DESTRUCTED)); + Event::trigger(CHANNEL_GAME, Event(EVENT_DESTRUCTED)); } static bool saveScreenshot() @@ -1418,7 +1420,7 @@ void Game::handleMoveAndAttack(SDL_Event &event, bool wasDown) Net::getPlayerHandler()->setDirection(direction); } } - direction = 0; +// direction = 0; } else { @@ -1693,7 +1695,7 @@ void Game::handleInput() { if (emoteShortcut) emoteShortcut->useEmote(emotion); - used = true; +// used = true; setValidSpeed(); return; } @@ -1841,9 +1843,9 @@ void Game::changeMap(const std::string &mapPath) if (mumbleManager) mumbleManager->setMap(mapPath); - Mana::Event event(EVENT_MAPLOADED); + Event event(EVENT_MAPLOADED); event.setString("mapPath", mapPath); - Mana::Event::trigger(CHANNEL_GAME, event); + Event::trigger(CHANNEL_GAME, event); } void Game::updateHistory(SDL_Event &event) diff --git a/src/graphics.cpp b/src/graphics.cpp index 5848d8c14..5241bbcc6 100644 --- a/src/graphics.cpp +++ b/src/graphics.cpp @@ -24,7 +24,6 @@ #include "graphicsvertexes.h" #include "logger.h" -#include "map.h" #include "resources/image.h" #include "resources/imageloader.h" @@ -113,7 +112,7 @@ bool Graphics::setVideoMode(int w, int h, int bpp, bool fs, if (mTarget->format) { logger->log("Bits per pixel: %d", mTarget->format->BytesPerPixel); - bpp = mTarget->format->BytesPerPixel; +// bpp = mTarget->format->BytesPerPixel; } const SDL_VideoInfo *vi = SDL_GetVideoInfo(); @@ -719,10 +718,10 @@ int Graphics::SDL_FakeUpperBlit(SDL_Surface *src, SDL_Rect *srcrect, /* Make sure the surfaces aren't locked */ if (!src || !dst) - return(-1); + return -1; if (src->locked || dst->locked) - return(-1); + return -1; /* If the destination rectangle is nullptr, use the entire dest surface */ if (!dstrect) @@ -841,7 +840,7 @@ void Graphics::fillRectangle(const gcn::Rectangle& rectangle) Uint32 pixel = SDL_MapRGB(mTarget->format, mColor.r, mColor.g, mColor.b); - switch(bpp) + switch (bpp) { case 1: for (y = y1; y < y2; y++) diff --git a/src/gui/botcheckerwindow.cpp b/src/gui/botcheckerwindow.cpp index 2043b4fe3..4a092ab55 100644 --- a/src/gui/botcheckerwindow.cpp +++ b/src/gui/botcheckerwindow.cpp @@ -53,7 +53,8 @@ #define TIME_COLUMN 1 #define ROW_HEIGHT 12 -// The following column widths really shouldn't be hardcoded but should scale with the size of the widget... excep +// The following column widths really shouldn't be hardcoded but should +// scale with the size of the widget... excep // that, right now, the widget doesn't exactly scale either. #define NAME_COLUMN_WIDTH 185 #define TIME_COLUMN_WIDTH 70 diff --git a/src/gui/chatwindow.cpp b/src/gui/chatwindow.cpp index 6831ad5b6..69e4d703f 100644 --- a/src/gui/chatwindow.cpp +++ b/src/gui/chatwindow.cpp @@ -159,7 +159,7 @@ ChatWindow::ChatWindow(): mGMLoaded(false) { listen(CHANNEL_NOTICES); - listen(Mana::CHANNEL_ATTRIBUTES); + listen(CHANNEL_ATTRIBUTES); setWindowName("Chat"); @@ -311,6 +311,7 @@ void ChatWindow::fillCommands() mCommands.push_back("<MONSTER>"); mCommands.push_back("<PEOPLE>"); mCommands.push_back("<PARTY>"); + mCommands.push_back("/setdrop "); } void ChatWindow::loadGMCommands() @@ -594,7 +595,7 @@ void ChatWindow::ignoreAllWhispers() PlayerRelation::IGNORED); } - delete(iter->second); + delete (iter->second); iter->second = nullptr; } } @@ -866,19 +867,19 @@ void ChatWindow::keyPressed(gcn::KeyEvent &event) addInputText(Temp, false); } -void ChatWindow::processEvent(Mana::Channels channel, const Mana::Event &event) +void ChatWindow::processEvent(Channels channel, const Event &event) { - if (channel == Mana::CHANNEL_NOTICES) + if (channel == CHANNEL_NOTICES) { - if (event.getName() == Mana::EVENT_SERVERNOTICE && localChatTab) + if (event.getName() == EVENT_SERVERNOTICE && localChatTab) localChatTab->chatLog(event.getString("message"), BY_SERVER); } - else if (channel == Mana::CHANNEL_ATTRIBUTES) + else if (channel == CHANNEL_ATTRIBUTES) { if (!config.getBoolValue("showBattleEvents")) return; - if (event.getName() == Mana::EVENT_UPDATEATTRIBUTE) + if (event.getName() == EVENT_UPDATEATTRIBUTE) { switch (event.getInt("id")) { @@ -902,7 +903,7 @@ void ChatWindow::processEvent(Mana::Channels channel, const Mana::Event &event) break; }; } - else if (event.getName() == Mana::EVENT_UPDATESTAT) + else if (event.getName() == EVENT_UPDATESTAT) { if (!config.getBoolValue("showJobExp")) return; @@ -1122,7 +1123,7 @@ std::string ChatWindow::addColors(std::string &msg) int cMap[] = {1, 4, 5, 2, 3, 6, 7, 9, 0, 8}; // rainbow - switch(mChatColor) + switch (mChatColor) { case 11: msg = removeColors(msg); diff --git a/src/gui/chatwindow.h b/src/gui/chatwindow.h index 82e3d31f2..b3dce33fc 100644 --- a/src/gui/chatwindow.h +++ b/src/gui/chatwindow.h @@ -80,7 +80,7 @@ struct CHATLOG class ChatWindow : public Window, public gcn::ActionListener, public gcn::KeyListener, - public Mana::Listener + public Listener { public: /** @@ -190,7 +190,7 @@ class ChatWindow : public Window, */ void mousePressed(gcn::MouseEvent &event); - void processEvent(Mana::Channels channel, const Mana::Event &event); + void processEvent(Channels channel, const Event &event); /** * Scrolls the chat window diff --git a/src/gui/confirmdialog.cpp b/src/gui/confirmdialog.cpp index cf9d541ad..22acf5116 100644 --- a/src/gui/confirmdialog.cpp +++ b/src/gui/confirmdialog.cpp @@ -112,4 +112,3 @@ void ConfirmDialog::action(const gcn::ActionEvent &event) scheduleDelete(); } } - diff --git a/src/gui/debugwindow.cpp b/src/gui/debugwindow.cpp index d13545bea..b65068dc5 100644 --- a/src/gui/debugwindow.cpp +++ b/src/gui/debugwindow.cpp @@ -62,7 +62,7 @@ DebugWindow::DebugWindow(): setSaveVisible(true); setStickyButtonLock(true); - setDefaultSize(400, 150, ImageRect::CENTER); + setDefaultSize(400, 300, ImageRect::CENTER); mTabs = new TabbedArea; mMapWidget = new MapDebugTab; @@ -269,9 +269,10 @@ TargetDebugTab::TargetDebugTab() mTargetLabel = new Label(strprintf("%s ?", _("Target:"))); mTargetIdLabel = new Label(strprintf("%s ? ", _("Target Id:"))); - mTargetLevelLabel = new Label(strprintf("%s ?", _("Target Level:"))); - mTargetPartyLabel = new Label(strprintf("%s ?", _("Target Party:"))); - mTargetGuildLabel = new Label(strprintf("%s ?", _("Target Guild:"))); + mTargetLevelLabel = new Label(strprintf("%s ?", _("Target level:"))); + mTargetRaceLabel = new Label(strprintf("%s ?", _("Target race:"))); + mTargetPartyLabel = new Label(strprintf("%s ?", _("Target party:"))); + mTargetGuildLabel = new Label(strprintf("%s ?", _("Target guild:"))); mAttackDelayLabel = new Label(strprintf("%s ?", _("Attack delay:"))); mMinHitLabel = new Label(strprintf("%s ?", _("Minimal hit:"))); mMaxHitLabel = new Label(strprintf("%s ?", _("Maximum hit:"))); @@ -280,12 +281,13 @@ TargetDebugTab::TargetDebugTab() place(0, 0, mTargetLabel, 2); place(0, 1, mTargetIdLabel, 2); place(0, 2, mTargetLevelLabel, 2); - place(0, 3, mAttackDelayLabel, 2); - place(0, 4, mTargetPartyLabel, 2); - place(0, 5, mTargetGuildLabel, 2); - place(0, 6, mMinHitLabel, 2); - place(0, 7, mMaxHitLabel, 2); - place(0, 8, mCriticalHitLabel, 2); + place(0, 3, mTargetRaceLabel, 2); + place(0, 4, mAttackDelayLabel, 2); + place(0, 5, mTargetPartyLabel, 2); + place(0, 6, mTargetGuildLabel, 2); + place(0, 7, mMinHitLabel, 2); + place(0, 8, mMaxHitLabel, 2); + place(0, 9, mCriticalHitLabel, 2); place.getCell().matchColWidth(0, 0); place = h.getPlacer(0, 1); @@ -315,6 +317,9 @@ void TargetDebugTab::logic() _("Target Level:"))); } + mTargetRaceLabel->setCaption(strprintf("%s %s", + _("Target race:"), target->getRaceName().c_str())); + mTargetPartyLabel->setCaption(strprintf("%s %s", _("Target Party:"), target->getPartyName().c_str())); @@ -396,4 +401,4 @@ void NetDebugTab::logic() PacketCounters::getInBytes())); mOutPackets1Label->setCaption(strprintf(_("Out: %d bytes/s"), PacketCounters::getOutBytes())); -}
\ No newline at end of file +} diff --git a/src/gui/debugwindow.h b/src/gui/debugwindow.h index ff86eaf74..8be6f1220 100644 --- a/src/gui/debugwindow.h +++ b/src/gui/debugwindow.h @@ -82,6 +82,7 @@ class TargetDebugTab : public DebugTab Label *mTargetLabel; Label *mTargetIdLabel; Label *mTargetLevelLabel; + Label *mTargetRaceLabel; Label *mTargetPartyLabel; Label *mTargetGuildLabel; Label *mAttackDelayLabel; diff --git a/src/gui/didyouknowwindow.cpp b/src/gui/didyouknowwindow.cpp index db0878360..a6b89923e 100644 --- a/src/gui/didyouknowwindow.cpp +++ b/src/gui/didyouknowwindow.cpp @@ -22,6 +22,7 @@ #include "gui/didyouknowwindow.h" +#include "configuration.h" #include "logger.h" #include "gui/gui.h" @@ -34,9 +35,9 @@ #include "gui/widgets/scrollarea.h" #include "resources/resourcemanager.h" -#include "configuration.h" #include "utils/gettext.h" +#include "utils/langs.h" #include "debug.h" diff --git a/src/gui/emotepopup.cpp b/src/gui/emotepopup.cpp index a286f78e8..39017ac91 100644 --- a/src/gui/emotepopup.cpp +++ b/src/gui/emotepopup.cpp @@ -197,12 +197,15 @@ void EmotePopup::recalculateSize() ++mRowCount; if (mRowCount) + { mColumnCount = emoteCount / mRowCount; + if (emoteCount % mRowCount > 0) + ++ mColumnCount; + } else + { mColumnCount = 1; - - if (emoteCount % mRowCount > 0) - ++mColumnCount; + } setContentSize(mColumnCount * gridWidth, mRowCount * gridHeight); } diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index 1d8b45872..f8d68a672 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -42,6 +42,8 @@ #include "resources/imageloader.h" #include "resources/resourcemanager.h" +#include "utils/langs.h" + #include <guichan/exception.hpp> #include <guichan/image.hpp> diff --git a/src/gui/helpwindow.cpp b/src/gui/helpwindow.cpp index a099c7a7a..5876667da 100644 --- a/src/gui/helpwindow.cpp +++ b/src/gui/helpwindow.cpp @@ -36,6 +36,7 @@ #include "configuration.h" #include "utils/gettext.h" +#include "utils/langs.h" #include "debug.h" diff --git a/src/gui/inventorywindow.cpp b/src/gui/inventorywindow.cpp index 23f1e6fcf..8c59d10eb 100644 --- a/src/gui/inventorywindow.cpp +++ b/src/gui/inventorywindow.cpp @@ -113,7 +113,7 @@ InventoryWindow::InventoryWindow(Inventory *inventory): setWindowName("Inventory"); } - listen(Mana::CHANNEL_ATTRIBUTES); + listen(CHANNEL_ATTRIBUTES); if (setupWindow) setupWindow->registerWindowForReset(this); @@ -585,10 +585,10 @@ void InventoryWindow::close() } } -void InventoryWindow::processEvent(Mana::Channels channel A_UNUSED, - const Mana::Event &event) +void InventoryWindow::processEvent(Channels channel A_UNUSED, + const Event &event) { - if (event.getName() == Mana::EVENT_UPDATEATTRIBUTE) + if (event.getName() == EVENT_UPDATEATTRIBUTE) { int id = event.getInt("id"); if (id == TOTAL_WEIGHT || id == MAX_WEIGHT) diff --git a/src/gui/inventorywindow.h b/src/gui/inventorywindow.h index 9d4be5afc..08456ba29 100644 --- a/src/gui/inventorywindow.h +++ b/src/gui/inventorywindow.h @@ -54,7 +54,7 @@ class InventoryWindow : public Window, public gcn::KeyListener, public gcn::SelectionListener, public InventoryListener, - public Mana::Listener + public Listener { public: /** @@ -126,7 +126,7 @@ class InventoryWindow : public Window, void updateDropButton(); - void processEvent(Mana::Channels channel, const Mana::Event &event); + void processEvent(Channels channel, const Event &event); void updateButtons(Item *item = nullptr); diff --git a/src/gui/itempopup.cpp b/src/gui/itempopup.cpp index 9a9e5f50d..d96aa564f 100644 --- a/src/gui/itempopup.cpp +++ b/src/gui/itempopup.cpp @@ -282,4 +282,4 @@ void ItemPopup::mouseMoved(gcn::MouseEvent &event) setVisible(false); mLastName = ""; mLastColor = 1; -}
\ No newline at end of file +} diff --git a/src/gui/killstats.cpp b/src/gui/killstats.cpp index 972c660ec..357a016f2 100644 --- a/src/gui/killstats.cpp +++ b/src/gui/killstats.cpp @@ -60,7 +60,7 @@ KillStats::KillStats(): setStickyButtonLock(true); setDefaultSize(250, 250, 350, 300); - listen(Mana::CHANNEL_ATTRIBUTES); + listen(CHANNEL_ATTRIBUTES); int xp(PlayerInfo::getAttribute(EXP)); int xpNextLevel(PlayerInfo::getAttribute(EXP_NEEDED)); @@ -438,10 +438,10 @@ void KillStats::validateJacko() } } -void KillStats::processEvent(Mana::Channels channel A_UNUSED, - const Mana::Event &event) +void KillStats::processEvent(Channels channel A_UNUSED, + const Event &event) { - if (event.getName() == Mana::EVENT_UPDATEATTRIBUTE) + if (event.getName() == EVENT_UPDATEATTRIBUTE) { int id = event.getInt("id"); if (id == EXP || id == EXP_NEEDED) diff --git a/src/gui/killstats.h b/src/gui/killstats.h index 8562e67a4..9773190de 100644 --- a/src/gui/killstats.h +++ b/src/gui/killstats.h @@ -33,7 +33,7 @@ class Label; class Button; -class KillStats : public Window, gcn::ActionListener, public Mana::Listener +class KillStats : public Window, gcn::ActionListener, public Listener { public: /** @@ -78,8 +78,8 @@ class KillStats : public Window, gcn::ActionListener, public Mana::Listener void addLog(std::string str); - void processEvent(Mana::Channels channel A_UNUSED, - const Mana::Event &event); + void processEvent(Channels channel A_UNUSED, + const Event &event); private: void validateJacko(); diff --git a/src/gui/logindialog.cpp b/src/gui/logindialog.cpp index ef8fd6bf0..cafc4f72c 100644 --- a/src/gui/logindialog.cpp +++ b/src/gui/logindialog.cpp @@ -41,6 +41,7 @@ #include "net/net.h" #include "utils/gettext.h" +#include "utils/paths.h" #include "utils/stringutils.h" #include "debug.h" diff --git a/src/gui/ministatuswindow.cpp b/src/gui/ministatuswindow.cpp index 00df97813..aaccd36c8 100644 --- a/src/gui/ministatuswindow.cpp +++ b/src/gui/ministatuswindow.cpp @@ -54,7 +54,7 @@ extern volatile int tick_time; MiniStatusWindow::MiniStatusWindow(): Popup("MiniStatus", "ministatus.xml") { - listen(Mana::CHANNEL_ATTRIBUTES); + listen(CHANNEL_ATTRIBUTES); mHpBar = createBar(0, 100, 20, Theme::PROG_HP, "hp bar", _("health bar")); StatusWindow::updateHPBar(mHpBar); @@ -218,10 +218,10 @@ void MiniStatusWindow::drawIcons(Graphics *graphics) } } -void MiniStatusWindow::processEvent(Mana::Channels channel A_UNUSED, - const Mana::Event &event) +void MiniStatusWindow::processEvent(Channels channel A_UNUSED, + const Event &event) { - if (event.getName() == Mana::EVENT_UPDATEATTRIBUTE) + if (event.getName() == EVENT_UPDATEATTRIBUTE) { int id = event.getInt("id"); if (id == HP || id == MAX_HP) @@ -235,7 +235,7 @@ void MiniStatusWindow::processEvent(Mana::Channels channel A_UNUSED, else if (id == MONEY) StatusWindow::updateMoneyBar(mMoneyBar); } - else if (event.getName() == Mana::EVENT_UPDATESTAT) + else if (event.getName() == EVENT_UPDATESTAT) { StatusWindow::updateMPBar(mMpBar); StatusWindow::updateJobBar(mJobBar); diff --git a/src/gui/ministatuswindow.h b/src/gui/ministatuswindow.h index ca18e1b92..eb6ded7dd 100644 --- a/src/gui/ministatuswindow.h +++ b/src/gui/ministatuswindow.h @@ -27,7 +27,6 @@ #include "listener.h" #include "gui/widgets/popup.h" -#include "gui/widgets/window.h" #include <vector> @@ -44,7 +43,7 @@ class TextPopup; */ class MiniStatusWindow : public Popup, public InventoryListener, - public Mana::Listener + public Listener { public: MiniStatusWindow(); @@ -60,7 +59,7 @@ class MiniStatusWindow : public Popup, void drawIcons(Graphics *graphics); - void processEvent(Mana::Channels channel, const Mana::Event &event); + void processEvent(Channels channel, const Event &event); void updateStatus(); diff --git a/src/gui/npcpostdialog.cpp b/src/gui/npcpostdialog.cpp index 6bcb62baf..b2ffb312c 100644 --- a/src/gui/npcpostdialog.cpp +++ b/src/gui/npcpostdialog.cpp @@ -128,4 +128,4 @@ void NpcPostDialog::closeAll() for (; it != it_end; ++it) (*it)->close(); -}
\ No newline at end of file +} diff --git a/src/gui/palette.cpp b/src/gui/palette.cpp index fe14cd2d4..3b36fa6ce 100644 --- a/src/gui/palette.cpp +++ b/src/gui/palette.cpp @@ -39,7 +39,8 @@ const gcn::Color Palette::BLACK = gcn::Color(0, 0, 0); Palette::Palettes Palette::mInstances; -const gcn::Color Palette::RAINBOW_COLORS[7] = { +const gcn::Color Palette::RAINBOW_COLORS[7] = +{ gcn::Color(255, 0, 0), gcn::Color(255, 153, 0), gcn::Color(255, 255, 0), @@ -48,6 +49,7 @@ const gcn::Color Palette::RAINBOW_COLORS[7] = { gcn::Color(51, 0, 153), gcn::Color(153, 0, 153) }; + /** Number of Elemets of RAINBOW_COLORS */ const int Palette::RAINBOW_COLOR_COUNT = 7; diff --git a/src/gui/popupmenu.cpp b/src/gui/popupmenu.cpp index 142acc69c..c987843d3 100644 --- a/src/gui/popupmenu.cpp +++ b/src/gui/popupmenu.cpp @@ -35,6 +35,7 @@ #include "localplayer.h" #include "logger.h" #include "map.h" +#include "maplayer.h" #include "party.h" #include "playerinfo.h" #include "playerrelations.h" diff --git a/src/gui/sdlfont.cpp b/src/gui/sdlfont.cpp index 0e69db026..7e0114cb8 100644 --- a/src/gui/sdlfont.cpp +++ b/src/gui/sdlfont.cpp @@ -27,6 +27,7 @@ #include "graphics.h" #include "logger.h" #include "main.h" +#include "utils/paths.h" #include "resources/image.h" #include "resources/resourcemanager.h" @@ -98,7 +99,7 @@ typedef std::list<SDLTextChunk>::iterator CacheIterator; static int fontCounter; -SDLFont::SDLFont(const std::string &filename, int size, int style) : +SDLFont::SDLFont(std::string filename, int size, int style) : mCreateCounter(0), mDeleteCounter(0) { @@ -117,13 +118,16 @@ SDLFont::SDLFont(const std::string &filename, int size, int style) : } ++fontCounter; + + fixDirSeparators(filename); mFont = TTF_OpenFont(resman->getPath(filename).c_str(), size); if (!mFont) { logger->log("Error finding font " + filename); + std::string backFile = "fonts/dejavusans.ttf"; mFont = TTF_OpenFont(resman->getPath( - "fonts/dejavusans.ttf").c_str(), size); + fixDirSeparators(backFile)).c_str(), size); if (!mFont) { throw GCN_EXCEPTION("SDLSDLFont::SDLSDLFont: " + @@ -148,7 +152,7 @@ SDLFont::~SDLFont() } } -void SDLFont::loadFont(const std::string &filename, int size, int style) +void SDLFont::loadFont(std::string filename, int size, int style) { ResourceManager *resman = ResourceManager::getInstance(); @@ -159,6 +163,7 @@ void SDLFont::loadFont(const std::string &filename, int size, int style) return; } + fixDirSeparators(filename); TTF_Font *font = TTF_OpenFont(resman->getPath(filename).c_str(), size); if (!font) diff --git a/src/gui/sdlfont.h b/src/gui/sdlfont.h index 6fcad34d4..77e3761e7 100644 --- a/src/gui/sdlfont.h +++ b/src/gui/sdlfont.h @@ -53,14 +53,14 @@ class SDLFont : public gcn::Font * @param filename Font filename. * @param size Font size. */ - SDLFont(const std::string &filename, int size, int style = 0); + SDLFont(std::string filename, int size, int style = 0); /** * Destructor. */ ~SDLFont(); - void loadFont(const std::string &filename, int size, int style = 0); + void loadFont(std::string filename, int size, int style = 0); void createSDLTextChunk(SDLTextChunk *chunk); diff --git a/src/gui/serverdialog.cpp b/src/gui/serverdialog.cpp index 59bdf9660..da61e105b 100644 --- a/src/gui/serverdialog.cpp +++ b/src/gui/serverdialog.cpp @@ -46,9 +46,9 @@ #include "net/net.h" #include "utils/gettext.h" +#include "utils/langs.h" #include "utils/stringutils.h" #include "utils/xml.h" -#include "widgets/dropdown.h" #include <guichan/font.hpp> @@ -283,14 +283,10 @@ ServerDialog::ServerDialog(ServerInfo *serverInfo, const std::string &dir): // Do this manually instead of calling reflowLayout so we can enforce a // minimum width. - int width = 0, height = 0; - getLayout().reflow(width, height); - if (width < 400) - { - width = 400; - getLayout().reflow(width, height); - } + int width = 500; + int height = 350; + getLayout().reflow(width, height); setContentSize(width, height); setMinWidth(getWidth()); @@ -309,7 +305,7 @@ ServerDialog::ServerDialog(ServerInfo *serverInfo, const std::string &dir): loadServers(true); - if (mServers.empty()) + if (needUpdateServers()) downloadServerList(); } @@ -488,13 +484,17 @@ void ServerDialog::downloadServerList() } mDownload = new Net::Download(this, listFile, &downloadUpdate); - mDownload->setFile(mDir + "/serverlist.xml"); + mDownload->setFile(mDir + "/" + branding.getStringValue( + "onlineServerFile")); mDownload->start(); + + config.setValue("serverslistupdate", getDateString()); } void ServerDialog::loadServers(bool addNew) { - XML::Document doc(mDir + "/serverlist.xml", false); + XML::Document doc(mDir + "/" + branding.getStringValue( + "onlineServerFile"), false); XmlNodePtr rootNode = doc.rootNode(); if (!rootNode || !xmlNameEqual(rootNode, "serverlist")) @@ -744,3 +744,14 @@ void ServerDialog::updateServer(ServerInfo server, int index) { saveCustomServers(server, index); } + +bool ServerDialog::needUpdateServers() +{ + if (mServers.empty() || config.getStringValue("serverslistupdate") + != getDateString()) + { + return true; + } + + return false; +} diff --git a/src/gui/serverdialog.h b/src/gui/serverdialog.h index c23fb8776..61620364c 100644 --- a/src/gui/serverdialog.h +++ b/src/gui/serverdialog.h @@ -138,12 +138,16 @@ class ServerDialog : public Window, * Called to load a list of available server from an online xml file. */ void downloadServerList(); + void loadServers(bool addNew = true); void loadCustomServers(); + void saveCustomServers(const ServerInfo ¤tServer = ServerInfo(), int index = -1); + bool needUpdateServers(); + static int downloadUpdate(void *ptr, DownloadStatus status, size_t total, size_t remaining); diff --git a/src/gui/setup_players.cpp b/src/gui/setup_players.cpp index f0bf4c0ea..a08517fae 100644 --- a/src/gui/setup_players.cpp +++ b/src/gui/setup_players.cpp @@ -84,6 +84,9 @@ Setup_Players::Setup_Players() new SetupItemCheckBox(_("Allow self heal with mouse click"), "", "selfMouseHeal", this, "selfMouseHealEvent"); + new SetupItemCheckBox(_("Group friends in who is online window"), "", + "groupFriends", this, "groupFriendsEvent"); + setDimension(gcn::Rectangle(0, 0, 550, 350)); } diff --git a/src/gui/setup_relations.cpp b/src/gui/setup_relations.cpp index 571856a14..47d53620c 100644 --- a/src/gui/setup_relations.cpp +++ b/src/gui/setup_relations.cpp @@ -50,7 +50,8 @@ #define RELATION_CHOICE_COLUMN 1 #define ROW_HEIGHT 12 -// The following column widths really shouldn't be hardcoded but should scale with the size of the widget... except +// The following column widths really shouldn't be hardcoded +// but should scale with the size of the widget... except // that, right now, the widget doesn't exactly scale either. #define NAME_COLUMN_WIDTH 230 #define RELATION_CHOICE_COLUMN_WIDTH 80 diff --git a/src/gui/setup_video.cpp b/src/gui/setup_video.cpp index 9a5b30ea7..cc3063a68 100644 --- a/src/gui/setup_video.cpp +++ b/src/gui/setup_video.cpp @@ -228,7 +228,6 @@ static const char *speechModeToString(Being::Speech mode) case Being::NAME_IN_BUBBLE: return _("Bubbles with names"); } - return ""; } const char *Setup_Video::overlayDetailToString(int detail) @@ -743,4 +742,4 @@ void Setup_Video::action(const gcn::ActionEvent &event) void Setup_Video::externalUpdated() { -}
\ No newline at end of file +} diff --git a/src/gui/skilldialog.cpp b/src/gui/skilldialog.cpp index 4ee674325..430705b1d 100644 --- a/src/gui/skilldialog.cpp +++ b/src/gui/skilldialog.cpp @@ -382,8 +382,8 @@ void SkillDialog::loadSkills(const std::string &file) SkillInfo *skill = new SkillInfo; skill->id = 1; - skill->name = "basic"; - skill->dispName = "Skill: basic, Id: 1"; + skill->name = _("basic"); + skill->dispName = _("Skill: basic, Id: 1"); skill->setIcon(""); skill->modifiable = true; skill->visible = true; @@ -428,14 +428,14 @@ void SkillDialog::loadSkills(const std::string &file) if (xmlNameEqual(node, "skill")) { int id = atoi(XML::getProperty(node, "id", "-1").c_str()); - std::string name = XML::getProperty(node, "name", + std::string name = XML::langProperty(node, "name", strprintf(_("Skill %d"), id)); std::string icon = XML::getProperty(node, "icon", ""); SkillInfo *skill = new SkillInfo; skill->id = static_cast<short unsigned>(id); skill->name = name; - skill->dispName = strprintf("Skill: %s, Id: %d", + skill->dispName = strprintf(_("Skill: %s, Id: %d"), name.c_str(), skill->id); skill->setIcon(icon); skill->modifiable = false; diff --git a/src/gui/socialwindow.cpp b/src/gui/socialwindow.cpp index 59ace1685..287089790 100644 --- a/src/gui/socialwindow.cpp +++ b/src/gui/socialwindow.cpp @@ -28,6 +28,7 @@ #include "localplayer.h" #include "logger.h" #include "map.h" +#include "maplayer.h" #include "party.h" #include "playerrelations.h" #include "gui/whoisonline.h" diff --git a/src/gui/spellpopup.cpp b/src/gui/spellpopup.cpp index 66d69b197..48037f03e 100644 --- a/src/gui/spellpopup.cpp +++ b/src/gui/spellpopup.cpp @@ -114,8 +114,6 @@ void SpellPopup::view(int x, int y) { if (y > getHeight() + distance) posY = y - getHeight() - distance; - else - y = 0; } setPosition(posX, posY); diff --git a/src/gui/statuswindow.cpp b/src/gui/statuswindow.cpp index 86964383a..1964b974d 100644 --- a/src/gui/statuswindow.cpp +++ b/src/gui/statuswindow.cpp @@ -126,7 +126,7 @@ StatusWindow::StatusWindow(): Window(player_node ? player_node->getName() : "?", false, nullptr, "status.xml") { - listen(Mana::CHANNEL_ATTRIBUTES); + listen(CHANNEL_ATTRIBUTES); setWindowName("Status"); setupWindow->registerWindowForReset(this); @@ -135,7 +135,13 @@ StatusWindow::StatusWindow(): setSaveVisible(true); setStickyButtonLock(true); setDefaultSize((windowContainer->getWidth() - 480) / 2, - (windowContainer->getHeight() - 500) / 2, 480, 500); + (windowContainer->getHeight() - 500) / 2, 480, 500); + + if (player_node && !player_node->getRaceName().empty()) + { + setCaption(strprintf("%s (%s)", player_node->getName().c_str(), + player_node->getRaceName().c_str())); + } // ---------------------- // Status Part @@ -277,16 +283,16 @@ StatusWindow::StatusWindow(): mLvlLabel->adjustSize(); } -void StatusWindow::processEvent(Mana::Channels channel A_UNUSED, - const Mana::Event &event) +void StatusWindow::processEvent(Channels channel A_UNUSED, + const Event &event) { static bool blocked = false; if (blocked) return; - if (event.getName() == Mana::EVENT_UPDATEATTRIBUTE) + if (event.getName() == EVENT_UPDATEATTRIBUTE) { - switch(event.getInt("id")) + switch (event.getInt("id")) { case HP: case MAX_HP: updateHPBar(mHpBar, true); @@ -343,7 +349,7 @@ void StatusWindow::processEvent(Mana::Channels channel A_UNUSED, break; } } - else if (event.getName() == Mana::EVENT_UPDATESTAT) + else if (event.getName() == EVENT_UPDATESTAT) { int id = event.getInt("id"); if (id == Net::getPlayerHandler()->getJobLocation()) diff --git a/src/gui/statuswindow.h b/src/gui/statuswindow.h index 8e110a354..7f6bd2d18 100644 --- a/src/gui/statuswindow.h +++ b/src/gui/statuswindow.h @@ -44,7 +44,7 @@ class VertContainer; */ class StatusWindow : public Window, public gcn::ActionListener, - public Mana::Listener + public Listener { public: /** @@ -52,7 +52,7 @@ class StatusWindow : public Window, */ StatusWindow(); - void processEvent(Mana::Channels channel, const Mana::Event &event); + void processEvent(Channels channel, const Event &event); void setPointsNeeded(int id, int needed); diff --git a/src/gui/textdialog.cpp b/src/gui/textdialog.cpp index b30c9eb82..d7d3d5eeb 100644 --- a/src/gui/textdialog.cpp +++ b/src/gui/textdialog.cpp @@ -126,4 +126,4 @@ void TextDialog::close() { keyboard.setEnabled(mEnabledKeyboard); scheduleDelete(); -}
\ No newline at end of file +} diff --git a/src/gui/updaterwindow.cpp b/src/gui/updaterwindow.cpp index 28bd8467c..3aaf93557 100644 --- a/src/gui/updaterwindow.cpp +++ b/src/gui/updaterwindow.cpp @@ -42,6 +42,7 @@ #include "resources/resourcemanager.h" #include "utils/gettext.h" +#include "utils/paths.h" #include "utils/stringutils.h" #include "utils/xml.h" diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp index 7ff2c8850..d4c188bfb 100644 --- a/src/gui/viewport.cpp +++ b/src/gui/viewport.cpp @@ -31,6 +31,7 @@ #include "keyboardconfig.h" #include "localplayer.h" #include "map.h" +#include "maplayer.h" #include "textmanager.h" #include "gui/beingpopup.h" @@ -878,7 +879,7 @@ bool Viewport::isPopupMenuVisible() void Viewport::moveCameraToActor(int actorId, int x, int y) { - if (!player_node) + if (!player_node || !actorSpriteManager) return; Actor *actor = actorSpriteManager->findBeing(actorId); diff --git a/src/gui/viewport.h b/src/gui/viewport.h index f3035b5df..ccb8124ba 100644 --- a/src/gui/viewport.h +++ b/src/gui/viewport.h @@ -90,7 +90,9 @@ class Viewport : public WindowContainer, public gcn::MouseListener, void logic(); /** - * Toggles whether the path debug graphics are shown. normal, debug with all images and grid, debug with out big images and with out grid. + * Toggles whether the path debug graphics are shown. normal, + * debug with all images and grid, debug with out big images + * and with out grid. */ void toggleDebugPath(); diff --git a/src/gui/whoisonline.cpp b/src/gui/whoisonline.cpp index 205a1aae1..7e4f02426 100644 --- a/src/gui/whoisonline.cpp +++ b/src/gui/whoisonline.cpp @@ -85,7 +85,8 @@ WhoIsOnline::WhoIsOnline(): mMemoryBuffer(nullptr), mCurlError(new char[CURL_ERROR_SIZE]), mAllowUpdate(true), - mShowLevel(false) + mShowLevel(false), + mGroupFriends(true) { mCurlError[0] = 0; setWindowName("WhoIsOnline"); @@ -124,12 +125,15 @@ WhoIsOnline::WhoIsOnline(): download(); config.addListener("updateOnlineList", this); + config.addListener("groupFriends", this); mUpdateOnlineList = config.getBoolValue("updateOnlineList"); + mGroupFriends = config.getBoolValue("groupFriends"); } WhoIsOnline::~WhoIsOnline() { config.removeListener("updateOnlineList", this); + config.removeListener("groupFriends", this); if (mThread && SDL_GetThreadID(mThread)) SDL_WaitThread(mThread, nullptr); @@ -138,7 +142,7 @@ WhoIsOnline::~WhoIsOnline() mMemoryBuffer = nullptr; // Remove possibly leftover temporary download - delete[] mCurlError; + delete []mCurlError; std::set<OnlinePlayer*>::iterator itd = mOnlinePlayers.begin(); std::set<OnlinePlayer*>::iterator itd_end = mOnlinePlayers.end(); @@ -226,7 +230,7 @@ void WhoIsOnline::updateWindow(std::vector<OnlinePlayer*> &friends, if (addedFromSection == true && !disregard.empty()) { mBrowserBox->addRow("---"); - addedFromSection = false; +// addedFromSection = false; } for (int i = 0; i < static_cast<int>(disregard.size()); i++) { @@ -282,7 +286,10 @@ void WhoIsOnline::loadList(std::vector<OnlinePlayer*> &list) case PlayerRelation::FRIEND: player->setText("2"); - friends.push_back(player); + if (mGroupFriends) + friends.push_back(player); + else + neutral.push_back(player); break; case PlayerRelation::DISREGARDED: @@ -425,7 +432,10 @@ void WhoIsOnline::loadWebList() case PlayerRelation::FRIEND: player->setText("2"); - friends.push_back(player); + if (mGroupFriends) + friends.push_back(player); + else + neutral.push_back(player); break; case PlayerRelation::DISREGARDED: @@ -716,12 +726,13 @@ void WhoIsOnline::optionChanged(const std::string &name) { if (name == "updateOnlineList") mUpdateOnlineList = config.getBoolValue("updateOnlineList"); + else if (name == "groupFriends") + mGroupFriends = config.getBoolValue("groupFriends"); } void OnlinePlayer::setText(std::string color) { - mText = strprintf("@@%s|##%s%s ", mNick.c_str(), - color.c_str(), mNick.c_str()); + mText = ""; if (mStatus != 255 && actorSpriteManager) { @@ -753,10 +764,13 @@ void OnlinePlayer::setText(std::string color) // TRANSLATORS: this inactive status writed in player nick mText += _("I"); } + if (mStatus & Being::FLAG_GM && color == "0") + color = "2"; } if (mVersion > 0) mText += strprintf(" - %d", mVersion); - mText += strprintf("@@"); + mText = strprintf("@@%s|##%s%s %s@@", mNick.c_str(), + color.c_str(), mNick.c_str(), mText.c_str()); } diff --git a/src/gui/whoisonline.h b/src/gui/whoisonline.h index dad51e857..1607286a9 100644 --- a/src/gui/whoisonline.h +++ b/src/gui/whoisonline.h @@ -201,6 +201,7 @@ private: bool mAllowUpdate; bool mShowLevel; bool mUpdateOnlineList; + bool mGroupFriends; }; extern WhoIsOnline *whoIsOnline; diff --git a/src/gui/widgets/avatarlistbox.cpp b/src/gui/widgets/avatarlistbox.cpp index 1bf897301..822e71805 100644 --- a/src/gui/widgets/avatarlistbox.cpp +++ b/src/gui/widgets/avatarlistbox.cpp @@ -26,6 +26,7 @@ #include "graphics.h" #include "guild.h" #include "localplayer.h" +#include "maplayer.h" #include "gui/chatwindow.h" #include "gui/gui.h" @@ -402,4 +403,4 @@ void AvatarListBox::optionChanged(const std::string &value) mShowGender = config.getBoolValue("showgender"); else if (value == "showlevel") mShowLevel = config.getBoolValue("showlevel"); -}
\ No newline at end of file +} diff --git a/src/gui/widgets/battletab.h b/src/gui/widgets/battletab.h index 8d85e739e..2a034a166 100644 --- a/src/gui/widgets/battletab.h +++ b/src/gui/widgets/battletab.h @@ -43,6 +43,3 @@ class BattleTab : public ChatTab extern BattleTab *battleChatTab; #endif - - - diff --git a/src/gui/widgets/chattab.cpp b/src/gui/widgets/chattab.cpp index 6d5dfc9dd..018e35030 100644 --- a/src/gui/widgets/chattab.cpp +++ b/src/gui/widgets/chattab.cpp @@ -467,4 +467,4 @@ void ChatTab::addNewRow(std::string &line) addRow(line); } mScrollArea->logic(); -}
\ No newline at end of file +} diff --git a/src/gui/widgets/container.cpp b/src/gui/widgets/container.cpp index 80028a62f..106112956 100644 --- a/src/gui/widgets/container.cpp +++ b/src/gui/widgets/container.cpp @@ -47,4 +47,4 @@ bool Container::safeRemove(gcn::Widget* widget) } } return false; -}
\ No newline at end of file +} diff --git a/src/gui/widgets/dropdown.h b/src/gui/widgets/dropdown.h index a769678ca..5896042fa 100644 --- a/src/gui/widgets/dropdown.h +++ b/src/gui/widgets/dropdown.h @@ -102,4 +102,3 @@ class DropDown : public gcn::DropDown }; #endif // end DROPDOWN_H - diff --git a/src/gui/widgets/inventoryfilter.cpp b/src/gui/widgets/inventoryfilter.cpp index 216c2bea0..515682cb6 100644 --- a/src/gui/widgets/inventoryfilter.cpp +++ b/src/gui/widgets/inventoryfilter.cpp @@ -58,4 +58,4 @@ void InventoryFilter::action(const gcn::ActionEvent &event) { (*iter)->action(event); } -}
\ No newline at end of file +} diff --git a/src/gui/widgets/layout.h b/src/gui/widgets/layout.h index 046d09b59..3c42554b6 100644 --- a/src/gui/widgets/layout.h +++ b/src/gui/widgets/layout.h @@ -37,8 +37,8 @@ class LayoutCell; class ContainerPlacer { public: - ContainerPlacer(gcn::Container *c = nullptr, LayoutCell *l = nullptr): - mContainer(c), mCell(l) + ContainerPlacer(gcn::Container *c = nullptr, LayoutCell *lc = nullptr): + mContainer(c), mCell(lc) {} /** diff --git a/src/gui/widgets/setupitem.cpp b/src/gui/widgets/setupitem.cpp index 059b05ba2..56ce0a25a 100644 --- a/src/gui/widgets/setupitem.cpp +++ b/src/gui/widgets/setupitem.cpp @@ -455,7 +455,6 @@ void SetupItemIntTextField::apply(std::string eventName) } - SetupItemLabel::SetupItemLabel(std::string text, std::string description, SetupTabScroll *parent, bool separator) : SetupItem(text, description, "", parent, "", "", true), diff --git a/src/gui/widgets/setuptab.cpp b/src/gui/widgets/setuptab.cpp index b3863c134..d4ae46eb8 100644 --- a/src/gui/widgets/setuptab.cpp +++ b/src/gui/widgets/setuptab.cpp @@ -31,4 +31,4 @@ SetupTab::SetupTab() void SetupTab::externalUpdated() { -}
\ No newline at end of file +} diff --git a/src/gui/widgets/shoplistbox.cpp b/src/gui/widgets/shoplistbox.cpp index 71e373d70..ab6400149 100644 --- a/src/gui/widgets/shoplistbox.cpp +++ b/src/gui/widgets/shoplistbox.cpp @@ -191,4 +191,4 @@ void ShopListBox::mouseExited(gcn::MouseEvent& mouseEvent A_UNUSED) return; mItemPopup->hide(); -}
\ No newline at end of file +} diff --git a/src/gui/widgets/slider.cpp b/src/gui/widgets/slider.cpp index ed667e194..c6b57858c 100644 --- a/src/gui/widgets/slider.cpp +++ b/src/gui/widgets/slider.cpp @@ -298,4 +298,3 @@ void Slider::mouseExited(gcn::MouseEvent& event A_UNUSED) { mHasMouse = false; } - diff --git a/src/gui/widgets/tablemodel.cpp b/src/gui/widgets/tablemodel.cpp index 5216fb89c..bc5d2ead6 100644 --- a/src/gui/widgets/tablemodel.cpp +++ b/src/gui/widgets/tablemodel.cpp @@ -173,4 +173,3 @@ int StaticTableModel::getHeight() const { return mColumns * mHeight; } - diff --git a/src/gui/widgets/textbox.cpp b/src/gui/widgets/textbox.cpp index a4bc3bc09..575036612 100644 --- a/src/gui/widgets/textbox.cpp +++ b/src/gui/widgets/textbox.cpp @@ -116,14 +116,14 @@ void TextBox::setTextWrapped(const std::string &text, int minDimension) mMinWidth = minWidth; wrappedStream.clear(); wrappedStream.str(""); - spacePos = 0; +// spacePos = 0; lastNewlinePos = 0; newlinePos = text.find("\n", lastNewlinePos); if (newlinePos == std::string::npos) newlinePos = text.size(); line = text.substr(lastNewlinePos, newlinePos - lastNewlinePos); - width = 0; +// width = 0; break; } else diff --git a/src/gui/widgets/textfield.cpp b/src/gui/widgets/textfield.cpp index 4dba2eb57..e207b0613 100644 --- a/src/gui/widgets/textfield.cpp +++ b/src/gui/widgets/textfield.cpp @@ -208,29 +208,29 @@ void TextField::keyPressed(gcn::KeyEvent &keyEvent) } else if (!mMaximum || mText.size() < mMaximum) { - int l; + int len; if (val < 128) - l = 1; // 0xxxxxxx + len = 1; // 0xxxxxxx else if (val < 0x800) - l = 2; // 110xxxxx 10xxxxxx + len = 2; // 110xxxxx 10xxxxxx else if (val < 0x10000) - l = 3; // 1110xxxx 10xxxxxx 10xxxxxx + len = 3; // 1110xxxx 10xxxxxx 10xxxxxx else - l = 4; // 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx + len = 4; // 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx char buf[4]; - for (int i = 0; i < l; ++i) + for (int i = 0; i < len; ++ i) { - buf[i] = static_cast<char>(val >> (6 * (l - i - 1))); + buf[i] = static_cast<char>(val >> (6 * (len - i - 1))); if (i > 0) buf[i] = static_cast<char>((buf[i] & 63) | 128); } - if (l > 1) - buf[0] |= static_cast<char>(255 << (8 - l)); + if (len > 1) + buf[0] |= static_cast<char>(255 << (8 - len)); - mText.insert(mCaretPosition, std::string(buf, buf + l)); - mCaretPosition += l; + mText.insert(mCaretPosition, std::string(buf, buf + len)); + mCaretPosition += len; } } diff --git a/src/gui/widgets/tradetab.h b/src/gui/widgets/tradetab.h index 06add3ee0..44922c31a 100644 --- a/src/gui/widgets/tradetab.h +++ b/src/gui/widgets/tradetab.h @@ -46,6 +46,3 @@ class TradeTab : public ChatTab extern TradeTab *tradeChatTab; #endif - - - diff --git a/src/guichanfwd.h b/src/guichanfwd.h index b3808d8ba..7ccc221b4 100644 --- a/src/guichanfwd.h +++ b/src/guichanfwd.h @@ -27,11 +27,6 @@ namespace gcn { class ActionEvent; class ActionListener; - class AllegroFont; - class AllegroGraphics; - class AllegroImage; - class AllegroImageLoader; - class AllegroInput; class BasicContainer; class Button; class CheckBox; @@ -70,7 +65,6 @@ namespace gcn class MouseEvent; class MouseInput; class MouseListener; - class OpenGLAllegroImageLoader; class OpenGLGraphics; class OpenGLImage; class OpenGLSDLImageLoader; diff --git a/src/itemshortcut.cpp b/src/itemshortcut.cpp index f267dd755..fedb92257 100644 --- a/src/itemshortcut.cpp +++ b/src/itemshortcut.cpp @@ -24,7 +24,6 @@ #include "inventory.h" #include "item.h" #include "itemshortcut.h" -#include "localplayer.h" #include "playerinfo.h" #include "spellmanager.h" diff --git a/src/listener.cpp b/src/listener.cpp index ea125013f..fd04c9f00 100644 --- a/src/listener.cpp +++ b/src/listener.cpp @@ -25,9 +25,6 @@ #include "debug.h" -namespace Mana -{ - Listener::~Listener() { Event::remove(this); @@ -42,5 +39,3 @@ void Listener::ignore(Channels channel) { Event::unbind(this, channel); } - -} // namespace Mana diff --git a/src/listener.h b/src/listener.h index dc968672a..bb6e3d4b4 100644 --- a/src/listener.h +++ b/src/listener.h @@ -26,9 +26,6 @@ #include <string> -namespace Mana -{ - class Listener { public: @@ -41,6 +38,4 @@ class Listener virtual void processEvent(Channels channel, const Event &event) = 0; }; -} // namespace Mana - #endif diff --git a/src/localconsts.h b/src/localconsts.h index 2d0eb5dea..de67c3850 100644 --- a/src/localconsts.h +++ b/src/localconsts.h @@ -30,4 +30,4 @@ #define A_UNUSED __attribute__ ((unused)) #else #define A_UNUSED -#endif
\ No newline at end of file +#endif diff --git a/src/localplayer.cpp b/src/localplayer.cpp index 27897a486..4675f80cf 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -33,6 +33,7 @@ #include "keyboardconfig.h" #include "logger.h" #include "map.h" +#include "maplayer.h" #include "party.h" #include "particle.h" #include "playerinfo.h" @@ -40,21 +41,16 @@ #include "simpleanimation.h" #include "sound.h" #include "statuseffect.h" -#include "text.h" #include "dropshortcut.h" #include "gui/chatwindow.h" #include "gui/gui.h" -#include "gui/inventorywindow.h" -#include "gui/killstats.h" #include "gui/ministatuswindow.h" #include "gui/okdialog.h" #include "gui/outfitwindow.h" -#include "gui/palette.h" #include "gui/shopwindow.h" #include "gui/skilldialog.h" #include "gui/socialwindow.h" -#include "gui/statuswindow.h" #include "gui/theme.h" #include "gui/userpalette.h" #include "gui/viewport.h" @@ -138,7 +134,7 @@ LocalPlayer::LocalPlayer(int id, int subtype): mAttackRange = 0; - listen(Mana::CHANNEL_ATTRIBUTES); + listen(CHANNEL_ATTRIBUTES); mLevel = 1; mAdvanced = true; @@ -1663,12 +1659,12 @@ void LocalPlayer::optionChanged(const std::string &value) mTargetOnlyReachable = config.getBoolValue("targetOnlyReachable"); } -void LocalPlayer::processEvent(Mana::Channels channel, - const Mana::Event &event) +void LocalPlayer::processEvent(Channels channel, + const Event &event) { - if (channel == Mana::CHANNEL_ATTRIBUTES) + if (channel == CHANNEL_ATTRIBUTES) { - if (event.getName() == Mana::EVENT_UPDATEATTRIBUTE) + if (event.getName() == EVENT_UPDATEATTRIBUTE) { switch (event.getInt("id")) { @@ -1691,7 +1687,7 @@ void LocalPlayer::processEvent(Mana::Channels channel, break; }; } - else if (event.getName() == Mana::EVENT_UPDATESTAT) + else if (event.getName() == EVENT_UPDATESTAT) { if (!mShowJobExp) return; @@ -1713,20 +1709,28 @@ void LocalPlayer::processEvent(Mana::Channels channel, if (!mMessages.empty()) { MessagePair pair = mMessages.back(); - if (pair.first.find(" xp") == pair.first.size() - 3) + // TRANSLATORS: this is normal experience + if (pair.first.find(strprintf(" %s", + _("xp"))) == pair.first.size() - 3) { mMessages.pop_back(); - pair.first += ", " + toString(change) + " job"; + // TRANSLATORS: this is job experience + pair.first += strprintf (", %d %s", + change, _("job")); mMessages.push_back(pair); } else { - addMessageToQueue(toString(change) + " job"); + // TRANSLATORS: this is job experience + addMessageToQueue(strprintf("%d %s", + change, _("job"))); } } else { - addMessageToQueue(toString(change) + " job"); + // TRANSLATORS: this is job experience + addMessageToQueue(strprintf( + "%d %s", change, _("job"))); } } } @@ -2035,7 +2039,7 @@ std::string LocalPlayer::getAttackTypeString() mAttackType, attackTypeSize)); } -const unsigned quickDropCounterSize = 10; +const unsigned quickDropCounterSize = 31; void LocalPlayer::changeQuickDropCounter() { @@ -2045,8 +2049,26 @@ void LocalPlayer::changeQuickDropCounter() std::string LocalPlayer::getQuickDropCounterString() { - return strprintf("(%d) drop counter %d", - mQuickDropCounter, mQuickDropCounter); + if (mQuickDropCounter > 9) + { + return strprintf("(%c) drop counter %d", + 'a' + mQuickDropCounter - 10, mQuickDropCounter); + } + else + { + return strprintf("(%d) drop counter %d", + mQuickDropCounter, mQuickDropCounter); + } +} + +void LocalPlayer::setQuickDropCounter(int n) +{ + if (n < 1 || n >= (signed)quickDropCounterSize) + return; + mQuickDropCounter = n; + config.setValue("quickDropCounter", mQuickDropCounter); + if (miniStatusWindow) + miniStatusWindow->updateStatus(); } const unsigned pickUpTypeSize = 7; @@ -2128,7 +2150,7 @@ void LocalPlayer::switchPvpAttack() static const char *pvpAttackStrings[] = { N_("(a) attack all players"), - N_("(f) attack not friends"), + N_("(f) attack all except friends"), N_("(b) attack bad relations"), N_("(d) dont attack players"), N_("(?) pvp attack") @@ -2329,7 +2351,7 @@ void LocalPlayer::crazyMove() { bool oldDisableCrazyMove = mDisableCrazyMove; mDisableCrazyMove = true; - switch(mCrazyMoveType) + switch (mCrazyMoveType) { case 1: crazyMove1(); @@ -2440,7 +2462,7 @@ void LocalPlayer::crazyMove3() if (mAction == MOVE) return; - switch(mCrazyMoveState) + switch (mCrazyMoveState) { case 0: move(1, 1); @@ -2474,7 +2496,7 @@ void LocalPlayer::crazyMove4() if (mAction == MOVE) return; - switch(mCrazyMoveState) + switch (mCrazyMoveState) { case 0: move(7, 0); @@ -2494,7 +2516,7 @@ void LocalPlayer::crazyMove5() if (mAction == MOVE) return; - switch(mCrazyMoveState) + switch (mCrazyMoveState) { case 0: move(0, 7); @@ -2514,7 +2536,7 @@ void LocalPlayer::crazyMove6() if (mAction == MOVE) return; - switch(mCrazyMoveState) + switch (mCrazyMoveState) { case 0: move(3, 0); @@ -2558,7 +2580,7 @@ void LocalPlayer::crazyMove7() if (mAction == MOVE) return; - switch(mCrazyMoveState) + switch (mCrazyMoveState) { case 0: move(1, 1); @@ -3036,7 +3058,7 @@ bool LocalPlayer::pickUpItems(int pickUpType) return status; int x1, y1, x2, y2; - switch(pickUpType) + switch (pickUpType) { case 1: switch (mDirection) @@ -3146,15 +3168,11 @@ void LocalPlayer::specialMove(unsigned char direction) && getInvertDirection() <= 4) && !mIsServerBuggy) { - int max; - if (getInvertDirection() == 2) - max = 10; - else - max = 30; - if (mAction == MOVE) return; + int max; + if (getInvertDirection() == 2) max = 5; else if (getInvertDirection() == 4) @@ -3197,7 +3215,7 @@ void LocalPlayer::magicAttack() if (!Client::limitPackets(PACKET_CHAT)) return; - switch(mMagicAttackType) + switch (mMagicAttackType) { //flar W00 case 0: diff --git a/src/localplayer.h b/src/localplayer.h index a7ce3dd7f..03b3a2538 100644 --- a/src/localplayer.h +++ b/src/localplayer.h @@ -69,7 +69,7 @@ enum * The local player character. */ class LocalPlayer : public Being, public ActorSpriteListener, - public Mana::Listener + public Listener { public: /** @@ -256,6 +256,8 @@ class LocalPlayer : public Being, public ActorSpriteListener, int getQuickDropCounter() const { return mQuickDropCounter; } + void setQuickDropCounter(int n); + void changeQuickDropCounter(); int getMoveState() const @@ -387,7 +389,7 @@ class LocalPlayer : public Being, public ActorSpriteListener, */ void optionChanged(const std::string &value); - void processEvent(Mana::Channels channel, const Mana::Event &event); + void processEvent(Channels channel, const Event &event); /** * set a following player. diff --git a/src/logger.cpp b/src/logger.cpp index a2df9a911..1541616f2 100644 --- a/src/logger.cpp +++ b/src/logger.cpp @@ -186,7 +186,7 @@ void Logger::log(const char *log_text, ...) debugChatTab->chatLog(buf, BY_LOGGER); // Delete temporary buffer - delete[] buf; + delete [] buf; } void Logger::error(const std::string &error_text) diff --git a/src/main.cpp b/src/main.cpp index 5025d6d29..f30e7bc62 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -31,9 +31,14 @@ #include <iostream> #include <physfs.h> +#include "utils/paths.h" #include "utils/stringutils.h" #include "utils/xml.h" +#ifdef UNITTESTS +#include <gtest/gtest.h> +#endif + #ifdef __MINGW32__ #include <windows.h> #endif @@ -209,6 +214,8 @@ static void parseOptions(int argc, char *argv[], Client::Options &options) extern "C" char const *_nl_locale_name_default(void); #endif +#ifndef UNITTESTS +// main for normal game usage int main(int argc, char *argv[]) { #if defined(__MINGW32__) @@ -261,3 +268,14 @@ int main(int argc, char *argv[]) return client.testsExec(); } } + +#else + +// main for unit testing +int main(int argc, char **argv) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} + +#endif diff --git a/src/main.h b/src/main.h index fbc672939..abc152ed3 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.2.2.5" -#define CHECK_VERSION "01.02.02.05" +#define SMALL_VERSION "1.2.2.19" +#define CHECK_VERSION "01.02.02.19" #ifdef HAVE_CONFIG_H #include "../config.h" diff --git a/src/map.cpp b/src/map.cpp index 488fb16e9..b8767e5e4 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -23,11 +23,10 @@ #include "map.h" #include "actorspritemanager.h" -#include "client.h" #include "configuration.h" -#include "graphics.h" -#include "graphicsvertexes.h" + #include "logger.h" +#include "maplayer.h" #include "particle.h" #include "simpleanimation.h" #include "tileset.h" @@ -37,18 +36,13 @@ #include "resources/image.h" #include "resources/resourcemanager.h" -#include "gui/gui.h" -#include "gui/palette.h" -#include "gui/sdlfont.h" - #include "gui/widgets/chattab.h" #include "utils/dtor.h" #include "utils/mkdir.h" -#include "utils/stringutils.h" -#include <queue> #include <limits.h> +#include <physfs.h> #include <sys/stat.h> @@ -123,485 +117,6 @@ void TileAnimation::update(int ticks) } } -MapLayer::MapLayer(int x, int y, int width, int height, bool fringeLayer): - mX(x), mY(y), - mWidth(width), mHeight(height), - mIsFringeLayer(fringeLayer), - mHighlightAttackRange(config.getBoolValue("highlightAttackRange")) -{ - const int size = mWidth * mHeight; - mTiles = new Image*[size]; - - std::fill_n(mTiles, size, static_cast<Image*>(nullptr)); - - config.addListener("highlightAttackRange", this); -} - -MapLayer::~MapLayer() -{ - config.removeListener("highlightAttackRange", this); - delete[] mTiles; - delete_all(mTempRows); - mTempRows.clear(); -} - -void MapLayer::optionChanged(const std::string &value) -{ - if (value == "highlightAttackRange") - { - mHighlightAttackRange = - config.getBoolValue("highlightAttackRange"); - } -} - -void MapLayer::setTile(int x, int y, Image *img) -{ - mTiles[x + y * mWidth] = img; -} - -void MapLayer::draw(Graphics *graphics, int startX, int startY, - int endX, int endY, int scrollX, int scrollY, - int debugFlags) const -{ - if (!player_node) - return; - - startX -= mX; - startY -= mY; - endX -= mX; - endY -= mY; - - if (startX < 0) - startX = 0; - if (startY < 0) - startY = 0; - if (endX > mWidth) - endX = mWidth; - if (endY > mHeight) - endY = mHeight; - - const int dx = (mX * 32) - scrollX; - const int dy = (mY * 32) - scrollY + 32; - const bool flag = (debugFlags != Map::MAP_SPECIAL - && debugFlags != Map::MAP_SPECIAL2); - - for (int y = startY; y < endY; y++) - { - const int y32 = y * 32; - const int yWidth = y * mWidth; - - const int py0 = y32 + dy; - - Image **tilePtr = mTiles + startX + yWidth; - - for (int x = startX; x < endX; x++, tilePtr++) - { - const int x32 = x * 32; - - int c = 0; - Image *img = *tilePtr; - if (img) - { - const int px = x32 + dx; - const int py = py0 - img->mBounds.h; - if (flag || img->mBounds.h <= 32) - { - int width = 0; - // here need not draw over player position - c = getTileDrawWidth(img, endX - x, width); - - if (!c) - { - graphics->drawImage(img, px, py); - } - else - { - graphics->drawImagePattern(img, px, py, - width, img->mBounds.h); - } - } - } - - x += c; - } - } -} - -void MapLayer::updateSDL(Graphics *graphics, int startX, int startY, - int endX, int endY, int scrollX, int scrollY, - int debugFlags) -{ - delete_all(mTempRows); - mTempRows.clear(); - - startX -= mX; - startY -= mY; - endX -= mX; - endY -= mY; - - if (startX < 0) - startX = 0; - if (startY < 0) - startY = 0; - if (endX > mWidth) - endX = mWidth; - if (endY > mHeight) - endY = mHeight; - - const int dx = (mX * 32) - scrollX; - const int dy = (mY * 32) - scrollY + 32; - const bool flag = (debugFlags != Map::MAP_SPECIAL - && debugFlags != Map::MAP_SPECIAL2); - - for (int y = startY; y < endY; y++) - { - MapRowVertexes *row = new MapRowVertexes(); - mTempRows.push_back(row); - - Image *lastImage = nullptr; - ImageVertexes *imgVert = nullptr; - - const int yWidth = y * mWidth; - const int py0 = y * 32 + dy; - Image **tilePtr = mTiles + startX + yWidth; - - for (int x = startX; x < endX; x++, tilePtr++) - { - Image *img = *tilePtr; - if (img) - { - const int px = x * 32 + dx; - const int py = py0 - img->mBounds.h; - if (flag || img->mBounds.h <= 32) - { - if (lastImage != img) - { - imgVert = new ImageVertexes(); - imgVert->image = img; - row->images.push_back(imgVert); - lastImage = img; - } - graphics->calcTile(imgVert, px, py); - } - } - } - } -} - -void MapLayer::drawSDL(Graphics *graphics) -{ - MapRows::const_iterator rit = mTempRows.begin(); - MapRows::const_iterator rit_end = mTempRows.end(); - while (rit != rit_end) - { - MepRowImages *images = &(*rit)->images; - MepRowImages::const_iterator iit = images->begin(); - MepRowImages::const_iterator iit_end = images->end(); - while (iit != iit_end) - { - graphics->drawTile(*iit); - ++ iit; - } - ++ rit; - } -} - -void MapLayer::updateOGL(Graphics *graphics, int startX, int startY, - int endX, int endY, int scrollX, int scrollY, - int debugFlags) -{ - delete_all(mTempRows); - mTempRows.clear(); - - startX -= mX; - startY -= mY; - endX -= mX; - endY -= mY; - - if (startX < 0) - startX = 0; - if (startY < 0) - startY = 0; - if (endX > mWidth) - endX = mWidth; - if (endY > mHeight) - endY = mHeight; - - const int dx = (mX * 32) - scrollX; - const int dy = (mY * 32) - scrollY + 32; - const bool flag = (debugFlags != Map::MAP_SPECIAL - && debugFlags != Map::MAP_SPECIAL2); - - for (int y = startY; y < endY; y++) - { - MapRowVertexes *row = new MapRowVertexes(); - mTempRows.push_back(row); - - Image *lastImage = nullptr; - ImageVertexes *imgVert = nullptr; - - const int yWidth = y * mWidth; - const int py0 = y * 32 + dy; - std::map<Image*, ImageVertexes*> imgSet; - - Image **tilePtr = mTiles + startX + yWidth; - for (int x = startX; x < endX; x++, tilePtr++) - { - Image *img = *tilePtr; - if (img) - { - const int px = x * 32 + dx; - const int py = py0 - img->mBounds.h; - if (flag || img->mBounds.h <= 32) - { - if (lastImage != img) - { - if (img->mBounds.w > 32) - imgSet.clear(); - - imgSet[lastImage] = imgVert; - if (imgSet.find(img) != imgSet.end()) - { - imgVert = imgSet[img]; - } - else - { - imgVert = new ImageVertexes(); - imgVert->image = img; - row->images.push_back(imgVert); - } - lastImage = img; - } - graphics->calcTile(imgVert, px, py); - } - } - } - } -} - -void MapLayer::drawOGL(Graphics *graphics) -{ - MapRows::const_iterator rit = mTempRows.begin(); - MapRows::const_iterator rit_end = mTempRows.end(); - while (rit != rit_end) - { - MepRowImages *images = &(*rit)->images; - MepRowImages::const_iterator iit = images->begin(); - MepRowImages::const_iterator iit_end = images->end(); - while (iit != iit_end) - { - graphics->drawTile(*iit); - ++ iit; - } - ++ rit; - } -} - -void MapLayer::drawFringe(Graphics *graphics, int startX, int startY, - int endX, int endY, int scrollX, int scrollY, - const Actors *actors, int debugFlags, int yFix) const -{ - if (!player_node || !mSpecialLayer || !mTempLayer) - return; - - startX -= mX; - startY -= mY; - endX -= mX; - endY -= mY; - - if (startX < 0) - startX = 0; - if (startY < 0) - startY = 0; - if (endX > mWidth) - endX = mWidth; - if (endY > mHeight) - endY = mHeight; - - Actors::const_iterator ai = actors->begin(); - - const int dx = (mX * 32) - scrollX; - const int dy = (mY * 32) - scrollY + 32; - - int specialWidth = mSpecialLayer->mWidth; - int specialHeight = mSpecialLayer->mHeight; - - for (int y = startY; y < endY; y++) - { - const int y32 = y * 32; - const int y32s = (y + yFix) * 32; - const int yWidth = y * mWidth; - - // If drawing the fringe layer, make sure all actors above this row of - // tiles have been drawn - while (ai != actors->end() && (*ai)->getPixelY() <= y32s) - { - (*ai)->draw(graphics, -scrollX, -scrollY); - ++ ai; - } - - if (debugFlags == Map::MAP_SPECIAL3 - || debugFlags == Map::MAP_BLACKWHITE) - { - if (y < specialHeight) - { - int ptr = y * specialWidth; - const int py1 = y32 - scrollY; - int endX1 = endX; - if (endX1 > specialWidth) - endX1 = specialWidth; - if (endX1 < 0) - endX1 = 0; - - for (int x = startX; x < endX1; x++) - { - const int px1 = x * 32 - scrollX; - - MapItem *item = mSpecialLayer->mTiles[ptr + x]; - if (item) - item->draw(graphics, px1, py1, 32, 32); - - item = mTempLayer->mTiles[ptr + x]; - if (item) - item->draw(graphics, px1, py1, 32, 32); - } - } - } - else - { - const int py0 = y32 + dy; - const int py1 = y32 - scrollY; - - Image **tilePtr = mTiles + startX + yWidth; - for (int x = startX; x < endX; x++, tilePtr++) - { - const int x32 = x * 32; - - const int px1 = x32 - scrollX; - int c = 0; - Image *img = *tilePtr; - if (img) - { - const int px = x32 + dx; - const int py = py0 - img->mBounds.h; - if ((debugFlags != Map::MAP_SPECIAL - && debugFlags != Map::MAP_SPECIAL2) - || img->mBounds.h <= 32) - { - int width = 0; - // here need not draw over player position - c = getTileDrawWidth(img, endX - x, width); - - if (!c) - { - graphics->drawImage(img, px, py); - } - else - { - graphics->drawImagePattern(img, px, py, - width, img->mBounds.h); - } - } - } - - if (y < specialHeight) - { - int c1 = c; - if (c1 + x + 1 > specialWidth) - c1 = specialWidth - x - 1; - if (c1 < 0) - c1 = 0; - - int ptr = y * specialWidth + x; - - for (int x1 = 0; x1 < c1 + 1; x1 ++) - { - MapItem *item1 = mSpecialLayer->mTiles[ptr + x1]; - MapItem *item2 = mTempLayer->mTiles[ptr + x1]; - if (item1 || item2) - { - const int px2 = px1 + (x1 * 32); - if (item1 && item1->mType != MapItem::EMPTY) - item1->draw(graphics, px2, py1, 32, 32); - - if (item2 && item2->mType != MapItem::EMPTY) - item2->draw(graphics, px2, py1, 32, 32); - } - } - } - x += c; - } - } - } - - // Draw any remaining actors - if (debugFlags != Map::MAP_SPECIAL3) - { - while (ai != actors->end()) - { - (*ai)->draw(graphics, -scrollX, -scrollY); - ++ai; - } - if (mHighlightAttackRange && player_node) - { - const int px = player_node->getPixelX() - scrollX - 16; - const int py = player_node->getPixelY() - scrollY - 32; - const int attackRange = player_node->getAttackRange() * 32; - - int x = px - attackRange; - int y = py - attackRange; - int w = 2 * attackRange + 32; - int h = w; - if (attackRange <= 32) - { - x -= 16; - y -= 16; - w += 32; - h += 32; - } - - if (userPalette) - { - graphics->setColor(userPalette->getColorWithAlpha( - UserPalette::ATTACK_RANGE)); - - graphics->fillRectangle(gcn::Rectangle( - x, y, - w, h)); - - graphics->setColor(userPalette->getColorWithAlpha( - UserPalette::ATTACK_RANGE_BORDER)); - - graphics->drawRectangle(gcn::Rectangle( - x, y, - w, h)); - } - } - } -} - -int MapLayer::getTileDrawWidth(Image *img, int endX, int &width) const -{ - Image *img1 = img; - int c = 0; - if (!img1) - { - width = 0; - return c; - } - width = img1->mBounds.w; - for (int x = 1; x < endX; x++) - { - img ++; - if (img != img1) - break; - c ++; - if (img) - width += img->mBounds.w; - } - return c; -} - Map::Map(int width, int height, int tileWidth, int tileHeight): mWidth(width), mHeight(height), mTileWidth(tileWidth), mTileHeight(tileHeight), @@ -667,9 +182,9 @@ Map::~Map() config.removeListener("beingopacity", this); // delete metadata, layers, tilesets and overlays - delete[] mMetaTiles; + delete [] mMetaTiles; for (int i = 0; i < NB_BLOCKTYPES; i++) - delete[] mOccupation[i]; + delete [] mOccupation[i]; mFringeLayer = nullptr; delete_all(mLayers); @@ -1737,7 +1252,7 @@ void Map::saveExtraLayer() std::string Map::getUserMapDirectory() const { - return Client::getServerConfigDirectory() + "/" + return Client::getServerConfigDirectory() + PHYSFS_getDirSeparator() + getProperty("_realfilename"); } @@ -1921,7 +1436,7 @@ void Map::clearIndexedTilesets() return; mTilesetsIndexed = false; - delete[] mIndexedTilesets; + delete [] mIndexedTilesets; mIndexedTilesetsSize = 0; } @@ -2055,301 +1570,3 @@ void Map::redrawMap() { mRedrawMap = true; } - -SpecialLayer::SpecialLayer(int width, int height, bool drawSprites): - mWidth(width), mHeight(height) -{ - const int size = mWidth * mHeight; - mTiles = new MapItem*[size]; - std::fill_n(mTiles, size, static_cast<MapItem*>(nullptr)); - mDrawSprites = drawSprites; -} - -SpecialLayer::~SpecialLayer() -{ - for (int f = 0; f < mWidth * mHeight; f ++) - { - delete mTiles[f]; - mTiles[f] = nullptr; - } - delete[] mTiles; -} - -MapItem* SpecialLayer::getTile(int x, int y) const -{ - if (x < 0 || x >= mWidth || - y < 0 || y >= mHeight) - { - return nullptr; - } - return mTiles[x + y * mWidth]; -} - -void SpecialLayer::setTile(int x, int y, MapItem *item) -{ - if (x < 0 || x >= mWidth || - y < 0 || y >= mHeight) - { - return; - } - - int idx = x + y * mWidth; - delete mTiles[idx]; - if (item) - item->setPos(x, y); - mTiles[idx] = item; -} - -void SpecialLayer::setTile(int x, int y, int type) -{ - if (x < 0 || x >= mWidth || - y < 0 || y >= mHeight) - { - return; - } - - int idx = x + y * mWidth; - if (mTiles[idx]) - mTiles[idx]->setType(type); - else - mTiles[idx] = new MapItem(type); - mTiles[idx]->setPos(x, y); -} - -void SpecialLayer::addRoad(Path road) -{ - for (Path::const_iterator i = road.begin(), i_end = road.end(); - i != i_end; ++i) - { - Position pos = (*i); - MapItem *item = getTile(pos.x, pos.y); - if (!item) - { - item = new MapItem(MapItem::ROAD); - setTile(pos.x, pos.y, item); - } - else - { - item->setType(MapItem::ROAD); - } - } -} - -void SpecialLayer::clean() -{ - if (!mTiles) - return; - - for (int f = 0; f < mWidth * mHeight; f ++) - { - MapItem *item = mTiles[f]; - if (item) - item->setType(MapItem::EMPTY); - } -} - -void SpecialLayer::draw(Graphics *graphics, int startX, int startY, - int endX, int endY, int scrollX, int scrollY) -{ - if (startX < 0) - startX = 0; - if (startY < 0) - startY = 0; - if (endX > mWidth) - endX = mWidth; - if (endY > mHeight) - endY = mHeight; - - for (int y = startY; y < endY; y++) - { - for (int x = startX; x < endX; x++) - itemDraw(graphics, x, y, scrollX, scrollY); - } -} - -void SpecialLayer::itemDraw(Graphics *graphics, int x, int y, - int scrollX, int scrollY) -{ - MapItem *item = getTile(x, y); - if (item) - { - const int px = x * 32 - scrollX; - const int py = y * 32 - scrollY; - item->draw(graphics, px, py, 32, 32); - } -} - - -MapItem::MapItem(): - mImage(nullptr), mComment(""), mName(""), mX(-1), mY(-1) -{ - setType(EMPTY); -} - -MapItem::MapItem(int type): - mImage(nullptr), mComment(""), mName(""), mX(-1), mY(-1) -{ - setType(type); -} - -MapItem::MapItem(int type, std::string comment): - mImage(nullptr), mComment(comment), mName(""), mX(-1), mY(-1) -{ - setType(type); -} - -MapItem::MapItem(int type, std::string comment, int x, int y): - mImage(nullptr), mComment(comment), mName(""), mX(x), mY(y) -{ - setType(type); -} - -MapItem::~MapItem() -{ - if (mImage) - { - mImage->decRef(); - mImage = nullptr; - } -} - -void MapItem::setType(int type) -{ - std::string name(""); - mType = type; - if (mImage) - mImage->decRef(); - - switch (type) - { - case ARROW_UP: - name = "graphics/sprites/arrow_up.gif"; - break; - case ARROW_DOWN: - name = "graphics/sprites/arrow_down.gif"; - break; - case ARROW_LEFT: - name = "graphics/sprites/arrow_left.gif"; - break; - case ARROW_RIGHT: - name = "graphics/sprites/arrow_right.gif"; - break; - default: - break; - } - - if (name != "") - { - ResourceManager *resman = ResourceManager::getInstance(); - mImage = resman->getImage(name); - } - else - { - mImage = nullptr; - } -} - -void MapItem::setPos(int x, int y) -{ - mX = x; - mY = y; -} - -void MapItem::draw(Graphics *graphics, int x, int y, int dx, int dy) -{ - if (mImage) - graphics->drawImage(mImage, x, y); - - switch(mType) - { - case ROAD: - case CROSS: - graphics->setColor(userPalette->getColorWithAlpha( - UserPalette::ROAD_POINT)); - graphics->fillRectangle(gcn::Rectangle(x + dx / 3, y + dy / 3, - dx / 3, dy / 3)); - break; - case HOME: - { - graphics->setColor(userPalette->getColorWithAlpha( - UserPalette::HOME_PLACE)); - graphics->fillRectangle(gcn::Rectangle( - x, y, - dx, dy)); - graphics->setColor(userPalette->getColorWithAlpha( - UserPalette::HOME_PLACE_BORDER)); - graphics->drawRectangle(gcn::Rectangle( - x, y, - dx, dy)); - break; - } - default: - break; - } - if (!mName.empty() && mType != PORTAL && mType != EMPTY && userPalette) - { - gcn::Font *font = gui->getFont(); - if (font) - { - graphics->setColor(userPalette->getColor(UserPalette::BEING)); - font->drawString(graphics, mName, x, y); - } - } -} - -ObjectsLayer::ObjectsLayer(unsigned width, unsigned height) : - mWidth(width), mHeight(height) -{ - const unsigned size = width * height; - mTiles = new MapObjectList*[size]; - std::fill_n(mTiles, size, static_cast<MapObjectList*>(nullptr)); -} - -ObjectsLayer::~ObjectsLayer() -{ - const unsigned size = mWidth * mHeight; - for (unsigned f = 0; f < size; f ++) - delete mTiles[f]; - - delete [] mTiles; - mTiles = nullptr; -} - -void ObjectsLayer::addObject(std::string name, int type, - unsigned x, unsigned y, - unsigned dx, unsigned dy) -{ - if (!mTiles) - return; - - if (x + dx > mWidth) - dx = mWidth - x; - if (y + dy > mHeight) - dy = mHeight - y; - - for (unsigned y1 = y; y1 < y + dy; y1 ++) - { - unsigned idx1 = x + y1 * mWidth; - unsigned idx2 = idx1 + dx; - - for (unsigned i = idx1; i < idx2; i ++) - { - if (!mTiles[i]) - mTiles[i] = new MapObjectList(); - mTiles[i]->objects.push_back(MapObject(type, name)); - } - } -} - -MapObjectList *ObjectsLayer::getAt(unsigned x, unsigned y) -{ - if (x >= mWidth || y >= mHeight) - return nullptr; - return mTiles[x + y * mWidth]; -} - -MapRowVertexes::~MapRowVertexes() -{ - delete_all(images); - images.clear(); -} @@ -28,14 +28,11 @@ #include "position.h" #include "properties.h" -#include <list> #include <string> #include <vector> class Animation; class AmbientLayer; -class Graphics; -class GraphicsVertexes; class MapLayer; class Particle; class SimpleAnimation; @@ -44,24 +41,8 @@ class SpecialLayer; class MapItem; class ObjectsLayer; -class ImageVertexes; - typedef std::vector<Tileset*> Tilesets; typedef std::vector<MapLayer*> Layers; -typedef std::vector<ImageVertexes*> MepRowImages; - -class MapRowVertexes -{ - public: - MapRowVertexes() - { - images.reserve(30); - } - - ~MapRowVertexes(); - - MepRowImages images; -}; /** * A meta tile stores additional information about a location on a tile map. @@ -87,25 +68,6 @@ struct MetaTile unsigned char blockmask; /**< Blocking properties of this tile */ }; -class MapObject -{ - public: - MapObject(int type0, std::string data0) - { - type = type0; - data = data0; - } - - int type; - std::string data; -}; - -class MapObjectList -{ - public: - std::vector<MapObject> objects; -}; - /** * Animation cycle of a tile image which changes the map accordingly. */ @@ -124,114 +86,6 @@ class TileAnimation }; /** - * A map layer. Stores a grid of tiles and their offset, and implements layer - * rendering. - */ -class MapLayer: public ConfigListener -{ - public: - friend class Map; - - /** - * Constructor, taking layer origin, size and whether this layer is the - * fringe layer. The fringe layer is the layer that draws the actors. - * There can be only one fringe layer per map. - */ - MapLayer(int x, int y, int width, int height, bool isFringeLayer); - - /** - * Destructor. - */ - ~MapLayer(); - - /** - * Set tile image, with x and y in layer coordinates. - */ - void setTile(int x, int y, Image *img); - - /** - * Set tile image with x + y * width already known. - */ - void setTile(int index, Image *img) - { mTiles[index] = img; } - - /** - * Draws this layer to the given graphics context. The coordinates are - * expected to be in map range and will be translated to local layer - * coordinates and clipped to the layer's dimensions. - * - * The given actors are only drawn when this layer is the fringe - * layer. - */ - void draw(Graphics *graphics, - int startX, int startY, - int endX, int endY, - int scrollX, int scrollY, - int mDebugFlags) const; - - void drawOGL(Graphics *graphics); - - void drawSDL(Graphics *graphics); - - void updateOGL(Graphics *graphics, - int startX, int startY, - int endX, int endY, - int scrollX, int scrollY, - int mDebugFlags); - - void updateSDL(Graphics *graphics, - int startX, int startY, - int endX, int endY, - int scrollX, int scrollY, - int mDebugFlags); - - void drawFringe(Graphics *graphics, - int startX, int startY, - int endX, int endY, - int scrollX, int scrollY, - const Actors *actors, - int mDebugFlags, int yFix) const; - - bool isFringeLayer() const - { return mIsFringeLayer; } - - void setSpecialLayer(SpecialLayer *val) - { mSpecialLayer = val; } - - void setTempLayer(SpecialLayer *val) - { mTempLayer = val; } - - int getWidth() const - { return mWidth; } - - int getHeight() const - { return mHeight; } - -// void setTileInfo(int x, int y, int width, int cnt); - -// void getTileInfo(int x, int y, int &width, int &cnt) const; - - void optionChanged(const std::string &value); - - int getTileDrawWidth(Image *img, int endX, int &width) const; - -// void initTileInfo(); - - private: - int mX, mY; - int mWidth, mHeight; - bool mIsFringeLayer; /**< Whether the actors are drawn. */ - bool mHighlightAttackRange; - Image **mTiles; -// int *mTilesWidth; -// int *mTilesCount; - SpecialLayer *mSpecialLayer; - SpecialLayer *mTempLayer; - typedef std::vector<MapRowVertexes*> MapRows; - MapRows mTempRows; -}; - -/** * A tile map. */ class Map : public Properties, public ConfigListener @@ -614,123 +468,4 @@ class Map : public Properties, public ConfigListener bool mBeingOpacity; }; - -class SpecialLayer -{ - public: - friend class Map; - friend class MapLayer; - - SpecialLayer(int width, int height, bool drawSprites = false); - - ~SpecialLayer(); - - void draw(Graphics *graphics, int startX, int startY, - int endX, int endY, int scrollX, int scrollY); - - MapItem* getTile(int x, int y) const; - - void setTile(int x, int y, MapItem* item); - - void setTile(int x, int y, int type); - - void addRoad(Path road); - - void clean(); - - void itemDraw(Graphics *graphics, int x, int y, - int scrollX, int scrollY); - - private: - int mWidth, mHeight; - bool mDrawSprites; - MapItem **mTiles; -}; - -class MapItem -{ - public: - friend class Map; - friend class MapLayer; - - enum ItemType - { - EMPTY = 0, - HOME = 1, - ROAD = 2, - CROSS = 3, - ARROW_UP = 4, - ARROW_DOWN = 5, - ARROW_LEFT = 6, - ARROW_RIGHT = 7, - PORTAL = 8, - MUSIC = 9, - ATTACK = 10, - PRIORITY = 11, - IGNORE_ = 12, - SEPARATOR = 13 - }; - - MapItem(); - - MapItem(int type); - - MapItem(int type, std::string comment); - - MapItem(int type, std::string comment, int x, int y); - - ~MapItem(); - - int getType() const - { return mType; } - - void setType(int type); - - void setPos(int x, int y); - - int getX() const - { return mX; } - - int getY() const - { return mY; } - - std::string &getComment() - { return mComment; } - - void setComment(std::string comment) - { mComment = comment; } - - std::string &getName() - { return mName; } - - void setName(std::string name) - { mName = name; } - - void draw(Graphics *graphics, int x, int y, int dx, int dy); - - private: - int mType; - Image *mImage; - std::string mComment; - std::string mName; - int mX; - int mY; -}; - -class ObjectsLayer -{ - public: - ObjectsLayer(unsigned width, unsigned height); - ~ObjectsLayer(); - - void addObject(std::string name, int type, unsigned x, unsigned y, - unsigned dx, unsigned dy); - - MapObjectList *getAt(unsigned x, unsigned y); - private: - MapObjectList **mTiles; - unsigned mWidth; - unsigned mHeight; -}; - #endif diff --git a/src/maplayer.cpp b/src/maplayer.cpp new file mode 100644 index 000000000..514a35858 --- /dev/null +++ b/src/maplayer.cpp @@ -0,0 +1,817 @@ +/* + * The ManaPlus Client + * Copyright (C) 2004-2009 The Mana World Development Team + * Copyright (C) 2009-2010 The Mana Developers + * Copyright (C) 2011-2012 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 "maplayer.h" + +#include "configuration.h" + +#include "graphicsvertexes.h" + +#include "logger.h" +#include "localplayer.h" + +#include "resources/image.h" +#include "resources/resourcemanager.h" + +#include "gui/gui.h" +#include "gui/sdlfont.h" + +#include "utils/dtor.h" + +#include "debug.h" + +MapLayer::MapLayer(int x, int y, int width, int height, bool fringeLayer): + mX(x), mY(y), + mWidth(width), mHeight(height), + mIsFringeLayer(fringeLayer), + mHighlightAttackRange(config.getBoolValue("highlightAttackRange")) +{ + const int size = mWidth * mHeight; + mTiles = new Image*[size]; + + std::fill_n(mTiles, size, static_cast<Image*>(nullptr)); + + config.addListener("highlightAttackRange", this); +} + +MapLayer::~MapLayer() +{ + config.removeListener("highlightAttackRange", this); + delete [] mTiles; + delete_all(mTempRows); + mTempRows.clear(); +} + +void MapLayer::optionChanged(const std::string &value) +{ + if (value == "highlightAttackRange") + { + mHighlightAttackRange = + config.getBoolValue("highlightAttackRange"); + } +} + +void MapLayer::setTile(int x, int y, Image *img) +{ + mTiles[x + y * mWidth] = img; +} + +void MapLayer::draw(Graphics *graphics, int startX, int startY, + int endX, int endY, int scrollX, int scrollY, + int debugFlags) const +{ + if (!player_node) + return; + + startX -= mX; + startY -= mY; + endX -= mX; + endY -= mY; + + if (startX < 0) + startX = 0; + if (startY < 0) + startY = 0; + if (endX > mWidth) + endX = mWidth; + if (endY > mHeight) + endY = mHeight; + + const int dx = (mX * 32) - scrollX; + const int dy = (mY * 32) - scrollY + 32; + const bool flag = (debugFlags != Map::MAP_SPECIAL + && debugFlags != Map::MAP_SPECIAL2); + + for (int y = startY; y < endY; y++) + { + const int y32 = y * 32; + const int yWidth = y * mWidth; + + const int py0 = y32 + dy; + + Image **tilePtr = mTiles + startX + yWidth; + + for (int x = startX; x < endX; x++, tilePtr++) + { + const int x32 = x * 32; + + int c = 0; + Image *img = *tilePtr; + if (img) + { + const int px = x32 + dx; + const int py = py0 - img->mBounds.h; + if (flag || img->mBounds.h <= 32) + { + int width = 0; + // here need not draw over player position + c = getTileDrawWidth(img, endX - x, width); + + if (!c) + { + graphics->drawImage(img, px, py); + } + else + { + graphics->drawImagePattern(img, px, py, + width, img->mBounds.h); + } + } + } + + x += c; + } + } +} + +void MapLayer::updateSDL(Graphics *graphics, int startX, int startY, + int endX, int endY, int scrollX, int scrollY, + int debugFlags) +{ + delete_all(mTempRows); + mTempRows.clear(); + + startX -= mX; + startY -= mY; + endX -= mX; + endY -= mY; + + if (startX < 0) + startX = 0; + if (startY < 0) + startY = 0; + if (endX > mWidth) + endX = mWidth; + if (endY > mHeight) + endY = mHeight; + + const int dx = (mX * 32) - scrollX; + const int dy = (mY * 32) - scrollY + 32; + const bool flag = (debugFlags != Map::MAP_SPECIAL + && debugFlags != Map::MAP_SPECIAL2); + + for (int y = startY; y < endY; y++) + { + MapRowVertexes *row = new MapRowVertexes(); + mTempRows.push_back(row); + + Image *lastImage = nullptr; + ImageVertexes *imgVert = nullptr; + + const int yWidth = y * mWidth; + const int py0 = y * 32 + dy; + Image **tilePtr = mTiles + startX + yWidth; + + for (int x = startX; x < endX; x++, tilePtr++) + { + Image *img = *tilePtr; + if (img) + { + const int px = x * 32 + dx; + const int py = py0 - img->mBounds.h; + if (flag || img->mBounds.h <= 32) + { + if (lastImage != img) + { + imgVert = new ImageVertexes(); + imgVert->image = img; + row->images.push_back(imgVert); + lastImage = img; + } + graphics->calcTile(imgVert, px, py); + } + } + } + } +} + +void MapLayer::drawSDL(Graphics *graphics) +{ + MapRows::const_iterator rit = mTempRows.begin(); + MapRows::const_iterator rit_end = mTempRows.end(); + while (rit != rit_end) + { + MepRowImages *images = &(*rit)->images; + MepRowImages::const_iterator iit = images->begin(); + MepRowImages::const_iterator iit_end = images->end(); + while (iit != iit_end) + { + graphics->drawTile(*iit); + ++ iit; + } + ++ rit; + } +} + +void MapLayer::updateOGL(Graphics *graphics, int startX, int startY, + int endX, int endY, int scrollX, int scrollY, + int debugFlags) +{ + delete_all(mTempRows); + mTempRows.clear(); + + startX -= mX; + startY -= mY; + endX -= mX; + endY -= mY; + + if (startX < 0) + startX = 0; + if (startY < 0) + startY = 0; + if (endX > mWidth) + endX = mWidth; + if (endY > mHeight) + endY = mHeight; + + const int dx = (mX * 32) - scrollX; + const int dy = (mY * 32) - scrollY + 32; + const bool flag = (debugFlags != Map::MAP_SPECIAL + && debugFlags != Map::MAP_SPECIAL2); + + for (int y = startY; y < endY; y++) + { + MapRowVertexes *row = new MapRowVertexes(); + mTempRows.push_back(row); + + Image *lastImage = nullptr; + ImageVertexes *imgVert = nullptr; + + const int yWidth = y * mWidth; + const int py0 = y * 32 + dy; + std::map<Image*, ImageVertexes*> imgSet; + + Image **tilePtr = mTiles + startX + yWidth; + for (int x = startX; x < endX; x++, tilePtr++) + { + Image *img = *tilePtr; + if (img) + { + const int px = x * 32 + dx; + const int py = py0 - img->mBounds.h; + if (flag || img->mBounds.h <= 32) + { + if (lastImage != img) + { + if (img->mBounds.w > 32) + imgSet.clear(); + + imgSet[lastImage] = imgVert; + if (imgSet.find(img) != imgSet.end()) + { + imgVert = imgSet[img]; + } + else + { + imgVert = new ImageVertexes(); + imgVert->image = img; + row->images.push_back(imgVert); + } + lastImage = img; + } + graphics->calcTile(imgVert, px, py); + } + } + } + } +} + +void MapLayer::drawOGL(Graphics *graphics) +{ + MapRows::const_iterator rit = mTempRows.begin(); + MapRows::const_iterator rit_end = mTempRows.end(); + while (rit != rit_end) + { + MepRowImages *images = &(*rit)->images; + MepRowImages::const_iterator iit = images->begin(); + MepRowImages::const_iterator iit_end = images->end(); + while (iit != iit_end) + { + graphics->drawTile(*iit); + ++ iit; + } + ++ rit; + } +} + +void MapLayer::drawFringe(Graphics *graphics, int startX, int startY, + int endX, int endY, int scrollX, int scrollY, + const Actors *actors, int debugFlags, int yFix) const +{ + if (!player_node || !mSpecialLayer || !mTempLayer) + return; + + startX -= mX; + startY -= mY; + endX -= mX; + endY -= mY; + + if (startX < 0) + startX = 0; + if (startY < 0) + startY = 0; + if (endX > mWidth) + endX = mWidth; + if (endY > mHeight) + endY = mHeight; + + Actors::const_iterator ai = actors->begin(); + + const int dx = (mX * 32) - scrollX; + const int dy = (mY * 32) - scrollY + 32; + + int specialWidth = mSpecialLayer->mWidth; + int specialHeight = mSpecialLayer->mHeight; + + for (int y = startY; y < endY; y++) + { + const int y32 = y * 32; + const int y32s = (y + yFix) * 32; + const int yWidth = y * mWidth; + + // If drawing the fringe layer, make sure all actors above this row of + // tiles have been drawn + while (ai != actors->end() && (*ai)->getPixelY() <= y32s) + { + (*ai)->draw(graphics, -scrollX, -scrollY); + ++ ai; + } + + if (debugFlags == Map::MAP_SPECIAL3 + || debugFlags == Map::MAP_BLACKWHITE) + { + if (y < specialHeight) + { + int ptr = y * specialWidth; + const int py1 = y32 - scrollY; + int endX1 = endX; + if (endX1 > specialWidth) + endX1 = specialWidth; + if (endX1 < 0) + endX1 = 0; + + for (int x = startX; x < endX1; x++) + { + const int px1 = x * 32 - scrollX; + + MapItem *item = mSpecialLayer->mTiles[ptr + x]; + if (item) + item->draw(graphics, px1, py1, 32, 32); + + item = mTempLayer->mTiles[ptr + x]; + if (item) + item->draw(graphics, px1, py1, 32, 32); + } + } + } + else + { + const int py0 = y32 + dy; + const int py1 = y32 - scrollY; + + Image **tilePtr = mTiles + startX + yWidth; + for (int x = startX; x < endX; x++, tilePtr++) + { + const int x32 = x * 32; + + const int px1 = x32 - scrollX; + int c = 0; + Image *img = *tilePtr; + if (img) + { + const int px = x32 + dx; + const int py = py0 - img->mBounds.h; + if ((debugFlags != Map::MAP_SPECIAL + && debugFlags != Map::MAP_SPECIAL2) + || img->mBounds.h <= 32) + { + int width = 0; + // here need not draw over player position + c = getTileDrawWidth(img, endX - x, width); + + if (!c) + { + graphics->drawImage(img, px, py); + } + else + { + graphics->drawImagePattern(img, px, py, + width, img->mBounds.h); + } + } + } + + if (y < specialHeight) + { + int c1 = c; + if (c1 + x + 1 > specialWidth) + c1 = specialWidth - x - 1; + if (c1 < 0) + c1 = 0; + + int ptr = y * specialWidth + x; + + for (int x1 = 0; x1 < c1 + 1; x1 ++) + { + MapItem *item1 = mSpecialLayer->mTiles[ptr + x1]; + MapItem *item2 = mTempLayer->mTiles[ptr + x1]; + if (item1 || item2) + { + const int px2 = px1 + (x1 * 32); + if (item1 && item1->mType != MapItem::EMPTY) + item1->draw(graphics, px2, py1, 32, 32); + + if (item2 && item2->mType != MapItem::EMPTY) + item2->draw(graphics, px2, py1, 32, 32); + } + } + } + x += c; + } + } + } + + // Draw any remaining actors + if (debugFlags != Map::MAP_SPECIAL3) + { + while (ai != actors->end()) + { + (*ai)->draw(graphics, -scrollX, -scrollY); + ++ai; + } + if (mHighlightAttackRange && player_node) + { + const int px = player_node->getPixelX() - scrollX - 16; + const int py = player_node->getPixelY() - scrollY - 32; + const int attackRange = player_node->getAttackRange() * 32; + + int x = px - attackRange; + int y = py - attackRange; + int w = 2 * attackRange + 32; + int h = w; + if (attackRange <= 32) + { + x -= 16; + y -= 16; + w += 32; + h += 32; + } + + if (userPalette) + { + graphics->setColor(userPalette->getColorWithAlpha( + UserPalette::ATTACK_RANGE)); + + graphics->fillRectangle(gcn::Rectangle( + x, y, + w, h)); + + graphics->setColor(userPalette->getColorWithAlpha( + UserPalette::ATTACK_RANGE_BORDER)); + + graphics->drawRectangle(gcn::Rectangle( + x, y, + w, h)); + } + } + } +} + +int MapLayer::getTileDrawWidth(Image *img, int endX, int &width) const +{ + Image *img1 = img; + int c = 0; + if (!img1) + { + width = 0; + return c; + } + width = img1->mBounds.w; + for (int x = 1; x < endX; x++) + { + img ++; + if (img != img1) + break; + c ++; + if (img) + width += img->mBounds.w; + } + return c; +} + +SpecialLayer::SpecialLayer(int width, int height, bool drawSprites): + mWidth(width), mHeight(height) +{ + const int size = mWidth * mHeight; + mTiles = new MapItem*[size]; + std::fill_n(mTiles, size, static_cast<MapItem*>(nullptr)); + mDrawSprites = drawSprites; +} + +SpecialLayer::~SpecialLayer() +{ + for (int f = 0; f < mWidth * mHeight; f ++) + { + delete mTiles[f]; + mTiles[f] = nullptr; + } + delete [] mTiles; +} + +MapItem* SpecialLayer::getTile(int x, int y) const +{ + if (x < 0 || x >= mWidth || + y < 0 || y >= mHeight) + { + return nullptr; + } + return mTiles[x + y * mWidth]; +} + +void SpecialLayer::setTile(int x, int y, MapItem *item) +{ + if (x < 0 || x >= mWidth || + y < 0 || y >= mHeight) + { + return; + } + + int idx = x + y * mWidth; + delete mTiles[idx]; + if (item) + item->setPos(x, y); + mTiles[idx] = item; +} + +void SpecialLayer::setTile(int x, int y, int type) +{ + if (x < 0 || x >= mWidth || + y < 0 || y >= mHeight) + { + return; + } + + int idx = x + y * mWidth; + if (mTiles[idx]) + mTiles[idx]->setType(type); + else + mTiles[idx] = new MapItem(type); + mTiles[idx]->setPos(x, y); +} + +void SpecialLayer::addRoad(Path road) +{ + for (Path::const_iterator i = road.begin(), i_end = road.end(); + i != i_end; ++i) + { + Position pos = (*i); + MapItem *item = getTile(pos.x, pos.y); + if (!item) + { + item = new MapItem(MapItem::ROAD); + setTile(pos.x, pos.y, item); + } + else + { + item->setType(MapItem::ROAD); + } + } +} + +void SpecialLayer::clean() +{ + if (!mTiles) + return; + + for (int f = 0; f < mWidth * mHeight; f ++) + { + MapItem *item = mTiles[f]; + if (item) + item->setType(MapItem::EMPTY); + } +} + +void SpecialLayer::draw(Graphics *graphics, int startX, int startY, + int endX, int endY, int scrollX, int scrollY) +{ + if (startX < 0) + startX = 0; + if (startY < 0) + startY = 0; + if (endX > mWidth) + endX = mWidth; + if (endY > mHeight) + endY = mHeight; + + for (int y = startY; y < endY; y++) + { + for (int x = startX; x < endX; x++) + itemDraw(graphics, x, y, scrollX, scrollY); + } +} + +void SpecialLayer::itemDraw(Graphics *graphics, int x, int y, + int scrollX, int scrollY) +{ + MapItem *item = getTile(x, y); + if (item) + { + const int px = x * 32 - scrollX; + const int py = y * 32 - scrollY; + item->draw(graphics, px, py, 32, 32); + } +} + + +MapItem::MapItem(): + mImage(nullptr), mComment(""), mName(""), mX(-1), mY(-1) +{ + setType(EMPTY); +} + +MapItem::MapItem(int type): + mImage(nullptr), mComment(""), mName(""), mX(-1), mY(-1) +{ + setType(type); +} + +MapItem::MapItem(int type, std::string comment): + mImage(nullptr), mComment(comment), mName(""), mX(-1), mY(-1) +{ + setType(type); +} + +MapItem::MapItem(int type, std::string comment, int x, int y): + mImage(nullptr), mComment(comment), mName(""), mX(x), mY(y) +{ + setType(type); +} + +MapItem::~MapItem() +{ + if (mImage) + { + mImage->decRef(); + mImage = nullptr; + } +} + +void MapItem::setType(int type) +{ + std::string name(""); + mType = type; + if (mImage) + mImage->decRef(); + + switch (type) + { + case ARROW_UP: + name = "graphics/sprites/arrow_up.gif"; + break; + case ARROW_DOWN: + name = "graphics/sprites/arrow_down.gif"; + break; + case ARROW_LEFT: + name = "graphics/sprites/arrow_left.gif"; + break; + case ARROW_RIGHT: + name = "graphics/sprites/arrow_right.gif"; + break; + default: + break; + } + + if (name != "") + { + ResourceManager *resman = ResourceManager::getInstance(); + mImage = resman->getImage(name); + } + else + { + mImage = nullptr; + } +} + +void MapItem::setPos(int x, int y) +{ + mX = x; + mY = y; +} + +void MapItem::draw(Graphics *graphics, int x, int y, int dx, int dy) +{ + if (mImage) + graphics->drawImage(mImage, x, y); + + switch (mType) + { + case ROAD: + case CROSS: + graphics->setColor(userPalette->getColorWithAlpha( + UserPalette::ROAD_POINT)); + graphics->fillRectangle(gcn::Rectangle(x + dx / 3, y + dy / 3, + dx / 3, dy / 3)); + break; + case HOME: + { + graphics->setColor(userPalette->getColorWithAlpha( + UserPalette::HOME_PLACE)); + graphics->fillRectangle(gcn::Rectangle( + x, y, + dx, dy)); + graphics->setColor(userPalette->getColorWithAlpha( + UserPalette::HOME_PLACE_BORDER)); + graphics->drawRectangle(gcn::Rectangle( + x, y, + dx, dy)); + break; + } + default: + break; + } + if (!mName.empty() && mType != PORTAL && mType != EMPTY && userPalette) + { + gcn::Font *font = gui->getFont(); + if (font) + { + graphics->setColor(userPalette->getColor(UserPalette::BEING)); + font->drawString(graphics, mName, x, y); + } + } +} + +ObjectsLayer::ObjectsLayer(unsigned width, unsigned height) : + mWidth(width), mHeight(height) +{ + const unsigned size = width * height; + mTiles = new MapObjectList*[size]; + std::fill_n(mTiles, size, static_cast<MapObjectList*>(nullptr)); +} + +ObjectsLayer::~ObjectsLayer() +{ + const unsigned size = mWidth * mHeight; + for (unsigned f = 0; f < size; f ++) + delete mTiles[f]; + + delete [] mTiles; + mTiles = nullptr; +} + +void ObjectsLayer::addObject(std::string name, int type, + unsigned x, unsigned y, + unsigned dx, unsigned dy) +{ + if (!mTiles) + return; + + if (x + dx > mWidth) + dx = mWidth - x; + if (y + dy > mHeight) + dy = mHeight - y; + + for (unsigned y1 = y; y1 < y + dy; y1 ++) + { + unsigned idx1 = x + y1 * mWidth; + unsigned idx2 = idx1 + dx; + + for (unsigned i = idx1; i < idx2; i ++) + { + if (!mTiles[i]) + mTiles[i] = new MapObjectList(); + mTiles[i]->objects.push_back(MapObject(type, name)); + } + } +} + +MapObjectList *ObjectsLayer::getAt(unsigned x, unsigned y) +{ + if (x >= mWidth || y >= mHeight) + return nullptr; + return mTiles[x + y * mWidth]; +} + +MapRowVertexes::~MapRowVertexes() +{ + delete_all(images); + images.clear(); +} diff --git a/src/maplayer.h b/src/maplayer.h new file mode 100644 index 000000000..861ef1318 --- /dev/null +++ b/src/maplayer.h @@ -0,0 +1,299 @@ +/* + * The ManaPlus Client + * Copyright (C) 2004-2009 The Mana World Development Team + * Copyright (C) 2009-2010 The Mana Developers + * Copyright (C) 2011-2012 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 MAPLAYER_H +#define MAPLAYER_H + +#include "actor.h" +#include "configlistener.h" +#include "position.h" +#include "properties.h" + +#include <string> +#include <vector> + +class MapItem; +class MapLayer; +class SpecialLayer; +class ImageVertexes; + +typedef std::vector<ImageVertexes*> MepRowImages; + +class MapRowVertexes +{ + public: + MapRowVertexes() + { + images.reserve(30); + } + + ~MapRowVertexes(); + + MepRowImages images; +}; + +class MapObject +{ + public: + MapObject(int type0, std::string data0) + { + type = type0; + data = data0; + } + + int type; + std::string data; +}; + +class MapObjectList +{ + public: + std::vector<MapObject> objects; +}; + +/** + * A map layer. Stores a grid of tiles and their offset, and implements layer + * rendering. + */ +class MapLayer: public ConfigListener +{ + public: + friend class Map; + + /** + * Constructor, taking layer origin, size and whether this layer is the + * fringe layer. The fringe layer is the layer that draws the actors. + * There can be only one fringe layer per map. + */ + MapLayer(int x, int y, int width, int height, bool isFringeLayer); + + /** + * Destructor. + */ + ~MapLayer(); + + /** + * Set tile image, with x and y in layer coordinates. + */ + void setTile(int x, int y, Image *img); + + /** + * Set tile image with x + y * width already known. + */ + void setTile(int index, Image *img) + { mTiles[index] = img; } + + /** + * Draws this layer to the given graphics context. The coordinates are + * expected to be in map range and will be translated to local layer + * coordinates and clipped to the layer's dimensions. + * + * The given actors are only drawn when this layer is the fringe + * layer. + */ + void draw(Graphics *graphics, + int startX, int startY, + int endX, int endY, + int scrollX, int scrollY, + int mDebugFlags) const; + + void drawOGL(Graphics *graphics); + + void drawSDL(Graphics *graphics); + + void updateOGL(Graphics *graphics, + int startX, int startY, + int endX, int endY, + int scrollX, int scrollY, + int mDebugFlags); + + void updateSDL(Graphics *graphics, + int startX, int startY, + int endX, int endY, + int scrollX, int scrollY, + int mDebugFlags); + + void drawFringe(Graphics *graphics, + int startX, int startY, + int endX, int endY, + int scrollX, int scrollY, + const Actors *actors, + int mDebugFlags, int yFix) const; + + bool isFringeLayer() const + { return mIsFringeLayer; } + + void setSpecialLayer(SpecialLayer *val) + { mSpecialLayer = val; } + + void setTempLayer(SpecialLayer *val) + { mTempLayer = val; } + + int getWidth() const + { return mWidth; } + + int getHeight() const + { return mHeight; } + +// void setTileInfo(int x, int y, int width, int cnt); + +// void getTileInfo(int x, int y, int &width, int &cnt) const; + + void optionChanged(const std::string &value); + + int getTileDrawWidth(Image *img, int endX, int &width) const; + +// void initTileInfo(); + + private: + int mX, mY; + int mWidth, mHeight; + bool mIsFringeLayer; /**< Whether the actors are drawn. */ + bool mHighlightAttackRange; + Image **mTiles; +// int *mTilesWidth; +// int *mTilesCount; + SpecialLayer *mSpecialLayer; + SpecialLayer *mTempLayer; + typedef std::vector<MapRowVertexes*> MapRows; + MapRows mTempRows; +}; + +class SpecialLayer +{ + public: + friend class Map; + friend class MapLayer; + + SpecialLayer(int width, int height, bool drawSprites = false); + + ~SpecialLayer(); + + void draw(Graphics *graphics, int startX, int startY, + int endX, int endY, int scrollX, int scrollY); + + MapItem* getTile(int x, int y) const; + + void setTile(int x, int y, MapItem* item); + + void setTile(int x, int y, int type); + + void addRoad(Path road); + + void clean(); + + void itemDraw(Graphics *graphics, int x, int y, + int scrollX, int scrollY); + + private: + int mWidth, mHeight; + bool mDrawSprites; + MapItem **mTiles; +}; + +class MapItem +{ + public: + friend class Map; + friend class MapLayer; + + enum ItemType + { + EMPTY = 0, + HOME = 1, + ROAD = 2, + CROSS = 3, + ARROW_UP = 4, + ARROW_DOWN = 5, + ARROW_LEFT = 6, + ARROW_RIGHT = 7, + PORTAL = 8, + MUSIC = 9, + ATTACK = 10, + PRIORITY = 11, + IGNORE_ = 12, + SEPARATOR = 13 + }; + + MapItem(); + + MapItem(int type); + + MapItem(int type, std::string comment); + + MapItem(int type, std::string comment, int x, int y); + + ~MapItem(); + + int getType() const + { return mType; } + + void setType(int type); + + void setPos(int x, int y); + + int getX() const + { return mX; } + + int getY() const + { return mY; } + + std::string &getComment() + { return mComment; } + + void setComment(std::string comment) + { mComment = comment; } + + std::string &getName() + { return mName; } + + void setName(std::string name) + { mName = name; } + + void draw(Graphics *graphics, int x, int y, int dx, int dy); + + private: + int mType; + Image *mImage; + std::string mComment; + std::string mName; + int mX; + int mY; +}; + +class ObjectsLayer +{ + public: + ObjectsLayer(unsigned width, unsigned height); + ~ObjectsLayer(); + + void addObject(std::string name, int type, unsigned x, unsigned y, + unsigned dx, unsigned dy); + + MapObjectList *getAt(unsigned x, unsigned y); + private: + MapObjectList **mTiles; + unsigned mWidth; + unsigned mHeight; +}; + +#endif diff --git a/src/mumblemanager.cpp b/src/mumblemanager.cpp index 100b600b4..7e857a52b 100644 --- a/src/mumblemanager.cpp +++ b/src/mumblemanager.cpp @@ -182,7 +182,7 @@ void MumbleManager::setAction(int action) if (!mLinkedMem) return; - switch(action) + switch (action) { case 0: /* STAND */ case 1: /* WALK */ @@ -228,7 +228,7 @@ void MumbleManager::setPos(int tileX, int tileY, int direction) // Unit vector pointing out of the avatars eyes // (here Front looks into scene). - switch(direction) + switch (direction) { case 4: /* UP */ mLinkedMemCache.fAvatarFront[0] = 0.0f; diff --git a/src/net/charhandler.h b/src/net/charhandler.h index 492e27e55..cee319719 100644 --- a/src/net/charhandler.h +++ b/src/net/charhandler.h @@ -26,8 +26,6 @@ #include "localplayer.h" #include "playerinfo.h" -#include "net/logindata.h" - #include <iosfwd> #include <vector> diff --git a/src/net/ea/beinghandler.cpp b/src/net/ea/beinghandler.cpp index 84bd03bb1..d9e7e7506 100644 --- a/src/net/ea/beinghandler.cpp +++ b/src/net/ea/beinghandler.cpp @@ -511,6 +511,12 @@ void BeingHandler::processBeingAction(Net::MessageIn &msg) } break; + case 0x01: // dead + break; + // tmw server can send here garbage? +// if (srcBeing) +// srcBeing->setAction(Being::DEAD); + case 0x02: // Sit if (srcBeing) { diff --git a/src/net/ea/gamehandler.cpp b/src/net/ea/gamehandler.cpp index b7566e271..6d021d6a9 100644 --- a/src/net/ea/gamehandler.cpp +++ b/src/net/ea/gamehandler.cpp @@ -43,20 +43,20 @@ GameHandler::GameHandler() { mCharID = 0; - listen(Mana::CHANNEL_GAME); + listen(CHANNEL_GAME); } -void GameHandler::processEvent(Mana::Channels channel, - const Mana::Event &event) +void GameHandler::processEvent(Channels channel, + const Event &event) { - if (channel == Mana::CHANNEL_GAME) + if (channel == CHANNEL_GAME) { - if (event.getName() == Mana::EVENT_ENGINESINITALIZED) + if (event.getName() == EVENT_ENGINESINITALIZED) { if (mMap != "") Game::instance()->changeMap(mMap); } - else if (event.getName() == Mana::EVENT_MAPLOADED) + else if (event.getName() == EVENT_MAPLOADED) { mapLoadedEvent(); } diff --git a/src/net/ea/gamehandler.h b/src/net/ea/gamehandler.h index 248175617..59cb148c4 100644 --- a/src/net/ea/gamehandler.h +++ b/src/net/ea/gamehandler.h @@ -32,13 +32,13 @@ namespace Ea { -class GameHandler : public Net::GameHandler, public Mana::Listener +class GameHandler : public Net::GameHandler, public Listener { public: GameHandler(); - virtual void processEvent(Mana::Channels channel, - const Mana::Event &event); + virtual void processEvent(Channels channel, + const Event &event); virtual void who(); diff --git a/src/net/ea/gui/partytab.cpp b/src/net/ea/gui/partytab.cpp index cf62af459..d5e344ac2 100644 --- a/src/net/ea/gui/partytab.cpp +++ b/src/net/ea/gui/partytab.cpp @@ -242,4 +242,3 @@ void PartyTab::saveToLogFile(std::string &msg) } } // namespace Ea - diff --git a/src/net/ea/inventoryhandler.cpp b/src/net/ea/inventoryhandler.cpp index 4c4fb760c..d870eff38 100644 --- a/src/net/ea/inventoryhandler.cpp +++ b/src/net/ea/inventoryhandler.cpp @@ -330,7 +330,7 @@ void InventoryHandler::processPlayerInventoryAdd(Net::MessageIn &msg) { Item *item = inventory->getItem(index); - if (item && item->getId() == itemId) + if (item && item->getId() == itemId) amount += item->getQuantity(); if (serverVersion < 1 && identified > 1) diff --git a/src/net/ea/itemhandler.cpp b/src/net/ea/itemhandler.cpp index e08fe2cd1..7a6ee2743 100644 --- a/src/net/ea/itemhandler.cpp +++ b/src/net/ea/itemhandler.cpp @@ -35,28 +35,39 @@ ItemHandler::ItemHandler() { } -void ItemHandler::processItemVisible(Net::MessageIn &msg, bool isDrop) +void ItemHandler::processItemVisible(Net::MessageIn &msg) { int id = msg.readInt32(); int itemId = msg.readInt16(); unsigned char identify = msg.readInt8(); // identify flag int x = msg.readInt16(); int y = msg.readInt16(); - int amount1 = msg.readInt16(); - int amount2 = msg.readInt16(); + int amount = msg.readInt16(); + int subX = msg.readInt8() + 16 - 8; + int subY = msg.readInt8() + 32 - 8; if (actorSpriteManager) { - if (!isDrop) - { - actorSpriteManager->createItem(id, itemId, - x, y, amount1, identify); - } - else - { - actorSpriteManager->createItem(id, itemId, - x, y, amount2, identify); - } + actorSpriteManager->createItem(id, itemId, + x, y, amount, identify, subX, subY); + } +} + +void ItemHandler::processItemDropped(Net::MessageIn &msg) +{ + int id = msg.readInt32(); + int itemId = msg.readInt16(); + unsigned char identify = msg.readInt8(); // identify flag + int x = msg.readInt16(); + int y = msg.readInt16(); + int subX = msg.readInt8() + 16 - 8; + int subY = msg.readInt8() + 32 - 8; + int amount = msg.readInt16(); + + if (actorSpriteManager) + { + actorSpriteManager->createItem(id, itemId, + x, y, amount, identify, subX, subY); } } diff --git a/src/net/ea/itemhandler.h b/src/net/ea/itemhandler.h index 1d0747c61..d5c268d2e 100644 --- a/src/net/ea/itemhandler.h +++ b/src/net/ea/itemhandler.h @@ -34,9 +34,11 @@ class ItemHandler public: ItemHandler(); - void processItemVisible(Net::MessageIn &msg, bool isDrop); + void processItemVisible(Net::MessageIn &msg); void processItemRemove(Net::MessageIn &msg); + + void processItemDropped(Net::MessageIn &msg); }; } // namespace Ea diff --git a/src/net/ea/loginhandler.cpp b/src/net/ea/loginhandler.cpp index 291a92906..39a920f03 100644 --- a/src/net/ea/loginhandler.cpp +++ b/src/net/ea/loginhandler.cpp @@ -28,6 +28,7 @@ #include "utils/dtor.h" #include "utils/gettext.h" +#include "utils/paths.h" #include "debug.h" diff --git a/src/net/ea/playerhandler.cpp b/src/net/ea/playerhandler.cpp index 76a7b0dbc..27aa4da80 100644 --- a/src/net/ea/playerhandler.cpp +++ b/src/net/ea/playerhandler.cpp @@ -22,6 +22,7 @@ #include "net/ea/playerhandler.h" +#include "localplayer.h" #include "logger.h" #include "party.h" #include "playerinfo.h" diff --git a/src/net/manaserv/chathandler.cpp b/src/net/manaserv/chathandler.cpp index f0a23127c..12451e6f6 100644 --- a/src/net/manaserv/chathandler.cpp +++ b/src/net/manaserv/chathandler.cpp @@ -293,7 +293,7 @@ void ChatHandler::handleChannelEvent(Net::MessageIn &msg) if (channel) { - switch(eventId) + switch (eventId) { case CHAT_EVENT_NEW_PLAYER: channel->getTab()->chatLog(strprintf(_("%s entered the " diff --git a/src/net/manaserv/generalhandler.cpp b/src/net/manaserv/generalhandler.cpp index 584faa368..d95c98d23 100644 --- a/src/net/manaserv/generalhandler.cpp +++ b/src/net/manaserv/generalhandler.cpp @@ -93,8 +93,8 @@ GeneralHandler::GeneralHandler(): generalHandler = this; - listen(Mana::CHANNEL_CLIENT); - listen(Mana::CHANNEL_GAME); + listen(CHANNEL_CLIENT); + listen(CHANNEL_GAME); } void GeneralHandler::load() @@ -176,10 +176,10 @@ void GeneralHandler::clearHandlers() clearNetworkHandlers(); } -void GeneralHandler::processEvent(Mana::Channels channel, - const Mana::Event &event) +void GeneralHandler::processEvent(Channels channel, + const Event &event) { - if (channel == Mana::CHANNEL_CLIENT) + if (channel == CHANNEL_CLIENT) { int newState = event.getInt("newState"); @@ -195,9 +195,9 @@ void GeneralHandler::processEvent(Mana::Channels channel, Attributes::informItemDB(); } } - else if (channel == Mana::CHANNEL_GAME) + else if (channel == CHANNEL_GAME) { - if (event.getName() == Mana::EVENT_GUIWINDOWSLOADED) + if (event.getName() == EVENT_GUIWINDOWSLOADED) { inventoryWindow->setSplitAllowed(true); skillDialog->loadSkills("mana-skills.xml"); diff --git a/src/net/manaserv/generalhandler.h b/src/net/manaserv/generalhandler.h index fcb28c846..6ea5c7845 100644 --- a/src/net/manaserv/generalhandler.h +++ b/src/net/manaserv/generalhandler.h @@ -33,7 +33,7 @@ namespace ManaServ { -class GeneralHandler : public Net::GeneralHandler, public Mana::Listener +class GeneralHandler : public Net::GeneralHandler, public Listener { public: GeneralHandler(); @@ -50,7 +50,7 @@ class GeneralHandler : public Net::GeneralHandler, public Mana::Listener void clearHandlers(); - void processEvent(Mana::Channels channel, const Mana::Event &event); + void processEvent(Channels channel, const Event &event); protected: MessageHandlerPtr mBeingHandler; diff --git a/src/net/manaserv/guildhandler.cpp b/src/net/manaserv/guildhandler.cpp index dfd2ed3cf..aa82d6dcd 100644 --- a/src/net/manaserv/guildhandler.cpp +++ b/src/net/manaserv/guildhandler.cpp @@ -153,7 +153,7 @@ void GuildHandler::handleMessage(Net::MessageIn &msg) Guild *guild = player_node->getGuild(guildId); if (guild) { - switch(eventId) + switch (eventId) { case GUILD_EVENT_NEW_PLAYER: member = guild->addMember(name); diff --git a/src/net/manaserv/playerhandler.cpp b/src/net/manaserv/playerhandler.cpp index aa79d4d41..b2609cf02 100644 --- a/src/net/manaserv/playerhandler.cpp +++ b/src/net/manaserv/playerhandler.cpp @@ -151,8 +151,7 @@ void PlayerHandler::handleMessage(Net::MessageIn &msg) PlayerInfo::setAttribute(CORR_POINTS, msg.readInt16()); Particle* effect = particleEngine->addEffect( paths.getStringValue("particles") - + paths.getStringValue("levelUpEffectFile") - , 0, 0); + + paths.getStringValue("levelUpEffectFile"), 0, 0); player_node->controlParticle(effect); } break; diff --git a/src/net/net.cpp b/src/net/net.cpp index 713b6aa7e..75bc35b72 100644 --- a/src/net/net.cpp +++ b/src/net/net.cpp @@ -202,4 +202,3 @@ ServerInfo::Type getNetworkType() } } // namespace Net - diff --git a/src/net/playerhandler.h b/src/net/playerhandler.h index 6ae912102..aa5d2b793 100644 --- a/src/net/playerhandler.h +++ b/src/net/playerhandler.h @@ -25,7 +25,6 @@ #include "being.h" #include "flooritem.h" -#include "localplayer.h" namespace Net { diff --git a/src/net/tmwa/generalhandler.cpp b/src/net/tmwa/generalhandler.cpp index a666fa5f4..77c91e1dd 100644 --- a/src/net/tmwa/generalhandler.cpp +++ b/src/net/tmwa/generalhandler.cpp @@ -244,12 +244,12 @@ void GeneralHandler::clearHandlers() mNetwork->clearHandlers(); } -void GeneralHandler::processEvent(Mana::Channels channel, - const Mana::Event &event) +void GeneralHandler::processEvent(Channels channel, + const Event &event) { - if (channel == Mana::CHANNEL_GAME) + if (channel == CHANNEL_GAME) { - if (event.getName() == Mana::EVENT_GUIWINDOWSLOADED) + if (event.getName() == EVENT_GUIWINDOWSLOADED) { if (inventoryWindow) inventoryWindow->setSplitAllowed(false); @@ -288,7 +288,7 @@ void GeneralHandler::processEvent(Mana::Channels channel, statusWindow->addAttribute(ATTACK_SPEED, _("Damage per sec."), false, ""); } - else if (event.getName() == Mana::EVENT_GUIWINDOWSUNLOADING) + else if (event.getName() == EVENT_GUIWINDOWSUNLOADING) { if (socialWindow) { diff --git a/src/net/tmwa/generalhandler.h b/src/net/tmwa/generalhandler.h index b250ddfd4..73f7a0e1b 100644 --- a/src/net/tmwa/generalhandler.h +++ b/src/net/tmwa/generalhandler.h @@ -34,7 +34,7 @@ namespace TmwAthena { class GeneralHandler : public MessageHandler, public Net::GeneralHandler, - public Mana::Listener + public Listener { public: GeneralHandler(); @@ -53,7 +53,7 @@ class GeneralHandler : public MessageHandler, public Net::GeneralHandler, void clearHandlers(); - void processEvent(Mana::Channels channel, const Mana::Event &event); + void processEvent(Channels channel, const Event &event); void reloadPartially(); diff --git a/src/net/tmwa/gui/guildtab.cpp b/src/net/tmwa/gui/guildtab.cpp index af90f5c6b..496ba64f5 100644 --- a/src/net/tmwa/gui/guildtab.cpp +++ b/src/net/tmwa/gui/guildtab.cpp @@ -53,4 +53,3 @@ GuildTab::~GuildTab() } } // namespace TmwAthena - diff --git a/src/net/tmwa/gui/partytab.cpp b/src/net/tmwa/gui/partytab.cpp index d0738e79c..02bcfd54f 100644 --- a/src/net/tmwa/gui/partytab.cpp +++ b/src/net/tmwa/gui/partytab.cpp @@ -56,4 +56,3 @@ PartyTab::~PartyTab() } } // namespace TmwAthena - diff --git a/src/net/tmwa/itemhandler.cpp b/src/net/tmwa/itemhandler.cpp index ce03044c7..d84d2f38d 100644 --- a/src/net/tmwa/itemhandler.cpp +++ b/src/net/tmwa/itemhandler.cpp @@ -48,9 +48,12 @@ void ItemHandler::handleMessage(Net::MessageIn &msg) switch (msg.getId()) { case SMSG_ITEM_VISIBLE: + processItemVisible(msg); + break; + case SMSG_ITEM_DROPPED: - processItemVisible(msg, msg.getId() == SMSG_ITEM_DROPPED); - break; + processItemDropped(msg); + break; case SMSG_ITEM_REMOVE: processItemRemove(msg); diff --git a/src/net/tmwa/network.cpp b/src/net/tmwa/network.cpp index 31329eafb..6e9e367c0 100644 --- a/src/net/tmwa/network.cpp +++ b/src/net/tmwa/network.cpp @@ -133,8 +133,8 @@ Network::~Network() mMutex = nullptr; mInstance = nullptr; - delete[] mInBuffer; - delete[] mOutBuffer; + delete []mInBuffer; + delete []mOutBuffer; SDLNet_Quit(); } diff --git a/src/net/tmwa/npchandler.cpp b/src/net/tmwa/npchandler.cpp index d86c64a96..837b83337 100644 --- a/src/net/tmwa/npchandler.cpp +++ b/src/net/tmwa/npchandler.cpp @@ -35,6 +35,8 @@ #include "net/ea/eaprotocol.h" +#include "utils/langs.h" + #include "debug.h" extern Net::NpcHandler *npcHandler; diff --git a/src/net/tmwa/playerhandler.cpp b/src/net/tmwa/playerhandler.cpp index 16e833ec9..bfe9eea42 100644 --- a/src/net/tmwa/playerhandler.cpp +++ b/src/net/tmwa/playerhandler.cpp @@ -23,6 +23,7 @@ #include "net/tmwa/playerhandler.h" #include "configuration.h" +#include "client.h" #include "logger.h" #include "net/messagein.h" diff --git a/src/openglgraphics.cpp b/src/openglgraphics.cpp index 2c3d914b0..bcf46e18b 100644 --- a/src/openglgraphics.cpp +++ b/src/openglgraphics.cpp @@ -61,9 +61,9 @@ OpenGLGraphics::OpenGLGraphics(): OpenGLGraphics::~OpenGLGraphics() { - delete[] mFloatTexArray; - delete[] mIntTexArray; - delete[] mIntVertArray; + delete [] mFloatTexArray; + delete [] mIntTexArray; + delete [] mIntVertArray; } void OpenGLGraphics::setSync(bool sync) diff --git a/src/playerinfo.cpp b/src/playerinfo.cpp index 0b9d16de2..6dd7bdc06 100644 --- a/src/playerinfo.cpp +++ b/src/playerinfo.cpp @@ -59,11 +59,11 @@ int mLevelProgress = 0; void triggerAttr(int id, int old) { - Mana::Event event(Mana::EVENT_UPDATEATTRIBUTE); + Event event(EVENT_UPDATEATTRIBUTE); event.setInt("id", id); event.setInt("oldValue", old); event.setInt("newValue", mData.mAttributes.find(id)->second); - Mana::Event::trigger(Mana::CHANNEL_ATTRIBUTES, event); + Event::trigger(CHANNEL_ATTRIBUTES, event); } void triggerStat(int id, const std::string &changed, int old1, int old2) @@ -72,7 +72,7 @@ void triggerStat(int id, const std::string &changed, int old1, int old2) if (it == mData.mStats.end()) return; - Mana::Event event(Mana::EVENT_UPDATESTAT); + Event event(EVENT_UPDATESTAT); event.setInt("id", id); event.setInt("base", it->second.base); event.setInt("mod", it->second.mod); @@ -81,7 +81,7 @@ void triggerStat(int id, const std::string &changed, int old1, int old2) event.setString("changed", changed); event.setInt("oldValue1", old1); event.setInt("oldValue2", old2); - Mana::Event::trigger(Mana::CHANNEL_ATTRIBUTES, event); + Event::trigger(CHANNEL_ATTRIBUTES, event); } // --- Attributes ------------------------------------------------------------- @@ -280,9 +280,9 @@ void setTrading(bool trading) if (notify) { - Mana::Event event(Mana::EVENT_TRADING); + Event event(EVENT_TRADING); event.setInt("trading", trading); - Mana::Event::trigger(Mana::CHANNEL_STATUS, event); + Event::trigger(CHANNEL_STATUS, event); } } @@ -303,20 +303,20 @@ void updateAttrs() } } -class PlayerInfoListener : Mana::Listener +class PlayerInfoListener : Listener { public: PlayerInfoListener() { - listen(Mana::CHANNEL_CLIENT); - listen(Mana::CHANNEL_GAME); + listen(CHANNEL_CLIENT); + listen(CHANNEL_GAME); } - void processEvent(Mana::Channels channel, const Mana::Event &event) + void processEvent(Channels channel, const Event &event) { - if (channel == Mana::CHANNEL_CLIENT) + if (channel == CHANNEL_CLIENT) { - if (event.getName() == Mana::EVENT_STATECHANGE) + if (event.getName() == EVENT_STATECHANGE) { int newState = event.getInt("newState"); @@ -330,9 +330,9 @@ public: } } } - else if (channel == Mana::CHANNEL_GAME) + else if (channel == CHANNEL_GAME) { - if (event.getName() == Mana::EVENT_DESTRUCTED) + if (event.getName() == EVENT_DESTRUCTED) { delete mInventory; mInventory = nullptr; diff --git a/src/playerrelations.cpp b/src/playerrelations.cpp index 6b5cb0199..38062c352 100644 --- a/src/playerrelations.cpp +++ b/src/playerrelations.cpp @@ -103,7 +103,8 @@ class PlayerConfSerialiser : static PlayerConfSerialiser player_conf_serialiser; // stateless singleton -const unsigned int PlayerRelation::RELATION_PERMISSIONS[RELATIONS_NR] = { +const unsigned int PlayerRelation::RELATION_PERMISSIONS[RELATIONS_NR] = +{ /* NEUTRAL */ 0, // we always fall back to the defaults anyway /* FRIEND */ EMOTE | SPEECH_FLOAT | SPEECH_LOG | WHISPER | TRADE, /* DISREGARDED*/ EMOTE | SPEECH_FLOAT, @@ -531,8 +532,6 @@ public: Uint8 mEmotion; }; - - std::vector<PlayerIgnoreStrategy *> * PlayerRelationsManager::getPlayerIgnoreStrategies() { diff --git a/src/resources/colordb.cpp b/src/resources/colordb.cpp index 2ddf27ac3..66c8de0a2 100644 --- a/src/resources/colordb.cpp +++ b/src/resources/colordb.cpp @@ -95,7 +95,7 @@ void ColorDB::loadHair() if (colors.find(id) != colors.end()) logger->log("ColorDB: Redefinition of dye ID %d", id); - colors[id] = ItemColor(id, XML::getProperty(node, "name", ""), + colors[id] = ItemColor(id, XML::langProperty(node, "name", ""), XML::getProperty(node, hairXml ? "value" : "dye", "#FFFFFF")); } } @@ -135,7 +135,7 @@ void ColorDB::loadColorLists() if (xmlNameEqual(colorNode, "color")) { ItemColor c(XML::getProperty(colorNode, "id", -1), - XML::getProperty(colorNode, "name", ""), + XML::langProperty(colorNode, "name", ""), XML::getProperty(colorNode, "value", "")); if (c.id > -1) colors[c.id] = c; diff --git a/src/resources/dye.cpp b/src/resources/dye.cpp index 6800c5170..eec5916c4 100644 --- a/src/resources/dye.cpp +++ b/src/resources/dye.cpp @@ -309,7 +309,7 @@ void Dye::instantiate(std::string &target, const std::string &palettes) { s << palettes.substr(pal_pos); s << target.substr(next_pos); - pal_pos = std::string::npos; + //pal_pos = std::string::npos; break; } s << palettes.substr(pal_pos, pal_next_pos - pal_pos); diff --git a/src/resources/emotedb.cpp b/src/resources/emotedb.cpp index 07e192cd4..d6c01af6d 100644 --- a/src/resources/emotedb.cpp +++ b/src/resources/emotedb.cpp @@ -93,7 +93,8 @@ void EmoteDB::load() spriteNode->xmlChildrenNode->content); currentSprite->sprite = AnimatedSprite::load(file, XML::getProperty(spriteNode, "variant", 0)); - currentSprite->name = XML::getProperty(spriteNode, "name", ""); + currentSprite->name = XML::langProperty( + spriteNode, "name", ""); currentInfo->sprites.push_back(currentSprite); } else if (xmlNameEqual(spriteNode, "particlefx")) @@ -147,7 +148,8 @@ void EmoteDB::load() spriteNode->xmlChildrenNode->content); currentSprite->sprite = AnimatedSprite::load(file, XML::getProperty(spriteNode, "variant", 0)); - currentSprite->name = XML::getProperty(spriteNode, "name", ""); + currentSprite->name = XML::langProperty( + spriteNode, "name", ""); currentInfo->sprites.push_back(currentSprite); } else if (xmlNameEqual(spriteNode, "particlefx")) diff --git a/src/resources/image.cpp b/src/resources/image.cpp index 6f9042029..1e2bd6b51 100644 --- a/src/resources/image.cpp +++ b/src/resources/image.cpp @@ -250,14 +250,14 @@ Image *Image::createTextSurface(SDL_Surface *tmpImage, float alpha) // We also delete the alpha channel since // it's not used. - delete[] alphaChannel; + delete [] alphaChannel; alphaChannel = nullptr; } if (!image) { logger->log1("Error: Image convert failed."); - delete[] alphaChannel; + delete [] alphaChannel; return nullptr; } @@ -295,7 +295,7 @@ void Image::unload() SDL_FreeSurface(mSDLSurface); mSDLSurface = nullptr; - delete[] mAlphaChannel; + delete [] mAlphaChannel; mAlphaChannel = nullptr; } @@ -689,14 +689,14 @@ Image *Image::_SDLload(SDL_Surface *tmpImage) // We also delete the alpha channel since // it's not used. - delete[] alphaChannel; + delete [] alphaChannel; alphaChannel = nullptr; } if (!image) { logger->log1("Error: Image convert failed."); - delete[] alphaChannel; + delete [] alphaChannel; return nullptr; } @@ -885,10 +885,20 @@ SubImage::SubImage(Image *parent, SDL_Surface *image, mBounds.y = static_cast<short>(y); mBounds.w = static_cast<Uint16>(width); mBounds.h = static_cast<Uint16>(height); - mInternalBounds.x = mParent->mBounds.x; - mInternalBounds.y = mParent->mBounds.y; - mInternalBounds.w = mParent->mBounds.w; - mInternalBounds.h = mParent->mBounds.h; + if (mParent) + { + mInternalBounds.x = mParent->mBounds.x; + mInternalBounds.y = mParent->mBounds.y; + mInternalBounds.w = mParent->mBounds.w; + mInternalBounds.h = mParent->mBounds.h; + } + else + { + mInternalBounds.x = 0; + mInternalBounds.y = 0; + mInternalBounds.w = 1; + mInternalBounds.h = 1; + } mUseAlphaCache = false; } diff --git a/src/resources/itemdb.cpp b/src/resources/itemdb.cpp index 5fa68a88f..e81700ecc 100644 --- a/src/resources/itemdb.cpp +++ b/src/resources/itemdb.cpp @@ -202,10 +202,10 @@ void ItemDB::load() int weight = XML::getProperty(node, "weight", 0); int view = XML::getProperty(node, "view", 0); - std::string name = XML::getProperty(node, "name", ""); + std::string name = XML::langProperty(node, "name", ""); std::string image = XML::getProperty(node, "image", ""); std::string floor = XML::getProperty(node, "floor", ""); - std::string description = XML::getProperty(node, "description", ""); + std::string description = XML::langProperty(node, "description", ""); std::string attackAction = XML::getProperty(node, "attack-action", ""); std::string drawBefore = XML::getProperty(node, "drawBefore", ""); std::string drawAfter = XML::getProperty(node, "drawAfter", ""); @@ -316,7 +316,7 @@ void ItemDB::load() effect += " / "; effect += strprintf(it->format.c_str(), value); } - std::string temp = XML::getProperty(node, "effect", ""); + std::string temp = XML::langProperty(node, "effect", ""); if (!effect.empty() && !temp.empty()) effect += " / "; effect += temp; diff --git a/src/resources/mapreader.cpp b/src/resources/mapreader.cpp index 8d71779f2..19f9ab3f2 100644 --- a/src/resources/mapreader.cpp +++ b/src/resources/mapreader.cpp @@ -22,9 +22,11 @@ #include "resources/mapreader.h" +#include "client.h" #include "configuration.h" #include "logger.h" #include "map.h" +#include "maplayer.h" #include "tileset.h" #include "resources/animation.h" @@ -459,12 +461,6 @@ void MapReader::readLayer(XmlNodePtr node, Map *map) MapLayer *layer = nullptr; - if (!isCollisionLayer) - { - layer = new MapLayer(offsetX, offsetY, w, h, isFringeLayer); - map->addLayer(layer); - } - logger->log("- Loading layer \"%s\"", name.c_str()); int x = 0; int y = 0; @@ -472,9 +468,33 @@ void MapReader::readLayer(XmlNodePtr node, Map *map) // Load the tile data for_each_xml_child_node(childNode, node) { + if (serverVersion > 0 && xmlNameEqual(childNode, "properties")) + { + for_each_xml_child_node(prop, childNode) + { + if (!xmlNameEqual(prop, "property")) + continue; + const std::string pname = XML::getProperty(prop, "name", ""); + const std::string value = XML::getProperty(prop, "value", ""); + // ignoring any layer if property Hidden is 1 + if (pname == "Hidden" && value == "1") + return; + if (pname == "Version" && value > CHECK_VERSION) + return; + if (pname == "NotVersion" && value <= CHECK_VERSION) + return; + } + } + if (!xmlNameEqual(childNode, "data")) continue; + if (!isCollisionLayer) + { + layer = new MapLayer(offsetX, offsetY, w, h, isFringeLayer); + map->addLayer(layer); + } + const std::string encoding = XML::getProperty(childNode, "encoding", ""); const std::string compression = @@ -502,7 +522,7 @@ void MapReader::readLayer(XmlNodePtr node, Map *map) const char *charStart = reinterpret_cast<const char*>(xmlChars); if (!charStart) { - delete[] charData; + delete [] charData; return; } @@ -525,7 +545,7 @@ void MapReader::readLayer(XmlNodePtr node, Map *map) static_cast<int>(strlen(reinterpret_cast<char*>( charData))), &binLen); - delete[] charData; + delete [] charData; xmlFree(xmlChars); if (binData) diff --git a/src/resources/monsterdb.cpp b/src/resources/monsterdb.cpp index 9d295db35..2c9448fc3 100644 --- a/src/resources/monsterdb.cpp +++ b/src/resources/monsterdb.cpp @@ -80,7 +80,7 @@ void MonsterDB::load() | Map::BLOCKMASK_CHARACTER | Map::BLOCKMASK_MONSTER); currentInfo->setBlockType(Map::BLOCKTYPE_MONSTER); - currentInfo->setName(XML::getProperty( + currentInfo->setName(XML::langProperty( monsterNode, "name", _("unnamed"))); currentInfo->setTargetCursorSize(XML::getProperty(monsterNode, diff --git a/src/resources/resourcemanager.cpp b/src/resources/resourcemanager.cpp index c26526b97..ec8764a44 100644 --- a/src/resources/resourcemanager.cpp +++ b/src/resources/resourcemanager.cpp @@ -329,12 +329,12 @@ std::string ResourceManager::getPath(const std::string &file) // if the file is not in the search path, then its nullptr if (tmp) { - path = std::string(tmp) + "/" + file; + path = std::string(tmp) + PHYSFS_getDirSeparator() + file; } else { // if not found in search path return the default path - path = Client::getPackageDirectory() + "/" + file; + path = Client::getPackageDirectory() + PHYSFS_getDirSeparator() + file; } return path; @@ -404,19 +404,19 @@ struct ResourceLoader { if (!v) return nullptr; - ResourceLoader *l = static_cast< ResourceLoader * >(v); - SDL_RWops *rw = PHYSFSRWOPS_openRead(l->path.c_str()); + ResourceLoader *rl = static_cast< ResourceLoader * >(v); + SDL_RWops *rw = PHYSFSRWOPS_openRead(rl->path.c_str()); if (!rw) return nullptr; - Resource *res = l->fun(rw); + Resource *res = rl->fun(rw); return res; } }; Resource *ResourceManager::load(const std::string &path, loader fun) { - ResourceLoader l = { this, path, fun }; - return get(path, ResourceLoader::load, &l); + ResourceLoader rl = { this, path, fun }; + return get(path, ResourceLoader::load, &rl); } Music *ResourceManager::getMusic(const std::string &idPath) @@ -438,11 +438,11 @@ struct DyedImageLoader if (!v) return nullptr; - DyedImageLoader *l = static_cast< DyedImageLoader * >(v); - if (!l->manager) + DyedImageLoader *rl = static_cast< DyedImageLoader * >(v); + if (!rl->manager) return nullptr; - std::string path = l->path; + std::string path = rl->path; std::string::size_type p = path.find('|'); Dye *d = nullptr; if (p != std::string::npos) @@ -465,8 +465,8 @@ struct DyedImageLoader Image *ResourceManager::getImage(const std::string &idPath) { - DyedImageLoader l = { this, idPath }; - return static_cast<Image*>(get(idPath, DyedImageLoader::load, &l)); + DyedImageLoader rl = { this, idPath }; + return static_cast<Image*>(get(idPath, DyedImageLoader::load, &rl)); } /* @@ -475,8 +475,8 @@ Image *ResourceManager::getSkinImage(const std::string &idPath) if (mSelectedSkin.empty()) return getImage(idPath); - DyedImageLoader l = { this, mSelectedSkin + idPath }; - void *ptr = get(idPath, DyedImageLoader::load, &l); + DyedImageLoader rl = { this, mSelectedSkin + idPath }; + void *ptr = get(idPath, DyedImageLoader::load, &rl); if (ptr) return static_cast<Image*>(ptr); else @@ -494,14 +494,14 @@ struct ImageSetLoader if (!v) return nullptr; - ImageSetLoader *l = static_cast< ImageSetLoader * >(v); - if (!l->manager) + ImageSetLoader *rl = static_cast< ImageSetLoader * >(v); + if (!rl->manager) return nullptr; - Image *img = l->manager->getImage(l->path); + Image *img = rl->manager->getImage(rl->path); if (!img) return nullptr; - ImageSet *res = new ImageSet(img, l->w, l->h); + ImageSet *res = new ImageSet(img, rl->w, rl->h); img->decRef(); return res; } @@ -510,10 +510,10 @@ struct ImageSetLoader ImageSet *ResourceManager::getImageSet(const std::string &imagePath, int w, int h) { - ImageSetLoader l = { this, imagePath, w, h }; + ImageSetLoader rl = { this, imagePath, w, h }; std::stringstream ss; ss << imagePath << "[" << w << "x" << h << "]"; - return static_cast<ImageSet*>(get(ss.str(), ImageSetLoader::load, &l)); + return static_cast<ImageSet*>(get(ss.str(), ImageSetLoader::load, &rl)); } struct SpriteDefLoader @@ -525,17 +525,17 @@ struct SpriteDefLoader if (!v) return nullptr; - SpriteDefLoader *l = static_cast< SpriteDefLoader * >(v); - return SpriteDef::load(l->path, l->variant); + SpriteDefLoader *rl = static_cast< SpriteDefLoader * >(v); + return SpriteDef::load(rl->path, rl->variant); } }; SpriteDef *ResourceManager::getSprite(const std::string &path, int variant) { - SpriteDefLoader l = { path, variant }; + SpriteDefLoader rl = { path, variant }; std::stringstream ss; ss << path << "[" << variant << "]"; - return static_cast<SpriteDef*>(get(ss.str(), SpriteDefLoader::load, &l)); + return static_cast<SpriteDef*>(get(ss.str(), SpriteDefLoader::load, &rl)); } void ResourceManager::release(Resource *res) @@ -723,10 +723,10 @@ struct RescaledLoader { if (!v) return nullptr; - RescaledLoader *l = static_cast< RescaledLoader * >(v); - if (!l->manager) + RescaledLoader *rl = static_cast< RescaledLoader * >(v); + if (!rl->manager || !rl->image) return nullptr; - Image *rescaled = l->image->SDLgetScaledImage(l->width, l->height); + Image *rescaled = rl->image->SDLgetScaledImage(rl->width, rl->height); if (!rescaled) return nullptr; return rescaled; @@ -740,7 +740,7 @@ Image *ResourceManager::getRescaled(Image *image, int width, int height) std::string idPath = image->getIdPath() + strprintf( "_rescaled%dx%d", width, height); - RescaledLoader l = { this, image, width, height }; - Image *img = static_cast<Image*>(get(idPath, RescaledLoader::load, &l)); + RescaledLoader rl = { this, image, width, height }; + Image *img = static_cast<Image*>(get(idPath, RescaledLoader::load, &rl)); return img; } diff --git a/src/resources/specialdb.cpp b/src/resources/specialdb.cpp index b1a3a9c4d..50ea773bc 100644 --- a/src/resources/specialdb.cpp +++ b/src/resources/specialdb.cpp @@ -36,7 +36,7 @@ namespace SpecialInfo::TargetMode SpecialDB::targetModeFromString(const std::string& str) { - if (str == "self") return SpecialInfo::TARGET_SELF; + if (str == "self") return SpecialInfo::TARGET_SELF; else if (str == "friend") return SpecialInfo::TARGET_FRIEND; else if (str == "enemy") return SpecialInfo::TARGET_ENEMY; else if (str == "being") return SpecialInfo::TARGET_BEING; @@ -129,6 +129,4 @@ SpecialInfo *SpecialDB::get(int id) return nullptr; else return i->second; - return nullptr; } - diff --git a/src/spellmanager.cpp b/src/spellmanager.cpp index 7c4c444f0..ebdff6382 100644 --- a/src/spellmanager.cpp +++ b/src/spellmanager.cpp @@ -66,7 +66,8 @@ TextCommand* SpellManager::getSpellByItem(int itemId) void SpellManager::fillSpells() { -//id, std::string name, std::string symbol, ST type, int basicLvl, MagicSchool school, int schoolLvl, int mana) +//id, std::string name, std::string symbol, ST type, int basicLvl, +// MagicSchool school, int schoolLvl, int mana) addSpell(new TextCommand(0, "lum", "#lum", "heal with lifestones", ALLOWTARGET, "", 1, SKILL_MAGIC_LIFE, 0, 6)); diff --git a/src/textcommand.h b/src/textcommand.h index 27b44cc7a..6677b97e9 100644 --- a/src/textcommand.h +++ b/src/textcommand.h @@ -153,7 +153,7 @@ class TextCommand { mCommandType = commandType; } bool isEmpty() const - { return mCommand == "" && mSymbol == "" ; } + { return mCommand == "" && mSymbol == ""; } Image *getImage() const { return mImage; } diff --git a/src/units.cpp b/src/units.cpp index 804512dbd..1440cff9f 100644 --- a/src/units.cpp +++ b/src/units.cpp @@ -150,12 +150,12 @@ void Units::loadUnits() } // Add one more level for saftey - struct UnitLevel ll; - ll.symbol = ""; - ll.count = INT_MAX; - ll.round = 0; + struct UnitLevel lev; + lev.symbol = ""; + lev.count = INT_MAX; + lev.round = 0; - ud.levels.push_back(ll); + ud.levels.push_back(lev); if (type == "weight") units[UNIT_WEIGHT] = ud; diff --git a/src/utils/base64.cpp b/src/utils/base64.cpp index 24a3a58e3..cd7d59cdb 100644 --- a/src/utils/base64.cpp +++ b/src/utils/base64.cpp @@ -125,7 +125,7 @@ unsigned char *php3_base64_decode(const unsigned char *string, continue; ch = static_cast<int>(chp - base64_table); - switch(i % 4) + switch (i % 4) { case 0: result[j] = ch << 2; @@ -151,7 +151,7 @@ unsigned char *php3_base64_decode(const unsigned char *string, /* mop things up if we ended on a boundary */ if (ch == base64_pad) { - switch(i % 4) + switch (i % 4) { case 0: case 1: diff --git a/src/utils/langs.cpp b/src/utils/langs.cpp new file mode 100644 index 000000000..2efbd781a --- /dev/null +++ b/src/utils/langs.cpp @@ -0,0 +1,87 @@ +/* + * The ManaPlus Client + * Copyright (C) 2011-2012 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 "utils/langs.h" + +#include "configuration.h" + +#include <string.h> +#include <algorithm> +#include <cstdarg> +#include <cstdio> +#include <list> + +#include "debug.h" + +std::vector<std::string> getLang() +{ + std::vector<std::string> langs; + + std::string lang = config.getValue("lang", "").c_str(); + if (lang.empty()) + { + char *lng = getenv("LANG"); + if (!lng) + return langs; + lang = lng; + } + + int dot = lang.find("."); + if (dot != (signed)std::string::npos) + lang = lang.substr(0, dot); + langs.push_back(lang); + dot = lang.find("_"); + if (dot != (signed)std::string::npos) + langs.push_back(lang.substr(0, dot)); + return langs; +} + +std::string getLangSimple() +{ + std::string lang = config.getValue("lang", "").c_str(); + if (lang.empty()) + { + char *lng = getenv("LANG"); + if (!lng) + return ""; + return lng; + } + return lang; +} + +std::string getLangShort() +{ + std::string lang = config.getValue("lang", "").c_str(); + if (lang.empty()) + { + char *lng = getenv("LANG"); + if (!lng) + return ""; + lang = lng; + } + + int dot = lang.find("."); + if (dot != (signed)std::string::npos) + lang = lang.substr(0, dot); + dot = lang.find("_"); + if (dot != (signed)std::string::npos) + return lang.substr(0, dot); + return lang; +} diff --git a/src/utils/langs.h b/src/utils/langs.h new file mode 100644 index 000000000..3b9f49f71 --- /dev/null +++ b/src/utils/langs.h @@ -0,0 +1,41 @@ +/* + * The ManaPlus Client + * Copyright (C) 2007-2009 The Mana World Development Team + * Copyright (C) 2009-2010 The Mana Developers + * Copyright (C) 2011-2012 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 UTILS_LANGS_H +#define UTILS_LANGS_H + +#include <string> +#include <sstream> +#include <list> +#include <set> +#include <vector> + +typedef std::vector<std::string> LangVect; +typedef LangVect::const_iterator LangIter; + +std::vector<std::string> getLang(); + +std::string getLangSimple(); + +std::string getLangShort(); + +#endif // UTILS_LANGS_H diff --git a/src/utils/paths.cpp b/src/utils/paths.cpp index 8decb6e95..04f553ca9 100644 --- a/src/utils/paths.cpp +++ b/src/utils/paths.cpp @@ -20,10 +20,12 @@ #include "utils/paths.h" +#include "utils/stringutils.h" + #include <string.h> #include <cstdarg> #include <cstdio> - +#include <physfs.h> #include <stdlib.h> #ifdef WIN32 @@ -55,3 +57,21 @@ bool isRealPath(const std::string &str) std::string path = getRealPath(str); return str == path; } + +bool checkPath(std::string path) +{ + if (path.empty()) + return true; + return path.find("../") == std::string::npos + && path.find("..\\") == std::string::npos + && path.find("/..") == std::string::npos + && path.find("\\..") == std::string::npos; +} + +std::string &fixDirSeparators(std::string &str) +{ + if (*PHYSFS_getDirSeparator() == '/') + return str; + + return replaceAll(str, "/", "\\"); +} diff --git a/src/utils/paths.h b/src/utils/paths.h index 804900587..b89671adc 100644 --- a/src/utils/paths.h +++ b/src/utils/paths.h @@ -27,4 +27,8 @@ std::string getRealPath(const std::string &str); bool isRealPath(const std::string &str); +bool checkPath(std::string path); + +std::string &fixDirSeparators(std::string &str); + #endif // UTILS_PATHS_H diff --git a/src/utils/physfsrwops.h b/src/utils/physfsrwops.h index efa004ac6..1f52f40aa 100644 --- a/src/utils/physfsrwops.h +++ b/src/utils/physfsrwops.h @@ -79,4 +79,3 @@ SDL_RWops *PHYSFSRWOPS_makeRWops(PHYSFS_file *handle); #endif /* include-once blocker */ /* end of physfsrwops.h ... */ - diff --git a/src/utils/process.cpp b/src/utils/process.cpp index 4a2081514..fd0ec0fa8 100644 --- a/src/utils/process.cpp +++ b/src/utils/process.cpp @@ -130,7 +130,7 @@ int execFile(std::string pathName, std::string name, } else if (!sleep_pid) { // sleep pid - sleep (timeOut); + sleep (waitTime); // printf ("time out\n"); exit(-1); } diff --git a/src/utils/stringutils.cpp b/src/utils/stringutils.cpp index 08bcac9e6..2f478a909 100644 --- a/src/utils/stringutils.cpp +++ b/src/utils/stringutils.cpp @@ -22,14 +22,14 @@ #include "utils/stringutils.h" -#include "configuration.h" - #include <string.h> #include <algorithm> #include <cstdarg> #include <cstdio> #include <list> +#include <sys/time.h> + #include "debug.h" static int UTF8_MAX_SIZE = 10; @@ -107,6 +107,7 @@ std::string strprintf(char const *format, ...) return res; } +/* std::string &removeBadChars(std::string &str) { std::string::size_type pos; @@ -120,6 +121,7 @@ std::string &removeBadChars(std::string &str) return str; } +*/ std::string removeColors(std::string msg) { @@ -318,27 +320,37 @@ void getSafeUtf8String(std::string text, char *buf) std::string getFileName(std::string path) { - size_t pos = path.rfind("/"); - if (pos == std::string::npos) - pos = path.rfind("\\"); - if (pos == std::string::npos) + size_t pos1 = path.rfind("/"); + size_t pos2 = path.rfind("\\"); + if (pos1 == std::string::npos) + pos1 = pos2; + else if (pos2 != std::string::npos && pos2 > pos1) + pos1 = pos2; + + if (pos1 == std::string::npos) return path; - return path.substr(pos + 1); + return path.substr(pos1 + 1); } std::string getFileDir(std::string path) { - size_t pos = path.rfind("/"); - if (pos == std::string::npos) - pos = path.rfind("\\"); - if (pos == std::string::npos) - return ""; - return path.substr(0, pos); + size_t pos1 = path.rfind("/"); + size_t pos2 = path.rfind("\\"); + if (pos1 == std::string::npos) + pos1 = pos2; + else if (pos2 != std::string::npos && pos2 > pos1) + pos1 = pos2; + + if (pos1 == std::string::npos) + return path; + return path.substr(0, pos1); } std::string& replaceAll(std::string& context, const std::string& from, const std::string& to) { + if (from.empty()) + return context; size_t lookHere = 0; size_t foundHere; while ((foundHere = context.find(from, lookHere)) != std::string::npos) @@ -405,7 +417,7 @@ std::set<int> splitToIntSet(const std::string &text, char separator) std::set<int> tokens; std::stringstream ss(text); std::string item; - while(std::getline(ss, item, separator)) + while (std::getline(ss, item, separator)) tokens.insert(atoi(item.c_str())); return tokens; @@ -416,7 +428,7 @@ std::list<int> splitToIntList(const std::string &text, char separator) std::list<int> tokens; std::stringstream ss(text); std::string item; - while(std::getline(ss, item, separator)) + while (std::getline(ss, item, separator)) tokens.push_back(atoi(item.c_str())); return tokens; @@ -429,7 +441,7 @@ std::list<std::string> splitToStringList(const std::string &text, std::list<std::string> tokens; std::stringstream ss(text); std::string item; - while(std::getline(ss, item, separator)) + while (std::getline(ss, item, separator)) tokens.push_back(item); return tokens; @@ -440,7 +452,7 @@ void splitToStringVector(std::vector<std::string> &tokens, { std::stringstream ss(text); std::string item; - while(std::getline(ss, item, separator)) + while (std::getline(ss, item, separator)) { item = trim(item); if (!item.empty()) @@ -486,62 +498,6 @@ std::string combineDye2(std::string file, std::string dye) } } -std::vector<std::string> getLang() -{ - std::vector<std::string> langs; - - std::string lang = config.getValue("lang", "").c_str(); - if (lang.empty()) - { - char *lng = getenv("LANG"); - if (!lng) - return langs; - lang = lng; - } - - int dot = lang.find("."); - if (dot != (signed)std::string::npos) - lang = lang.substr(0, dot); - langs.push_back(lang); - dot = lang.find("_"); - if (dot != (signed)std::string::npos) - langs.push_back(lang.substr(0, dot)); - return langs; -} - -std::string getLangSimple() -{ - std::string lang = config.getValue("lang", "").c_str(); - if (lang.empty()) - { - char *lng = getenv("LANG"); - if (!lng) - return ""; - return lng; - } - return lang; -} - -std::string getLangShort() -{ - std::string lang = config.getValue("lang", "").c_str(); - if (lang.empty()) - { - char *lng = getenv("LANG"); - if (!lng) - return ""; - lang = lng; - } - - int dot = lang.find("."); - if (dot != (signed)std::string::npos) - lang = lang.substr(0, dot); - dot = lang.find("_"); - if (dot != (signed)std::string::npos) - return lang.substr(0, dot); - return lang; -} - std::string packList(std::list<std::string> &list) { std::list<std::string>::const_iterator i = list.begin(); @@ -649,12 +605,23 @@ std::string &removeProtocol(std::string &url) return url; } -bool checkPath(std::string path) +bool strStartWith(std::string str1, std::string str2) { - if (path.empty()) - return true; - return path.find("../") == std::string::npos - && path.find("..\\") == std::string::npos - && path.find("/..") == std::string::npos - && path.find("\\..") == std::string::npos; + if (str1.size() < str2.size()) + return false; + return str1.substr(0, str2.size()) == str2; +} + +std::string getDateString() +{ + char buffer[80]; + + time_t rawtime; + struct tm *timeinfo; + + time (&rawtime); + timeinfo = localtime(&rawtime); + + strftime(buffer, 79, "%Y-%m-%d", timeinfo); + return std::string(buffer); } diff --git a/src/utils/stringutils.h b/src/utils/stringutils.h index 0b22ef847..31ee6d51f 100644 --- a/src/utils/stringutils.h +++ b/src/utils/stringutils.h @@ -103,7 +103,7 @@ std::string strprintf(char const *, ...) * @param str the string to remove the bad chars from * @return a reference to the string without bad chars */ -std::string &removeBadChars(std::string &str); +//std::string &removeBadChars(std::string &str); /** * Removes colors from a string @@ -186,12 +186,6 @@ std::string combineDye(std::string file, std::string dye); std::string combineDye2(std::string file, std::string dye); -std::vector<std::string> getLang(); - -std::string getLangSimple(); - -std::string getLangShort(); - std::string packList(std::list<std::string> &list); std::list<std::string> unpackList(const std::string &str); @@ -210,6 +204,8 @@ bool findCutFirst(std::string &str1, std::string str2); std::string &removeProtocol(std::string &url); -bool checkPath(std::string path); +bool strStartWith(std::string str, std::string start); + +std::string getDateString(); #endif // UTILS_STRINGUTILS_H diff --git a/src/utils/stringutils_unittest.cc b/src/utils/stringutils_unittest.cc new file mode 100644 index 000000000..81030631a --- /dev/null +++ b/src/utils/stringutils_unittest.cc @@ -0,0 +1,517 @@ +/* + * The ManaPlus Client + * Copyright (C) 2012 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 "utils/stringutils.h" + +#include "gtest/gtest.h" + +#include <list> +#include <string> +#include <vector> + +#include "debug.h" + +TEST(stringuntils, trim1) +{ + std::string str = "str"; + EXPECT_EQ("str", trim(str)); + + str = " str"; + EXPECT_EQ("str", trim(str)); + EXPECT_EQ("str", trim(str)); + + str = " str this IS Long Стринг " + "~!@#$%^&*()_+`-=[]\\{}|;':\",./<>? "; + EXPECT_EQ("str this IS Long Стринг ~!@#$%^&*()_+`-=[]\\{}|;':\",./<>?", + trim(str)); + + str = ""; + EXPECT_EQ("", trim(str)); +} + +TEST(stringuntils, toLower1) +{ + std::string str = "str"; + EXPECT_EQ("str", toLower(str)); + + str = " StR"; + EXPECT_EQ(" str", toLower(str)); + + str = " str this IS Long " + "~!@#$%^&*()_+`-=[]\\{}|;':\",./<>? "; + + EXPECT_EQ(" str this is long ~!@#$%^&*()_+`-=[]\\{}|;':\",./<>? ", + toLower(str)); + + str = ""; + EXPECT_EQ("", toLower(str)); +} + +TEST(stringuntils, toUpper1) +{ + std::string str = "str"; + EXPECT_EQ("STR", toUpper(str)); + + str = " StR"; + EXPECT_EQ(" STR", toUpper(str)); + + str = " str this IS Long " + "~!@#$%^&*()_+`-=[]\\{}|;':,./<>? "; + + EXPECT_EQ(" STR THIS IS LONG ~!@#$%^&*()_+`-=[]\\{}|;':,./<>? ", + toUpper(str)); + + str = ""; + EXPECT_EQ("", toUpper(str)); +} + +TEST(stringuntils, atox1) +{ + std::string str = "0x10"; + EXPECT_EQ(16, atox(str)); + + str = "0x0"; + EXPECT_EQ(0, atox(str)); + + str = "0x1"; + EXPECT_EQ(1, atox(str)); + + str = "0x0x0x0x0x0x0x0"; + EXPECT_EQ(0, atox(str)); + + str = "0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; + atox(str); + + str = ""; + int k = atox(str); + + str = "0"; + k = atox(str); + + str = "0x"; + k = atox(str); +} + +TEST(stringuntils, ipToString1) +{ + EXPECT_EQ("0.0.0.0", std::string(ipToString(0))); + EXPECT_EQ("219.255.210.73", std::string(ipToString(1238564827))); +} + +TEST(stringuntils, removeColors1) +{ + EXPECT_EQ("", removeColors("")); + EXPECT_EQ("#", removeColors("#")); + EXPECT_EQ("##", removeColors("##")); + EXPECT_EQ("", removeColors("##1")); + EXPECT_EQ("2", removeColors("##12")); + EXPECT_EQ("1##", removeColors("1##")); + EXPECT_EQ("1", removeColors("1##2")); + EXPECT_EQ("13", removeColors("1##23")); + EXPECT_EQ("#1#2", removeColors("#1#2")); + EXPECT_EQ("#1", removeColors("#1##2")); +} + +TEST(stringuntils, compareStrI1) +{ + std::string str1 = ""; + std::string str2 = ""; + EXPECT_TRUE(compareStrI(str1, str2) == 0); + + str1 = "test"; + str2 = "test"; + EXPECT_TRUE(compareStrI(str1, str2) == 0); + + str1 = "test"; + str2 = "test1"; + EXPECT_TRUE(compareStrI(str1, str2) < 0); + + str1 = "test"; + str2 = "aest1"; + EXPECT_TRUE(compareStrI(str1, str2) > 0); +} + +TEST(stringuntils, isWordSeparator1) +{ + EXPECT_TRUE(isWordSeparator(' ')); + EXPECT_TRUE(isWordSeparator(',')); + EXPECT_TRUE(isWordSeparator('.')); + EXPECT_TRUE(isWordSeparator('\"')); + EXPECT_TRUE(!isWordSeparator(0)); + EXPECT_TRUE(!isWordSeparator('a')); + EXPECT_TRUE(!isWordSeparator('-')); +} + +TEST(stringuntils, findSameSubstring) +{ + std::string str1 = ""; + std::string str2 = ""; + + EXPECT_EQ("", findSameSubstring("", "")); + + str1 = "test line"; + str2 = "test line"; + EXPECT_EQ("test line", findSameSubstring(str1, str2)); + + str1 = "test li"; + str2 = "test line"; + EXPECT_EQ("test li", findSameSubstring(str1, str2)); + + str1 = "test li"; + str2 = "est li"; + EXPECT_EQ("", findSameSubstring(str1, str2)); +} + +TEST(stringuntils, findSameSubstringI) +{ + std::string str1 = ""; + std::string str2 = ""; + + EXPECT_EQ("", findSameSubstringI("", "")); + + str1 = "tEst line"; + str2 = "tesT line"; + EXPECT_EQ("tEst line", findSameSubstringI(str1, str2)); + + str1 = "test Li"; + str2 = "test lINe"; + EXPECT_EQ("test Li", findSameSubstringI(str1, str2)); + + str1 = "teSt li"; + str2 = "est li"; + EXPECT_EQ("", findSameSubstringI(str1, str2)); +} + +TEST(stringuntils, findI1) +{ + EXPECT_EQ(0, findI("", "")); + EXPECT_EQ(std::string::npos, findI("test", "line")); + EXPECT_EQ(0, findI("test line", "t")); + EXPECT_EQ(0, findI("test line", "te")); + EXPECT_EQ(3, findI("test line", "t l")); +} + +TEST(stringuntils, findI2) +{ + std::vector <std::string> vect1; + vect1.push_back("test"); + vect1.push_back("line"); + vect1.push_back("qwe"); + + EXPECT_EQ(std::string::npos, findI("", vect1)); + EXPECT_EQ(0, findI("test", vect1)); + EXPECT_EQ(0, findI("tesT lIne", vect1)); + EXPECT_EQ(5, findI("teoT line", vect1)); + EXPECT_EQ(std::string::npos, findI("zzz", vect1)); +} + +TEST(stringuntils, encodeStr1) +{ + std::string str = encodeStr(10, 1); + EXPECT_EQ(10, decodeStr(str)); + + str = encodeStr(10, 2); + EXPECT_EQ(10, decodeStr(str)); + + str = encodeStr(100, 3); + EXPECT_EQ(100, decodeStr(str)); + + str = encodeStr(1000, 4); + EXPECT_EQ(1000, decodeStr(str)); +} + +TEST(stringuntils, extractNameFromSprite1) +{ + EXPECT_EQ("", extractNameFromSprite("")); + EXPECT_EQ("test", extractNameFromSprite("test")); + EXPECT_EQ("test", extractNameFromSprite("test.qwe")); + EXPECT_EQ("line", extractNameFromSprite("test/line.zzz")); +} + +TEST(stringuntils, removeSpriteIndex1) +{ + EXPECT_EQ("", removeSpriteIndex("")); + EXPECT_EQ("test", removeSpriteIndex("test")); + EXPECT_EQ("test", removeSpriteIndex("test[1]")); + EXPECT_EQ("line", removeSpriteIndex("test/line[12]")); +} + +TEST(stringuntils, getFileName1) +{ + EXPECT_EQ("", getFileName("")); + EXPECT_EQ("file", getFileName("file")); + EXPECT_EQ("file", getFileName("test/file1\\file")); + EXPECT_EQ("file", getFileName("test\\file1/file")); + EXPECT_EQ("", getFileName("file/")); + EXPECT_EQ("file", getFileName("/file")); +} + +TEST(stringuntils, getFileDir1) +{ + EXPECT_EQ("", getFileDir("")); + EXPECT_EQ("file", getFileDir("file")); + EXPECT_EQ("test/file1", getFileDir("test/file1\\file")); + EXPECT_EQ("test\\file1", getFileDir("test\\file1/file")); + EXPECT_EQ("file", getFileDir("file/")); + EXPECT_EQ("", getFileDir("/file")); +} + +TEST(stringuntils, replaceAll1) +{ + std::string str1 = ""; + std::string str2 = ""; + std::string str3 = ""; + + EXPECT_EQ("", replaceAll(str1, str2, str3)); + + str1 = "this is test line"; + str2 = ""; + str3 = ""; + EXPECT_EQ("this is test line", replaceAll(str1, str2, str3)); + + str1 = "this is test line"; + str2 = "is "; + str3 = ""; + EXPECT_EQ("thtest line", replaceAll(str1, str2, str3)); + + str1 = "this is test line"; + str2 = ""; + str3 = "1"; + EXPECT_EQ("this is test line", replaceAll(str1, str2, str3)); +} + +TEST(stringuntils, getBoolFromString1) +{ + EXPECT_TRUE(getBoolFromString("true")); + EXPECT_TRUE(!getBoolFromString("false")); + EXPECT_TRUE(getBoolFromString("1")); + EXPECT_TRUE(!getBoolFromString("0")); +} + +TEST(stringuntils, replaceSpecialChars1) +{ + std::string str; + + str = ""; + replaceSpecialChars(str); + EXPECT_EQ("", str); + + str = "test"; + replaceSpecialChars(str); + EXPECT_EQ("test", str); + + str = "&"; + replaceSpecialChars(str); + EXPECT_EQ("&", str); + + str = "&1"; + replaceSpecialChars(str); + EXPECT_EQ("&1", str); + + str = "&33"; + replaceSpecialChars(str); + EXPECT_EQ("&33", str); + + str = "&33;"; + replaceSpecialChars(str); + EXPECT_EQ("!", str); + + str = "1&33;"; + replaceSpecialChars(str); + EXPECT_EQ("1!", str); + + str = "&33;2"; + replaceSpecialChars(str); + EXPECT_EQ("!2", str); + + str = "&33;&"; + replaceSpecialChars(str); + EXPECT_EQ("!&", str); + + str = "test line&33;"; + replaceSpecialChars(str); + EXPECT_EQ("test line!", str); +} + +TEST(stringuntils, combineDye1) +{ + EXPECT_EQ("", combineDye("", "")); + EXPECT_EQ("test", combineDye("test", "")); + EXPECT_EQ("|line", combineDye("", "line")); + EXPECT_EQ("test|line", combineDye("test", "line")); +} + +TEST(stringuntils, combineDye2) +{ + EXPECT_EQ("", combineDye2("", "")); + EXPECT_EQ("test", combineDye2("test", "")); + EXPECT_EQ("", combineDye2("", "line")); + EXPECT_EQ("test.xml", combineDye2("test.xml", "123")); + EXPECT_EQ("test.xml|#43413d,59544f,7a706c", + combineDye2("test.xml|#43413d,59544f,7a706c", "")); + EXPECT_EQ("test.xml|#43413d,59544f,7a706c:W;", + combineDye2("test.xml|#43413d,59544f,7a706c", "W")); + EXPECT_EQ("test.xml|#43413d,59544f,7a706c:W;#123456:B;", + combineDye2("test.xml|#43413d,59544f,7a706c;#123456", "W;B")); +} + +TEST(stringuntils, packList1) +{ + std::list <std::string> list; + EXPECT_EQ("", packList(list)); + + list.push_back(""); + EXPECT_EQ("|", packList(list)); + + list.clear(); + list.push_back("test"); + EXPECT_EQ("test", packList(list)); + + list.push_back("line"); + EXPECT_EQ("test|line", packList(list)); + + list.push_back("2"); + EXPECT_EQ("test|line|2", packList(list)); +} + +TEST(stringuntils, stringToHexPath1) +{ + std::string str; + + str = ""; + EXPECT_EQ("", stringToHexPath(str)); + + str = "a"; + EXPECT_EQ("%61/", stringToHexPath(str)); + + str = "ab"; + EXPECT_EQ("%61/%62", stringToHexPath(str)); + + str = "abc"; + EXPECT_EQ("%61/%62%63", stringToHexPath(str)); + + str = "abcd"; + EXPECT_EQ("%61/%62%63%64", stringToHexPath(str)); +} + +TEST(stringuntils, deleteCharLeft1) +{ + std::string str; + unsigned int pos = 0; + + str = ""; + deleteCharLeft(str, nullptr); + EXPECT_EQ("", str); + + str = "test line"; + pos = 4; + deleteCharLeft(str, &pos); + EXPECT_EQ("tes line", str); + + str = "тест line"; + pos = 8; + deleteCharLeft(str, &pos); + EXPECT_EQ("тес line", str); +} + +TEST(stringuntils, findLast1) +{ + std::string str; + + str = ""; + EXPECT_TRUE(findLast(str, "")); + + str = "test line"; + EXPECT_TRUE(findLast(str, "line")); + + str = "test line"; + EXPECT_TRUE(!findLast(str, "lin")); +} + +TEST(stringuntils, findFirst1) +{ + std::string str; + + str = ""; + EXPECT_TRUE(findFirst(str, "")); + + str = "test line"; + EXPECT_TRUE(findFirst(str, "test")); + + str = "test line"; + EXPECT_TRUE(!findFirst(str, "est")); +} + +TEST(stringuntils, findCutLast1) +{ + std::string str; + + str = ""; + EXPECT_TRUE(findCutLast(str, "")); + EXPECT_EQ("", str); + + str = "test line"; + EXPECT_TRUE(findCutLast(str, "line")); + EXPECT_EQ("test ", str); + + str = "test line"; + EXPECT_TRUE(!findCutLast(str, "lin")); + EXPECT_EQ("test line", str); +} + +TEST(stringuntils, findCutFirst1) +{ + std::string str; + + str = ""; + EXPECT_TRUE(findCutFirst(str, "")); + EXPECT_EQ("", str); + + str = "test line"; + EXPECT_TRUE(findCutFirst(str, "test")); + EXPECT_EQ(" line", str); + + str = "test line"; + EXPECT_TRUE(!findCutFirst(str, "est")); + EXPECT_EQ("test line", str); +} + +TEST(stringuntils, removeProtocol1) +{ + std::string str; + + str = ""; + EXPECT_EQ("", removeProtocol(str)); + + str = "http://"; + EXPECT_EQ("", removeProtocol(str)); + + str = "http://test"; + EXPECT_EQ("test", removeProtocol(str)); +} + +TEST(stringuntils, strStartWith1) +{ + EXPECT_TRUE(strStartWith("", "")); + EXPECT_TRUE(!strStartWith("", "1")); + EXPECT_TRUE(strStartWith("test line", "test")); + EXPECT_TRUE(strStartWith("test line", "test line")); + EXPECT_TRUE(!strStartWith("test line", "est")); +} diff --git a/src/utils/translation/podict.cpp b/src/utils/translation/podict.cpp new file mode 100644 index 000000000..0be0b279f --- /dev/null +++ b/src/utils/translation/podict.cpp @@ -0,0 +1,55 @@ +/* + * The ManaPlus Client + * Copyright (C) 2012 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 "utils/translation/podict.h" + +#include <string.h> + +#include "localconsts.h" +#include "logger.h" + +#include "debug.h" + +std::string empty; + +PoDict *translator = nullptr; + +PoDict::PoDict(std::string lang) : + mLang(lang) +{ +} + +PoDict::~PoDict() +{ +} + +const std::string PoDict::getStr(std::string &str) +{ + if (mPoLines.find(str) == mPoLines.end()) + return str; + return mPoLines[str]; +} + +const char *PoDict::getChar(const char *str) +{ + if (mPoLines.find(str) == mPoLines.end()) + return str; + return mPoLines[str].c_str(); +} diff --git a/src/utils/translation/podict.h b/src/utils/translation/podict.h new file mode 100644 index 000000000..0b7dd726c --- /dev/null +++ b/src/utils/translation/podict.h @@ -0,0 +1,59 @@ +/* + * The ManaPlus Client + * Copyright (C) 2012 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 UTILS_TRANSLATION_PODICT_H +#define UTILS_TRANSLATION_PODICT_H + +#include <string> +#include <map> + +typedef std::map <std::string, std::string> PoMap; + +class PoDict +{ + public: + PoDict(std::string lang); + + ~PoDict(); + + const std::string getStr(std::string &str); + + const char *getChar(const char *str); + + protected: + friend class PoParser; + + PoMap *getMap() + { return &mPoLines; } + + void set(std::string key, std::string value) + { mPoLines[key] = value; } + + void setLang(std::string lang) + { mLang = lang; } + + private: + PoMap mPoLines; + std::string mLang; +}; + +extern PoDict *translator; + +#endif // UTILS_TRANSLATION_PODICT_H diff --git a/src/utils/translation/poparser.cpp b/src/utils/translation/poparser.cpp new file mode 100644 index 000000000..24d2ee4d4 --- /dev/null +++ b/src/utils/translation/poparser.cpp @@ -0,0 +1,221 @@ +/* + * The ManaPlus Client + * Copyright (C) 2012 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 "utils/translation/poparser.h" + +#include "resources/resourcemanager.h" + +#include "utils/stringutils.h" + +#include "localconsts.h" +#include "logger.h" + +#include <string.h> +#include <stdlib.h> + +#include "debug.h" + +PoParser::PoParser() : + mDict(nullptr), + mReadingId(false), + mReadingStr(false) +{ +} + +void PoParser::openFile() +{ + ResourceManager *resman = ResourceManager::getInstance(); + int size; + char *buf = static_cast<char*>(resman->loadFile(getFileName(mLang), size)); + + mFile.str(std::string(buf, size)); + free(buf); +} + +PoDict *PoParser::load(std::string lang) +{ + setLang(lang); + mDict = getDict(); + + openFile(); + + mMsgId = ""; + mMsgStr = ""; + + // cycle by msgid+msgstr + while (readLine()) + { + // reading msgid + while (readMsgId()) + { + if (!readLine()) + break; + } + + if (!mMsgId.empty()) + { + // if we got msgid then reading msgstr + while (readMsgStr()) + { + if (!readLine()) + break; + } + } + + if (!mMsgId.empty() && !mMsgStr.empty()) + { +// logger->log("add key: " + mMsgId); +// logger->log("add value: " + mMsgStr); + + // store key and value + mDict->set(mMsgId, mMsgStr); + } + + mMsgId = ""; + mMsgStr = ""; + } + + return mDict; +} + +bool PoParser::readLine() +{ + char line[1001]; + if (!mFile.getline(line, 1000)) + return false; + mLine = line; + return true; +} + +bool PoParser::readMsgId() +{ + // if we reading msgstr then stop here + if (mReadingStr) + return false; + + const std::string msgId1 = "msgid \""; + + // check if in reading process + if (mReadingId) + { + // if we get empty line in file then stop reading + if (mLine.empty()) + { + mReadingId = false; + return false; + } + else if (checkLine()) + { + // reading text from: "text" + mMsgId += mLine.substr(1, mLine.size() - 2); + mLine = ""; + return true; + } + // stop reading in other case + mReadingId = false; + return false; + } + else + { + // check line start from msgid " + if (strStartWith(mLine, msgId1)) + { + mReadingId = true; + // reading text from: msgid "text" + mMsgId += mLine.substr(msgId1.size(), + mLine.size() - 1 - msgId1.size()); + mLine = ""; + return true; + } + // stop reading if we dont read msgid before + return mMsgId.empty(); + } +} + +bool PoParser::readMsgStr() +{ + const std::string msgStr1 = "msgstr \""; + + // check if in reading process + if (mReadingStr) + { + // if we get empty line in file then stop reading + if (mLine.empty()) + { + mReadingStr = false; + return false; + } + if (checkLine()) + { + // reading text from: "text" + mMsgStr += mLine.substr(1, mLine.size() - 2); + mLine = ""; + return true; + } + // stop reading in other case + mReadingStr = false; + } + else + { + // check line start from msgstr " + if (strStartWith(mLine, msgStr1)) + { + mReadingStr = true; + // reading text from: msgid "text" + mMsgStr += mLine.substr(msgStr1.size(), + mLine.size() - 1 - msgStr1.size()); + mLine = ""; + return true; + } + } + + // stop reading in other case + return false; +} + +bool PoParser::checkLine() +{ + // check is line in format: "text" + return mLine.size() > 2 && mLine[0] == '\"' + && mLine[mLine.size() - 1] == '\"'; +} + +PoDict *PoParser::getEmptyDict() +{ + return new PoDict(""); +} + +bool PoParser::checkLang(std::string lang) const +{ + // check is po file exists + ResourceManager *resman = ResourceManager::getInstance(); + return resman->exists(getFileName(lang)); +} + +std::string PoParser::getFileName(std::string lang) const +{ + // get po file name from lang name + return strprintf("translations/%s.po", lang.c_str()); +} + +PoDict *PoParser::getDict() +{ + return new PoDict(mLang); +} diff --git a/src/utils/translation/poparser.h b/src/utils/translation/poparser.h new file mode 100644 index 000000000..799cd2fe7 --- /dev/null +++ b/src/utils/translation/poparser.h @@ -0,0 +1,78 @@ +/* + * The ManaPlus Client + * Copyright (C) 2012 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 UTILS_TRANSLATION_POPARSER_H +#define UTILS_TRANSLATION_POPARSER_H + +#include "utils/translation/podict.h" + +#include <sstream> +#include <string> + +class PoParser +{ + public: + PoParser(); + + PoDict *load(std::string fileName); + + bool checkLang(std::string lang) const; + + static PoDict *getEmptyDict(); + + private: + void setLang(std::string lang) + { mLang = lang; } + + void openFile(); + + bool readLine(); + + bool readMsgId(); + + bool readMsgStr(); + + bool checkLine(); + + std::string getFileName(std::string lang) const; + + PoDict *getDict(); + + // current lang + std::string mLang; + + // po file object + std::istringstream mFile; + + // current line from po file + std::string mLine; + + std::string mMsgId; + + std::string mMsgStr; + + PoDict *mDict; + + bool mReadingId; + + bool mReadingStr; +}; + +#endif // UTILS_TRANSLATION_POPARSER_H diff --git a/src/utils/translation/translationmanager.cpp b/src/utils/translation/translationmanager.cpp new file mode 100644 index 000000000..1b68cc91d --- /dev/null +++ b/src/utils/translation/translationmanager.cpp @@ -0,0 +1,78 @@ +/* + * The ManaPlus Client + * Copyright (C) 2012 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 "utils/translation/translationmanager.h" + +#include "utils/langs.h" + +#include "utils/translation/podict.h" +#include "utils/translation/poparser.h" + +#include <string.h> + +#include "localconsts.h" +#include "logger.h" + +#include "debug.h" + +void TranslationManager::init() +{ + if (translator) + delete translator; + translator = PoParser::getEmptyDict(); +} + +void TranslationManager::loadCurrentLang() +{ + if (translator) + delete translator; + translator = loadLang(getLang()); +} + +void TranslationManager::close() +{ + delete translator; + translator = nullptr; +} + +PoDict *TranslationManager::loadLang(LangVect lang) +{ + std::string name = ""; + PoParser parser; + + LangIter it = lang.begin(); + LangIter it_end = lang.end(); + + for (; it != it_end; ++ it) + { + if (*it == "C") + continue; + + if (parser.checkLang(*it)) + { + name = *it; + break; + } + } + if (!name.empty()) + return parser.load(name); + logger->log("can't find client data translation"); + return PoParser::getEmptyDict(); +} diff --git a/src/utils/translation/translationmanager.h b/src/utils/translation/translationmanager.h new file mode 100644 index 000000000..39702f4f4 --- /dev/null +++ b/src/utils/translation/translationmanager.h @@ -0,0 +1,41 @@ +/* + * The ManaPlus Client + * Copyright (C) 2012 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 UTILS_TRANSLATION_MANAGER_H +#define UTILS_TRANSLATION_MANAGER_H + +#include <string> +#include <vector> + +class PoDict; + +class TranslationManager +{ + public: + static PoDict *loadLang(std::vector<std::string> lang); + + static void init(); + + static void close(); + + static void loadCurrentLang(); +}; + +#endif // UTILS_TRANSLATION_MANAGER_H diff --git a/src/utils/xml.cpp b/src/utils/xml.cpp index 420915d8f..140da72df 100644 --- a/src/utils/xml.cpp +++ b/src/utils/xml.cpp @@ -26,6 +26,8 @@ #include "resources/resourcemanager.h" +#include "utils/translation/podict.h" + #include <iostream> #include <fstream> #include <cstring> @@ -148,6 +150,16 @@ namespace XML return def; } + std::string langProperty(XmlNodePtr node, const char *name, + const std::string &def) + { + std::string str = getProperty(node, name, def); + if (!translator) + return str; + + return translator->getStr(str); + } + bool getBoolProperty(XmlNodePtr node, const char* name, bool def) { xmlChar *prop = xmlGetProp(node, BAD_CAST name); diff --git a/src/utils/xml.h b/src/utils/xml.h index f623fa618..eb5ee88b0 100644 --- a/src/utils/xml.h +++ b/src/utils/xml.h @@ -92,6 +92,12 @@ namespace XML const std::string &def); /** + * Gets a translated string property from an XmlNodePtr. + */ + std::string langProperty(XmlNodePtr node, const char *name, + const std::string &def); + + /** * Gets a boolean property from an XmlNodePtr. */ bool getBoolProperty(XmlNodePtr node, const char *name, bool def); diff --git a/src/variabledata.h b/src/variabledata.h index e5516bd9f..c306d43ed 100644 --- a/src/variabledata.h +++ b/src/variabledata.h @@ -24,9 +24,6 @@ #include <string> -namespace Mana -{ - class VariableData { public: @@ -109,6 +106,4 @@ class BoolData : public VariableData bool mData; }; -} // namespace Mana - #endif diff --git a/src/vector.h b/src/vector.h index 744b235c0..2caf48418 100644 --- a/src/vector.h +++ b/src/vector.h @@ -185,8 +185,8 @@ class Vector */ Vector normalized() const { - const float l = length(); - return Vector(x / l, y / l, z / l); + const float len = length(); + return Vector(x / len, y / len, z / len); } float x, y, z; |