Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add support for set_formspec_prepend in main menu (#8611)
  • Loading branch information
rubenwardy authored and sfan5 committed Aug 12, 2019
1 parent a067d40 commit 91114b5
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 1 deletion.
2 changes: 2 additions & 0 deletions doc/menu_lua_api.txt
Expand Up @@ -79,6 +79,8 @@ core.explode_table_event(string) -> table
core.explode_textlist_event(string) -> table
^ returns e.g. {type="CHG", index=1}
^ type: "INV" (no row selected), "CHG" (selected) or "DCL" (double-click)
core.set_formspec_prepend(formspec)
^ string to be added to every mainmenu formspec, to be used for theming.

GUI:
core.set_background(type, texturepath,[tile],[minsize])
Expand Down
10 changes: 9 additions & 1 deletion src/gui/guiEngine.cpp
Expand Up @@ -389,6 +389,15 @@ void GUIEngine::cloudPostProcess()
}
}

/******************************************************************************/
void GUIEngine::setFormspecPrepend(const std::string &fs)
{
if (m_menu) {
m_menu->setFormspecPrepend(fs);
}
}


/******************************************************************************/
void GUIEngine::drawBackground(video::IVideoDriver *driver)
{
Expand Down Expand Up @@ -610,4 +619,3 @@ unsigned int GUIEngine::queueAsync(const std::string &serialized_func,
{
return m_script->queueAsync(serialized_func, serialized_params);
}

2 changes: 2 additions & 0 deletions src/gui/guiEngine.h
Expand Up @@ -221,6 +221,8 @@ class GUIEngine {
/** script basefolder */
std::string m_scriptdir = "";

void setFormspecPrepend(const std::string &fs);

/**
* draw background layer
* @param driver to use for drawing
Expand Down
16 changes: 16 additions & 0 deletions src/script/lua_api/l_mainmenu.cpp
Expand Up @@ -106,6 +106,21 @@ int ModApiMainMenu::l_update_formspec(lua_State *L)
return 0;
}

/******************************************************************************/
int ModApiMainMenu::l_set_formspec_prepend(lua_State *L)
{
GUIEngine *engine = getGuiEngine(L);
sanity_check(engine != NULL);

if (engine->m_startgame)
return 0;

std::string formspec(luaL_checkstring(L, 1));
engine->setFormspecPrepend(formspec);

return 0;
}

/******************************************************************************/
int ModApiMainMenu::l_start(lua_State *L)
{
Expand Down Expand Up @@ -1041,6 +1056,7 @@ int ModApiMainMenu::l_do_async_callback(lua_State *L)
void ModApiMainMenu::Initialize(lua_State *L, int top)
{
API_FCT(update_formspec);
API_FCT(set_formspec_prepend);
API_FCT(set_clouds);
API_FCT(get_textlist_index);
API_FCT(get_table_index);
Expand Down
2 changes: 2 additions & 0 deletions src/script/lua_api/l_mainmenu.h
Expand Up @@ -104,6 +104,8 @@ class ModApiMainMenu: public ModApiBase

static int l_update_formspec(lua_State *L);

static int l_set_formspec_prepend(lua_State *L);

static int l_get_screen_info(lua_State *L);

//filesystem
Expand Down

0 comments on commit 91114b5

Please sign in to comment.