#include "../../geometry/Point.h"
#include "../../graphics/Frame.h"
+#include <iostream>
+
using app::Application;
using app::Input;
using geometry::Point;
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) {
#include "../geometry/Point.h"
#include "../geometry/Vector.h"
+#include <iostream>
#include <vector>
#include <SDL.h>
class Sprite;
-// TODO: alternate font for disabled entries
-// TODO: sprite for the cursor
// TODO: animation when top row changes
template<class T>
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;
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; }
}
+template<class T>
+Menu<T>::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<class T>
int Menu<T>::Width() const {
template<class T>
void Menu<T>::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;