menulist =
{
	main =
	{
		init =
			function(name)
				local x = screenw - 48
				local y = 48
				
				button("build","Build",x,y,3,1,nil,"Build new rooms & doors")
				
				y = y + 32
				
				button("upgrade","Upgrade",x,y,3,1,1,"Upgrade rooms for specific tasks")
			end,
		button_build =
			function(id,name)
				submenu("build",true)
			end,
		button_upgrade =
			function(id,name)
				submenu("upgrade",true)
			end,
	},
	build =
	{
		init =
			function(name)
				local x = 128
				local y = 128
				
				button("small","Small",x,y,3,3,nil,"Small 1x1 room (10 material)")
				
				x = x + 96
				
				button("horizontal","Blab",x,y,3,3,nil,"2x1 room (20 material)")
				
				x = x + 96
				
				button("vertical","Blab2",x,y,3,3,nil,"1x2 room (20 material)")
				
				x = x + 96
				
				button("large","Lorge",x,y,3,3,nil,"Large 2x2 room (30 material)")
				
				x = 128
				y = y + 96
				
				button("door_hor","Door",x,y,3,3,nil,"Horizontal door (5 material)")
				
				x = x + 96
				
				button("door_ver","Also door",x,y,3,3,nil,"Vertical door (5 material)")
				
				x = x + 96
				
				button("scaffold","Scaffolding",x,y,3,3,nil,"Scaffolding (10 material)")
			end,
		button_small =
			function(id,name)
				MF_setvalue(GDATA,DESIGNATE,1)
				MF_setvalue(GDATA,OCCUPIED,1)
				closemenu()
			end,
		button_horizontal =
			function(id,name)
				MF_setvalue(GDATA,DESIGNATE,2)
				MF_setvalue(GDATA,OCCUPIED,1)
				closemenu()
			end,
		button_vertical =
			function(id,name)
				MF_setvalue(GDATA,DESIGNATE,3)
				MF_setvalue(GDATA,OCCUPIED,1)
				closemenu()
			end,
		button_large =
			function(id,name)
				MF_setvalue(GDATA,DESIGNATE,4)
				MF_setvalue(GDATA,OCCUPIED,1)
				closemenu()
			end,
		button_door_hor =
			function(id,name)
				MF_setvalue(GDATA,DESIGNATE,5)
				MF_setvalue(GDATA,OCCUPIED,1)
				closemenu()
			end,
		button_door_ver =
			function(id,name)
				MF_setvalue(GDATA,DESIGNATE,6)
				MF_setvalue(GDATA,OCCUPIED,1)
				closemenu()
			end,
		button_scaffold =
			function(id,name)
				MF_setvalue(GDATA,DESIGNATE,7)
				MF_setvalue(GDATA,OCCUPIED,1)
				closemenu()
			end,
	},
	upgrade =
	{
		init =
			function(name)
				local roomid = MF_getvalue(RTARGET,R_TARGET)
				local style = MF_getvalue(roomid,STYLE) + 1
				MF_setvalue(GDATA,OCCUPIED,2)
				
				local x,y = 128,128
				
				local data = roomlist[style]
				local upgrades = data.upgrades or {}
				
				local i = 0
				for a,b in pairs(upgrades) do
					button(a,b.name,x,y,3,3,nil,b.subtitle or "")
					
					x = x + 96
					i = i + 1
					
					if (i % 4 == 0) then
						x = 128
						y = y + 96
					end
				end
			end,
		button_any =
			function(id,name)
				local roomid = MF_getvalue(RTARGET,R_TARGET)
				local style = MF_getvalue(roomid,STYLE) + 1
				
				local hasmoney = checkprice(style,id)
				
				if (hasmoney == 1) then
					MF_setvalue(roomid,UPGRADED,1)
					
					local data = roomlist[style]
					local upgrades = data.upgrades
					
					if (upgrades[id] ~= nil) then
						local udata = upgrades[id]
						MF_setstring(roomid,NAME,udata.name)
						udata.setup(roomid,data)
					end
					
					MF_setvalue(RTARGET,R_TARGET,0)
				end
				
				MF_setvalue(GDATA,OCCUPIED,0)
				closemenu()
			end,
	},
}