Merge branch 'master' into 'familiars'

# Conflicts:
#   squirrelbattle/display/display_manager.py
#   squirrelbattle/display/logsdisplay.py
#   squirrelbattle/display/mapdisplay.py
#   squirrelbattle/display/menudisplay.py
#   squirrelbattle/menus.py
This commit is contained in:
eichhornchen
2021-01-05 10:27:39 +01:00
15 changed files with 167 additions and 57 deletions

View File

@ -5,8 +5,9 @@ import curses
from random import randint
from typing import List
from squirrelbattle.menus import Menu, MainMenu
from squirrelbattle.menus import Menu, MainMenu, SettingsMenu, StoreMenu
from .display import Box, Display
from ..entities.player import Player
from ..enums import KeyValues, GameMode
from ..game import Game
from ..resources import ResourceManager
@ -17,6 +18,7 @@ class MenuDisplay(Display):
"""
A class to display the menu objects.
"""
menu: Menu
position: int
def __init__(self, *args, **kwargs):
@ -80,6 +82,11 @@ class SettingsMenuDisplay(MenuDisplay):
"""
A class to display specifically a settingsmenu object.
"""
menu: SettingsMenu
def update(self, game: Game) -> None:
self.update_menu(game.settings_menu)
@property
def values(self) -> List[str]:
return [_(a[1][1]) + (" : "
@ -124,6 +131,9 @@ class MainMenuDisplay(Display):
menuy, menux, min(self.menudisplay.preferred_height,
self.height - menuy), menuwidth)
def update(self, game: Game) -> None:
self.menudisplay.update_menu(game.main_menu)
def handle_click(self, y: int, x: int, game: Game) -> None:
menuwidth = min(self.menudisplay.preferred_width, self.width)
menuy, menux = len(self.title) + 8, self.width // 2 - menuwidth // 2 - 1
@ -143,13 +153,33 @@ class PlayerInventoryDisplay(MenuDisplay):
"""
A class to handle the display of the player's inventory.
"""
player: Player = None
selected: bool = True
store_mode: bool = False
def update(self, game: Game) -> None:
self.player = game.player
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 else f" {rep} "
selection = f"[{rep}]" if i == self.menu.position \
and self.selected else f" {rep} "
self.addstr(self.pad, i + 1, 0, selection
+ " " + item.translated_name.capitalize())
+ " " + item.translated_name.capitalize()
+ (": " + str(item.price) + " Hazels"
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
def truewidth(self) -> int:
@ -164,6 +194,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)
@ -171,15 +202,28 @@ class StoreInventoryDisplay(MenuDisplay):
"""
A class to handle the display of a merchant's inventory.
"""
menu: StoreMenu
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 else f" {rep} "
selection = f"[{rep}]" if i == self.menu.position \
and self.selected else f" {rep} "
self.addstr(self.pad, i + 1, 0, selection
+ " " + item.translated_name.capitalize()
+ ": " + 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
def truewidth(self) -> int:
return max(1, self.height if hasattr(self, "height") else 10)
@ -193,4 +237,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)