ui/curses: fix arrows not working in game view

This commit is contained in:
rr-
2019-01-04 16:25:58 +01:00
parent 5bdfc2ed25
commit b20c4b4b34
3 changed files with 15 additions and 6 deletions
+6
View File
@@ -1,6 +1,12 @@
import curses
import typing as T
from dataclasses import dataclass
KEYS_DOWN = set(map(ord, "jJ")) | {curses.KEY_DOWN}
KEYS_LEFT = set(map(ord, "hH")) | {curses.KEY_LEFT}
KEYS_RIGHT = set(map(ord, "lL")) | {curses.KEY_RIGHT}
KEYS_UP = set(map(ord, "kK")) | {curses.KEY_UP}
@dataclass
class Choice:
+5 -4
View File
@@ -6,6 +6,7 @@ import typing as T
from pqcli.mechanic import Player, Simulation
from pqcli.roster import Roster
from pqcli.ui.curses.event_handler import EventHandler
from pqcli.ui.curses.util import KEYS_DOWN, KEYS_LEFT, KEYS_RIGHT, KEYS_UP
from pqcli.ui.curses.widgets import Widget
from ..base_view import BaseView
@@ -42,7 +43,7 @@ class GameView(BaseView):
if key in map(ord, "qQ"):
self.on_exit()
elif key in map(ord, "jJ"):
elif key in KEYS_DOWN:
if focused == self._char_sheet_win:
self.focus(self._spell_book_win)
elif focused == self._equipment_win:
@@ -50,7 +51,7 @@ class GameView(BaseView):
elif focused == self._plot_win:
self.focus(self._quest_book_win)
elif key in map(ord, "kK"):
elif key in KEYS_UP:
if focused == self._spell_book_win:
self.focus(self._char_sheet_win)
elif focused == self._inventory_win:
@@ -58,7 +59,7 @@ class GameView(BaseView):
elif focused == self._quest_book_win:
self.focus(self._plot_win)
elif key in map(ord, "hH"):
elif key in KEYS_LEFT:
if focused == self._equipment_win:
self.focus(self._char_sheet_win)
elif focused == self._inventory_win:
@@ -68,7 +69,7 @@ class GameView(BaseView):
elif focused == self._quest_book_win:
self.focus(self._inventory_win)
elif key in map(ord, "lL"):
elif key in KEYS_RIGHT:
if focused == self._char_sheet_win:
self.focus(self._equipment_win)
elif focused == self._spell_book_win:
+4 -2
View File
@@ -1,6 +1,8 @@
import curses
import typing as T
from pqcli.ui.curses.util import KEYS_DOWN, KEYS_UP
from ..util import Choice
from .base import Widget
@@ -49,11 +51,11 @@ class Menu(Widget):
choice.callback()
return
if key in set(map(ord, "jJ")) | {curses.KEY_DOWN}:
if key in KEYS_DOWN:
self.next()
return
if key in set(map(ord, "kK")) | {curses.KEY_UP}:
if key in KEYS_UP:
self.prev()
return