diff options
Diffstat (limited to 'builtin/mainmenu')
-rw-r--r-- | builtin/mainmenu/dlg_contentstore.lua | 61 | ||||
-rw-r--r-- | builtin/mainmenu/dlg_settings_advanced.lua | 6 | ||||
-rw-r--r-- | builtin/mainmenu/tab_local.lua | 92 | ||||
-rw-r--r-- | builtin/mainmenu/tab_settings.lua | 58 | ||||
-rw-r--r-- | builtin/mainmenu/tests/serverlistmgr_spec.lua | 1 |
5 files changed, 185 insertions, 33 deletions
diff --git a/builtin/mainmenu/dlg_contentstore.lua b/builtin/mainmenu/dlg_contentstore.lua index 20a446d5d..790da03ba 100644 --- a/builtin/mainmenu/dlg_contentstore.lua +++ b/builtin/mainmenu/dlg_contentstore.lua @@ -57,24 +57,39 @@ local filter_types_type = { "txp", } +local REASON_NEW = "new" +local REASON_UPDATE = "update" +local REASON_DEPENDENCY = "dependency" + + +local function get_download_url(package, reason) + local base_url = core.settings:get("contentdb_url") + local ret = base_url .. ("/packages/%s/%s/releases/%d/download/"):format(package.author, package.name, package.release) + if reason then + ret = ret .. "?reason=" .. reason + end + return ret +end + local function download_package(param) - if core.download_file(param.package.url, param.filename) then + if core.download_file(param.url, param.filename) then return { filename = param.filename, successful = true, } else - core.log("error", "downloading " .. dump(param.package.url) .. " failed") + core.log("error", "downloading " .. dump(param.url) .. " failed") return { successful = false, } end end -local function start_install(package) +local function start_install(package, reason) local params = { package = package, + url = get_download_url(package, reason), filename = os.tempfolder() .. "_MODNAME_" .. package.name .. ".zip", } @@ -135,7 +150,7 @@ local function start_install(package) if next then table.remove(download_queue, 1) - start_install(next) + start_install(next.package, next.reason) end ui.update() @@ -151,12 +166,12 @@ local function start_install(package) end end -local function queue_download(package) +local function queue_download(package, reason) local max_concurrent_downloads = tonumber(core.settings:get("contentdb_max_concurrent_downloads")) if number_downloading < max_concurrent_downloads then - start_install(package) + start_install(package, reason) else - table.insert(download_queue, package) + table.insert(download_queue, { package = package, reason = reason }) package.queued = true end end @@ -407,12 +422,12 @@ function install_dialog.handle_submit(this, fields) end if fields.install_all then - queue_download(install_dialog.package) + queue_download(install_dialog.package, REASON_NEW) if install_dialog.will_install_deps then for _, dep in pairs(install_dialog.dependencies) do if not dep.is_optional and not dep.installed and dep.package then - queue_download(dep.package) + queue_download(dep.package, REASON_DEPENDENCY) end end end @@ -560,18 +575,25 @@ function store.load() end store.packages_full = core.parse_json(response.data) or {} + store.aliases = {} for _, package in pairs(store.packages_full) do - package.url = base_url .. "/packages/" .. - package.author .. "/" .. package.name .. - "/releases/" .. package.release .. "/download/" - local name_len = #package.name if package.type == "game" and name_len > 5 and package.name:sub(name_len - 4) == "_game" then package.id = package.author:lower() .. "/" .. package.name:sub(1, name_len - 5) else package.id = package.author:lower() .. "/" .. package.name end + + if package.aliases then + for _, alias in ipairs(package.aliases) do + -- We currently don't support name changing + local suffix = "/" .. package.name + if alias:sub(-#suffix) == suffix then + store.aliases[alias:lower()] = package.id + end + end + end end store.packages_full_unordered = store.packages_full @@ -584,7 +606,8 @@ function store.update_paths() pkgmgr.refresh_globals() for _, mod in pairs(pkgmgr.clientmods:get_list()) do if mod.author and mod.release > 0 then - mod_hash[mod.author:lower() .. "/" .. mod.name] = mod + local id = mod.author:lower() .. "/" .. mod.name + mod_hash[store.aliases[id] or id] = mod end end @@ -592,14 +615,16 @@ function store.update_paths() pkgmgr.update_gamelist() for _, game in pairs(pkgmgr.games) do if game.author ~= "" and game.release > 0 then - game_hash[game.author:lower() .. "/" .. game.id] = game + local id = game.author:lower() .. "/" .. game.id + game_hash[store.aliases[id] or id] = game end end local txp_hash = {} for _, txp in pairs(pkgmgr.get_texture_packs()) do if txp.author and txp.release > 0 then - txp_hash[txp.author:lower() .. "/" .. txp.name] = txp + local id = txp.author:lower() .. "/" .. txp.name + txp_hash[store.aliases[id] or id] = txp end end @@ -915,7 +940,7 @@ function store.handle_submit(this, fields) local package = store.packages_full[i] if package.path and package.installed_release < package.release and not (package.downloading or package.queued) then - queue_download(package) + queue_download(package, REASON_UPDATE) end end return true @@ -948,7 +973,7 @@ function store.handle_submit(this, fields) this:hide() dlg:show() else - queue_download(package) + queue_download(package, package.path and REASON_UPDATE or REASON_NEW) end end diff --git a/builtin/mainmenu/dlg_settings_advanced.lua b/builtin/mainmenu/dlg_settings_advanced.lua index 26f4fa4a7..38a658969 100644 --- a/builtin/mainmenu/dlg_settings_advanced.lua +++ b/builtin/mainmenu/dlg_settings_advanced.lua @@ -31,6 +31,10 @@ end -- returns error message, or nil local function parse_setting_line(settings, line, read_all, base_level, allow_secure) + + -- strip carriage returns (CR, /r) + line = line:gsub("\r", "") + -- comment local comment = line:match("^#" .. CHAR_CLASSES.SPACE .. "*(.*)$") if comment then @@ -650,7 +654,7 @@ local function create_change_setting_formspec(dialogdata) -- Third row add_field(0.3, "te_octaves", fgettext("Octaves"), t[7]) - add_field(3.6, "te_persist", fgettext("Persistance"), t[8]) + add_field(3.6, "te_persist", fgettext("Persistence"), t[8]) add_field(6.9, "te_lacun", fgettext("Lacunarity"), t[9]) height = height + 1.1 diff --git a/builtin/mainmenu/tab_local.lua b/builtin/mainmenu/tab_local.lua index 0e06c3bef..be5f905ac 100644 --- a/builtin/mainmenu/tab_local.lua +++ b/builtin/mainmenu/tab_local.lua @@ -18,8 +18,14 @@ local enable_gamebar = PLATFORM ~= "Android" local current_game, singleplayer_refresh_gamebar +local valid_disabled_settings = { + ["enable_damage"]=true, + ["creative_mode"]=true, + ["enable_server"]=true, +} if enable_gamebar then + -- Currently chosen game in gamebar for theming and filtering function current_game() local last_game_id = core.settings:get("menu_last_game") local game = pkgmgr.find_by_gameid(last_game_id) @@ -102,37 +108,87 @@ if enable_gamebar then btnbar:add_button("game_open_cdb", "", plus_image, fgettext("Install games from ContentDB")) end else + -- Currently chosen game in gamebar: no gamebar -> no "current" game function current_game() return nil end end +local function get_disabled_settings(game) + if not game then + return {} + end + + local gameconfig = Settings(game.path .. "/game.conf") + local disabled_settings = {} + if gameconfig then + local disabled_settings_str = (gameconfig:get("disabled_settings") or ""):split() + for _, value in pairs(disabled_settings_str) do + local state = false + value = value:trim() + if string.sub(value, 1, 1) == "!" then + state = true + value = string.sub(value, 2) + end + if valid_disabled_settings[value] then + disabled_settings[value] = state + else + core.log("error", "Invalid disabled setting in game.conf: "..tostring(value)) + end + end + end + return disabled_settings +end + local function get_formspec(tabview, name, tabdata) local retval = "" local index = filterlist.get_current_index(menudata.worldlist, - tonumber(core.settings:get("mainmenu_last_selected_world")) - ) + tonumber(core.settings:get("mainmenu_last_selected_world"))) + local list = menudata.worldlist:get_list() + local world = list and index and list[index] + local gameid = world and world.gameid + local game = gameid and pkgmgr.find_by_gameid(gameid) + local disabled_settings = get_disabled_settings(game) + + local creative, damage, host = "", "", "" + + -- Y offsets for game settings checkboxes + local y = -0.2 + local yo = 0.45 + + if disabled_settings["creative_mode"] == nil then + creative = "checkbox[0,"..y..";cb_creative_mode;".. fgettext("Creative Mode") .. ";" .. + dump(core.settings:get_bool("creative_mode")) .. "]" + y = y + yo + end + if disabled_settings["enable_damage"] == nil then + damage = "checkbox[0,"..y..";cb_enable_damage;".. fgettext("Enable Damage") .. ";" .. + dump(core.settings:get_bool("enable_damage")) .. "]" + y = y + yo + end + if disabled_settings["enable_server"] == nil then + host = "checkbox[0,"..y..";cb_server;".. fgettext("Host Server") ..";" .. + dump(core.settings:get_bool("enable_server")) .. "]" + y = y + yo + end retval = retval .. "button[3.9,3.8;2.8,1;world_delete;".. fgettext("Delete") .. "]" .. "button[6.55,3.8;2.8,1;world_configure;".. fgettext("Select Mods") .. "]" .. "button[9.2,3.8;2.8,1;world_create;".. fgettext("New") .. "]" .. "label[3.9,-0.05;".. fgettext("Select World:") .. "]".. - "checkbox[0,-0.20;cb_creative_mode;".. fgettext("Creative Mode") .. ";" .. - dump(core.settings:get_bool("creative_mode")) .. "]".. - "checkbox[0,0.25;cb_enable_damage;".. fgettext("Enable Damage") .. ";" .. - dump(core.settings:get_bool("enable_damage")) .. "]".. - "checkbox[0,0.7;cb_server;".. fgettext("Host Server") ..";" .. - dump(core.settings:get_bool("enable_server")) .. "]" .. + creative .. + damage .. + host .. "textlist[3.9,0.4;7.9,3.45;sp_worlds;" .. menu_render_worldlist() .. ";" .. index .. "]" - if core.settings:get_bool("enable_server") then + if core.settings:get_bool("enable_server") and disabled_settings["enable_server"] == nil then retval = retval .. "button[7.9,4.75;4.1,1;play;".. fgettext("Host Game") .. "]" .. - "checkbox[0,1.15;cb_server_announce;" .. fgettext("Announce Server") .. ";" .. + "checkbox[0,"..y..";cb_server_announce;" .. fgettext("Announce Server") .. ";" .. dump(core.settings:get_bool("server_announce")) .. "]" .. "field[0.3,2.85;3.8,0.5;te_playername;" .. fgettext("Name") .. ";" .. core.formspec_escape(core.settings:get("name")) .. "]" .. @@ -227,9 +283,21 @@ local function main_button_handler(this, fields, name, tabdata) -- Update last game local world = menudata.worldlist:get_raw_element(gamedata.selected_world) + local game_obj if world then - local game = pkgmgr.find_by_gameid(world.gameid) - core.settings:set("menu_last_game", game.id) + game_obj = pkgmgr.find_by_gameid(world.gameid) + core.settings:set("menu_last_game", game_obj.id) + end + + local disabled_settings = get_disabled_settings(game_obj) + for k, _ in pairs(valid_disabled_settings) do + local v = disabled_settings[k] + if v ~= nil then + if k == "enable_server" and v == true then + error("Setting 'enable_server' cannot be force-enabled! The game.conf needs to be fixed.") + end + core.settings:set_bool(k, disabled_settings[k]) + end end if core.settings:get_bool("enable_server") then diff --git a/builtin/mainmenu/tab_settings.lua b/builtin/mainmenu/tab_settings.lua index 29744048a..f06e35872 100644 --- a/builtin/mainmenu/tab_settings.lua +++ b/builtin/mainmenu/tab_settings.lua @@ -43,6 +43,14 @@ local labels = { fgettext("2x"), fgettext("4x"), fgettext("8x") + }, + shadow_levels = { + fgettext("Disabled"), + fgettext("Very Low"), + fgettext("Low"), + fgettext("Medium"), + fgettext("High"), + fgettext("Ultra High") } } @@ -66,6 +74,10 @@ local dd_options = { antialiasing = { table.concat(labels.antialiasing, ","), {"0", "2", "4", "8"} + }, + shadow_levels = { + table.concat(labels.shadow_levels, ","), + { "0", "1", "2", "3", "4", "5" } } } @@ -110,6 +122,15 @@ local getSettingIndex = { end end return 1 + end, + ShadowMapping = function() + local shadow_setting = core.settings:get("shadow_levels") + for i = 1, #dd_options.shadow_levels[2] do + if shadow_setting == dd_options.shadow_levels[2][i] then + return i + end + end + return 1 end } @@ -197,7 +218,10 @@ local function formspec(tabview, name, tabdata) "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")) .. "]" + .. dump(core.settings:get_bool("enable_waving_plants")) .. "]".. + "label[8.25,3.0;" .. fgettext("Dynamic shadows: ") .. "]" .. + "dropdown[8.25,3.5;3.5;dd_shadows;" .. dd_options.shadow_levels[1] .. ";" + .. getSettingIndex.ShadowMapping() .. "]" else tab_string = tab_string .. "label[8.38,0.7;" .. core.colorize("#888888", @@ -207,7 +231,9 @@ local function formspec(tabview, name, tabdata) "label[8.38,1.7;" .. core.colorize("#888888", fgettext("Waving Leaves")) .. "]" .. "label[8.38,2.2;" .. core.colorize("#888888", - fgettext("Waving Plants")) .. "]" + fgettext("Waving Plants")) .. "]".. + "label[8.38,2.7;" .. core.colorize("#888888", + fgettext("Dynamic shadows")) .. "]" end return tab_string @@ -333,6 +359,34 @@ local function handle_settings_buttons(this, fields, tabname, tabdata) ddhandled = true end + for i = 1, #labels.shadow_levels do + if fields["dd_shadows"] == labels.shadow_levels[i] then + core.settings:set("shadow_levels", dd_options.shadow_levels[2][i]) + ddhandled = true + end + end + + if fields["dd_shadows"] == labels.shadow_levels[1] then + core.settings:set("enable_dynamic_shadows", "false") + else + local shadow_presets = { + [2] = { 80, 512, "true", 0, "false" }, + [3] = { 120, 1024, "true", 1, "false" }, + [4] = { 350, 2048, "true", 1, "false" }, + [5] = { 350, 2048, "true", 2, "true" }, + [6] = { 450, 4096, "true", 2, "true" }, + } + local s = shadow_presets[table.indexof(labels.shadow_levels, fields["dd_shadows"])] + if s then + core.settings:set("enable_dynamic_shadows", "true") + core.settings:set("shadow_map_max_distance", s[1]) + core.settings:set("shadow_map_texture_size", s[2]) + core.settings:set("shadow_map_texture_32bit", s[3]) + core.settings:set("shadow_filters", s[4]) + core.settings:set("shadow_map_color", s[5]) + end + end + return ddhandled end diff --git a/builtin/mainmenu/tests/serverlistmgr_spec.lua b/builtin/mainmenu/tests/serverlistmgr_spec.lua index 148e9b794..a091959fb 100644 --- a/builtin/mainmenu/tests/serverlistmgr_spec.lua +++ b/builtin/mainmenu/tests/serverlistmgr_spec.lua @@ -2,6 +2,7 @@ _G.core = {} _G.unpack = table.unpack _G.serverlistmgr = {} +dofile("builtin/common/vector.lua") dofile("builtin/common/misc_helpers.lua") dofile("builtin/mainmenu/serverlistmgr.lua") |