Browse Source

Add rudimentary level select menu

master
C. J. Howard 7 years ago
parent
commit
8a1dc02752
4 changed files with 112 additions and 13 deletions
  1. +101
    -11
      src/application.cpp
  2. +2
    -0
      src/application.hpp
  3. +5
    -2
      src/states/game-state.cpp
  4. +4
    -0
      src/states/title-state.cpp

+ 101
- 11
src/application.cpp View File

@ -198,9 +198,6 @@ Application::Application(int argc, char* argv[]):
height = windowedHeight;
}
width = 1920;
height = 1080;
// Get window title string
std::string title;
strings.get("title", &title);
@ -1069,9 +1066,11 @@ bool Application::loadUI()
// Build menu system
activeMenu = nullptr;
previousActiveMenu = nullptr;
// Allocate menus
mainMenu = new Menu();
levelsMenu = new Menu();
optionsMenu = new Menu();
pauseMenu = new Menu();
@ -1091,7 +1090,7 @@ bool Application::loadUI()
newGameItem->setLabel(newGameString);
MenuItem* levelsItem = mainMenu->addItem();
levelsItem->setActivatedCallback(std::bind(&std::printf, "0\n"));
levelsItem->setActivatedCallback(std::bind(&Application::openMenu, this, levelsMenu));
levelsItem->setLabel(levelsString);
MenuItem* sandboxItem = mainMenu->addItem();
@ -1111,6 +1110,59 @@ bool Application::loadUI()
uiRootElement->addChild(mainMenu->getUIContainer());
}
// Levels menu
{
levelsMenu->setFont(menuFont);
levelsMenu->getUIContainer()->setAnchor(Vector2(0.5f, 0.8f));
levelsMenu->getUIContainer()->setLayerOffset(ANTKEEPER_UI_LAYER_MENU);
levelsMenu->setLineSpacing(1.0f);
for (std::size_t world = 0; world < campaign.getWorldCount(); ++world)
{
for (std::size_t level = 0; level < campaign.getLevelCount(world); ++level)
{
// Form level ID string
char levelIDBuffer[6];
std::sprintf(levelIDBuffer, "%02d-%02d", static_cast<int>(world + 1), static_cast<int>(level + 1));
std::string levelID(levelIDBuffer);
// Look up level name
std::string levelName;
strings.get(levelIDBuffer, &levelName);
// Create label
std::string label = levelID + ": " + levelName;
MenuItem* levelItem = levelsMenu->addItem();
levelItem->setActivatedCallback
(
[this, world, level]()
{
closeMenu();
loadWorld(world);
loadLevel(level);
changeState(gameState);
}
);
levelItem->setLabel(label);
}
}
MenuItem* backItem = levelsMenu->addItem();
backItem->setActivatedCallback
(
[this]()
{
openMenu(previousActiveMenu);
}
);
backItem->setLabel(backString);
levelsMenu->getUIContainer()->setActive(false);
levelsMenu->getUIContainer()->setVisible(false);
uiRootElement->addChild(levelsMenu->getUIContainer());
}
// Options menu
{
optionsMenu->setFont(menuFont);
@ -1118,8 +1170,20 @@ bool Application::loadUI()
optionsMenu->getUIContainer()->setLayerOffset(ANTKEEPER_UI_LAYER_MENU);
optionsMenu->setLineSpacing(1.0f);
MenuItem* resolutionItem = optionsMenu->addItem();
resolutionItem->setLabel("Resolution");
MenuItem* fullscreenItem = optionsMenu->addItem();
fullscreenItem->setLabel("Fullscreen");
MenuItem* backItem = optionsMenu->addItem();
backItem->setActivatedCallback(std::bind(&Application::openMenu, this, mainMenu));
backItem->setActivatedCallback
(
[this]()
{
openMenu(previousActiveMenu);
}
);
backItem->setLabel(backString);
optionsMenu->getUIContainer()->setActive(false);
@ -1138,13 +1202,33 @@ bool Application::loadUI()
resumeItem->setActivatedCallback(std::bind(&Application::unpauseSimulation, this));
resumeItem->setLabel("Resume");
MenuItem* levelsItem = pauseMenu->addItem();
levelsItem->setActivatedCallback(std::bind(&Application::openMenu, this, levelsMenu));
levelsItem->setLabel(levelsString);
MenuItem* optionsItem = pauseMenu->addItem();
optionsItem->setActivatedCallback(std::bind(&Application::openMenu, this, optionsMenu));
optionsItem->setLabel(optionsString);
MenuItem* mainMenuItem = pauseMenu->addItem();
mainMenuItem->setActivatedCallback(std::bind(&Application::changeState, this, titleState));
mainMenuItem->setActivatedCallback
(
[this]()
{
// Close pause menu
closeMenu();
// Begin fade-out to title state
fadeOutTween->setEndCallback(std::bind(&Application::changeState, this, titleState));
fadeOutTween->reset();
fadeOutTween->start();
}
);
mainMenuItem->setLabel("Main Menu");
MenuItem* desktopItem = pauseMenu->addItem();
desktopItem->setActivatedCallback(std::bind(&Application::close, this, EXIT_SUCCESS));
desktopItem->setLabel("Exit to Desktop");
MenuItem* exitItem = pauseMenu->addItem();
exitItem->setActivatedCallback(std::bind(&Application::close, this, EXIT_SUCCESS));
exitItem->setLabel(exitString);
pauseMenu->getUIContainer()->setActive(false);
pauseMenu->getUIContainer()->setVisible(false);
@ -1318,6 +1402,7 @@ void Application::closeMenu()
activeMenu->getUIContainer()->setActive(false);
activeMenu->getUIContainer()->setVisible(false);
previousActiveMenu = activeMenu;
activeMenu = nullptr;
}
}
@ -1362,6 +1447,13 @@ void Application::continueGame()
void Application::newGame()
{
// Close main menu
closeMenu();
// Begin title fade-out
titleFadeOutTween->reset();
titleFadeOutTween->start();
if (currentWorldIndex != 0 || currentLevelIndex != 0)
{
// Select first level of the first world
@ -1380,8 +1472,6 @@ void Application::newGame()
}
else
{
closeMenu();
// Begin fade-out
fadeOutTween->setEndCallback(std::bind(&Application::changeState, this, gameState));
fadeOutTween->reset();

+ 2
- 0
src/application.hpp View File

@ -300,7 +300,9 @@ public:
// Menus
Menu* activeMenu;
Menu* previousActiveMenu;
Menu* mainMenu;
Menu* levelsMenu;
Menu* optionsMenu;
Menu* pauseMenu;

+ 5
- 2
src/states/game-state.cpp View File

@ -55,8 +55,8 @@ void GameState::enter()
// Add terrain to scene
application->defaultLayer->addObject(&application->currentLevel->terrainSurface);
application->defaultLayer->addObject(&application->currentLevel->terrainSubsurface);
application->defaultLayer->addObject(&application->biomeFloorModelInstance);
//application->defaultLayer->addObject(&application->currentLevel->terrainSubsurface);
//application->defaultLayer->addObject(&application->biomeFloorModelInstance);
@ -95,6 +95,9 @@ void GameState::enter()
//application->selectTool(application->forceps);
application->pieMenu->select(1);
// Position options menu
application->optionsMenu->getUIContainer()->setAnchor(Vector2(0.5f, 0.5f));
// Begin fade-in
application->fadeInTween->start();

+ 4
- 0
src/states/title-state.cpp View File

@ -56,10 +56,14 @@ void TitleState::enter()
// Show title
application->titleImage->setVisible(true);
application->titleImage->setTintColor(Vector4(1.0f));
// Open main menu
application->openMenu(application->mainMenu);
// Position options menu
application->optionsMenu->getUIContainer()->setAnchor(Vector2(0.5f, 0.8f));
// Setup fade-in
application->blackoutImage->setVisible(true);
application->fadeInTween->start();

Loading…
Cancel
Save