Lua should not depend on ThemeManager
This commit is contained in:
@@ -3,7 +3,6 @@
|
||||
#include "LuaFunctions.h"
|
||||
#include "RageUtil.h"
|
||||
#include "RageLog.h"
|
||||
#include "ScreenDimensions.h"
|
||||
#include "arch/Dialog/Dialog.h"
|
||||
|
||||
#include <csetjmp>
|
||||
@@ -98,6 +97,10 @@ bool Lua::GetStack( lua_State *L, int pos, int &out )
|
||||
return true;
|
||||
}
|
||||
|
||||
void Lua::SetGlobal( lua_State *L, const CString &sName )
|
||||
{
|
||||
lua_setglobal( L, sName );
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -145,33 +148,11 @@ void CloseLua()
|
||||
L = NULL;
|
||||
}
|
||||
|
||||
void Lua::UpdateGlobals()
|
||||
lua_State *Lua::GetGlobalState()
|
||||
{
|
||||
if( L == NULL )
|
||||
OpenLua();
|
||||
|
||||
ASSERT( L );
|
||||
|
||||
/* Important: explicitly refresh cached metrics that we use. */
|
||||
THEME_SCREEN_WIDTH.Read();
|
||||
THEME_SCREEN_HEIGHT.Read();
|
||||
|
||||
lua_pushnumber( L, SCREEN_WIDTH );
|
||||
lua_setglobal( L, "SCREEN_WIDTH" );
|
||||
lua_pushnumber( L, SCREEN_HEIGHT );
|
||||
lua_setglobal( L, "SCREEN_HEIGHT" );
|
||||
lua_pushnumber( L, SCREEN_LEFT );
|
||||
lua_setglobal( L, "SCREEN_LEFT" );
|
||||
lua_pushnumber( L, SCREEN_RIGHT );
|
||||
lua_setglobal( L, "SCREEN_RIGHT" );
|
||||
lua_pushnumber( L, SCREEN_TOP );
|
||||
lua_setglobal( L, "SCREEN_TOP" );
|
||||
lua_pushnumber( L, SCREEN_BOTTOM );
|
||||
lua_setglobal( L, "SCREEN_BOTTOM" );
|
||||
lua_pushnumber( L, SCREEN_CENTER_X );
|
||||
lua_setglobal( L, "SCREEN_CENTER_X" );
|
||||
lua_pushnumber( L, SCREEN_CENTER_Y );
|
||||
lua_setglobal( L, "SCREEN_CENTER_Y" );
|
||||
return L;
|
||||
}
|
||||
|
||||
void Lua::PrepareExpression( CString &sInOut )
|
||||
|
||||
@@ -19,7 +19,9 @@ namespace Lua
|
||||
void PushStack( lua_State *L, const CString &out );
|
||||
void PopStack( lua_State *L, CString &out );
|
||||
bool GetStack( lua_State *L, int pos, int &out );
|
||||
void UpdateGlobals(); // call this when the theme changes
|
||||
void SetGlobal( lua_State *L, const CString &sName );
|
||||
|
||||
lua_State *GetGlobalState();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -538,7 +538,7 @@ void ScreenOptionsMaster::ExportOptions()
|
||||
|
||||
if( ChangeMask & OPT_APPLY_ASPECT_RATIO )
|
||||
{
|
||||
Lua::UpdateGlobals(); // This needs to be done before resetting the projection matrix below
|
||||
THEME->UpdateLuaGlobals(); // This needs to be done before resetting the projection matrix below
|
||||
SCREENMAN->ThemeChanged(); // recreate ScreenSystemLayer and SharedBGA
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#include "Foreach.h"
|
||||
#include "ThemeMetric.h"
|
||||
#include "LuaHelpers.h"
|
||||
#include "ScreenDimensions.h"
|
||||
|
||||
|
||||
ThemeManager* THEME = NULL; // global object accessable from anywhere in the program
|
||||
@@ -267,12 +268,38 @@ void ThemeManager::SwitchThemeAndLanguage( const CString &sThemeName, const CStr
|
||||
/* Lua globals can use metrics which are cached, and vice versa. Update Lua
|
||||
* globals first; it's Lua's job to explicitly update cached metrics that it
|
||||
* uses. */
|
||||
Lua::UpdateGlobals();
|
||||
UpdateLuaGlobals();
|
||||
|
||||
// reload subscribers
|
||||
FOREACH( IThemeMetric*, *g_pvpSubscribers, p ) (*p)->Read();
|
||||
}
|
||||
|
||||
void ThemeManager::UpdateLuaGlobals()
|
||||
{
|
||||
/* Important: explicitly refresh cached metrics that we use. */
|
||||
THEME_SCREEN_WIDTH.Read();
|
||||
THEME_SCREEN_HEIGHT.Read();
|
||||
|
||||
lua_State *L = Lua::GetGlobalState();
|
||||
|
||||
Lua::PushStack( L, (int) SCREEN_WIDTH );
|
||||
Lua::SetGlobal( L, "SCREEN_WIDTH" );
|
||||
Lua::PushStack( L, (int) SCREEN_HEIGHT );
|
||||
Lua::SetGlobal( L, "SCREEN_HEIGHT" );
|
||||
Lua::PushStack( L, (int) SCREEN_LEFT );
|
||||
Lua::SetGlobal( L, "SCREEN_LEFT" );
|
||||
Lua::PushStack( L, (int) SCREEN_RIGHT );
|
||||
Lua::SetGlobal( L, "SCREEN_RIGHT" );
|
||||
Lua::PushStack( L, (int) SCREEN_TOP );
|
||||
Lua::SetGlobal( L, "SCREEN_TOP" );
|
||||
Lua::PushStack( L, (int) SCREEN_BOTTOM );
|
||||
Lua::SetGlobal( L, "SCREEN_BOTTOM" );
|
||||
Lua::PushStack( L, (int) SCREEN_CENTER_X );
|
||||
Lua::SetGlobal( L, "SCREEN_CENTER_X" );
|
||||
Lua::PushStack( L, (int) SCREEN_CENTER_Y );
|
||||
Lua::SetGlobal( L, "SCREEN_CENTER_Y" );
|
||||
}
|
||||
|
||||
CString ThemeManager::GetThemeDirFromName( const CString &sThemeName )
|
||||
{
|
||||
return THEMES_DIR + sThemeName + "/";
|
||||
|
||||
@@ -27,6 +27,7 @@ public:
|
||||
void GetLanguages( CStringArray& AddTo );
|
||||
bool DoesLanguageExist( const CString &sLanguage );
|
||||
void SwitchThemeAndLanguage( const CString &sThemeName, const CString &sLanguage );
|
||||
void UpdateLuaGlobals();
|
||||
CString GetCurThemeName() { return m_sCurThemeName; };
|
||||
CString GetCurLanguage() { return m_sCurLanguage; };
|
||||
CString GetCurThemeDir() { return GetThemeDirFromName(m_sCurThemeName); };
|
||||
|
||||
Reference in New Issue
Block a user