Merchant menu is updated through its update function, and does not access globally to the Game instance

This commit is contained in:
Yohann D'ANELLO
2020-12-18 15:15:47 +01:00
parent 85870494a0
commit 46ce7c33bf
4 changed files with 18 additions and 11 deletions

View File

@ -7,6 +7,7 @@ from squirrelbattle.interfaces import Logs
class LogsDisplay(Display):
logs: Logs
def __init__(self, *args) -> None:
super().__init__(*args)

View File

@ -7,6 +7,7 @@ from ..game import Game
class MapDisplay(Display):
map: Map
def __init__(self, *args):
super().__init__(*args)

View File

@ -144,21 +144,25 @@ class MainMenuDisplay(Display):
class PlayerInventoryDisplay(MenuDisplay):
selected: bool = True
store_mode: bool = False
def update(self, game: Game) -> None:
self.update_menu(game.inventory_menu)
self.store_mode = game.state == GameMode.STORE
self.selected = game.state == GameMode.INVENTORY \
or self.store_mode and not game.is_in_store_menu
def update_pad(self) -> None:
self.menubox.update_title(_("INVENTORY"))
for i, item in enumerate(self.menu.values):
rep = self.pack[item.name.upper()]
selection = f"[{rep}]" if i == self.menu.position \
and (Game.INSTANCE.state == GameMode.INVENTORY
or Game.INSTANCE.state == GameMode.STORE
and not Game.INSTANCE.is_in_store_menu) else f" {rep} "
and self.selected else f" {rep} "
self.addstr(self.pad, i + 1, 0, selection
+ " " + item.translated_name.capitalize()
+ (": " + str(item.price) + " Hazels"
if Game.INSTANCE.state == GameMode.STORE else ""))
if self.store_mode else ""))
@property
def truewidth(self) -> int:
@ -178,15 +182,18 @@ class PlayerInventoryDisplay(MenuDisplay):
class StoreInventoryDisplay(MenuDisplay):
selected: bool = False
def update(self, game: Game) -> None:
self.update_menu(game.store_menu)
self.selected = game.is_in_store_menu
def update_pad(self) -> None:
self.menubox.update_title(_("STALL"))
for i, item in enumerate(self.menu.values):
rep = self.pack[item.name.upper()]
selection = f"[{rep}]" if i == self.menu.position \
and Game.INSTANCE.is_in_store_menu else f" {rep} "
and self.selected else f" {rep} "
self.addstr(self.pad, i + 1, 0, selection
+ " " + item.translated_name.capitalize()
+ ": " + str(item.price) + " Hazels")