From e7d5947299e4388264d8eaa758a137d79e664b66 Mon Sep 17 00:00:00 2001 From: rr- Date: Sat, 10 Nov 2018 11:27:28 +0100 Subject: [PATCH] ui: improve predicted times near zero values --- pqcli/ui/custom_progress_bar.py | 7 +++++++ pqcli/ui/game_view.py | 23 ++++++++++++----------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/pqcli/ui/custom_progress_bar.py b/pqcli/ui/custom_progress_bar.py index 6f9cc02..d903b03 100644 --- a/pqcli/ui/custom_progress_bar.py +++ b/pqcli/ui/custom_progress_bar.py @@ -55,6 +55,13 @@ class CustomProgressBar(urwid.Widget): self.max_ = value self._invalidate() + def reset(self, cur: float, max_: T.Union[int, float]) -> None: + if self.last_tick is None or cur == 0 or max_ != self.max_: + self.last_tick = (datetime.datetime.now(), cur) + self.position = cur + self.max_ = max_ + self._invalidate() + def rows(self, size: T.Tuple[int, int], focus: bool = False) -> int: return 1 diff --git a/pqcli/ui/game_view.py b/pqcli/ui/game_view.py index b5c5882..0e22152 100644 --- a/pqcli/ui/game_view.py +++ b/pqcli/ui/game_view.py @@ -67,8 +67,7 @@ class CharacterSheetView(DoubleLineBox): def sync_exp(self) -> None: 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.exp_bar.reset(cur, max_) self.set_bottom_title(f"Experience ({max_-cur:.0f} XP to go)") @@ -177,8 +176,7 @@ class InventoryView(DoubleLineBox): def sync_encumbrance_position(self) -> None: 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.encumbrance_bar.reset(cur, max_) self.set_bottom_title(f"Encumbrance ({cur:.0f}/{max_} cubits)") def sync_item_add(self, item: InventoryItem) -> None: @@ -254,8 +252,10 @@ class PlotView(DoubleLineBox): self.scrollable.set_scrollpos(self.scrollable.rows_max() - 1) def sync_position(self) -> None: - self.plot_bar.set_completion(self.player.quest_book.plot_bar.position) - self.plot_bar.set_max(self.player.quest_book.plot_bar.max_) + self.plot_bar.reset( + self.player.quest_book.plot_bar.position, + self.player.quest_book.plot_bar.max_, + ) class QuestBookView(DoubleLineBox): @@ -296,10 +296,10 @@ class QuestBookView(DoubleLineBox): self.scrollable.set_scrollpos(self.scrollable.rows_max() - 1) def sync_position(self) -> None: - self.quest_bar.set_completion( - self.player.quest_book.quest_bar.position + self.quest_bar.reset( + self.player.quest_book.quest_bar.position, + self.player.quest_book.quest_bar.max_, ) - self.quest_bar.set_max(self.player.quest_book.quest_bar.max_) class TaskView(NPile): @@ -325,8 +325,9 @@ class TaskView(NPile): ) 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_) + self.current_task_bar.reset( + self.player.task_bar.position, self.player.task_bar.max_ + ) def pack(self, size: T.Tuple[int, int]) -> T.Tuple[int, int]: return (size[0], 2)