1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-08-01 17:38:41 +00:00

Clean up and improve mainmenu theme / game theme code (#13885)

This commit is contained in:
Gregor Parzefall 2023-10-18 20:18:50 +02:00 committed by GitHub
parent 62eb6cfed0
commit b1dec37adb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 96 additions and 80 deletions

View file

@ -20,10 +20,6 @@ mm_game_theme = {}
--------------------------------------------------------------------------------
function mm_game_theme.init()
mm_game_theme.defaulttexturedir = core.get_texturepath_share() .. DIR_DELIM .. "base" ..
DIR_DELIM .. "pack" .. DIR_DELIM
mm_game_theme.basetexturedir = mm_game_theme.defaulttexturedir
mm_game_theme.texturepack = core.settings:get("texture_path")
mm_game_theme.gameid = nil
@ -32,35 +28,27 @@ function mm_game_theme.init()
end
--------------------------------------------------------------------------------
function mm_game_theme.update(tab,gamedetails)
if tab ~= "singleplayer" then
mm_game_theme.reset()
return
end
if gamedetails == nil then
return
end
mm_game_theme.update_game(gamedetails)
end
--------------------------------------------------------------------------------
function mm_game_theme.reset()
function mm_game_theme.set_engine(hide_decorations)
mm_game_theme.gameid = nil
mm_game_theme.stop_music()
core.set_topleft_text("")
local have_bg = false
local have_overlay = mm_game_theme.set_generic("overlay")
local have_overlay = mm_game_theme.set_engine_single("overlay")
if not have_overlay then
have_bg = mm_game_theme.set_generic("background")
have_bg = mm_game_theme.set_engine_single("background")
end
mm_game_theme.clear("header")
mm_game_theme.clear("footer")
mm_game_theme.clear_single("header")
mm_game_theme.clear_single("footer")
core.set_clouds(false)
mm_game_theme.set_generic("footer")
mm_game_theme.set_generic("header")
if not hide_decorations then
mm_game_theme.set_engine_single("header")
mm_game_theme.set_engine_single("footer")
end
if not have_bg then
if core.settings:get_bool("menu_clouds") then
@ -69,51 +57,50 @@ function mm_game_theme.reset()
mm_game_theme.set_dirt_bg()
end
end
if mm_game_theme.music_handle ~= nil then
core.sound_stop(mm_game_theme.music_handle)
end
end
--------------------------------------------------------------------------------
function mm_game_theme.update_game(gamedetails)
function mm_game_theme.set_game(gamedetails)
assert(gamedetails ~= nil)
if mm_game_theme.gameid == gamedetails.id then
return
end
mm_game_theme.gameid = gamedetails.id
mm_game_theme.set_music(gamedetails)
core.set_topleft_text(gamedetails.name)
local have_bg = false
local have_overlay = mm_game_theme.set_game("overlay",gamedetails)
local have_overlay = mm_game_theme.set_game_single("overlay", gamedetails)
if not have_overlay then
have_bg = mm_game_theme.set_game("background",gamedetails)
have_bg = mm_game_theme.set_game_single("background", gamedetails)
end
mm_game_theme.clear("header")
mm_game_theme.clear("footer")
mm_game_theme.clear_single("header")
mm_game_theme.clear_single("footer")
core.set_clouds(false)
if not have_bg then
mm_game_theme.set_game_single("header", gamedetails)
mm_game_theme.set_game_single("footer", gamedetails)
if not have_bg then
if core.settings:get_bool("menu_clouds") then
core.set_clouds(true)
else
mm_game_theme.set_dirt_bg()
end
end
mm_game_theme.set_game("footer",gamedetails)
mm_game_theme.set_game("header",gamedetails)
mm_game_theme.gameid = gamedetails.id
end
--------------------------------------------------------------------------------
function mm_game_theme.clear(identifier)
function mm_game_theme.clear_single(identifier)
core.set_background(identifier,"")
end
--------------------------------------------------------------------------------
function mm_game_theme.set_generic(identifier)
function mm_game_theme.set_engine_single(identifier)
--try texture pack first
if mm_game_theme.texturepack ~= nil then
local path = mm_game_theme.texturepack .. DIR_DELIM .."menu_" ..
@ -123,25 +110,17 @@ function mm_game_theme.set_generic(identifier)
end
end
if mm_game_theme.defaulttexturedir ~= nil then
local path = mm_game_theme.defaulttexturedir .. DIR_DELIM .."menu_" ..
identifier .. ".png"
if core.set_background(identifier,path) then
return true
end
local path = defaulttexturedir .. DIR_DELIM .. "menu_" .. identifier .. ".png"
if core.set_background(identifier, path) then
return true
end
return false
end
--------------------------------------------------------------------------------
function mm_game_theme.set_game(identifier, gamedetails)
if gamedetails == nil then
return false
end
mm_game_theme.set_music(gamedetails)
function mm_game_theme.set_game_single(identifier, gamedetails)
assert(gamedetails ~= nil)
if mm_game_theme.texturepack ~= nil then
local path = mm_game_theme.texturepack .. DIR_DELIM ..
@ -194,10 +173,18 @@ function mm_game_theme.set_dirt_bg()
end
--------------------------------------------------------------------------------
function mm_game_theme.set_music(gamedetails)
function mm_game_theme.stop_music()
if mm_game_theme.music_handle ~= nil then
core.sound_stop(mm_game_theme.music_handle)
end
end
--------------------------------------------------------------------------------
function mm_game_theme.set_music(gamedetails)
mm_game_theme.stop_music()
assert(gamedetails ~= nil)
local music_path = gamedetails.path .. DIR_DELIM .. "menu" .. DIR_DELIM .. "theme"
mm_game_theme.music_handle = core.sound_play(music_path, true)
end