diff --git a/LICENSE.txt b/LICENSE.txt index a912bebb5..479834dbd 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -16,23 +16,16 @@ Everything not listed in here: Copyright (C) 2010-2012 celeron55, Perttu Ahola MultiCraft Development Team: + textures/base/pack/gui/*.png textures/base/pack/attention.png - textures/base/pack/authors_menu.png - textures/base/pack/authors_menu_*.png textures/base/pack/bg_common.png - textures/base/pack/btn_down.png - textures/base/pack/btn_down_hover.png - textures/base/pack/btn_download.png - textures/base/pack/btn_download_hover.png textures/base/pack/btn_play.png textures/base/pack/btn_play_hover.png - textures/base/pack/btn_up.png textures/base/pack/camera_btn.png textures/base/pack/chat_btn.png textures/base/pack/crack_anylength_touch.png textures/base/pack/creative_bg.png - textures/base/pack/creative_bg_*.png - textures/base/pack/creative_checkbox.png + textures/base/pack/error_screenshot.png textures/base/pack/desc_bg.png textures/base/pack/down_btn.png textures/base/pack/drop_btn.png @@ -41,14 +34,13 @@ MultiCraft Development Team: textures/base/pack/inventory_btn.png textures/base/pack/joystick_*.png textures/base/pack/jump_btn.png + textures/base/pack/loading_screenshot.png textures/base/pack/logo.png textures/base/pack/minimap_btn.png textures/base/pack/progress_bar.png - textures/base/pack/progress_bar_bg.png + textures/base/pack/progress_bar_*.png textures/base/pack/rangeview_btn.png textures/base/pack/refresh.png - textures/base/pack/search.png - textures/base/pack/select_btn.png textures/base/pack/server_flags_creative.png textures/base/pack/server_flags_damage.png textures/base/pack/server_flags_favorite.png @@ -56,19 +48,9 @@ MultiCraft Development Team: textures/base/pack/server_flags_mt.png textures/base/pack/server_flags_pvp.png textures/base/pack/server_ping_*.png - textures/base/pack/settings_menu.png - textures/base/pack/settings_menu_*.png - textures/base/pack/side_menu_divider.png - textures/base/pack/side_menu.png - textures/base/pack/side_menu_left.png textures/base/pack/switch_local_*.png textures/base/pack/trash.png - textures/base/pack/trash_hover.png - textures/base/pack/upper_buttons_*.png - textures/base/pack/world_delete.png - textures/base/pack/world_delete_hover.png - textures/base/pack/world_new.png - textures/base/pack/world_new_hover.png + textures/base/pack/trash_pressed.png textures/base/pack/worldlist_bg.png ShadowNinja: diff --git a/builtin/common/btn_style.lua b/builtin/common/btn_style.lua index a7a4919f2..6a42b8678 100644 --- a/builtin/common/btn_style.lua +++ b/builtin/common/btn_style.lua @@ -1,6 +1,8 @@ -- MultiCraft: builtin/common/btn_style.lua -- luacheck: read_globals PLATFORM +local fmt = string.format + local device_is_tablet = core.settings:get_bool("device_is_tablet", false) local screen_density = core.get_screen_info().density function is_high_dpi() @@ -16,14 +18,17 @@ end local DIR_DELIM_esc = core.formspec_escape(DIR_DELIM) local button_path = (INIT == "mainmenu" and defaulttexturedir_esc or "") .. "gui" .. DIR_DELIM_esc -function btn_style(field, color) - local btn_size = is_high_dpi() and ".x2" or "" +function btn_style(field, color, no_padding) + local high_dpi = is_high_dpi() + local btn_size = high_dpi and ".x2" or "" color = (color and "_" .. color) or "" + local bgimg_middle = high_dpi and 48 or 32 local retval = "style[" .. field .. ";border=false]" .. "style[" .. field .. ";bgimg=" .. button_path .. "gui_button" .. color .. btn_size .. - ".png;bgimg_middle=" .. (is_high_dpi() and 48 or 32) .. ";padding=" .. (is_high_dpi() and -36 or -24) .. "]" + ".png;bgimg_middle=" .. bgimg_middle .. ";padding=" .. + (no_padding and -bgimg_middle or (high_dpi and -36 or -24)) .. "]" if color ~= "_gray" and color:sub(-8) ~= "_pressed" then retval = retval .. @@ -35,3 +40,71 @@ function btn_style(field, color) return retval end +-------------------------------------------------------------------------------- +function get_dropdown(x, y, w, name, items, selected_idx, dropdown_open, max_items) + local fs = {} + fs[#fs + 1] = fmt("style[%s;bgimg=%s%s;bgimg_middle=32;padding=-24;border=false]", + name, button_path, dropdown_open and "dropdown_open.png" or "dropdown.png") + fs[#fs + 1] = fmt("button[%s,%s;%s,0.8;%s;%s]", x, y, w, name, items[selected_idx]) + fs[#fs + 1] = fmt("image[%s,%s;0.3375,0.225;%sdropdown_arrow.png]", + x + w - 0.2 - 0.3375, y + 0.325, button_path) + + if dropdown_open then + -- Make clicking outside of the dropdown close the menu + fs[#fs + 1] = "image_button[-50,-50;100,100;;dropdown_close;;true;false]" + + max_items = max_items or 6 + local scroll_container = #items > max_items + if scroll_container then + fs[#fs + 1] = fmt("scroll_container[%s,%s;%s,%s;scrbar;vertical]", x, y + 0.79, w, 0.79 * max_items) + else + fs[#fs + 1] = fmt("container[%s,%s]", x, y + 0.79) + end + + -- Add a button for each dropdown entry + for i, entry in ipairs(items) do + local btn_name = "dropdown_" .. i + local suffix = i <= 6 and i == #items and "_end" or "" + fs[#fs + 1] = fmt("style[%s;bgimg=%sdropdown_bg%s.png;bgimg_middle=32;padding=-24;border=false;noclip=%s]", + btn_name, button_path, suffix, scroll_container and "false" or "true") + fs[#fs + 1] = fmt("style[%s:hovered,%s:pressed;bgimg=%sdropdown_bg%s_hover.png]", + btn_name, btn_name, button_path, suffix) + + -- 0.79 is used to prevent any 1px gaps between entries + fs[#fs + 1] = fmt("button[0,%s;%s,0.8;%s;%s]", (i - 1) * 0.79, w, btn_name, entry) + end + + if scroll_container then + fs[#fs + 1] = "scroll_container_end[]" + local outer_h = max_items * 0.79 + local inner_h = #items * 0.79 + local scrollbar_max = (inner_h - outer_h) * 10 + + fs[#fs + 1] = fmt("scrollbaroptions[max=%d;thumbsize=%s]", math.ceil(scrollbar_max), + (outer_h / inner_h) * scrollbar_max) + fs[#fs + 1] = fmt("scrollbar[%s,%s;0.7,%s;vertical;scrbar;0;" .. + "%sscrollbar_bg.png,%sscrollbar_slider.png,%sscrollbar_up.png,%sscrollbar_down.png]", + x + w - 0.76, y + 0.84, outer_h - 0.11, button_path, button_path, button_path, button_path) + fs[#fs + 1] = fmt("image[%s,%s;%s,0.79;%sdropdown_fg_end.png;32]", x, y + outer_h + 0.02, w, button_path) + else + fs[#fs + 1] = "container_end[]" + end + end + + return table.concat(fs) +end +-------------------------------------------------------------------------------- +function checkbox(x, y, name, label, checked, small) + -- Note: checkbox[] sends a "true" or "false" value in fields but this + -- doesn't, code will have to be changed to toggle the value and redraw the + -- formspec instead + return ([[ + image[%s,%.3f;0.4,0.4;%sgui%scheckbox%s.png] + label[%s,%.3f;%s] + image_button[%s,%.2f;%s,0.5;;%s;;false;false] + ]]):format( + x, y - 0.2, defaulttexturedir_esc, DIR_DELIM_esc, checked and "_checked" or "", + x + 0.6, y, label, + x, y - 0.25, small and 4.3 or 7, name + ) +end diff --git a/builtin/mainmenu/common.lua b/builtin/mainmenu/common.lua index c08bccc66..a5b06d793 100644 --- a/builtin/mainmenu/common.lua +++ b/builtin/mainmenu/common.lua @@ -158,15 +158,26 @@ end -------------------------------------------------------------------------------- function menu_render_worldlist() - local retval = "" - local current_worldlist = menudata.worldlist:get_list() + local retval = {} - for _, v in ipairs(current_worldlist) do - if retval ~= "" then retval = retval .. "," end - retval = retval .. core.formspec_escape(v.name) + local creative = core.settings:get_bool("creative_mode", false) + local damage = core.settings:get_bool("enable_damage", true) + + for _, world in ipairs(menudata.worldlist:get_list()) do + if world.creative_mode == nil or world.enable_damage == nil then + -- There's a built-in menu_worldmt function that can read from + -- world.mt but it would read from the file once for each setting + -- read + local world_conf = Settings(world.path .. DIR_DELIM .. "world.mt") + world.creative_mode = world_conf:get_bool("creative_mode", creative) + world.enable_damage = world_conf:get_bool("enable_damage", damage) + end + + retval[#retval + 1] = world.creative_mode and "5" or "4" + retval[#retval + 1] = core.formspec_escape(world.name) end - return retval + return table.concat(retval, ",") end -------------------------------------------------------------------------------- @@ -282,21 +293,21 @@ function get_language_list() languages[#languages + 1] = "en" language_names.en = "English" - -- Sort the languages list based on their human readable name + -- Sort the languages list based on their human readable name and make sure + -- that English is the first entry table.sort(languages, function(a, b) - return language_names[a] < language_names[b] + return a == "en" or (b ~= "en" and language_names[a] < language_names[b]) end) local language_name_list = {} for i, language in ipairs(languages) do language_name_list[i] = core.formspec_escape(language_names[language]) end - local language_dropdown = table.concat(language_name_list, ",") local lang_idx = table.indexof(languages, fgettext("LANG_CODE")) if lang_idx < 0 then lang_idx = table.indexof(languages, "en") end - return languages, language_dropdown, lang_idx, language_name_list + return languages, lang_idx, language_name_list end diff --git a/builtin/mainmenu/dlg_config_world.lua b/builtin/mainmenu/dlg_config_world.lua index bac35b52c..9f0cf11e5 100644 --- a/builtin/mainmenu/dlg_config_world.lua +++ b/builtin/mainmenu/dlg_config_world.lua @@ -138,7 +138,7 @@ local function get_formspec(data) "button[8.5,7.1;3,0.5;btn_config_world_cancel;" .. fgettext("Cancel") .. "]" .. btn_style("btn_config_world_cdb") .. - "button[-0.05,7.1;3.5,0.5;btn_config_world_cdb;" .. + "button[-0.05,7.1;5.5,0.5;btn_config_world_cdb;" .. fgettext("Find More Mods") .. "]" .. "image[0.09,7.05;0.6,0.6;" .. defaulttexturedir_esc .. "gui" .. DIR_DELIM_esc .. "btn_download.png]" @@ -148,35 +148,39 @@ local function get_formspec(data) if pkgmgr.is_modpack_entirely_enabled(data, mod.name) then retval = retval .. - btn_style("btn_mp_disable", "yellow") .. - "button[5.5,0.025;3,0.5;btn_mp_disable;" .. + btn_style("btn_mod_disable", "yellow") .. + "button[5.5,0.025;3.3,0.5;btn_mod_disable;" .. fgettext("Disable modpack") .. "]" else retval = retval .. - btn_style("btn_mp_enable", "green") .. - "button[5.5,0.025;3,0.5;btn_mp_enable;" .. + btn_style("btn_mod_enable", "green") .. + "button[5.5,0.025;3.3,0.5;btn_mod_enable;" .. fgettext("Enable modpack") .. "]" end else retval = retval .. - "checkbox[5.5,-0.125;cb_mod_enable;" .. fgettext("Enabled") .. - ";" .. tostring(mod.enabled) .. "]" + "real_coordinates[true]" .. + checkbox(7.3, 0.64, mod.enabled and "btn_mod_disable" or "btn_mod_enable", + fgettext("Enabled"), mod.enabled) .. + "real_coordinates[false]" end end if enabled_all then retval = retval .. btn_style("btn_disable_all_mods", "yellow") .. - "button[8.95,0.025;2.5,0.5;btn_disable_all_mods;" .. + "button[8.8,0.025;2.695,0.5;btn_disable_all_mods;" .. fgettext("Disable all") .. "]" else retval = retval .. btn_style("btn_enable_all_mods", "green") .. - "button[8.95,0.025;2.5,0.5;btn_enable_all_mods;" .. + "button[8.8,0.025;2.695,0.5;btn_enable_all_mods;" .. fgettext("Enable all") .. "]" end return retval .. + "background9[5.6,0.85;5.8,6;" .. defaulttexturedir_esc .. "worldlist_bg.png;false;40]" .. "tablecolumns[color;tree;text]" .. - "table[5.5,0.75;5.75,6;world_config_modlist;" .. + "tableoptions[background=#0000;border=false]" .. + "table[5.58,0.84;5.59,5.82;world_config_modlist;" .. pkgmgr.render_packagelist(data.list) .. ";" .. data.selected_mod .."]" end @@ -198,14 +202,9 @@ local function handle_buttons(this, fields) return true end - if fields.cb_mod_enable ~= nil then - pkgmgr.enable_mod(this, core.is_yes(fields.cb_mod_enable)) - return true - end - - if fields.btn_mp_enable ~= nil or - fields.btn_mp_disable then - pkgmgr.enable_mod(this, fields.btn_mp_enable ~= nil) + if fields.btn_mod_enable ~= nil or + fields.btn_mod_disable then + pkgmgr.enable_mod(this, fields.btn_mod_enable ~= nil) return true end diff --git a/builtin/mainmenu/dlg_contentstore.lua b/builtin/mainmenu/dlg_contentstore.lua index 658ef1239..1c2d5c6f2 100644 --- a/builtin/mainmenu/dlg_contentstore.lua +++ b/builtin/mainmenu/dlg_contentstore.lua @@ -44,6 +44,7 @@ local search_string = "" local cur_page = 1 local num_per_page = 5 local filter_type = 1 +local dropdown_open = false local filter_types_titles = { fgettext("All packages"), fgettext("Games"), @@ -711,13 +712,11 @@ function store.get_formspec(dlgdata) "style[status,downloading,queued;border=false]", "container[0.375,0.375]", - "image[0,0;7.25,0.8;", defaulttexturedir_esc, "field_bg.png;32]", + "image[0,0;7.7,0.8;", defaulttexturedir_esc, "field_bg.png;32]", "style[Dsearch_string;border=false;bgcolor=transparent]", - "field[0.1,0;7.15,0.8;Dsearch_string;;", esc(search_string), "]", + "field[0.1,0;6.65,0.8;Dsearch_string;;", esc(search_string), "]", "set_focus[Dsearch_string;true]", - btn_style("clear"), - "image_button[7.4,0;0.8,0.8;", defaulttexturedir_esc, "clear.png;clear;;true;false]", - "dropdown[8.35,0;3.5,0.8;type;", table.concat(filter_types_titles, ","), ";", filter_type, "]", + "image_button[6.9,0.05;0.7,0.7;", defaulttexturedir_esc, "clear.png;clear;;true;false]", "container_end[]", -- Page nav buttons @@ -731,7 +730,8 @@ function store.get_formspec(dlgdata) btn_style("pback"), "image_button[0.8,0;0.8,0.8;", defaulttexturedir_esc, "prev_icon.png;pback;;true;false]", "style[pagenum;border=false]", - "button[1.5,0;2,0.8;pagenum;", tonumber(cur_page), " / ", tonumber(dlgdata.pagemax), "]", + "button[1.5,0;2,0.8;pagenum;", core.colorize("#FFDF00", tostring(cur_page)), + " / ", core.colorize("#FFDF00", tostring(dlgdata.pagemax)), "]", btn_style("pnext"), "image_button[3.5,0;0.8,0.8;", defaulttexturedir_esc, "next_icon.png;pnext;;true;false]", btn_style("pend"), @@ -809,6 +809,12 @@ function store.get_formspec(dlgdata) formspec[#formspec + 1] = get_screenshot(package) formspec[#formspec + 1] = "]" + formspec[#formspec + 1] = "image[-0.01,-0.01;1.52,1.02;" + formspec[#formspec + 1] = defaulttexturedir_esc + formspec[#formspec + 1] = "gui" + formspec[#formspec + 1] = DIR_DELIM_esc + formspec[#formspec + 1] = "cdb_img_corners.png;15]" + -- title formspec[#formspec + 1] = "label[1.875,0.1;" formspec[#formspec + 1] = esc( @@ -832,7 +838,7 @@ function store.get_formspec(dlgdata) formspec[#formspec + 1] = "cdb_queued.png;queued]" elseif not package.path then local elem_name = "install_" .. i .. ";" - formspec[#formspec + 1] = "style[" .. elem_name .. "bgcolor=#71aa34]" + formspec[#formspec + 1] = btn_style("install_" .. i, "green", true) formspec[#formspec + 1] = left_base .. "cdb_add.png;" .. elem_name .. "]" formspec[#formspec + 1] = "tooltip[" .. elem_name .. fgettext("Install") .. tooltip_colors else @@ -840,19 +846,20 @@ function store.get_formspec(dlgdata) -- The install_ action also handles updating local elem_name = "install_" .. i .. ";" - formspec[#formspec + 1] = "style[" .. elem_name .. "bgcolor=#28ccdf]" + formspec[#formspec + 1] = btn_style("install_" .. i, nil, true) formspec[#formspec + 1] = left_base .. "cdb_update.png;" .. elem_name .. "]" formspec[#formspec + 1] = "tooltip[" .. elem_name .. fgettext("Update") .. tooltip_colors else local elem_name = "uninstall_" .. i .. ";" - formspec[#formspec + 1] = "style[" .. elem_name .. "bgcolor=#a93b3b]" + formspec[#formspec + 1] = btn_style("uninstall_" .. i, "red", true) formspec[#formspec + 1] = left_base .. "cdb_clear.png;" .. elem_name .. "]" formspec[#formspec + 1] = "tooltip[" .. elem_name .. fgettext("Uninstall") .. tooltip_colors end end local web_elem_name = "view_" .. i .. ";" + formspec[#formspec + 1] = btn_style("view_" .. i, nil, true) formspec[#formspec + 1] = "image_button[-0.7,0;0.7,0.7;" .. defaulttexturedir_esc .. "cdb_viewonline.png;" .. web_elem_name .. "]" formspec[#formspec + 1] = "tooltip[" .. web_elem_name .. @@ -872,6 +879,12 @@ function store.get_formspec(dlgdata) formspec[#formspec + 1] = "container_end[]" end + -- Add the dropdown last so that it is over top of everything else + if #store.packages_full > 0 then + formspec[#formspec + 1] = get_dropdown(8.22, 0.375, 4, "change_type", + filter_types_titles, filter_type, dropdown_open) + end + return table.concat(formspec, "") end @@ -915,11 +928,20 @@ function store.handle_submit(this, fields) return true end - if fields.type then - local new_type = table.indexof(filter_types_titles, fields.type) - if new_type ~= filter_type then - filter_type = new_type - store.filter_packages(search_string) + if fields.change_type then + dropdown_open = true + return true + end + + for field in pairs(fields) do + if field:sub(1, 9) == "dropdown_" then + dropdown_open = false + local new_type = tonumber(field:sub(10)) + if new_type and new_type ~= filter_type then + filter_type = new_type + cur_page = 1 + store.filter_packages(search_string) + end return true end end diff --git a/builtin/mainmenu/dlg_create_world.lua b/builtin/mainmenu/dlg_create_world.lua index 114ee95f3..aa6b78f3e 100644 --- a/builtin/mainmenu/dlg_create_world.lua +++ b/builtin/mainmenu/dlg_create_world.lua @@ -16,6 +16,7 @@ --51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. local worldname = "" +local dropdown_open = false local function table_to_flags(ftable) -- Convert e.g. { jungles = true, caves = false } to "jungles,nocaves" @@ -26,11 +27,6 @@ local function table_to_flags(ftable) return table.concat(str, ",") end --- Same as check_flag but returns a string -local function strflag(flags, flag) - return (flags[flag] == true) and "true" or "false" -end - local cb_caverns = { "caverns", fgettext("Caverns"), "caverns", fgettext("Very large caverns deep in the underground") } local tt_sea_rivers = fgettext("Sea level rivers") @@ -182,25 +178,27 @@ local function create_world_formspec(dialogdata) end end - local mglist = "" - local selindex - local i = 1 - local first_mg - for k,v in pairs(mapgens) do + local first_mg, selindex + local mapgen_names = {} + dialogdata.mapgens = mapgens + for i, v in ipairs(mapgens) do if not first_mg then first_mg = v end if current_mg == v then selindex = i end - i = i + 1 - mglist = mglist .. v .. "," + + if v == "v7p" then + mapgen_names[i] = "Default" + else + mapgen_names[i] = v:sub(1, 1):upper() .. v:sub(2) + end end if not selindex then selindex = 1 current_mg = first_mg end - mglist = mglist:sub(1, -2) local mg_main_flags = function(mapgen, y) if mapgen == "singlenode" or mapgen == "superflat" then @@ -210,13 +208,11 @@ local function create_world_formspec(dialogdata) return "", y end - local form = "checkbox[0," .. y .. ";flag_mg_caves;" .. - fgettext("Caves") .. ";"..strflag(flags.main, "caves").."]" - y = y + 0.5 + local form = checkbox(0, y, "flag_mg_caves", fgettext("Caves"), flags.main.caves) + y = y + 0.575 - form = form .. "checkbox[0,"..y..";flag_mg_dungeons;" .. - fgettext("Dungeons") .. ";"..strflag(flags.main, "dungeons").."]" - y = y + 0.5 + form = form .. checkbox(0, y, "flag_mg_dungeons", fgettext("Dungeons"), flags.main.dungeons) + y = y + 0.575 local d_name = fgettext("Decorations") local d_tt @@ -225,13 +221,11 @@ local function create_world_formspec(dialogdata) else d_tt = fgettext("Structures appearing on the terrain, typically trees and plants") end - form = form .. "checkbox[0,"..y..";flag_mg_decorations;" .. - d_name .. ";" .. - strflag(flags.main, "decorations").."]" .. + form = form .. checkbox(0, y, "flag_mg_decorations", d_name, flags.main.decorations) .. "tooltip[flag_mg_decorations;" .. d_tt .. "]" - y = y + 0.5 + y = y + 0.575 form = form .. "tooltip[flag_mg_caves;" .. fgettext("Network of tunnels and caves") @@ -249,13 +243,12 @@ local function create_world_formspec(dialogdata) local form = "" for _,tab in pairs(flag_checkboxes[mapgen]) do local id = "flag_mg"..mapgen.."_"..tab[1] - form = form .. ("checkbox[0,%f;%s;%s;%s]"): - format(y, id, tab[2], strflag(flags[mapgen], tab[3])) + form = form .. checkbox(0, y, id, tab[2], flags[mapgen][tab[3]]) if tab[4] then form = form .. "tooltip["..id..";"..tab[4].."]" end - y = y + 0.5 + y = y + 0.575 end if mapgen ~= "v6" then @@ -273,10 +266,10 @@ local function create_world_formspec(dialogdata) else biometype = 3 end - y = y + 0.3 + y = y + 0.345 - form = form .. "label[0,"..(y+0.1)..";" .. fgettext("Biomes") .. ":]" - y = y + 0.6 + form = form .. "label[0,"..(y+0.11)..";" .. fgettext("Biomes") .. ":]" + y = y + 0.69 form = form .. "dropdown[0,"..y..";6.3;mgv6_biomes;" for b=1, #mgv6_biomes do @@ -288,9 +281,9 @@ local function create_world_formspec(dialogdata) form = form .. ";" .. biometype.. "]" -- biomeblend - y = y + 0.55 - form = form .. "checkbox[0,"..y..";flag_mgv6_biomeblend;" .. - fgettext("Biome blending") .. ";"..strflag(flags.v6, "biomeblend").."]" .. + y = y + 0.6325 + form = form .. checkbox(0, y, "flag_mgv6_biomeblend", + fgettext("Biome blending"), flags.v6.biomeblend) .. "tooltip[flag_mgv6_biomeblend;" .. fgettext("Smooth transition between biomes") .. "]" @@ -299,19 +292,17 @@ local function create_world_formspec(dialogdata) current_seed = core.formspec_escape(current_seed) - local y_start = 0.0 + local y_start = 0.575 local y = y_start local str_flags, str_spflags local label_flags, label_spflags = "", "" - y = y + 0.3 + y = y + 0.5 str_flags, y = mg_main_flags(current_mg, y) if str_flags ~= "" then label_flags = "label[0,"..y_start..";" .. fgettext("Mapgen flags") .. ":]" - y_start = y + 0.4 - else - y_start = 0.0 + y_start = y + 0.5 end - y = y_start + 0.3 + y = y_start + 0.5 str_spflags = mg_specific_flags(current_mg, y) if str_spflags ~= "" then label_spflags = "label[0,"..y_start..";" .. fgettext("Mapgen-specific flags") .. ":]" @@ -319,13 +310,13 @@ local function create_world_formspec(dialogdata) -- Warning if only devtest is installed local devtest_only = "" - local gamelist_height = 2.3 + local gamelist_height = 2.97 if #pkgmgr.games == 1 and pkgmgr.games[1].id == "devtest" then - devtest_only = "box[0,0;5.8,1.7;#ff8800]" .. - "textarea[0.3,0;6,1.8;;;".. + devtest_only = "box[0,0;7.25,1.6;#ff8800]" .. + "textarea[0,0;7.25,1.6;;;".. fgettext("Warning: The Development Test is meant for developers.") .. "\n" .. fgettext("Download a game, such as Minetest Game, from minetest.net") .. "]" - gamelist_height = 0.5 + gamelist_height = 1.12 end local _gameidx = gameidx @@ -339,8 +330,6 @@ local function create_world_formspec(dialogdata) "background9[0,0;0,0;" .. defaulttexturedir_esc .. "bg_common.png;true;40]" .. -- Left side - "container[0,0]".. - "real_coordinates[true]" .. "formspec_version[3]" .. "image[0.37,0.6;7.28,0.8;" .. defaulttexturedir_esc .. "field_bg.png;32]" .. @@ -354,37 +343,38 @@ local function create_world_formspec(dialogdata) "field[0.42,1.9;7.18,0.8;te_seed;" .. fgettext("Seed") .. ":;".. current_seed .. "]" .. - "real_coordinates[false]" .. - "label[0,2.1;" .. fgettext("Mapgen") .. ":]".. - "dropdown[0,2.5;6.27;dd_mapgen;" .. mglist .. ";" .. selindex .. "]" .. - - "label[0,3.45;" .. fgettext("Game") .. ":]".. - "textlist[0,3.85;5.8,"..gamelist_height..";games;" .. - pkgmgr.gamelist() .. ";" .. _gameidx .. ";false]" .. - "container[0,4.5]" .. + "label[0.43,4.3;" .. fgettext("Game") .. ":]" .. + "background9[0.37,4.5;7.28," .. gamelist_height .. ";" .. defaulttexturedir_esc .. "worldlist_bg.png;false;40]" .. + "textlist[0.47,4.6;7.08,".. gamelist_height - 0.2 .. ";games;" .. + pkgmgr.gamelist() .. ";" .. _gameidx .. ";true]" .. + "container[0.37,5.8]" .. devtest_only .. "container_end[]" .. - "container_end[]" .. -- Right side - "container[6.2,0]".. + "container[8.25,0]" .. label_flags .. str_flags .. label_spflags .. str_spflags .. - "container_end[]".. + "container_end[]" .. + "real_coordinates[false]" .. -- Menu buttons btn_style("world_create_confirm", "green") .. "button[3.25,6.5;3,0.5;world_create_confirm;" .. fgettext("Create") .. "]" .. btn_style("world_create_cancel") .. - "button[6.25,6.5;3,0.5;world_create_cancel;" .. fgettext("Cancel") .. "]" + "button[6.25,6.5;3,0.5;world_create_cancel;" .. fgettext("Cancel") .. "]" .. + + -- Mapgen (must be last) + "real_coordinates[true]" .. + "label[0.43,3;" .. fgettext("Mapgen") .. ":]".. + get_dropdown(0.37, 3.2, 7.28, "change_mapgen", mapgen_names, selindex, dropdown_open) return retval end local function create_world_buttonhandler(this, fields) - if fields["world_create_confirm"] or fields["key_enter"] then @@ -423,17 +413,16 @@ local function create_world_buttonhandler(this, fields) local message if not menudata.worldlist:uid_exists_raw(worldname) then local old_mg_flags - if fields["dd_mapgen"] == "superflat" then + local mg_name = core.settings:get("mg_name") + if mg_name == "superflat" then core.settings:set("mg_name", "flat") old_mg_flags = core.settings:get("mg_flags") core.settings:set("mg_flags", "nocaves,nodungeons,nodecorations") - else - core.settings:set("mg_name", fields["dd_mapgen"]) end message = core.create_world(worldname,gameindex) -- Restore the old mg_flags setting if creating a superflat world - if fields["dd_mapgen"] == "superflat" then + if mg_name == "superflat" then core.settings:set("mg_name", "superflat") if old_mg_flags then core.settings:set("mg_flags", old_mg_flags) @@ -477,7 +466,7 @@ local function create_world_buttonhandler(this, fields) return true end - for k,v in pairs(fields) do + for k in pairs(fields) do local split = string.split(k, "_", nil, 3) if split and split[1] == "flag" then local setting @@ -489,11 +478,12 @@ local function create_world_buttonhandler(this, fields) -- We replaced the underscore of flag names with a dash. local flag = string.gsub(split[3], "-", "_") local ftable = core.settings:get_flags(setting) - if v == "true" then - ftable[flag] = true - else - ftable[flag] = false - end + -- if v == "true" then + -- ftable[flag] = true + -- else + -- ftable[flag] = false + -- end + ftable[flag] = not ftable[flag] local flags = table_to_flags(ftable) core.settings:set(setting, flags) return true @@ -505,6 +495,22 @@ local function create_world_buttonhandler(this, fields) return true end + if fields.change_mapgen then + dropdown_open = true + return true + end + + for field in pairs(fields) do + if field:sub(1, 9) == "dropdown_" and this.data.mapgens then + dropdown_open = false + local new_mapgen = this.data.mapgens[tonumber(field:sub(10))] + if new_mapgen then + core.settings:set("mg_name", new_mapgen) + end + return true + end + end + if fields["mgv6_biomes"] then local entry = core.formspec_escape(fields["mgv6_biomes"]) for b=1, #mgv6_biomes do @@ -519,11 +525,6 @@ local function create_world_buttonhandler(this, fields) end end - if fields["dd_mapgen"] then - core.settings:set("mg_name", fields["dd_mapgen"]) - return true - end - return false end diff --git a/builtin/mainmenu/dlg_settings_advanced.lua b/builtin/mainmenu/dlg_settings_advanced.lua index eded14bd4..084a34f96 100644 --- a/builtin/mainmenu/dlg_settings_advanced.lua +++ b/builtin/mainmenu/dlg_settings_advanced.lua @@ -516,7 +516,8 @@ local full_settings = parse_config_file(false, true) local search_string = "" local settings = full_settings local selected_setting = 1 -local languages, language_dropdown, lang_idx, language_name_list = get_language_list() +local languages, lang_idx, language_name_list = get_language_list() +local language_dropdown = table.concat(language_name_list, ",") local function get_current_value(setting) local value = core.settings:get(setting.name) @@ -1022,13 +1023,11 @@ local function create_settings_formspec(tabview, _, tabdata) "tablecolumns[color;tree;text,width=28;text]" .. "tableoptions[background=#00000000;border=false]" .. "formspec_version[3]" .. - "image[-0.05,-0.13;12.55,0.8;" .. defaulttexturedir_esc .. "field_bg.png;32]" .. - "style[search_string;border=false;bgcolor=transparent]" .. - "field[0.3,0.15;10.15,0.9;search_string;;" .. core.formspec_escape(search_string) .. "]" .. - "field_close_on_enter[search_string;false]" .. - btn_style("search") .. - "button[10.1,-0.22;2,1;search;" .. fgettext("Search") .. "]" .. - "table[0,0.8;12,3.5;list_settings;" + "image[-0.04,-0.13;14.9,0.8;" .. defaulttexturedir_esc .. "field_bg.png;32]" .. + "style[Dsearch_string;border=false;bgcolor=transparent]" .. + "field[0.3,0.15;12.0,0.9;Dsearch_string;;" .. core.formspec_escape(search_string) .. "]" .. + "field_close_on_enter[Dsearch_string;false]" .. + "table[0,0.8;11.8,3.5;list_settings;" local current_level = 0 for _, entry in ipairs(settings) do @@ -1106,8 +1105,10 @@ 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 (fields.Dsearch_string or fields.key_enter_field == "Dsearch_string") and + not (fields["btn_edit"] or list_enter or fields["btn_restore"] or + fields["btn_back"] or fields["cb_tech_settings"]) then + if search_string == fields.Dsearch_string then if selected_setting > 0 then -- Go to next result on enter press local i = selected_setting + 1 @@ -1129,7 +1130,7 @@ local function handle_settings_buttons(this, fields, tabname, tabdata) end else -- Search for setting - search_string = fields.search_string + search_string = fields.Dsearch_string settings, selected_setting = filter_settings(full_settings, search_string) core.update_formspec(this:get_formspec()) end diff --git a/builtin/mainmenu/tab_content.lua b/builtin/mainmenu/tab_content.lua index 9279a9239..6692103e1 100644 --- a/builtin/mainmenu/tab_content.lua +++ b/builtin/mainmenu/tab_content.lua @@ -67,7 +67,9 @@ local function get_formspec(tabview, name, tabdata) pkgmgr.render_packagelist(packages) .. ";" .. tabdata.selected_pkg .. "]" .. btn_style("btn_contentdb") .. - "image_button[-0.11,4.8;5.5,0.9;;btn_contentdb;" .. fgettext("Browse online content") .. ";true;false]" + "image_button[-0.11,4.8;5.5,0.9;;btn_contentdb;" .. fgettext("Browse online content") .. ";true;false]" .. + "image[0.03,4.925;0.6,0.6;" .. defaulttexturedir_esc .. "gui" .. + DIR_DELIM_esc .. "btn_download.png]" local selected_pkg @@ -98,16 +100,18 @@ local function get_formspec(tabview, name, tabdata) retval = retval .. "image[5.5,0;3,2;" .. core.formspec_escape(modscreenshot) .. "]" .. + "image[5.5,0;3,2;" .. defaulttexturedir_esc .. "gui" .. DIR_DELIM_esc .. "cdb_img_corners.png;15]" .. "label[8.25,0.6;" .. core.formspec_escape(selected_pkg.name) .. "]" .. "background9[5.6,2.3;6.2,2.4;" .. defaulttexturedir_esc .. "desc_bg.png;false;32]" if selected_pkg.type == "mod" then - if selected_pkg.is_modpack then - retval = retval .. - btn_style("btn_mod_mgr_rename_modpack") .. - "image_button[8.65,4.8;3.25,0.9;;btn_mod_mgr_rename_modpack;" .. - fgettext("Rename") .. ";true;false]" - else + -- if selected_pkg.is_modpack then + -- retval = retval .. + -- btn_style("btn_mod_mgr_rename_modpack") .. + -- "image_button[8.65,4.8;3.25,0.9;;btn_mod_mgr_rename_modpack;" .. + -- fgettext("Rename") .. ";true;false]" + -- else + if not selected_pkg.is_modpack then --show dependencies desc = desc .. "\n\n" local toadd_hard = table.concat(info.depends or {}, "\n") @@ -134,12 +138,12 @@ local function get_formspec(tabview, name, tabdata) if selected_pkg.enabled then retval = retval .. btn_style("btn_mod_mgr_disable_txp") .. - "image_button[8.65,4.8;3.25,0.9;;btn_mod_mgr_disable_txp;" .. + "image_button[6.4,4.8;5.5,0.9;;btn_mod_mgr_disable_txp;" .. fgettext("Disable Texture Pack") .. ";true;false]" else retval = retval .. btn_style("btn_mod_mgr_use_txp", "green") .. - "image_button[8.65,4.8;3.25,0.9;;btn_mod_mgr_use_txp;" .. + "image_button[6.4,4.8;5.5,0.9;;btn_mod_mgr_use_txp;" .. fgettext("Use Texture Pack") .. ";true;false]" end end @@ -151,8 +155,9 @@ local function get_formspec(tabview, name, tabdata) if core.may_modify_path(selected_pkg.path) then retval = retval .. btn_style("btn_mod_mgr_delete_mod", "red") .. - "image_button[5.5,4.8;3.25,0.9;;btn_mod_mgr_delete_mod;" .. - fgettext("Uninstall Package") .. ";true;false]" + "image_button[5.5,4.8;0.9,0.9;" .. defaulttexturedir_esc .. + "trash.png;btn_mod_mgr_delete_mod;;true;false;" .. defaulttexturedir_esc .. "trash_pressed.png]" .. + "tooltip[btn_mod_mgr_delete_mod;" .. fgettext("Uninstall Package") .. "]" end end return retval @@ -175,6 +180,7 @@ local function handle_buttons(tabview, fields, tabname, tabdata) return true end + --[[ if fields["btn_mod_mgr_rename_modpack"] ~= nil then local mod = packages:get_list()[tabdata.selected_pkg] local dlg_renamemp = create_rename_modpack_dlg(mod) @@ -184,6 +190,7 @@ local function handle_buttons(tabview, fields, tabname, tabdata) packages = nil return true end + ]] if fields["btn_mod_mgr_delete_mod"] ~= nil then local mod = packages:get_list()[tabdata.selected_pkg] diff --git a/builtin/mainmenu/tab_local.lua b/builtin/mainmenu/tab_local.lua index 4dde40984..650261edc 100644 --- a/builtin/mainmenu/tab_local.lua +++ b/builtin/mainmenu/tab_local.lua @@ -15,9 +15,6 @@ --with this program; if not, write to the Free Software Foundation, Inc., --51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -local lang = core.settings:get("language") -if not lang or lang == "" then lang = os.getenv("LANG") end - local esc = core.formspec_escape local small_screen = (PLATFORM == "Android" or PLATFORM == "iOS") and not core.settings:get_bool("device_is_tablet") @@ -110,14 +107,6 @@ local function get_formspec(_, _, tab_data) -- Default index if index == 0 then index = 1 end - local creative_checkbox = core.settings:get_bool("creative_mode") and - "creative_checkbox.png" or "blank.png" - - local creative_bg = "creative_bg.png" - if lang and lang == "ru" then - creative_bg = "creative_bg_" .. lang .. ".png" - end - local space = small_screen and ("\n"):rep(3) or ("\n"):rep(5) local retval = "style[world_delete,world_create,world_configure;font_size=*" .. @@ -139,21 +128,25 @@ local function get_formspec(_, _, tab_data) "image[8.3,5.02;0.5,0.5;" .. defaulttexturedir_esc .. "gui" .. DIR_DELIM_esc .. "world_settings.png]" end + local c_label = utf8.gsub(fgettext("Creative mode"), "(%w)(%w+)", + function(a, b) return utf8.upper(a) .. b end) retval = retval .. btn_style("play") .. "style[play;font_size=*" .. (small_screen and 2.25 or 3) .. "]" .. "image_button[6.72,1.43;4.96,1.41;;play;" .. space .. " " .. fgettext("Play") .. space .. ";true;false]" .. "image[7,1.63;1,1;" .. defaulttexturedir_esc .. "btn_play_icon.png]" .. - "tooltip[play;".. fgettext("Play Game") .. "]" .. - "image_button[7.2,3.09;4,0.83;" .. defaulttexturedir_esc .. creative_bg .. ";;;true;false]" .. - "style[cb_creative_mode;content_offset=0]" .. - "image_button[7.2,3.09;4,0.83;" .. defaulttexturedir_esc .. creative_checkbox .. - ";cb_creative_mode;;true;false]" .. + "style[cb_creative_mode;content_offset=0;font_size=*" .. (small_screen and 1.2 or 1.5) .. + ";textcolor=#53659C]" .. + "image_button[6.86,3.09;4.65,0.83;" .. defaulttexturedir_esc .. "creative_bg.png;cb_creative_mode;;true;false]" .. + "image[6.96,3.19;0.55,0.55;" .. defaulttexturedir_esc .. "gui" .. DIR_DELIM_esc .. + (core.settings:get_bool("creative_mode") and "checkbox_checked" or "checkbox") .. ".png]" .. + "image_button[7.31,3.09;4.2,0.83;;cb_creative_mode;" .. c_label .. ";true;false]" .. "background9[0,0;6.5,4.8;" .. defaulttexturedir_esc .. "worldlist_bg.png;false;40]" .. "tableoptions[background=#0000;border=false]" .. + "tablecolumns[" .. image_column(fgettext("Creative mode")) .. ";text]" .. "table[0,0;6.28,4.64;sp_worlds;" .. menu_render_worldlist() .. ";" .. index .. "]" if tab_data.hidden then @@ -199,6 +192,13 @@ local function main_button_handler(this, fields, name, tab_data) end if event.type == "CHG" and selected ~= nil then + local world = menudata.worldlist:get_list()[selected] + if world and world.creative_mode ~= nil and + world.enable_damage ~= nil then + core.settings:set_bool("creative_mode", world.creative_mode) + core.settings:set_bool("enable_damage", world.enable_damage) + end + core.settings:set("mainmenu_last_selected_world", menudata.worldlist:get_raw_index(selected)) return true @@ -210,9 +210,23 @@ local function main_button_handler(this, fields, name, tab_data) end if fields["cb_creative_mode"] then - local creative_mode = core.settings:get_bool("creative_mode") - core.settings:set("creative_mode", tostring(not creative_mode)) - core.settings:set("enable_damage", tostring(creative_mode)) + local creative_mode = core.settings:get_bool("creative_mode", false) + core.settings:set_bool("creative_mode", not creative_mode) + core.settings:set_bool("enable_damage", creative_mode) + + local selected = core.get_table_index("sp_worlds") + local world = menudata.worldlist:get_list()[selected] + if world then + -- Update the cached values + world.creative_mode = not creative_mode + world.enable_damage = creative_mode + + -- Update the settings in world.mt + local world_conf = Settings(world.path .. DIR_DELIM .. "world.mt") + world_conf:set_bool("creative_mode", not creative_mode) + world_conf:set_bool("enable_damage", creative_mode) + world_conf:write() + end return true end @@ -396,6 +410,21 @@ local function on_change(type, old_tab, new_tab) singleplayer_refresh_gamebar() ui.find_by_name("game_button_bar"):show() + + -- Update creative_mode and enable_damage settings + local index = filterlist.get_current_index(menudata.worldlist, + tonumber(core.settings:get("mainmenu_last_selected_world"))) + local world = menudata.worldlist:get_list()[index] or menudata.worldlist:get_list()[1] + if world then + if world.creative_mode == nil or world.enable_damage == nil then + local world_conf = Settings(world.path .. DIR_DELIM .. "world.mt") + world.creative_mode = world_conf:get_bool("creative_mode") + world.enable_damage = world_conf:get_bool("enable_damage") + end + + core.settings:set_bool("creative_mode", world.creative_mode) + core.settings:set_bool("enable_damage", world.enable_damage) + end else menudata.worldlist:set_filtercriteria(nil) local gamebar = ui.find_by_name("game_button_bar") diff --git a/builtin/mainmenu/tab_local_default.lua b/builtin/mainmenu/tab_local_default.lua index c999b2bc4..990c56d23 100644 --- a/builtin/mainmenu/tab_local_default.lua +++ b/builtin/mainmenu/tab_local_default.lua @@ -15,9 +15,6 @@ --with this program; if not, write to the Free Software Foundation, Inc., --51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -local lang = core.settings:get("language") -if not lang or lang == "" then lang = os.getenv("LANG") end - local small_screen = (PLATFORM == "Android" or PLATFORM == "iOS") and not core.settings:get_bool("device_is_tablet") local default_worlds = { @@ -79,15 +76,9 @@ local function get_formspec(this) end end - local creative_checkbox = core.settings:get_bool("creative_mode") and - "creative_checkbox.png" or "blank.png" - - local creative_bg = "creative_bg.png" - if lang and lang == "ru" then - creative_bg = "creative_bg_" .. lang .. ".png" - end - local space = small_screen and ("\n"):rep(3) or ("\n"):rep(5) + local c_label = utf8.gsub(fgettext("Creative mode"), "(%w)(%w+)", + function(a, b) return utf8.upper(a) .. b end) local retval = "style[world_delete,world_create;font_size=*" .. (small_screen and 1.2 or 1.5) .. "]" .. @@ -104,15 +95,17 @@ local function get_formspec(this) "image_button[6.72,1.43;4.96,1.41;;play;" .. space .. " " .. fgettext("Play") .. space .. ";true;false]" .. "image[7,1.63;1,1;" .. defaulttexturedir_esc .. "btn_play_icon.png]" .. - "tooltip[play;".. fgettext("Play Game") .. "]" .. - "image_button[7.2,3.09;4,0.83;" .. defaulttexturedir_esc .. creative_bg .. ";;;true;false]" .. - "style[cb_creative_mode;content_offset=0]" .. - "image_button[7.2,3.09;4,0.83;" .. defaulttexturedir_esc .. creative_checkbox .. - ";cb_creative_mode;;true;false]" .. + "style[cb_creative_mode;content_offset=0;font_size=*" .. (small_screen and 1.2 or 1.5) .. + ";textcolor=#53659C]" .. + "image_button[6.86,3.09;4.65,0.83;" .. defaulttexturedir_esc .. "creative_bg.png;cb_creative_mode;;true;false]" .. + "image[6.96,3.19;0.55,0.55;" .. defaulttexturedir_esc .. "gui" .. DIR_DELIM_esc .. + (core.settings:get_bool("creative_mode") and "checkbox_checked" or "checkbox") .. ".png]" .. + "image_button[7.31,3.09;4.2,0.83;;cb_creative_mode;" .. c_label .. ";true;false]" .. "background9[0,0;6.5,4.8;" .. defaulttexturedir_esc .. "worldlist_bg.png;false;40]" .. "tableoptions[background=#0000;border=false]" .. + "tablecolumns[" .. image_column(fgettext("Creative mode")) .. ";text]" .. "table[0,0;6.28,4.64;sp_worlds;" .. menu_render_worldlist() .. ";" .. index .. "]" .. btn_style("switch_local") .. @@ -157,6 +150,13 @@ local function main_button_handler(this, fields, name) end if event.type == "CHG" and selected ~= nil then + local world = menudata.worldlist:get_list()[selected] + if world and world.creative_mode ~= nil and + world.enable_damage ~= nil then + core.settings:set_bool("creative_mode", world.creative_mode) + core.settings:set_bool("enable_damage", world.enable_damage) + end + core.settings:set("mainmenu_last_selected_world", menudata.worldlist:get_raw_index(selected)) return true @@ -168,9 +168,23 @@ local function main_button_handler(this, fields, name) end if fields["cb_creative_mode"] then - local creative_mode = core.settings:get_bool("creative_mode") - core.settings:set("creative_mode", tostring(not creative_mode)) - core.settings:set("enable_damage", tostring(creative_mode)) + local creative_mode = core.settings:get_bool("creative_mode", false) + core.settings:set_bool("creative_mode", not creative_mode) + core.settings:set_bool("enable_damage", creative_mode) + + local selected = core.get_table_index("sp_worlds") + local world = menudata.worldlist:get_list()[selected] + if world then + -- Update the cached values + world.creative_mode = not creative_mode + world.enable_damage = creative_mode + + -- Update the settings in world.mt + local world_conf = Settings(world.path .. DIR_DELIM .. "world.mt") + world_conf:set_bool("creative_mode", not creative_mode) + world_conf:set_bool("enable_damage", creative_mode) + world_conf:write() + end return true end @@ -297,6 +311,21 @@ local function on_change(type, _, _, this) else mm_texture.update("singleplayer",game) menudata.worldlist:set_filtercriteria("default") + + -- Update creative_mode and enable_damage settings + local index = filterlist.get_current_index(menudata.worldlist, + tonumber(core.settings:get("mainmenu_last_selected_world"))) + local world = menudata.worldlist:get_list()[index] or menudata.worldlist:get_list()[1] + if world then + if world.creative_mode == nil or world.enable_damage == nil then + local world_conf = Settings(world.path .. DIR_DELIM .. "world.mt") + world.creative_mode = world_conf:get_bool("creative_mode") + world.enable_damage = world_conf:get_bool("enable_damage") + end + + core.settings:set_bool("creative_mode", world.creative_mode) + core.settings:set_bool("enable_damage", world.enable_damage) + end end end end diff --git a/builtin/mainmenu/tab_online.lua b/builtin/mainmenu/tab_online.lua index dbd0056ad..2ae12987b 100644 --- a/builtin/mainmenu/tab_online.lua +++ b/builtin/mainmenu/tab_online.lua @@ -46,10 +46,9 @@ local function get_formspec(tabview, name, tabdata) local retval = -- Search "formspec_version[3]" .. - "image[-0.11,4.93;7.02,0.81;" .. defaulttexturedir_esc .. "field_bg.png;32]" .. + "image[-0.11,4.93;8.02,0.81;" .. defaulttexturedir_esc .. "field_bg.png;32]" .. "style[Dte_search;border=false;bgcolor=transparent]" .. - "field[0.25,5.25;5.7,0.83;Dte_search;;" .. esc(tabdata.search_for) .. "]" .. - btn_style("btn_mp_clear") .. + "field[0.25,5.25;5.9,0.83;Dte_search;;" .. esc(tabdata.search_for) .. "]" .. "image_button[5.62,4.93;0.83,0.83;" .. defaulttexturedir_esc .. "clear.png;btn_mp_clear;;true;false]" .. btn_style("btn_mp_refresh") .. @@ -94,8 +93,8 @@ local function get_formspec(tabview, name, tabdata) "tooltip[btn_delete_favorite;" .. fgettext("Del. Favorite") .. "]" end if selected.description then - retval = retval .. "textarea[7.5,2.2;4.8,3;;" .. - esc((gamedata.serverdescription or ""), true) .. ";]" + retval = retval .. + "textarea[7.5,2.2;4.8,3;;" .. esc((gamedata.serverdescription or ""), true) .. ";]" end end diff --git a/builtin/mainmenu/tab_settings.lua b/builtin/mainmenu/tab_settings.lua index 733cea2c3..afff0be90 100644 --- a/builtin/mainmenu/tab_settings.lua +++ b/builtin/mainmenu/tab_settings.lua @@ -47,65 +47,50 @@ local labels = { } local dd_options = { - leaves = { - table.concat(labels.leaves, ","), - {"opaque", "simple", "fancy"} - }, - node_highlighting = { - table.concat(labels.node_highlighting, ","), - {"box", "halo", "none"} - }, - filters = { - table.concat(labels.filters, ","), - {"", "bilinear_filter", "trilinear_filter"} - }, - mipmap = { - table.concat(labels.mipmap, ","), - {"", "mip_map", "anisotropic_filter"} - }, - antialiasing = { - table.concat(labels.antialiasing, ","), - {"0", "2", "4", "8"} - } + leaves = {"opaque", "simple", "fancy"}, + node_highlighting = {"box", "halo", "none"}, + filters = {"", "bilinear_filter", "trilinear_filter"}, + mipmap = {"", "mip_map", "anisotropic_filter"}, + antialiasing = {"0", "2", "4", "8"} } local getSettingIndex = { Leaves = function() local style = core.settings:get("leaves_style") - for idx, name in pairs(dd_options.leaves[2]) do + for idx, name in pairs(dd_options.leaves) do if style == name then return idx end end return 1 end, NodeHighlighting = function() local style = core.settings:get("node_highlighting") - for idx, name in pairs(dd_options.node_highlighting[2]) do + for idx, name in pairs(dd_options.node_highlighting) do if style == name then return idx end end return 1 end, Filter = function() - if core.settings:get(dd_options.filters[2][3]) == "true" then + if core.settings:get(dd_options.filters[3]) == "true" then return 3 - elseif core.settings:get(dd_options.filters[2][3]) == "false" and - core.settings:get(dd_options.filters[2][2]) == "true" then + elseif core.settings:get(dd_options.filters[3]) == "false" and + core.settings:get(dd_options.filters[2]) == "true" then return 2 end return 1 end, Mipmap = function() - if core.settings:get(dd_options.mipmap[2][3]) == "true" then + if core.settings:get(dd_options.mipmap[3]) == "true" then return 3 - elseif core.settings:get(dd_options.mipmap[2][3]) == "false" and - core.settings:get(dd_options.mipmap[2][2]) == "true" then + elseif core.settings:get(dd_options.mipmap[3]) == "false" and + core.settings:get(dd_options.mipmap[2]) == "true" then return 2 end return 1 end, Antialiasing = function() local antialiasing_setting = core.settings:get("fsaa") - for i = 1, #dd_options.antialiasing[2] do - if antialiasing_setting == dd_options.antialiasing[2][i] then + for i = 1, #dd_options.antialiasing do + if antialiasing_setting == dd_options.antialiasing[i] then return i end end @@ -113,106 +98,102 @@ local getSettingIndex = { end } -local function antialiasing_fname_to_name(fname) - for i = 1, #labels.antialiasing do - if fname == labels.antialiasing[i] then - return dd_options.antialiasing[2][i] - end - end - return 0 +local function setting_cb(x, y, setting, label) + return checkbox(x, y, "cb_" .. setting, label, core.settings:get_bool(setting), true) end +local function disabled_cb(x, y, _, label) + return ("label[%s,%s;%s]"):format(x + 0.6, y, core.colorize("#888", label)) +end + +local open_dropdown local function formspec(tabview, name, tabdata) - local tab_string = - "background9[0.1,0.1;3.75,4.5;" .. defaulttexturedir_esc .. "desc_bg.png;false;32]" .. - "checkbox[0.25,0;cb_smooth_lighting;" .. fgettext("Smooth Lighting") .. ";" - .. dump(core.settings:get_bool("smooth_lighting")) .. "]" .. - "checkbox[0.25,0.5;cb_particles;" .. fgettext("Particles") .. ";" - .. dump(core.settings:get_bool("enable_particles")) .. "]" .. - "checkbox[0.25,1;cb_3d_clouds;" .. fgettext("3D Clouds") .. ";" - .. dump(core.settings:get_bool("enable_3d_clouds")) .. "]" .. - "checkbox[0.25,1.5;cb_opaque_water;" .. fgettext("Opaque Water") .. ";" - .. dump(core.settings:get_bool("opaque_water")) .. "]" .. - "checkbox[0.25,2.0;cb_connected_glass;" .. fgettext("Connected Glass") .. ";" - .. dump(core.settings:get_bool("connected_glass")) .. "]" .. - "dropdown[0.25,2.8;3.5;dd_node_highlighting;" .. dd_options.node_highlighting[1] .. ";" - .. getSettingIndex.NodeHighlighting() .. "]" .. - "dropdown[0.25,3.6;3.5;dd_leaves_style;" .. dd_options.leaves[1] .. ";" - .. getSettingIndex.Leaves() .. "]" .. - "background9[4.1,0.1;3.75,4.5;" .. defaulttexturedir_esc .. "desc_bg.png;false;32]" .. - "label[4.25,0.1;" .. fgettext("Texturing:") .. "]" .. - "dropdown[4.25,0.55;3.5;dd_filters;" .. dd_options.filters[1] .. ";" - .. getSettingIndex.Filter() .. "]" .. - "dropdown[4.25,1.35;3.5;dd_mipmap;" .. dd_options.mipmap[1] .. ";" - .. getSettingIndex.Mipmap() .. "]" .. - "label[4.25,2.15;" .. fgettext("Antialiasing:") .. "]" .. - "dropdown[4.25,2.6;3.5;dd_antialiasing;" .. dd_options.antialiasing[1] .. ";" - .. getSettingIndex.Antialiasing() .. "]" .. - "label[4.25,3.45;" .. fgettext("Screen:") .. "]" .. - "checkbox[4.25,3.6;cb_autosave_screensize;" .. fgettext("Autosave Screen Size") .. ";" - .. dump(core.settings:get_bool("autosave_screensize")) .. "]" .. - "background9[8.1,0.1;3.75,4.5;" .. defaulttexturedir_esc .. "desc_bg.png;false;32]" + local open_dropdown_fs + local function dropdown(x, y, w, name, items, selected_idx, max_items) + local dd = get_dropdown(x, y, w, name, items, selected_idx, open_dropdown == name, max_items) + if open_dropdown == name then + open_dropdown_fs = dd + return "" + end + return dd + end + + local fs = { + "formspec_version[4]", + "real_coordinates[true]", + "background9[0.625,0.6;4.7,5.2;", defaulttexturedir_esc, "desc_bg.png;false;32]", + setting_cb(0.825, 1, "smooth_lighting", fgettext("Smooth Lighting")), + setting_cb(0.825, 1.6, "enable_particles", fgettext("Particles")), + setting_cb(0.825, 2.2, "enable_3d_clouds", fgettext("3D Clouds")), + setting_cb(0.825, 2.8, "opaque_water", fgettext("Opaque Water")), + setting_cb(0.825, 3.4, "connected_glass", fgettext("Connected Glass")), + dropdown(0.825, 3.8, 4.3, "dd_node_highlighting", labels.node_highlighting, + getSettingIndex.NodeHighlighting()), + dropdown(0.825, 4.8, 4.3, "dd_leaves_style", labels.leaves, + getSettingIndex.Leaves()), + + -- Middle column + "background9[5.6875,0.6;4.7,5.2;", defaulttexturedir_esc, "desc_bg.png;false;32]", + "label[5.8875,1;", fgettext("Texturing:"), "]", + dropdown(5.8875, 1.3, 4.3, "dd_filters", labels.filters, + getSettingIndex.Filter()), + dropdown(5.8875, 2.3, 4.3, "dd_mipmap", labels.mipmap, + getSettingIndex.Mipmap()), + + "label[5.8875,3.4;", fgettext("Antialiasing:"), "]", + dropdown(5.8875, 3.7, 4.3, "dd_antialiasing", labels.antialiasing, + getSettingIndex.Antialiasing()), + + "label[5.8875,4.8;", fgettext("Screen:"), "]", + checkbox(5.8875, 5.3, "cb_autosave_screensize", fgettext("Autosave Screen Size"), + core.settings:get_bool("autosave_screensize")), + "background9[10.75,0.6;4.7,5.2;", defaulttexturedir_esc, "desc_bg.png;false;32]", + } + + local shader_y = 1 + if core.settings:get("touchscreen_threshold") ~= nil then + fs[#fs + 1] = "label[10.95,1;" .. fgettext("Touchthreshold: (px)") .. "]" + fs[#fs + 1] = dropdown(10.95, 1.3, 4.3, "dd_touchthreshold", + {"0", "10", "20", "30", "40", "50"}, + (tonumber(core.settings:get("touchscreen_threshold")) / 10) + 1) + shader_y = 2.9 + end local video_driver = core.settings:get("video_driver") local shaders_enabled = core.settings:get_bool("enable_shaders") if video_driver == "opengl" then - tab_string = tab_string .. - "checkbox[8.25,0;cb_shaders;" .. fgettext("Shaders") .. ";" - .. tostring(shaders_enabled) .. "]" + fs[#fs + 1] = checkbox(10.95, shader_y, "cb_shaders", fgettext("Shaders"), shaders_enabled) elseif video_driver == "ogles2" then - tab_string = tab_string .. - "checkbox[8.25,0;cb_shaders;" .. fgettext("Shaders (experimental)") .. ";" - .. tostring(shaders_enabled) .. "]" + fs[#fs + 1] = checkbox(10.95, shader_y, "cb_shaders", fgettext("Shaders (experimental)"), shaders_enabled) else core.settings:set_bool("enable_shaders", false) shaders_enabled = false - tab_string = tab_string .. - "label[8.38,0.2;" .. core.colorize("#888888", - fgettext("Shaders (unavailable)")) .. "]" + fs[#fs + 1] = disabled_cb(10.95, shader_y, nil, fgettext("Shaders (unavailable)")) end - tab_string = tab_string .. - btn_style("btn_change_keys") .. - "button[8,4.75;3.95,1;btn_change_keys;" - .. fgettext("Change Keys") .. "]" + local shader_cb = shaders_enabled and setting_cb or disabled_cb + table.insert_all(fs, { + shader_cb(10.95, shader_y + 0.6, "cb_tonemapping", fgettext("Tone Mapping"), + core.settings:get_bool("tone_mapping")), + shader_cb(10.95, shader_y + 1.2, "cb_waving_water", fgettext("Waving Liquids"), + core.settings:get_bool("enable_waving_water")), + shader_cb(10.95, shader_y + 1.8, "cb_waving_leaves", fgettext("Waving Leaves"), + core.settings:get_bool("enable_waving_leaves")), + shader_cb(10.95, shader_y + 2.4, "cb_waving_plants", fgettext("Waving Plants"), + core.settings:get_bool("enable_waving_plants")), - tab_string = tab_string .. - btn_style("btn_advanced_settings") .. - "button[0,4.75;3.95,1;btn_advanced_settings;" - .. fgettext("All Settings") .. "]" + btn_style("btn_change_keys"), + "button[10.75,6.1;4.7,0.8;btn_change_keys;", fgettext("Change Keys"), "]", + btn_style("btn_advanced_settings"), + "button[0.625,6.1;4.7,0.8;btn_advanced_settings;", fgettext("All Settings"), "]", + }) - if core.settings:get("touchscreen_threshold") ~= nil then - tab_string = tab_string .. - "label[4.3,4.2;" .. fgettext("Touchthreshold: (px)") .. "]" .. - "dropdown[4.25,4.65;3.5;dd_touchthreshold;0,10,20,30,40,50;" .. - ((tonumber(core.settings:get("touchscreen_threshold")) / 10) + 1) .. - "]box[4.0,4.5;3.75,1.0;#999999]" - end + -- Add the open dropdown (if any) last + fs[#fs + 1] = open_dropdown_fs + fs[#fs + 1] = "real_coordinates[false]" - if shaders_enabled then - tab_string = tab_string .. - "checkbox[8.25,0.5;cb_tonemapping;" .. fgettext("Tone Mapping") .. ";" - .. dump(core.settings:get_bool("tone_mapping")) .. "]" .. - "checkbox[8.25,1;cb_waving_water;" .. fgettext("Waving Liquids") .. ";" - .. dump(core.settings:get_bool("enable_waving_water")) .. "]" .. - "checkbox[8.25,1.5;cb_waving_leaves;" .. fgettext("Waving Leaves") .. ";" - .. dump(core.settings:get_bool("enable_waving_leaves")) .. "]" .. - "checkbox[8.25,2;cb_waving_plants;" .. fgettext("Waving Plants") .. ";" - .. dump(core.settings:get_bool("enable_waving_plants")) .. "]" - else - tab_string = tab_string .. - "label[8.38,0.7;" .. core.colorize("#888888", - fgettext("Tone Mapping")) .. "]" .. - "label[8.38,1.2;" .. core.colorize("#888888", - fgettext("Waving Liquids")) .. "]" .. - "label[8.38,1.7;" .. core.colorize("#888888", - fgettext("Waving Leaves")) .. "]" .. - "label[8.38,2.2;" .. core.colorize("#888888", - fgettext("Waving Plants")) .. "]" - end - - return tab_string + return table.concat(fs) end -------------------------------------------------------------------------------- @@ -226,116 +207,59 @@ local function handle_settings_buttons(this, fields, tabname, tabdata) --mm_texture.update("singleplayer", current_game()) return true end - if fields["cb_smooth_lighting"] then - core.settings:set("smooth_lighting", fields["cb_smooth_lighting"]) - return true - end - if fields["cb_particles"] then - core.settings:set("enable_particles", fields["cb_particles"]) - return true - end - if fields["cb_3d_clouds"] then - core.settings:set("enable_3d_clouds", fields["cb_3d_clouds"]) - return true - end - if fields["cb_opaque_water"] then - core.settings:set("opaque_water", fields["cb_opaque_water"]) - return true - end - if fields["cb_connected_glass"] then - core.settings:set("connected_glass", fields["cb_connected_glass"]) - return true - end - if fields["cb_autosave_screensize"] then - core.settings:set("autosave_screensize", fields["cb_autosave_screensize"]) - return true - end + if fields["cb_shaders"] then 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.settings:set("enable_shaders", fields["cb_shaders"]) + core.settings:set_bool("enable_shaders", not core.settings:get_bool("enable_shaders")) end return true end - if fields["cb_tonemapping"] then - core.settings:set("tone_mapping", fields["cb_tonemapping"]) - return true - end - if fields["cb_waving_water"] then - core.settings:set("enable_waving_water", fields["cb_waving_water"]) - return true - end - if fields["cb_waving_leaves"] then - core.settings:set("enable_waving_leaves", fields["cb_waving_leaves"]) - end - if fields["cb_waving_plants"] then - core.settings:set("enable_waving_plants", fields["cb_waving_plants"]) - return true + + for field in pairs(fields) do + if field:sub(1, 3) == "cb_" then + -- Checkboxes + local setting_name = field:sub(4) + core.settings:set_bool(setting_name, not core.settings:get_bool(setting_name)) + print('Updated', setting_name) + return true + elseif field:sub(1, 3) == "dd_" then + -- Dropdown buttons + open_dropdown = field + return true + elseif open_dropdown and field:sub(1, 9) == "dropdown_" then + -- Dropdown fields + local i = tonumber(field:sub(10)) + if i then + if open_dropdown == "dd_leaves_style" then + core.settings:set("leaves_style", dd_options.leaves[i]) + elseif open_dropdown == "dd_node_highlighting" then + core.settings:set("node_highlighting", dd_options.node_highlighting[i]) + elseif open_dropdown == "dd_filters" then + core.settings:set_bool("bilinear_filter", i == 2) + core.settings:set_bool("trilinear_filter", i == 3) + elseif open_dropdown == "dd_mipmap" then + core.settings:set_bool("mip_map", i >= 2) + core.settings:set_bool("anisotropic_filter", i >= 3) + elseif open_dropdown == "dd_antialiasing" then + core.settings:set("fsaa", dd_options.antialiasing[i]) + elseif open_dropdown == "dd_touchthreshold" then + core.settings:set("touchscreen_threshold", (i - 1) * 10) + end + end + + open_dropdown = nil + return true + end end + if fields["btn_change_keys"] then core.show_keys_menu() return true end - if fields["cb_touchscreen_target"] then - core.settings:set("touchtarget", fields["cb_touchscreen_target"]) - return true - end - - --Note dropdowns have to be handled LAST! - local ddhandled = false - - for i = 1, #labels.leaves do - if fields["dd_leaves_style"] == labels.leaves[i] then - 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.settings:set("node_highlighting", dd_options.node_highlighting[2][i]) - ddhandled = true - end - end - if fields["dd_filters"] == labels.filters[1] then - core.settings:set("bilinear_filter", "false") - core.settings:set("trilinear_filter", "false") - ddhandled = true - elseif fields["dd_filters"] == labels.filters[2] then - core.settings:set("bilinear_filter", "true") - core.settings:set("trilinear_filter", "false") - ddhandled = true - elseif fields["dd_filters"] == labels.filters[3] then - core.settings:set("bilinear_filter", "false") - core.settings:set("trilinear_filter", "true") - ddhandled = true - end - if fields["dd_mipmap"] == labels.mipmap[1] then - core.settings:set("mip_map", "false") - core.settings:set("anisotropic_filter", "false") - ddhandled = true - elseif fields["dd_mipmap"] == labels.mipmap[2] then - core.settings:set("mip_map", "true") - core.settings:set("anisotropic_filter", "false") - ddhandled = true - elseif fields["dd_mipmap"] == labels.mipmap[3] then - core.settings:set("mip_map", "true") - core.settings:set("anisotropic_filter", "true") - ddhandled = true - end - if fields["dd_antialiasing"] then - core.settings:set("fsaa", - antialiasing_fname_to_name(fields["dd_antialiasing"])) - ddhandled = true - end - if fields["dd_touchthreshold"] then - core.settings:set("touchscreen_threshold", fields["dd_touchthreshold"]) - ddhandled = true - end - - return ddhandled end return { diff --git a/builtin/mainmenu/tab_settings_simple.lua b/builtin/mainmenu/tab_settings_simple.lua index 6d6990dfb..aba7e5683 100644 --- a/builtin/mainmenu/tab_settings_simple.lua +++ b/builtin/mainmenu/tab_settings_simple.lua @@ -60,141 +60,146 @@ end -------------------------------------------------------------------------------- -local labels = { - node_highlighting = { - fgettext("Node Outlining"), - fgettext("Node Highlighting"), - fgettext("None") - } +local languages, lang_idx, language_labels = get_language_list() + +local node_highlighting_labels = { + fgettext("Node Outlining"), + fgettext("Node Highlighting"), + fgettext("None") } +local fps_max_labels = {"30", "60", "90", [-1] = "45"} + local dd_options = { - node_highlighting = { - table.concat(labels.node_highlighting, ","), - {"box", "halo", "none"} - } + -- "30 FPS" actually sets 35 FPS for some reason + fps_max = {"35", "60", "90"}, + language = languages, + node_highlighting = {"box", "halo", "none"}, + viewing_range = {"30", "40", "60", "80", "100", "125", "150", "175", "200"}, } local getSettingIndex = { NodeHighlighting = function() local style = core.settings:get("node_highlighting") - for idx, name in pairs(dd_options.node_highlighting[2]) do + for idx, name in pairs(dd_options.node_highlighting) do if style == name then return idx end end return 1 end } -local languages, language_dropdown, lang_idx = get_language_list() +local function setting_cb(x, y, setting, label) + return checkbox(x, y, "cb_" .. setting, label, core.settings:get_bool(setting), true) +end +local function disabled_cb(x, y, _, label) + return ("label[%s,%s;%s]"):format(x + 0.6, y, core.colorize("#888", label)) +end + +local open_dropdown +local guitexturedir = defaulttexturedir_esc .. "gui" .. DIR_DELIM_esc local function formspec(tabview, name, tabdata) local fps = tonumber(core.settings:get("fps_max")) local range = tonumber(core.settings:get("viewing_range")) local sensitivity = tonumber(core.settings:get("touch_sensitivity") or 0) * 2000 local touchtarget = core.settings:get_bool("touchtarget", false) local fancy_leaves = core.settings:get("leaves_style") == "fancy" - local arm_inertia = core.settings:get_bool("arm_inertia", false) - local sound = tonumber(core.settings:get("sound_volume")) ~= 0 and true or false - - local tab_string = - "background9[0,0.05;3.85,5.5;" .. defaulttexturedir_esc .. "desc_bg.png;false;32]" .. - "checkbox[0.15,-0.1;cb_smooth_lighting;" .. fgettext("Smooth Lighting") .. ";" - .. dump(core.settings:get_bool("smooth_lighting")) .. "]" .. - "checkbox[0.15,0.45;cb_particles;" .. fgettext("Particles") .. ";" - .. dump(core.settings:get_bool("enable_particles")) .. "]" .. - "checkbox[0.15,1.05;cb_3d_clouds;" .. fgettext("3D Clouds") .. ";" - .. dump(core.settings:get_bool("enable_3d_clouds")) .. "]" .. - --[["checkbox[0.15,1.65;cb_opaque_water;" .. fgettext("Opaque Water") .. ";" - .. dump(core.settings:get_bool("opaque_water")) .. "]" .. - "checkbox[0.15,1.95;cb_connected_glass;" .. fgettext("Connected Glass") .. ";" - .. dump(core.settings:get_bool("connected_glass")) .. "]" ..]] - "checkbox[0.15,1.65;cb_fog;" .. fgettext("Fog") .. ";" - .. dump(core.settings:get_bool("enable_fog")) .. "]" .. - "checkbox[0.15,2.25;cb_inventory_items_animations;" .. fgettext("Inv. animations") .. ";" - .. dump(core.settings:get_bool("inventory_items_animations")) .. "]" .. - "checkbox[0.15,2.85;cb_fancy_leaves;" .. fgettext("Fancy Leaves") .. ";" - .. dump(fancy_leaves) .. "]" .. - "checkbox[0.15,3.45;cb_crosshair;" .. fgettext("Crosshair") .. ";" - .. dump(not touchtarget) .. "]" .. - "checkbox[0.15,4.05;cb_arm_inertia;" .. fgettext("Arm inertia") .. ";" - .. dump(arm_inertia) .. "]" .. - "checkbox[0.15,4.65;cb_sound;" .. fgettext("Sound") .. ";" - .. dump(sound) .. "]" .. - - "background9[4.1,0.05;3.75,5.5;" .. defaulttexturedir_esc .. "desc_bg.png;false;32]" .. - - "label[4.25,0.1;" .. fgettext("Maximum FPS") .. ":]" .. - "dropdown[4.25,0.55;3.5;dd_fps_max;30,35,45,60,90;" .. - (fps <= 30 and 1 or fps == 35 and 2 or fps == 45 and 3 or fps == 60 and 4 or 5) .. "]" .. - - "label[4.25,1.5;" .. fgettext("Viewing range") .. ":]" .. - "dropdown[4.25,1.95;3.5;dd_viewing_range;30,40,60,80,100,125,150,175,200;" .. - (range <= 30 and 1 or range == 40 and 2 or range == 60 and 3 or - range == 80 and 4 or range == 100 and 5 or range == 125 and 6 or - range == 150 and 7 or range == 175 and 8 or 9) .. "]" .. - - "label[4.25,2.9;" .. fgettext("Node highlighting") .. ":]" .. - "dropdown[4.25,3.35;3.5;dd_node_highlighting;" .. dd_options.node_highlighting[1] .. ";" - .. getSettingIndex.NodeHighlighting() .. "]" .. - - "label[4.25,4.3;" .. fgettext("Mouse sensitivity") .. ":]" .. - "scrollbar[4.25,4.75;3.23,0.5;horizontal;sb_sensitivity;" .. sensitivity .. "]" .. - - "background9[8.1,0.05;3.85,3.15;" .. defaulttexturedir_esc .. "desc_bg.png;false;32]" + local sound = tonumber(core.settings:get("sound_volume")) ~= 0 local video_driver = core.settings:get("video_driver") local shaders_enabled = video_driver == "opengl" or video_driver == "ogles2" core.settings:set_bool("enable_shaders", shaders_enabled) - if shaders_enabled then - tab_string = tab_string .. - "label[8.25,0.1;" .. fgettext("Shaders") .. "]" - else - tab_string = tab_string .. - "label[8.25,0.1;" .. core.colorize("#888888", - fgettext("Shaders (unavailable)")) .. "]" + + local open_dropdown_fs + local function dropdown(x, y, w, name, items, selected_idx, max_items, container_pos) + local dd = get_dropdown(x, y, w, name, items, selected_idx, open_dropdown == name, max_items) + if open_dropdown == name then + open_dropdown_fs = dd + -- Items positioned inside scroll containers are very slightly + -- offset from the same item in a regular container + if container_pos then + open_dropdown_fs = "scroll_container[" .. container_pos .. ";" .. w + x + 1 .. ",10;;vertical;0]" .. + open_dropdown_fs .. + "scroll_container_end[]" + end + return "" + end + return dd end ---[[tab_string = tab_string .. - btn_style("btn_change_keys") .. - "button[8,3.22;3.95,1;btn_change_keys;" - .. fgettext("Change Keys") .. "]" + local shader_cb = shaders_enabled and setting_cb or disabled_cb + local fs = { + "formspec_version[4]", + "real_coordinates[true]", + "background9[0.5,0.5;4.8,6.4;", defaulttexturedir_esc, "desc_bg.png;false;32]", - tab_string = tab_string .. - btn_style("btn_advanced_settings") .. - "button[8,4.57;3.95,1;btn_advanced_settings;" - .. fgettext("All Settings") .. "]"]] + -- A scroll container is used so that long labels are clipped + "scroll_container[0.5,0.5;4.8,6.4;;vertical;0]", - if shaders_enabled then - tab_string = tab_string .. - "checkbox[8.25,0.45;cb_tonemapping;" .. fgettext("Tone Mapping") .. ";" - .. dump(core.settings:get_bool("tone_mapping")) .. "]" .. - "checkbox[8.25,1.05;cb_waving_water;" .. fgettext("Waving liquids") .. ";" - .. dump(core.settings:get_bool("enable_waving_water")) .. "]" .. - "checkbox[8.25,1.65;cb_waving_leaves;" .. fgettext("Waving leaves") .. ";" - .. dump(core.settings:get_bool("enable_waving_leaves")) .. "]" .. - "checkbox[8.25,2.25;cb_waving_plants;" .. fgettext("Waving plants") .. ";" - .. dump(core.settings:get_bool("enable_waving_plants")) .. "]" - else - tab_string = tab_string .. - "label[8.38,0.65;" .. core.colorize("#888888", - fgettext("Tone Mapping")) .. "]" .. - "label[8.38,1.25;" .. core.colorize("#888888", - fgettext("Waving Liquids")) .. "]" .. - "label[8.38,1.85;" .. core.colorize("#888888", - fgettext("Waving Leaves")) .. "]" .. - "label[8.38,2.45;" .. core.colorize("#888888", - fgettext("Waving Plants")) .. "]" - end + setting_cb(0.3, 0.5, "smooth_lighting", fgettext("Smooth Lighting")), + setting_cb(0.3, 1.175, "enable_particles", fgettext("Particles")), + setting_cb(0.3, 1.85, "enable_3d_clouds", fgettext("3D Clouds")), + -- setting_cb(0.3, y, "opaque_water", fgettext("Opaque Water")), + -- setting_cb(0.3, y, "connected_glass", fgettext("Connected Glass")), + setting_cb(0.3, 2.525, "enable_fog", fgettext("Fog")), + setting_cb(0.3, 3.2, "inventory_items_animations", fgettext("Inv. animations")), - tab_string = tab_string .. - "background9[8.1,3.35;3.85,2.2;" .. defaulttexturedir_esc .. "desc_bg.png;false;32]" .. - "label[8.25,3.3;" .. fgettext("Language") .. ":]" .. - "dropdown[8.25,3.75;3.58;dd_language;" .. language_dropdown .. ";" .. - lang_idx .. ";true]" .. - btn_style("btn_reset") .. - "button[8.25,4.6;3.5,0.8;btn_reset;" .. fgettext("Reset all settings") .. "]" + -- Some checkboxes don't directly have a boolean setting so they need + -- to be handled separately + checkbox(0.3, 3.875, "fancy_leaves", fgettext("Fancy Leaves"), fancy_leaves, true), + checkbox(0.3, 4.55, "crosshair", fgettext("Crosshair"), not touchtarget, true), + setting_cb(0.3, 5.225, "arm_inertia", fgettext("Arm inertia")), + checkbox(0.3, 5.9, "sound", fgettext("Sound"), sound, true), - return tab_string + "scroll_container_end[]", + + -- Middle column + "background9[5.6,0.5;4.8,6.4;", defaulttexturedir_esc, "desc_bg.png;false;32]", + "scroll_container[5.6,0.5;4.8,6.4;;vertical;0]", + "label[0.3,0.5;", fgettext("Maximum FPS"), ":]", + dropdown(0.3, 0.8, 4.2, "dd_fps_max", fps_max_labels, + fps <= 35 and 1 or fps == 45 and -1 or fps == 60 and 2 or 3, nil, "5.6,0.5"), + + "label[0.3,2;", fgettext("Viewing range"), ":]", + dropdown(0.3, 2.3, 4.2, "dd_viewing_range", dd_options.viewing_range, + range <= 30 and 1 or range == 40 and 2 or range == 60 and 3 or + range == 80 and 4 or range == 100 and 5 or range == 125 and 6 or + range == 150 and 7 or range == 175 and 8 or 9, 4.5, "5.6,0.5"), + + "label[0.3,3.5;", fgettext("Node highlighting"), ":]", + dropdown(0.3, 3.8, 4.2, "dd_node_highlighting", node_highlighting_labels, + getSettingIndex.NodeHighlighting(), nil, "5.6,0.5"), + + "label[0.3,5;", fgettext("Mouse sensitivity"), ":]", + "scrollbar[0.3,5.3;4.2,0.8;horizontal;sb_sensitivity;", tostring(sensitivity), ";", + guitexturedir, "scrollbar_horiz_bg.png,", guitexturedir, "scrollbar_slider.png,", + guitexturedir, "scrollbar_minus.png,", guitexturedir, "scrollbar_plus.png]", + "scroll_container_end[]", + + -- Right column + "background9[10.7,0.5;4.8,1.9;", defaulttexturedir_esc, "desc_bg.png;false;32]", + "label[11,1;", fgettext("Language"), ":]", + dropdown(11, 1.3, 4.2, "dd_language", language_labels, lang_idx, 6.4), + + "background9[10.7,2.6;4.8,4.3;", defaulttexturedir_esc, "desc_bg.png;false;32]", + "scroll_container[10.7,2.6;4.8,4.3;;vertical;0]", + "label[0.3,0.5;", shaders_enabled and fgettext("Shaders") or + core.colorize("#888888", fgettext("Shaders (unavailable)")), "]", + shader_cb(0.3, 1, "tone_mapping", fgettext("Tone Mapping")), + shader_cb(0.3, 1.6, "enable_waving_water", fgettext("Waving liquids")), + shader_cb(0.3, 2.2, "enable_waving_leaves", fgettext("Waving leaves")), + shader_cb(0.3, 2.8, "enable_waving_plants", fgettext("Waving plants")), + "scroll_container_end[]", + + btn_style("btn_reset"), + "button[11,5.8;4.2,0.8;btn_reset;", fgettext("Reset all settings"), "]", + } + + -- Show the open dropdown (if any) last + fs[#fs + 1] = open_dropdown_fs + fs[#fs + 1] = "real_coordinates[false]" + + return table.concat(fs) end -------------------------------------------------------------------------------- @@ -206,65 +211,49 @@ local function handle_settings_buttons(this, fields, tabname, tabdata) adv_settings_dlg:show() return true end]] - if fields["cb_smooth_lighting"] then - core.settings:set("smooth_lighting", fields["cb_smooth_lighting"]) + + for field in pairs(fields) do + if field:sub(1, 3) == "cb_" then + -- Checkboxes + local setting_name = field:sub(4) + core.settings:set_bool(setting_name, not core.settings:get_bool(setting_name)) + return true + elseif field:sub(1, 3) == "dd_" then + -- Dropdown buttons + open_dropdown = field + return true + elseif open_dropdown and field:sub(1, 9) == "dropdown_" then + -- Dropdown fields + local i = tonumber(field:sub(10)) + local setting = open_dropdown:sub(4) + if i and dd_options[setting] then + core.settings:set(setting, dd_options[setting][i]) + + -- Reload the main menu so that everything uses the new language + if setting == "language" then + dofile(core.get_builtin_path() .. "init.lua") + end + end + + open_dropdown = nil + return true + end + end + + -- Special checkboxes + if fields["fancy_leaves"] then + core.settings:set("leaves_style", core.settings:get("leaves_style") == "fancy" and "opaque" or "fancy") return true end - if fields["cb_particles"] then - core.settings:set("enable_particles", fields["cb_particles"]) + if fields["crosshair"] then + core.settings:set_bool("touchtarget", not core.settings:get_bool("touchtarget")) return true end - if fields["cb_3d_clouds"] then - core.settings:set("enable_3d_clouds", fields["cb_3d_clouds"]) - return true - end - if fields["cb_opaque_water"] then - core.settings:set("opaque_water", fields["cb_opaque_water"]) - return true - end ---[[if fields["cb_connected_glass"] then - core.settings:set("connected_glass", fields["cb_connected_glass"]) - return true - end]] - if fields["cb_fog"] then - core.settings:set("enable_fog", fields["cb_fog"]) - return true - end - if fields["cb_inventory_items_animations"] then - core.settings:set("inventory_items_animations", fields["cb_inventory_items_animations"]) - return true - end - if fields["cb_fancy_leaves"] then - core.settings:set("leaves_style", (minetest.is_yes(fields["cb_fancy_leaves"]) and "fancy" or "opaque")) - return true - end - if fields["cb_crosshair"] then - core.settings:set_bool("touchtarget", not minetest.is_yes(fields["cb_crosshair"])) - return true - end - if fields["cb_arm_inertia"] then - core.settings:set("arm_inertia", fields["cb_arm_inertia"]) - return true - end - if fields["cb_sound"] then - core.settings:set("sound_volume", (minetest.is_yes(fields["cb_sound"]) and "1.0") or "0.0") - return true - end - if fields["cb_tonemapping"] then - core.settings:set("tone_mapping", fields["cb_tonemapping"]) - return true - end - if fields["cb_waving_water"] then - core.settings:set("enable_waving_water", fields["cb_waving_water"]) - return true - end - if fields["cb_waving_leaves"] then - core.settings:set("enable_waving_leaves", fields["cb_waving_leaves"]) - end - if fields["cb_waving_plants"] then - core.settings:set("enable_waving_plants", fields["cb_waving_plants"]) + if fields["sound"] then + core.settings:set("sound_volume", tonumber(core.settings:get("sound_volume")) == 0 and "1.0" or "0.0") return true end + --[[if fields["btn_change_keys"] then core.show_keys_menu() return true @@ -278,27 +267,6 @@ local function handle_settings_buttons(this, fields, tabname, tabdata) return true end - -- Note dropdowns have to be handled LAST! - local ddhandled = false - - if fields["cb_touchscreen_target"] then - core.settings:set("touchtarget", fields["cb_touchscreen_target"]) - ddhandled = true - end - for i = 1, #labels.node_highlighting do - if fields["dd_node_highlighting"] == labels.node_highlighting[i] then - core.settings:set("node_highlighting", dd_options.node_highlighting[2][i]) - ddhandled = true - end - end - if fields["dd_fps_max"] then - core.settings:set("fps_max", fields["dd_fps_max"]) - ddhandled = true - end - if fields["dd_viewing_range"] then - core.settings:set("viewing_range", fields["dd_viewing_range"]) - ddhandled = true - end if fields["sb_sensitivity"] then -- reset old setting core.settings:remove("touchscreen_threshold") @@ -306,24 +274,8 @@ local function handle_settings_buttons(this, fields, tabname, tabdata) local event = core.explode_scrollbar_event(fields["sb_sensitivity"]) if event.type == "CHG" then core.settings:set("touch_sensitivity", event.value / 2000) - - -- The formspec cannot be updated or the scrollbar movement will - -- break. - ddhandled = false end end - if fields["dd_language"] then - local new_idx = tonumber(fields["dd_language"]) - if lang_idx ~= new_idx then - core.settings:set("language", languages[new_idx] or "") - ddhandled = true - - -- Reload the main menu so that everything uses the new language - dofile(core.get_builtin_path() .. "init.lua") - end - end - - return ddhandled end return { diff --git a/textures/base/pack/clear.png b/textures/base/pack/clear.png index 32b3dbf9f..64d94f042 100644 Binary files a/textures/base/pack/clear.png and b/textures/base/pack/clear.png differ diff --git a/textures/base/pack/creative_bg.png b/textures/base/pack/creative_bg.png index 0e5026ede..1a0c8ce85 100644 Binary files a/textures/base/pack/creative_bg.png and b/textures/base/pack/creative_bg.png differ diff --git a/textures/base/pack/creative_bg_ru.png b/textures/base/pack/creative_bg_ru.png deleted file mode 100644 index 3a308d263..000000000 Binary files a/textures/base/pack/creative_bg_ru.png and /dev/null differ diff --git a/textures/base/pack/creative_checkbox.png b/textures/base/pack/creative_checkbox.png deleted file mode 100644 index aed949949..000000000 Binary files a/textures/base/pack/creative_checkbox.png and /dev/null differ diff --git a/textures/base/pack/error_screenshot.png b/textures/base/pack/error_screenshot.png index 2a3b70d97..e57e49b0e 100644 Binary files a/textures/base/pack/error_screenshot.png and b/textures/base/pack/error_screenshot.png differ diff --git a/textures/base/pack/field_bg.png b/textures/base/pack/field_bg.png index 2f7754af5..502fd7ef0 100644 Binary files a/textures/base/pack/field_bg.png and b/textures/base/pack/field_bg.png differ diff --git a/textures/base/pack/gui/cdb_img_corners.png b/textures/base/pack/gui/cdb_img_corners.png new file mode 100644 index 000000000..f9917d7fa Binary files /dev/null and b/textures/base/pack/gui/cdb_img_corners.png differ diff --git a/textures/base/pack/gui/checkbox.png b/textures/base/pack/gui/checkbox.png new file mode 100644 index 000000000..020176f3a Binary files /dev/null and b/textures/base/pack/gui/checkbox.png differ diff --git a/textures/base/pack/gui/checkbox_checked.png b/textures/base/pack/gui/checkbox_checked.png new file mode 100644 index 000000000..f2a2c8044 Binary files /dev/null and b/textures/base/pack/gui/checkbox_checked.png differ diff --git a/textures/base/pack/gui/dropdown.png b/textures/base/pack/gui/dropdown.png new file mode 100644 index 000000000..f26982c9e Binary files /dev/null and b/textures/base/pack/gui/dropdown.png differ diff --git a/textures/base/pack/gui/dropdown_arrow.png b/textures/base/pack/gui/dropdown_arrow.png new file mode 100644 index 000000000..9323698fb Binary files /dev/null and b/textures/base/pack/gui/dropdown_arrow.png differ diff --git a/textures/base/pack/gui/dropdown_bg.png b/textures/base/pack/gui/dropdown_bg.png new file mode 100644 index 000000000..4e198fdc9 Binary files /dev/null and b/textures/base/pack/gui/dropdown_bg.png differ diff --git a/textures/base/pack/gui/dropdown_bg_end.png b/textures/base/pack/gui/dropdown_bg_end.png new file mode 100644 index 000000000..2d858dd4f Binary files /dev/null and b/textures/base/pack/gui/dropdown_bg_end.png differ diff --git a/textures/base/pack/gui/dropdown_bg_end_hover.png b/textures/base/pack/gui/dropdown_bg_end_hover.png new file mode 100644 index 000000000..6111f8694 Binary files /dev/null and b/textures/base/pack/gui/dropdown_bg_end_hover.png differ diff --git a/textures/base/pack/gui/dropdown_bg_hover.png b/textures/base/pack/gui/dropdown_bg_hover.png new file mode 100644 index 000000000..d4a84201a Binary files /dev/null and b/textures/base/pack/gui/dropdown_bg_hover.png differ diff --git a/textures/base/pack/gui/dropdown_fg_end.png b/textures/base/pack/gui/dropdown_fg_end.png new file mode 100644 index 000000000..0b505773c Binary files /dev/null and b/textures/base/pack/gui/dropdown_fg_end.png differ diff --git a/textures/base/pack/gui/dropdown_open.png b/textures/base/pack/gui/dropdown_open.png new file mode 100644 index 000000000..decab945d Binary files /dev/null and b/textures/base/pack/gui/dropdown_open.png differ diff --git a/textures/base/pack/loading_screenshot.png b/textures/base/pack/loading_screenshot.png index 9b5db64f2..5a8453cf5 100644 Binary files a/textures/base/pack/loading_screenshot.png and b/textures/base/pack/loading_screenshot.png differ diff --git a/textures/base/pack/no_screenshot.png b/textures/base/pack/no_screenshot.png index 427ff62f3..e62e38f11 100644 Binary files a/textures/base/pack/no_screenshot.png and b/textures/base/pack/no_screenshot.png differ