cleanup
add Lua method
This commit is contained in:
@@ -24,14 +24,7 @@
|
|||||||
|
|
||||||
ThemeManager* THEME = NULL; // global object accessable from anywhere in the program
|
ThemeManager* THEME = NULL; // global object accessable from anywhere in the program
|
||||||
|
|
||||||
|
static const CString ElementCategoryNames[NUM_ELEMENT_CATEGORIES] = {
|
||||||
const CString BASE_THEME_NAME = "default";
|
|
||||||
const CString LANGUAGES_SUBDIR = "Languages/";
|
|
||||||
const CString BASE_LANGUAGE = "english";
|
|
||||||
const CString THEMES_DIR = "Themes/";
|
|
||||||
const CString METRICS_FILE = "metrics.ini";
|
|
||||||
const CString ELEMENT_CATEGORY_STRING[NUM_ELEMENT_CATEGORIES] =
|
|
||||||
{
|
|
||||||
"BGAnimations",
|
"BGAnimations",
|
||||||
"Fonts",
|
"Fonts",
|
||||||
"Graphics",
|
"Graphics",
|
||||||
@@ -39,6 +32,26 @@ const CString ELEMENT_CATEGORY_STRING[NUM_ELEMENT_CATEGORIES] =
|
|||||||
"Sounds",
|
"Sounds",
|
||||||
"Other"
|
"Other"
|
||||||
};
|
};
|
||||||
|
XToString( ElementCategory );
|
||||||
|
StringToX( ElementCategory );
|
||||||
|
static void LuaElementCategory(lua_State* L)
|
||||||
|
{
|
||||||
|
FOREACH_ElementCategory( ec )
|
||||||
|
{
|
||||||
|
CString s = ElementCategoryNames[ec];
|
||||||
|
s.MakeUpper();
|
||||||
|
LUA->SetGlobal( "ELEMENT_CATEGORY_"+s, ec );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
REGISTER_WITH_LUA_FUNCTION( LuaElementCategory );
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
const CString BASE_THEME_NAME = "default";
|
||||||
|
const CString LANGUAGES_SUBDIR = "Languages/";
|
||||||
|
const CString BASE_LANGUAGE = "english";
|
||||||
|
const CString THEMES_DIR = "Themes/";
|
||||||
|
const CString METRICS_FILE = "metrics.ini";
|
||||||
|
|
||||||
|
|
||||||
struct Theme
|
struct Theme
|
||||||
@@ -342,13 +355,13 @@ CString ThemeManager::GetPathToRaw( const CString &sThemeName_, ElementCategory
|
|||||||
try_element_again:
|
try_element_again:
|
||||||
|
|
||||||
const CString sThemeDir = GetThemeDirFromName( sThemeName );
|
const CString sThemeDir = GetThemeDirFromName( sThemeName );
|
||||||
const CString &sCategory = ELEMENT_CATEGORY_STRING[category];
|
const CString &sCategory = ElementCategoryToString(category);
|
||||||
|
|
||||||
CStringArray asElementPaths;
|
CStringArray asElementPaths;
|
||||||
|
|
||||||
// If sFileName already has an extension, we're looking for a specific file
|
// If sFileName already has an extension, we're looking for a specific file
|
||||||
bool bLookingForSpecificFile = sElement.find_last_of('.') != sElement.npos;
|
bool bLookingForSpecificFile = sElement.find_last_of('.') != sElement.npos;
|
||||||
bool bDirsOnly = category==BGAnimations;
|
bool bDirsOnly = category==ELEMENT_CATEGORY_BGANIMATIONS;
|
||||||
|
|
||||||
if( bLookingForSpecificFile )
|
if( bLookingForSpecificFile )
|
||||||
{
|
{
|
||||||
@@ -356,7 +369,7 @@ try_element_again:
|
|||||||
}
|
}
|
||||||
else // look for all files starting with sFileName that have types we can use
|
else // look for all files starting with sFileName that have types we can use
|
||||||
{
|
{
|
||||||
const CString wildcard = (category == BGAnimations? "":"*");
|
const CString wildcard = (category == ELEMENT_CATEGORY_BGANIMATIONS? "":"*");
|
||||||
|
|
||||||
/* First, look for redirs. */
|
/* First, look for redirs. */
|
||||||
GetDirListing( sThemeDir + sCategory + "/" + ClassAndElementToFileName(sClassName,sElement) + wildcard + ".redir",
|
GetDirListing( sThemeDir + sCategory + "/" + ClassAndElementToFileName(sClassName,sElement) + wildcard + ".redir",
|
||||||
@@ -397,7 +410,7 @@ try_element_again:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if( category == Fonts )
|
if( category == ELEMENT_CATEGORY_FONTS )
|
||||||
Font::WeedFontNames(asElementPaths, ClassAndElementToFileName(sClassName,sElement));
|
Font::WeedFontNames(asElementPaths, ClassAndElementToFileName(sClassName,sElement));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -405,8 +418,8 @@ try_element_again:
|
|||||||
if( asElementPaths.size() == 0 )
|
if( asElementPaths.size() == 0 )
|
||||||
{
|
{
|
||||||
// HACK: have Fonts fall back to Numbers. Eventually Numbers will be removed.
|
// HACK: have Fonts fall back to Numbers. Eventually Numbers will be removed.
|
||||||
if( category == Fonts )
|
if( category == ELEMENT_CATEGORY_FONTS )
|
||||||
return GetPathToRaw( sThemeName, Numbers, sClassName, sElement ) ;
|
return GetPathToRaw( sThemeName, ELEMENT_CATEGORY_NUMBERS, sClassName, sElement ) ;
|
||||||
return ""; // This isn't fatal.
|
return ""; // This isn't fatal.
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -450,7 +463,7 @@ try_element_again:
|
|||||||
FileNameToClassAndElement(sNewFileName, sNewClassName, sNewFile);
|
FileNameToClassAndElement(sNewFileName, sNewClassName, sNewFile);
|
||||||
|
|
||||||
/* backwards-compatibility hack */
|
/* backwards-compatibility hack */
|
||||||
if( category == Fonts )
|
if( category == ELEMENT_CATEGORY_FONTS )
|
||||||
sNewFileName.Replace(" 16x16.png", "");
|
sNewFileName.Replace(" 16x16.png", "");
|
||||||
|
|
||||||
/* Search again. For example, themes/default/Fonts/foo might redir
|
/* Search again. For example, themes/default/Fonts/foo might redir
|
||||||
@@ -525,12 +538,12 @@ try_element_again:
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
const CString &sCategory = ELEMENT_CATEGORY_STRING[category];
|
const CString &sCategory = ElementCategoryToString(category);
|
||||||
|
|
||||||
/* We can't fall back on _missing in Other: the file types are unknown. */
|
/* We can't fall back on _missing in Other: the file types are unknown. */
|
||||||
CString sMessage = "The theme element \"" + sCategory + "/" + sFileName +"\" is missing.";
|
CString sMessage = "The theme element \"" + sCategory + "/" + sFileName +"\" is missing.";
|
||||||
Dialog::Result res;
|
Dialog::Result res;
|
||||||
if( category != Other )
|
if( category != ELEMENT_CATEGORY_OTHER )
|
||||||
res = Dialog::AbortRetryIgnore(sMessage, "MissingThemeElement");
|
res = Dialog::AbortRetryIgnore(sMessage, "MissingThemeElement");
|
||||||
else
|
else
|
||||||
res = Dialog::AbortRetry(sMessage, "MissingThemeElement");
|
res = Dialog::AbortRetry(sMessage, "MissingThemeElement");
|
||||||
@@ -821,10 +834,12 @@ public:
|
|||||||
LunaThemeManager() { LUA->Register( Register ); }
|
LunaThemeManager() { LUA->Register( Register ); }
|
||||||
|
|
||||||
static int GetMetric( T* p, lua_State *L ) { lua_pushstring(L, p->GetMetric(SArg(1),SArg(2)) ); return 1; }
|
static int GetMetric( T* p, lua_State *L ) { lua_pushstring(L, p->GetMetric(SArg(1),SArg(2)) ); return 1; }
|
||||||
|
static int GetPath( T* p, lua_State *L ) { lua_pushstring(L, p->GetPath((ElementCategory)IArg(1),SArg(2),SArg(3)) ); return 1; }
|
||||||
|
|
||||||
static void Register(lua_State *L)
|
static void Register(lua_State *L)
|
||||||
{
|
{
|
||||||
ADD_METHOD( GetMetric )
|
ADD_METHOD( GetMetric )
|
||||||
|
ADD_METHOD( GetPath )
|
||||||
Luna<T>::Register( L );
|
Luna<T>::Register( L );
|
||||||
|
|
||||||
// add global singleton
|
// add global singleton
|
||||||
|
|||||||
@@ -14,7 +14,19 @@ class IThemeMetric;
|
|||||||
class IniFile;
|
class IniFile;
|
||||||
struct lua_State;
|
struct lua_State;
|
||||||
|
|
||||||
enum ElementCategory { BGAnimations, Fonts, Graphics, Numbers, Sounds, Other, NUM_ELEMENT_CATEGORIES };
|
enum ElementCategory
|
||||||
|
{
|
||||||
|
ELEMENT_CATEGORY_BGANIMATIONS,
|
||||||
|
ELEMENT_CATEGORY_FONTS,
|
||||||
|
ELEMENT_CATEGORY_GRAPHICS,
|
||||||
|
ELEMENT_CATEGORY_NUMBERS,
|
||||||
|
ELEMENT_CATEGORY_SOUNDS,
|
||||||
|
ELEMENT_CATEGORY_OTHER,
|
||||||
|
NUM_ELEMENT_CATEGORIES
|
||||||
|
};
|
||||||
|
#define FOREACH_ElementCategory( ec ) FOREACH_ENUM( ElementCategory, NUM_ELEMENT_CATEGORIES, ec )
|
||||||
|
const CString& ElementCategoryToString( ElementCategory ec );
|
||||||
|
ElementCategory StringToElementCategory( const CString& s );
|
||||||
|
|
||||||
struct Theme;
|
struct Theme;
|
||||||
|
|
||||||
@@ -44,11 +56,11 @@ public:
|
|||||||
* GetPathToB( str, str ) was matching the ones below instead of these. It's also
|
* GetPathToB( str, str ) was matching the ones below instead of these. It's also
|
||||||
* easier to search for uses of obsolete functions if they have a different name. */
|
* easier to search for uses of obsolete functions if they have a different name. */
|
||||||
CString GetPath( ElementCategory category, const CString &sClassName, const CString &sElement, bool bOptional=false );
|
CString GetPath( ElementCategory category, const CString &sClassName, const CString &sElement, bool bOptional=false );
|
||||||
CString GetPathB( const CString &sClassName, const CString &sElement, bool bOptional=false ) { return GetPath(BGAnimations,sClassName,sElement,bOptional); };
|
CString GetPathB( const CString &sClassName, const CString &sElement, bool bOptional=false ) { return GetPath(ELEMENT_CATEGORY_BGANIMATIONS,sClassName,sElement,bOptional); };
|
||||||
CString GetPathF( const CString &sClassName, const CString &sElement, bool bOptional=false ) { return GetPath(Fonts,sClassName,sElement,bOptional); };
|
CString GetPathF( const CString &sClassName, const CString &sElement, bool bOptional=false ) { return GetPath(ELEMENT_CATEGORY_FONTS,sClassName,sElement,bOptional); };
|
||||||
CString GetPathG( const CString &sClassName, const CString &sElement, bool bOptional=false ) { return GetPath(Graphics,sClassName,sElement,bOptional); };
|
CString GetPathG( const CString &sClassName, const CString &sElement, bool bOptional=false ) { return GetPath(ELEMENT_CATEGORY_GRAPHICS,sClassName,sElement,bOptional); };
|
||||||
CString GetPathS( const CString &sClassName, const CString &sElement, bool bOptional=false ) { return GetPath(Sounds,sClassName,sElement,bOptional); };
|
CString GetPathS( const CString &sClassName, const CString &sElement, bool bOptional=false ) { return GetPath(ELEMENT_CATEGORY_SOUNDS,sClassName,sElement,bOptional); };
|
||||||
CString GetPathO( const CString &sClassName, const CString &sElement, bool bOptional=false ) { return GetPath(Other,sClassName,sElement,bOptional); };
|
CString GetPathO( const CString &sClassName, const CString &sElement, bool bOptional=false ) { return GetPath(ELEMENT_CATEGORY_OTHER,sClassName,sElement,bOptional); };
|
||||||
|
|
||||||
// TODO: remove these and update the places that use them
|
// TODO: remove these and update the places that use them
|
||||||
CString GetPathToB( const CString &sFileName, bool bOptional=false );
|
CString GetPathToB( const CString &sFileName, bool bOptional=false );
|
||||||
|
|||||||
Reference in New Issue
Block a user