graphics::Frame *selectFrame;
graphics::Font *normalFont;
+ graphics::Font *disabledFont;
const char *spellMenuHeadline;
graphics::Menu</* Spell */ void *> spellMenuPrototype;
, selectFrame(0)
, normalFont(0)
+ , disabledFont(0)
, spellMenuHeadline("")
{ }
class Menu {
public:
- explicit Menu(const Font *font = NULL, int charsPerEntry = 16, int rows = 1, int rowGap = 0, int cols = 1, int colGap = 0);
+ explicit Menu(const Font *font = NULL, const Font *disabledFont = NULL, int charsPerEntry = 16, int rows = 1, int rowGap = 0, int cols = 1, int colGap = 0);
public:
int Width() const;
bool enabled;
};
const Font *font;
+ const Font *disabledFont;
std::vector<Entry> entries;
int charsPerEntry;
int rows;
template<class T>
-Menu<T>::Menu(const Font *font, int charsPerEntry, int rows, int rowGap, int cols, int colGap)
+Menu<T>::Menu(const Font *font, const Font *disabledFont, int charsPerEntry, int rows, int rowGap, int cols, int colGap)
: font(font)
+, disabledFont(disabledFont ? disabledFont : font)
, charsPerEntry(charsPerEntry)
, rows(rows)
, rowGap(rowGap)
int end(items < slots ? items : slots);
for (int i(0), count(end - start); i < count; ++i) {
geometry::Vector<int> offset((i % cols) * (ColWidth() + colGap), (i / cols) * RowHeight());
- font->DrawString(entries[start + i].title, dest, position + offset, charsPerEntry);
+ if (entries[start + i].enabled) {
+ font->DrawString(entries[start + i].title, dest, position + offset, charsPerEntry);
+ } else {
+ disabledFont->DrawString(entries[start + i].title, dest, position + offset, charsPerEntry);
+ }
}
}
// TODO: add '.' character
battleRes.normalFont = &normalFont;
+ SDL_Surface *disabledFontImg(IMG_Load("test-data/disabled-font.png"));
+ Sprite disabledFontSprite(disabledFontImg, 16, 16);
+ Font disabledFont(&disabledFontSprite);
+ disabledFont.MapRange('A', 'M', 0, 1);
+ disabledFont.MapRange('N', 'Z', 0, 2);
+ disabledFont.MapRange('a', 'm', 0, 3);
+ disabledFont.MapRange('n', 'z', 0, 4);
+ disabledFont.MapChar(':', 10, 0);
+ disabledFont.MapChar('!', 10, 0);
+ disabledFont.MapChar('?', 10, 0);
+ // TODO: add '.' character
+ battleRes.disabledFont = &disabledFont;
+
battleRes.spellMenuHeadline = "Please choose a spell.";
- battleRes.spellMenuPrototype = Menu</* Spell */ void *>(&normalFont, 12, 6, 8, 2, 32);
+ battleRes.spellMenuPrototype = Menu</* Spell */ void *>(&normalFont, &disabledFont, 12, 6, 8, 2, 32);
BattleState *battleState(new BattleState(bg, monstersLayout, heroesLayout, &battleRes));
battleState->AddMonster(monster);