Skip to content

Commit 91114b5

Browse files
rubenwardysfan5
authored andcommittedAug 12, 2019
Add support for set_formspec_prepend in main menu (#8611)
1 parent a067d40 commit 91114b5

File tree

5 files changed

+31
-1
lines changed

5 files changed

+31
-1
lines changed
 

‎doc/menu_lua_api.txt

+2
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ core.explode_table_event(string) -> table
7979
core.explode_textlist_event(string) -> table
8080
^ returns e.g. {type="CHG", index=1}
8181
^ type: "INV" (no row selected), "CHG" (selected) or "DCL" (double-click)
82+
core.set_formspec_prepend(formspec)
83+
^ string to be added to every mainmenu formspec, to be used for theming.
8284

8385
GUI:
8486
core.set_background(type, texturepath,[tile],[minsize])

‎src/gui/guiEngine.cpp

+9-1
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,15 @@ void GUIEngine::cloudPostProcess()
389389
}
390390
}
391391

392+
/******************************************************************************/
393+
void GUIEngine::setFormspecPrepend(const std::string &fs)
394+
{
395+
if (m_menu) {
396+
m_menu->setFormspecPrepend(fs);
397+
}
398+
}
399+
400+
392401
/******************************************************************************/
393402
void GUIEngine::drawBackground(video::IVideoDriver *driver)
394403
{
@@ -610,4 +619,3 @@ unsigned int GUIEngine::queueAsync(const std::string &serialized_func,
610619
{
611620
return m_script->queueAsync(serialized_func, serialized_params);
612621
}
613-

‎src/gui/guiEngine.h

+2
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,8 @@ class GUIEngine {
221221
/** script basefolder */
222222
std::string m_scriptdir = "";
223223

224+
void setFormspecPrepend(const std::string &fs);
225+
224226
/**
225227
* draw background layer
226228
* @param driver to use for drawing

‎src/script/lua_api/l_mainmenu.cpp

+16
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,21 @@ int ModApiMainMenu::l_update_formspec(lua_State *L)
106106
return 0;
107107
}
108108

109+
/******************************************************************************/
110+
int ModApiMainMenu::l_set_formspec_prepend(lua_State *L)
111+
{
112+
GUIEngine *engine = getGuiEngine(L);
113+
sanity_check(engine != NULL);
114+
115+
if (engine->m_startgame)
116+
return 0;
117+
118+
std::string formspec(luaL_checkstring(L, 1));
119+
engine->setFormspecPrepend(formspec);
120+
121+
return 0;
122+
}
123+
109124
/******************************************************************************/
110125
int ModApiMainMenu::l_start(lua_State *L)
111126
{
@@ -1041,6 +1056,7 @@ int ModApiMainMenu::l_do_async_callback(lua_State *L)
10411056
void ModApiMainMenu::Initialize(lua_State *L, int top)
10421057
{
10431058
API_FCT(update_formspec);
1059+
API_FCT(set_formspec_prepend);
10441060
API_FCT(set_clouds);
10451061
API_FCT(get_textlist_index);
10461062
API_FCT(get_table_index);

‎src/script/lua_api/l_mainmenu.h

+2
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ class ModApiMainMenu: public ModApiBase
104104

105105
static int l_update_formspec(lua_State *L);
106106

107+
static int l_set_formspec_prepend(lua_State *L);
108+
107109
static int l_get_screen_info(lua_State *L);
108110

109111
//filesystem

0 commit comments

Comments
 (0)
Please sign in to comment.