Ejemplo n.º 1
0
 def render(self, screen: Screen, model: Model) -> None:
     x, font_size, spacing = rescale_horizontal(250, 35, 50)
     y, = rescale_vertical(250)
     screen.render_text('Settings! (press y)',
                        font_size=font_size,
                        x=x,
                        y=y,
                        color=WHITE)
Ejemplo n.º 2
0
def _render_mod_property(x: int, spacing: int, label: str,
                         lines: Sequence[str], text_rect: Rect,
                         screen: Screen) -> Rect:
    y = text_rect.y + text_rect.h + spacing
    text_rect = screen.render_text(label, _SLOT_FONT_SIZE, x, y, _TEXT_COLOR)
    y = text_rect.y + text_rect.h
    text = '\n'.join(lines)
    text_rect = screen.render_text(text, _SLOT_FONT_SIZE, x + 40, y,
                                   _TEXT_COLOR)
    return text_rect
Ejemplo n.º 3
0
def _render_text_data(data: DecisionInfo, rect: Rect, screen: Screen) -> None:
    # Use data options to specify arguments to screen.render_text.

    if data.is_prompt:
        args = [data.text, _PROMPT_FONT_SIZE]
    else:
        args = ['{}: {}'.format(data.key, data.text), _CHOICE_FONT_SIZE]
    args.extend([rect, data.color, data.centered])

    screen.render_text_in_rect(*args)  # type: ignore
Ejemplo n.º 4
0
    def render(self, screen: Screen, scene: Scene) -> None:
        assert isinstance(scene, SettingsScene)

        x, font_size, spacing = rescale_horizontal(250, 35, 50)
        y, = rescale_vertical(250)
        screen.render_texts(list(scene.options),
                            font_size=font_size,
                            x=x,
                            y=y,
                            color=WHITE,
                            spacing=spacing)
Ejemplo n.º 5
0
    def render(self, screen: Screen, scene: Scene) -> None:
        assert isinstance(scene, InventoryScene)

        # Scene title, exit key, and error message
        inv_key = Keybindings().keys_for_event(BasicEvents.INVENTORY)[0]
        x, = rescale_horizontal(20)
        y_shift, = rescale_vertical(10)
        y = y_shift
        rect = screen.render_text('Inventory', _OVERLAY_FONT_SIZE, x, y, WHITE)
        y = rect.y + rect.h
        rect = screen.render_text('{} - Return'.format(inv_key),
                                  _OVERLAY_FONT_SIZE, x, y, WHITE)

        if scene.UI_error_message:
            x = rect.x + rect.w + 50
            h = y + rect.h - y_shift
            y = y_shift
            screen.render_text(scene.UI_error_message,
                               _ERROR_FONT_SIZE,
                               x,
                               y,
                               RED,
                               h=h)

        # Inventory slots, mods, and mod information
        layout = scene.layout
        scene_objects = layout.all_objects()

        if scene.selected_mod is not None:
            selected_mod_slots = scene.selected_mod.valid_slots()
            selected_mod_slots.append(SlotTypes.GROUND)  # ground always valid
        else:
            selected_mod_slots = []

        for obj in scene_objects:
            if obj is None:
                continue

            rects = layout.get_rects(obj)
            if isinstance(obj, SlotHeaderInfo):
                assert len(rects) == 1
                _render_slot_header(obj, rects[0], selected_mod_slots, screen)
            elif isinstance(obj, SlotRowInfo):
                assert len(rects) == 1
                _render_mod_slot(obj, rects[0], screen)
            elif isinstance(obj, SelectedModInfo):
                assert len(rects) == 1
                _render_selected_mod_info(obj, rects[0], screen)
Ejemplo n.º 6
0
def _render_combat_options(scene: CombatScene, screen: Screen) -> None:
    x, font_size, spacing = rescale_horizontal(450, 35, 50)
    y, = rescale_vertical(700)

    text = [
        '{}: {} ({} rounds, {} CPU)'.format(i + 1, m.subroutine.description(),
                                            m.subroutine.time_to_resolve(),
                                            m.subroutine.cpu_slots())
        for i, m in enumerate(scene.available_moves())
    ]

    screen.render_texts(text,
                        font_size=font_size,
                        x=x,
                        y=y,
                        color=GREEN,
                        spacing=spacing)
Ejemplo n.º 7
0
    def render(self, screen: Screen, scene: Scene) -> None:

        # key hints
        x = 20
        y = 10
        line_spacing = 10

        rect = screen.render_text('x: Settings', _FONT_SIZE, x, y, WHITE)
        y += rect.h + line_spacing

        if hasattr(scene, 'inventory_available'):
            if scene.inventory_available:  # type: ignore
                rect = screen.render_text('i: Inventory', _FONT_SIZE, x, y,
                                          WHITE)
                y += rect.h + line_spacing

        if hasattr(scene, 'layout'):
            screen.render_text('d: debug', _FONT_SIZE, x, y, WHITE)
Ejemplo n.º 8
0
def _render_mod_slot(slot_data: SlotRowInfo, rect: Rect,
                     screen: Screen) -> None:
    # Render a row representing a given equipped or stored mod.

    screen.render_rect(rect, LIGHT_GRAY, 0)
    border = RED if slot_data.is_selected else DARK_GRAY
    screen.render_rect(rect, border, 4)

    screen.render_text(slot_data.mod.description(),
                       _SLOT_FONT_SIZE,
                       rect.x + 10,
                       rect.y,
                       _TEXT_COLOR,
                       h=rect.h)
Ejemplo n.º 9
0
def _render_selected_mod_info(info: SelectedModInfo, rect: Rect,
                              screen: Screen) -> None:
    # Render relevant information about a mod.
    screen.render_rect(rect, LIGHT_GRAY, 0)
    screen.render_rect(rect, RED, 4)

    spacing = 30

    # Mod header
    x = rect.x
    y = rect.y + 10

    mod = info.mod
    text_rect = screen.render_text(mod.description(), _SLOT_FONT_SIZE, x, y,
                                   _TEXT_COLOR, rect.w)
    y = text_rect.y + text_rect.h + spacing

    # Mod properties
    x = rect.x + 10
    valid_slots = [slot.value for slot in mod.valid_slots()]
    slots = 'Slots: ' + ', '.join(valid_slots)
    text_rect = screen.render_text(slots, _SLOT_FONT_SIZE, x, y, _TEXT_COLOR)
    y = text_rect.y + text_rect.h + spacing

    if mod.states_granted():
        states = [s.value for s in mod.states_granted()]
        subject = 'States granted: '

        text_rect = _render_mod_property(x, spacing, subject, states,
                                         text_rect, screen)

    if mod.attribute_modifiers():
        atts = [
            '{} : {}'.format(att.value, num)
            for att, num in mod.attribute_modifiers().items()
        ]

        text_rect = _render_mod_property(x, spacing, 'Attribute modifiers:',
                                         atts, text_rect, screen)

    if mod.subroutines_granted():
        subs = [sub.description() for sub in mod.subroutines_granted()]
        _render_mod_property(x, spacing, 'Subroutines granted:', subs,
                             text_rect, screen)
Ejemplo n.º 10
0
def _render_slot_header(slot_data: SlotHeaderInfo, rect: Rect,
                        selected_mod_slots: List[SlotTypes],
                        screen: Screen) -> None:
    # Render the header for a given slot category, including storage capacity.
    # If the slot is a valid transfer slot, use a different border.

    screen.render_rect(rect, LIGHT_GRAY, 0)

    border = GREEN if slot_data.slot in selected_mod_slots else DARK_GRAY

    screen.render_rect(rect, border, 4)

    if slot_data.slot != SlotTypes.GROUND:
        text = '{} - {} / {}'.format(slot_data.slot.value,
                                     slot_data.num_filled, slot_data.capacity)
    else:
        text = slot_data.slot.value

    screen.render_text(text, _SLOT_FONT_SIZE, rect.x, rect.y, _TEXT_COLOR,
                       rect.w, rect.h)
Ejemplo n.º 11
0
def _render_move(move: Move,
                 time: Optional[int],
                 rect: Rect,
                 screen: Screen,
                 small_text: bool = False,
                 CPU_not_time: bool = False) -> None:
    # Background
    screen.render_rect(rect, DARK_GRAY, 0)
    screen.render_rect(rect, LIGHT_GRAY, _STACK_OUTLINE)

    font_size = _SMALL_FONT_SIZE if small_text else _FONT_SIZE
    # Description
    screen.render_text(move.subroutine.description(), font_size,
                       rect.x + _TEXT_SPACE, rect.y + _TEXT_SPACE, WHITE)

    # CPU slots
    if CPU_not_time:
        screen.render_text('CPU: {}'.format(move.subroutine.cpu_slots()),
                           font_size, rect.x + rect.w - 6 * _TEXT_SPACE,
                           rect.y + _TEXT_SPACE, YELLOW)
    # Time to resolve
    elif time is not None:
        screen.render_text('T: {}'.format(time), font_size,
                           rect.x + rect.w - 5 * _TEXT_SPACE,
                           rect.y + _TEXT_SPACE, RED)
    # USER + TARGET
    screen.render_image(move.user.image_path, rect.x - _TARGET_SIZE, rect.y,
                        _TARGET_SIZE, _TARGET_SIZE)
    screen.render_image(move.target.image_path, rect.x + rect.w, rect.y,
                        _TARGET_SIZE, _TARGET_SIZE)
Ejemplo n.º 12
0
def _render_character(info: CharacterInfo, screen: Screen, rect: Rect) -> None:
    screen.render_image(info.image_path, rect.x, rect.y, rect.w, rect.h)

    font_size = rescale_vertical(30)[0]
    vert_spacing = font_size
    x = rect.x

    # health above image
    health_bar = 'HP: {} / {}'.format(info.health, info.max_health)

    y = rect.y - vert_spacing
    screen.render_text(health_bar, font_size, x, y, GREEN, w=rect.w)

    # Draw shields if they exist above health
    if info.shields > 0:
        y = rect.y - 2 * vert_spacing
        screen.render_text('Shield: {}'.format(info.shields),
                           font_size,
                           x,
                           y,
                           LIGHT_BLUE,
                           w=rect.w)

    # Status effects above health/shields
    y -= vert_spacing * (len(info.active_effects) + 1)
    for effect in info.active_effects:
        y += vert_spacing
        screen.render_text(effect.label, font_size, x, y, RED, w=rect.w)

    # Name below image
    y = rect.y + rect.h + 0.5 * vert_spacing
    screen.render_text(info.description, font_size, x, y, GREEN, w=rect.w)

    # CPU slots below name
    y += vert_spacing
    cpu_bar = 'CPU: {} / {}'.format(info.cpu, info.max_cpu)
    screen.render_text(cpu_bar, font_size, x, y, YELLOW, w=rect.w)

    # Selection box
    if info.is_selected:
        screen.render_rect(rect, RED, 2)

    # X out dead character
    if info.is_dead:
        start = rect.x, rect.y
        end = rect.x + rect.w, rect.y + rect.h
        screen.render_line(start, end, RED, 4)

        start, end = (start[0], end[1]), (end[0], start[1])
        screen.render_line(start, end, RED, 4)
Ejemplo n.º 13
0
 def render(self, screen: Screen, scene: Scene) -> None:
     w, h = SCREEN_SIZE
     screen.render_image(self._background_image, 0, 0, w, h)