mirror of
https://github.com/rr-/pq-cli.git
synced 2026-09-29 06:44:00 -06:00
ui/curses: cancel char creation one step at a time
This commit is contained in:
@@ -35,6 +35,7 @@ class ConfirmView(BaseView):
|
||||
self.main_menu = Menu(
|
||||
header=self.title,
|
||||
choices=self.choices,
|
||||
active_choice=0,
|
||||
scr_height=scr_height,
|
||||
scr_width=scr_width,
|
||||
)
|
||||
|
||||
@@ -3,7 +3,7 @@ import curses.ascii
|
||||
import functools
|
||||
import typing as T
|
||||
|
||||
from pqcli.config import CLASSES, PRIME_STATS, RACES
|
||||
from pqcli.config import CLASSES, PRIME_STATS, RACES, Class, Race
|
||||
from pqcli.mechanic import StatsBuilder, generate_name
|
||||
from pqcli.ui.curses.event_handler import EventHandler
|
||||
from pqcli.ui.curses.util import Choice
|
||||
@@ -12,13 +12,15 @@ from pqcli.ui.curses.views.menu_view import MenuView
|
||||
|
||||
|
||||
class ChooseCharacterNameView(BaseView):
|
||||
def __init__(self, screen: T.Any) -> None:
|
||||
def __init__(
|
||||
self, screen: T.Any, character_name: T.Optional[str] = None
|
||||
) -> None:
|
||||
super().__init__(screen)
|
||||
|
||||
self.on_cancel = EventHandler()
|
||||
self.on_confirm = EventHandler()
|
||||
|
||||
self._text = generate_name()
|
||||
self._text = character_name or generate_name()
|
||||
|
||||
def start(self) -> None:
|
||||
self.screen.erase()
|
||||
@@ -79,8 +81,12 @@ class ChooseCharacterNameView(BaseView):
|
||||
|
||||
|
||||
class ChooseCharacterRaceView(MenuView):
|
||||
def __init__(self, screen: T.Any) -> None:
|
||||
super().__init__(screen, "Choose character race")
|
||||
def __init__(self, screen: T.Any, race: T.Optional[Race] = None) -> None:
|
||||
super().__init__(
|
||||
screen,
|
||||
"Choose character race",
|
||||
RACES.index(race) if race is not None else 0,
|
||||
)
|
||||
|
||||
for y, race in enumerate(RACES, 1):
|
||||
key: T.Optional[str] = str(y % 10) if y <= 10 else None
|
||||
@@ -102,8 +108,14 @@ class ChooseCharacterRaceView(MenuView):
|
||||
|
||||
|
||||
class ChooseCharacterClassView(MenuView):
|
||||
def __init__(self, screen: T.Any) -> None:
|
||||
super().__init__(screen, "Choose character class")
|
||||
def __init__(
|
||||
self, screen: T.Any, class_: T.Optional[Class] = None
|
||||
) -> None:
|
||||
super().__init__(
|
||||
screen,
|
||||
"Choose character class",
|
||||
CLASSES.index(class_) if class_ is not None else 0,
|
||||
)
|
||||
|
||||
for y, class_ in enumerate(CLASSES, 1):
|
||||
key: T.Optional[str] = str(y % 10) if y <= 10 else None
|
||||
|
||||
@@ -8,7 +8,9 @@ from pqcli.ui.curses.widgets import Menu
|
||||
|
||||
|
||||
class MenuView(BaseView):
|
||||
def __init__(self, screen: T.Any, title: str) -> None:
|
||||
def __init__(
|
||||
self, screen: T.Any, title: str, active_choice: int = 0
|
||||
) -> None:
|
||||
super().__init__(screen)
|
||||
|
||||
self.on_cancel = EventHandler()
|
||||
@@ -16,6 +18,7 @@ class MenuView(BaseView):
|
||||
|
||||
self._title = f"{title}:"
|
||||
self._choices: T.List[Choice] = []
|
||||
self._active_choice = active_choice
|
||||
|
||||
def start(self) -> None:
|
||||
scr_height, scr_width = self.screen.getmaxyx()
|
||||
@@ -25,6 +28,7 @@ class MenuView(BaseView):
|
||||
self.main_menu = Menu(
|
||||
header=self._title,
|
||||
choices=self._choices,
|
||||
active_choice=self._active_choice,
|
||||
scr_height=scr_height,
|
||||
scr_width=scr_width,
|
||||
)
|
||||
|
||||
@@ -53,6 +53,7 @@ class RosterView(BaseView):
|
||||
self.main_menu = Menu(
|
||||
header=LOGO,
|
||||
choices=self.choices,
|
||||
active_choice=0,
|
||||
scr_height=scr_height,
|
||||
scr_width=scr_width,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user