From: Daniel Karbach Date: Sun, 18 Nov 2012 16:13:24 +0000 (+0100) Subject: implemented spell sorting X-Git-Url: http://git.localhorst.tv/?a=commitdiff_plain;h=6a954cc1f6324d61282e21ec0d7dee6e6265f44f;p=l2e.git implemented spell sorting sorting order is cost for now, need to find out the real order --- diff --git a/src/common/Hero.h b/src/common/Hero.h index 77269c6..1905c81 100644 --- a/src/common/Hero.h +++ b/src/common/Hero.h @@ -71,6 +71,7 @@ public: bool HasRing() const { return ring; } bool HasJewel() const { return jewel; } + std::vector &Spells() { return spells; } const std::vector &Spells() const { return spells; } graphics::Sprite *BattleSprite() { return battleSprite; } diff --git a/src/common/Spell.cpp b/src/common/Spell.cpp index 4fce22f..33979ca 100644 --- a/src/common/Spell.cpp +++ b/src/common/Spell.cpp @@ -23,6 +23,12 @@ Spell::Spell() } +bool Spell::Less(const Spell *lhs, const Spell *rhs) { + // TODO: find out real spell sorting order + return lhs->Cost() < rhs->Cost(); +} + + void Spell::CreateTypeDescription() { Spell s; diff --git a/src/common/Spell.h b/src/common/Spell.h index 0f864b8..e9befa9 100644 --- a/src/common/Spell.h +++ b/src/common/Spell.h @@ -35,6 +35,8 @@ public: HeroGroup &UsableBy() { return usableBy; } const HeroGroup &UsableBy() const { return usableBy; } + static bool Less(const Spell *, const Spell *); + // temporary setters public: void SetName(const char *n) { name = n; } diff --git a/src/menu/SpellMenu.cpp b/src/menu/SpellMenu.cpp index 0f34d06..3be722b 100644 --- a/src/menu/SpellMenu.cpp +++ b/src/menu/SpellMenu.cpp @@ -18,6 +18,7 @@ #include "../graphics/Font.h" #include "../graphics/Frame.h" +#include #include #include @@ -68,6 +69,10 @@ const Hero &SpellMenu::GetHero() const { return *parent->Game().state->party[cursor]; } +Hero &SpellMenu::GetHero() { + return *parent->Game().state->party[cursor]; +} + void SpellMenu::OnExitState(SDL_Surface *) { SDL_FreeSurface(highlight); } @@ -112,7 +117,9 @@ void SpellMenu::HandleEvents(const Input &input) { if (input.JustPressed(Input::ACTION_A)) { if (actionMenu.IsActive()) { if (actionMenu.Selected() == CHOICE_SORT) { - // TODO: sort spells + std::sort(GetHero().Spells().begin(), + GetHero().Spells().end(), + Spell::Less); LoadSpells(); } else { actionMenu.SetSelected(); diff --git a/src/menu/SpellMenu.h b/src/menu/SpellMenu.h index c9c62a7..d289794 100644 --- a/src/menu/SpellMenu.h +++ b/src/menu/SpellMenu.h @@ -39,6 +39,7 @@ private: virtual void OnResize(int width, int height); + common::Hero &GetHero(); const common::Hero &GetHero() const; void LoadSpells();