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"
11 #include "../math/Vector.h"
21 ChangeHero::ChangeHero(PartyMenu *parent)
29 void ChangeHero::OnEnterState(SDL_Surface *) {
30 const HeroStatus &status(parent->GetHeroStatus(0));
31 highlight = SDL_CreateRGBSurface(0, status.Width(), status.Height(), 32, 0xFF000000, 0xFF0000, 0xFF00, 0);
32 SDL_FillRect(highlight, 0, SDL_MapRGB(highlight->format, 0xFF, 0xFF, 0xFF));
33 SDL_SetAlpha(highlight, SDL_SRCALPHA|SDL_RLEACCEL, 0x20);
36 void ChangeHero::OnExitState(SDL_Surface *) {
37 SDL_FreeSurface(highlight);
40 void ChangeHero::OnResumeState(SDL_Surface *) {
45 Ctrl().PushState(new SelectHero(this, parent, this, OnHeroSelected));
49 void ChangeHero::OnPauseState(SDL_Surface *) {
54 void ChangeHero::OnResize(int width, int height) {
59 int ChangeHero::Width() const {
60 return parent->Width();
63 int ChangeHero::Height() const {
64 return parent->Height();
68 void ChangeHero::HandleEvents(const Input &input) {
72 void ChangeHero::UpdateWorld(Uint32 deltaT) {
76 void ChangeHero::Render(SDL_Surface *screen) {
77 Vector<int> offset((screen->w - Width()) / 2, (screen->h - Height()) / 2);
79 parent->RenderBackground(screen);
80 RenderHighlight(screen, offset);
81 parent->RenderHeros(screen, offset);
82 parent->RenderMenu(screen, offset + Vector<int>(8 * parent->Res().normalFont->CharWidth(), 13 * parent->Res().normalFont->CharHeight() + parent->Res().normalFont->CharHeight() / 8));
83 parent->RenderInfo(screen, offset + Vector<int>(14 * parent->Res().normalFont->CharWidth(), 21 * parent->Res().normalFont->CharHeight() + parent->Res().normalFont->CharHeight() / 8));
86 void ChangeHero::RenderHighlight(SDL_Surface *screen, const Vector<int> &offset) const {
87 if (selection < 0) return;
88 Vector<int> statusOffset(parent->StatusOffset(selection));
89 statusOffset -= Vector<int>(0, parent->Res().normalFont->CharHeight() / 8);
91 rect.x = statusOffset.X();
92 rect.y = statusOffset.Y();
93 SDL_BlitSurface(highlight, 0, screen, &rect);
97 void ChangeHero::OnHeroSelected(void *ref, int index) {
98 ChangeHero *self(reinterpret_cast<ChangeHero *>(ref));
99 self->SelectedHero(index);
102 void ChangeHero::SelectedHero(int index) {
106 if (index != selection) {
107 swap(parent->Game().state->party[selection],
108 parent->Game().state->party[index]);