Beispiel #1
0
bool Scene::scanSpots() {
  bool foundAction = false;
  
  // Check if the current node has spots to draw, and also if
  // we aren't dragging the view
  if (_canDrawSpots) {
    Node* currentNode = _currentRoom->currentNode();
    
    // Check if the current node is enabled
    if (currentNode->isEnabled()) {
      renderManager.disableAlpha();
      renderManager.disableTextures();
      
      // First pass: draw the colored spots
      currentNode->beginIteratingSpots();
      do {
        Spot* spot = currentNode->currentSpot();
        
        if (spot->hasColor() && spot->isEnabled()) {
          renderManager.setColor(spot->color());
          renderManager.drawPolygon(spot->arrayOfCoordinates(), spot->face());
        }
      } while (currentNode->iterateSpots());
      
      // Second pass: test the color under the cursor and
      // set action, if available
      
      // FIXME: Should unify the checks here a bit more...
      if (!cursorManager.isDragging() && !cursorManager.onButton()) {
        Point position = cursorManager.position();
        uint32_t color = renderManager.testColor(position.x, position.y);
        if (color) {
          currentNode->beginIteratingSpots();
          do {
            Spot* spot = currentNode->currentSpot();
            if (color == spot->color()) {
              cursorManager.setAction(*spot->action());
              foundAction = true;
              if (_hoveredSpot != spot) {
                if (_hoveredSpot && _hoveredSpot->hasOnUnhoverCallback()) {
                  Script::instance().processCallback(_hoveredSpot->onUnhoverCallback(),
                                                     _hoveredSpot->luaObject());
                }
                _hoveredSpot = spot;
                if (spot->hasOnHoverCallback()) {
                  Script::instance().processCallback(spot->onHoverCallback(), spot->luaObject());
                }
              }
              break;
            }
          } while (currentNode->iterateSpots());
        }
        
        if (!foundAction) {
          if (_hoveredSpot && _hoveredSpot->hasOnUnhoverCallback()) {
            Script::instance().processCallback(_hoveredSpot->onUnhoverCallback(),
                                               _hoveredSpot->luaObject());
          }
          _hoveredSpot = nullptr;
          cursorManager.removeAction();
          
          if (cameraManager.isPanning())
            cursorManager.setCursor(cameraManager.cursorWhenPanning());
          else cursorManager.setCursor(kCursorNormal);
        }
      }
      
      renderManager.enableAlpha();
      renderManager.enableTextures();
    }
  }
  
  renderManager.clearView();
  
  if (foundAction) return true;
  else return false;
}