]> git.localhorst.tv Git - l2e.git/blobdiff - src/battle/states/SelectItem.cpp
alternate approach to battle animation
[l2e.git] / src / battle / states / SelectItem.cpp
index 0bdd4b10c3adfba9fe4216e5a8b9e6cc1d582628..0291b739c9c2746b5b17f6f72edf58fabb203f57 100644 (file)
@@ -8,15 +8,18 @@
 #include "SelectItem.h"
 
 #include "SelectAttackType.h"
+#include "SelectTarget.h"
 #include "../BattleState.h"
 #include "../../app/Application.h"
 #include "../../app/Input.h"
+#include "../../common/Item.h"
 #include "../../geometry/Point.h"
 #include "../../geometry/operators.h"
 #include "../../graphics/Frame.h"
 
 using app::Application;
 using app::Input;
+using common::Item;
 using geometry::Point;
 using geometry::Vector;
 using graphics::Frame;
@@ -32,7 +35,11 @@ void SelectItem::ExitState(Application &c, SDL_Surface *screen) {
 }
 
 void SelectItem::ResumeState(Application &ctrl, SDL_Surface *screen) {
-
+       if (battle->ActiveHeroAttackChoice().Selection().HasSelected()) {
+               battle->ActiveHeroAttackChoice().SetType(AttackChoice::ITEM);
+               battle->ActiveHeroAttackChoice().SetItem(battle->GetItemMenu().Selected());
+               ctrl.PopState();
+       }
 }
 
 void SelectItem::PauseState(Application &ctrl, SDL_Surface *screen) {
@@ -45,12 +52,30 @@ void SelectItem::Resize(int width, int height) {
 }
 
 
-void SelectItem::HandleInput(const Input &input) {
+void SelectItem::HandleEvents(const Input &input) {
        if (input.JustPressed(Input::ACTION_A)) {
-               // TODO: switch to target select
                if (battle->GetItemMenu().SelectedIsEnabled()) {
-                       battle->NextHero();
-                       ctrl->PopState();
+                       const Item *item(battle->GetItemMenu().Selected());
+                       battle->ActiveHeroAttackChoice().Selection().Reset();
+                       if (item->GetTargetingMode().TargetsAlly()) {
+                               battle->ActiveHeroAttackChoice().Selection().SelectHeroes();
+                       } else {
+                               battle->ActiveHeroAttackChoice().Selection().SelectEnemies();
+                       }
+                       if (item->GetTargetingMode().TargetsAll()) {
+                               battle->ActiveHeroAttackChoice().SetType(AttackChoice::ITEM);
+                               // TODO: remove item from inventory
+                               battle->ActiveHeroAttackChoice().SetItem(item);
+                               battle->NextHero();
+                               ctrl->PopState();
+                       } else {
+                               if (item->GetTargetingMode().TargetsSingle()) {
+                                       battle->ActiveHeroAttackChoice().Selection().SetSingle();
+                               } else {
+                                       battle->ActiveHeroAttackChoice().Selection().SetMultiple();
+                               }
+                               ctrl->PushState(new SelectTarget(battle, parent, &battle->ActiveHeroAttackChoice().Selection(), battle->Res().itemTargetCursor));
+                       }
                }
        }
        if (input.JustPressed(Input::ACTION_B)) {
@@ -85,7 +110,7 @@ void SelectItem::Render(SDL_Surface *screen) {
 void SelectItem::RenderFrame(SDL_Surface *screen, const Vector<int> &offset) {
        const Frame *frame(battle->Res().selectFrame);
        Point<int> position(frame->BorderWidth(), frame->BorderHeight());
-       int width(battle->BackgroundWidth() - 2 * frame->BorderWidth());
+       int width(battle->Width() - 2 * frame->BorderWidth());
        int height(battle->Res().normalFont->CharHeight() * 13);
        frame->Draw(screen, position + offset, width, height);
 }