mirror of
https://github.com/rr-/pq-cli.git
synced 2026-09-29 06:44:00 -06:00
ui: show more character info in the roster view
This commit is contained in:
@@ -82,6 +82,10 @@ class Stats(SignalMixin):
|
||||
def __getitem__(self, stat: StatType) -> int:
|
||||
return self._values[stat]
|
||||
|
||||
@property
|
||||
def best(self) -> StatType:
|
||||
return max(self, key=lambda kv: kv[1])[0]
|
||||
|
||||
def increment(self, stat: StatType, qty: int = 1) -> None:
|
||||
self._values[stat] += qty
|
||||
logger.info("Increased %s to %d", stat.value, self[stat])
|
||||
@@ -193,6 +197,7 @@ class Equipment(SignalMixin):
|
||||
EquipmentType.weapon: "Sharp Rock",
|
||||
EquipmentType.hauberk: "-3 Burlap",
|
||||
}
|
||||
self.best = self[EquipmentType.weapon]
|
||||
|
||||
def __iter__(self) -> T.Iterator[T.Tuple[EquipmentType, str]]:
|
||||
return iter(self._items.items())
|
||||
@@ -203,6 +208,12 @@ class Equipment(SignalMixin):
|
||||
def put(self, equipment_type: EquipmentType, item_name: str) -> None:
|
||||
self._items[equipment_type] = item_name
|
||||
self.emit("change", equipment_type, item_name)
|
||||
self.best = item_name + (
|
||||
" " + equipment_type.value
|
||||
if equipment_type
|
||||
not in {EquipmentType.weapon, EquipmentType.shield}
|
||||
else ""
|
||||
)
|
||||
|
||||
|
||||
@dataclass
|
||||
@@ -233,6 +244,12 @@ class SpellBook(SignalMixin):
|
||||
logger.info("Learned %s at level %d", spell.name, spell.level)
|
||||
self.emit("add", spell)
|
||||
|
||||
@property
|
||||
def best(self) -> T.Optional[Spell]:
|
||||
if not self._spells:
|
||||
return None
|
||||
return max(self._spells, key=lambda spell: spell.level)
|
||||
|
||||
|
||||
@dataclass
|
||||
class BaseTask:
|
||||
|
||||
+24
-1
@@ -2,6 +2,7 @@ import typing as T
|
||||
|
||||
import urwid
|
||||
|
||||
from pqcli.lingo import act_name, to_roman
|
||||
from pqcli.roster import Roster
|
||||
from pqcli.ui.custom_button import CustomButton
|
||||
|
||||
@@ -16,11 +17,32 @@ class RosterView(urwid.Filler):
|
||||
|
||||
buttons = []
|
||||
for player_idx, player in enumerate(self.roster.players):
|
||||
best_equip = player.equipment.best
|
||||
|
||||
best_spell = player.spell_book.best
|
||||
if best_spell:
|
||||
best_spell_name = (
|
||||
best_spell.name + " " + to_roman(best_spell.level)
|
||||
)
|
||||
else:
|
||||
best_spell_name = "-"
|
||||
|
||||
best_stat_name = (
|
||||
f"{player.stats.best.value} {player.stats[player.stats.best]}"
|
||||
)
|
||||
|
||||
label = (
|
||||
f"{player.name} the {player.race.name} "
|
||||
f"({act_name(player.quest_book.act)})\n"
|
||||
f"Level {player.level} {player.class_.name}\n"
|
||||
f"{best_equip} / {best_spell_name} / {best_stat_name}"
|
||||
)
|
||||
|
||||
buttons.append(
|
||||
urwid.Columns(
|
||||
[
|
||||
CustomButton(
|
||||
label=player.name,
|
||||
label=label,
|
||||
on_press=self.on_resume_game_press,
|
||||
user_data=player_idx,
|
||||
),
|
||||
@@ -35,6 +57,7 @@ class RosterView(urwid.Filler):
|
||||
]
|
||||
)
|
||||
)
|
||||
buttons.append(urwid.Divider())
|
||||
|
||||
buttons.append(
|
||||
CustomButton(
|
||||
|
||||
Reference in New Issue
Block a user