]> git.localhorst.tv Git - l2e.git/blob - src/menu/ChangeHero.cpp
removed lazy fwd headers
[l2e.git] / src / menu / ChangeHero.cpp
1 #include "ChangeHero.h"
2
3 #include "HeroStatus.h"
4 #include "PartyMenu.h"
5 #include "Resources.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"
12
13 #include <algorithm>
14
15 using app::Input;
16 using math::Vector;
17 using std::swap;
18
19 namespace menu {
20
21 ChangeHero::ChangeHero(PartyMenu *parent)
22 : parent(parent)
23 , highlight(0)
24 , selection(0) {
25
26 }
27
28
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);
34 }
35
36 void ChangeHero::OnExitState(SDL_Surface *) {
37         SDL_FreeSurface(highlight);
38 }
39
40 void ChangeHero::OnResumeState(SDL_Surface *) {
41         if (selection < 0) {
42                 Ctrl().PopState();
43         } else {
44                 selection = -1;
45                 Ctrl().PushState(new SelectHero(this, parent, this, OnHeroSelected));
46         }
47 }
48
49 void ChangeHero::OnPauseState(SDL_Surface *) {
50
51 }
52
53
54 void ChangeHero::OnResize(int width, int height) {
55
56 }
57
58
59 int ChangeHero::Width() const {
60         return parent->Width();
61 }
62
63 int ChangeHero::Height() const {
64         return parent->Height();
65 }
66
67
68 void ChangeHero::HandleEvents(const Input &input) {
69
70 }
71
72 void ChangeHero::UpdateWorld(Uint32 deltaT) {
73
74 }
75
76 void ChangeHero::Render(SDL_Surface *screen) {
77         Vector<int> offset((screen->w - Width()) / 2, (screen->h - Height()) / 2);
78
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));
84 }
85
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);
90         SDL_Rect rect;
91         rect.x = statusOffset.X();
92         rect.y = statusOffset.Y();
93         SDL_BlitSurface(highlight, 0, screen, &rect);
94 }
95
96
97 void ChangeHero::OnHeroSelected(void *ref, int index) {
98         ChangeHero *self(reinterpret_cast<ChangeHero *>(ref));
99         self->SelectedHero(index);
100 }
101
102 void ChangeHero::SelectedHero(int index) {
103         if (selection < 0) {
104                 selection = index;
105         } else {
106                 if (index != selection) {
107                         swap(parent->Game().state->party[selection],
108                                         parent->Game().state->party[index]);
109                 }
110                 selection = -1;
111         }
112 }
113
114 }