diff --git a/resources/config/main_menu.json b/resources/config/main_menu.json new file mode 100644 index 0000000..9677e48 --- /dev/null +++ b/resources/config/main_menu.json @@ -0,0 +1,128 @@ +{ + "root": { + "type": "FrameLayout", + "x": 0, + "y": 0, + "width": 1280, + "height": 720, + "children": [ + { + "type": "LinearLayout", + "name": "settingsButtons", + "orientation": "vertical", + "spacing": 10, + "x": 0, + "y": 0, + "width": 300, + "height": 300, + "children": [ + { + "type": "Button", + "name": "langButton", + "x": 1100, + "y": 580, + "width": 142, + "height": 96, + "textures": { + "normal": "resources/main_menu/lang.png", + "hover": "resources/main_menu/lang.png", + "pressed": "resources/main_menu/lang.png" + } + }, + { + "type": "Button", + "name": "titleBtn", + "x": 473, + "y": 500, + "width": 254, + "height": 35, + "textures": { + "normal": "resources/main_menu/title.png", + "hover": "resources/main_menu/title.png", + "pressed": "resources/main_menu/title.png" + } + }, + { + "type": "Button", + "name": "underlineBtn", + "x": 516, + "y": 465, + "width": 168, + "height": 44, + "textures": { + "normal": "resources/main_menu/line.png", + "hover": "resources/main_menu/line.png", + "pressed": "resources/main_menu/line.png" + } + }, + { + "type": "Button", + "name": "subtitleBtn", + "x": 528, + "y": 455, + "width": 144, + "height": 11, + "textures": { + "normal": "resources/main_menu/subtitle.png", + "hover": "resources/main_menu/subtitle.png", + "pressed": "resources/main_menu/subtitle.png" + } + }, + { + "type": "Button", + "name": "singleButton", + "x": 409, + "y": 360, + "width": 382, + "height": 56, + "textures": { + "normal": "resources/main_menu/single.png", + "hover": "resources/main_menu/single.png", + "pressed": "resources/main_menu/single.png" + } + }, + { + "type": "Button", + "name": "multiplayerButton", + "x": 409, + "y": 289, + "width": 382, + "height": 56, + "textures": { + "normal": "resources/main_menu/multi.png", + "hover": "resources/main_menu/multi.png", + "pressed": "resources/main_menu/multi.png" + } + }, + { + "type": "Button", + "name": "exitButton", + "x": 409, + "y": 218, + "width": 382, + "height": 56, + "textures": { + "normal": "resources/main_menu/exit.png", + "hover": "resources/main_menu/exit.png", + "pressed": "resources/main_menu/exit.png" + } + }, + { + "type": "Button", + "name": "versionLabel", + "x": 559.5, + "y": 170, + "width": 81, + "height": 9, + "textures": { + "normal": "resources/main_menu/version.png", + "hover": "resources/main_menu/version.png", + "pressed": "resources/main_menu/version.png" + } + } + ] + } + ] + } + } + \ No newline at end of file diff --git a/resources/main_menu/exit.png b/resources/main_menu/exit.png new file mode 100644 index 0000000..d2e10c7 --- /dev/null +++ b/resources/main_menu/exit.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:cd2def6829ad74a9a6f466259f56001261161e44e04d54452b20537f02100510 +size 1705 diff --git a/resources/main_menu/lang.png b/resources/main_menu/lang.png new file mode 100644 index 0000000..6ab2a9d --- /dev/null +++ b/resources/main_menu/lang.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:063b260ec102139ba2afe878ceff30343c1d3debe82cfed2bf80c4681d9f97e1 +size 9811 diff --git a/resources/main_menu/line.png b/resources/main_menu/line.png new file mode 100644 index 0000000..73e47a5 --- /dev/null +++ b/resources/main_menu/line.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:268a7cb9f878a44b0e170655f6ef88ef6ba55e422458a87e05a16a121a5ed2f3 +size 5774 diff --git a/resources/main_menu/multi.png b/resources/main_menu/multi.png new file mode 100644 index 0000000..8ed569b --- /dev/null +++ b/resources/main_menu/multi.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:44549cc8ac38f4ee24ebf8feedd11a5c0dfb156ad1f65c84d290980d5b0f44fb +size 1909 diff --git a/resources/main_menu/single.png b/resources/main_menu/single.png new file mode 100644 index 0000000..ee1595e --- /dev/null +++ b/resources/main_menu/single.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:34926668c8f681d6fa9527343bf47169f0f6683a281591ee0d8106b65ad2e758 +size 2036 diff --git a/resources/main_menu/subtitle.png b/resources/main_menu/subtitle.png new file mode 100644 index 0000000..4955406 --- /dev/null +++ b/resources/main_menu/subtitle.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ef4a84b8462285ee4038b85b5474059c5dc77b114a93e35ce09dd71f74c9ed60 +size 1652 diff --git a/resources/main_menu/title.png b/resources/main_menu/title.png new file mode 100644 index 0000000..81d446a --- /dev/null +++ b/resources/main_menu/title.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:efaa78ed8e564bc34e0f2d154f92b5a0e4cc18da733db729925967d1b1c4e482 +size 2023 diff --git a/resources/main_menu/version.png b/resources/main_menu/version.png new file mode 100644 index 0000000..daaa9ce --- /dev/null +++ b/resources/main_menu/version.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9570c36786c210f39fc6e44a428b7fbeecfa91d564b8982e9cc479aa8a2d545f +size 1157 diff --git a/src/Game.cpp b/src/Game.cpp index bd0778d..2e7aa41 100644 --- a/src/Game.cpp +++ b/src/Game.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #ifdef __ANDROID__ #include #endif @@ -164,102 +165,119 @@ namespace ZL bool explosionCfgLoaded = explosionEmitter.loadFromJsonFile("resources/config/explosion_config.json", renderer, CONST_ZIP_FILE); explosionEmitter.setEmissionPoints(std::vector()); projectileEmitter.setEmissionPoints(std::vector()); - uiManager.loadFromFile("resources/config/ui.json", renderer, CONST_ZIP_FILE); - uiManager.startAnimationOnNode("backgroundNode", "bgScroll"); - static bool isExitButtonAnimating = false; - uiManager.setAnimationCallback("settingsButton", "buttonsExit", [this]() { - std::cerr << "Settings button animation finished -> переход в настройки" << std::endl; - if (uiManager.pushMenuFromFile("resources/config/settings.json", this->renderer, CONST_ZIP_FILE)) { - uiManager.setButtonCallback("Opt1", [this](const std::string& n) { - std::cerr << "Opt1 pressed: " << n << std::endl; - }); - uiManager.setButtonCallback("Opt2", [this](const std::string& n) { - std::cerr << "Opt2 pressed: " << n << std::endl; - }); - uiManager.setButtonCallback("backButton", [this](const std::string& n) { - uiManager.stopAllAnimations(); - uiManager.popMenu(); - }); - } - else { - std::cerr << "Failed to open settings menu after animations" << std::endl; - } - }); + uiManager.loadFromFile("resources/config/main_menu.json", renderer, CONST_ZIP_FILE); + std::function loadGameplayUI; + loadGameplayUI = [this]() { + uiManager.loadFromFile("resources/config/ui.json", renderer, CONST_ZIP_FILE); - uiManager.setAnimationCallback("exitButton", "bgScroll", []() { - std::cerr << "Exit button bgScroll animation finished" << std::endl; - g_exitBgAnimating = false; - }); - - // Set UI button callbacks - uiManager.setButtonCallback("playButton", [this](const std::string& name) { - std::cerr << "Play button pressed: " << name << std::endl; - - }); - - uiManager.setButtonCallback("settingsButton", [this](const std::string& name) { - std::cerr << "Settings button pressed: " << name << std::endl; - uiManager.startAnimationOnNode("playButton", "buttonsExit"); - uiManager.startAnimationOnNode("settingsButton", "buttonsExit"); - uiManager.startAnimationOnNode("exitButton", "buttonsExit"); - }); - - uiManager.setButtonCallback("exitButton", [this](const std::string& name) { - std::cerr << "Exit button pressed: " << name << std::endl; - - if (!g_exitBgAnimating) { - std::cerr << "start repeat anim bgScroll on exitButton" << std::endl; - g_exitBgAnimating = true; - uiManager.startAnimationOnNode("exitButton", "bgScroll"); - } - else { - std::cerr << "stop repeat anim bgScroll on exitButton" << std::endl; - g_exitBgAnimating = false; - uiManager.stopAnimationOnNode("exitButton", "bgScroll"); - - auto exitButton = uiManager.findButton("exitButton"); - if (exitButton) { - exitButton->animOffsetX = 0.0f; - exitButton->animOffsetY = 0.0f; - exitButton->animScaleX = 1.0f; - exitButton->animScaleY = 1.0f; - exitButton->buildMesh(); + uiManager.startAnimationOnNode("backgroundNode", "bgScroll"); + static bool isExitButtonAnimating = false; + uiManager.setAnimationCallback("settingsButton", "buttonsExit", [this]() { + std::cerr << "Settings button animation finished -> переход в настройки" << std::endl; + if (uiManager.pushMenuFromFile("resources/config/settings.json", this->renderer, CONST_ZIP_FILE)) { + uiManager.setButtonCallback("Opt1", [this](const std::string& n) { + std::cerr << "Opt1 pressed: " << n << std::endl; + }); + uiManager.setButtonCallback("Opt2", [this](const std::string& n) { + std::cerr << "Opt2 pressed: " << n << std::endl; + }); + uiManager.setButtonCallback("backButton", [this](const std::string& n) { + uiManager.stopAllAnimations(); + uiManager.popMenu(); + }); } - } + else { + std::cerr << "Failed to open settings menu after animations" << std::endl; + } + }); + + uiManager.setAnimationCallback("exitButton", "bgScroll", []() { + std::cerr << "Exit button bgScroll animation finished" << std::endl; + g_exitBgAnimating = false; + }); + + uiManager.setButtonCallback("playButton", [this](const std::string& name) { + std::cerr << "Play button pressed: " << name << std::endl; + }); + + uiManager.setButtonCallback("settingsButton", [this](const std::string& name) { + std::cerr << "Settings button pressed: " << name << std::endl; + uiManager.startAnimationOnNode("playButton", "buttonsExit"); + uiManager.startAnimationOnNode("settingsButton", "buttonsExit"); + uiManager.startAnimationOnNode("exitButton", "buttonsExit"); + }); + + uiManager.setButtonCallback("exitButton", [this](const std::string& name) { + std::cerr << "Exit button pressed: " << name << std::endl; + + if (!g_exitBgAnimating) { + std::cerr << "start repeat anim bgScroll on exitButton" << std::endl; + g_exitBgAnimating = true; + uiManager.startAnimationOnNode("exitButton", "bgScroll"); + } + else { + std::cerr << "stop repeat anim bgScroll on exitButton" << std::endl; + g_exitBgAnimating = false; + uiManager.stopAnimationOnNode("exitButton", "bgScroll"); + + auto exitButton = uiManager.findButton("exitButton"); + if (exitButton) { + exitButton->animOffsetX = 0.0f; + exitButton->animOffsetY = 0.0f; + exitButton->animScaleX = 1.0f; + exitButton->animScaleY = 1.0f; + exitButton->buildMesh(); + } + } + }); + + uiManager.setButtonCallback("shootButton", [this](const std::string& name) { + uint64_t now = SDL_GetTicks64(); + if (now - lastProjectileFireTime >= static_cast(projectileCooldownMs)) { + lastProjectileFireTime = now; + + this->fireProjectiles(); + + Eigen::Vector3f localForward = { 0, 0, -1 }; + Eigen::Vector3f worldForward = (Environment::shipState.rotation * localForward).normalized(); + + Eigen::Vector3f centerPos = Environment::shipState.position + + Environment::shipState.rotation * Vector3f{ 0, 0.9f, 5.0f }; + + std::string fireMsg = "FIRE:" + + std::to_string(now) + ":" + + std::to_string(centerPos.x()) + ":" + + std::to_string(centerPos.y()) + ":" + + std::to_string(centerPos.z()) + ":" + + std::to_string(worldForward.x()) + ":" + + std::to_string(worldForward.y()) + ":" + + std::to_string(worldForward.z()) + ":" + + "2"; + + networkClient->Send(fireMsg); + } + }); + + uiManager.setSliderCallback("velocitySlider", [this](const std::string& name, float value) { + int newVel = roundf(value * 10); + if (newVel != Environment::shipState.selectedVelocity) { + newShipVelocity = newVel; + } + }); + }; + + uiManager.setButtonCallback("singleButton", [loadGameplayUI](const std::string& name) { + std::cerr << "Single button pressed: " << name << " -> load gameplay UI\n"; + loadGameplayUI(); }); - uiManager.setButtonCallback("shootButton", [this](const std::string& name) { - uint64_t now = SDL_GetTicks64(); - if (now - lastProjectileFireTime >= static_cast(projectileCooldownMs)) { - lastProjectileFireTime = now; - - this->fireProjectiles(); - - Eigen::Vector3f localForward = { 0, 0, -1 }; - Eigen::Vector3f worldForward = (Environment::shipState.rotation * localForward).normalized(); - - Eigen::Vector3f centerPos = Environment::shipState.position + - Environment::shipState.rotation * Vector3f{ 0, 0.9f, 5.0f }; - - std::string fireMsg = "FIRE:" + - std::to_string(now) + ":" + - std::to_string(centerPos.x()) + ":" + - std::to_string(centerPos.y()) + ":" + - std::to_string(centerPos.z()) + ":" + - std::to_string(worldForward.x()) + ":" + - std::to_string(worldForward.y()) + ":" + - std::to_string(worldForward.z()) + ":" + - "2"; - - networkClient->Send(fireMsg); - } + uiManager.setButtonCallback("multiplayerButton", [loadGameplayUI](const std::string& name) { + std::cerr << "Multiplayer button pressed: " << name << " -> load gameplay UI\n"; + loadGameplayUI(); }); - - uiManager.setSliderCallback("velocitySlider", [this](const std::string& name, float value) { - int newVel = roundf(value * 10); - if (newVel != Environment::shipState.selectedVelocity) { - newShipVelocity = newVel; - } + uiManager.setButtonCallback("exitButton", [](const std::string& name) { + std::cerr << "Exit from main menu pressed: " << name << " -> exiting\n"; + Environment::exitGameLoop = true; }); cubemapTexture = std::make_shared(