mirror of
https://github.com/rr-/pq-cli.git
synced 2026-09-29 06:44:00 -06:00
ui/curses: improve character choice
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import functools
|
import functools
|
||||||
import typing as T
|
import typing as T
|
||||||
|
|
||||||
|
from pqcli.lingo import act_name, to_roman
|
||||||
from pqcli.roster import Roster
|
from pqcli.roster import Roster
|
||||||
from pqcli.ui.curses.event_handler import EventHandler
|
from pqcli.ui.curses.event_handler import EventHandler
|
||||||
from pqcli.ui.curses.util import Choice
|
from pqcli.ui.curses.util import Choice
|
||||||
@@ -14,10 +15,33 @@ class ChooseCharacterView(MenuView):
|
|||||||
|
|
||||||
for y, player in enumerate(roster.players, 1):
|
for y, player in enumerate(roster.players, 1):
|
||||||
key: T.Optional[str] = str(y % 10) if y <= 10 else None
|
key: T.Optional[str] = str(y % 10) if y <= 10 else None
|
||||||
|
|
||||||
|
best_equip = player.equipment.best
|
||||||
|
|
||||||
|
best_spell = player.spell_book.best
|
||||||
|
best_spell_name = (
|
||||||
|
(best_spell.name + " " + to_roman(best_spell.level))
|
||||||
|
if best_spell
|
||||||
|
else "-"
|
||||||
|
)
|
||||||
|
|
||||||
|
best_stat_name = (
|
||||||
|
f"{player.stats.best_prime.value} "
|
||||||
|
f"{player.stats[player.stats.best_prime]}"
|
||||||
|
)
|
||||||
|
|
||||||
|
label = (
|
||||||
|
f"[{key or '-'}] "
|
||||||
|
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}"
|
||||||
|
)
|
||||||
|
|
||||||
self._choices.append(
|
self._choices.append(
|
||||||
Choice(
|
Choice(
|
||||||
keys=[ord(key)] if key is not None else [],
|
keys=[ord(key)] if key is not None else [],
|
||||||
desc=f"[{key or '-'}] {player.name}",
|
desc=label,
|
||||||
callback=functools.partial(self.on_confirm, player),
|
callback=functools.partial(self.on_confirm, player),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -23,8 +23,12 @@ class Menu(Widget):
|
|||||||
self._scr_width = scr_width
|
self._scr_width = scr_width
|
||||||
self._scr_height = scr_height
|
self._scr_height = scr_height
|
||||||
|
|
||||||
w = max(map(len, self._header_lines))
|
all_lines = self._header_lines + sum(
|
||||||
h = len(self._header_lines) + 1 + len(choices)
|
[choice.desc.splitlines() for choice in choices], []
|
||||||
|
)
|
||||||
|
|
||||||
|
w = max(map(len, all_lines)) + 1
|
||||||
|
h = len(all_lines) + 1
|
||||||
self._pad: T.Optional[T.Any] = curses.newpad(h, w)
|
self._pad: T.Optional[T.Any] = curses.newpad(h, w)
|
||||||
|
|
||||||
for y, line in enumerate(self._header_lines):
|
for y, line in enumerate(self._header_lines):
|
||||||
@@ -72,10 +76,15 @@ class Menu(Widget):
|
|||||||
if not self._pad:
|
if not self._pad:
|
||||||
return
|
return
|
||||||
|
|
||||||
for y, choice in enumerate(self._choices):
|
y = len(self._header_lines) + 1
|
||||||
self._pad.move(len(self._header_lines) + 1 + y, 0)
|
for i, choice in enumerate(self._choices):
|
||||||
with focus_standout(y == self._active_choice, self._pad):
|
self._pad.move(y, 0)
|
||||||
self._pad.addstr(choice.desc)
|
with focus_standout(i == self._active_choice, self._pad):
|
||||||
|
lines = choice.desc.splitlines()
|
||||||
|
max_len = max(map(len, lines))
|
||||||
|
lines = [line.ljust(max_len) for line in lines]
|
||||||
|
self._pad.addstr("\n".join(lines))
|
||||||
|
y += len(choice.desc.splitlines())
|
||||||
|
|
||||||
self._pad.refresh(
|
self._pad.refresh(
|
||||||
0,
|
0,
|
||||||
|
|||||||
Reference in New Issue
Block a user