forked from Mirrors/openclonk
Move C4AchievementGraphics to its own file
Scenario parameters are useful in a script-only context (such as the one mape uses). C4AchievementGraphics introduces a dependency on C4Surface which isn't available in that context.alut-include-path
parent
97bdddba24
commit
5719524241
|
@ -721,6 +721,8 @@ set(OC_CLONK_SOURCES
|
||||||
src/platform/PlatformAbstraction.cpp
|
src/platform/PlatformAbstraction.cpp
|
||||||
src/platform/PlatformAbstraction.h
|
src/platform/PlatformAbstraction.h
|
||||||
src/platform/StdSync.h
|
src/platform/StdSync.h
|
||||||
|
src/player/C4Achievement.cpp
|
||||||
|
src/player/C4Achievement.h
|
||||||
src/player/C4Player.cpp
|
src/player/C4Player.cpp
|
||||||
src/player/C4Player.h
|
src/player/C4Player.h
|
||||||
src/player/C4PlayerList.cpp
|
src/player/C4PlayerList.cpp
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
#include "graphics/C4Surface.h"
|
#include "graphics/C4Surface.h"
|
||||||
#include "graphics/C4FacetEx.h"
|
#include "graphics/C4FacetEx.h"
|
||||||
#include "gui/C4Gui.h"
|
#include "gui/C4Gui.h"
|
||||||
#include "player/C4ScenarioParameters.h"
|
#include "player/C4Achievement.h"
|
||||||
|
|
||||||
class C4GraphicsResource
|
class C4GraphicsResource
|
||||||
{
|
{
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
#include "landscape/C4Scenario.h"
|
#include "landscape/C4Scenario.h"
|
||||||
#include "gui/C4Folder.h"
|
#include "gui/C4Folder.h"
|
||||||
#include "player/C4ScenarioParameters.h"
|
#include "player/C4ScenarioParameters.h"
|
||||||
|
#include "player/C4Achievement.h"
|
||||||
|
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
|
@ -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<StdCopyStrBuf, C4FacetSurface *> 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
|
|
@ -17,63 +17,6 @@
|
||||||
#include "player/C4ScenarioParameters.h"
|
#include "player/C4ScenarioParameters.h"
|
||||||
#include "c4group/C4Components.h"
|
#include "c4group/C4Components.h"
|
||||||
#include "script/C4Aul.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
|
// *** C4ScenarioParameters
|
||||||
|
|
||||||
|
|
|
@ -20,23 +20,6 @@
|
||||||
#ifndef INC_C4ScenarioParameters
|
#ifndef INC_C4ScenarioParameters
|
||||||
#define INC_C4ScenarioParameters
|
#define INC_C4ScenarioParameters
|
||||||
|
|
||||||
// Maps IDs to achievement graphics to be shown beside scenarios (and maybe other things)
|
|
||||||
class C4AchievementGraphics
|
|
||||||
{
|
|
||||||
std::map<StdCopyStrBuf, C4FacetSurface *> 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
|
// Definition for a custom setting for the scenario
|
||||||
class C4ScenarioParameterDef
|
class C4ScenarioParameterDef
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue