2020-11-27 15:33:17 +00:00
|
|
|
# Copyright (C) 2020 by ÿnérant, eichhornchen, nicomarg, charlse
|
|
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
2020-11-11 00:17:00 +00:00
|
|
|
import curses
|
|
|
|
|
2020-11-27 19:42:19 +00:00
|
|
|
from ..entities.player import Player
|
|
|
|
from ..translations import gettext as _
|
2020-11-10 17:08:06 +00:00
|
|
|
from .display import Display
|
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-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-11 00:17:00 +00:00
|
|
|
self.init_pair(3, curses.COLOR_RED, curses.COLOR_BLACK)
|
2020-11-10 19:34:22 +00:00
|
|
|
|
|
|
|
def update_player(self, p: Player) -> None:
|
2020-11-10 17:08:06 +00:00
|
|
|
self.player = p
|
2020-11-06 20:15:09 +00:00
|
|
|
|
|
|
|
def update_pad(self) -> None:
|
2020-11-20 17:07:09 +00:00
|
|
|
string2 = "Player -- LVL {}\nEXP {}/{}\nHP {}/{}"\
|
2020-11-06 20:15:09 +00:00
|
|
|
.format(self.player.level, self.player.current_xp,
|
|
|
|
self.player.max_xp, self.player.health,
|
2020-11-07 14:00:24 +00:00
|
|
|
self.player.maxhealth)
|
2020-11-26 11:35:52 +00:00
|
|
|
self.addstr(self.pad, 0, 0, string2)
|
2020-11-20 17:07:09 +00:00
|
|
|
string3 = "STR {}\nINT {}\nCHR {}\nDEX {}\nCON {}"\
|
2020-11-07 14:00:24 +00:00
|
|
|
.format(self.player.strength,
|
2020-11-06 20:15:09 +00:00
|
|
|
self.player.intelligence, self.player.charisma,
|
|
|
|
self.player.dexterity, self.player.constitution)
|
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)
|
2020-11-26 11:35:52 +00:00
|
|
|
self.addstr(self.pad, 8, 0, inventory_str)
|
2020-11-11 22:41:06 +00:00
|
|
|
|
2020-12-09 15:54:53 +00:00
|
|
|
self.addstr(self.pad, 9, 0, f"{self.pack.HAZELNUT} "
|
|
|
|
f"x{self.player.hazel}")
|
|
|
|
|
2020-11-11 00:17:00 +00:00
|
|
|
if self.player.dead:
|
2020-12-09 15:54:53 +00:00
|
|
|
self.addstr(self.pad, 11, 0, _("YOU ARE DEAD"),
|
2020-11-26 11:35:52 +00:00
|
|
|
curses.A_BOLD | curses.A_BLINK | curses.A_STANDOUT
|
|
|
|
| self.color_pair(3))
|
2020-11-06 20:15:09 +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)
|