import pygame
import sys
import math

pygame.init()

W, H = 1200, 700
screen = pygame.display.set_mode((W, H))
pygame.display.set_caption("Delta Action | Pygame")
clock = pygame.time.Clock()
FPS = 60

# 配色：三角洲暗军风
BG_COLOR = (12, 15, 18)
PANEL_BG = (22, 28, 34)
LINE_COLOR = (60, 110, 135)
GLOW_COLOR = (75, 180, 210)
TEXT_COLOR = (220, 235, 245)
HOVER_COLOR = (100, 210, 240)

# ========== 重点修改：不用微软雅黑，用默认字体 ==========
font_lg = pygame.font.Font(None, 48)
font_md = pygame.font.Font(None, 28)
font_sm = pygame.font.Font(None, 20)

buttons = [
    {"text": "START",    "rect": pygame.Rect(820, 180, 260, 60)},
    {"text": "OPERATOR", "rect": pygame.Rect(820, 260, 260, 60)},
    {"text": "STORAGE",  "rect": pygame.Rect(820, 340, 260, 60)},
    {"text": "SETTING",  "rect": pygame.Rect(820, 420, 260, 60)},
    {"text": "EXIT",     "rect": pygame.Rect(820, 500, 260, 60)},
]

angle = 0  # 雷达旋转角度

def draw_hud_box(surf, rect, glow=False):
    """绘制带发光效果的HUD面板"""
    pygame.draw.rect(surf, PANEL_BG, rect, border_radius=6)
    c = GLOW_COLOR if glow else LINE_COLOR
    pygame.draw.rect(surf, c, rect, width=2, border_radius=6)

def draw_radar(surf, cx, cy, r, ang):
    """旋转雷达扫描线"""
    pygame.draw.circle(surf, LINE_COLOR, (cx, cy), r, 2)
    pygame.draw.circle(surf, (35,70,90), (cx, cy), r//2, 1)
    pygame.draw.circle(surf, (35,70,90), (cx, cy), r//4, 1)
    # 扫描线
    end_x = cx + r * math.cos(math.radians(ang))
    end_y = cy + r * math.sin(math.radians(ang))
    pygame.draw.line(surf, GLOW_COLOR, (cx, cy), (end_x, end_y), 2)

def draw_button(surf, btn, hover):
    r = btn["rect"]
    draw_hud_box(surf, r, glow=hover)
    color = HOVER_COLOR if hover else TEXT_COLOR
    t = font_md.render(btn["text"], True, color)
    tr = t.get_rect(center=r.center)
    surf.blit(t, tr)

running = True
while running:
    mouse_pos = pygame.mouse.get_pos()

    for e in pygame.event.get():
        if e.type == pygame.QUIT:
            running = False
        if e.type == pygame.MOUSEBUTTONDOWN and e.button == 1:
            for b in buttons:
                if b["rect"].collidepoint(mouse_pos):
                    if b["text"] == "EXIT":
                        running = False
                    else:
                        print(f"Click: {b['text']}")

    screen.fill(BG_COLOR)

    # 标题面板
    title_rect = pygame.Rect(60, 40, 620, 110)
    draw_hud_box(screen, title_rect, glow=True)
    title = font_lg.render("DELTA ACTION", True, GLOW_COLOR)
    screen.blit(title, title.get_rect(center=title_rect.center))

    # 雷达
    draw_radar(screen, 370, 320, 140, angle)
    angle += 0.6
    if angle > 360:
        angle = 0

    # 左下角信息面板
    info_rect = pygame.Rect(60, 480, 360, 160)
    draw_hud_box(screen, info_rect)
    lines = ["[ TACTICAL REPORT ]", "SIGNAL: STABLE", "SUPPLY: ADEQUATE", "ZONE: 07"]
    for i, line in enumerate(lines):
        txt = font_sm.render(line, True, TEXT_COLOR)
        screen.blit(txt, (info_rect.x + 18, info_rect.y + 16 + i * 32))

    # 右侧按钮
    for b in buttons:
        is_hover = b["rect"].collidepoint(mouse_pos)
        draw_button(screen, b, is_hover)

    pygame.display.flip()
    clock.tick(FPS)

pygame.quit()
sys.exit()
