Exemple #1
0
def chargen_options(posx, posy, width, options, typ):
	choice = False
	current = 0
	key = libtcod.Key()
	mouse = libtcod.Mouse()
	lerp = 1.0
	descending = True

	while not choice:
		if typ == 'race':
			character_description('race', current)
		if typ == 'class':
			character_description('class', current)
		ev = libtcod.sys_check_for_event(libtcod.EVENT_ANY, key, mouse)
		libtcod.console_set_default_foreground(0, libtcod.grey)
		libtcod.console_set_default_background(0, libtcod.black)

		for y in range(len(options)):
			if y == current:
				libtcod.console_set_default_foreground(0, libtcod.white)
				color, lerp, descending = util.color_lerp(lerp, descending)
				libtcod.console_set_default_background(0, color)
			else:
				libtcod.console_set_default_foreground(0, libtcod.grey)
				libtcod.console_set_default_background(0, libtcod.black)
			libtcod.console_rect(0, posx, y + posy, width, 1, True, libtcod.BKGND_SET)
			libtcod.console_print_ex(0, posx + 2, y + posy, libtcod.BKGND_SET, libtcod.LEFT, options[y])
		libtcod.console_flush()

		if key.vk == libtcod.KEY_DOWN and ev == libtcod.EVENT_KEY_PRESS:
			current = (current + 1) % len(options)
			lerp = 1.0
			descending = True
		elif key.vk == libtcod.KEY_UP and ev == libtcod.EVENT_KEY_PRESS:
			current = (current - 1) % len(options)
			lerp = 1.0
			descending = True
		elif key.vk == libtcod.KEY_ENTER and ev == libtcod.EVENT_KEY_PRESS:
			choice = True
	return current
Exemple #2
0
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