add main menu
This commit is contained in:
parent
50232c0816
commit
204b79bf06
128
resources/config/main_menu.json
Normal file
128
resources/config/main_menu.json
Normal file
@ -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"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
BIN
resources/main_menu/exit.png
(Stored with Git LFS)
Normal file
BIN
resources/main_menu/exit.png
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
resources/main_menu/lang.png
(Stored with Git LFS)
Normal file
BIN
resources/main_menu/lang.png
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
resources/main_menu/line.png
(Stored with Git LFS)
Normal file
BIN
resources/main_menu/line.png
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
resources/main_menu/multi.png
(Stored with Git LFS)
Normal file
BIN
resources/main_menu/multi.png
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
resources/main_menu/single.png
(Stored with Git LFS)
Normal file
BIN
resources/main_menu/single.png
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
resources/main_menu/subtitle.png
(Stored with Git LFS)
Normal file
BIN
resources/main_menu/subtitle.png
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
resources/main_menu/title.png
(Stored with Git LFS)
Normal file
BIN
resources/main_menu/title.png
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
resources/main_menu/version.png
(Stored with Git LFS)
Normal file
BIN
resources/main_menu/version.png
(Stored with Git LFS)
Normal file
Binary file not shown.
200
src/Game.cpp
200
src/Game.cpp
@ -10,6 +10,7 @@
|
|||||||
#include <random>
|
#include <random>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <functional>
|
||||||
#ifdef __ANDROID__
|
#ifdef __ANDROID__
|
||||||
#include <android/log.h>
|
#include <android/log.h>
|
||||||
#endif
|
#endif
|
||||||
@ -164,102 +165,119 @@ namespace ZL
|
|||||||
bool explosionCfgLoaded = explosionEmitter.loadFromJsonFile("resources/config/explosion_config.json", renderer, CONST_ZIP_FILE);
|
bool explosionCfgLoaded = explosionEmitter.loadFromJsonFile("resources/config/explosion_config.json", renderer, CONST_ZIP_FILE);
|
||||||
explosionEmitter.setEmissionPoints(std::vector<Vector3f>());
|
explosionEmitter.setEmissionPoints(std::vector<Vector3f>());
|
||||||
projectileEmitter.setEmissionPoints(std::vector<Vector3f>());
|
projectileEmitter.setEmissionPoints(std::vector<Vector3f>());
|
||||||
uiManager.loadFromFile("resources/config/ui.json", renderer, CONST_ZIP_FILE);
|
|
||||||
|
|
||||||
uiManager.startAnimationOnNode("backgroundNode", "bgScroll");
|
uiManager.loadFromFile("resources/config/main_menu.json", renderer, CONST_ZIP_FILE);
|
||||||
static bool isExitButtonAnimating = false;
|
std::function<void()> loadGameplayUI;
|
||||||
uiManager.setAnimationCallback("settingsButton", "buttonsExit", [this]() {
|
loadGameplayUI = [this]() {
|
||||||
std::cerr << "Settings button animation finished -> переход в настройки" << std::endl;
|
uiManager.loadFromFile("resources/config/ui.json", renderer, CONST_ZIP_FILE);
|
||||||
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", []() {
|
uiManager.startAnimationOnNode("backgroundNode", "bgScroll");
|
||||||
std::cerr << "Exit button bgScroll animation finished" << std::endl;
|
static bool isExitButtonAnimating = false;
|
||||||
g_exitBgAnimating = 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)) {
|
||||||
// Set UI button callbacks
|
uiManager.setButtonCallback("Opt1", [this](const std::string& n) {
|
||||||
uiManager.setButtonCallback("playButton", [this](const std::string& name) {
|
std::cerr << "Opt1 pressed: " << n << std::endl;
|
||||||
std::cerr << "Play button pressed: " << name << std::endl;
|
});
|
||||||
|
uiManager.setButtonCallback("Opt2", [this](const std::string& n) {
|
||||||
});
|
std::cerr << "Opt2 pressed: " << n << std::endl;
|
||||||
|
});
|
||||||
uiManager.setButtonCallback("settingsButton", [this](const std::string& name) {
|
uiManager.setButtonCallback("backButton", [this](const std::string& n) {
|
||||||
std::cerr << "Settings button pressed: " << name << std::endl;
|
uiManager.stopAllAnimations();
|
||||||
uiManager.startAnimationOnNode("playButton", "buttonsExit");
|
uiManager.popMenu();
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
}
|
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<uint64_t>(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) {
|
uiManager.setButtonCallback("multiplayerButton", [loadGameplayUI](const std::string& name) {
|
||||||
uint64_t now = SDL_GetTicks64();
|
std::cerr << "Multiplayer button pressed: " << name << " -> load gameplay UI\n";
|
||||||
if (now - lastProjectileFireTime >= static_cast<uint64_t>(projectileCooldownMs)) {
|
loadGameplayUI();
|
||||||
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("exitButton", [](const std::string& name) {
|
||||||
uiManager.setSliderCallback("velocitySlider", [this](const std::string& name, float value) {
|
std::cerr << "Exit from main menu pressed: " << name << " -> exiting\n";
|
||||||
int newVel = roundf(value * 10);
|
Environment::exitGameLoop = true;
|
||||||
if (newVel != Environment::shipState.selectedVelocity) {
|
|
||||||
newShipVelocity = newVel;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
cubemapTexture = std::make_shared<Texture>(
|
cubemapTexture = std::make_shared<Texture>(
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user