]> git.lizzy.rs Git - dragonfireclient.git/commitdiff
Add texture pack selection to main menu
authorNovatux <nathanael.courant@laposte.net>
Fri, 2 Aug 2013 13:18:48 +0000 (15:18 +0200)
committerPilzAdam <pilzadam@minetest.net>
Sun, 4 Aug 2013 14:52:30 +0000 (16:52 +0200)
builtin/mainmenu.lua
src/game.cpp
src/guiLuaApi.cpp
src/guiLuaApi.h
src/server.cpp
src/tile.cpp
src/tile.h
src/util/container.h
textures/all/textures_here.txt [deleted file]
textures/texture_packs_here.txt [new file with mode: 0644]

index 0bd2b13aa426abd8a7e976620fbe64e18d3a7299..3e3777227210d6299ad21cb2ef2c9ad79b1d70c9 100644 (file)
@@ -20,6 +20,17 @@ menu = {}
 local tabbuilder = {}
 local worldlist = nil
 
+--------------------------------------------------------------------------------
+local function filterTP(TPlist)
+       TPlist2 = {"None"}
+       for _,i in ipairs(TPlist) do
+               if i~="base" then
+                       table.insert(TPlist2, i)
+               end
+       end
+       return TPlist2
+end
+
 --------------------------------------------------------------------------------
 function menu.render_favorite(spec,render_details)
        local text = ""
@@ -162,6 +173,23 @@ function menu.render_world_list()
        return retval
 end
 
+--------------------------------------------------------------------------------
+function menu.render_TP_list(TPlist)
+       local retval = ""
+
+       --local current_TP = filterlist.get_list(TPlist)
+
+       for i,v in ipairs(TPlist) do
+               if retval ~= "" then
+                       retval = retval ..","
+               end
+
+               retval = retval .. v
+       end
+
+       return retval
+end
+
 --------------------------------------------------------------------------------
 function menu.init()
        --init menu data
@@ -179,8 +207,7 @@ function menu.init()
                menu.favorites = engine.get_favorites("local")
        end
        
-       menu.defaulttexturedir = engine.get_gamepath() .. DIR_DELIM .. ".." ..
-                                       DIR_DELIM .. "textures" .. DIR_DELIM .. "base" .. 
+       menu.defaulttexturedir = engine.get_texturepath() .. DIR_DELIM .. "base" .. 
                                        DIR_DELIM .. "pack" .. DIR_DELIM
 end
 
@@ -307,6 +334,10 @@ function tabbuilder.gettab()
                retval = retval .. tabbuilder.tab_settings()
        end
        
+       if tabbuilder.current_tab == "texture_packs" then
+               retval = retval .. tabbuilder.tab_TP()
+       end
+       
        if tabbuilder.current_tab == "credits" then
                retval = retval .. tabbuilder.tab_credits()
        end
@@ -734,6 +765,23 @@ function tabbuilder.handle_singleplayer_buttons(fields)
        end
 end
 
+--------------------------------------------------------------------------------
+function tabbuilder.handle_TP_buttons(fields)
+       if fields["TPs"] ~= nil then
+               local event = explode_textlist_event(fields["TPs"])
+               if event.typ == "CHG" or event.typ=="DCL" then
+                       local index = engine.get_textlist_index("TPs")
+                       engine.setting_set("mainmenu_last_selected_TP",
+                               index)
+                       local TPlist = filterTP(engine.get_dirlist(engine.get_texturepath(), true))
+                       local TPname = TPlist[engine.get_textlist_index("TPs")]
+                       local TPpath = engine.get_texturepath()..DIR_DELIM..TPname
+                       if TPname == "None" then TPpath = "" end
+                       engine.setting_set("texture_path", TPpath)
+               end
+       end
+end
+
 --------------------------------------------------------------------------------
 function tabbuilder.tab_header()
 
@@ -798,6 +846,7 @@ function tabbuilder.init()
        table.insert(tabbuilder.current_buttons,{name="multiplayer", caption="Client"})
        table.insert(tabbuilder.current_buttons,{name="server", caption="Server"})
        table.insert(tabbuilder.current_buttons,{name="settings", caption="Settings"})
+       table.insert(tabbuilder.current_buttons,{name="texture_packs", caption="Texture Packs"})
        
        if engine.setting_getbool("main_menu_game_mgr") then
                table.insert(tabbuilder.current_buttons,{name="game_mgr", caption="Games"})
@@ -946,6 +995,49 @@ function tabbuilder.tab_singleplayer()
                        menubar.formspec
 end
 
+--------------------------------------------------------------------------------
+function tabbuilder.tab_TP()
+       local TPpath = engine.setting_get("texture_path")
+       local TPlist = filterTP(engine.get_dirlist(engine.get_texturepath(), true))
+       local index = tonumber(engine.setting_get("mainmenu_last_selected_TP"))
+       if index == nil then index = 1 end
+       if TPpath == "" then
+               return  "label[4,-0.25;Select texture pack:]"..
+                       "vertlabel[0,-0.25;TEXTURE PACKS]" ..
+                       "textlist[4,0.25;7.5,5.0;TPs;" ..
+                       menu.render_TP_list(TPlist) ..
+                       ";" .. index .. "]" ..
+                       menubar.formspec
+       end
+       local TPinfofile = TPpath..DIR_DELIM.."info.txt"
+       local f = io.open(TPinfofile, "r")
+       if f==nil then
+               menu.TPinfo = "No information available" 
+       else
+               menu.TPinfo = f:read("*all")
+               f:close()
+       end
+       local TPscreenfile = TPpath..DIR_DELIM.."screenshot.png"
+       local f = io.open(TPscreenfile, "r")
+       if f==nil then
+               menu.TPscreen = nil
+       else
+               menu.TPscreen = TPscreenfile
+               f:close()
+       end
+       
+       local no_screenshot = engine.get_texturepath()..DIR_DELIM.."base"..DIR_DELIM.."pack"..DIR_DELIM.."no_screenshot.png"
+
+       return  "label[4,-0.25;Select texture pack:]"..
+                       "vertlabel[0,-0.25;TEXTURE PACKS]" ..
+                       "textlist[4,0.25;7.5,5.0;TPs;" ..
+                       menu.render_TP_list(TPlist) ..
+                       ";" .. index .. "]" ..
+                       "image[0.65,0.25;4.0,3.7;"..(menu.TPscreen or no_screenshot).."]"..
+                       "textarea[1.0,3.25;3.7,1.5;;"..(menu.TPinfo or "")..";]"..
+                       menubar.formspec
+end
+
 --------------------------------------------------------------------------------
 function tabbuilder.tab_credits()
        return  "vertlabel[0,-0.5;CREDITS]" ..
@@ -1039,6 +1131,10 @@ engine.button_handler = function(fields)
                tabbuilder.handle_singleplayer_buttons(fields)
        end
        
+       if tabbuilder.current_tab == "texture_packs" then
+               tabbuilder.handle_TP_buttons(fields)
+       end
+       
        if tabbuilder.current_tab == "multiplayer" then
                tabbuilder.handle_multiplayer_buttons(fields)
        end
index 205c345153264272d593126995d3c6f9694cdbdd..cb2a508239e4222ee2364fef0d0ca844f6beebdc 100644 (file)
@@ -3482,6 +3482,7 @@ void the_game(
                infostream << "\t\t" << i << ":" << texture->getName().getPath().c_str()
                                << std::endl;
        }
+       clearTextureNameCache();
        infostream << "\tRemaining materials: "
                << driver-> getMaterialRendererCount ()
                << " (note: irrlicht doesn't support removing renderers)"<< std::endl;
index 485cab88393150bc7f5c4dcd47836eef76798cd6..5d3e9dc1241e66f0573b1c95eac77237534026fd 100644 (file)
@@ -82,6 +82,7 @@ void guiLuaApi::initialize(lua_State* L,GUIEngine* engine)
        retval &= API_FCT(set_topleft_text);
        retval &= API_FCT(get_modpath);
        retval &= API_FCT(get_gamepath);
+       retval &= API_FCT(get_texturepath);
        retval &= API_FCT(get_dirlist);
        retval &= API_FCT(create_dir);
        retval &= API_FCT(delete_dir);
@@ -829,6 +830,15 @@ int guiLuaApi::l_get_gamepath(lua_State *L)
        return 1;
 }
 
+/******************************************************************************/
+int guiLuaApi::l_get_texturepath(lua_State *L)
+{
+       std::string gamepath
+                       = fs::RemoveRelativePathComponents(porting::path_user + DIR_DELIM + "textures");
+       lua_pushstring(L, gamepath.c_str());
+       return 1;
+}
+
 /******************************************************************************/
 int guiLuaApi::l_get_dirlist(lua_State *L) {
        const char *path        = luaL_checkstring(L, 1);
index 11b94ba75ab0aee94b61eae7f065a0b3aa8913cc..9555f00c5921e7b5d23691d30569a4ca96be06eb 100644 (file)
@@ -164,6 +164,8 @@ class guiLuaApi {
        static int l_get_modpath(lua_State *L);
 
        static int l_get_gamepath(lua_State *L);
+       
+       static int l_get_texturepath(lua_State *L);
 
        static int l_get_dirlist(lua_State *L);
 
index 4099d99978c11da34a3c1680be38bca715efd509..f5f6645a220eef45d079433d8ecd7e5db5f57209 100644 (file)
@@ -4273,8 +4273,7 @@ void Server::fillMediaCache()
                paths.push_back(mod.path + DIR_DELIM + "media");
                paths.push_back(mod.path + DIR_DELIM + "models");
        }
-       std::string path_all = "textures";
-       paths.push_back(path_all + DIR_DELIM + "all");
+       paths.push_back(porting::path_user + DIR_DELIM + "textures" + DIR_DELIM + "server");
 
        // Collect media file information from paths into cache
        for(std::list<std::string>::iterator i = paths.begin();
index 6e4fde011acf411ec8ba7021a8cd472679199231..726f7f6020f759b99b6417d1b3af30352247f3c7 100644 (file)
@@ -131,18 +131,6 @@ std::string getTexturePath(const std::string &filename)
                // Check all filename extensions. Returns "" if not found.
                fullpath = getImagePath(testpath);
        }
-       
-       /*
-               Check from $user/textures/all
-       */
-       if(fullpath == "")
-       {
-               std::string texture_path = porting::path_user + DIR_DELIM
-                               + "textures" + DIR_DELIM + "all";
-               std::string testpath = texture_path + DIR_DELIM + filename;
-               // Check all filename extensions. Returns "" if not found.
-               fullpath = getImagePath(testpath);
-       }
 
        /*
                Check from default data directory
@@ -163,6 +151,11 @@ std::string getTexturePath(const std::string &filename)
        return fullpath;
 }
 
+void clearTextureNameCache()
+{
+       g_texturename_to_path_cache.clear();
+}
+
 /*
        Stores internal information about a texture.
 */
index 8008d212715ad161b387d1cd24aa9d0737501fc8..23c2143506b1fdafdf0e6eb20f19823b2dc0b5ed 100644 (file)
@@ -57,6 +57,8 @@ std::string getImagePath(std::string path);
 */
 std::string getTexturePath(const std::string &filename);
 
+void clearTextureNameCache();
+
 /*
        ITextureSource::generateTextureFromMesh parameters
 */
index 9bb388f0e69bac2558e1d9bd2bedb164c26db38d..84616d2dba88a3617a15b004f947086fb764de48 100644 (file)
@@ -118,6 +118,11 @@ class MutexedMap
                }
                return result;
        }
+       
+       void clear ()
+       {
+               m_values.clear();
+       }
 
 private:
        std::map<Key, Value> m_values;
diff --git a/textures/all/textures_here.txt b/textures/all/textures_here.txt
deleted file mode 100644 (file)
index 3794085..0000000
+++ /dev/null
@@ -1 +0,0 @@
-If you haven't modified the texture_path setting, you can copy textures of your texture packs into here. Folders are currently not supported.
diff --git a/textures/texture_packs_here.txt b/textures/texture_packs_here.txt
new file mode 100644 (file)
index 0000000..4c9afe1
--- /dev/null
@@ -0,0 +1 @@
+Put your texture pack folders in this folder. Textures in the "server" pack will be used by the server.