added menu
This commit is contained in:
parent
8e0936836e
commit
9d4da63e36
33
resources/config2/about.json
Normal file
33
resources/config2/about.json
Normal file
@ -0,0 +1,33 @@
|
||||
{
|
||||
"root": {
|
||||
"type": "LinearLayout",
|
||||
"orientation": "vertical",
|
||||
"horizontal_align": "center",
|
||||
"vertical_align": "center",
|
||||
"spacing": 30,
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"width": "match_parent",
|
||||
"height": "match_parent",
|
||||
"children": [
|
||||
{
|
||||
"type": "StaticImage",
|
||||
"name": "aboutImage",
|
||||
"width": 400,
|
||||
"height": 300,
|
||||
"texture": "resources/loading.png"
|
||||
},
|
||||
{
|
||||
"type": "Button",
|
||||
"name": "backButton",
|
||||
"width": 200,
|
||||
"height": 60,
|
||||
"textures": {
|
||||
"normal": "resources/loading.png",
|
||||
"hover": "resources/loading.png",
|
||||
"pressed": "resources/loading.png"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
33
resources/config2/help.json
Normal file
33
resources/config2/help.json
Normal file
@ -0,0 +1,33 @@
|
||||
{
|
||||
"root": {
|
||||
"type": "LinearLayout",
|
||||
"orientation": "vertical",
|
||||
"horizontal_align": "center",
|
||||
"vertical_align": "center",
|
||||
"spacing": 30,
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"width": "match_parent",
|
||||
"height": "match_parent",
|
||||
"children": [
|
||||
{
|
||||
"type": "StaticImage",
|
||||
"name": "helpImage",
|
||||
"width": 400,
|
||||
"height": 300,
|
||||
"texture": "resources/loading.png"
|
||||
},
|
||||
{
|
||||
"type": "Button",
|
||||
"name": "backButton",
|
||||
"width": 200,
|
||||
"height": 60,
|
||||
"textures": {
|
||||
"normal": "resources/loading.png",
|
||||
"hover": "resources/loading.png",
|
||||
"pressed": "resources/loading.png"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
55
resources/config2/main_menu.json
Normal file
55
resources/config2/main_menu.json
Normal file
@ -0,0 +1,55 @@
|
||||
{
|
||||
"root": {
|
||||
"type": "LinearLayout",
|
||||
"orientation": "vertical",
|
||||
"horizontal_align": "center",
|
||||
"vertical_align": "center",
|
||||
"spacing": 20,
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"width": "match_parent",
|
||||
"height": "match_parent",
|
||||
"children": [
|
||||
{
|
||||
"type": "StaticImage",
|
||||
"name": "title",
|
||||
"width": 300,
|
||||
"height": 100,
|
||||
"texture": "resources/loading.png"
|
||||
},
|
||||
{
|
||||
"type": "Button",
|
||||
"name": "startButton",
|
||||
"width": 300,
|
||||
"height": 60,
|
||||
"textures": {
|
||||
"normal": "resources/loading.png",
|
||||
"hover": "resources/loading.png",
|
||||
"pressed": "resources/loading.png"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "Button",
|
||||
"name": "helpButton",
|
||||
"width": 300,
|
||||
"height": 60,
|
||||
"textures": {
|
||||
"normal": "resources/loading.png",
|
||||
"hover": "resources/loading.png",
|
||||
"pressed": "resources/loading.png"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "Button",
|
||||
"name": "aboutButton",
|
||||
"width": 300,
|
||||
"height": 60,
|
||||
"textures": {
|
||||
"normal": "resources/loading.png",
|
||||
"hover": "resources/loading.png",
|
||||
"pressed": "resources/loading.png"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
@ -113,7 +113,6 @@
|
||||
[1, -5.5],
|
||||
[-0.2, -5.5]
|
||||
]
|
||||
},
|
||||
},
|
||||
{
|
||||
"name": "main_corridor10x",
|
||||
|
||||
77
src/Game.cpp
77
src/Game.cpp
@ -222,6 +222,9 @@ namespace ZL
|
||||
std::cout << "Audio initialization failed" << std::endl;
|
||||
}
|
||||
|
||||
menuManager.setupMainMenu();
|
||||
|
||||
SDL_ShowCursor(SDL_ENABLE);
|
||||
}
|
||||
|
||||
void Game::drawUI()
|
||||
@ -235,7 +238,22 @@ namespace ZL
|
||||
renderer.RenderUniform1i(textureUniformName, 0);
|
||||
glEnable(GL_BLEND);
|
||||
|
||||
if (menuManager.getState() == GameState::MainMenu ||
|
||||
menuManager.getState() == GameState::HelpScreen ||
|
||||
menuManager.getState() == GameState::AboutMenu)
|
||||
{
|
||||
SDL_ShowCursor(SDL_ENABLE);
|
||||
}
|
||||
else if (menuManager.getState() == GameState::Gameplay)
|
||||
{
|
||||
SDL_ShowCursor(SDL_DISABLE);
|
||||
}
|
||||
|
||||
if (menuManager.getState() != GameState::Gameplay)
|
||||
{
|
||||
menuManager.uiManager.draw(renderer);
|
||||
}
|
||||
|
||||
if (currentLocation)
|
||||
{
|
||||
currentLocation->dialogueSystem.draw(renderer);
|
||||
@ -252,32 +270,28 @@ namespace ZL
|
||||
|
||||
void Game::drawScene() {
|
||||
glViewport(0, 0, Environment::width, Environment::height);
|
||||
|
||||
if (!loadingCompleted) {
|
||||
drawLoading();
|
||||
return;
|
||||
}
|
||||
else
|
||||
|
||||
if (menuManager.getState() == GameState::MainMenu ||
|
||||
menuManager.getState() == GameState::HelpScreen ||
|
||||
menuManager.getState() == GameState::AboutMenu)
|
||||
{
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
drawUI();
|
||||
return;
|
||||
}
|
||||
|
||||
if (currentLocation)
|
||||
{
|
||||
/*
|
||||
if (currentLocation->shadowMap) {
|
||||
CheckGlError(__FILE__, __LINE__);
|
||||
currentLocation->drawShadowDepthPass();
|
||||
CheckGlError(__FILE__, __LINE__);
|
||||
currentLocation->drawGameWithShadows();
|
||||
CheckGlError(__FILE__, __LINE__);
|
||||
}
|
||||
else {*/
|
||||
currentLocation->drawGame();
|
||||
CheckGlError(__FILE__, __LINE__);
|
||||
//}
|
||||
}
|
||||
else
|
||||
{
|
||||
// ??? Main menu???
|
||||
}
|
||||
|
||||
drawUI();
|
||||
}
|
||||
CheckGlError(__FILE__, __LINE__);
|
||||
}
|
||||
|
||||
@ -376,7 +390,11 @@ namespace ZL
|
||||
}
|
||||
|
||||
if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_FOCUS_GAINED) {
|
||||
if (menuManager.getState() == GameState::Gameplay) {
|
||||
SDL_SetRelativeMouseMode(SDL_TRUE);
|
||||
} else {
|
||||
SDL_SetRelativeMouseMode(SDL_FALSE);
|
||||
}
|
||||
}
|
||||
if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_FOCUS_LOST) {
|
||||
SDL_SetRelativeMouseMode(SDL_FALSE);
|
||||
@ -435,8 +453,9 @@ namespace ZL
|
||||
std::cout << "\n========== MOUSE DOWN EVENT ==========" << std::endl;
|
||||
handleDown(ZL::UiManager::MOUSE_FINGER_ID, mx, my);
|
||||
|
||||
if (menuManager.uiManager.isUiInteractionForFinger(ZL::UiManager::MOUSE_FINGER_ID)) {
|
||||
std::cout << "[CLICK] UI handled, skipping character movement" << std::endl;
|
||||
if (menuManager.getState() != GameState::Gameplay ||
|
||||
menuManager.uiManager.isUiInteractionForFinger(ZL::UiManager::MOUSE_FINGER_ID)) {
|
||||
std::cout << "[CLICK] UI handled or in menu, skipping game logic" << std::endl;
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -450,6 +469,8 @@ namespace ZL
|
||||
}
|
||||
}
|
||||
else if (event.button.button == SDL_BUTTON_RIGHT) {
|
||||
if (menuManager.getState() == GameState::Gameplay)
|
||||
{
|
||||
if (event.type == SDL_MOUSEBUTTONDOWN) {
|
||||
rightMouseDown = true;
|
||||
lastMouseX = event.button.x;
|
||||
@ -470,17 +491,20 @@ namespace ZL
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (event.type == SDL_MOUSEMOTION) {
|
||||
int mx = static_cast<int>((float)event.motion.x / Environment::width * Environment::projectionWidth);
|
||||
int my = static_cast<int>((float)event.motion.y / Environment::height * Environment::projectionHeight);
|
||||
handleMotion(ZL::UiManager::MOUSE_FINGER_ID, mx, my);
|
||||
if (currentLocation)
|
||||
|
||||
if (menuManager.getState() == GameState::Gameplay && currentLocation)
|
||||
{
|
||||
currentLocation->handleMotion(ZL::UiManager::MOUSE_FINGER_ID, event.motion.xrel, event.motion.yrel, mx, my);
|
||||
}
|
||||
}
|
||||
|
||||
if (event.type == SDL_MOUSEWHEEL) {
|
||||
if (menuManager.getState() == GameState::Gameplay) {
|
||||
static const float zoomstep = 2.0f;
|
||||
if (event.wheel.y > 0) {
|
||||
Environment::zoom -= zoomstep;
|
||||
@ -492,6 +516,7 @@ namespace ZL
|
||||
Environment::zoom = zoomstep;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (event.type == SDL_KEYDOWN && event.key.repeat == 0) {
|
||||
switch (event.key.keysym.sym) {
|
||||
@ -506,21 +531,25 @@ namespace ZL
|
||||
break;
|
||||
case SDLK_c:
|
||||
{
|
||||
if (menuManager.getState() == GameState::Gameplay) {
|
||||
std::cout << "[GAME] Location change triggered by key press" << std::endl;
|
||||
static size_t locIndex = 0;
|
||||
static std::vector<std::string> locations = {"forest", "default"};
|
||||
locIndex = (locIndex + 1) % locations.size();
|
||||
changeLocation(locations[locIndex]);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case SDLK_f:
|
||||
currentLocation->dialogueSystem.startDialogue("dialogue_gas1");
|
||||
if (currentLocation) currentLocation->dialogueSystem.startDialogue("dialogue_gas1");
|
||||
break;
|
||||
|
||||
case SDLK_e:
|
||||
//currentLocation->dialogueSystem.startDialogue("test_cutscene_pan_dialogue");
|
||||
if (currentLocation) {
|
||||
currentLocation->navigation.build({}, "resources/config2/navigation2.json", CONST_ZIP_FILE);
|
||||
currentLocation->buildDebugNavMeshes();
|
||||
}
|
||||
break;
|
||||
|
||||
case SDLK_p:
|
||||
@ -538,7 +567,9 @@ namespace ZL
|
||||
case SDLK_d:
|
||||
case SDLK_u:
|
||||
case SDLK_i:
|
||||
if (currentLocation) currentLocation->handleKeyDown(event.key.keysym.sym);
|
||||
if (menuManager.getState() == GameState::Gameplay && currentLocation) {
|
||||
currentLocation->handleKeyDown(event.key.keysym.sym);
|
||||
}
|
||||
break;
|
||||
|
||||
case SDLK_RETURN:
|
||||
@ -575,7 +606,9 @@ namespace ZL
|
||||
case SDLK_a:
|
||||
case SDLK_d:
|
||||
case SDLK_i:
|
||||
if (currentLocation) currentLocation->handleKeyUp(event.key.keysym.sym);
|
||||
if (menuManager.getState() == GameState::Gameplay && currentLocation) {
|
||||
currentLocation->handleKeyUp(event.key.keysym.sym);
|
||||
}
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
|
||||
@ -15,6 +15,64 @@ namespace ZL {
|
||||
{
|
||||
}
|
||||
|
||||
void MenuManager::setupMainMenu()
|
||||
{
|
||||
currentState = GameState::MainMenu;
|
||||
uiManager.loadFromFile("resources/config2/main_menu.json", renderer, CONST_ZIP_FILE);
|
||||
|
||||
uiManager.setButtonCallback("startButton", [this](const std::string&) {
|
||||
startGame();
|
||||
});
|
||||
|
||||
uiManager.setButtonCallback("helpButton", [this](const std::string&) {
|
||||
enterHelpMenu();
|
||||
});
|
||||
|
||||
uiManager.setButtonCallback("aboutButton", [this](const std::string&) {
|
||||
enterAboutMenu();
|
||||
});
|
||||
}
|
||||
|
||||
void MenuManager::setupHelpMenu()
|
||||
{
|
||||
currentState = GameState::HelpScreen;
|
||||
uiManager.loadFromFile("resources/config2/help.json", renderer, CONST_ZIP_FILE);
|
||||
|
||||
uiManager.setButtonCallback("backButton", [this](const std::string&) {
|
||||
enterMainMenu();
|
||||
});
|
||||
}
|
||||
|
||||
void MenuManager::setupAboutMenu()
|
||||
{
|
||||
currentState = GameState::AboutMenu;
|
||||
uiManager.loadFromFile("resources/config2/about.json", renderer, CONST_ZIP_FILE);
|
||||
|
||||
uiManager.setButtonCallback("backButton", [this](const std::string&) {
|
||||
enterMainMenu();
|
||||
});
|
||||
}
|
||||
|
||||
void MenuManager::enterMainMenu()
|
||||
{
|
||||
setupMainMenu();
|
||||
}
|
||||
|
||||
void MenuManager::enterHelpMenu()
|
||||
{
|
||||
setupHelpMenu();
|
||||
}
|
||||
|
||||
void MenuManager::enterAboutMenu()
|
||||
{
|
||||
setupAboutMenu();
|
||||
}
|
||||
|
||||
void MenuManager::startGame()
|
||||
{
|
||||
currentState = GameState::Gameplay;
|
||||
}
|
||||
|
||||
/*
|
||||
void MenuManager::setupMenu()
|
||||
{
|
||||
|
||||
@ -56,10 +56,19 @@ namespace ZL {
|
||||
*/
|
||||
public:
|
||||
UiManager uiManager;
|
||||
GameState currentState = GameState::MainMenu;
|
||||
|
||||
MenuManager(Renderer& iRenderer);
|
||||
|
||||
//void setupMenu();
|
||||
void setupMainMenu();
|
||||
void setupHelpMenu();
|
||||
void setupAboutMenu();
|
||||
void enterMainMenu();
|
||||
void enterHelpMenu();
|
||||
void enterAboutMenu();
|
||||
void startGame();
|
||||
|
||||
GameState getState() const { return currentState; }
|
||||
|
||||
/*
|
||||
// Returns true for states where Space should render and run (Gameplay, GameOver, ConnectionLost)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user