def onLeftMouse( self ):
		self.clickX = 0
		self.clickY = 0
		
		# first see if there's a gizmo in the house
		if self.objInfo.overGizmo:
			# if so, let it take care of things
			WorldEditor.gizmoClick()
			return

		if not self.mouseRevealer.size:
			# nothing to click on, start a marquee selection. This will take
			# care of clearing the selection if it's only a click.
			self.startDragSelect()
			return

		# Check if control is held down, it indicates that we want to toggle
		# what's pointed to in/out of the selection
		if (WorldEditor.isKeyDown( KEY_LCONTROL ) or WorldEditor.isKeyDown( KEY_RCONTROL )):
			# if we're pointing at a subset of the selection
			if set_issubset( self.selection, self.mouseRevealer):
				# remove the subset
				self.selection.rem( self.mouseRevealer )
				self.selUpdate()
				return
			else:
				# add the mouseRevealer to the selection
				set_union( self.selection, self.mouseRevealer )
				self.selUpdate()
				return
		else:
			# if the selection is totally different to what's under the mouse
			# specifically, if we're only pointing at a subset of the
			# selection, we don't want to set the selection to that, we want
			# to drag it instead (which happens below )
			#if not set_intersection_new( self.selection, self.mouseRevealer).size:
			if not set_issubset( self.selection, self.mouseRevealer ):
				# set the selection to what's under the mouse
				set_assign( self.selection, self.mouseRevealer )
				self.selUpdate()



		# nothing under the mouse, bail
		if not self.selection.size:
			return

		if not WorldEditor.getOptionInt( "dragOnSelect" ):
			if not WorldEditor.isKeyDown( KEY_V ):
				return

		# ok, it's drag time
		self.dragging = 1
	def onMiddleMouse( self ):
		# ensure that we both have a selection and something under the mouse
		if not self.selection.size or not self.mouseRevealer.size:
			return

		# ensure that we're in shell mode
		if not WorldEditor.isChunkSelected():
			return

		# If v is held down, clone and snap the shell under the cursor
		if WorldEditor.isKeyDown( KEY_V ):
			group = WorldEditor.cloneAndAutoSnap( self.mouseRevealer, self.selection )
			if ( group != None ):
				set_assign( self.selection, group )
				self.selUpdate()
			else:
				WorldEditor.addCommentaryMsg( "No matching portals", 2 )

			return

		# if the selection is different to what's under the mouse,
		if set_difference_new( self.selection, self.mouseRevealer ).size:
			# auto snap the shells together
			if not WorldEditor.autoSnap( self.selection, self.mouseRevealer ):
				WorldEditor.addCommentaryMsg( "No matching portals" )
Example #3
0
	def selUpdate( self ):
		if self.selection.size:
			if WorldEditor.isKeyDown( KEY_C ):
				self.selEditor = WorldEditor.ChunkEditor( self.selection )
			else:
				self.selEditor = WorldEditor.ChunkItemEditor( self.selection )
			WorldEditor.setCurrentEditors( self.selEditor )
			print "Selected a", self.selEditor.description
		else:
			self.selEditor = None
			WorldEditor.setCurrentEditors()
Example #4
0
	def handleEvent( self, type, key, modifiers, c ):

		if ( WorldEditor.isKeyDown( key ) ):

			if ( key == Keys.KEY_LEFTMOUSE ) :
				c.textureName = self.textureMouseDown
				self.clickState = 1
				return 1

		else:
			
			if ( key == Keys.KEY_LEFTMOUSE ) :
				c.textureName = self.textureFocus
				if ( self.clickState == 1 ):
					if ( self.eventHandler != None ):
						self.eventHandler.onClick( self.buttonEvent )
				return 1
		
		return 0
Example #5
0
    def handleEvent(self, type, key, modifiers, c):

        if (WorldEditor.isKeyDown(key)):

            if (key == Keys.KEY_LEFTMOUSE):
                c.textureName = self.textureMouseDown
                self.clickState = 1
                return 1

        else:

            if (key == Keys.KEY_LEFTMOUSE):
                c.textureName = self.textureFocus
                if (self.clickState == 1):
                    if (self.eventHandler != None):
                        self.eventHandler.onClick(self.buttonEvent)
                return 1

        return 0
	def update( self, dTime, tool ):
		# must use update to check for this, key events aren't reliable
		if not WorldEditor.isKeyDown( KEY_LEFTMOUSE ):
			if (WorldEditor.isKeyDown( KEY_LCONTROL ) or WorldEditor.isKeyDown( KEY_RCONTROL )):
				# add the set
				set_union( self.chunkItemFunctor.selection, self.mouseRevealer )
			elif WorldEditor.isKeyDown( KEY_LALT ) or WorldEditor.isKeyDown( KEY_RALT ):
				# remove the set
				self.chunkItemFunctor.selection.rem( self.mouseRevealer )
			else:
				# set the selection to our mouse revaler
				set_assign( self.chunkItemFunctor.selection, self.mouseRevealer )

			if not WorldEditor.isKeyDown( KEY_LALT ) and not WorldEditor.isKeyDown( KEY_RALT ):
				# not removing, so also add whatever is under the cursor
				set_union( self.chunkItemFunctor.selection, self.chunkItemFunctor.mouseRevealer )

			self.chunkItemFunctor.selUpdate()

			WorldEditor.popTool( )
	def onMouseEvent( self, mx, my, mz ):
		handled = 0

		if mx or my:
			self.mouseMoved = 1

		legacyMouse = WorldEditor.getOptionInt( "input/legacyMouseWheel" )
		itemsRotated = 0
		cameraSpeedChanged = False
		
		if legacyMouse != 0:
			# if using legacy mouse
			if WorldEditor.isKeyDown( KEY_MOUSE1 ):
				# Change camera speed with right click
				self.handleWheelCameraSpeed( mz )
				cameraSpeedChanged = True
			elif WorldEditor.tool():
				# handle the tool
				handled = WorldEditor.tool().handleMouseEvent( mx, my, mz )
				itemsRotated = self.itemTool.functor.script.selection.size
		else: 
			# if using new mouse
			if WorldEditor.tool() and mz == 0:
				# handle the tool
				handled = WorldEditor.tool().handleMouseEvent( mx, my, mz )
			elif WorldEditor.isKeyDown( KEY_SPACE ):
				# Change camera speed with space
				self.handleWheelCameraSpeed( mz )
				cameraSpeedChanged = True
			elif ( WorldEditor.isKeyDown( KEY_LSHIFT ) or WorldEditor.isKeyDown( KEY_RSHIFT ) ) and WorldEditor.tool():
				# handle the tool with shift
				handled = WorldEditor.tool().handleMouseEvent( mx, my, mz )
				itemsRotated = self.itemTool.functor.script.selection.size
			elif mz != 0 and \
					( WorldEditor.isKeyDown( KEY_LCONTROL ) or WorldEditor.isKeyDown( KEY_RCONTROL ) ) and \
					self.itemTool.functor.script.selection.size > 0:
				WorldEditor.rotateSnap( self.itemTool.functor.script.selection, mz, self.itemTool.functor.script.mouseRevealer )
				itemsRotated = self.itemTool.functor.script.selection.size

		if not handled:
			handled = WorldEditor.camera().handleMouseEvent( mx, my, mz )
		
		if not handled and ( mz != 0 ) and not itemsRotated and not cameraSpeedChanged:
			# zoom using scroll wheel
			handled = 1
			view = WorldEditor.camera().view
			view.invert()
			mult = mz / 1200.0

			if WorldEditor.isCapsLockOn():
				mult = mult * WorldEditor.camera().turboSpeed
			else:
				mult = mult * WorldEditor.camera().speed
			
			forward = view.applyToAxis( 2 )
			
			view.translation = (
				view.translation[0] + forward[0] * mult,
				view.translation[1] + forward[1] * mult,
				view.translation[2] + forward[2] * mult )
			
			view.invert()
			WorldEditor.camera().view = view

		return handled
		pass

	def startDragSelect( self ):
		# add a drag select tool, which will pop itself and set our
		# selection when done.
		nt = WorldEditor.Tool()
		nt.locator = bd.itemTool.locator.subLocator
		nt.functor = Functor.ScriptedFunctor( DragSelectFunctor(nt, self) )
		WorldEditor.pushTool( nt )
		
	def dragDeltaExceeded( self ):
		return abs( self.clickX ) > self.dragStartDelta or abs( self.clickY ) > self.dragStartDelta

	def onMouseEvent( self, (dx,dy,dz), tool ):
		if dz != 0 \
			and ( WorldEditor.isKeyDown( KEY_LSHIFT ) \
				  or WorldEditor.isKeyDown( KEY_RSHIFT ) \
				  or WorldEditor.getOptionInt( "input/legacyMouseWheel" ) != 0 ) \
			and self.selection.size:
			rotateTool = WorldEditor.Tool()
			rotateTool.functor = Functor.WheelRotator()
			rotateTool.locator = Locator.OriginLocator()

			rotateTool.handleMouseEvent( dx, dy, dz )

			# Add the mousewheel rotate tool, it'll automatically pop itself
			WorldEditor.pushTool( rotateTool )

		if not WorldEditor.isKeyDown( KEY_MOUSE0 ):
			# just to make sure that leftMouseDown has a consistent value
			self.leftMouseDown = 0
Example #9
0
	def handleEvent( self, type, key, modifiers, c ):

		shiftDown = WorldEditor.isKeyDown( Keys.KEY_LSHIFT ) or WorldEditor.isKeyDown( Keys.KEY_RSHIFT )

		if ( WorldEditor.isKeyDown( key ) ):

			if ( key == Keys.KEY_BACKSPACE ) :
				c.text = c.text[0:len(c.text)-1]
				c.text = c.text[0:len(c.text)-1]	
				c.text = c.text + "_"

				return 1

			elif ( key >= Keys.KEY_1 and key <= Keys.KEY_0 ) :
				character = WorldEditor.keyToString( key )

				c.text = c.text[0:len(c.text)-1]
				c.text = c.text + character
				c.text = c.text + "_"

				return 1

			elif ( key >= Keys.KEY_Q and key <= Keys.KEY_P ) :
				character = WorldEditor.keyToString( key )
				if ( not shiftDown ):
					character = string.swapcase( character )

				c.text = c.text[0:len(c.text)-1]
				c.text = c.text + character
				c.text = c.text + "_"

				return 1

			elif ( key >= Keys.KEY_A and key <= Keys.KEY_L ) :
				character = WorldEditor.keyToString( key )
				if ( not shiftDown ):
					character = string.swapcase( character )

				c.text = c.text[0:len(c.text)-1]
				c.text = c.text + character
				c.text = c.text + "_"

				return 1

			elif ( key >= Keys.KEY_Z and key <= Keys.KEY_M ) :
				character = WorldEditor.keyToString( key )
				if ( not shiftDown ):
					character = string.swapcase( character )

				c.text = c.text[0:len(c.text)-1]
				c.text = c.text + character
				c.text = c.text + "_"

				return 1

			elif ( key == Keys.KEY_SPACE ) :

				c.text = c.text[0:len(c.text)-1]
				c.text = c.text + " "
				c.text = c.text + "_"

				return 
				
			elif ( key == Keys.KEY_RETURN ) :
				if ( self.eventHandler != None ):
					textString = c.text
					self.eventHandler.onClick( c.text[0:len(c.text)-1] )
				

			if ( key == Keys.KEY_LEFTMOUSE ) :
				c.colour = ( 128, 255, 128, 255 )
				return 1

		else:
			
			if ( key == Keys.KEY_LEFTMOUSE ) :
				c.colour = ( 128, 128, 128, 255 )
				return 1
		
		return 0
Example #10
0
    def handleEvent(self, type, key, modifiers, c):

        shiftDown = WorldEditor.isKeyDown(
            Keys.KEY_LSHIFT) or WorldEditor.isKeyDown(Keys.KEY_RSHIFT)

        if (WorldEditor.isKeyDown(key)):

            if (key == Keys.KEY_BACKSPACE):
                c.text = c.text[0:len(c.text) - 1]
                c.text = c.text[0:len(c.text) - 1]
                c.text = c.text + "_"

                return 1

            elif (key >= Keys.KEY_1 and key <= Keys.KEY_0):
                character = WorldEditor.keyToString(key)

                c.text = c.text[0:len(c.text) - 1]
                c.text = c.text + character
                c.text = c.text + "_"

                return 1

            elif (key >= Keys.KEY_Q and key <= Keys.KEY_P):
                character = WorldEditor.keyToString(key)
                if (not shiftDown):
                    character = string.swapcase(character)

                c.text = c.text[0:len(c.text) - 1]
                c.text = c.text + character
                c.text = c.text + "_"

                return 1

            elif (key >= Keys.KEY_A and key <= Keys.KEY_L):
                character = WorldEditor.keyToString(key)
                if (not shiftDown):
                    character = string.swapcase(character)

                c.text = c.text[0:len(c.text) - 1]
                c.text = c.text + character
                c.text = c.text + "_"

                return 1

            elif (key >= Keys.KEY_Z and key <= Keys.KEY_M):
                character = WorldEditor.keyToString(key)
                if (not shiftDown):
                    character = string.swapcase(character)

                c.text = c.text[0:len(c.text) - 1]
                c.text = c.text + character
                c.text = c.text + "_"

                return 1

            elif (key == Keys.KEY_SPACE):

                c.text = c.text[0:len(c.text) - 1]
                c.text = c.text + " "
                c.text = c.text + "_"

                return

            elif (key == Keys.KEY_RETURN):
                if (self.eventHandler != None):
                    textString = c.text
                    self.eventHandler.onClick(c.text[0:len(c.text) - 1])

            if (key == Keys.KEY_LEFTMOUSE):
                c.colour = (128, 255, 128, 255)
                return 1

        else:

            if (key == Keys.KEY_LEFTMOUSE):
                c.colour = (128, 128, 128, 255)
                return 1

        return 0