From e462583cabc752b8f03b423e98e93bca5f5045d8 Mon Sep 17 00:00:00 2001 From: Daniel Karbach Date: Thu, 9 Aug 2012 00:01:42 +0200 Subject: [PATCH] interpret user input in spell selection --- src/battle/states/SelectSpell.cpp | 28 ++++++++++++++++++++++++++-- src/graphics/Menu.h | 25 ++++++++++++++++++++++--- 2 files changed, 48 insertions(+), 5 deletions(-) diff --git a/src/battle/states/SelectSpell.cpp b/src/battle/states/SelectSpell.cpp index 713c3d5..954b39e 100644 --- a/src/battle/states/SelectSpell.cpp +++ b/src/battle/states/SelectSpell.cpp @@ -16,6 +16,8 @@ #include "../../geometry/Point.h" #include "../../graphics/Frame.h" +#include + using app::Application; using app::Input; using geometry::Point; @@ -49,12 +51,34 @@ void SelectSpell::Resize(int width, int height) { void SelectSpell::HandleInput(const Input &input) { if (input.JustPressed(Input::ACTION_A)) { // TODO: switch to target select - battle->NextHero(); - ctrl->PopState(); + if (battle->GetSpellMenu().SelectedIsEnabled()) { + battle->NextHero(); + ctrl->PopState(); + } } if (input.JustPressed(Input::ACTION_B)) { ctrl->PopState(); // return control to parent } + if (input.JustPressed(Input::PAD_UP)) { + std::cout << "pressed up" << std::endl; + battle->GetSpellMenu().PreviousRow(); + std::cout << "selected index: " << battle->GetSpellMenu().SelectedIndex() << std::endl; + } + if (input.JustPressed(Input::PAD_RIGHT)) { + std::cout << "pressed right" << std::endl; + battle->GetSpellMenu().NextItem(); + std::cout << "selected index: " << battle->GetSpellMenu().SelectedIndex() << std::endl; + } + if (input.JustPressed(Input::PAD_DOWN)) { + std::cout << "pressed down" << std::endl; + battle->GetSpellMenu().NextRow(); + std::cout << "selected index: " << battle->GetSpellMenu().SelectedIndex() << std::endl; + } + if (input.JustPressed(Input::PAD_LEFT)) { + std::cout << "pressed left" << std::endl; + battle->GetSpellMenu().PreviousItem(); + std::cout << "selected index: " << battle->GetSpellMenu().SelectedIndex() << std::endl; + } } void SelectSpell::UpdateWorld(float deltaT) { diff --git a/src/graphics/Menu.h b/src/graphics/Menu.h index ab661c7..f35a2be 100644 --- a/src/graphics/Menu.h +++ b/src/graphics/Menu.h @@ -14,6 +14,7 @@ #include "../geometry/Point.h" #include "../geometry/Vector.h" +#include #include #include @@ -21,8 +22,6 @@ namespace graphics { class Sprite; -// TODO: alternate font for disabled entries -// TODO: sprite for the cursor // TODO: animation when top row changes template class Menu { @@ -30,6 +29,7 @@ class Menu { public: Menu(); Menu(const Font *font, const Font *disabledFont, const Sprite *cursor, int charsPerEntry, int rows, int rowGap = 0, int cols = 1, int colGap = 0); + Menu(const Menu &); public: int Width() const; @@ -47,6 +47,8 @@ public: void NextRow(); void PreviousRow(); void SelectIndex(int index); + int SelectedIndex() const { return selected; } + bool IsSelected(int index) const { return index == selected; } int EntryCount() const { return entries.size(); } T &ValueAt(int index) { return entries[index].value; } @@ -117,6 +119,22 @@ Menu::Menu(const Font *font, const Font *disabledFont, const Sprite *cursor, } +template +Menu::Menu(const Menu &other) +: font(other.font) +, disabledFont(other.disabledFont) +, cursor(other.cursor) +, entries(other.entries) +, charsPerEntry(other.charsPerEntry) +, rows(other.rows) +, rowGap(other.rowGap) +, cols(other.cols) +, colGap(other.colGap) +, selected(other.selected) +, topRow(other.topRow) { + std::cout << "copied Menu" << std::endl; +} + template int Menu::Width() const { @@ -151,7 +169,8 @@ void Menu::PreviousRow() { template void Menu::SelectIndex(int index) { - if (index < 0 || entries.size() < index) return; + if (index < 0 || int(entries.size()) < index) return; + std::cout << "selecting index " << index << std::endl; selected = index; if (GetRow(selected) - rows > topRow) { topRow = GetRow(selected) - rows; -- 2.39.2