2021-01-10 09:46:17 +00:00
|
|
|
# Copyright (C) 2020-2021 by ÿnérant, eichhornchen, nicomarg, charlse
|
2020-11-27 15:33:17 +00:00
|
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
2020-11-11 00:17:00 +00:00
|
|
|
import curses
|
|
|
|
|
2021-01-10 10:25:53 +00:00
|
|
|
from .display import Display
|
2021-01-08 14:48:12 +00:00
|
|
|
from ..entities.items import Monocle
|
2020-11-27 19:42:19 +00:00
|
|
|
from ..entities.player import Player
|
2020-12-18 14:07:09 +00:00
|
|
|
from ..game import Game
|
2021-01-08 14:48:12 +00:00
|
|
|
from ..interfaces import FightingEntity
|
2020-11-27 19:42:19 +00:00
|
|
|
from ..translations import gettext as _
|
2020-11-06 18:53:27 +00:00
|
|
|
|
2020-11-06 20:15:09 +00:00
|
|
|
|
2020-11-10 17:08:06 +00:00
|
|
|
class StatsDisplay(Display):
|
2020-12-13 20:29:25 +00:00
|
|
|
"""
|
|
|
|
A class to handle the display of the stats of the player.
|
|
|
|
"""
|
2021-01-08 14:07:35 +00:00
|
|
|
game: Game
|
2020-11-10 09:49:11 +00:00
|
|
|
player: Player
|
2020-11-10 19:34:22 +00:00
|
|
|
|
2020-11-10 19:43:30 +00:00
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
super().__init__(*args, **kwargs)
|
2020-11-10 17:08:06 +00:00
|
|
|
self.pad = self.newpad(self.rows, self.cols)
|
2020-11-10 19:34:22 +00:00
|
|
|
|
2020-12-18 14:07:09 +00:00
|
|
|
def update(self, game: Game) -> None:
|
2021-01-08 14:07:35 +00:00
|
|
|
self.game = game
|
2020-12-18 14:07:09 +00:00
|
|
|
self.player = game.player
|
2020-11-06 20:15:09 +00:00
|
|
|
|
|
|
|
def update_pad(self) -> None:
|
2021-01-06 14:17:02 +00:00
|
|
|
string2 = f"{_(self.player.name).capitalize()} " \
|
|
|
|
f"-- LVL {self.player.level} -- " \
|
|
|
|
f"FLOOR {-self.player.map.floor}\n" \
|
|
|
|
f"EXP {self.player.current_xp}/{self.player.max_xp}\n" \
|
|
|
|
f"HP {self.player.health}/{self.player.maxhealth}"
|
2020-11-26 11:35:52 +00:00
|
|
|
self.addstr(self.pad, 0, 0, string2)
|
2021-01-06 14:17:02 +00:00
|
|
|
string3 = f"STR {self.player.strength}\n" \
|
|
|
|
f"INT {self.player.intelligence}\n" \
|
|
|
|
f"CHR {self.player.charisma}\n" \
|
|
|
|
f"DEX {self.player.dexterity}\n" \
|
2021-01-08 01:11:40 +00:00
|
|
|
f"CON {self.player.constitution}\n" \
|
|
|
|
f"CRI {self.player.critical}%"
|
2020-11-26 11:35:52 +00:00
|
|
|
self.addstr(self.pad, 3, 0, string3)
|
2020-11-11 22:41:06 +00:00
|
|
|
|
2020-12-06 10:43:48 +00:00
|
|
|
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)
|
2021-01-05 18:23:25 +00:00
|
|
|
self.addstr(self.pad, 9, 0, inventory_str)
|
2020-11-11 22:41:06 +00:00
|
|
|
|
2021-01-06 09:46:36 +00:00
|
|
|
if self.player.equipped_main:
|
2021-01-05 18:23:25 +00:00
|
|
|
self.addstr(self.pad, 10, 0,
|
2021-01-06 09:46:36 +00:00
|
|
|
_("Equipped main:") + " "
|
|
|
|
f"{self.pack[self.player.equipped_main.name.upper()]}")
|
|
|
|
if self.player.equipped_secondary:
|
2021-01-05 18:23:25 +00:00
|
|
|
self.addstr(self.pad, 11, 0,
|
2021-01-06 09:46:36 +00:00
|
|
|
_("Equipped secondary:") + " "
|
2021-01-06 17:02:58 +00:00
|
|
|
+ self.pack[self.player.equipped_secondary
|
|
|
|
.name.upper()])
|
2021-01-06 09:46:36 +00:00
|
|
|
if self.player.equipped_armor:
|
|
|
|
self.addstr(self.pad, 12, 0,
|
|
|
|
_("Equipped chestplate:") + " "
|
2021-01-06 17:02:58 +00:00
|
|
|
+ self.pack[self.player.equipped_armor.name.upper()])
|
2021-01-06 09:46:36 +00:00
|
|
|
if self.player.equipped_helmet:
|
|
|
|
self.addstr(self.pad, 13, 0,
|
|
|
|
_("Equipped helmet:") + " "
|
2021-01-06 17:02:58 +00:00
|
|
|
+ self.pack[self.player.equipped_helmet.name.upper()])
|
2020-12-18 16:30:03 +00:00
|
|
|
|
2021-01-06 09:46:36 +00:00
|
|
|
self.addstr(self.pad, 14, 0, f"{self.pack.HAZELNUT} "
|
2020-12-18 16:30:03 +00:00
|
|
|
f"x{self.player.hazel}")
|
2020-12-09 15:54:53 +00:00
|
|
|
|
2020-11-11 00:17:00 +00:00
|
|
|
if self.player.dead:
|
2021-01-06 09:46:36 +00:00
|
|
|
self.addstr(self.pad, 15, 0, _("YOU ARE DEAD"), curses.COLOR_RED,
|
2020-12-12 12:46:45 +00:00
|
|
|
bold=True, blink=True, standout=True)
|
2020-11-06 20:15:09 +00:00
|
|
|
|
2021-01-08 13:51:56 +00:00
|
|
|
if self.player.map.tiles[self.player.y][self.player.x].is_ladder():
|
|
|
|
msg = _("Use {key} to use the ladder") \
|
2021-01-08 14:07:35 +00:00
|
|
|
.format(key=self.game.settings.KEY_LADDER.upper())
|
2021-01-08 13:51:56 +00:00
|
|
|
self.addstr(self.pad, self.height - 2, 0, msg,
|
|
|
|
italic=True, reverse=True)
|
|
|
|
|
2021-01-08 14:48:12 +00:00
|
|
|
self.update_entities_stats()
|
|
|
|
|
|
|
|
def update_entities_stats(self) -> None:
|
|
|
|
"""
|
|
|
|
Display information about a near entity if we have a monocle.
|
|
|
|
"""
|
2021-01-08 13:59:44 +00:00
|
|
|
for dy, dx in [(-1, 0), (0, -1), (0, 1), (1, 0)]:
|
2021-01-08 14:48:12 +00:00
|
|
|
for entity in self.player.map.find_entities(FightingEntity):
|
|
|
|
if entity == self.player:
|
|
|
|
continue
|
|
|
|
|
2021-01-08 13:59:44 +00:00
|
|
|
if entity.y == self.player.y + dy \
|
|
|
|
and entity.x == self.player.x + dx:
|
2021-01-08 14:48:12 +00:00
|
|
|
if entity.is_friendly():
|
|
|
|
msg = _("Move to the friendly entity to talk to it") \
|
|
|
|
if self.game.waiting_for_friendly_key else \
|
|
|
|
_("Use {key} then move to talk to the entity") \
|
|
|
|
.format(key=self.game.settings.KEY_CHAT.upper())
|
|
|
|
self.addstr(self.pad, self.height - 1, 0, msg,
|
|
|
|
italic=True, reverse=True)
|
|
|
|
|
|
|
|
if isinstance(self.player.equipped_secondary, Monocle):
|
|
|
|
# Truth monocle
|
|
|
|
message = f"{entity.translated_name.capitalize()} " \
|
|
|
|
f"{self.pack[entity.name.upper()]}\n" \
|
|
|
|
f"STR {entity.strength}\n" \
|
|
|
|
f"INT {entity.intelligence}\n" \
|
|
|
|
f"CHR {entity.charisma}\n" \
|
|
|
|
f"DEX {entity.dexterity}\n" \
|
|
|
|
f"CON {entity.constitution}\n" \
|
|
|
|
f"CRI {entity.critical}%"
|
|
|
|
self.addstr(self.pad, 17, 0, message)
|
|
|
|
# Only display one entity
|
|
|
|
break
|
2021-01-08 13:59:44 +00:00
|
|
|
|
2020-11-10 17:08:06 +00:00
|
|
|
def display(self) -> None:
|
2020-11-26 21:20:14 +00:00
|
|
|
self.pad.erase()
|
2020-11-06 18:50:26 +00:00
|
|
|
self.update_pad()
|
2020-11-26 19:58:46 +00:00
|
|
|
self.refresh_pad(self.pad, 0, 0, self.y, self.x,
|
2020-11-20 17:07:09 +00:00
|
|
|
self.y + self.height - 1, self.width + self.x - 1)
|