]> git.localhorst.tv Git - l2e.git/commitdiff
added item select state
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Wed, 8 Aug 2012 23:48:04 +0000 (01:48 +0200)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Wed, 8 Aug 2012 23:48:04 +0000 (01:48 +0200)
Debug/src/battle/states/subdir.mk
Release/src/battle/states/subdir.mk
src/battle/BattleState.cpp
src/battle/BattleState.h
src/battle/Resources.h
src/battle/states/SelectAttackType.cpp
src/battle/states/SelectItem.cpp [new file with mode: 0644]
src/battle/states/SelectItem.h [new file with mode: 0644]
src/main.cpp

index bb15270d3754b521b1b38c76c98be4dae88048fc..6697dcbd3d1306b31262dc5611a612f9f77839a0 100644 (file)
@@ -5,16 +5,19 @@
 # Add inputs and outputs from these tool invocations to the build variables 
 CPP_SRCS += \
 ../src/battle/states/SelectAttackType.cpp \
+../src/battle/states/SelectItem.cpp \
 ../src/battle/states/SelectMoveAction.cpp \
 ../src/battle/states/SelectSpell.cpp 
 
 OBJS += \
 ./src/battle/states/SelectAttackType.o \
+./src/battle/states/SelectItem.o \
 ./src/battle/states/SelectMoveAction.o \
 ./src/battle/states/SelectSpell.o 
 
 CPP_DEPS += \
 ./src/battle/states/SelectAttackType.d \
+./src/battle/states/SelectItem.d \
 ./src/battle/states/SelectMoveAction.d \
 ./src/battle/states/SelectSpell.d 
 
index a1256fc712b1b45b51f19ad4b45ff4de8c86fc57..5fdaab06eede93738c6e1c5d8589c2f41b16d77a 100644 (file)
@@ -5,16 +5,19 @@
 # Add inputs and outputs from these tool invocations to the build variables 
 CPP_SRCS += \
 ../src/battle/states/SelectAttackType.cpp \
+../src/battle/states/SelectItem.cpp \
 ../src/battle/states/SelectMoveAction.cpp \
 ../src/battle/states/SelectSpell.cpp 
 
 OBJS += \
 ./src/battle/states/SelectAttackType.o \
+./src/battle/states/SelectItem.o \
 ./src/battle/states/SelectMoveAction.o \
 ./src/battle/states/SelectSpell.o 
 
 CPP_DEPS += \
 ./src/battle/states/SelectAttackType.d \
+./src/battle/states/SelectItem.d \
 ./src/battle/states/SelectMoveAction.d \
 ./src/battle/states/SelectSpell.d 
 
index d7b5a075a311da997070b4d5e9a519211affeb08..6db79f882f9253e0466ec03bce13f361183b5679 100644 (file)
@@ -74,6 +74,18 @@ void BattleState::EnterState(Application &ctrl, SDL_Surface *screen) {
                spellMenus.back().Add("Spark    : 3", 0);
                heroTags.push_back(HeroTag(&heroes[i], &attackChoices[i], res, HeroTag::Alignment((i + 1) % 2)));
        }
+       itemMenu = res->itemMenuPrototype;
+       itemMenu.Add("Antidote    : 9", 0);
+       itemMenu.Add("Magic jar   : 4", 0);
+       itemMenu.Add("Miracle     : 4", 0);
+       itemMenu.Add("Hi-Potion   : 6", 0);
+       itemMenu.Add("Hi-Magic    : 7", 0);
+       itemMenu.Add("Regain      : 4", 0);
+       itemMenu.Add("Power potion: 4", 0, false);
+       itemMenu.Add("Life potion : 1", 0, false);
+       itemMenu.Add("Escape      : 2", 0, false);
+       itemMenu.Add("Power gourd : 3", 0);
+       itemMenu.Add("Mystery pin : 2", 0);
 }
 
 void BattleState::ExitState(Application &ctrl, SDL_Surface *screen) {
index f6890f3d40d35c261b0188cdc51679586671f42c..65e8727906859fd442c174107ce92782d603fb1d 100644 (file)
@@ -80,6 +80,8 @@ public:
        bool AttackSelectionDone() const { return activeHero >= (int) heroes.size(); }
        graphics::Menu</* Spell */ void *> &GetSpellMenu() { return spellMenus[activeHero]; }
        const graphics::Menu</* Spell */ void *> &GetSpellMenu() const { return spellMenus[activeHero]; }
+       graphics::Menu</* Item */ void *> &GetItemMenu() { return itemMenu; }
+               const graphics::Menu</* Item */ void *> &GetItemMenu() const { return itemMenu; }
 
 public:
        geometry::Vector<int> CalculateScreenOffset(SDL_Surface *screen) const {
@@ -107,6 +109,7 @@ private:
        std::vector<Monster> monsters;
        std::vector<Hero> heroes;
        std::vector<graphics::Menu</* Spell */ void *> > spellMenus;
+       graphics::Menu</* Item */ void *> itemMenu;
        std::vector<HeroTag> heroTags;
        std::vector<AttackChoice> attackChoices;
        int activeHero;
index 3876072ecad2b7dd8aca5940579f72a458fb4824..0c646670bcd545841bc6867c5337bb56a939df46 100644 (file)
@@ -44,6 +44,9 @@ struct Resources {
        const char *spellMenuHeadline;
        graphics::Menu</* Spell */ void *> spellMenuPrototype;
 
+       const char *itemMenuHeadline;
+       graphics::Menu</* Spell */ void *> itemMenuPrototype;
+
 
        Resources()
        : moveIcons(0)
@@ -65,8 +68,8 @@ struct Resources {
        , disabledFont(0)
 
        , menuCursor(0)
-
        , spellMenuHeadline("")
+       , itemMenuHeadline("")
        { }
 
 };
index 7dd06f6217b8e610f49828b891994b020ef20c1d..c5e0bba3b580ebcd20886fed04996f54f590b130 100644 (file)
@@ -7,6 +7,7 @@
 
 #include "SelectAttackType.h"
 
+#include "SelectItem.h"
 #include "SelectMoveAction.h"
 #include "SelectSpell.h"
 #include "../AttackChoice.h"
@@ -82,8 +83,7 @@ void SelectAttackType::HandleInput(const Input &input) {
                                battle->NextHero();
                                break;
                        case AttackChoice::ITEM:
-                               // TODO: switch to item select
-                               battle->NextHero();
+                               ctrl->PushState(new SelectItem(battle, this));
                                break;
                        default:
                                throw std::logic_error("selected invalid attack type");
diff --git a/src/battle/states/SelectItem.cpp b/src/battle/states/SelectItem.cpp
new file mode 100644 (file)
index 0000000..0bdd4b1
--- /dev/null
@@ -0,0 +1,109 @@
+/*
+ * SelectItem.cpp
+ *
+ *  Created on: Aug 9, 2012
+ *      Author: holy
+ */
+
+#include "SelectItem.h"
+
+#include "SelectAttackType.h"
+#include "../BattleState.h"
+#include "../../app/Application.h"
+#include "../../app/Input.h"
+#include "../../geometry/Point.h"
+#include "../../geometry/operators.h"
+#include "../../graphics/Frame.h"
+
+using app::Application;
+using app::Input;
+using geometry::Point;
+using geometry::Vector;
+using graphics::Frame;
+
+namespace battle {
+
+void SelectItem::EnterState(Application &c, SDL_Surface *screen) {
+       ctrl = &c;
+}
+
+void SelectItem::ExitState(Application &c, SDL_Surface *screen) {
+       ctrl = 0;
+}
+
+void SelectItem::ResumeState(Application &ctrl, SDL_Surface *screen) {
+
+}
+
+void SelectItem::PauseState(Application &ctrl, SDL_Surface *screen) {
+
+}
+
+
+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->NextHero();
+                       ctrl->PopState();
+               }
+       }
+       if (input.JustPressed(Input::ACTION_B)) {
+               ctrl->PopState(); // return control to parent
+       }
+       if (input.JustPressed(Input::PAD_UP)) {
+               battle->GetItemMenu().PreviousRow();
+       }
+       if (input.JustPressed(Input::PAD_RIGHT)) {
+               battle->GetItemMenu().NextItem();
+       }
+       if (input.JustPressed(Input::PAD_DOWN)) {
+               battle->GetItemMenu().NextRow();
+       }
+       if (input.JustPressed(Input::PAD_LEFT)) {
+               battle->GetItemMenu().PreviousItem();
+       }
+}
+
+void SelectItem::UpdateWorld(float deltaT) {
+
+}
+
+void SelectItem::Render(SDL_Surface *screen) {
+       parent->Render(screen);
+       Vector<int> offset(battle->CalculateScreenOffset(screen));
+       RenderFrame(screen, offset);
+       RenderHeadline(screen, offset);
+       RenderMenu(screen, offset);
+}
+
+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 height(battle->Res().normalFont->CharHeight() * 13);
+       frame->Draw(screen, position + offset, width, height);
+}
+
+void SelectItem::RenderHeadline(SDL_Surface *screen, const Vector<int> &offset) {
+       const Resources &res(battle->Res());
+       Point<int> position(
+                       2 * res.selectFrame->BorderWidth() + res.normalFont->CharWidth(),
+                       2 * res.selectFrame->BorderHeight());
+       res.normalFont->DrawString(res.itemMenuHeadline, screen, position + offset);
+}
+
+void SelectItem::RenderMenu(SDL_Surface *screen, const Vector<int> &offset) {
+       const Resources &res(battle->Res());
+       Point<int> position(
+                       2 * res.selectFrame->BorderWidth() + res.normalFont->CharWidth(),
+                       2 * res.selectFrame->BorderHeight() + 2 * res.normalFont->CharHeight());
+       battle->GetItemMenu().Draw(screen, position + offset);
+}
+
+}
diff --git a/src/battle/states/SelectItem.h b/src/battle/states/SelectItem.h
new file mode 100644 (file)
index 0000000..be089f8
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * SelectItem.h
+ *
+ *  Created on: Aug 9, 2012
+ *      Author: holy
+ */
+
+#ifndef BATTLE_SELECTITEM_H_
+#define BATTLE_SELECTITEM_H_
+
+#include "../../app/State.h"
+
+#include "../../geometry/Vector.h"
+
+namespace battle {
+
+class BattleState;
+class SelectAttackType;
+
+class SelectItem
+: public app::State {
+
+public:
+       SelectItem(BattleState *battle, SelectAttackType *parent)
+       : ctrl(0), battle(battle), parent(parent) { }
+
+public:
+       virtual void EnterState(app::Application &ctrl, SDL_Surface *screen);
+       virtual void ExitState(app::Application &ctrl, SDL_Surface *screen);
+       virtual void ResumeState(app::Application &ctrl, SDL_Surface *screen);
+       virtual void PauseState(app::Application &ctrl, SDL_Surface *screen);
+
+       virtual void Resize(int width, int height);
+
+       virtual void HandleInput(const app::Input &);
+       virtual void UpdateWorld(float deltaT);
+       virtual void Render(SDL_Surface *);
+
+private:
+       void RenderFrame(SDL_Surface *, const geometry::Vector<int> &offset);
+       void RenderHeadline(SDL_Surface *, const geometry::Vector<int> &offset);
+       void RenderMenu(SDL_Surface *, const geometry::Vector<int> &offset);
+
+private:
+       app::Application *ctrl;
+       BattleState *battle;
+       SelectAttackType *parent;
+
+};
+
+}
+
+#endif /* BATTLE_SELECTITEM_H_ */
index 9a68807f5aeac2de0bc75d304a22a7c3b706ccce..4335ecaee98b1315a50928a8eca565c2ea7ae9e8 100644 (file)
@@ -189,6 +189,9 @@ int main(int argc, char **argv) {
                battleRes.spellMenuHeadline = "Please choose a spell.";
                battleRes.spellMenuPrototype = Menu</* Spell */ void *>(&normalFont, &disabledFont, &handCursorSprite, 12, 6, 8, 2, 32);
 
+               battleRes.itemMenuHeadline = "Please choose an item.";
+               battleRes.itemMenuPrototype = Menu</* Item */ void *>(&normalFont, &disabledFont, &handCursorSprite, 15, 6, 8, 1, 32);
+
                BattleState *battleState(new BattleState(bg, monstersLayout, heroesLayout, &battleRes));
                battleState->AddMonster(monster);
                battleState->AddMonster(monster);