Display full inventory

This commit is contained in:
Yohann D'ANELLO 2020-12-04 16:28:37 +01:00
parent fbfcd5dae0
commit a68b3a6d08
3 changed files with 23 additions and 4 deletions

View File

@ -21,8 +21,6 @@ class MenuDisplay(Display):
# Menu values are printed in pad
self.pad = self.newpad(self.trueheight, self.truewidth + 2)
for i in range(self.trueheight):
self.addstr(self.pad, i, 0, " " + self.values[i])
def update_pad(self) -> None:
for i in range(self.trueheight):
@ -107,3 +105,16 @@ class InventoryDisplay(MenuDisplay):
message = _("== INVENTORY ==")
self.addstr(self.pad, 0, (self.width - len(message)) // 2, message,
curses.A_BOLD | curses.A_ITALIC)
for i, item in enumerate(self.menu.values):
rep = self.pack[item.name.upper()]
selection = f"[{rep}]" if i == self.menu.position else f" {rep} "
self.addstr(self.pad, 2 + i, 0, selection
+ " " + _(item.name).capitalize())
@property
def truewidth(self) -> int:
return max(1, self.height if hasattr(self, "height") else 10)
@property
def trueheight(self) -> int:
return 2 + super().trueheight

View File

@ -55,6 +55,7 @@ class Game:
self.map.add_entity(self.player)
self.player.move(self.map.start_y, self.map.start_x)
self.map.spawn_random_entities(randint(3, 10))
self.inventory_menu.update_player(self.player)
def run(self, screen: Any) -> None:
"""

View File

@ -5,6 +5,7 @@ from enum import Enum
from typing import Any, Optional
from .display.texturepack import TexturePack
from .entities.player import Player
from .enums import GameMode, KeyValues, DisplayActions
from .settings import Settings
from .translations import gettext as _, Translator
@ -118,5 +119,11 @@ class SettingsMenu(Menu):
class InventoryMenu(Menu):
# FIXME Use real menu
values = ["bomb"]
player: Player
def update_player(self, player: Player) -> None:
self.player = player
@property
def values(self) -> list:
return self.player.inventory