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_game_theme.init()
23 mm_game_theme.defaulttexturedir = core.get_texturepath_share() .. DIR_DELIM .. "base" ..
24 DIR_DELIM .. "pack" .. DIR_DELIM
25 mm_game_theme.basetexturedir = mm_game_theme.defaulttexturedir
27 mm_game_theme.texturepack = core.settings:get("texture_path")
29 mm_game_theme.gameid = nil
31 mm_game_theme.music_handle = nil
34 --------------------------------------------------------------------------------
35 function mm_game_theme.update(tab,gamedetails)
36 if tab ~= "singleplayer" then
41 if gamedetails == nil then
45 mm_game_theme.update_game(gamedetails)
48 --------------------------------------------------------------------------------
49 function mm_game_theme.reset()
50 mm_game_theme.gameid = nil
52 local have_overlay = mm_game_theme.set_generic("overlay")
54 if not have_overlay then
55 have_bg = mm_game_theme.set_generic("background")
58 mm_game_theme.clear("header")
59 mm_game_theme.clear("footer")
60 core.set_clouds(false)
62 mm_game_theme.set_generic("footer")
63 mm_game_theme.set_generic("header")
66 if core.settings:get_bool("menu_clouds") then
69 mm_game_theme.set_dirt_bg()
73 if mm_game_theme.music_handle ~= nil then
74 core.sound_stop(mm_game_theme.music_handle)
78 --------------------------------------------------------------------------------
79 function mm_game_theme.update_game(gamedetails)
80 if mm_game_theme.gameid == gamedetails.id then
85 local have_overlay = mm_game_theme.set_game("overlay",gamedetails)
87 if not have_overlay then
88 have_bg = mm_game_theme.set_game("background",gamedetails)
91 mm_game_theme.clear("header")
92 mm_game_theme.clear("footer")
93 core.set_clouds(false)
97 if core.settings:get_bool("menu_clouds") then
100 mm_game_theme.set_dirt_bg()
104 mm_game_theme.set_game("footer",gamedetails)
105 mm_game_theme.set_game("header",gamedetails)
107 mm_game_theme.gameid = gamedetails.id
110 --------------------------------------------------------------------------------
111 function mm_game_theme.clear(identifier)
112 core.set_background(identifier,"")
115 --------------------------------------------------------------------------------
116 function mm_game_theme.set_generic(identifier)
117 --try texture pack first
118 if mm_game_theme.texturepack ~= nil then
119 local path = mm_game_theme.texturepack .. DIR_DELIM .."menu_" ..
121 if core.set_background(identifier,path) then
126 if mm_game_theme.defaulttexturedir ~= nil then
127 local path = mm_game_theme.defaulttexturedir .. DIR_DELIM .."menu_" ..
129 if core.set_background(identifier,path) then
137 --------------------------------------------------------------------------------
138 function mm_game_theme.set_game(identifier, gamedetails)
140 if gamedetails == nil then
144 mm_game_theme.set_music(gamedetails)
146 if mm_game_theme.texturepack ~= nil then
147 local path = mm_game_theme.texturepack .. DIR_DELIM ..
148 gamedetails.id .. "_menu_" .. identifier .. ".png"
149 if core.set_background(identifier, path) then
154 -- Find out how many randomized textures the game provides
157 local menu_files = core.get_dir_list(gamedetails.path .. DIR_DELIM .. "menu", false)
158 for i = 1, #menu_files do
159 filename = identifier .. "." .. i .. ".png"
160 if table.indexof(menu_files, filename) == -1 then
165 -- Select random texture, 0 means standard texture
166 n = math.random(0, n)
168 filename = identifier .. ".png"
170 filename = identifier .. "." .. n .. ".png"
173 local path = gamedetails.path .. DIR_DELIM .. "menu" ..
174 DIR_DELIM .. filename
175 if core.set_background(identifier, path) then
182 --------------------------------------------------------------------------------
183 function mm_game_theme.set_dirt_bg()
184 if mm_game_theme.texturepack ~= nil then
185 local path = mm_game_theme.texturepack .. DIR_DELIM .."default_dirt.png"
186 if core.set_background("background", path, true, 128) then
191 -- Use universal fallback texture in textures/base/pack
192 local minimalpath = defaulttexturedir .. "menu_bg.png"
193 core.set_background("background", minimalpath, true, 128)
196 --------------------------------------------------------------------------------
197 function mm_game_theme.set_music(gamedetails)
198 if mm_game_theme.music_handle ~= nil then
199 core.sound_stop(mm_game_theme.music_handle)
201 local music_path = gamedetails.path .. DIR_DELIM .. "menu" .. DIR_DELIM .. "theme"
202 mm_game_theme.music_handle = core.sound_play(music_path, true)