4 * Created on: Nov 4, 2012
8 #include "ChangeHero.h"
10 #include "HeroStatus.h"
11 #include "PartyMenu.h"
12 #include "Resources.h"
13 #include "SelectHero.h"
14 #include "../app/Application.h"
15 #include "../app/Input.h"
16 #include "../common/GameConfig.h"
17 #include "../common/GameState.h"
22 using geometry::Vector;
27 ChangeHero::ChangeHero(PartyMenu *parent)
35 void ChangeHero::OnEnterState(SDL_Surface *) {
36 const HeroStatus &status(parent->GetHeroStatus(0));
37 highlight = SDL_CreateRGBSurface(0, status.Width(), status.Height(), 32, 0xFF000000, 0xFF0000, 0xFF00, 0);
38 SDL_FillRect(highlight, 0, SDL_MapRGB(highlight->format, 0xFF, 0xFF, 0xFF));
39 SDL_SetAlpha(highlight, SDL_SRCALPHA|SDL_RLEACCEL, 0x20);
42 void ChangeHero::OnExitState(SDL_Surface *) {
43 SDL_FreeSurface(highlight);
46 void ChangeHero::OnResumeState(SDL_Surface *) {
51 Ctrl().PushState(new SelectHero(this, parent, this, OnHeroSelected));
55 void ChangeHero::OnPauseState(SDL_Surface *) {
60 void ChangeHero::OnResize(int width, int height) {
65 int ChangeHero::Width() const {
66 return parent->Width();
69 int ChangeHero::Height() const {
70 return parent->Height();
74 void ChangeHero::HandleEvents(const Input &input) {
78 void ChangeHero::UpdateWorld(float deltaT) {
82 void ChangeHero::Render(SDL_Surface *screen) {
83 Vector<int> offset((screen->w - Width()) / 2, (screen->h - Height()) / 2);
85 parent->RenderBackground(screen);
86 RenderHighlight(screen, offset);
87 parent->RenderHeros(screen, offset);
88 parent->RenderMenu(screen, offset + Vector<int>(8 * parent->Res().normalFont->CharWidth(), 13 * parent->Res().normalFont->CharHeight() + parent->Res().normalFont->CharHeight() / 8));
89 parent->RenderInfo(screen, offset + Vector<int>(14 * parent->Res().normalFont->CharWidth(), 21 * parent->Res().normalFont->CharHeight() + parent->Res().normalFont->CharHeight() / 8));
92 void ChangeHero::RenderHighlight(SDL_Surface *screen, const Vector<int> &offset) const {
93 if (selection < 0) return;
94 Vector<int> statusOffset(parent->StatusOffset(selection));
95 statusOffset -= Vector<int>(0, parent->Res().normalFont->CharHeight() / 8);
97 rect.x = statusOffset.X();
98 rect.y = statusOffset.Y();
99 SDL_BlitSurface(highlight, 0, screen, &rect);
103 void ChangeHero::OnHeroSelected(void *ref, int index) {
104 ChangeHero *self(reinterpret_cast<ChangeHero *>(ref));
105 self->SelectedHero(index);
108 void ChangeHero::SelectedHero(int index) {
112 if (index != selection) {
113 swap(parent->Game().state->party[selection],
114 parent->Game().state->party[index]);