ui: fix arrow navigation

This commit is contained in:
rr-
2018-11-08 21:41:20 +01:00
parent 3b19191120
commit 904951acf4
2 changed files with 44 additions and 43 deletions
+27 -22
View File
@@ -351,43 +351,32 @@ class GameView(urwid.Pile):
self.quest_book_view = QuestBookView(player) self.quest_book_view = QuestBookView(player)
self.task_view = TaskView(player) self.task_view = TaskView(player)
super().__init__( self.columns = urwid.Columns(
[
urwid.Columns(
[ [
( (
urwid.WEIGHT, urwid.WEIGHT,
1, 1,
urwid.Pile( urwid.Pile(
[ [(19, self.character_sheet_view), self.spell_book_view]
(19, self.character_sheet_view),
self.spell_book_view,
]
), ),
), ),
( (
urwid.WEIGHT, urwid.WEIGHT,
2, 2,
urwid.Pile( urwid.Pile(
[ [(15, self.equipment_view), self.inventory_view]
(15, self.equipment_view),
self.inventory_view,
]
), ),
), ),
( (
urwid.WEIGHT, urwid.WEIGHT,
2, 2,
urwid.Pile( urwid.Pile([(15, self.plot_view), self.quest_book_view]),
[(15, self.plot_view), self.quest_book_view]
), ),
),
]
),
(urwid.PACK, self.task_view),
] ]
) )
super().__init__([self.columns, (urwid.PACK, self.task_view)])
def cancel(self) -> None: def cancel(self) -> None:
self._emit("cancel") self._emit("cancel")
@@ -397,15 +386,31 @@ class GameView(urwid.Pile):
self.simulation.tick(elapsed * 1000) self.simulation.tick(elapsed * 1000)
self.last_tick = datetime.datetime.now() self.last_tick = datetime.datetime.now()
def unhandled_input(self, key: str) -> bool: def keypress(self, size: T.Tuple[int, int], key: str) -> bool:
if key == "esc": if key == "esc":
self.cancel() self.cancel()
return True return None
if self._command_map[key] == urwid.CURSOR_RIGHT:
old_focus_position = self.columns.focus.focus_position
self.columns.focus_position = (
self.columns.focus_position + 1
) % len(self.columns.contents)
self.columns.focus.focus_position = old_focus_position
return None
if self._command_map[key] == urwid.CURSOR_LEFT:
old_focus_position = self.columns.focus.focus_position
self.columns.focus_position = (
self.columns.focus_position - 1
) % len(self.columns.contents)
self.columns.focus.focus_position = old_focus_position
return None
if self.args.cheats: if self.args.cheats:
if key == "e": if key == "e":
self.simulation.player.exp_bar.increment(1) self.simulation.player.exp_bar.increment(1)
return True return None
fast_forward = {"t": 1, "T": 100, "ctrl t": 10000} fast_forward = {"t": 1, "T": 100, "ctrl t": 10000}
if key in fast_forward: if key in fast_forward:
@@ -420,9 +425,9 @@ class GameView(urwid.Pile):
for _ in range(iterations): for _ in range(iterations):
self.simulation.tick() self.simulation.tick()
return True return None
return False return super().keypress(size, key)
@contextlib.contextmanager @contextlib.contextmanager
def suppress_updates(self) -> T.Generator: def suppress_updates(self) -> T.Generator:
+2 -6
View File
@@ -14,6 +14,7 @@
# - reformatted the code # - reformatted the code
# - added AttrMap wrapping # - added AttrMap wrapping
# - added padding support # - added padding support
# - removed up/down arrow navigation (for widget navigation)
import typing as T import typing as T
@@ -187,12 +188,7 @@ class _Scrollable(urwid.WidgetDecoration):
# Handle up/down, page up/down, etc # Handle up/down, page up/down, etc
command_map = self._command_map command_map = self._command_map
if command_map[key] == urwid.CURSOR_UP: if command_map[key] == urwid.CURSOR_PAGE_UP:
self._scroll_action = SCROLL_LINE_UP
elif command_map[key] == urwid.CURSOR_DOWN:
self._scroll_action = SCROLL_LINE_DOWN
elif command_map[key] == urwid.CURSOR_PAGE_UP:
self._scroll_action = SCROLL_PAGE_UP self._scroll_action = SCROLL_PAGE_UP
elif command_map[key] == urwid.CURSOR_PAGE_DOWN: elif command_map[key] == urwid.CURSOR_PAGE_DOWN:
self._scroll_action = SCROLL_PAGE_DOWN self._scroll_action = SCROLL_PAGE_DOWN