]> git.localhorst.tv Git - l2e.git/blob - src/battle/states/SelectMoveAction.cpp
de8e97b4db066fca0b316cfcc767094470f8bc89
[l2e.git] / src / battle / states / SelectMoveAction.cpp
1 /*
2  * SelectMoveAction.cpp
3  *
4  *  Created on: Aug 7, 2012
5  *      Author: holy
6  */
7
8 #include "SelectMoveAction.h"
9
10 #include "SelectAttackType.h"
11 #include "SwapHeroes.h"
12 #include "../BattleState.h"
13 #include "../MoveMenu.h"
14 #include "../../app/Application.h"
15 #include "../../app/Input.h"
16 #include "../../geometry/operators.h"
17
18 using app::Application;
19 using app::Input;
20 using geometry::Point;
21 using geometry::Vector;
22
23 namespace battle {
24
25 void SelectMoveAction::EnterState(Application &c, SDL_Surface *screen) {
26         ctrl = &c;
27 }
28
29 void SelectMoveAction::ExitState(Application &c, SDL_Surface *screen) {
30         ctrl = 0;
31 }
32
33 void SelectMoveAction::ResumeState(Application &ctrl, SDL_Surface *screen) {
34
35 }
36
37 void SelectMoveAction::PauseState(Application &ctrl, SDL_Surface *screen) {
38
39 }
40
41
42 void SelectMoveAction::Resize(int width, int height) {
43
44 }
45
46
47 void SelectMoveAction::HandleInput(const Input &input) {
48         if (input.IsDown(Input::PAD_UP)) {
49                 battle->GetMoveMenu().Select(MoveMenu::CHANGE);
50         } else if (input.IsDown(Input::PAD_DOWN)) {
51                 battle->GetMoveMenu().Select(MoveMenu::RUN);
52         } else {
53                 battle->GetMoveMenu().Select(MoveMenu::ATTACK);
54         }
55
56         if (input.JustPressed(Input::ACTION_A)) {
57                 switch (battle->GetMoveMenu().Selected()) {
58                         case MoveMenu::ATTACK:
59                                 ctrl->ChangeState(new SelectAttackType(battle));
60                                 battle->NextHero();
61                                 break;
62                         case MoveMenu::CHANGE:
63                                 ctrl->PushState(new SwapHeroes(battle, this));
64                                 break;
65                         case MoveMenu::RUN:
66                                 // TODO: switch to run state
67                                 break;
68                 }
69         }
70 }
71
72 void SelectMoveAction::UpdateWorld(float deltaT) {
73
74 }
75
76 void SelectMoveAction::Render(SDL_Surface *screen) {
77         Vector<int> offset(battle->CalculateScreenOffset(screen));
78         battle->RenderBackground(screen, offset);
79         battle->RenderMonsters(screen, offset);
80         battle->RenderHeroTags(screen, offset);
81         RenderMenu(screen, offset);
82 }
83
84 void SelectMoveAction::RenderMenu(SDL_Surface *screen, const Vector<int> &offset) {
85         Point<int> position(
86                         (battle->BackgroundWidth() - battle->GetMoveMenu().Width()) / 2,
87                         battle->BackgroundHeight() - battle->GetMoveMenu().Height() - battle->GetMoveMenu().Height() / 2);
88         battle->GetMoveMenu().Render(screen, position + offset);
89 }
90
91 }