X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fmenu%2FSelectHero.cpp;fp=src%2Fmenu%2FSelectHero.cpp;h=723414ff95164d051c6d5a93c3e5eb7ba4b257a1;hb=bba1ac05e8c1854dc61bd737d228d9bc18bbb6ad;hp=0000000000000000000000000000000000000000;hpb=aedf4ae020e3c811341df79ceae63ca56fb7ce83;p=l2e.git diff --git a/src/menu/SelectHero.cpp b/src/menu/SelectHero.cpp new file mode 100644 index 0000000..723414f --- /dev/null +++ b/src/menu/SelectHero.cpp @@ -0,0 +1,133 @@ +/* + * SelectHero.cpp + * + * Created on: Oct 22, 2012 + * Author: holy + */ + +#include "SelectHero.h" + +#include "HeroStatus.h" +#include "PartyMenu.h" +#include "Resources.h" +#include "../app/Application.h" +#include "../app/Input.h" +#include "../common/GameConfig.h" +#include "../common/GameState.h" +#include "../common/Hero.h" +#include "../geometry/Vector.h" +#include "../graphics/Sprite.h" + +using app::Input; +using geometry::Vector; + +namespace menu { + +SelectHero::SelectHero(PartyMenu *parent, Callback cb, int cursor) +: parent(parent) +, callback(cb) +, cursor(cursor) { + +} + + +void SelectHero::OnEnterState(SDL_Surface *) { + cursorBlink = GraphicsTimers().StartInterval(Res().heroCursorBlinkTime); +} + +void SelectHero::OnExitState(SDL_Surface *) { + +} + +void SelectHero::OnResumeState(SDL_Surface *) { + +} + +void SelectHero::OnPauseState(SDL_Surface *) { + +} + + +void SelectHero::OnResize(int width, int height) { + +} + + +void SelectHero::HandleEvents(const Input &input) { + if (input.JustPressed(Input::ACTION_A)) { + callback(parent, cursor); + } + if (input.JustPressed(Input::ACTION_B)) { + Ctrl().PopState(); + } + + if (input.JustPressed(Input::PAD_UP)) { + SelectUp(); + } else if (input.JustPressed(Input::PAD_RIGHT)) { + SelectRight(); + } else if (input.JustPressed(Input::PAD_DOWN)) { + SelectDown(); + } else if (input.JustPressed(Input::PAD_LEFT)) { + SelectLeft(); + } +} + +void SelectHero::SelectUp() { + cursor = (cursor + 2) % parent->Game().state->partySize; + cursorBlink.Restart(); +} + +void SelectHero::SelectRight() { + cursor = (cursor + 1) % parent->Game().state->partySize; + cursorBlink.Restart(); +} + +void SelectHero::SelectDown() { + cursor = (cursor + 2) % parent->Game().state->partySize; + cursorBlink.Restart(); +} + +void SelectHero::SelectLeft() { + cursor = (cursor + 3) % parent->Game().state->partySize; + cursorBlink.Restart(); +} + + +common::GameConfig &SelectHero::Game() { + return parent->Game(); +} + +const common::GameConfig &SelectHero::Game() const { + return parent->Game(); +} + +Resources &SelectHero::Res() { + return parent->Res(); +} + +const Resources &SelectHero::Res() const { + return parent->Res(); +} + + +void SelectHero::UpdateWorld(float deltaT) { + +} + + +void SelectHero::Render(SDL_Surface *screen) { + parent->Render(screen); + if (cursorBlink.Iteration() % 2 == 0) { + RenderCursor(screen); + } +} + +void SelectHero::RenderCursor(SDL_Surface *screen) const { + const HeroStatus &status(parent->GetHeroStatus(cursor)); + Vector position( + 0, Game().state->party[cursor]->BattleSprite()->Height()); + position += status.Position() + parent->StatusOffset(); + Res().heroCursor->Draw(screen, position); +} + +}