From: Daniel Karbach Date: Fri, 10 Aug 2012 10:46:41 +0000 (+0200) Subject: added item target selection X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;h=b7a90738b9ae701cfc86bf74a11ba59d7fcb17ba;p=l2e.git added item target selection --- diff --git a/src/battle/AttackChoice.cpp b/src/battle/AttackChoice.cpp index c966b53..5d3359b 100644 --- a/src/battle/AttackChoice.cpp +++ b/src/battle/AttackChoice.cpp @@ -9,4 +9,10 @@ namespace battle { +void AttackChoice::Reset() { + thing = 0; + selection.Reset(); + type = UNDECIDED; +} + } diff --git a/src/battle/AttackChoice.h b/src/battle/AttackChoice.h index 0068e6f..42eb0d3 100644 --- a/src/battle/AttackChoice.h +++ b/src/battle/AttackChoice.h @@ -10,6 +10,8 @@ #include "TargetSelection.h" +namespace common { class Item; } + namespace battle { class AttackChoice { @@ -25,18 +27,23 @@ public: }; public: - explicit AttackChoice(BattleState *b = 0) : type(UNDECIDED), selection(b) { } + explicit AttackChoice(BattleState *b = 0) : thing(0), selection(b), type(UNDECIDED) { } ~AttackChoice() { } public: Type GetType() const { return type; } void SetType(Type t) { type = t; } + const common::Item *GetItem() const { return (const common::Item *)thing; } + void SetItem(const common::Item *i) { thing = i; } TargetSelection &Selection() { return selection; } const TargetSelection &Selection() const { return selection; } + void Reset(); + private: - Type type; + const void *thing; TargetSelection selection; + Type type; }; diff --git a/src/battle/BattleState.h b/src/battle/BattleState.h index 3b29354..1a0586c 100644 --- a/src/battle/BattleState.h +++ b/src/battle/BattleState.h @@ -86,6 +86,8 @@ public: const geometry::Point &HeroTagPositionAt(std::vector::size_type index) const { return heroTagPositions[index]; } bool HasChosenAttackType() const { return attackChoices[activeHero].GetType() != AttackChoice::UNDECIDED; } void SetAttackType(AttackChoice::Type t) { attackChoices[activeHero].SetType(t); } + AttackChoice &ActiveHeroAttackChoice() { return attackChoices[activeHero]; } + const AttackChoice &ActiveHeroAttackChoice() const { return attackChoices[activeHero]; } TargetSelection &ActiveHeroTargets() { return attackChoices[activeHero].Selection(); } const TargetSelection &ActiveHeroTargets() const { return attackChoices[activeHero].Selection(); } bool AttackSelectionDone() const { return activeHero >= (int) heroes.size(); } diff --git a/src/battle/states/SelectAttackType.cpp b/src/battle/states/SelectAttackType.cpp index 1039e51..90d483c 100644 --- a/src/battle/states/SelectAttackType.cpp +++ b/src/battle/states/SelectAttackType.cpp @@ -75,7 +75,7 @@ void SelectAttackType::HandleInput(const Input &input) { // TODO: detect single/multiple/all attack mode battle->ActiveHeroTargets().SetSingle(); battle->ActiveHeroTargets().Reset(); - ctrl->PushState(new SelectTarget(battle, this, &battle->ActiveHeroTargets(), battle->Res().weaponTargetCursor, true)); + ctrl->PushState(new SelectTarget(battle, this, &battle->ActiveHeroTargets(), battle->Res().weaponTargetCursor)); break; case AttackChoice::MAGIC: if (battle->ActiveHero().CanUseMagic()) { @@ -96,11 +96,12 @@ void SelectAttackType::HandleInput(const Input &input) { throw std::logic_error("selected invalid attack type"); } } else if (input.JustPressed(Input::ACTION_B)) { + battle->ActiveHeroAttackChoice().Reset(); battle->PreviousHero(); if (battle->BeforeFirstHero()) { ctrl->ChangeState(new SelectMoveAction(battle)); } else { - battle->SetAttackType(AttackChoice::UNDECIDED); + battle->ActiveHeroAttackChoice().Reset(); } } diff --git a/src/battle/states/SelectItem.cpp b/src/battle/states/SelectItem.cpp index 4f6c7af..a2d178e 100644 --- a/src/battle/states/SelectItem.cpp +++ b/src/battle/states/SelectItem.cpp @@ -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,9 @@ void SelectItem::ExitState(Application &c, SDL_Surface *screen) { } void SelectItem::ResumeState(Application &ctrl, SDL_Surface *screen) { - + if (battle->ActiveHeroTargets().HasSelected()) { + ctrl.PopState(); + } } void SelectItem::PauseState(Application &ctrl, SDL_Surface *screen) { @@ -47,11 +52,31 @@ void SelectItem::Resize(int width, int height) { void SelectItem::HandleInput(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->TargetAlly()) { + battle->ActiveHeroTargets().SelectHeroes(); + } else { + battle->ActiveHeroTargets().SelectEnemies(); + } + if (item->TargetAll()) { + battle->SetAttackType(AttackChoice::ITEM); + // TODO: remove item from inventory + battle->ActiveHeroAttackChoice().SetItem(item); + battle->NextHero(); + ctrl->PopState(); + } else { + if (item->TargetOne()) { + battle->ActiveHeroTargets().SetSingle(); + } else { + battle->ActiveHeroTargets().SetMultiple(); + } + ctrl->PushState(new SelectTarget(battle, parent, &battle->ActiveHeroTargets(), battle->Res().itemTargetCursor)); + } +// battle->SetAttackType(AttackChoice::ITEM); +// battle->NextHero(); +// ctrl->PopState(); } } if (input.JustPressed(Input::ACTION_B)) { diff --git a/src/battle/states/SelectTarget.h b/src/battle/states/SelectTarget.h index b9085a5..f84dd31 100644 --- a/src/battle/states/SelectTarget.h +++ b/src/battle/states/SelectTarget.h @@ -24,7 +24,7 @@ class SelectTarget : public app::State { public: - SelectTarget(BattleState *battle, SelectAttackType *parent, TargetSelection *selection, const graphics::Sprite *cursorIcon, bool startWithEnemy) + SelectTarget(BattleState *battle, SelectAttackType *parent, TargetSelection *selection, const graphics::Sprite *cursorIcon) : ctrl(0), battle(battle), parent(parent), selection(selection), cursorIcon(cursorIcon), flipFlop(true) { } public: diff --git a/src/common/Item.h b/src/common/Item.h index 2f66207..1dde887 100644 --- a/src/common/Item.h +++ b/src/common/Item.h @@ -79,8 +79,9 @@ public: void SetName(const char *n) { name = n; } void SetMenuIcon(const graphics::Sprite *icon) { menuIcon = icon; } void SetUsableInBattle() { usability |= USABILITY_BATTLE; } + void SetTargettingMode(int m) { targettingMode = m; } -private: +public: enum Usability { USABILITY_MOST_USEFUL = 1, USABILITY_EQUIPABLE = 2, diff --git a/src/main.cpp b/src/main.cpp index 5e14001..503c426 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -197,11 +197,12 @@ int main(int argc, char **argv) { SDL_Surface *targetingIconsImg(IMG_Load("test-data/targeting-icons.png")); Sprite weaponTargetCursor(targetingIconsImg, 32, 32); + Sprite itemTargetCursor(targetingIconsImg, 32, 32, 0, 64); battleRes.weaponTargetCursor = &weaponTargetCursor; // TODO: add image for magic targeting cursor battleRes.magicTargetCursor = &weaponTargetCursor; // TODO: add image for item targeting cursor - battleRes.itemTargetCursor = &weaponTargetCursor; + battleRes.itemTargetCursor = &itemTargetCursor; battleRes.spellMenuHeadline = "Please choose a spell."; battleRes.spellMenuPrototype = Menu(&normalFont, &disabledFont, &handCursorSprite, 12, 6, 8, 0, 2, 32); @@ -244,16 +245,19 @@ int main(int argc, char **argv) { antidote.SetName("Antidote"); antidote.SetMenuIcon(&potionIcon); antidote.SetUsableInBattle(); + antidote.SetTargettingMode(Item::TARGETTING_MODE_ALLY | Item::TARGETTING_MODE_ONE); inventory.Add(&antidote, 9); Item magicJar; magicJar.SetName("Magic jar"); magicJar.SetMenuIcon(&potionIcon); magicJar.SetUsableInBattle(); + magicJar.SetTargettingMode(Item::TARGETTING_MODE_ALLY | Item::TARGETTING_MODE_ONE); inventory.Add(&magicJar, 4); Item hiPotion; hiPotion.SetName("Hi-Potion"); hiPotion.SetMenuIcon(&potionIcon); hiPotion.SetUsableInBattle(); + hiPotion.SetTargettingMode(Item::TARGETTING_MODE_ALLY | Item::TARGETTING_MODE_ONE); inventory.Add(&hiPotion, 4); Item powerPotion; powerPotion.SetName("Power potion"); @@ -266,10 +270,18 @@ int main(int argc, char **argv) { sleepBall.SetName("Sleep ball"); sleepBall.SetMenuIcon(&ballIcon); sleepBall.SetUsableInBattle(); + sleepBall.SetTargettingMode(Item::TARGETTING_MODE_ENEMY | Item::TARGETTING_MODE_ONE); inventory.Add(&sleepBall, 1); + Item multiBall; + multiBall.SetName("Multi-ball!"); + multiBall.SetMenuIcon(&ballIcon); + multiBall.SetUsableInBattle(); + multiBall.SetTargettingMode(Item::TARGETTING_MODE_ENEMY | Item::TARGETTING_MODE_MULTIPLE); + inventory.Add(&multiBall, 1); Item figgoru; figgoru.SetName("Figgoru"); figgoru.SetMenuIcon(&crankIcon); + figgoru.SetTargettingMode(Item::TARGETTING_MODE_ENEMY | Item::TARGETTING_MODE_ALL); inventory.Add(&figgoru, 1); battleRes.inventory = &inventory; diff --git a/test-data/targeting-icons.png b/test-data/targeting-icons.png index 64b32bf..c0e56fa 100644 Binary files a/test-data/targeting-icons.png and b/test-data/targeting-icons.png differ