Display more precisely where we are in the store menu

This commit is contained in:
Yohann D'ANELLO
2020-12-18 01:50:11 +01:00
parent 9a556ba669
commit c55a7451e7
4 changed files with 24 additions and 6 deletions

View File

@ -7,7 +7,7 @@ from typing import List
from squirrelbattle.menus import Menu, MainMenu
from .display import Box, Display
from ..enums import KeyValues
from ..enums import KeyValues, GameMode
from ..game import Game
from ..resources import ResourceManager
from ..translations import gettext as _
@ -139,9 +139,14 @@ class PlayerInventoryDisplay(MenuDisplay):
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 else f" {rep} "
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} "
self.addstr(self.pad, i + 1, 0, selection
+ " " + item.translated_name.capitalize())
+ " " + item.translated_name.capitalize()
+ (": " + str(item.price) + " Hazels"
if Game.INSTANCE.state == GameMode.STORE else ""))
@property
def truewidth(self) -> int:
@ -156,6 +161,7 @@ class PlayerInventoryDisplay(MenuDisplay):
We can select a menu item with the mouse.
"""
self.menu.position = max(0, min(len(self.menu.values) - 1, y - 2))
game.is_in_store_menu = False
game.handle_key_pressed(KeyValues.ENTER)
@ -164,7 +170,8 @@ class StoreInventoryDisplay(MenuDisplay):
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 else f" {rep} "
selection = f"[{rep}]" if i == self.menu.position \
and Game.INSTANCE.is_in_store_menu else f" {rep} "
self.addstr(self.pad, i + 1, 0, selection
+ " " + item.translated_name.capitalize()
+ ": " + str(item.price) + " Hazels")
@ -182,4 +189,5 @@ class StoreInventoryDisplay(MenuDisplay):
We can select a menu item with the mouse.
"""
self.menu.position = max(0, min(len(self.menu.values) - 1, y - 2))
game.is_in_store_menu = True
game.handle_key_pressed(KeyValues.ENTER)

View File

@ -97,7 +97,7 @@ TexturePack.SQUIRREL_PACK = TexturePack(
MERCHANT='🦜',
RABBIT='🐇',
SUNFLOWER='🌻',
SWORD='🗡️',
SWORD='🗡️ ',
TEDDY_BEAR='🧸',
TIGER='🐅',
WALL='🧱',