/* * dispatchClickDragInput */ void InGameState::dispatchClickDragInput(int iX, int iY, int eX,int eY,int screeniX,int screeniY){ if(!game->getGSM()->isGameInProgress()){ int overlayState= game->getGSM()->getOverlayGameState(); map<int,GUIScreenOverlay*>::iterator find=overlayWorkers.find(overlayState); if(find!=overlayWorkers.end())(*find).second->dispatchClickDrag(screeniX,screeniY,eX,eY); return; } Viewport *vp = game->getGUI()->getViewport(); if( screeniY < vp->getViewportHeight()+vp->getViewportOffsetY() ){ int gameEX=eX+vp->getViewportX()-vp->getViewportOffsetX(); int gameEY=eY+vp->getViewportY()-vp->getViewportOffsetY(); if (canCastSpell() && !isCursorBusy()){ Spell* p = toolbar.getCurrentSpell(); if(p!=NULL && p->getType()==clickdrag){ if(p->getManaCost(game,iX,iY,gameEX,gameEY)<=this->mainPlayer->mana){ mainPlayer->mana-=p->getManaCost(game,iX,iY,gameEX,gameEY); p=p->clone(); //iX+=vp->getViewportX()-vp->getViewportOffsetX(); //iY+=vp->getViewportY()-vp->getViewportOffsetY(); p->start(game,iX,iY,gameEX,gameEY); p->owner=mainPlayer; spells.push_back(p); } } if(p!=NULL && p->getType()==click){ mainPlayer->mana-=p->getManaCost(game,iX,iY,gameEX,gameEY); //iX+=vp->getViewportX()-vp->getViewportOffsetX(); //iY+=vp->getViewportY()-vp->getViewportOffsetY(); p=p->clone(); p->start(game,iX,iY); p->owner=mainPlayer; spells.push_back(p); } } } }
/* * handleClickInput - if shift is held, then user is wanting to select units, * and no spell will cast. Otherwise the selected spell, if a single-click * type spell, will cast. */ void InGameState::handleClickInput(int x, int y,int screenX,int screenY){ if(!game->getGSM()->isGameInProgress()){ int overlayState= game->getGSM()->getOverlayGameState(); map<int,GUIScreenOverlay*>::iterator find=overlayWorkers.find(overlayState); if(find!=overlayWorkers.end())(*find).second->handleClick(screenX,screenY); return; } Viewport *vp = game->getGUI()->getViewport(); Cursor *c = game->getGUI()->getCursor(GS_GAME_IN_PROGRESS); toolbar.handleClick(game,screenX,screenY); displayUnits.handleClick(this,game,x,y); //spDBToolbar.handleClick(this, game, screenX, screenY); if(!isCursorBusy()){ vector<Tower*>::iterator beginTower=towers.begin(), endTower=towers.end(); b2Vec2 scaleMouse(x,y); scaleMouse*=BOX2D_Scale_Factor; for(;beginTower!=endTower;) { Tower* t = *beginTower; if(!t->isDead()){ if(t->p==mainPlayer){ b2AABB rct=t->getAABB(); if(rct.lowerBound.x<scaleMouse.x && rct.lowerBound.y<scaleMouse.y && rct.upperBound.x>scaleMouse.x && rct.upperBound.y>scaleMouse.y){ t->mouseClick(game,screenX,screenY); } } beginTower++; }else{ beginTower=towers.erase(beginTower); endTower=towers.end(); } } vector<Building*>::iterator beginOther=buildings.begin(), endOther=buildings.end(); for(;beginOther!=endOther;) { Building* t = *beginOther; if(!t->isDead()){ if(t->p==mainPlayer){ b2AABB rct=t->getAABB(); if(rct.lowerBound.x<scaleMouse.x && rct.lowerBound.y<scaleMouse.y && rct.upperBound.x>scaleMouse.x && rct.upperBound.y>scaleMouse.y){ t->mouseClick(game,screenX,screenY); } } beginOther++; } else{ beginOther=buildings.erase(beginOther); endOther=buildings.end(); } } } if( screenY < vp->getViewportHeight()+vp->getViewportOffsetY() ){ if (canCastSpell() && !isCursorBusy()){ Spell* p = toolbar.getCurrentSpell(); if(p!=NULL && p->getType()==click){ //x+=vp->getViewportX()-vp->getViewportOffsetX(); //y+=vp->getViewportY()-vp->getViewportOffsetY(); if(p->getManaCost(game,x,y,0,0)<=this->mainPlayer->mana){ mainPlayer->mana-=p->getManaCost(game,x,y,0,0); p=p->clone(); p->start(game,x,y); p->owner=mainPlayer; spells.push_back(p); } } //c->setActiveCursorID(2); } else{ if(currentBuilding!=NULL&& mappable){ if(!mainPlayer->getWizard()->buildingsTutorials){ tutSys->currentTutorial="BuildBarracks"; game->getGSM()->setOverlayGameState(TUTSYSSCREENOVERLAYNUM); mainPlayer->getWizard()->buildingsTutorials=true; } this->addBuilding(currentBuilding,bx,by,this->players[0]); currentBuilding=NULL; } } } }