"""
level intro
"""


import sys

from OpenGL.GL import *
from OpenGL.GLU import *
import pygame, pygame.image
from pygame.locals import *

import texMgr
import draw_util
import gui_widgets as gw

import fsm_mgr as fsm
import tubeMgr

import levels

import voiceover


def func_play(level_name):
    fsm.popState()


bsz=256
bc1=400

br1 = 300

buttons=[gw.Button("button_keys",        bc1-bsz, br1+bsz, bc1+bsz, br1-bsz, func_play, "tutorial_1"),
         ]


introDict={
    "tutorial_1": ("data/level_intros/tutorial_1.png", "tutorial_1"),
    "tutorial_2": ("data/level_intros/tutorial_2.png", "tutorial_2"),
    "tutorial_3": ("data/level_intros/tutorial_3.png", "tutorial_3"),
    "tutorial_4": ("data/level_intros/tutorial_4.png", "tutorial_4"),

    "blake_1": ("data/level_intros/blake_1.png", "intro_blake_1"),
    "blake_2": ("data/level_intros/blake_2.png", "intro_blake_2"),
    "blake_3": ("data/level_intros/blake_3.png", "intro_blake_3"),
    "blake_4": ("data/level_intros/blake_4.png", "intro_blake_4"),

    "tess_1": ("data/level_intros/tess_1.png", "intro_tess_1"),
    "tess_2": ("data/level_intros/tess_2.png", "intro_tess_2"),
    "tess_3": ("data/level_intros/tess_3.png", "intro_tess_3"),
    "tess_4": ("data/level_intros/tess_4.png", "intro_tess_4"),

    "woody_1": ("data/level_intros/woody_1.png", "intro_woody_1"),
    "woody_2": ("data/level_intros/woody_2.png", "intro_woody_2"),
    "woody_3": ("data/level_intros/woody_3.png", "intro_woody_3"),
    "woody_4": ("data/level_intros/woody_4.png", "intro_woody_4"),


    "out-good-tutorial": ("data/level_outros/tim-good.png", "out_tim_good"),
    "out-bad-tutorial": ("data/level_outros/tim-bad.png", "out_tim_bad"),
    "out-good-blake": ("data/level_outros/blake-good.png", "out_blake_good"),
    "out-bad-blake": ("data/level_outros/blake-bad.png", "out_blake_bad"),
    "out-good-tess": ("data/level_outros/tess-good.png", "out_tess_good"),
    "out-bad-tess": ("data/level_outros/tess-bad.png", "out_tess_bad"),
    "out-good-woody": ("data/level_outros/woody-good.png", "out_woody_good"),
    "out-bad-woody": ("data/level_outros/woody-bad.png", "out_woody_bad"),

    
}    

class StateIntro(fsm.State):
    def __init__(self):
        fsm.State.__init__(self)
        self.tag=None

    def init(self, levelName):
        p,tag=introDict[levelName]
        texMgr.loadTexture(p,tag)
        self.tag=tag
        self.timeNow=0.0

    def draw(self):
        glColor3f(1.0, 1.0, 1.0)
        self.parent.draw()
        glColor4f(0.0, 0.0, 0.0, 0.7)
        
        draw_util.draw_quad(None, 0, 600, 800, 0)
        glColor3f(1.0, 1.0, 1.0)

        draw_util.draw_quad(self.tag, 144,512,656,0)

    def activateApp(self, bNowActive):
        if not bNowActive:
            fsm.popState()
        return False

    def handleKey(self, key, unicode):
        fsm.popState()
        return True
        
    def handleMouseButton(self, bDown, buttonIndex):
        if self.timeNow<0.5:
            return True
        
        if not bDown:
            return True

        fsm.popState()

        return True
        
    def update(self, dt):
        self.timeNow+=dt
        return True
        
        
