import pygame, math

#Font Used: https://fontenddev.com/fonts/digital-disco/
#Font License Info: https://creativecommons.org/licenses/by/4.0/

pygame.font.init()

font = pygame.font.Font("./fonts/DigitalDisco.ttf", 24)
size = 24
window = None
color = [0,0,0]

def FontInit(s, w):
    global font, size, window
    font = pygame.font.Font("./fonts/DigitalDisco.ttf", s)
    size = s
    window = w

def Font(s):
    global font, size
    font = pygame.font.Font("./fonts/DigitalDisco.ttf", s)
    size = s

def Box(dim, pos, centered=False, color=[0,0,0]):
    box = pygame.surface.Surface(list(dim))
    box.fill(list(color))
    box.set_alpha(192)
    if centered:
        cpos = pos[0] - box.get_rect().width/2, pos[1] - box.get_rect().height/2
        window.blit(box, list(cpos))
    else:
        window.blit(box, list(pos))

def Text(text, pos, centered=False):
    render = font.render(str(text), 1, color)
    if centered:
        cpos = pos[0] - render.get_rect().width/2, pos[1] - render.get_rect().height/2
        window.blit(render, list(cpos))
    else:
        window.blit(render, list(pos))

def TextR(text, pos, centered=False):
    render = font.render(str(text), 1, color)
    if centered:
        cpos = pos[0] - render.get_rect().width/2, pos[1] - render.get_rect().height/2
        window.blit(render, list(cpos))
    else:
        window.blit(render, list(pos))
    return render.get_rect()

class Button(pygame.sprite.Sprite):
    def __init__(self, text, pos, centered=False, hcolor=None, bkgcolor=[0,0,0]):
        pygame.sprite.Sprite.__init__(self)
        self.otext = font.render(str(text), 1, color)
        if hcolor==None: hcolor = color
        self.htext = font.render(str(text), 1, hcolor)
        self.rect = self.otext.get_rect()
        self.size = self.rect.width+10, self.rect.height+10
        self.bkg = pygame.surface.Surface(self.size)
        self.bkg.fill(bkgcolor)
        self.bkg.set_alpha(128)
        self.bkg2 = pygame.surface.Surface(self.size)
        self.bkg2.fill(bkgcolor)
        self.bkg2.set_alpha(192)
        self.image = pygame.surface.Surface(self.size)
        self.image.blit(self.bkg, [0,0])
        self.image.blit(self.otext, [5,5])
        if centered:
            self.rect.center = list(pos)
        else:
            self.rect.topleft = list(pos)
    def click(self, mouse):
        c=False
        if self.rect.collidepoint(mouse):
            c=True
        return c
    def update(self, mouse): #highlights
        self.image = pygame.surface.Surface(self.size)
        self.image.blit(self.bkg, [0, 0])
        self.image.blit(self.otext, [5, 5])
        self.image.set_alpha(192)
        if self.rect.collidepoint(mouse):
            self.image = pygame.surface.Surface(self.size)
            self.image.blit(self.bkg2, [0, 0])
            self.image.blit(self.htext, [5, 5])
            self.image.set_alpha(255)
    def draw(self):
        global window
        window.blit(self.image, self.rect.topleft)

class Effect(pygame.sprite.Sprite):
    def __init__(self, text, pos, duration=1, color=[255, 255, 255], centered=True, velocity=1):
        pygame.sprite.Sprite.__init__(self)
        self.image = font.render(str(text), 1, color)
        self.rect = self.image.get_rect()
        if centered:
            self.rect.center = list(pos)
        else:
            self.rect.topleft = list(pos)
        self.velocity = 1
        self.pos = self.rect.center
        self.duration = duration
        self.velocity
    def update(self, clock):
        self.pos[1] += clock.get