class IntroInstance(Instance): def __init__(self): self.screen = Screen(curses.LINES - 1, curses.COLS - 1) self.pad = self.screen.pad self.h = 30 self.w = 124 self.H = self.screen.H self.W = self.screen.W self.dy, self.dx = get_dy_dx(self.H, self.W, self.h, self.w) def process_key_event(self, key): if key == ord(' ') or key == ord('\n'): from controller.create_hero_handler import CreateHeroHandler return CreateHeroHandler(), False from controller.splash_screen_handler import SplashScreenHandler return SplashScreenHandler(self), False def invoke(self): self.screen.clear() self.print() self.screen.refresh() def print(self): y = self.dy x = self.dx h = self.h w = self.w draw_window(self.pad, y, x, h, w, 'Пролог', 'Нажмите [Enter] или [Space] для продолжения') self._print_description() def _print_description(self): draw_pic(self.pad, self.dy + 2, self.dx + 2, PIC)
class Menu(object): def __init__(self): self.screen = Screen() self.running = True self.tab = 0 self.target = 0 self.escaped = 0 self.tabs = [ Library(self.screen), Settings(self.screen), Console(self.screen) ] self.debug = False def update(self): if self.escaped == 1: self.escaped = 0 c = self.screen.getch() if c == 127: self.debug = not self.debug if c == ord('a'): self.target = 0 elif c == ord('s'): self.target = 1 elif c == ord('`'): self.target = 2 elif self.tab == 3 or c == 4: self.running = False return elif c == 27: self.escaped = 2 - self.escaped self.target = self.tab elif c == 10: if self.escaped: self.escaped = 1 self.tab = self.target elif self.escaped and c == ord('h'): self.target = self.target - 1 if self.target > 0 else 3 elif self.escaped and c == ord('l'): self.target = self.target + 1 if self.target < 3 else 0 if not self.escaped: self.tab = self.target if self.tab < len(self.tabs): self.tabs[self.tab].__update__(c if not self.escaped else -1) self.screen.addstr( self.screen.height - 1, 0, ' ' * self.screen.width, colors.bar_active[0] if self.escaped else colors.bar[0], colors.bar_active[1] if self.escaped else colors.bar[1]) # Library self.screen.addstr( self.screen.height - 1, self.screen.width // 2 - 25, ' a ', colors.button_active[0] if self.target == 0 else colors.button[0], colors.button_active[1] if self.target == 0 else colors.button[1]) self.screen.addstr( self.screen.height - 1, self.screen.width // 2 - 21, "library", colors.bar_active[0] if self.escaped else colors.bar[0], colors.bar_active[1] if self.escaped else colors.bar[1]) # Settings self.screen.addstr( self.screen.height - 1, self.screen.width // 2 - 11, ' s ', colors.button_active[0] if self.target == 0 else colors.button[0], colors.button_active[1] if self.target == 1 else colors.button[1]) self.screen.addstr( self.screen.height - 1, self.screen.width // 2 - 7, "settings", colors.bar_active[0] if self.escaped else colors.bar[0], colors.bar_active[1] if self.escaped else colors.bar[1]) # Console self.screen.addstr( self.screen.height - 1, self.screen.width // 2 + 2, ' ` ', colors.button_active[0] if self.target == 0 else colors.button[0], colors.button_active[1] if self.target == 2 else colors.button[1]) self.screen.addstr( self.screen.height - 1, self.screen.width // 2 + 6, "console", colors.bar_active[0] if self.escaped else colors.bar[0], colors.bar_active[1] if self.escaped else colors.bar[1]) # Quit self.screen.addstr( self.screen.height - 1, self.screen.width // 2 + 15, ' ^D ', colors.button_active[0] if self.target == 0 else colors.button[0], colors.button_active[1] if self.target == 3 else colors.button[1]) self.screen.addstr( self.screen.height - 1, self.screen.width // 2 + 20, "quit", colors.bar_active[0] if self.escaped else colors.bar[0], colors.bar_active[1] if self.escaped else colors.bar[1]) if self.debug: self.screen.addstr(0, 0, c) self.screen.refresh()
class CreateHeroInstance(Instance): def __init__(self, screen): self.choices = [ 'Солдат Содружества', 'Инженер Содружества', 'Псионик класса А', 'Псионик класса Б', 'Солест' ] self.dx = max(0, screen.W // 2 - 170 // 2) self.dy = max(0, screen.H // 2 - len(self.choices) - 7) self.screen = screen self.pad = screen.get_pad() self.menu_screen = Screen(H=len(self.choices) + 2, W=23, fromy=self.dy + 2, fromx=self.dx + 2) self.menu = MenuInstance(self.menu_screen, self.choices) self._set_current_choice_info(0) def process_key_event(self, key): if key == ord('q') or key == curses.KEY_EXIT: return MainMenuHandler(), False choice = self.menu.process_key_event(key) if choice < 0: self._set_current_choice_info(self.menu.current) return CreateHeroHandler(self), False else: self._set_current_choice_info(choice) overlay = MoveTutorialOverlay() return DungeonHandler(self.clazz, overlay=overlay), False def invoke(self): self.screen.clear() self.menu_screen.clear() self.print() self.menu.print() self.screen.refresh() self.menu_screen.refresh() def _set_current_choice_info(self, current): choice = self.choices[current] clazz = CLASSES[choice] self.description = clazz['description'] self.personal = clazz['personal'] self.skills = clazz['skills'] self.clazz = clazz['class'] def print(self): draw_window(self.screen.pad, self.dy + 1, self.dx + 1, len(self.choices) + 5, 35, 'Выберите класс') draw_window(self.screen.pad, self.dy + len(self.choices) + 7, self.dx + 1, 13, 35, 'Характеристики') draw_window(self.screen.pad, self.dy + 1, self.dx + 38, len(self.choices) + 5, 135, 'Описание класса') draw_window(self.screen.pad, self.dy + len(self.choices) + 7, self.dx + 38, 13, 135, 'Предыстория') draw_text(self.screen.pad, self.dy + 3, self.dx + 40, len(self.choices) + 5, 132, self.description) tlen = draw_text(self.screen.pad, self.dy + len(self.choices) + 9, self.dx + 40, len(self.choices) + 5, 132, self.personal) draw_text(self.screen.pad, self.dy + len(self.choices) + 9 + tlen, self.dx + 40, len(self.choices) + 5, 132, self.skills) self._print_stats() def _print_stats(self): draw_class_stats(self.screen.pad, self.dy + len(self.choices) + 9, self.dx + 3, self.clazz) draw_text(self.screen.pad, self.dy + len(self.choices) + 16, self.dx + 3, 1, 34, '(можно изменить позднее)')