2
0

dlg_delete_world.lua 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. local function delete_world_formspec(dialogdata)
  18. return confirmation_formspec(
  19. fgettext("Delete World \"$1\"?", dialogdata.delete_name),
  20. 'world_delete_confirm', fgettext("Delete"),
  21. 'world_delete_cancel', fgettext("Cancel"))
  22. end
  23. local function delete_world_buttonhandler(this, fields)
  24. if fields["world_delete_confirm"] then
  25. if this.data.delete_index > 0 and
  26. this.data.delete_index <= #menudata.worldlist:get_raw_list() then
  27. core.delete_world(this.data.delete_index)
  28. menudata.worldlist:refresh()
  29. end
  30. this:delete()
  31. return true
  32. end
  33. if fields["world_delete_cancel"] then
  34. this:delete()
  35. return true
  36. end
  37. return false
  38. end
  39. function create_delete_world_dlg(name_to_del, index_to_del)
  40. assert(name_to_del ~= nil and type(name_to_del) == "string" and name_to_del ~= "")
  41. assert(index_to_del ~= nil and type(index_to_del) == "number")
  42. local retval = dialog_create("delete_world",
  43. delete_world_formspec,
  44. delete_world_buttonhandler,
  45. nil)
  46. retval.data.delete_name = name_to_del
  47. retval.data.delete_index = index_to_del
  48. return retval
  49. end