mirror of
https://github.com/rr-/pq-cli.git
synced 2026-09-28 22:33:59 -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:
|
def __getitem__(self, stat: StatType) -> int:
|
||||||
return self._values[stat]
|
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:
|
def increment(self, stat: StatType, qty: int = 1) -> None:
|
||||||
self._values[stat] += qty
|
self._values[stat] += qty
|
||||||
logger.info("Increased %s to %d", stat.value, self[stat])
|
logger.info("Increased %s to %d", stat.value, self[stat])
|
||||||
@@ -193,6 +197,7 @@ class Equipment(SignalMixin):
|
|||||||
EquipmentType.weapon: "Sharp Rock",
|
EquipmentType.weapon: "Sharp Rock",
|
||||||
EquipmentType.hauberk: "-3 Burlap",
|
EquipmentType.hauberk: "-3 Burlap",
|
||||||
}
|
}
|
||||||
|
self.best = self[EquipmentType.weapon]
|
||||||
|
|
||||||
def __iter__(self) -> T.Iterator[T.Tuple[EquipmentType, str]]:
|
def __iter__(self) -> T.Iterator[T.Tuple[EquipmentType, str]]:
|
||||||
return iter(self._items.items())
|
return iter(self._items.items())
|
||||||
@@ -203,6 +208,12 @@ class Equipment(SignalMixin):
|
|||||||
def put(self, equipment_type: EquipmentType, item_name: str) -> None:
|
def put(self, equipment_type: EquipmentType, item_name: str) -> None:
|
||||||
self._items[equipment_type] = item_name
|
self._items[equipment_type] = item_name
|
||||||
self.emit("change", 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
|
@dataclass
|
||||||
@@ -233,6 +244,12 @@ class SpellBook(SignalMixin):
|
|||||||
logger.info("Learned %s at level %d", spell.name, spell.level)
|
logger.info("Learned %s at level %d", spell.name, spell.level)
|
||||||
self.emit("add", spell)
|
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
|
@dataclass
|
||||||
class BaseTask:
|
class BaseTask:
|
||||||
|
|||||||
+24
-1
@@ -2,6 +2,7 @@ import typing as T
|
|||||||
|
|
||||||
import urwid
|
import urwid
|
||||||
|
|
||||||
|
from pqcli.lingo import act_name, to_roman
|
||||||
from pqcli.roster import Roster
|
from pqcli.roster import Roster
|
||||||
from pqcli.ui.custom_button import CustomButton
|
from pqcli.ui.custom_button import CustomButton
|
||||||
|
|
||||||
@@ -16,11 +17,32 @@ class RosterView(urwid.Filler):
|
|||||||
|
|
||||||
buttons = []
|
buttons = []
|
||||||
for player_idx, player in enumerate(self.roster.players):
|
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(
|
buttons.append(
|
||||||
urwid.Columns(
|
urwid.Columns(
|
||||||
[
|
[
|
||||||
CustomButton(
|
CustomButton(
|
||||||
label=player.name,
|
label=label,
|
||||||
on_press=self.on_resume_game_press,
|
on_press=self.on_resume_game_press,
|
||||||
user_data=player_idx,
|
user_data=player_idx,
|
||||||
),
|
),
|
||||||
@@ -35,6 +57,7 @@ class RosterView(urwid.Filler):
|
|||||||
]
|
]
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
buttons.append(urwid.Divider())
|
||||||
|
|
||||||
buttons.append(
|
buttons.append(
|
||||||
CustomButton(
|
CustomButton(
|
||||||
|
|||||||
Reference in New Issue
Block a user