547 lines
22 KiB
Python
547 lines
22 KiB
Python
"""Pure renderer: reads GameFlow/GameSession and draws. Never mutates state."""
|
|
from __future__ import annotations
|
|
|
|
import math
|
|
|
|
import pygame
|
|
|
|
from data.constants import (
|
|
BOTTOM_BAR_H,
|
|
FINAL_FLOOR,
|
|
LEVEL_TABLE,
|
|
LOG_PANEL_W,
|
|
MAX_LOG_SHOWN,
|
|
SIGHT_RADIUS,
|
|
SCREEN_H,
|
|
SCREEN_W,
|
|
TILE_FLOOR,
|
|
TILE_SIZE,
|
|
TOP_BAR_H,
|
|
VIEW_TILES_H,
|
|
VIEW_TILES_W,
|
|
)
|
|
from engine.flow import (
|
|
DEAD,
|
|
EQUIPMENT,
|
|
HOWTO,
|
|
INVENTORY,
|
|
MENU,
|
|
PLAYING,
|
|
POTIONS,
|
|
SCROLLS,
|
|
VICTORY,
|
|
GameFlow,
|
|
)
|
|
from entities.enemy import Enemy
|
|
from entities.item import Item
|
|
from render import sprites as sprite_render
|
|
from render.effects import Effects, brightness_step, light_overlay, shadow, vignette
|
|
|
|
UI_BG = (14, 13, 18)
|
|
UI_BORDER = (120, 110, 80)
|
|
UI_BORDER_DARK = (60, 54, 40)
|
|
UI_TEXT = (210, 205, 195)
|
|
UI_TEXT_DIM = (130, 126, 120)
|
|
HP_GREEN = (95, 200, 90)
|
|
HP_RED = (180, 50, 45)
|
|
XP_BLUE = (90, 130, 220)
|
|
STAIRS_YELLOW = (245, 210, 70)
|
|
|
|
HOWTO_LINES: tuple[tuple[str, bool], ...] = (
|
|
("HOW TO PLAY", True),
|
|
("", False),
|
|
("Arrows or HJKL move / attack (walk into an enemy)", False),
|
|
("G pick up the item under you", False),
|
|
("F descend while standing on the yellow > stairs", False),
|
|
("I inventory E equipment", False),
|
|
("Q quaff a potion R read a scroll", False),
|
|
("S save and quit M mute sounds", False),
|
|
("? reopen this help Esc close menus", False),
|
|
("", False),
|
|
("In lists, press the letter next to an item (or arrows + Enter).", False),
|
|
("", False),
|
|
("Press any key to continue", True),
|
|
)
|
|
|
|
LIST_TITLES = {
|
|
INVENTORY: "INVENTORY — letter to equip",
|
|
EQUIPMENT: "EQUIPMENT — letter to remove",
|
|
POTIONS: "POTIONS — letter to quaff",
|
|
SCROLLS: "SCROLLS — letter to read",
|
|
}
|
|
|
|
|
|
def _log_color(message: str) -> tuple[int, int, int]:
|
|
low = message.lower()
|
|
if "hit you" in low or "you die" in low or "misses you" in low or "breathes" in low:
|
|
return (225, 90, 80)
|
|
if "reach level" in low:
|
|
return (110, 220, 110)
|
|
if "pick up" in low or "equip" in low or "quaff" in low or "defeated" in low or "scroll" in low:
|
|
return (235, 210, 120)
|
|
if "you hit" in low or "critical hit" in low:
|
|
return (240, 240, 240)
|
|
return (170, 166, 160)
|
|
|
|
|
|
def _wrap(font: pygame.font.Font, text: str, width: int) -> list[str]:
|
|
words = text.split()
|
|
if not words:
|
|
return [text]
|
|
lines: list[str] = []
|
|
current = words[0]
|
|
for word in words[1:]:
|
|
if font.size(current + " " + word)[0] <= width:
|
|
current += " " + word
|
|
else:
|
|
lines.append(current)
|
|
current = word
|
|
lines.append(current)
|
|
return lines
|
|
|
|
|
|
def _draw_panel(
|
|
surface: pygame.Surface,
|
|
rect: pygame.Rect,
|
|
background: tuple[int, int, int] = UI_BG,
|
|
) -> None:
|
|
pygame.draw.rect(surface, background, rect)
|
|
pygame.draw.rect(surface, UI_BORDER, rect, 1)
|
|
inner = rect.inflate(-4, -4)
|
|
pygame.draw.line(
|
|
surface, UI_BORDER_DARK, (inner.x, inner.bottom), (inner.right, inner.bottom)
|
|
)
|
|
pygame.draw.line(
|
|
surface, UI_BORDER_DARK, (inner.right, inner.y), (inner.right, inner.bottom)
|
|
)
|
|
|
|
|
|
def _bar(
|
|
surface: pygame.Surface,
|
|
rect: pygame.Rect,
|
|
fraction: float,
|
|
fill: tuple[int, int, int],
|
|
) -> None:
|
|
pygame.draw.rect(surface, (30, 28, 34), rect)
|
|
width = max(0, min(1.0, fraction))
|
|
pygame.draw.rect(surface, fill, (rect.x, rect.y, int(rect.w * width), rect.h))
|
|
pygame.draw.rect(surface, UI_BORDER_DARK, rect, 1)
|
|
|
|
|
|
class Renderer:
|
|
def __init__(self, screen: pygame.Surface) -> None:
|
|
self.screen = screen
|
|
self.effects = Effects()
|
|
self.font = pygame.font.SysFont(None, 18)
|
|
self.small = pygame.font.SysFont(None, 15)
|
|
self.mid = pygame.font.SysFont(None, 24)
|
|
self.big = pygame.font.SysFont(None, 48)
|
|
self.world_sprites: set[str] = set()
|
|
self._time = 0.0
|
|
self._camera_snapped = False
|
|
|
|
# -- dispatch ---------------------------------------------------------
|
|
|
|
def draw(self, flow: GameFlow, dt: float) -> None:
|
|
self._time += dt
|
|
self.screen.fill((8, 8, 12))
|
|
if flow.screen == MENU:
|
|
self._draw_menu(flow)
|
|
elif flow.screen == HOWTO:
|
|
self._draw_howto(flow)
|
|
elif flow.screen in (DEAD, VICTORY):
|
|
self._draw_game_over(flow)
|
|
else:
|
|
self._draw_play(flow, dt)
|
|
pygame.display.flip()
|
|
|
|
# -- world -------------------------------------------------------------
|
|
|
|
def _draw_play(self, flow: GameFlow, dt: float) -> None:
|
|
session = flow.session
|
|
assert session is not None
|
|
self.world_sprites.clear()
|
|
self.effects.observe(session)
|
|
self.effects.update(dt)
|
|
self._draw_world(session)
|
|
self._draw_top_bar(session)
|
|
self._draw_log_panel(session)
|
|
self._draw_bottom_bar(flow)
|
|
self._draw_context_prompt(flow)
|
|
if flow.screen != PLAYING:
|
|
self._draw_list(flow)
|
|
|
|
def _draw_world(self, session) -> None:
|
|
game_map = session.current_map
|
|
player = session.player
|
|
view_w = VIEW_TILES_W * TILE_SIZE
|
|
view_h = VIEW_TILES_H * TILE_SIZE
|
|
|
|
target_x = player.x * TILE_SIZE + TILE_SIZE / 2 - view_w / 2
|
|
target_y = player.y * TILE_SIZE + TILE_SIZE / 2 - view_h / 2
|
|
if not self._camera_snapped:
|
|
self.effects.camera.snap(target_x, target_y)
|
|
self._camera_snapped = True
|
|
self.effects.camera.update(target_x, target_y, 1 / 60.0)
|
|
cam_x = max(0.0, min(self.effects.camera.x, game_map.width * TILE_SIZE - view_w))
|
|
cam_y = max(0.0, min(self.effects.camera.y, game_map.height * TILE_SIZE - view_h))
|
|
ox, oy = self.effects.camera.offset
|
|
origin_x = int(cam_x - ox)
|
|
origin_y = int(cam_y - oy) + TOP_BAR_H
|
|
self._origin = (origin_x, origin_y)
|
|
|
|
x0 = max(0, int(cam_x // TILE_SIZE))
|
|
y0 = max(0, int(cam_y // TILE_SIZE))
|
|
x1 = min(game_map.width, x0 + VIEW_TILES_W + 2)
|
|
y1 = min(game_map.height, y0 + VIEW_TILES_H + 2)
|
|
|
|
clip = self.screen.get_rect().clip(pygame.Rect(0, TOP_BAR_H, view_w, view_h))
|
|
self.screen.set_clip(clip)
|
|
self.screen.fill((6, 6, 9), clip)
|
|
|
|
for y in range(y0, y1):
|
|
row_tiles = game_map.tiles[y]
|
|
for x in range(x0, x1):
|
|
if not game_map.explored[y][x]:
|
|
continue
|
|
is_floor = row_tiles[x] == TILE_FLOOR
|
|
variant = (x * 7 + y * 13) % 3
|
|
tile = sprite_render.get_tile("floor" if is_floor else "wall", variant)
|
|
self.screen.blit(tile, (x * TILE_SIZE - origin_x, y * TILE_SIZE - origin_y))
|
|
distance = math.hypot(x - player.x, y - player.y)
|
|
if game_map.visible[y][x]:
|
|
step = brightness_step(distance, self._time)
|
|
else:
|
|
step = 3
|
|
self.screen.blit(
|
|
light_overlay(step), (x * TILE_SIZE - origin_x, y * TILE_SIZE - origin_y)
|
|
)
|
|
|
|
if game_map.stairs_down is not None:
|
|
sx, sy = game_map.stairs_down
|
|
if game_map.explored[sy][sx]:
|
|
px = sx * TILE_SIZE - origin_x
|
|
py = sy * TILE_SIZE - origin_y
|
|
self.screen.blit(shadow(TILE_SIZE, TILE_SIZE // 3), (px, py + TILE_SIZE - TILE_SIZE // 3))
|
|
self.screen.blit(sprite_render.get_sprite("stairs"), (px, py))
|
|
if game_map.visible[sy][sx]:
|
|
step = brightness_step(math.hypot(sx - player.x, sy - player.y), self._time)
|
|
self.screen.blit(light_overlay(max(step, 10)), (px, py))
|
|
self.world_sprites.add("stairs")
|
|
|
|
for entity in game_map.entities:
|
|
if not game_map.visible[entity.y][entity.x]:
|
|
continue
|
|
self._draw_entity(entity)
|
|
|
|
self._draw_player(session)
|
|
self.effects.draw(self.screen, cam_x - ox, cam_y - oy + TOP_BAR_H)
|
|
self.screen.set_clip(self.screen.get_rect())
|
|
self.screen.blit(vignette((view_w, view_h)), (0, TOP_BAR_H))
|
|
|
|
def _bob(self, phase: float) -> int:
|
|
return int(round(math.sin(phase) * 1.5))
|
|
|
|
def _draw_entity(self, entity) -> None:
|
|
origin_x, origin_y = self._origin
|
|
px = entity.x * TILE_SIZE - origin_x
|
|
py = entity.y * TILE_SIZE - origin_y
|
|
if isinstance(entity, Item):
|
|
key = sprite_render.item_sprite_key(entity.key, entity.sprite_key)
|
|
bob = self._bob(self._time * 2.2 + entity.x * 1.3 + entity.y * 0.7)
|
|
self.screen.blit(shadow(TILE_SIZE // 2, 5), (px + TILE_SIZE // 4, py + TILE_SIZE - 6))
|
|
self.screen.blit(sprite_render.get_sprite(key), (px, py + bob))
|
|
self.world_sprites.add(key)
|
|
return
|
|
if not isinstance(entity, Enemy) or not entity.alive:
|
|
return
|
|
key = entity.sprite_key
|
|
sprite = sprite_render.get_sprite(key)
|
|
size = sprite.get_width()
|
|
offset = (TILE_SIZE - size) // 2
|
|
bob = self._bob(self._time * 1.8 + entity.x + entity.y)
|
|
self.screen.blit(shadow(size, size // 4), (px + offset, py + TILE_SIZE - size // 4 - 2))
|
|
if self.effects.enemy_flash.get(id(entity), 0) > 0:
|
|
sprite = sprite_render.get_flash(key, sprite)
|
|
if key == "wraith":
|
|
sprite = sprite.copy()
|
|
sprite.set_alpha(190)
|
|
self.screen.blit(sprite, (px + offset, py + offset + bob))
|
|
if entity.hp < entity.max_hp:
|
|
bar = pygame.Rect(px + 2, py - 4, TILE_SIZE - 4, 3)
|
|
_bar(self.screen, bar, entity.hp / entity.max_hp, HP_RED)
|
|
self.world_sprites.add(key)
|
|
|
|
def _draw_player(self, session) -> None:
|
|
origin_x, origin_y = self._origin
|
|
player = session.player
|
|
px = player.x * TILE_SIZE - origin_x
|
|
py = player.y * TILE_SIZE - origin_y
|
|
weapon = player.equipped_weapon.key if player.equipped_weapon else ""
|
|
armor = player.equipped_armor.key if player.equipped_armor else ""
|
|
facing = self.effects.player_facing
|
|
sprite = sprite_render.get_player_sprite(weapon, armor, facing)
|
|
if self.effects.player_flash > 0:
|
|
sprite = sprite_render.get_flash(f"player:{weapon}:{armor}", sprite)
|
|
bob = self._bob(self._time * 2.4)
|
|
self.screen.blit(shadow(TILE_SIZE, 6), (px, py + TILE_SIZE - 6))
|
|
if player.is_invisible:
|
|
sprite = sprite.copy()
|
|
sprite.set_alpha(120)
|
|
self.screen.blit(sprite, (px, py + bob))
|
|
self.world_sprites.add("player")
|
|
|
|
# -- UI panels -----------------------------------------------------------
|
|
|
|
def _draw_top_bar(self, session) -> None:
|
|
player = session.player
|
|
rect = pygame.Rect(0, 0, SCREEN_W, TOP_BAR_H)
|
|
_draw_panel(self.screen, rect)
|
|
y = rect.y + 8
|
|
|
|
floor_label = self.font.render(
|
|
f"Floor {session.current_floor + 1}/{FINAL_FLOOR + 1}", True, UI_TEXT
|
|
)
|
|
self.screen.blit(floor_label, (10, y))
|
|
|
|
heart = sprite_render.get_sprite("potion_heal")
|
|
self.screen.blit(
|
|
pygame.transform.scale(heart, (14, 14)), (140, y + 1)
|
|
)
|
|
hp_rect = pygame.Rect(160, y, 160, 12)
|
|
_bar(self.screen, hp_rect, player.hp / player.max_hp, HP_GREEN if player.hp > player.max_hp * 0.3 else HP_RED)
|
|
label = self.small.render(f"{player.hp}/{player.max_hp}", True, UI_TEXT)
|
|
self.screen.blit(label, (hp_rect.x + hp_rect.w + 6, y + 1))
|
|
|
|
level_label = self.font.render(f"Lv {player.level}", True, UI_TEXT)
|
|
self.screen.blit(level_label, (400, y))
|
|
next_xp = LEVEL_TABLE.get(player.level + 1)
|
|
prev_needed = LEVEL_TABLE.get(player.level, (0,))[0]
|
|
fraction = 1.0 if next_xp is None else (player.xp - prev_needed) / max(1, next_xp[0] - prev_needed)
|
|
xp_label = self.small.render(f"XP {player.xp}", True, UI_TEXT_DIM)
|
|
self.screen.blit(xp_label, (450 - xp_label.get_width() - 6, y + 1))
|
|
xp_rect = pygame.Rect(452, y, 150, 12)
|
|
_bar(self.screen, xp_rect, fraction, (110, 160, 240))
|
|
|
|
turn_label = self.small.render(f"Turn {session.turn}", True, UI_TEXT_DIM)
|
|
self.screen.blit(turn_label, (SCREEN_W - LOG_PANEL_W - 90, y + 1))
|
|
power_label = self.font.render(
|
|
f"PWR {player.total_power} DEF {player.total_armor}", True, UI_TEXT
|
|
)
|
|
self.screen.blit(power_label, (620, y))
|
|
|
|
def _draw_log_panel(self, session) -> None:
|
|
rect = pygame.Rect(SCREEN_W - LOG_PANEL_W, TOP_BAR_H, LOG_PANEL_W, SCREEN_H - TOP_BAR_H)
|
|
_draw_panel(self.screen, rect)
|
|
title = self.small.render("MESSAGE LOG", True, UI_TEXT_DIM)
|
|
self.screen.blit(title, (rect.x + 10, rect.y + 6))
|
|
pygame.draw.line(
|
|
self.screen, UI_BORDER_DARK, (rect.x + 8, rect.y + 22), (rect.right - 8, rect.y + 22)
|
|
)
|
|
y = rect.y + 28
|
|
messages = session.log[-MAX_LOG_SHOWN:]
|
|
lines: list[tuple[str, tuple[int, int, int]]] = []
|
|
for message in messages:
|
|
for line in _wrap(self.font, message, LOG_PANEL_W - 24):
|
|
lines.append((line, _log_color(message)))
|
|
for line, color in lines[-MAX_LOG_SHOWN * 2:]:
|
|
self.screen.blit(self.font.render(line, True, color), (rect.x + 10, y))
|
|
y += self.font.get_height() + 2
|
|
|
|
def _draw_bottom_bar(self, flow: GameFlow) -> None:
|
|
session = flow.session
|
|
assert session is not None
|
|
player = session.player
|
|
rect = pygame.Rect(0, SCREEN_H - BOTTOM_BAR_H, SCREEN_W - LOG_PANEL_W, BOTTOM_BAR_H)
|
|
_draw_panel(self.screen, rect)
|
|
|
|
slots = [
|
|
(player.equipped_weapon, "weapon"),
|
|
(player.equipped_armor, "armor"),
|
|
]
|
|
x = 14
|
|
for item, kind in slots:
|
|
slot = pygame.Rect(x, rect.y + 12, TILE_SIZE + 8, TILE_SIZE + 8)
|
|
pygame.draw.rect(self.screen, (24, 22, 28), slot)
|
|
pygame.draw.rect(self.screen, UI_BORDER_DARK, slot, 1)
|
|
if item is not None:
|
|
key = sprite_render.item_sprite_key(item.key, item.sprite_key)
|
|
self.screen.blit(sprite_render.get_sprite(key), (slot.x + 4, slot.y + 4))
|
|
else:
|
|
hint = self.small.render("-", True, UI_TEXT_DIM)
|
|
self.screen.blit(hint, (slot.centerx - 4, slot.centery - 7))
|
|
label = self.small.render(
|
|
item.name[:14] if item else ("no weapon" if kind == "weapon" else "no armor"),
|
|
True,
|
|
UI_TEXT if item else UI_TEXT_DIM,
|
|
)
|
|
self.screen.blit(label, (slot.x - 2, slot.bottom + 2))
|
|
x += TILE_SIZE + 76
|
|
|
|
effect_x = x + 10
|
|
if player.strength_turns > 0:
|
|
label = self.font.render(f"STR {player.strength_turns}", True, (240, 150, 60))
|
|
self.screen.blit(label, (effect_x, rect.y + 14))
|
|
effect_x += label.get_width() + 14
|
|
if player.invisible_turns > 0:
|
|
label = self.font.render(f"INV {player.invisible_turns}", True, (150, 200, 240))
|
|
self.screen.blit(label, (effect_x, rect.y + 14))
|
|
|
|
muted = flow.audio is None or flow.audio.muted
|
|
icon_x = rect.right - 60
|
|
color = UI_TEXT_DIM if muted else UI_TEXT
|
|
pygame.draw.polygon(
|
|
self.screen,
|
|
color,
|
|
[
|
|
(icon_x, rect.y + 22),
|
|
(icon_x + 8, rect.y + 22),
|
|
(icon_x + 18, rect.y + 14),
|
|
(icon_x + 18, rect.y + 34),
|
|
(icon_x + 8, rect.y + 26),
|
|
(icon_x, rect.y + 26),
|
|
],
|
|
)
|
|
if muted:
|
|
pygame.draw.line(self.screen, (200, 80, 70), (icon_x - 2, rect.y + 12), (icon_x + 22, rect.y + 36), 2)
|
|
else:
|
|
pygame.draw.arc(self.screen, color, (icon_x + 16, rect.y + 18, 10, 12), -1.2, 1.2, 2)
|
|
hint = self.small.render("M", True, UI_TEXT_DIM)
|
|
self.screen.blit(hint, (icon_x + 6, rect.y + 40))
|
|
|
|
def _draw_context_prompt(self, flow: GameFlow) -> None:
|
|
prompt = flow.context_prompt()
|
|
if not prompt:
|
|
return
|
|
label = self.font.render(prompt, True, (20, 16, 8))
|
|
pad = 10
|
|
rect = label.get_rect(
|
|
midbottom=(VIEW_TILES_W * TILE_SIZE // 2, SCREEN_H - BOTTOM_BAR_H - 8)
|
|
).inflate(pad * 2, pad)
|
|
pygame.draw.rect(self.screen, STAIRS_YELLOW, rect)
|
|
pygame.draw.rect(self.screen, (120, 95, 25), rect, 2)
|
|
self.screen.blit(label, (rect.x + pad, rect.y + pad - 2))
|
|
|
|
# -- menus ------------------------------------------------------------
|
|
|
|
def _draw_menu(self, flow: GameFlow) -> None:
|
|
cx = SCREEN_W // 2
|
|
dragon = pygame.transform.scale(sprite_render.get_sprite("ancient_dragon"), (60, 60))
|
|
self.screen.blit(
|
|
dragon,
|
|
(cx - 30, 60),
|
|
)
|
|
title = self.big.render("UNDERDEPTHS", True, STAIRS_YELLOW)
|
|
self.screen.blit(title, (cx - title.get_width() // 2, 30))
|
|
subtitle = self.small.render("a procedural pixel roguelike", True, UI_TEXT_DIM)
|
|
self.screen.blit(subtitle, (cx - subtitle.get_width() // 2, 200))
|
|
|
|
y = 260
|
|
for index, item in enumerate(flow.menu_items):
|
|
selected = index == flow.menu_index
|
|
label = self.mid.render(item, True, STAIRS_YELLOW if selected else UI_TEXT)
|
|
x = cx - label.get_width() // 2
|
|
self.screen.blit(label, (x, y))
|
|
if selected:
|
|
cursor = self.mid.render(">", True, STAIRS_YELLOW)
|
|
self.screen.blit(cursor, (x - 28, y))
|
|
y += 40
|
|
hint = self.small.render("arrows to choose, Enter to confirm", True, UI_TEXT_DIM)
|
|
self.screen.blit(hint, (cx - hint.get_width() // 2, SCREEN_H - 30))
|
|
|
|
def _draw_howto(self, flow: GameFlow) -> None:
|
|
cx = SCREEN_W // 2
|
|
y = 70
|
|
for text, highlight in HOWTO_LINES:
|
|
font = self.mid if highlight and text == "HOW TO PLAY" else self.font
|
|
label = font.render(
|
|
text, True, STAIRS_YELLOW if highlight else UI_TEXT
|
|
)
|
|
self.screen.blit(label, (cx - label.get_width() // 2, y))
|
|
y += 28 if text else 14
|
|
if flow.session is None:
|
|
note = self.small.render("(menu)", True, UI_TEXT_DIM)
|
|
self.screen.blit(note, (cx - 12, y + 4))
|
|
|
|
def _draw_game_over(self, flow: GameFlow) -> None:
|
|
session = flow.session
|
|
assert session is not None
|
|
cx = SCREEN_W // 2
|
|
if flow.screen == DEAD:
|
|
title = self.big.render("YOU DIED", True, (220, 70, 60))
|
|
line1 = self.mid.render(
|
|
f"You died on floor {session.current_floor + 1}.", True, UI_TEXT
|
|
)
|
|
line2 = self.mid.render(
|
|
f"You reached level {session.player.level}.", True, UI_TEXT
|
|
)
|
|
else:
|
|
title = self.big.render("VICTORY!", True, STAIRS_YELLOW)
|
|
line1 = self.mid.render("You slew the Ancient Dragon!", True, STAIRS_YELLOW)
|
|
line2 = self.mid.render("You conquered Underdepths.", True, STAIRS_YELLOW)
|
|
self.screen.blit(title, (cx - title.get_width() // 2, 120))
|
|
self.screen.blit(line1, (cx - line1.get_width() // 2, 220))
|
|
self.screen.blit(line2, (cx - line2.get_width() // 2, 260))
|
|
hint = self.font.render("Press any key to return to the menu", True, UI_TEXT_DIM)
|
|
self.screen.blit(hint, (cx - hint.get_width() // 2, 340))
|
|
|
|
def _draw_list(self, flow: GameFlow) -> None:
|
|
session = flow.session
|
|
assert session is not None
|
|
items, _ = flow._list_target()
|
|
panel = pygame.Rect(
|
|
60, TOP_BAR_H + 40, VIEW_TILES_W * TILE_SIZE - 120, VIEW_TILES_H * TILE_SIZE - 80
|
|
)
|
|
shade = pygame.Surface(panel.size, pygame.SRCALPHA)
|
|
shade.fill((0, 0, 0, 140))
|
|
self.screen.blit(shade, panel.topleft)
|
|
_draw_panel(self.screen, panel)
|
|
title = self.mid.render(LIST_TITLES.get(flow.screen, flow.screen.upper()), True, STAIRS_YELLOW)
|
|
self.screen.blit(title, (panel.x + 16, panel.y + 10))
|
|
pygame.draw.line(
|
|
self.screen, UI_BORDER_DARK,
|
|
(panel.x + 12, panel.y + 40), (panel.right - 12, panel.y + 40),
|
|
)
|
|
|
|
letters = "abcdefghijklmnopqrstuvwxyz"
|
|
y = panel.y + 52
|
|
row = 0
|
|
if not items:
|
|
self.screen.blit(self.font.render("(nothing here)", True, UI_TEXT_DIM), (panel.x + 20, y))
|
|
for index, item in enumerate(items):
|
|
selected = index == flow.selection
|
|
if selected:
|
|
highlight = pygame.Rect(panel.x + 10, y - 2, panel.w - 20, 26)
|
|
pygame.draw.rect(self.screen, (40, 38, 30), highlight)
|
|
cursor = self.font.render(">", True, STAIRS_YELLOW)
|
|
self.screen.blit(cursor, (panel.x + 14, y))
|
|
letter = letters[index] if index < len(letters) else " "
|
|
prefix = f"{letter}) "
|
|
x = panel.x + 34
|
|
if item is not None:
|
|
key = sprite_render.item_sprite_key(item.key, item.sprite_key)
|
|
icon = pygame.transform.scale(sprite_render.get_sprite(key), (18, 18))
|
|
self.screen.blit(icon, (x, y))
|
|
x += 26
|
|
stats = ""
|
|
if item.category == "weapon":
|
|
stats = f" power +{item.power}"
|
|
elif item.category == "armor":
|
|
stats = f" armor {item.armor}"
|
|
elif item.category == "potion":
|
|
stats = " drink"
|
|
elif item.category == "scroll":
|
|
stats = " read"
|
|
text = f"{prefix}{item.name}{stats}"
|
|
else:
|
|
text = f"{prefix}(empty)"
|
|
self.screen.blit(
|
|
self.font.render(text, True, UI_TEXT if item else UI_TEXT_DIM), (x, y + 2)
|
|
)
|
|
y += 28
|
|
row += 1
|
|
if row >= 16:
|
|
break
|
|
hint = self.small.render("letter selects, Esc closes", True, UI_TEXT_DIM)
|
|
self.screen.blit(hint, (panel.x + 16, panel.bottom - 24))
|