]> git.lizzy.rs Git - dragonfireclient.git/blob - builtin/mainmenu/dlg_delete_world.lua
33e7bc94548918a4ee6cb879150de5f2eda068ac
[dragonfireclient.git] / builtin / mainmenu / dlg_delete_world.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 local function delete_world_formspec(dialogdata)
20         local retval =
21                 "size[10,2.5,true]" ..
22                 "label[0.5,0.5;" ..
23                 fgettext("Delete World \"$1\"?", dialogdata.delete_name) .. "]" ..
24                 "style[world_delete_confirm;bgcolor=red]" ..
25                 "button[0.5,1.5;2.5,0.5;world_delete_confirm;" .. fgettext("Delete") .. "]" ..
26                 "button[7.0,1.5;2.5,0.5;world_delete_cancel;" .. fgettext("Cancel") .. "]"
27         return retval
28 end
29
30 local function delete_world_buttonhandler(this, fields)
31         if fields["world_delete_confirm"] then
32                 if this.data.delete_index > 0 and
33                                 this.data.delete_index <= #menudata.worldlist:get_raw_list() then
34                         core.delete_world(this.data.delete_index)
35                         menudata.worldlist:refresh()
36                 end
37                 this:delete()
38                 return true
39         end
40
41         if fields["world_delete_cancel"] then
42                 this:delete()
43                 return true
44         end
45
46         return false
47 end
48
49
50 function create_delete_world_dlg(name_to_del, index_to_del)
51         assert(name_to_del ~= nil and type(name_to_del) == "string" and name_to_del ~= "")
52         assert(index_to_del ~= nil and type(index_to_del) == "number")
53
54         local retval = dialog_create("delete_world",
55                                         delete_world_formspec,
56                                         delete_world_buttonhandler,
57                                         nil)
58         retval.data.delete_name  = name_to_del
59         retval.data.delete_index = index_to_del
60
61         return retval
62 end