added choosing spaceship in singleplay
This commit is contained in:
parent
ad7294ceea
commit
5216965496
64
resources/config/ship_selection_menu.json
Normal file
64
resources/config/ship_selection_menu.json
Normal file
@ -0,0 +1,64 @@
|
||||
{
|
||||
"root": {
|
||||
"name": "shipSelectionRoot",
|
||||
"type": "node",
|
||||
"children": [
|
||||
|
||||
{
|
||||
"type": "TextField",
|
||||
"name": "nicknameInput",
|
||||
"x": 400,
|
||||
"y": 150,
|
||||
"width": 400,
|
||||
"height": 50,
|
||||
"placeholder": "Enter your nickname",
|
||||
"fontPath": "resources/fonts/DroidSans.ttf",
|
||||
"fontSize": 16,
|
||||
"maxLength": 256,
|
||||
"color": [122, 156, 198, 1],
|
||||
"placeholderColor": [122, 156, 198, 1],
|
||||
"backgroundColor": [15, 29, 51, 1],
|
||||
"borderColor": [15, 29, 51, 1]
|
||||
},
|
||||
{
|
||||
"type": "Button",
|
||||
"name": "spaceshipButton",
|
||||
"x": 300,
|
||||
"y": 320,
|
||||
"width": 200,
|
||||
"height": 80,
|
||||
"textures": {
|
||||
"normal": "resources/multiplayer_menu/JoinServer.png",
|
||||
"hover": "resources/multiplayer_menu/JoinServer.png",
|
||||
"pressed": "resources/multiplayer_menu/JoinServer.png"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "Button",
|
||||
"name": "cargoshipButton",
|
||||
"x": 700,
|
||||
"y": 320,
|
||||
"width": 200,
|
||||
"height": 80,
|
||||
"textures": {
|
||||
"normal": "resources/multiplayer_menu/JoinServer.png",
|
||||
"hover": "resources/multiplayer_menu/JoinServer.png",
|
||||
"pressed": "resources/multiplayer_menu/JoinServer.png"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "Button",
|
||||
"name": "backButton",
|
||||
"x": 449,
|
||||
"y": 280,
|
||||
"width": 382,
|
||||
"height": 56,
|
||||
"textures": {
|
||||
"normal": "resources/multiplayer_menu/Backbutton.png",
|
||||
"hover": "resources/multiplayer_menu/Backbutton.png",
|
||||
"pressed": "resources/multiplayer_menu/Backbutton.png"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
15
src/Game.cpp
15
src/Game.cpp
@ -103,9 +103,22 @@ namespace ZL
|
||||
|
||||
menuManager.setupMenu();
|
||||
|
||||
menuManager.onSingleplayerPressed = [this]() {
|
||||
menuManager.onSingleplayerPressed = [this](const std::string& nickname, int shipType) {
|
||||
Environment::shipState.nickname = nickname;
|
||||
Environment::shipState.shipType = shipType;
|
||||
|
||||
networkClient = std::make_unique<LocalClient>();
|
||||
networkClient->Connect("", 0);
|
||||
|
||||
#ifndef NETWORK
|
||||
auto localClient = dynamic_cast<ZL::LocalClient*>(networkClient.get());
|
||||
if (localClient) {
|
||||
ZL::ClientState st = Environment::shipState;
|
||||
st.id = localClient->GetClientId();
|
||||
localClient->setLocalPlayerState(st);
|
||||
}
|
||||
#endif
|
||||
lastTickCount = 0;
|
||||
spaceGameStarted = 1;
|
||||
};
|
||||
|
||||
|
||||
@ -21,6 +21,7 @@ namespace ZL {
|
||||
|
||||
gameOverSavedRoot = loadUiFromFile("resources/config/game_over.json", renderer, CONST_ZIP_FILE);
|
||||
|
||||
auto shipSelectionRoot = loadUiFromFile("resources/config/ship_selection_menu.json", renderer, CONST_ZIP_FILE);
|
||||
std::function<void()> loadGameplayUI;
|
||||
loadGameplayUI = [this]() {
|
||||
uiManager.replaceRoot(uiSavedRoot);
|
||||
@ -114,10 +115,38 @@ namespace ZL {
|
||||
});
|
||||
};
|
||||
|
||||
uiManager.setButtonCallback("singleButton", [loadGameplayUI, this](const std::string& name) {
|
||||
std::cerr << "Single button pressed: " << name << " -> load gameplay UI\n";
|
||||
uiManager.setButtonCallback("singleButton", [this, shipSelectionRoot, loadGameplayUI](const std::string& name) {
|
||||
std::cerr << "Single button pressed: " << name << " -> open ship selection UI\n";
|
||||
if (!shipSelectionRoot) {
|
||||
std::cerr << "Failed to load ship selection UI\n";
|
||||
return;
|
||||
}
|
||||
if (uiManager.pushMenuFromSavedRoot(shipSelectionRoot)) {
|
||||
uiManager.setButtonCallback("spaceshipButton", [this, loadGameplayUI](const std::string& btnName) {
|
||||
std::string nick = uiManager.getTextFieldValue("nicknameInput");
|
||||
if (nick.empty()) nick = "Player";
|
||||
int shipType = 0;
|
||||
uiManager.popMenu();
|
||||
loadGameplayUI();
|
||||
onSingleplayerPressed();
|
||||
if (onSingleplayerPressed) onSingleplayerPressed(nick, shipType);
|
||||
});
|
||||
|
||||
uiManager.setButtonCallback("cargoshipButton", [this, loadGameplayUI](const std::string& btnName) {
|
||||
std::string nick = uiManager.getTextFieldValue("nicknameInput");
|
||||
if (nick.empty()) nick = "Player";
|
||||
int shipType = 1;
|
||||
uiManager.popMenu();
|
||||
loadGameplayUI();
|
||||
if (onSingleplayerPressed) onSingleplayerPressed(nick, shipType);
|
||||
});
|
||||
|
||||
uiManager.setButtonCallback("backButton", [this](const std::string& btnName) {
|
||||
uiManager.popMenu();
|
||||
});
|
||||
}
|
||||
else {
|
||||
std::cerr << "Failed to push ship selection menu\n";
|
||||
}
|
||||
});
|
||||
uiManager.setButtonCallback("multiplayerButton", [loadGameplayUI, this](const std::string& name) {
|
||||
std::cerr << "Multiplayer button pressed: " << name << " -> load gameplay UI\n";
|
||||
|
||||
@ -34,7 +34,7 @@ namespace ZL {
|
||||
std::function<void(float)> onVelocityChanged;
|
||||
std::function<void()> onFirePressed;
|
||||
|
||||
std::function<void()> onSingleplayerPressed;
|
||||
std::function<void(const std::string&, int)> onSingleplayerPressed;
|
||||
std::function<void()> onMultiplayerPressed;
|
||||
|
||||
};
|
||||
|
||||
@ -454,9 +454,15 @@ namespace ZL
|
||||
renderer.TranslateMatrix({ 0, -6.f, 0 }); //Ship camera offset
|
||||
|
||||
if (shipAlive) {
|
||||
if (Environment::shipState.shipType == 1 && cargoTexture) {
|
||||
glBindTexture(GL_TEXTURE_2D, cargoTexture->getTexID());
|
||||
renderer.DrawVertexRenderStruct(cargo);
|
||||
}
|
||||
else {
|
||||
glBindTexture(GL_TEXTURE_2D, spaceshipTexture->getTexID());
|
||||
renderer.DrawVertexRenderStruct(spaceship);
|
||||
}
|
||||
}
|
||||
renderer.PopMatrix();
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
@ -4,6 +4,7 @@
|
||||
#define _USE_MATH_DEFINES
|
||||
#include <math.h>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
|
||||
using std::min;
|
||||
@ -38,6 +39,7 @@ struct ClientState {
|
||||
float discreteMag = 0;
|
||||
int discreteAngle = -1;
|
||||
|
||||
std::string nickname = "Player";
|
||||
int shipType = 0;
|
||||
// ??? ??????? ????
|
||||
std::chrono::system_clock::time_point lastUpdateServerTime;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user