]> git.localhorst.tv Git - l2e.git/blobdiff - src/menu/EquipMenu.cpp
started implementation of equipment menu
[l2e.git] / src / menu / EquipMenu.cpp
diff --git a/src/menu/EquipMenu.cpp b/src/menu/EquipMenu.cpp
new file mode 100644 (file)
index 0000000..da24f77
--- /dev/null
@@ -0,0 +1,181 @@
+/*
+ * EquipMenu.cpp
+ *
+ *  Created on: Nov 18, 2012
+ *      Author: holy
+ */
+
+#include "EquipMenu.h"
+
+#include "HeroStatus.h"
+#include "PartyMenu.h"
+#include "Resources.h"
+#include "../app/Application.h"
+#include "../app/Input.h"
+#include "../common/GameConfig.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"
+
+using app::Input;
+using common::Hero;
+using common::Item;
+using common::Stats;
+using geometry::Vector;
+using graphics::Font;
+using graphics::Frame;
+
+namespace menu {
+
+EquipMenu::EquipMenu(PartyMenu *parent, int cursor)
+: parent(parent)
+, cursor(cursor)
+, actionMenu(*parent->Res().equipmentActionMenuProperties)
+, equipmentMenu(*parent->Res().equipmentMenuProperties)
+, inventoryMenu(*parent->Res().inventoryMenuProperties) {
+       actionMenu.Add(parent->Res().equipMenuEquipLabel, CHOICE_EQUIP);
+       actionMenu.Add(parent->Res().equipMenuStrongestLabel, CHOICE_STRONGEST);
+       actionMenu.Add(parent->Res().equipMenuRemoveLabel, CHOICE_REMOVE);
+       actionMenu.Add(parent->Res().equipMenuRemoveAllLabel, CHOICE_REMOVE_ALL);
+       actionMenu.Add(parent->Res().equipMenuDropLabel, CHOICE_DROP);
+
+       LoadEquipment();
+}
+
+
+void EquipMenu::OnEnterState(SDL_Surface *) {
+       equipmentMenu.SetInactive();
+}
+
+void EquipMenu::OnExitState(SDL_Surface *) {
+
+}
+
+void EquipMenu::OnResumeState(SDL_Surface *) {
+
+}
+
+void EquipMenu::OnPauseState(SDL_Surface *) {
+
+}
+
+
+void EquipMenu::OnResize(int width, int height) {
+
+}
+
+
+void EquipMenu::HandleEvents(const Input &input) {
+
+}
+
+void EquipMenu::UpdateWorld(float deltaT) {
+
+}
+
+void EquipMenu::Render(SDL_Surface *screen) {
+       Vector<int> offset((screen->w - Width()) / 2, (screen->h - Height()) / 2);
+       Vector<int> shoulderNavOffset(
+                       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);
+
+       parent->RenderBackground(screen);
+       parent->Res().shoulderNav->Draw(screen, offset + shoulderNavOffset);
+       RenderStatus(screen, offset + parent->StatusOffset(0));
+       RenderStats(screen, offset + statsOffset);
+       RenderEquipmentMenu(screen, equipOffset);
+}
+
+int EquipMenu::Width() const {
+       return parent->Width();
+}
+
+int EquipMenu::Height() const {
+       return parent->Height();
+}
+
+void EquipMenu::RenderStatus(SDL_Surface *screen, const Vector<int> &offset) const {
+       parent->GetHeroStatus(cursor).Render(screen, offset);
+}
+
+void EquipMenu::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);
+       RenderStatsLine(parent->Res().atpLabel, stats.Attack(), screen, position);
+
+       position += lineBreak;
+       RenderStatsLine(parent->Res().dfpLabel, stats.Defense(), screen, position);
+
+       position += lineBreak;
+       RenderStatsLine(parent->Res().strLabel, stats.Strength(), screen, position);
+
+       position += lineBreak;
+       RenderStatsLine(parent->Res().aglLabel, stats.Agility(), screen, position);
+
+       position += lineBreak;
+       RenderStatsLine(parent->Res().intLabel, stats.Intelligence(), screen, position);
+
+       position += lineBreak;
+       RenderStatsLine(parent->Res().gutLabel, stats.Gut(), screen, position);
+
+       position += lineBreak;
+       RenderStatsLine(parent->Res().mgrLabel, stats.MagicResistance(), screen, position);
+}
+
+void EquipMenu::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 EquipMenu::RenderEquipmentMenu(SDL_Surface *screen, const Vector<int> &offset) const {
+       equipmentMenu.Draw(screen, offset);
+}
+
+void EquipMenu::RenderActionMenu(SDL_Surface *screen, const Vector<int> &offset) const {
+
+}
+
+void EquipMenu::RenderInventoryMenu(SDL_Surface *screen, const Vector<int> &offset) const {
+
+}
+
+
+void EquipMenu::NextHero() {
+       cursor = (cursor + 1) % parent->Game().state->partySize;
+       LoadEquipment();
+}
+
+void EquipMenu::PreviousHero() {
+       cursor = (cursor + parent->Game().state->partySize - 1) % parent->Game().state->partySize;
+       LoadEquipment();
+}
+
+const Hero &EquipMenu::GetHero() const {
+       return *parent->Game().state->party[cursor];
+}
+
+void EquipMenu::LoadEquipment() {
+       equipmentMenu.Clear();
+       equipmentMenu.Add(GetHero().Weapon()->Name(), GetHero().Weapon(), true, GetHero().Weapon()->MenuIcon());
+       equipmentMenu.Add(GetHero().Armor()->Name(), GetHero().Armor(), true, GetHero().Armor()->MenuIcon());
+       equipmentMenu.Add(GetHero().Shield()->Name(), GetHero().Shield(), true, GetHero().Shield()->MenuIcon());
+       equipmentMenu.Add(GetHero().Helmet()->Name(), GetHero().Helmet(), true, GetHero().Helmet()->MenuIcon());
+       equipmentMenu.Add(GetHero().Ring()->Name(), GetHero().Ring(), true, GetHero().Ring()->MenuIcon());
+       equipmentMenu.Add(GetHero().Jewel()->Name(), GetHero().Jewel(), true, GetHero().Jewel()->MenuIcon());
+}
+
+}