"""
main menu screen
"""


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 state_level_select
import state_credits



def func_quit(args):
    sys.exit(0)

def func_play(args):
    fsm.pushState(state_level_select.StateLevelSelect(), None)

def func_credits(args):
    fsm.pushState(state_credits.StateCredits(), None)

button_size=120
button_space=150
button_col=800-button_space/2
b_hs=button_size/2

by2=300
by1=by2+button_space
by3=by2-button_space

bleft=button_col-button_size/2
bright=button_col+button_size/2

buttons=[gw.Button("button_play",     bleft, by1+b_hs, bright, by1-b_hs, func_play),
         gw.Button("button_credits",  bleft, by2+b_hs, bright, by2-b_hs, func_credits),
         gw.Button("button_quit",     bleft, by3+b_hs, bright, by3-b_hs, func_quit)]



class StateMainMenu(fsm.State):
    def __init__(self):
        fsm.State.__init__(self)

    def init(self, unused_args):
        texMgr.loadTexture("data/intro/logo.png", "woody_logo")
        texMgr.loadTexture("data/intro/factory.png", "factory")
        texMgr.loadTexture("data/buttons/play.png", "button_play")
        texMgr.loadTexture("data/buttons/credits.png", "button_credits")
        texMgr.loadTexture("data/buttons/quit.png", "button_quit")

    def draw(self):
        #draw_util.draw_quad("main_bkgd",        0, 600, 800, 0)
        draw_util.draw_quad("factory",       0, 700, 800, -100)
        draw_util.draw_quad("woody_logo",       0, 600, 300,300)

        for b in buttons:
            b.draw()

    def handleMouseButton(self, bDown, buttonIndex):
        if not bDown:
            return True
        for b in buttons:
            if b.handleMouseButton(bDown, buttonIndex):
                return True
        return True
        
    def update(self, dt):
        return True
        
        
