namespace common {
GameState::GameState()
-: money(0) {
+: money(0)
+, time(0) {
party[0] = heroes;
party[1] = 0;
party[2] = 0;
Inventory inventory;
Uint32 money;
+ Uint32 time;
};
menubg.SetSize(Vector<int>(64, 64));
menuResources.menubg = &menubg;
- menuResources.normalFont = gameConfig.battleResources->normalFont;
+ menuResources.statusFont = gameConfig.battleResources->normalFont;
graphics::Sprite statusLabels(IMG_Load("test-data/status-labels.png"), 32, 16);
menuResources.statusLabels = &statusLabels;
graphics::Frame statusFrame(IMG_Load("test-data/status-frame.png"), 32, 32, 32, 32);
menuResources.statusFrame = &statusFrame;
+ graphics::Sprite menuFontSprite(IMG_Load("test-data/menu-font.png"), 16, 16);
+ graphics::Font menuFont(&menuFontSprite, 0, -2);
+
+ menuResources.normalFont = &menuFont;
+
+ graphics::Sprite menuCursor(IMG_Load("test-data/menu-cursor.png"), 32, 16);
+
+ graphics::MenuProperties mainMenuProperties;
+ mainMenuProperties.cols = 2;
+ mainMenuProperties.rows = 4;
+ mainMenuProperties.charsPerEntry = 8;
+ mainMenuProperties.rowGap = 8;
+ mainMenuProperties.colGap = 32;
+ mainMenuProperties.cursor = &menuCursor;
+ mainMenuProperties.font = &menuFont;
+ mainMenuProperties.wrapX = true;
+ mainMenuProperties.wrapY = true;
+ menuResources.mainMenuProperties = &mainMenuProperties;
+
+ menuResources.mainMenuItemText = "ITEM";
+ menuResources.mainMenuSpellText = "SPELL";
+ menuResources.mainMenuCapsuleText = "CAPSULE";
+ menuResources.mainMenuEquipmentText = "EQUIP";
+ menuResources.mainMenuStatusText = "STATUS";
+ menuResources.mainMenuChangeText = "CHANGE";
+ menuResources.mainMenuConfigText = "CONFIG";
+ menuResources.mainMenuScenarioText = "SCENARIO";
+
+ menuResources.mainMenuTimeText = "TIME";
+ menuResources.mainMenuGoldText = "GOLD";
+
InitScreen screen(width, height);
app::State *state(0);
int HeroStatus::Width() const {
- return hero->BattleSprite()->Width() + res->normalFont->CharWidth() * 10;
+ return hero->BattleSprite()->Width() + res->statusFont->CharWidth() * 10;
}
int HeroStatus::Height() const {
// for some reason, fonts are shifted by one pixel in the original
Vector<int> nameOffset(
hero->BattleSprite()->Width(),
- res->normalFont->CharHeight() * 7 / 8);
+ res->statusFont->CharHeight() * 7 / 8);
nameOffset += position + offset;
- res->normalFont->DrawString(hero->Name(), screen, nameOffset, 5);
+ res->statusFont->DrawString(hero->Name(), screen, nameOffset, 5);
- Vector<int> levelLabelOffset(nameOffset.X() + 6 * res->normalFont->CharWidth(), nameOffset.Y());
+ Vector<int> levelLabelOffset(nameOffset.X() + 6 * res->statusFont->CharWidth(), nameOffset.Y());
res->statusLabels->Draw(screen, levelLabelOffset, 0, 0);
- Vector<int> levelOffset(levelLabelOffset.X() + 2 * res->normalFont->CharWidth(), levelLabelOffset.Y());
- res->normalFont->DrawNumber(hero->Level(), screen, levelOffset, 2);
+ Vector<int> levelOffset(levelLabelOffset.X() + 2 * res->statusFont->CharWidth(), levelLabelOffset.Y());
+ res->statusFont->DrawNumber(hero->Level(), screen, levelOffset, 2);
- Vector<int> healthLabelOffset(nameOffset.X(), nameOffset.Y() + res->normalFont->CharHeight());
+ Vector<int> healthLabelOffset(nameOffset.X(), nameOffset.Y() + res->statusFont->CharHeight());
res->statusLabels->Draw(screen, healthLabelOffset, 0, 1);
- Vector<int> healthOffset(nameOffset.X() + 3 * res->normalFont->CharWidth(), nameOffset.Y() + res->normalFont->CharHeight());
- res->normalFont->DrawNumber(hero->Health(), screen, healthOffset, 3);
+ Vector<int> healthOffset(nameOffset.X() + 3 * res->statusFont->CharWidth(), nameOffset.Y() + res->statusFont->CharHeight());
+ res->statusFont->DrawNumber(hero->Health(), screen, healthOffset, 3);
- Vector<int> healthSeparatorOffset(healthOffset.X() + 3 * res->normalFont->CharWidth(), healthOffset.Y());
- res->normalFont->DrawChar('/', screen, healthSeparatorOffset);
+ Vector<int> healthSeparatorOffset(healthOffset.X() + 3 * res->statusFont->CharWidth(), healthOffset.Y());
+ res->statusFont->DrawChar('/', screen, healthSeparatorOffset);
- Vector<int> maxHealthOffset(healthSeparatorOffset.X() + res->normalFont->CharWidth(), healthOffset.Y());
- res->normalFont->DrawNumber(hero->MaxHealth(), screen, maxHealthOffset, 3);
+ Vector<int> maxHealthOffset(healthSeparatorOffset.X() + res->statusFont->CharWidth(), healthOffset.Y());
+ res->statusFont->DrawNumber(hero->MaxHealth(), screen, maxHealthOffset, 3);
- Vector<int> manaLabelOffset(healthLabelOffset.X(), healthLabelOffset.Y() + res->normalFont->CharHeight());
+ Vector<int> manaLabelOffset(healthLabelOffset.X(), healthLabelOffset.Y() + res->statusFont->CharHeight());
res->statusLabels->Draw(screen, manaLabelOffset, 0, 2);
- Vector<int> manaOffset(healthOffset.X(), healthOffset.Y() + res->normalFont->CharHeight());
- res->normalFont->DrawNumber(hero->Mana(), screen, manaOffset, 3);
+ Vector<int> manaOffset(healthOffset.X(), healthOffset.Y() + res->statusFont->CharHeight());
+ res->statusFont->DrawNumber(hero->Mana(), screen, manaOffset, 3);
Vector<int> manaSeparatorOffset(healthSeparatorOffset.X(), manaOffset.Y());
- res->normalFont->DrawChar('/', screen, manaSeparatorOffset);
+ res->statusFont->DrawChar('/', screen, manaSeparatorOffset);
Vector<int> maxManaOffset(maxHealthOffset.X(), manaOffset.Y());
- res->normalFont->DrawNumber(hero->MaxMana(), screen, maxManaOffset, 3);
+ res->statusFont->DrawNumber(hero->MaxMana(), screen, maxManaOffset, 3);
}
}
namespace menu {
PartyMenu::PartyMenu(GameConfig *game)
-: game(game) {
+: game(game)
+, mainMenu(*game->menuResources->mainMenuProperties) {
for (int i(0); i < 4; ++i) {
status[i].SetHero(game->state->party[i]);
status[i].SetResources(game->menuResources);
status[1].SetPosition(Vector<int>(status[0].Width() + Res().normalFont->CharWidth(), 0));
status[2].SetPosition(Vector<int>(0, status[0].Height() + Res().normalFont->CharHeight()));
status[3].SetPosition(Vector<int>(status[0].Width() + Res().normalFont->CharWidth(), status[0].Height() + Res().normalFont->CharHeight()));
+
+ mainMenu.Add(Res().mainMenuItemText, 0);
+ mainMenu.Add(Res().mainMenuStatusText, 4);
+ mainMenu.Add(Res().mainMenuSpellText, 1);
+ mainMenu.Add(Res().mainMenuChangeText, 5);
+ mainMenu.Add(Res().mainMenuCapsuleText, 2);
+ mainMenu.Add(Res().mainMenuConfigText, 6);
+ mainMenu.Add(Res().mainMenuEquipmentText, 3);
+ mainMenu.Add(Res().mainMenuScenarioText, 7);
}
PartyMenu::~PartyMenu() {
Ctrl().PopState();
return;
}
+
+ if (input.JustPressed(Input::PAD_UP)) {
+ mainMenu.PreviousRow();
+ } else if (input.JustPressed(Input::PAD_RIGHT)) {
+ mainMenu.NextItem();
+ } else if (input.JustPressed(Input::PAD_DOWN)) {
+ mainMenu.NextRow();
+ } else if (input.JustPressed(Input::PAD_LEFT)) {
+ mainMenu.PreviousItem();
+ }
}
void PartyMenu::UpdateWorld(float deltaT) {
RenderInfo(screen, Vector<int>(14 * Res().normalFont->CharWidth(), 21 * Res().normalFont->CharHeight() + Res().normalFont->CharHeight() / 8));
}
-void PartyMenu::RenderHeros(SDL_Surface *screen, const geometry::Vector<int> &offset) const {
+void PartyMenu::RenderHeros(SDL_Surface *screen, const Vector<int> &offset) const {
for (int i(0); i < 4; ++i) {
status[i].Render(screen, offset);
}
}
-void PartyMenu::RenderMenu(SDL_Surface *screen, const geometry::Vector<int> &offset) const {
+void PartyMenu::RenderMenu(SDL_Surface *screen, const Vector<int> &offset) const {
+ Vector<int> menuOffset(3 * Res().normalFont->CharWidth(), Res().normalFont->CharHeight() + Res().normalFont->CharHeight() / 4);
+
Res().statusFrame->Draw(screen, offset, 23 * Res().normalFont->CharWidth(), 8 * Res().normalFont->CharHeight());
+ mainMenu.Draw(screen, offset + menuOffset);
}
-void PartyMenu::RenderInfo(SDL_Surface *screen, const geometry::Vector<int> &offset) const {
+void PartyMenu::RenderInfo(SDL_Surface *screen, const Vector<int> &offset) const {
Res().statusFrame->Draw(screen, offset, 17 * Res().normalFont->CharWidth(), 5 * Res().normalFont->CharHeight());
+
+ Vector<int> timeLabelOffset(2 * Res().normalFont->CharWidth(), Res().normalFont->CharHeight() + Res().normalFont->CharHeight() / 4);
+ Res().normalFont->DrawString(Res().mainMenuTimeText, screen, offset + timeLabelOffset);
+
+ Vector<int> hoursOffset(timeLabelOffset.X() + 6 * Res().normalFont->CharWidth(), timeLabelOffset.Y());
+ Res().normalFont->DrawNumber(game->state->time / 60 / 60, screen, offset + hoursOffset, 4);
+
+ Vector<int> timeSeparatorOffset(hoursOffset.X() + 4 * Res().normalFont->CharWidth(), hoursOffset.Y());
+ Res().normalFont->DrawChar(':', screen, offset + timeSeparatorOffset);
+
+ Vector<int> minutesOffset(timeSeparatorOffset.X() + Res().normalFont->CharWidth(), timeSeparatorOffset.Y());
+ Res().normalFont->DrawNumber(game->state->time / 60, screen, offset + minutesOffset, 2);
+ if (game->state->time / 60 < 10) {
+ Res().normalFont->DrawChar('0', screen, offset + minutesOffset);
+ }
+
+ Vector<int> goldLabelOffset(2 * Res().normalFont->CharWidth(), 2 * Res().normalFont->CharHeight() + Res().normalFont->CharHeight() * 3 / 4);
+ Res().normalFont->DrawString(Res().mainMenuGoldText, screen, offset + goldLabelOffset);
+
+ Vector<int> goldOffset(goldLabelOffset.X() + 6 * Res().normalFont->CharWidth(), goldLabelOffset.Y());
+ Res().normalFont->DrawNumber(game->state->money, screen, offset + goldOffset, 7);
}
#include "../app/State.h"
#include "../common/fwd.h"
#include "../geometry/Vector.h"
+#include "../graphics/Menu.h"
namespace menu {
private:
HeroStatus status[4];
common::GameConfig *game;
+ graphics::Menu<int> mainMenu;
};
graphics::Texture *menubg;
graphics::Font *normalFont;
+ graphics::Font *statusFont;
graphics::Sprite *statusLabels;
-
graphics::Frame *statusFrame;
+ graphics::MenuProperties *mainMenuProperties;
+ const char *mainMenuItemText;
+ const char *mainMenuSpellText;
+ const char *mainMenuCapsuleText;
+ const char *mainMenuEquipmentText;
+ const char *mainMenuStatusText;
+ const char *mainMenuChangeText;
+ const char *mainMenuConfigText;
+ const char *mainMenuScenarioText;
+
+ const char *mainMenuTimeText;
+ const char *mainMenuGoldText;
+
Resources();
};