예제 #1
0
파일: util.py 프로젝트: pom2ter/immortal
def change_settings(box, width, height, blitmap=False):
	confirm, cancel = False, False
	lerp = 1.0
	descending = True
	current = 0

	fonts = sorted(game.fonts, reverse=True)
	font = 0
	if game.setting_font == 'large':
		font = 2
	elif game.setting_font == 'medium':
		font = 1
	history = game.setting_history
	fullscreen = ['on', 'off']
	fs = 0
	if game.setting_fullscreen == 'off':
		fs = 1

	key = libtcod.Key()
	libtcod.console_print_rect(box, 2, 2, width - 4, 2, '(You may need to restart the game for the changes to take effect)')
	libtcod.console_print(box, 2, 5, 'Font size: ')
	libtcod.console_print(box, 2, 6, 'Message history size: ')
	libtcod.console_print(box, 2, 7, 'Fullscreen: ')
	while not confirm and not cancel:
		color, lerp, descending = color_lerp(lerp, descending)

		# font size setting
		if current == 0:
			libtcod.console_set_default_foreground(box, libtcod.white)
			libtcod.console_set_default_background(box, color)
		else:
			libtcod.console_set_default_foreground(box, libtcod.grey)
			libtcod.console_set_default_background(box, libtcod.black)
		libtcod.console_rect(box, 26, 5, 13, 1, True, libtcod.BKGND_SET)
		libtcod.console_print_ex(box, 32, 5, libtcod.BKGND_SET, libtcod.CENTER, fonts[font].capitalize())

		# message history size setting
		if current == 1:
			libtcod.console_set_default_foreground(box, libtcod.white)
			libtcod.console_set_default_background(box, color)
		else:
			libtcod.console_set_default_foreground(box, libtcod.grey)
			libtcod.console_set_default_background(box, libtcod.black)
		libtcod.console_rect(box, 26, 6, 13, 1, True, libtcod.BKGND_SET)
		libtcod.console_print_ex(box, 32, 6, libtcod.BKGND_SET, libtcod.CENTER, str(history))

		# full screen mode
		if current == 2:
			libtcod.console_set_default_foreground(box, libtcod.white)
			libtcod.console_set_default_background(box, color)
		else:
			libtcod.console_set_default_foreground(box, libtcod.grey)
			libtcod.console_set_default_background(box, libtcod.black)
		libtcod.console_rect(box, 26, 7, 13, 1, True, libtcod.BKGND_SET)
		libtcod.console_print_ex(box, 32, 7, libtcod.BKGND_SET, libtcod.CENTER, fullscreen[fs].capitalize())

		for i in range(5, 8):
			libtcod.console_set_default_foreground(box, libtcod.white)
			libtcod.console_print_ex(box, 25, i, libtcod.BKGND_NONE, libtcod.LEFT, chr(27))
			libtcod.console_print_ex(box, 39, i, libtcod.BKGND_NONE, libtcod.LEFT, chr(26))

		if blitmap:
			libtcod.console_blit(box, 0, 0, width, height, 0, ((game.MAP_WIDTH - width) / 2) + game.MAP_X, (game.MAP_HEIGHT - height) / 2, 1.0, 1.0)
		else:
			libtcod.console_blit(box, 0, 0, width, height, 0, (game.SCREEN_WIDTH - width) / 2, (game.SCREEN_HEIGHT - height) / 2, 1.0, 1.0)
		libtcod.console_flush()
		libtcod.sys_check_for_event(libtcod.EVENT_KEY_PRESS, key, libtcod.Mouse())

		if key.vk == libtcod.KEY_LEFT or key.vk == libtcod.KEY_RIGHT or key.vk == libtcod.KEY_UP or key.vk == libtcod.KEY_DOWN:
			lerp = 1.0
			descending = True
		if key.vk == libtcod.KEY_LEFT:
			if current == 0:
				font -= 1
				if font == -1:
					font = len(fonts) - 1
			if current == 1:
				history -= 50
				if history == 0:
					history = 1000
			if current == 2:
				if fs == 0:
					fs = 1
				else:
					fs = 0
		elif key.vk == libtcod.KEY_RIGHT:
			if current == 0:
				font += 1
				if font == len(fonts):
					font = 0
			if current == 1:
				history += 50
				if history > 1000:
					history = 50
			if current == 2:
				if fs == 0:
					fs = 1
				else:
					fs = 0
		elif key.vk == libtcod.KEY_UP:
			current -= 1
			if current == -1:
				current = 2
		elif key.vk == libtcod.KEY_DOWN:
			current += 1
			if current == 3:
				current = 0
		elif key.vk == libtcod.KEY_ESCAPE:
			cancel = True
		elif key.vk == libtcod.KEY_ENTER:
			confirm = True

	if confirm:
		game.setting_history = history
		game.setting_fullscreen = fullscreen[fs]
		if game.setting_fullscreen == 'on':
			libtcod.console_set_fullscreen(True)
		else:
			libtcod.console_set_fullscreen(False)
		if blitmap:
			game.message.trim_history()
		IO.save_settings(fonts[font], str(history), fullscreen[fs])