Use tree to list mods rather than textlist

This commit is contained in:
rubenwardy 2016-12-27 23:26:36 +00:00 committed by Nils Dagsson Moskopp
parent 3c57053538
commit a41241456a
Signed by: erle
GPG Key ID: A3BC671C35191080
3 changed files with 59 additions and 112 deletions

View File

@ -17,14 +17,13 @@
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
local enabled_all = false local enabled_all = false
local function modname_valid(name) local function modname_valid(name)
return not name:find("[^a-z0-9_]") return not name:find("[^a-z0-9_]")
end end
local function get_formspec(data) local function get_formspec(data)
local mod = data.list:get_list()[data.selected_mod] local mod = data.list:get_list()[data.selected_mod]
local retval = local retval =
@ -32,24 +31,12 @@ local function get_formspec(data)
"label[0.5,0;" .. fgettext("World:") .. "]" .. "label[0.5,0;" .. fgettext("World:") .. "]" ..
"label[1.75,0;" .. data.worldspec.name .. "]" "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 if mod == nil then
mod = {name=""} mod = {name=""}
end end
local hard_deps, soft_deps = modmgr.get_dependencies(mod.path) local hard_deps, soft_deps = modmgr.get_dependencies(mod.path)
retval = retval .. retval = retval ..
"label[0,0.7;" .. fgettext("Mod:") .. "]" .. "label[0,0.7;" .. fgettext("Mod:") .. "]" ..
"label[0.75,0.7;" .. mod.name .. "]" .. "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[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") .. "]" "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 if mod.is_modpack then
local rawlist = data.list:get_raw_list() local rawlist = data.list:get_raw_list()
local all_enabled = true local all_enabled = true
for j=1,#rawlist,1 do for j = 1, #rawlist, 1 do
if rawlist[j].modpack == mod.name and if rawlist[j].modpack == mod.name and not rawlist[j].enabled then
rawlist[j].enabled ~= true then all_enabled = false
all_enabled = false break
break
end end
end end
if all_enabled == false then if all_enabled then
retval = retval .. "button[5.5,0.125;2.5,0.5;btn_mp_enable;" .. fgettext("Enable MP") .. "]" retval = retval .. "button[5.5,0.125;2.5,0.5;btn_mp_disable;" ..
fgettext("Disable MP") .. "]"
else 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 end
else else
if mod.enabled then 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 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 end
end end
if enabled_all then if enabled_all then
retval = retval .. retval = retval ..
"button[8.75,0.125;2.5,0.5;btn_disable_all_mods;" .. fgettext("Disable all") .. "]" .. "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;"
else else
retval = retval .. retval = retval ..
"button[8.75,0.125;2.5,0.5;btn_enable_all_mods;" .. fgettext("Enable all") .. "]" .. "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;"
end 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 .. modmgr.render_modlist(data.list)
retval = retval .. ";" .. data.selected_mod .."]" retval = retval .. ";" .. data.selected_mod .."]"
@ -129,16 +120,15 @@ end
local function handle_buttons(this, fields) local function handle_buttons(this, fields)
if fields["world_config_modlist"] ~= nil then if fields["world_config_modlist"] ~= nil then
local event = core.explode_textlist_event(fields["world_config_modlist"]) local event = core.explode_table_event(fields["world_config_modlist"])
this.data.selected_mod = event.index this.data.selected_mod = event.row
core.setting_set("world_config_selected_mod", event.index) core.setting_set("world_config_selected_mod", event.row)
if event.type == "DCL" then if event.type == "DCL" then
enable_mod(this) enable_mod(this)
end end
return true return true
end end
@ -160,44 +150,7 @@ local function handle_buttons(this, fields)
return true return true
end 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 if fields["btn_config_world_save"] then
local filename = this.data.worldspec.path .. local filename = this.data.worldspec.path ..
DIR_DELIM .. "world.mt" DIR_DELIM .. "world.mt"
@ -231,7 +184,7 @@ local function handle_buttons(this, fields)
if not worldfile:write() then if not worldfile:write() then
core.log("error", "Failed to write world config file") core.log("error", "Failed to write world config file")
end end
this:delete() this:delete()
return true return true
end end
@ -252,7 +205,7 @@ local function handle_buttons(this, fields)
enabled_all = true enabled_all = true
return true return true
end end
if fields.btn_disable_all_mods then if fields.btn_disable_all_mods then
local list = this.data.list:get_raw_list() local list = this.data.list:get_raw_list()
@ -269,14 +222,11 @@ local function handle_buttons(this, fields)
end end
function create_configure_world_dlg(worldidx) function create_configure_world_dlg(worldidx)
local dlg = dialog_create("sp_config_world", local dlg = dialog_create("sp_config_world",
get_formspec, get_formspec,
handle_buttons, handle_buttons,
nil) 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")) dlg.data.selected_mod = tonumber(core.setting_get("world_config_selected_mod"))
if dlg.data.selected_mod == nil then if dlg.data.selected_mod == nil then
dlg.data.selected_mod = 0 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 if dlg.data.worldspec == nil then dlg:delete() return nil end
dlg.data.worldconfig = modmgr.get_worldconfig(dlg.data.worldspec.path) dlg.data.worldconfig = modmgr.get_worldconfig(dlg.data.worldspec.path)
if dlg.data.worldconfig == nil or dlg.data.worldconfig.id == nil or if dlg.data.worldconfig == nil or dlg.data.worldconfig.id == nil or
dlg.data.worldconfig.id == "" then dlg.data.worldconfig.id == "" then
dlg:delete() dlg:delete()
return nil return nil
end end
dlg.data.list = filterlist.create( dlg.data.list = filterlist.create(
modmgr.preparemodlist, --refresh modmgr.preparemodlist, --refresh
modmgr.comparemod, --compare modmgr.comparemod, --compare

View File

@ -18,7 +18,7 @@
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
function get_mods(path,retval,modpack) function get_mods(path,retval,modpack)
local mods = core.get_dir_list(path, true) local mods = core.get_dir_list(path, true)
for _, name in ipairs(mods) do for _, name in ipairs(mods) do
if name:sub(1, 1) ~= "." then if name:sub(1, 1) ~= "." then
local prefix = path .. DIR_DELIM .. name .. DIR_DELIM local prefix = path .. DIR_DELIM .. name .. DIR_DELIM
@ -237,49 +237,45 @@ function modmgr.render_modlist(render_list)
local list = render_list:get_list() local list = render_list:get_list()
local last_modpack = nil local last_modpack = nil
local retval = {}
for i,v in ipairs(list) do local in_game_mods = false
if retval ~= "" then for i, v in ipairs(list) do
retval = retval .."," if v.typ == "game_mod" and not in_game_mods then
in_game_mods = true
retval[#retval + 1] = mt_color_blue
retval[#retval + 1] = "0"
retval[#retval + 1] = fgettext("Subgame Mods")
end end
local color = "" local color = ""
if v.is_modpack then if v.is_modpack then
local rawlist = render_list:get_raw_list() local rawlist = render_list:get_raw_list()
color = mt_color_dark_green
local all_enabled = true for j = 1, #rawlist, 1 do
for j=1,#rawlist,1 do
if rawlist[j].modpack == list[i].name and if rawlist[j].modpack == list[i].name and
rawlist[j].enabled ~= true then rawlist[j].enabled ~= true then
all_enabled = false -- Modpack not entirely enabled so showing as grey
break color = mt_color_grey
break
end end
end end
elseif v.typ == "game_mod" then
if all_enabled == false then
color = mt_color_grey
else
color = mt_color_dark_green
end
end
if v.typ == "game_mod" then
color = mt_color_blue color = mt_color_blue
else elseif v.enabled then
if v.enabled then color = mt_color_green
color = mt_color_green
end
end end
retval = retval .. color retval[#retval + 1] = color
if v.modpack ~= nil then if v.modpack ~= nil or v.typ == "game_mod" then
retval = retval .. " " retval[#retval + 1] = "1"
else
retval[#retval + 1] = "0"
end end
retval = retval .. v.name retval[#retval + 1] = core.formspec_escape(v.name)
end end
return retval return table.concat(retval, ",")
end end
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------

View File

@ -28,7 +28,8 @@ local function get_formspec(tabview, name, tabdata)
local retval = local retval =
"label[0.05,-0.25;".. fgettext("Installed Mods:") .. "]" .. "label[0.05,-0.25;".. fgettext("Installed Mods:") .. "]" ..
"textlist[0,0.25;5.1,5;modlist;" .. "tablecolumns[color;tree;text]" ..
"table[0,0.25;5.1,5;modlist;" ..
modmgr.render_modlist(modmgr.global_mods) .. modmgr.render_modlist(modmgr.global_mods) ..
";" .. tabdata.selected_mod .. "]" ";" .. tabdata.selected_mod .. "]"
@ -127,8 +128,8 @@ end
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
local function handle_buttons(tabview, fields, tabname, tabdata) local function handle_buttons(tabview, fields, tabname, tabdata)
if fields["modlist"] ~= nil then if fields["modlist"] ~= nil then
local event = core.explode_textlist_event(fields["modlist"]) local event = core.explode_table_event(fields["modlist"])
tabdata.selected_mod = event.index tabdata.selected_mod = event.row
return true return true
end end