]> git.localhorst.tv Git - l2e.git/blobdiff - src/menu/StatusMenu.cpp
added menu cursor animations
[l2e.git] / src / menu / StatusMenu.cpp
index e46a1dd1fbc9d2f11d36d4399286af0cc6a8e200..b2435edbea1cf34de405a82a59a8adeb200fcf1e 100644 (file)
@@ -1,10 +1,3 @@
-/*
- * StatusMenu.cpp
- *
- *  Created on: Oct 22, 2012
- *      Author: holy
- */
-
 #include "StatusMenu.h"
 
 #include "HeroStatus.h"
 #include "../common/GameState.h"
 #include "../common/Hero.h"
 #include "../common/Item.h"
+#include "../common/Stats.h"
 #include "../graphics/Font.h"
+#include "../graphics/Frame.h"
+#include "../math/Vector.h"
 
 using app::Input;
 using common::Hero;
 using common::Item;
-using geometry::Vector;
+using common::Stats;
+using math::Vector;
 using graphics::Font;
+using graphics::Frame;
 
 namespace menu {
 
 StatusMenu::StatusMenu(PartyMenu *parent, int cursor)
 : parent(parent)
-, cursor(cursor) {
-
+, cursor(cursor)
+, menu(*parent->Res().statusMenuProperties) {
+       menu.Add(parent->Res().nextLabel, 0);
+       menu.Add(parent->Res().returnLabel, 1);
 }
 
 
 void StatusMenu::OnEnterState(SDL_Surface *) {
-
+       menu.StartAnimation(Ctrl());
 }
 
 void StatusMenu::OnExitState(SDL_Surface *) {
@@ -56,19 +56,33 @@ void StatusMenu::OnResize(int width, int height) {
 
 
 void StatusMenu::HandleEvents(const Input &input) {
-       if (input.JustPressed(Input::ACTION_B)) {
-               Ctrl().PopState();
-       }
-
        if (input.JustPressed(Input::SHOULDER_RIGHT)) {
                NextHero();
        }
        if (input.JustPressed(Input::SHOULDER_LEFT)) {
                PreviousHero();
        }
+
+       if (input.JustPressed(Input::PAD_LEFT)) {
+               menu.PreviousItem();
+       }
+       if (input.JustPressed(Input::PAD_RIGHT)) {
+               menu.NextItem();
+       }
+
+       if (input.JustPressed(Input::ACTION_A)) {
+               if (menu.Selected() == 0) {
+                       NextHero();
+               } else if (menu.Selected() == 1) {
+                       Ctrl().PopState();
+               }
+       }
+       if (input.JustPressed(Input::ACTION_B)) {
+               Ctrl().PopState();
+       }
 }
 
-void StatusMenu::UpdateWorld(float deltaT) {
+void StatusMenu::UpdateWorld(Uint32 deltaT) {
 
 }
 
@@ -78,13 +92,33 @@ void StatusMenu::Render(SDL_Surface *screen) {
                        5 * parent->Res().statusFont->CharWidth(),
                        parent->Res().statusFont->CharHeight());
        Vector<int> statsOffset(
+                       4 * parent->Res().statusFont->CharWidth(),
+                       8 * parent->Res().statusFont->CharHeight() - parent->Res().statusFont->CharHeight() / 8);
+       Vector<int> equipOffset(
                        17 * parent->Res().statusFont->CharWidth(),
                        4 * parent->Res().statusFont->CharHeight() - parent->Res().statusFont->CharHeight() / 8);
+       Vector<int> experienceOffset(
+                       11 * parent->Res().statusFont->CharWidth(),
+                       17 * parent->Res().statusFont->CharHeight() - parent->Res().statusFont->CharHeight() / 8);
+       Vector<int> nextLevelOffset(
+                       11 * parent->Res().statusFont->CharWidth(),
+                       20 * parent->Res().statusFont->CharHeight() - parent->Res().statusFont->CharHeight() / 8);
+       Vector<int> ikariOffset(
+                       17 * parent->Res().statusFont->CharWidth(),
+                       17 * parent->Res().statusFont->CharHeight() - parent->Res().statusFont->CharHeight() / 8);
+       Vector<int> menuOffset(
+                       parent->Res().statusFont->CharWidth(),
+                       23 * parent->Res().statusFont->CharHeight() - parent->Res().statusFont->CharHeight() / 8);
 
        parent->RenderBackground(screen);
        parent->Res().shoulderNav->Draw(screen, offset + shoulderNavOffset);
        RenderStatus(screen, offset + parent->StatusOffset(0));
-       RenderEquipment(screen, offset + statsOffset);
+       RenderStats(screen, offset + statsOffset);
+       RenderEquipment(screen, offset + equipOffset);
+       RenderExperience(screen, experienceOffset);
+       RenderNextLevel(screen, nextLevelOffset);
+       RenderIkari(screen, ikariOffset);
+       RenderMenu(screen, menuOffset);
 }
 
 int StatusMenu::Width() const {
@@ -99,27 +133,49 @@ void StatusMenu::RenderStatus(SDL_Surface *screen, const Vector<int> &offset) co
        parent->GetHeroStatus(cursor).Render(screen, offset);
 }
 
-void StatusMenu::RenderEquipment(SDL_Surface *screen, const geometry::Vector<int> &offset) const {
-       const Hero &hero(*parent->Game().state->party[cursor]);
-       Vector<int> lineBreak(0, 2 * parent->Res().statusFont->CharHeight());
+void StatusMenu::RenderStats(SDL_Surface *screen, const Vector<int> &offset) const {
+       const Stats &stats(GetHero().GetStats());
+       Vector<int> lineBreak(0, parent->Res().statusFont->CharHeight());
 
        Vector<int> position(offset);
-       RenderEquipmentLine(hero.Weapon(), screen, position);
+       RenderStatsLine(parent->Res().atpLabel, stats.Attack(), screen, position);
+
+       position += lineBreak;
+       RenderStatsLine(parent->Res().dfpLabel, stats.Defense(), screen, position);
 
        position += lineBreak;
-       RenderEquipmentLine(hero.Armor(), screen, position);
+       RenderStatsLine(parent->Res().strLabel, stats.Strength(), screen, position);
 
        position += lineBreak;
-       RenderEquipmentLine(hero.Shield(), screen, position);
+       RenderStatsLine(parent->Res().aglLabel, stats.Agility(), screen, position);
 
        position += lineBreak;
-       RenderEquipmentLine(hero.Helmet(), screen, position);
+       RenderStatsLine(parent->Res().intLabel, stats.Intelligence(), screen, position);
 
        position += lineBreak;
-       RenderEquipmentLine(hero.Ring(), screen, position);
+       RenderStatsLine(parent->Res().gutLabel, stats.Gut(), screen, position);
 
        position += lineBreak;
-       RenderEquipmentLine(hero.Jewel(), screen, position);
+       RenderStatsLine(parent->Res().mgrLabel, stats.MagicResistance(), screen, position);
+}
+
+void StatusMenu::RenderStatsLine(const char *label, int number, SDL_Surface *screen, const Vector<int> &position) const {
+       const Font &font(*parent->Res().statusFont);
+       const Vector<int> numberOffset(4 * font.CharWidth(), 0);
+
+       font.DrawString(label, screen, position, 3);
+       font.DrawNumber(number, screen, position + numberOffset, 3);
+}
+
+void StatusMenu::RenderEquipment(SDL_Surface *screen, const Vector<int> &offset) const {
+       const Hero &hero(GetHero());
+       Vector<int> lineBreak(0, 2 * parent->Res().statusFont->CharHeight());
+
+       Vector<int> position(offset);
+       for (int i = 0; i < Hero::EQUIP_COUNT; ++i) {
+               RenderEquipmentLine(hero.Equipment(Hero::EquipSlot(i)), screen, position);
+               position += lineBreak;
+       }
 }
 
 void StatusMenu::RenderEquipmentLine(const Item *item, SDL_Surface *screen, const Vector<int> &position) const {
@@ -135,6 +191,47 @@ void StatusMenu::RenderEquipmentLine(const Item *item, SDL_Surface *screen, cons
        }
 }
 
+void StatusMenu::RenderExperience(SDL_Surface *screen, const math::Vector<int> &offset) const {
+       const Font &font(*parent->Res().statusFont);
+       font.DrawStringRight(parent->Res().experienceLabel, screen, offset, 10);
+
+       Vector<int> numberOffset(offset.X(), offset.Y() + font.CharHeight());
+       font.DrawNumberRight(GetHero().Experience(), screen, numberOffset, 7);
+}
+
+void StatusMenu::RenderNextLevel(SDL_Surface *screen, const math::Vector<int> &offset) const {
+       const Font &font(*parent->Res().statusFont);
+       font.DrawStringRight(parent->Res().nextLevelLabel, screen, offset, 10);
+
+       Vector<int> numberOffset(offset.X(), offset.Y() + font.CharHeight());
+       font.DrawNumberRight(GetHero().NextLevel(), screen, numberOffset, 7);
+}
+
+void StatusMenu::RenderIkari(SDL_Surface *screen, const math::Vector<int> &offset) const {
+       const Font &font(*parent->Res().statusFont);
+       font.DrawString(parent->Res().ipLabel, screen, offset, 5);
+
+       Vector<int> numberOffset(offset.X() + 5 * font.CharWidth(), offset.Y());
+       font.DrawNumber(GetHero().RelativeIP(100), screen, numberOffset, 3);
+
+       Vector<int> percentOffset(offset.X() + 8 * font.CharWidth(), offset.Y());
+       font.DrawChar('%', screen, percentOffset);
+}
+
+void StatusMenu::RenderMenu(SDL_Surface *screen, const math::Vector<int> &offset) const {
+       const Font &font(*parent->Res().normalFont);
+       const Frame &frame(*parent->Res().statusFrame);
+
+       Vector<int> labelOffset(2 * font.CharWidth(), font.CharHeight());
+       frame.Draw(screen, offset, 10 * font.CharWidth(), 3 * font.CharHeight());
+       font.DrawString(parent->Res().mainMenuStatusText, screen, offset + labelOffset);
+
+       Vector<int> menuFrameOffset(10 * font.CharWidth(), 0);
+       Vector<int> menuOffset(13 * font.CharWidth(), font.CharHeight());
+       frame.Draw(screen, offset + menuFrameOffset, 20 * font.CharWidth(), 3 * font.CharHeight());
+       menu.Draw(screen, offset + menuOffset);
+}
+
 
 void StatusMenu::NextHero() {
        cursor = (cursor + 1) % parent->Game().state->partySize;
@@ -144,4 +241,8 @@ void StatusMenu::PreviousHero() {
        cursor = (cursor + parent->Game().state->partySize - 1) % parent->Game().state->partySize;
 }
 
+const Hero &StatusMenu::GetHero() const {
+       return *parent->Game().state->party[cursor];
+}
+
 }