Add online content repository

Replaces mods and texture pack tabs with a single content tab
This commit is contained in:
rubenwardy 2018-04-17 14:54:50 +01:00 committed by Nils Dagsson Moskopp
parent a7cfc3984c
commit b744f1d46f
Signed by: erle
GPG Key ID: A3BC671C35191080
16 changed files with 1047 additions and 606 deletions

View File

@ -288,11 +288,11 @@ function sort_mod_list(self)
table.sort(self.m_processed_list, function(a, b)
-- Show game mods at bottom
if a.typ ~= b.typ then
if b.typ == "game" then
return a.typ ~= "game_mod"
if a.type ~= b.type or a.loc ~= b.loc then
if b.type == "game" then
return a.loc ~= "game"
end
return b.typ == "game_mod"
return b.loc == "game"
end
-- If in same or no modpack, sort by name
if a.modpack == b.modpack then

View File

@ -551,6 +551,16 @@ function table.copy(t, seen)
end
return n
end
function table.insert_all(t, other)
for i=1, #other do
t[#t + 1] = other[i]
end
return t
end
--------------------------------------------------------------------------------
-- mainmenu only functions
--------------------------------------------------------------------------------

View File

@ -41,7 +41,7 @@ local function render_client_count(n)
end
local function configure_selected_world_params(idx)
local worldconfig = modmgr.get_worldconfig(menudata.worldlist:get_list()[idx].path)
local worldconfig = pkgmgr.get_worldconfig(menudata.worldlist:get_list()[idx].path)
if worldconfig.creative_mode then
core.settings:set("creative_mode", worldconfig.creative_mode)
end

View File

@ -35,7 +35,7 @@ local function get_formspec(data)
mod = {name=""}
end
local hard_deps, soft_deps = modmgr.get_dependencies(mod.path)
local hard_deps, soft_deps = pkgmgr.get_dependencies(mod.path)
retval = retval ..
"label[0,0.7;" .. fgettext("Mod:") .. "]" ..
@ -88,7 +88,7 @@ local function get_formspec(data)
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 .. pkgmgr.render_packagelist(data.list)
retval = retval .. ";" .. data.selected_mod .."]"
return retval
@ -237,7 +237,7 @@ function create_configure_world_dlg(worldidx)
dlg.data.worldspec = core.get_worlds()[worldidx]
if dlg.data.worldspec == nil then dlg:delete() return nil end
dlg.data.worldconfig = modmgr.get_worldconfig(dlg.data.worldspec.path)
dlg.data.worldconfig = pkgmgr.get_worldconfig(dlg.data.worldspec.path)
if dlg.data.worldconfig == nil or dlg.data.worldconfig.id == nil or
dlg.data.worldconfig.id == "" then
@ -247,8 +247,8 @@ function create_configure_world_dlg(worldidx)
end
dlg.data.list = filterlist.create(
modmgr.preparemodlist, --refresh
modmgr.comparemod, --compare
pkgmgr.preparemodlist, --refresh
pkgmgr.comparemod, --compare
function(element,uid) --uid match
if element.name == uid then
return true

View File

@ -0,0 +1,451 @@
--Minetest
--Copyright (C) 2018 rubenwardy
--
--This program is free software; you can redistribute it and/or modify
--it under the terms of the GNU Lesser General Public License as published by
--the Free Software Foundation; either version 2.1 of the License, or
--(at your option) any later version.
--
--This program is distributed in the hope that it will be useful,
--but WITHOUT ANY WARRANTY; without even the implied warranty of
--MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
--GNU Lesser General Public License for more details.
--
--You should have received a copy of the GNU Lesser General Public License along
--with this program; if not, write to the Free Software Foundation, Inc.,
--51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
local function download_package(param)
if core.download_file(param.package.url, param.filename) then
return {
package = param.package,
filename = param.filename,
successful = true,
}
else
core.log("error", "downloading " .. dump(param.package.url) .. " failed")
return {
package = param.package,
successful = false,
}
end
end
local function start_install(calling_dialog, package)
local params = {
package = package,
filename = os.tempfolder() .. "_MODNAME_" .. package.name .. ".zip",
}
local function callback(result)
if result.successful then
local path, msg = pkgmgr.install(result.package.type, result.filename, result.package.name)
if not path then
gamedata.errormessage = msg
else
local conf_path
local name_is_title = false
if result.package.type == "mod" then
conf_path = path .. DIR_DELIM .. "mod.conf"
elseif result.package.type == "game" then
conf_path = path .. DIR_DELIM .. "game.conf"
name_is_title = true
elseif result.package.type == "txp" then
conf_path = path .. DIR_DELIM .. "texture_pack.conf"
end
if conf_path then
local conf = Settings(conf_path)
local function set_def(key, value)
if conf:get(key) == nil then
conf:set(key, value)
end
end
if name_is_title then
set_def("name", result.package.title)
else
set_def("title", result.package.title)
set_def("name", result.package.name)
end
set_def("description", result.package.short_description)
set_def("author", result.package.author)
conf:write()
end
end
os.remove(result.filename)
else
gamedata.errormessage = fgettext("Failed to download $1", package.name)
end
if gamedata.errormessage == nil then
core.button_handler({btn_hidden_close_download=result})
else
core.button_handler({btn_hidden_close_download={successful=false}})
end
end
if not core.handle_async(download_package, params, callback) then
minetest.log("error", "ERROR: async event failed")
gamedata.errormessage = fgettext("Failed to download $1", package.name)
end
local new_dlg = dialog_create("store_downloading",
function(data)
return "size[7,2]label[0.25,0.75;" ..
fgettext("Downloading and installing $1, please wait...", data.title) .. "]"
end,
function(this,fields)
if fields["btn_hidden_close_download"] ~= nil then
this:delete()
return true
end
return false
end,
nil)
new_dlg:set_parent(calling_dialog)
new_dlg.data.title = package.title
calling_dialog:hide()
new_dlg:show()
end
local package_dialog = {}
function package_dialog.get_formspec()
local package = package_dialog.package
local formspec = {
"size[8,4;true]",
"label[2.5,0.2;", core.formspec_escape(package.title), "]",
"label[0,1;", core.formspec_escape(package.short_description), "]",
"button[0,0;2,1;back;", fgettext("Back"), "]",
"button[6,0;2,1;install;", fgettext("Install"), "]",
}
-- TODO: screenshots
return table.concat(formspec, "")
end
function package_dialog.handle_submit(this, fields, tabname, tabdata)
if fields.back then
this:delete()
return true
end
if fields.install then
start_install(package_dialog.package)
return true
end
return false
end
function package_dialog.create(package)
package_dialog.package = package
return dialog_create("package_view",
package_dialog.get_formspec,
package_dialog.handle_submit,
nil)
end
local store = {}
local search_string = ""
local cur_page = 1
local num_per_page = 5
local filter_type = 1
local filter_types_titles = {
fgettext("All packages"),
fgettext("Games"),
fgettext("Mods"),
fgettext("Texture packs"),
}
local filter_types_type = {
nil,
"game",
"mod",
"txp",
}
function store.load()
store.packages_full = core.get_package_list()
store.packages = store.packages_full
store.loaded = true
end
function store.update_paths()
local mod_hash = {}
pkgmgr.refresh_globals()
for _, mod in pairs(pkgmgr.global_mods:get_list()) do
mod_hash[mod.name] = mod
end
local game_hash = {}
pkgmgr.update_gamelist()
for _, game in pairs(pkgmgr.games) do
game_hash[game.id] = game
end
local txp_hash = {}
for _, txp in pairs(pkgmgr.get_texture_packs()) do
txp_hash[txp.name] = txp
end
for _, package in pairs(store.packages_full) do
local content
if package.type == "mod" then
content = mod_hash[package.name]
elseif package.type == "game" then
content = game_hash[package.name]
elseif package.type == "txp" then
content = txp_hash[package.name]
end
if content and content.author == package.author then
package.path = content.path
else
package.path = nil
end
end
end
function store.filter_packages(query)
if query == "" and filter_type == 1 then
store.packages = store.packages_full
return
end
local keywords = {}
for word in query:lower():gmatch("%S+") do
table.insert(keywords, word)
end
local function matches_keywords(package, keywords)
for k = 1, #keywords do
local keyword = keywords[k]
if string.find(package.name:lower(), keyword, 1, true) or
string.find(package.title:lower(), keyword, 1, true) or
string.find(package.author:lower(), keyword, 1, true) or
string.find(package.short_description:lower(), keyword, 1, true) then
return true
end
end
return false
end
store.packages = {}
for _, package in pairs(store.packages_full) do
if (query == "" or matches_keywords(package, keywords)) and
(filter_type == 1 or package.type == filter_types_type[filter_type]) then
store.packages[#store.packages + 1] = package
end
end
end
function store.get_formspec()
assert(store.loaded)
store.update_paths()
local pages = math.ceil(#store.packages / num_per_page)
if cur_page > pages then
cur_page = 1
end
local formspec = {
"size[12,6.5;true]",
"field[0.3,0.1;10.2,1;search_string;;", core.formspec_escape(search_string), "]",
"field_close_on_enter[search_string;false]",
"button[10.2,-0.2;2,1;search;", fgettext("Search"), "]",
"dropdown[0,1;2.4;type;",
table.concat(filter_types_titles, ","),
";",
filter_type,
"]",
-- "textlist[0,1;2.4,5.6;a;",
-- table.concat(taglist, ","),
-- "]"
}
local start_idx = (cur_page - 1) * num_per_page + 1
for i=start_idx, math.min(#store.packages, start_idx+num_per_page-1) do
local package = store.packages[i]
formspec[#formspec + 1] = "container[3,"
formspec[#formspec + 1] = i - start_idx + 1
formspec[#formspec + 1] = "]"
-- image
formspec[#formspec + 1] = "image[-0.4,0;1.5,1;"
formspec[#formspec + 1] = defaulttexturedir
formspec[#formspec + 1] = "no_screenshot.png"
formspec[#formspec + 1] = "]"
-- title
formspec[#formspec + 1] = "label[1,0;"
formspec[#formspec + 1] = core.formspec_escape(package.title ..
" by " .. package.author)
formspec[#formspec + 1] = "]"
-- description
local short = package.short_description
if #short > 60 then
short = short:sub(1, 59) .. ""
end
formspec[#formspec + 1] = "label[1,0.3;"
formspec[#formspec + 1] = core.formspec_escape(short)
formspec[#formspec + 1] = "]"
-- buttons
if package.path then
formspec[#formspec + 1] = "button[6,0;1.5,1;uninstall_"
formspec[#formspec + 1] = tostring(i)
formspec[#formspec + 1] = ";"
formspec[#formspec + 1] = fgettext("Uninstall")
formspec[#formspec + 1] = "]"
else
formspec[#formspec + 1] = "button[6,0;1.5,1;install_"
formspec[#formspec + 1] = tostring(i)
formspec[#formspec + 1] = ";"
formspec[#formspec + 1] = fgettext("Install")
formspec[#formspec + 1] = "]"
end
formspec[#formspec + 1] = "button[7.5,0;1.5,1;view_"
formspec[#formspec + 1] = tostring(i)
formspec[#formspec + 1] = ";"
formspec[#formspec + 1] = fgettext("View")
formspec[#formspec + 1] = "]"
formspec[#formspec + 1] = "container_end[]"
end
formspec[#formspec + 1] = "container[0,"
formspec[#formspec + 1] = num_per_page + 1
formspec[#formspec + 1] = "]"
formspec[#formspec + 1] = "button[2.6,0;3,1;back;"
formspec[#formspec + 1] = fgettext("Back to Main Menu")
formspec[#formspec + 1] = "]"
formspec[#formspec + 1] = "button[7,0;1,1;pstart;<<]"
formspec[#formspec + 1] = "button[8,0;1,1;pback;<]"
formspec[#formspec + 1] = "label[9.2,0.2;"
formspec[#formspec + 1] = tonumber(cur_page)
formspec[#formspec + 1] = " / "
formspec[#formspec + 1] = tonumber(pages)
formspec[#formspec + 1] = "]"
formspec[#formspec + 1] = "button[10,0;1,1;pnext;>]"
formspec[#formspec + 1] = "button[11,0;1,1;pend;>>]"
formspec[#formspec + 1] = "container_end[]"
formspec[#formspec + 1] = "]"
return table.concat(formspec, "")
end
function store.handle_submit(this, fields, tabname, tabdata)
if fields.search or fields.key_enter_field == "search_string" then
search_string = fields.search_string:trim()
cur_page = 1
store.filter_packages(search_string)
core.update_formspec(store.get_formspec())
return true
end
if fields.back then
this:delete()
return true
end
if fields.pstart then
cur_page = 1
core.update_formspec(store.get_formspec())
return true
end
if fields.pend then
cur_page = math.ceil(#store.packages / num_per_page)
core.update_formspec(store.get_formspec())
return true
end
if fields.pnext then
cur_page = cur_page + 1
local pages = math.ceil(#store.packages / num_per_page)
if cur_page > pages then
cur_page = 1
end
core.update_formspec(store.get_formspec())
return true
end
if fields.pback then
if cur_page == 1 then
local pages = math.ceil(#store.packages / num_per_page)
cur_page = pages
else
cur_page = cur_page - 1
end
core.update_formspec(store.get_formspec())
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)
return true
end
end
local start_idx = (cur_page - 1) * num_per_page + 1
assert(start_idx ~= nil)
for i=start_idx, math.min(#store.packages, start_idx+num_per_page-1) do
local package = store.packages[i]
assert(package)
if fields["install_" .. i] then
start_install(this, package)
return true
end
if fields["uninstall_" .. i] then
local dlg_delmod = create_delete_content_dlg(package)
dlg_delmod:set_parent(this)
this:hide()
dlg_delmod:show()
return true
end
if fields["view_" .. i] then
local dlg = package_dialog.create(package)
dlg:set_parent(this)
this:hide()
dlg:show()
return true
end
end
return false
end
function create_store_dlg(type)
if not store.loaded then
store.load()
end
search_string = ""
cur_page = 1
store.filter_packages(search_string)
return dialog_create("store",
store.get_formspec,
store.handle_submit,
nil)
end

View File

@ -26,7 +26,7 @@ local function create_world_formspec(dialogdata)
local game, gameidx = nil , 0
if gameid ~= nil then
game, gameidx = gamemgr.find_by_gameid(gameid)
game, gameidx = pkgmgr.find_by_gameid(gameid)
if gameidx == nil then
gameidx = 0
@ -77,17 +77,17 @@ local function create_world_formspec(dialogdata)
"dropdown[4.2,2;6.3;dd_mapgen;" .. mglist .. ";" .. selindex .. "]" ..
"label[2,3;" .. fgettext("Game") .. "]"..
"textlist[4.2,3;5.8,2.3;games;" .. gamemgr.gamelist() ..
"textlist[4.2,3;5.8,2.3;games;" .. pkgmgr.gamelist() ..
";" .. gameidx .. ";true]" ..
"button[3.25,6;2.5,0.5;world_create_confirm;" .. fgettext("Create") .. "]" ..
"button[5.75,6;2.5,0.5;world_create_cancel;" .. fgettext("Cancel") .. "]"
if #gamemgr.games == 0 then
if #pkgmgr.games == 0 then
retval = retval .. "box[2,4;8,1;#ff8800]label[2.25,4;" ..
fgettext("You have no games installed.") .. "]label[2.25,4.4;" ..
fgettext("Download one from minetest.net") .. "]"
elseif #gamemgr.games == 1 and gamemgr.games[1].id == "minimal" then
elseif #pkgmgr.games == 1 and pkgmgr.games[1].id == "minimal" then
retval = retval .. "box[1.75,4;8.7,1;#ff8800]label[2,4;" ..
fgettext("Warning: The minimal development test is meant for developers.") .. "]label[2,4.4;" ..
fgettext("Download a game, such as minetest_game, from minetest.net") .. "]"
@ -125,10 +125,10 @@ local function create_world_buttonhandler(this, fields)
if message ~= nil then
gamedata.errormessage = message
else
core.settings:set("menu_last_game",gamemgr.games[gameindex].id)
core.settings:set("menu_last_game",pkgmgr.games[gameindex].id)
if this.data.update_worldlist_filter then
menudata.worldlist:set_filtercriteria(gamemgr.games[gameindex].id)
mm_texture.update("singleplayer", gamemgr.games[gameindex].id)
menudata.worldlist:set_filtercriteria(pkgmgr.games[gameindex].id)
mm_texture.update("singleplayer", pkgmgr.games[gameindex].id)
end
menudata.worldlist:refresh()
core.settings:set("mainmenu_last_selected_world",
@ -145,7 +145,7 @@ local function create_world_buttonhandler(this, fields)
if fields["games"] then
local gameindex = core.get_textlist_index("games")
core.settings:set("menu_last_game", gamemgr.games[gameindex].id)
core.settings:set("menu_last_game", pkgmgr.games[gameindex].id)
return true
end

View File

@ -17,39 +17,38 @@
--------------------------------------------------------------------------------
local function delete_mod_formspec(dialogdata)
dialogdata.mod = modmgr.global_mods:get_list()[dialogdata.selected]
local function delete_content_formspec(dialogdata)
local retval =
"size[11.5,4.5,true]" ..
"label[2,2;" ..
fgettext("Are you sure you want to delete \"$1\"?", dialogdata.mod.name) .. "]"..
"button[3.25,3.5;2.5,0.5;dlg_delete_mod_confirm;" .. fgettext("Delete") .. "]" ..
"button[5.75,3.5;2.5,0.5;dlg_delete_mod_cancel;" .. fgettext("Cancel") .. "]"
fgettext("Are you sure you want to delete \"$1\"?", dialogdata.content.name) .. "]"..
"button[3.25,3.5;2.5,0.5;dlg_delete_content_confirm;" .. fgettext("Delete") .. "]" ..
"button[5.75,3.5;2.5,0.5;dlg_delete_content_cancel;" .. fgettext("Cancel") .. "]"
return retval
end
--------------------------------------------------------------------------------
local function delete_mod_buttonhandler(this, fields)
if fields["dlg_delete_mod_confirm"] ~= nil then
local function delete_content_buttonhandler(this, fields)
if fields["dlg_delete_content_confirm"] ~= nil then
if this.data.mod.path ~= nil and
this.data.mod.path ~= "" and
this.data.mod.path ~= core.get_modpath() then
if not core.delete_dir(this.data.mod.path) then
gamedata.errormessage = fgettext("Modmgr: failed to delete \"$1\"", this.data.mod.path)
if this.data.content.path ~= nil and
this.data.content.path ~= "" and
this.data.content.path ~= core.get_modpath() and
this.data.content.path ~= core.get_gamepath() and
this.data.content.path ~= core.get_texturepath() then
if not core.delete_dir(this.data.content.path) then
gamedata.errormessage = fgettext("pkgmgr: failed to delete \"$1\"", this.data.content.path)
end
modmgr.refresh_globals()
pkgmgr.refresh_globals()
else
gamedata.errormessage = fgettext("Modmgr: invalid modpath \"$1\"", this.data.mod.path)
gamedata.errormessage = fgettext("pkgmgr: invalid path \"$1\"", this.data.content.path)
end
this:delete()
return true
end
if fields["dlg_delete_mod_cancel"] then
if fields["dlg_delete_content_cancel"] then
this:delete()
return true
end
@ -58,12 +57,13 @@ local function delete_mod_buttonhandler(this, fields)
end
--------------------------------------------------------------------------------
function create_delete_mod_dlg(selected_index)
function create_delete_content_dlg(content)
assert(content.name)
local retval = dialog_create("dlg_delete_mod",
delete_mod_formspec,
delete_mod_buttonhandler,
local retval = dialog_create("dlg_delete_content",
delete_content_formspec,
delete_content_buttonhandler,
nil)
retval.data.selected = selected_index
retval.data.content = content
return retval
end

View File

@ -19,7 +19,7 @@
local function rename_modpack_formspec(dialogdata)
dialogdata.mod = modmgr.global_mods:get_list()[dialogdata.selected]
dialogdata.mod = pkgmgr.global_mods:get_list()[dialogdata.selected]
local retval =
"size[11.5,4.5,true]" ..
@ -39,9 +39,9 @@ local function rename_modpack_buttonhandler(this, fields)
local oldpath = core.get_modpath() .. DIR_DELIM .. this.data.mod.name
local targetpath = core.get_modpath() .. DIR_DELIM .. fields["te_modpack_name"]
core.copy_dir(oldpath,targetpath,false)
modmgr.refresh_globals()
modmgr.selected_mod = modmgr.global_mods:get_current_index(
modmgr.global_mods:raw_index_by_uid(fields["te_modpack_name"]))
pkgmgr.refresh_globals()
pkgmgr.selected_mod = pkgmgr.global_mods:get_current_index(
pkgmgr.global_mods:raw_index_by_uid(fields["te_modpack_name"]))
this:delete()
return true

View File

@ -338,7 +338,7 @@ local function parse_config_file(read_all, parse_mods)
-- Parse games
local games_category_initialized = false
local index = 1
local game = gamemgr.get_game(index)
local game = pkgmgr.get_game(index)
while game do
local path = game.path .. DIR_DELIM .. FILENAME
local file = io.open(path, "r")
@ -365,7 +365,7 @@ local function parse_config_file(read_all, parse_mods)
end
index = index + 1
game = gamemgr.get_game(index)
game = pkgmgr.get_game(index)
end
-- Parse mods

View File

@ -1,83 +0,0 @@
--Minetest
--Copyright (C) 2013 sapier
--
--This program is free software; you can redistribute it and/or modify
--it under the terms of the GNU Lesser General Public License as published by
--the Free Software Foundation; either version 2.1 of the License, or
--(at your option) any later version.
--
--This program is distributed in the hope that it will be useful,
--but WITHOUT ANY WARRANTY; without even the implied warranty of
--MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
--GNU Lesser General Public License for more details.
--
--You should have received a copy of the GNU Lesser General Public License along
--with this program; if not, write to the Free Software Foundation, Inc.,
--51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
gamemgr = {}
--------------------------------------------------------------------------------
function gamemgr.find_by_gameid(gameid)
for i=1,#gamemgr.games,1 do
if gamemgr.games[i].id == gameid then
return gamemgr.games[i], i
end
end
return nil, nil
end
--------------------------------------------------------------------------------
function gamemgr.get_game_mods(gamespec, retval)
if gamespec ~= nil and
gamespec.gamemods_path ~= nil and
gamespec.gamemods_path ~= "" then
get_mods(gamespec.gamemods_path, retval)
end
end
--------------------------------------------------------------------------------
function gamemgr.get_game_modlist(gamespec)
local retval = ""
local game_mods = {}
gamemgr.get_game_mods(gamespec, game_mods)
for i=1,#game_mods,1 do
if retval ~= "" then
retval = retval..","
end
retval = retval .. game_mods[i].name
end
return retval
end
--------------------------------------------------------------------------------
function gamemgr.get_game(index)
if index > 0 and index <= #gamemgr.games then
return gamemgr.games[index]
end
return nil
end
--------------------------------------------------------------------------------
function gamemgr.update_gamelist()
gamemgr.games = core.get_games()
end
--------------------------------------------------------------------------------
function gamemgr.gamelist()
local retval = ""
if #gamemgr.games > 0 then
retval = retval .. core.formspec_escape(gamemgr.games[1].name)
for i=2,#gamemgr.games,1 do
retval = retval .. "," .. core.formspec_escape(gamemgr.games[i].name)
end
end
return retval
end
--------------------------------------------------------------------------------
-- read initial data
--------------------------------------------------------------------------------
gamemgr.update_gamelist()

View File

@ -38,15 +38,15 @@ dofile(basepath .. "fstk" .. DIR_DELIM .. "dialog.lua")
dofile(basepath .. "fstk" .. DIR_DELIM .. "tabview.lua")
dofile(basepath .. "fstk" .. DIR_DELIM .. "ui.lua")
dofile(menupath .. DIR_DELIM .. "common.lua")
dofile(menupath .. DIR_DELIM .. "gamemgr.lua")
dofile(menupath .. DIR_DELIM .. "modmgr.lua")
dofile(menupath .. DIR_DELIM .. "pkgmgr.lua")
dofile(menupath .. DIR_DELIM .. "textures.lua")
dofile(menupath .. DIR_DELIM .. "dlg_config_world.lua")
dofile(menupath .. DIR_DELIM .. "dlg_settings_advanced.lua")
dofile(menupath .. DIR_DELIM .. "dlg_contentstore.lua")
if menustyle ~= "simple" then
dofile(menupath .. DIR_DELIM .. "dlg_create_world.lua")
dofile(menupath .. DIR_DELIM .. "dlg_delete_mod.lua")
dofile(menupath .. DIR_DELIM .. "dlg_delete_content.lua")
dofile(menupath .. DIR_DELIM .. "dlg_delete_world.lua")
dofile(menupath .. DIR_DELIM .. "dlg_rename_modpack.lua")
end
@ -54,14 +54,13 @@ end
local tabs = {}
tabs.settings = dofile(menupath .. DIR_DELIM .. "tab_settings.lua")
tabs.mods = dofile(menupath .. DIR_DELIM .. "tab_mods.lua")
tabs.content = dofile(menupath .. DIR_DELIM .. "tab_content.lua")
tabs.credits = dofile(menupath .. DIR_DELIM .. "tab_credits.lua")
if menustyle == "simple" then
tabs.simple_main = dofile(menupath .. DIR_DELIM .. "tab_simple_main.lua")
else
tabs.local_game = dofile(menupath .. DIR_DELIM .. "tab_local.lua")
tabs.play_online = dofile(menupath .. DIR_DELIM .. "tab_online.lua")
tabs.texturepacks = dofile(menupath .. DIR_DELIM .. "tab_texturepacks.lua")
end
--------------------------------------------------------------------------------
@ -134,16 +133,14 @@ local function init_globals()
if menustyle == "simple" then
tv_main:add(tabs.simple_main)
tv_main:add(tabs.settings)
else
tv_main:set_autosave_tab(true)
tv_main:add(tabs.local_game)
tv_main:add(tabs.play_online)
tv_main:add(tabs.settings)
tv_main:add(tabs.texturepacks)
end
tv_main:add(tabs.mods)
tv_main:add(tabs.content)
tv_main:add(tabs.settings)
tv_main:add(tabs.credits)
tv_main:set_global_event_handler(main_event_handler)

View File

@ -31,7 +31,9 @@ function get_mods(path,retval,modpack)
end
toadd.name = name
toadd.author = mod_conf.author
toadd.path = prefix
toadd.type = "mod"
if modpack ~= nil and modpack ~= "" then
toadd.modpack = modpack
@ -39,6 +41,7 @@ function get_mods(path,retval,modpack)
local modpackfile = io.open(prefix .. "modpack.txt")
if modpackfile then
modpackfile:close()
toadd.type = "modpack"
toadd.is_modpack = true
get_mods(prefix, retval, name)
end
@ -48,10 +51,46 @@ function get_mods(path,retval,modpack)
end
--modmanager implementation
modmgr = {}
pkgmgr = {}
function pkgmgr.get_texture_packs()
local txtpath = core.get_texturepath()
local list = core.get_dir_list(txtpath, true)
local retval = {}
local current_texture_path = core.settings:get("texture_path")
for _, item in ipairs(list) do
if item ~= "base" then
local name = item
local path = txtpath .. DIR_DELIM .. item .. DIR_DELIM
if path == current_texture_path then
name = fgettext("$1 (Enabled)", name)
end
local conf = Settings(path .. "texture_pack.conf")
retval[#retval + 1] = {
name = item,
author = conf:get("author"),
list_name = name,
type = "txp",
path = path,
enabled = path == current_texture_path,
}
end
end
table.sort(retval, function(a, b)
return a.name > b.name
end)
return retval
end
--------------------------------------------------------------------------------
function modmgr.extract(modfile)
function pkgmgr.extract(modfile)
if modfile.type == "zip" then
local tempfolder = os.tempfolder()
@ -66,72 +105,60 @@ function modmgr.extract(modfile)
return nil
end
function pkgmgr.get_folder_type(path)
local testfile = io.open(path .. DIR_DELIM .. "init.lua","r")
if testfile ~= nil then
testfile:close()
return { type = "mod", path = path }
end
testfile = io.open(path .. DIR_DELIM .. "modpack.txt","r")
if testfile ~= nil then
testfile:close()
return { type = "modpack", path = path }
end
testfile = io.open(path .. DIR_DELIM .. "game.conf","r")
if testfile ~= nil then
testfile:close()
return { type = "game", path = path }
end
testfile = io.open(path .. DIR_DELIM .. "texture_pack.conf","r")
if testfile ~= nil then
testfile:close()
return { type = "txp", path = path }
end
return nil
end
-------------------------------------------------------------------------------
function modmgr.getbasefolder(temppath)
function pkgmgr.get_base_folder(temppath)
if temppath == nil then
return {
type = "invalid",
path = ""
}
return { type = "invalid", path = "" }
end
local testfile = io.open(temppath .. DIR_DELIM .. "init.lua","r")
if testfile ~= nil then
testfile:close()
return {
type="mod",
path=temppath
}
end
testfile = io.open(temppath .. DIR_DELIM .. "modpack.txt","r")
if testfile ~= nil then
testfile:close()
return {
type="modpack",
path=temppath
}
local ret = pkgmgr.get_folder_type(temppath)
if ret then
return ret
end
local subdirs = core.get_dir_list(temppath, true)
--only single mod or modpack allowed
if #subdirs ~= 1 then
return {
type = "invalid",
path = ""
}
if #subdirs == 1 then
ret = pkgmgr.get_folder_type(temppath .. DIR_DELIM .. subdirs[1])
if ret then
return ret
else
return { type = "invalid", path = temppath .. DIR_DELIM .. subdirs[1] }
end
end
testfile =
io.open(temppath .. DIR_DELIM .. subdirs[1] ..DIR_DELIM .."init.lua","r")
if testfile ~= nil then
testfile:close()
return {
type="mod",
path= temppath .. DIR_DELIM .. subdirs[1]
}
end
testfile =
io.open(temppath .. DIR_DELIM .. subdirs[1] ..DIR_DELIM .."modpack.txt","r")
if testfile ~= nil then
testfile:close()
return {
type="modpack",
path=temppath .. DIR_DELIM .. subdirs[1]
}
end
return {
type = "invalid",
path = ""
}
return nil
end
--------------------------------------------------------------------------------
function modmgr.isValidModname(modpath)
function pkgmgr.isValidModname(modpath)
if modpath:find("-") ~= nil then
return false
end
@ -140,7 +167,7 @@ function modmgr.isValidModname(modpath)
end
--------------------------------------------------------------------------------
function modmgr.parse_register_line(line)
function pkgmgr.parse_register_line(line)
local pos1 = line:find("\"")
local pos2 = nil
if pos1 ~= nil then
@ -167,7 +194,7 @@ function modmgr.parse_register_line(line)
end
--------------------------------------------------------------------------------
function modmgr.parse_dofile_line(modpath,line)
function pkgmgr.parse_dofile_line(modpath,line)
local pos1 = line:find("\"")
local pos2 = nil
if pos1 ~= nil then
@ -180,14 +207,14 @@ function modmgr.parse_dofile_line(modpath,line)
if filename ~= nil and
filename ~= "" and
filename:find(".lua") then
return modmgr.identify_modname(modpath,filename)
return pkgmgr.identify_modname(modpath,filename)
end
end
return nil
end
--------------------------------------------------------------------------------
function modmgr.identify_modname(modpath,filename)
function pkgmgr.identify_modname(modpath,filename)
local testfile = io.open(modpath .. DIR_DELIM .. filename,"r")
if testfile ~= nil then
local line = testfile:read()
@ -196,20 +223,20 @@ function modmgr.identify_modname(modpath,filename)
local modname = nil
if line:find("minetest.register_tool") then
modname = modmgr.parse_register_line(line)
modname = pkgmgr.parse_register_line(line)
end
if line:find("minetest.register_craftitem") then
modname = modmgr.parse_register_line(line)
modname = pkgmgr.parse_register_line(line)
end
if line:find("minetest.register_node") then
modname = modmgr.parse_register_line(line)
modname = pkgmgr.parse_register_line(line)
end
if line:find("dofile") then
modname = modmgr.parse_dofile_line(modpath,line)
modname = pkgmgr.parse_dofile_line(modpath,line)
end
if modname ~= nil then
@ -225,14 +252,14 @@ function modmgr.identify_modname(modpath,filename)
return nil
end
--------------------------------------------------------------------------------
function modmgr.render_modlist(render_list)
function pkgmgr.render_packagelist(render_list)
local retval = ""
if render_list == nil then
if modmgr.global_mods == nil then
modmgr.refresh_globals()
if pkgmgr.global_mods == nil then
pkgmgr.refresh_globals()
end
render_list = modmgr.global_mods
render_list = pkgmgr.global_mods
end
local list = render_list:get_list()
@ -252,36 +279,36 @@ function modmgr.render_modlist(render_list)
break
end
end
elseif v.is_game_content then
elseif v.is_game_content or v.type == "game" then
color = mt_color_blue
elseif v.enabled then
elseif v.enabled or v.type == "txp" then
color = mt_color_green
end
retval[#retval + 1] = color
if v.modpack ~= nil or v.typ == "game_mod" then
if v.modpack ~= nil or v.loc == "game" then
retval[#retval + 1] = "1"
else
retval[#retval + 1] = "0"
end
retval[#retval + 1] = core.formspec_escape(v.name)
retval[#retval + 1] = core.formspec_escape(v.list_name or v.name)
end
return table.concat(retval, ",")
end
--------------------------------------------------------------------------------
function modmgr.get_dependencies(path)
function pkgmgr.get_dependencies(path)
if path == nil then
return "", ""
end
local info = core.get_mod_info(path)
return table.concat(info.depends, ","), table.concat(info.optional_depends, ",")
local info = core.get_content_info(path)
return table.concat(info.depends or {}, ","), table.concat(info.optional_depends or {}, ",")
end
--------------------------------------------------------------------------------
function modmgr.get_worldconfig(worldpath)
function pkgmgr.get_worldconfig(worldpath)
local filename = worldpath ..
DIR_DELIM .. "world.mt"
@ -302,26 +329,35 @@ function modmgr.get_worldconfig(worldpath)
end
--read gamemods
local gamespec = gamemgr.find_by_gameid(worldconfig.id)
gamemgr.get_game_mods(gamespec, worldconfig.game_mods)
local gamespec = pkgmgr.find_by_gameid(worldconfig.id)
pkgmgr.get_game_mods(gamespec, worldconfig.game_mods)
return worldconfig
end
--------------------------------------------------------------------------------
function modmgr.installmod(modfilename,basename)
local modfile = modmgr.identify_filetype(modfilename)
local modpath = modmgr.extract(modfile)
function pkgmgr.install_dir(type, path, basename)
local basefolder = pkgmgr.get_base_folder(path)
if modpath == nil then
gamedata.errormessage = fgettext("Install Mod: file: \"$1\"", modfile.name) ..
fgettext("\nInstall Mod: unsupported filetype \"$1\" or broken archive", modfile.type)
return
local targetpath
if type == "txp" then
if basefolder and basefolder.type ~= "invalid" and basefolder.type ~= "txp" then
return nil, fgettext("Unable to install a $1 as a texture pack", basefolder.type)
end
local basefolder = modmgr.getbasefolder(modpath)
local from = basefolder and basefolder.path or path
targetpath = core.get_texturepath() .. DIR_DELIM .. basename
core.copy_dir(from, targetpath)
return targetpath, nil
elseif not basefolder then
return nil, fgettext("Unable to find a valid mod or modpack")
end
if basefolder.type == "modpack" then
if type ~= "mod" then
return nil, fgettext("Unable to install a modpack as a $1", type)
end
local clean_path = nil
if basename ~= nil then
@ -333,20 +369,27 @@ function modmgr.installmod(modfilename,basename)
end
if clean_path ~= nil then
local targetpath = core.get_modpath() .. DIR_DELIM .. clean_path
targetpath = core.get_modpath() .. DIR_DELIM .. clean_path
if not core.copy_dir(basefolder.path,targetpath) then
gamedata.errormessage = fgettext("Failed to install $1 to $2", basename, targetpath)
return nil,
fgettext("Failed to install $1 to $2", basename, targetpath)
end
else
gamedata.errormessage = fgettext("Install Mod: unable to find suitable foldername for modpack $1", modfilename)
end
return nil,
fgettext("Install Mod: unable to find suitable foldername for modpack $1",
modfilename)
end
if basefolder.type == "mod" then
pkgmgr.refresh_globals()
elseif basefolder.type == "mod" then
if type ~= "mod" then
return nil, fgettext("Unable to install a mod as a $1", type)
end
local targetfolder = basename
if targetfolder == nil then
targetfolder = modmgr.identify_modname(basefolder.path,"init.lua")
targetfolder = pkgmgr.identify_modname(basefolder.path,"init.lua")
end
--if heuristic failed try to use current foldername
@ -354,22 +397,46 @@ function modmgr.installmod(modfilename,basename)
targetfolder = get_last_folder(basefolder.path)
end
if targetfolder ~= nil and modmgr.isValidModname(targetfolder) then
local targetpath = core.get_modpath() .. DIR_DELIM .. targetfolder
core.copy_dir(basefolder.path,targetpath)
if targetfolder ~= nil and pkgmgr.isValidModname(targetfolder) then
targetpath = core.get_modpath() .. DIR_DELIM .. targetfolder
core.copy_dir(basefolder.path, targetpath)
else
gamedata.errormessage = fgettext("Install Mod: unable to find real modname for: $1", modfilename)
end
return nil, fgettext("Install Mod: unable to find real modname for: $1", modfilename)
end
core.delete_dir(modpath)
pkgmgr.refresh_globals()
modmgr.refresh_globals()
elseif basefolder.type == "game" then
if type ~= "game" then
return nil, fgettext("Unable to install a game as a $1", type)
end
targetpath = core.get_gamepath() .. DIR_DELIM .. basename
core.copy_dir(basefolder.path, targetpath)
end
return targetpath, nil
end
--------------------------------------------------------------------------------
function modmgr.preparemodlist(data)
function pkgmgr.install(type, modfilename, basename)
local archive_info = pkgmgr.identify_filetype(modfilename)
local path = pkgmgr.extract(archive_info)
if path == nil then
return nil,
fgettext("Install: file: \"$1\"", archive_info.name) .. "\n" ..
fgettext("Install: unsupported filetype \"$1\" or broken archive",
archive_info.type)
end
local targetpath, msg = pkgmgr.install_dir(type, path, basename)
core.delete_dir(path)
return targetpath, msg
end
--------------------------------------------------------------------------------
function pkgmgr.preparemodlist(data)
local retval = {}
local global_mods = {}
@ -384,25 +451,27 @@ function modmgr.preparemodlist(data)
end
for i=1,#global_mods,1 do
global_mods[i].typ = "global_mod"
global_mods[i].type = "mod"
global_mods[i].loc = "global"
retval[#retval + 1] = global_mods[i]
end
--read game mods
local gamespec = gamemgr.find_by_gameid(data.gameid)
gamemgr.get_game_mods(gamespec, game_mods)
local gamespec = pkgmgr.find_by_gameid(data.gameid)
pkgmgr.get_game_mods(gamespec, game_mods)
if #game_mods > 0 then
-- Add title
retval[#retval + 1] = {
typ = "game",
type = "game",
is_game_content = true,
name = fgettext("Subgame Mods")
}
end
for i=1,#game_mods,1 do
game_mods[i].typ = "game_mod"
game_mods[i].type = "mod"
game_mods[i].loc = "game"
game_mods[i].is_game_content = true
retval[#retval + 1] = game_mods[i]
end
@ -439,8 +508,12 @@ function modmgr.preparemodlist(data)
return retval
end
function pkgmgr.compare_package(a, b)
return a and b and a.name == b.name and a.path == b.path
end
--------------------------------------------------------------------------------
function modmgr.comparemod(elem1,elem2)
function pkgmgr.comparemod(elem1,elem2)
if elem1 == nil or elem2 == nil then
return false
end
@ -450,7 +523,7 @@ function modmgr.comparemod(elem1,elem2)
if elem1.is_modpack ~= elem2.is_modpack then
return false
end
if elem1.typ ~= elem2.typ then
if elem1.type ~= elem2.type then
return false
end
if elem1.modpack ~= elem2.modpack then
@ -465,13 +538,13 @@ function modmgr.comparemod(elem1,elem2)
end
--------------------------------------------------------------------------------
function modmgr.mod_exists(basename)
function pkgmgr.mod_exists(basename)
if modmgr.global_mods == nil then
modmgr.refresh_globals()
if pkgmgr.global_mods == nil then
pkgmgr.refresh_globals()
end
if modmgr.global_mods:raw_index_by_uid(basename) > 0 then
if pkgmgr.global_mods:raw_index_by_uid(basename) > 0 then
return true
end
@ -479,39 +552,35 @@ function modmgr.mod_exists(basename)
end
--------------------------------------------------------------------------------
function modmgr.get_global_mod(idx)
function pkgmgr.get_global_mod(idx)
if modmgr.global_mods == nil then
if pkgmgr.global_mods == nil then
return nil
end
if idx == nil or idx < 1 or
idx > modmgr.global_mods:size() then
idx > pkgmgr.global_mods:size() then
return nil
end
return modmgr.global_mods:get_list()[idx]
return pkgmgr.global_mods:get_list()[idx]
end
--------------------------------------------------------------------------------
function modmgr.refresh_globals()
modmgr.global_mods = filterlist.create(
modmgr.preparemodlist, --refresh
modmgr.comparemod, --compare
function(element,uid) --uid match
function pkgmgr.refresh_globals()
local function is_equal(element,uid) --uid match
if element.name == uid then
return true
end
end,
nil, --filter
{}
)
modmgr.global_mods:add_sort_mechanism("alphabetic", sort_mod_list)
modmgr.global_mods:set_sortmode("alphabetic")
end
pkgmgr.global_mods = filterlist.create(pkgmgr.preparemodlist,
pkgmgr.comparemod, is_equal, nil, {})
pkgmgr.global_mods:add_sort_mechanism("alphabetic", sort_mod_list)
pkgmgr.global_mods:set_sortmode("alphabetic")
end
--------------------------------------------------------------------------------
function modmgr.identify_filetype(name)
function pkgmgr.identify_filetype(name)
if name:sub(-3):lower() == "zip" then
return {
@ -547,3 +616,69 @@ function modmgr.identify_filetype(name)
type = "ukn"
}
end
--------------------------------------------------------------------------------
function pkgmgr.find_by_gameid(gameid)
for i=1,#pkgmgr.games,1 do
if pkgmgr.games[i].id == gameid then
return pkgmgr.games[i], i
end
end
return nil, nil
end
--------------------------------------------------------------------------------
function pkgmgr.get_game_mods(gamespec, retval)
if gamespec ~= nil and
gamespec.gamemods_path ~= nil and
gamespec.gamemods_path ~= "" then
get_mods(gamespec.gamemods_path, retval)
end
end
--------------------------------------------------------------------------------
function pkgmgr.get_game_modlist(gamespec)
local retval = ""
local game_mods = {}
pkgmgr.get_game_mods(gamespec, game_mods)
for i=1,#game_mods,1 do
if retval ~= "" then
retval = retval..","
end
retval = retval .. game_mods[i].name
end
return retval
end
--------------------------------------------------------------------------------
function pkgmgr.get_game(index)
if index > 0 and index <= #pkgmgr.games then
return pkgmgr.games[index]
end
return nil
end
--------------------------------------------------------------------------------
function pkgmgr.update_gamelist()
pkgmgr.games = core.get_games()
end
--------------------------------------------------------------------------------
function pkgmgr.gamelist()
local retval = ""
if #pkgmgr.games > 0 then
retval = retval .. core.formspec_escape(pkgmgr.games[1].name)
for i=2,#pkgmgr.games,1 do
retval = retval .. "," .. core.formspec_escape(pkgmgr.games[i].name)
end
end
return retval
end
--------------------------------------------------------------------------------
-- read initial data
--------------------------------------------------------------------------------
pkgmgr.update_gamelist()

View File

@ -0,0 +1,217 @@
--Minetest
--Copyright (C) 2014 sapier
--Copyright (C) 2018 rubenwardy <rw@rubenwardy.com>
--
--This program is free software; you can redistribute it and/or modify
--it under the terms of the GNU Lesser General Public License as published by
--the Free Software Foundation; either version 2.1 of the License, or
--(at your option) any later version.
--
--This program is distributed in the hope that it will be useful,
--but WITHOUT ANY WARRANTY; without even the implied warranty of
--MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
--GNU Lesser General Public License for more details.
--
--You should have received a copy of the GNU Lesser General Public License along
--with this program; if not, write to the Free Software Foundation, Inc.,
--51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
local packages_raw
local packages
--------------------------------------------------------------------------------
local function get_formspec(tabview, name, tabdata)
if pkgmgr.global_mods == nil then
pkgmgr.refresh_globals()
end
if pkgmgr.games == nil then
pkgmgr.update_gamelist()
end
if packages == nil then
packages_raw = {}
table.insert_all(packages_raw, pkgmgr.games)
table.insert_all(packages_raw, pkgmgr.get_texture_packs())
table.insert_all(packages_raw, pkgmgr.global_mods:get_list())
local function get_data()
return packages_raw
end
local function is_equal(element, uid) --uid match
return (element.type == "game" and element.id == uid) or
element.name == uid
end
packages = filterlist.create(get_data, pkgmgr.compare_package,
is_equal, nil, {})
end
if tabdata.selected_pkg == nil then
tabdata.selected_pkg = 1
end
local retval =
"label[0.05,-0.25;".. fgettext("Installed Packages:") .. "]" ..
"tablecolumns[color;tree;text]" ..
"table[0,0.25;5.1,4.3;pkglist;" ..
pkgmgr.render_packagelist(packages) ..
";" .. tabdata.selected_pkg .. "]" ..
"button[0,4.85;5.25,0.5;btn_contentdb;".. fgettext("Browse online content") .. "]"
local selected_pkg
if filterlist.size(packages) >= tabdata.selected_pkg then
selected_pkg = packages:get_list()[tabdata.selected_pkg]
end
if selected_pkg ~= nil then
--check for screenshot beeing available
local screenshotfilename = selected_pkg.path .. DIR_DELIM .. "screenshot.png"
local screenshotfile, error = io.open(screenshotfilename, "r")
local modscreenshot
if error == nil then
screenshotfile:close()
modscreenshot = screenshotfilename
end
if modscreenshot == nil then
modscreenshot = defaulttexturedir .. "no_screenshot.png"
end
retval = retval ..
"image[5.5,0;3,2;" .. core.formspec_escape(modscreenshot) .. "]" ..
"label[8.25,0.6;" .. core.formspec_escape(selected_pkg.name) .. "]" ..
"label[5.5,1.7;".. fgettext("Information:") .. "]" ..
"textlist[5.5,2.2;6.2,2.4;description;"
local info = core.get_content_info(selected_pkg.path)
local desc = info.description or fgettext("No package description available")
local descriptionlines = core.wrap_text(desc, 42, true)
for i = 1, #descriptionlines do
retval = retval .. core.formspec_escape(descriptionlines[i]) .. ","
end
if selected_pkg.type == "mod" then
if selected_pkg.is_modpack then
retval = retval .. ";0]" ..
"button[8.9,4.65;3,1;btn_mod_mgr_rename_modpack;" ..
fgettext("Rename") .. "]"
else
--show dependencies
local toadd_hard = table.concat(info.depends or {}, ",")
local toadd_soft = table.concat(info.optional_depends or {}, ",")
if toadd_hard == "" and toadd_soft == "" then
retval = retval .. "," .. fgettext("No dependencies.")
else
if toadd_hard ~= "" then
retval = retval .. "," .. fgettext("Dependencies:") .. ","
retval = retval .. toadd_hard
end
if toadd_soft ~= "" then
if toadd_hard ~= "" then
retval = retval .. ","
end
retval = retval .. "," .. fgettext("Optional dependencies:") .. ","
retval = retval .. toadd_soft
end
end
retval = retval .. ";0]"
end
else
retval = retval .. ";0]"
if selected_pkg.type == "txp" then
if selected_pkg.enabled then
retval = retval ..
"button[8.9,4.65;3,1;btn_mod_mgr_disable_txp;" ..
fgettext("Disable Texture Pack") .. "]"
else
retval = retval ..
"button[8.9,4.65;3,1;btn_mod_mgr_use_txp;" ..
fgettext("Use Texture Pack") .. "]"
end
end
end
retval = retval .. "button[5.5,4.65;3,1;btn_mod_mgr_delete_mod;"
.. fgettext("Uninstall Package") .. "]"
end
return retval
end
--------------------------------------------------------------------------------
local function handle_buttons(tabview, fields, tabname, tabdata)
if fields["pkglist"] ~= nil then
local event = core.explode_table_event(fields["pkglist"])
tabdata.selected_pkg = event.row
return true
end
if fields["btn_mod_mgr_install_local"] ~= nil then
core.show_file_open_dialog("mod_mgt_open_dlg", fgettext("Select Package File:"))
return true
end
if fields["btn_contentdb"] ~= nil then
local dlg = create_store_dlg()
dlg:set_parent(tabview)
tabview:hide()
dlg:show()
packages = nil
return true
end
if fields["btn_mod_mgr_rename_modpack"] ~= nil then
local dlg_renamemp = create_rename_modpack_dlg(tabdata.selected_pkg)
dlg_renamemp:set_parent(tabview)
tabview:hide()
dlg_renamemp:show()
return true
end
if fields["btn_mod_mgr_delete_mod"] ~= nil then
local mod = packages:get_list()[tabdata.selected_pkg]
local dlg_delmod = create_delete_content_dlg(mod)
dlg_delmod:set_parent(tabview)
tabview:hide()
dlg_delmod:show()
packages = nil
return true
end
if fields.btn_mod_mgr_use_txp then
local txp = packages:get_list()[tabdata.selected_pkg]
core.settings:set("texture_path", txp.path)
packages = nil
return true
end
if fields.btn_mod_mgr_disable_txp then
core.settings:set("texture_path", "")
packages = nil
return true
end
if fields["mod_mgt_open_dlg_accepted"] and
fields["mod_mgt_open_dlg_accepted"] ~= "" then
pkgmgr.install_mod(fields["mod_mgt_open_dlg_accepted"],nil)
return true
end
return false
end
--------------------------------------------------------------------------------
return {
name = "content",
caption = fgettext("Content"),
cbf_formspec = get_formspec,
cbf_button_handler = handle_buttons,
on_change = pkgmgr.update_gamelist
}

View File

@ -17,7 +17,7 @@
local function current_game()
local last_game_id = core.settings:get("menu_last_game")
local game, index = gamemgr.find_by_gameid(last_game_id)
local game, index = pkgmgr.find_by_gameid(last_game_id)
return game
end
@ -32,12 +32,12 @@ local function singleplayer_refresh_gamebar()
local function game_buttonbar_button_handler(fields)
for key,value in pairs(fields) do
for j=1,#gamemgr.games,1 do
if ("game_btnbar_" .. gamemgr.games[j].id == key) then
mm_texture.update("singleplayer", gamemgr.games[j])
core.set_topleft_text(gamemgr.games[j].name)
core.settings:set("menu_last_game",gamemgr.games[j].id)
menudata.worldlist:set_filtercriteria(gamemgr.games[j].id)
for j=1,#pkgmgr.games,1 do
if ("game_btnbar_" .. pkgmgr.games[j].id == key) then
mm_texture.update("singleplayer", pkgmgr.games[j])
core.set_topleft_text(pkgmgr.games[j].name)
core.settings:set("menu_last_game",pkgmgr.games[j].id)
menudata.worldlist:set_filtercriteria(pkgmgr.games[j].id)
local index = filterlist.get_current_index(menudata.worldlist,
tonumber(core.settings:get("mainmenu_last_selected_world")))
if not index or index < 1 then
@ -59,21 +59,21 @@ local function singleplayer_refresh_gamebar()
game_buttonbar_button_handler,
{x=-0.3,y=5.9}, "horizontal", {x=12.4,y=1.15})
for i=1,#gamemgr.games,1 do
local btn_name = "game_btnbar_" .. gamemgr.games[i].id
for i=1,#pkgmgr.games,1 do
local btn_name = "game_btnbar_" .. pkgmgr.games[i].id
local image = nil
local text = nil
local tooltip = core.formspec_escape(gamemgr.games[i].name)
local tooltip = core.formspec_escape(pkgmgr.games[i].name)
if gamemgr.games[i].menuicon_path ~= nil and
gamemgr.games[i].menuicon_path ~= "" then
image = core.formspec_escape(gamemgr.games[i].menuicon_path)
if pkgmgr.games[i].menuicon_path ~= nil and
pkgmgr.games[i].menuicon_path ~= "" then
image = core.formspec_escape(pkgmgr.games[i].menuicon_path)
else
local part1 = gamemgr.games[i].id:sub(1,5)
local part2 = gamemgr.games[i].id:sub(6,10)
local part3 = gamemgr.games[i].id:sub(11)
local part1 = pkgmgr.games[i].id:sub(1,5)
local part2 = pkgmgr.games[i].id:sub(6,10)
local part3 = pkgmgr.games[i].id:sub(11)
text = part1 .. "\n" .. part2
if part3 ~= nil and
@ -213,7 +213,7 @@ local function main_button_handler(this, fields, name, tabdata)
--update last game
local world = menudata.worldlist:get_raw_element(gamedata.selected_world)
if world then
local game, index = gamemgr.find_by_gameid(world.gameid)
local game, index = pkgmgr.find_by_gameid(world.gameid)
core.settings:set("menu_last_game", game.id)
end

View File

@ -1,151 +0,0 @@
--Minetest
--Copyright (C) 2014 sapier
--
--This program is free software; you can redistribute it and/or modify
--it under the terms of the GNU Lesser General Public License as published by
--the Free Software Foundation; either version 2.1 of the License, or
--(at your option) any later version.
--
--This program is distributed in the hope that it will be useful,
--but WITHOUT ANY WARRANTY; without even the implied warranty of
--MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
--GNU Lesser General Public License for more details.
--
--You should have received a copy of the GNU Lesser General Public License along
--with this program; if not, write to the Free Software Foundation, Inc.,
--51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
--------------------------------------------------------------------------------
local function get_formspec(tabview, name, tabdata)
if modmgr.global_mods == nil then
modmgr.refresh_globals()
end
if tabdata.selected_mod == nil then
tabdata.selected_mod = 1
end
local retval =
"label[0.05,-0.25;".. fgettext("Installed Mods:") .. "]" ..
"tablecolumns[color;tree;text]" ..
"table[0,0.25;5.1,5;modlist;" ..
modmgr.render_modlist(modmgr.global_mods) ..
";" .. tabdata.selected_mod .. "]"
local selected_mod = nil
if filterlist.size(modmgr.global_mods) >= tabdata.selected_mod then
selected_mod = modmgr.global_mods:get_list()[tabdata.selected_mod]
end
if selected_mod ~= nil then
--check for screenshot beeing available
local screenshotfilename = selected_mod.path .. DIR_DELIM .. "screenshot.png"
local screenshotfile, error = io.open(screenshotfilename,"r")
local modscreenshot
if error == nil then
screenshotfile:close()
modscreenshot = screenshotfilename
end
if modscreenshot == nil then
modscreenshot = defaulttexturedir .. "no_screenshot.png"
end
retval = retval ..
"image[5.5,0;3,2;" .. core.formspec_escape(modscreenshot) .. "]" ..
"label[8.25,0.6;" .. selected_mod.name .. "]" ..
"label[5.5,1.7;".. fgettext("Mod Information:") .. "]" ..
"textlist[5.5,2.2;6.2,2.4;description;"
local info = core.get_mod_info(selected_mod.path)
local desc = info.description or fgettext("No mod description available")
local descriptionlines = core.wrap_text(desc, 42, true)
for i = 1, #descriptionlines do
retval = retval .. core.formspec_escape(descriptionlines[i]) .. ","
end
if selected_mod.is_modpack then
retval = retval .. ";0]" ..
"button[9.9,4.65;2,1;btn_mod_mgr_rename_modpack;" ..
fgettext("Rename") .. "]"
retval = retval .. "button[5.5,4.65;4.5,1;btn_mod_mgr_delete_mod;"
.. fgettext("Uninstall Selected Modpack") .. "]"
else
--show dependencies
local toadd_hard = table.concat(info.depends, ",")
local toadd_soft = table.concat(info.optional_depends, ",")
if toadd_hard == "" and toadd_soft == "" then
retval = retval .. "," .. fgettext("No dependencies.")
else
if toadd_hard ~= "" then
retval = retval .. "," .. fgettext("Dependencies:") .. ","
retval = retval .. toadd_hard
end
if toadd_soft ~= "" then
if toadd_hard ~= "" then
retval = retval .. ","
end
retval = retval .. "," .. fgettext("Optional dependencies:") .. ","
retval = retval .. toadd_soft
end
end
retval = retval .. ";0]"
retval = retval .. "button[5.5,4.65;4.5,1;btn_mod_mgr_delete_mod;"
.. fgettext("Uninstall Selected Mod") .. "]"
end
end
return retval
end
--------------------------------------------------------------------------------
local function handle_buttons(tabview, fields, tabname, tabdata)
if fields["modlist"] ~= nil then
local event = core.explode_table_event(fields["modlist"])
tabdata.selected_mod = event.row
return true
end
if fields["btn_mod_mgr_install_local"] ~= nil then
core.show_file_open_dialog("mod_mgt_open_dlg",fgettext("Select Mod File:"))
return true
end
if fields["btn_mod_mgr_rename_modpack"] ~= nil then
local dlg_renamemp = create_rename_modpack_dlg(tabdata.selected_mod)
dlg_renamemp:set_parent(tabview)
tabview:hide()
dlg_renamemp:show()
return true
end
if fields["btn_mod_mgr_delete_mod"] ~= nil then
local dlg_delmod = create_delete_mod_dlg(tabdata.selected_mod)
dlg_delmod:set_parent(tabview)
tabview:hide()
dlg_delmod:show()
return true
end
if fields["mod_mgt_open_dlg_accepted"] ~= nil and
fields["mod_mgt_open_dlg_accepted"] ~= "" then
modmgr.installmod(fields["mod_mgt_open_dlg_accepted"],nil)
return true
end
return false
end
--------------------------------------------------------------------------------
return {
name = "mods",
caption = fgettext("Mods"),
cbf_formspec = get_formspec,
cbf_button_handler = handle_buttons,
on_change = gamemgr.update_gamelist
}

View File

@ -1,135 +0,0 @@
--Minetest
--Copyright (C) 2014 sapier
--
--This program is free software; you can redistribute it and/or modify
--it under the terms of the GNU Lesser General Public License as published by
--the Free Software Foundation; either version 2.1 of the License, or
--(at your option) any later version.
--
--This program is distributed in the hope that it will be useful,
--but WITHOUT ANY WARRANTY; without even the implied warranty of
--MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
--GNU Lesser General Public License for more details.
--
--You should have received a copy of the GNU Lesser General Public License along
--with this program; if not, write to the Free Software Foundation, Inc.,
--51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
--------------------------------------------------------------------------------
local function filter_texture_pack_list(list)
local retval = {}
for _, item in ipairs(list) do
if item ~= "base" then
retval[#retval + 1] = item
end
end
table.sort(retval)
table.insert(retval, 1, fgettext("None"))
return retval
end
--------------------------------------------------------------------------------
local function render_texture_pack_list(list)
local retval = ""
for i, v in ipairs(list) do
if v:sub(1, 1) ~= "." then
if retval ~= "" then
retval = retval .. ","
end
retval = retval .. core.formspec_escape(v)
end
end
return retval
end
--------------------------------------------------------------------------------
local function get_formspec(tabview, name, tabdata)
local retval = "label[4,-0.25;" .. fgettext("Select Texture Pack:") .. "]" ..
"textlist[4,0.25;7.5,5.0;TPs;"
local current_texture_path = core.settings:get("texture_path")
local list = filter_texture_pack_list(core.get_dir_list(core.get_texturepath(), true))
local index = tonumber(core.settings:get("mainmenu_last_selected_TP"))
if not index then index = 1 end
if current_texture_path == "" then
retval = retval ..
render_texture_pack_list(list) ..
";" .. index .. "]" ..
"textarea[0.6,2.85;3.7,1.5;;" ..
fgettext("Default textures will be used.") ..
";]"
return retval
end
local infofile = current_texture_path .. DIR_DELIM .. "description.txt"
-- This adds backwards compatibility for old texture pack description files named
-- "info.txt", and should be removed once all such texture packs have been updated
if not file_exists(infofile) then
infofile = current_texture_path .. DIR_DELIM .. "info.txt"
if file_exists(infofile) then
core.log("deprecated", "info.txt is deprecated. description.txt should be used instead.")
end
end
local infotext = ""
local f = io.open(infofile, "r")
if not f then
infotext = fgettext("No information available")
else
infotext = f:read("*all")
f:close()
end
local screenfile = current_texture_path .. DIR_DELIM .. "screenshot.png"
local no_screenshot
if not file_exists(screenfile) then
screenfile = nil
no_screenshot = defaulttexturedir .. "no_screenshot.png"
end
return retval ..
render_texture_pack_list(list) ..
";" .. index .. "]" ..
"image[0.25,0.25;4.05,2.7;" .. core.formspec_escape(screenfile or no_screenshot) .. "]" ..
"textarea[0.6,2.85;3.7,1.5;;" .. core.formspec_escape(infotext or "") .. ";]"
end
--------------------------------------------------------------------------------
local function main_button_handler(tabview, fields, name, tabdata)
if fields["TPs"] then
local event = core.explode_textlist_event(fields["TPs"])
if event.type == "CHG" or event.type == "DCL" then
local index = core.get_textlist_index("TPs")
core.settings:set("mainmenu_last_selected_TP", index)
local list = filter_texture_pack_list(core.get_dir_list(core.get_texturepath(), true))
local current_index = core.get_textlist_index("TPs")
if current_index and #list >= current_index then
local new_path = core.get_texturepath() .. DIR_DELIM .. list[current_index]
if list[current_index] == fgettext("None") then
new_path = ""
end
core.settings:set("texture_path", new_path)
end
end
return true
end
return false
end
--------------------------------------------------------------------------------
return {
name = "texturepacks",
caption = fgettext("Texture Packs"),
cbf_formspec = get_formspec,
cbf_button_handler = main_button_handler,
on_change = nil
}