]> git.lizzy.rs Git - dragonfireclient.git/blob - builtin/mainmenu/dlg_rename_modpack.lua
Include tile definitions in get_node_def; Client-side minetest.object_refs table
[dragonfireclient.git] / builtin / mainmenu / dlg_rename_modpack.lua
1 --Minetest
2 --Copyright (C) 2014 sapier
3 --
4 --This program is free software; you can redistribute it and/or modify
5 --it under the terms of the GNU Lesser General Public License as published by
6 --the Free Software Foundation; either version 2.1 of the License, or
7 --(at your option) any later version.
8 --
9 --This program is distributed in the hope that it will be useful,
10 --but WITHOUT ANY WARRANTY; without even the implied warranty of
11 --MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 --GNU Lesser General Public License for more details.
13 --
14 --You should have received a copy of the GNU Lesser General Public License along
15 --with this program; if not, write to the Free Software Foundation, Inc.,
16 --51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
18 --------------------------------------------------------------------------------
19
20 local function rename_modpack_formspec(dialogdata)
21         local retval =
22                 "size[11.5,4.5,true]" ..
23                 "button[3.25,3.5;2.5,0.5;dlg_rename_modpack_confirm;"..
24                                 fgettext("Accept") .. "]" ..
25                 "button[5.75,3.5;2.5,0.5;dlg_rename_modpack_cancel;"..
26                                 fgettext("Cancel") .. "]"
27
28         local input_y = 2
29         if dialogdata.mod.is_name_explicit then
30                 retval = retval .. "textarea[1,0.2;10,2;;;" ..
31                                 fgettext("This modpack has an explicit name given in its modpack.conf " ..
32                                                 "which will override any renaming here.") .. "]"
33                 input_y = 2.5
34         end
35         retval = retval ..
36                 "field[2.5," .. input_y .. ";7,0.5;te_modpack_name;" ..
37                 fgettext("Rename Modpack:") .. ";" .. dialogdata.mod.dir_name .. "]"
38
39         return retval
40 end
41
42 --------------------------------------------------------------------------------
43 local function rename_modpack_buttonhandler(this, fields)
44         if fields["dlg_rename_modpack_confirm"] ~= nil then
45                 local oldpath = this.data.mod.path
46                 local targetpath = this.data.mod.parent_dir .. DIR_DELIM .. fields["te_modpack_name"]
47                 os.rename(oldpath, targetpath)
48                 pkgmgr.refresh_globals()
49                 pkgmgr.selected_mod = pkgmgr.global_mods:get_current_index(
50                         pkgmgr.global_mods:raw_index_by_uid(fields["te_modpack_name"]))
51
52                 this:delete()
53                 return true
54         end
55
56         if fields["dlg_rename_modpack_cancel"] then
57                 this:delete()
58                 return true
59         end
60
61         return false
62 end
63
64 --------------------------------------------------------------------------------
65 function create_rename_modpack_dlg(modpack)
66
67         local retval = dialog_create("dlg_delete_mod",
68                                         rename_modpack_formspec,
69                                         rename_modpack_buttonhandler,
70                                         nil)
71         retval.data.mod = modpack
72         return retval
73 end