def secondscreen():

    #intro = True

    #while intro:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            quit()
        if event.type == pygame.MOUSEBUTTONDOWN:
            if player1.pressed():
                config.window="PlayerNameMenu"
                config.numofplayers = 1
            if player2.pressed():
                config.window="PlayerNameMenu"
                config.numofplayers = 2
            if player3.pressed():
                config.window="PlayerNameMenu"
                config.numofplayers = 3
            if player4.pressed():
                config.window="PlayerNameMenu"
                config.numofplayers = 4
            if MainMenu.pressed():
                config.window="MainMenu"               

    Graphics_game.draw_background()
    player1.draw(1000,300,config.setDisplay)
    MainMenu.draw(135,830,config.setDisplay)
    player2.draw(1115,300,config.setDisplay)
    player3.draw(1000,415,config.setDisplay)
    player4.draw(1115,415,config.setDisplay)
    HowMany.draw(915,200,config.setDisplay)
    #Graphics_game.draw_socialmedia((1200,800))
    largeText = pygame.font.SysFont("algerian",90)
    TextSurf, TextRect = text_objects("Frequency", largeText)
    TextRect.center = ((display_width/4),(display_height/6))

    config.setDisplay.blit(TextSurf, TextRect)


   # button("New Game",500,450,500,150,green,bright_green,secondscreen)
   # button("Quit",780,780,100,100,red,bright_red,quitgame)
   # button("Load Game",600,650,300,80,yellow,bright_yellow,quitgame)
   # button("Settings",620,780,100,100,blue,bright_blue,quitgame)
        
    #pygame.draw.rect(gameDisplay, red, (500,450,100,50))
    #if 500+100 > mouse[0] > 500 and 450+50 > mouse[1] > 450:
        #pygame.draw.rect(gameDisplay, bright_red, (500,450,100,50))
    #else:
        #pygame.draw.rect(gameDisplay, red, (500,450,100,50))

    #pygame.display.update()
    #clock.tick(15)

#game_intro()
#pygame.quit()
#quit()
#
def game_intro():
    
    #intro = True

    #while intro:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            quit()
        if event.type == pygame.MOUSEBUTTONDOWN:
            if NewGame.pressed():
                config.window="PlayerMenu"
            if QuitGame.pressed():
                pygame.quit()
                quit()
            if Settings.pressed():
                config.window="SettingMenu"
            if LoadGame.pressed():
                Saving.load()
                config.window = "Main"
                config.firsttime = True


    #Music.MenuMusic()
    Graphics_game.draw_background()
    NewGame.draw(500,450,config.setDisplay)
    QuitGame.draw(765,780,config.setDisplay)
    LoadGame.draw(600,650,config.setDisplay)
    Settings.draw(615,780,config.setDisplay)
    #Graphics_game.draw_socialmedia((1200,800))
    largeText = pygame.font.SysFont("algerian",135)
    TextSurf, TextRect = text_objects("Frequency", largeText)
    TextRect.center = ((display_width/2),(display_height/3.5))
    config.setDisplay.blit(TextSurf, TextRect)

   # button("New Game",500,450,500,150,green,bright_green,secondscreen)
   # button("Quit",780,780,100,100,red,bright_red,quitgame)
   # button("Load Game",600,650,300,80,yellow,bright_yellow,quitgame)
   # button("Settings",620,780,100,100,blue,bright_blue,quitgame)
        
    #pygame.draw.rect(gameDisplay, red, (500,450,100,50))
    #if 500+100 > mouse[0] > 500 and 450+50 > mouse[1] > 450:
        #pygame.draw.rect(gameDisplay, bright_red, (500,450,100,50))
    #else:
        #pygame.draw.rect(gameDisplay, red, (500,450,100,50))

    #pygame.display.update()
    #clock.tick(15)

#game_intro()
#pygame.quit()
#quit()
def settingscreen():

    #intro = True

    #while intro:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            quit()
        if event.type == pygame.MOUSEBUTTONDOWN:
            if BGMOn.pressed():
                config.music = True
                Music.MenuMusic()
            if BGMOff.pressed():
                config.music = False
                pygame.mixer.music.stop()
            if MainMenu.pressed():
                config.window="MainMenu"
                config.firsttime = False                

    Graphics_game.draw_background()
    BGMOn.draw(1000,300,config.setDisplay)
    MainMenu.draw(135,830,config.setDisplay)
    BGMOff.draw(1115,300,config.setDisplay)
    BGMusic.draw(840,200,config.setDisplay)
    #Graphics_game.draw_socialmedia((1200,800))
    largeText = pygame.font.SysFont("algerian",90)
    TextSurf, TextRect = text_objects("Frequency", largeText)
    TextRect.center = ((display_width/4),(display_height/6))

    config.setDisplay.blit(TextSurf, TextRect)


   # button("New Game",500,450,500,150,green,bright_green,secondscreen)
   # button("Quit",780,780,100,100,red,bright_red,quitgame)
   # button("Load Game",600,650,300,80,yellow,bright_yellow,quitgame)
   # button("Settings",620,780,100,100,blue,bright_blue,quitgame)
        
    #pygame.draw.rect(gameDisplay, red, (500,450,100,50))
    #if 500+100 > mouse[0] > 500 and 450+50 > mouse[1] > 450:
        #pygame.draw.rect(gameDisplay, bright_red, (500,450,100,50))
    #else:
        #pygame.draw.rect(gameDisplay, red, (500,450,100,50))

    #pygame.display.update()
    #clock.tick(15)

#game_intro()
#pygame.quit()
#quit()
#
    if config.window == "PlayerNameMenu":
        PlayerNameMenu.thirdscreen()
    if config.window == "SettingMenu":
        SettingMenu.settingscreen()
    if config.window == "terminationmenu":
        EndingMenu.endscreen()



    if config.window == "Main":
        #if config.mapArray[7][1].troops != []:
        #    if config.mapArray[7][1].troops[0].troops != []:
        #        print(config.mapArray[7][1].troops[0].troops[0].Name)
        if config.firsttime:
            Music.GameMusic()
            Graphics_game.draw_background()
            Graphics_game.draw_logo((1000, 50))
            config.firsttime = False
        Graphics_game.draw_everything()
        if config.debug == True:
            Debug_screen.Draw((1000,0))
        Game_Logic.DrawTileInfo((600, 600))

        for event in pygame.event.get():
            #print(event)
            if event.type == pygame.QUIT:
                pygame.quit()
                sys.exit()
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_ESCAPE:
                    config.window = "Esc_Menu"
def thirdscreen():
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            quit()
        if event.type == pygame.MOUSEBUTTONDOWN:
            if Back.pressed():
                config.window="PlayerMenu"

            if startgame.pressed():
                config.window="Main"
                config.firsttime = True
                resetgame()
                if config.numofplayers >=1:
                    print("Player 1")
                    print(config.Playerlist)
                    Player_functions.PlayerCreation(playername1.text, playercolor1.bgcolor)
                    print("Player 1 appended")
                if config.numofplayers >=2:
                    print("Player 2")
                    print(config.Playerlist)
                    Player_functions.PlayerCreation(playername2.text, playercolor2.bgcolor)
                if config.numofplayers >=3:
                    print("Player 3")
                    print(config.Playerlist)
                    Player_functions.PlayerCreation(playername3.text, playercolor3.bgcolor)
                if config.numofplayers >=4:
                    print("Player 4")
                    print(config.Playerlist)
                    Player_functions.PlayerCreation(playername4.text, playercolor4.bgcolor)

            if config.numofplayers >=1:
                playername1.handlemousepress()
                player1colorR.handlemousepress()
                player1colorG.handlemousepress()
                player1colorB.handlemousepress()

            if config.numofplayers  >=2:
                playername2.handlemousepress()
                player2colorR.handlemousepress()
                player2colorG.handlemousepress()
                player2colorB.handlemousepress()

            if config.numofplayers  >=3:
                playername3.handlemousepress()
                player3colorR.handlemousepress()
                player3colorG.handlemousepress()
                player3colorB.handlemousepress()

            if config.numofplayers  >=4:
                playername4.handlemousepress()
                player4colorR.handlemousepress()
                player4colorG.handlemousepress()
                player4colorB.handlemousepress()

        if event.type == pygame.KEYDOWN:        #All keystrokes are handled here
            playername1.handle_char(event)
            playername2.handle_char(event)
            playername3.handle_char(event)
            playername4.handle_char(event)
            player1colorR.handle_char(event)
            player1colorG.handle_char(event)
            player1colorB.handle_char(event)
            player2colorR.handle_char(event)
            player2colorG.handle_char(event)
            player2colorB.handle_char(event)
            player3colorR.handle_char(event)
            player3colorG.handle_char(event)
            player3colorB.handle_char(event)
            player4colorR.handle_char(event)
            player4colorG.handle_char(event)
            player4colorB.handle_char(event)


    Graphics_game.draw_background()
    Back.draw(135,830,config.setDisplay)
    HowMany.draw(835,200,config.setDisplay)
    largeText = pygame.font.SysFont("algerian",90)
    TextSurf, TextRect = text_objects("Frequency", largeText)
    TextRect.center = ((display_width/4),(display_height/6))
    startgame.draw(835,830,config.setDisplay)
    

    if config.numofplayers >=1:
        playercolor1.bgcolor = calculate_color(player1colorR.text,player1colorG.text,player1colorB.text)    #sets the background color of the "player colour" bar into the calculated rgb
        playername1.draw((pos_name_boxX, pos_name_boxY))                                                    #draws the player name menu
        player1colorR.draw((pos_name_boxX+width_textbox, pos_name_boxY))                                    #Draws the red textbar
        player1colorG.draw((pos_name_boxX+width_textbox+width_color_box, pos_name_boxY))                    #Draws the green textbar
        player1colorB.draw((pos_name_boxX+width_textbox+2*width_color_box, pos_name_boxY))                  #Draws the blue textbar
        playercolor1.draw((pos_name_boxX+width_textbox+3*width_color_box, pos_name_boxY))                   #
    if config.numofplayers  >=2:
        playercolor2.bgcolor = calculate_color(player2colorR.text,player2colorG.text,player2colorB.text) 
        playername2.draw((pos_name_boxX, pos_name_boxY+25))
        player2colorR.draw((pos_name_boxX+width_textbox, pos_name_boxY+25))
        player2colorG.draw((pos_name_boxX+width_textbox+width_color_box, pos_name_boxY+25))
        player2colorB.draw((pos_name_boxX+width_textbox+2*width_color_box, pos_name_boxY+25))
        playercolor2.draw((pos_name_boxX+width_textbox+3*width_color_box, pos_name_boxY+25))
    if config.numofplayers  >=3:
        playercolor3.bgcolor = calculate_color(player3colorR.text,player3colorG.text,player3colorB.text) 
        playername3.draw((pos_name_boxX, pos_name_boxY+50))
        player3colorR.draw((pos_name_boxX+width_textbox, pos_name_boxY+50))
        player3colorG.draw((pos_name_boxX+width_textbox+width_color_box, pos_name_boxY+50))
        player3colorB.draw((pos_name_boxX+width_textbox+2*width_color_box, pos_name_boxY+50))
        playercolor3.draw((pos_name_boxX+width_textbox+3*width_color_box, pos_name_boxY+50))
    if config.numofplayers  >=4:
        playercolor4.bgcolor = calculate_color(player4colorR.text,player4colorG.text,player4colorB.text) 
        playername4.draw((pos_name_boxX, pos_name_boxY+75))
        player4colorR.draw((pos_name_boxX+width_textbox, pos_name_boxY+75))
        player4colorG.draw((pos_name_boxX+width_textbox+width_color_box, pos_name_boxY+75))
        player4colorB.draw((pos_name_boxX+width_textbox+2*width_color_box, pos_name_boxY+75))
        playercolor4.draw((pos_name_boxX+width_textbox+3*width_color_box, pos_name_boxY+75))
    
    

    config.setDisplay.blit(TextSurf, TextRect)


   # button("New Game",500,450,500,150,green,bright_green,secondscreen)
   # button("Quit",780,780,100,100,red,bright_red,quitgame)
   # button("Load Game",600,650,300,80,yellow,bright_yellow,quitgame)
   # button("Settings",620,780,100,100,blue,bright_blue,quitgame)
        
    #pygame.draw.rect(gameDisplay, red, (500,450,100,50))
    #if 500+100 > mouse[0] > 500 and 450+50 > mouse[1] > 450:
        #pygame.draw.rect(gameDisplay, bright_red, (500,450,100,50))
    #else:
        #pygame.draw.rect(gameDisplay, red, (500,450,100,50))

    #pygame.display.update()
    #clock.tick(15)

#game_intro()
#pygame.quit()
#quit()