mirror of
https://github.com/minetest/minetest.git
synced 2024-11-27 01:53:45 +01:00
Enable the gamebar on Android (#12354)
This commit is contained in:
parent
4648d8f499
commit
f090471022
@ -125,18 +125,12 @@ os.tmpname = function()
|
|||||||
end
|
end
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
function menu_render_worldlist(show_gameid)
|
function menu_render_worldlist()
|
||||||
local retval = {}
|
local retval = {}
|
||||||
local current_worldlist = menudata.worldlist:get_list()
|
local current_worldlist = menudata.worldlist:get_list()
|
||||||
|
|
||||||
local row
|
|
||||||
for i, v in ipairs(current_worldlist) do
|
for i, v in ipairs(current_worldlist) do
|
||||||
row = v.name
|
retval[#retval+1] = core.formspec_escape(v.name)
|
||||||
if show_gameid == nil or show_gameid == true then
|
|
||||||
row = row .. " [" .. v.gameid .. "]"
|
|
||||||
end
|
|
||||||
retval[#retval+1] = core.formspec_escape(row)
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return table.concat(retval, ",")
|
return table.concat(retval, ",")
|
||||||
|
@ -15,9 +15,6 @@
|
|||||||
--with this program; if not, write to the Free Software Foundation, Inc.,
|
--with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
--51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
--51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
|
||||||
-- cf. tab_local, the gamebar already provides game selection so we hide the list from here
|
|
||||||
local hide_gamelist = PLATFORM ~= "Android"
|
|
||||||
|
|
||||||
local function table_to_flags(ftable)
|
local function table_to_flags(ftable)
|
||||||
-- Convert e.g. { jungles = true, caves = false } to "jungles,nocaves"
|
-- Convert e.g. { jungles = true, caves = false } to "jungles,nocaves"
|
||||||
local str = {}
|
local str = {}
|
||||||
@ -111,14 +108,11 @@ local function create_world_formspec(dialogdata)
|
|||||||
|
|
||||||
local flags = dialogdata.flags
|
local flags = dialogdata.flags
|
||||||
|
|
||||||
local game, gameidx = pkgmgr.find_by_gameid(gameid)
|
local game = pkgmgr.find_by_gameid(gameid)
|
||||||
if game == nil and hide_gamelist then
|
if game == nil then
|
||||||
-- should never happen but just pick the first game
|
-- should never happen but just pick the first game
|
||||||
game = pkgmgr.get_game(1)
|
game = pkgmgr.get_game(1)
|
||||||
gameidx = 1
|
|
||||||
core.settings:set("menu_last_game", game.id)
|
core.settings:set("menu_last_game", game.id)
|
||||||
elseif game == nil then
|
|
||||||
gameidx = 0
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local disallowed_mapgen_settings = {}
|
local disallowed_mapgen_settings = {}
|
||||||
@ -296,17 +290,6 @@ local function create_world_formspec(dialogdata)
|
|||||||
label_spflags = "label[0,"..y_start..";" .. fgettext("Mapgen-specific flags") .. "]"
|
label_spflags = "label[0,"..y_start..";" .. fgettext("Mapgen-specific flags") .. "]"
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Warning if only devtest is installed
|
|
||||||
local devtest_only = ""
|
|
||||||
local gamelist_height = 2.3
|
|
||||||
if #pkgmgr.games == 1 and pkgmgr.games[1].id == "devtest" then
|
|
||||||
devtest_only = "box[0,0;5.8,1.7;#ff8800]" ..
|
|
||||||
"textarea[0.4,0.1;6,1.8;;;"..
|
|
||||||
fgettext("Development Test is meant for developers.") .. "]" ..
|
|
||||||
"button[1,1;4,0.5;world_create_open_cdb;" .. fgettext("Install another game") .. "]"
|
|
||||||
gamelist_height = 0.5
|
|
||||||
end
|
|
||||||
|
|
||||||
local retval =
|
local retval =
|
||||||
"size[12.25,7,true]" ..
|
"size[12.25,7,true]" ..
|
||||||
|
|
||||||
@ -329,13 +312,14 @@ local function create_world_formspec(dialogdata)
|
|||||||
"label[0,2;" .. fgettext("Mapgen") .. "]"..
|
"label[0,2;" .. fgettext("Mapgen") .. "]"..
|
||||||
"dropdown[0,2.5;6.3;dd_mapgen;" .. mglist .. ";" .. selindex .. "]"
|
"dropdown[0,2.5;6.3;dd_mapgen;" .. mglist .. ";" .. selindex .. "]"
|
||||||
|
|
||||||
if not hide_gamelist or devtest_only ~= "" then
|
-- Warning if only devtest is installed
|
||||||
|
if #pkgmgr.games == 1 and pkgmgr.games[1].id == "devtest" then
|
||||||
retval = retval ..
|
retval = retval ..
|
||||||
"label[0,3.35;" .. fgettext("Game") .. "]"..
|
"container[0,3.5]" ..
|
||||||
"textlist[0,3.85;5.8,"..gamelist_height..";games;" ..
|
"box[0,0;5.8,1.7;#ff8800]" ..
|
||||||
pkgmgr.gamelist() .. ";" .. gameidx .. ";false]" ..
|
"textarea[0.4,0.1;6,1.8;;;"..
|
||||||
"container[0,4.5]" ..
|
fgettext("Development Test is meant for developers.") .. "]" ..
|
||||||
devtest_only ..
|
"button[1,1;4,0.5;world_create_open_cdb;" .. fgettext("Install another game") .. "]" ..
|
||||||
"container_end[]"
|
"container_end[]"
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -371,13 +355,7 @@ local function create_world_buttonhandler(this, fields)
|
|||||||
fields["key_enter"] then
|
fields["key_enter"] then
|
||||||
|
|
||||||
local worldname = fields["te_world_name"]
|
local worldname = fields["te_world_name"]
|
||||||
local game, gameindex
|
local game, gameindex = pkgmgr.find_by_gameid(core.settings:get("menu_last_game"))
|
||||||
if hide_gamelist then
|
|
||||||
game, gameindex = pkgmgr.find_by_gameid(core.settings:get("menu_last_game"))
|
|
||||||
else
|
|
||||||
gameindex = core.get_textlist_index("games")
|
|
||||||
game = pkgmgr.get_game(gameindex)
|
|
||||||
end
|
|
||||||
|
|
||||||
local message
|
local message
|
||||||
if game == nil then
|
if game == nil then
|
||||||
@ -426,9 +404,7 @@ local function create_world_buttonhandler(this, fields)
|
|||||||
|
|
||||||
if message == nil then
|
if message == nil then
|
||||||
core.settings:set("menu_last_game", game.id)
|
core.settings:set("menu_last_game", game.id)
|
||||||
if this.data.update_worldlist_filter then
|
menudata.worldlist:set_filtercriteria(game.id)
|
||||||
menudata.worldlist:set_filtercriteria(game.id)
|
|
||||||
end
|
|
||||||
menudata.worldlist:refresh()
|
menudata.worldlist:refresh()
|
||||||
core.settings:set("mainmenu_last_selected_world",
|
core.settings:set("mainmenu_last_selected_world",
|
||||||
menudata.worldlist:raw_index_by_uid(worldname))
|
menudata.worldlist:raw_index_by_uid(worldname))
|
||||||
@ -486,13 +462,12 @@ local function create_world_buttonhandler(this, fields)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function create_create_world_dlg(update_worldlistfilter)
|
function create_create_world_dlg()
|
||||||
local retval = dialog_create("sp_create_world",
|
local retval = dialog_create("sp_create_world",
|
||||||
create_world_formspec,
|
create_world_formspec,
|
||||||
create_world_buttonhandler,
|
create_world_buttonhandler,
|
||||||
nil)
|
nil)
|
||||||
retval.data = {
|
retval.data = {
|
||||||
update_worldlist_filter = update_worldlistfilter,
|
|
||||||
worldname = "",
|
worldname = "",
|
||||||
-- settings the world is created with:
|
-- settings the world is created with:
|
||||||
seed = core.settings:get("fixed_map_seed") or "",
|
seed = core.settings:get("fixed_map_seed") or "",
|
||||||
|
@ -16,7 +16,6 @@
|
|||||||
--51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
--51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
|
||||||
|
|
||||||
local enable_gamebar = PLATFORM ~= "Android"
|
|
||||||
local current_game, singleplayer_refresh_gamebar
|
local current_game, singleplayer_refresh_gamebar
|
||||||
local valid_disabled_settings = {
|
local valid_disabled_settings = {
|
||||||
["enable_damage"]=true,
|
["enable_damage"]=true,
|
||||||
@ -24,95 +23,88 @@ local valid_disabled_settings = {
|
|||||||
["enable_server"]=true,
|
["enable_server"]=true,
|
||||||
}
|
}
|
||||||
|
|
||||||
if enable_gamebar then
|
-- Currently chosen game in gamebar for theming and filtering
|
||||||
-- Currently chosen game in gamebar for theming and filtering
|
function current_game()
|
||||||
function current_game()
|
local last_game_id = core.settings:get("menu_last_game")
|
||||||
local last_game_id = core.settings:get("menu_last_game")
|
local game = pkgmgr.find_by_gameid(last_game_id)
|
||||||
local game = pkgmgr.find_by_gameid(last_game_id)
|
|
||||||
|
|
||||||
return game
|
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
|
end
|
||||||
|
|
||||||
-- Apply menu changes from given game
|
local function game_buttonbar_button_handler(fields)
|
||||||
function apply_game(game)
|
if fields.game_open_cdb then
|
||||||
core.set_topleft_text(game.name)
|
local maintab = ui.find_by_name("maintab")
|
||||||
core.settings:set("menu_last_game", game.id)
|
local dlg = create_store_dlg("game")
|
||||||
menudata.worldlist:set_filtercriteria(game.id)
|
dlg:set_parent(maintab)
|
||||||
|
maintab:hide()
|
||||||
mm_game_theme.update("singleplayer", game) -- this refreshes the formspec
|
dlg:show()
|
||||||
|
return true
|
||||||
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
|
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
|
for _, game in ipairs(pkgmgr.games) do
|
||||||
local btn_name = "game_btnbar_" .. game.id
|
if fields["game_btnbar_" .. game.id] then
|
||||||
|
apply_game(game)
|
||||||
local image = nil
|
return true
|
||||||
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
|
end
|
||||||
btnbar:add_button(btn_name, text, image, tooltip)
|
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
local plus_image = core.formspec_escape(defaulttexturedir .. "plus.png")
|
local btnbar = buttonbar_create("game_button_bar",
|
||||||
btnbar:add_button("game_open_cdb", "", plus_image, fgettext("Install games from ContentDB"))
|
game_buttonbar_button_handler,
|
||||||
end
|
{x=-0.3,y=5.9}, "horizontal", {x=12.4,y=1.15})
|
||||||
else
|
|
||||||
-- Currently chosen game in gamebar: no gamebar -> no "current" game
|
for _, game in ipairs(pkgmgr.games) do
|
||||||
function current_game()
|
local btn_name = "game_btnbar_" .. game.id
|
||||||
return nil
|
|
||||||
|
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
|
end
|
||||||
|
|
||||||
|
local plus_image = core.formspec_escape(defaulttexturedir .. "plus.png")
|
||||||
|
btnbar:add_button("game_open_cdb", "", plus_image, fgettext("Install games from ContentDB"))
|
||||||
end
|
end
|
||||||
|
|
||||||
local function get_disabled_settings(game)
|
local function get_disabled_settings(game)
|
||||||
@ -187,7 +179,7 @@ local function get_formspec(tabview, name, tabdata)
|
|||||||
damage ..
|
damage ..
|
||||||
host ..
|
host ..
|
||||||
"textlist[3.9,0.4;7.9,3.45;sp_worlds;" ..
|
"textlist[3.9,0.4;7.9,3.45;sp_worlds;" ..
|
||||||
menu_render_worldlist(not enable_gamebar) ..
|
menu_render_worldlist() ..
|
||||||
";" .. index .. "]"
|
";" .. index .. "]"
|
||||||
|
|
||||||
if core.settings:get_bool("enable_server") and disabled_settings["enable_server"] == nil then
|
if core.settings:get_bool("enable_server") and disabled_settings["enable_server"] == nil then
|
||||||
@ -324,7 +316,7 @@ local function main_button_handler(this, fields, name, tabdata)
|
|||||||
end
|
end
|
||||||
|
|
||||||
if fields["world_create"] ~= nil then
|
if fields["world_create"] ~= nil then
|
||||||
local create_world_dlg = create_create_world_dlg(enable_gamebar)
|
local create_world_dlg = create_create_world_dlg()
|
||||||
create_world_dlg:set_parent(this)
|
create_world_dlg:set_parent(this)
|
||||||
this:hide()
|
this:hide()
|
||||||
create_world_dlg:show()
|
create_world_dlg:show()
|
||||||
@ -371,26 +363,23 @@ local function main_button_handler(this, fields, name, tabdata)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local on_change
|
local function on_change(type, old_tab, new_tab)
|
||||||
if enable_gamebar then
|
if (type == "ENTER") then
|
||||||
function on_change(type, old_tab, new_tab)
|
local game = current_game()
|
||||||
if (type == "ENTER") then
|
if game then
|
||||||
local game = current_game()
|
apply_game(game)
|
||||||
if game then
|
|
||||||
apply_game(game)
|
|
||||||
end
|
|
||||||
|
|
||||||
singleplayer_refresh_gamebar()
|
|
||||||
ui.find_by_name("game_button_bar"):show()
|
|
||||||
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)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
singleplayer_refresh_gamebar()
|
||||||
|
ui.find_by_name("game_button_bar"):show()
|
||||||
|
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)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user