mirror of
https://github.com/rr-/pq-cli.git
synced 2026-09-29 06:44:00 -06:00
ui: add universal sync() method
This commit is contained in:
+32
-20
@@ -38,11 +38,14 @@ class CharacterSheetView(CustomLineBox):
|
|||||||
|
|
||||||
self.player.connect("level_up", self.sync_level)
|
self.player.connect("level_up", self.sync_level)
|
||||||
self.player.stats.connect("change", self.sync_stats)
|
self.player.stats.connect("change", self.sync_stats)
|
||||||
self.sync_level()
|
self.sync()
|
||||||
self.sync_stats()
|
|
||||||
|
|
||||||
super().__init__(self.list_box, title="Character Sheet")
|
super().__init__(self.list_box, title="Character Sheet")
|
||||||
|
|
||||||
|
def sync(self) -> None:
|
||||||
|
self.sync_level()
|
||||||
|
self.sync_stats()
|
||||||
|
|
||||||
def sync_level(self) -> None:
|
def sync_level(self) -> None:
|
||||||
self.level_text.set_text(str(self.player.level))
|
self.level_text.set_text(str(self.player.level))
|
||||||
|
|
||||||
@@ -57,12 +60,12 @@ class ExperienceView(urwid.Pile):
|
|||||||
|
|
||||||
self.exp_bar = CustomProgressBar()
|
self.exp_bar = CustomProgressBar()
|
||||||
|
|
||||||
self.player.exp_bar.connect("change", self.sync_position)
|
self.player.exp_bar.connect("change", self.sync)
|
||||||
self.sync_position()
|
self.sync()
|
||||||
|
|
||||||
super().__init__([urwid.Text("Experience"), self.exp_bar])
|
super().__init__([urwid.Text("Experience"), self.exp_bar])
|
||||||
|
|
||||||
def sync_position(self) -> None:
|
def sync(self) -> None:
|
||||||
self.exp_bar.set_completion(self.player.exp_bar.position)
|
self.exp_bar.set_completion(self.player.exp_bar.position)
|
||||||
self.exp_bar.set_max(self.player.exp_bar.max_)
|
self.exp_bar.set_max(self.player.exp_bar.max_)
|
||||||
|
|
||||||
@@ -78,11 +81,11 @@ class SpellBookView(CustomLineBox):
|
|||||||
|
|
||||||
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)
|
||||||
self.sync_spells()
|
self.sync()
|
||||||
|
|
||||||
super().__init__(self.list_box, title="Spell Book")
|
super().__init__(self.list_box, title="Spell Book")
|
||||||
|
|
||||||
def sync_spells(self) -> None:
|
def sync(self) -> None:
|
||||||
del self.list_box.body[:]
|
del self.list_box.body[:]
|
||||||
for spell in self.player.spell_book:
|
for spell in self.player.spell_book:
|
||||||
self.sync_spell_add(spell)
|
self.sync_spell_add(spell)
|
||||||
@@ -120,11 +123,11 @@ class EquipmentView(CustomLineBox):
|
|||||||
)
|
)
|
||||||
|
|
||||||
self.player.equipment.connect("change", self.sync_equipment_change)
|
self.player.equipment.connect("change", self.sync_equipment_change)
|
||||||
self.sync_equipment()
|
self.sync()
|
||||||
|
|
||||||
super().__init__(self.list_box, title="Equipment")
|
super().__init__(self.list_box, title="Equipment")
|
||||||
|
|
||||||
def sync_equipment(self) -> None:
|
def sync(self) -> None:
|
||||||
for equipment_type in EquipmentType:
|
for equipment_type in EquipmentType:
|
||||||
self.sync_equipment_change(
|
self.sync_equipment_change(
|
||||||
equipment_type, self.player.equipment[equipment_type]
|
equipment_type, self.player.equipment[equipment_type]
|
||||||
@@ -153,9 +156,7 @@ class InventoryView(urwid.Pile):
|
|||||||
self.player.inventory.encum_bar.connect(
|
self.player.inventory.encum_bar.connect(
|
||||||
"change", self.sync_encumbrance_position
|
"change", self.sync_encumbrance_position
|
||||||
)
|
)
|
||||||
self.sync_gold()
|
self.sync()
|
||||||
self.sync_items()
|
|
||||||
self.sync_encumbrance_position()
|
|
||||||
|
|
||||||
super().__init__(
|
super().__init__(
|
||||||
[
|
[
|
||||||
@@ -165,6 +166,11 @@ class InventoryView(urwid.Pile):
|
|||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def sync(self) -> None:
|
||||||
|
self.sync_gold()
|
||||||
|
self.sync_items()
|
||||||
|
self.sync_encumbrance_position()
|
||||||
|
|
||||||
def sync_gold(self) -> None:
|
def sync_gold(self) -> None:
|
||||||
self.gold_text.set_text(str(self.player.inventory.gold))
|
self.gold_text.set_text(str(self.player.inventory.gold))
|
||||||
|
|
||||||
@@ -214,8 +220,7 @@ class PlotView(urwid.Pile):
|
|||||||
|
|
||||||
self.player.connect("complete_act", self.sync_act_add)
|
self.player.connect("complete_act", self.sync_act_add)
|
||||||
self.player.plot_bar.connect("change", self.sync_position)
|
self.player.plot_bar.connect("change", self.sync_position)
|
||||||
self.sync_acts()
|
self.sync()
|
||||||
self.sync_position()
|
|
||||||
|
|
||||||
super().__init__(
|
super().__init__(
|
||||||
[
|
[
|
||||||
@@ -224,6 +229,10 @@ class PlotView(urwid.Pile):
|
|||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def sync(self) -> None:
|
||||||
|
self.sync_acts()
|
||||||
|
self.sync_position()
|
||||||
|
|
||||||
def sync_acts(self) -> None:
|
def sync_acts(self) -> None:
|
||||||
del self.list_box.body[:]
|
del self.list_box.body[:]
|
||||||
for act_number in range(
|
for act_number in range(
|
||||||
@@ -257,22 +266,25 @@ class TaskView(urwid.Pile):
|
|||||||
self.current_task_text = urwid.Text("...")
|
self.current_task_text = urwid.Text("...")
|
||||||
self.current_task_bar = CustomProgressBar()
|
self.current_task_bar = CustomProgressBar()
|
||||||
|
|
||||||
self.player.task_bar.connect("change", self.sync_position)
|
|
||||||
self.player.connect("new_task", self.sync_task_name)
|
self.player.connect("new_task", self.sync_task_name)
|
||||||
self.sync_position()
|
self.player.task_bar.connect("change", self.sync_position)
|
||||||
self.sync_task_name()
|
self.sync()
|
||||||
|
|
||||||
super().__init__([self.current_task_text, self.current_task_bar])
|
super().__init__([self.current_task_text, self.current_task_bar])
|
||||||
|
|
||||||
def sync_position(self) -> None:
|
def sync(self) -> None:
|
||||||
self.current_task_bar.set_completion(self.player.task_bar.position)
|
self.sync_task_name()
|
||||||
self.current_task_bar.set_max(self.player.task_bar.max_)
|
self.sync_position()
|
||||||
|
|
||||||
def sync_task_name(self) -> None:
|
def sync_task_name(self) -> None:
|
||||||
self.current_task_text.set_text(
|
self.current_task_text.set_text(
|
||||||
f"{self.player.task.description}..." if self.player.task else "?"
|
f"{self.player.task.description}..." if self.player.task else "?"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def sync_position(self) -> None:
|
||||||
|
self.current_task_bar.set_completion(self.player.task_bar.position)
|
||||||
|
self.current_task_bar.set_max(self.player.task_bar.max_)
|
||||||
|
|
||||||
def pack(self, size: T.Tuple[int, int]) -> T.Tuple[int, int]:
|
def pack(self, size: T.Tuple[int, int]) -> T.Tuple[int, int]:
|
||||||
return (size[0], 2)
|
return (size[0], 2)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user