Exemplo n.º 1
0
void InfoBoxManager::showHelp( const Tile& tile )
{
  LandOverlayPtr overlay = tile.getTerrain().getOverlay();
  BuildingType type;

  if( _d->showDebugInfo )
  {
    StringHelper::debug( 0xff, "Tile debug info: dsrbl=%d", tile.getTerrain().getDesirability() ); 
  }

  type = overlay.isNull() ? B_NONE : overlay->getType();

  Impl::InfoboxCreators::iterator findConstructor = _d->constructors.find( type );

  GuiInfoBox* infoBox = findConstructor != _d->constructors.end() 
                                  ? findConstructor->second->create( _d->gui->getRootWidget(), tile )
                                  : 0;
  
  if( infoBox && infoBox->isAutoPosition() )
  {
    Size rSize = _d->gui->getRootWidget()->getSize();
    int y = ( _d->gui->getCursorPos().getY() < rSize.getHeight() / 2 ) 
                ? rSize.getHeight() - infoBox->getHeight() - 5
                : 30;
    Point pos( ( rSize.getWidth() - infoBox->getWidth() ) / 2, y );

    infoBox->setPosition( pos );
  }
}
Exemplo n.º 2
0
void GuiTilemap::handleEvent(SDL_Event &event)
{
   if (event.type == SDL_MOUSEMOTION)
   {
       _d->lastCursorPos = Point( event.motion.x, event.motion.y );  
       updatePreviewTiles();
   }

   if (event.type == SDL_MOUSEBUTTONDOWN)
   {
      int button = event.button.button;
      int x = event.button.x;
      int y = event.button.y;

      Tile* tile = getTileXY(x, y);  // tile under the cursor (or NULL)
      if (tile == NULL)
      {
         // std::cout << "No Tile pressed at ("<<x<<","<<y<<")" << std::endl;
      }
      else
      {
         int i = tile->getI();
         int j = tile->getJ();
         std::cout << "Tile ("<<i<<","<<j<<") pressed at ("<<x<<","<<y<<") with button:" << button << std::endl;

         if (button == 1)
         {
            // left button
            if (_removeTool)
            {
               _city->clearLand(i, j);
            }
            else if (_buildInstance != NULL)
            {
               Construction& overlay = *_buildInstance;
               if (overlay.canBuild(i, j))
               {
                  _city->build(overlay, i, j);
               }
            }
            else
            {
               getMapArea().setCenterIJ(i, j);
            }
         }
         else if (button == 3)
         {
            if (_removeTool)
            { 
				// discard removeTool
               _removeTool = false;
               discardPreview();
            }
            else if (_buildInstance != NULL)
            {
				// discard buildTool
               _buildInstance = NULL;
               discardPreview();
            }
            else if (tile->get_terrain().getOverlay() != NULL)
            {
               // tile has an overlay
               LandOverlay &overlay = *tile->get_terrain().getOverlay();
               GuiInfoBox* infoBox = overlay.makeInfoBox();

               if (infoBox != NULL)
               {
                  infoBox->setPosition((GfxEngine::instance().getScreenWidth()-infoBox->getWidth())/2, 10);
                  _screenGame->setInfoBox(infoBox);
               }
            }
         }
      }

   }
}