1
Programming / Screen Not Refreshing upon Menu Close
« on: January 28, 2017, 10:39:39 PM »
I've been struggling lately with having my screen refresh upon the inventory or level-up menu being closed. I'm going to put relevant parts of script here, any help is appreciated. Other minor bugs;
1. The screen, upon resizing, doesn't resize any of the menu bars to make them fit the new window size that bearlibterminal imparts.
2. I'd like to be able to display names with just a mouse hover, rather than a mouse click, mouse-click I'd like to work into having a more full description come up. Not sure where or if there are commands for these things.
1. The screen, upon resizing, doesn't resize any of the menu bars to make them fit the new window size that bearlibterminal imparts.
2. I'd like to be able to display names with just a mouse hover, rather than a mouse click, mouse-click I'd like to work into having a more full description come up. Not sure where or if there are commands for these things.
Quote
def inventory_menu(header):
global fov_recompute
#show a menu with each item of the inventory as an option
if len(inventory) == 0:
options = ['Inventory is empty.']
else:
options = []
for item in inventory:
text = item.name
#show additional info, in case it's equipped
if item.equipment and item.equipment.is_equipped:
text = text + ' (on ' + item.equipment.slot + ')'
options.append(text)
#options = [item.name for item in inventory]
index = menu(header, options, INVENTORY_WIDTH)
#if an item was chosen, return it
if index is None or len(inventory) == 0: return None
return inventory[index].item
terminal.layer(6)
terminal.clear_area(0, 0, MAP_WIDTH, MAP_HEIGHT)
fov_recompute = True
Quote
def handle_keys():
terminal.set('window.resizeable=true')
global fov_recompute
# Read keyboard input
global key
key = terminal.read()
if key == terminal.TK_ESCAPE:
# Close terminal
return 'exit'
if game_state == 'playing':
#??? it was 'exit()'
a = 'player moved'
if key == terminal.TK_KP_2 or key == terminal.TK_DOWN:
player_move_or_attack(0, 1)
return a
elif key == terminal.TK_KP_8 or key == terminal.TK_UP:
player_move_or_attack(0, -1)
return a
elif key == terminal.TK_KP_6 or key == terminal.TK_RIGHT:
player_move_or_attack(1, 0)
return a
elif key == terminal.TK_KP_4 or key == terminal.TK_LEFT:
player_move_or_attack(-1, 0)
return a
elif key == terminal.TK_KP_7:
player_move_or_attack(-1, -1)
return a
elif key == terminal.TK_KP_9:
player_move_or_attack(1, -1)
return a
elif key == terminal.TK_KP_1:
player_move_or_attack(-1, 1)
return a
elif key == terminal.TK_KP_3:
player_move_or_attack(1, 1)
return a
elif key == terminal.TK_KP_5:
return a
else: #test for other keys
if key == terminal.TK_G:
#pick up an item
for object in objects: #look for an item in the player's tile
if object.x == player.x and object.y == player.y and object.item:
object.item.pick_up()
break
if key == terminal.TK_I:
#show the inventory; if an item is selected, use it
chosen_item = inventory_menu('Press the key next to an item to use it, or any other to cancel.\n')
if chosen_item is not None:
chosen_item.use()
if key == terminal.TK_D:
#show the inventory; if an item is selected, drop it
chosen_item = inventory_menu('Press the key next to an item to drop it, or any other to cancel.\n')
if chosen_item is not None:
chosen_item.drop()
if key == terminal.TK_C:
#show character info
level_up_xp = LEVEL_UP_BASE + player.level * LEVEL_UP_FACTOR
msgbox('Character Information\n\nLevel: ' + str(player.level) +
'\nExperience: ' + str(player.fighter.xp) + ' / ' + str(level_up_xp) +
'\n\nMaximum HP: ' + str(player.fighter.max_hp) +
'\nAttack: ' + str(player.fighter.power) + '\nDefense: ' + str(player.fighter.defense), CHARACTER_SCREEN_WIDTH)
if key == terminal.TK_SHIFT:
key = terminal.read()
if key == terminal.TK_PERIOD and stairs.x == player.x and stairs.y == player.y:
#go down stairs, if the player is on them
next_level()
key = terminal.read()
if key == terminal.TK_RESIZED:
new_columns = terminal.state(terminal.TK_WIDTH)
new_rows = terminal.state(terminal.TK_HEIGHT)
return 'didnt-take-turn'