From: Daniel Karbach Date: Sun, 21 Oct 2012 19:45:06 +0000 (+0200) Subject: added party main menu stub X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;h=aedf4ae020e3c811341df79ceae63ca56fb7ce83;p=l2e.git added party main menu stub --- diff --git a/src/common/GameState.cpp b/src/common/GameState.cpp index 7992d43..91e8d4a 100644 --- a/src/common/GameState.cpp +++ b/src/common/GameState.cpp @@ -10,7 +10,8 @@ namespace common { GameState::GameState() -: money(0) { +: money(0) +, time(0) { party[0] = heroes; party[1] = 0; party[2] = 0; diff --git a/src/common/GameState.h b/src/common/GameState.h index fca50c1..0ef442b 100644 --- a/src/common/GameState.h +++ b/src/common/GameState.h @@ -25,6 +25,7 @@ struct GameState { Inventory inventory; Uint32 money; + Uint32 time; }; diff --git a/src/main.cpp b/src/main.cpp index 075ce1e..8fcb09e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -279,7 +279,7 @@ int main(int argc, char **argv) { menubg.SetSize(Vector(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; @@ -287,6 +287,37 @@ int main(int argc, char **argv) { 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); diff --git a/src/menu/HeroStatus.cpp b/src/menu/HeroStatus.cpp index e84327e..6f8b341 100644 --- a/src/menu/HeroStatus.cpp +++ b/src/menu/HeroStatus.cpp @@ -28,7 +28,7 @@ HeroStatus::~HeroStatus() { int HeroStatus::Width() const { - return hero->BattleSprite()->Width() + res->normalFont->CharWidth() * 10; + return hero->BattleSprite()->Width() + res->statusFont->CharWidth() * 10; } int HeroStatus::Height() const { @@ -44,39 +44,39 @@ void HeroStatus::Render(SDL_Surface *screen, const Vector &offset) const { // for some reason, fonts are shifted by one pixel in the original Vector 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 levelLabelOffset(nameOffset.X() + 6 * res->normalFont->CharWidth(), nameOffset.Y()); + Vector levelLabelOffset(nameOffset.X() + 6 * res->statusFont->CharWidth(), nameOffset.Y()); res->statusLabels->Draw(screen, levelLabelOffset, 0, 0); - Vector levelOffset(levelLabelOffset.X() + 2 * res->normalFont->CharWidth(), levelLabelOffset.Y()); - res->normalFont->DrawNumber(hero->Level(), screen, levelOffset, 2); + Vector levelOffset(levelLabelOffset.X() + 2 * res->statusFont->CharWidth(), levelLabelOffset.Y()); + res->statusFont->DrawNumber(hero->Level(), screen, levelOffset, 2); - Vector healthLabelOffset(nameOffset.X(), nameOffset.Y() + res->normalFont->CharHeight()); + Vector healthLabelOffset(nameOffset.X(), nameOffset.Y() + res->statusFont->CharHeight()); res->statusLabels->Draw(screen, healthLabelOffset, 0, 1); - Vector healthOffset(nameOffset.X() + 3 * res->normalFont->CharWidth(), nameOffset.Y() + res->normalFont->CharHeight()); - res->normalFont->DrawNumber(hero->Health(), screen, healthOffset, 3); + Vector healthOffset(nameOffset.X() + 3 * res->statusFont->CharWidth(), nameOffset.Y() + res->statusFont->CharHeight()); + res->statusFont->DrawNumber(hero->Health(), screen, healthOffset, 3); - Vector healthSeparatorOffset(healthOffset.X() + 3 * res->normalFont->CharWidth(), healthOffset.Y()); - res->normalFont->DrawChar('/', screen, healthSeparatorOffset); + Vector healthSeparatorOffset(healthOffset.X() + 3 * res->statusFont->CharWidth(), healthOffset.Y()); + res->statusFont->DrawChar('/', screen, healthSeparatorOffset); - Vector maxHealthOffset(healthSeparatorOffset.X() + res->normalFont->CharWidth(), healthOffset.Y()); - res->normalFont->DrawNumber(hero->MaxHealth(), screen, maxHealthOffset, 3); + Vector maxHealthOffset(healthSeparatorOffset.X() + res->statusFont->CharWidth(), healthOffset.Y()); + res->statusFont->DrawNumber(hero->MaxHealth(), screen, maxHealthOffset, 3); - Vector manaLabelOffset(healthLabelOffset.X(), healthLabelOffset.Y() + res->normalFont->CharHeight()); + Vector manaLabelOffset(healthLabelOffset.X(), healthLabelOffset.Y() + res->statusFont->CharHeight()); res->statusLabels->Draw(screen, manaLabelOffset, 0, 2); - Vector manaOffset(healthOffset.X(), healthOffset.Y() + res->normalFont->CharHeight()); - res->normalFont->DrawNumber(hero->Mana(), screen, manaOffset, 3); + Vector manaOffset(healthOffset.X(), healthOffset.Y() + res->statusFont->CharHeight()); + res->statusFont->DrawNumber(hero->Mana(), screen, manaOffset, 3); Vector manaSeparatorOffset(healthSeparatorOffset.X(), manaOffset.Y()); - res->normalFont->DrawChar('/', screen, manaSeparatorOffset); + res->statusFont->DrawChar('/', screen, manaSeparatorOffset); Vector maxManaOffset(maxHealthOffset.X(), manaOffset.Y()); - res->normalFont->DrawNumber(hero->MaxMana(), screen, maxManaOffset, 3); + res->statusFont->DrawNumber(hero->MaxMana(), screen, maxManaOffset, 3); } } diff --git a/src/menu/PartyMenu.cpp b/src/menu/PartyMenu.cpp index 4949bfa..5a68ca4 100644 --- a/src/menu/PartyMenu.cpp +++ b/src/menu/PartyMenu.cpp @@ -24,7 +24,8 @@ using geometry::Vector; 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); @@ -32,6 +33,15 @@ PartyMenu::PartyMenu(GameConfig *game) status[1].SetPosition(Vector(status[0].Width() + Res().normalFont->CharWidth(), 0)); status[2].SetPosition(Vector(0, status[0].Height() + Res().normalFont->CharHeight())); status[3].SetPosition(Vector(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() { @@ -66,6 +76,16 @@ void PartyMenu::HandleEvents(const Input &input) { 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) { @@ -79,18 +99,42 @@ void PartyMenu::Render(SDL_Surface *screen) { RenderInfo(screen, Vector(14 * Res().normalFont->CharWidth(), 21 * Res().normalFont->CharHeight() + Res().normalFont->CharHeight() / 8)); } -void PartyMenu::RenderHeros(SDL_Surface *screen, const geometry::Vector &offset) const { +void PartyMenu::RenderHeros(SDL_Surface *screen, const Vector &offset) const { for (int i(0); i < 4; ++i) { status[i].Render(screen, offset); } } -void PartyMenu::RenderMenu(SDL_Surface *screen, const geometry::Vector &offset) const { +void PartyMenu::RenderMenu(SDL_Surface *screen, const Vector &offset) const { + Vector 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 &offset) const { +void PartyMenu::RenderInfo(SDL_Surface *screen, const Vector &offset) const { Res().statusFrame->Draw(screen, offset, 17 * Res().normalFont->CharWidth(), 5 * Res().normalFont->CharHeight()); + + Vector timeLabelOffset(2 * Res().normalFont->CharWidth(), Res().normalFont->CharHeight() + Res().normalFont->CharHeight() / 4); + Res().normalFont->DrawString(Res().mainMenuTimeText, screen, offset + timeLabelOffset); + + Vector hoursOffset(timeLabelOffset.X() + 6 * Res().normalFont->CharWidth(), timeLabelOffset.Y()); + Res().normalFont->DrawNumber(game->state->time / 60 / 60, screen, offset + hoursOffset, 4); + + Vector timeSeparatorOffset(hoursOffset.X() + 4 * Res().normalFont->CharWidth(), hoursOffset.Y()); + Res().normalFont->DrawChar(':', screen, offset + timeSeparatorOffset); + + Vector 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 goldLabelOffset(2 * Res().normalFont->CharWidth(), 2 * Res().normalFont->CharHeight() + Res().normalFont->CharHeight() * 3 / 4); + Res().normalFont->DrawString(Res().mainMenuGoldText, screen, offset + goldLabelOffset); + + Vector goldOffset(goldLabelOffset.X() + 6 * Res().normalFont->CharWidth(), goldLabelOffset.Y()); + Res().normalFont->DrawNumber(game->state->money, screen, offset + goldOffset, 7); } diff --git a/src/menu/PartyMenu.h b/src/menu/PartyMenu.h index aabc206..5baaf69 100644 --- a/src/menu/PartyMenu.h +++ b/src/menu/PartyMenu.h @@ -13,6 +13,7 @@ #include "../app/State.h" #include "../common/fwd.h" #include "../geometry/Vector.h" +#include "../graphics/Menu.h" namespace menu { @@ -47,6 +48,7 @@ private: private: HeroStatus status[4]; common::GameConfig *game; + graphics::Menu mainMenu; }; diff --git a/src/menu/Resources.h b/src/menu/Resources.h index c65a7cb..6472d3c 100644 --- a/src/menu/Resources.h +++ b/src/menu/Resources.h @@ -17,11 +17,24 @@ struct Resources { 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(); }; diff --git a/test-data/menu-cursor.png b/test-data/menu-cursor.png new file mode 100644 index 0000000..b5743f1 Binary files /dev/null and b/test-data/menu-cursor.png differ diff --git a/test-data/menu-font.png b/test-data/menu-font.png new file mode 100644 index 0000000..a8122a8 Binary files /dev/null and b/test-data/menu-font.png differ