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