mirror of
https://github.com/rr-/pq-cli.git
synced 2026-09-29 06:44:00 -06:00
ui: make spell book scrollable
This commit is contained in:
+12
-13
@@ -76,33 +76,32 @@ class SpellBookView(CustomLineBox):
|
|||||||
def __init__(self, player: Player) -> None:
|
def __init__(self, player: Player) -> None:
|
||||||
self.player = player
|
self.player = player
|
||||||
|
|
||||||
self.list_box = CustomListBox([])
|
self.data_table = DataTable(columns=[("weight", 3), ("pack",)])
|
||||||
|
self.scrollable = Scrollable(self.data_table)
|
||||||
|
|
||||||
self.player.spell_book.connect("add", self.sync_spell_add)
|
self.player.spell_book.connect("add", self.sync_spell_add)
|
||||||
self.player.spell_book.connect("change", self.sync_spell_change)
|
self.player.spell_book.connect("change", self.sync_spell_change)
|
||||||
|
|
||||||
super().__init__(self.list_box, title="Spell Book")
|
super().__init__(
|
||||||
|
ScrollBar(self.scrollable, padding=1), title="Spell Book"
|
||||||
|
)
|
||||||
self.sync()
|
self.sync()
|
||||||
|
|
||||||
def sync(self) -> None:
|
def sync(self) -> None:
|
||||||
del self.list_box.body[:]
|
self.data_table.delete_rows(0, len(self.data_table.data_rows))
|
||||||
for spell in self.player.spell_book:
|
for spell in self.player.spell_book:
|
||||||
self.sync_spell_add(spell)
|
self.sync_spell_add(spell)
|
||||||
|
|
||||||
def sync_spell_add(self, spell: Spell) -> None:
|
def sync_spell_add(self, spell: Spell) -> None:
|
||||||
self.list_box.body.append(
|
self.data_table.add_row(
|
||||||
urwid.Columns(
|
urwid.Text(spell.name), urwid.Text(to_roman(spell.level))
|
||||||
[
|
|
||||||
("weight", 3, urwid.Text(spell.name)),
|
|
||||||
urwid.Text(to_roman(spell.level)),
|
|
||||||
]
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
self.scrollable.set_scrollpos(len(self.data_table.data_rows) - 1)
|
||||||
|
|
||||||
def sync_spell_change(self, spell: Spell) -> None:
|
def sync_spell_change(self, spell: Spell) -> None:
|
||||||
for widget in self.list_box.body:
|
for row_widgets in self.data_table.data_rows:
|
||||||
if widget.contents[0][0].text == spell.name:
|
if row_widgets[0].text == spell.name:
|
||||||
widget.contents[1][0].set_text(to_roman(spell.level))
|
row_widgets[1].set_text(to_roman(spell.level))
|
||||||
|
|
||||||
|
|
||||||
class EquipmentView(CustomLineBox):
|
class EquipmentView(CustomLineBox):
|
||||||
|
|||||||
Reference in New Issue
Block a user