Display the amount of hazels in the store menu, closes #49

This commit is contained in:
Yohann D'ANELLO 2020-12-18 15:36:25 +01:00
parent 46ce7c33bf
commit 5ae49e71ff
1 changed files with 16 additions and 1 deletions

View File

@ -5,8 +5,9 @@ import curses
from random import randint from random import randint
from typing import List from typing import List
from squirrelbattle.menus import Menu, MainMenu, SettingsMenu from squirrelbattle.menus import Menu, MainMenu, SettingsMenu, StoreMenu
from .display import Box, Display from .display import Box, Display
from ..entities.player import Player
from ..enums import KeyValues, GameMode from ..enums import KeyValues, GameMode
from ..game import Game from ..game import Game
from ..resources import ResourceManager from ..resources import ResourceManager
@ -144,10 +145,12 @@ class MainMenuDisplay(Display):
class PlayerInventoryDisplay(MenuDisplay): class PlayerInventoryDisplay(MenuDisplay):
player: Player = None
selected: bool = True selected: bool = True
store_mode: bool = False store_mode: bool = False
def update(self, game: Game) -> None: def update(self, game: Game) -> None:
self.player = game.player
self.update_menu(game.inventory_menu) self.update_menu(game.inventory_menu)
self.store_mode = game.state == GameMode.STORE self.store_mode = game.state == GameMode.STORE
self.selected = game.state == GameMode.INVENTORY \ self.selected = game.state == GameMode.INVENTORY \
@ -164,6 +167,12 @@ class PlayerInventoryDisplay(MenuDisplay):
+ (": " + str(item.price) + " Hazels" + (": " + str(item.price) + " Hazels"
if self.store_mode else "")) if self.store_mode else ""))
if self.store_mode:
price = f"{self.pack.HAZELNUT} {self.player.hazel} Hazels"
width = len(price) + (self.pack.tile_width - 1)
self.addstr(self.pad, self.height - 3, self.width - width - 2,
price, italic=True)
@property @property
def truewidth(self) -> int: def truewidth(self) -> int:
return max(1, self.height if hasattr(self, "height") else 10) return max(1, self.height if hasattr(self, "height") else 10)
@ -182,6 +191,7 @@ class PlayerInventoryDisplay(MenuDisplay):
class StoreInventoryDisplay(MenuDisplay): class StoreInventoryDisplay(MenuDisplay):
menu: StoreMenu
selected: bool = False selected: bool = False
def update(self, game: Game) -> None: def update(self, game: Game) -> None:
@ -198,6 +208,11 @@ class StoreInventoryDisplay(MenuDisplay):
+ " " + item.translated_name.capitalize() + " " + item.translated_name.capitalize()
+ ": " + str(item.price) + " Hazels") + ": " + str(item.price) + " Hazels")
price = f"{self.pack.HAZELNUT} {self.menu.merchant.hazel} Hazels"
width = len(price) + (self.pack.tile_width - 1)
self.addstr(self.pad, self.height - 3, self.width - width - 2, price,
italic=True)
@property @property
def truewidth(self) -> int: def truewidth(self) -> int:
return max(1, self.height if hasattr(self, "height") else 10) return max(1, self.height if hasattr(self, "height") else 10)