Merging master into village, conflicts were solved
This commit is contained in:
@ -6,8 +6,8 @@ from squirrelbattle.display.display import VerticalSplit, HorizontalSplit
|
||||
from squirrelbattle.display.mapdisplay import MapDisplay
|
||||
from squirrelbattle.display.messagedisplay import MessageDisplay
|
||||
from squirrelbattle.display.statsdisplay import StatsDisplay
|
||||
from squirrelbattle.display.menudisplay import SettingsMenuDisplay, \
|
||||
MainMenuDisplay
|
||||
from squirrelbattle.display.menudisplay import MainMenuDisplay, \
|
||||
InventoryDisplay, SettingsMenuDisplay
|
||||
from squirrelbattle.display.logsdisplay import LogsDisplay
|
||||
from squirrelbattle.display.texturepack import TexturePack
|
||||
from typing import Any
|
||||
@ -23,10 +23,11 @@ class DisplayManager:
|
||||
pack = TexturePack.get_pack(self.game.settings.TEXTURE_PACK)
|
||||
self.mapdisplay = MapDisplay(screen, pack)
|
||||
self.statsdisplay = StatsDisplay(screen, pack)
|
||||
self.logsdisplay = LogsDisplay(screen, pack)
|
||||
self.inventorydisplay = InventoryDisplay(screen, pack)
|
||||
self.mainmenudisplay = MainMenuDisplay(self.game.main_menu,
|
||||
screen, pack)
|
||||
self.settingsmenudisplay = SettingsMenuDisplay(screen, pack)
|
||||
self.logsdisplay = LogsDisplay(screen, pack)
|
||||
self.messagedisplay = MessageDisplay(screen=screen, pack=None)
|
||||
self.hbar = HorizontalSplit(screen, pack)
|
||||
self.vbar = VerticalSplit(screen, pack)
|
||||
@ -46,12 +47,14 @@ 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.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:
|
||||
if self.game.state == GameMode.PLAY \
|
||||
or self.game.state == GameMode.INVENTORY:
|
||||
# The map pad has already the good size
|
||||
self.mapdisplay.refresh(0, 0, self.rows * 4 // 5,
|
||||
self.mapdisplay.pack.tile_width
|
||||
@ -64,10 +67,15 @@ class DisplayManager:
|
||||
self.rows // 5 - 1, self.cols * 4 // 5)
|
||||
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.MAINMENU:
|
||||
if self.game.state == GameMode.INVENTORY:
|
||||
self.inventorydisplay.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)
|
||||
if self.game.state == GameMode.SETTINGS:
|
||||
self.settingsmenudisplay.refresh(0, 0, self.rows, self.cols - 1)
|
||||
elif self.game.state == GameMode.SETTINGS:
|
||||
self.settingsmenudisplay.refresh(0, 0, self.rows, self.cols)
|
||||
|
||||
if self.game.message:
|
||||
height, width = 0, 0
|
||||
|
@ -1,6 +1,6 @@
|
||||
# Copyright (C) 2020 by ÿnérant, eichhornchen, nicomarg, charlse
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
import curses
|
||||
from typing import List
|
||||
|
||||
from squirrelbattle.menus import Menu, MainMenu
|
||||
@ -24,8 +24,6 @@ class MenuDisplay(Display):
|
||||
|
||||
# Menu values are printed in pad
|
||||
self.pad = self.newpad(self.trueheight, self.truewidth + 2)
|
||||
for i in range(self.trueheight):
|
||||
self.addstr(self.pad, i, 0, " " + self.values[i])
|
||||
|
||||
def update_pad(self) -> None:
|
||||
for i in range(self.trueheight):
|
||||
@ -110,12 +108,22 @@ class MainMenuDisplay(Display):
|
||||
menuy, menux, min(self.menudisplay.preferred_height,
|
||||
self.height - menuy), menuwidth)
|
||||
|
||||
class VariableMenuDisplay(MenuDisplay):
|
||||
"""
|
||||
A class to display a menu in which each value is associated to a parameter
|
||||
"""
|
||||
|
||||
class InventoryDisplay(MenuDisplay):
|
||||
def update_pad(self) -> None:
|
||||
message = _("== INVENTORY ==")
|
||||
self.addstr(self.pad, 0, (self.width - len(message)) // 2, 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())
|
||||
|
||||
@property
|
||||
def values(self) -> List[str]:
|
||||
return [a[1][1] + (" : "
|
||||
+ (a[1][0])
|
||||
if a[1][0] else "") for a in self.menu.values]
|
||||
def truewidth(self) -> int:
|
||||
return max(1, self.height if hasattr(self, "height") else 10)
|
||||
|
||||
@property
|
||||
def trueheight(self) -> int:
|
||||
return 2 + super().trueheight
|
||||
|
@ -31,8 +31,19 @@ class StatsDisplay(Display):
|
||||
self.player.dexterity, self.player.constitution)
|
||||
self.addstr(self.pad, 3, 0, string3)
|
||||
|
||||
inventory_str = _("Inventory:") + " " + "".join(
|
||||
self.pack[item.name.upper()] for item in self.player.inventory)
|
||||
inventory_str = _("Inventory:") + " "
|
||||
# Stack items by type instead of displaying each item
|
||||
item_types = [item.name for item in self.player.inventory]
|
||||
item_types.sort(key=item_types.count, reverse=True)
|
||||
printed_items = []
|
||||
for item in item_types:
|
||||
if item in printed_items:
|
||||
continue
|
||||
count = item_types.count(item)
|
||||
inventory_str += self.pack[item.upper()]
|
||||
if count > 1:
|
||||
inventory_str += f"x{count} "
|
||||
printed_items.append(item)
|
||||
self.addstr(self.pad, 8, 0, inventory_str)
|
||||
|
||||
if self.player.dead:
|
||||
|
@ -58,6 +58,7 @@ TexturePack.ASCII_PACK = TexturePack(
|
||||
TEDDY_BEAR='8',
|
||||
MERCHANT='M',
|
||||
SUNFLOWER='I',
|
||||
BODY_SNATCH_POTION='S',
|
||||
)
|
||||
|
||||
TexturePack.SQUIRREL_PACK = TexturePack(
|
||||
@ -79,4 +80,5 @@ TexturePack.SQUIRREL_PACK = TexturePack(
|
||||
TEDDY_BEAR='🧸',
|
||||
MERCHANT='🦜',
|
||||
SUNFLOWER='🌻',
|
||||
BODY_SNATCH_POTION='🔀',
|
||||
)
|
||||
|
Reference in New Issue
Block a user