From bb4db84bdbc7038a6ac495dd5f732f89ac40bfcc Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Tue, 27 Dec 2016 23:26:36 +0000 Subject: Use tree to list mods rather than textlist --- builtin/mainmenu/dlg_config_world.lua | 110 ++++++++++------------------------ 1 file changed, 30 insertions(+), 80 deletions(-) (limited to 'builtin/mainmenu/dlg_config_world.lua') diff --git a/builtin/mainmenu/dlg_config_world.lua b/builtin/mainmenu/dlg_config_world.lua index 7b3ab9852..619c927c5 100644 --- a/builtin/mainmenu/dlg_config_world.lua +++ b/builtin/mainmenu/dlg_config_world.lua @@ -17,14 +17,13 @@ -------------------------------------------------------------------------------- -local enabled_all = false +local enabled_all = false local function modname_valid(name) return not name:find("[^a-z0-9_]") end local function get_formspec(data) - local mod = data.list:get_list()[data.selected_mod] local retval = @@ -32,24 +31,12 @@ local function get_formspec(data) "label[0.5,0;" .. fgettext("World:") .. "]" .. "label[1.75,0;" .. data.worldspec.name .. "]" - if data.hide_gamemods then - retval = retval .. "checkbox[1,6;cb_hide_gamemods;" .. fgettext("Hide Game") .. ";true]" - else - retval = retval .. "checkbox[1,6;cb_hide_gamemods;" .. fgettext("Hide Game") .. ";false]" - end - - if data.hide_modpackcontents then - retval = retval .. "checkbox[6,6;cb_hide_mpcontent;" .. fgettext("Hide mp content") .. ";true]" - else - retval = retval .. "checkbox[6,6;cb_hide_mpcontent;" .. fgettext("Hide mp content") .. ";false]" - end - if mod == nil then mod = {name=""} end local hard_deps, soft_deps = modmgr.get_dependencies(mod.path) - + retval = retval .. "label[0,0.7;" .. fgettext("Mod:") .. "]" .. "label[0.75,0.7;" .. mod.name .. "]" .. @@ -62,41 +49,45 @@ local function get_formspec(data) "button[3.25,7;2.5,0.5;btn_config_world_save;" .. fgettext("Save") .. "]" .. "button[5.75,7;2.5,0.5;btn_config_world_cancel;" .. fgettext("Cancel") .. "]" - if mod ~= nil and mod.name ~= "" and mod.typ ~= "game_mod" then + if mod and mod.name ~= "" and mod.typ ~= "game_mod" then if mod.is_modpack then local rawlist = data.list:get_raw_list() local all_enabled = true - for j=1,#rawlist,1 do - if rawlist[j].modpack == mod.name and - rawlist[j].enabled ~= true then - all_enabled = false - break + for j = 1, #rawlist, 1 do + if rawlist[j].modpack == mod.name and not rawlist[j].enabled then + all_enabled = false + break end end - if all_enabled == false then - retval = retval .. "button[5.5,0.125;2.5,0.5;btn_mp_enable;" .. fgettext("Enable MP") .. "]" + if all_enabled then + retval = retval .. "button[5.5,0.125;2.5,0.5;btn_mp_disable;" .. + fgettext("Disable MP") .. "]" else - retval = retval .. "button[5.5,0.125;2.5,0.5;btn_mp_disable;" .. fgettext("Disable MP") .. "]" + retval = retval .. "button[5.5,0.125;2.5,0.5;btn_mp_enable;" .. + fgettext("Enable MP") .. "]" end else if mod.enabled then - retval = retval .. "checkbox[5.5,-0.125;cb_mod_enable;" .. fgettext("enabled") .. ";true]" + retval = retval .. "checkbox[5.5,-0.125;cb_mod_enable;" .. + fgettext("enabled") .. ";true]" else - retval = retval .. "checkbox[5.5,-0.125;cb_mod_enable;" .. fgettext("enabled") .. ";false]" + retval = retval .. "checkbox[5.5,-0.125;cb_mod_enable;" .. + fgettext("enabled") .. ";false]" end end end - if enabled_all then + if enabled_all then retval = retval .. - "button[8.75,0.125;2.5,0.5;btn_disable_all_mods;" .. fgettext("Disable all") .. "]" .. - "textlist[5.5,0.75;5.75,5.4;world_config_modlist;" + "button[8.75,0.125;2.5,0.5;btn_disable_all_mods;" .. fgettext("Disable all") .. "]" else retval = retval .. - "button[8.75,0.125;2.5,0.5;btn_enable_all_mods;" .. fgettext("Enable all") .. "]" .. - "textlist[5.5,0.75;5.75,5.4;world_config_modlist;" + "button[8.75,0.125;2.5,0.5;btn_enable_all_mods;" .. fgettext("Enable all") .. "]" end + retval = retval .. + "tablecolumns[color;tree;text]" .. + "table[5.5,0.75;5.75,6;world_config_modlist;" retval = retval .. modmgr.render_modlist(data.list) retval = retval .. ";" .. data.selected_mod .."]" @@ -129,16 +120,15 @@ end local function handle_buttons(this, fields) - if fields["world_config_modlist"] ~= nil then - local event = core.explode_textlist_event(fields["world_config_modlist"]) - this.data.selected_mod = event.index - core.setting_set("world_config_selected_mod", event.index) + local event = core.explode_table_event(fields["world_config_modlist"]) + this.data.selected_mod = event.row + core.setting_set("world_config_selected_mod", event.row) if event.type == "DCL" then enable_mod(this) end - + return true end @@ -160,44 +150,7 @@ local function handle_buttons(this, fields) return true end - if fields["cb_hide_gamemods"] ~= nil or - fields["cb_hide_mpcontent"] ~= nil then - local current = this.data.list:get_filtercriteria() - - if current == nil then - current = {} - end - - if fields["cb_hide_gamemods"] ~= nil then - if core.is_yes(fields["cb_hide_gamemods"]) then - current.hide_game = true - this.data.hide_gamemods = true - core.setting_set("world_config_hide_gamemods", "true") - else - current.hide_game = false - this.data.hide_gamemods = false - core.setting_set("world_config_hide_gamemods", "false") - end - end - - if fields["cb_hide_mpcontent"] ~= nil then - if core.is_yes(fields["cb_hide_mpcontent"]) then - current.hide_modpackcontents = true - this.data.hide_modpackcontents = true - core.setting_set("world_config_hide_modpackcontents", "true") - else - current.hide_modpackcontents = false - this.data.hide_modpackcontents = false - core.setting_set("world_config_hide_modpackcontents", "false") - end - end - - this.data.list:set_filtercriteria(current) - return true - end - if fields["btn_config_world_save"] then - local filename = this.data.worldspec.path .. DIR_DELIM .. "world.mt" @@ -231,7 +184,7 @@ local function handle_buttons(this, fields) if not worldfile:write() then core.log("error", "Failed to write world config file") end - + this:delete() return true end @@ -252,7 +205,7 @@ local function handle_buttons(this, fields) enabled_all = true return true end - + if fields.btn_disable_all_mods then local list = this.data.list:get_raw_list() @@ -269,14 +222,11 @@ local function handle_buttons(this, fields) end function create_configure_world_dlg(worldidx) - local dlg = dialog_create("sp_config_world", get_formspec, handle_buttons, nil) - dlg.data.hide_gamemods = core.setting_getbool("world_config_hide_gamemods") - dlg.data.hide_modpackcontents = core.setting_getbool("world_config_hide_modpackcontents") dlg.data.selected_mod = tonumber(core.setting_get("world_config_selected_mod")) if dlg.data.selected_mod == nil then dlg.data.selected_mod = 0 @@ -286,14 +236,14 @@ function create_configure_world_dlg(worldidx) if dlg.data.worldspec == nil then dlg:delete() return nil end dlg.data.worldconfig = modmgr.get_worldconfig(dlg.data.worldspec.path) - + if dlg.data.worldconfig == nil or dlg.data.worldconfig.id == nil or dlg.data.worldconfig.id == "" then dlg:delete() return nil end - + dlg.data.list = filterlist.create( modmgr.preparemodlist, --refresh modmgr.comparemod, --compare -- cgit v1.2.3 From 43d1f375d18a2fbc547a9b4f23d1354d645856ca Mon Sep 17 00:00:00 2001 From: ShadowNinja Date: Fri, 12 Dec 2014 14:49:19 -0500 Subject: Use a settings object for the main settings This unifies the settings APIs. This also unifies the sync and async registration APIs, since the async registration API did not support adding non-functions to the API table. --- builtin/mainmenu/dlg_config_world.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'builtin/mainmenu/dlg_config_world.lua') diff --git a/builtin/mainmenu/dlg_config_world.lua b/builtin/mainmenu/dlg_config_world.lua index 619c927c5..3e5ba16eb 100644 --- a/builtin/mainmenu/dlg_config_world.lua +++ b/builtin/mainmenu/dlg_config_world.lua @@ -123,7 +123,7 @@ local function handle_buttons(this, fields) if fields["world_config_modlist"] ~= nil then local event = core.explode_table_event(fields["world_config_modlist"]) this.data.selected_mod = event.row - core.setting_set("world_config_selected_mod", event.row) + core.settings:set("world_config_selected_mod", event.row) if event.type == "DCL" then enable_mod(this) @@ -227,7 +227,7 @@ function create_configure_world_dlg(worldidx) handle_buttons, nil) - dlg.data.selected_mod = tonumber(core.setting_get("world_config_selected_mod")) + dlg.data.selected_mod = tonumber(core.settings:get("world_config_selected_mod")) if dlg.data.selected_mod == nil then dlg.data.selected_mod = 0 end -- cgit v1.2.3 From 674400523e10624ae8320b0d18a05dbfd6dcac42 Mon Sep 17 00:00:00 2001 From: SmallJoker Date: Fri, 19 May 2017 07:45:47 +0200 Subject: Mainmenu: Fix issues while trying to enable all mods (#5770) --- builtin/mainmenu/dlg_config_world.lua | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) (limited to 'builtin/mainmenu/dlg_config_world.lua') diff --git a/builtin/mainmenu/dlg_config_world.lua b/builtin/mainmenu/dlg_config_world.lua index 3e5ba16eb..fcedadea8 100644 --- a/builtin/mainmenu/dlg_config_world.lua +++ b/builtin/mainmenu/dlg_config_world.lua @@ -49,7 +49,7 @@ local function get_formspec(data) "button[3.25,7;2.5,0.5;btn_config_world_save;" .. fgettext("Save") .. "]" .. "button[5.75,7;2.5,0.5;btn_config_world_cancel;" .. fgettext("Cancel") .. "]" - if mod and mod.name ~= "" and mod.typ ~= "game_mod" then + if mod and mod.name ~= "" and not mod.is_game_content then if mod.is_modpack then local rawlist = data.list:get_raw_list() @@ -97,7 +97,7 @@ end local function enable_mod(this, toset) local mod = this.data.list:get_list()[this.data.selected_mod] - if mod.typ == "game_mod" then + if mod.is_game_content then -- game mods can't be enabled or disabled elseif not mod.is_modpack then if toset == nil then @@ -162,7 +162,7 @@ local function handle_buttons(this, fields) local i,mod for i,mod in ipairs(rawlist) do if not mod.is_modpack and - mod.typ ~= "game_mod" then + not mod.is_game_content then if modname_valid(mod.name) then worldfile:set("load_mod_"..mod.name, tostring(mod.enabled)) else @@ -198,7 +198,8 @@ local function handle_buttons(this, fields) local list = this.data.list:get_raw_list() for i = 1, #list do - if list[i].typ ~= "game_mod" and not list[i].is_modpack then + if not list[i].is_game_content + and not list[i].is_modpack then list[i].enabled = true end end @@ -210,7 +211,8 @@ local function handle_buttons(this, fields) local list = this.data.list:get_raw_list() for i = 1, #list do - if list[i].typ ~= "game_mod" and not list[i].is_modpack then + if not list[i].is_game_content + and not list[i].is_modpack then list[i].enabled = false end end @@ -252,16 +254,16 @@ function create_configure_world_dlg(worldidx) return true end end, - function(element,criteria) + function(element, criteria) if criteria.hide_game and - element.typ == "game_mod" then - return false + element.is_game_content then + return false end if criteria.hide_modpackcontents and - element.modpack ~= nil then - return false - end + element.modpack ~= nil then + return false + end return true end, --filter { worldpath= dlg.data.worldspec.path, -- cgit v1.2.3