mirror of
https://github.com/rr-/pq-cli.git
synced 2026-09-29 06:44:00 -06:00
ui/curses: fix arrows not working in game view
This commit is contained in:
@@ -1,6 +1,12 @@
|
|||||||
|
import curses
|
||||||
import typing as T
|
import typing as T
|
||||||
from dataclasses import dataclass
|
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
|
@dataclass
|
||||||
class Choice:
|
class Choice:
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import typing as T
|
|||||||
from pqcli.mechanic import Player, Simulation
|
from pqcli.mechanic import Player, Simulation
|
||||||
from pqcli.roster import Roster
|
from pqcli.roster import Roster
|
||||||
from pqcli.ui.curses.event_handler import EventHandler
|
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 pqcli.ui.curses.widgets import Widget
|
||||||
|
|
||||||
from ..base_view import BaseView
|
from ..base_view import BaseView
|
||||||
@@ -42,7 +43,7 @@ class GameView(BaseView):
|
|||||||
if key in map(ord, "qQ"):
|
if key in map(ord, "qQ"):
|
||||||
self.on_exit()
|
self.on_exit()
|
||||||
|
|
||||||
elif key in map(ord, "jJ"):
|
elif key in KEYS_DOWN:
|
||||||
if focused == self._char_sheet_win:
|
if focused == self._char_sheet_win:
|
||||||
self.focus(self._spell_book_win)
|
self.focus(self._spell_book_win)
|
||||||
elif focused == self._equipment_win:
|
elif focused == self._equipment_win:
|
||||||
@@ -50,7 +51,7 @@ class GameView(BaseView):
|
|||||||
elif focused == self._plot_win:
|
elif focused == self._plot_win:
|
||||||
self.focus(self._quest_book_win)
|
self.focus(self._quest_book_win)
|
||||||
|
|
||||||
elif key in map(ord, "kK"):
|
elif key in KEYS_UP:
|
||||||
if focused == self._spell_book_win:
|
if focused == self._spell_book_win:
|
||||||
self.focus(self._char_sheet_win)
|
self.focus(self._char_sheet_win)
|
||||||
elif focused == self._inventory_win:
|
elif focused == self._inventory_win:
|
||||||
@@ -58,7 +59,7 @@ class GameView(BaseView):
|
|||||||
elif focused == self._quest_book_win:
|
elif focused == self._quest_book_win:
|
||||||
self.focus(self._plot_win)
|
self.focus(self._plot_win)
|
||||||
|
|
||||||
elif key in map(ord, "hH"):
|
elif key in KEYS_LEFT:
|
||||||
if focused == self._equipment_win:
|
if focused == self._equipment_win:
|
||||||
self.focus(self._char_sheet_win)
|
self.focus(self._char_sheet_win)
|
||||||
elif focused == self._inventory_win:
|
elif focused == self._inventory_win:
|
||||||
@@ -68,7 +69,7 @@ class GameView(BaseView):
|
|||||||
elif focused == self._quest_book_win:
|
elif focused == self._quest_book_win:
|
||||||
self.focus(self._inventory_win)
|
self.focus(self._inventory_win)
|
||||||
|
|
||||||
elif key in map(ord, "lL"):
|
elif key in KEYS_RIGHT:
|
||||||
if focused == self._char_sheet_win:
|
if focused == self._char_sheet_win:
|
||||||
self.focus(self._equipment_win)
|
self.focus(self._equipment_win)
|
||||||
elif focused == self._spell_book_win:
|
elif focused == self._spell_book_win:
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
import curses
|
import curses
|
||||||
import typing as T
|
import typing as T
|
||||||
|
|
||||||
|
from pqcli.ui.curses.util import KEYS_DOWN, KEYS_UP
|
||||||
|
|
||||||
from ..util import Choice
|
from ..util import Choice
|
||||||
from .base import Widget
|
from .base import Widget
|
||||||
|
|
||||||
@@ -49,11 +51,11 @@ class Menu(Widget):
|
|||||||
choice.callback()
|
choice.callback()
|
||||||
return
|
return
|
||||||
|
|
||||||
if key in set(map(ord, "jJ")) | {curses.KEY_DOWN}:
|
if key in KEYS_DOWN:
|
||||||
self.next()
|
self.next()
|
||||||
return
|
return
|
||||||
|
|
||||||
if key in set(map(ord, "kK")) | {curses.KEY_UP}:
|
if key in KEYS_UP:
|
||||||
self.prev()
|
self.prev()
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user