Add support for set_formspec_prepend in main menu (#8611)
authorrubenwardy <rw@rubenwardy.com>
Mon, 12 Aug 2019 17:16:35 +0000 (18:16 +0100)
committersfan5 <sfan5@live.de>
Mon, 12 Aug 2019 17:16:35 +0000 (19:16 +0200)
doc/menu_lua_api.txt
src/gui/guiEngine.cpp
src/gui/guiEngine.h
src/script/lua_api/l_mainmenu.cpp
src/script/lua_api/l_mainmenu.h

index f6b2ffbd28ccfd3a6b955212cc6f62cde9c7458d..a2f9c3f5ba58df41aa7fef1c80be65088ef17460 100644 (file)
@@ -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])
index 241144a2aa3678111932eb6dcbd599367e29082a..3107d64cd08349a4afe8364280863dd79eca8293 100644 (file)
@@ -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)
 {
@@ -610,4 +619,3 @@ unsigned int GUIEngine::queueAsync(const std::string &serialized_func,
 {
        return m_script->queueAsync(serialized_func, serialized_params);
 }
-
index 0ff5030c0b93b677c91301ae95e2a59c373c305d..e55531bbca638c9c2f2f5b9331b0b3a8b817c9fb 100644 (file)
@@ -221,6 +221,8 @@ private:
        /** script basefolder */
        std::string              m_scriptdir = "";
 
+       void setFormspecPrepend(const std::string &fs);
+
        /**
         * draw background layer
         * @param driver to use for drawing
index 2094da241b095121932c9e1ed65fb43f3be66e6b..76db7ed13be24ccd2be4b5b0347d8359f1eda834 100644 (file)
@@ -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)
 {
@@ -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);
index 9ff8229609956906da1a74b638ba2b0cc1b4b9e1..b2ca4932065cc74d8ab89693a5c38e53978a8a8f 100644 (file)
@@ -104,6 +104,8 @@ private:
 
        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