#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;
}
void SelectItem::ResumeState(Application &ctrl, SDL_Surface *screen) {
-
+ if (battle->ActiveHeroTargets().HasSelected()) {
+ battle->SetAttackType(AttackChoice::ITEM);
+ battle->ActiveHeroAttackChoice().SetItem(battle->GetItemMenu().Selected());
+ ctrl.PopState();
+ }
}
void SelectItem::PauseState(Application &ctrl, SDL_Surface *screen) {
}
-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->SetAttackType(AttackChoice::ITEM);
- battle->NextHero();
- ctrl->PopState();
+ const Item *item(battle->GetItemMenu().Selected());
+ battle->ActiveHeroTargets().Reset();
+ if (item->GetTargetingMode().TargetsAlly()) {
+ battle->ActiveHeroTargets().SelectHeroes();
+ } else {
+ battle->ActiveHeroTargets().SelectEnemies();
+ }
+ if (item->GetTargetingMode().TargetsAll()) {
+ battle->SetAttackType(AttackChoice::ITEM);
+ // TODO: remove item from inventory
+ battle->ActiveHeroAttackChoice().SetItem(item);
+ battle->NextHero();
+ ctrl->PopState();
+ } else {
+ if (item->GetTargetingMode().TargetsSingle()) {
+ battle->ActiveHeroTargets().SetSingle();
+ } else {
+ battle->ActiveHeroTargets().SetMultiple();
+ }
+ ctrl->PushState(new SelectTarget(battle, parent, &battle->ActiveHeroTargets(), battle->Res().itemTargetCursor));
+ }
}
}
if (input.JustPressed(Input::ACTION_B)) {