]> git.lizzy.rs Git - minetest.git/blob - builtin/mainmenu/tab_content.lua
Update credits (#8162)
[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                         "button[5.5,4.65;3.25,1;btn_mod_mgr_delete_mod;" ..
139                         fgettext("Uninstall Package") .. "]"
140         end
141         return retval
142 end
143
144 --------------------------------------------------------------------------------
145 local function handle_buttons(tabview, fields, tabname, tabdata)
146         if fields["pkglist"] ~= nil then
147                 local event = core.explode_table_event(fields["pkglist"])
148                 tabdata.selected_pkg = event.row
149                 return true
150         end
151
152         if fields["btn_mod_mgr_install_local"] ~= nil then
153                 core.show_file_open_dialog("mod_mgt_open_dlg", fgettext("Select Package File:"))
154                 return true
155         end
156
157         if fields["btn_contentdb"] ~= nil then
158                 local dlg = create_store_dlg()
159                 dlg:set_parent(tabview)
160                 tabview:hide()
161                 dlg:show()
162                 packages = nil
163                 return true
164         end
165
166         if fields["btn_mod_mgr_rename_modpack"] ~= nil then
167                 local mod = packages:get_list()[tabdata.selected_pkg]
168                 local dlg_renamemp = create_rename_modpack_dlg(mod)
169                 dlg_renamemp:set_parent(tabview)
170                 tabview:hide()
171                 dlg_renamemp:show()
172                 packages = nil
173                 return true
174         end
175
176         if fields["btn_mod_mgr_delete_mod"] ~= nil then
177                 local mod = packages:get_list()[tabdata.selected_pkg]
178                 local dlg_delmod = create_delete_content_dlg(mod)
179                 dlg_delmod:set_parent(tabview)
180                 tabview:hide()
181                 dlg_delmod:show()
182                 packages = nil
183                 return true
184         end
185
186         if fields.btn_mod_mgr_use_txp then
187                 local txp = packages:get_list()[tabdata.selected_pkg]
188                 core.settings:set("texture_path", txp.path)
189                 packages = nil
190                 return true
191         end
192
193
194         if fields.btn_mod_mgr_disable_txp then
195                 core.settings:set("texture_path", "")
196                 packages = nil
197                 return true
198         end
199
200         if fields["mod_mgt_open_dlg_accepted"] and
201                         fields["mod_mgt_open_dlg_accepted"] ~= "" then
202                 pkgmgr.install_mod(fields["mod_mgt_open_dlg_accepted"],nil)
203                 return true
204         end
205
206         return false
207 end
208
209 --------------------------------------------------------------------------------
210 return {
211         name = "content",
212         caption = fgettext("Content"),
213         cbf_formspec = get_formspec,
214         cbf_button_handler = handle_buttons,
215         on_change = pkgmgr.update_gamelist
216 }