From 8f9611bcb20f4eca69abb204bf5dc28f62fab4a2 Mon Sep 17 00:00:00 2001 From: Ezhh Date: Sat, 7 Jan 2017 11:33:38 +0000 Subject: Make column alignment consistent in advanced settings (#5004) --- builtin/mainmenu/dlg_settings_advanced.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'builtin/mainmenu') diff --git a/builtin/mainmenu/dlg_settings_advanced.lua b/builtin/mainmenu/dlg_settings_advanced.lua index b0d923768..85218c852 100644 --- a/builtin/mainmenu/dlg_settings_advanced.lua +++ b/builtin/mainmenu/dlg_settings_advanced.lua @@ -544,7 +544,7 @@ end local function create_settings_formspec(tabview, name, tabdata) local formspec = "size[12,6.5;true]" .. - "tablecolumns[color;tree;text;text]" .. + "tablecolumns[color;tree;text,width=32;text]" .. "tableoptions[background=#00000000;border=false]" .. "table[0,0;12,5.5;list_settings;" -- cgit v1.2.3 From bb154c2e1cf185f181c3e85df9addb79e6d18b4c Mon Sep 17 00:00:00 2001 From: ShadowNinja Date: Thu, 15 Oct 2015 13:05:33 -0400 Subject: Main menu tweaks --- builtin/init.lua | 7 +++---- builtin/mainmenu/dlg_settings_advanced.lua | 2 +- src/guiEngine.cpp | 10 +++++----- 3 files changed, 9 insertions(+), 10 deletions(-) (limited to 'builtin/mainmenu') diff --git a/builtin/init.lua b/builtin/init.lua index 4400a19d6..b34ad14a0 100644 --- a/builtin/init.lua +++ b/builtin/init.lua @@ -37,9 +37,9 @@ dofile(commonpath .. "misc_helpers.lua") if INIT == "game" then dofile(gamepath .. "init.lua") elseif INIT == "mainmenu" then - local mainmenuscript = core.setting_get("main_menu_script") - if mainmenuscript ~= nil and mainmenuscript ~= "" then - dofile(mainmenuscript) + local mm_script = core.setting_get("main_menu_script") + if mm_script and mm_script ~= "" then + dofile(mm_script) else dofile(core.get_mainmenu_path() .. DIR_DELIM .. "init.lua") end @@ -48,4 +48,3 @@ elseif INIT == "async" then else error(("Unrecognized builtin initialization type %s!"):format(tostring(INIT))) end - diff --git a/builtin/mainmenu/dlg_settings_advanced.lua b/builtin/mainmenu/dlg_settings_advanced.lua index 85218c852..60ec1250f 100644 --- a/builtin/mainmenu/dlg_settings_advanced.lua +++ b/builtin/mainmenu/dlg_settings_advanced.lua @@ -667,4 +667,4 @@ end -- The documentation of mapgen noise parameter formats (title plus 16 lines) -- Noise parameter 'mgv5_np_ground' in group format (13 lines) ---assert(loadfile(core.get_mainmenu_path()..DIR_DELIM.."generate_from_settingtypes.lua"))(parse_config_file(true, false)) +--assert(loadfile(core.get_builtin_path()..DIR_DELIM.."mainmenu"..DIR_DELIM.."generate_from_settingtypes.lua"))(parse_config_file(true, false)) diff --git a/src/guiEngine.cpp b/src/guiEngine.cpp index 6d66ed08d..03fee6b96 100644 --- a/src/guiEngine.cpp +++ b/src/guiEngine.cpp @@ -213,13 +213,13 @@ GUIEngine::GUIEngine( irr::IrrlichtDevice* dev, m_data->script_data.errormessage = ""; if (!loadMainMenuScript()) { - errorstream << "No future without mainmenu" << std::endl; + errorstream << "No future without main menu!" << std::endl; abort(); } run(); } catch (LuaError &e) { - errorstream << "MAINMENU ERROR: " << e.what() << std::endl; + errorstream << "Main menu error: " << e.what() << std::endl; m_data->script_data.errormessage = e.what(); } @@ -231,13 +231,13 @@ GUIEngine::GUIEngine( irr::IrrlichtDevice* dev, /******************************************************************************/ bool GUIEngine::loadMainMenuScript() { - // Try custom menu script (main_menu_path) - + // Set main menu path (for core.get_mainmenu_path()) m_scriptdir = g_settings->get("main_menu_path"); if (m_scriptdir.empty()) { - m_scriptdir = porting::path_share + DIR_DELIM "builtin" + DIR_DELIM "mainmenu"; + m_scriptdir = porting::path_share + DIR_DELIM + "builtin" + DIR_DELIM + "mainmenu"; } + // Load builtin (which will load the main menu script) std::string script = porting::path_share + DIR_DELIM "builtin" + DIR_DELIM "init.lua"; try { m_script->loadScript(script); -- cgit v1.2.3 From f3bd4c405df6bce64b7a98789d825eeac9c279b2 Mon Sep 17 00:00:00 2001 From: red-001 Date: Fri, 6 Jan 2017 20:29:29 +0000 Subject: Add keyword based search to serverlist --- builtin/mainmenu/common.lua | 2 +- builtin/mainmenu/init.lua | 2 +- builtin/mainmenu/tab_credits.lua | 2 +- builtin/mainmenu/tab_multiplayer.lua | 116 ++++++++++++++++++++++++++++++---- builtin/mainmenu/tab_server.lua | 2 +- builtin/mainmenu/tab_settings.lua | 4 +- builtin/mainmenu/tab_simple_main.lua | 4 +- builtin/mainmenu/tab_singleplayer.lua | 4 +- 8 files changed, 113 insertions(+), 23 deletions(-) (limited to 'builtin/mainmenu') diff --git a/builtin/mainmenu/common.lua b/builtin/mainmenu/common.lua index da3667828..5e3df0864 100644 --- a/builtin/mainmenu/common.lua +++ b/builtin/mainmenu/common.lua @@ -77,7 +77,7 @@ function order_favorite_list(list) end -------------------------------------------------------------------------------- -function render_favorite(spec, is_favorite) +function render_serverlist_row(spec, is_favorite) local text = "" if spec.name then text = text .. core.formspec_escape(spec.name:trim()) diff --git a/builtin/mainmenu/init.lua b/builtin/mainmenu/init.lua index 7f0c1e386..1b527a053 100644 --- a/builtin/mainmenu/init.lua +++ b/builtin/mainmenu/init.lua @@ -128,7 +128,7 @@ local function init_globals() end -- Create main tabview - local tv_main = tabview_create("maintab", {x = 12, y = 5.2}, {x = 0, y = 0}) + local tv_main = tabview_create("maintab", {x = 12, y = 5.4}, {x = 0, y = 0}) if PLATFORM == "Android" then tv_main:add(tabs.simple_main) diff --git a/builtin/mainmenu/tab_credits.lua b/builtin/mainmenu/tab_credits.lua index c2ad19183..80e03f84d 100644 --- a/builtin/mainmenu/tab_credits.lua +++ b/builtin/mainmenu/tab_credits.lua @@ -85,7 +85,7 @@ return { "label[0.5,3.5;http://minetest.net]" .. "tablecolumns[color;text]" .. "tableoptions[background=#00000000;highlight=#00000000;border=false]" .. - "table[3.5,-0.25;8.5,5.8;list_credits;" .. + "table[3.5,-0.25;8.5,6.05;list_credits;" .. "#FFFF00," .. fgettext("Core Developers") .. ",," .. table.concat(core_developers, ",,") .. ",,," .. "#FFFF00," .. fgettext("Active Contributors") .. ",," .. diff --git a/builtin/mainmenu/tab_multiplayer.lua b/builtin/mainmenu/tab_multiplayer.lua index 00150f26d..3c2b2cdbe 100644 --- a/builtin/mainmenu/tab_multiplayer.lua +++ b/builtin/mainmenu/tab_multiplayer.lua @@ -20,7 +20,16 @@ local function get_formspec(tabview, name, tabdata) -- Update the cached supported proto info, -- it may have changed after a change by the settings menu. common_update_cached_supp_proto() - local fav_selected = menudata.favorites[tabdata.fav_selected] + local fav_selected = nil + if menudata.search_result then + fav_selected = menudata.search_result[tabdata.fav_selected] + else + fav_selected = menudata.favorites[tabdata.fav_selected] + end + + if not tabdata.search_for then + tabdata.search_for = "" + end local retval = "label[7.75,-0.15;" .. fgettext("Address / Port") .. "]" .. @@ -33,7 +42,9 @@ local function get_formspec(tabview, name, tabdata) "field[8,1.95;2.95,0.5;te_name;;" .. core.formspec_escape(core.setting_get("name")) .. "]" .. "pwdfield[10.78,1.95;1.77,0.5;te_pwd;]" .. - "box[7.73,2.35;4.3,2.28;#999999]" + "box[7.73,2.35;4.3,2.28;#999999]".. + "field[0.15,0.25;4.5,0.27;te_search;;"..core.formspec_escape(tabdata.search_for).."]".. + "button[4.8,0;2.7,0.1;btn_mp_search;" .. fgettext("Search") .. "]" if tabdata.fav_selected and fav_selected then if gamedata.fav then @@ -58,9 +69,27 @@ local function get_formspec(tabview, name, tabdata) image_column(fgettext("PvP enabled"), "pvp") .. ",padding=0.25;" .. "color,span=1;" .. "text,padding=1]" .. - "table[-0.15,-0.1;7.75,5.5;favourites;" + "table[-0.15,0.4;7.75,5.35;favourites;" + + if menudata.search_result then + for i = 1, #menudata.search_result do + local favs = core.get_favorites("local") + local server = menudata.search_result[i] - if #menudata.favorites > 0 then + for fav_id = 1, #favs do + if server.address == favs[fav_id].address and + server.port == favs[fav_id].port then + server.is_favorite = true + end + end + + if i ~= 1 then + retval = retval .. "," + end + + retval = retval .. render_serverlist_row(server, server.is_favorite) + end + elseif #menudata.favorites > 0 then local favs = core.get_favorites("local") if #favs > 0 then for i = 1, #favs do @@ -75,9 +104,9 @@ local function get_formspec(tabview, name, tabdata) end end end - retval = retval .. render_favorite(menudata.favorites[1], (#favs > 0)) + retval = retval .. render_serverlist_row(menudata.favorites[1], (#favs > 0)) for i = 2, #menudata.favorites do - retval = retval .. "," .. render_favorite(menudata.favorites[i], (i <= #favs)) + retval = retval .. "," .. render_serverlist_row(menudata.favorites[i], (i <= #favs)) end end @@ -92,6 +121,8 @@ end -------------------------------------------------------------------------------- local function main_button_handler(tabview, fields, name, tabdata) + local serverlist = menudata.search_result or menudata.favorites + if fields.te_name then gamedata.playername = fields.te_name core.setting_set("name", fields.te_name) @@ -99,10 +130,10 @@ local function main_button_handler(tabview, fields, name, tabdata) if fields.favourites then local event = core.explode_table_event(fields.favourites) - local fav = menudata.favorites[event.row] + local fav = serverlist[event.row] if event.type == "DCL" then - if event.row <= #menudata.favorites then + if event.row <= #serverlist then if menudata.favorites_is_public and not is_server_protocol_compat_or_error( fav.proto_min, fav.proto_max) then @@ -131,7 +162,7 @@ local function main_button_handler(tabview, fields, name, tabdata) end if event.type == "CHG" then - if event.row <= #menudata.favorites then + if event.row <= #serverlist then gamedata.fav = false local favs = core.get_favorites("local") local address = fav.address @@ -157,7 +188,7 @@ local function main_button_handler(tabview, fields, name, tabdata) if fields.key_up or fields.key_down then local fav_idx = core.get_table_index("favourites") - local fav = menudata.favorites[fav_idx] + local fav = serverlist[fav_idx] if fav_idx then if fields.key_up and fav_idx > 1 then @@ -176,7 +207,7 @@ local function main_button_handler(tabview, fields, name, tabdata) local address = fav.address local port = fav.port - + gamedata.serverdescription = fav.description if address and port then core.setting_set("address", address) core.setting_set("remote_port", port) @@ -199,6 +230,65 @@ local function main_button_handler(tabview, fields, name, tabdata) return true end + if fields.btn_mp_search or fields.key_enter_field == "te_search" then + tabdata.fav_selected = 1 + local input = fields.te_search:lower() + tabdata.search_for = fields.te_search + + if #menudata.favorites < 2 then + return true + end + + menudata.search_result = {} + + -- setup the keyword list + local keywords = {} + for word in input:gmatch("%S+") do + table.insert(keywords, word) + end + + if #keywords == 0 then + menudata.search_result = nil + return true + end + + -- Search the serverlist + local search_result = {} + for i = 1, #menudata.favorites do + local server = menudata.favorites[i] + local found = 0 + for k = 1, #keywords do + local keyword = keywords[k] + if server.name then + local name = server.name:lower() + local _, count = name:gsub(keyword, keyword) + found = found + count * 4 + end + + if server.description then + local desc = server.description:lower() + local _, count = desc:gsub(keyword, keyword) + found = found + count * 2 + end + end + if found > 0 then + local points = (#menudata.favorites - i) / 5 + found + server.points = points + table.insert(search_result, server) + end + end + if #search_result > 0 then + table.sort(search_result, function(a, b) + return a.points > b.points + end) + menudata.search_result = search_result + local first_server = search_result[1] + core.setting_set("address", first_server.address) + core.setting_set("remote_port", first_server.port) + end + return true + end + if (fields.btn_mp_connect or fields.key_enter) and fields.te_address and fields.te_port then gamedata.playername = fields.te_name gamedata.password = fields.te_pwd @@ -206,9 +296,9 @@ local function main_button_handler(tabview, fields, name, tabdata) gamedata.port = fields.te_port gamedata.selected_world = 0 local fav_idx = core.get_table_index("favourites") - local fav = menudata.favorites[fav_idx] + local fav = serverlist[fav_idx] - if fav_idx and fav_idx <= #menudata.favorites and + if fav_idx and fav_idx <= #serverlist and fav.address == fields.te_address and fav.port == fields.te_port then diff --git a/builtin/mainmenu/tab_server.lua b/builtin/mainmenu/tab_server.lua index 6b96825a0..be57ad7ef 100644 --- a/builtin/mainmenu/tab_server.lua +++ b/builtin/mainmenu/tab_server.lua @@ -26,7 +26,7 @@ local function get_formspec(tabview, name, tabdata) "button[4,4.15;2.6,0.5;world_delete;" .. fgettext("Delete") .. "]" .. "button[6.5,4.15;2.8,0.5;world_create;" .. fgettext("New") .. "]" .. "button[9.2,4.15;2.55,0.5;world_configure;" .. fgettext("Configure") .. "]" .. - "button[8.5,4.95;3.25,0.5;start_server;" .. fgettext("Start Game") .. "]" .. + "button[8.5,5;3.25,0.5;start_server;" .. fgettext("Start Game") .. "]" .. "label[4,-0.25;" .. fgettext("Select World:") .. "]" .. "checkbox[0.25,0.25;cb_creative_mode;" .. fgettext("Creative Mode") .. ";" .. dump(core.setting_getbool("creative_mode")) .. "]" .. diff --git a/builtin/mainmenu/tab_settings.lua b/builtin/mainmenu/tab_settings.lua index af8df0ccb..e59572a41 100644 --- a/builtin/mainmenu/tab_settings.lua +++ b/builtin/mainmenu/tab_settings.lua @@ -209,12 +209,12 @@ local function formspec(tabview, name, tabdata) .. fgettext("Reset singleplayer world") .. "]" else tab_string = tab_string .. - "button[8,4.75;3.75,0.5;btn_change_keys;" + "button[8,4.85;3.75,0.5;btn_change_keys;" .. fgettext("Change keys") .. "]" end tab_string = tab_string .. - "button[0,4.75;3.75,0.5;btn_advanced_settings;" + "button[0,4.85;3.75,0.5;btn_advanced_settings;" .. fgettext("Advanced Settings") .. "]" diff --git a/builtin/mainmenu/tab_simple_main.lua b/builtin/mainmenu/tab_simple_main.lua index 3818f321f..a773a4912 100644 --- a/builtin/mainmenu/tab_simple_main.lua +++ b/builtin/mainmenu/tab_simple_main.lua @@ -70,9 +70,9 @@ local function get_formspec(tabview, name, tabdata) end end end - retval = retval .. render_favorite(menudata.favorites[1], (#favs > 0)) + retval = retval .. render_serverlist_row(menudata.favorites[1], (#favs > 0)) for i = 2, #menudata.favorites do - retval = retval .. "," .. render_favorite(menudata.favorites[i], (i <= #favs)) + retval = retval .. "," .. render_serverlist_row(menudata.favorites[i], (i <= #favs)) end end diff --git a/builtin/mainmenu/tab_singleplayer.lua b/builtin/mainmenu/tab_singleplayer.lua index 05060cbc6..236de763c 100644 --- a/builtin/mainmenu/tab_singleplayer.lua +++ b/builtin/mainmenu/tab_singleplayer.lua @@ -57,7 +57,7 @@ local function singleplayer_refresh_gamebar() local btnbar = buttonbar_create("game_button_bar", game_buttonbar_button_handler, - {x=-0.3,y=5.65}, "horizontal", {x=12.4,y=1.15}) + {x=-0.3,y=5.9}, "horizontal", {x=12.4,y=1.15}) for i=1,#gamemgr.games,1 do local btn_name = "game_btnbar_" .. gamemgr.games[i].id @@ -96,7 +96,7 @@ local function get_formspec(tabview, name, tabdata) "button[4,4.15;2.6,0.5;world_delete;".. fgettext("Delete") .. "]" .. "button[6.5,4.15;2.8,0.5;world_create;".. fgettext("New") .. "]" .. "button[9.2,4.15;2.55,0.5;world_configure;".. fgettext("Configure") .. "]" .. - "button[8.5,4.95;3.25,0.5;play;".. fgettext("Play") .. "]" .. + "button[8.5,5;3.25,0.5;play;".. fgettext("Play") .. "]" .. "label[4,-0.25;".. fgettext("Select World:") .. "]".. "checkbox[0.25,0.25;cb_creative_mode;".. fgettext("Creative Mode") .. ";" .. dump(core.setting_getbool("creative_mode")) .. "]".. -- cgit v1.2.3 From d2f5732f89cd58dafc6a4f398b8ebfd122754852 Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Mon, 16 Jan 2017 15:15:43 +0000 Subject: Adjust formspec spacing on the Client tab of the mainmenu --- builtin/mainmenu/tab_multiplayer.lua | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) (limited to 'builtin/mainmenu') diff --git a/builtin/mainmenu/tab_multiplayer.lua b/builtin/mainmenu/tab_multiplayer.lua index 3c2b2cdbe..f8edeaddd 100644 --- a/builtin/mainmenu/tab_multiplayer.lua +++ b/builtin/mainmenu/tab_multiplayer.lua @@ -32,27 +32,36 @@ local function get_formspec(tabview, name, tabdata) end local retval = - "label[7.75,-0.15;" .. fgettext("Address / Port") .. "]" .. - "label[7.75,1.05;" .. fgettext("Name / Password") .. "]" .. - "field[8,0.75;3.3,0.5;te_address;;" .. + -- Search + "field[0.15,0.35;6.05,0.27;te_search;;"..core.formspec_escape(tabdata.search_for).."]".. + "button[5.8,0.1;2,0.1;btn_mp_search;" .. fgettext("Search") .. "]" .. + + -- Address / Port + "label[7.75,-0.25;" .. fgettext("Address / Port") .. "]" .. + "field[8,0.65;3.25,0.5;te_address;;" .. core.formspec_escape(core.setting_get("address")) .. "]" .. - "field[11.15,0.75;1.4,0.5;te_port;;" .. + "field[11.1,0.65;1.4,0.5;te_port;;" .. core.formspec_escape(core.setting_get("remote_port")) .. "]" .. - "button[10.1,4.9;2,0.5;btn_mp_connect;" .. fgettext("Connect") .. "]" .. - "field[8,1.95;2.95,0.5;te_name;;" .. + + -- Name / Password + "label[7.75,0.95;" .. fgettext("Name / Password") .. "]" .. + "field[8,1.85;2.9,0.5;te_name;;" .. core.formspec_escape(core.setting_get("name")) .. "]" .. - "pwdfield[10.78,1.95;1.77,0.5;te_pwd;]" .. - "box[7.73,2.35;4.3,2.28;#999999]".. - "field[0.15,0.25;4.5,0.27;te_search;;"..core.formspec_escape(tabdata.search_for).."]".. - "button[4.8,0;2.7,0.1;btn_mp_search;" .. fgettext("Search") .. "]" + "pwdfield[10.73,1.85;1.77,0.5;te_pwd;]" .. + + -- Description Background + "box[7.73,2.25;4.25,2.6;#999999]".. + + -- Connect + "button[10.1,5.15;2,0.5;btn_mp_connect;" .. fgettext("Connect") .. "]" if tabdata.fav_selected and fav_selected then if gamedata.fav then - retval = retval .. "button[7.85,4.9;2.3,0.5;btn_delete_favorite;" .. + retval = retval .. "button[7.75,5.15;2.3,0.5;btn_delete_favorite;" .. fgettext("Del. Favorite") .. "]" end if fav_selected.description then - retval = retval .. "textarea[8.1,2.4;4.26,2.6;;" .. + retval = retval .. "textarea[8.1,2.3;4.23,2.9;;" .. core.formspec_escape((gamedata.serverdescription or ""), true) .. ";]" end end @@ -69,7 +78,7 @@ local function get_formspec(tabview, name, tabdata) image_column(fgettext("PvP enabled"), "pvp") .. ",padding=0.25;" .. "color,span=1;" .. "text,padding=1]" .. - "table[-0.15,0.4;7.75,5.35;favourites;" + "table[-0.15,0.6;7.75,5.15;favourites;" if menudata.search_result then for i = 1, #menudata.search_result do -- cgit v1.2.3 From a378e32751127e2ae3708a33f035d1dcf5d400a1 Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Wed, 18 Jan 2017 06:48:25 +0000 Subject: Add search to advanced settings (#4806) * Add search to advanced settings * Press enter again to go to next result * Use keyword based search, auto select best option --- builtin/mainmenu/dlg_settings_advanced.lua | 120 +++++++++++++++++++++++++++-- 1 file changed, 114 insertions(+), 6 deletions(-) (limited to 'builtin/mainmenu') diff --git a/builtin/mainmenu/dlg_settings_advanced.lua b/builtin/mainmenu/dlg_settings_advanced.lua index 60ec1250f..697babeb6 100644 --- a/builtin/mainmenu/dlg_settings_advanced.lua +++ b/builtin/mainmenu/dlg_settings_advanced.lua @@ -344,7 +344,82 @@ local function parse_config_file(read_all, parse_mods) return settings end -local settings = parse_config_file(false, true) +local function filter_settings(settings, searchstring) + if not searchstring or searchstring == "" then + return settings, -1 + end + + -- Setup the keyword list + local keywords = {} + for word in searchstring:lower():gmatch("%S+") do + table.insert(keywords, word) + end + + local result = {} + local category_stack = {} + local current_level = 0 + local best_setting = nil + for _, entry in pairs(settings) do + if entry.type == "category" then + -- Remove all settingless categories + while #category_stack > 0 and entry.level <= current_level do + table.remove(category_stack, #category_stack) + if #category_stack > 0 then + current_level = category_stack[#category_stack].level + else + current_level = 0 + end + end + + -- Push category onto stack + category_stack[#category_stack + 1] = entry + current_level = entry.level + else + -- See if setting matches keywords + local setting_score = 0 + for k = 1, #keywords do + local keyword = keywords[k] + + if string.find(entry.name:lower(), keyword, 1, true) then + setting_score = setting_score + 1 + end + + if entry.readable_name and + string.find(fgettext(entry.readable_name):lower(), keyword, 1, true) then + setting_score = setting_score + 1 + end + + if entry.comment and + string.find(fgettext_ne(entry.comment):lower(), keyword, 1, true) then + setting_score = setting_score + 1 + end + end + + -- Add setting to results if match + if setting_score > 0 then + -- Add parent categories + for _, category in pairs(category_stack) do + result[#result + 1] = category + end + category_stack = {} + + -- Add setting + result[#result + 1] = entry + entry.score = setting_score + + if not best_setting or + setting_score > result[best_setting].score then + best_setting = #result + end + end + end + end + return result, best_setting or -1 +end + +local full_settings = parse_config_file(false, true) +local search_string = "" +local settings = full_settings local selected_setting = 1 local function get_current_value(setting) @@ -546,7 +621,10 @@ local function create_settings_formspec(tabview, name, tabdata) local formspec = "size[12,6.5;true]" .. "tablecolumns[color;tree;text,width=32;text]" .. "tableoptions[background=#00000000;border=false]" .. - "table[0,0;12,5.5;list_settings;" + "field[0.3,0.1;10.2,1;search_string;;" .. core.formspec_escape(search_string) .. "]" .. + "field_close_on_enter[search_string;false]" .. + "button[10.2,-0.2;2,1;search;" .. fgettext("Search") .. "]" .. + "table[0,0.8;12,4.5;list_settings;" local current_level = 0 for _, entry in ipairs(settings) do @@ -597,10 +675,10 @@ local function handle_settings_buttons(this, fields, tabname, tabdata) local list_enter = false if fields["list_settings"] then selected_setting = core.get_table_index("list_settings") - if core.explode_table_event(fields["list_settings"]).type == "DCL" then + if core.explode_table_event(fields["list_settings"]).type == "DCL" then -- Directly toggle booleans local setting = settings[selected_setting] - if setting.type == "bool" then + if setting and setting.type == "bool" then local current_value = get_current_value(setting) core.setting_setbool(setting.name, not core.is_yes(current_value)) core.setting_save() @@ -613,9 +691,39 @@ local function handle_settings_buttons(this, fields, tabname, tabdata) end end + if fields.search or fields.key_enter_field == "search_string" then + if search_string == fields.search_string then + if selected_setting > 0 then + -- Go to next result on enter press + local i = selected_setting + 1 + local looped = false + while i > #settings or settings[i].type == "category" do + i = i + 1 + if i > #settings then + -- Stop infinte looping + if looped then + return false + end + i = 1 + looped = true + end + end + selected_setting = i + core.update_formspec(this:get_formspec()) + return true + end + else + -- Search for setting + search_string = fields.search_string + settings, selected_setting = filter_settings(full_settings, search_string) + core.update_formspec(this:get_formspec()) + end + return true + end + if fields["btn_edit"] or list_enter then local setting = settings[selected_setting] - if setting.type ~= "category" then + if setting and setting.type ~= "category" then local edit_dialog = dialog_create("change_setting", create_change_setting_formspec, handle_change_setting_buttons) edit_dialog:set_parent(this) @@ -627,7 +735,7 @@ local function handle_settings_buttons(this, fields, tabname, tabdata) if fields["btn_restore"] then local setting = settings[selected_setting] - if setting.type ~= "category" then + if setting and setting.type ~= "category" then core.setting_set(setting.name, setting.default) core.setting_save() core.update_formspec(this:get_formspec()) -- cgit v1.2.3 From 03b34cb3dd0647b3e378f00cdc7203e580c9dcc8 Mon Sep 17 00:00:00 2001 From: kilbith Date: Fri, 3 Feb 2017 14:53:43 +0100 Subject: Serverlist: Add ping indicators (#5164) --- builtin/mainmenu/common.lua | 21 ++++++++++++++++++++- builtin/mainmenu/tab_multiplayer.lua | 1 + builtin/mainmenu/tab_simple_main.lua | 1 + src/script/lua_api/l_mainmenu.cpp | 7 +++++++ textures/base/pack/server_ping_1.png | Bin 0 -> 251 bytes textures/base/pack/server_ping_2.png | Bin 0 -> 244 bytes textures/base/pack/server_ping_3.png | Bin 0 -> 245 bytes textures/base/pack/server_ping_4.png | Bin 0 -> 213 bytes 8 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 textures/base/pack/server_ping_1.png create mode 100644 textures/base/pack/server_ping_2.png create mode 100644 textures/base/pack/server_ping_3.png create mode 100644 textures/base/pack/server_ping_4.png (limited to 'builtin/mainmenu') diff --git a/builtin/mainmenu/common.lua b/builtin/mainmenu/common.lua index 5e3df0864..17d910e8b 100644 --- a/builtin/mainmenu/common.lua +++ b/builtin/mainmenu/common.lua @@ -54,7 +54,11 @@ end function image_column(tooltip, flagname) return "image,tooltip=" .. core.formspec_escape(tooltip) .. "," .. "0=" .. core.formspec_escape(defaulttexturedir .. "blank.png") .. "," .. - "1=" .. core.formspec_escape(defaulttexturedir .. "server_flags_" .. flagname .. ".png") + "1=" .. core.formspec_escape(defaulttexturedir .. "server_flags_" .. flagname .. ".png") .. "," .. + "2=" .. core.formspec_escape(defaulttexturedir .. "server_ping_4.png") .. "," .. + "3=" .. core.formspec_escape(defaulttexturedir .. "server_ping_3.png") .. "," .. + "4=" .. core.formspec_escape(defaulttexturedir .. "server_ping_2.png") .. "," .. + "5=" .. core.formspec_escape(defaulttexturedir .. "server_ping_1.png") end -------------------------------------------------------------------------------- @@ -97,6 +101,21 @@ function render_serverlist_row(spec, is_favorite) details = "0," end + if spec.ping then + local ping = spec.ping * 1000 + if ping <= 50 then + details = details .. "2," + elseif ping <= 100 then + details = details .. "3," + elseif ping <= 250 then + details = details .. "4," + else + details = details .. "5," + end + else + details = details .. "0," + end + if spec.clients and spec.clients_max then local clients_color = '' local clients_percent = 100 * spec.clients / spec.clients_max diff --git a/builtin/mainmenu/tab_multiplayer.lua b/builtin/mainmenu/tab_multiplayer.lua index f8edeaddd..033ba38d8 100644 --- a/builtin/mainmenu/tab_multiplayer.lua +++ b/builtin/mainmenu/tab_multiplayer.lua @@ -69,6 +69,7 @@ local function get_formspec(tabview, name, tabdata) --favourites retval = retval .. "tablecolumns[" .. image_column(fgettext("Favorite"), "favorite") .. ";" .. + image_column(fgettext("Ping"), "") .. ",padding=0.25;" .. "color,span=3;" .. "text,align=right;" .. -- clients "text,align=center,padding=0.25;" .. -- "/" diff --git a/builtin/mainmenu/tab_simple_main.lua b/builtin/mainmenu/tab_simple_main.lua index a773a4912..23820aab7 100644 --- a/builtin/mainmenu/tab_simple_main.lua +++ b/builtin/mainmenu/tab_simple_main.lua @@ -43,6 +43,7 @@ local function get_formspec(tabview, name, tabdata) retval = retval .. "tablecolumns[" .. image_column(fgettext("Favorite"), "favorite") .. ";" .. + image_column(fgettext("Ping"), "") .. ",padding=0.25;" .. "color,span=3;" .. "text,align=right;" .. -- clients "text,align=center,padding=0.25;" .. -- "/" diff --git a/src/script/lua_api/l_mainmenu.cpp b/src/script/lua_api/l_mainmenu.cpp index 4a2484613..de8890b11 100644 --- a/src/script/lua_api/l_mainmenu.cpp +++ b/src/script/lua_api/l_mainmenu.cpp @@ -577,6 +577,13 @@ int ModApiMainMenu::l_get_favorites(lua_State *L) lua_settable(L, top_lvl2); } + if (servers[i].isMember("ping")) { + float ping = servers[i]["ping"].asFloat(); + lua_pushstring(L, "ping"); + lua_pushnumber(L, ping); + lua_settable(L, top_lvl2); + } + lua_settable(L, top); index++; } diff --git a/textures/base/pack/server_ping_1.png b/textures/base/pack/server_ping_1.png new file mode 100644 index 000000000..ba5bba1e3 Binary files /dev/null and b/textures/base/pack/server_ping_1.png differ diff --git a/textures/base/pack/server_ping_2.png b/textures/base/pack/server_ping_2.png new file mode 100644 index 000000000..8dca0be0d Binary files /dev/null and b/textures/base/pack/server_ping_2.png differ diff --git a/textures/base/pack/server_ping_3.png b/textures/base/pack/server_ping_3.png new file mode 100644 index 000000000..c2cab017e Binary files /dev/null and b/textures/base/pack/server_ping_3.png differ diff --git a/textures/base/pack/server_ping_4.png b/textures/base/pack/server_ping_4.png new file mode 100644 index 000000000..03b4b5b83 Binary files /dev/null and b/textures/base/pack/server_ping_4.png differ -- cgit v1.2.3 From bb4db84bdbc7038a6ac495dd5f732f89ac40bfcc Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Tue, 27 Dec 2016 23:26:36 +0000 Subject: Use tree to list mods rather than textlist --- builtin/mainmenu/dlg_config_world.lua | 110 ++++++++++------------------------ builtin/mainmenu/modmgr.lua | 54 ++++++++--------- builtin/mainmenu/tab_mods.lua | 7 ++- 3 files changed, 59 insertions(+), 112 deletions(-) (limited to 'builtin/mainmenu') diff --git a/builtin/mainmenu/dlg_config_world.lua b/builtin/mainmenu/dlg_config_world.lua index 7b3ab9852..619c927c5 100644 --- a/builtin/mainmenu/dlg_config_world.lua +++ b/builtin/mainmenu/dlg_config_world.lua @@ -17,14 +17,13 @@ -------------------------------------------------------------------------------- -local enabled_all = false +local enabled_all = false local function modname_valid(name) return not name:find("[^a-z0-9_]") end local function get_formspec(data) - local mod = data.list:get_list()[data.selected_mod] local retval = @@ -32,24 +31,12 @@ local function get_formspec(data) "label[0.5,0;" .. fgettext("World:") .. "]" .. "label[1.75,0;" .. data.worldspec.name .. "]" - if data.hide_gamemods then - retval = retval .. "checkbox[1,6;cb_hide_gamemods;" .. fgettext("Hide Game") .. ";true]" - else - retval = retval .. "checkbox[1,6;cb_hide_gamemods;" .. fgettext("Hide Game") .. ";false]" - end - - if data.hide_modpackcontents then - retval = retval .. "checkbox[6,6;cb_hide_mpcontent;" .. fgettext("Hide mp content") .. ";true]" - else - retval = retval .. "checkbox[6,6;cb_hide_mpcontent;" .. fgettext("Hide mp content") .. ";false]" - end - if mod == nil then mod = {name=""} end local hard_deps, soft_deps = modmgr.get_dependencies(mod.path) - + retval = retval .. "label[0,0.7;" .. fgettext("Mod:") .. "]" .. "label[0.75,0.7;" .. mod.name .. "]" .. @@ -62,41 +49,45 @@ local function get_formspec(data) "button[3.25,7;2.5,0.5;btn_config_world_save;" .. fgettext("Save") .. "]" .. "button[5.75,7;2.5,0.5;btn_config_world_cancel;" .. fgettext("Cancel") .. "]" - if mod ~= nil and mod.name ~= "" and mod.typ ~= "game_mod" then + if mod and mod.name ~= "" and mod.typ ~= "game_mod" then if mod.is_modpack then local rawlist = data.list:get_raw_list() local all_enabled = true - for j=1,#rawlist,1 do - if rawlist[j].modpack == mod.name and - rawlist[j].enabled ~= true then - all_enabled = false - break + for j = 1, #rawlist, 1 do + if rawlist[j].modpack == mod.name and not rawlist[j].enabled then + all_enabled = false + break end end - if all_enabled == false then - retval = retval .. "button[5.5,0.125;2.5,0.5;btn_mp_enable;" .. fgettext("Enable MP") .. "]" + if all_enabled then + retval = retval .. "button[5.5,0.125;2.5,0.5;btn_mp_disable;" .. + fgettext("Disable MP") .. "]" else - retval = retval .. "button[5.5,0.125;2.5,0.5;btn_mp_disable;" .. fgettext("Disable MP") .. "]" + retval = retval .. "button[5.5,0.125;2.5,0.5;btn_mp_enable;" .. + fgettext("Enable MP") .. "]" end else if mod.enabled then - retval = retval .. "checkbox[5.5,-0.125;cb_mod_enable;" .. fgettext("enabled") .. ";true]" + retval = retval .. "checkbox[5.5,-0.125;cb_mod_enable;" .. + fgettext("enabled") .. ";true]" else - retval = retval .. "checkbox[5.5,-0.125;cb_mod_enable;" .. fgettext("enabled") .. ";false]" + retval = retval .. "checkbox[5.5,-0.125;cb_mod_enable;" .. + fgettext("enabled") .. ";false]" end end end - if enabled_all then + if enabled_all then retval = retval .. - "button[8.75,0.125;2.5,0.5;btn_disable_all_mods;" .. fgettext("Disable all") .. "]" .. - "textlist[5.5,0.75;5.75,5.4;world_config_modlist;" + "button[8.75,0.125;2.5,0.5;btn_disable_all_mods;" .. fgettext("Disable all") .. "]" else retval = retval .. - "button[8.75,0.125;2.5,0.5;btn_enable_all_mods;" .. fgettext("Enable all") .. "]" .. - "textlist[5.5,0.75;5.75,5.4;world_config_modlist;" + "button[8.75,0.125;2.5,0.5;btn_enable_all_mods;" .. fgettext("Enable all") .. "]" end + retval = retval .. + "tablecolumns[color;tree;text]" .. + "table[5.5,0.75;5.75,6;world_config_modlist;" retval = retval .. modmgr.render_modlist(data.list) retval = retval .. ";" .. data.selected_mod .."]" @@ -129,16 +120,15 @@ end local function handle_buttons(this, fields) - if fields["world_config_modlist"] ~= nil then - local event = core.explode_textlist_event(fields["world_config_modlist"]) - this.data.selected_mod = event.index - core.setting_set("world_config_selected_mod", event.index) + local event = core.explode_table_event(fields["world_config_modlist"]) + this.data.selected_mod = event.row + core.setting_set("world_config_selected_mod", event.row) if event.type == "DCL" then enable_mod(this) end - + return true end @@ -160,44 +150,7 @@ local function handle_buttons(this, fields) return true end - if fields["cb_hide_gamemods"] ~= nil or - fields["cb_hide_mpcontent"] ~= nil then - local current = this.data.list:get_filtercriteria() - - if current == nil then - current = {} - end - - if fields["cb_hide_gamemods"] ~= nil then - if core.is_yes(fields["cb_hide_gamemods"]) then - current.hide_game = true - this.data.hide_gamemods = true - core.setting_set("world_config_hide_gamemods", "true") - else - current.hide_game = false - this.data.hide_gamemods = false - core.setting_set("world_config_hide_gamemods", "false") - end - end - - if fields["cb_hide_mpcontent"] ~= nil then - if core.is_yes(fields["cb_hide_mpcontent"]) then - current.hide_modpackcontents = true - this.data.hide_modpackcontents = true - core.setting_set("world_config_hide_modpackcontents", "true") - else - current.hide_modpackcontents = false - this.data.hide_modpackcontents = false - core.setting_set("world_config_hide_modpackcontents", "false") - end - end - - this.data.list:set_filtercriteria(current) - return true - end - if fields["btn_config_world_save"] then - local filename = this.data.worldspec.path .. DIR_DELIM .. "world.mt" @@ -231,7 +184,7 @@ local function handle_buttons(this, fields) if not worldfile:write() then core.log("error", "Failed to write world config file") end - + this:delete() return true end @@ -252,7 +205,7 @@ local function handle_buttons(this, fields) enabled_all = true return true end - + if fields.btn_disable_all_mods then local list = this.data.list:get_raw_list() @@ -269,14 +222,11 @@ local function handle_buttons(this, fields) end function create_configure_world_dlg(worldidx) - local dlg = dialog_create("sp_config_world", get_formspec, handle_buttons, nil) - dlg.data.hide_gamemods = core.setting_getbool("world_config_hide_gamemods") - dlg.data.hide_modpackcontents = core.setting_getbool("world_config_hide_modpackcontents") dlg.data.selected_mod = tonumber(core.setting_get("world_config_selected_mod")) if dlg.data.selected_mod == nil then dlg.data.selected_mod = 0 @@ -286,14 +236,14 @@ function create_configure_world_dlg(worldidx) if dlg.data.worldspec == nil then dlg:delete() return nil end dlg.data.worldconfig = modmgr.get_worldconfig(dlg.data.worldspec.path) - + if dlg.data.worldconfig == nil or dlg.data.worldconfig.id == nil or dlg.data.worldconfig.id == "" then dlg:delete() return nil end - + dlg.data.list = filterlist.create( modmgr.preparemodlist, --refresh modmgr.comparemod, --compare diff --git a/builtin/mainmenu/modmgr.lua b/builtin/mainmenu/modmgr.lua index 2b7b371bf..0fbfa3e6b 100644 --- a/builtin/mainmenu/modmgr.lua +++ b/builtin/mainmenu/modmgr.lua @@ -18,7 +18,7 @@ -------------------------------------------------------------------------------- function get_mods(path,retval,modpack) local mods = core.get_dir_list(path, true) - + for _, name in ipairs(mods) do if name:sub(1, 1) ~= "." then local prefix = path .. DIR_DELIM .. name .. DIR_DELIM @@ -237,49 +237,45 @@ function modmgr.render_modlist(render_list) local list = render_list:get_list() local last_modpack = nil - - for i,v in ipairs(list) do - if retval ~= "" then - retval = retval .."," + local retval = {} + local in_game_mods = false + for i, v in ipairs(list) do + if v.typ == "game_mod" and not in_game_mods then + in_game_mods = true + retval[#retval + 1] = mt_color_blue + retval[#retval + 1] = "0" + retval[#retval + 1] = fgettext("Subgame Mods") end local color = "" - if v.is_modpack then local rawlist = render_list:get_raw_list() + color = mt_color_dark_green - local all_enabled = true - for j=1,#rawlist,1 do + for j = 1, #rawlist, 1 do if rawlist[j].modpack == list[i].name and - rawlist[j].enabled ~= true then - all_enabled = false - break + rawlist[j].enabled ~= true then + -- Modpack not entirely enabled so showing as grey + color = mt_color_grey + break end end - - if all_enabled == false then - color = mt_color_grey - else - color = mt_color_dark_green - end - end - - if v.typ == "game_mod" then + elseif v.typ == "game_mod" then color = mt_color_blue - else - if v.enabled then - color = mt_color_green - end + elseif v.enabled then + color = mt_color_green end - retval = retval .. color - if v.modpack ~= nil then - retval = retval .. " " + retval[#retval + 1] = color + if v.modpack ~= nil or v.typ == "game_mod" then + retval[#retval + 1] = "1" + else + retval[#retval + 1] = "0" end - retval = retval .. v.name + retval[#retval + 1] = core.formspec_escape(v.name) end - return retval + return table.concat(retval, ",") end -------------------------------------------------------------------------------- diff --git a/builtin/mainmenu/tab_mods.lua b/builtin/mainmenu/tab_mods.lua index 4a5b6c041..29afd8a4e 100644 --- a/builtin/mainmenu/tab_mods.lua +++ b/builtin/mainmenu/tab_mods.lua @@ -28,7 +28,8 @@ local function get_formspec(tabview, name, tabdata) local retval = "label[0.05,-0.25;".. fgettext("Installed Mods:") .. "]" .. - "textlist[0,0.25;5.1,5;modlist;" .. + "tablecolumns[color;tree;text]" .. + "table[0,0.25;5.1,5;modlist;" .. modmgr.render_modlist(modmgr.global_mods) .. ";" .. tabdata.selected_mod .. "]" @@ -127,8 +128,8 @@ end -------------------------------------------------------------------------------- local function handle_buttons(tabview, fields, tabname, tabdata) if fields["modlist"] ~= nil then - local event = core.explode_textlist_event(fields["modlist"]) - tabdata.selected_mod = event.index + local event = core.explode_table_event(fields["modlist"]) + tabdata.selected_mod = event.row return true end -- cgit v1.2.3 From 2bd10022cb06850a404f180c455954ed2f817ce3 Mon Sep 17 00:00:00 2001 From: Hybrid Dog Date: Sat, 11 Feb 2017 11:39:41 +0100 Subject: Mainmenu: Brighter text colours for readability --- builtin/mainmenu/init.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'builtin/mainmenu') diff --git a/builtin/mainmenu/init.lua b/builtin/mainmenu/init.lua index 1b527a053..79e6d5c02 100644 --- a/builtin/mainmenu/init.lua +++ b/builtin/mainmenu/init.lua @@ -16,9 +16,9 @@ --51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. mt_color_grey = "#AAAAAA" -mt_color_blue = "#0000DD" -mt_color_green = "#00DD00" -mt_color_dark_green = "#003300" +mt_color_blue = "#6389FF" +mt_color_green = "#72FF63" +mt_color_dark_green = "#25C191" --for all other colors ask sfan5 to complete his work! -- cgit v1.2.3 From d0a6cacd51a25f75b0b2e9133514c7cf40a36805 Mon Sep 17 00:00:00 2001 From: kilbith Date: Thu, 16 Feb 2017 20:14:49 -0800 Subject: Multiplayer menu: fix attempt to open nonexistant image Since local servers and local favorites have no ping value (these are only provided by the server) we shouldn't load a broken image filename. Fixes #5238 --- builtin/mainmenu/common.lua | 3 ++- builtin/mainmenu/tab_multiplayer.lua | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'builtin/mainmenu') diff --git a/builtin/mainmenu/common.lua b/builtin/mainmenu/common.lua index 17d910e8b..57950c62c 100644 --- a/builtin/mainmenu/common.lua +++ b/builtin/mainmenu/common.lua @@ -54,7 +54,8 @@ end function image_column(tooltip, flagname) return "image,tooltip=" .. core.formspec_escape(tooltip) .. "," .. "0=" .. core.formspec_escape(defaulttexturedir .. "blank.png") .. "," .. - "1=" .. core.formspec_escape(defaulttexturedir .. "server_flags_" .. flagname .. ".png") .. "," .. + "1=" .. core.formspec_escape(defaulttexturedir .. + (flagname and "server_flags_" .. flagname .. ".png" or "blank.png")) .. "," .. "2=" .. core.formspec_escape(defaulttexturedir .. "server_ping_4.png") .. "," .. "3=" .. core.formspec_escape(defaulttexturedir .. "server_ping_3.png") .. "," .. "4=" .. core.formspec_escape(defaulttexturedir .. "server_ping_2.png") .. "," .. diff --git a/builtin/mainmenu/tab_multiplayer.lua b/builtin/mainmenu/tab_multiplayer.lua index 033ba38d8..0f4921b03 100644 --- a/builtin/mainmenu/tab_multiplayer.lua +++ b/builtin/mainmenu/tab_multiplayer.lua @@ -69,7 +69,7 @@ local function get_formspec(tabview, name, tabdata) --favourites retval = retval .. "tablecolumns[" .. image_column(fgettext("Favorite"), "favorite") .. ";" .. - image_column(fgettext("Ping"), "") .. ",padding=0.25;" .. + image_column(fgettext("Ping")) .. ",padding=0.25;" .. "color,span=3;" .. "text,align=right;" .. -- clients "text,align=center,padding=0.25;" .. -- "/" -- cgit v1.2.3 From cfe0291b131630a7400fdcf46b720bd70d8d0fa0 Mon Sep 17 00:00:00 2001 From: paramat Date: Mon, 17 Apr 2017 14:17:43 +0100 Subject: Conf.example: Move some lines to minetest.conf.example.extra Some information in conf.example cannot be generated from settingtypes.txt, moving it to a new file makes generating conf.example while preserving that information easier. Regenerate conf.example from settingtypes.txt. --- builtin/mainmenu/dlg_settings_advanced.lua | 6 --- minetest.conf.example | 37 +----------------- minetest.conf.example.extra | 63 ++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+), 42 deletions(-) create mode 100644 minetest.conf.example.extra (limited to 'builtin/mainmenu') diff --git a/builtin/mainmenu/dlg_settings_advanced.lua b/builtin/mainmenu/dlg_settings_advanced.lua index 697babeb6..c63eb972e 100644 --- a/builtin/mainmenu/dlg_settings_advanced.lua +++ b/builtin/mainmenu/dlg_settings_advanced.lua @@ -769,10 +769,4 @@ end -- Generate minetest.conf.example and settings_translation_file.cpp --- *** Please note *** --- There is text in minetest.conf.example that will not be generated from --- settingtypes.txt but must be preserved: --- The documentation of mapgen noise parameter formats (title plus 16 lines) --- Noise parameter 'mgv5_np_ground' in group format (13 lines) - --assert(loadfile(core.get_builtin_path()..DIR_DELIM.."mainmenu"..DIR_DELIM.."generate_from_settingtypes.lua"))(parse_config_file(true, false)) diff --git a/minetest.conf.example b/minetest.conf.example index 9b50a775d..bdd6fd7f4 100644 --- a/minetest.conf.example +++ b/minetest.conf.example @@ -92,7 +92,7 @@ # joystick_id = 0 # The type of joystick -# type: enum values: auto,generic,xbox +# type: enum values: auto, generic, xbox # joystick_type = auto # The time in seconds it takes between repeated events @@ -1201,25 +1201,6 @@ # type: int # num_emerge_threads = 1 -#### Noise parameters and formats - -# Noise parameters can be specified as a set of positional values, for example: -# Offset, scale, (spread factors), seed offset, number of octaves, persistence, lacunarity -# mgv6_np_terrain_base = -4, 20, (250, 250, 250), 82341, 5, 0.6, 2.0 -# Or the group format can be used instead, for example: -# mgv6_np_terrain_base = { -# offset = -4, -# scale = 20, -# spread = (250, 250, 250), -# seed = 82341, -# octaves = 5, -# persistence = 0.6, -# lacunarity = 2.0, -# flags = "defaults" -# } -# Only the group format supports noise flags which are needed for eased noise. -# Mgv5 uses eased noise for np_ground so this is shown in group format below. - #### Biome API temperature and humidity noise parameters # Temperature variation for biomes. @@ -1287,22 +1268,6 @@ # type: noise_params # mgv5_np_cavern = 0, 1, (384, 128, 384), 723, 5, 0.63, 2.0 -# Noise parameter in group format, unsupported by advanced settings -# menu but settable in minetest.conf. -# See documentation of noise parameter formats above. -# 3D noise defining terrain. -# type: noise_params -# mgv5_np_ground = { -# offset = 0, -# scale = 40, -# spread = (80, 80, 80), -# seed = 983240, -# octaves = 4, -# persistence = 0.55, -# lacunarity = 2.0, -# flags = "eased" -# } - #### Mapgen v6 # Map generation attributes specific to Mapgen v6. diff --git a/minetest.conf.example.extra b/minetest.conf.example.extra new file mode 100644 index 000000000..7dd6c0939 --- /dev/null +++ b/minetest.conf.example.extra @@ -0,0 +1,63 @@ +# This file contains information (some of which was previously stored in +# minetest.conf.example) that cannot be automatically generated from +# builtin/settingtypes.txt. +# This file contains a list of settings and their default value for minetest.conf + +# By default, all the settings are commented and not functional. +# Uncomment settings by removing the preceding #. + +# minetest.conf is read by default from: +# ../minetest.conf +# ../../minetest.conf +# Any other path can be chosen by passing the path as a parameter +# to the program, eg. "minetest.exe --config ../minetest.conf.example". + +# Further documentation: +# http://wiki.minetest.net/ + + +# Mapgen + +# Noise parameters and formats + +# Noise parameters can be specified as a set of positional values, for example: +# +# Offset, scale, (x, y, z spread factors), seed offset, octaves, persistence, lacunarity +# mgv6_np_terrain_base = -4, 20, (250, 250, 250), 82341, 5, 0.6, 2.0 +# +# Or the group format can be used instead, for example: +# +# mgv6_np_terrain_base = { +# offset = -4, +# scale = 20, +# spread = (250, 250, 250), +# seed = 82341, +# octaves = 5, +# persistence = 0.6, +# lacunarity = 2.0, +# flags = "defaults" +# } +# +# The advanced settings menu does not yet support the group format. +# Only the group format supports noise flags which are needed for eased noise. +# Mgv5 uses eased noise for np_ground so this is shown in group format below +# and is not present in the advanced settings menu. + +# Mapgen v5 + +# Noise parameter in group format, unsupported by advanced settings menu but +# settable in minetest.conf. +# See documentation of noise parameter formats above. +# +# 3D noise defining terrain. +# type: noise_params +# mgv5_np_ground = { +# offset = 0, +# scale = 40, +# spread = (80, 80, 80), +# seed = 983240, +# octaves = 4, +# persistence = 0.55, +# lacunarity = 2.0, +# flags = "eased" +# } -- cgit v1.2.3 From 21e0a049f81eb0d34adaf45646b11569eeadec52 Mon Sep 17 00:00:00 2001 From: Loïc Blot Date: Fri, 5 May 2017 13:47:11 +0200 Subject: Save minetest screen width/height options when modified (#5683) * Save minetest screen width/height options when modified * Add autosave_screensize setting (default true) * Fix @SmallJoker comments --- builtin/mainmenu/tab_settings.lua | 9 ++++++++- builtin/settingtypes.txt | 3 +++ minetest.conf.example | 4 ++++ src/defaultsettings.cpp | 1 + src/game.cpp | 16 ++++++++++++++++ src/guiEngine.cpp | 20 ++++++++++++++++++-- 6 files changed, 50 insertions(+), 3 deletions(-) (limited to 'builtin/mainmenu') diff --git a/builtin/mainmenu/tab_settings.lua b/builtin/mainmenu/tab_settings.lua index e59572a41..8a97d8334 100644 --- a/builtin/mainmenu/tab_settings.lua +++ b/builtin/mainmenu/tab_settings.lua @@ -190,7 +190,7 @@ local function formspec(tabview, name, tabdata) .. getSettingIndex.NodeHighlighting() .. "]" .. "dropdown[0.25,3.6;3.3;dd_leaves_style;" .. dd_options.leaves[1] .. ";" .. getSettingIndex.Leaves() .. "]" .. - "box[3.75,0;3.75,3.45;#999999]" .. + "box[3.75,0;3.75,4.45;#999999]" .. "label[3.85,0.1;" .. fgettext("Texturing:") .. "]" .. "dropdown[3.85,0.55;3.85;dd_filters;" .. dd_options.filters[1] .. ";" .. getSettingIndex.Filter() .. "]" .. @@ -199,6 +199,9 @@ local function formspec(tabview, name, tabdata) "label[3.85,2.15;" .. fgettext("Antialiasing:") .. "]" .. "dropdown[3.85,2.6;3.85;dd_antialiasing;" .. dd_options.antialiasing[1] .. ";" .. getSettingIndex.Antialiasing() .. "]" .. + "label[3.85,3.45;" .. fgettext("Screen:") .. "]" .. + "checkbox[3.85,3.6;cb_autosave_screensize;" .. fgettext("Autosave screen size") .. ";" + .. dump(core.setting_getbool("autosave_screensize")) .. "]" .. "box[7.75,0;4,4.4;#999999]" .. "checkbox[8,0;cb_shaders;" .. fgettext("Shaders") .. ";" .. dump(core.setting_getbool("enable_shaders")) .. "]" @@ -290,6 +293,10 @@ local function handle_settings_buttons(this, fields, tabname, tabdata) core.setting_set("connected_glass", fields["cb_connected_glass"]) return true end + if fields["cb_autosave_screensize"] then + core.setting_set("autosave_screensize", fields["cb_autosave_screensize"]) + return true + end if fields["cb_shaders"] then if (core.setting_get("video_driver") == "direct3d8" or core.setting_get("video_driver") == "direct3d9") then diff --git a/builtin/settingtypes.txt b/builtin/settingtypes.txt index 29a96ab8e..4b82a1e0e 100644 --- a/builtin/settingtypes.txt +++ b/builtin/settingtypes.txt @@ -459,6 +459,9 @@ screenW (Screen width) int 800 # Height component of the initial window size. screenH (Screen height) int 600 +# Save window size automatically when modified. +autosave_screensize (Autosave Screen Size) bool true + # Fullscreen mode. fullscreen (Full screen) bool false diff --git a/minetest.conf.example b/minetest.conf.example index ecbadb556..b9efc432a 100644 --- a/minetest.conf.example +++ b/minetest.conf.example @@ -526,6 +526,10 @@ # type: int # screenH = 600 +# Save the window size automatically when modified. +# type: bool +# autosave_screensize = true + # Fullscreen mode. # type: bool # fullscreen = false diff --git a/src/defaultsettings.cpp b/src/defaultsettings.cpp index d45e386cf..434c887e8 100644 --- a/src/defaultsettings.cpp +++ b/src/defaultsettings.cpp @@ -121,6 +121,7 @@ void set_default_settings(Settings *settings) settings->setDefault("viewing_range", "100"); settings->setDefault("screenW", "800"); settings->setDefault("screenH", "600"); + settings->setDefault("autosave_screensize", "true"); settings->setDefault("fullscreen", "false"); settings->setDefault("fullscreen_bpp", "24"); settings->setDefault("vsync", "false"); diff --git a/src/game.cpp b/src/game.cpp index be0cc8fd5..ace647456 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -1629,10 +1629,26 @@ void Game::run() && client->checkPrivilege("fast"); #endif + irr::core::dimension2d previous_screen_size(g_settings->getU16("screenW"), + g_settings->getU16("screenH")); + while (device->run() && !(*kill || g_gamecallback->shutdown_requested || (server && server->getShutdownRequested()))) { + const irr::core::dimension2d ¤t_screen_size = + device->getVideoDriver()->getScreenSize(); + // Verify if window size has changed and save it if it's the case + // Ensure evaluating settings->getBool after verifying screensize + // First condition is cheaper + if (previous_screen_size != current_screen_size && + current_screen_size != irr::core::dimension2d(0,0) && + g_settings->getBool("autosave_screensize")) { + g_settings->setU16("screenW", current_screen_size.Width); + g_settings->setU16("screenH", current_screen_size.Height); + previous_screen_size = current_screen_size; + } + /* Must be called immediately after a device->run() call because it * uses device->getTimer()->getTime() */ diff --git a/src/guiEngine.cpp b/src/guiEngine.cpp index ebc4aac44..2d1bd6d44 100644 --- a/src/guiEngine.cpp +++ b/src/guiEngine.cpp @@ -262,8 +262,24 @@ void GUIEngine::run() unsigned int text_height = g_fontengine->getTextHeight(); - while(m_device->run() && (!m_startgame) && (!m_kill)) - { + irr::core::dimension2d previous_screen_size(g_settings->getU16("screenW"), + g_settings->getU16("screenH")); + + while (m_device->run() && (!m_startgame) && (!m_kill)) { + + const irr::core::dimension2d ¤t_screen_size = + m_device->getVideoDriver()->getScreenSize(); + // Verify if window size has changed and save it if it's the case + // Ensure evaluating settings->getBool after verifying screensize + // First condition is cheaper + if (previous_screen_size != current_screen_size && + current_screen_size != irr::core::dimension2d(0,0) && + g_settings->getBool("autosave_screensize")) { + g_settings->setU16("screenW", current_screen_size.Width); + g_settings->setU16("screenH", current_screen_size.Height); + previous_screen_size = current_screen_size; + } + //check if we need to update the "upper left corner"-text if (text_height != g_fontengine->getTextHeight()) { updateTopLeftTextSize(); -- cgit v1.2.3 From 43d1f375d18a2fbc547a9b4f23d1354d645856ca Mon Sep 17 00:00:00 2001 From: ShadowNinja Date: Fri, 12 Dec 2014 14:49:19 -0500 Subject: Use a settings object for the main settings This unifies the settings APIs. This also unifies the sync and async registration APIs, since the async registration API did not support adding non-functions to the API table. --- builtin/common/misc_helpers.lua | 6 +- builtin/fstk/tabview.lua | 2 +- builtin/game/auth.lua | 6 +- builtin/game/chatcommands.lua | 20 ++--- builtin/game/deprecated.lua | 21 +++++ builtin/game/forceloading.lua | 2 +- builtin/game/init.lua | 2 +- builtin/game/item.lua | 2 +- builtin/game/item_entity.lua | 2 +- builtin/game/misc.lua | 2 +- builtin/game/statbars.lua | 2 +- builtin/game/static_spawn.lua | 4 +- builtin/init.lua | 2 +- builtin/mainmenu/common.lua | 14 ++-- builtin/mainmenu/dlg_config_world.lua | 4 +- builtin/mainmenu/dlg_create_world.lua | 14 ++-- builtin/mainmenu/dlg_settings_advanced.lua | 32 ++++---- builtin/mainmenu/init.lua | 8 +- builtin/mainmenu/store.lua | 6 +- builtin/mainmenu/tab_multiplayer.lua | 32 ++++---- builtin/mainmenu/tab_server.lua | 34 ++++---- builtin/mainmenu/tab_settings.lua | 120 ++++++++++++++--------------- builtin/mainmenu/tab_simple_main.lua | 30 ++++---- builtin/mainmenu/tab_singleplayer.lua | 18 ++--- builtin/mainmenu/tab_texturepacks.lua | 8 +- builtin/mainmenu/textures.lua | 6 +- builtin/profiler/init.lua | 12 ++- builtin/profiler/instrumentation.lua | 18 ++--- builtin/profiler/reporter.lua | 6 +- builtin/profiler/sampling.lua | 2 +- doc/lua_api.txt | 25 +++--- src/script/cpp_api/s_async.cpp | 17 ++-- src/script/cpp_api/s_async.h | 10 +-- src/script/lua_api/l_base.cpp | 14 ++-- src/script/lua_api/l_base.h | 5 +- src/script/lua_api/l_internal.h | 3 +- src/script/lua_api/l_mainmenu.cpp | 36 +++++---- src/script/lua_api/l_mainmenu.h | 3 +- src/script/lua_api/l_settings.cpp | 83 ++++++++++++++++---- src/script/lua_api/l_settings.h | 13 +++- src/script/lua_api/l_util.cpp | 110 +++++--------------------- src/script/lua_api/l_util.h | 18 +---- src/script/scripting_client.cpp | 10 +-- src/script/scripting_mainmenu.cpp | 17 ++-- src/script/scripting_mainmenu.h | 1 + src/script/scripting_server.cpp | 26 +++---- 46 files changed, 411 insertions(+), 417 deletions(-) (limited to 'builtin/mainmenu') diff --git a/builtin/common/misc_helpers.lua b/builtin/common/misc_helpers.lua index fc284c843..1ca400688 100644 --- a/builtin/common/misc_helpers.lua +++ b/builtin/common/misc_helpers.lua @@ -463,7 +463,7 @@ if INIT == "game" then core.rotate_node = function(itemstack, placer, pointed_thing) core.rotate_and_place(itemstack, placer, pointed_thing, - core.setting_getbool("creative_mode"), + core.settings:get_bool("creative_mode"), {invert_wall = placer:get_player_control().sneak}) return itemstack end @@ -642,8 +642,8 @@ end local ESCAPE_CHAR = string.char(0x1b) --- Client-sided mods don't have access to getbool -if core.setting_getbool and core.setting_getbool("disable_escape_sequences") then +-- Client-side mods don't have access to settings +if core.settings and core.settings:get_bool("disable_escape_sequences") then function core.get_color_escape_sequence(color) return "" diff --git a/builtin/fstk/tabview.lua b/builtin/fstk/tabview.lua index 72551afd7..3715e231b 100644 --- a/builtin/fstk/tabview.lua +++ b/builtin/fstk/tabview.lua @@ -167,7 +167,7 @@ local function switch_to_tab(self, index) self.current_tab = self.tablist[index].name if (self.autosave_tab) then - core.setting_set(self.name .. "_LAST",self.current_tab) + core.settings:set(self.name .. "_LAST",self.current_tab) end -- call for tab to enter diff --git a/builtin/game/auth.lua b/builtin/game/auth.lua index 46fe3d342..8cb4ebf57 100644 --- a/builtin/game/auth.lua +++ b/builtin/game/auth.lua @@ -106,7 +106,7 @@ core.builtin_auth_handler = { end end -- For the admin, give everything - elseif name == core.setting_get("name") then + elseif name == core.settings:get("name") then for priv, def in pairs(core.registered_privileges) do privileges[priv] = true end @@ -125,7 +125,7 @@ core.builtin_auth_handler = { core.log('info', "Built-in authentication handler adding player '"..name.."'") core.auth_table[name] = { password = password, - privileges = core.string_to_privs(core.setting_get("default_privs")), + privileges = core.string_to_privs(core.settings:get("default_privs")), last_login = os.time(), } save_auth_file() @@ -148,7 +148,7 @@ core.builtin_auth_handler = { if not core.auth_table[name] then core.builtin_auth_handler.create_auth(name, core.get_password_hash(name, - core.setting_get("default_password"))) + core.settings:get("default_password"))) end core.auth_table[name].privileges = privileges core.notify_authentication_modified(name) diff --git a/builtin/game/chatcommands.lua b/builtin/game/chatcommands.lua index cbf75c1bc..b792a01cd 100644 --- a/builtin/game/chatcommands.lua +++ b/builtin/game/chatcommands.lua @@ -39,7 +39,7 @@ core.register_on_chat_message(function(name, message) return true -- Handled chat message end) -if core.setting_getbool("profiler.load") then +if core.settings:get_bool("profiler.load") then -- Run after register_chatcommand and its register_on_chat_message -- Before any chattcommands that should be profiled profiler.init_chatcommand() @@ -82,7 +82,7 @@ core.register_chatcommand("me", { core.register_chatcommand("admin", { description = "Show the name of the server owner", func = function(name) - local admin = minetest.setting_get("name") + local admin = minetest.settings:get("name") if admin then return true, "The administrator of this server is "..admin.."." else @@ -119,7 +119,7 @@ local function handle_grant_command(caller, grantname, grantprivstr) local privs = core.get_player_privs(grantname) local privs_unknown = "" local basic_privs = - core.string_to_privs(core.setting_get("basic_privs") or "interact,shout") + core.string_to_privs(core.settings:get("basic_privs") or "interact,shout") for priv, _ in pairs(grantprivs) do if not basic_privs[priv] and not caller_privs.privs then return false, "Your privileges are insufficient." @@ -185,7 +185,7 @@ core.register_chatcommand("revoke", { local revoke_privs = core.string_to_privs(revoke_priv_str) local privs = core.get_player_privs(revoke_name) local basic_privs = - core.string_to_privs(core.setting_get("basic_privs") or "interact,shout") + core.string_to_privs(core.settings:get("basic_privs") or "interact,shout") for priv, _ in pairs(revoke_privs) do if not basic_privs[priv] and not core.check_player_privs(name, {privs=true}) then @@ -419,20 +419,20 @@ core.register_chatcommand("set", { func = function(name, param) local arg, setname, setvalue = string.match(param, "(-[n]) ([^ ]+) (.+)") if arg and arg == "-n" and setname and setvalue then - core.setting_set(setname, setvalue) + core.settings:set(setname, setvalue) return true, setname .. " = " .. setvalue end local setname, setvalue = string.match(param, "([^ ]+) (.+)") if setname and setvalue then - if not core.setting_get(setname) then + if not core.settings:get(setname) then return false, "Failed. Use '/set -n ' to create a new setting." end - core.setting_set(setname, setvalue) + core.settings:set(setname, setvalue) return true, setname .. " = " .. setvalue end local setname = string.match(param, "([^ ]+)") if setname then - local setvalue = core.setting_get(setname) + local setvalue = core.settings:get(setname) if not setvalue then setvalue = "" end @@ -667,7 +667,7 @@ core.register_chatcommand("rollback_check", { .. " seconds = 86400 = 24h, limit = 5", privs = {rollback=true}, func = function(name, param) - if not core.setting_getbool("enable_rollback_recording") then + if not core.settings:get_bool("enable_rollback_recording") then return false, "Rollback functions are disabled." end local range, seconds, limit = @@ -718,7 +718,7 @@ core.register_chatcommand("rollback", { description = "Revert actions of a player. Default for is 60", privs = {rollback=true}, func = function(name, param) - if not core.setting_getbool("enable_rollback_recording") then + if not core.settings:get_bool("enable_rollback_recording") then return false, "Rollback functions are disabled." end local target_name, seconds = string.match(param, ":([^ ]+) *(%d*)") diff --git a/builtin/game/deprecated.lua b/builtin/game/deprecated.lua index cd1cf5e2d..1a9a96f2a 100644 --- a/builtin/game/deprecated.lua +++ b/builtin/game/deprecated.lua @@ -49,3 +49,24 @@ setmetatable(core.env, { function core.rollback_get_last_node_actor(pos, range, seconds) return core.rollback_get_node_actions(pos, range, seconds, 1)[1] end + +-- +-- core.setting_* +-- + +local settings = core.settings + +local function setting_proxy(name) + return function(...) + core.log("deprecated", "WARNING: minetest.setting_* ".. + "functions are deprecated. ".. + "Use methods on the minetest.settings object.") + return settings[name](settings, ...) + end +end + +core.setting_set = setting_proxy("set") +core.setting_get = setting_proxy("get") +core.setting_setbool = setting_proxy("set_bool") +core.setting_getbool = setting_proxy("get_bool") +core.setting_save = setting_proxy("write") diff --git a/builtin/game/forceloading.lua b/builtin/game/forceloading.lua index 8a05de36c..7c5537e85 100644 --- a/builtin/game/forceloading.lua +++ b/builtin/game/forceloading.lua @@ -40,7 +40,7 @@ function core.forceload_block(pos, transient) elseif other_table[hash] ~= nil then relevant_table[hash] = 1 else - if total_forceloaded >= (tonumber(core.setting_get("max_forceloaded_blocks")) or 16) then + if total_forceloaded >= (tonumber(core.settings:get("max_forceloaded_blocks")) or 16) then return false end total_forceloaded = total_forceloaded+1 diff --git a/builtin/game/init.lua b/builtin/game/init.lua index 3e192a30a..e2635f07a 100644 --- a/builtin/game/init.lua +++ b/builtin/game/init.lua @@ -13,7 +13,7 @@ dofile(gamepath.."constants.lua") assert(loadfile(gamepath.."item.lua"))(builtin_shared) dofile(gamepath.."register.lua") -if core.setting_getbool("profiler.load") then +if core.settings:get_bool("profiler.load") then profiler = dofile(scriptpath.."profiler"..DIR_DELIM.."init.lua") end diff --git a/builtin/game/item.lua b/builtin/game/item.lua index 671a994c7..e36745f93 100644 --- a/builtin/game/item.lua +++ b/builtin/game/item.lua @@ -483,7 +483,7 @@ function core.node_dig(pos, node, digger) wielded = wdef.after_use(wielded, digger, node, dp) or wielded else -- Wear out tool - if not core.setting_getbool("creative_mode") then + if not core.settings:get_bool("creative_mode") then wielded:add_wear(dp.wear) if wielded:get_count() == 0 and wdef.sound and wdef.sound.breaks then core.sound_play(wdef.sound.breaks, {pos = pos, gain = 0.5}) diff --git a/builtin/game/item_entity.lua b/builtin/game/item_entity.lua index 7b8247116..c0e36be2d 100644 --- a/builtin/game/item_entity.lua +++ b/builtin/game/item_entity.lua @@ -14,7 +14,7 @@ end -- If item_entity_ttl is not set, enity will have default life time -- Setting it to -1 disables the feature -local time_to_live = tonumber(core.setting_get("item_entity_ttl")) +local time_to_live = tonumber(core.settings:get("item_entity_ttl")) if not time_to_live then time_to_live = 900 end diff --git a/builtin/game/misc.lua b/builtin/game/misc.lua index a3eb26ac2..bfe407b9d 100644 --- a/builtin/game/misc.lua +++ b/builtin/game/misc.lua @@ -121,7 +121,7 @@ function core.get_node_group(name, group) end function core.setting_get_pos(name) - local value = core.setting_get(name) + local value = core.settings:get(name) if not value then return nil end diff --git a/builtin/game/statbars.lua b/builtin/game/statbars.lua index 4e7781e53..6aa106140 100644 --- a/builtin/game/statbars.lua +++ b/builtin/game/statbars.lua @@ -1,5 +1,5 @@ -- cache setting -local enable_damage = core.setting_getbool("enable_damage") == true +local enable_damage = core.settings:get_bool("enable_damage") local health_bar_definition = { diff --git a/builtin/game/static_spawn.lua b/builtin/game/static_spawn.lua index 100334226..b1157b42e 100644 --- a/builtin/game/static_spawn.lua +++ b/builtin/game/static_spawn.lua @@ -1,10 +1,10 @@ -- Minetest: builtin/static_spawn.lua local function warn_invalid_static_spawnpoint() - if core.setting_get("static_spawnpoint") and + if core.settings:get("static_spawnpoint") and not core.setting_get_pos("static_spawnpoint") then core.log("error", "The static_spawnpoint setting is invalid: \"".. - core.setting_get("static_spawnpoint").."\"") + core.settings:get("static_spawnpoint").."\"") end end diff --git a/builtin/init.lua b/builtin/init.lua index c9fa70fc7..356e119fb 100644 --- a/builtin/init.lua +++ b/builtin/init.lua @@ -38,7 +38,7 @@ dofile(commonpath .. "misc_helpers.lua") if INIT == "game" then dofile(gamepath .. "init.lua") elseif INIT == "mainmenu" then - local mm_script = core.setting_get("main_menu_script") + local mm_script = core.settings:get("main_menu_script") if mm_script and mm_script ~= "" then dofile(mm_script) else diff --git a/builtin/mainmenu/common.lua b/builtin/mainmenu/common.lua index 57950c62c..294e1a621 100644 --- a/builtin/mainmenu/common.lua +++ b/builtin/mainmenu/common.lua @@ -43,10 +43,10 @@ end local function configure_selected_world_params(idx) local worldconfig = modmgr.get_worldconfig(menudata.worldlist:get_list()[idx].path) if worldconfig.creative_mode then - core.setting_set("creative_mode", worldconfig.creative_mode) + core.settings:set("creative_mode", worldconfig.creative_mode) end if worldconfig.enable_damage then - core.setting_set("enable_damage", worldconfig.enable_damage) + core.settings:set("enable_damage", worldconfig.enable_damage) end end @@ -164,8 +164,8 @@ end -------------------------------------------------------------------------------- os.tempfolder = function() - if core.setting_get("TMPFolder") then - return core.setting_get("TMPFolder") .. DIR_DELIM .. "MT_" .. math.random(0,10000) + if core.settings:get("TMPFolder") then + return core.settings:get("TMPFolder") .. DIR_DELIM .. "MT_" .. math.random(0,10000) end local filetocheck = os.tmpname() @@ -206,7 +206,7 @@ function menu_handle_key_up_down(fields, textlist, settingname) oldidx < menudata.worldlist:size() then newidx = oldidx + 1 end - core.setting_set(settingname, menudata.worldlist:get_raw_index(newidx)) + core.settings:set(settingname, menudata.worldlist:get_raw_index(newidx)) configure_selected_world_params(newidx) return true end @@ -328,9 +328,9 @@ function menu_worldmt_legacy(selected) for _, mode_name in pairs(modes_names) do local mode_val = menu_worldmt(selected, mode_name) if mode_val then - core.setting_set(mode_name, mode_val) + core.settings:set(mode_name, mode_val) else - menu_worldmt(selected, mode_name, core.setting_get(mode_name)) + menu_worldmt(selected, mode_name, core.settings:get(mode_name)) end end end diff --git a/builtin/mainmenu/dlg_config_world.lua b/builtin/mainmenu/dlg_config_world.lua index 619c927c5..3e5ba16eb 100644 --- a/builtin/mainmenu/dlg_config_world.lua +++ b/builtin/mainmenu/dlg_config_world.lua @@ -123,7 +123,7 @@ local function handle_buttons(this, fields) if fields["world_config_modlist"] ~= nil then local event = core.explode_table_event(fields["world_config_modlist"]) this.data.selected_mod = event.row - core.setting_set("world_config_selected_mod", event.row) + core.settings:set("world_config_selected_mod", event.row) if event.type == "DCL" then enable_mod(this) @@ -227,7 +227,7 @@ function create_configure_world_dlg(worldidx) handle_buttons, nil) - dlg.data.selected_mod = tonumber(core.setting_get("world_config_selected_mod")) + dlg.data.selected_mod = tonumber(core.settings:get("world_config_selected_mod")) if dlg.data.selected_mod == nil then dlg.data.selected_mod = 0 end diff --git a/builtin/mainmenu/dlg_create_world.lua b/builtin/mainmenu/dlg_create_world.lua index 477b8bcb9..e9ca7799f 100644 --- a/builtin/mainmenu/dlg_create_world.lua +++ b/builtin/mainmenu/dlg_create_world.lua @@ -18,8 +18,8 @@ local function create_world_formspec(dialogdata) local mapgens = core.get_mapgen_names() - local current_seed = core.setting_get("fixed_map_seed") or "" - local current_mg = core.setting_get("mg_name") + local current_seed = core.settings:get("fixed_map_seed") or "" + local current_mg = core.settings:get("mg_name") local mglist = "" local selindex = 1 @@ -33,7 +33,7 @@ local function create_world_formspec(dialogdata) end mglist = mglist:sub(1, -2) - local gameid = core.setting_get("menu_last_game") + local gameid = core.settings:get("menu_last_game") local game, gameidx = nil , 0 if gameid ~= nil then @@ -90,10 +90,10 @@ local function create_world_buttonhandler(this, fields) local message = nil - core.setting_set("fixed_map_seed", fields["te_seed"]) + core.settings:set("fixed_map_seed", fields["te_seed"]) if not menudata.worldlist:uid_exists_raw(worldname) then - core.setting_set("mg_name",fields["dd_mapgen"]) + core.settings:set("mg_name",fields["dd_mapgen"]) message = core.create_world(worldname,gameindex) else message = fgettext("A world named \"$1\" already exists", worldname) @@ -102,13 +102,13 @@ local function create_world_buttonhandler(this, fields) if message ~= nil then gamedata.errormessage = message else - core.setting_set("menu_last_game",gamemgr.games[gameindex].id) + core.settings:set("menu_last_game",gamemgr.games[gameindex].id) if this.data.update_worldlist_filter then menudata.worldlist:set_filtercriteria(gamemgr.games[gameindex].id) mm_texture.update("singleplayer", gamemgr.games[gameindex].id) end menudata.worldlist:refresh() - core.setting_set("mainmenu_last_selected_world", + core.settings:set("mainmenu_last_selected_world", menudata.worldlist:raw_index_by_uid(worldname)) end else diff --git a/builtin/mainmenu/dlg_settings_advanced.lua b/builtin/mainmenu/dlg_settings_advanced.lua index c63eb972e..206ce1620 100644 --- a/builtin/mainmenu/dlg_settings_advanced.lua +++ b/builtin/mainmenu/dlg_settings_advanced.lua @@ -423,7 +423,7 @@ local settings = full_settings local selected_setting = 1 local function get_current_value(setting) - local value = core.setting_get(setting.name) + local value = core.settings:get(setting.name) if value == nil then value = setting.default end @@ -539,11 +539,11 @@ local function handle_change_setting_buttons(this, fields) if setting.type == "bool" then local new_value = fields["dd_setting_value"] -- Note: new_value is the actual (translated) value shown in the dropdown - core.setting_setbool(setting.name, new_value == fgettext("Enabled")) + core.settings:set_bool(setting.name, new_value == fgettext("Enabled")) elseif setting.type == "enum" then local new_value = fields["dd_setting_value"] - core.setting_set(setting.name, new_value) + core.settings:set(setting.name, new_value) elseif setting.type == "int" then local new_value = tonumber(fields["te_setting_value"]) @@ -565,7 +565,7 @@ local function handle_change_setting_buttons(this, fields) core.update_formspec(this:get_formspec()) return true end - core.setting_set(setting.name, new_value) + core.settings:set(setting.name, new_value) elseif setting.type == "float" then local new_value = tonumber(fields["te_setting_value"]) @@ -575,7 +575,7 @@ local function handle_change_setting_buttons(this, fields) core.update_formspec(this:get_formspec()) return true end - core.setting_set(setting.name, new_value) + core.settings:set(setting.name, new_value) elseif setting.type == "flags" then local new_value = fields["te_setting_value"] @@ -589,13 +589,13 @@ local function handle_change_setting_buttons(this, fields) return true end end - core.setting_set(setting.name, new_value) + core.settings:set(setting.name, new_value) else local new_value = fields["te_setting_value"] - core.setting_set(setting.name, new_value) + core.settings:set(setting.name, new_value) end - core.setting_save() + core.settings:write() this:delete() return true end @@ -629,7 +629,7 @@ local function create_settings_formspec(tabview, name, tabdata) local current_level = 0 for _, entry in ipairs(settings) do local name - if not core.setting_getbool("main_menu_technical_settings") and entry.readable_name then + if not core.settings:get_bool("main_menu_technical_settings") and entry.readable_name then name = fgettext_ne(entry.readable_name) else name = entry.name @@ -666,7 +666,7 @@ local function create_settings_formspec(tabview, name, tabdata) "button[10,6;2,1;btn_edit;" .. fgettext("Edit") .. "]" .. "button[7,6;3,1;btn_restore;" .. fgettext("Restore Default") .. "]" .. "checkbox[0,5.3;cb_tech_settings;" .. fgettext("Show technical names") .. ";" - .. dump(core.setting_getbool("main_menu_technical_settings")) .. "]" + .. dump(core.settings:get_bool("main_menu_technical_settings")) .. "]" return formspec end @@ -680,8 +680,8 @@ local function handle_settings_buttons(this, fields, tabname, tabdata) local setting = settings[selected_setting] if setting and setting.type == "bool" then local current_value = get_current_value(setting) - core.setting_setbool(setting.name, not core.is_yes(current_value)) - core.setting_save() + core.settings:set_bool(setting.name, not core.is_yes(current_value)) + core.settings:write() return true else list_enter = true @@ -736,8 +736,8 @@ local function handle_settings_buttons(this, fields, tabname, tabdata) if fields["btn_restore"] then local setting = settings[selected_setting] if setting and setting.type ~= "category" then - core.setting_set(setting.name, setting.default) - core.setting_save() + core.settings:set(setting.name, setting.default) + core.settings:write() core.update_formspec(this:get_formspec()) end return true @@ -749,8 +749,8 @@ local function handle_settings_buttons(this, fields, tabname, tabdata) end if fields["cb_tech_settings"] then - core.setting_set("main_menu_technical_settings", fields["cb_tech_settings"]) - core.setting_save() + core.settings:set("main_menu_technical_settings", fields["cb_tech_settings"]) + core.settings:write() core.update_formspec(this:get_formspec()) return true end diff --git a/builtin/mainmenu/init.lua b/builtin/mainmenu/init.lua index 79e6d5c02..492bb22d6 100644 --- a/builtin/mainmenu/init.lua +++ b/builtin/mainmenu/init.lua @@ -119,9 +119,9 @@ local function init_globals() menudata.worldlist:add_sort_mechanism("alphabetic", sort_worlds_alphabetic) menudata.worldlist:set_sortmode("alphabetic") - if not core.setting_get("menu_last_game") then - local default_game = core.setting_get("default_game") or "minetest" - core.setting_set("menu_last_game", default_game) + 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() @@ -149,7 +149,7 @@ local function init_globals() tv_main:set_fixed_size(false) if PLATFORM ~= "Android" then - tv_main:set_tab(core.setting_get("maintab_LAST")) + tv_main:set_tab(core.settings:get("maintab_LAST")) end ui.set_default("maintab") tv_main:show() diff --git a/builtin/mainmenu/store.lua b/builtin/mainmenu/store.lua index ad861082d..59391f8bc 100644 --- a/builtin/mainmenu/store.lua +++ b/builtin/mainmenu/store.lua @@ -233,14 +233,14 @@ function modstore.handle_buttons(parent, fields, name, data) if not core.handle_async( function(param) - local fullurl = core.setting_get("modstore_download_url") .. + local fullurl = core.settings:get("modstore_download_url") .. param.moddetails.download_url if param.version ~= nil then local found = false for i=1,#param.moddetails.versions, 1 do if param.moddetails.versions[i].date:sub(1,10) == param.version then - fullurl = core.setting_get("modstore_download_url") .. + fullurl = core.settings:get("modstore_download_url") .. param.moddetails.versions[i].download_url found = true end @@ -400,7 +400,7 @@ function modstore.getscreenshot(ypos,listentry) listentry.texturename = "in progress" --prepare url and filename - local fullurl = core.setting_get("modstore_download_url") .. + local fullurl = core.settings:get("modstore_download_url") .. listentry.details.screenshot_url local filename = os.tempfolder() .. "_MID_" .. listentry.id diff --git a/builtin/mainmenu/tab_multiplayer.lua b/builtin/mainmenu/tab_multiplayer.lua index 0f4921b03..a9b2b35fe 100644 --- a/builtin/mainmenu/tab_multiplayer.lua +++ b/builtin/mainmenu/tab_multiplayer.lua @@ -39,14 +39,14 @@ local function get_formspec(tabview, name, tabdata) -- Address / Port "label[7.75,-0.25;" .. fgettext("Address / Port") .. "]" .. "field[8,0.65;3.25,0.5;te_address;;" .. - core.formspec_escape(core.setting_get("address")) .. "]" .. + core.formspec_escape(core.settings:get("address")) .. "]" .. "field[11.1,0.65;1.4,0.5;te_port;;" .. - core.formspec_escape(core.setting_get("remote_port")) .. "]" .. + core.formspec_escape(core.settings:get("remote_port")) .. "]" .. -- Name / Password "label[7.75,0.95;" .. fgettext("Name / Password") .. "]" .. "field[8,1.85;2.9,0.5;te_name;;" .. - core.formspec_escape(core.setting_get("name")) .. "]" .. + core.formspec_escape(core.settings:get("name")) .. "]" .. "pwdfield[10.73,1.85;1.77,0.5;te_pwd;]" .. -- Description Background @@ -135,7 +135,7 @@ local function main_button_handler(tabview, fields, name, tabdata) if fields.te_name then gamedata.playername = fields.te_name - core.setting_set("name", fields.te_name) + core.settings:set("name", fields.te_name) end if fields.favourites then @@ -163,8 +163,8 @@ local function main_button_handler(tabview, fields, name, tabdata) gamedata.serverdescription = fav.description if gamedata.address and gamedata.port then - core.setting_set("address", gamedata.address) - core.setting_set("remote_port", gamedata.port) + core.settings:set("address", gamedata.address) + core.settings:set("remote_port", gamedata.port) core.start() end end @@ -187,8 +187,8 @@ local function main_button_handler(tabview, fields, name, tabdata) end if address and port then - core.setting_set("address", address) - core.setting_set("remote_port", port) + core.settings:set("address", address) + core.settings:set("remote_port", port) end tabdata.fav_selected = event.row end @@ -219,8 +219,8 @@ local function main_button_handler(tabview, fields, name, tabdata) local port = fav.port gamedata.serverdescription = fav.description if address and port then - core.setting_set("address", address) - core.setting_set("remote_port", port) + core.settings:set("address", address) + core.settings:set("remote_port", port) end tabdata.fav_selected = fav_idx @@ -235,8 +235,8 @@ local function main_button_handler(tabview, fields, name, tabdata) asyncOnlineFavourites() tabdata.fav_selected = nil - core.setting_set("address", "") - core.setting_set("remote_port", "30000") + core.settings:set("address", "") + core.settings:set("remote_port", "30000") return true end @@ -293,8 +293,8 @@ local function main_button_handler(tabview, fields, name, tabdata) end) menudata.search_result = search_result local first_server = search_result[1] - core.setting_set("address", first_server.address) - core.setting_set("remote_port", first_server.port) + core.settings:set("address", first_server.address) + core.settings:set("remote_port", first_server.port) end return true end @@ -325,8 +325,8 @@ local function main_button_handler(tabview, fields, name, tabdata) gamedata.serverdescription = "" end - core.setting_set("address", fields.te_address) - core.setting_set("remote_port", fields.te_port) + core.settings:set("address", fields.te_address) + core.settings:set("remote_port", fields.te_port) core.start() return true diff --git a/builtin/mainmenu/tab_server.lua b/builtin/mainmenu/tab_server.lua index be57ad7ef..8f25ce871 100644 --- a/builtin/mainmenu/tab_server.lua +++ b/builtin/mainmenu/tab_server.lua @@ -19,7 +19,7 @@ local function get_formspec(tabview, name, tabdata) local index = menudata.worldlist:get_current_index( - tonumber(core.setting_get("mainmenu_last_selected_world")) + tonumber(core.settings:get("mainmenu_last_selected_world")) ) local retval = @@ -29,29 +29,29 @@ local function get_formspec(tabview, name, tabdata) "button[8.5,5;3.25,0.5;start_server;" .. fgettext("Start Game") .. "]" .. "label[4,-0.25;" .. fgettext("Select World:") .. "]" .. "checkbox[0.25,0.25;cb_creative_mode;" .. fgettext("Creative Mode") .. ";" .. - dump(core.setting_getbool("creative_mode")) .. "]" .. + dump(core.settings:get_bool("creative_mode")) .. "]" .. "checkbox[0.25,0.7;cb_enable_damage;" .. fgettext("Enable Damage") .. ";" .. - dump(core.setting_getbool("enable_damage")) .. "]" .. + dump(core.settings:get_bool("enable_damage")) .. "]" .. "checkbox[0.25,1.15;cb_server_announce;" .. fgettext("Public") .. ";" .. - dump(core.setting_getbool("server_announce")) .. "]" .. + dump(core.settings:get_bool("server_announce")) .. "]" .. "label[0.25,2.2;" .. fgettext("Name/Password") .. "]" .. "field[0.55,3.2;3.5,0.5;te_playername;;" .. - core.formspec_escape(core.setting_get("name")) .. "]" .. + core.formspec_escape(core.settings:get("name")) .. "]" .. "pwdfield[0.55,4;3.5,0.5;te_passwd;]" - local bind_addr = core.setting_get("bind_address") + local bind_addr = core.settings:get("bind_address") if bind_addr ~= nil and bind_addr ~= "" then retval = retval .. "field[0.55,5.2;2.25,0.5;te_serveraddr;" .. fgettext("Bind Address") .. ";" .. - core.formspec_escape(core.setting_get("bind_address")) .. "]" .. + core.formspec_escape(core.settings:get("bind_address")) .. "]" .. "field[2.8,5.2;1.25,0.5;te_serverport;" .. fgettext("Port") .. ";" .. - core.formspec_escape(core.setting_get("port")) .. "]" + core.formspec_escape(core.settings:get("port")) .. "]" else retval = retval .. "field[0.55,5.2;3.5,0.5;te_serverport;" .. fgettext("Server Port") .. ";" .. - core.formspec_escape(core.setting_get("port")) .. "]" + core.formspec_escape(core.settings:get("port")) .. "]" end - + retval = retval .. "textlist[4,0.25;7.5,3.7;srv_worlds;" .. menu_render_worldlist() .. @@ -75,7 +75,7 @@ local function main_button_handler(this, fields, name, tabdata) world_doubleclick = true end if event.type == "CHG" then - core.setting_set("mainmenu_last_selected_world", + core.settings:set("mainmenu_last_selected_world", menudata.worldlist:get_raw_index(core.get_textlist_index("srv_worlds"))) return true end @@ -86,7 +86,7 @@ local function main_button_handler(this, fields, name, tabdata) end if fields["cb_creative_mode"] then - core.setting_set("creative_mode", fields["cb_creative_mode"]) + core.settings:set("creative_mode", fields["cb_creative_mode"]) local selected = core.get_textlist_index("srv_worlds") menu_worldmt(selected, "creative_mode", fields["cb_creative_mode"]) @@ -94,7 +94,7 @@ local function main_button_handler(this, fields, name, tabdata) end if fields["cb_enable_damage"] then - core.setting_set("enable_damage", fields["cb_enable_damage"]) + core.settings:set("enable_damage", fields["cb_enable_damage"]) local selected = core.get_textlist_index("srv_worlds") menu_worldmt(selected, "enable_damage", fields["cb_enable_damage"]) @@ -102,7 +102,7 @@ local function main_button_handler(this, fields, name, tabdata) end if fields["cb_server_announce"] then - core.setting_set("server_announce", fields["cb_server_announce"]) + core.settings:set("server_announce", fields["cb_server_announce"]) local selected = core.get_textlist_index("srv_worlds") menu_worldmt(selected, "server_announce", fields["cb_server_announce"]) @@ -120,16 +120,16 @@ local function main_button_handler(this, fields, name, tabdata) gamedata.port = fields["te_serverport"] gamedata.address = "" - core.setting_set("port",gamedata.port) + core.settings:set("port",gamedata.port) if fields["te_serveraddr"] ~= nil then - core.setting_set("bind_address",fields["te_serveraddr"]) + 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 = gamemgr.find_by_gameid(world.gameid) - core.setting_set("menu_last_game", game.id) + core.settings:set("menu_last_game", game.id) end core.start() diff --git a/builtin/mainmenu/tab_settings.lua b/builtin/mainmenu/tab_settings.lua index 8a97d8334..69683eaa3 100644 --- a/builtin/mainmenu/tab_settings.lua +++ b/builtin/mainmenu/tab_settings.lua @@ -70,39 +70,39 @@ local dd_options = { local getSettingIndex = { Leaves = function() - local style = core.setting_get("leaves_style") + local style = core.settings:get("leaves_style") for idx, name in pairs(dd_options.leaves[2]) do if style == name then return idx end end return 1 end, NodeHighlighting = function() - local style = core.setting_get("node_highlighting") + local style = core.settings:get("node_highlighting") for idx, name in pairs(dd_options.node_highlighting[2]) do if style == name then return idx end end return 1 end, Filter = function() - if core.setting_get(dd_options.filters[2][3]) == "true" then + if core.settings:get(dd_options.filters[2][3]) == "true" then return 3 - elseif core.setting_get(dd_options.filters[2][3]) == "false" and - core.setting_get(dd_options.filters[2][2]) == "true" then + elseif core.settings:get(dd_options.filters[2][3]) == "false" and + core.settings:get(dd_options.filters[2][2]) == "true" then return 2 end return 1 end, Mipmap = function() - if core.setting_get(dd_options.mipmap[2][3]) == "true" then + if core.settings:get(dd_options.mipmap[2][3]) == "true" then return 3 - elseif core.setting_get(dd_options.mipmap[2][3]) == "false" and - core.setting_get(dd_options.mipmap[2][2]) == "true" then + elseif core.settings:get(dd_options.mipmap[2][3]) == "false" and + core.settings:get(dd_options.mipmap[2][2]) == "true" then return 2 end return 1 end, Antialiasing = function() - local antialiasing_setting = core.setting_get("fsaa") + local antialiasing_setting = core.settings:get("fsaa") for i = 1, #dd_options.antialiasing[2] do if antialiasing_setting == dd_options.antialiasing[2][i] then return i @@ -177,15 +177,15 @@ local function formspec(tabview, name, tabdata) local tab_string = "box[0,0;3.5,4.5;#999999]" .. "checkbox[0.25,0;cb_smooth_lighting;" .. fgettext("Smooth Lighting") .. ";" - .. dump(core.setting_getbool("smooth_lighting")) .. "]" .. + .. dump(core.settings:get_bool("smooth_lighting")) .. "]" .. "checkbox[0.25,0.5;cb_particles;" .. fgettext("Particles") .. ";" - .. dump(core.setting_getbool("enable_particles")) .. "]" .. + .. dump(core.settings:get_bool("enable_particles")) .. "]" .. "checkbox[0.25,1;cb_3d_clouds;" .. fgettext("3D Clouds") .. ";" - .. dump(core.setting_getbool("enable_3d_clouds")) .. "]" .. + .. dump(core.settings:get_bool("enable_3d_clouds")) .. "]" .. "checkbox[0.25,1.5;cb_opaque_water;" .. fgettext("Opaque Water") .. ";" - .. dump(core.setting_getbool("opaque_water")) .. "]" .. + .. dump(core.settings:get_bool("opaque_water")) .. "]" .. "checkbox[0.25,2.0;cb_connected_glass;" .. fgettext("Connected Glass") .. ";" - .. dump(core.setting_getbool("connected_glass")) .. "]" .. + .. dump(core.settings:get_bool("connected_glass")) .. "]" .. "dropdown[0.25,2.8;3.3;dd_node_highlighting;" .. dd_options.node_highlighting[1] .. ";" .. getSettingIndex.NodeHighlighting() .. "]" .. "dropdown[0.25,3.6;3.3;dd_leaves_style;" .. dd_options.leaves[1] .. ";" @@ -201,10 +201,10 @@ local function formspec(tabview, name, tabdata) .. getSettingIndex.Antialiasing() .. "]" .. "label[3.85,3.45;" .. fgettext("Screen:") .. "]" .. "checkbox[3.85,3.6;cb_autosave_screensize;" .. fgettext("Autosave screen size") .. ";" - .. dump(core.setting_getbool("autosave_screensize")) .. "]" .. + .. dump(core.settings:get_bool("autosave_screensize")) .. "]" .. "box[7.75,0;4,4.4;#999999]" .. "checkbox[8,0;cb_shaders;" .. fgettext("Shaders") .. ";" - .. dump(core.setting_getbool("enable_shaders")) .. "]" + .. dump(core.settings:get_bool("enable_shaders")) .. "]" if PLATFORM == "Android" then tab_string = tab_string .. @@ -221,29 +221,29 @@ local function formspec(tabview, name, tabdata) .. fgettext("Advanced Settings") .. "]" - if core.setting_get("touchscreen_threshold") ~= nil then + if core.settings:get("touchscreen_threshold") ~= nil then tab_string = tab_string .. "label[4.3,4.1;" .. fgettext("Touchthreshold (px)") .. "]" .. "dropdown[3.85,4.55;3.85;dd_touchthreshold;0,10,20,30,40,50;" .. - ((tonumber(core.setting_get("touchscreen_threshold")) / 10) + 1) .. "]" + ((tonumber(core.settings:get("touchscreen_threshold")) / 10) + 1) .. "]" end - if core.setting_getbool("enable_shaders") then + if core.settings:get_bool("enable_shaders") then tab_string = tab_string .. "checkbox[8,0.5;cb_bumpmapping;" .. fgettext("Bump Mapping") .. ";" - .. dump(core.setting_getbool("enable_bumpmapping")) .. "]" .. + .. dump(core.settings:get_bool("enable_bumpmapping")) .. "]" .. "checkbox[8,1;cb_tonemapping;" .. fgettext("Tone Mapping") .. ";" - .. dump(core.setting_getbool("tone_mapping")) .. "]" .. + .. dump(core.settings:get_bool("tone_mapping")) .. "]" .. "checkbox[8,1.5;cb_generate_normalmaps;" .. fgettext("Normal Mapping") .. ";" - .. dump(core.setting_getbool("generate_normalmaps")) .. "]" .. + .. dump(core.settings:get_bool("generate_normalmaps")) .. "]" .. "checkbox[8,2;cb_parallax;" .. fgettext("Parallax Occlusion") .. ";" - .. dump(core.setting_getbool("enable_parallax_occlusion")) .. "]" .. + .. dump(core.settings:get_bool("enable_parallax_occlusion")) .. "]" .. "checkbox[8,2.5;cb_waving_water;" .. fgettext("Waving Water") .. ";" - .. dump(core.setting_getbool("enable_waving_water")) .. "]" .. + .. dump(core.settings:get_bool("enable_waving_water")) .. "]" .. "checkbox[8,3;cb_waving_leaves;" .. fgettext("Waving Leaves") .. ";" - .. dump(core.setting_getbool("enable_waving_leaves")) .. "]" .. + .. dump(core.settings:get_bool("enable_waving_leaves")) .. "]" .. "checkbox[8,3.5;cb_waving_plants;" .. fgettext("Waving Plants") .. ";" - .. dump(core.setting_getbool("enable_waving_plants")) .. "]" + .. dump(core.settings:get_bool("enable_waving_plants")) .. "]" else tab_string = tab_string .. "tablecolumns[color;text]" .. @@ -274,64 +274,64 @@ local function handle_settings_buttons(this, fields, tabname, tabdata) return true end if fields["cb_smooth_lighting"] then - core.setting_set("smooth_lighting", fields["cb_smooth_lighting"]) + core.settings:set("smooth_lighting", fields["cb_smooth_lighting"]) return true end if fields["cb_particles"] then - core.setting_set("enable_particles", fields["cb_particles"]) + core.settings:set("enable_particles", fields["cb_particles"]) return true end if fields["cb_3d_clouds"] then - core.setting_set("enable_3d_clouds", fields["cb_3d_clouds"]) + core.settings:set("enable_3d_clouds", fields["cb_3d_clouds"]) return true end if fields["cb_opaque_water"] then - core.setting_set("opaque_water", fields["cb_opaque_water"]) + core.settings:set("opaque_water", fields["cb_opaque_water"]) return true end if fields["cb_connected_glass"] then - core.setting_set("connected_glass", fields["cb_connected_glass"]) + core.settings:set("connected_glass", fields["cb_connected_glass"]) return true end if fields["cb_autosave_screensize"] then - core.setting_set("autosave_screensize", fields["cb_autosave_screensize"]) + core.settings:set("autosave_screensize", fields["cb_autosave_screensize"]) return true end if fields["cb_shaders"] then - if (core.setting_get("video_driver") == "direct3d8" or - core.setting_get("video_driver") == "direct3d9") then - core.setting_set("enable_shaders", "false") + if (core.settings:get("video_driver") == "direct3d8" or + core.settings:get("video_driver") == "direct3d9") then + core.settings:set("enable_shaders", "false") gamedata.errormessage = fgettext("To enable shaders the OpenGL driver needs to be used.") else - core.setting_set("enable_shaders", fields["cb_shaders"]) + core.settings:set("enable_shaders", fields["cb_shaders"]) end return true end if fields["cb_bumpmapping"] then - core.setting_set("enable_bumpmapping", fields["cb_bumpmapping"]) + core.settings:set("enable_bumpmapping", fields["cb_bumpmapping"]) return true end if fields["cb_tonemapping"] then - core.setting_set("tone_mapping", fields["cb_tonemapping"]) + core.settings:set("tone_mapping", fields["cb_tonemapping"]) return true end if fields["cb_generate_normalmaps"] then - core.setting_set("generate_normalmaps", fields["cb_generate_normalmaps"]) + core.settings:set("generate_normalmaps", fields["cb_generate_normalmaps"]) return true end if fields["cb_parallax"] then - core.setting_set("enable_parallax_occlusion", fields["cb_parallax"]) + core.settings:set("enable_parallax_occlusion", fields["cb_parallax"]) return true end if fields["cb_waving_water"] then - core.setting_set("enable_waving_water", fields["cb_waving_water"]) + core.settings:set("enable_waving_water", fields["cb_waving_water"]) return true end if fields["cb_waving_leaves"] then - core.setting_set("enable_waving_leaves", fields["cb_waving_leaves"]) + core.settings:set("enable_waving_leaves", fields["cb_waving_leaves"]) end if fields["cb_waving_plants"] then - core.setting_set("enable_waving_plants", fields["cb_waving_plants"]) + core.settings:set("enable_waving_plants", fields["cb_waving_plants"]) return true end if fields["btn_change_keys"] then @@ -339,7 +339,7 @@ local function handle_settings_buttons(this, fields, tabname, tabdata) return true end if fields["cb_touchscreen_target"] then - core.setting_set("touchtarget", fields["cb_touchscreen_target"]) + core.settings:set("touchtarget", fields["cb_touchscreen_target"]) return true end if fields["btn_reset_singleplayer"] then @@ -352,49 +352,49 @@ local function handle_settings_buttons(this, fields, tabname, tabdata) for i = 1, #labels.leaves do if fields["dd_leaves_style"] == labels.leaves[i] then - core.setting_set("leaves_style", dd_options.leaves[2][i]) + core.settings:set("leaves_style", dd_options.leaves[2][i]) ddhandled = true end end for i = 1, #labels.node_highlighting do if fields["dd_node_highlighting"] == labels.node_highlighting[i] then - core.setting_set("node_highlighting", dd_options.node_highlighting[2][i]) + core.settings:set("node_highlighting", dd_options.node_highlighting[2][i]) ddhandled = true end end if fields["dd_filters"] == labels.filters[1] then - core.setting_set("bilinear_filter", "false") - core.setting_set("trilinear_filter", "false") + core.settings:set("bilinear_filter", "false") + core.settings:set("trilinear_filter", "false") ddhandled = true elseif fields["dd_filters"] == labels.filters[2] then - core.setting_set("bilinear_filter", "true") - core.setting_set("trilinear_filter", "false") + core.settings:set("bilinear_filter", "true") + core.settings:set("trilinear_filter", "false") ddhandled = true elseif fields["dd_filters"] == labels.filters[3] then - core.setting_set("bilinear_filter", "false") - core.setting_set("trilinear_filter", "true") + core.settings:set("bilinear_filter", "false") + core.settings:set("trilinear_filter", "true") ddhandled = true end if fields["dd_mipmap"] == labels.mipmap[1] then - core.setting_set("mip_map", "false") - core.setting_set("anisotropic_filter", "false") + core.settings:set("mip_map", "false") + core.settings:set("anisotropic_filter", "false") ddhandled = true elseif fields["dd_mipmap"] == labels.mipmap[2] then - core.setting_set("mip_map", "true") - core.setting_set("anisotropic_filter", "false") + core.settings:set("mip_map", "true") + core.settings:set("anisotropic_filter", "false") ddhandled = true elseif fields["dd_mipmap"] == labels.mipmap[3] then - core.setting_set("mip_map", "true") - core.setting_set("anisotropic_filter", "true") + core.settings:set("mip_map", "true") + core.settings:set("anisotropic_filter", "true") ddhandled = true end if fields["dd_antialiasing"] then - core.setting_set("fsaa", + core.settings:set("fsaa", antialiasing_fname_to_name(fields["dd_antialiasing"])) ddhandled = true end if fields["dd_touchthreshold"] then - core.setting_set("touchscreen_threshold", fields["dd_touchthreshold"]) + core.settings:set("touchscreen_threshold", fields["dd_touchthreshold"]) ddhandled = true end diff --git a/builtin/mainmenu/tab_simple_main.lua b/builtin/mainmenu/tab_simple_main.lua index 23820aab7..90a743f68 100644 --- a/builtin/mainmenu/tab_simple_main.lua +++ b/builtin/mainmenu/tab_simple_main.lua @@ -25,12 +25,12 @@ local function get_formspec(tabview, name, tabdata) local retval = "label[9.5,0;".. fgettext("Name / Password") .. "]" .. "field[0.25,3.35;5.5,0.5;te_address;;" .. - core.formspec_escape(core.setting_get("address")) .."]" .. + core.formspec_escape(core.settings:get("address")) .."]" .. "field[5.75,3.35;2.25,0.5;te_port;;" .. - core.formspec_escape(core.setting_get("remote_port")) .."]" .. + core.formspec_escape(core.settings:get("remote_port")) .."]" .. "button[10,2.6;2,1.5;btn_mp_connect;".. fgettext("Connect") .. "]" .. "field[9.8,1;2.6,0.5;te_name;;" .. - core.formspec_escape(core.setting_get("name")) .."]" .. + core.formspec_escape(core.settings:get("name")) .."]" .. "pwdfield[9.8,2;2.6,0.5;te_pwd;]" @@ -89,9 +89,9 @@ local function get_formspec(tabview, name, tabdata) -- checkboxes retval = retval .. "checkbox[8.0,3.9;cb_creative;".. fgettext("Creative Mode") .. ";" .. - dump(core.setting_getbool("creative_mode")) .. "]".. + dump(core.settings:get_bool("creative_mode")) .. "]".. "checkbox[8.0,4.4;cb_damage;".. fgettext("Enable Damage") .. ";" .. - dump(core.setting_getbool("enable_damage")) .. "]" + dump(core.settings:get_bool("enable_damage")) .. "]" -- buttons retval = retval .. "button[0,3.7;8,1.5;btn_start_singleplayer;" .. fgettext("Start Singleplayer") .. "]" .. @@ -128,8 +128,8 @@ local function main_button_handler(tabview, fields, name, tabdata) end if address and port then - core.setting_set("address", address) - core.setting_set("remote_port", port) + core.settings:set("address", address) + core.settings:set("remote_port", port) end tabdata.fav_selected = event.row end @@ -145,18 +145,18 @@ local function main_button_handler(tabview, fields, name, tabdata) asyncOnlineFavourites() tabdata.fav_selected = nil - core.setting_set("address", "") - core.setting_set("remote_port", "30000") + core.settings:set("address", "") + core.settings:set("remote_port", "30000") return true end if fields.cb_creative then - core.setting_set("creative_mode", fields.cb_creative) + core.settings:set("creative_mode", fields.cb_creative) return true end if fields.cb_damage then - core.setting_set("enable_damage", fields.cb_damage) + core.settings:set("enable_damage", fields.cb_damage) return true end @@ -186,12 +186,8 @@ local function main_button_handler(tabview, fields, name, tabdata) gamedata.selected_world = 0 - core.setting_set("address", fields.te_address) - core.setting_set("remote_port", fields.te_port) - - core.start() - return true - end + core.settings:set("address", fields.te_address) + core.settings:set("remote_port", fields.te_port) if fields.btn_config_sp_world then local configdialog = create_configure_world_dlg(1) diff --git a/builtin/mainmenu/tab_singleplayer.lua b/builtin/mainmenu/tab_singleplayer.lua index 236de763c..c58ad4164 100644 --- a/builtin/mainmenu/tab_singleplayer.lua +++ b/builtin/mainmenu/tab_singleplayer.lua @@ -16,7 +16,7 @@ --51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. local function current_game() - local last_game_id = core.setting_get("menu_last_game") + local last_game_id = core.settings:get("menu_last_game") local game, index = gamemgr.find_by_gameid(last_game_id) return game @@ -36,10 +36,10 @@ local function singleplayer_refresh_gamebar() if ("game_btnbar_" .. gamemgr.games[j].id == key) then mm_texture.update("singleplayer", gamemgr.games[j]) core.set_topleft_text(gamemgr.games[j].name) - core.setting_set("menu_last_game",gamemgr.games[j].id) + core.settings:set("menu_last_game",gamemgr.games[j].id) menudata.worldlist:set_filtercriteria(gamemgr.games[j].id) local index = filterlist.get_current_index(menudata.worldlist, - tonumber(core.setting_get("mainmenu_last_selected_world"))) + 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 @@ -89,7 +89,7 @@ local function get_formspec(tabview, name, tabdata) local retval = "" local index = filterlist.get_current_index(menudata.worldlist, - tonumber(core.setting_get("mainmenu_last_selected_world")) + tonumber(core.settings:get("mainmenu_last_selected_world")) ) retval = retval .. @@ -99,9 +99,9 @@ local function get_formspec(tabview, name, tabdata) "button[8.5,5;3.25,0.5;play;".. fgettext("Play") .. "]" .. "label[4,-0.25;".. fgettext("Select World:") .. "]".. "checkbox[0.25,0.25;cb_creative_mode;".. fgettext("Creative Mode") .. ";" .. - dump(core.setting_getbool("creative_mode")) .. "]".. + dump(core.settings:get_bool("creative_mode")) .. "]".. "checkbox[0.25,0.7;cb_enable_damage;".. fgettext("Enable Damage") .. ";" .. - dump(core.setting_getbool("enable_damage")) .. "]".. + dump(core.settings:get_bool("enable_damage")) .. "]".. "textlist[4,0.25;7.5,3.7;sp_worlds;" .. menu_render_worldlist() .. ";" .. index .. "]" @@ -125,7 +125,7 @@ local function main_button_handler(this, fields, name, tabdata) end if event.type == "CHG" and selected ~= nil then - core.setting_set("mainmenu_last_selected_world", + core.settings:set("mainmenu_last_selected_world", menudata.worldlist:get_raw_index(selected)) return true end @@ -136,7 +136,7 @@ local function main_button_handler(this, fields, name, tabdata) end if fields["cb_creative_mode"] then - core.setting_set("creative_mode", fields["cb_creative_mode"]) + core.settings:set("creative_mode", fields["cb_creative_mode"]) local selected = core.get_textlist_index("sp_worlds") menu_worldmt(selected, "creative_mode", fields["cb_creative_mode"]) @@ -144,7 +144,7 @@ local function main_button_handler(this, fields, name, tabdata) end if fields["cb_enable_damage"] then - core.setting_set("enable_damage", fields["cb_enable_damage"]) + core.settings:set("enable_damage", fields["cb_enable_damage"]) local selected = core.get_textlist_index("sp_worlds") menu_worldmt(selected, "enable_damage", fields["cb_enable_damage"]) diff --git a/builtin/mainmenu/tab_texturepacks.lua b/builtin/mainmenu/tab_texturepacks.lua index 4638beaa1..2957481cf 100644 --- a/builtin/mainmenu/tab_texturepacks.lua +++ b/builtin/mainmenu/tab_texturepacks.lua @@ -54,9 +54,9 @@ local function get_formspec(tabview, name, tabdata) local retval = "label[4,-0.25;" .. fgettext("Select texture pack:") .. "]" .. "textlist[4,0.25;7.5,5.0;TPs;" - local current_texture_path = core.setting_get("texture_path") + local current_texture_path = core.settings:get("texture_path") local list = filter_texture_pack_list(core.get_dir_list(core.get_texturepath(), true)) - local index = tonumber(core.setting_get("mainmenu_last_selected_TP")) + local index = tonumber(core.settings:get("mainmenu_last_selected_TP")) if not index then index = 1 end @@ -106,7 +106,7 @@ local function main_button_handler(tabview, fields, name, tabdata) local event = core.explode_textlist_event(fields["TPs"]) if event.type == "CHG" or event.type == "DCL" then local index = core.get_textlist_index("TPs") - core.setting_set("mainmenu_last_selected_TP", index) + core.settings:set("mainmenu_last_selected_TP", index) local list = filter_texture_pack_list(core.get_dir_list(core.get_texturepath(), true)) local current_index = core.get_textlist_index("TPs") if current_index and #list >= current_index then @@ -114,7 +114,7 @@ local function main_button_handler(tabview, fields, name, tabdata) if list[current_index] == fgettext("None") then new_path = "" end - core.setting_set("texture_path", new_path) + core.settings:set("texture_path", new_path) end end return true diff --git a/builtin/mainmenu/textures.lua b/builtin/mainmenu/textures.lua index dadbb093e..9ba4ade7e 100644 --- a/builtin/mainmenu/textures.lua +++ b/builtin/mainmenu/textures.lua @@ -24,7 +24,7 @@ function mm_texture.init() DIR_DELIM .. "pack" .. DIR_DELIM mm_texture.basetexturedir = mm_texture.defaulttexturedir - mm_texture.texturepack = core.setting_get("texture_path") + mm_texture.texturepack = core.settings:get("texture_path") mm_texture.gameid = nil end @@ -61,7 +61,7 @@ function mm_texture.reset() mm_texture.set_generic("header") if not have_bg then - if core.setting_getbool("menu_clouds") then + if core.settings:get_bool("menu_clouds") then core.set_clouds(true) else mm_texture.set_dirt_bg() @@ -88,7 +88,7 @@ function mm_texture.update_game(gamedetails) if not have_bg then - if core.setting_getbool("menu_clouds") then + if core.settings:get_bool("menu_clouds") then core.set_clouds(true) else mm_texture.set_dirt_bg() diff --git a/builtin/profiler/init.lua b/builtin/profiler/init.lua index c1597d280..874950364 100644 --- a/builtin/profiler/init.lua +++ b/builtin/profiler/init.lua @@ -15,10 +15,18 @@ --with this program; if not, write to the Free Software Foundation, Inc., --51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +local function get_bool_default(name, default) + local val = core.settings:get_bool(name) + if val == nil then + return default + end + return val +end + local profiler_path = core.get_builtin_path()..DIR_DELIM.."profiler"..DIR_DELIM local profiler = {} local sampler = assert(loadfile(profiler_path .. "sampling.lua"))(profiler) -local instrumentation = assert(loadfile(profiler_path .. "instrumentation.lua"))(profiler, sampler) +local instrumentation = assert(loadfile(profiler_path .. "instrumentation.lua"))(profiler, sampler, get_bool_default) local reporter = dofile(profiler_path .. "reporter.lua") profiler.instrument = instrumentation.instrument @@ -27,7 +35,7 @@ profiler.instrument = instrumentation.instrument -- Is called later, after `core.register_chatcommand` was set up. -- function profiler.init_chatcommand() - local instrument_profiler = core.setting_getbool("instrument.profiler") or false + local instrument_profiler = get_bool_default("instrument.profiler", false) if instrument_profiler then instrumentation.init_chatcommand() end diff --git a/builtin/profiler/instrumentation.lua b/builtin/profiler/instrumentation.lua index 4311215b2..be3a460e5 100644 --- a/builtin/profiler/instrumentation.lua +++ b/builtin/profiler/instrumentation.lua @@ -17,8 +17,9 @@ local format, pairs, type = string.format, pairs, type local core, get_current_modname = core, core.get_current_modname -local profiler, sampler = ... -local instrument_builtin = core.setting_getbool("instrument.builtin") or false +local profiler, sampler, get_bool_default = ... + +local instrument_builtin = get_bool_default("instrument.builtin", false) local register_functions = { register_globalstep = 0, @@ -137,7 +138,7 @@ local function instrument_register(func, func_name) end local function init_chatcommand() - if core.setting_getbool("instrument.chatcommand") or true then + if get_bool_default("instrument.chatcommand", true) then local orig_register_chatcommand = core.register_chatcommand core.register_chatcommand = function(cmd, def) def.func = instrument { @@ -153,8 +154,7 @@ end -- Start instrumenting selected functions -- local function init() - local is_set = core.setting_getbool - if is_set("instrument.entity") or true then + if get_bool_default("instrument.entity", true) then -- Explicitly declare entity api-methods. -- Simple iteration would ignore lookup via __index. local entity_instrumentation = { @@ -180,7 +180,7 @@ local function init() end end - if is_set("instrument.abm") or true then + if get_bool_default("instrument.abm", true) then -- Wrap register_abm() to automatically instrument abms. local orig_register_abm = core.register_abm core.register_abm = function(spec) @@ -193,7 +193,7 @@ local function init() end end - if is_set("instrument.lbm") or true then + if get_bool_default("instrument.lbm", true) then -- Wrap register_lbm() to automatically instrument lbms. local orig_register_lbm = core.register_lbm core.register_lbm = function(spec) @@ -206,13 +206,13 @@ local function init() end end - if is_set("instrument.global_callback") or true then + if get_bool_default("instrument.global_callback", true) then for func_name, _ in pairs(register_functions) do core[func_name] = instrument_register(core[func_name], func_name) end end - if is_set("instrument.profiler") or false then + if get_bool_default("instrument.profiler", false) then -- Measure overhead of instrumentation, but keep it down for functions -- So keep the `return` for better optimization. profiler.empty_instrument = instrument { diff --git a/builtin/profiler/reporter.lua b/builtin/profiler/reporter.lua index 5b38ed4df..fed47a36b 100644 --- a/builtin/profiler/reporter.lua +++ b/builtin/profiler/reporter.lua @@ -18,7 +18,7 @@ local DIR_DELIM, LINE_DELIM = DIR_DELIM, "\n" local table, unpack, string, pairs, io, os = table, unpack, string, pairs, io, os local rep, sprintf, tonumber = string.rep, string.format, tonumber -local core, setting_get = core, core.setting_get +local core, settings = core, core.settings local reporter = {} --- @@ -229,7 +229,7 @@ end local worldpath = core.get_worldpath() local function get_save_path(format, filter) - local report_path = setting_get("profiler.report_path") or "" + local report_path = settings:get("profiler.report_path") or "" if report_path ~= "" then core.mkdir(sprintf("%s%s%s", worldpath, DIR_DELIM, report_path)) end @@ -249,7 +249,7 @@ end -- function reporter.save(profile, format, filter) if not format or format == "" then - format = setting_get("profiler.default_report_format") or "txt" + format = settings:get("profiler.default_report_format") or "txt" end if filter == "" then filter = nil diff --git a/builtin/profiler/sampling.lua b/builtin/profiler/sampling.lua index 1d1ef256d..4b53399a5 100644 --- a/builtin/profiler/sampling.lua +++ b/builtin/profiler/sampling.lua @@ -185,7 +185,7 @@ end function sampler.init() sampler.reset() - if core.setting_getbool("instrument.profiler") then + if core.settings:get_bool("instrument.profiler") then core.register_globalstep(function() if logged_time == 0 then return diff --git a/doc/lua_api.txt b/doc/lua_api.txt index 1550a78be..166cc024a 100644 --- a/doc/lua_api.txt +++ b/doc/lua_api.txt @@ -172,8 +172,8 @@ The main Lua script. Running this script should register everything it wants to register. Subsequent execution depends on minetest calling the registered callbacks. -`minetest.setting_get(name)` and `minetest.setting_getbool(name)` can be used -to read custom or existing settings at load time, if necessary. +`minetest.settings` can be used to read custom or existing settings at load +time, if necessary. (See `Settings`) ### `models` Models for entities or meshnodes. @@ -2177,16 +2177,10 @@ Call these functions only at load time! * See `minetest.builtin_auth_handler` in `builtin.lua` for reference ### Setting-related -* `minetest.setting_set(name, value)` - * Setting names can't contain whitespace or any of `="{}#`. - * Setting values can't contain the sequence `\n"""`. - * Setting names starting with "secure." can't be set. -* `minetest.setting_get(name)`: returns string or `nil` -* `minetest.setting_setbool(name, value)` - * See documentation on `setting_set` for restrictions. -* `minetest.setting_getbool(name)`: returns boolean or `nil` -* `minetest.setting_get_pos(name)`: returns position or nil -* `minetest.setting_save()`, returns `nil`, save all settings to config file +* `minetest.settings`: Settings object containing all of the settings from the + main config file (`minetest.conf`). +* `minetest.setting_get_pos(name)`: Loads a setting from the main settings and + parses it as a position (in the format `(1,2,3)`). Returns a position or nil. ### Authentication * `minetest.notify_authentication_modified(name)` @@ -3536,10 +3530,15 @@ It can be created via `Settings(filename)`. * `get(key)`: returns a value * `get_bool(key)`: returns a boolean * `set(key, value)` + * Setting names can't contain whitespace or any of `="{}#`. + * Setting values can't contain the sequence `\n"""`. + * Setting names starting with "secure." can't be set on the main settings object (`minetest.settings`). +* `set_bool(key, value)` + * See documentation for set() above. * `remove(key)`: returns a boolean (`true` for success) * `get_names()`: returns `{key1,...}` * `write()`: returns a boolean (`true` for success) - * write changes to file + * Writes changes to file. * `to_table()`: returns `{[key1]=value1,...}` Mapgen objects diff --git a/src/script/cpp_api/s_async.cpp b/src/script/cpp_api/s_async.cpp index 080ae887c..722359066 100644 --- a/src/script/cpp_api/s_async.cpp +++ b/src/script/cpp_api/s_async.cpp @@ -76,14 +76,9 @@ AsyncEngine::~AsyncEngine() } /******************************************************************************/ -bool AsyncEngine::registerFunction(const char* name, lua_CFunction func) +void AsyncEngine::registerStateInitializer(StateInitializer func) { - if (initDone) { - return false; - } - - functionList[name] = func; - return true; + stateInitializers.push_back(func); } /******************************************************************************/ @@ -204,11 +199,9 @@ void AsyncEngine::pushFinishedJobs(lua_State* L) { /******************************************************************************/ void AsyncEngine::prepareEnvironment(lua_State* L, int top) { - for (UNORDERED_MAP::iterator it = functionList.begin(); - it != functionList.end(); ++it) { - lua_pushstring(L, it->first.c_str()); - lua_pushcfunction(L, it->second); - lua_settable(L, top); + for (std::vector::iterator it = stateInitializers.begin(); + it != stateInitializers.end(); it++) { + (*it)(L, top); } } diff --git a/src/script/cpp_api/s_async.h b/src/script/cpp_api/s_async.h index 93e9759b4..dbe0654e2 100644 --- a/src/script/cpp_api/s_async.h +++ b/src/script/cpp_api/s_async.h @@ -75,16 +75,16 @@ private: // Asynchornous thread and job management class AsyncEngine { friend class AsyncWorkerThread; + typedef void (*StateInitializer)(lua_State *L, int top); public: AsyncEngine(); ~AsyncEngine(); /** - * Register function to be used within engine - * @param name Function name to be used within Lua environment + * Register function to be called on new states * @param func C function to be called */ - bool registerFunction(const char* name, lua_CFunction func); + void registerStateInitializer(StateInitializer func); /** * Create async engine tasks and lock function registration @@ -140,8 +140,8 @@ private: // Variable locking the engine against further modification bool initDone; - // Internal store for registred functions - UNORDERED_MAP functionList; + // Internal store for registred state initializers + std::vector stateInitializers; // Internal counter to create job IDs unsigned int jobIdCounter; diff --git a/src/script/lua_api/l_base.cpp b/src/script/lua_api/l_base.cpp index dfe743b72..5d7ba9640 100644 --- a/src/script/lua_api/l_base.cpp +++ b/src/script/lua_api/l_base.cpp @@ -74,17 +74,13 @@ std::string ModApiBase::getCurrentModPath(lua_State *L) } -bool ModApiBase::registerFunction( - lua_State *L, - const char *name, - lua_CFunction fct, - int top) +bool ModApiBase::registerFunction(lua_State *L, const char *name, + lua_CFunction func, int top) { - //TODO check presence first! + // TODO: Check presence first! - lua_pushstring(L,name); - lua_pushcfunction(L,fct); - lua_settable(L, top); + lua_pushcfunction(L, func); + lua_setfield(L, top, name); return true; } diff --git a/src/script/lua_api/l_base.h b/src/script/lua_api/l_base.h index cd382629d..af89afd93 100644 --- a/src/script/lua_api/l_base.h +++ b/src/script/lua_api/l_base.h @@ -68,9 +68,8 @@ public: static bool registerFunction(lua_State *L, const char* name, - lua_CFunction fct, - int top - ); + lua_CFunction func, + int top); }; #endif /* L_BASE_H_ */ diff --git a/src/script/lua_api/l_internal.h b/src/script/lua_api/l_internal.h index b7627619e..e9b689931 100644 --- a/src/script/lua_api/l_internal.h +++ b/src/script/lua_api/l_internal.h @@ -31,8 +31,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #define luamethod(class, name) {#name, class::l_##name} #define luamethod_aliased(class, name, alias) {#name, class::l_##name}, {#alias, class::l_##name} -#define API_FCT(name) registerFunction(L, #name, l_##name,top) -#define ASYNC_API_FCT(name) engine.registerFunction(#name, l_##name) +#define API_FCT(name) registerFunction(L, #name, l_##name, top) #define MAP_LOCK_REQUIRED #define NO_MAP_LOCK_REQUIRED diff --git a/src/script/lua_api/l_mainmenu.cpp b/src/script/lua_api/l_mainmenu.cpp index 4d0be257c..dc8654960 100644 --- a/src/script/lua_api/l_mainmenu.cpp +++ b/src/script/lua_api/l_mainmenu.cpp @@ -38,6 +38,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include #include + /******************************************************************************/ std::string ModApiMainMenu::getTextData(lua_State *L, std::string name) { @@ -1141,23 +1142,24 @@ void ModApiMainMenu::Initialize(lua_State *L, int top) } /******************************************************************************/ -void ModApiMainMenu::InitializeAsync(AsyncEngine& engine) +void ModApiMainMenu::InitializeAsync(lua_State *L, int top) { - ASYNC_API_FCT(get_worlds); - ASYNC_API_FCT(get_games); - ASYNC_API_FCT(get_favorites); - ASYNC_API_FCT(get_mapgen_names); - ASYNC_API_FCT(get_modpath); - ASYNC_API_FCT(get_gamepath); - ASYNC_API_FCT(get_texturepath); - ASYNC_API_FCT(get_texturepath_share); - ASYNC_API_FCT(create_dir); - ASYNC_API_FCT(delete_dir); - ASYNC_API_FCT(copy_dir); - //ASYNC_API_FCT(extract_zip); //TODO remove dependency to GuiEngine - ASYNC_API_FCT(download_file); - ASYNC_API_FCT(get_modstore_details); - ASYNC_API_FCT(get_modstore_list); - //ASYNC_API_FCT(gettext); (gettext lib isn't threadsafe) + API_FCT(get_worlds); + API_FCT(get_games); + API_FCT(get_favorites); + API_FCT(get_mapgen_names); + API_FCT(get_modpath); + API_FCT(get_gamepath); + API_FCT(get_texturepath); + API_FCT(get_texturepath_share); + API_FCT(create_dir); + API_FCT(delete_dir); + API_FCT(copy_dir); + //API_FCT(extract_zip); //TODO remove dependency to GuiEngine + API_FCT(download_file); + API_FCT(get_modstore_details); + API_FCT(get_modstore_list); + //API_FCT(gettext); (gettext lib isn't threadsafe) } + diff --git a/src/script/lua_api/l_mainmenu.h b/src/script/lua_api/l_mainmenu.h index e31ac0112..d4946bab1 100644 --- a/src/script/lua_api/l_mainmenu.h +++ b/src/script/lua_api/l_mainmenu.h @@ -142,6 +142,7 @@ private: static int l_do_async_callback(lua_State *L); public: + /** * initialize this API module * @param L lua stack to initialize @@ -149,7 +150,7 @@ public: */ static void Initialize(lua_State *L, int top); - static void InitializeAsync(AsyncEngine& engine); + static void InitializeAsync(lua_State *L, int top); }; diff --git a/src/script/lua_api/l_settings.cpp b/src/script/lua_api/l_settings.cpp index 809f7d115..70807f3d2 100644 --- a/src/script/lua_api/l_settings.cpp +++ b/src/script/lua_api/l_settings.cpp @@ -23,6 +23,47 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "settings.h" #include "log.h" + +#define SET_SECURITY_CHECK(L, name) \ + if (o->m_settings == g_settings && ScriptApiSecurity::isSecure(L) && \ + name.compare(0, 7, "secure.") == 0) { \ + throw LuaError("Attempt to set secure setting."); \ + } + +LuaSettings::LuaSettings(Settings *settings, const std::string &filename) : + m_settings(settings), + m_filename(filename), + m_is_own_settings(false), + m_write_allowed(true) +{ +} + +LuaSettings::LuaSettings(const std::string &filename, bool write_allowed) : + m_filename(filename), + m_is_own_settings(true), + m_write_allowed(write_allowed) +{ + m_settings = new Settings(); + m_settings->readConfigFile(filename.c_str()); +} + +LuaSettings::~LuaSettings() +{ + if (m_is_own_settings) + delete m_settings; +} + + +void LuaSettings::create(lua_State *L, Settings *settings, + const std::string &filename) +{ + LuaSettings *o = new LuaSettings(settings, filename); + *(void **)(lua_newuserdata(L, sizeof(void *))) = o; + luaL_getmetatable(L, className); + lua_setmetatable(L, -2); +} + + // garbage collector int LuaSettings::gc_object(lua_State* L) { @@ -31,6 +72,7 @@ int LuaSettings::gc_object(lua_State* L) return 0; } + // get(self, key) -> value int LuaSettings::l_get(lua_State* L) { @@ -74,12 +116,30 @@ int LuaSettings::l_set(lua_State* L) std::string key = std::string(luaL_checkstring(L, 2)); const char* value = luaL_checkstring(L, 3); + SET_SECURITY_CHECK(L, key); + if (!o->m_settings->set(key, value)) throw LuaError("Invalid sequence found in setting parameters"); return 0; } +// set_bool(self, key, value) +int LuaSettings::l_set_bool(lua_State* L) +{ + NO_MAP_LOCK_REQUIRED; + LuaSettings* o = checkobject(L, 1); + + std::string key = std::string(luaL_checkstring(L, 2)); + bool value = lua_toboolean(L, 3); + + SET_SECURITY_CHECK(L, key); + + o->m_settings->setBool(key, value); + + return 1; +} + // remove(self, key) -> success int LuaSettings::l_remove(lua_State* L) { @@ -88,6 +148,8 @@ int LuaSettings::l_remove(lua_State* L) std::string key = std::string(luaL_checkstring(L, 2)); + SET_SECURITY_CHECK(L, key); + bool success = o->m_settings->remove(key); lua_pushboolean(L, success); @@ -147,19 +209,6 @@ int LuaSettings::l_to_table(lua_State* L) return 1; } -LuaSettings::LuaSettings(const char* filename, bool write_allowed) -{ - m_write_allowed = write_allowed; - m_filename = std::string(filename); - - m_settings = new Settings(); - m_settings->readConfigFile(m_filename.c_str()); -} - -LuaSettings::~LuaSettings() -{ - delete m_settings; -} void LuaSettings::Register(lua_State* L) { @@ -190,7 +239,7 @@ void LuaSettings::Register(lua_State* L) } // LuaSettings(filename) -// Creates an LuaSettings and leaves it on top of stack +// Creates a LuaSettings and leaves it on top of the stack int LuaSettings::create_object(lua_State* L) { NO_MAP_LOCK_REQUIRED; @@ -209,8 +258,9 @@ LuaSettings* LuaSettings::checkobject(lua_State* L, int narg) NO_MAP_LOCK_REQUIRED; luaL_checktype(L, narg, LUA_TUSERDATA); void *ud = luaL_checkudata(L, narg, className); - if(!ud) luaL_typerror(L, narg, className); - return *(LuaSettings**)ud; // unbox pointer + if (!ud) + luaL_typerror(L, narg, className); + return *(LuaSettings**) ud; // unbox pointer } const char LuaSettings::className[] = "Settings"; @@ -218,6 +268,7 @@ const luaL_Reg LuaSettings::methods[] = { luamethod(LuaSettings, get), luamethod(LuaSettings, get_bool), luamethod(LuaSettings, set), + luamethod(LuaSettings, set_bool), luamethod(LuaSettings, remove), luamethod(LuaSettings, get_names), luamethod(LuaSettings, write), diff --git a/src/script/lua_api/l_settings.h b/src/script/lua_api/l_settings.h index b90f0a8f2..f3bc7410b 100644 --- a/src/script/lua_api/l_settings.h +++ b/src/script/lua_api/l_settings.h @@ -42,6 +42,9 @@ private: // set(self, key, value) static int l_set(lua_State *L); + // set_bool(self, key, value) + static int l_set_bool(lua_State* L); + // remove(self, key) -> success static int l_remove(lua_State *L); @@ -54,16 +57,20 @@ private: // to_table(self) -> {[key1]=value1,...} static int l_to_table(lua_State *L); - bool m_write_allowed; Settings *m_settings; std::string m_filename; + bool m_is_own_settings; + bool m_write_allowed; public: - LuaSettings(const char *filename, bool write_allowed); + LuaSettings(Settings *settings, const std::string &filename); + LuaSettings(const std::string &filename, bool write_allowed); ~LuaSettings(); + static void create(lua_State *L, Settings *settings, const std::string &filename); + // LuaSettings(filename) - // Creates an LuaSettings and leaves it on top of stack + // Creates a LuaSettings and leaves it on top of the stack static int create_object(lua_State *L); static LuaSettings *checkobject(lua_State *L, int narg); diff --git a/src/script/lua_api/l_util.cpp b/src/script/lua_api/l_util.cpp index 809a2eb68..c4a988e07 100644 --- a/src/script/lua_api/l_util.cpp +++ b/src/script/lua_api/l_util.cpp @@ -19,6 +19,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "lua_api/l_util.h" #include "lua_api/l_internal.h" +#include "lua_api/l_settings.h" #include "common/c_converter.h" #include "common/c_content.h" #include "cpp_api/s_async.h" @@ -77,71 +78,6 @@ int ModApiUtil::l_get_us_time(lua_State *L) return 1; } -#define CHECK_SECURE_SETTING(L, name) \ - if (ScriptApiSecurity::isSecure(L) && \ - name.compare(0, 7, "secure.") == 0) { \ - throw LuaError("Attempt to set secure setting."); \ - } - -// setting_set(name, value) -int ModApiUtil::l_setting_set(lua_State *L) -{ - NO_MAP_LOCK_REQUIRED; - std::string name = luaL_checkstring(L, 1); - std::string value = luaL_checkstring(L, 2); - CHECK_SECURE_SETTING(L, name); - g_settings->set(name, value); - return 0; -} - -// setting_get(name) -int ModApiUtil::l_setting_get(lua_State *L) -{ - NO_MAP_LOCK_REQUIRED; - const char *name = luaL_checkstring(L, 1); - try{ - std::string value = g_settings->get(name); - lua_pushstring(L, value.c_str()); - } catch(SettingNotFoundException &e){ - lua_pushnil(L); - } - return 1; -} - -// setting_setbool(name) -int ModApiUtil::l_setting_setbool(lua_State *L) -{ - NO_MAP_LOCK_REQUIRED; - std::string name = luaL_checkstring(L, 1); - bool value = lua_toboolean(L, 2); - CHECK_SECURE_SETTING(L, name); - g_settings->setBool(name, value); - return 0; -} - -// setting_getbool(name) -int ModApiUtil::l_setting_getbool(lua_State *L) -{ - NO_MAP_LOCK_REQUIRED; - const char *name = luaL_checkstring(L, 1); - try{ - bool value = g_settings->getBool(name); - lua_pushboolean(L, value); - } catch(SettingNotFoundException &e){ - lua_pushnil(L); - } - return 1; -} - -// setting_save() -int ModApiUtil::l_setting_save(lua_State *L) -{ - NO_MAP_LOCK_REQUIRED; - if(g_settings_path != "") - g_settings->updateConfigFile(g_settings_path.c_str()); - return 0; -} - // parse_json(str[, nullvalue]) int ModApiUtil::l_parse_json(lua_State *L) { @@ -493,12 +429,6 @@ void ModApiUtil::Initialize(lua_State *L, int top) API_FCT(get_us_time); - API_FCT(setting_set); - API_FCT(setting_get); - API_FCT(setting_setbool); - API_FCT(setting_getbool); - API_FCT(setting_save); - API_FCT(parse_json); API_FCT(write_json); @@ -524,6 +454,9 @@ void ModApiUtil::Initialize(lua_State *L, int top) API_FCT(decode_base64); API_FCT(get_version); + + LuaSettings::create(L, g_settings, g_settings_path); + lua_setfield(L, top, "settings"); } void ModApiUtil::InitializeClient(lua_State *L, int top) @@ -548,34 +481,31 @@ void ModApiUtil::InitializeClient(lua_State *L, int top) API_FCT(get_version); } -void ModApiUtil::InitializeAsync(AsyncEngine& engine) +void ModApiUtil::InitializeAsync(lua_State *L, int top) { - ASYNC_API_FCT(log); + API_FCT(log); - ASYNC_API_FCT(get_us_time); + API_FCT(get_us_time); - //ASYNC_API_FCT(setting_set); - ASYNC_API_FCT(setting_get); - //ASYNC_API_FCT(setting_setbool); - ASYNC_API_FCT(setting_getbool); - //ASYNC_API_FCT(setting_save); + API_FCT(parse_json); + API_FCT(write_json); - ASYNC_API_FCT(parse_json); - ASYNC_API_FCT(write_json); + API_FCT(is_yes); - ASYNC_API_FCT(is_yes); + API_FCT(get_builtin_path); - ASYNC_API_FCT(get_builtin_path); + API_FCT(compress); + API_FCT(decompress); - ASYNC_API_FCT(compress); - ASYNC_API_FCT(decompress); + API_FCT(mkdir); + API_FCT(get_dir_list); - ASYNC_API_FCT(mkdir); - ASYNC_API_FCT(get_dir_list); + API_FCT(encode_base64); + API_FCT(decode_base64); - ASYNC_API_FCT(encode_base64); - ASYNC_API_FCT(decode_base64); + API_FCT(get_version); - ASYNC_API_FCT(get_version); + LuaSettings::create(L, g_settings, g_settings_path); + lua_setfield(L, top, "settings"); } diff --git a/src/script/lua_api/l_util.h b/src/script/lua_api/l_util.h index 7325a841a..c36c054e6 100644 --- a/src/script/lua_api/l_util.h +++ b/src/script/lua_api/l_util.h @@ -45,21 +45,6 @@ private: // get us precision time static int l_get_us_time(lua_State *L); - // setting_set(name, value) - static int l_setting_set(lua_State *L); - - // setting_get(name) - static int l_setting_get(lua_State *L); - - // setting_setbool(name, value) - static int l_setting_setbool(lua_State *L); - - // setting_getbool(name) - static int l_setting_getbool(lua_State *L); - - // setting_save() - static int l_setting_save(lua_State *L); - // parse_json(str[, nullvalue]) static int l_parse_json(lua_State *L); @@ -109,8 +94,9 @@ private: static int l_get_version(lua_State *L); public: - static void Initialize(lua_State *L, int top); + static void Initialize(lua_State *L, int top); + static void InitializeAsync(lua_State *L, int top); static void InitializeClient(lua_State *L, int top); static void InitializeAsync(AsyncEngine &engine); diff --git a/src/script/scripting_client.cpp b/src/script/scripting_client.cpp index b5a5085be..24f70b8c1 100644 --- a/src/script/scripting_client.cpp +++ b/src/script/scripting_client.cpp @@ -62,17 +62,17 @@ ClientScripting::ClientScripting(Client *client): void ClientScripting::InitializeModApi(lua_State *L, int top) { - ModApiUtil::InitializeClient(L, top); - ModApiClient::Initialize(L, top); - ModApiStorage::Initialize(L, top); - ModApiEnvMod::InitializeClient(L, top); - LuaItemStack::Register(L); StorageRef::Register(L); LuaMinimap::Register(L); NodeMetaRef::RegisterClient(L); LuaLocalPlayer::Register(L); LuaCamera::Register(L); + + ModApiUtil::InitializeClient(L, top); + ModApiClient::Initialize(L, top); + ModApiStorage::Initialize(L, top); + ModApiEnvMod::InitializeClient(L, top); } void ClientScripting::on_client_ready(LocalPlayer *localplayer) diff --git a/src/script/scripting_mainmenu.cpp b/src/script/scripting_mainmenu.cpp index d79864a95..48957b472 100644 --- a/src/script/scripting_mainmenu.cpp +++ b/src/script/scripting_mainmenu.cpp @@ -59,23 +59,28 @@ MainMenuScripting::MainMenuScripting(GUIEngine* guiengine) /******************************************************************************/ void MainMenuScripting::initializeModApi(lua_State *L, int top) { + registerLuaClasses(L, top); + // Initialize mod API modules ModApiMainMenu::Initialize(L, top); ModApiUtil::Initialize(L, top); ModApiSound::Initialize(L, top); - // Register reference classes (userdata) - LuaSettings::Register(L); - - // Register functions to async environment - ModApiMainMenu::InitializeAsync(asyncEngine); - ModApiUtil::InitializeAsync(asyncEngine); + asyncEngine.registerStateInitializer(registerLuaClasses); + asyncEngine.registerStateInitializer(ModApiMainMenu::InitializeAsync); + asyncEngine.registerStateInitializer(ModApiUtil::InitializeAsync); // Initialize async environment //TODO possibly make number of async threads configurable asyncEngine.initialize(MAINMENU_NUM_ASYNC_THREADS); } +/******************************************************************************/ +void MainMenuScripting::registerLuaClasses(lua_State *L, int top) +{ + LuaSettings::Register(L); +} + /******************************************************************************/ void MainMenuScripting::step() { diff --git a/src/script/scripting_mainmenu.h b/src/script/scripting_mainmenu.h index 9aacd55d6..7b3a6eba8 100644 --- a/src/script/scripting_mainmenu.h +++ b/src/script/scripting_mainmenu.h @@ -44,6 +44,7 @@ public: const std::string &serialized_params); private: void initializeModApi(lua_State *L, int top); + static void registerLuaClasses(lua_State *L, int top); AsyncEngine asyncEngine; DISABLE_CLASS_COPY(MainMenuScripting); diff --git a/src/script/scripting_server.cpp b/src/script/scripting_server.cpp index ce56fcf19..cd01b0773 100644 --- a/src/script/scripting_server.cpp +++ b/src/script/scripting_server.cpp @@ -82,19 +82,6 @@ ServerScripting::ServerScripting(Server* server) void ServerScripting::InitializeModApi(lua_State *L, int top) { - // Initialize mod api modules - ModApiCraft::Initialize(L, top); - ModApiEnvMod::Initialize(L, top); - ModApiInventory::Initialize(L, top); - ModApiItemMod::Initialize(L, top); - ModApiMapgen::Initialize(L, top); - ModApiParticles::Initialize(L, top); - ModApiRollback::Initialize(L, top); - ModApiServer::Initialize(L, top); - ModApiUtil::Initialize(L, top); - ModApiHttp::Initialize(L, top); - ModApiStorage::Initialize(L, top); - // Register reference classes (userdata) InvRef::Register(L); ItemStackMetaRef::Register(L); @@ -111,6 +98,19 @@ void ServerScripting::InitializeModApi(lua_State *L, int top) ObjectRef::Register(L); LuaSettings::Register(L); StorageRef::Register(L); + + // Initialize mod api modules + ModApiCraft::Initialize(L, top); + ModApiEnvMod::Initialize(L, top); + ModApiInventory::Initialize(L, top); + ModApiItemMod::Initialize(L, top); + ModApiMapgen::Initialize(L, top); + ModApiParticles::Initialize(L, top); + ModApiRollback::Initialize(L, top); + ModApiServer::Initialize(L, top); + ModApiUtil::Initialize(L, top); + ModApiHttp::Initialize(L, top); + ModApiStorage::Initialize(L, top); } void log_deprecated(const std::string &message) -- cgit v1.2.3 From a32a06e088df34efb82e3ec8633d331e3b177796 Mon Sep 17 00:00:00 2001 From: Auke Kok Date: Mon, 8 May 2017 23:56:57 -0700 Subject: Move Pilzadam to previous developers. (#5735) --- builtin/mainmenu/tab_credits.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'builtin/mainmenu') diff --git a/builtin/mainmenu/tab_credits.lua b/builtin/mainmenu/tab_credits.lua index 80e03f84d..ff47dbb22 100644 --- a/builtin/mainmenu/tab_credits.lua +++ b/builtin/mainmenu/tab_credits.lua @@ -20,7 +20,6 @@ local core_developers = { "Perttu Ahola (celeron55) ", "Ryan Kwolek (kwolekr) ", - "PilzAdam ", "sfan5 ", "kahrl ", "sapier", @@ -54,6 +53,7 @@ local previous_core_developers = { "Lisa Milne (darkrose) ", "proller", "Ilya Zhuravlev (xyz) ", + "PilzAdam ", } local previous_contributors = { -- cgit v1.2.3 From 34c52d0ad76f627c719adc8806ca71c4968b8b39 Mon Sep 17 00:00:00 2001 From: red-001 Date: Tue, 9 May 2017 17:30:34 +0100 Subject: Android: Fix crash while loading main menu (#5736) Broken by 43d1f37 --- builtin/mainmenu/tab_simple_main.lua | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'builtin/mainmenu') diff --git a/builtin/mainmenu/tab_simple_main.lua b/builtin/mainmenu/tab_simple_main.lua index 90a743f68..de4ae1751 100644 --- a/builtin/mainmenu/tab_simple_main.lua +++ b/builtin/mainmenu/tab_simple_main.lua @@ -188,6 +188,10 @@ local function main_button_handler(tabview, fields, name, tabdata) core.settings:set("address", fields.te_address) core.settings:set("remote_port", fields.te_port) + + core.start() + return true + end if fields.btn_config_sp_world then local configdialog = create_configure_world_dlg(1) -- cgit v1.2.3 From 441740e021f48a3c4f7595711777b7655fdd5778 Mon Sep 17 00:00:00 2001 From: red-001 Date: Wed, 10 May 2017 22:25:45 +0100 Subject: Menu: Fix starting a server if the server address is an empty string. (#5742) Minetest uses an empty string internal to signal that a server should be started. --- builtin/mainmenu/tab_multiplayer.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'builtin/mainmenu') diff --git a/builtin/mainmenu/tab_multiplayer.lua b/builtin/mainmenu/tab_multiplayer.lua index a9b2b35fe..f40b707ac 100644 --- a/builtin/mainmenu/tab_multiplayer.lua +++ b/builtin/mainmenu/tab_multiplayer.lua @@ -299,7 +299,8 @@ local function main_button_handler(tabview, fields, name, tabdata) return true end - if (fields.btn_mp_connect or fields.key_enter) and fields.te_address and fields.te_port then + if (fields.btn_mp_connect or fields.key_enter) + and fields.te_address ~= "" and fields.te_port then gamedata.playername = fields.te_name gamedata.password = fields.te_pwd gamedata.address = fields.te_address -- cgit v1.2.3 From 018217f6b2058db44b59a86e170614e1c6925f9f Mon Sep 17 00:00:00 2001 From: ezhh Date: Thu, 11 May 2017 23:18:36 +0100 Subject: Add option to use neither node highlighting nor outlining --- builtin/mainmenu/tab_settings.lua | 5 +++-- builtin/settingtypes.txt | 2 +- minetest.conf.example | 2 +- src/hud.cpp | 25 ++++++++++++++++--------- src/hud.h | 6 +++++- 5 files changed, 26 insertions(+), 14 deletions(-) (limited to 'builtin/mainmenu') diff --git a/builtin/mainmenu/tab_settings.lua b/builtin/mainmenu/tab_settings.lua index 69683eaa3..5a8cc19b8 100644 --- a/builtin/mainmenu/tab_settings.lua +++ b/builtin/mainmenu/tab_settings.lua @@ -25,7 +25,8 @@ local labels = { }, node_highlighting = { fgettext("Node Outlining"), - fgettext("Node Highlighting") + fgettext("Node Highlighting"), + fgettext("None") }, filters = { fgettext("No Filter"), @@ -52,7 +53,7 @@ local dd_options = { }, node_highlighting = { table.concat(labels.node_highlighting, ","), - {"box", "halo"} + {"box", "halo", "none"} }, filters = { table.concat(labels.filters, ","), diff --git a/builtin/settingtypes.txt b/builtin/settingtypes.txt index 61c04e616..463ca0be9 100644 --- a/builtin/settingtypes.txt +++ b/builtin/settingtypes.txt @@ -344,7 +344,7 @@ enable_clouds (Clouds) bool true enable_3d_clouds (3D clouds) bool true # Method used to highlight selected object. -node_highlighting (Node highlighting) enum box box,halo +node_highlighting (Node highlighting) enum box box,halo,none # Adds particles when digging a node. enable_particles (Digging particles) bool true diff --git a/minetest.conf.example b/minetest.conf.example index 6c6ce91b8..e9add1597 100644 --- a/minetest.conf.example +++ b/minetest.conf.example @@ -382,7 +382,7 @@ # enable_3d_clouds = true # Method used to highlight selected object. -# type: enum values: box, halo +# type: enum values: box, halo, none # node_highlighting = box # Adds particles when digging a node. diff --git a/src/hud.cpp b/src/hud.cpp index 9729013ee..3e4162b64 100644 --- a/src/hud.cpp +++ b/src/hud.cpp @@ -87,24 +87,31 @@ Hud::Hud(video::IVideoDriver *driver, scene::ISceneManager* smgr, m_halo_boxes.clear(); m_selection_pos = v3f(0.0, 0.0, 0.0); - std::string mode = g_settings->get("node_highlighting"); + std::string mode_setting = g_settings->get("node_highlighting"); + + if (mode_setting == "halo") { + m_mode = HIGHLIGHT_HALO; + } else if (mode_setting == "none") { + m_mode = HIGHLIGHT_NONE; + } else { + m_mode = HIGHLIGHT_BOX; + } + m_selection_material.Lighting = false; if (g_settings->getBool("enable_shaders")) { IShaderSource *shdrsrc = client->getShaderSource(); u16 shader_id = shdrsrc->getShader( - mode == "halo" ? "selection_shader" : "default_shader", 1, 1); + m_mode == HIGHLIGHT_HALO ? "selection_shader" : "default_shader", 1, 1); m_selection_material.MaterialType = shdrsrc->getShaderInfo(shader_id).material; } else { m_selection_material.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL; } - if (mode == "box") { - m_use_selection_mesh = false; + if (m_mode == HIGHLIGHT_BOX) { m_selection_material.Thickness = rangelim(g_settings->getS16("selectionbox_width"), 1, 5); - } else if (mode == "halo") { - m_use_selection_mesh = true; + } else if (m_mode == HIGHLIGHT_HALO) { m_selection_material.setTexture(0, tsrc->getTextureForMesh("halo.png")); m_selection_material.setFlag(video::EMF_BACK_FACE_CULLING, true); } else { @@ -518,7 +525,7 @@ void Hud::setSelectionPos(const v3f &pos, const v3s16 &camera_offset) void Hud::drawSelectionMesh() { - if (!m_use_selection_mesh) { + if (m_mode == HIGHLIGHT_BOX) { // Draw 3D selection boxes video::SMaterial oldmaterial = driver->getMaterial2D(); driver->setMaterial(m_selection_material); @@ -538,7 +545,7 @@ void Hud::drawSelectionMesh() driver->draw3DBox(box, video::SColor(255, r, g, b)); } driver->setMaterial(oldmaterial); - } else if (m_selection_mesh) { + } else if (m_mode == HIGHLIGHT_HALO && m_selection_mesh) { // Draw selection mesh video::SMaterial oldmaterial = driver->getMaterial2D(); driver->setMaterial(m_selection_material); @@ -564,7 +571,7 @@ void Hud::drawSelectionMesh() void Hud::updateSelectionMesh(const v3s16 &camera_offset) { m_camera_offset = camera_offset; - if (!m_use_selection_mesh) + if (m_mode != HIGHLIGHT_HALO) return; if (m_selection_mesh) { diff --git a/src/hud.h b/src/hud.h index efa0c3648..15c115d89 100644 --- a/src/hud.h +++ b/src/hud.h @@ -175,7 +175,11 @@ private: v3f m_selected_face_normal; video::SMaterial m_selection_material; - bool m_use_selection_mesh; + + enum { + HIGHLIGHT_BOX, + HIGHLIGHT_HALO, + HIGHLIGHT_NONE } m_mode; }; enum ItemRotationKind { -- cgit v1.2.3 From 0120fe16a761f9e06c8c2877439db6a46d808143 Mon Sep 17 00:00:00 2001 From: SmallJoker Date: Sat, 13 May 2017 13:14:41 +0200 Subject: CSM: Document forgotten functions --- builtin/common/misc_helpers.lua | 2 +- builtin/mainmenu/common.lua | 2 +- builtin/mainmenu/tab_mods.lua | 2 +- doc/client_lua_api.md | 41 +++++++++++++++++++++++++++++++++++++---- doc/lua_api.txt | 5 ++++- 5 files changed, 44 insertions(+), 8 deletions(-) (limited to 'builtin/mainmenu') diff --git a/builtin/common/misc_helpers.lua b/builtin/common/misc_helpers.lua index 1ca400688..68481f7c8 100644 --- a/builtin/common/misc_helpers.lua +++ b/builtin/common/misc_helpers.lua @@ -308,7 +308,7 @@ function core.formspec_escape(text) end -function core.splittext(text,charlimit) +function core.wrap_text(text, charlimit) local retval = {} local current_idx = 1 diff --git a/builtin/mainmenu/common.lua b/builtin/mainmenu/common.lua index 294e1a621..fa7ae583b 100644 --- a/builtin/mainmenu/common.lua +++ b/builtin/mainmenu/common.lua @@ -250,7 +250,7 @@ end -------------------------------------------------------------------------------- function text2textlist(xpos, ypos, width, height, tl_name, textlen, text, transparency) - local textlines = core.splittext(text, textlen) + local textlines = core.wrap_text(text, textlen) local retval = "textlist[" .. xpos .. "," .. ypos .. ";" .. width .. "," .. height .. ";" .. tl_name .. ";" diff --git a/builtin/mainmenu/tab_mods.lua b/builtin/mainmenu/tab_mods.lua index 29afd8a4e..9510a9e18 100644 --- a/builtin/mainmenu/tab_mods.lua +++ b/builtin/mainmenu/tab_mods.lua @@ -75,7 +75,7 @@ local function get_formspec(tabview, name, tabdata) if error == nil then local descriptiontext = descriptionfile:read("*all") - descriptionlines = core.splittext(descriptiontext,42) + descriptionlines = core.wrap_text(descriptiontext, 42) descriptionfile:close() else descriptionlines = {} diff --git a/doc/client_lua_api.md b/doc/client_lua_api.md index 19947a525..9f59b4671 100644 --- a/doc/client_lua_api.md +++ b/doc/client_lua_api.md @@ -590,17 +590,24 @@ Helper functions * `math.sign(x, tolerance)` * Get the sign of a number. Optional: Also returns `0` when the absolute value is within the tolerance (default: `0`) -* `string.split(str, separator=",", include_empty=false, max_splits=-1, -* sep_is_pattern=false)` +* `string.split(str, separator=",", include_empty=false, max_splits=-1, sep_is_pattern=false)` * If `max_splits` is negative, do not limit splits. * `sep_is_pattern` specifies if separator is a plain string or a pattern (regex). * e.g. `string:split("a,b", ",") == {"a","b"}` * `string:trim()` * e.g. `string.trim("\n \t\tfoo bar\t ") == "foo bar"` +* `minetest.wrap_text(str, limit)`: returns a string + * Adds new lines to the string to keep it within the specified character limit + * limit: Maximal amount of characters in one line +* `minetest.pos_to_string({x=X,y=Y,z=Z}, decimal_places))`: returns string `"(X,Y,Z)"` + * Convert position to a printable string + Optional: 'decimal_places' will round the x, y and z of the pos to the given decimal place. +* `minetest.string_to_pos(string)`: returns a position + * Same but in reverse. Returns `nil` if the string can't be parsed to a position. +* `minetest.string_to_area("(X1, Y1, Z1) (X2, Y2, Z2)")`: returns two positions + * Converts a string representing an area box into two positions * `minetest.is_yes(arg)` * returns whether `arg` can be interpreted as yes -* `minetest.get_us_time()` - * returns time with microsecond precision. May not return wall time. * `table.copy(table)`: returns a table * returns a deep copy of `table` @@ -649,6 +656,8 @@ Call these functions only at load time! * Return `true` to mark the message as handled, which means that it will not be sent to server * `minetest.register_chatcommand(cmd, chatcommand definition)` * Adds definition to minetest.registered_chatcommands +* `minetest.unregister_chatcommand(name)` + * Unregisters a chatcommands registered with register_chatcommand. * `minetest.register_on_death(func())` * Called when the local player dies * `minetest.register_on_hp_modification(func(hp))` @@ -683,6 +692,12 @@ Call these functions only at load time! * `minetest.after(time, func, ...)` * Call the function `func` after `time` seconds, may be fractional * Optional: Variable number of arguments that are passed to `func` +* `minetest.get_us_time()` + * Returns time with microsecond precision. May not return wall time. +* `minetest.get_day_count()` + * Returns number days elapsed since world was created, accounting for time changes. +* `minetest.get_timeofday()` + * Returns the time of day: `0` for midnight, `0.5` for midday ### Map * `minetest.get_node(pos)` @@ -691,8 +706,17 @@ Call these functions only at load time! for unloaded areas. * `minetest.get_node_or_nil(pos)` * Same as `get_node` but returns `nil` for unloaded areas. +* `minetest.find_node_near(pos, radius, nodenames, [search_center])`: returns pos or `nil` + * `radius`: using a maximum metric + * `nodenames`: e.g. `{"ignore", "group:tree"}` or `"default:dirt"` + * `search_center` is an optional boolean (default: `false`) + If true `pos` is also checked for the nodes * `minetest.get_meta(pos)` * Get a `NodeMetaRef` at that position +* `minetest.get_node_level(pos)` + * get level of leveled node (water, snow) +* `minetest.get_node_max_level(pos)` + * get max available level for leveled node ### Player * `minetest.get_wielded_item()` @@ -710,6 +734,13 @@ Call these functions only at load time! * Take a screenshot. * `minetest.get_server_info()` * Returns [server info](#server-info). +* `minetest.send_respawn()` + * Sends a respawn request to the server. + +### Storage API +* `minetest.get_mod_storage()`: + * returns reference to mod private `StorageRef` + * must be called during mod load time ### Misc. * `minetest.parse_json(string[, nullvalue])`: returns something @@ -763,6 +794,8 @@ Call these functions only at load time! * same as fgettext_ne(), but calls minetest.formspec_escape before returning result * `minetest.pointed_thing_to_face_pos(placer, pointed_thing)`: returns a position * returns the exact position on the surface of a pointed node +* `minetest.global_exists(name)` + * Checks if a global variable has been set, without triggering a warning. ### UI * `minetest.ui.minimap` diff --git a/doc/lua_api.txt b/doc/lua_api.txt index 4e2ec00c3..762446466 100644 --- a/doc/lua_api.txt +++ b/doc/lua_api.txt @@ -1931,7 +1931,10 @@ Helper functions * e.g. `string:split("a,b", ",") == {"a","b"}` * `string:trim()` * e.g. `string.trim("\n \t\tfoo bar\t ") == "foo bar"` -* `minetest.pos_to_string({x=X,y=Y,z=Z}, decimal_places))`: returns `"(X,Y,Z)"` +* `minetest.wrap_text(str, limit)`: returns a string + * Adds new lines to the string to keep it within the specified character limit + * limit: Maximal amount of characters in one line +* `minetest.pos_to_string({x=X,y=Y,z=Z}, decimal_places))`: returns string `"(X,Y,Z)"` * Convert position to a printable string Optional: 'decimal_places' will round the x, y and z of the pos to the given decimal place. * `minetest.string_to_pos(string)`: returns a position -- cgit v1.2.3 From 9b5effffbb0599f85014b53c3fd025b6a8222e02 Mon Sep 17 00:00:00 2001 From: SmallJoker Date: Wed, 17 May 2017 19:31:57 +0200 Subject: Builtin: Fix subgame mod selection (#5367) --- builtin/common/filterlist.lua | 3 +++ builtin/mainmenu/modmgr.lua | 18 +++++++++--------- 2 files changed, 12 insertions(+), 9 deletions(-) (limited to 'builtin/mainmenu') diff --git a/builtin/common/filterlist.lua b/builtin/common/filterlist.lua index 2a62362e3..562231192 100644 --- a/builtin/common/filterlist.lua +++ b/builtin/common/filterlist.lua @@ -289,6 +289,9 @@ function sort_mod_list(self) table.sort(self.m_processed_list, function(a, b) -- Show game mods at bottom if a.typ ~= b.typ then + if b.typ == "game" then + return a.typ ~= "game_mod" + end return b.typ == "game_mod" end -- If in same or no modpack, sort by name diff --git a/builtin/mainmenu/modmgr.lua b/builtin/mainmenu/modmgr.lua index 0fbfa3e6b..14d29272e 100644 --- a/builtin/mainmenu/modmgr.lua +++ b/builtin/mainmenu/modmgr.lua @@ -238,15 +238,7 @@ function modmgr.render_modlist(render_list) local list = render_list:get_list() local last_modpack = nil local retval = {} - local in_game_mods = false for i, v in ipairs(list) do - if v.typ == "game_mod" and not in_game_mods then - in_game_mods = true - retval[#retval + 1] = mt_color_blue - retval[#retval + 1] = "0" - retval[#retval + 1] = fgettext("Subgame Mods") - end - local color = "" if v.is_modpack then local rawlist = render_list:get_raw_list() @@ -260,7 +252,7 @@ function modmgr.render_modlist(render_list) break end end - elseif v.typ == "game_mod" then + elseif v.typ == "game_mod" or v.typ == "game" then color = mt_color_blue elseif v.enabled then color = mt_color_green @@ -421,6 +413,14 @@ function modmgr.preparemodlist(data) local gamespec = gamemgr.find_by_gameid(data.gameid) gamemgr.get_game_mods(gamespec, game_mods) + if #game_mods > 0 then + -- Add title + retval[#retval + 1] = { + typ = "game", + name = fgettext("Subgame Mods") + } + end + for i=1,#game_mods,1 do game_mods[i].typ = "game_mod" retval[#retval + 1] = game_mods[i] -- cgit v1.2.3 From 674400523e10624ae8320b0d18a05dbfd6dcac42 Mon Sep 17 00:00:00 2001 From: SmallJoker Date: Fri, 19 May 2017 07:45:47 +0200 Subject: Mainmenu: Fix issues while trying to enable all mods (#5770) --- builtin/mainmenu/dlg_config_world.lua | 24 +++++++++++++----------- builtin/mainmenu/modmgr.lua | 4 +++- src/client.cpp | 2 +- src/server.cpp | 2 +- src/serverenvironment.cpp | 2 +- 5 files changed, 19 insertions(+), 15 deletions(-) (limited to 'builtin/mainmenu') diff --git a/builtin/mainmenu/dlg_config_world.lua b/builtin/mainmenu/dlg_config_world.lua index 3e5ba16eb..fcedadea8 100644 --- a/builtin/mainmenu/dlg_config_world.lua +++ b/builtin/mainmenu/dlg_config_world.lua @@ -49,7 +49,7 @@ local function get_formspec(data) "button[3.25,7;2.5,0.5;btn_config_world_save;" .. fgettext("Save") .. "]" .. "button[5.75,7;2.5,0.5;btn_config_world_cancel;" .. fgettext("Cancel") .. "]" - if mod and mod.name ~= "" and mod.typ ~= "game_mod" then + if mod and mod.name ~= "" and not mod.is_game_content then if mod.is_modpack then local rawlist = data.list:get_raw_list() @@ -97,7 +97,7 @@ end local function enable_mod(this, toset) local mod = this.data.list:get_list()[this.data.selected_mod] - if mod.typ == "game_mod" then + if mod.is_game_content then -- game mods can't be enabled or disabled elseif not mod.is_modpack then if toset == nil then @@ -162,7 +162,7 @@ local function handle_buttons(this, fields) local i,mod for i,mod in ipairs(rawlist) do if not mod.is_modpack and - mod.typ ~= "game_mod" then + not mod.is_game_content then if modname_valid(mod.name) then worldfile:set("load_mod_"..mod.name, tostring(mod.enabled)) else @@ -198,7 +198,8 @@ local function handle_buttons(this, fields) local list = this.data.list:get_raw_list() for i = 1, #list do - if list[i].typ ~= "game_mod" and not list[i].is_modpack then + if not list[i].is_game_content + and not list[i].is_modpack then list[i].enabled = true end end @@ -210,7 +211,8 @@ local function handle_buttons(this, fields) local list = this.data.list:get_raw_list() for i = 1, #list do - if list[i].typ ~= "game_mod" and not list[i].is_modpack then + if not list[i].is_game_content + and not list[i].is_modpack then list[i].enabled = false end end @@ -252,16 +254,16 @@ function create_configure_world_dlg(worldidx) return true end end, - function(element,criteria) + function(element, criteria) if criteria.hide_game and - element.typ == "game_mod" then - return false + element.is_game_content then + return false end if criteria.hide_modpackcontents and - element.modpack ~= nil then - return false - end + element.modpack ~= nil then + return false + end return true end, --filter { worldpath= dlg.data.worldspec.path, diff --git a/builtin/mainmenu/modmgr.lua b/builtin/mainmenu/modmgr.lua index 14d29272e..dee048982 100644 --- a/builtin/mainmenu/modmgr.lua +++ b/builtin/mainmenu/modmgr.lua @@ -252,7 +252,7 @@ function modmgr.render_modlist(render_list) break end end - elseif v.typ == "game_mod" or v.typ == "game" then + elseif v.is_game_content then color = mt_color_blue elseif v.enabled then color = mt_color_green @@ -417,12 +417,14 @@ function modmgr.preparemodlist(data) -- Add title retval[#retval + 1] = { typ = "game", + is_game_content = true, name = fgettext("Subgame Mods") } end for i=1,#game_mods,1 do game_mods[i].typ = "game_mod" + game_mods[i].is_game_content = true retval[#retval + 1] = game_mods[i] end diff --git a/src/client.cpp b/src/client.cpp index 6ab4002a5..5f2d2d9d2 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -171,7 +171,7 @@ void Client::initMods() if (!string_allowed(mod.name, MODNAME_ALLOWED_CHARS)) { throw ModError("Error loading mod \"" + mod.name + "\": Mod name does not follow naming conventions: " - "Only chararacters [a-z0-9_] are allowed."); + "Only characters [a-z0-9_] are allowed."); } std::string script_path = mod.path + DIR_DELIM + "init.lua"; infostream << " [" << padStringRight(mod.name, 12) << "] [\"" diff --git a/src/server.cpp b/src/server.cpp index 5400dd595..6889451d9 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -283,7 +283,7 @@ Server::Server( if (!string_allowed(mod.name, MODNAME_ALLOWED_CHARS)) { throw ModError("Error loading mod \"" + mod.name + "\": Mod name does not follow naming conventions: " - "Only chararacters [a-z0-9_] are allowed."); + "Only characters [a-z0-9_] are allowed."); } std::string script_path = mod.path + DIR_DELIM + "init.lua"; infostream << " [" << padStringRight(mod.name, 12) << "] [\"" diff --git a/src/serverenvironment.cpp b/src/serverenvironment.cpp index 4d2c87a4d..892c6c55b 100644 --- a/src/serverenvironment.cpp +++ b/src/serverenvironment.cpp @@ -141,7 +141,7 @@ void LBMManager::addLBMDef(LoadingBlockModifierDef *lbm_def) if (!string_allowed(lbm_def->name, LBM_NAME_ALLOWED_CHARS)) { throw ModError("Error adding LBM \"" + lbm_def->name + "\": Does not follow naming conventions: " - "Only chararacters [a-z0-9_:] are allowed."); + "Only characters [a-z0-9_:] are allowed."); } m_lbm_defs[lbm_def->name] = lbm_def; -- cgit v1.2.3 From 4dc97eb99fdbeec186cce5b03c64fb1df319d19d Mon Sep 17 00:00:00 2001 From: Elijah Duffy Date: Sun, 21 May 2017 01:07:05 -0700 Subject: Menu: Merge singleplayer and server tabs (#5627) Rename "Singleplayer" tab to "Play" and remove "Server" tab placing server functionality under a "Host Game" checkbox in "Play." --- builtin/mainmenu/init.lua | 11 +- builtin/mainmenu/tab_local.lua | 317 ++++++++++++++++++++++++++++++ builtin/mainmenu/tab_multiplayer.lua | 350 ---------------------------------- builtin/mainmenu/tab_online.lua | 350 ++++++++++++++++++++++++++++++++++ builtin/mainmenu/tab_server.lua | 195 ------------------- builtin/mainmenu/tab_singleplayer.lua | 250 ------------------------ 6 files changed, 671 insertions(+), 802 deletions(-) create mode 100644 builtin/mainmenu/tab_local.lua delete mode 100644 builtin/mainmenu/tab_multiplayer.lua create mode 100644 builtin/mainmenu/tab_online.lua delete mode 100644 builtin/mainmenu/tab_server.lua delete mode 100644 builtin/mainmenu/tab_singleplayer.lua (limited to 'builtin/mainmenu') diff --git a/builtin/mainmenu/init.lua b/builtin/mainmenu/init.lua index 492bb22d6..7c6af7d27 100644 --- a/builtin/mainmenu/init.lua +++ b/builtin/mainmenu/init.lua @@ -56,9 +56,8 @@ tabs.credits = dofile(menupath .. DIR_DELIM .. "tab_credits.lua") if PLATFORM == "Android" then tabs.simple_main = dofile(menupath .. DIR_DELIM .. "tab_simple_main.lua") else - tabs.singleplayer = dofile(menupath .. DIR_DELIM .. "tab_singleplayer.lua") - tabs.multiplayer = dofile(menupath .. DIR_DELIM .. "tab_multiplayer.lua") - tabs.server = dofile(menupath .. DIR_DELIM .. "tab_server.lua") + tabs.local_game = dofile(menupath .. DIR_DELIM .. "tab_local.lua") + tabs.play_online = dofile(menupath .. DIR_DELIM .. "tab_online.lua") tabs.texturepacks = dofile(menupath .. DIR_DELIM .. "tab_texturepacks.lua") end @@ -135,9 +134,8 @@ local function init_globals() tv_main:add(tabs.settings) else tv_main:set_autosave_tab(true) - tv_main:add(tabs.singleplayer) - tv_main:add(tabs.multiplayer) - tv_main:add(tabs.server) + tv_main:add(tabs.local_game) + tv_main:add(tabs.play_online) tv_main:add(tabs.settings) tv_main:add(tabs.texturepacks) end @@ -167,4 +165,3 @@ local function init_globals() end init_globals() - diff --git a/builtin/mainmenu/tab_local.lua b/builtin/mainmenu/tab_local.lua new file mode 100644 index 000000000..3e62078ce --- /dev/null +++ b/builtin/mainmenu/tab_local.lua @@ -0,0 +1,317 @@ +--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 current_game() + local last_game_id = core.settings:get("menu_last_game") + local game, index = gamemgr.find_by_gameid(last_game_id) + + return game +end + +local 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) + for key,value in pairs(fields) do + for j=1,#gamemgr.games,1 do + if ("game_btnbar_" .. gamemgr.games[j].id == key) then + mm_texture.update("singleplayer", gamemgr.games[j]) + core.set_topleft_text(gamemgr.games[j].name) + core.settings:set("menu_last_game",gamemgr.games[j].id) + menudata.worldlist:set_filtercriteria(gamemgr.games[j].id) + 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) + return true + end + 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 i=1,#gamemgr.games,1 do + local btn_name = "game_btnbar_" .. gamemgr.games[i].id + + local image = nil + local text = nil + local tooltip = core.formspec_escape(gamemgr.games[i].name) + + if gamemgr.games[i].menuicon_path ~= nil and + gamemgr.games[i].menuicon_path ~= "" then + image = core.formspec_escape(gamemgr.games[i].menuicon_path) + else + + local part1 = gamemgr.games[i].id:sub(1,5) + local part2 = gamemgr.games[i].id:sub(6,10) + local part3 = gamemgr.games[i].id:sub(11) + + text = part1 .. "\n" .. part2 + if part3 ~= nil and + part3 ~= "" then + text = text .. "\n" .. part3 + end + end + btnbar:add_button(btn_name, text, image, tooltip) + end +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")) + ) + + retval = retval .. + "button[4,4.15;2.6,0.5;world_delete;".. fgettext("Delete") .. "]" .. + "button[6.5,4.15;2.8,0.5;world_create;".. fgettext("New") .. "]" .. + "button[9.2,4.15;2.55,0.5;world_configure;".. fgettext("Configure") .. "]" .. + "label[4,-0.25;".. fgettext("Select World:") .. "]".. + "checkbox[0.25,0.25;cb_creative_mode;".. fgettext("Creative Mode") .. ";" .. + dump(core.settings:get_bool("creative_mode")) .. "]".. + "checkbox[0.25,0.7;cb_enable_damage;".. fgettext("Enable Damage") .. ";" .. + dump(core.settings:get_bool("enable_damage")) .. "]".. + "checkbox[0.25,1.15;cb_server;".. fgettext("Host Server") ..";" .. + dump(core.settings:get_bool("enable_server")) .. "]" .. + "textlist[4,0.25;7.5,3.7;sp_worlds;" .. + menu_render_worldlist() .. + ";" .. index .. "]" + + if core.settings:get_bool("enable_server") then + retval = retval .. + "button[8.5,5;3.25,0.5;play;".. fgettext("Host Game") .. "]" .. + "checkbox[0.25,1.6;cb_server_announce;" .. fgettext("Announce Server") .. ";" .. + dump(core.settings:get_bool("server_announce")) .. "]" .. + "label[0.25,2.2;" .. fgettext("Name/Password") .. "]" .. + "field[0.55,3.2;3.5,0.5;te_playername;;" .. + core.formspec_escape(core.settings:get("name")) .. "]" .. + "pwdfield[0.55,4;3.5,0.5;te_passwd;]" + + local bind_addr = core.settings:get("bind_address") + if bind_addr ~= nil and bind_addr ~= "" then + retval = retval .. + "field[0.55,5.2;2.25,0.5;te_serveraddr;" .. fgettext("Bind Address") .. ";" .. + core.formspec_escape(core.settings:get("bind_address")) .. "]" .. + "field[2.8,5.2;1.25,0.5;te_serverport;" .. fgettext("Port") .. ";" .. + core.formspec_escape(core.settings:get("port")) .. "]" + else + retval = retval .. + "field[0.55,5.2;3.5,0.5;te_serverport;" .. fgettext("Server Port") .. ";" .. + core.formspec_escape(core.settings:get("port")) .. "]" + end + else + retval = retval .. + "button[8.5,5;3.25,0.5;play;".. fgettext("Play Game") .. "]" + end + + return retval +end + +local function main_button_handler(this, fields, name, tabdata) + + assert(name == "local") + + local world_doubleclick = false + + if fields["sp_worlds"] ~= nil then + local event = core.explode_textlist_event(fields["sp_worlds"]) + local selected = core.get_textlist_index("sp_worlds") + + menu_worldmt_legacy(selected) + + if event.type == "DCL" then + world_doubleclick = true + end + + if event.type == "CHG" and selected ~= nil then + core.settings:set("mainmenu_last_selected_world", + menudata.worldlist:get_raw_index(selected)) + return true + end + end + + if menu_handle_key_up_down(fields,"sp_worlds","mainmenu_last_selected_world") then + return true + end + + if fields["cb_creative_mode"] then + core.settings:set("creative_mode", fields["cb_creative_mode"]) + local selected = core.get_textlist_index("sp_worlds") + menu_worldmt(selected, "creative_mode", fields["cb_creative_mode"]) + + return true + end + + if fields["cb_enable_damage"] then + core.settings:set("enable_damage", fields["cb_enable_damage"]) + local selected = core.get_textlist_index("sp_worlds") + menu_worldmt(selected, "enable_damage", fields["cb_enable_damage"]) + + return true + end + + if fields["cb_server"] then + core.settings:set("enable_server", fields["cb_server"]) + + return true + end + + if fields["cb_server_announce"] then + core.settings:set("server_announce", fields["cb_server_announce"]) + local selected = core.get_textlist_index("srv_worlds") + menu_worldmt(selected, "server_announce", fields["cb_server_announce"]) + + return true + end + + if fields["play"] ~= nil or world_doubleclick or fields["key_enter"] then + local selected = core.get_textlist_index("sp_worlds") + gamedata.selected_world = menudata.worldlist:get_raw_index(selected) + + if core.settings:get_bool("enable_server") then + 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"]) + end + + --update last game + local world = menudata.worldlist:get_raw_element(gamedata.selected_world) + if world then + local game, index = gamemgr.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 + 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 + end + + if fields["world_create"] ~= nil then + local create_world_dlg = create_create_world_dlg(true) + create_world_dlg:set_parent(this) + this:hide() + create_world_dlg:show() + mm_texture.update("singleplayer",current_game()) + return true + end + + if fields["world_delete"] ~= nil then + local selected = core.get_textlist_index("sp_worlds") + if selected ~= nil and + selected <= menudata.worldlist:size() then + local world = menudata.worldlist:get_list()[selected] + if world ~= nil and + world.name ~= nil and + world.name ~= "" then + local index = menudata.worldlist:get_raw_index(selected) + local delete_world_dlg = create_delete_world_dlg(world.name,index) + delete_world_dlg:set_parent(this) + this:hide() + delete_world_dlg:show() + mm_texture.update("singleplayer",current_game()) + end + end + + return true + end + + if fields["world_configure"] ~= nil then + local selected = core.get_textlist_index("sp_worlds") + if selected ~= nil then + local configdialog = + create_configure_world_dlg( + menudata.worldlist:get_raw_index(selected)) + + if (configdialog ~= nil) then + configdialog:set_parent(this) + this:hide() + configdialog:show() + mm_texture.update("singleplayer",current_game()) + end + end + + return true + end +end + +local function on_change(type, old_tab, new_tab) + local buttonbar = ui.find_by_name("game_button_bar") + + if ( buttonbar == nil ) then + singleplayer_refresh_gamebar() + buttonbar = ui.find_by_name("game_button_bar") + end + + if (type == "ENTER") then + local game = current_game() + + if game then + menudata.worldlist:set_filtercriteria(game.id) + core.set_topleft_text(game.name) + mm_texture.update("singleplayer",game) + end + buttonbar:show() + else + menudata.worldlist:set_filtercriteria(nil) + buttonbar:hide() + core.set_topleft_text("") + mm_texture.update(new_tab,nil) + end +end + +-------------------------------------------------------------------------------- +return { + name = "local", + caption = fgettext("Local Game"), + cbf_formspec = get_formspec, + cbf_button_handler = main_button_handler, + on_change = on_change +} diff --git a/builtin/mainmenu/tab_multiplayer.lua b/builtin/mainmenu/tab_multiplayer.lua deleted file mode 100644 index f40b707ac..000000000 --- a/builtin/mainmenu/tab_multiplayer.lua +++ /dev/null @@ -1,350 +0,0 @@ ---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 get_formspec(tabview, name, tabdata) - -- Update the cached supported proto info, - -- it may have changed after a change by the settings menu. - common_update_cached_supp_proto() - local fav_selected = nil - if menudata.search_result then - fav_selected = menudata.search_result[tabdata.fav_selected] - else - fav_selected = menudata.favorites[tabdata.fav_selected] - end - - if not tabdata.search_for then - tabdata.search_for = "" - end - - local retval = - -- Search - "field[0.15,0.35;6.05,0.27;te_search;;"..core.formspec_escape(tabdata.search_for).."]".. - "button[5.8,0.1;2,0.1;btn_mp_search;" .. fgettext("Search") .. "]" .. - - -- Address / Port - "label[7.75,-0.25;" .. fgettext("Address / Port") .. "]" .. - "field[8,0.65;3.25,0.5;te_address;;" .. - core.formspec_escape(core.settings:get("address")) .. "]" .. - "field[11.1,0.65;1.4,0.5;te_port;;" .. - core.formspec_escape(core.settings:get("remote_port")) .. "]" .. - - -- Name / Password - "label[7.75,0.95;" .. fgettext("Name / Password") .. "]" .. - "field[8,1.85;2.9,0.5;te_name;;" .. - core.formspec_escape(core.settings:get("name")) .. "]" .. - "pwdfield[10.73,1.85;1.77,0.5;te_pwd;]" .. - - -- Description Background - "box[7.73,2.25;4.25,2.6;#999999]".. - - -- Connect - "button[10.1,5.15;2,0.5;btn_mp_connect;" .. fgettext("Connect") .. "]" - - if tabdata.fav_selected and fav_selected then - if gamedata.fav then - retval = retval .. "button[7.75,5.15;2.3,0.5;btn_delete_favorite;" .. - fgettext("Del. Favorite") .. "]" - end - if fav_selected.description then - retval = retval .. "textarea[8.1,2.3;4.23,2.9;;" .. - core.formspec_escape((gamedata.serverdescription or ""), true) .. ";]" - end - end - - --favourites - retval = retval .. "tablecolumns[" .. - image_column(fgettext("Favorite"), "favorite") .. ";" .. - image_column(fgettext("Ping")) .. ",padding=0.25;" .. - "color,span=3;" .. - "text,align=right;" .. -- clients - "text,align=center,padding=0.25;" .. -- "/" - "text,align=right,padding=0.25;" .. -- clients_max - image_column(fgettext("Creative mode"), "creative") .. ",padding=1;" .. - image_column(fgettext("Damage enabled"), "damage") .. ",padding=0.25;" .. - image_column(fgettext("PvP enabled"), "pvp") .. ",padding=0.25;" .. - "color,span=1;" .. - "text,padding=1]" .. - "table[-0.15,0.6;7.75,5.15;favourites;" - - if menudata.search_result then - for i = 1, #menudata.search_result do - local favs = core.get_favorites("local") - local server = menudata.search_result[i] - - for fav_id = 1, #favs do - if server.address == favs[fav_id].address and - server.port == favs[fav_id].port then - server.is_favorite = true - end - end - - if i ~= 1 then - retval = retval .. "," - end - - retval = retval .. render_serverlist_row(server, server.is_favorite) - end - elseif #menudata.favorites > 0 then - local favs = core.get_favorites("local") - if #favs > 0 then - for i = 1, #favs do - for j = 1, #menudata.favorites do - if menudata.favorites[j].address == favs[i].address and - menudata.favorites[j].port == favs[i].port then - table.insert(menudata.favorites, i, table.remove(menudata.favorites, j)) - end - end - if favs[i].address ~= menudata.favorites[i].address then - table.insert(menudata.favorites, i, favs[i]) - end - end - end - retval = retval .. render_serverlist_row(menudata.favorites[1], (#favs > 0)) - for i = 2, #menudata.favorites do - retval = retval .. "," .. render_serverlist_row(menudata.favorites[i], (i <= #favs)) - end - end - - if tabdata.fav_selected then - retval = retval .. ";" .. tabdata.fav_selected .. "]" - else - retval = retval .. ";0]" - end - - return retval -end - --------------------------------------------------------------------------------- -local function main_button_handler(tabview, fields, name, tabdata) - local serverlist = menudata.search_result or menudata.favorites - - if fields.te_name then - gamedata.playername = fields.te_name - core.settings:set("name", fields.te_name) - end - - if fields.favourites then - local event = core.explode_table_event(fields.favourites) - local fav = serverlist[event.row] - - if event.type == "DCL" then - if event.row <= #serverlist then - if menudata.favorites_is_public and - not is_server_protocol_compat_or_error( - fav.proto_min, fav.proto_max) then - return true - end - - gamedata.address = fav.address - gamedata.port = fav.port - gamedata.playername = fields.te_name - gamedata.selected_world = 0 - - if fields.te_pwd then - gamedata.password = fields.te_pwd - end - - gamedata.servername = fav.name - gamedata.serverdescription = fav.description - - if gamedata.address and gamedata.port then - core.settings:set("address", gamedata.address) - core.settings:set("remote_port", gamedata.port) - core.start() - end - end - return true - end - - if event.type == "CHG" then - if event.row <= #serverlist then - gamedata.fav = false - local favs = core.get_favorites("local") - local address = fav.address - local port = fav.port - gamedata.serverdescription = fav.description - - for i = 1, #favs do - if fav.address == favs[i].address and - fav.port == favs[i].port then - gamedata.fav = true - end - end - - if address and port then - core.settings:set("address", address) - core.settings:set("remote_port", port) - end - tabdata.fav_selected = event.row - end - return true - end - end - - if fields.key_up or fields.key_down then - local fav_idx = core.get_table_index("favourites") - local fav = serverlist[fav_idx] - - if fav_idx then - if fields.key_up and fav_idx > 1 then - fav_idx = fav_idx - 1 - elseif fields.key_down and fav_idx < #menudata.favorites then - fav_idx = fav_idx + 1 - end - else - fav_idx = 1 - end - - if not menudata.favorites or not fav then - tabdata.fav_selected = 0 - return true - end - - local address = fav.address - local port = fav.port - gamedata.serverdescription = fav.description - if address and port then - core.settings:set("address", address) - core.settings:set("remote_port", port) - end - - tabdata.fav_selected = fav_idx - return true - end - - if fields.btn_delete_favorite then - local current_favourite = core.get_table_index("favourites") - if not current_favourite then return end - - core.delete_favorite(current_favourite) - asyncOnlineFavourites() - tabdata.fav_selected = nil - - core.settings:set("address", "") - core.settings:set("remote_port", "30000") - return true - end - - if fields.btn_mp_search or fields.key_enter_field == "te_search" then - tabdata.fav_selected = 1 - local input = fields.te_search:lower() - tabdata.search_for = fields.te_search - - if #menudata.favorites < 2 then - return true - end - - menudata.search_result = {} - - -- setup the keyword list - local keywords = {} - for word in input:gmatch("%S+") do - table.insert(keywords, word) - end - - if #keywords == 0 then - menudata.search_result = nil - return true - end - - -- Search the serverlist - local search_result = {} - for i = 1, #menudata.favorites do - local server = menudata.favorites[i] - local found = 0 - for k = 1, #keywords do - local keyword = keywords[k] - if server.name then - local name = server.name:lower() - local _, count = name:gsub(keyword, keyword) - found = found + count * 4 - end - - if server.description then - local desc = server.description:lower() - local _, count = desc:gsub(keyword, keyword) - found = found + count * 2 - end - end - if found > 0 then - local points = (#menudata.favorites - i) / 5 + found - server.points = points - table.insert(search_result, server) - end - end - if #search_result > 0 then - table.sort(search_result, function(a, b) - return a.points > b.points - end) - menudata.search_result = search_result - local first_server = search_result[1] - core.settings:set("address", first_server.address) - core.settings:set("remote_port", first_server.port) - end - return true - end - - if (fields.btn_mp_connect or fields.key_enter) - and fields.te_address ~= "" and fields.te_port then - gamedata.playername = fields.te_name - gamedata.password = fields.te_pwd - gamedata.address = fields.te_address - gamedata.port = fields.te_port - gamedata.selected_world = 0 - local fav_idx = core.get_table_index("favourites") - local fav = serverlist[fav_idx] - - if fav_idx and fav_idx <= #serverlist and - fav.address == fields.te_address and - fav.port == fields.te_port then - - gamedata.servername = fav.name - gamedata.serverdescription = fav.description - - if menudata.favorites_is_public and - not is_server_protocol_compat_or_error( - fav.proto_min, fav.proto_max) then - return true - end - else - gamedata.servername = "" - gamedata.serverdescription = "" - end - - core.settings:set("address", fields.te_address) - core.settings:set("remote_port", fields.te_port) - - core.start() - return true - end - return false -end - -local function on_change(type, old_tab, new_tab) - if type == "LEAVE" then return end - asyncOnlineFavourites() -end - --------------------------------------------------------------------------------- -return { - name = "multiplayer", - caption = fgettext("Client"), - cbf_formspec = get_formspec, - cbf_button_handler = main_button_handler, - on_change = on_change -} diff --git a/builtin/mainmenu/tab_online.lua b/builtin/mainmenu/tab_online.lua new file mode 100644 index 000000000..ab23a4b7c --- /dev/null +++ b/builtin/mainmenu/tab_online.lua @@ -0,0 +1,350 @@ +--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 get_formspec(tabview, name, tabdata) + -- Update the cached supported proto info, + -- it may have changed after a change by the settings menu. + common_update_cached_supp_proto() + local fav_selected = nil + if menudata.search_result then + fav_selected = menudata.search_result[tabdata.fav_selected] + else + fav_selected = menudata.favorites[tabdata.fav_selected] + end + + if not tabdata.search_for then + tabdata.search_for = "" + end + + local retval = + -- Search + "field[0.15,0.35;6.05,0.27;te_search;;"..core.formspec_escape(tabdata.search_for).."]".. + "button[5.8,0.1;2,0.1;btn_mp_search;" .. fgettext("Search") .. "]" .. + + -- Address / Port + "label[7.75,-0.25;" .. fgettext("Address / Port") .. "]" .. + "field[8,0.65;3.25,0.5;te_address;;" .. + core.formspec_escape(core.settings:get("address")) .. "]" .. + "field[11.1,0.65;1.4,0.5;te_port;;" .. + core.formspec_escape(core.settings:get("remote_port")) .. "]" .. + + -- Name / Password + "label[7.75,0.95;" .. fgettext("Name / Password") .. "]" .. + "field[8,1.85;2.9,0.5;te_name;;" .. + core.formspec_escape(core.settings:get("name")) .. "]" .. + "pwdfield[10.73,1.85;1.77,0.5;te_pwd;]" .. + + -- Description Background + "box[7.73,2.25;4.25,2.6;#999999]".. + + -- Connect + "button[10.1,5.15;2,0.5;btn_mp_connect;" .. fgettext("Connect") .. "]" + + if tabdata.fav_selected and fav_selected then + if gamedata.fav then + retval = retval .. "button[7.75,5.15;2.3,0.5;btn_delete_favorite;" .. + fgettext("Del. Favorite") .. "]" + end + if fav_selected.description then + retval = retval .. "textarea[8.1,2.3;4.23,2.9;;" .. + core.formspec_escape((gamedata.serverdescription or ""), true) .. ";]" + end + end + + --favourites + retval = retval .. "tablecolumns[" .. + image_column(fgettext("Favorite"), "favorite") .. ";" .. + image_column(fgettext("Ping")) .. ",padding=0.25;" .. + "color,span=3;" .. + "text,align=right;" .. -- clients + "text,align=center,padding=0.25;" .. -- "/" + "text,align=right,padding=0.25;" .. -- clients_max + image_column(fgettext("Creative mode"), "creative") .. ",padding=1;" .. + image_column(fgettext("Damage enabled"), "damage") .. ",padding=0.25;" .. + image_column(fgettext("PvP enabled"), "pvp") .. ",padding=0.25;" .. + "color,span=1;" .. + "text,padding=1]" .. + "table[-0.15,0.6;7.75,5.15;favourites;" + + if menudata.search_result then + for i = 1, #menudata.search_result do + local favs = core.get_favorites("local") + local server = menudata.search_result[i] + + for fav_id = 1, #favs do + if server.address == favs[fav_id].address and + server.port == favs[fav_id].port then + server.is_favorite = true + end + end + + if i ~= 1 then + retval = retval .. "," + end + + retval = retval .. render_serverlist_row(server, server.is_favorite) + end + elseif #menudata.favorites > 0 then + local favs = core.get_favorites("local") + if #favs > 0 then + for i = 1, #favs do + for j = 1, #menudata.favorites do + if menudata.favorites[j].address == favs[i].address and + menudata.favorites[j].port == favs[i].port then + table.insert(menudata.favorites, i, table.remove(menudata.favorites, j)) + end + end + if favs[i].address ~= menudata.favorites[i].address then + table.insert(menudata.favorites, i, favs[i]) + end + end + end + retval = retval .. render_serverlist_row(menudata.favorites[1], (#favs > 0)) + for i = 2, #menudata.favorites do + retval = retval .. "," .. render_serverlist_row(menudata.favorites[i], (i <= #favs)) + end + end + + if tabdata.fav_selected then + retval = retval .. ";" .. tabdata.fav_selected .. "]" + else + retval = retval .. ";0]" + end + + return retval +end + +-------------------------------------------------------------------------------- +local function main_button_handler(tabview, fields, name, tabdata) + local serverlist = menudata.search_result or menudata.favorites + + if fields.te_name then + gamedata.playername = fields.te_name + core.settings:set("name", fields.te_name) + end + + if fields.favourites then + local event = core.explode_table_event(fields.favourites) + local fav = serverlist[event.row] + + if event.type == "DCL" then + if event.row <= #serverlist then + if menudata.favorites_is_public and + not is_server_protocol_compat_or_error( + fav.proto_min, fav.proto_max) then + return true + end + + gamedata.address = fav.address + gamedata.port = fav.port + gamedata.playername = fields.te_name + gamedata.selected_world = 0 + + if fields.te_pwd then + gamedata.password = fields.te_pwd + end + + gamedata.servername = fav.name + gamedata.serverdescription = fav.description + + if gamedata.address and gamedata.port then + core.settings:set("address", gamedata.address) + core.settings:set("remote_port", gamedata.port) + core.start() + end + end + return true + end + + if event.type == "CHG" then + if event.row <= #serverlist then + gamedata.fav = false + local favs = core.get_favorites("local") + local address = fav.address + local port = fav.port + gamedata.serverdescription = fav.description + + for i = 1, #favs do + if fav.address == favs[i].address and + fav.port == favs[i].port then + gamedata.fav = true + end + end + + if address and port then + core.settings:set("address", address) + core.settings:set("remote_port", port) + end + tabdata.fav_selected = event.row + end + return true + end + end + + if fields.key_up or fields.key_down then + local fav_idx = core.get_table_index("favourites") + local fav = serverlist[fav_idx] + + if fav_idx then + if fields.key_up and fav_idx > 1 then + fav_idx = fav_idx - 1 + elseif fields.key_down and fav_idx < #menudata.favorites then + fav_idx = fav_idx + 1 + end + else + fav_idx = 1 + end + + if not menudata.favorites or not fav then + tabdata.fav_selected = 0 + return true + end + + local address = fav.address + local port = fav.port + gamedata.serverdescription = fav.description + if address and port then + core.settings:set("address", address) + core.settings:set("remote_port", port) + end + + tabdata.fav_selected = fav_idx + return true + end + + if fields.btn_delete_favorite then + local current_favourite = core.get_table_index("favourites") + if not current_favourite then return end + + core.delete_favorite(current_favourite) + asyncOnlineFavourites() + tabdata.fav_selected = nil + + core.settings:set("address", "") + core.settings:set("remote_port", "30000") + return true + end + + if fields.btn_mp_search or fields.key_enter_field == "te_search" then + tabdata.fav_selected = 1 + local input = fields.te_search:lower() + tabdata.search_for = fields.te_search + + if #menudata.favorites < 2 then + return true + end + + menudata.search_result = {} + + -- setup the keyword list + local keywords = {} + for word in input:gmatch("%S+") do + table.insert(keywords, word) + end + + if #keywords == 0 then + menudata.search_result = nil + return true + end + + -- Search the serverlist + local search_result = {} + for i = 1, #menudata.favorites do + local server = menudata.favorites[i] + local found = 0 + for k = 1, #keywords do + local keyword = keywords[k] + if server.name then + local name = server.name:lower() + local _, count = name:gsub(keyword, keyword) + found = found + count * 4 + end + + if server.description then + local desc = server.description:lower() + local _, count = desc:gsub(keyword, keyword) + found = found + count * 2 + end + end + if found > 0 then + local points = (#menudata.favorites - i) / 5 + found + server.points = points + table.insert(search_result, server) + end + end + if #search_result > 0 then + table.sort(search_result, function(a, b) + return a.points > b.points + end) + menudata.search_result = search_result + local first_server = search_result[1] + core.settings:set("address", first_server.address) + core.settings:set("remote_port", first_server.port) + end + return true + end + + if (fields.btn_mp_connect or fields.key_enter) + and fields.te_address ~= "" and fields.te_port then + gamedata.playername = fields.te_name + gamedata.password = fields.te_pwd + gamedata.address = fields.te_address + gamedata.port = fields.te_port + gamedata.selected_world = 0 + local fav_idx = core.get_table_index("favourites") + local fav = serverlist[fav_idx] + + if fav_idx and fav_idx <= #serverlist and + fav.address == fields.te_address and + fav.port == fields.te_port then + + gamedata.servername = fav.name + gamedata.serverdescription = fav.description + + if menudata.favorites_is_public and + not is_server_protocol_compat_or_error( + fav.proto_min, fav.proto_max) then + return true + end + else + gamedata.servername = "" + gamedata.serverdescription = "" + end + + core.settings:set("address", fields.te_address) + core.settings:set("remote_port", fields.te_port) + + core.start() + return true + end + return false +end + +local function on_change(type, old_tab, new_tab) + if type == "LEAVE" then return end + asyncOnlineFavourites() +end + +-------------------------------------------------------------------------------- +return { + name = "online", + caption = fgettext("Play Online"), + cbf_formspec = get_formspec, + cbf_button_handler = main_button_handler, + on_change = on_change +} diff --git a/builtin/mainmenu/tab_server.lua b/builtin/mainmenu/tab_server.lua deleted file mode 100644 index 8f25ce871..000000000 --- a/builtin/mainmenu/tab_server.lua +++ /dev/null @@ -1,195 +0,0 @@ ---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 get_formspec(tabview, name, tabdata) - - local index = menudata.worldlist:get_current_index( - tonumber(core.settings:get("mainmenu_last_selected_world")) - ) - - local retval = - "button[4,4.15;2.6,0.5;world_delete;" .. fgettext("Delete") .. "]" .. - "button[6.5,4.15;2.8,0.5;world_create;" .. fgettext("New") .. "]" .. - "button[9.2,4.15;2.55,0.5;world_configure;" .. fgettext("Configure") .. "]" .. - "button[8.5,5;3.25,0.5;start_server;" .. fgettext("Start Game") .. "]" .. - "label[4,-0.25;" .. fgettext("Select World:") .. "]" .. - "checkbox[0.25,0.25;cb_creative_mode;" .. fgettext("Creative Mode") .. ";" .. - dump(core.settings:get_bool("creative_mode")) .. "]" .. - "checkbox[0.25,0.7;cb_enable_damage;" .. fgettext("Enable Damage") .. ";" .. - dump(core.settings:get_bool("enable_damage")) .. "]" .. - "checkbox[0.25,1.15;cb_server_announce;" .. fgettext("Public") .. ";" .. - dump(core.settings:get_bool("server_announce")) .. "]" .. - "label[0.25,2.2;" .. fgettext("Name/Password") .. "]" .. - "field[0.55,3.2;3.5,0.5;te_playername;;" .. - core.formspec_escape(core.settings:get("name")) .. "]" .. - "pwdfield[0.55,4;3.5,0.5;te_passwd;]" - - local bind_addr = core.settings:get("bind_address") - if bind_addr ~= nil and bind_addr ~= "" then - retval = retval .. - "field[0.55,5.2;2.25,0.5;te_serveraddr;" .. fgettext("Bind Address") .. ";" .. - core.formspec_escape(core.settings:get("bind_address")) .. "]" .. - "field[2.8,5.2;1.25,0.5;te_serverport;" .. fgettext("Port") .. ";" .. - core.formspec_escape(core.settings:get("port")) .. "]" - else - retval = retval .. - "field[0.55,5.2;3.5,0.5;te_serverport;" .. fgettext("Server Port") .. ";" .. - core.formspec_escape(core.settings:get("port")) .. "]" - end - - retval = retval .. - "textlist[4,0.25;7.5,3.7;srv_worlds;" .. - menu_render_worldlist() .. - ";" .. index .. "]" - - return retval -end - --------------------------------------------------------------------------------- -local function main_button_handler(this, fields, name, tabdata) - - local world_doubleclick = false - - if fields["srv_worlds"] ~= nil then - local event = core.explode_textlist_event(fields["srv_worlds"]) - local selected = core.get_textlist_index("srv_worlds") - - menu_worldmt_legacy(selected) - - if event.type == "DCL" then - world_doubleclick = true - end - if event.type == "CHG" then - core.settings:set("mainmenu_last_selected_world", - menudata.worldlist:get_raw_index(core.get_textlist_index("srv_worlds"))) - return true - end - end - - if menu_handle_key_up_down(fields,"srv_worlds","mainmenu_last_selected_world") then - return true - end - - if fields["cb_creative_mode"] then - core.settings:set("creative_mode", fields["cb_creative_mode"]) - local selected = core.get_textlist_index("srv_worlds") - menu_worldmt(selected, "creative_mode", fields["cb_creative_mode"]) - - return true - end - - if fields["cb_enable_damage"] then - core.settings:set("enable_damage", fields["cb_enable_damage"]) - local selected = core.get_textlist_index("srv_worlds") - menu_worldmt(selected, "enable_damage", fields["cb_enable_damage"]) - - return true - end - - if fields["cb_server_announce"] then - core.settings:set("server_announce", fields["cb_server_announce"]) - local selected = core.get_textlist_index("srv_worlds") - menu_worldmt(selected, "server_announce", fields["cb_server_announce"]) - - return true - end - - if fields["start_server"] ~= nil or - world_doubleclick or - fields["key_enter"] then - local selected = core.get_textlist_index("srv_worlds") - gamedata.selected_world = menudata.worldlist:get_raw_index(selected) - 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"]) - end - - --update last game - local world = menudata.worldlist:get_raw_element(gamedata.selected_world) - if world then - local game, index = gamemgr.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 - return true - end - - if fields["world_create"] ~= nil then - local create_world_dlg = create_create_world_dlg(true) - create_world_dlg:set_parent(this) - create_world_dlg:show() - this:hide() - return true - end - - if fields["world_delete"] ~= nil then - local selected = core.get_textlist_index("srv_worlds") - if selected ~= nil and - selected <= menudata.worldlist:size() then - local world = menudata.worldlist:get_list()[selected] - if world ~= nil and - world.name ~= nil and - world.name ~= "" then - local index = menudata.worldlist:get_raw_index(selected) - local delete_world_dlg = create_delete_world_dlg(world.name,index) - delete_world_dlg:set_parent(this) - delete_world_dlg:show() - this:hide() - end - end - - return true - end - - if fields["world_configure"] ~= nil then - local selected = core.get_textlist_index("srv_worlds") - if selected ~= nil then - local configdialog = - create_configure_world_dlg( - menudata.worldlist:get_raw_index(selected)) - - if (configdialog ~= nil) then - configdialog:set_parent(this) - configdialog:show() - this:hide() - end - end - return true - end - return false -end - --------------------------------------------------------------------------------- -return { - name = "server", - caption = fgettext("Server"), - cbf_formspec = get_formspec, - cbf_button_handler = main_button_handler, - on_change = nil -} diff --git a/builtin/mainmenu/tab_singleplayer.lua b/builtin/mainmenu/tab_singleplayer.lua deleted file mode 100644 index c58ad4164..000000000 --- a/builtin/mainmenu/tab_singleplayer.lua +++ /dev/null @@ -1,250 +0,0 @@ ---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 current_game() - local last_game_id = core.settings:get("menu_last_game") - local game, index = gamemgr.find_by_gameid(last_game_id) - - return game -end - -local 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) - for key,value in pairs(fields) do - for j=1,#gamemgr.games,1 do - if ("game_btnbar_" .. gamemgr.games[j].id == key) then - mm_texture.update("singleplayer", gamemgr.games[j]) - core.set_topleft_text(gamemgr.games[j].name) - core.settings:set("menu_last_game",gamemgr.games[j].id) - menudata.worldlist:set_filtercriteria(gamemgr.games[j].id) - 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) - return true - end - 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 i=1,#gamemgr.games,1 do - local btn_name = "game_btnbar_" .. gamemgr.games[i].id - - local image = nil - local text = nil - local tooltip = core.formspec_escape(gamemgr.games[i].name) - - if gamemgr.games[i].menuicon_path ~= nil and - gamemgr.games[i].menuicon_path ~= "" then - image = core.formspec_escape(gamemgr.games[i].menuicon_path) - else - - local part1 = gamemgr.games[i].id:sub(1,5) - local part2 = gamemgr.games[i].id:sub(6,10) - local part3 = gamemgr.games[i].id:sub(11) - - text = part1 .. "\n" .. part2 - if part3 ~= nil and - part3 ~= "" then - text = text .. "\n" .. part3 - end - end - btnbar:add_button(btn_name, text, image, tooltip) - end -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")) - ) - - retval = retval .. - "button[4,4.15;2.6,0.5;world_delete;".. fgettext("Delete") .. "]" .. - "button[6.5,4.15;2.8,0.5;world_create;".. fgettext("New") .. "]" .. - "button[9.2,4.15;2.55,0.5;world_configure;".. fgettext("Configure") .. "]" .. - "button[8.5,5;3.25,0.5;play;".. fgettext("Play") .. "]" .. - "label[4,-0.25;".. fgettext("Select World:") .. "]".. - "checkbox[0.25,0.25;cb_creative_mode;".. fgettext("Creative Mode") .. ";" .. - dump(core.settings:get_bool("creative_mode")) .. "]".. - "checkbox[0.25,0.7;cb_enable_damage;".. fgettext("Enable Damage") .. ";" .. - dump(core.settings:get_bool("enable_damage")) .. "]".. - "textlist[4,0.25;7.5,3.7;sp_worlds;" .. - menu_render_worldlist() .. - ";" .. index .. "]" - return retval -end - -local function main_button_handler(this, fields, name, tabdata) - - assert(name == "singleplayer") - - local world_doubleclick = false - - if fields["sp_worlds"] ~= nil then - local event = core.explode_textlist_event(fields["sp_worlds"]) - local selected = core.get_textlist_index("sp_worlds") - - menu_worldmt_legacy(selected) - - if event.type == "DCL" then - world_doubleclick = true - end - - if event.type == "CHG" and selected ~= nil then - core.settings:set("mainmenu_last_selected_world", - menudata.worldlist:get_raw_index(selected)) - return true - end - end - - if menu_handle_key_up_down(fields,"sp_worlds","mainmenu_last_selected_world") then - return true - end - - if fields["cb_creative_mode"] then - core.settings:set("creative_mode", fields["cb_creative_mode"]) - local selected = core.get_textlist_index("sp_worlds") - menu_worldmt(selected, "creative_mode", fields["cb_creative_mode"]) - - return true - end - - if fields["cb_enable_damage"] then - core.settings:set("enable_damage", fields["cb_enable_damage"]) - local selected = core.get_textlist_index("sp_worlds") - menu_worldmt(selected, "enable_damage", fields["cb_enable_damage"]) - - return true - end - - if fields["play"] ~= nil or - world_doubleclick or - fields["key_enter"] then - local selected = core.get_textlist_index("sp_worlds") - gamedata.selected_world = menudata.worldlist:get_raw_index(selected) - - 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 - - if fields["world_create"] ~= nil then - local create_world_dlg = create_create_world_dlg(true) - create_world_dlg:set_parent(this) - this:hide() - create_world_dlg:show() - mm_texture.update("singleplayer",current_game()) - return true - end - - if fields["world_delete"] ~= nil then - local selected = core.get_textlist_index("sp_worlds") - if selected ~= nil and - selected <= menudata.worldlist:size() then - local world = menudata.worldlist:get_list()[selected] - if world ~= nil and - world.name ~= nil and - world.name ~= "" then - local index = menudata.worldlist:get_raw_index(selected) - local delete_world_dlg = create_delete_world_dlg(world.name,index) - delete_world_dlg:set_parent(this) - this:hide() - delete_world_dlg:show() - mm_texture.update("singleplayer",current_game()) - end - end - - return true - end - - if fields["world_configure"] ~= nil then - local selected = core.get_textlist_index("sp_worlds") - if selected ~= nil then - local configdialog = - create_configure_world_dlg( - menudata.worldlist:get_raw_index(selected)) - - if (configdialog ~= nil) then - configdialog:set_parent(this) - this:hide() - configdialog:show() - mm_texture.update("singleplayer",current_game()) - end - end - - return true - end -end - -local function on_change(type, old_tab, new_tab) - local buttonbar = ui.find_by_name("game_button_bar") - - if ( buttonbar == nil ) then - singleplayer_refresh_gamebar() - buttonbar = ui.find_by_name("game_button_bar") - end - - if (type == "ENTER") then - local game = current_game() - - if game then - menudata.worldlist:set_filtercriteria(game.id) - core.set_topleft_text(game.name) - mm_texture.update("singleplayer",game) - end - buttonbar:show() - else - menudata.worldlist:set_filtercriteria(nil) - buttonbar:hide() - core.set_topleft_text("") - mm_texture.update(new_tab,nil) - end -end - --------------------------------------------------------------------------------- -return { - name = "singleplayer", - caption = fgettext("Singleplayer"), - cbf_formspec = get_formspec, - cbf_button_handler = main_button_handler, - on_change = on_change -} -- cgit v1.2.3 From e8fb1f79bcd4261e2ed58f2f4286994d947572e2 Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Wed, 24 May 2017 06:45:23 +0100 Subject: Add formspec escaping to subgame list in create world dialog (#5808) --- builtin/mainmenu/gamemgr.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'builtin/mainmenu') diff --git a/builtin/mainmenu/gamemgr.lua b/builtin/mainmenu/gamemgr.lua index b6faa71d9..fd6025fcd 100644 --- a/builtin/mainmenu/gamemgr.lua +++ b/builtin/mainmenu/gamemgr.lua @@ -68,10 +68,10 @@ end function gamemgr.gamelist() local retval = "" if #gamemgr.games > 0 then - retval = retval .. gamemgr.games[1].name + retval = retval .. core.formspec_escape(gamemgr.games[1].name) for i=2,#gamemgr.games,1 do - retval = retval .. "," .. gamemgr.games[i].name + retval = retval .. "," .. core.formspec_escape(gamemgr.games[i].name) end end return retval -- cgit v1.2.3 From fe046fab8aa0bde610f8828fb1c3fc014cf7e193 Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Sun, 28 May 2017 20:37:44 +0100 Subject: Update credits The following algorithm was used when selecting contributors: * Every non-trivial contributor from the current release, Non-trivial meaning more than X non-trivial commits, not counting documentation/translation changes * The top Y contributors from the last 4 years. * Previous contributor means no contributions since a few months before the last release. In the future this should be automated --- builtin/mainmenu/tab_credits.lua | 81 ++++++++++++++++++++++------------------ 1 file changed, 44 insertions(+), 37 deletions(-) (limited to 'builtin/mainmenu') diff --git a/builtin/mainmenu/tab_credits.lua b/builtin/mainmenu/tab_credits.lua index ff47dbb22..0774433b6 100644 --- a/builtin/mainmenu/tab_credits.lua +++ b/builtin/mainmenu/tab_credits.lua @@ -19,61 +19,68 @@ local core_developers = { "Perttu Ahola (celeron55) ", - "Ryan Kwolek (kwolekr) ", "sfan5 ", - "kahrl ", - "sapier", "ShadowNinja ", "Nathanaël Courant (Nore/Ekdohibs) ", "Loic Blot (nerzhul/nrz) ", - "Matt Gregory (paramat)", - "est31 ", + "paramat", "Craig Robbins (Zeno) ", "Auke Kok (sofar) ", - "Andrew Ward (rubenwardy) ", + "rubenwardy ", + "Krock/SmallJoker ", } local active_contributors = { - "Duane Robertson ", - "SmallJoker ", - "Lars Hofhansl ", - "Jeija ", - "Gregory Currie (gregorycu)", - "Sokomine ", - "TeTpaAka", - "Jean-Patrick G (kilbith) ", - "Diego Martínez (kaeza) ", - "Dániel Juhász (juhdanad) ", - "Rogier ", + "red-001 [CSM & Menu fixes]", + "Dániel Juhász (juhdanad) [Audiovisuals: lighting]", + "numberZero [Audiovisuals: meshgen]", + "Lars Hofhansl [Occulusion culling, fixes]", + "Jean-Patrick G (kilbith) [Audiovisuals]", + "Vincent Glize (Dumbeldor) [CSM]", + "bigfoot547 [CSM]", + "Rogier [Fixes]", + "Wuzzy [Audiovisuals]", + "Shara/Ezhh [Settings]", } local previous_core_developers = { "BlockMen", - "Maciej Kasatkin (RealBadAngel) ", + "Maciej Kasatkin (RealBadAngel) [RIP]", "Lisa Milne (darkrose) ", "proller", "Ilya Zhuravlev (xyz) ", "PilzAdam ", + "est31 ", + "kahrl ", + "Ryan Kwolek (kwolekr) ", + "sapier", } local previous_contributors = { - "Vanessa Ezekowitz (VanessaE) ", - "Jurgen Doser (doserj) ", - "MirceaKitsune ", - "dannydark ", - "0gb.us <0gb.us@0gb.us>", - "Guiseppe Bilotta (Oblomov) ", - "Jonathan Neuschafer ", - "Nils Dagsson Moskopp (erlehmann) ", - "Břetislav Štec (t0suj4/TBC_x)", - "Aaron Suen ", - "Constantin Wenger (SpeedProg) ", - "matttpt ", - "JacobF ", - "TriBlade9 ", - "Zefram ", + "Gregory Currie (gregorycu) [optimisation]", + "Diego Martínez (kaeza) ", + "T4im [Profiler]", + "TeTpaAka [Hand overriding, nametag colors]", + "HybridDog [Fixes]", + "Duane Robertson [MGValleys]", + "neoascetic [OS X Fixes]", + "TriBlade9 [Audiovisuals]", + "Jurgen Doser (doserj) [Fixes]", + "MirceaKitsune [Audiovisuals]", + "Guiseppe Bilotta (Oblomov) [Fixes]", + "matttpt [Fixes]", + "Nils Dagsson Moskopp (erlehmann) [Minetest Logo]", + "Jeija [HTTP, particles]", } +local function buildCreditList(source) + ret = {} + for i = 1, #source do + ret[i] = core.formspec_escape(source[i]) + end + return table.concat(ret, ",,") +end + return { name = "credits", caption = fgettext("Credits"), @@ -87,13 +94,13 @@ return { "tableoptions[background=#00000000;highlight=#00000000;border=false]" .. "table[3.5,-0.25;8.5,6.05;list_credits;" .. "#FFFF00," .. fgettext("Core Developers") .. ",," .. - table.concat(core_developers, ",,") .. ",,," .. + buildCreditList(core_developers) .. ",,," .. "#FFFF00," .. fgettext("Active Contributors") .. ",," .. - table.concat(active_contributors, ",,") .. ",,," .. + buildCreditList(active_contributors) .. ",,," .. "#FFFF00," .. fgettext("Previous Core Developers") ..",," .. - table.concat(previous_core_developers, ",,") .. ",,," .. + buildCreditList(previous_core_developers) .. ",,," .. "#FFFF00," .. fgettext("Previous Contributors") .. ",," .. - table.concat(previous_contributors, ",,") .. "," .. + buildCreditList(previous_contributors) .. "," .. ";1]" end } -- cgit v1.2.3