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 --------------------------------------------------------------------------------
23 local function get_formspec(tabview, name, tabdata)
24 if pkgmgr.global_mods == nil then
25 pkgmgr.refresh_globals()
27 if pkgmgr.games == nil then
28 pkgmgr.update_gamelist()
31 if packages == nil then
33 table.insert_all(packages_raw, pkgmgr.games)
34 table.insert_all(packages_raw, pkgmgr.get_texture_packs())
35 table.insert_all(packages_raw, pkgmgr.global_mods:get_list())
37 local function get_data()
41 local function is_equal(element, uid) --uid match
42 return (element.type == "game" and element.id == uid) or
46 packages = filterlist.create(get_data, pkgmgr.compare_package,
50 if tabdata.selected_pkg == nil then
51 tabdata.selected_pkg = 1
56 "label[0.05,-0.25;".. fgettext("Installed Packages:") .. "]" ..
57 "tablecolumns[color;tree;text]" ..
58 "table[0,0.25;5.1,4.3;pkglist;" ..
59 pkgmgr.render_packagelist(packages) ..
60 ";" .. tabdata.selected_pkg .. "]" ..
61 "button[0,4.85;5.25,0.5;btn_contentdb;".. fgettext("Browse online content") .. "]"
65 if filterlist.size(packages) >= tabdata.selected_pkg then
66 selected_pkg = packages:get_list()[tabdata.selected_pkg]
69 if selected_pkg ~= nil then
70 --check for screenshot beeing available
71 local screenshotfilename = selected_pkg.path .. DIR_DELIM .. "screenshot.png"
72 local screenshotfile, error = io.open(screenshotfilename, "r")
76 screenshotfile:close()
77 modscreenshot = screenshotfilename
80 if modscreenshot == nil then
81 modscreenshot = defaulttexturedir .. "no_screenshot.png"
84 local info = core.get_content_info(selected_pkg.path)
85 local desc = fgettext("No package description available")
86 if info.description and info.description:trim() ~= "" then
87 desc = info.description
91 "image[5.5,0;3,2;" .. core.formspec_escape(modscreenshot) .. "]" ..
92 "label[8.25,0.6;" .. core.formspec_escape(selected_pkg.name) .. "]" ..
93 "box[5.5,2.2;6.15,2.35;#000]"
95 if selected_pkg.type == "mod" then
96 if selected_pkg.is_modpack then
98 "button[8.65,4.65;3.25,1;btn_mod_mgr_rename_modpack;" ..
99 fgettext("Rename") .. "]"
102 desc = desc .. "\n\n"
103 local toadd_hard = table.concat(info.depends or {}, "\n")
104 local toadd_soft = table.concat(info.optional_depends or {}, "\n")
105 if toadd_hard == "" and toadd_soft == "" then
106 desc = desc .. fgettext("No dependencies.")
108 if toadd_hard ~= "" then
109 desc = desc ..fgettext("Dependencies:") ..
112 if toadd_soft ~= "" then
113 if toadd_hard ~= "" then
114 desc = desc .. "\n\n"
116 desc = desc .. fgettext("Optional dependencies:") ..
123 if selected_pkg.type == "txp" then
124 if selected_pkg.enabled then
126 "button[8.65,4.65;3.25,1;btn_mod_mgr_disable_txp;" ..
127 fgettext("Disable Texture Pack") .. "]"
130 "button[8.65,4.65;3.25,1;btn_mod_mgr_use_txp;" ..
131 fgettext("Use Texture Pack") .. "]"
136 retval = retval .. "textarea[5.85,2.2;6.35,2.9;;" ..
137 fgettext("Information:") .. ";" .. desc .. "]"
139 if core.may_modify_path(selected_pkg.path) then
141 "button[5.5,4.65;3.25,1;btn_mod_mgr_delete_mod;" ..
142 fgettext("Uninstall Package") .. "]"
148 --------------------------------------------------------------------------------
149 local function handle_doubleclick(pkg)
150 if pkg.type == "txp" then
151 if core.settings:get("texture_path") == pkg.path then
152 core.settings:set("texture_path", "")
154 core.settings:set("texture_path", pkg.path)
159 mm_game_theme.reset()
163 --------------------------------------------------------------------------------
164 local function handle_buttons(tabview, fields, tabname, tabdata)
165 if fields["pkglist"] ~= nil then
166 local event = core.explode_table_event(fields["pkglist"])
167 tabdata.selected_pkg = event.row
168 if event.type == "DCL" then
169 handle_doubleclick(packages:get_list()[tabdata.selected_pkg])
174 if fields["btn_contentdb"] ~= nil then
175 local dlg = create_store_dlg()
176 dlg:set_parent(tabview)
183 if fields["btn_mod_mgr_rename_modpack"] ~= nil then
184 local mod = packages:get_list()[tabdata.selected_pkg]
185 local dlg_renamemp = create_rename_modpack_dlg(mod)
186 dlg_renamemp:set_parent(tabview)
193 if fields["btn_mod_mgr_delete_mod"] ~= nil then
194 local mod = packages:get_list()[tabdata.selected_pkg]
195 local dlg_delmod = create_delete_content_dlg(mod)
196 dlg_delmod:set_parent(tabview)
203 if fields.btn_mod_mgr_use_txp or fields.btn_mod_mgr_disable_txp then
205 if fields.btn_mod_mgr_use_txp then
206 txp_path = packages:get_list()[tabdata.selected_pkg].path
209 core.settings:set("texture_path", txp_path)
213 mm_game_theme.reset()
220 --------------------------------------------------------------------------------
223 caption = fgettext("Content"),
224 cbf_formspec = get_formspec,
225 cbf_button_handler = handle_buttons,
226 on_change = pkgmgr.update_gamelist