2 --Copyright (C) 2013 sapier
4 --This program is free software; you can redistribute it and/or modify
5 --it under the terms of the GNU Lesser General Public License as published by
6 --the Free Software Foundation; either version 2.1 of the License, or
7 --(at your option) any later version.
9 --This program is distributed in the hope that it will be useful,
10 --but WITHOUT ANY WARRANTY; without even the implied warranty of
11 --MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 --GNU Lesser General Public License for more details.
14 --You should have received a copy of the GNU Lesser General Public License along
15 --with this program; if not, write to the Free Software Foundation, Inc.,
16 --51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 --------------------------------------------------------------------------------
22 function mm_texture.init()
23 mm_texture.defaulttexturedir = core.get_texturepath() .. DIR_DELIM .. "base" ..
24 DIR_DELIM .. "pack" .. DIR_DELIM
25 mm_texture.basetexturedir = mm_texture.defaulttexturedir
27 mm_texture.texturepack = core.setting_get("texture_path")
29 mm_texture.gameid = nil
32 --------------------------------------------------------------------------------
33 function mm_texture.update(tab,gamedetails)
34 if tab ~= "singleplayer" then
39 if gamedetails == nil then
43 mm_texture.update_game(gamedetails)
46 --------------------------------------------------------------------------------
47 function mm_texture.reset()
48 mm_texture.gameid = nil
50 local have_overlay = mm_texture.set_generic("overlay")
52 if not have_overlay then
53 have_bg = mm_texture.set_generic("background")
56 mm_texture.clear("header")
57 mm_texture.clear("footer")
58 core.set_clouds(false)
60 mm_texture.set_generic("footer")
61 mm_texture.set_generic("header")
64 if core.setting_getbool("menu_clouds") then
67 mm_texture.set_dirt_bg()
72 --------------------------------------------------------------------------------
73 function mm_texture.update_game(gamedetails)
74 if mm_texture.gameid == gamedetails.id then
79 local have_overlay = mm_texture.set_game("overlay",gamedetails)
81 if not have_overlay then
82 have_bg = mm_texture.set_game("background",gamedetails)
85 mm_texture.clear("header")
86 mm_texture.clear("footer")
87 core.set_clouds(false)
91 if core.setting_getbool("menu_clouds") then
94 mm_texture.set_dirt_bg()
98 mm_texture.set_game("footer",gamedetails)
99 mm_texture.set_game("header",gamedetails)
101 mm_texture.gameid = gamedetails.id
104 --------------------------------------------------------------------------------
105 function mm_texture.clear(identifier)
106 core.set_background(identifier,"")
109 --------------------------------------------------------------------------------
110 function mm_texture.set_generic(identifier)
111 --try texture pack first
112 if mm_texture.texturepack ~= nil then
113 local path = mm_texture.texturepack .. DIR_DELIM .."menu_" ..
115 if core.set_background(identifier,path) then
120 if mm_texture.defaulttexturedir ~= nil then
121 local path = mm_texture.defaulttexturedir .. DIR_DELIM .."menu_" ..
123 if core.set_background(identifier,path) then
131 --------------------------------------------------------------------------------
132 function mm_texture.set_game(identifier, gamedetails)
134 if gamedetails == nil then
138 if mm_texture.texturepack ~= nil then
139 local path = mm_texture.texturepack .. DIR_DELIM ..
140 gamedetails.id .. "_menu_" .. identifier .. ".png"
141 if core.set_background(identifier, path) then
146 -- Find out how many randomized textures the subgame provides
149 local menu_files = core.get_dir_list(gamedetails.path .. DIR_DELIM .. "menu", false)
150 for i = 1, #menu_files do
151 filename = identifier .. "." .. i .. ".png"
152 if table.indexof(menu_files, filename) == -1 then
157 -- Select random texture, 0 means standard texture
158 n = math.random(0, n)
160 filename = identifier .. ".png"
162 filename = identifier .. "." .. n .. ".png"
165 local path = gamedetails.path .. DIR_DELIM .. "menu" ..
166 DIR_DELIM .. filename
167 if core.set_background(identifier, path) then
174 function mm_texture.set_dirt_bg()
175 if mm_texture.texturepack ~= nil then
176 local path = mm_texture.texturepack .. DIR_DELIM .."default_dirt.png"
177 if core.set_background("background", path, true, 128) then
183 local minimalpath = defaulttexturedir .. "dirt_bg.png"
184 core.set_background("background", minimalpath, true, 128)