]> git.lizzy.rs Git - minetest.git/blobdiff - builtin/mainmenu/textures.lua
Allow random menu images for subgames
[minetest.git] / builtin / mainmenu / textures.lua
index cec12235c44e88b6b88e01de0ed28558dd99a055..700bdb5cc05a0caa957cc1cd12723000c0dffd26 100644 (file)
@@ -60,9 +60,12 @@ function mm_texture.reset()
        mm_texture.set_generic("footer")
        mm_texture.set_generic("header")
        
-       if not have_bg and
-               core.setting_getbool("menu_clouds") then
+       if not have_bg then
+               if core.setting_getbool("menu_clouds") then
                        core.set_clouds(true)
+               else
+                       mm_texture.set_dirt_bg()
+               end
        end
 end
 
@@ -83,9 +86,13 @@ function mm_texture.update_game(gamedetails)
        mm_texture.clear("footer")
        core.set_clouds(false)
        
-       if not have_bg and
-               core.setting_getbool("menu_clouds") then
+       if not have_bg then
+               
+               if core.setting_getbool("menu_clouds") then
                        core.set_clouds(true)
+               else
+                       mm_texture.set_dirt_bg()
+               end
        end
        
        mm_texture.set_game("footer",gamedetails)
@@ -122,7 +129,7 @@ function mm_texture.set_generic(identifier)
 end
 
 --------------------------------------------------------------------------------
-function mm_texture.set_game(identifier,gamedetails)
+function mm_texture.set_game(identifier, gamedetails)
        
        if gamedetails == nil then
                return false
@@ -130,17 +137,48 @@ function mm_texture.set_game(identifier,gamedetails)
 
        if mm_texture.texturepack ~= nil then
                local path = mm_texture.texturepack .. DIR_DELIM ..
-                                               gamedetails.id .. "_menu_" .. identifier .. ".png"
-               if core.set_background(identifier,path) then
+                       gamedetails.id .. "_menu_" .. identifier .. ".png"
+               if core.set_background(identifier, path) then
                        return true
                end
        end
        
-       local path = gamedetails.path .. DIR_DELIM .."menu" ..
-                                                                        DIR_DELIM .. identifier .. ".png"
-       if core.set_background(identifier,path) then
+       -- Find out how many randomized textures the subgame provides
+       local n, filename
+       local menu_files = core.get_dir_list(gamedetails.path .. DIR_DELIM .. "menu", false)
+       for i = 1, #menu_files do
+               local filename = identifier .. "." .. i .. ".png"
+               if table.indexof(menu_files, filename) == -1 then
+                       n = i - 1
+                       break
+               end
+       end
+       -- Select random texture, 0 means standard texture
+       n = math.random(0, n)
+       if n == 0 then
+               filename = identifier .. ".png"
+       else
+               filename = identifier .. "." .. n .. ".png"
+       end
+
+       local path = gamedetails.path .. DIR_DELIM .. "menu" ..
+               DIR_DELIM .. filename
+       if core.set_background(identifier, path) then
                return true
        end
        
        return false
 end
+
+function mm_texture.set_dirt_bg()
+       if mm_texture.texturepack ~= nil then
+               local path = mm_texture.texturepack .. DIR_DELIM .."default_dirt.png"
+               if core.set_background("background", path, true, 128) then
+                       return true
+               end
+       end
+       
+       --use base pack
+       local minimalpath = defaulttexturedir .. "dirt_bg.png"
+       core.set_background("background", minimalpath, true, 128)
+end