mirror of
https://github.com/MCLx86/xtreemtest.git
synced 2024-11-24 19:22:13 +01:00
More main menu tweaks
This commit is contained in:
parent
f15b796344
commit
78fb1bc302
38
builtin/common/async_event.lua
Normal file
38
builtin/common/async_event.lua
Normal file
@ -0,0 +1,38 @@
|
||||
core.async_jobs = {}
|
||||
|
||||
local function handle_job(jobid, serialized_retval)
|
||||
local retval = core.deserialize(serialized_retval)
|
||||
assert(type(core.async_jobs[jobid]) == "function")
|
||||
core.async_jobs[jobid](retval)
|
||||
core.async_jobs[jobid] = nil
|
||||
end
|
||||
|
||||
if core.register_globalstep then
|
||||
core.register_globalstep(function(dtime)
|
||||
for i, job in ipairs(core.get_finished_jobs()) do
|
||||
handle_job(job.jobid, job.retval)
|
||||
end
|
||||
end)
|
||||
else
|
||||
core.async_event_handler = handle_job
|
||||
end
|
||||
|
||||
function core.handle_async(func, parameter, callback)
|
||||
-- Serialize function
|
||||
local serialized_func = string.dump(func)
|
||||
|
||||
assert(serialized_func ~= nil)
|
||||
|
||||
-- Serialize parameters
|
||||
local serialized_param = core.serialize(parameter)
|
||||
|
||||
if serialized_param == nil then
|
||||
return false
|
||||
end
|
||||
|
||||
local jobid = core.do_async_callback(serialized_func, serialized_param)
|
||||
|
||||
core.async_jobs[jobid] = callback
|
||||
|
||||
return true
|
||||
end
|
237
builtin/fstk/tabview_layouts.lua
Normal file
237
builtin/fstk/tabview_layouts.lua
Normal file
@ -0,0 +1,237 @@
|
||||
--Minetest
|
||||
--Copyright (C) 2014 sapier
|
||||
--
|
||||
--This program is free software; you can redistribute it and/or modify
|
||||
--it under the terms of the GNU Lesser General Public License as published by
|
||||
--the Free Software Foundation; either version 2.1 of the License, or
|
||||
--(at your option) any later version.
|
||||
--
|
||||
--This program is distributed in the hope that it will be useful,
|
||||
--but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
--MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
--GNU Lesser General Public License for more details.
|
||||
--
|
||||
--You should have received a copy of the GNU Lesser General Public License along
|
||||
--with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
--51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
|
||||
tabview_layouts = {}
|
||||
|
||||
tabview_layouts.tabs = {
|
||||
get = function(self, view)
|
||||
local formspec = ""
|
||||
if view.parent == nil then
|
||||
local tsize = view.tablist[view.last_tab_index].tabsize or
|
||||
{width=view.width, height=view.height}
|
||||
formspec = formspec ..
|
||||
string.format("size[%f,%f,%s]",tsize.width,tsize.height,
|
||||
dump(view.fixed_size))
|
||||
end
|
||||
formspec = formspec .. self:get_header(view)
|
||||
formspec = formspec ..
|
||||
view.tablist[view.last_tab_index].get_formspec(
|
||||
view,
|
||||
view.tablist[view.last_tab_index].name,
|
||||
view.tablist[view.last_tab_index].tabdata,
|
||||
view.tablist[view.last_tab_index].tabsize
|
||||
)
|
||||
|
||||
return formspec
|
||||
end,
|
||||
|
||||
get_header = function(self, view)
|
||||
local toadd = ""
|
||||
for i=1,#view.tablist do
|
||||
if toadd ~= "" then
|
||||
toadd = toadd .. ","
|
||||
end
|
||||
toadd = toadd .. view.tablist[i].caption
|
||||
end
|
||||
|
||||
return string.format("tabheader[%f,%f;%s;%s;%i;true;false]",
|
||||
view.header_x, view.header_y, view.name, toadd, view.last_tab_index);
|
||||
end,
|
||||
|
||||
handle_buttons = function(self, view, fields)
|
||||
--save tab selection to config file
|
||||
if fields[view.name] then
|
||||
local index = tonumber(fields[view.name])
|
||||
view:switch_to_tab(index)
|
||||
return true
|
||||
end
|
||||
|
||||
return false
|
||||
end,
|
||||
}
|
||||
|
||||
|
||||
tabview_layouts.vertical = {
|
||||
get = function(self, view)
|
||||
local formspec = ""
|
||||
if view.parent == nil then
|
||||
local tsize = view.tablist[view.last_tab_index].tabsize or
|
||||
{width=view.width, height=view.height}
|
||||
formspec = formspec ..
|
||||
string.format("size[%f,%f,%s]real_coordinates[true]",tsize.width+3,tsize.height,
|
||||
dump(view.fixed_size))
|
||||
end
|
||||
formspec = formspec .. self:get_header(view)
|
||||
formspec = formspec .. "container[3,0]"
|
||||
formspec = formspec ..
|
||||
view.tablist[view.last_tab_index].get_formspec(
|
||||
view,
|
||||
view.tablist[view.last_tab_index].name,
|
||||
view.tablist[view.last_tab_index].tabdata,
|
||||
view.tablist[view.last_tab_index].tabsize
|
||||
)
|
||||
formspec = formspec .. "container_end[]"
|
||||
|
||||
return formspec
|
||||
end,
|
||||
|
||||
get_header = function(self, view)
|
||||
local icon = view.icon
|
||||
local bgcolor = view.bgcolor or "#ACACAC33"
|
||||
local selcolor = view.selcolor or "#ACACAC66"
|
||||
|
||||
local tsize = view.tablist[view.last_tab_index].tabsize or
|
||||
{width=view.width, height=view.height}
|
||||
|
||||
local fs = {
|
||||
("box[%f,%f;%f,%f;%s]"):format(0, 0, 3, tsize.height, bgcolor)
|
||||
}
|
||||
|
||||
if icon then
|
||||
fs[#fs + 1] = "image[1,0.375;1,1;"
|
||||
fs[#fs + 1] = icon
|
||||
fs[#fs + 1] = "]"
|
||||
end
|
||||
|
||||
for i = 1, #view.tablist do
|
||||
local tab = view.tablist[i]
|
||||
local name = "tab_" .. tab.name
|
||||
local y = (i - 1) * 0.8 + 2.25
|
||||
|
||||
fs[#fs + 1] = "label[0.375,"
|
||||
fs[#fs + 1] = tonumber(y)
|
||||
fs[#fs + 1] = ";"
|
||||
fs[#fs + 1] = tab.caption
|
||||
fs[#fs + 1] = "]"
|
||||
|
||||
fs[#fs + 1] = "style["
|
||||
fs[#fs + 1] = name
|
||||
fs[#fs + 1] = ";border=false]"
|
||||
|
||||
fs[#fs + 1] = "button[0,"
|
||||
fs[#fs + 1] = tonumber(y - 0.4 )
|
||||
fs[#fs + 1] = ";3,0.8;"
|
||||
fs[#fs + 1] = name
|
||||
fs[#fs + 1] = ";]"
|
||||
|
||||
if i == view.last_tab_index then
|
||||
fs[#fs + 1] = ("box[%f,%f;%f,%f;%s]"):format(0, y - 0.4, 3, 0.8, selcolor)
|
||||
end
|
||||
end
|
||||
|
||||
print(defaulttexturedir .. "blank.png")
|
||||
|
||||
return table.concat(fs, "")
|
||||
end,
|
||||
|
||||
handle_buttons = function(self, view, fields)
|
||||
for i = 1, #view.tablist do
|
||||
local tab = view.tablist[i]
|
||||
if fields["tab_" .. tab.name] then
|
||||
view:switch_to_tab(i)
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
return false
|
||||
end,
|
||||
}
|
||||
|
||||
|
||||
tabview_layouts.mainmenu = {
|
||||
backtxt = (defaulttexturedir or "") .. "back.png",
|
||||
|
||||
get = function(self, view)
|
||||
local tab = view.tablist[view.last_tab_index]
|
||||
if tab then
|
||||
return self:get_with_back(view, tab)
|
||||
else
|
||||
return self:get_main_buttons(view)
|
||||
end
|
||||
end,
|
||||
|
||||
get_with_back = function(self, view, tab)
|
||||
local backtxt = view.backtxt or self.backtxt
|
||||
|
||||
local formspec = ""
|
||||
if view.parent == nil then
|
||||
local tsize = tab.tabsize or
|
||||
{width=view.width, height=view.height}
|
||||
formspec = formspec ..
|
||||
string.format("size[%f,%f,%s]real_coordinates[true]",tsize.width,tsize.height,
|
||||
dump(view.fixed_size))
|
||||
end
|
||||
formspec = formspec ..
|
||||
"style[main_back;noclip=true;border=false]image_button[-1.25,0;1,1;" .. backtxt .. ";main_back;]" ..
|
||||
tab.get_formspec(
|
||||
view,
|
||||
view.tablist[view.last_tab_index].name,
|
||||
view.tablist[view.last_tab_index].tabdata,
|
||||
view.tablist[view.last_tab_index].tabsize
|
||||
)
|
||||
|
||||
return formspec
|
||||
end,
|
||||
|
||||
get_main_buttons = function(self, view)
|
||||
local icon = view.icon
|
||||
local bgcolor = view.bgcolor or "#ACACAC33"
|
||||
local selcolor = view.selcolor or "#ACACAC66"
|
||||
|
||||
local tsize = { width = 3, height = #view.tablist - 0.2}
|
||||
|
||||
local fs = {
|
||||
("size[%f,%f]"):format(tsize.width, tsize.height),
|
||||
"real_coordinates[true]",
|
||||
"bgcolor[#00000000]",
|
||||
("box[%f,%f;%f,%f;%s]"):format(0, 0, 3, tsize.height, bgcolor)
|
||||
}
|
||||
|
||||
for i = 1, #view.tablist do
|
||||
local tab = view.tablist[i]
|
||||
local name = "tab_" .. tab.name
|
||||
local y = i - 1
|
||||
|
||||
fs[#fs + 1] = "button[0,"
|
||||
fs[#fs + 1] = tonumber(y)
|
||||
fs[#fs + 1] = ";3,0.8;"
|
||||
fs[#fs + 1] = name
|
||||
fs[#fs + 1] = ";"
|
||||
fs[#fs + 1] = minetest.formspec_escape(tab.caption)
|
||||
fs[#fs + 1] ="]"
|
||||
end
|
||||
|
||||
return table.concat(fs, "")
|
||||
end,
|
||||
|
||||
handle_buttons = function(self, view, fields)
|
||||
if fields.main_back then
|
||||
view:switch_to_tab(nil)
|
||||
return true
|
||||
end
|
||||
for i = 1, #view.tablist do
|
||||
local tab = view.tablist[i]
|
||||
if fields["tab_" .. tab.name] then
|
||||
view:switch_to_tab(i)
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
return false
|
||||
end,
|
||||
}
|
26
builtin/mainmenu/dlg_beta_menu.lua
Normal file
26
builtin/mainmenu/dlg_beta_menu.lua
Normal file
@ -0,0 +1,26 @@
|
||||
--Minetest
|
||||
--Copyright (C) 2014 sapier
|
||||
--
|
||||
--This program is free software; you can redistribute it and/or modify
|
||||
--it under the terms of the GNU Lesser General Public License as published by
|
||||
--the Free Software Foundation; either version 2.1 of the License, or
|
||||
--(at your option) any later version.
|
||||
--
|
||||
--This program is distributed in the hope that it will be useful,
|
||||
--but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
--MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
--GNU Lesser General Public License for more details.
|
||||
--
|
||||
--You should have received a copy of the GNU Lesser General Public License along
|
||||
--with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
--51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
|
||||
local function beta_menu_formspec()
|
||||
return "size[8,2.5,true]" ..
|
||||
"style[label_button;border=false]" ..
|
||||
"button[0.5,0.5;7,0.5;label_button;" ..
|
||||
fgettext("You have no games installed.") .. "]" ..
|
||||
"button[0.5,1.5;2.5,0.5;world_create_open_cdb;" .. fgettext("Install a game") .. "]" ..
|
||||
"button[5.0,1.5;2.5,0.5;world_create_cancel;" .. fgettext("Cancel") .. "]"
|
||||
end
|
@ -15,48 +15,62 @@
|
||||
--with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
--51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
mt_color_grey = "#AAAAFF"
|
||||
mt_color_grey = "#AAAAAA"
|
||||
mt_color_blue = "#6389FF"
|
||||
mt_color_lightblue = "#99CCFF"
|
||||
mt_color_green = "#7264F3"
|
||||
mt_color_dark_green = "#25C1F1"
|
||||
mt_color_orange = "#FF6600"
|
||||
mt_color_red = "#FF0000"
|
||||
mt_color_green = "#72FF63"
|
||||
mt_color_dark_green = "#25C191"
|
||||
|
||||
--for all other colors ask sfan5 to complete his work!
|
||||
|
||||
local menupath = core.get_mainmenu_path()
|
||||
local basepath = core.get_builtin_path()
|
||||
local menustyle = core.settings:get("main_menu_style")
|
||||
defaulttexturedir = core.get_texturepath_share() .. DIR_DELIM .. "base" ..
|
||||
DIR_DELIM .. "pack" .. DIR_DELIM
|
||||
|
||||
dofile(basepath .. "common" .. DIR_DELIM .. "async_event.lua")
|
||||
dofile(basepath .. "common" .. DIR_DELIM .. "filterlist.lua")
|
||||
dofile(basepath .. "fstk" .. DIR_DELIM .. "buttonbar.lua")
|
||||
dofile(basepath .. "fstk" .. DIR_DELIM .. "dialog.lua")
|
||||
dofile(basepath .. "fstk" .. DIR_DELIM .. "tabview.lua")
|
||||
dofile(basepath .. "fstk" .. DIR_DELIM .. "tabview_layouts.lua")
|
||||
dofile(basepath .. "fstk" .. DIR_DELIM .. "ui.lua")
|
||||
dofile(menupath .. DIR_DELIM .. "async_event.lua")
|
||||
dofile(menupath .. DIR_DELIM .. "common.lua")
|
||||
dofile(menupath .. DIR_DELIM .. "pkgmgr.lua")
|
||||
dofile(menupath .. DIR_DELIM .. "serverlistmgr.lua")
|
||||
dofile(menupath .. DIR_DELIM .. "game_theme.lua")
|
||||
dofile(menupath .. DIR_DELIM .. "textures.lua")
|
||||
|
||||
dofile(menupath .. DIR_DELIM .. "dlg_config_world.lua")
|
||||
dofile(menupath .. DIR_DELIM .. "dlg_settings_advanced.lua")
|
||||
dofile(menupath .. DIR_DELIM .. "dlg_contentstore.lua")
|
||||
dofile(menupath .. DIR_DELIM .. "dlg_create_world.lua")
|
||||
dofile(menupath .. DIR_DELIM .. "dlg_delete_content.lua")
|
||||
dofile(menupath .. DIR_DELIM .. "dlg_delete_world.lua")
|
||||
dofile(menupath .. DIR_DELIM .. "dlg_register.lua")
|
||||
dofile(menupath .. DIR_DELIM .. "dlg_rename_modpack.lua")
|
||||
dofile(menupath .. DIR_DELIM .. "dlg_version_info.lua")
|
||||
if menustyle ~= "simple" then
|
||||
dofile(menupath .. DIR_DELIM .. "dlg_create_world.lua")
|
||||
dofile(menupath .. DIR_DELIM .. "dlg_delete_content.lua")
|
||||
dofile(menupath .. DIR_DELIM .. "dlg_delete_world.lua")
|
||||
dofile(menupath .. DIR_DELIM .. "dlg_rename_modpack.lua")
|
||||
end
|
||||
|
||||
local tabs = {}
|
||||
|
||||
tabs.settings = dofile(menupath .. DIR_DELIM .. "tab_settings.lua")
|
||||
tabs.content = dofile(menupath .. DIR_DELIM .. "tab_content.lua")
|
||||
tabs.about = dofile(menupath .. DIR_DELIM .. "tab_about.lua")
|
||||
tabs.local_game = dofile(menupath .. DIR_DELIM .. "tab_local.lua")
|
||||
tabs.play_online = dofile(menupath .. DIR_DELIM .. "tab_online.lua")
|
||||
tabs.beta = dofile(menupath .. DIR_DELIM .. "tab_beta.lua")
|
||||
tabs.about = dofile(menupath .. DIR_DELIM .. "tab_about.lua")
|
||||
if menustyle == "simple" then
|
||||
tabs.simple_main = dofile(menupath .. DIR_DELIM .. "tab_simple_main.lua")
|
||||
else
|
||||
tabs.world = dofile(menupath .. DIR_DELIM .. "tab_local.lua")
|
||||
tabs.online = dofile(menupath .. DIR_DELIM .. "tab_online.lua")
|
||||
|
||||
tabs.new_game = {
|
||||
name = "new",
|
||||
caption = fgettext("New Game"),
|
||||
show = function(_, _, this)
|
||||
local create_world_dlg = create_create_world_dlg(true)
|
||||
create_world_dlg:set_parent(this)
|
||||
this:hide()
|
||||
create_world_dlg:show()
|
||||
return true
|
||||
end
|
||||
}
|
||||
end
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
local function main_event_handler(tabview, event)
|
||||
@ -71,40 +85,69 @@ local function init_globals()
|
||||
-- Init gamedata
|
||||
gamedata.worldindex = 0
|
||||
|
||||
menudata.worldlist = filterlist.create(
|
||||
core.get_worlds,
|
||||
compare_worlds,
|
||||
-- Unique id comparison function
|
||||
function(element, uid)
|
||||
return element.name == uid
|
||||
end,
|
||||
-- Filter function
|
||||
function(element, gameid)
|
||||
return element.gameid == gameid
|
||||
if menustyle == "simple" then
|
||||
local world_list = core.get_worlds()
|
||||
local world_index
|
||||
|
||||
local found_singleplayerworld = false
|
||||
for i, world in ipairs(world_list) do
|
||||
if world.name == "singleplayerworld" then
|
||||
found_singleplayerworld = true
|
||||
world_index = i
|
||||
break
|
||||
end
|
||||
end
|
||||
)
|
||||
|
||||
menudata.worldlist:add_sort_mechanism("alphabetic", sort_worlds_alphabetic)
|
||||
menudata.worldlist:set_sortmode("alphabetic")
|
||||
if not found_singleplayerworld then
|
||||
core.create_world("singleplayerworld", 1)
|
||||
|
||||
if not core.settings:get("menu_last_game") then
|
||||
local default_game = core.settings:get("default_game") or "minetest"
|
||||
core.settings:set("menu_last_game", default_game)
|
||||
world_list = core.get_worlds()
|
||||
|
||||
for i, world in ipairs(world_list) do
|
||||
if world.name == "singleplayerworld" then
|
||||
world_index = i
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
gamedata.worldindex = world_index
|
||||
else
|
||||
menudata.worldlist = filterlist.create(
|
||||
core.get_worlds,
|
||||
compare_worlds,
|
||||
-- Unique id comparison function
|
||||
function(element, uid)
|
||||
return element.name == uid
|
||||
end,
|
||||
-- Filter function
|
||||
function(element, gameid)
|
||||
return element.gameid == gameid
|
||||
end
|
||||
)
|
||||
|
||||
menudata.worldlist:add_sort_mechanism("alphabetic", sort_worlds_alphabetic)
|
||||
menudata.worldlist:set_sortmode("alphabetic")
|
||||
|
||||
if not core.settings:get("menu_last_game") then
|
||||
local default_game = core.settings:get("default_game") or "minetest"
|
||||
core.settings:set("menu_last_game", default_game)
|
||||
end
|
||||
|
||||
mm_texture.init()
|
||||
end
|
||||
|
||||
mm_game_theme.init()
|
||||
|
||||
-- Create main tabview
|
||||
--[[local tv_main = tabview_create("maintab", {x = 12, y = 5.4}, {x = 0, y = 0})
|
||||
-- note: size would be 15.5,7.1 in real coordinates mode
|
||||
|
||||
tv_main:set_autosave_tab(true)
|
||||
|
||||
tv_main:add(tabs.beta)
|
||||
|
||||
tv_main:add(tabs.local_game)
|
||||
tv_main:add(tabs.play_online)
|
||||
local tv_main = tabview_create("maintab", {x = 15.5, y = 9}, {x = 0, y = 0}, tabview_layouts.mainmenu)
|
||||
tv_main.icon = "/home/ruben/dev/minetest/games/minetest_game/menu/icon.png"
|
||||
|
||||
if menustyle == "simple" then
|
||||
tv_main:add(tabs.simple_main)
|
||||
else
|
||||
tv_main:set_autosave_tab(true)
|
||||
tv_main:add(tabs.online)
|
||||
tv_main:add(tabs.world)
|
||||
end
|
||||
tv_main:add(tabs.content)
|
||||
tv_main:add(tabs.settings)
|
||||
tv_main:add(tabs.about)
|
||||
@ -112,25 +155,19 @@ local function init_globals()
|
||||
tv_main:set_global_event_handler(main_event_handler)
|
||||
tv_main:set_fixed_size(false)
|
||||
|
||||
|
||||
tv_main:set_tab(tabs.about)
|
||||
|
||||
local last_tab = core.settings:get("maintab_LAST")
|
||||
if menustyle ~= "simple" and last_tab and tv_main.current_tab ~= last_tab then
|
||||
tv_main:set_tab(last_tab)
|
||||
else
|
||||
tv_main:set_tab("local")
|
||||
end
|
||||
|
||||
-- In case the folder of the last selected game has been deleted,
|
||||
-- display "Minetest" as a header
|
||||
if tv_main.current_tab == "local" then
|
||||
local game = pkgmgr.find_by_gameid(core.settings:get("menu_last_game"))
|
||||
if game == nil then
|
||||
mm_game_theme.reset()
|
||||
end
|
||||
end]]
|
||||
ui.set_default("maintab")
|
||||
tv_main:show()
|
||||
|
||||
--ui.set_default("maintab")
|
||||
--check_new_version()
|
||||
--tv_main:show()
|
||||
--ui.update()
|
||||
ui.update()
|
||||
|
||||
core.sound_play("main_menu", true)
|
||||
end
|
||||
|
||||
init_globals()
|
||||
|
||||
|
||||
init_globals()
|
@ -16,199 +16,116 @@
|
||||
--51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
|
||||
local current_game, singleplayer_refresh_gamebar
|
||||
local valid_disabled_settings = {
|
||||
["enable_damage"]=true,
|
||||
["creative_mode"]=true,
|
||||
["enable_server"]=true,
|
||||
}
|
||||
|
||||
-- Currently chosen game in gamebar for theming and filtering
|
||||
function current_game()
|
||||
local function current_game()
|
||||
local last_game_id = core.settings:get("menu_last_game")
|
||||
local game = pkgmgr.find_by_gameid(last_game_id)
|
||||
local game, index = pkgmgr.find_by_gameid(last_game_id)
|
||||
|
||||
return game
|
||||
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
|
||||
|
||||
local index = filterlist.get_current_index(menudata.worldlist,
|
||||
tonumber(core.settings:get("mainmenu_last_selected_world")))
|
||||
if not index or index < 1 then
|
||||
local selected = core.get_textlist_index("sp_worlds")
|
||||
if selected ~= nil and selected < #menudata.worldlist:get_list() then
|
||||
index = selected
|
||||
else
|
||||
index = #menudata.worldlist:get_list()
|
||||
end
|
||||
end
|
||||
menu_worldmt_legacy(index)
|
||||
end
|
||||
|
||||
function singleplayer_refresh_gamebar()
|
||||
|
||||
local old_bar = ui.find_by_name("game_button_bar")
|
||||
if old_bar ~= nil then
|
||||
old_bar:delete()
|
||||
end
|
||||
|
||||
local function game_buttonbar_button_handler(fields)
|
||||
if fields.game_open_cdb then
|
||||
local maintab = ui.find_by_name("maintab")
|
||||
local dlg = create_store_dlg("game")
|
||||
dlg:set_parent(maintab)
|
||||
maintab:hide()
|
||||
dlg:show()
|
||||
return true
|
||||
end
|
||||
|
||||
for _, game in ipairs(pkgmgr.games) do
|
||||
if fields["game_btnbar_" .. game.id] then
|
||||
apply_game(game)
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local btnbar = buttonbar_create("game_button_bar",
|
||||
game_buttonbar_button_handler,
|
||||
{x=-0.3,y=5.9}, "horizontal", {x=12.4,y=1.15})
|
||||
|
||||
for _, game in ipairs(pkgmgr.games) do
|
||||
local btn_name = "game_btnbar_" .. game.id
|
||||
|
||||
local image = nil
|
||||
local text = nil
|
||||
local tooltip = core.formspec_escape(game.title)
|
||||
|
||||
if (game.menuicon_path or "") ~= "" then
|
||||
image = core.formspec_escape(game.menuicon_path)
|
||||
else
|
||||
local part1 = game.id:sub(1,5)
|
||||
local part2 = game.id:sub(6,10)
|
||||
local part3 = game.id:sub(11)
|
||||
|
||||
text = part1 .. "\n" .. part2
|
||||
if part3 ~= "" then
|
||||
text = text .. "\n" .. part3
|
||||
end
|
||||
end
|
||||
btnbar:add_button(btn_name, text, image, tooltip)
|
||||
end
|
||||
|
||||
local plus_image = core.formspec_escape(defaulttexturedir .. "plus.png")
|
||||
btnbar:add_button("game_open_cdb", "", plus_image, fgettext("Install games from ContentDB"))
|
||||
end
|
||||
|
||||
local function get_disabled_settings(game)
|
||||
if not game then
|
||||
return {}
|
||||
end
|
||||
|
||||
local gameconfig = Settings(game.path .. "/game.conf")
|
||||
local disabled_settings = {}
|
||||
if gameconfig then
|
||||
local disabled_settings_str = (gameconfig:get("disabled_settings") or ""):split()
|
||||
for _, value in pairs(disabled_settings_str) do
|
||||
local state = false
|
||||
value = value:trim()
|
||||
if string.sub(value, 1, 1) == "!" then
|
||||
state = true
|
||||
value = string.sub(value, 2)
|
||||
end
|
||||
if valid_disabled_settings[value] then
|
||||
disabled_settings[value] = state
|
||||
else
|
||||
core.log("error", "Invalid disabled setting in game.conf: "..tostring(value))
|
||||
end
|
||||
end
|
||||
end
|
||||
return disabled_settings
|
||||
end
|
||||
|
||||
local function get_formspec(tabview, name, tabdata)
|
||||
local retval = ""
|
||||
|
||||
local index = filterlist.get_current_index(menudata.worldlist,
|
||||
tonumber(core.settings:get("mainmenu_last_selected_world")))
|
||||
local list = menudata.worldlist:get_list()
|
||||
local world = list and index and list[index]
|
||||
local game
|
||||
if world then
|
||||
game = pkgmgr.find_by_gameid(world.gameid)
|
||||
else
|
||||
game = current_game()
|
||||
end
|
||||
local disabled_settings = get_disabled_settings(game)
|
||||
tonumber(core.settings:get("mainmenu_last_selected_world")))
|
||||
|
||||
local creative, damage, host = "", "", ""
|
||||
retval = {
|
||||
"container[0.375,0.375]",
|
||||
"box[11,-0.375;4.125,9;#ACACAC33]",
|
||||
--"field[1.75,0;5.125,0.8;query;;", query, "]",
|
||||
--"button[6.875,0;1.5,0.8;search;", fgettext("Search"), "]",
|
||||
"textlist[0,0;10.625,8.25;sp_worlds;", menu_render_worldlist(), ";", index, "]",
|
||||
}
|
||||
|
||||
-- Y offsets for game settings checkboxes
|
||||
local y = -0.2
|
||||
local yo = 0.45
|
||||
do
|
||||
retval[#retval + 1] = "container[11.375,0.2]"
|
||||
local enable_server = core.settings:get_bool("enable_server")
|
||||
local options = {
|
||||
{ name = "creative_mode", text = fgettext("Creative Mode") },
|
||||
{ name = "enable_damage", text = fgettext("Enable Damage") },
|
||||
{ name = "enable_server", text = fgettext("Host Server") },
|
||||
}
|
||||
|
||||
if disabled_settings["creative_mode"] == nil then
|
||||
creative = "checkbox[0,"..y..";cb_creative_mode;".. fgettext("Creative Mode") .. ";" ..
|
||||
dump(core.settings:get_bool("creative_mode")) .. "]"
|
||||
y = y + yo
|
||||
end
|
||||
if disabled_settings["enable_damage"] == nil then
|
||||
damage = "checkbox[0,"..y..";cb_enable_damage;".. fgettext("Enable Damage") .. ";" ..
|
||||
dump(core.settings:get_bool("enable_damage")) .. "]"
|
||||
y = y + yo
|
||||
end
|
||||
if disabled_settings["enable_server"] == nil then
|
||||
host = "checkbox[0,"..y..";cb_server;".. fgettext("Host Server") ..";" ..
|
||||
dump(core.settings:get_bool("enable_server")) .. "]"
|
||||
y = y + yo
|
||||
end
|
||||
|
||||
retval = retval ..
|
||||
"button[3.9,3.8;2.8,1;world_delete;".. fgettext("Delete") .. "]" ..
|
||||
"button[6.55,3.8;2.8,1;world_configure;".. fgettext("Select Mods") .. "]" ..
|
||||
"button[9.2,3.8;2.8,1;world_create;".. fgettext("New") .. "]" ..
|
||||
"label[3.9,-0.05;".. fgettext("Select World:") .. "]"..
|
||||
creative ..
|
||||
damage ..
|
||||
host ..
|
||||
"textlist[3.9,0.4;7.9,3.45;sp_worlds;" ..
|
||||
menu_render_worldlist() ..
|
||||
";" .. index .. "]"
|
||||
|
||||
if core.settings:get_bool("enable_server") and disabled_settings["enable_server"] == nil then
|
||||
retval = retval ..
|
||||
"button[7.9,4.75;4.1,1;play;".. fgettext("Host Game") .. "]" ..
|
||||
"checkbox[0,"..y..";cb_server_announce;" .. fgettext("Announce Server") .. ";" ..
|
||||
dump(core.settings:get_bool("server_announce")) .. "]" ..
|
||||
"field[0.3,2.85;3.8,0.5;te_playername;" .. fgettext("Name") .. ";" ..
|
||||
core.formspec_escape(core.settings:get("name")) .. "]" ..
|
||||
"pwdfield[0.3,4.05;3.8,0.5;te_passwd;" .. fgettext("Password") .. "]"
|
||||
|
||||
local bind_addr = core.settings:get("bind_address")
|
||||
if bind_addr ~= nil and bind_addr ~= "" then
|
||||
retval = retval ..
|
||||
"field[0.3,5.25;2.5,0.5;te_serveraddr;" .. fgettext("Bind Address") .. ";" ..
|
||||
core.formspec_escape(core.settings:get("bind_address")) .. "]" ..
|
||||
"field[2.85,5.25;1.25,0.5;te_serverport;" .. fgettext("Port") .. ";" ..
|
||||
core.formspec_escape(core.settings:get("port")) .. "]"
|
||||
else
|
||||
retval = retval ..
|
||||
"field[0.3,5.25;3.8,0.5;te_serverport;" .. fgettext("Server Port") .. ";" ..
|
||||
core.formspec_escape(core.settings:get("port")) .. "]"
|
||||
if enable_server then
|
||||
options[#options + 1] = { name = "server_announce", text = fgettext("Announce Server") }
|
||||
end
|
||||
else
|
||||
retval = retval ..
|
||||
"button[7.9,4.75;4.1,1;play;" .. fgettext("Play Game") .. "]"
|
||||
|
||||
local y = 0
|
||||
for _, opt in pairs(options) do
|
||||
retval[#retval + 1] = "checkbox[0,"
|
||||
retval[#retval + 1] = y
|
||||
retval[#retval + 1] =";cb_"
|
||||
retval[#retval + 1] = opt.name
|
||||
retval[#retval + 1] = ";"
|
||||
retval[#retval + 1] = opt.text
|
||||
retval[#retval + 1] = ";"
|
||||
retval[#retval + 1] = dump(core.settings:get_bool(opt.name))
|
||||
retval[#retval + 1] = "]"
|
||||
|
||||
y = y + 0.5
|
||||
end
|
||||
|
||||
y = y + 0.25
|
||||
|
||||
if enable_server then
|
||||
retval[#retval + 1] = "container[0,"
|
||||
retval[#retval + 1] = y
|
||||
retval[#retval + 1] = "]label[0,0;"
|
||||
retval[#retval + 1] = fgettext("Name/Password")
|
||||
retval[#retval + 1] = "]"
|
||||
retval[#retval + 1] = "field[0,0.3;3.375,0.5;te_playername;;"
|
||||
retval[#retval + 1] = core.formspec_escape(core.settings:get("name"))
|
||||
retval[#retval + 1] = "]"
|
||||
retval[#retval + 1] = "pwdfield[0,1;3.375,0.5;te_passwd;]"
|
||||
|
||||
local bind_addr = core.settings:get("bind_address")
|
||||
if bind_addr ~= nil and bind_addr ~= "" then
|
||||
retval[#retval + 1] = "field[0,2.2;2.25,0.5;te_serveraddr;" .. fgettext("Bind Address")
|
||||
retval[#retval + 1] = ";"
|
||||
retval[#retval + 1] = core.formspec_escape(core.settings:get("bind_address"))
|
||||
retval[#retval + 1] = "]"
|
||||
retval[#retval + 1] = "field[2.3,2.2;1.25,0.5;te_serverport;"
|
||||
retval[#retval + 1] = fgettext("Port")
|
||||
retval[#retval + 1] = ";"
|
||||
retval[#retval + 1] = core.formspec_escape(core.settings:get("port"))
|
||||
retval[#retval + 1] = "]"
|
||||
else
|
||||
retval[#retval + 1] = "field[0,2.2;3.375,0.5;te_serverport;"
|
||||
retval[#retval + 1] = fgettext("Server Port")
|
||||
retval[#retval + 1] = ";"
|
||||
retval[#retval + 1] = core.formspec_escape(core.settings:get("port"))
|
||||
retval[#retval + 1] = "]"
|
||||
end
|
||||
retval[#retval + 1] = "container_end[]"
|
||||
end
|
||||
|
||||
if index > 0 then
|
||||
retval[#retval + 1] = "container[0,5.15]"
|
||||
retval[#retval + 1] = "button[0,0;3.375,0.8;world_delete;"
|
||||
retval[#retval + 1] = fgettext("Delete")
|
||||
retval[#retval + 1] = "]"
|
||||
retval[#retval + 1] = "button[0,1.05;3.375,0.8;world_configure;"
|
||||
retval[#retval + 1] = fgettext("Configure")
|
||||
retval[#retval + 1] = "]"
|
||||
retval[#retval + 1] = "button[0,2.1;3.375,0.8;play;"
|
||||
retval[#retval + 1] = fgettext("Play Game")
|
||||
retval[#retval + 1] = "]"
|
||||
-- "button[4,3.95;2.6,1;world_delete;", fgettext("Delete"), "]",
|
||||
--"button[6.5,3.95;2.8,1;world_configure;", fgettext("Configure"), "]",
|
||||
retval[#retval + 1] = "container_end[]"
|
||||
else
|
||||
retval[#retval + 1] = "container[0,5.15]"
|
||||
retval[#retval + 1] = "box[0,0;2.625,0.8;#333]"
|
||||
retval[#retval + 1] = "box[0,1.05;2.625,0.8;#333]"
|
||||
retval[#retval + 1] = "box[0,2.1;2.625,0.8;#333]"
|
||||
retval[#retval + 1] = "container_end[]"
|
||||
end
|
||||
|
||||
|
||||
retval[#retval + 1] = "container_end[]"
|
||||
end
|
||||
|
||||
return retval
|
||||
return table.concat(retval, "") .. "container_end[]"
|
||||
end
|
||||
|
||||
local function main_button_handler(this, fields, name, tabdata)
|
||||
@ -254,8 +171,8 @@ local function main_button_handler(this, fields, name, tabdata)
|
||||
return true
|
||||
end
|
||||
|
||||
if fields["cb_server"] then
|
||||
core.settings:set("enable_server", fields["cb_server"])
|
||||
if fields["cb_enable_server"] then
|
||||
core.settings:set("enable_server", fields["cb_enable_server"])
|
||||
|
||||
return true
|
||||
end
|
||||
@ -268,61 +185,46 @@ local function main_button_handler(this, fields, name, tabdata)
|
||||
return true
|
||||
end
|
||||
|
||||
if fields["play"] ~= nil or world_doubleclick or fields["key_enter"] then
|
||||
if fields["play"] ~= nil or world_doubleclick then
|
||||
local selected = core.get_textlist_index("sp_worlds")
|
||||
gamedata.selected_world = menudata.worldlist:get_raw_index(selected)
|
||||
|
||||
if selected == nil or gamedata.selected_world == 0 then
|
||||
gamedata.errormessage =
|
||||
fgettext("No world created or selected!")
|
||||
return true
|
||||
end
|
||||
|
||||
-- Update last game
|
||||
local world = menudata.worldlist:get_raw_element(gamedata.selected_world)
|
||||
local game_obj
|
||||
if world then
|
||||
game_obj = pkgmgr.find_by_gameid(world.gameid)
|
||||
core.settings:set("menu_last_game", game_obj.id)
|
||||
end
|
||||
|
||||
local disabled_settings = get_disabled_settings(game_obj)
|
||||
for k, _ in pairs(valid_disabled_settings) do
|
||||
local v = disabled_settings[k]
|
||||
if v ~= nil then
|
||||
if k == "enable_server" and v == true then
|
||||
error("Setting 'enable_server' cannot be force-enabled! The game.conf needs to be fixed.")
|
||||
end
|
||||
core.settings:set_bool(k, disabled_settings[k])
|
||||
end
|
||||
end
|
||||
|
||||
if core.settings:get_bool("enable_server") then
|
||||
gamedata.playername = fields["te_playername"]
|
||||
gamedata.password = fields["te_passwd"]
|
||||
gamedata.port = fields["te_serverport"]
|
||||
gamedata.address = ""
|
||||
if selected ~= nil and gamedata.selected_world ~= 0 then
|
||||
gamedata.playername = fields["te_playername"]
|
||||
gamedata.password = fields["te_passwd"]
|
||||
gamedata.port = fields["te_serverport"]
|
||||
gamedata.address = ""
|
||||
|
||||
core.settings:set("port",gamedata.port)
|
||||
if fields["te_serveraddr"] ~= nil then
|
||||
core.settings:set("bind_address",fields["te_serveraddr"])
|
||||
core.settings:set("port",gamedata.port)
|
||||
if fields["te_serveraddr"] ~= nil then
|
||||
core.settings:set("bind_address",fields["te_serveraddr"])
|
||||
end
|
||||
|
||||
--update last game
|
||||
local world = menudata.worldlist:get_raw_element(gamedata.selected_world)
|
||||
if world then
|
||||
local game, index = pkgmgr.find_by_gameid(world.gameid)
|
||||
core.settings:set("menu_last_game", game.id)
|
||||
end
|
||||
|
||||
core.start()
|
||||
else
|
||||
gamedata.errormessage =
|
||||
fgettext("No world created or selected!")
|
||||
end
|
||||
else
|
||||
gamedata.singleplayer = true
|
||||
if selected ~= nil and gamedata.selected_world ~= 0 then
|
||||
gamedata.singleplayer = true
|
||||
core.start()
|
||||
else
|
||||
gamedata.errormessage =
|
||||
fgettext("No world created or selected!")
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
core.start()
|
||||
return true
|
||||
end
|
||||
|
||||
if fields["world_create"] ~= nil then
|
||||
local create_world_dlg = create_create_world_dlg()
|
||||
create_world_dlg:set_parent(this)
|
||||
this:hide()
|
||||
create_world_dlg:show()
|
||||
mm_game_theme.update("singleplayer", current_game())
|
||||
return true
|
||||
end
|
||||
|
||||
if fields["world_delete"] ~= nil then
|
||||
local selected = core.get_textlist_index("sp_worlds")
|
||||
@ -337,7 +239,7 @@ 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())
|
||||
mm_texture.update("singleplayer",current_game())
|
||||
end
|
||||
end
|
||||
|
||||
@ -355,7 +257,7 @@ local function main_button_handler(this, fields, name, tabdata)
|
||||
configdialog:set_parent(this)
|
||||
this:hide()
|
||||
configdialog:show()
|
||||
mm_game_theme.update("singleplayer",current_game())
|
||||
mm_texture.update("singleplayer",current_game())
|
||||
end
|
||||
end
|
||||
|
||||
@ -364,29 +266,25 @@ local function main_button_handler(this, fields, name, tabdata)
|
||||
end
|
||||
|
||||
local function on_change(type, old_tab, new_tab)
|
||||
if (type == "ENTER") then
|
||||
if type == "ENTER" then
|
||||
local game = current_game()
|
||||
if game then
|
||||
apply_game(game)
|
||||
end
|
||||
|
||||
singleplayer_refresh_gamebar()
|
||||
ui.find_by_name("game_button_bar"):show()
|
||||
if game then
|
||||
menudata.worldlist:set_filtercriteria(game.id)
|
||||
core.set_topleft_text(game.name)
|
||||
mm_texture.update("singleplayer",game)
|
||||
end
|
||||
else
|
||||
menudata.worldlist:set_filtercriteria(nil)
|
||||
local gamebar = ui.find_by_name("game_button_bar")
|
||||
if gamebar then
|
||||
gamebar:hide()
|
||||
end
|
||||
core.set_topleft_text("")
|
||||
mm_game_theme.update(new_tab,nil)
|
||||
mm_texture.update(new_tab,nil)
|
||||
end
|
||||
end
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
return {
|
||||
name = "local",
|
||||
caption = fgettext("Start Game"),
|
||||
caption = fgettext("Load Game"),
|
||||
cbf_formspec = get_formspec,
|
||||
cbf_button_handler = main_button_handler,
|
||||
on_change = on_change
|
||||
|
185
builtin/mainmenu/textures.lua
Normal file
185
builtin/mainmenu/textures.lua
Normal file
@ -0,0 +1,185 @@
|
||||
--Minetest
|
||||
--Copyright (C) 2013 sapier
|
||||
--
|
||||
--This program is free software; you can redistribute it and/or modify
|
||||
--it under the terms of the GNU Lesser General Public License as published by
|
||||
--the Free Software Foundation; either version 2.1 of the License, or
|
||||
--(at your option) any later version.
|
||||
--
|
||||
--This program is distributed in the hope that it will be useful,
|
||||
--but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
--MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
--GNU Lesser General Public License for more details.
|
||||
--
|
||||
--You should have received a copy of the GNU Lesser General Public License along
|
||||
--with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
--51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
|
||||
mm_texture = {}
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
function mm_texture.init()
|
||||
mm_texture.defaulttexturedir = core.get_texturepath() .. DIR_DELIM .. "base" ..
|
||||
DIR_DELIM .. "pack" .. DIR_DELIM
|
||||
mm_texture.basetexturedir = mm_texture.defaulttexturedir
|
||||
|
||||
mm_texture.texturepack = core.settings:get("texture_path")
|
||||
|
||||
mm_texture.gameid = nil
|
||||
end
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
function mm_texture.update(tab,gamedetails)
|
||||
if tab ~= "singleplayer" then
|
||||
mm_texture.reset()
|
||||
return
|
||||
end
|
||||
|
||||
if gamedetails == nil then
|
||||
return
|
||||
end
|
||||
|
||||
mm_texture.update_game(gamedetails)
|
||||
end
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
function mm_texture.reset()
|
||||
mm_texture.gameid = nil
|
||||
local have_bg = false
|
||||
local have_overlay = mm_texture.set_generic("overlay")
|
||||
|
||||
if not have_overlay then
|
||||
have_bg = mm_texture.set_generic("background")
|
||||
end
|
||||
|
||||
mm_texture.clear("header")
|
||||
mm_texture.clear("footer")
|
||||
core.set_clouds(false)
|
||||
|
||||
mm_texture.set_generic("footer")
|
||||
mm_texture.set_generic("header")
|
||||
|
||||
if not have_bg then
|
||||
if core.settings:get_bool("menu_clouds") then
|
||||
core.set_clouds(true)
|
||||
else
|
||||
mm_texture.set_dirt_bg()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
function mm_texture.update_game(gamedetails)
|
||||
if mm_texture.gameid == gamedetails.id then
|
||||
return
|
||||
end
|
||||
|
||||
local have_bg = false
|
||||
local have_overlay = mm_texture.set_game("overlay",gamedetails)
|
||||
|
||||
if not have_overlay then
|
||||
have_bg = mm_texture.set_game("background",gamedetails)
|
||||
end
|
||||
|
||||
mm_texture.clear("header")
|
||||
mm_texture.clear("footer")
|
||||
core.set_clouds(false)
|
||||
|
||||
if not have_bg then
|
||||
|
||||
if core.settings:get_bool("menu_clouds") then
|
||||
core.set_clouds(true)
|
||||
else
|
||||
mm_texture.set_dirt_bg()
|
||||
end
|
||||
end
|
||||
|
||||
mm_texture.set_game("footer",gamedetails)
|
||||
mm_texture.set_game("header",gamedetails)
|
||||
|
||||
mm_texture.gameid = gamedetails.id
|
||||
end
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
function mm_texture.clear(identifier)
|
||||
core.set_background(identifier,"")
|
||||
end
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
function mm_texture.set_generic(identifier)
|
||||
--try texture pack first
|
||||
if mm_texture.texturepack ~= nil then
|
||||
local path = mm_texture.texturepack .. DIR_DELIM .."menu_" ..
|
||||
identifier .. ".png"
|
||||
if core.set_background(identifier,path) then
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
if mm_texture.defaulttexturedir ~= nil then
|
||||
local path = mm_texture.defaulttexturedir .. DIR_DELIM .."menu_" ..
|
||||
identifier .. ".png"
|
||||
if core.set_background(identifier,path) then
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
function mm_texture.set_game(identifier, gamedetails)
|
||||
|
||||
if gamedetails == nil then
|
||||
return false
|
||||
end
|
||||
|
||||
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
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
-- Find out how many randomized textures the game provides
|
||||
local n = 0
|
||||
local filename
|
||||
local menu_files = core.get_dir_list(gamedetails.path .. DIR_DELIM .. "menu", false)
|
||||
for i = 1, #menu_files do
|
||||
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 universal fallback texture in textures/base/pack
|
||||
local minimalpath = defaulttexturedir .. "menu_bg.png"
|
||||
core.set_background("background", minimalpath, true, 128)
|
||||
end
|
Loading…
Reference in New Issue
Block a user