From: Daniel Karbach Date: Tue, 20 Nov 2012 19:22:38 +0000 (+0100) Subject: started implementation of equipment menu X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;h=f2abfc21845c29024ce2478f95429801e91ef8e8;p=l2e.git started implementation of equipment menu --- diff --git a/src/main.cpp b/src/main.cpp index acdc0ad..df5ab7a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -411,6 +411,28 @@ int main(int argc, char **argv) { spellMenuProperties.delimiter = ':'; menuResources.spellMenuProperties = &spellMenuProperties; + graphics::MenuProperties equipmentActionMenuProperties; + equipmentActionMenuProperties.cols = 1; + equipmentActionMenuProperties.rows = 5; + equipmentActionMenuProperties.charsPerEntry = 10; + equipmentActionMenuProperties.rowGap = 8; + equipmentActionMenuProperties.cursor = &menuCursor; + equipmentActionMenuProperties.selectedCursor = &menuActiveCursor; + equipmentActionMenuProperties.font = &menuFont; + equipmentActionMenuProperties.iconSpace = 0; + menuResources.equipmentActionMenuProperties = &equipmentActionMenuProperties; + + graphics::MenuProperties equipmentMenuProperties; + equipmentMenuProperties.cols = 1; + equipmentMenuProperties.rows = 5; + equipmentMenuProperties.charsPerEntry = 12; + equipmentMenuProperties.rowGap = 16; + equipmentMenuProperties.cursor = &menuCursor; + equipmentMenuProperties.selectedCursor = &menuActiveCursor; + equipmentMenuProperties.font = menuResources.statusFont; + equipmentMenuProperties.iconSpace = 16; + menuResources.equipmentMenuProperties = &equipmentMenuProperties; + InitScreen screen(width, height); app::State *state(0); diff --git a/src/menu/EquipMenu.cpp b/src/menu/EquipMenu.cpp new file mode 100644 index 0000000..da24f77 --- /dev/null +++ b/src/menu/EquipMenu.cpp @@ -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 offset((screen->w - Width()) / 2, (screen->h - Height()) / 2); + Vector shoulderNavOffset( + 5 * parent->Res().statusFont->CharWidth(), + parent->Res().statusFont->CharHeight()); + Vector statsOffset( + 4 * parent->Res().statusFont->CharWidth(), + 8 * parent->Res().statusFont->CharHeight() - parent->Res().statusFont->CharHeight() / 8); + Vector 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 &offset) const { + parent->GetHeroStatus(cursor).Render(screen, offset); +} + +void EquipMenu::RenderStats(SDL_Surface *screen, const Vector &offset) const { + const Stats &stats(GetHero().GetStats()); + Vector lineBreak(0, parent->Res().statusFont->CharHeight()); + + Vector 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 &position) const { + const Font &font(*parent->Res().statusFont); + const Vector 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 &offset) const { + equipmentMenu.Draw(screen, offset); +} + +void EquipMenu::RenderActionMenu(SDL_Surface *screen, const Vector &offset) const { + +} + +void EquipMenu::RenderInventoryMenu(SDL_Surface *screen, const Vector &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()); +} + +} diff --git a/src/menu/EquipMenu.h b/src/menu/EquipMenu.h new file mode 100644 index 0000000..39380dc --- /dev/null +++ b/src/menu/EquipMenu.h @@ -0,0 +1,74 @@ +/* + * EquipMenu.h + * + * Created on: Nov 18, 2012 + * Author: holy + */ + +#ifndef MENU_EQUIPMENU_H_ +#define MENU_EQUIPMENU_H_ + +#include "fwd.h" +#include "../app/State.h" +#include "../common/fwd.h" +#include "../geometry/Vector.h" +#include "../graphics/Menu.h" + +namespace menu { + +class EquipMenu +: public app::State { + +public: + EquipMenu(PartyMenu *parent, int heroIndex); + +public: + virtual void HandleEvents(const app::Input &); + virtual void UpdateWorld(float deltaT); + virtual void Render(SDL_Surface *); + +public: + int Width() const; + int Height() const; + +private: + virtual void OnEnterState(SDL_Surface *screen); + virtual void OnExitState(SDL_Surface *screen); + virtual void OnResumeState(SDL_Surface *screen); + virtual void OnPauseState(SDL_Surface *screen); + + virtual void OnResize(int width, int height); + + void NextHero(); + void PreviousHero(); + + const common::Hero &GetHero() const; + + void LoadEquipment(); + + void RenderStatus(SDL_Surface *screen, const geometry::Vector &offset) const; + void RenderStats(SDL_Surface *screen, const geometry::Vector &offset) const; + void RenderStatsLine(const char *label, int number, SDL_Surface *screen, const geometry::Vector &position) const; + void RenderEquipmentMenu(SDL_Surface *screen, const geometry::Vector &offset) const; + void RenderActionMenu(SDL_Surface *screen, const geometry::Vector &offset) const; + void RenderInventoryMenu(SDL_Surface *screen, const geometry::Vector &offset) const; + +private: + PartyMenu *parent; + int cursor; + enum Choice { + CHOICE_EQUIP, + CHOICE_STRONGEST, + CHOICE_REMOVE, + CHOICE_REMOVE_ALL, + CHOICE_DROP, + }; + graphics::Menu actionMenu; + graphics::Menu equipmentMenu; + graphics::Menu inventoryMenu; + +}; + +} + +#endif /* MENU_EQUIPMENU_H_ */ diff --git a/src/menu/PartyMenu.cpp b/src/menu/PartyMenu.cpp index 993fad5..bda6331 100644 --- a/src/menu/PartyMenu.cpp +++ b/src/menu/PartyMenu.cpp @@ -8,6 +8,7 @@ #include "PartyMenu.h" #include "ChangeHero.h" +#include "EquipMenu.h" #include "InventoryMenu.h" #include "Resources.h" #include "SelectHero.h" @@ -104,6 +105,7 @@ void PartyMenu::HandleEvents(const Input &input) { case MENU_ITEM_CAPSULE: break; case MENU_ITEM_EQUIP: + Ctrl().PushState(new SelectHero(this, this, this, OnEquipSelect)); break; case MENU_ITEM_STATUS: Ctrl().PushState(new SelectHero(this, this, this, OnStatusSelect)); @@ -202,10 +204,10 @@ const Resources &PartyMenu::Res() const { return *game->menuResources; } -void PartyMenu::OnStatusSelect(void *ref, int index) { +void PartyMenu::OnEquipSelect(void *ref, int index) { PartyMenu *self(reinterpret_cast(ref)); self->Ctrl().ChangeState( - new StatusMenu(self, index)); + new EquipMenu(self, index)); } void PartyMenu::OnSpellSelect(void *ref, int index) { @@ -214,4 +216,10 @@ void PartyMenu::OnSpellSelect(void *ref, int index) { new SpellMenu(self, index)); } +void PartyMenu::OnStatusSelect(void *ref, int index) { + PartyMenu *self(reinterpret_cast(ref)); + self->Ctrl().ChangeState( + new StatusMenu(self, index)); +} + } diff --git a/src/menu/PartyMenu.h b/src/menu/PartyMenu.h index 91c25ba..f915d30 100644 --- a/src/menu/PartyMenu.h +++ b/src/menu/PartyMenu.h @@ -47,8 +47,9 @@ public: geometry::Vector StatusOffset(int index) const; const HeroStatus &GetHeroStatus(int index) const { return status[index]; } - static void OnStatusSelect(void *, int); + static void OnEquipSelect(void *, int); static void OnSpellSelect(void *, int); + static void OnStatusSelect(void *, int); private: virtual void OnEnterState(SDL_Surface *screen); diff --git a/src/menu/Resources.cpp b/src/menu/Resources.cpp index 0e256ac..8b36b25 100644 --- a/src/menu/Resources.cpp +++ b/src/menu/Resources.cpp @@ -64,7 +64,15 @@ Resources::Resources() , inventoryMenuProperties(0) -, spellMenuProperties(0) { +, spellMenuProperties(0) + +, equipmentActionMenuProperties(0) +, equipmentMenuProperties(0) +, equipMenuEquipLabel(0) +, equipMenuStrongestLabel(0) +, equipMenuRemoveLabel(0) +, equipMenuRemoveAllLabel(0) +, equipMenuDropLabel(0) { } diff --git a/src/menu/Resources.h b/src/menu/Resources.h index df69225..acc99ad 100644 --- a/src/menu/Resources.h +++ b/src/menu/Resources.h @@ -71,6 +71,14 @@ struct Resources { graphics::MenuProperties *spellMenuProperties; + graphics::MenuProperties *equipmentActionMenuProperties; + graphics::MenuProperties *equipmentMenuProperties; + const char *equipMenuEquipLabel; + const char *equipMenuStrongestLabel; + const char *equipMenuRemoveLabel; + const char *equipMenuRemoveAllLabel; + const char *equipMenuDropLabel; + Resources(); }; diff --git a/src/menu/fwd.h b/src/menu/fwd.h index 0f88e19..40d0163 100644 --- a/src/menu/fwd.h +++ b/src/menu/fwd.h @@ -11,6 +11,7 @@ namespace menu { class ChangeHero; +class EquipMenu; class HeroStatus; class InventoryMenu; class PartyMenu;