ui: show basic stats above progress bars

This commit is contained in:
rr-
2018-11-05 22:09:35 +01:00
parent fb727b11c9
commit a54d22fdd2
3 changed files with 37 additions and 42 deletions
+2 -2
View File
@@ -3,13 +3,13 @@ import typing as T
import urwid
class CustomLineBox(urwid.AttrWrap):
class CustomLineBox(urwid.AttrMap):
def __init__(
self, widget: urwid.Widget, *args: T.Any, **kwargs: T.Any
) -> None:
super().__init__(
urwid.LineBox(
urwid.AttrWrap(widget, "linebox-content", "linebox-content"),
urwid.AttrMap(widget, "linebox-content", "linebox-content"),
*args,
**kwargs,
),
+14 -23
View File
@@ -1,9 +1,7 @@
import typing as T
import urwid
class DoubleLineBox(urwid.AttrWrap):
class DoubleLineBox(urwid.AttrMap):
def __init__(
self,
top_widget: urwid.Widget,
@@ -11,31 +9,24 @@ class DoubleLineBox(urwid.AttrWrap):
top_title: str = "",
bottom_title: str = "",
) -> None:
super().__init__(
urwid.Pile(
[
urwid.LineBox(
urwid.AttrWrap(
top_widget, "linebox-content", "linebox-content"
),
self.top_line_box = urwid.LineBox(
urwid.AttrMap(top_widget, "linebox-content", "linebox-content"),
title=top_title,
bline="",
),
(
"pack",
urwid.LineBox(
urwid.AttrWrap(
bottom_widget,
"linebox-content",
"linebox-content",
),
)
self.bottom_line_box = urwid.LineBox(
urwid.AttrMap(bottom_widget, "linebox-content", "linebox-content"),
title=bottom_title,
tlcorner="├",
trcorner="┤",
),
),
]
),
)
super().__init__(
urwid.Pile([self.top_line_box, ("pack", self.bottom_line_box)]),
"linebox",
"linebox-focus",
)
def set_bottom_title(self, text: str) -> None:
self.bottom_line_box.set_title(text)
+17 -13
View File
@@ -50,7 +50,6 @@ class CharacterSheetView(DoubleLineBox):
self.player.connect("level_up", self.sync_level)
self.player.stats.connect("change", self.sync_stats)
self.player.exp_bar.connect("change", self.sync_exp)
self.sync()
super().__init__(
top_widget=self.list_box,
@@ -58,6 +57,7 @@ class CharacterSheetView(DoubleLineBox):
top_title="Character Sheet",
bottom_title="Experience",
)
self.sync()
def sync(self) -> None:
self.sync_level()
@@ -72,8 +72,11 @@ class CharacterSheetView(DoubleLineBox):
self.stat_texts[stat].set_text(str(self.player.stats[stat]))
def sync_exp(self) -> None:
self.exp_bar.set_completion(self.player.exp_bar.position)
self.exp_bar.set_max(self.player.exp_bar.max_)
cur = self.player.exp_bar.position
max_ = self.player.exp_bar.max_
self.exp_bar.set_completion(cur)
self.exp_bar.set_max(max_)
self.set_bottom_title(f"Experience ({max_-cur:.0f} XP to go)")
class SpellBookView(CustomLineBox):
@@ -84,9 +87,9 @@ class SpellBookView(CustomLineBox):
self.player.spell_book.connect("add", self.sync_spell_add)
self.player.spell_book.connect("change", self.sync_spell_change)
self.sync()
super().__init__(self.list_box, title="Spell Book")
self.sync()
def sync(self) -> None:
del self.list_box.body[:]
@@ -129,9 +132,9 @@ class EquipmentView(CustomLineBox):
)
self.player.equipment.connect("change", self.sync_equipment_change)
self.sync()
super().__init__(self.list_box, title="Equipment")
self.sync()
def sync(self) -> None:
for equipment_type in EquipmentType:
@@ -167,7 +170,6 @@ class InventoryView(DoubleLineBox):
self.player.inventory.encum_bar.connect(
"change", self.sync_encumbrance_position
)
self.sync()
super().__init__(
top_widget=self.list_box,
@@ -175,6 +177,7 @@ class InventoryView(DoubleLineBox):
bottom_widget=self.encumbrance_bar,
bottom_title="Encumbrance",
)
self.sync()
def sync(self) -> None:
self.sync_gold()
@@ -190,10 +193,11 @@ class InventoryView(DoubleLineBox):
self.sync_item_add(item)
def sync_encumbrance_position(self) -> None:
self.encumbrance_bar.set_completion(
self.player.inventory.encum_bar.position
)
self.encumbrance_bar.set_max(self.player.inventory.encum_bar.max_)
cur = self.player.inventory.encum_bar.position
max_ = self.player.inventory.encum_bar.max_
self.encumbrance_bar.set_completion(cur)
self.encumbrance_bar.set_max(max_)
self.set_bottom_title(f"Encumbrance ({cur:.0f}/{max_} cubits)")
def sync_item_add(self, item: InventoryItem) -> None:
self.list_box.body.append(
@@ -238,13 +242,13 @@ class PlotView(DoubleLineBox):
self.player.quest_book.connect("complete_act", self.sync_act_add)
self.player.quest_book.plot_bar.connect("change", self.sync_position)
self.sync()
super().__init__(
top_widget=self.list_box,
top_title="Plot Development",
bottom_widget=self.plot_bar,
)
self.sync()
def sync(self) -> None:
self.sync_acts()
@@ -287,13 +291,13 @@ class QuestBookView(DoubleLineBox):
self.player.quest_book.connect("complete_quest", self.sync_quest_add)
self.player.quest_book.quest_bar.connect("change", self.sync_position)
self.sync()
super().__init__(
top_widget=self.list_box,
top_title="Quests",
bottom_widget=self.quest_bar,
)
self.sync()
def sync(self) -> None:
self.sync_quests()
@@ -330,9 +334,9 @@ class TaskView(urwid.Pile):
self.player.connect("new_task", self.sync_task_name)
self.player.task_bar.connect("change", self.sync_position)
self.sync()
super().__init__([self.current_task_text, self.current_task_bar])
self.sync()
def sync(self) -> None:
self.sync_task_name()