#!/usr/bin/python3

import sys
import random

import pygame
from settings import Settings
from sailor_moon import Moon_Walk
from sailor_moon import Wand
from sailor_mars import Mars_Up_Dog
from sailor_mars import Mars_Gauge
from sailor_venus import Venus_Cakes
from sailor_venus import Venus_Gauge
from display_load import Display_Cpu_Temp_Text
from display_load import Display_Cpu_Load_Text
from display_load import Display_Memory_Text
from display_load import Display_Disk_Text
from load import Load

#we imported load here so take it out of sailormoon and flow the load info into sailormoon
class Cpu_Temp_Spec:
    def __init__(self):
        pygame.init()

        self.clock = pygame.time.Clock()
        
        #flags
        self.walking = True
        self.delay = 0

        #settings
        self.settings = Settings()

        #screens
        self.screen = pygame.display.set_mode((self.settings.screen_width, self.settings.screen_height))
        self.screen_rect = self.screen.get_rect()
        
        #background
        self.background_animation = []
        self.background_animation.append(pygame.image.load('backgrounds/gibson1-1.png'))
        self.background_animation.append(pygame.image.load('backgrounds/gibson1-2.png'))
        self.background_animation.append(pygame.image.load('backgrounds/gibson1-3.png'))
        self.background_animation.append(pygame.image.load('backgrounds/gibson1-4.png'))
        self.background_animation.append(pygame.image.load('backgrounds/gibson1-5.png'))
        self.background_animation.append(pygame.image.load('backgrounds/gibson1-6.png'))
        self.background_animation.append(pygame.image.load('backgrounds/gibson1-7.png'))
        self.current_background = 0
        self.image = self.background_animation[self.current_background]
        self.rect = self.image.get_rect()
        self.animation = False

        #sprites
        self.sailor_moon_gauge_sprite = pygame.sprite.Group()
        self.sailor_moon_walking_sprite = pygame.sprite.Group()
        self.moon_walk = Moon_Walk(self)
        self.moon_wand = Wand(self)
        self.sailor_moon_walking_sprite.add(self.moon_walk)
        self.sailor_moon_gauge_sprite.add(self.moon_wand)

        #modules
        self.load = Load()
        self.display_cpu_text = Display_Cpu_Temp_Text(self)
        self.display_cpu_text.prep_text(self.load)

    def _key_down(self, event):
        if event.key == pygame.K_q:
            sys.exit()
        elif event.key == pygame.K_e:
            self.walking = False
       

    def check_events(self):
        """checks for events"""
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                sys.exit()
            elif event.type == pygame.KEYDOWN:
                self._key_down(event)

    def _random_number_checker(self):
        if self.animation == False:
            random_number = random.randrange(25)
            if random_number == 5:
                self.animation = True

    def _animation(self):
        self.image = self.background_animation[self.current_background]
        self.current_background += 1
        if self.current_background >= len(self.background_animation):
            self.current_background = 0
            self.animation = False


    def background_update(self):
        self._random_number_checker()
        if self.animation == False:
            self.image = self.background_animation[self.current_background]
        elif self.animation == True:
            self._animation()

    def update_text(self):
        self.display_cpu_text.update_cpu_temp(self.load)
        self.delay += 1
        if self.delay == 7:
            self.display_cpu_text.update_text(self.load)
            self.delay = 0
        self.display_cpu_text.show_text()


    def update_screen(self):
        """updates the screen"""
        self.screen.fill(self.settings.screen_color)
        self.background_update()
        self.screen.blit(self.image, self.rect)
        self.sailor_moon_walking_sprite.draw(self.screen)
        self.sailor_moon_gauge_sprite.draw(self.screen)
        self.update_text()
        pygame.display.flip()

    def run_walk(self):
        """main loop"""
        while self.walking == True:
            self.check_events()
            self.load.load_update()
            self.sailor_moon_walking_sprite.update()
            self.sailor_moon_gauge_sprite.update(self)
            self.update_screen()
            self.clock.tick(4)

class Cpu_Load_Spec:
    def __init__(self):
        pygame.init()

        self.clock = pygame.time.Clock()
        
        #flags
        self.up_dog = True
        self.delay = 0

        #settings
        self.settings = Settings()

        #screens
        self.screen = pygame.display.set_mode((self.settings.screen_width, self.settings.screen_height))
        self.screen_rect = self.screen.get_rect()
        
        #background
        self.background_animation = []
        self.background_animation.append(pygame.image.load('backgrounds/gibson1-1.png'))
        self.background_animation.append(pygame.image.load('backgrounds/gibson1-2.png'))
        self.background_animation.append(pygame.image.load('backgrounds/gibson1-3.png'))
        self.background_animation.append(pygame.image.load('backgrounds/gibson1-4.png'))
        self.background_animation.append(pygame.image.load('backgrounds/gibson1-5.png'))
        self.background_animation.append(pygame.image.load('backgrounds/gibson1-6.png'))
        self.background_animation.append(pygame.image.load('backgrounds/gibson1-7.png'))
        self.current_background = 0
        self.image = self.background_animation[self.current_background]
        self.rect = self.image.get_rect()
        self.animation = False

        #sprites
        self.sailor_mars_gauge_sprite = pygame.sprite.Group()
        self.sailor_mars_up_dog_sprite = pygame.sprite.Group()
        self.mars_up_dog = Mars_Up_Dog(self)
        self.mars_gauge = Mars_Gauge(self)
        self.sailor_mars_up_dog_sprite.add(self.mars_up_dog)
        self.sailor_mars_gauge_sprite.add(self.mars_gauge)

        #modules
        self.load = Load()
        self.display_cpu_text = Display_Cpu_Load_Text(self)
        self.display_cpu_text.prep_text(self.load)

    def _key_down(self, event):
        if event.key == pygame.K_q:
            sys.exit()
        elif event.key == pygame.K_e:
            self.up_dog = False
       

    def check_events(self):
        """checks for events"""
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                sys.exit()
            elif event.type == pygame.KEYDOWN:
                self._key_down(event)

    def _random_number_checker(self):
        if self.animation == False:
            random_number = random.randrange(25)
            if random_number == 5:
                self.animation = True

    def _animation(self):
        self.image = self.background_animation[self.current_background]
        self.current_background += 1
        if self.current_background >= len(self.background_animation):
            self.current_background = 0
            self.animation = False


    def background_update(self):
        self._random_number_checker()
        if self.animation == False:
            self.image = self.background_animation[self.current_background]
        elif self.animation == True:
            self._animation()

    def update_text(self):
        self.display_cpu_text.update_cpu_temp(self.load)
        self.delay += 1
        if self.delay == 7:
            self.display_cpu_text.update_text(self.load)
            self.delay = 0
        self.display_cpu_text.show_text()


    def update_screen(self):
        """updates the screen"""
        self.screen.fill(self.settings.screen_color)
        self.background_update()
        self.screen.blit(self.image, self.rect)
        self.sailor_mars_up_dog_sprite.draw(self.screen)
        self.sailor_mars_gauge_sprite.draw(self.screen)
        self.update_text()
        pygame.display.flip()

    def up_dog_loop(self):
        """main loop"""
        while self.up_dog == True:
            self.check_events()
            self.load.load_update()
            self.sailor_mars_up_dog_sprite.update()
            self.sailor_mars_gauge_sprite.update(self)
            self.update_screen()
            self.clock.tick(4)


class Memory_Load_Spec:
    def __init__(self):
        pygame.init()

        self.clock = pygame.time.Clock()
        
        #flags
        self.major_cakes = True
        self.delay = 0

        #settings
        self.settings = Settings()

        #screens
        self.screen = pygame.display.set_mode((self.settings.screen_width, self.settings.screen_height))
        self.screen_rect = self.screen.get_rect()
        
        #background
        self.background_animation = []
        self.background_animation.append(pygame.image.load('backgrounds/gibson1-1.png'))
        self.background_animation.append(pygame.image.load('backgrounds/gibson1-2.png'))
        self.background_animation.append(pygame.image.load('backgrounds/gibson1-3.png'))
        self.background_animation.append(pygame.image.load('backgrounds/gibson1-4.png'))
        self.background_animation.append(pygame.image.load('backgrounds/gibson1-5.png'))
        self.background_animation.append(pygame.image.load('backgrounds/gibson1-6.png'))
        self.background_animation.append(pygame.image.load('backgrounds/gibson1-7.png'))
        self.current_background = 0
        self.image = self.background_animation[self.current_background]
        self.rect = self.image.get_rect()
        self.animation = False

        #sprites
        self.sailor_venus_gauge_sprite = pygame.sprite.Group()
        self.sailor_venus_cakes_sprite = pygame.sprite.Group()
        self.venus_cakes = Venus_Cakes(self)
        self.venus_gauge = Venus_Gauge(self)
        self.sailor_venus_cakes_sprite.add(self.venus_cakes)
        self.sailor_venus_gauge_sprite.add(self.venus_gauge)

        #modules
        self.load = Load()
        self.display_memory_text = Display_Memory_Text(self)
        self.display_memory_text.prep_text(self.load)

    def _key_down(self, event):
        if event.key == pygame.K_q:
            sys.exit()
        elif event.key == pygame.K_e:
            self.major_cakes = False
       

    def check_events(self):
        """checks for events"""
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                sys.exit()
            elif event.type == pygame.KEYDOWN:
                self._key_down(event)

    def _random_number_checker(self):
        if self.animation == False:
            random_number = random.randrange(25)
            if random_number == 5:
                self.animation = True

    def _animation(self):
        self.image = self.background_animation[self.current_background]
        self.current_background += 1
        if self.current_background >= len(self.background_animation):
            self.current_background = 0
            self.animation = False


    def background_update(self):
        self._random_number_checker()
        if self.animation == False:
            self.image = self.background_animation[self.current_background]
        elif self.animation == True:
            self._animation()

    def update_text(self):
        self.display_memory_text.update_memory(self.load)
        self.delay += 1
        if self.delay == 7:
            self.display_memory_text.update_text(self.load)
            self.delay = 0
        self.display_memory_text.show_text()


    def update_screen(self):
        """updates the screen"""
        self.screen.fill(self.settings.screen_color)
        self.background_update()
        self.screen.blit(self.image, self.rect)
        self.sailor_venus_cakes_sprite.draw(self.screen)
        self.sailor_venus_gauge_sprite.draw(self.screen)
        self.update_text()
        pygame.display.flip()

    def major_cakes_loop(self):
        """main loop"""
        while self.major_cakes == True:
            self.check_events()
            self.load.load_update()
            self.sailor_venus_cakes_sprite.update()
            self.sailor_venus_gauge_sprite.update(self)
            self.update_screen()
            self.clock.tick(4)

class Disk_Usage_Spec:
    def __init__(self):
        pygame.init()

        self.clock = pygame.time.Clock()
        
        #flags
        self.mercury_office = True
        self.delay = 0

        #settings
        self.settings = Settings()

        #screens
        self.screen = pygame.display.set_mode((self.settings.screen_width, self.settings.screen_height))
        self.screen_rect = self.screen.get_rect()
        
        #background
        self.background_animation = []
        self.background_animation.append(pygame.image.load('backgrounds/gibson1-1.png'))
        self.background_animation.append(pygame.image.load('backgrounds/gibson1-2.png'))
        self.background_animation.append(pygame.image.load('backgrounds/gibson1-3.png'))
        self.background_animation.append(pygame.image.load('backgrounds/gibson1-4.png'))
        self.background_animation.append(pygame.image.load('backgrounds/gibson1-5.png'))
        self.background_animation.append(pygame.image.load('backgrounds/gibson1-6.png'))
        self.background_animation.append(pygame.image.load('backgrounds/gibson1-7.png'))
        self.current_background = 0
        self.image = self.background_animation[self.current_background]
        self.rect = self.image.get_rect()
        self.animation = False

        #sprites

        #modules
        self.load = Load()
        self.display_disk_text = Display_Disk_Text(self)
        self.display_disk_text.prep_text(self.load)

    def _key_down(self, event):
        if event.key == pygame.K_q:
            sys.exit()
        elif event.key == pygame.K_e:
            self.mercury_office = False

    def check_events(self):
        """checks for events"""
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                sys.exit()
            elif event.type == pygame.KEYDOWN:
                self._key_down(event)

    def update_screen(self):
        """updates the screen"""
        self.screen.fill(self.settings.screen_color)
        self.display_disk_text.prep_text(self.load)
        self.display_disk_text.show_text()
        #self.background_update()
        #self.screen.blit(self.image, self.rect)
        #self.update_text()
        pygame.display.flip()

    def mercury_office_loop(self):
        """main loop"""
        while self.mercury_office == True:
            self.check_events()
            self.load.load_update()
            self.update_screen()
            self.clock.tick(4)

