コード例 #1
0
ファイル: commands.py プロジェクト: pom2ter/immortal
def see_message_history():
	box_width = game.MESSAGE_WIDTH + 2
	box_height = (game.SCREEN_HEIGHT / 2) + 4
	box = libtcod.console_new(box_width, box_height)
	game.messages.box_gui(box, 0, 0, box_width, box_height, libtcod.green)
	libtcod.console_set_default_foreground(box, libtcod.black)
	libtcod.console_set_default_background(box, libtcod.green)
	libtcod.console_print_ex(box, box_width / 2, 0, libtcod.BKGND_SET, libtcod.CENTER, ' Message History ')
	libtcod.console_set_default_foreground(box, libtcod.green)
	libtcod.console_set_default_background(box, libtcod.black)
	libtcod.console_print_ex(box, box_width / 2, box_height - 1, libtcod.BKGND_SET, libtcod.CENTER, ' Arrow keys - Scroll up/down, ESC - exit ')
	libtcod.console_set_default_foreground(box, libtcod.white)

	scroll = 0
	exit = False
	key = libtcod.Key()
	while exit is False:
		libtcod.console_rect(box, 1, 1, box_width - 2, box_height - 2, True, libtcod.BKGND_SET)
		for i in range(min(box_height - 4, len(game.message.history))):
			libtcod.console_set_default_foreground(box, game.message.history[i + scroll][1])
			libtcod.console_print(box, 2, i + 2, game.message.history[i + scroll][0])
		util.scrollbar(box, box_width - 2, 2, scroll, box_height - 4, len(game.message.history))
		libtcod.console_blit(box, 0, 0, box_width, box_height, 0, (game.SCREEN_WIDTH - box_width) / 2, (game.MAP_HEIGHT - box_height + 2) / 2, 1.0, 1.0)
		libtcod.console_flush()
		ev = libtcod.sys_check_for_event(libtcod.EVENT_KEY_PRESS, key, libtcod.Mouse())
		if ev == libtcod.EVENT_KEY_PRESS:
			if key.vk == libtcod.KEY_ESCAPE:
				exit = True
			elif key.vk == libtcod.KEY_UP or key.vk == libtcod.KEY_KP8:
				if scroll > 0:
					scroll -= 1
			elif key.vk == libtcod.KEY_DOWN or key.vk == libtcod.KEY_KP2:
				if box_height - 4 + scroll < len(game.message.history):
					scroll += 1
	libtcod.console_delete(box)
	game.draw_gui = True
コード例 #2
0
ファイル: messages.py プロジェクト: pom2ter/immortal
def box_options(con, posx, posy, width, height, options, default, inv, step, mouse_exit, align, scrollbar):
	choice = False
	current, up, down = default, 0, height
	key = libtcod.Key()
	mouse = libtcod.Mouse()
	lerp = 1.0
	descending = True
	scroll = 0
	if scrollbar:
		scroll = 1
		down -= 2

	while not choice:
		ev = libtcod.sys_check_for_event(libtcod.EVENT_ANY, key, mouse)
		libtcod.console_set_default_foreground(con, libtcod.grey)
		libtcod.console_set_default_background(con, libtcod.black)
		libtcod.console_rect(con, 1, 1, width, height, True, libtcod.BKGND_SET)

		for y in range(up, down):
			if y < len(options):
				if y == current:
					libtcod.console_set_default_foreground(con, libtcod.white)
					color, lerp, descending = util.color_lerp(lerp, descending)
					libtcod.console_set_default_background(con, color)
				else:
					libtcod.console_set_default_foreground(con, libtcod.grey)
					libtcod.console_set_default_background(con, libtcod.black)
				if inv:
					text_left, text_right = util.inventory_output(options[y])
				else:
					text_left = options[y]
					text_right = ''
				libtcod.console_rect(con, step, y + step - up, width - ((step - 1) * 2) - scroll, 1, True, libtcod.BKGND_SET)
				if align == libtcod.LEFT:
					libtcod.console_print_ex(con, 1 + step, y + step - up, libtcod.BKGND_SET, libtcod.LEFT, text_left)
				if align == libtcod.RIGHT:
					libtcod.console_print_ex(con, width - 1 + step, y + step - up, libtcod.BKGND_SET, libtcod.RIGHT, text_left)
				libtcod.console_print_ex(con, width - step - scroll, y + step - up, libtcod.BKGND_SET, libtcod.RIGHT, text_right)

		if scrollbar:
			util.scrollbar(con, width, 2, up, height - 2, len(options))
		libtcod.console_blit(con, 0, 0, width + 2, height + 2, 0, posx, posy, 1.0, 0.9)
		libtcod.console_flush()

		if ev == libtcod.EVENT_MOUSE_MOVE:
			(mx, my) = (mouse.cx, mouse.cy)
			if my in range(posy + step, height + posy + step) and mx in range(posx + step, width + posx + 2 - step):
				mpos = my - posy - step + up
				if mpos <= len(options) - 1:
					current = mpos

		if key.vk == libtcod.KEY_DOWN and ev == libtcod.EVENT_KEY_PRESS:
			current = (current + 1) % len(options)
			if current == down:
				down += 1
				up += 1
			if current == 0:
				down = height
				up = 0
				if scrollbar:
					down -= 2
			lerp = 1.0
			descending = True
		elif key.vk == libtcod.KEY_UP and ev == libtcod.EVENT_KEY_PRESS:
			current = (current - 1) % len(options)
			if current < up:
				up -= 1
				down -= 1
			if current == len(options) - 1:
				if current > height - 3:
					up = len(options) - height
					down = len(options)
					if scrollbar:
						up += 2
			lerp = 1.0
			descending = True
		elif (key.vk == libtcod.KEY_ESCAPE and ev == libtcod.EVENT_KEY_PRESS) or (mouse_exit and mouse.lbutton_pressed and mx == width + posx - 2 and my == posy):
			current = -1
			choice = -1
		elif (key.vk == libtcod.KEY_ENTER and ev == libtcod.EVENT_KEY_PRESS) or (mouse.lbutton_pressed and my in range(posy + step, height + posy + step) and mx in range(posx + step, width + posx + 2 - step) and (my - posy - step + up) <= len(options) - 1):
			choice = True
	return current