mirror of
https://github.com/rr-/pq-cli.git
synced 2026-09-29 06:44:00 -06:00
ui/curses: cycle widgets on tab
This commit is contained in:
@@ -3,6 +3,7 @@ import curses.ascii
|
|||||||
import typing as T
|
import typing as T
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
|
|
||||||
|
KEYS_CYCLE = {curses.ascii.TAB}
|
||||||
KEYS_DOWN = set(map(ord, "jJ")) | {curses.KEY_DOWN}
|
KEYS_DOWN = set(map(ord, "jJ")) | {curses.KEY_DOWN}
|
||||||
KEYS_LEFT = set(map(ord, "hH")) | {curses.KEY_LEFT}
|
KEYS_LEFT = set(map(ord, "hH")) | {curses.KEY_LEFT}
|
||||||
KEYS_RIGHT = set(map(ord, "lL")) | {curses.KEY_RIGHT}
|
KEYS_RIGHT = set(map(ord, "lL")) | {curses.KEY_RIGHT}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import typing as T
|
|||||||
|
|
||||||
from pqcli.mechanic import generate_name
|
from pqcli.mechanic import generate_name
|
||||||
from pqcli.ui.curses.event_handler import EventHandler
|
from pqcli.ui.curses.event_handler import EventHandler
|
||||||
from pqcli.ui.curses.util import KEYS_CANCEL, KEYS_DOWN, KEYS_UP
|
from pqcli.ui.curses.util import KEYS_CANCEL, KEYS_CYCLE, KEYS_DOWN, KEYS_UP
|
||||||
from pqcli.ui.curses.views.base_view import BaseView
|
from pqcli.ui.curses.views.base_view import BaseView
|
||||||
from pqcli.ui.curses.widgets.focusable import focus_standout
|
from pqcli.ui.curses.widgets.focusable import focus_standout
|
||||||
|
|
||||||
@@ -51,6 +51,9 @@ class ChooseCharacterNameView(BaseView):
|
|||||||
elif key == curses.KEY_F10:
|
elif key == curses.KEY_F10:
|
||||||
self._finish()
|
self._finish()
|
||||||
|
|
||||||
|
elif key in KEYS_CYCLE:
|
||||||
|
self._active_widget = (self._active_widget + 1) % 4
|
||||||
|
|
||||||
elif self._active_widget == 0:
|
elif self._active_widget == 0:
|
||||||
if key == curses.ascii.ESC:
|
if key == curses.ascii.ESC:
|
||||||
self.on_cancel()
|
self.on_cancel()
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import typing as T
|
|||||||
from pqcli.config import PRIME_STATS
|
from pqcli.config import PRIME_STATS
|
||||||
from pqcli.mechanic import StatsBuilder
|
from pqcli.mechanic import StatsBuilder
|
||||||
from pqcli.ui.curses.event_handler import EventHandler
|
from pqcli.ui.curses.event_handler import EventHandler
|
||||||
from pqcli.ui.curses.util import KEYS_CANCEL, KEYS_DOWN, KEYS_UP
|
from pqcli.ui.curses.util import KEYS_CANCEL, KEYS_CYCLE, KEYS_DOWN, KEYS_UP
|
||||||
from pqcli.ui.curses.views.base_view import BaseView
|
from pqcli.ui.curses.views.base_view import BaseView
|
||||||
from pqcli.ui.curses.widgets.focusable import focus_standout
|
from pqcli.ui.curses.widgets.focusable import focus_standout
|
||||||
|
|
||||||
@@ -70,6 +70,9 @@ class ChooseCharacterStatsView(BaseView):
|
|||||||
elif key == curses.KEY_F10:
|
elif key == curses.KEY_F10:
|
||||||
self.on_confirm(self._stats)
|
self.on_confirm(self._stats)
|
||||||
|
|
||||||
|
elif key in KEYS_CYCLE:
|
||||||
|
self._active_widget = (self._active_widget + 1) % 4
|
||||||
|
|
||||||
elif key in KEYS_DOWN and self._active_widget < 3:
|
elif key in KEYS_DOWN and self._active_widget < 3:
|
||||||
self._active_widget += 1
|
self._active_widget += 1
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ 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 (
|
from pqcli.ui.curses.util import (
|
||||||
KEYS_CANCEL,
|
KEYS_CANCEL,
|
||||||
|
KEYS_CYCLE,
|
||||||
KEYS_DOWN,
|
KEYS_DOWN,
|
||||||
KEYS_LEFT,
|
KEYS_LEFT,
|
||||||
KEYS_RIGHT,
|
KEYS_RIGHT,
|
||||||
@@ -57,6 +58,20 @@ class GameView(BaseView):
|
|||||||
if hasattr(focused, "scroll_page_down"):
|
if hasattr(focused, "scroll_page_down"):
|
||||||
focused.scroll_page_down()
|
focused.scroll_page_down()
|
||||||
|
|
||||||
|
elif key in KEYS_CYCLE:
|
||||||
|
if focused == self._char_sheet_win:
|
||||||
|
self.focus(self._spell_book_win)
|
||||||
|
elif focused == self._spell_book_win:
|
||||||
|
self.focus(self._equipment_win)
|
||||||
|
elif focused == self._equipment_win:
|
||||||
|
self.focus(self._inventory_win)
|
||||||
|
elif focused == self._inventory_win:
|
||||||
|
self.focus(self._plot_win)
|
||||||
|
elif focused == self._plot_win:
|
||||||
|
self.focus(self._quest_book_win)
|
||||||
|
elif focused == self._quest_book_win:
|
||||||
|
self.focus(self._char_sheet_win)
|
||||||
|
|
||||||
elif key in KEYS_DOWN:
|
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)
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import curses
|
|||||||
import curses.ascii
|
import curses.ascii
|
||||||
import typing as T
|
import typing as T
|
||||||
|
|
||||||
from pqcli.ui.curses.util import KEYS_DOWN, KEYS_UP
|
from pqcli.ui.curses.util import KEYS_CYCLE, KEYS_DOWN, KEYS_UP
|
||||||
from pqcli.ui.curses.widgets.focusable import focus_standout
|
from pqcli.ui.curses.widgets.focusable import focus_standout
|
||||||
|
|
||||||
from ..util import Choice
|
from ..util import Choice
|
||||||
@@ -54,6 +54,9 @@ class Menu(Widget):
|
|||||||
def prev(self) -> None:
|
def prev(self) -> None:
|
||||||
self._active_choice = max(0, self._active_choice - 1)
|
self._active_choice = max(0, self._active_choice - 1)
|
||||||
|
|
||||||
|
def cycle(self) -> None:
|
||||||
|
self._active_choice = (self._active_choice + 1) % len(self._choices)
|
||||||
|
|
||||||
def keypress(self, key: int) -> None:
|
def keypress(self, key: int) -> None:
|
||||||
for choice in self._choices:
|
for choice in self._choices:
|
||||||
if key in choice.keys:
|
if key in choice.keys:
|
||||||
@@ -62,15 +65,12 @@ class Menu(Widget):
|
|||||||
|
|
||||||
if key == curses.ascii.NL:
|
if key == curses.ascii.NL:
|
||||||
self._choices[self._active_choice].callback()
|
self._choices[self._active_choice].callback()
|
||||||
return
|
elif key in KEYS_DOWN:
|
||||||
|
|
||||||
if key in KEYS_DOWN:
|
|
||||||
self.next()
|
self.next()
|
||||||
return
|
elif key in KEYS_UP:
|
||||||
|
|
||||||
if key in KEYS_UP:
|
|
||||||
self.prev()
|
self.prev()
|
||||||
return
|
elif key in KEYS_CYCLE:
|
||||||
|
self.cycle()
|
||||||
|
|
||||||
def render(self) -> None:
|
def render(self) -> None:
|
||||||
if not self._pad:
|
if not self._pad:
|
||||||
|
|||||||
Reference in New Issue
Block a user