Ejemplo n.º 1
0
    def initiateActionEvent(self,event):
        pos = event.pos

        if self.minimap.rect.collidepoint(pos):
            mapClickPoint = self.minimap.clickToGridPos(pos)
            if mapClickPoint is not None:
                return 
            else:            
                cartPos = specialMath.isoToCart(pos)
                destCart = self.cartScrollLoc[0] + cartPos[0], \
                            self.cartScrollLoc[1] + cartPos[1]
        else:
            cartPos = specialMath.isoToCart(pos)
            destCart = self.cartScrollLoc[0] + cartPos[0], \
                        self.cartScrollLoc[1] + cartPos[1]
        
        clicked = specialMath.closestEntity(self.viewportEntities,pos)
        
        if clicked:
            drawRect = clicked.rect.move(clicked.drawOffset)
            drawRect.center = specialMath.cartToIso(drawRect.center)
        
            if not drawRect.collidepoint(pos):
                clicked = None
        
        if clicked is not None:
            self.currentMenu = self.contextualMenu.getMenu(self.selectedEntities,clicked)
        else:
            self.currentMenu = self.contextualMenu.getMenu(self.selectedEntities,WayPoint(*destCart))
            
        if self.currentMenu is not None:
            self.currentMenu.open(event.pos)
Ejemplo n.º 2
0
 def completeActionEvent(self,event):
     attacking = False
     pos = event.pos
     
     # Performs action indicated by menu if menu is visible
     # and exists.  Otherwise, the menu reference is destroyed.
     if self.currentMenu is not None and self.currentMenu.visible:
         self.selectMenu(pos)
         return # Do not do anything else if the menu is selected
     else:
         self.currentMenu = None
     
     # Sets destination in cartesian coordinates
     # Handles minimap clicks
     if self.minimap.rect.collidepoint(pos):
         mapClickPoint = self.minimap.clickToGridPos(pos)
         if mapClickPoint is not None:
             destCart = mapClickPoint
         else:
             cartPos = specialMath.isoToCart(pos)
             destCart = (self.cartScrollLoc[0] + cartPos[0])%self.worldSize[0], \
                         (self.cartScrollLoc[1] + cartPos[1])%self.worldSize[1]
     else:
         cartPos = specialMath.isoToCart(pos)
         destCart = (self.cartScrollLoc[0] + cartPos[0])%self.worldSize[0], \
                     (self.cartScrollLoc[1] + cartPos[1])%self.worldSize[1]
     
     # Determines closest entity to a click
     clicked = specialMath.closestEntity(self.viewportEntities,pos)
     
     if clicked:
         drawRect = clicked.rect.move(clicked.drawOffset)
         drawRect.center = specialMath.cartToIso(drawRect.center)
     
         if not drawRect.collidepoint(pos):
             clicked = None
     
     # clicked is now either None or the closest Entity to the click
     if clicked:
         for selected in self.selectedEntities:
             attacking=True
             if isinstance(selected,Unit):
                 selected.initAction(clicked)
    
     if not attacking:
         eCenter = specialMath.centerOfEntityList(self.selectedEntities, self.worldSize)
         for entity in self.selectedEntities:
             if not entity.status==Locals.MOVING:
                 entity.dest=entity.realCenter
             if entity.movable: entity.status=Locals.MOVING
             dx = entity.rect.center[0] - eCenter[0]
             dy = entity.rect.center[1] - eCenter[1]
             newLoc = (dx+destCart[0],dy+destCart[1])
             entity.addToPath(newLoc)
Ejemplo n.º 3
0
    def clickEvent(self,event):
        """
        What works:
        single - clicking on units
        click on ground to deselect all (without a modifier)
        click a unit while holding a modifier to add to the selection
        click a selected unit while holding a modifier to remove from the selection
        """
        
        pos = event.pos
        
        if self.minimap.rect.collidepoint(pos):
            mapClickPoint = self.minimap.clickToGridPos(pos)
            if mapClickPoint is not None:
                self._setCartScrollLocation(mapClickPoint)
                return
        cartPos = specialMath.isoToCart(pos)
        destCart = (self.cartScrollLoc[0] + cartPos[0])/self.worldSize[0], \
                       (self.cartScrollLoc[1] + cartPos[1])/self.worldSize[1]
        
        # MAY BREAK THINGS - CHECK
        #clicked = specialMath.closestEntity(self.viewportEntities,pos)
        clicked = specialMath.closestEntity(self.myViewportEntities,pos)
        
        if clicked:
            drawRect = clicked.rect.move(clicked.drawOffset)
            drawRect.center = specialMath.cartToIso(drawRect.center)
            
            selectRect=clicked.getSelectionRect(drawRect)
            
            if not selectRect.collidepoint(pos):
                clicked = None
        
        if isinstance(event,Event.SelectionEvent):
            for e in self.selectedEntities:
                e.deselect()

            self.selectedEntities = []
            self._selectedEntitiesChanged = True

        if clicked and self.ownsEntity(clicked):
            # Determines if the closest entity is already selected.
            # If it is, it makes it no longer selected.
            if clicked.selected:
                clicked.deselect()
                self.selectedEntities.remove(clicked)
            else:
                clicked.select()
                self.selectedEntities.append(clicked)
                #print clicked.healthStr()
                #if isinstance(clicked, Unit): print '\n' + str(clicked.inventory)
            self._selectedEntitiesChanged = True