msgbox = {
	lines = 3,
	line_space = 18
}

if not GAME.CompatMode
	msgbox.lines = 5
	msgbox.line_space = 9
end

local function DrawBox(screen,y,lines)
	screen.draw(graphics[TextBox],{0,0,244,8},{38,y})
	for i = 1,lines
		screen.draw(graphics[TextBox],{0,8,244,8},{38,y+i*8})
	end
	screen.draw(graphics[TextBox],{0,16,244,8},{38,y+(lines+1)*8})
end

function msgbox.think()
	if not tsc.msgbox return end
	if tsc.addtext
		tsc.shownod = true
		tsc.nodblink = 0
	end
	tsc.nodblink = (tsc.nodblink + 1) % 10
	if tsc.nodblink == 0
		tsc.shownod = not tsc.shownod
	end
end

function msgbox.draw(screen)
	if not tsc.msgbox return end
	DrawBox(screen,174,6)
	local last_line = 1
	local y = 184
	for i = msgbox.lines,1,-1
		if tsc.msgtext[i]
			if tsc.tur
				local spacing = 5
				if not GAME.CompatMode
					spacing = nil
				end
				font.draw_string(screen,tsc.msgtext[i],38+8,y,"thin",spacing)
			else
				local msg = tsc.msgtext[i]
				if (not tsc.addtext or not GAME.CompatMode) and tsc.nod and not tsc.msgtext[i-1] and tsc.shownod
					msg = msg .. '_'
				end
				local spacing = 6
				if not GAME.CompatMode
					spacing = nil
				end
				font.draw_string(screen,msg,38+8,y,"normal",spacing)
			end
			last_line = i
			y = y + msgbox.line_space
		end
	end

	if tsc.ynj and not tsc.addtext
		screen.draw(graphics[TextBox],{152,48,92,32},{216,144})
		screen.draw(graphics[TextBox],{112,88,16,16},{211+41*tsc.ynjcursor,154})
	end
end
