diff --git a/CMakeLists.txt b/CMakeLists.txt index cf7a2d55b..c6df5b15b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -721,6 +721,8 @@ set(OC_CLONK_SOURCES src/platform/PlatformAbstraction.cpp src/platform/PlatformAbstraction.h src/platform/StdSync.h + src/player/C4Achievement.cpp + src/player/C4Achievement.h src/player/C4Player.cpp src/player/C4Player.h src/player/C4PlayerList.cpp diff --git a/src/graphics/C4GraphicsResource.h b/src/graphics/C4GraphicsResource.h index 8ce827522..01a036579 100644 --- a/src/graphics/C4GraphicsResource.h +++ b/src/graphics/C4GraphicsResource.h @@ -24,7 +24,7 @@ #include "graphics/C4Surface.h" #include "graphics/C4FacetEx.h" #include "gui/C4Gui.h" -#include "player/C4ScenarioParameters.h" +#include "player/C4Achievement.h" class C4GraphicsResource { diff --git a/src/gui/C4StartupScenSelDlg.h b/src/gui/C4StartupScenSelDlg.h index 36b6f6f4f..afe6cf26d 100644 --- a/src/gui/C4StartupScenSelDlg.h +++ b/src/gui/C4StartupScenSelDlg.h @@ -22,6 +22,7 @@ #include "landscape/C4Scenario.h" #include "gui/C4Folder.h" #include "player/C4ScenarioParameters.h" +#include "player/C4Achievement.h" #include #include diff --git a/src/player/C4Achievement.cpp b/src/player/C4Achievement.cpp new file mode 100644 index 000000000..b6a3bbec3 --- /dev/null +++ b/src/player/C4Achievement.cpp @@ -0,0 +1,72 @@ +/* + * OpenClonk, http://www.openclonk.org + * + * Copyright (c) 2014-2017, The OpenClonk Team and contributors + * + * Distributed under the terms of the ISC license; see accompanying file + * "COPYING" for details. + * + * "Clonk" is a registered trademark of Matthes Bender, used with permission. + * See accompanying file "TRADEMARK" for details. + * + * To redistribute this file separately, substitute the full license texts + * for the above references. + */ +#include "C4Include.h" +#include "player/C4Achievement.h" +#include "c4group/C4Components.h" +#include "graphics/C4FacetEx.h" + + +/* C4AchievementGraphics */ + +bool C4AchievementGraphics::Init(C4Group &File) +{ + // Load all graphics matching achievement filename and register them to map + char FileName[_MAX_FNAME]; + File.ResetSearch(); + while (File.FindNextEntry(C4CFN_Achievements, FileName)) + { + C4FacetSurface *new_fct = new C4FacetSurface(); + if (!new_fct->Load(File, FileName, C4FCT_Height, C4FCT_Full, false, 0)) + { + delete new_fct; + LogF(LoadResStr("IDS_PRC_NOGFXFILE"), FileName, LoadResStr("IDS_ERR_NOFILE")); + return false; + } + // Register under filename excluding the leading "Achv" part. Delete any existing file with same name. + RemoveExtension(FileName); + int32_t id_offset = SCharPos('*', C4CFN_Achievements); assert(id_offset>=0); + StdCopyStrBuf sFileName(FileName + id_offset); + auto i = Graphics.find(sFileName); + if (i != Graphics.end()) delete i->second; + Graphics[sFileName] = new_fct; + } + // done. success no matter how many files were loaded. + return true; +} + +bool C4AchievementGraphics::Init(C4GroupSet &Files) +{ + int32_t idNewGrp=0; + C4Group *pGrp = Files.FindEntry(C4CFN_Achievements, nullptr, &idNewGrp); + if (!pGrp) return true; // no achievement gfx. That's OK. + if (idNewGrp == idGrp) return true; // no update + idGrp = idNewGrp; + // OK, load from this group + return Init(*pGrp); +} + +void C4AchievementGraphics::Clear() +{ + for (auto i = Graphics.begin(); i != Graphics.end(); ++i) + delete i->second; + Graphics.clear(); + idGrp = 0; +} + +C4FacetSurface *C4AchievementGraphics::FindByName(const char *name) const +{ + auto i = Graphics.find(StdCopyStrBuf(name)); + if (i != Graphics.end()) return i->second; else return nullptr; +} diff --git a/src/player/C4Achievement.h b/src/player/C4Achievement.h new file mode 100644 index 000000000..94b002e09 --- /dev/null +++ b/src/player/C4Achievement.h @@ -0,0 +1,36 @@ +/* + * OpenClonk, http://www.openclonk.org + * + * Copyright (c) 2014-2017, The OpenClonk Team and contributors + * + * Distributed under the terms of the ISC license; see accompanying file + * "COPYING" for details. + * + * "Clonk" is a registered trademark of Matthes Bender, used with permission. + * See accompanying file "TRADEMARK" for details. + * + * To redistribute this file separately, substitute the full license texts + * for the above references. + */ + +#ifndef INC_C4Achievement +#define INC_C4Achievement + +// Maps IDs to achievement graphics to be shown beside scenarios (and maybe other things) +class C4AchievementGraphics +{ + std::map Graphics; + int32_t idGrp; // ID of group file from which achievements were loaded + +public: + C4AchievementGraphics() : idGrp(0) {} + + // Init will always load all achievement files from the first group that contains achievements + bool Init(C4Group &File); + bool Init(C4GroupSet &Files); + void Clear(); + + C4FacetSurface *FindByName(const char *name) const; +}; + +#endif // INC_C4Achievement diff --git a/src/player/C4ScenarioParameters.cpp b/src/player/C4ScenarioParameters.cpp index 9480bc40c..839ecfe82 100644 --- a/src/player/C4ScenarioParameters.cpp +++ b/src/player/C4ScenarioParameters.cpp @@ -17,63 +17,6 @@ #include "player/C4ScenarioParameters.h" #include "c4group/C4Components.h" #include "script/C4Aul.h" -#include "graphics/C4FacetEx.h" - - -/* C4AchievementGraphics */ - -bool C4AchievementGraphics::Init(C4Group &File) -{ - // Load all graphics matching achievement filename and register them to map - char FileName[_MAX_FNAME]; - File.ResetSearch(); - while (File.FindNextEntry(C4CFN_Achievements, FileName)) - { - C4FacetSurface *new_fct = new C4FacetSurface(); - if (!new_fct->Load(File, FileName, C4FCT_Height, C4FCT_Full, false, 0)) - { - delete new_fct; - LogF(LoadResStr("IDS_PRC_NOGFXFILE"), FileName, LoadResStr("IDS_ERR_NOFILE")); - return false; - } - // Register under filename excluding the leading "Achv" part. Delete any existing file with same name. - RemoveExtension(FileName); - int32_t id_offset = SCharPos('*', C4CFN_Achievements); assert(id_offset>=0); - StdCopyStrBuf sFileName(FileName + id_offset); - auto i = Graphics.find(sFileName); - if (i != Graphics.end()) delete i->second; - Graphics[sFileName] = new_fct; - } - // done. success no matter how many files were loaded. - return true; -} - -bool C4AchievementGraphics::Init(C4GroupSet &Files) -{ - int32_t idNewGrp=0; - C4Group *pGrp = Files.FindEntry(C4CFN_Achievements, nullptr, &idNewGrp); - if (!pGrp) return true; // no achievement gfx. That's OK. - if (idNewGrp == idGrp) return true; // no update - idGrp = idNewGrp; - // OK, load from this group - return Init(*pGrp); -} - -void C4AchievementGraphics::Clear() -{ - for (auto i = Graphics.begin(); i != Graphics.end(); ++i) - delete i->second; - Graphics.clear(); - idGrp = 0; -} - -C4FacetSurface *C4AchievementGraphics::FindByName(const char *name) const -{ - auto i = Graphics.find(StdCopyStrBuf(name)); - if (i != Graphics.end()) return i->second; else return nullptr; -} - - // *** C4ScenarioParameters diff --git a/src/player/C4ScenarioParameters.h b/src/player/C4ScenarioParameters.h index 0a8ef83e7..c8fa69e49 100644 --- a/src/player/C4ScenarioParameters.h +++ b/src/player/C4ScenarioParameters.h @@ -20,23 +20,6 @@ #ifndef INC_C4ScenarioParameters #define INC_C4ScenarioParameters -// Maps IDs to achievement graphics to be shown beside scenarios (and maybe other things) -class C4AchievementGraphics -{ - std::map Graphics; - int32_t idGrp; // ID of group file from which achievements were loaded - -public: - C4AchievementGraphics() : idGrp(0) {} - - // Init will always load all achievement files from the first group that contains achievements - bool Init(C4Group &File); - bool Init(C4GroupSet &Files); - void Clear(); - - C4FacetSurface *FindByName(const char *name) const; -}; - // Definition for a custom setting for the scenario class C4ScenarioParameterDef {