MoneyController = class(Group, function(o, amt, parent)
	Group.init(o)
	o:setup(amt, parent)
end)
function MoneyController:setup(amt, parent)
	local o = self
	local padding = Vec2(14, 32)
	o.tPadding = Vec2(56, 4)
	o.parent = parent
	padding:mult(0.5* r_scale); o.tPadding:mult(0.5* r_scale)
	
	o.interface = o:add(Object(0,0,bludG.camera.w, bludG.camera.h))
	o.interface.svg = SvgLoader(svg_root .. "interface/top_bar_" .. player.currentWorld.id .. ".svg", true)
	o.interface:setPosition(bludG.camera.w/2-o.interface.svg:getMaxX()/2, 20)
	o.interface.drawType = 'svg'
	o.interface.svg:setScrollFactor(0,0)
	
	-- add the buttons for pause, etc
	if o.interface.svg.id then
		-- should move this into the svg loader
		for key, rbd in pairs(o.interface.svg.id) do
			if key == 'waveBg' then
				o.waveBg = Object(rbd.minX+o.interface.pos.x, rbd.minY+o.interface.pos.y, rbd.maxX-rbd.minX, rbd.maxY-rbd.minY)
				o.waveBg.scrollFactor = Vec2(0,0)
				o.waveBg.sprite = sprites['tiles']['white.png']
				o.waveBg.drawType = 'stretched'
				local wbgc = player.currentWorld.wave_bg;

				o.waveBg:setColor(wbgc[1], wbgc[2], wbgc[3])
			else
				local button = o:add(CameraButton(rbd.minX+o.interface.pos.x, rbd.minY+o.interface.pos.y, rbd.maxX-rbd.minX, rbd.maxY-rbd.minY))
				button.scrollFactor = Vec2(0,0)
				button.onPress = function()
					if o[key .. "_callback"] then o[key .. "_callback"](o) end
				end
				button:setColor(0,0,0,0)
			end
		end
	end
	o.money = amt
	o:setupMoneyBox()
	-- put the money display in the lower corner
	o.pauseState = PauseState(o.parent)
end
function MoneyController:setupMoneyBox()
	local o = self
	o.moneyDisplaySvg = o:add(Object(0,0,bludG.camera.w, bludG.camera.h))
	o.moneyDisplaySvg.svg = SvgLoader(svg_root .. "interface/money_box_" .. player.currentWorld.id .. ".svg", true)
	o.moneyDisplaySvg.drawType = 'svg'
	o.moneyDisplaySvg.svg:setScrollFactor(0,0)
	o.moneyDisplaySvg:setPosition(bludG.camera.w-o.moneyDisplaySvg.svg:getMaxX(), bludG.camera.h-250*r_scale*0.5+o.moneyDisplaySvg.svg:getMaxY())
	o.moneyboxY = o.moneyDisplaySvg.pos.y+o.moneyDisplaySvg.svg.id.moneybox.minY
	o.moneyboxX = o.moneyDisplaySvg.pos.x+o.moneyDisplaySvg.svg.id.moneybox.maxX
	o.moneyboxH = o.moneyDisplaySvg.svg.id.moneybox.maxY-o.interface.svg.id.moneybox.minY
	o.moneyboxW = o.moneyDisplaySvg.svg.id.moneybox.maxX-o.interface.svg.id.moneybox.minX
	o.moneyDisplay = o:add(StringObject(0,0, math.floor(o.money), nil, 0.4))
	o.moneyDisplay:setColor(0,0,0)
	o.moneyDisplay:setScrollFactor(Vec2(0,0))
	o.moneyDisplay:setPosition(o.moneyboxX-o.moneyDisplay.w, o.moneyboxY)
	-- add in the dollar sign sprite
	local dmult = 0.5
	if r_scale == 4 then
		dmult = dmult*2
	end
	local dspr = sprites['tiles']['money_particle.png']
	local dbox = o.moneyDisplaySvg.svg.id.dollarbox
	local dcenter = Vec2(dbox.minX+o.moneyDisplaySvg.pos.x+(dbox.maxX-dbox.minX)/2,dbox.minY+o.moneyDisplaySvg.pos.y+(dbox.maxY-dbox.minY)/2)
	o.dollarSign = o:add(Object(dcenter.x-dspr:getWidth()*dmult/2, dcenter.y-dspr:getHeight()*dmult/2,dspr:getWidth()*dmult, dspr:getHeight()*dmult))
	o.dollarSign.sprite = dspr
	o.dollarSign.scrollFactor = Vec2(0,0)
	o.dollarSign.drawType = 'stretched'
	o.dollarSign:setColor(0,0,0, 100)
end
function MoneyController:pausebutton_callback()
	mainState:changeState(self.pauseState)
	self.pauseState:onLoad()
end

function MoneyController:setAmount(amt)
	self.moneyDisplay:setValue(math.floor(amt))
	self.money = amt
	self.moneyDisplay:setPosition(self.moneyboxX-self.moneyDisplay.w, self.moneyboxY+self.moneyboxH/2-self.moneyDisplay.h/2+1*r_scale)
end

function MoneyController:getAmount()
	return self.money
end
function MoneyController:draw()
	bellhop = self.parent.waveController.bellhop
	local opx, opy = bellhop.pos.x, bellhop.pos.y
	if not bellhop.o_w then bellhop.o_w = bellhop.w; bellhop.o_h = bellhop.h end

	bellhop.pos.x = bellhop.pos.x+bellhop.sprite:getSpriteX()*bellhop.bmult
	bellhop.pos.y = bellhop.pos.y+bellhop.sprite:getSpriteY()*bellhop.bmult
	bellhop.w = (bellhop.o_w/bellhop.sprite:getWidth())*bellhop.sprite:getTexWidth()
	bellhop.h = (bellhop.o_h/bellhop.sprite:getHeight())*bellhop.sprite:getTexHeight()
	Group.draw(self)
	bellhop.pos.x, bellhop.pos.y = opx, opy
	bellhop.w, bellhop.h = bellhop.o_w, bellhop.o_h
end

-- mainState = WrapperState(Group());
-- mainState:changeState(TitleScreenState())
-- mainState.substate.playButton.onPress()
-- mainState.substate.playButton.onPress()
-- mainState.substate.playButton.onPress()