added menu

This commit is contained in:
Vlad 2026-04-19 13:46:44 +06:00
parent 8e0936836e
commit 9d4da63e36
7 changed files with 282 additions and 62 deletions

View 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"
}
}
]
}
}

View 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"
}
}
]
}
}

View 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"
}
}
]
}
}

View File

@ -114,7 +114,6 @@
[-0.2, -5.5] [-0.2, -5.5]
] ]
}, },
},
{ {
"name": "main_corridor10x", "name": "main_corridor10x",
"available": true, "available": true,

View File

@ -222,6 +222,9 @@ namespace ZL
std::cout << "Audio initialization failed" << std::endl; std::cout << "Audio initialization failed" << std::endl;
} }
menuManager.setupMainMenu();
SDL_ShowCursor(SDL_ENABLE);
} }
void Game::drawUI() void Game::drawUI()
@ -235,7 +238,22 @@ namespace ZL
renderer.RenderUniform1i(textureUniformName, 0); renderer.RenderUniform1i(textureUniformName, 0);
glEnable(GL_BLEND); glEnable(GL_BLEND);
menuManager.uiManager.draw(renderer); 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) if (currentLocation)
{ {
currentLocation->dialogueSystem.draw(renderer); currentLocation->dialogueSystem.draw(renderer);
@ -252,32 +270,28 @@ namespace ZL
void Game::drawScene() { void Game::drawScene() {
glViewport(0, 0, Environment::width, Environment::height); glViewport(0, 0, Environment::width, Environment::height);
if (!loadingCompleted) { if (!loadingCompleted) {
drawLoading(); drawLoading();
return;
} }
else
if (menuManager.getState() == GameState::MainMenu ||
menuManager.getState() == GameState::HelpScreen ||
menuManager.getState() == GameState::AboutMenu)
{ {
if (currentLocation) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
{
/*
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(); drawUI();
return;
} }
if (currentLocation)
{
currentLocation->drawGame();
CheckGlError(__FILE__, __LINE__);
}
drawUI();
CheckGlError(__FILE__, __LINE__); CheckGlError(__FILE__, __LINE__);
} }
@ -376,7 +390,11 @@ namespace ZL
} }
if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_FOCUS_GAINED) { if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_FOCUS_GAINED) {
SDL_SetRelativeMouseMode(SDL_TRUE); 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) { if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_FOCUS_LOST) {
SDL_SetRelativeMouseMode(SDL_FALSE); SDL_SetRelativeMouseMode(SDL_FALSE);
@ -435,8 +453,9 @@ namespace ZL
std::cout << "\n========== MOUSE DOWN EVENT ==========" << std::endl; std::cout << "\n========== MOUSE DOWN EVENT ==========" << std::endl;
handleDown(ZL::UiManager::MOUSE_FINGER_ID, mx, my); handleDown(ZL::UiManager::MOUSE_FINGER_ID, mx, my);
if (menuManager.uiManager.isUiInteractionForFinger(ZL::UiManager::MOUSE_FINGER_ID)) { if (menuManager.getState() != GameState::Gameplay ||
std::cout << "[CLICK] UI handled, skipping character movement" << std::endl; menuManager.uiManager.isUiInteractionForFinger(ZL::UiManager::MOUSE_FINGER_ID)) {
std::cout << "[CLICK] UI handled or in menu, skipping game logic" << std::endl;
continue; continue;
} }
@ -450,22 +469,25 @@ namespace ZL
} }
} }
else if (event.button.button == SDL_BUTTON_RIGHT) { else if (event.button.button == SDL_BUTTON_RIGHT) {
if (event.type == SDL_MOUSEBUTTONDOWN) { if (menuManager.getState() == GameState::Gameplay)
rightMouseDown = true; {
lastMouseX = event.button.x; if (event.type == SDL_MOUSEBUTTONDOWN) {
lastMouseY = event.button.y; rightMouseDown = true;
if (currentLocation) lastMouseX = event.button.x;
{ lastMouseY = event.button.y;
currentLocation->rightMouseDown = true; if (currentLocation)
currentLocation->lastMouseX = event.button.x; {
currentLocation->lastMouseY = event.button.y; currentLocation->rightMouseDown = true;
currentLocation->lastMouseX = event.button.x;
currentLocation->lastMouseY = event.button.y;
}
} }
} else {
else { rightMouseDown = false;
rightMouseDown = false; if (currentLocation)
if (currentLocation) {
{ currentLocation->rightMouseDown = false;
currentLocation->rightMouseDown = false; }
} }
} }
} }
@ -474,22 +496,25 @@ namespace ZL
int mx = static_cast<int>((float)event.motion.x / Environment::width * Environment::projectionWidth); 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); int my = static_cast<int>((float)event.motion.y / Environment::height * Environment::projectionHeight);
handleMotion(ZL::UiManager::MOUSE_FINGER_ID, mx, my); 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); currentLocation->handleMotion(ZL::UiManager::MOUSE_FINGER_ID, event.motion.xrel, event.motion.yrel, mx, my);
} }
} }
if (event.type == SDL_MOUSEWHEEL) { if (event.type == SDL_MOUSEWHEEL) {
static const float zoomstep = 2.0f; if (menuManager.getState() == GameState::Gameplay) {
if (event.wheel.y > 0) { static const float zoomstep = 2.0f;
Environment::zoom -= zoomstep; if (event.wheel.y > 0) {
} Environment::zoom -= zoomstep;
else if (event.wheel.y < 0) { }
Environment::zoom += zoomstep; else if (event.wheel.y < 0) {
} Environment::zoom += zoomstep;
if (Environment::zoom < zoomstep) { }
Environment::zoom = zoomstep; if (Environment::zoom < zoomstep) {
Environment::zoom = zoomstep;
}
} }
} }
@ -506,21 +531,25 @@ namespace ZL
break; break;
case SDLK_c: case SDLK_c:
{ {
std::cout << "[GAME] Location change triggered by key press" << std::endl; if (menuManager.getState() == GameState::Gameplay) {
static size_t locIndex = 0; std::cout << "[GAME] Location change triggered by key press" << std::endl;
static std::vector<std::string> locations = {"forest", "default"}; static size_t locIndex = 0;
locIndex = (locIndex + 1) % locations.size(); static std::vector<std::string> locations = {"forest", "default"};
changeLocation(locations[locIndex]); locIndex = (locIndex + 1) % locations.size();
changeLocation(locations[locIndex]);
}
break; break;
} }
case SDLK_f: case SDLK_f:
currentLocation->dialogueSystem.startDialogue("dialogue_gas1"); if (currentLocation) currentLocation->dialogueSystem.startDialogue("dialogue_gas1");
break; break;
case SDLK_e: case SDLK_e:
//currentLocation->dialogueSystem.startDialogue("test_cutscene_pan_dialogue"); //currentLocation->dialogueSystem.startDialogue("test_cutscene_pan_dialogue");
currentLocation->navigation.build({}, "resources/config2/navigation2.json", CONST_ZIP_FILE); if (currentLocation) {
currentLocation->buildDebugNavMeshes(); currentLocation->navigation.build({}, "resources/config2/navigation2.json", CONST_ZIP_FILE);
currentLocation->buildDebugNavMeshes();
}
break; break;
case SDLK_p: case SDLK_p:
@ -538,7 +567,9 @@ namespace ZL
case SDLK_d: case SDLK_d:
case SDLK_u: case SDLK_u:
case SDLK_i: case SDLK_i:
if (currentLocation) currentLocation->handleKeyDown(event.key.keysym.sym); if (menuManager.getState() == GameState::Gameplay && currentLocation) {
currentLocation->handleKeyDown(event.key.keysym.sym);
}
break; break;
case SDLK_RETURN: case SDLK_RETURN:
@ -575,7 +606,9 @@ namespace ZL
case SDLK_a: case SDLK_a:
case SDLK_d: case SDLK_d:
case SDLK_i: case SDLK_i:
if (currentLocation) currentLocation->handleKeyUp(event.key.keysym.sym); if (menuManager.getState() == GameState::Gameplay && currentLocation) {
currentLocation->handleKeyUp(event.key.keysym.sym);
}
break; break;
default: break; default: break;
} }

View File

@ -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() void MenuManager::setupMenu()
{ {

View File

@ -56,10 +56,19 @@ namespace ZL {
*/ */
public: public:
UiManager uiManager; UiManager uiManager;
GameState currentState = GameState::MainMenu;
MenuManager(Renderer& iRenderer); 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) // Returns true for states where Space should render and run (Gameplay, GameOver, ConnectionLost)