ui: improve predicted times near zero values

This commit is contained in:
rr-
2018-11-10 17:24:42 +01:00
parent 16ec0cfa5d
commit e7d5947299
2 changed files with 19 additions and 11 deletions
+7
View File
@@ -55,6 +55,13 @@ class CustomProgressBar(urwid.Widget):
self.max_ = value self.max_ = value
self._invalidate() 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: def rows(self, size: T.Tuple[int, int], focus: bool = False) -> int:
return 1 return 1
+12 -11
View File
@@ -67,8 +67,7 @@ class CharacterSheetView(DoubleLineBox):
def sync_exp(self) -> None: def sync_exp(self) -> None:
cur = self.player.exp_bar.position cur = self.player.exp_bar.position
max_ = self.player.exp_bar.max_ max_ = self.player.exp_bar.max_
self.exp_bar.set_completion(cur) self.exp_bar.reset(cur, max_)
self.exp_bar.set_max(max_)
self.set_bottom_title(f"Experience ({max_-cur:.0f} XP to go)") 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: def sync_encumbrance_position(self) -> None:
cur = self.player.inventory.encum_bar.position cur = self.player.inventory.encum_bar.position
max_ = self.player.inventory.encum_bar.max_ max_ = self.player.inventory.encum_bar.max_
self.encumbrance_bar.set_completion(cur) self.encumbrance_bar.reset(cur, max_)
self.encumbrance_bar.set_max(max_)
self.set_bottom_title(f"Encumbrance ({cur:.0f}/{max_} cubits)") self.set_bottom_title(f"Encumbrance ({cur:.0f}/{max_} cubits)")
def sync_item_add(self, item: InventoryItem) -> None: def sync_item_add(self, item: InventoryItem) -> None:
@@ -254,8 +252,10 @@ class PlotView(DoubleLineBox):
self.scrollable.set_scrollpos(self.scrollable.rows_max() - 1) 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.reset(
self.plot_bar.set_max(self.player.quest_book.plot_bar.max_) self.player.quest_book.plot_bar.position,
self.player.quest_book.plot_bar.max_,
)
class QuestBookView(DoubleLineBox): class QuestBookView(DoubleLineBox):
@@ -296,10 +296,10 @@ class QuestBookView(DoubleLineBox):
self.scrollable.set_scrollpos(self.scrollable.rows_max() - 1) self.scrollable.set_scrollpos(self.scrollable.rows_max() - 1)
def sync_position(self) -> None: def sync_position(self) -> None:
self.quest_bar.set_completion( self.quest_bar.reset(
self.player.quest_book.quest_bar.position 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): class TaskView(NPile):
@@ -325,8 +325,9 @@ class TaskView(NPile):
) )
def sync_position(self) -> None: def sync_position(self) -> None:
self.current_task_bar.set_completion(self.player.task_bar.position) self.current_task_bar.reset(
self.current_task_bar.set_max(self.player.task_bar.max_) self.player.task_bar.position, 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)