msgbox = {}

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 not tsc.nod
		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 = 3,1,-1
		if tsc.msgtext[i]
			if tsc.tur
				font.draw_string(screen,tsc.msgtext[i],38+8,y,"thin",5)
			else
				if tsc.nod and not tsc.msgtext[i-1] and tsc.shownod
					font.draw_string(screen,tsc.msgtext[i]..'×',38+8,y,"normal",6)
				else
					font.draw_string(screen,tsc.msgtext[i],38+8,y,"normal",6)
				end
			end
			last_line = i
			y = y + 18
		end
	end
end
