]> git.lizzy.rs Git - dragonfireclient.git/blob - builtin/mainmenu/dlg_delete_world.lua
Add formspec toolkit and refactor mainmenu to use it
[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 create_world_formspec(dialogdata)
20
21         local retval =
22                 "size[12,6,true]" ..
23                 "label[2,2;" ..
24                 fgettext("Delete World \"$1\"?", dialogdata.delete_name) .. "]"..
25                 "button[3.5,4.2;2.6,0.5;world_delete_confirm;" .. fgettext("Yes").. "]" ..
26                 "button[6,4.2;2.8,0.5;world_delete_cancel;" .. fgettext("No") .. "]"
27         return retval
28 end
29
30 local function create_world_buttonhandler(this, fields)
31         if fields["world_delete_confirm"] then
32
33                 if this.data.delete_index > 0 and
34                         this.data.delete_index <= #menudata.worldlist:get_raw_list() then
35                         core.delete_world(this.data.delete_index)
36                         menudata.worldlist:refresh()
37                 end
38                 this:delete()
39                 return true
40         end
41         
42         if fields["world_delete_cancel"] then
43                 this:delete()
44                 return true
45         end
46         
47         return false
48 end
49
50
51 function create_delete_world_dlg(name_to_del,index_to_del)
52
53         assert(name_to_del ~= nil and type(name_to_del) == "string" and name_to_del ~= "")
54         assert(index_to_del ~= nil and type(index_to_del) == "number")
55
56         local retval = dialog_create("sp_create_world",
57                                         create_world_formspec,
58                                         create_world_buttonhandler,
59                                         nil)
60         retval.data.delete_name  = name_to_del
61         retval.data.delete_index = index_to_del
62         
63         return retval
64 end