TypeButton = class(CameraDragArea, function(o, x, y, w, h, p, rtype)
	DragArea.init(o, x, y, w, h)
	o.parent = p
	o.drawType = 'stretched'
	o.sprite = sprites['tiles']['white.png']
	o.layer = 0
	Object.setColor(o, 0,255,0)
	local padding = 2*r_scale
	o.room = _G[rtype](x+padding, y+padding, nil, {noHealth=true})
	o.padding = padding
	local roomSize = 60*r_scale
	local scale = (w-padding*2)/roomSize

	o.room:setScale(scale)
	o.scrollFactor = Vec2(0,0)
	o.room:setScrollFactor(0,0)
	o.overlay = Object(x, y, w, h)
	o.overlay.drawType = o.drawType
	o.overlay.sprite = o.sprite
	o.overlay.scrollFactor = o.scrollFactor
	o.overlay:setColor(0,0,0,0)

end)
function TypeButton:setScrollFactor(x, y)
	self.scrollFactor.x, self.scrollFactor.y = x, y
	self.room:setScrollFactor(x, y)
	if self.overlay then
		self.overlay.scrollFactor = self.scrollFactor
	end
end
function TypeButton:onStart(x, y, id)
	if self.parent then
		self.parent.newType = self.room
	end
end
function TypeButton:onPress(x, y, id)
	if self.parent and Rectangle.doesPointTouch(self, Vec2(x, y)) then
		self.parent.newType = nil
	end
end
function TypeButton:update()
	Object.update(self)
end
function TypeButton:setPosition(x, y)
	if self.room then
		self.room:setPosition(x+self.padding, y+self.padding)
	end
	if self.overlay then
		self.overlay:setPosition(x,y)
	end
	Object.setPosition(self, x, y)
end
function TypeButton:draw()
	Object.draw(self)
	self.room:draw()
	self.overlay:draw()
end
function TypeButton:afford(canAfford)
	if canAfford and not self.canAfford then
		if self.overlayTween then Tweener:removeTween(self.overlayTween) end
		self.overlayTween = Tweener:addTween(self.overlay.tint, {a=0}, {time=0.25})
	elseif not canAfford and self.canAfford then
		if self.overlayTween then Tweener:removeTween(self.overlayTween) end
		self.overlayTween = Tweener:addTween(self.overlay.tint, {a=150}, {time=0.25})
	end
	self.canAfford = canAfford
end