Example #1
0
def ask_choose_target(player, text = None, symbol1 = '?', symbol2 = None, x = None, y = None):
	if text is not None:
		messages.Basic(text + ' [ENTER]/[ESC]', symbol1 = '?', symbol2 = None)
		
		draw_hud(player)
	
	cursor_x, cursor_y = x or player.x, y or player.y
	
	while True:
		draw_map(player)
		highlight_tile(cursor_x, cursor_y)
		
		libtcod.console_flush()
		
		key = libtcod.console_wait_for_keypress(True)
		
		if key.vk == libtcod.KEY_ESCAPE:
			yield False
		
		elif key.vk in [libtcod.KEY_ENTER, libtcod.KEY_KPENTER]:
			yield (cursor_x, cursor_y)
		
		elif key.vk in DIRECTION_KEYS:
			dx, dy = DIRECTION_KEYS[key.vk]
			
			cursor_x += dx
			cursor_y += dy
		
			cursor_x %= 80
			cursor_y %= 40
Example #2
0
def ask_confirmation(player, text, confirm_key = 'y', symbol1 = '?', symbol2 = None):
	messages.Basic('{:s} [{:s}]/[any]'.format(text, confirm_key), symbol1 = '?', symbol2 = None)
	
	draw_hud(player)
	
	libtcod.console_flush()
	
	key = libtcod.console_wait_for_keypress(True)
	
	return key.c == ord(confirm_key)
Example #3
0
def ask_hit_enter(player, text, symbol1 = '?', symbol2 = None):
	messages.Basic('{:s} [ENTER]'.format(text), symbol1, symbol2)
	
	draw_hud(player)
	
	libtcod.console_flush()
	
	key = None
	
	while not key or key.vk not in [libtcod.KEY_ENTER, libtcod.KEY_KPENTER]:
		key = libtcod.console_wait_for_keypress(True)
Example #4
0
def debug(player):
	messages.Basic('Switching focus to the python console...', ('<', libtcod.green))
	draw_hud(player)
	libtcod.console_flush()
	
	quit = False
	exceptions = []
	
	print 'Debug console'
	print 'To quit, set local variable quit = True'
	
	while not quit:
		try:
			exec raw_input('>>> ')
		
		except Exception as exception:
			print str(exception) + ' (appended to local variable exceptions)'
			exceptions.append(exception)
	
	messages.Basic('Exited console.', ('/', libtcod.green), ('>', libtcod.green))
Example #5
0
def ask_which_direction(player, text, directions = ADJACENT, symbol1 = '?', symbol2 = None):
	if not directions:
		return None
	
	elif len(directions) == 1:
		return directions[0]
	
	else:
		messages.Basic('{:s} ({:s})'.format(text, ','.join(DIRECTION_PHRASE[direction] for direction in directions)), symbol1 = '?', symbol2 = None)
		
		draw_hud(player)
		
		libtcod.console_flush()
		
		key = libtcod.console_wait_for_keypress(True)
		dir = DIRECTION_KEYS.get(key.vk)
		if dir and dir in directions:
			return dir
		else:
			return None
Example #6
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)