local love = assert( love ) local button = require( "ui.button" ) local t = {} t.__index = t local i = 0 function t.start( self ) print( "starting modal:", i + 1) love.graphics.setScissor( self.x or 0, self.y or 0, self.w or love.graphics.getWidth(), self.h or love.graphics.getHeight()) i = i + 1 t[i] = { modal = self } t.previous = t[i] t.current = self --store callbacks for name in pairs( self ) do if love[name] then t[i][name] = love[name] love[name] = self[name] end end --store menus local b = button.next repeat t[i][b] = b.visible b = b.next until b == button end function t.stop( self ) --restore callbacks for name in pairs( self ) do if love[name] then love[name] = t[i][name] or love[name] end end --restore menus local b = button button.deselect() repeat b = b.next b.visible = t[i][b] or false until b == button t.current = t[i].modal t[i] = nil i = i - 1 t.previous = t[i - 1] love.graphics.setScissor(0, 0, love.graphics.getDimensions()) end function t.exitAll() if i < 1 then return end i = 1 return t.stop( love ) end function t.new( modal ) return setmetatable( modal or {}, t ) end return t