#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"
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();
}
}
void CapsuleMenu::Render(SDL_Surface *screen) {
- Vector<int> offset((screen->w - Width()) / 2, (screen->h - Height()) / 2);
+ const Font &font(*parent->Res().statusFont);
+ const Vector<int> offset((screen->w - Width()) / 2, (screen->h - Height()) / 2);
+ const Vector<int> capsuleOffset(
+ 6 * font.CharWidth(),
+ 12 * font.CharHeight());
+ const Vector<int> infoOffset(
+ 12 * font.CharWidth(),
+ 2 * font.CharHeight() - font.CharHeight() / 8);
+ // TODO: wheel offset: top left, center, or center bottom?
+ const Vector<int> wheelOffset;
+ const Vector<int> statsOffset(
+ 12 * font.CharWidth(),
+ 15 * font.CharHeight() - font.CharHeight() / 8);
+ const Vector<int> 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<int>(), Vector<int>(screen->w, screen->h));
}
+void CapsuleMenu::RenderCapsule(SDL_Surface *screen, const Vector<int> &offset) const {
+ GetCapsule().BattleSprite()->DrawCenterBottom(screen, offset);
+}
+
+void CapsuleMenu::RenderInfo(SDL_Surface *screen, const Vector<int> &offset) const {
+ const Capsule &capsule(GetCapsule());
+ const Font &font(*parent->Res().statusFont);
+ const Vector<int> delimiterOffset(5 * font.CharWidth(), 0);
+ const Vector<int> valueOffset(6 * font.CharWidth(), 0);
+ const Vector<int> lineBreak(0, font.CharHeight() + font.CharHeight() / 2);
+ Vector<int> 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<int> &offset) const {
+ // later
+}
+
+void CapsuleMenu::RenderStats(SDL_Surface *screen, const Vector<int> &offset) const {
+ const Capsule &capsule(GetCapsule());
+ Stats stats(capsule.GetStats());
+ const Font &font(*parent->Res().statusFont);
+ const Vector<int> lineBreak(0, font.CharHeight());
+ Vector<int> 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<int>(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<int> &offset, const char *name, int value) const {
+ const Font &font(*parent->Res().statusFont);
+ const Vector<int> 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<int> &offset) const {
+ const Font &font(*parent->Res().normalFont);
+ const Frame &frame(*parent->Res().statusFrame);
+ const Vector<int> 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();
}