]> git.lizzy.rs Git - minetest.git/blob - builtin/mainmenu/tab_content.lua
Remove modstore leftovers. Fix core.show_path_select_dialog documentation (#8572)
[minetest.git] / builtin / mainmenu / tab_content.lua
1 --Minetest
2 --Copyright (C) 2014 sapier
3 --Copyright (C) 2018 rubenwardy <rw@rubenwardy.com>
4 --
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.
9 --
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.
14 --
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.
18
19 local packages_raw
20 local packages
21
22 --------------------------------------------------------------------------------
23 local function get_formspec(tabview, name, tabdata)
24         if pkgmgr.global_mods == nil then
25                 pkgmgr.refresh_globals()
26         end
27         if pkgmgr.games == nil then
28                 pkgmgr.update_gamelist()
29         end
30
31         if packages == nil then
32                 packages_raw = {}
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())
36
37                 local function get_data()
38                         return packages_raw
39                 end
40
41                 local function is_equal(element, uid) --uid match
42                         return (element.type == "game" and element.id == uid) or
43                                         element.name == uid
44                 end
45
46                 packages = filterlist.create(get_data, pkgmgr.compare_package,
47                                 is_equal, nil, {})
48         end
49
50         if tabdata.selected_pkg == nil then
51                 tabdata.selected_pkg = 1
52         end
53
54
55         local retval =
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") .. "]"
62
63
64         local selected_pkg
65         if filterlist.size(packages) >= tabdata.selected_pkg then
66                 selected_pkg = packages:get_list()[tabdata.selected_pkg]
67         end
68
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")
73
74                 local modscreenshot
75                 if error == nil then
76                         screenshotfile:close()
77                         modscreenshot = screenshotfilename
78                 end
79
80                 if modscreenshot == nil then
81                                 modscreenshot = defaulttexturedir .. "no_screenshot.png"
82                 end
83
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
88                 end
89
90                 retval = retval ..
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]"
94
95                 if selected_pkg.type == "mod" then
96                         if selected_pkg.is_modpack then
97                                 retval = retval ..
98                                         "button[8.65,4.65;3.25,1;btn_mod_mgr_rename_modpack;" ..
99                                         fgettext("Rename") .. "]"
100                         else
101                                 --show dependencies
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.")
107                                 else
108                                         if toadd_hard ~= "" then
109                                                 desc = desc ..fgettext("Dependencies:") ..
110                                                         "\n" .. toadd_hard
111                                         end
112                                         if toadd_soft ~= "" then
113                                                 if toadd_hard ~= "" then
114                                                         desc = desc .. "\n\n"
115                                                 end
116                                                 desc = desc .. fgettext("Optional dependencies:") ..
117                                                         "\n" .. toadd_soft
118                                         end
119                                 end
120                         end
121
122                 else
123                         if selected_pkg.type == "txp" then
124                                 if selected_pkg.enabled then
125                                         retval = retval ..
126                                                 "button[8.65,4.65;3.25,1;btn_mod_mgr_disable_txp;" ..
127                                                 fgettext("Disable Texture Pack") .. "]"
128                                 else
129                                         retval = retval ..
130                                                 "button[8.65,4.65;3.25,1;btn_mod_mgr_use_txp;" ..
131                                                 fgettext("Use Texture Pack") .. "]"
132                                 end
133                         end
134                 end
135
136                 retval = retval .. "textarea[5.85,2.2;6.35,2.9;;" ..
137                         fgettext("Information:") .. ";" .. desc .. "]"
138
139                 if core.may_modify_path(selected_pkg.path) then
140                         retval = retval ..
141                                 "button[5.5,4.65;3.25,1;btn_mod_mgr_delete_mod;" ..
142                                 fgettext("Uninstall Package") .. "]"
143                 end
144         end
145         return retval
146 end
147
148 --------------------------------------------------------------------------------
149 local function handle_buttons(tabview, fields, tabname, tabdata)
150         if fields["pkglist"] ~= nil then
151                 local event = core.explode_table_event(fields["pkglist"])
152                 tabdata.selected_pkg = event.row
153                 return true
154         end
155
156         if fields["btn_contentdb"] ~= nil then
157                 local dlg = create_store_dlg()
158                 dlg:set_parent(tabview)
159                 tabview:hide()
160                 dlg:show()
161                 packages = nil
162                 return true
163         end
164
165         if fields["btn_mod_mgr_rename_modpack"] ~= nil then
166                 local mod = packages:get_list()[tabdata.selected_pkg]
167                 local dlg_renamemp = create_rename_modpack_dlg(mod)
168                 dlg_renamemp:set_parent(tabview)
169                 tabview:hide()
170                 dlg_renamemp:show()
171                 packages = nil
172                 return true
173         end
174
175         if fields["btn_mod_mgr_delete_mod"] ~= nil then
176                 local mod = packages:get_list()[tabdata.selected_pkg]
177                 local dlg_delmod = create_delete_content_dlg(mod)
178                 dlg_delmod:set_parent(tabview)
179                 tabview:hide()
180                 dlg_delmod:show()
181                 packages = nil
182                 return true
183         end
184
185         if fields.btn_mod_mgr_use_txp then
186                 local txp = packages:get_list()[tabdata.selected_pkg]
187                 core.settings:set("texture_path", txp.path)
188                 packages = nil
189                 return true
190         end
191
192
193         if fields.btn_mod_mgr_disable_txp then
194                 core.settings:set("texture_path", "")
195                 packages = nil
196                 return true
197         end
198
199         return false
200 end
201
202 --------------------------------------------------------------------------------
203 return {
204         name = "content",
205         caption = fgettext("Content"),
206         cbf_formspec = get_formspec,
207         cbf_button_handler = handle_buttons,
208         on_change = pkgmgr.update_gamelist
209 }