From: Daniel Karbach Date: Tue, 4 Dec 2012 21:48:07 +0000 (+0100) Subject: added most of the capsule main menu's features X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;h=7f0a586b8238c7093a8942ff5b5c4122edd386fc;p=l2e.git added most of the capsule main menu's features --- diff --git a/src/menu/CapsuleMenu.cpp b/src/menu/CapsuleMenu.cpp index c85091b..7837ea5 100644 --- a/src/menu/CapsuleMenu.cpp +++ b/src/menu/CapsuleMenu.cpp @@ -6,6 +6,7 @@ #include "../app/Input.h" #include "../common/GameConfig.h" #include "../common/GameState.h" +#include "../common/Spell.h" #include "../common/Stats.h" #include "../graphics/Font.h" #include "../graphics/Frame.h" @@ -52,6 +53,13 @@ void CapsuleMenu::OnResize(int width, int height) { void CapsuleMenu::HandleEvents(const Input &input) { + if (input.JustPressed(Input::PAD_LEFT)) { + menu.PreviousItem(); + } + if (input.JustPressed(Input::PAD_RIGHT)) { + menu.NextItem(); + } + if (input.JustPressed(Input::ACTION_B)) { Ctrl().PopState(); } @@ -62,15 +70,152 @@ void CapsuleMenu::UpdateWorld(float deltaT) { } void CapsuleMenu::Render(SDL_Surface *screen) { - Vector offset((screen->w - Width()) / 2, (screen->h - Height()) / 2); + const Font &font(*parent->Res().statusFont); + const Vector offset((screen->w - Width()) / 2, (screen->h - Height()) / 2); + const Vector capsuleOffset( + 6 * font.CharWidth(), + 12 * font.CharHeight()); + const Vector infoOffset( + 12 * font.CharWidth(), + 2 * font.CharHeight() - font.CharHeight() / 8); + // TODO: wheel offset: top left, center, or center bottom? + const Vector wheelOffset; + const Vector statsOffset( + 12 * font.CharWidth(), + 15 * font.CharHeight() - font.CharHeight() / 8); + const Vector menuOffset( + font.CharWidth(), + 24 * font.CharHeight() - font.CharHeight() / 8); RenderBackground(screen); + RenderCapsule(screen, offset + capsuleOffset); + RenderInfo(screen, offset + infoOffset); + RenderWheel(screen, offset + wheelOffset); + RenderStats(screen, offset + statsOffset); + RenderMenu(screen, offset + menuOffset); } void CapsuleMenu::RenderBackground(SDL_Surface *screen) const { parent->Res().capsulebg->Render(screen, Vector(), Vector(screen->w, screen->h)); } +void CapsuleMenu::RenderCapsule(SDL_Surface *screen, const Vector &offset) const { + GetCapsule().BattleSprite()->DrawCenterBottom(screen, offset); +} + +void CapsuleMenu::RenderInfo(SDL_Surface *screen, const Vector &offset) const { + const Capsule &capsule(GetCapsule()); + const Font &font(*parent->Res().statusFont); + const Vector delimiterOffset(5 * font.CharWidth(), 0); + const Vector valueOffset(6 * font.CharWidth(), 0); + const Vector lineBreak(0, font.CharHeight() + font.CharHeight() / 2); + Vector lineHead(offset); + + font.DrawString(parent->Res().capsuleNameLabel, screen, lineHead, 5); + font.DrawChar(':', screen, lineHead + delimiterOffset); + font.DrawString(capsule.Name(), screen, lineHead + valueOffset); + + lineHead += lineBreak; + font.DrawString(parent->Res().capsuleClassLabel, screen, lineHead, 5); + font.DrawChar(':', screen, lineHead + delimiterOffset); + font.DrawString(capsule.ClassName(), screen, lineHead + valueOffset); + + lineHead += lineBreak; + font.DrawString(parent->Res().capsuleAlignmentLabel, screen, lineHead, 5); + font.DrawChar(':', screen, lineHead + delimiterOffset); + font.DrawString(capsule.Alignment(), screen, lineHead + valueOffset); + + lineHead += lineBreak; + font.DrawString(parent->Res().capsuleTribeLabel, screen, lineHead, 5); + font.DrawChar(':', screen, lineHead + delimiterOffset); + font.DrawString(capsule.Tribe(), screen, lineHead + valueOffset); + + lineHead += lineBreak; + font.DrawString(parent->Res().capsuleAttack1Label, screen, lineHead, 5); + font.DrawChar(':', screen, lineHead + delimiterOffset); + if (capsule.Attack1()) { + font.DrawString(capsule.Attack1()->Name(), screen, lineHead + valueOffset); + } else { + font.DrawString(parent->Res().capsuleNoAttackText, screen, lineHead + valueOffset); + } + + lineHead += lineBreak; + font.DrawString(parent->Res().capsuleAttack1Label, screen, lineHead, 5); + font.DrawChar(':', screen, lineHead + delimiterOffset); + if (capsule.Attack2()) { + font.DrawString(capsule.Attack2()->Name(), screen, lineHead + valueOffset); + } else { + font.DrawString(parent->Res().capsuleNoAttackText, screen, lineHead + valueOffset); + } + + lineHead += lineBreak; + font.DrawString(parent->Res().capsuleAttack1Label, screen, lineHead, 5); + font.DrawChar(':', screen, lineHead + delimiterOffset); + if (capsule.Attack3()) { + font.DrawString(capsule.Attack3()->Name(), screen, lineHead + valueOffset); + } else { + font.DrawString(parent->Res().capsuleNoAttackText, screen, lineHead + valueOffset); + } +} + +void CapsuleMenu::RenderWheel(SDL_Surface *screen, const Vector &offset) const { + // later +} + +void CapsuleMenu::RenderStats(SDL_Surface *screen, const Vector &offset) const { + const Capsule &capsule(GetCapsule()); + Stats stats(capsule.GetStats()); + const Font &font(*parent->Res().statusFont); + const Vector lineBreak(0, font.CharHeight()); + Vector lineHead(offset); + + RenderStatsLine(screen, lineHead, parent->Res().hpLabel, capsule.MaxHealth()); + lineHead += lineBreak; + RenderStatsLine(screen, lineHead, parent->Res().atpLabel, stats.Attack()); + lineHead += lineBreak; + RenderStatsLine(screen, lineHead, parent->Res().dfpLabel, stats.Defense()); + lineHead += lineBreak; + RenderStatsLine(screen, lineHead, parent->Res().strLabel, stats.Strength()); + lineHead += lineBreak; + RenderStatsLine(screen, lineHead, parent->Res().aglLabel, stats.Agility()); + lineHead += lineBreak; + RenderStatsLine(screen, lineHead, parent->Res().intLabel, stats.Intelligence()); + lineHead += lineBreak; + RenderStatsLine(screen, lineHead, parent->Res().gutLabel, stats.Gut()); + lineHead += lineBreak; + RenderStatsLine(screen, lineHead, parent->Res().mgrLabel, stats.MagicResistance()); + + lineHead = offset + Vector(18 * font.CharWidth(), 0); + font.DrawStringRight(parent->Res().levelLabel, screen, lineHead); + lineHead += lineBreak; + font.DrawNumberRight(capsule.Level(), screen, lineHead); + lineHead += 2 * lineBreak; + font.DrawStringRight(parent->Res().experienceLabel, screen, lineHead); + lineHead += lineBreak; + font.DrawNumberRight(capsule.Experience(), screen, lineHead); + lineHead += 2 * lineBreak; + font.DrawStringRight(parent->Res().nextLevelLabel, screen, lineHead); + lineHead += lineBreak; + font.DrawNumberRight(capsule.NextLevel(), screen, lineHead); +} + +void CapsuleMenu::RenderStatsLine(SDL_Surface *screen, const geometry::Vector &offset, const char *name, int value) const { + const Font &font(*parent->Res().statusFont); + const Vector numberOffset(4 * font.CharWidth(), 0); + + font.DrawString(name, screen, offset, 4); + font.DrawNumber(value, screen, offset + numberOffset, 3); +} + +void CapsuleMenu::RenderMenu(SDL_Surface *screen, const Vector &offset) const { + const Font &font(*parent->Res().normalFont); + const Frame &frame(*parent->Res().statusFrame); + const Vector menuOffset(3 * font.CharWidth(), font.CharHeight()); + + frame.Draw(screen, offset, 30 * font.CharWidth(), 3 * font.CharHeight()); + menu.Draw(screen, offset + menuOffset); +} + int CapsuleMenu::Width() const { return parent->Width(); } diff --git a/src/menu/CapsuleMenu.h b/src/menu/CapsuleMenu.h index ad20b25..ce57bd2 100644 --- a/src/menu/CapsuleMenu.h +++ b/src/menu/CapsuleMenu.h @@ -35,6 +35,12 @@ private: const common::Capsule &GetCapsule() const; void RenderBackground(SDL_Surface *screen) const; + void RenderCapsule(SDL_Surface *screen, const geometry::Vector &offset) const; + void RenderInfo(SDL_Surface *screen, const geometry::Vector &offset) const; + void RenderWheel(SDL_Surface *screen, const geometry::Vector &offset) const; + void RenderStats(SDL_Surface *screen, const geometry::Vector &offset) const; + void RenderStatsLine(SDL_Surface *screen, const geometry::Vector &offset, const char *name, int value) const; + void RenderMenu(SDL_Surface *screen, const geometry::Vector &offset) const; private: PartyMenu *parent; diff --git a/src/menu/Resources.cpp b/src/menu/Resources.cpp index 9b725d0..f625e67 100644 --- a/src/menu/Resources.cpp +++ b/src/menu/Resources.cpp @@ -56,7 +56,9 @@ Resources::Resources() , gutLabel(0) , mgrLabel(0) +, hpLabel(0) , ipLabel(0) +, levelLabel(0) , experienceLabel(0) , nextLevelLabel(0) @@ -111,6 +113,7 @@ Resources::Resources() , capsuleAttack1Label(0) , capsuleAttack2Label(0) , capsuleAttack3Label(0) +, capsuleNoAttackText(0) { } @@ -159,7 +162,9 @@ void Resources::CreateTypeDescription() { td.AddField("gutLabel", FieldDescription(((char *)&r.gutLabel) - ((char *)&r), Interpreter::STRING_ID).SetReferenced()); td.AddField("mgrLabel", FieldDescription(((char *)&r.mgrLabel) - ((char *)&r), Interpreter::STRING_ID).SetReferenced()); + td.AddField("hpLabel", FieldDescription(((char *)&r.hpLabel) - ((char *)&r), Interpreter::STRING_ID).SetReferenced()); td.AddField("ipLabel", FieldDescription(((char *)&r.ipLabel) - ((char *)&r), Interpreter::STRING_ID).SetReferenced()); + td.AddField("levelLabel", FieldDescription(((char *)&r.levelLabel) - ((char *)&r), Interpreter::STRING_ID).SetReferenced()); td.AddField("experienceLabel", FieldDescription(((char *)&r.experienceLabel) - ((char *)&r), Interpreter::STRING_ID).SetReferenced()); td.AddField("nextLevelLabel", FieldDescription(((char *)&r.nextLevelLabel) - ((char *)&r), Interpreter::STRING_ID).SetReferenced()); @@ -213,6 +218,7 @@ void Resources::CreateTypeDescription() { td.AddField("capsuleAttack1Label", FieldDescription(((char *)&r.capsuleAttack1Label) - ((char *)&r), Interpreter::STRING_ID).SetReferenced()); td.AddField("capsuleAttack2Label", FieldDescription(((char *)&r.capsuleAttack2Label) - ((char *)&r), Interpreter::STRING_ID).SetReferenced()); td.AddField("capsuleAttack3Label", FieldDescription(((char *)&r.capsuleAttack3Label) - ((char *)&r), Interpreter::STRING_ID).SetReferenced()); + td.AddField("capsuleNoAttackText", FieldDescription(((char *)&r.capsuleNoAttackText) - ((char *)&r), Interpreter::STRING_ID).SetReferenced()); } void Resources::Construct(void *data) { diff --git a/src/menu/Resources.h b/src/menu/Resources.h index 47e4625..5b581e6 100644 --- a/src/menu/Resources.h +++ b/src/menu/Resources.h @@ -46,7 +46,9 @@ struct Resources { const char *gutLabel; const char *mgrLabel; + const char *hpLabel; const char *ipLabel; + const char *levelLabel; const char *experienceLabel; const char *nextLevelLabel; @@ -101,6 +103,7 @@ struct Resources { const char *capsuleAttack1Label; const char *capsuleAttack2Label; const char *capsuleAttack3Label; + const char *capsuleNoAttackText; Resources(); diff --git a/test-data/test.l2s b/test-data/test.l2s index 0d76b42..2ea517a 100644 --- a/test-data/test.l2s +++ b/test-data/test.l2s @@ -729,7 +729,9 @@ export MenuResources menuResources { intLabel: "INT", gutLabel: "GUT", mgrLabel: "MGR", + hpLabel: "HP", ipLabel: "IP", + levelLabel: "LEVEL", experienceLabel: "NOW EXP", nextLevelLabel: "NEXT LEVEL", statusMenu: MenuProperties { @@ -845,7 +847,12 @@ export MenuResources menuResources { }, capsuleMenu: MenuProperties { cols: 3, - rows: 1 + rows: 1, + charsPerEntry: 7, + cursor: menuCursor, + selectedCursor: menuActiveCursor, + font: menuFont, + thirdColumnHack: 2 }, capsuleFeedLabel: "FEED", capsuleChangeLabel: "CHANGE", @@ -855,5 +862,6 @@ export MenuResources menuResources { capsuleTribeLabel: "TRIBE", capsuleAttack1Label: "SP.1", capsuleAttack2Label: "SP.2", - capsuleAttack3Label: "SP.3" + capsuleAttack3Label: "SP.3", + capsuleNoAttackText: "Nothing" }