コード例 #1
0
ファイル: userinterface.py プロジェクト: sean-brock/rift
    def _render(self, offset: (int, int) = (0, 0)):
        """Renders the text of the selector."""
        sets = Settings()

        # Position
        x, y = offset
        x += self._x
        y += self._y

        # Text and color
        text = self._text
        fg = sets.colors['default_fg']
        bg = sets.colors['default_bg']

        # Active highlight
        if self.active:
            if self._mode == Highlight.INVERT:
                bg = sets.colors['default_fg']
                fg = sets.colors['default_bg']
            elif self._mode == Highlight.COLOR:
                fg = sets.colors['highlight_fg']
            elif self._mode == Highlight.ASTERISK:
                text = "* " + text
            elif self._mode == Highlight.DASH:
                text = "- " + text

        #console.print(x+self._x, y+self._y, self._text, fg=sets.colors['default_fg'], bg=sets.colors['default_bg'], alignment=self._align)
        # BearLibTerm print
        terminal.color(fg)
        terminal.bkcolor(bg)
        terminal.puts(x, y, text, *self.size,
                      self._horiz_align.value + self._vert_align.value)
コード例 #2
0
ファイル: worldgen.py プロジェクト: sean-brock/rift
    def __init__(self):
        super().__init__()

        sets = Settings()
        self._ui = WorldGenUI(*sets.screen_size, None)
        self._input_handler = InputHandler()
        self.exit = False
コード例 #3
0
    def __init__(self):
        super().__init__()

        sets = Settings()
        self._ui = MainMenuUI(*sets.screen_size,
                              None)  # TODO: more flexible, work for all menus?
        self._input_handler = SelectorMenu(self._ui, Orientation.VERTICAL)
        self.exit = False
コード例 #4
0
ファイル: rift.py プロジェクト: sean-brock/rift
def main():
    # Initialize global settings.
    sets = Settings()
    sets.initialize()

    terminal.open()

    # Load assets
    f = sets.font('dejavu_sans')
    if not terminal.set("font: %s, size=%d" % (f.path, sets.tile_size[0])):
        print("ERROR: Failed to set font.")
        raise SystemError
    if not terminal.set("window: title=%s, size=%dx%d" %
                        (sets.title, *sets.screen_size)):
        print("ERROR: Failed to set screen size.")
        raise SystemError

    # Flag to prevent drawing before state update
    game_state_change = False

    # Create the game-scene state machine and initialize with the main menu.
    game_state = GameStateMachine(MenuState())
    game_state.render()
    terminal.refresh()

    # Update/render loop
    while True:
        # Wait for an event (animation, user input).
        while terminal.has_input():
            game_state_change = True
            # If the game state is over/exited, it will empty the state machine and return false.
            if not game_state.run(terminal.read()):
                terminal.close()
                raise SystemExit

        # Render a frame with a clear, draw, frame-swap operation.
        if (game_state_change):
            terminal.clear()
            game_state.render()
            terminal.refresh()

            # Reset game state change for renedering
            game_state_change = False
コード例 #5
0
ファイル: userinterface.py プロジェクト: sean-brock/rift
    def _render(self, offset: (int, int) = (0, 0)):
        sets = Settings()

        # Position
        x, y = offset
        x += self._x
        y += self._y

        # Text and color
        fg = sets.colors['default_fg']
        bg = sets.colors['default_bg']

        #console.print(x+self._x, y+self._y, self._text, fg=self._color, bg=sets.colors['default_bg'], alignment=self._align)
        # BearLibTerm print
        terminal.color(fg)
        terminal.bkcolor(bg)
        terminal.puts(x, y, self._text, *self.size,
                      self._horiz_align.value + self._vert_align.value)
コード例 #6
0
ファイル: worldgen.py プロジェクト: sean-brock/rift
    def __init__(self,
                 width: int,
                 height: int,
                 parent: ui.UserInterface,
                 x: int = 0,
                 y: int = 0):
        super().__init__(width, height, parent, x=x, y=y)

        sets = Settings()
        # Add text element for the title
        self._children.append(
            ui.Text("World Generation",
                    sets.colors['default_fg'],
                    20,
                    1,
                    self,
                    x=0,
                    y=0))
コード例 #7
0
    def __init__(self,
                 width: int,
                 height: int,
                 parent: ui.UserInterface,
                 x: int = 0,
                 y: int = 0):
        super().__init__(width, height, parent, x=x, y=y)

        sets = Settings()
        origin_x = int(width / 2) - 5
        origin_y = int(height / 2) - 5

        # Add text element for the title
        self._children.append(
            ui.Text("RIFT",
                    sets.colors['default_fg'],
                    10,
                    1,
                    self,
                    x=origin_x,
                    y=origin_y))

        # Define start selector as activated
        def _start():
            return (StateTransition.NONE, None)

        self._children.append(
            ui.Selector("Start",
                        10,
                        1,
                        self,
                        action=_start,
                        x=origin_x,
                        y=origin_y + 2))
        self._children[1].toggle()

        # Define world gen activator
        def _worldgen():
            return (StateTransition.NEXT, WorldGenState())

        self._children.append(
            ui.Selector("World Generation",
                        20,
                        1,
                        self,
                        action=_worldgen,
                        x=origin_x,
                        y=origin_y + 3))

        # Define options selector
        def _options():
            return (StateTransition.NONE, None)

        self._children.append(
            ui.Selector("Options",
                        10,
                        1,
                        self,
                        action=_options,
                        x=origin_x,
                        y=origin_y + 4))

        # Define exit selector
        def _exit():
            return (StateTransition.EXIT, None)

        self._children.append(
            ui.Selector("Exit",
                        10,
                        1,
                        self,
                        action=_exit,
                        x=origin_x,
                        y=origin_y + 5))