Merge branch 'village' into 'master'
Village Closes #41, #38, #37, #36, and #18 See merge request ynerant/squirrel-battle!44
This commit is contained in:
@ -7,7 +7,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
|
||||
@ -24,7 +24,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)
|
||||
@ -33,7 +34,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) -> None:
|
||||
@ -47,14 +50,18 @@ 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)
|
||||
|
||||
def refresh(self) -> None:
|
||||
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
|
||||
@ -68,10 +75,13 @@ class DisplayManager:
|
||||
self.hbar.refresh(self.rows * 4 // 5, 0, 1, self.cols * 4 // 5)
|
||||
self.vbar.refresh(0, self.cols * 4 // 5, self.rows, 1)
|
||||
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)
|
||||
elif self.game.state == GameMode.STORE:
|
||||
self.storeinventorydisplay.refresh(
|
||||
self.rows // 10, self.cols // 2,
|
||||
8 * self.rows // 10, 2 * self.cols // 5)
|
||||
elif self.game.state == GameMode.MAINMENU:
|
||||
self.mainmenudisplay.refresh(0, 0, self.rows, self.cols)
|
||||
elif self.game.state == GameMode.SETTINGS:
|
||||
|
@ -10,6 +10,9 @@ from ..translations import gettext as _
|
||||
|
||||
|
||||
class MenuDisplay(Display):
|
||||
"""
|
||||
A class to display the menu objects
|
||||
"""
|
||||
position: int
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
@ -63,6 +66,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]) + (" : "
|
||||
@ -73,6 +79,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
|
||||
@ -100,11 +109,12 @@ class MainMenuDisplay(Display):
|
||||
self.height - menuy), menuwidth)
|
||||
|
||||
|
||||
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} "
|
||||
@ -118,3 +128,25 @@ class InventoryDisplay(MenuDisplay):
|
||||
@property
|
||||
def trueheight(self) -> int:
|
||||
return 2 + super().trueheight
|
||||
|
||||
|
||||
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
|
||||
|
@ -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))
|
||||
|
||||
|
@ -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='🧱',
|
||||
)
|
||||
|
Reference in New Issue
Block a user