2 --Copyright (C) 2014 sapier
3 --Copyright (C) 2018 rubenwardy <rw@rubenwardy.com>
5 --This program is free software; you can redistribute it and/or modify
6 --it under the terms of the GNU Lesser General Public License as published by
7 --the Free Software Foundation; either version 2.1 of the License, or
8 --(at your option) any later version.
10 --This program is distributed in the hope that it will be useful,
11 --but WITHOUT ANY WARRANTY; without even the implied warranty of
12 --MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 --GNU Lesser General Public License for more details.
15 --You should have received a copy of the GNU Lesser General Public License along
16 --with this program; if not, write to the Free Software Foundation, Inc.,
17 --51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 local function modname_valid(name)
23 return not name:find("[^a-z0-9_]")
26 --------------------------------------------------------------------------------
27 local function get_formspec(tabview, name, tabdata)
28 if pkgmgr.global_mods == nil then
29 pkgmgr.refresh_globals()
31 if pkgmgr.games == nil then
32 pkgmgr.update_gamelist()
35 if packages == nil then
37 table.insert_all(packages_raw, pkgmgr.games)
38 table.insert_all(packages_raw, pkgmgr.get_texture_packs())
39 table.insert_all(packages_raw, pkgmgr.global_mods:get_list())
40 table.insert_all(packages_raw, pkgmgr.clientmods:get_list())
42 local function get_data()
46 local function is_equal(element, uid) --uid match
47 return (element.type == "game" and element.id == uid) or
51 packages = filterlist.create(get_data, pkgmgr.compare_package,
54 local filename = core.get_clientmodpath() .. DIR_DELIM .. "mods.conf"
56 local conffile = Settings(filename)
57 local mods = conffile:to_table()
59 for i = 1, #packages_raw do
60 local mod = packages_raw[i]
61 if mod.is_clientside and not mod.is_modpack then
62 if modname_valid(mod.name) then
63 conffile:set("load_mod_" .. mod.name,
64 mod.enabled and "true" or "false")
65 elseif mod.enabled then
66 gamedata.errormessage = fgettext_ne("Failed to enable clientmo" ..
67 "d \"$1\" as it contains disallowed characters. " ..
68 "Only characters [a-z0-9_] are allowed.",
71 mods["load_mod_" .. mod.name] = nil
75 -- Remove mods that are not present anymore
76 for key in pairs(mods) do
77 if key:sub(1, 9) == "load_mod_" then
82 if not conffile:write() then
83 core.log("error", "Failed to write clientmod config file")
87 if tabdata.selected_pkg == nil then
88 tabdata.selected_pkg = 1
91 local use_technical_names = core.settings:get_bool("show_technical_names")
95 "label[0.05,-0.25;".. fgettext("Installed Packages:") .. "]" ..
96 "tablecolumns[color;tree;text]" ..
97 "table[0,0.25;5.1,4.3;pkglist;" ..
98 pkgmgr.render_packagelist(packages, use_technical_names) ..
99 ";" .. tabdata.selected_pkg .. "]" ..
100 "button[0,4.85;5.25,0.5;btn_contentdb;".. fgettext("Browse online content") .. "]"
104 if filterlist.size(packages) >= tabdata.selected_pkg then
105 selected_pkg = packages:get_list()[tabdata.selected_pkg]
108 if selected_pkg ~= nil then
109 --check for screenshot beeing available
110 local screenshotfilename = selected_pkg.path .. DIR_DELIM .. "screenshot.png"
111 local screenshotfile, error = io.open(screenshotfilename, "r")
115 screenshotfile:close()
116 modscreenshot = screenshotfilename
119 if modscreenshot == nil then
120 modscreenshot = defaulttexturedir .. "no_screenshot.png"
123 local info = core.get_content_info(selected_pkg.path)
124 local desc = fgettext("No package description available")
125 if info.description and info.description:trim() ~= "" then
126 desc = info.description
130 if selected_pkg.type == "game" then
131 title_and_name = selected_pkg.name
133 title_and_name = (selected_pkg.title or selected_pkg.name) .. "\n" ..
134 core.colorize("#BFBFBF", selected_pkg.name)
138 "image[5.5,0;3,2;" .. core.formspec_escape(modscreenshot) .. "]" ..
139 "label[8.25,0.6;" .. core.formspec_escape(title_and_name) .. "]" ..
140 "box[5.5,2.2;6.15,2.35;#000]"
142 if selected_pkg.type == "mod" then
143 if selected_pkg.is_modpack then
144 if selected_pkg.is_clientside then
145 if pkgmgr.is_modpack_entirely_enabled({list = packages}, selected_pkg.name) then
147 "button[8.65,4.65;3.25,1;btn_mod_mgr_mp_disable;" ..
148 fgettext("Disable modpack") .. "]"
151 "button[8.65,4.65;3.25,1;btn_mod_mgr_mp_enable;" ..
152 fgettext("Enable modpack") .. "]"
156 "button[8.65,4.65;3.25,1;btn_mod_mgr_rename_modpack;" ..
157 fgettext("Rename") .. "]"
161 desc = desc .. "\n\n"
162 local toadd_hard = table.concat(info.depends or {}, "\n")
163 local toadd_soft = table.concat(info.optional_depends or {}, "\n")
164 if toadd_hard == "" and toadd_soft == "" then
165 desc = desc .. fgettext("No dependencies.")
167 if toadd_hard ~= "" then
168 desc = desc ..fgettext("Dependencies:") ..
171 if toadd_soft ~= "" then
172 if toadd_hard ~= "" then
173 desc = desc .. "\n\n"
175 desc = desc .. fgettext("Optional dependencies:") ..
179 if selected_pkg.is_clientside then
180 if selected_pkg.enabled then
182 "button[8.65,4.65;3.25,1;btn_mod_mgr_disable_mod;" ..
183 fgettext("Disable") .. "]"
186 "button[8.65,4.65;3.25,1;btn_mod_mgr_enable_mod;" ..
187 fgettext("Enable") .. "]"
193 if selected_pkg.type == "txp" then
194 if selected_pkg.enabled then
196 "button[8.65,4.65;3.25,1;btn_mod_mgr_disable_txp;" ..
197 fgettext("Disable Texture Pack") .. "]"
200 "button[8.65,4.65;3.25,1;btn_mod_mgr_use_txp;" ..
201 fgettext("Use Texture Pack") .. "]"
206 retval = retval .. "textarea[5.85,2.2;6.35,2.9;;" ..
207 fgettext("Information:") .. ";" .. desc .. "]"
209 if core.may_modify_path(selected_pkg.path) then
211 "button[5.5,4.65;3.25,1;btn_mod_mgr_delete_mod;" ..
212 fgettext("Uninstall Package") .. "]"
218 --------------------------------------------------------------------------------
219 local function handle_doubleclick(pkg, pkg_name)
220 if pkg.type == "txp" then
221 if core.settings:get("texture_path") == pkg.path then
222 core.settings:set("texture_path", "")
224 core.settings:set("texture_path", pkg.path)
229 mm_game_theme.reset()
230 elseif pkg.is_clientside then
231 pkgmgr.enable_mod({data = {list = packages, selected_mod = pkg_name}})
236 --------------------------------------------------------------------------------
237 local function handle_buttons(tabview, fields, tabname, tabdata)
238 if fields["pkglist"] ~= nil then
239 local event = core.explode_table_event(fields["pkglist"])
240 tabdata.selected_pkg = event.row
241 if event.type == "DCL" then
242 handle_doubleclick(packages:get_list()[tabdata.selected_pkg], tabdata.selected_pkg)
247 if fields.btn_mod_mgr_mp_enable ~= nil or
248 fields.btn_mod_mgr_mp_disable ~= nil then
249 pkgmgr.enable_mod({data = {list = packages, selected_mod = tabdata.selected_pkg}},
250 fields.btn_mod_mgr_mp_enable ~= nil)
255 if fields.btn_mod_mgr_enable_mod ~= nil or
256 fields.btn_mod_mgr_disable_mod ~= nil then
257 pkgmgr.enable_mod({data = {list = packages, selected_mod = tabdata.selected_pkg}},
258 fields.btn_mod_mgr_enable_mod ~= nil)
263 if fields["btn_contentdb"] ~= nil then
264 local dlg = create_store_dlg()
265 dlg:set_parent(tabview)
272 if fields["btn_mod_mgr_rename_modpack"] ~= nil then
273 local mod = packages:get_list()[tabdata.selected_pkg]
274 local dlg_renamemp = create_rename_modpack_dlg(mod)
275 dlg_renamemp:set_parent(tabview)
282 if fields["btn_mod_mgr_delete_mod"] ~= nil then
283 local mod = packages:get_list()[tabdata.selected_pkg]
284 local dlg_delmod = create_delete_content_dlg(mod)
285 dlg_delmod:set_parent(tabview)
292 if fields.btn_mod_mgr_use_txp or fields.btn_mod_mgr_disable_txp then
294 if fields.btn_mod_mgr_use_txp then
295 txp_path = packages:get_list()[tabdata.selected_pkg].path
298 core.settings:set("texture_path", txp_path)
302 mm_game_theme.reset()
309 --------------------------------------------------------------------------------
312 caption = fgettext("Content"),
313 cbf_formspec = get_formspec,
314 cbf_button_handler = handle_buttons,
315 on_change = pkgmgr.update_gamelist