Merge branch 'master' into 'mouse_interaction'

# Conflicts:
#   squirrelbattle/display/display_manager.py
#   squirrelbattle/display/menudisplay.py
#   squirrelbattle/entities/items.py
This commit is contained in:
ynerant
2020-12-11 18:38:13 +01:00
17 changed files with 865 additions and 118 deletions

View File

@ -8,7 +8,7 @@ from squirrelbattle.display.mapdisplay import MapDisplay
from squirrelbattle.display.messagedisplay import MessageDisplay
from squirrelbattle.display.statsdisplay import StatsDisplay
from squirrelbattle.display.menudisplay import MainMenuDisplay, \
InventoryDisplay, SettingsMenuDisplay
PlayerInventoryDisplay, StoreInventoryDisplay, SettingsMenuDisplay
from squirrelbattle.display.logsdisplay import LogsDisplay
from squirrelbattle.display.texturepack import TexturePack
from typing import Any, List
@ -25,7 +25,8 @@ class DisplayManager:
self.mapdisplay = MapDisplay(screen, pack)
self.statsdisplay = StatsDisplay(screen, pack)
self.logsdisplay = LogsDisplay(screen, pack)
self.inventorydisplay = InventoryDisplay(screen, pack)
self.playerinventorydisplay = PlayerInventoryDisplay(screen, pack)
self.storeinventorydisplay = StoreInventoryDisplay(screen, pack)
self.mainmenudisplay = MainMenuDisplay(self.game.main_menu,
screen, pack)
self.settingsmenudisplay = SettingsMenuDisplay(screen, pack)
@ -34,7 +35,9 @@ class DisplayManager:
self.vbar = VerticalSplit(screen, pack)
self.displays = [self.statsdisplay, self.mapdisplay,
self.mainmenudisplay, self.settingsmenudisplay,
self.logsdisplay, self.messagedisplay]
self.logsdisplay, self.messagedisplay,
self.playerinventorydisplay,
self.storeinventorydisplay]
self.update_game_components()
def handle_display_action(self, action: DisplayActions, *params) -> None:
@ -50,7 +53,10 @@ class DisplayManager:
d.pack = TexturePack.get_pack(self.game.settings.TEXTURE_PACK)
self.mapdisplay.update_map(self.game.map)
self.statsdisplay.update_player(self.game.player)
self.inventorydisplay.update_menu(self.game.inventory_menu)
self.game.inventory_menu.update_player(self.game.player)
self.game.store_menu.update_merchant(self.game.player)
self.playerinventorydisplay.update_menu(self.game.inventory_menu)
self.storeinventorydisplay.update_menu(self.game.store_menu)
self.settingsmenudisplay.update_menu(self.game.settings_menu)
self.logsdisplay.update_logs(self.game.logs)
self.messagedisplay.update_message(self.game.message)
@ -71,7 +77,8 @@ class DisplayManager:
displays = []
if self.game.state == GameMode.PLAY \
or self.game.state == GameMode.INVENTORY:
or self.game.state == GameMode.INVENTORY \
or self.game.state == GameMode.STORE:
# The map pad has already the good size
self.mapdisplay.refresh(0, 0, self.rows * 4 // 5,
self.mapdisplay.pack.tile_width
@ -89,11 +96,15 @@ class DisplayManager:
self.hbar, self.vbar]
if self.game.state == GameMode.INVENTORY:
self.inventorydisplay.refresh(self.rows // 10,
self.cols // 2,
8 * self.rows // 10,
2 * self.cols // 5)
self.playerinventorydisplay.refresh(
self.rows // 10, self.cols // 2,
8 * self.rows // 10, 2 * self.cols // 5)
displays.append(self.inventorydisplay)
elif self.game.state == GameMode.STORE:
self.storeinventorydisplay.refresh(
self.rows // 10, self.cols // 2,
8 * self.rows // 10, 2 * self.cols // 5)
displays.append(self.storeinventorydisplay)
elif self.game.state == GameMode.MAINMENU:
self.mainmenudisplay.refresh(0, 0, self.rows, self.cols)
displays.append(self.mainmenudisplay)

View File

@ -13,6 +13,9 @@ from ..translations import gettext as _
class MenuDisplay(Display):
"""
A class to display the menu objects
"""
position: int
def __init__(self, *args, **kwargs):
@ -73,6 +76,9 @@ class MenuDisplay(Display):
class SettingsMenuDisplay(MenuDisplay):
"""
A class to display specifically a settingsmenu object
"""
@property
def values(self) -> List[str]:
return [_(a[1][1]) + (" : "
@ -83,6 +89,9 @@ class SettingsMenuDisplay(MenuDisplay):
class MainMenuDisplay(Display):
"""
A class to display specifically a mainmenu object
"""
def __init__(self, menu: MainMenu, *args):
super().__init__(*args)
self.menu = menu
@ -118,11 +127,12 @@ class MainMenuDisplay(Display):
self.menudisplay.handle_click(y - menuy, x - menux, game)
class InventoryDisplay(MenuDisplay):
class PlayerInventoryDisplay(MenuDisplay):
message = _("== INVENTORY ==")
def update_pad(self) -> None:
message = _("== INVENTORY ==")
self.addstr(self.pad, 0, (self.width - len(message)) // 2, message,
curses.A_BOLD | curses.A_ITALIC)
self.addstr(self.pad, 0, (self.width - len(self.message)) // 2,
self.message, curses.A_BOLD | curses.A_ITALIC)
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} "
@ -143,3 +153,32 @@ class InventoryDisplay(MenuDisplay):
"""
self.menu.position = max(0, min(len(self.menu.values) - 1, y - 3))
game.handle_key_pressed(KeyValues.ENTER)
class StoreInventoryDisplay(MenuDisplay):
message = _("== STALL ==")
def update_pad(self) -> None:
self.addstr(self.pad, 0, (self.width - len(self.message)) // 2,
self.message, curses.A_BOLD | curses.A_ITALIC)
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} "
self.addstr(self.pad, 2 + i, 0, selection
+ " " + item.translated_name.capitalize()
+ ": " + str(item.price) + " Hazels")
@property
def truewidth(self) -> int:
return max(1, self.height if hasattr(self, "height") else 10)
@property
def trueheight(self) -> int:
return 2 + super().trueheight
def handle_click(self, y: int, x: int, game: Game) -> None:
"""
We can select a menu item with the mouse.
"""
self.menu.position = max(0, min(len(self.menu.values) - 1, y - 3))
game.handle_key_pressed(KeyValues.ENTER)

View File

@ -46,8 +46,11 @@ class StatsDisplay(Display):
printed_items.append(item)
self.addstr(self.pad, 8, 0, inventory_str)
self.addstr(self.pad, 9, 0, f"{self.pack.HAZELNUT} "
f"x{self.player.hazel}")
if self.player.dead:
self.addstr(self.pad, 10, 0, _("YOU ARE DEAD"),
self.addstr(self.pad, 11, 0, _("YOU ARE DEAD"),
curses.A_BOLD | curses.A_BLINK | curses.A_STANDOUT
| self.color_pair(3))

View File

@ -14,10 +14,22 @@ class TexturePack:
tile_bg_color: int
entity_fg_color: int
entity_bg_color: int
BODY_SNATCH_POTION: str
BOMB: str
HEART: str
HEDGEHOG: str
EMPTY: str
WALL: str
FLOOR: str
HAZELNUT: str
MERCHANT: str
PLAYER: str
RABBIT: str
SUNFLOWER: str
SWORD: str
TEDDY_BEAR: str
TIGER: str
WALL: str
ASCII_PACK: "TexturePack"
SQUIRREL_PACK: "TexturePack"
@ -46,17 +58,22 @@ TexturePack.ASCII_PACK = TexturePack(
tile_bg_color=curses.COLOR_BLACK,
entity_fg_color=curses.COLOR_WHITE,
entity_bg_color=curses.COLOR_BLACK,
EMPTY=' ',
WALL='#',
FLOOR='.',
PLAYER='@',
HEDGEHOG='*',
HEART='',
BOMB='o',
RABBIT='Y',
TIGER='n',
TEDDY_BEAR='8',
BODY_SNATCH_POTION='S',
BOMB='o',
EMPTY=' ',
FLOOR='.',
HAZELNUT='¤',
HEART='',
HEDGEHOG='*',
MERCHANT='M',
PLAYER='@',
RABBIT='Y',
SUNFLOWER='I',
SWORD='\u2020',
TEDDY_BEAR='8',
TIGER='n',
WALL='#',
)
TexturePack.SQUIRREL_PACK = TexturePack(
@ -66,15 +83,20 @@ TexturePack.SQUIRREL_PACK = TexturePack(
tile_bg_color=curses.COLOR_BLACK,
entity_fg_color=curses.COLOR_WHITE,
entity_bg_color=curses.COLOR_WHITE,
EMPTY=' ',
WALL='🧱',
FLOOR='██',
PLAYER='🐿️ ',
HEDGEHOG='🦔',
HEART='💜',
BOMB='💣',
RABBIT='🐇',
TIGER='🐅',
TEDDY_BEAR='🧸',
BODY_SNATCH_POTION='🔀',
BOMB='💣',
EMPTY=' ',
FLOOR='██',
HAZELNUT='🌰',
HEART='💜',
HEDGEHOG='🦔',
PLAYER='🐿️ ',
MERCHANT='🦜',
RABBIT='🐇',
SUNFLOWER='🌻',
SWORD='🗡️',
TEDDY_BEAR='🧸',
TIGER='🐅',
WALL='🧱',
)