예제 #1
0
파일: hud.py 프로젝트: bricks42/BrutalRL
def draw_messages(player, start_pos = 0):
	X, Y, W, H = 30, 40, 50, 10
	
	libtcod.console_set_background_color(0, libtcod.black)
	libtcod.console_rect(0, X, Y, W, H, True, libtcod.BKGND_SET)
	
	libtcod.console_set_foreground_color(0, libtcod.white)
	
	if start_pos > 0:
		offset = 1
		libtcod.console_print_left(0, X + 1, Y + 0, libtcod.BKGND_NONE, '? Too many messages; [any] to see more')
	
	else:
		offset = 0
	
	try:
		for m, message in enumerate(player.message_log[start_pos:]):
			color = message.has_seen and libtcod.grey or libtcod.white
			
			libtcod.console_set_foreground_color(0, color)
			
			wrapped = wrap_text(message.text, W - 3, subsequent_indent = ' ')
			
			for line, text in enumerate(wrapped):
				
				if line == 0:
					if message.symbol1:
						libtcod.console_put_char_ex( 0, X + ((message.symbol2 is None) and 1 or 0), Y + offset, message.symbol1[0], message.symbol1[1] * (message.has_seen and 0.5 or 1), message.symbol1[2] * (message.has_seen and 0.5 or 1))
					
					if message.symbol2:
						libtcod.console_put_char_ex( 0, X + 1, Y + offset, message.symbol2[0], message.symbol2[1] * (message.has_seen and 0.5 or 1), message.symbol2[2] * (message.has_seen and 0.5 or 1))
				
				parsed_text, parse_data = parse_colors(text)
				libtcod.console_print_left(0, X + 3, Y + offset, libtcod.BKGND_NONE, parsed_text%parse_data)
				offset += 1
				
				if offset >= H:
					if (not message.has_seen and line + 1 < len(wrapped)) or (m + 1 < len(player.message_log) and not player.message_log[start_pos+m+1].has_seen):
						raise TooManyMessages()
					
					else:
						raise LogIsFull()
				
	except LogIsFull:
		pass
	
	except TooManyMessages:
		draw_messages(player, start_pos + 1)
		return
	
	for message in player.message_log[start_pos:]:
		message.has_seen = True
	
	if start_pos > 0:
		libtcod.console_flush()
		key = libtcod.console_wait_for_keypress(True)
		draw_messages(player)
예제 #2
0
def display_message_log(player):
	message_log_console = libtcod.console_new(80, 40)
	
	start_on_line = 0
	focus = 0
	n_messages = len(player.message_log)
	
	while True:
		# draw the log
		libtcod.console_clear(message_log_console)
		
		libtcod.console_set_foreground_color(message_log_console, libtcod.white)
		libtcod.console_print_center(message_log_console, 40, 1, libtcod.BKGND_NONE, 'Message Log')
		
		offset = 3
		line_n = 0
		
		focus_age = player.message_log[focus].age
		focus_drawn = False
		
		try:
			for n, message in enumerate(player.message_log):
				for line, text in enumerate(wrap_text(message.text, 75, subsequent_indent = ' ')):
					if line_n < start_on_line:
						line_n += 1
						
						if n == focus:
							raise FocusAboveScreen()
						
						continue
					
					if message.age == focus_age:
						shade = 1
					
					else:
						shade = 0.5
					
					libtcod.console_set_foreground_color(message_log_console, libtcod.white * shade)
					
					if line == 0:
						
						if n == focus:
							libtcod.console_put_char_ex( message_log_console, 0, offset, libtcod.CHAR_ARROW_E, libtcod.white, libtcod.black)
						
						if message.symbol1:
							libtcod.console_put_char_ex( message_log_console, (message.symbol2 is None) and 2 or 1, offset, message.symbol1[0], message.symbol1[1] * shade, message.symbol1[2] * shade )
						
						if message.symbol2:
							libtcod.console_put_char_ex( message_log_console, 2, offset, message.symbol2[0], message.symbol2[1] * shade, message.symbol2[2] * shade )
					
					parsed_text, parse_data = parse_colors(text)
					libtcod.console_print_left(message_log_console, 4, offset, libtcod.BKGND_NONE, parsed_text%parse_data)
					offset += 1
					
					if offset >= 39:
						if focus_drawn:
							raise LogIsFull()
						
						else:
							raise FocusBelowScreen()
				
				if n == focus:
					focus_drawn = True
		
		except LogIsFull:
			pass
		
		except FocusAboveScreen:
			start_on_line = max(0, start_on_line - 35)
			continue
		
		except FocusBelowScreen:
			start_on_line += 35
			continue
		
		libtcod.console_blit(message_log_console, 0, 0, 80, 40, 0, 0, 0)
		
		draw_hud(player)
		
		libtcod.console_flush()
		
		# wait for input
		key = libtcod.console_wait_for_keypress(True)
		
		if key.vk == libtcod.KEY_ESCAPE or key.c == ord('m'):
			break
		
		elif key.vk in DIRECTION_KEYS and DIRECTION_KEYS[key.vk][0] == 0:
			focus += DIRECTION_KEYS[key.vk][1]
			focus %= n_messages
	
	libtcod.console_delete(message_log_console)