ui: make plot development view scrollable

This commit is contained in:
rr-
2018-11-08 20:01:12 +01:00
parent 0b74d1a36e
commit 88a936c293
2 changed files with 18 additions and 19 deletions
+2 -2
View File
@@ -93,7 +93,7 @@ class Stats(SignalMixin):
class QuestBook(SignalMixin): class QuestBook(SignalMixin):
signals = ["complete_act", "start_quest"] signals = ["start_act", "start_quest"]
def __init__(self) -> None: def __init__(self) -> None:
self._quests: T.List[str] = [] self._quests: T.List[str] = []
@@ -118,7 +118,7 @@ class QuestBook(SignalMixin):
def increment_act(self) -> None: def increment_act(self) -> None:
self._act += 1 self._act += 1
self.emit("complete_act") self.emit("start_act", self._act)
def add_quest(self, name: str) -> None: def add_quest(self, name: str) -> None:
logger.info("Commencing quest: %s", name) logger.info("Commencing quest: %s", name)
+16 -17
View File
@@ -216,14 +216,15 @@ class PlotView(DoubleLineBox):
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", 1)])
self.scrollable = Scrollable(self.data_table)
self.plot_bar = CustomProgressBar() self.plot_bar = CustomProgressBar()
self.player.quest_book.connect("complete_act", self.sync_act_add) self.player.quest_book.connect("start_act", self.sync_act_add)
self.player.quest_book.plot_bar.connect("change", self.sync_position) self.player.quest_book.plot_bar.connect("change", self.sync_position)
super().__init__( super().__init__(
top_widget=self.list_box, top_widget=ScrollBar(self.scrollable),
top_title="Plot Development", top_title="Plot Development",
bottom_widget=self.plot_bar, bottom_widget=self.plot_bar,
) )
@@ -234,25 +235,23 @@ class PlotView(DoubleLineBox):
self.sync_position() self.sync_position()
def sync_acts(self) -> None: def sync_acts(self) -> None:
del self.list_box.body[:] self.data_table.delete_rows(0, len(self.data_table.data_rows))
for act_number in range( for act_number in range(
max(0, self.player.quest_book.act - self.cutoff), max(0, self.player.quest_book.act - self.cutoff),
self.player.quest_book.act, self.player.quest_book.act + 1,
): ):
self.list_box.body.append( self.sync_act_add(act_number)
ReadOnlyCheckBox(act_name(act_number), state=True)
)
self.list_box.body.append(
ReadOnlyCheckBox(act_name(self.player.quest_book.act), state=False)
)
def sync_act_add(self) -> None: def sync_act_add(self, act_number: int) -> None:
del self.list_box.body[: -self.cutoff] self.data_table.delete_rows(
if self.list_box.body: 0, max(0, self.data_table.row_count - self.cutoff)
self.list_box.body[-1].set_state(True)
self.list_box.body.append(
ReadOnlyCheckBox(act_name(self.player.quest_book.act), state=False)
) )
if self.data_table.data_rows:
self.data_table.data_rows[-1][0].set_state(True)
self.data_table.add_row(
ReadOnlyCheckBox(act_name(act_number), state=False)
)
self.scrollable.set_scrollpos(self.scrollable.rows_max() - 1)
def sync_position(self) -> None: def sync_position(self) -> None:
self.plot_bar.set_completion(self.player.quest_book.plot_bar.position) self.plot_bar.set_completion(self.player.quest_book.plot_bar.position)