Esempio n. 1
0
void frts::Drawer::updateMap(const SharedManagerPtr& shared, Point::value zLevel,
                             const RegionManagerPtr& regionManager, const ModelFactoryPtr& modelFactory,
                             const GraphicDataPtr& graphicData, const ModelDataPtr& modelData)
{
    assert(shared != nullptr);

    PerformanceLog pl(getName() + " UpdateMap", shared);

    auto gd = getDataValue<GraphicData>(shared, Sdl2Ids::graphicData());
    auto mapArea = gd->getMapArea();

    Point::value offsetX = screenToRegionX(0, shared);
    Point::value width = screenToRegionX(mapArea.width, shared) + 1;
    Point::value offsetY = screenToRegionY(0, shared);
    Point::value height = screenToRegionY(mapArea.height, shared) + 1;

    for (Point::value x = offsetX; x < width; ++x)
    {
        for (Point::value y = offsetY; y < height; ++y)
        {
            auto pos = modelFactory->makePoint(x, y, zLevel);
            updatePosition(shared, pos, zLevel, regionManager, modelFactory, graphicData, modelData);
        }
    }
}
Esempio n. 2
0
void ScreenGame::initialize( GfxEngine& engine, GuiEnv& gui )
{
  _d->gui = &gui;
  _d->engine = &engine;
  _d->infoBoxMgr = InfoBoxManager::create( &gui );

  CityPtr city = _d->scenario->getCity();

  _d->gui->clear();

  /*new PopupMessageBox( _d->gui->getRootWidget(), "Test title", "This is test string for popup message box", 
                       "Sen 351 BC", "For New player" ); */

  const int topMenuHeight = 23;
  const Picture& rPanelPic = Picture::load( ResourceGroup::panelBackground, 14 );
  Rect rPanelRect( engine.getScreenWidth() - rPanelPic.getWidth(), topMenuHeight,
                   engine.getScreenWidth(), engine.getScreenHeight() );

  _d->rightPanel = MenuRigthPanel::create( gui.getRootWidget(), rPanelRect, rPanelPic);

  _d->topMenu = TopMenu::create( gui.getRootWidget(), topMenuHeight );
  _d->topMenu->setPopulation( city->getPopulation() );
  _d->topMenu->setFunds( city->getFunds().getValue() );
  _d->topMenu->setDate( GameDate::current() );

  _d->menu = Menu::create( gui.getRootWidget(), -1, _d->scenario->getCity() );
  _d->menu->setPosition( Point( engine.getScreenWidth() - _d->menu->getWidth() - _d->rightPanel->getWidth(), 
                                 _d->topMenu->getHeight() ) );

  _d->extMenu = ExtentMenu::create( gui.getRootWidget(), _d->mapRenderer, -1, _d->scenario->getCity() );
  _d->extMenu->setPosition( Point( engine.getScreenWidth() - _d->extMenu->getWidth() - _d->rightPanel->getWidth(), 
                                     _d->topMenu->getHeight() ) );

  _d->wndStackMsgs = WindowMessageStack::create( gui.getRootWidget(), -1 );
  _d->wndStackMsgs->setPosition( Point( gui.getRootWidget()->getWidth() / 4, 33 ) );
  _d->wndStackMsgs->sendToBack();
    
  _d->rightPanel->bringToFront();

  // 8*30: used for high buildings (granary...), visible even when not in tilemap_area.
  getMapArea().setViewSize( engine.getScreenSize() + Size( 180 ) );
        
  // here move camera to start position of map
  getMapArea().setCenterIJ( _d->scenario->getCity()->getCameraPos() ); 

  new SenatePopupInfo( _d->gui->getRootWidget(), _d->mapRenderer );

  //connect elements
  CONNECT( _d->topMenu, onSave(), _d.data(), Impl::showSaveDialog );
  CONNECT( _d->topMenu, onExit(), this, ScreenGame::resolveExitGame );
  CONNECT( _d->topMenu, onEnd(), this, ScreenGame::resolveEndGame );
  CONNECT( _d->topMenu, onRequestAdvisor(), _d.data(), Impl::showAdvisorsWindow );

  CONNECT( _d->menu, onCreateConstruction(), _d.data(), Impl::resolveCreateConstruction );
  CONNECT( _d->menu, onRemoveTool(), _d.data(), Impl::resolveRemoveTool );
  CONNECT( _d->menu, onMaximize(), _d->extMenu, ExtentMenu::maximize );

  CONNECT( _d->extMenu, onCreateConstruction(), _d.data(), Impl::resolveCreateConstruction );
  CONNECT( _d->extMenu, onRemoveTool(), _d.data(), Impl::resolveRemoveTool );

  CONNECT( city, onPopulationChanged(), _d->topMenu, TopMenu::setPopulation );
  CONNECT( city, onFundsChanged(), _d->topMenu, TopMenu::setFunds );
  CONNECT( &GameDate::instance(), onMonthChanged(), _d->topMenu, TopMenu::setDate );

  CONNECT( &_d->mapRenderer, onShowTileInfo(), _d.data(), Impl::showTileInfo );

  CONNECT( city, onWarningMessage(), _d->wndStackMsgs, WindowMessageStack::addMessage );
  CONNECT( &_d->mapRenderer, onWarningMessage(), _d->wndStackMsgs, WindowMessageStack::addMessage );
  CONNECT( _d->extMenu, onSelectOverlayType(), _d.data(), Impl::resolveSelectOverlayView );
  CONNECT( _d->extMenu, onEmpireMapShow(), _d.data(), Impl::showEmpireMapWindow );
  CONNECT( _d->extMenu, onAdvisorsWindowShow(), _d.data(), Impl::showAdvisorsWindow );
  CONNECT( _d->extMenu, onMissionTargetsWindowShow(), _d.data(), Impl::showMissionTaretsWindow );

  CONNECT( city, onDisasterEvent(), &_d->alarmsHolder, AlarmEventHolder::add );
  CONNECT( _d->extMenu, onSwitchAlarm(), &_d->alarmsHolder, AlarmEventHolder::next );
  CONNECT( &_d->alarmsHolder, onMoveToAlarm(), &_d->mapArea, TilemapArea::setCenterIJ );
  CONNECT( &_d->alarmsHolder, onAlarmChange(), _d->extMenu, ExtentMenu::setAlarmEnabled );
}
Esempio n. 3
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);
               }
            }
         }
      }

   }
}