import direct.directbase.DirectStart
from pandac.PandaModules import *
from direct.actor import Actor
from direct.interval.IntervalGlobal import *
from direct.gui.DirectGui import *
from direct.showbase.DirectObject import *
import sys,os

class World(DirectObject):
  def __init__(self):
    base.disableMouse()
    base.setBackgroundColor(0,0,0)
    self.accept('escape', sys.exit)
    camera.setPos(-5.4, -16.5, -1.8)
    
    self.card = Actor.Actor("models/thankyou_card",
                            {"main": "models/thankyou_anim"})
    self.card.reparentTo(render)
    self.card.pose("main", 0)
    self.card.action = self.card.actorInterval("main")

    self.setupLights()
    self.music = loader.loadMusic('sound/soundtrack.mp3')

    seq = Sequence(Wait(5), Func(self.music.play), self.card.action)
    if sys.platform == "win32":
      #self.card.find("**/pPlane11").setTexture(
      #  loader.loadTexture("models/textures/pandasign_win.jpg"), 1)
      seq = Parallel(seq,
                     Sequence(Wait(40), 
                              Func(self.createButton)))
     
    seq.start()

  def createButton(self):
    self.button = DirectButton(
                   pad = (1.333, 1), frameColor = (.5,.5,.5,0),
                   pos = Vec3(0, 0, 0),
                   rolloverSound = None, clickSound = None,
                   command = self.openTutorialDirWin32)
    #self.button.setTransparency(1)

  def setButtonFrameColor(self, color):
    self.button["frameColor"] = color

  def openTutorialDirWin32(self):
    Sequence(Func(self.setButtonFrameColor, (.5,.5,.5,.5)),
             Wait(.25),
             Func(self.setButtonFrameColor, (1,1,0,0))).start()

    if (len(sys.argv) > 1):
      path = sys.argv[1]
    else:
      path = os.path.join(os.path.abspath(sys.path[0]),"..")
    os.startfile(path)

  def setupLights(self):
    lAttrib = LightAttrib.makeAllOff()
    ambientLight = AmbientLight( "ambientLight" )
    ambientLight.setColor( Vec4(.8, .8, .75, 1) )
    lAttrib = lAttrib.addLight( ambientLight )
    directionalLight = DirectionalLight( "directionalLight" )
    directionalLight.setDirection( Vec3( 0, .8944, -.447 ) )
    directionalLight.setColor( Vec4( 0.9, 0.8, 0.9, 1 ) )
    lAttrib = lAttrib.addLight( directionalLight )
    render.attachNewNode( directionalLight.upcastToPandaNode() )
    render.attachNewNode( ambientLight.upcastToPandaNode() )
    render.node().setAttrib( lAttrib )

w = World()
run()
                            
