From: Daniel Karbach Date: Wed, 8 Aug 2012 21:30:55 +0000 (+0200) Subject: added a "disabled" font X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;h=19e11f43c4ad3aaccce8809ba66350dd3cbeb3dd;p=l2e.git added a "disabled" font --- diff --git a/src/battle/Resources.h b/src/battle/Resources.h index 2de6b69..098c844 100644 --- a/src/battle/Resources.h +++ b/src/battle/Resources.h @@ -37,6 +37,7 @@ struct Resources { graphics::Frame *selectFrame; graphics::Font *normalFont; + graphics::Font *disabledFont; const char *spellMenuHeadline; graphics::Menu spellMenuPrototype; @@ -59,6 +60,7 @@ struct Resources { , selectFrame(0) , normalFont(0) + , disabledFont(0) , spellMenuHeadline("") { } diff --git a/src/graphics/Menu.h b/src/graphics/Menu.h index 083e741..90af3e4 100644 --- a/src/graphics/Menu.h +++ b/src/graphics/Menu.h @@ -27,7 +27,7 @@ template 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; @@ -71,6 +71,7 @@ private: bool enabled; }; const Font *font; + const Font *disabledFont; std::vector entries; int charsPerEntry; int rows; @@ -84,8 +85,9 @@ private: template -Menu::Menu(const Font *font, int charsPerEntry, int rows, int rowGap, int cols, int colGap) +Menu::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) @@ -148,7 +150,11 @@ void Menu::Draw(SDL_Surface *dest, geometry::Point position) const { int end(items < slots ? items : slots); for (int i(0), count(end - start); i < count; ++i) { geometry::Vector 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); + } } } diff --git a/src/main.cpp b/src/main.cpp index 22c43cc..df3def1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -169,8 +169,21 @@ int main(int argc, char **argv) { // 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(&normalFont, 12, 6, 8, 2, 32); + battleRes.spellMenuPrototype = Menu(&normalFont, &disabledFont, 12, 6, 8, 2, 32); BattleState *battleState(new BattleState(bg, monstersLayout, heroesLayout, &battleRes)); battleState->AddMonster(monster); diff --git a/test-data/disabled-font.png b/test-data/disabled-font.png new file mode 100644 index 0000000..794d05f Binary files /dev/null and b/test-data/disabled-font.png differ diff --git a/test-data/normal-font.png b/test-data/normal-font.png index 0bd50d0..b6a286e 100644 Binary files a/test-data/normal-font.png and b/test-data/normal-font.png differ