###########################################################
# Start Menu - Railshooter Module
# This loads the Title Screen at the beginning of the Game
###########################################################

# DESCRIPTION:
# This Class creates the Splash Screen and the Menu System 
# associated with it by using Direct GUI.  The Menus are 
# composed of Labels and Buttons.  These Buttons and Labels
# are hidden and shown to allow the player to interact with
# the sub-menus.


from direct.showbase.ShowBaseGlobal import *
from direct.gui.DirectGui import *
from direct.showbase import DirectObject

# Import Railshooter Modules
import ClassGlobals


########################################
#     Creates a Title Screen Menu      #
########################################
class StartMenu(DirectObject.DirectObject):
    def __init__(self):
 
	# Make Background Black for Splash Screen
	base.setBackgroundColor(0, 0, 0)

	########################################
	# Loads up Title Screen Menu
	########################################

	self.title = DirectLabel(image='Textures/SplashScreen.png', scale = 1.2)
        self.title.setPos(0, 0, 0.12)

	self.menuBack = DirectLabel(image='Textures/MenuBackground.png', scale = (0.43, 0.31, 0.25))
        self.menuBack.setPos(0, 0, -0.1)
	self.menuBack.setTransparency(1)
	self.menuBack.setColor(0, 0, 0, 0.4)

	self.startButton = DirectButton(image = "Textures/StartButton.png", command = self.startGame, scale = (0.6, 1, 0.04), relief = None)
	self.startButton.setTransparency(1)	
	self.startButton.setPos(0, 0, 0.03)

	self.creditsButton = DirectButton(image = "Textures/CreditsButton.png", command = self.loadCredits, scale = (0.6, 1, 0.04), relief = None)
	self.creditsButton.setTransparency(1)
	self.creditsButton.setPos(0, 0, -0.23)

	self.optionsButton = DirectButton(image = "Textures/OptionsButton.png", command = self.loadOptions, scale = (0.6, 1, 0.04), relief = None)
	self.optionsButton.setTransparency(1)
	self.optionsButton.setPos(0, 0, -0.10)


	########################################
	# Loads up Options Menu
	########################################

	self.optionTitle = DirectLabel(image='Textures/OptionsMenu.png', scale = 1.2)
        self.optionTitle.setPos(0, 0, -0.03)

	self.difficultyLabel = DirectLabel(text = 'Difficulty:', scale=0.08, text_fg=(1, 1, 0.5, 1), relief = None)
	self.difficultyLabel.setPos(-0.7, 0, 0.3) 

	self.easyButton = DirectButton(text = "Easy", command = self.setEasyMode, scale = 0.08, text_fg=(1, 1, 1, 1), relief = None)
	self.easyButton.setPos(-0.3, 0, 0.3) 
	self.easyButton.setTransparency(1)

	self.mediumButton = DirectButton(text = "Normal", command = self.setNormalMode, scale = 0.08, text_fg=(1, 1, 1, 1), relief = None)
	self.mediumButton.setPos(0.1, 0, 0.3)
	self.mediumButton.setTransparency(1)

	self.hardButton = DirectButton(text = "Hard", command = self.setHardMode, scale = 0.08, text_fg=(1, 1, 1, 1), relief = None)
	self.hardButton.setPos(0.5, 0, 0.3)
	self.hardButton.setTransparency(1)

	self.overkillButton = DirectButton(text = "Overkill", command = self.setOverkillMode, scale = 0.08, text_fg=(1, 1, 1, 1), relief = None)
	self.overkillButton.setPos(0.9, 0, 0.3)
	self.overkillButton.setTransparency(1)


	self.invertMouseLabel = DirectLabel(text = 'Mouse Controls:', scale=0.08, text_fg=(1, 1, 0.5, 1), relief = None)
	self.invertMouseLabel.setPos(-0.7, 0, 0.0) 

	self.noInvertMouseButton = DirectButton(text = "Normal", command = self.setInvertOff, scale = 0.08, text_fg=(1, 1, 1, 1), relief = None)
	self.noInvertMouseButton.setPos(-0.2, 0, 0.0) 
	self.noInvertMouseButton.setTransparency(1)

	self.invertMouseButton = DirectButton(text = "Inverted", command = self.setInvertOn, scale = 0.08, text_fg=(1, 1, 1, 1), relief = None)
	self.invertMouseButton.setPos(0.2, 0, 0.0) 
	self.invertMouseButton.setTransparency(1)


	self.invincibleLabel = DirectLabel(text = 'God Mode:', scale=0.08, text_fg=(1, 1, 0.5, 1), relief = None)
	self.invincibleLabel.setPos(-0.7, 0, -0.3) 

	self.invincibleOnButton = DirectButton(text = "On", command = self.setGodModeOn, scale = 0.08, text_fg=(1, 1, 1, 1), relief = None)
	self.invincibleOnButton.setPos(-0.2, 0, -0.3) 
	self.invincibleOnButton.setTransparency(1)

	self.invincibleOffButton = DirectButton(text = "Off", command = self.setGodModeOff, scale = 0.08, text_fg=(1, 1, 1, 1), relief = None)
	self.invincibleOffButton.setPos(0.2, 0, -0.3) 
	self.invincibleOffButton.setTransparency(1)


	self.otherOptions = DirectButton(text = "1 = Toggle Wireframe View \n2 = Toggle Texture View \nEsc = Disable Mouse", text_align=TextNode.ALeft, scale = 0.06, text_fg=(1, 1, 1, 1), relief = None)
	self.otherOptions.setPos(-0.85, 0, -0.5) 

	
	########################################
	# Loads up Credits Screen
	########################################
	self.creditsTitle = DirectLabel(image='Textures/Credits.png', scale = 1.2)
        self.creditsTitle.setPos(0, 0, -0.03)

	self.credits1 = DirectLabel(text = 'CARNEGIE MELLON UNIVERSITY \n Entertainment Technology Center \n www.etc.cmu.edu \n\n Fall 2003 Panda Team:\n Reagan Heller \n Ben Johnson \n Jason Pratt \n Jeff Styers \n Jason Yeung \n\n Advisor: Jesse Schell \n\n Music by Ari Winters \n City Architecture designed by Chia Cheng \n\n Panda 3d Website - www.etc.cmu.edu/panda3d', scale=0.065, text_fg=(1, 1, 1, 1), relief = None)
	self.credits1.setPos(0, 0, 0.45) 

	self.mainMenuButton = DirectButton(image = "Textures/ReturnButton.png", command = self.returnOptions, scale = (0.75, 0, 0.15), relief = None)
	self.mainMenuButton.setPos(-0.5, 0, -0.8) 
	self.mainMenuButton.setTransparency(1)


	########################################
	# Hide Other Menus at Start
	########################################
	self.hideOptionsMenu()
	self.hideCredits()


########################################
# Main Menu Functions
########################################

    # This Function Starts the Game
    def startGame(self):
	# Toggle Start Game Variable
	ClassGlobals.gameStart = 1
	self.hideTitleMenu()

    # This Function Loads the Option Screen
    def loadOptions(self):
	self.hideTitleMenu()
	self.showOptionsMenu()

	# Add Task to Update the Option Menu Status
        taskMgr.add(self.updateOptions, 'updateOptions')

    # This Function Loads the Credits
    def loadCredits(self):
	self.hideTitleMenu()
	self.showCredits()


########################################
# Option Menu Functions
########################################

    # Choose Easy Mode
    def setEasyMode(self):
	ClassGlobals.difficulty = 1

    # Choose Normal Mode
    def setNormalMode(self):
	ClassGlobals.difficulty = 2

    # Choose Hard Mode
    def setHardMode(self):
	ClassGlobals.difficulty = 3

    # Choose Overkill Mode
    def setOverkillMode(self):
	ClassGlobals.difficulty = 4


    # Turn Inverted Mouse On
    def setInvertOn(self):
	ClassGlobals.mouser.inverted = 1

    # Turn Inverted Mouse Off
    def setInvertOff(self):
	ClassGlobals.mouser.inverted = 0


    # Turn God Mode On
    def setGodModeOn(self):
	ClassGlobals.p1.godMode = 1

    # Turn God Mode Off
    def setGodModeOff(self):
	ClassGlobals.p1.godMode = 0


   # This Function Ends the Option Screen
    def returnOptions(self):
	self.showTitleMenu()
	self.hideOptionsMenu()
	self.hideCredits()

	# Add Task to Update the Option Menu Status
        taskMgr.remove('updateOptions')


########################################
# Functions to Swap Out the Menus
########################################

    # Hides the Title Screen Menu
    def hideTitleMenu(self):
	self.title.hide()
	self.startButton.hide()
	self.optionsButton.hide()
	self.creditsButton.hide()
	self.menuBack.hide()

    # Shows the Title Screen Menu
    def showTitleMenu(self):
	self.title.show()
	self.startButton.show()
	self.optionsButton.show()
	self.creditsButton.show()
	self.menuBack.show()

    # Hides the Options Menu
    def hideOptionsMenu(self):
	self.optionTitle.hide()
	self.invertMouseLabel.hide()
	self.invertMouseButton.hide()
	self.noInvertMouseButton.hide()
	self.mainMenuButton.hide()
	self.difficultyLabel.hide()
	self.easyButton.hide()
	self.mediumButton.hide()
	self.hardButton.hide()
	self.overkillButton.hide()
	self.invincibleLabel.hide()
	self.invincibleOnButton.hide()
	self.invincibleOffButton.hide()
        self.otherOptions.hide()

    # Shows the Options Menu
    def showOptionsMenu(self):
	self.optionTitle.show()
	self.invertMouseLabel.show()
	self.invertMouseButton.show()
	self.noInvertMouseButton.show()
	self.mainMenuButton.show()	
	self.difficultyLabel.show()
	self.easyButton.show()
	self.mediumButton.show()
	self.hardButton.show()
	self.overkillButton.show()
	self.invincibleLabel.show()
	self.invincibleOnButton.show()
	self.invincibleOffButton.show()
        self.otherOptions.show()
        
    # Hides the Credits Screen Menu
    def hideCredits(self):
	self.creditsTitle.hide()
	self.credits1.hide()
	self.mainMenuButton.hide()

    # Show the Credits Screen Menu
    def showCredits(self):
	self.creditsTitle.show()
	self.credits1.show()
	self.mainMenuButton.show()	


########################################
# Task to Update Options Menu
########################################

    # Update the Information in the Option Menu
    def updateOptions(self, task):
	
	# Remove Selection Indicators from Choices
    	self.easyButton['image'] = None
    	self.mediumButton['image'] = None
    	self.hardButton['image'] = None
    	self.overkillButton['image'] = None
	self.invertMouseButton['image'] = None
	self.noInvertMouseButton['image'] = None
	self.invincibleOnButton['image'] = None
	self.invincibleOffButton['image'] = None

	# Update Difficulty Selection
	if ClassGlobals.difficulty == 1:
	    self.easyButton['image'] = "Textures/SelectionOrb.png"
	    self.easyButton['image_pos'] = (0, 0, 0.3)
	elif ClassGlobals.difficulty == 2:
	    self.mediumButton['image'] = "Textures/SelectionOrb.png"
	    self.mediumButton['image_pos'] = (0, 0, 0.3)
	elif ClassGlobals.difficulty == 3:
	    self.hardButton['image'] = "Textures/SelectionOrb.png"
	    self.hardButton['image_pos'] = (0, 0, 0.3)
	elif ClassGlobals.difficulty == 4:
	    self.overkillButton['image'] = "Textures/SelectionOrb.png"
	    self.overkillButton['image_pos'] = (0, 0, 0.3)

	# Update Inverted Mouse Buttons
	if ClassGlobals.mouser.inverted == 1:
	    self.invertMouseButton['image'] = "Textures/SelectionOrb.png"
	    self.invertMouseButton['image_pos'] = (0, 0, 0.3)
	if ClassGlobals.mouser.inverted == 0:
	    self.noInvertMouseButton['image'] = "Textures/SelectionOrb.png"
	    self.noInvertMouseButton['image_pos'] = (0, 0, 0.3)

	# Update God-Mode Buttons
	if ClassGlobals.p1.godMode == 1:
	    self.invincibleOnButton['image'] = "Textures/SelectionOrb.png"
	    self.invincibleOnButton['image_pos'] = (0, 0, 0.3)
	if ClassGlobals.p1.godMode == 0:
	    self.invincibleOffButton['image'] = "Textures/SelectionOrb.png"
	    self.invincibleOffButton['image_pos'] = (0, 0, 0.3)

        return Task.cont
