mirror of
https://github.com/minetest/minetest.git
synced 2024-12-28 00:47:29 +01:00
Clean up and improve mainmenu theme / game theme code (#13885)
This commit is contained in:
parent
62eb6cfed0
commit
b1dec37adb
@ -1177,8 +1177,12 @@ end
|
||||
|
||||
function store.handle_events(event)
|
||||
if event == "DialogShow" then
|
||||
-- On mobile, don't show the "MINETEST" header behind the dialog.
|
||||
mm_game_theme.set_engine(TOUCHSCREEN_GUI)
|
||||
|
||||
-- If the store is already loaded, auto-install packages here.
|
||||
do_auto_install()
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
|
@ -41,8 +41,6 @@ function check_reinstall_mtg()
|
||||
return
|
||||
end
|
||||
|
||||
mm_game_theme.reset()
|
||||
|
||||
local maintab = ui.find_by_name("maintab")
|
||||
|
||||
local dlg = create_reinstall_mtg_dlg()
|
||||
@ -96,7 +94,10 @@ local function buttonhandler(this, fields)
|
||||
end
|
||||
|
||||
local function eventhandler(event)
|
||||
if event == "MenuQuit" then
|
||||
if event == "DialogShow" then
|
||||
mm_game_theme.set_engine()
|
||||
return true
|
||||
elseif event == "MenuQuit" then
|
||||
-- Don't allow closing the dialog with ESC, but still allow exiting
|
||||
-- Minetest.
|
||||
core.close()
|
||||
|
@ -71,6 +71,15 @@ local function version_info_buttonhandler(this, fields)
|
||||
return false
|
||||
end
|
||||
|
||||
local function version_info_eventhandler(event)
|
||||
if event == "DialogShow" then
|
||||
mm_game_theme.set_engine()
|
||||
return true
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
local function create_version_info_dlg(new_version, url)
|
||||
assert(type(new_version) == "string")
|
||||
assert(type(url) == "string")
|
||||
@ -78,7 +87,7 @@ local function create_version_info_dlg(new_version, url)
|
||||
local retval = dialog_create("version_info",
|
||||
version_info_formspec,
|
||||
version_info_buttonhandler,
|
||||
nil)
|
||||
version_info_eventhandler)
|
||||
|
||||
retval.data.new_version = new_version
|
||||
retval.data.url = url
|
||||
|
@ -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
|
||||
|
@ -89,7 +89,7 @@ local function init_globals()
|
||||
menudata.worldlist:set_sortmode("alphabetic")
|
||||
|
||||
mm_game_theme.init()
|
||||
mm_game_theme.reset()
|
||||
mm_game_theme.set_engine() -- This is just a fallback.
|
||||
|
||||
-- Create main tabview
|
||||
local tv_main = tabview_create("maintab", {x = 15.5, y = 7.1}, {x = 0, y = 0})
|
||||
|
@ -692,8 +692,19 @@ local function buttonhandler(this, fields)
|
||||
end
|
||||
|
||||
|
||||
local function eventhandler(event)
|
||||
if event == "DialogShow" then
|
||||
-- Don't show the "MINETEST" header behind the dialog.
|
||||
mm_game_theme.set_engine(true)
|
||||
return true
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
|
||||
function create_settings_dlg()
|
||||
local dlg = dialog_create("dlg_settings", get_formspec, buttonhandler, nil)
|
||||
local dlg = dialog_create("dlg_settings", get_formspec, buttonhandler, eventhandler)
|
||||
|
||||
dlg.data.page_id = update_filtered_pages("")
|
||||
|
||||
|
@ -122,6 +122,7 @@ end
|
||||
return {
|
||||
name = "about",
|
||||
caption = fgettext("About"),
|
||||
|
||||
cbf_formspec = function(tabview, name, tabdata)
|
||||
local logofile = defaulttexturedir .. "logo.png"
|
||||
local version = core.get_version()
|
||||
@ -196,6 +197,7 @@ return {
|
||||
|
||||
return fs
|
||||
end,
|
||||
|
||||
cbf_button_handler = function(this, fields, name, tabdata)
|
||||
if fields.homepage then
|
||||
core.open_url("https://www.minetest.net")
|
||||
@ -210,4 +212,10 @@ return {
|
||||
core.open_dir(core.get_user_path())
|
||||
end
|
||||
end,
|
||||
|
||||
on_change = function(type)
|
||||
if type == "ENTER" then
|
||||
mm_game_theme.set_engine()
|
||||
end
|
||||
end,
|
||||
}
|
||||
|
@ -46,6 +46,7 @@ end
|
||||
|
||||
local function on_change(type)
|
||||
if type == "ENTER" then
|
||||
mm_game_theme.set_engine()
|
||||
update_packages()
|
||||
end
|
||||
end
|
||||
@ -171,7 +172,7 @@ local function handle_doubleclick(pkg)
|
||||
packages = nil
|
||||
|
||||
mm_game_theme.init()
|
||||
mm_game_theme.reset()
|
||||
mm_game_theme.set_engine()
|
||||
end
|
||||
end
|
||||
|
||||
@ -225,7 +226,7 @@ local function handle_buttons(tabview, fields, tabname, tabdata)
|
||||
packages = nil
|
||||
|
||||
mm_game_theme.init()
|
||||
mm_game_theme.reset()
|
||||
mm_game_theme.set_engine()
|
||||
return true
|
||||
end
|
||||
|
||||
|
@ -53,11 +53,10 @@ end
|
||||
|
||||
-- Apply menu changes from given game
|
||||
function apply_game(game)
|
||||
core.set_topleft_text(game.name)
|
||||
core.settings:set("menu_last_game", game.id)
|
||||
menudata.worldlist:set_filtercriteria(game.id)
|
||||
|
||||
mm_game_theme.update("singleplayer", game) -- this refreshes the formspec
|
||||
mm_game_theme.set_game(game)
|
||||
|
||||
local index = filterlist.get_current_index(menudata.worldlist,
|
||||
tonumber(core.settings:get("mainmenu_last_selected_world")))
|
||||
@ -396,7 +395,6 @@ local function main_button_handler(this, fields, name, tabdata)
|
||||
create_world_dlg:set_parent(this)
|
||||
this:hide()
|
||||
create_world_dlg:show()
|
||||
mm_game_theme.update("singleplayer", current_game())
|
||||
return true
|
||||
end
|
||||
|
||||
@ -413,7 +411,6 @@ local function main_button_handler(this, fields, name, tabdata)
|
||||
delete_world_dlg:set_parent(this)
|
||||
this:hide()
|
||||
delete_world_dlg:show()
|
||||
mm_game_theme.update("singleplayer",current_game())
|
||||
end
|
||||
end
|
||||
|
||||
@ -431,7 +428,6 @@ local function main_button_handler(this, fields, name, tabdata)
|
||||
configdialog:set_parent(this)
|
||||
this:hide()
|
||||
configdialog:show()
|
||||
mm_game_theme.update("singleplayer",current_game())
|
||||
end
|
||||
end
|
||||
|
||||
@ -439,27 +435,24 @@ local function main_button_handler(this, fields, name, tabdata)
|
||||
end
|
||||
end
|
||||
|
||||
local function on_change(type, old_tab, new_tab)
|
||||
if (type == "ENTER") then
|
||||
local function on_change(type)
|
||||
if type == "ENTER" then
|
||||
local game = current_game()
|
||||
if game then
|
||||
apply_game(game)
|
||||
else
|
||||
mm_game_theme.set_engine()
|
||||
end
|
||||
|
||||
if singleplayer_refresh_gamebar() then
|
||||
ui.find_by_name("game_button_bar"):show()
|
||||
end
|
||||
else
|
||||
elseif type == "LEAVE" then
|
||||
menudata.worldlist:set_filtercriteria(nil)
|
||||
local gamebar = ui.find_by_name("game_button_bar")
|
||||
if gamebar then
|
||||
gamebar:hide()
|
||||
end
|
||||
core.set_topleft_text("")
|
||||
-- If new_tab is nil, a dialog is being shown; avoid resetting the theme
|
||||
if new_tab then
|
||||
mm_game_theme.update(new_tab,nil)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -416,9 +416,11 @@ local function main_button_handler(tabview, fields, name, tabdata)
|
||||
return false
|
||||
end
|
||||
|
||||
local function on_change(type, old_tab, new_tab)
|
||||
if type == "LEAVE" then return end
|
||||
serverlistmgr.sync()
|
||||
local function on_change(type)
|
||||
if type == "ENTER" then
|
||||
mm_game_theme.set_engine()
|
||||
serverlistmgr.sync()
|
||||
end
|
||||
end
|
||||
|
||||
return {
|
||||
|
Loading…
Reference in New Issue
Block a user