2 --Copyright (C) 2014 sapier
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.
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.
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.
18 local function dialog_event_handler(self,event)
19 if self.user_eventhandler == nil or
20 self.user_eventhandler(event) == false then
23 if event == "MenuQuit" then
30 local dialog_metatable = {
31 eventhandler = dialog_event_handler,
32 get_formspec = function(self)
33 if not self.hidden then return self.formspec(self.data) end
35 handle_buttons = function(self,fields)
36 if not self.hidden then return self.buttonhandler(self,fields) end
38 handle_events = function(self,event)
39 if not self.hidden then return self.eventhandler(self,event) end
41 hide = function(self) self.hidden = true end,
42 show = function(self) self.hidden = false end,
43 delete = function(self)
44 if self.parent ~= nil then
49 set_parent = function(self,parent) self.parent = parent end
51 dialog_metatable.__index = dialog_metatable
53 function dialog_create(name,get_formspec,buttonhandler,eventhandler)
57 self.type = "toplevel"
61 self.formspec = get_formspec
62 self.buttonhandler = buttonhandler
63 self.user_eventhandler = eventhandler
65 setmetatable(self,dialog_metatable)