mirror of
https://github.com/devZoGok/PlanetFleet.git
synced 2026-08-26 19:43:29 +00:00
loading player data from the single player menu to load the game
This commit is contained in:
@@ -52,6 +52,8 @@ ListboxType = {
|
||||
LAND_TEXTURES = 7,
|
||||
CPU_DIFFICULTIES = 8,
|
||||
FACTIONS = 9,
|
||||
CONSOLE = 10,
|
||||
TRADE_OFFERS = 11
|
||||
COLORS = 10,
|
||||
TEAMS = 11,
|
||||
CONSOLE = 12,
|
||||
TRADE_OFFERS = 13
|
||||
}
|
||||
|
||||
@@ -1,23 +1,49 @@
|
||||
playerListboxPos = {x = 110, y = 10, z = 0}
|
||||
Pos = {x = playerListboxPos.x, y = playerListboxPos.y, z = playerListboxPos.z}
|
||||
Size = {x = 100, y = 20}
|
||||
Size = {x = 150, y = 20}
|
||||
gap = 10
|
||||
gapFactor = 3
|
||||
|
||||
factions = {'None', "America inc.", "European Republic", "Asian Co-Prosperity Sphere"}
|
||||
difficulties = {"Easy", "Medium", "Hard"}
|
||||
space = 10
|
||||
colors = {'White', 'Black', 'Red'}
|
||||
teams = {'0', '1', '2', '3', '4'}
|
||||
|
||||
gui = {
|
||||
{
|
||||
pos = {x = Pos.x, y = Pos.y + (#factions * Size.y + space) * (lineId + 1), z = Pos.z},
|
||||
pos = {x = Pos.x, y = Pos.y + (gapFactor * Size.y + gap) * (lineId + 1), z = Pos.z},
|
||||
size = Size,
|
||||
guiType = GuiType.LISTBOX,
|
||||
name = 'factions',
|
||||
numMaxDisplay = 3,
|
||||
lines = factions,
|
||||
listboxType = ListboxType.FACTIONS
|
||||
},
|
||||
{
|
||||
pos = {x = Pos.x + Size.x + space, y = Pos.y + (#difficulties * Size.y + space) * (lineId + 1), z = Pos.z},
|
||||
pos = {x = Pos.x + Size.x + gap, y = Pos.y + (gapFactor * Size.y + gap) * (lineId + 1), z = Pos.z},
|
||||
size = Size,
|
||||
guiType = GuiType.LISTBOX,
|
||||
name = 'difficulties',
|
||||
numMaxDisplay = 3,
|
||||
lines = difficulties,
|
||||
listboxType = ListboxType.CPU_DIFFICULTIES
|
||||
},
|
||||
{
|
||||
pos = {x = Pos.x + 2 * (Size.x + gap), y = Pos.y + (gapFactor * Size.y + gap) * (lineId + 1), z = Pos.z},
|
||||
size = Size,
|
||||
guiType = GuiType.LISTBOX,
|
||||
name = 'colors',
|
||||
numMaxDisplay = 3,
|
||||
lines = colors,
|
||||
listboxType = ListboxType.COLORS
|
||||
},
|
||||
{
|
||||
pos = {x = Pos.x + 3 * (Size.x + gap), y = Pos.y + (gapFactor * Size.y + gap) * (lineId + 1), z = Pos.z},
|
||||
size = Size,
|
||||
guiType = GuiType.LISTBOX,
|
||||
name = 'teams',
|
||||
numMaxDisplay = 3,
|
||||
lines = teams,
|
||||
listboxType = ListboxType.TEAMS
|
||||
},
|
||||
}
|
||||
|
||||
@@ -1,17 +1,6 @@
|
||||
Size = {x = 100, y = 20}
|
||||
playerListboxPos = {x = 110, y = 10, z = 0}
|
||||
factions = {"America inc.", "European Republic", "Asian Co-Prosperity Sphere"}
|
||||
|
||||
numGui = 6
|
||||
gui = {
|
||||
{
|
||||
pos = playerListboxPos,
|
||||
size = Size,
|
||||
guiType = GuiType.LISTBOX,
|
||||
numMaxDisplay = 3,
|
||||
lines = factions,
|
||||
listboxType = ListboxType.FACTIONS
|
||||
},
|
||||
{
|
||||
pos = {x = 110, y = 310, z = 0},
|
||||
size = Size,
|
||||
@@ -27,12 +16,7 @@ gui = {
|
||||
buttonType = ButtonType.PLAY,
|
||||
name = 'Play',
|
||||
numDependencies = 4,
|
||||
dependencies = {
|
||||
{id = 0},
|
||||
{id = 1},
|
||||
{id = 2},
|
||||
{id = 3}
|
||||
}
|
||||
dependencies = {{id = 0}}
|
||||
},
|
||||
{
|
||||
pos = {x = 110 + Size.x + 10, y = 460, z = 0},
|
||||
|
||||
+10
-20
@@ -156,21 +156,9 @@ namespace battleship{
|
||||
button = new ExportButton(pos, size);
|
||||
break;
|
||||
case PLAY:{
|
||||
int did = guiTable["dependencies"][1]["id"];
|
||||
vector<Listbox*> difficultyListboxes = vector<Listbox*>{(Listbox*)guiElements[did].second};
|
||||
|
||||
vector<Listbox*> factionsListboxes;
|
||||
int numPlayers = 2;
|
||||
|
||||
for(int i = 0; i < numPlayers; i++){
|
||||
int did = guiTable["dependencies"][i + 2]["id"];
|
||||
factionsListboxes.push_back((Listbox*)guiElements[did].second);
|
||||
}
|
||||
|
||||
int mid = guiTable["dependencies"][4]["id"];
|
||||
int mid = guiTable["dependencies"][1]["id"];
|
||||
Listbox *mapListbox = (MapListbox*)guiElements[mid].second;
|
||||
|
||||
button = new PlayButton(difficultyListboxes, factionsListboxes, mapListbox, pos, size, name, true);
|
||||
button = new PlayButton(mapListbox, pos, size, name, true);
|
||||
break;
|
||||
}
|
||||
case RESUME:
|
||||
@@ -308,6 +296,10 @@ namespace battleship{
|
||||
|
||||
Listbox *listbox = nullptr;
|
||||
string fontPath = fontBasePath + "batang.ttf";
|
||||
sol::optional<string> nameOpt = guiTable["name"];
|
||||
string name = "";
|
||||
|
||||
if(nameOpt != sol::nullopt) name = guiTable["name"];
|
||||
|
||||
switch(listboxType){
|
||||
case CONTROLS:{
|
||||
@@ -389,13 +381,9 @@ namespace battleship{
|
||||
listbox = new LandTextureListbox(pos, size, lines, maxDisplay, fontPath);
|
||||
break;
|
||||
case CPU_DIFFICULTIES:
|
||||
numLines = lines.size();
|
||||
closable = true;
|
||||
maxDisplay = (numLines > numMaxDisplay ? numMaxDisplay : numLines);
|
||||
|
||||
listbox = new Listbox(pos, size, lines, maxDisplay, fontPath);
|
||||
break;
|
||||
case FACTIONS:
|
||||
case COLORS:
|
||||
case TEAMS:
|
||||
numLines = lines.size();
|
||||
closable = true;
|
||||
maxDisplay = (numLines > numMaxDisplay ? numMaxDisplay : numLines);
|
||||
@@ -421,6 +409,8 @@ namespace battleship{
|
||||
int typeArr[2]{(int)GuiElementType::LISTBOX, (int)listboxType};
|
||||
guiElements.push_back(make_pair(typeArr, (void*)listbox));
|
||||
|
||||
listbox->setName(name);
|
||||
|
||||
return listbox;
|
||||
}
|
||||
|
||||
|
||||
@@ -65,6 +65,8 @@ namespace battleship{
|
||||
LAND_TEXTURES,
|
||||
CPU_DIFFICULTIES,
|
||||
FACTIONS,
|
||||
COLORS,
|
||||
TEAMS,
|
||||
CONSOLE,
|
||||
TRADE_OFFERS
|
||||
};
|
||||
|
||||
+4
-26
@@ -45,39 +45,17 @@ namespace battleship{
|
||||
Console::execute(wstringToString(textbox->getText()));
|
||||
}
|
||||
|
||||
InGameAppState::InGameAppState(vector<string> difficultyLevels, vector<string> factions) : AbstractAppState(
|
||||
InGameAppState::InGameAppState() : AbstractAppState(
|
||||
AppStateType::IN_GAME_STATE,
|
||||
configData::calcSumBinds(AppStateType::IN_GAME_STATE, true),
|
||||
configData::calcSumBinds(AppStateType::IN_GAME_STATE, false),
|
||||
GameManager::getSingleton()->getPath() + scripts[(int)ScriptFiles::OPTIONS]){
|
||||
this->playerId = 1;
|
||||
this->difficultyLevels = difficultyLevels;
|
||||
this->factions = factions;
|
||||
}
|
||||
|
||||
InGameAppState::~InGameAppState() {
|
||||
}
|
||||
GameManager::getSingleton()->getPath() + scripts[(int)ScriptFiles::OPTIONS]
|
||||
),
|
||||
playerId(0){}
|
||||
|
||||
void InGameAppState::onAttached() {
|
||||
AbstractAppState::onAttached();
|
||||
|
||||
for (int i = 0; i < factions.size(); i++) {
|
||||
int faction, difficulty;
|
||||
|
||||
if (i == 0)
|
||||
difficulty = -1;
|
||||
else {
|
||||
if (difficultyLevels[i - 1] == "Easy")
|
||||
difficulty = 0;
|
||||
else if (difficultyLevels[i - 1] == "Medium")
|
||||
difficulty = 1;
|
||||
else
|
||||
difficulty = 2;
|
||||
}
|
||||
|
||||
faction = factions[i][0] - 48;
|
||||
}
|
||||
|
||||
Camera *cam = Root::getSingleton()->getCamera();
|
||||
cam->setPosition(Map::getSingleton()->getSpawnPoint(playerId - 1) + Vector3(1, 1, 1) * configData::CAMERA_DISTANCE);
|
||||
cam->lookAt(Vector3(0, -1, -1).norm(), Vector3(0, 1, -1).norm());
|
||||
|
||||
+3
-3
@@ -39,8 +39,8 @@ namespace battleship{
|
||||
private:
|
||||
};
|
||||
|
||||
InGameAppState(std::vector<std::string>, std::vector<std::string>);
|
||||
~InGameAppState();
|
||||
InGameAppState();
|
||||
~InGameAppState(){}
|
||||
void onAttached();
|
||||
void onDettached();
|
||||
void update();
|
||||
@@ -50,7 +50,7 @@ namespace battleship{
|
||||
inline ActiveGameState* getActiveState(){return activeState;}
|
||||
private:
|
||||
bool isMainMenuActive = false;
|
||||
std::vector<std::string> difficultyLevels, factions, modelPaths;
|
||||
std::vector<std::string> modelPaths;
|
||||
Player *mainPlayer;
|
||||
int playerId;
|
||||
ActiveGameState* activeState;
|
||||
|
||||
@@ -384,7 +384,7 @@ namespace battleship{
|
||||
|
||||
void Map::loadSpawnPoints(){
|
||||
sol::state_view SOL_LUA_VIEW = generateView();
|
||||
int numSpawnPoints = getNumSpawnPoints();
|
||||
int numSpawnPoints = getNumMapSpawnPoints();
|
||||
|
||||
for(int i = 0; i < numSpawnPoints; i++){
|
||||
sol::table posTable = SOL_LUA_VIEW[mapTable]["spawnPoints"][i + 1];
|
||||
|
||||
+3
-6
@@ -20,10 +20,7 @@ namespace battleship{
|
||||
|
||||
MapListbox::MapListbox(Vector3 pos, Vector2 size, std::vector<string> &lines, int maxDisplay, bool adg, string fontPath, bool closeable) :
|
||||
Listbox(pos, size, lines, maxDisplay, fontPath, closeable),
|
||||
addPlayerGui(adg) {
|
||||
openUp();
|
||||
close();
|
||||
}
|
||||
addPlayerGui(adg) {}
|
||||
|
||||
void MapListbox::onClose(){
|
||||
if(addPlayerGui){
|
||||
@@ -38,14 +35,14 @@ namespace battleship{
|
||||
int numSpawnPoints = Map::getSingleton()->getNumMapSpawnPoints(mapName);
|
||||
sol::state_view SOL_LUA_VIEW = generateView();
|
||||
|
||||
for(int i = 0; i < numSpawnPoints - 1; i++){
|
||||
for(int i = 0; i < numSpawnPoints; i++){
|
||||
int prevNumListboxes = guiManager->getListboxes().size();
|
||||
|
||||
SOL_LUA_VIEW.script("lineId = " + to_string(i));
|
||||
guiManager->parseLuaScript("playerSelection.lua");
|
||||
|
||||
std::vector<Listbox*> listboxes = guiManager->getListboxes();
|
||||
int diffNumListboxes = guiManager->getListboxes().size() - prevNumListboxes;
|
||||
int diffNumListboxes = listboxes.size() - prevNumListboxes;
|
||||
|
||||
for(int j = 0; j < diffNumListboxes; j++)
|
||||
cpuPlayerListboxes.push_back(listboxes[listboxes.size() - 1 - j]);
|
||||
|
||||
+58
-33
@@ -14,42 +14,67 @@ namespace battleship{
|
||||
using namespace vb01Gui;
|
||||
using namespace gameBase;
|
||||
|
||||
PlayButton::PlayButton(vector<Listbox*> difficulties, vector<Listbox*> factions, Listbox *mapListbox, Vector3 pos, Vector2 size, string name, bool separate) : Button(pos, size, name, GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", GLFW_KEY_P, separate) {
|
||||
difficultiesListboxes = difficulties;
|
||||
factionsListboxes = factions;
|
||||
this->mapListbox = mapListbox;
|
||||
}
|
||||
PlayButton::PlayButton(Listbox *ml, Vector3 pos, Vector2 size, string name, bool separate) : Button(pos, size, name, GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", GLFW_KEY_P, separate), mapListbox(ml) {}
|
||||
|
||||
void PlayButton::onClick() {
|
||||
std::vector<string> difficulties, factions;
|
||||
void PlayButton::onClick() {
|
||||
|
||||
for(int i = 0; i < difficultiesListboxes.size(); i++)
|
||||
difficulties.push_back(wstringToString(difficultiesListboxes[i]->getContents()[difficultiesListboxes[i]->getSelectedOption()]));
|
||||
ConcreteGuiManager *guiManager = ConcreteGuiManager::getSingleton();
|
||||
vector<Listbox*> factionsListboxes, difficultiesListboxes, colorsListboxes, teamsListboxes;
|
||||
|
||||
for(Listbox *listbox : guiManager->getListboxes()){
|
||||
string name = listbox->getName();
|
||||
|
||||
if(name == "factions") factionsListboxes.push_back(listbox);
|
||||
else if(name == "difficulties") difficultiesListboxes.push_back(listbox);
|
||||
else if(name == "colors") colorsListboxes.push_back(listbox);
|
||||
else if(name == "teams") teamsListboxes.push_back(listbox);
|
||||
}
|
||||
|
||||
Game *game = Game::getSingleton();
|
||||
game->initTechnologies();
|
||||
|
||||
int selectedMap = mapListbox->getSelectedOption();
|
||||
string mapName = wstringToString(mapListbox->getContents()[selectedMap]);
|
||||
|
||||
Map *map = Map::getSingleton();
|
||||
map->load(mapName);
|
||||
int numPlayers = map->getNumSpawnPoints();
|
||||
|
||||
for(int i = 0; i < factionsListboxes.size(); i++)
|
||||
factions.push_back(to_string(factionsListboxes[i]->getSelectedOption()));
|
||||
for(int i = 0; i < numPlayers; i++){
|
||||
int factionChoice = factionsListboxes[i]->getSelectedOption();
|
||||
|
||||
Game *game = Game::getSingleton();
|
||||
game->initTechnologies();
|
||||
if(factionChoice == 0) continue;
|
||||
|
||||
int faction = factionChoice - 1;
|
||||
|
||||
bool cpuPlayer = (i > 0);
|
||||
string diffStr = (cpuPlayer ? wstringToString(difficultiesListboxes[i]->getContents()[colorsListboxes[i]->getSelectedOption()]) : "");
|
||||
int difficulty = -1;
|
||||
|
||||
if(diffStr == "Easy") difficulty = 0;
|
||||
else if(diffStr == "Medium") difficulty = 1;
|
||||
else if(diffStr == "Hard") difficulty = 2;
|
||||
|
||||
string colorStr = wstringToString(colorsListboxes[i]->getContents()[colorsListboxes[i]->getSelectedOption()]);
|
||||
Vector3 color;
|
||||
|
||||
if(colorStr == "Black") color = Vector3::VEC_ZERO;
|
||||
else if(colorStr == "Red") color = Vector3::VEC_I;
|
||||
else if(colorStr == "Green") color = Vector3::VEC_J;
|
||||
else if(colorStr == "Blue") color = Vector3::VEC_K;
|
||||
else if(colorStr == "White") color = Vector3::VEC_IJK;
|
||||
|
||||
int team = stoi(teamsListboxes[i]->getContents()[teamsListboxes[i]->getSelectedOption()]);
|
||||
|
||||
string name = (cpuPlayer ? "CPU player #" + to_string(i) : "Player");
|
||||
game->addPlayer(new Player(difficulty, faction, team, color, cpuPlayer, map->getSpawnPoint(i), name));
|
||||
}
|
||||
|
||||
int selectedMap = mapListbox->getSelectedOption();
|
||||
string mapName = wstringToString(mapListbox->getContents()[selectedMap]);
|
||||
Map *map = Map::getSingleton();
|
||||
map->load(mapName);
|
||||
|
||||
int numPlayers = map->getNumSpawnPoints();
|
||||
|
||||
for(int i = 0; i < numPlayers; i++){
|
||||
bool cpuPlayer = (i < numPlayers - 1);
|
||||
string name = (cpuPlayer ? "CPU player #" + to_string(i) : "Player");
|
||||
game->addPlayer(new Player(0, 0, i, Vector3(i, i, i), cpuPlayer, map->getSpawnPoint(i), name));
|
||||
}
|
||||
|
||||
map->loadPlayerGameObjects();
|
||||
|
||||
ConcreteGuiManager::getSingleton()->readLuaScreenScript("inGame.lua");
|
||||
|
||||
StateManager *stateManager = GameManager::getSingleton()->getStateManager();
|
||||
stateManager->attachAppState(new InGameAppState(difficulties, factions));
|
||||
}
|
||||
map->loadPlayerGameObjects();
|
||||
|
||||
guiManager->readLuaScreenScript("inGame.lua");
|
||||
|
||||
StateManager *stateManager = GameManager::getSingleton()->getStateManager();
|
||||
stateManager->attachAppState(new InGameAppState());
|
||||
}
|
||||
}
|
||||
|
||||
+1
-3
@@ -10,12 +10,10 @@ namespace vb01Gui{
|
||||
namespace battleship{
|
||||
class PlayButton : public vb01Gui::Button {
|
||||
public:
|
||||
PlayButton(std::vector<vb01Gui::Listbox*>, std::vector<vb01Gui::Listbox*>, vb01Gui::Listbox*, vb01::Vector3, vb01::Vector2, std::string, bool);
|
||||
PlayButton(vb01Gui::Listbox*, vb01::Vector3, vb01::Vector2, std::string, bool);
|
||||
void onClick();
|
||||
private:
|
||||
std::vector<vb01Gui::Listbox*> difficultiesListboxes, factionsListboxes;
|
||||
vb01Gui::Listbox *mapListbox = nullptr;
|
||||
int lengths[2];
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
#include "gameManager.h"
|
||||
#include "concreteGuiManager.h"
|
||||
|
||||
#include <listbox.h>
|
||||
|
||||
#include <glfw3.h>
|
||||
|
||||
namespace battleship{
|
||||
@@ -21,5 +23,9 @@ namespace battleship{
|
||||
|
||||
void SinglePlayerButton::onClick() {
|
||||
ConcreteGuiManager::getSingleton()->readLuaScreenScript("singlePlayerMenu.lua");
|
||||
|
||||
Listbox *listbox = ConcreteGuiManager::getSingleton()->getListboxes()[0];
|
||||
listbox->openUp();
|
||||
listbox->close();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user