# Arup Guha
# Sushi Game with High Score List - example for SI@UCF
# 6/21/2023
# Updated on 6/23/2025

import sushifunctions
import pygame, sys
import time
from pygame.locals import *

SCREEN_W = 1000
SCREEN_H = 600

# Initialize all imported pygame modules.
pygame.init()
# Create a custom caption that will be displayed on the top of your window of your game.
pygame.display.set_caption('Sushi Game!')

# Create a Font object from the system fonts. I chose size 100.
font = pygame.font.SysFont(None, 45)
bigfont = pygame.font.SysFont(None, 60)

# Create an object to help track time
clock = pygame.time.Clock()

def menu():

    # Creates a screen with width and height.
    screen = pygame.display.set_mode((SCREEN_W, SCREEN_H))

# Created buttons. X, Y, Width, Height.
    button_1 = pygame.Rect(300, 100, 400, 100)
    button_2 = pygame.Rect(300, 250, 400, 100)
    button_3 = pygame.Rect(300, 400, 400, 100)
        
    # While true, so infinite loop.
    while True:

        # Fill surface with a solid color, I chose black.
        screen.fill((0, 0, 0))

        # Get mouse position x and y.
        mx, my = pygame.mouse.get_pos()

        # Refers to the draw_text function I made above.
        # Requires text, font, color, surface, x, y.
        # This is how we draw text to screen. IMPORTANT!!
        sushifunctions.draw('Menu', bigfont, (255, 255, 255), screen, 450, 30)

        # Draws buttons onto screen
        pygame.draw.rect(screen, (192,192,192), button_1)
        pygame.draw.rect(screen, (147,112,219), button_2)
        pygame.draw.rect(screen, (0,200,200), button_3)

        # Creates and draws text on buttons.
        sushifunctions.draw('Play Game', font, (255, 255, 255), screen, 420, 135)
        sushifunctions.draw('Display Leaderboard', font, (255, 255, 255), screen, 350, 285)
        sushifunctions.draw('Quit', font, (255, 255, 255), screen, 470, 435)
        
        # Get events from the queue
        for event in pygame.event.get():

            # If you close the game.
            if event.type == QUIT:
                pygame.quit()
                sys.exit()

            # If you press down a key.
            if event.type == KEYDOWN:
                # If that key was the escape button do this.
                if event.key == K_ESCAPE:
                    pygame.quit()
                    sys.exit()

            # If you click on screen.
            if event.type == MOUSEBUTTONDOWN:
                # 1 - left click, 2 - middle click, 3 - right click, 4 - scroll up, 5 - scroll down
                if event.button == 1:
                    
                    # Activate game.
                    if button_1.collidepoint((mx, my)):

                        #name = input("Enter your name.\n")
                        
                        name = sushifunctions.getname()
                        myScore = sushifunctions.playgame(name)
                        sushifunctions.updateScores("highscores.txt",[myScore,name])

                    # Show leaderboard.
                    if button_2.collidepoint((mx, my)):
                        sushifunctions.showhighscores("highscores.txt")

                    # Get out.
                    if button_3.collidepoint((mx, my)):
                        pygame.quit()
                        sys.exit()

        # Update portions of the screen for software displays
        pygame.display.update()

        # Update the clock in milliseconds. Should be called once per frame.
        clock.tick(60)

# Loads main menu.
menu()
