###########################################################
# LockOnCrosshair - Railshooter Module
# Class to create the Target Lockon Crosshair Animation
###########################################################

# DESCRIPTION:
# This Class creates an animated Lock-On Crosshair that surrounds
# a target of your choice.  This is used in conjunction with the 
# Player's Homing Laser Attack to show which targets are Locked On.


from direct.showbase.ShowBaseGlobal import *
from direct.interval.IntervalGlobal import *
from direct.showbase import DirectObject
from direct.task import Task
from pandac.PandaModules import *

import LoadTextures


########################################
# LockOn Class
########################################

class LockOnCrosshair(DirectObject.DirectObject):
    def __init__(self, target): 
	
        # Load the First Crosshair
        self.crosshair = loader.loadModel("Models/basics/crosshair")
     	self.crosshair.reparentTo(target)
	self.crosshair.lookAt(camera)
	self.crosshair.setTransparency(1)
	self.crosshair.setColor(1.0, 1.0, 1.0, 0.6)
	self.crosshair.setScale(0.6, 0.6, 0.6)
	self.crosshair.setFogOff()

        # Load Appropriate Texture
        self.crosshair.setTexture(LoadTextures.LockOnCrosshair, 1)

	# Create Rotating Animation
	self.rotateCrosshair = self.crosshair.hprInterval(2, 
	 			Point3(0, 0, 360), 
	 			startHpr=Point3(0, 0, 0))
	self.rotateCrosshair.loop()

	# Create Initial Scaling Animation
	self.scaleCrosshair = self.crosshair.scaleInterval(0.5, 
	 			Point3(0.2, 0.2, 0.2), 
				blendType = 'easeIn')
	self.scaleCrosshair.start()

	# Create a Blank Light Attribute
	# Results in Object being unaffected by light and
	# glowing as a result
	lightAttributes = LightAttrib.makeAllOff()
	self.crosshair.node().setAttrib(lightAttributes)

	# Create a GUI Layer for the Crosshair
	# CullBinManager.getGlobalPtr().addBin('gui-popup', CullBinManager.BTUnsorted, 60)

	# Add the Crosshair to the new GUI Bin
	self.crosshair.setBin('gui-popup', 0)
	self.crosshair.setDepthTest(0)


    ########################################
    # Define Methods
    ########################################

    # Destroy the LockOn Crosshair and Remove its Parts
    def destroy(self):
	self.rotateCrosshair.finish()    
	self.crosshair.removeNode()

