/** * Takes care of any events from the core game engine, * and passes them on to its InteractiveSurface child elements. * @param action Pointer to an action. */ void State::handle(Action *action) { for (std::vector<Surface*>::reverse_iterator i = _surfaces.rbegin(); i != _surfaces.rend(); ++i) { InteractiveSurface* j = dynamic_cast<InteractiveSurface*>(*i); if (j != 0) j->handle(action, this); } }
/** * Takes care of any events from the core game engine, * and passes them on to its InteractiveSurface child elements. * @param action Pointer to an action. */ void State::handle(Action *action) { for (std::vector<Surface*>::iterator i = _surfaces.begin(); i < _surfaces.end(); i++) { InteractiveSurface* j = dynamic_cast<InteractiveSurface*>(*i); if (j != 0) j->handle(action, this); } }
/** * Resets the status of all the Surface child elements, * like unpressing buttons. */ void State::resetAll() { for (std::vector<Surface*>::iterator i = _surfaces.begin(); i != _surfaces.end(); ++i) { InteractiveSurface *s = dynamic_cast<InteractiveSurface*>(*i); if (s != 0) { s->unpress(this); } } }
/** * Initializes all the elements in the MiniMapState screen. * @param game Pointer to the core game. * @param map The Battlescape map. * @param battleGame The Battlescape save. */ MiniMapState::MiniMapState (Game * game, Camera * camera, SavedBattleGame * battleGame) : State(game) { _surface = new InteractiveSurface(320, 200); _miniMapView = new MiniMapView(222, 150, 49, 15, game, camera, battleGame); InteractiveSurface * btnLvlUp = new InteractiveSurface(18, 20, 24, 62); InteractiveSurface * btnLvlDwn = new InteractiveSurface(18, 20, 24, 88); InteractiveSurface * btnOk = new InteractiveSurface(32, 32, 275, 145); _txtLevel = new Text (20, 25, 281, 75); add(_surface); add(_miniMapView); add(btnLvlUp); add(btnLvlDwn); add(btnOk); add(_txtLevel); _game->getResourcePack()->getSurface("SCANBORD.PCK")->blit(_surface); btnLvlUp->onMouseClick((ActionHandler)&MiniMapState::btnLevelUpClick); btnLvlDwn->onMouseClick((ActionHandler)&MiniMapState::btnLevelDownClick); btnOk->onMouseClick((ActionHandler)&MiniMapState::btnOkClick); _txtLevel->setBig(); _txtLevel->setColor(Palette::blockOffset(4)); _txtLevel->setHighContrast(true); std::wstringstream s; s << camera->getViewHeight(); _txtLevel->setText(s.str()); _timerAnimate = new Timer(125); _timerAnimate->onTimer((StateHandler)&MiniMapState::animate); _timerAnimate->start(); _miniMapView->draw(); }
SlideshowState::SlideshowState(const SlideshowHeader &slideshowHeader, const std::vector<SlideshowSlide> *slideshowSlides) : _slideshowHeader(slideshowHeader), _slideshowSlides(slideshowSlides), _curScreen(-1) { _wasLetterboxed = CutsceneState::initDisplay(); // pre-render and queue up all the frames for (std::vector<SlideshowSlide>::const_iterator it = _slideshowSlides->begin(); it != _slideshowSlides->end(); ++it) { InteractiveSurface *slide = new InteractiveSurface(Screen::ORIGINAL_WIDTH, Screen::ORIGINAL_HEIGHT, 0, 0); slide->loadImage(FileMap::getFilePath(it->imagePath)); slide->onMouseClick((ActionHandler)&SlideshowState::screenClick); slide->setVisible(false); _slides.push_back(slide); setPalette(slide->getPalette()); add(slide); // initialize with default rect; may get overridden by // category/id definition Text *caption = new Text(it->w, it->h, it->x, it->y); caption->setColor(it->color); caption->setText(tr(it->caption)); caption->setWordWrap(true); caption->setVisible(false); _captions.push_back(caption); add(caption); } centerAllSurfaces(); _transitionTimer = new Timer(slideshowHeader.transitionSeconds * 1000); _transitionTimer->onTimer((StateHandler)&SlideshowState::screenTimer); _game->getResourcePack()->playMusic(slideshowHeader.musicId); screenClick(0); }
/** * Initializes all the elements in the MiniMapState screen. * @param game Pointer to the core game. * @param camera The Battlescape camera. * @param battleGame The Battlescape save. */ MiniMapState::MiniMapState (Game * game, Camera * camera, SavedBattleGame * battleGame) : State(game) { _surface = new InteractiveSurface(320, 200); _miniMapView = new MiniMapView(222, 150, 49, 15, game, camera, battleGame); InteractiveSurface * btnLvlUp = new InteractiveSurface(18, 20, 24, 62); InteractiveSurface * btnLvlDwn = new InteractiveSurface(18, 20, 24, 88); InteractiveSurface * btnOk = new InteractiveSurface(32, 32, 275, 145); _txtLevel = new Text (20, 25, 281, 75); add(_surface); add(_miniMapView); add(btnLvlUp); add(btnLvlDwn); add(btnOk); add(_txtLevel); centerAllSurfaces(); if (_game->getScreen()->getDY() > 50) { _screen = false; SDL_Rect current; current.w = 223; current.h = 151; current.x = 46; current.y = 14; _surface->drawRect(¤t, Palette::blockOffset(15)+15); } _game->getResourcePack()->getSurface("SCANBORD.PCK")->blit(_surface); btnLvlUp->onMouseClick((ActionHandler)&MiniMapState::btnLevelUpClick); btnLvlDwn->onMouseClick((ActionHandler)&MiniMapState::btnLevelDownClick); btnOk->onMouseClick((ActionHandler)&MiniMapState::btnOkClick); btnOk->onKeyboardPress((ActionHandler)&MiniMapState::btnOkClick, Options::keyCancel); btnOk->onKeyboardPress((ActionHandler)&MiniMapState::btnOkClick, Options::keyBattleMap); _txtLevel->setBig(); _txtLevel->setColor(Palette::blockOffset(4)); _txtLevel->setHighContrast(true); std::wostringstream s; s << camera->getViewLevel(); _txtLevel->setText(s.str()); _timerAnimate = new Timer(125); _timerAnimate->onTimer((StateHandler)&MiniMapState::animate); _timerAnimate->start(); _miniMapView->draw(); }
/** * The state machine takes care of passing all the events from SDL to the * active state, running any code within and blitting all the states and * cursor to the screen. This is run indefinitely until the game quits. */ void Game::run() { while (!_quit) { // Clean up states while (!_deleted.empty()) { delete _deleted.back(); _deleted.pop_back(); } // Initialize active state if (!_init) { _states.back()->init(); _init = true; // Unpress buttons for (std::vector<Surface*>::iterator i = _states.back()->getSurfaces()->begin(); i < _states.back()->getSurfaces()->end(); i++) { InteractiveSurface *s = dynamic_cast<InteractiveSurface*>(*i); if (s != 0) { s->unpress(_states.back()); } } // Refresh mouse position SDL_Event ev; int x, y; SDL_GetMouseState(&x, &y); ev.type = SDL_MOUSEMOTION; ev.motion.x = x; ev.motion.y = y; Action action = Action(&ev, _screen->getXScale(), _screen->getYScale()); _states.back()->handle(&action); } // Process events while (SDL_PollEvent(&_event)) { if (_event.type == SDL_QUIT) { _quit = true; } else { Action action = Action(&_event, _screen->getXScale(), _screen->getYScale()); _screen->handle(&action); _cursor->handle(&action); _fpsCounter->handle(&action); _states.back()->handle(&action); } } // Process logic _fpsCounter->think(); _states.back()->think(); // Process rendering if (_init) { _screen->clear(); std::list<State*>::iterator i = _states.end(); do { i--; } while(i != _states.begin() && !(*i)->isScreen()); for (; i != _states.end(); i++) { (*i)->blit(); } _fpsCounter->blit(_screen->getSurface()); _cursor->blit(_screen->getSurface()); } _screen->flip(); SDL_Delay(0); } }
/** * Initialize the Medikit State * @param game Pointer to the core game. * @param targetUnit The wounded unit. * @param action The healing action. */ MedikitState::MedikitState (Game * game, BattleUnit * targetUnit, BattleAction *action) : State (game), _targetUnit(targetUnit), _action(action) { _unit = action->actor; _item = action->weapon; _surface = new InteractiveSurface(320, 200); if (Screen::getDY() > 50) { _screen = false; SDL_Rect current; current.w = 190; current.h = 100; current.x = 67; current.y = 44; _surface->drawRect(¤t, Palette::blockOffset(15)+15); } _partTxt = new Text(50, 15, 90, 120); _woundTxt = new Text(10, 15, 145, 120); _medikitView = new MedikitView(52, 58, 95, 60, _game, _targetUnit, _partTxt, _woundTxt); InteractiveSurface *endButton = new InteractiveSurface(20, 20, 220, 140); InteractiveSurface *stimulantButton = new MedikitButton(84); InteractiveSurface *pkButton = new MedikitButton(48); InteractiveSurface *healButton = new MedikitButton(120); _pkText = new MedikitTxt (50); _stimulantTxt = new MedikitTxt (85); _healTxt = new MedikitTxt (120); add(_surface); add(_medikitView); add(endButton); add(new MedikitTitle (37, _game->getLanguage()->getString("STR_PAIN_KILLER"))); add(new MedikitTitle (73, _game->getLanguage()->getString("STR_STIMULANT"))); add(new MedikitTitle (109, _game->getLanguage()->getString("STR_HEAL"))); add(healButton); add(stimulantButton); add(pkButton); add(_pkText); add(_stimulantTxt); add(_healTxt); add(_partTxt); add(_woundTxt); centerAllSurfaces(); _game->getResourcePack()->getSurface("MEDIBORD.PCK")->blit(_surface); _pkText->setBig(); _stimulantTxt->setBig(); _healTxt->setBig(); _partTxt->setColor(Palette::blockOffset(2)); _partTxt->setHighContrast(true); _woundTxt->setColor(Palette::blockOffset(2)); _woundTxt->setHighContrast(true); endButton->onMouseClick((ActionHandler)&MedikitState::onEndClick); endButton->onKeyboardPress((ActionHandler)&MedikitState::onEndClick, (SDLKey)Options::getInt("keyCancel")); healButton->onMouseClick((ActionHandler)&MedikitState::onHealClick); stimulantButton->onMouseClick((ActionHandler)&MedikitState::onStimulantClick); pkButton->onMouseClick((ActionHandler)&MedikitState::onPainKillerClick); update(); }