1 #include "ChangeHero.h"
3 #include "HeroStatus.h"
6 #include "SelectHero.h"
7 #include "../app/Application.h"
8 #include "../app/Input.h"
9 #include "../common/GameConfig.h"
10 #include "../common/GameState.h"
15 using geometry::Vector;
20 ChangeHero::ChangeHero(PartyMenu *parent)
28 void ChangeHero::OnEnterState(SDL_Surface *) {
29 const HeroStatus &status(parent->GetHeroStatus(0));
30 highlight = SDL_CreateRGBSurface(0, status.Width(), status.Height(), 32, 0xFF000000, 0xFF0000, 0xFF00, 0);
31 SDL_FillRect(highlight, 0, SDL_MapRGB(highlight->format, 0xFF, 0xFF, 0xFF));
32 SDL_SetAlpha(highlight, SDL_SRCALPHA|SDL_RLEACCEL, 0x20);
35 void ChangeHero::OnExitState(SDL_Surface *) {
36 SDL_FreeSurface(highlight);
39 void ChangeHero::OnResumeState(SDL_Surface *) {
44 Ctrl().PushState(new SelectHero(this, parent, this, OnHeroSelected));
48 void ChangeHero::OnPauseState(SDL_Surface *) {
53 void ChangeHero::OnResize(int width, int height) {
58 int ChangeHero::Width() const {
59 return parent->Width();
62 int ChangeHero::Height() const {
63 return parent->Height();
67 void ChangeHero::HandleEvents(const Input &input) {
71 void ChangeHero::UpdateWorld(float deltaT) {
75 void ChangeHero::Render(SDL_Surface *screen) {
76 Vector<int> offset((screen->w - Width()) / 2, (screen->h - Height()) / 2);
78 parent->RenderBackground(screen);
79 RenderHighlight(screen, offset);
80 parent->RenderHeros(screen, offset);
81 parent->RenderMenu(screen, offset + Vector<int>(8 * parent->Res().normalFont->CharWidth(), 13 * parent->Res().normalFont->CharHeight() + parent->Res().normalFont->CharHeight() / 8));
82 parent->RenderInfo(screen, offset + Vector<int>(14 * parent->Res().normalFont->CharWidth(), 21 * parent->Res().normalFont->CharHeight() + parent->Res().normalFont->CharHeight() / 8));
85 void ChangeHero::RenderHighlight(SDL_Surface *screen, const Vector<int> &offset) const {
86 if (selection < 0) return;
87 Vector<int> statusOffset(parent->StatusOffset(selection));
88 statusOffset -= Vector<int>(0, parent->Res().normalFont->CharHeight() / 8);
90 rect.x = statusOffset.X();
91 rect.y = statusOffset.Y();
92 SDL_BlitSurface(highlight, 0, screen, &rect);
96 void ChangeHero::OnHeroSelected(void *ref, int index) {
97 ChangeHero *self(reinterpret_cast<ChangeHero *>(ref));
98 self->SelectedHero(index);
101 void ChangeHero::SelectedHero(int index) {
105 if (index != selection) {
106 swap(parent->Game().state->party[selection],
107 parent->Game().state->party[index]);