#!BPY
#

"""
Name: 'Uru Properties menu 1.04'
Blender: 237
Group: 'Misc'
Tooltip: 'Menu to set (and MASK) URU Object Properties'
"""

__author__ = "Sjaak-de-Draak"
__url__ = ("blender", "blah","Authors hangout: http://www.cobbs.ca")
__version__ = "URU Properties 1.04"

__bpydoc__ = """\
This script Creates a menu to easily set and fetch Object properties
used in URU.
"""
#
# $Id: uruProperties_menu_104.py,v 1.03 2006/06/04 15:31:00 Sjaak $
#
# A script to easily set various URU properties for selected objects
#
######################################
# By Sjaak-de-Draak                  #
######################################
# 
# Enjoy ... 
# 
# Submenu: 'Open the URU Properties menu' i_URUProperties_menu
# Submenu: 'Properties Menu' 

#import Blender, time, sys, os
import Blender, time, os
try: import sys
except: print "Couldn't import the 'sys' module"

# TEST
from Blender import *
# TEST

from types import ListType, IntType, FloatType, StringType, ModuleType
from Blender.Draw import *    # needed to draw the menu buttons
from Blender.BGL import *
from string import strip

import URUProperties_class_104    # imports 'URUProperties_class.py' 
from URUProperties_class_104 import URUProperties

version = "1.04"

verbose = 0
debug = 0

# Get it from the class
#AlcSpecialList = [ "none", "point",  "footsteprgn", "swimrgn", "swimplainsfc", "StraightCurrent", "CircularCurrent" ]

# Set all the Toggle button defaults
#
Default = Create(0)
SfxRegSen = Create(0)
GenDetReg = Create(0)
LdrBottom = Create(0)
LdrBounds = Create(0)
LdrTop = Create(0)
CollObj = Create(0)
GenObjWC = Create(1)
GenObjNC = Create(0)
Kickable = Create(0)
SfxFtRegSen = Create(0)
SwimRegSen = Create(0)
SwimDetRegSen = Create(0)
Clickable = Create(0)
Custom = Create(0)

# added a mode to only apply active properties
ChangeMode = Create(0)
MaskChanges = 0

propertyType = "GenObjWC"

showName = Create("default")
showNameStringLen = 20
menuName = Create(1)
showPageNum= Create("0")
showPageNumStringLen = 1
showAlcType= Create("object")
showAlcTypeStringLen = 8
#showAlcSpecial= Create("none")
menuAlcSpecial= Create(0)
showAlcSpecialStringLen = 20
showFootstepSound= Create("00")
showFootstepSoundStringLen = 8
menuFootstepSound = Create(19)
showColType= Create("4")
showColTypeStringLen = 1
showMass = Create(0.000)
showRC =   Create(0.000)
showEL =   Create(0.000)
showLight = Create("00000000")
showLightStringLen = 8
showMaterial = Create("material")
showMaterialStringLen = 20
menuMaterial = Create(1)
showColFlags0= Create("0000")
showColFlags0StringLen = 4
showColFlags1= Create("00000000")
showColFlags1StringLen = 8
showColFlags2= Create("00000000")
showColFlags2StringLen = 8
showColFlags3= Create("0000")
showColFlags3StringLen = 4
showColFlags4= Create("00000000")
showColFlags4StringLen = 8
showColFlags5= Create("00000000")
showColFlags5StringLen = 8
showCurrentDummy= Create("SwimCurrentDummy")
showCurrentDummyStringLen= 20
showSwimSFC_F1= Create(2.000)
showSwimSFC_F2= Create(0.000)
showSwimSFC_F3= Create(3.000)
showSwimSFC_F4= Create(0.000)
showSwimSFC_F5= Create(-3.000)
showBottomFlag= Create(1)
showClimbOffset= Create(0)
showClimbHeight= Create(4)

# Turn all options on or off by default
state=1
#
stateName = Create(state)
stateMaterial = Create(state)
statePageNum = Create(state)
stateAlcType = Create(state)
stateAlcSpecial = Create(0)
stateFootstepSound = Create(0)
stateColType = Create(state)
stateMass = Create(state)
stateRC = Create(state)
stateEL = Create(state)
stateLight = Create(state)
stateMaterial = Create(state)
stateColFlags0 = Create(state)
stateColFlags1 = Create(state)
stateColFlags2 = Create(state)
stateColFlags3 = Create(state)
stateColFlags4 = Create(state)
stateColFlags5 = Create(state)
#stateSwimSFC_F1= Create(state)
#stateSwimSFC_F2= Create(state)
#stateSwimSFC_F3= Create(state)
#stateSwimSFC_F4= Create(state)
#stateSwimSFC_F5= Create(state)
stateCurrentDummy= Create(0)
stateSwimSFC_F1= Create(0)
stateSwimSFC_F2= Create(0)
stateSwimSFC_F3= Create(0)
stateSwimSFC_F4= Create(0)
stateSwimSFC_F5= Create(0)
stateBottomFlag= Create(0)
stateClimbOffset= Create(0)
stateClimbHeight= Create(0)



# Get a class instance
#
myURUProperties = URUProperties()

# Get the AlcSpecialList
#
AlcSpecialList=myURUProperties.getAlcSpecialList()


# Ok, let's do some basic tests
#
#myURUProperties.setDebug()
#myURUProperties.setVerbose()



def checkEditMode(): 
    # Check if we are in edit mode (cuz we don't want this when creating a new Mesh)
    #
    editmode = Blender.Window.EditMode()
    if editmode:
        Blender.Window.EditMode(0)    # Leave edit mode

def setStates(state=0, swimsfc_f=0, alcspecial=0, footstep=0, climbregion=0):
    global stateName, stateMaterial, statePageNum, stateAlcType, stateColType
    global stateMass, stateEL, stateRC, stateLight, stateMaterial
    global stateColFlags0, stateColFlags1, stateColFlags2
    global stateColFlags3, stateColFlags4, stateColFlags5
    global stateSwimSFC_F1, stateSwimSFC_F2, stateSwimSFC_F3, stateSwimSFC_F4, stateSwimSFC_F5
    global stateAlcSpecial, stateFootstepSound, menuFootstepSound
    global stateBottomFlag, stateClimbOffset, stateClimbHeight
    global menuName, menuMaterial
    global stateCurrentDummy
    global MaskChanges, ChangeMode

    # quick hack to easily set all to 1 (except the swimsfc)
    if (state == 2):
        state=1
        alcspecial=1
        footstep=1
    # quick hack to easily set all to 1 (including the swimsfc)
    elif (state == 3):
        state=1
        swimsfc_f=1
        alcspecial=1
        footstep=1
    
    # Turn all options ON or OFF (default is off) 
    stateName.val = state
    stateMaterial.val = state
    statePageNum.val = state
    stateAlcType.val = state
    if (alcspecial == 1):
        stateAlcSpecial.val = state
    else:
        stateAlcSpecial.val = 0
    if (footstep == 1):
        stateFootstepSound.val = state
    else:
        stateFootstepSound.val = 0
    stateColType.val = state
    stateMass.val = state
    stateRC.val = state
    stateEL.val = state
    stateLight.val = state
    stateMaterial.val = state
    stateColFlags0.val = state
    stateColFlags1.val = state
    stateColFlags2.val = state
    stateColFlags3.val = state
    stateColFlags4.val = state
    stateColFlags5.val = state
    if (swimsfc_f == 1):
        stateCurrentDummy.val= state
        stateSwimSFC_F1.val= state
        stateSwimSFC_F2.val= state
        stateSwimSFC_F3.val= state
        stateSwimSFC_F4.val= state
        stateSwimSFC_F5.val= state
    else:
        stateCurrentDummy.val= 0
        stateSwimSFC_F1.val= 0
        stateSwimSFC_F2.val= 0
        stateSwimSFC_F3.val= 0
        stateSwimSFC_F4.val= 0
        stateSwimSFC_F5.val= 0
    if (climbregion == 1):
        stateBottomFlag.val= state
        stateClimbOffset.val= state
        stateClimbHeight.val= state
    else:
        stateBottomFlag.val= 0
        stateClimbOffset.val= 0
        stateClimbHeight.val= 0

def updateToggleButtons(toggle = None):
    global Default, SfxRegSen, GenDetReg, LdrBottom, LdrBounds, LdrTop, CollObj, GenObjWC, GenObjNC, Kickable, SfxFtRegSen, SwimRegSen, SwimDetRegSen, Clickable, Custom
    global MaskChanges, ChangeMode
    buttonList = [ SfxRegSen, GenDetReg, LdrBottom, LdrBounds, LdrTop, CollObj, GenObjWC, GenObjNC, Kickable, SfxFtRegSen, SwimRegSen, SwimDetRegSen, Clickable, Custom ]
    if ( toggle == None ):
        toggle = GenObjWC
    # make sure only one button can be active
    for button in buttonList:
        if ( button == toggle ):
            button.val = 1
        else:
            button.val = 0

def getCustomPropertiesList():
    global debug, verbose, propertyType, showName, showNameStringLen, filename
    global showPageNum, showPageNumStringLen, showAlcType, showAlcTypeStringLen, showColType, showColTypeStringLen
    global showAlcSpecial, menuAlcSpecial, showAlcSpecialStringLen, showFootstepSound, showFootstepSoundStringLen
    global showMass, showEL, showRC, showLight, showLightStringLen, showMaterial, showMaterialStringLen
    global showColFlags0, showColFlags0StringLen, showColFlags1, showColFlags1StringLen, showColFlags2, showColFlags2StringLen
    global showColFlags3, showColFlags4StringLen, showColFlags4, showColFlags4StringLen, showColFlags5, showColFlags5StringLen
    global stateName, stateMaterial, statePageNum, stateAlcType, stateColType
    global stateMass, stateEL, stateRC, stateLight, stateMaterial
    global stateColFlags0, stateColFlags1, stateColFlags2
    global stateColFlags3, stateColFlags4, stateColFlags5
    global showSwimSFC_F1, showSwimSFC_F2, showSwimSFC_F3, showSwimSFC_F4, showSwimSFC_F5
    global stateSwimSFC_F1, stateSwimSFC_F2, stateSwimSFC_F3, stateSwimSFC_F4, stateSwimSFC_F5
    global stateAlcSpecial, stateFootstepSound, menuFootstepSound
    global showBottomFlag, showClimbOffset, showClimbHeight
    global stateBottomFlag, stateClimbOffset, stateClimbHeight
    global menuName, menuMaterial
    global AlcSpecialList
    global stateCurrentDummy, showCurrentDummy, showCurrentDummyStringLen
    global MaskChanges, ChangeMode


    name        = [ "name",        showName.val,                "STRING",    stateName.val ]
    page_num        = [ "page_num",        showPageNum.val,            "STRING",    statePageNum.val ]
    alctype        = [ "alctype",        showAlcType.val,            "STRING",    stateAlcType.val ]
    alcspecial        = [ "alcspecial",    AlcSpecialList[int(menuAlcSpecial.val)],"STRING",    stateAlcSpecial.val ]
    footstepsound    = [ "footstepsound",    menuFootstepSound.val,            "STRING",    stateFootstepSound.val ]
    col_type        = [ "col_type",        showColType.val,            "STRING",    stateColType.val ]
    mass        = [ "mass",        showMass.val,                "FLOAT",    stateMass.val  ]
    rc            = [ "rc",        showRC.val,                "FLOAT",    stateRC.val  ]
    el            = [ "el",        showEL.val,                "FLOAT",    stateEL.val  ]
    light        = [ "light",        showLight.val,                "STRING",    stateLight.val ]
    material        = [ "material",        showMaterial.val,            "STRING",    stateMaterial.val ]
    col_flags0        = [ "col_flags0",    showColFlags0.val,            "STRING",    stateColFlags0.val ]
    col_flags1        = [ "col_flags1",    showColFlags1.val,            "STRING",    stateColFlags1.val ]
    col_flags2        = [ "col_flags2",    showColFlags2.val,            "STRING",    stateColFlags2.val ]
    col_flags3        = [ "col_flags3",    showColFlags3.val,            "STRING",    stateColFlags3.val ]
    col_flags4        = [ "col_flags4",    showColFlags4.val,            "STRING",    stateColFlags4.val ]
    col_flags5        = [ "col_flags5",    showColFlags5.val,            "STRING",    stateColFlags5.val ]
    currentdummy    = [ "currentdummy",    showCurrentDummy.val,            "STRING",    stateCurrentDummy.val ]
    swimsfc_f1        = [ "swimsfc_f1",    showSwimSFC_F1.val,            "FLOAT",    stateSwimSFC_F1.val ]
    swimsfc_f2        = [ "swimsfc_f2",    showSwimSFC_F2.val,            "FLOAT",    stateSwimSFC_F2.val ]
    swimsfc_f3        = [ "swimsfc_f3",    showSwimSFC_F3.val,            "FLOAT",    stateSwimSFC_F3.val ]
    swimsfc_f4        = [ "swimsfc_f4",    showSwimSFC_F4.val,            "FLOAT",    stateSwimSFC_F4.val ]
    swimsfc_f5        = [ "swimsfc_f5",    showSwimSFC_F5.val,            "FLOAT",    stateSwimSFC_F5.val ]
    bottomflag        = [ "bottomFlag",    showBottomFlag.val,            "INT",      stateBottomFlag.val ]
    climboffset       = [ "climbOffset",   showClimbOffset.val,           "INT",      stateClimbOffset.val ]
    climbheight       = [ "climbHeight",   showClimbHeight.val,           "INT",      stateClimbHeight.val ]

    list = [name, page_num, alctype, alcspecial, footstepsound, col_type, mass, rc, el, light, material, col_flags0, col_flags1, col_flags2, col_flags3, col_flags4, col_flags5, currentdummy, swimsfc_f1, swimsfc_f2, swimsfc_f3, swimsfc_f4, swimsfc_f5, bottomflag, climboffset, climbheight ]

    return list

def updateProperties(type = "GenObjWC", list = None):
    global debug, verbose, propertyType, showName, showNameStringLen, filename
    global showPageNum, showPageNumStringLen, showAlcType, showAlcTypeStringLen, showColType, showColTypeStringLen
    global showMass, showEL, showRC, showLight, showLightStringLen, showMaterial, showMaterialStringLen
    global showColFlags0, showColFlags0StringLen, showColFlags1, showColFlags1StringLen, showColFlags2, showColFlags2StringLen
    global showColFlags3, showColFlags4StringLen, showColFlags4, showColFlags4StringLen, showColFlags5, showColFlags5StringLen
    global myURUProperties
    global stateName, stateMaterial, statePageNum, stateAlcType, stateColType
    global stateMass, stateEL, stateRC, stateLight, stateMaterial
    global stateColFlags0, stateColFlags1, stateColFlags2
    global stateColFlags3, stateColFlags4, stateColFlags5
    global showSwimSFC_F1, showSwimSFC_F2, showSwimSFC_F3, showSwimSFC_F4, showSwimSFC_F5
    global stateSwimSFC_F1, stateSwimSFC_F2, stateSwimSFC_F3, stateSwimSFC_F4, stateSwimSFC_F5
    global menuName, menuMaterial
    global showAlcSpecial, menuAlcSpecial, showAlcSpecialStringLen, showFootstepSound, showFootstepSoundStringLen
    global stateAlcSpecial, stateFootstepSound, menuFootstepSound
    global showBottomFlag, showClimbOffset, showClimbHeight
    global stateBottomFlag, stateClimbOffset, stateClimbHeight
    global AlcSpecialList
    global stateCurrentDummy, showCurrentDummy, showCurrentDummyStringLen
    global MaskChanges, ChangeMode

    if (type == "Custom"):
        if ( list == None ):
            list = getCustomPropertiesList()
        propertiesList = myURUProperties.fetchCustomProperties(list)
    else:
        propertiesList = myURUProperties.fetchBuiltinProperty(type)

    # DEBUG
    #
    #print "propertiesList: %s" % propertiesList

    # example 
    # [name, page_num, alctype, alcspecial, footstepsound, col_type, mass, rc, el, light, material, col_flags0, col_flags1, col_flags2, col_flags3, col_flags4, col_flags5 ]
    #    0       1        2         3             4            5       6    7   8    9       10          11          12          13          14          15          16
    showName.val        = propertiesList[0][1]
    stateName.val        = propertiesList[0][3]
    showPageNum.val        = propertiesList[1][1]
    statePageNum.val        = propertiesList[1][3]
    showAlcType.val        = propertiesList[2][1]
    stateAlcType.val        = propertiesList[2][3]
    
    menuAlcSpecial.val    = 0
    count = 0
    for item in AlcSpecialList:
        if ( item == propertiesList[3][1] ):
            menuAlcSpecial.val    = count
        count=count+1
    stateAlcSpecial.val        = propertiesList[3][3]
    menuFootstepSound.val    = propertiesList[4][1]
    stateFootstepSound.val    = propertiesList[4][3]
    showColType.val        = propertiesList[5][1]
    stateColType.val        = propertiesList[5][3]
    showMass.val        = propertiesList[6][1]
    stateMass.val        = propertiesList[6][3]
    showRC.val            = propertiesList[7][1]
    stateRC.val            = propertiesList[7][3]
    showEL.val            = propertiesList[8][1]
    stateEL.val            = propertiesList[8][3]
    showLight.val        = propertiesList[9][1]
    stateLight.val        = propertiesList[9][3]
    showMaterial.val        = propertiesList[10][1]
    stateMaterial.val        = propertiesList[10][3]
    showColFlags0.val        = propertiesList[11][1]
    stateColFlags0.val        = propertiesList[11][3]
    showColFlags1.val        = propertiesList[12][1]
    stateColFlags1.val        = propertiesList[12][3]
    showColFlags2.val        = propertiesList[13][1]
    stateColFlags2.val        = propertiesList[13][3]
    showColFlags3.val        = propertiesList[14][1]
    stateColFlags3.val        = propertiesList[14][3]
    showColFlags4.val        = propertiesList[15][1]
    stateColFlags4.val        = propertiesList[15][3]
    showColFlags5.val        = propertiesList[16][1]
    stateColFlags5.val        = propertiesList[16][3]
    showCurrentDummy.val    = propertiesList[17][1]
    stateCurrentDummy.val    = propertiesList[17][3]
    showSwimSFC_F1.val        = propertiesList[18][1]
    stateSwimSFC_F1.val        = propertiesList[18][3]
    showSwimSFC_F2.val        = propertiesList[19][1]
    stateSwimSFC_F2.val        = propertiesList[19][3]
    showSwimSFC_F3.val        = propertiesList[20][1]
    stateSwimSFC_F3.val        = propertiesList[20][3]
    showSwimSFC_F4.val        = propertiesList[21][1]
    stateSwimSFC_F4.val        = propertiesList[21][3]
    showSwimSFC_F5.val        = propertiesList[22][1]
    stateSwimSFC_F5.val        = propertiesList[22][3]
    showBottomFlag.val        = propertiesList[23][1]
    stateBottomFlag.val        = propertiesList[23][3]
    showClimbOffset.val        = propertiesList[24][1]
    stateClimbOffset.val        = propertiesList[24][3]
    showClimbHeight.val        = propertiesList[25][1]
    stateClimbHeight.val        = propertiesList[25][3]


# dirty solution but should do the trick
#
# Update the Properties before draw is called for the 1st time
#
updateProperties()
# and set all the propetry states to active
#setStates(1)

def draw():
    global Default, SfxRegSen, GenDetReg, LdrBottom, LdrBounds, LdrTop, CollObj, GenObjWC, GenObjNC, Kickable, SfxFtRegSen, SwimRegSen, SwimDetRegSen, Clickable, Custom
    global debug, verbose, propertyType, showName, showNameStringLen, filename
    global showPageNum, showPageNumStringLen, showAlcType, showAlcTypeStringLen, showColType, showColTypeStringLen
    global showMass, showEL, showRC, showLight, showLightStringLen, showMaterial, showMaterialStringLen
    global showColFlags0, showColFlags0StringLen, showColFlags1, showColFlags1StringLen, showColFlags2, showColFlags2StringLen
    global showColFlags3, showColFlags4StringLen, showColFlags4, showColFlags4StringLen, showColFlags5, showColFlags5StringLen
    global stateName, stateMaterial, statePageNum, stateAlcType, stateColType
    global stateMass, stateEL, stateRC, stateLight, stateMaterial
    global stateColFlags0, stateColFlags1, stateColFlags2
    global stateColFlags3, stateColFlags4, stateColFlags5
    global showSwimSFC_F1, showSwimSFC_F2, showSwimSFC_F3, showSwimSFC_F4, showSwimSFC_F5
    global stateSwimSFC_F1, stateSwimSFC_F2, stateSwimSFC_F3, stateSwimSFC_F4, stateSwimSFC_F5
    global menuName, menuMaterial
    global showAlcSpecial, menuAlcSpecial, showAlcSpecialStringLen, showFootstepSound, showFootstepSoundStringLen
    global stateAlcSpecial, stateFootstepSound, menuFootstepSound
    global showBottomFlag, showClimbOffset, showClimbHeight
    global stateBottomFlag, stateClimbOffset, stateClimbHeight
    global stateCurrentDummy, showCurrentDummy, showCurrentDummyStringLen
    global MaskChanges, ChangeMode
    global version


    glClearColor(0.6, 0.6, 0.65, 0.0)
    glClear(GL_COLOR_BUFFER_BIT)

    glColor3f(0.75,0.75,0.75)
    glRasterPos2i(10, 405)
    #Text("URU Properties Script ver 1.01 ")
    Text("URU Properties Script ver %s " % version )

    glColor3f(0.2,0.2,0.0)
    #glRasterPos2i(10, 345)
    #Text("PropertyTypes:")
    if (Custom.val == 0):
## Y = 420
##        Clickable=     Toggle("Clickable",        17, 130, 420, 65, 18, Clickable.val,  "Clickable region")
# Y = 400
        LdrBottom=     Toggle("LdrBottom",    14,  00, 400, 65, 18, LdrBottom.val, "Ladder Bottom Boundry (going UP)")
        LdrTop=     Toggle("LdrTop",    15,  65, 400, 65, 18, LdrTop.val,  "Ladder Top Boundry (going Down)")
        #LdrBounds=     Toggle("LdrBounds",    16, 130, 400, 65, 18, LdrBounds.val, "Ladder Boundry (for Camera (and/or) Avatar)")
        Clickable=     Toggle("Clickable",        17, 130, 400, 65, 18, Clickable.val,  "Clickable region")
# Y = 380
        SfxFtRegSen=     Toggle("SfxFtRegSen",    11,  00, 380, 65, 18, SfxFtRegSen.val, "Sound Footstep Region Sensor")
        SwimRegSen=     Toggle("SwimRegSen",    12,  65, 380, 65, 18, SwimRegSen.val,  "Swim Detection Region Sensor (Avatar swim action)")
        SwimDetRegSen=     Toggle("SwimDetRegSen",    13, 130, 380, 65, 18, SwimDetRegSen.val,"Master Swim Region Sensor (only one needed)")
# Y = 360
        SfxRegSen=     Toggle("SfxRegSen",       4,  00, 360, 65, 18, SfxRegSen.val, "Sound Region Sensor")
        GenDetReg=     Toggle("GenDetReg",       5,  65, 360, 65, 18, GenDetReg.val, "Generic Detection Region (camera,marker,click)")
        Kickable=     Toggle("Kickable",        6, 130, 360, 65, 18, Kickable.val,  "Generic Kickable Object")
# Y = 340
        CollObj=       Toggle(" CollObj ",       7,  00, 340, 65, 18, CollObj.val,   "Collision Object (invisible)")
        GenObjWC=      Toggle("GenObjWC ",       8,  65, 340, 65, 18, GenObjWC.val,  "Generic Object With Collision")
        GenObjNC=      Toggle("GenObjNC ",       9, 130, 340, 65, 18, GenObjNC.val,  "Generic Object No Collision")

    if (Custom.val == 1):
        stateName=    Toggle(("%d" % stateName.val),    2,  0,  380,  20, 18, stateName.val, "State (ON/OFF)" )
        menuName= Menu("Name:%t| Object %x1| Custom %x4", 2, 20, 380, 80, 18, menuName.val, "Object Name or Custom Name")
        if (menuName.val == 4):
            showName= String("name: ",            2, 100,  380, 90, 18, showName.val, showNameStringLen, "Object Name (for export)")
        else:
            glRasterPos2i(103, 385)
            Text("name")

        stateMaterial=Toggle(("%d" % stateMaterial.val),    2,  0,  360,  20, 18, stateMaterial.val, "State (ON/OFF)" )
        menuMaterial= Menu("Material:%t| ObjMaterial %x1| Object %x2| ParentObj %x3| CustMat %x4", 2, 20, 360, 80, 18, menuMaterial.val, "Material, Obj, ParentObj, or Custom Name")
        if (menuMaterial.val == 4):
            showMaterial= String("name: ",            2, 100,  360, 90, 18, showMaterial.val, showMaterialStringLen, "Object Material name (for export)")
        else:
            glRasterPos2i(103, 365)
            Text("name")

    #Custom=    Toggle(" Custom  ", 10, 195, 340, 60, 58, Custom.val,    "Customized by User")
    Custom=    Toggle(" Custom  ", 10, 195, 340, 60, 78, Custom.val,    "Customized by User")

    #ChangeMode=Toggle("Mask Changes",  2, 182, 40, 73, 298, ChangeMode.val, "Only alter active elements (and don't delete the inactive ones)")
    ChangeMode=Toggle("Mask",  2, 222, 40, 33, 298, ChangeMode.val, "Only alter active elements (and don't delete the inactive ones)")

    # show the properties
    statePageNum=   Toggle(("%d" % statePageNum.val),        2,  0,  320,  20, 18, statePageNum.val, "State (ON/OFF)" )
    showPageNum=   String("page_num:      ",            2, 20,  320, 160, 18, showPageNum.val,  showPageNumStringLen,  "Page Number")
    stateAlcType=   Toggle(("%d" % stateAlcType.val),        2,  0,  300,  20, 18, stateAlcType.val, "State (ON/OFF)" )
    showAlcType=   String("alctype:       ",            2, 20,  300, 160, 18, showAlcType.val,  showAlcTypeStringLen,  "Alcugs Type")
    stateAlcSpecial=   Toggle(("%d" % stateAlcSpecial.val),    2,  0,  280,  20, 18, stateAlcSpecial.val, "State (ON/OFF)" )
    
    glRasterPos2i(23, 285)
    Text("alcspecial:")

    menuAlcSpecial= Menu("AlcSpecial:%t| none %x0|point %x1|footsteprgn %x2|swimrgn %x3|swimplainsfc %x4|StraightCurrent %x5|CircularCurrent %x6|PanicLinkRgn %x7|ClimbRegion %x8|Clickable %x9", 2, 100, 280, 80, 18, menuAlcSpecial.val, "Special features")

    if (menuAlcSpecial.val == 8):
        glRasterPos2i(23, 265)
        Text("ClimbOptions")
        stateBottomFlag=Toggle(("%d" % stateBottomFlag.val),    2,  0,  260,  20, 18, stateBottomFlag.val, "State (ON/OFF)" )
        if (showBottomFlag.val == 0):
            BottomFlagName="top"
        else:
            BottomFlagName="bottom"
        showBottomFlag= Toggle(BottomFlagName, 			2, 20, 260, 40, 18, showBottomFlag.val,    "Ladder Bottom or Top")
        showClimbOffset=      Number("offset: ",            2, 60,  260, 80, 18, showClimbOffset.val, -100.0, 100.0, "ClimbOffset")
        showClimbHeight=      Number("height: ",            2, 140,  260, 80, 18, showClimbHeight.val, -100.0, 100.0, "ClimbHeight")
    else:
        glRasterPos2i(23, 265)
        Text("footstepsound")

        stateFootstepSound=Toggle(("%d" % stateFootstepSound.val),    2,  0,  260,  20, 18, stateFootstepSound.val, "State (ON/OFF)" )
        # careful now, these are decimal numbers (the class converts them to hex just before sending the values to the object)
        menuFootstepSound= Menu("FootstepSound:%t| Dirt %x0| Puddle %x1| Water(shallow)%x2| Tile %x3| Metal %x4| WoodBridge %x5| RopeLadder %x6| Grass %x7| Brush %x8| HardWood %x9| Rug %x10| Stone %x11| Mud %x12| MetalLadder %x13| WoodLadder %x14| DeepWater %x15| Maintainer(Glass) %x16| Maintianer(Stone) %x17| Swimming %x18| none %x19", 2, 100, 260, 80, 18, menuFootstepSound.val, "Sound of the Footstep Region")

    stateColType=   Toggle(("%d" % stateColType.val),        2,  0,  240,  20, 18, stateColType.val, "State (ON/OFF)" )
    showColType=   String("col_type:     ",            2, 20,  240, 160, 18, showColType.val, showColTypeStringLen, "Collision Type")

    stateMass=   Toggle(("%d" % stateMass.val),            2,  0,  220,  20, 18, stateMass.val, "State (ON/OFF)" )
    showMass=      Number("mass:       ",            2, 20,  220, 120, 18, showMass.val, -10.0, 10.0, "Object Mass")

    stateRC=   Toggle(("%d" % stateRC.val),            2,  0,  200,  20, 18, stateRC.val, "State (ON/OFF)" )
    showRC=        Number("rc:          ",            2, 20,  200, 120, 18, showRC.val,   -10.0, 10.0, "Object Relative friction Coefficient")
    stateEL=   Toggle(("%d" % stateEL.val),            2,  0,  180,  20, 18, stateEL.val, "State (ON/OFF)" )
    showEL=        Number("el:          ",            2, 20,  180, 120, 18, showEL.val,   -10.0, 10.0, "Object ELasticity")

    stateLight=   Toggle(("%d" % stateLight.val),        2,  0,  160,  20, 18, stateLight.val, "State (ON/OFF)" )
    showLight=     String("light:       ",            2, 20,  160, 160, 18, showLight.val,  showLightStringLen,  "Light Type(s)")

    #if (SwimRegSen.val == 0):
    #if (SwimRegSen.val == 1):
    if ( (SwimRegSen.val == 1 or Custom.val == 1) and (menuAlcSpecial.val == 5 or menuAlcSpecial.val == 6) ):
        if (MaskChanges):
            # leave this up to the user
            pass
        else:
            # make sure the state of the SwimSFC_Fx is set to ON
            stateCurrentDummy.val = 1
            stateSwimSFC_F1.val   = 1
            stateSwimSFC_F2.val   = 1
            stateSwimSFC_F3.val   = 1
            stateSwimSFC_F4.val   = 1
            stateSwimSFC_F5.val   = 1
        stateCurrentDummy= Toggle(("%d" % stateCurrentDummy.val), 2,  145,  140, 20, 18, stateCurrentDummy.val, "State (ON/OFF)" )
        showCurrentDummy= String("currentdummy: ",2, 165,  140, 120, 18, showCurrentDummy.val, showCurrentDummyStringLen, "SwimCurrentDummy")
        stateSwimSFC_F1= Toggle(("%d" % stateSwimSFC_F1.val), 2,  145, 120, 20, 18, stateSwimSFC_F1.val, "State (ON/OFF)" )
        showSwimSFC_F1= Number("f1:  ",        2, 165, 120, 80, 18, showSwimSFC_F1.val,  -10000.0, 10000.0,  "Horizontal/Circular Force (x=x+f1)")
        stateSwimSFC_F2= Toggle(("%d" % stateSwimSFC_F2.val), 2,  145, 100, 20, 18, stateSwimSFC_F2.val, "State (ON/OFF)" )
        showSwimSFC_F2= Number("f2:  ",        2, 165, 100, 80, 18, showSwimSFC_F2.val,  -10000.0, 10000.0,  "Flow/Foam type (horizontal?)")
        stateSwimSFC_F3= Toggle(("%d" % stateSwimSFC_F3.val), 2,  145,  80, 20, 18, stateSwimSFC_F3.val, "State (ON/OFF)" )
        showSwimSFC_F3= Number("f3:  ",        2, 165,  80, 80, 18, showSwimSFC_F3.val,  -10000.0, 10000.0,  "Vertical Force BELOW SwimCurrentDummy point (y=y+f3)")
        stateSwimSFC_F4= Toggle(("%d" % stateSwimSFC_F4.val), 2,  145,  60, 20, 18, stateSwimSFC_F4.val, "State (ON/OFF)" )
        showSwimSFC_F4= Number("f4:  ",        2, 165,  60, 80, 18, showSwimSFC_F4.val,  -10000.0, 10000.0,  "Flow/Foam type (vertical?)")
        stateSwimSFC_F5= Toggle(("%d" % stateSwimSFC_F5.val), 2,  145,  40, 20, 18, stateSwimSFC_F5.val, "State (ON/OFF)" )
        showSwimSFC_F5= Number("f5:  ",        2, 165,  40, 80, 18, showSwimSFC_F5.val,  -10000.0, 10000.0,  "Vertical Force ABOVE SwimCurrentDummy point (y=y+f5)")
        #stateColFlags5= Toggle(("%d" % stateColFlags5.val), 2,  0,    40, 20, 18, stateColFlags5.val, "State (ON/OFF)" )
        #showColFlags5= String("col_flags5:  ",        2, 20,   40, 160, 18, showColFlags5.val,  showColFlags5StringLen, "Collision Flags 5")
        stateColFlags0= Toggle(("%d" % stateColFlags0.val), 2,  0,  140, 20, 18, stateColFlags0.val, "State (ON/OFF)" )
        showColFlags0= String("col_flags0:   ",        2, 20,  140, 120, 18, showColFlags0.val,  showColFlags0StringLen, "Collision Flags 0")
        stateColFlags1= Toggle(("%d" % stateColFlags1.val), 2,  0,  120, 20, 18, stateColFlags1.val, "State (ON/OFF)" )
        showColFlags1= String("col_flags1: ",        2, 20,  120, 120, 18, showColFlags1.val,  showColFlags1StringLen, "Collision Flags 1")
        stateColFlags2= Toggle(("%d" % stateColFlags2.val), 2,  0,  100, 20, 18, stateColFlags2.val, "State (ON/OFF)" )
        showColFlags2= String("col_flags2: ",        2, 20,  100, 120, 18, showColFlags2.val,  showColFlags2StringLen, "Collision Flags 2")
        stateColFlags3= Toggle(("%d" % stateColFlags3.val), 2,  0,   80, 20, 18, stateColFlags3.val, "State (ON/OFF)" )
        showColFlags3= String("col_flags3:   ",        2, 20,   80, 120, 18, showColFlags3.val,  showColFlags3StringLen, "Collision Flags 3")
        stateColFlags4= Toggle(("%d" % stateColFlags4.val), 2,  0,   60, 20, 18, stateColFlags4.val, "State (ON/OFF)" )
        showColFlags4= String("col_flags4: ",        2, 20,   60, 120, 18, showColFlags4.val,  showColFlags4StringLen, "Collision Flags 4")
        stateColFlags5= Toggle(("%d" % stateColFlags5.val), 2,  0,   40, 20, 18, stateColFlags5.val, "State (ON/OFF)" )
        showColFlags5= String("col_flags5: ",        2, 20,   40, 120, 18, showColFlags5.val,  showColFlags5StringLen, "Collision Flags 5")
    else:
        stateColFlags0= Toggle(("%d" % stateColFlags0.val), 2,  0,  140, 20, 18, stateColFlags0.val, "State (ON/OFF)" )
        showColFlags0= String("col_flags0:  ",        2, 20,  140, 160, 18, showColFlags0.val,  showColFlags0StringLen, "Collision Flags 0")
        stateColFlags1= Toggle(("%d" % stateColFlags1.val), 2,  0,  120, 20, 18, stateColFlags1.val, "State (ON/OFF)" )
        showColFlags1= String("col_flags1:  ",        2, 20,  120, 160, 18, showColFlags1.val,  showColFlags1StringLen, "Collision Flags 1")
        stateColFlags2= Toggle(("%d" % stateColFlags2.val), 2,  0,  100, 20, 18, stateColFlags2.val, "State (ON/OFF)" )
        showColFlags2= String("col_flags2:  ",        2, 20,  100, 160, 18, showColFlags2.val,  showColFlags2StringLen, "Collision Flags 2")
        stateColFlags3= Toggle(("%d" % stateColFlags3.val), 2,  0,   80, 20, 18, stateColFlags3.val, "State (ON/OFF)" )
        showColFlags3= String("col_flags3:  ",        2, 20,   80, 160, 18, showColFlags3.val,  showColFlags3StringLen, "Collision Flags 3")
        stateColFlags4= Toggle(("%d" % stateColFlags4.val), 2,  0,   60, 20, 18, stateColFlags4.val, "State (ON/OFF)" )
        showColFlags4= String("col_flags4:  ",        2, 20,   60, 160, 18, showColFlags4.val,  showColFlags4StringLen, "Collision Flags 4")
        stateColFlags5= Toggle(("%d" % stateColFlags5.val), 2,  0,   40, 20, 18, stateColFlags5.val, "State (ON/OFF)" )
        showColFlags5= String("col_flags5:  ",        2, 20,   40, 160, 18, showColFlags5.val,  showColFlags5StringLen, "Collision Flags 5")
        if (MaskChanges):
            # leave this up to the user
            pass
        else:
            # make sure the state of the SwimSFC_Fx is set to OFF
            stateCurrentDummy.val = 0
            stateSwimSFC_F1.val   = 0
            stateSwimSFC_F2.val   = 0
            stateSwimSFC_F3.val   = 0
            stateSwimSFC_F4.val   = 0
            stateSwimSFC_F5.val   = 0

    Button("EXIT", 1, 170, 10, 80, 25)
    Button("FETCH", 18, 85, 10, 80, 25)
    Button("APPLY", 3, 0, 10, 80, 25)

    #glColor3f(0.5,0.75,0.5)
    #glRasterPos2i(10, 8)
    #Text("built with code from: www.geocities.com/blenderdungeon/")



def event(evt, val):    
    if (evt== QKEY and not val): Exit()


def bevent(evt):
    global Default, SfxRegSen, GenDetReg, LdrBottom, LdrBounds, LdrTop, CollObj, GenObjWC, GenObjNC, Kickable, SfxFtRegSen, SwimRegSen, SwimDetRegSen, Clickable, Custom
    global debug, verbose, propertyType, showName, showNameStringLen, filename
    global showPageNum, showPageNumStringLen, showAlcType, showAlcTypeStringLen, showColType, showColTypeStringLen
    global showMass, showEL, showRC, showLight, showLightStringLen, showMaterial, showMaterialStringLen
    global showColFlags0, showColFlags0StringLen, showColFlags1, showColFlags1StringLen, showColFlags2, showColFlags2StringLen
    global showColFlags3, showColFlags4StringLen, showColFlags4, showColFlags4StringLen, showColFlags5, showColFlags5StringLen
    global stateName, stateMaterial, statePageNum, stateAlcType, stateColType
    global stateMass, stateEL, stateRC, stateLight, stateMaterial
    global stateColFlags0, stateColFlags1, stateColFlags2
    global stateColFlags3, stateColFlags4, stateColFlags5
    global showSwimSFC_F1, showSwimSFC_F2, showSwimSFC_F3, showSwimSFC_F4, showSwimSFC_F5
    global stateSwimSFC_F1, stateSwimSFC_F2, stateSwimSFC_F3, stateSwimSFC_F4, stateSwimSFC_F5
    global menuName, menuMaterial
    global showAlcSpecial, menuAlcSpecial, showAlcSpecialStringLen, showFootstepSound, showFootstepSoundStringLen
    global stateAlcSpecial, stateFootstepSound, menuFootstepSound
    global stateCurrentDummy, showCurrentDummy, showCurrentDummyStringLen
    global MaskChanges, ChangeMode

    if   (evt== 1):
        print "User chose exit."
        Exit()
    elif (evt== 2):
        if debug: print "Custom(ized) User settings (not fully implemented (yet))"
        if ( menuName.val == 1 ):
            showName.val = "default"
        elif ( menuName.val == 4 ):
            print "Object name: %s" % showName.val 
        else:
            showName.val = "default"

        if ( menuMaterial.val == 2 ):
            showMaterial.val = "default"
        elif ( menuMaterial.val == 3 ):
            showMaterial.val = "parent"
        elif ( menuMaterial.val == 4 ):
            print "Material name: %s" % showMaterial.val 
        else:
            showMaterial.val = "material"

        # check if the ChangeMode is on 
        if ( ChangeMode.val == 1):
            MaskChanges = 1
        else:
            MaskChanges = 0
            
        if ( Custom.val == 0):
            Custom.val = 1
        if debug: print "MenuFootstepSound.val = %s" % menuFootstepSound.val                
        propertyType = "Custom"
        updateProperties(propertyType)
        updateToggleButtons(Custom)
    #
    # don't worry, 3 is defined below
    #
    elif (evt== 4):
        propertyType = "SfxRegSen"
        if debug: print "%s selected" % propertyType
        updateToggleButtons(SfxRegSen)
        updateProperties(propertyType)
        setStates(1)
    elif (evt== 5):
        propertyType = "GenDetReg"
        if debug: print "%s selected" % propertyType
        updateToggleButtons(GenDetReg)
        updateProperties(propertyType)
        setStates(1)
    elif (evt== 6):
        propertyType = "Kickable"
        if debug: print "%s selected" % propertyType
        updateToggleButtons(Kickable)
        updateProperties(propertyType)
        setStates(1)
    elif (evt== 7):
        propertyType = "CollObj"
        if debug: print "%s   selected" % propertyType
        updateToggleButtons(CollObj)
        updateProperties(propertyType)
        setStates(1)
    elif (evt== 8):
        propertyType = "GenObjWC"
        if debug: print "%s  selected" % propertyType
        updateToggleButtons(GenObjWC)
        updateProperties(propertyType)
        setStates(1)
    elif (evt== 9):
        propertyType = "GenObjNC"
        if debug: print "%s  selected" % propertyType
        updateToggleButtons(GenObjNC)
        updateProperties(propertyType)
        setStates(1)
    elif (evt== 10):
        if debug: print "%s  selected" % propertyType
        if ( Custom.val == 0):
            propertyType = "GenObjWC"
            updateToggleButtons(GenObjWC)
            updateProperties(propertyType)
            setStates(1)
        else:
            propertyType = "Custom"
            updateToggleButtons(Custom)
            list=getCustomPropertiesList()
            updateProperties(propertyType,list)
    elif (evt== 11):
        propertyType = "SfxFtRegSen"
        if debug: print "%s selected" % propertyType
        updateToggleButtons(SfxFtRegSen)
        updateProperties(propertyType)
        setStates(2) # set all except the swimXcursfc force values & climb region
    elif (evt== 12):
        propertyType = "SwimRegSen"
        if debug: print "%s selected" % propertyType
        updateToggleButtons(SwimRegSen)
        updateProperties(propertyType)
        #setStates(1,1) # Also set the swimsfc_fx (defaults to 0)
        setStates(1,1,1,0) # set all except the footstep & climb region
    elif (evt== 13):
        propertyType = "SwimDetRegSen"
        if debug: print "%s selected" % propertyType
        updateToggleButtons(SwimDetRegSen)
        updateProperties(propertyType)
        #setStates(1)
        setStates(1,0,1,0) # set all except the swimXcursfc & footstep & climb regions
    elif (evt== 14):
        propertyType = "LdrBottom"
        if debug: print "%s selected" % propertyType
        updateToggleButtons(LdrBottom)
        updateProperties(propertyType)
        #setStates(1)
        setStates(1,0,1,0,1) # set AlcSpecial and ClimbRegion
    elif (evt== 15):
        propertyType = "LdrTop"
        if debug: print "%s selected" % propertyType
        updateToggleButtons(LdrTop)
        updateProperties(propertyType)
        #setStates(1)
        setStates(1,0,1,0,1) # set AlcSpecial and ClimbRegion
    elif (evt== 16):
        propertyType = "LdrBounds"
        if debug: print "%s selected" % propertyType
        updateToggleButtons(LdrBounds)
        updateProperties(propertyType)
        setStates(1)
    elif (evt== 17):
        propertyType = "Clickable"
        if debug: print "%s selected" % propertyType
        updateToggleButtons(Clickable)
        updateProperties(propertyType)
        setStates(1,0,1,0) # set all except the swimXcursfc & footstep & climb regions
    elif (evt== 18):
        if debug: print "Fetch properties (not fully implemented)"
        propertiesList = myURUProperties.fetchSelectedProperties()
        if ( Custom.val == 0):
            Custom.val = 1
        propertyType = "Custom"
        updateProperties(propertyType,propertiesList)
        updateToggleButtons(Custom)
    elif (evt== 19):
        if debug: print "Save Prop selected (not implemented)"
        # TODO: save custom Properties to a file
    elif (evt== 3): 
        print "Applying properties..."
        # make sure we aren't in the edit mode (get out if we are)
        checkEditMode()
        # Try to set URU Properties for the selected Object(s)
        #
        if verbose: print "Checking and setting the naming scheme"

        if (showName.val != "default"):
            myURUProperties.customName = showName.val
            myURUProperties.nameScheme = "custom"
        else:
            myURUProperties.nameScheme = "default"

        if verbose: print "Trying to apply properties to selected objects"

        # check if the ChangeMode is on 
        if ( ChangeMode.val == 1):
            MaskChanges = 1
        else:
            MaskChanges = 0
            
        list=getCustomPropertiesList()
        #myURUProperties.setUruPropertiesForSelectedObjects(propertyType,list)
        myURUProperties.setUruPropertiesForSelectedObjects(propertyType,list,MaskChanges)

        print "\nDone"


    # redraw the menu
    Draw()

    if debug: print "Hey I fell though .. evt = %d" % evt


# Register the 3 functions to make the gui menu work
#
#def URUProperties_menu()
#    Register(draw, event, bevent)
    
Register(draw, event, bevent)
