From: Daniel Karbach Date: Wed, 8 Aug 2012 21:23:07 +0000 (+0200) Subject: added ability to disable menu entries X-Git-Url: http://git.localhorst.tv/?a=commitdiff_plain;ds=inline;h=4470cf4b44128f3509bfab43483844d19f563a77;p=l2e.git added ability to disable menu entries --- diff --git a/src/battle/BattleState.cpp b/src/battle/BattleState.cpp index d1cb4ff..549fdb4 100644 --- a/src/battle/BattleState.cpp +++ b/src/battle/BattleState.cpp @@ -53,7 +53,7 @@ void BattleState::EnterState(Application &ctrl, SDL_Surface *screen) { for (vector::size_type i(0), end(heroes.size()); i < end; ++i) { spellMenus.push_back(res->spellMenuPrototype); // TODO: insert real spell menu entries - spellMenus.back().Add("Reset : 0", 0); + spellMenus.back().Add("Reset : 0", 0, false); spellMenus.back().Add("Strong : 3", 0); spellMenus.back().Add("Stronger : 8", 0); spellMenus.back().Add("Champion :16", 0); diff --git a/src/graphics/Menu.h b/src/graphics/Menu.h index 576120e..083e741 100644 --- a/src/graphics/Menu.h +++ b/src/graphics/Menu.h @@ -20,7 +20,7 @@ namespace graphics { class Sprite; -// TODO: disabled entries + alternate font for those +// TODO: alternate font for disabled entries // TODO: sprite for the cursor // TODO: animation when top row changes template @@ -38,6 +38,7 @@ public: T &Selected() { return entries[selected].value; } const T &Selected() const { return entries[selected].value; } const char *SelectedTitle() const { return entries[selected].title; } + bool SelectedIsEnabled() const { return entries[selected].enabled; } void NextItem(); void PreviousItem(); @@ -45,7 +46,13 @@ public: void PreviousRow(); void SelectIndex(int index); - void Add(const char *title, const T &value, const Sprite *icon = 0) { entries.push_back(Entry(title, value, icon)); } + int EntryCount() const { return entries.size(); } + T &ValueAt(int index) { return entries[index].value; } + const T &ValueAt(int index) const { return entries[index].value; } + + void Add(const char *title, const T &value, bool enabled = true, const Sprite *icon = 0) { entries.push_back(Entry(title, value, enabled, icon)); } + void Disable(int index) { entries[index].enabled = false; } + void Enable(int index) { entries[index].enabled = true; } void Reserve(int n) { entries.reserve(n); } void Draw(SDL_Surface *dest, geometry::Point position) const; @@ -56,11 +63,12 @@ private: private: struct Entry { - Entry(const char *title, const T &value, const Sprite *icon = 0) - : title(title), icon(icon), value(value) { } + Entry(const char *title, const T &value, bool enabled = true, const Sprite *icon = 0) + : title(title), icon(icon), value(value), enabled(enabled) { } const char *title; const Sprite *icon; T value; + bool enabled; }; const Font *font; std::vector entries;