Display more precisely where we are in the store menu
This commit is contained in:
parent
9a556ba669
commit
c55a7451e7
|
@ -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)
|
||||
|
|
|
@ -97,7 +97,7 @@ TexturePack.SQUIRREL_PACK = TexturePack(
|
|||
MERCHANT='🦜',
|
||||
RABBIT='🐇',
|
||||
SUNFLOWER='🌻',
|
||||
SWORD='🗡️',
|
||||
SWORD='🗡️ ',
|
||||
TEDDY_BEAR='🧸',
|
||||
TIGER='🐅',
|
||||
WALL='🧱',
|
||||
|
|
|
@ -22,6 +22,9 @@ class Game:
|
|||
"""
|
||||
The game object controls all actions in the game.
|
||||
"""
|
||||
# Global instance of the game
|
||||
INSTANCE: "Game"
|
||||
|
||||
map: Map
|
||||
player: Player
|
||||
screen: Any
|
||||
|
@ -32,6 +35,8 @@ class Game:
|
|||
"""
|
||||
Init the game.
|
||||
"""
|
||||
Game.INSTANCE = self
|
||||
|
||||
self.state = GameMode.MAINMENU
|
||||
self.waiting_for_friendly_key = False
|
||||
self.is_in_store_menu = True
|
||||
|
@ -52,7 +57,7 @@ class Game:
|
|||
Create a new game on the screen.
|
||||
"""
|
||||
# TODO generate a new map procedurally
|
||||
self.map = Map.load(ResourceManager.get_asset_path("example_map.txt"))
|
||||
self.map = Map.load(ResourceManager.get_asset_path("example_map_2.txt"))
|
||||
self.map.logs = self.logs
|
||||
self.logs.clear()
|
||||
self.player = Player()
|
||||
|
@ -163,6 +168,7 @@ class Game:
|
|||
self.logs.add_message(msg)
|
||||
if entity.is_merchant():
|
||||
self.state = GameMode.STORE
|
||||
self.is_in_store_menu = True
|
||||
self.store_menu.update_merchant(entity)
|
||||
|
||||
def handle_key_pressed_inventory(self, key: KeyValues) -> None:
|
||||
|
|
|
@ -546,6 +546,10 @@ class TestGame(unittest.TestCase):
|
|||
# Navigate in the menu
|
||||
self.game.handle_key_pressed(KeyValues.DOWN)
|
||||
self.game.handle_key_pressed(KeyValues.DOWN)
|
||||
self.game.handle_key_pressed(KeyValues.LEFT)
|
||||
self.assertFalse(self.game.is_in_store_menu)
|
||||
self.game.handle_key_pressed(KeyValues.RIGHT)
|
||||
self.assertTrue(self.game.is_in_store_menu)
|
||||
self.game.handle_key_pressed(KeyValues.UP)
|
||||
self.assertEqual(self.game.store_menu.position, 1)
|
||||
|
||||
|
|
Loading…
Reference in New Issue