-- a state that sits on top of the play state on certain levels for the boss to yammer on.
OverlayState = class(Group, function(o, item, parent)
	item = item or {['img']={}, }
	Group.init(o)
	o.parent = parent
	o:setup(item, parent)
end)
function OverlayState:setup(item, parent)
	local o = self
	local padding = 40*r_scale
	-- add a background layout for all but the first level
	
	o.bg = o:add(Object(0,0, bludG.camera.w, bludG.camera.h))
	o.bg:setScrollFactor(Vec2(0,0))
	o.bg.sprite = sprites['tiles']['white.png']
	o.bg.drawType = 'stretched'
	o.bg:setColor(0,0,0,0.5*255)

	-- load in the proper overlay
	o.overlay = o:add(Object(0,0, bludG.camera.w, bludG.camera.h))
	o.overlay:setScrollFactor(Vec2(0,0))
	o.overlay.sprite = sprites['tiles']['white.png']
	o.overlay:setColor(255, 255, 255, 0)
	o.iscale = bludG.camera.h/1024
	o.overlay:setPosition(bludG.camera.w/2-768*o.iscale/2, 0)
	if item.img[1] then
		local overlayImgs = {}
		for i,v in ipairs(item.img) do
			local svg = SvgLoader(svg_root .. "level_overlay/" .. v .. "_ipad.svg", false, nil, true)
			svg:scale(o.iscale, o.iscale)
			table.insert(overlayImgs, svg)
		end
		o.overlay.animation = AnimationModel(overlayImgs)
		o.overlay.animation.rate = item.aniRate or 200
		o.overlay.svg = o.overlay.animation:getSprite()
		o.overlay.svg:setScrollFactor(0,0)
		o.overlay:setColor(255, 255, 255)
		o.overlay.drawType = 'svg'
	end
	local textHeight = 0
	currentText = item.text
	if parent.customDraft then
		currentText = "Custom room mode enabled! High Scores will not be saved."
	end
	if currentText then
		-- add in the text
		o.text = o:add(MultilineString(padding, 0, bludG.camera.w-padding*2, item.text, nil, 0.4, 1.4))
		o.text:setScrollFactor(Vec2(0,0))
		o.text:center()
		o.text:setPosition(0, bludG.camera.h/3-o.text.h/2)
		if item.textColor then
			o.text:setColor(item.textColor[1], item.textColor[2], item.textColor[3])
		end
		textHeight = textHeight+o.text.h
	end
	local titleText = item.title or parent.waveData.name
	o.title = o:add(MultilineString(padding, 0, bludG.camera.w-padding*2, titleText, nil, 0.6))
	o.title:setScrollFactor(Vec2(0,0))
	o.title:center()
	o.title:setPosition(0, bludG.camera.h/4-o.title.h/2)
	if item.textColor then
		o.title:setColor(item.textColor[1], item.textColor[2], item.textColor[3])
	end
	textHeight = textHeight+o.title.h
	-- fix the positioning to fit both of the objects
	if o.text then
		local waveBottom = 40*r_scale
		if o.parent.waveController then
			waveBottom = o.parent.waveController.blockCam.pos.y
		end
		textHeight = textHeight+20*r_scale
		o.title:setPosition(0, waveBottom+30*r_scale)
		o.text:setPosition(0, o.title.pos.y+o.title.h+20*r_scale)
	end
end
function OverlayState:update()
	if self.overlay.animation then
		self.overlay.svg = self.overlay.animation:getSprite()
		self.overlay.svg:setScrollFactor(0,0)
	end
end
function OverlayState:touchDown()
	self.parent:remove(self)
	return false
end