# Arup Guha and Erick Verlangieli
# Updated 6/14/2024 for multifile object dot game with multiple screens.

import random
import math
import time
import dotconsts
import dotfunctions
import pygame, sys
from pygame.locals import *

def options():
    running = True

    # If you click escape, it will default to lime as the dot color.
    color = dotconsts.LIME

    # Create a Font object from the system fonts. I chose size 100.
    font = pygame.font.SysFont(None, 100)

    # Create an object to help track time
    clock = pygame.time.Clock()

    # Created buttons. X, Y, Width, Height.
    button_1 = pygame.Rect(350, 150, 300, 80)
    button_2 = pygame.Rect(350, 300, 300, 80)
    button_3 = pygame.Rect(350, 450, 300, 80)

    # Creates a screen with width and height.
    screen = pygame.display.set_mode((dotconsts.SCREEN_W, dotconsts.SCREEN_H))

    while running:

        # Fill surface with a solid color, I chose black.
        screen.fill("black")

        dotfunctions.draw('Color Options', font, (255, 255, 255), screen, 250, 20)

        # Draws the buttons
        pygame.draw.rect(screen, "red", button_1)
        pygame.draw.rect(screen, "green", button_2)
        pygame.draw.rect(screen, "blue", button_3)

        # Creates and draws text on buttons.
        dotfunctions.draw('Red', font, (255, 255, 255), screen, 430, 160)
        dotfunctions.draw('Green', font, (255, 255, 255), screen, 400, 310)
        dotfunctions.draw('Blue', font, (255, 255, 255), screen, 420, 460)

        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 event.key == K_ESCAPE:
                    running = False

            # 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:

                    # Get mouse position x and y.
                    mx, my = pygame.mouse.get_pos()

                    # If mouse location is inside this rectangle.
                    if button_1.collidepoint((mx, my)):
                        color = dotconsts.RED
                        running = False

                    # If mouse location is inside this rectangle.
                    if button_2.collidepoint((mx, my)):
                        color = dotconsts.GREEN
                        running = False

                    # If mouse location is inside this rectangle.
                    if button_3.collidepoint((mx, my)):
                        color = dotconsts.BLUE
                        running = False

        # 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)

    return color

