2018-04-17 14:54:50 +01:00
|
|
|
--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
|
2020-08-06 20:33:21 +02:00
|
|
|
--the Free Software Foundation; either version 3.0 of the License, or
|
2018-04-17 14:54:50 +01:00
|
|
|
--(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 = {}
|
2020-08-06 20:33:21 +02:00
|
|
|
local i = 0
|
|
|
|
for _, game in ipairs(pkgmgr.games) do
|
2023-11-06 02:42:27 +13:00
|
|
|
if not game.hidden then
|
2020-08-06 20:33:21 +02:00
|
|
|
i = i + 1
|
|
|
|
packages_raw[i] = game
|
|
|
|
end
|
|
|
|
end
|
2018-04-17 14:54:50 +01:00
|
|
|
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 =
|
2022-07-19 08:09:48 +12:00
|
|
|
"label[-0.05,-0.25;".. fgettext("Installed Packages:") .. "]" ..
|
2022-12-07 16:05:14 +02:00
|
|
|
"background9[0,0.23;5.3,4.46;" .. defaulttexturedir_esc .. "worldlist_bg.png;false;40]" ..
|
2018-04-17 14:54:50 +01:00
|
|
|
"tablecolumns[color;tree;text]" ..
|
2022-06-17 20:21:15 +03:00
|
|
|
"tableoptions[background=#0000;border=false]" ..
|
2023-04-25 21:05:45 +03:00
|
|
|
scrollbar_style("pkglist") ..
|
2018-04-17 14:54:50 +01:00
|
|
|
"table[0,0.25;5.1,4.3;pkglist;" ..
|
|
|
|
pkgmgr.render_packagelist(packages) ..
|
|
|
|
";" .. tabdata.selected_pkg .. "]" ..
|
2022-11-13 17:44:48 +01:00
|
|
|
btn_style("btn_contentdb") ..
|
2023-03-27 01:34:50 +13:00
|
|
|
"image_button[-0.11,4.8;5.5,0.9;;btn_contentdb;" .. fgettext("Browse online content") .. ";true;false]" ..
|
|
|
|
"image[0.03,4.925;0.6,0.6;" .. defaulttexturedir_esc .. "gui" ..
|
|
|
|
DIR_DELIM_esc .. "btn_download.png]"
|
2018-04-17 14:54:50 +01:00
|
|
|
|
|
|
|
|
|
|
|
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
|
2022-11-13 17:44:48 +01:00
|
|
|
modscreenshot = defaulttexturedir_esc .. "no_screenshot.png"
|
2018-04-17 14:54:50 +01:00
|
|
|
end
|
|
|
|
|
2018-09-07 03:46:58 +02:00
|
|
|
local info = core.get_content_info(selected_pkg.path)
|
|
|
|
local desc = fgettext("No package description available")
|
|
|
|
if info.description and info.description:trim() ~= "" then
|
|
|
|
desc = info.description
|
|
|
|
end
|
|
|
|
|
2023-08-04 14:33:33 +03:00
|
|
|
local pkg_name = selected_pkg.name
|
|
|
|
pkg_name = (pkg_name:sub(1, 1)):upper() .. pkg_name:sub(2)
|
|
|
|
|
2018-04-17 14:54:50 +01:00
|
|
|
retval = retval ..
|
2022-11-13 17:44:48 +01:00
|
|
|
"image[5.5,0;3,2;" .. core.formspec_escape(modscreenshot) .. "]" ..
|
2023-03-27 01:34:50 +13:00
|
|
|
"image[5.5,0;3,2;" .. defaulttexturedir_esc .. "gui" .. DIR_DELIM_esc .. "cdb_img_corners.png;15]" ..
|
2023-08-04 14:33:33 +03:00
|
|
|
"label[8.25,0.6;" .. core.formspec_escape(pkg_name) .. "]" ..
|
2022-12-07 16:05:14 +02:00
|
|
|
"background9[5.6,2.3;6.2,2.4;" .. defaulttexturedir_esc .. "desc_bg.png;false;32]"
|
2018-04-17 14:54:50 +01:00
|
|
|
|
|
|
|
if selected_pkg.type == "mod" then
|
2023-03-27 01:34:50 +13:00
|
|
|
-- if selected_pkg.is_modpack then
|
|
|
|
-- retval = retval ..
|
|
|
|
-- btn_style("btn_mod_mgr_rename_modpack") ..
|
|
|
|
-- "image_button[8.65,4.8;3.25,0.9;;btn_mod_mgr_rename_modpack;" ..
|
|
|
|
-- fgettext("Rename") .. ";true;false]"
|
|
|
|
-- else
|
|
|
|
if not selected_pkg.is_modpack then
|
2018-04-17 14:54:50 +01:00
|
|
|
--show dependencies
|
2018-09-07 03:46:58 +02:00
|
|
|
desc = desc .. "\n\n"
|
|
|
|
local toadd_hard = table.concat(info.depends or {}, "\n")
|
|
|
|
local toadd_soft = table.concat(info.optional_depends or {}, "\n")
|
2018-04-17 14:54:50 +01:00
|
|
|
if toadd_hard == "" and toadd_soft == "" then
|
2018-09-07 03:46:58 +02:00
|
|
|
desc = desc .. fgettext("No dependencies.")
|
2018-04-17 14:54:50 +01:00
|
|
|
else
|
|
|
|
if toadd_hard ~= "" then
|
2018-09-07 03:46:58 +02:00
|
|
|
desc = desc ..fgettext("Dependencies:") ..
|
|
|
|
"\n" .. toadd_hard
|
2018-04-17 14:54:50 +01:00
|
|
|
end
|
|
|
|
if toadd_soft ~= "" then
|
|
|
|
if toadd_hard ~= "" then
|
2018-09-07 03:46:58 +02:00
|
|
|
desc = desc .. "\n\n"
|
2018-04-17 14:54:50 +01:00
|
|
|
end
|
2018-09-07 03:46:58 +02:00
|
|
|
desc = desc .. fgettext("Optional dependencies:") ..
|
|
|
|
"\n" .. toadd_soft
|
2018-04-17 14:54:50 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
else
|
|
|
|
if selected_pkg.type == "txp" then
|
|
|
|
if selected_pkg.enabled then
|
|
|
|
retval = retval ..
|
2022-11-13 17:44:48 +01:00
|
|
|
btn_style("btn_mod_mgr_disable_txp") ..
|
2023-03-27 01:34:50 +13:00
|
|
|
"image_button[6.4,4.8;5.5,0.9;;btn_mod_mgr_disable_txp;" ..
|
2022-07-19 08:09:48 +12:00
|
|
|
fgettext("Disable Texture Pack") .. ";true;false]"
|
2018-04-17 14:54:50 +01:00
|
|
|
else
|
|
|
|
retval = retval ..
|
2022-12-07 16:05:14 +02:00
|
|
|
btn_style("btn_mod_mgr_use_txp", "green") ..
|
2023-03-27 01:34:50 +13:00
|
|
|
"image_button[6.4,4.8;5.5,0.9;;btn_mod_mgr_use_txp;" ..
|
2022-07-19 08:09:48 +12:00
|
|
|
fgettext("Use Texture Pack") .. ";true;false]"
|
2018-04-17 14:54:50 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-08-04 14:33:33 +03:00
|
|
|
retval = retval .. scrollbar_style("textarea", true) ..
|
|
|
|
"textarea[5.83,2.23;6.33,2.89;;" .. fgettext("Information:") .. ";" .. desc .. "]"
|
2019-03-05 07:12:58 +00:00
|
|
|
|
2022-06-25 21:05:54 +12:00
|
|
|
if core.may_modify_path(selected_pkg.path) then
|
2019-03-05 07:12:58 +00:00
|
|
|
retval = retval ..
|
2022-12-07 16:05:14 +02:00
|
|
|
btn_style("btn_mod_mgr_delete_mod", "red") ..
|
2023-03-27 01:34:50 +13:00
|
|
|
"image_button[5.5,4.8;0.9,0.9;" .. defaulttexturedir_esc ..
|
|
|
|
"trash.png;btn_mod_mgr_delete_mod;;true;false;" .. defaulttexturedir_esc .. "trash_pressed.png]" ..
|
|
|
|
"tooltip[btn_mod_mgr_delete_mod;" .. fgettext("Uninstall Package") .. "]"
|
2019-03-05 07:12:58 +00:00
|
|
|
end
|
2018-04-17 14:54:50 +01:00
|
|
|
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_contentdb"] ~= nil then
|
|
|
|
local dlg = create_store_dlg()
|
|
|
|
dlg:set_parent(tabview)
|
|
|
|
tabview:hide()
|
|
|
|
dlg:show()
|
|
|
|
packages = nil
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2023-03-27 01:34:50 +13:00
|
|
|
--[[
|
2018-04-17 14:54:50 +01:00
|
|
|
if fields["btn_mod_mgr_rename_modpack"] ~= nil then
|
2018-06-11 01:40:00 +03:00
|
|
|
local mod = packages:get_list()[tabdata.selected_pkg]
|
|
|
|
local dlg_renamemp = create_rename_modpack_dlg(mod)
|
2018-04-17 14:54:50 +01:00
|
|
|
dlg_renamemp:set_parent(tabview)
|
|
|
|
tabview:hide()
|
|
|
|
dlg_renamemp:show()
|
2018-06-11 01:40:00 +03:00
|
|
|
packages = nil
|
2018-04-17 14:54:50 +01:00
|
|
|
return true
|
|
|
|
end
|
2023-03-27 01:34:50 +13:00
|
|
|
]]
|
2018-04-17 14:54:50 +01:00
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
return {
|
|
|
|
name = "content",
|
2022-06-14 20:58:04 +12:00
|
|
|
caption = "", -- fgettext("Content"),
|
2018-04-17 14:54:50 +01:00
|
|
|
cbf_formspec = get_formspec,
|
|
|
|
cbf_button_handler = handle_buttons,
|
|
|
|
on_change = pkgmgr.update_gamelist
|
|
|
|
}
|