mirror of
https://github.com/devZoGok/PlanetFleet.git
synced 2026-08-26 19:43:29 +00:00
Merge pull request #185 from devZoGok/ft-183-selectable-players
Ft 183 selectable players
This commit is contained in:
@@ -4,6 +4,7 @@ gui = {
|
||||
pos = {x = 110, y = 190, z = 0},
|
||||
size = {x = 360, y = 20},
|
||||
guiType = GuiType.LISTBOX,
|
||||
addPlayerGui = false,
|
||||
listboxType = ListboxType.MAPS,
|
||||
numMaxDisplay = 5
|
||||
},
|
||||
|
||||
@@ -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,62 +1,49 @@
|
||||
Pos = {x = 110, y = 150, z = 0}
|
||||
Size = {x = 100, y = 20}
|
||||
space = 60
|
||||
playerListboxPos = {x = 110, y = 10, z = 0}
|
||||
Pos = {x = playerListboxPos.x, y = playerListboxPos.y, z = playerListboxPos.z}
|
||||
Size = {x = 150, y = 20}
|
||||
gap = 10
|
||||
gapFactor = 3
|
||||
|
||||
factions = {'None', "America inc.", "European Republic", "Asian Co-Prosperity Sphere"}
|
||||
difficulties = {"Easy", "Medium", "Hard"}
|
||||
colors = {'White', 'Black', 'Red'}
|
||||
teams = {'0', '1', '2', '3', '4'}
|
||||
|
||||
gui = {
|
||||
{
|
||||
pos = Pos,
|
||||
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, y = Pos.y + Size.y + space},
|
||||
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,
|
||||
listboxType = ListboxType.FACTIONS
|
||||
lines = difficulties,
|
||||
listboxType = ListboxType.CPU_DIFFICULTIES
|
||||
},
|
||||
{
|
||||
pos = {x = Pos.x, y = Pos.y + 2 * (Size.y + space)},
|
||||
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,
|
||||
listboxType = ListboxType.FACTIONS
|
||||
lines = colors,
|
||||
listboxType = ListboxType.COLORS
|
||||
},
|
||||
{
|
||||
pos = {x = Pos.x, y = Pos.y + 3 * (Size.y + space)},
|
||||
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,
|
||||
listboxType = ListboxType.FACTIONS
|
||||
},
|
||||
{
|
||||
pos = {x = Pos.x, y = Pos.y + 4 * (Size.y + space)},
|
||||
size = Size,
|
||||
guiType = GuiType.LISTBOX,
|
||||
numMaxDisplay = 3,
|
||||
listboxType = ListboxType.FACTIONS
|
||||
},
|
||||
{
|
||||
pos = {x = Pos.x, y = Pos.y + 5 * (Size.y + space)},
|
||||
size = Size,
|
||||
guiType = GuiType.LISTBOX,
|
||||
numMaxDisplay = 3,
|
||||
listboxType = ListboxType.FACTIONS
|
||||
},
|
||||
{
|
||||
pos = {x = Pos.x, y = Pos.y + 6 * (Size.y + space)},
|
||||
size = Size,
|
||||
guiType = GuiType.LISTBOX,
|
||||
numMaxDisplay = 3,
|
||||
listboxType = ListboxType.FACTIONS
|
||||
},
|
||||
{
|
||||
pos = {x = Pos.x, y = Pos.y + 7 * (Size.y + space)},
|
||||
size = Size,
|
||||
guiType = GuiType.LISTBOX,
|
||||
numMaxDisplay = 3,
|
||||
listboxType = ListboxType.FACTIONS
|
||||
lines = teams,
|
||||
listboxType = ListboxType.TEAMS
|
||||
},
|
||||
}
|
||||
|
||||
@@ -1,32 +1,11 @@
|
||||
Size = {x = 100, y = 20}
|
||||
|
||||
numGui = 6
|
||||
gui = {
|
||||
{
|
||||
pos = {x = 100, y = 100, z = 0},
|
||||
size = Size,
|
||||
guiType = GuiType.LISTBOX,
|
||||
numMaxDisplay = 3,
|
||||
listboxType = ListboxType.CPU_DIFFICULTIES
|
||||
},
|
||||
{
|
||||
pos = {x = 210, y = 100, z = 0},
|
||||
size = Size,
|
||||
guiType = GuiType.LISTBOX,
|
||||
numMaxDisplay = 3,
|
||||
listboxType = ListboxType.FACTIONS
|
||||
},
|
||||
{
|
||||
pos = {x = 100, y = 230, z = 0},
|
||||
size = Size,
|
||||
guiType = GuiType.LISTBOX,
|
||||
numMaxDisplay = 3,
|
||||
listboxType = ListboxType.FACTIONS
|
||||
},
|
||||
{
|
||||
pos = {x = 110, y = 310, z = 0},
|
||||
size = Size,
|
||||
guiType = GuiType.LISTBOX,
|
||||
addPlayerGui = true,
|
||||
listboxType = ListboxType.MAPS,
|
||||
numMaxDisplay = 5
|
||||
},
|
||||
@@ -37,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},
|
||||
|
||||
+1
-1
@@ -22,7 +22,7 @@ set(MENU_BUTTONS mainMenuButton.cpp singlePlayerButton.cpp exitButton.cpp backBu
|
||||
set(MAP_EDITOR_BUTTONS mapEditorButton.cpp newMapButton.cpp loadMapButton.cpp exportButton.cpp)
|
||||
set(BUTTONS statsButton.cpp activeStateButton.cpp minimapButton.cpp ${TRADING_BUTTONS} ${OPTIONS_BUTTONS} ${MENU_BUTTONS} ${MAP_EDITOR_BUTTONS} ${UNIT_BUTTONS})
|
||||
|
||||
set(LISTBOXES skyboxTextureListbox.cpp landTextureListbox.cpp gameObjectListbox.cpp)
|
||||
set(LISTBOXES skyboxTextureListbox.cpp landTextureListbox.cpp gameObjectListbox.cpp mapListbox.cpp)
|
||||
set(GUI tooltip.cpp concreteGuiManager.cpp ${BUTTONS} ${LISTBOXES})
|
||||
|
||||
set(STATES activeGameState.cpp inGameAppState.cpp guiAppState.cpp mapEditorAppState.cpp)
|
||||
|
||||
+29
-27
@@ -15,6 +15,7 @@
|
||||
#include "newMapButton.h"
|
||||
#include "loadMapButton.h"
|
||||
#include "exportButton.h"
|
||||
#include "mapListbox.h"
|
||||
#include "skyboxTextureListbox.h"
|
||||
#include "landTextureListbox.h"
|
||||
#include "gameObjectListbox.h"
|
||||
@@ -155,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"];
|
||||
Listbox *mapListbox = (Listbox*)guiElements[mid].second;
|
||||
|
||||
button = new PlayButton(difficultyListboxes, factionsListboxes, mapListbox, pos, size, name, true);
|
||||
int mid = guiTable["dependencies"][1]["id"];
|
||||
Listbox *mapListbox = (MapListbox*)guiElements[mid].second;
|
||||
button = new PlayButton(mapListbox, pos, size, name, true);
|
||||
break;
|
||||
}
|
||||
case RESUME:
|
||||
@@ -293,12 +282,24 @@ namespace battleship{
|
||||
int numMaxDisplay = guiTable["numMaxDisplay"];
|
||||
ListboxType listboxType = (ListboxType)guiTable["listboxType"];
|
||||
|
||||
vector<string> lines;
|
||||
int maxDisplay, numLines;
|
||||
bool closable;
|
||||
Listbox *listbox = nullptr;
|
||||
vector<string> lines;
|
||||
sol::optional<sol::table> linesOpt = guiTable["lines"];
|
||||
|
||||
if(linesOpt != sol::nullopt){
|
||||
sol::table linesTbl = guiTable["lines"];
|
||||
|
||||
for(int i = 0; i < linesTbl.size(); i++)
|
||||
lines.push_back(guiTable["lines"][i + 1]);
|
||||
}
|
||||
|
||||
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:{
|
||||
@@ -326,14 +327,16 @@ namespace battleship{
|
||||
|
||||
break;
|
||||
}
|
||||
case MAPS:
|
||||
case MAPS:{
|
||||
lines = readDir(GameManager::getSingleton()->getPath() + "Models/Maps/", true);
|
||||
numLines = lines.size();
|
||||
closable = true;
|
||||
maxDisplay = (numLines > numMaxDisplay ? numMaxDisplay : numLines);
|
||||
bool addPlayers = guiTable["addPlayerGui"];
|
||||
|
||||
listbox = new Listbox(pos, size, lines, maxDisplay, fontPath, closable);
|
||||
listbox = new MapListbox(pos, size, lines, maxDisplay, addPlayers, fontPath, closable);
|
||||
break;
|
||||
}
|
||||
case VEHICLES:
|
||||
case STRUCTURES:
|
||||
case RESOURCE_DEPOSITS:{
|
||||
@@ -378,15 +381,9 @@ namespace battleship{
|
||||
listbox = new LandTextureListbox(pos, size, lines, maxDisplay, fontPath);
|
||||
break;
|
||||
case CPU_DIFFICULTIES:
|
||||
lines = vector<string>{"Easy", "Medium", "Hard"};
|
||||
numLines = lines.size();
|
||||
closable = true;
|
||||
maxDisplay = (numLines > numMaxDisplay ? numMaxDisplay : numLines);
|
||||
|
||||
listbox = new Listbox(pos, size, lines, maxDisplay, fontPath);
|
||||
break;
|
||||
case FACTIONS:
|
||||
lines = vector<string>{"Empire", "Mutants", "Shapeshifters"};
|
||||
case COLORS:
|
||||
case TEAMS:
|
||||
numLines = lines.size();
|
||||
closable = true;
|
||||
maxDisplay = (numLines > numMaxDisplay ? numMaxDisplay : numLines);
|
||||
@@ -412,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;
|
||||
}
|
||||
|
||||
@@ -552,7 +551,10 @@ namespace battleship{
|
||||
){
|
||||
removeAllGuiElements(buttonExceptions, listboxExceptions, checkboxExceptions, sliderExceptions, textboxExceptions, guiRecttboxExceptions, textExceptions);
|
||||
guiElements.clear();
|
||||
parseLuaScript(script);
|
||||
}
|
||||
|
||||
void ConcreteGuiManager::parseLuaScript(string script){
|
||||
string basePath = GameManager::getSingleton()->getPath() + "Scripts/Gui/";
|
||||
sol::state_view SOL_LUA_VIEW = generateView();
|
||||
SOL_LUA_VIEW.script_file(basePath + script);
|
||||
|
||||
@@ -65,6 +65,8 @@ namespace battleship{
|
||||
LAND_TEXTURES,
|
||||
CPU_DIFFICULTIES,
|
||||
FACTIONS,
|
||||
COLORS,
|
||||
TEAMS,
|
||||
CONSOLE,
|
||||
TRADE_OFFERS
|
||||
};
|
||||
@@ -82,6 +84,7 @@ namespace battleship{
|
||||
std::vector<vb01::Node*> = std::vector<vb01::Node*>{},
|
||||
std::vector<vb01::Text*> = std::vector<vb01::Text*>{}
|
||||
);
|
||||
void parseLuaScript(std::string);
|
||||
private:
|
||||
ConcreteGuiManager();
|
||||
vb01Gui::Button* parseButton(int);
|
||||
|
||||
+5
-27
@@ -45,41 +45,19 @@ 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->setPosition(Map::getSingleton()->getSpawnPoint(playerId) + Vector3(1, 1, 1) * configData::CAMERA_DISTANCE);
|
||||
cam->lookAt(Vector3(0, -1, -1).norm(), Vector3(0, 1, -1).norm());
|
||||
|
||||
mainPlayer = Game::getSingleton()->getPlayer(playerId);
|
||||
|
||||
+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;
|
||||
|
||||
@@ -374,14 +374,20 @@ namespace battleship{
|
||||
}
|
||||
}
|
||||
|
||||
int Map::getNumMapSpawnPoints(string name){
|
||||
if(name != "")
|
||||
generateView().script_file(GameManager::getSingleton()->getPath() + "Models/Maps/" + name + "/" + name + ".lua");
|
||||
|
||||
sol::table spawnPointsTbl = generateView()["map"]["spawnPoints"];
|
||||
return spawnPointsTbl.size();
|
||||
}
|
||||
|
||||
void Map::loadSpawnPoints(){
|
||||
sol::state_view SOL_LUA_VIEW = generateView();
|
||||
string spawnPointInd = "spawnPoints";
|
||||
sol::table spawnPointsTbl = SOL_LUA_VIEW[mapTable][spawnPointInd];
|
||||
int numSpawnPoints = spawnPointsTbl.size();
|
||||
int numSpawnPoints = getNumMapSpawnPoints();
|
||||
|
||||
for(int i = 0; i < numSpawnPoints; i++){
|
||||
sol::table posTable = SOL_LUA_VIEW[mapTable][spawnPointInd][i + 1];
|
||||
sol::table posTable = SOL_LUA_VIEW[mapTable]["spawnPoints"][i + 1];
|
||||
spawnPoints.push_back(Vector3(posTable["x"], posTable["y"], posTable["z"]));
|
||||
}
|
||||
}
|
||||
@@ -397,9 +403,8 @@ namespace battleship{
|
||||
assetManager->load(path + vfxPrefix, true);
|
||||
assetManager->load(path + gameObjPrefix, true);
|
||||
|
||||
int numPlayers = Game::getSingleton()->getNumPlayers();
|
||||
string playerInd = "players";
|
||||
SOL_LUA_VIEW.script("numPlayers = #" + mapTable + "." + playerInd);
|
||||
int numPlayers = SOL_LUA_VIEW["numPlayers"];
|
||||
|
||||
for(int i = 0; i < numPlayers; i++){
|
||||
string resDepInd = "resourceDeposits";
|
||||
|
||||
@@ -76,6 +76,7 @@ namespace battleship{
|
||||
int getCellId(vb01::Vector3, bool = true);
|
||||
bool isPointWithinTerrainObject(vb01::Vector3, int);
|
||||
void loadPlayerGameObjects();
|
||||
int getNumMapSpawnPoints(std::string = "");
|
||||
inline std::string getMapName(){return mapName;}
|
||||
inline vb01::Node* getNodeParent(){return terrainNode;}
|
||||
inline vb01::Vector3 getCellSize(){return CELL_SIZE;}
|
||||
|
||||
+29
-11
@@ -3,6 +3,8 @@
|
||||
#include "concreteGuiManager.h"
|
||||
#include "gameManager.h"
|
||||
|
||||
#include <solUtil.h>
|
||||
|
||||
#include <button.h>
|
||||
#include <checkbox.h>
|
||||
#include <slider.h>
|
||||
@@ -14,21 +16,37 @@ namespace battleship{
|
||||
using namespace vb01;
|
||||
using namespace vb01Gui;
|
||||
using namespace std;
|
||||
using namespace gameBase;
|
||||
|
||||
MapListbox::MapListbox(Vector2 pos, Vector2 size, std::vector<string> &lines, int maxDisplay, string fontPath, bool closeable) : Listbox(pos, size, lines, maxDisplay, fontPath, closeable){}
|
||||
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) {}
|
||||
|
||||
void MapListbox::onClose(){
|
||||
ConcreteGuiManager *guiManager = ConcreteGuiManager::getSingleton();
|
||||
if(addPlayerGui){
|
||||
ConcreteGuiManager *guiManager = ConcreteGuiManager::getSingleton();
|
||||
|
||||
Listbox *mapListbox = guiManager->getListboxes()[0];
|
||||
int selectedMap = mapListbox->getSelectedOption();
|
||||
string mapName = wstringToString(mapListbox->getContents()[selectedMap]);
|
||||
string mapPath = GameManager::getSingleton()->getPath() + "Models/Maps/" + mapName + "/" + mapName + ".lua";
|
||||
int numSpawnPoints = Map::getNumSpawnPointsByMap(mapPath);
|
||||
for(Listbox *listbox : cpuPlayerListboxes)
|
||||
guiManager->removeListbox(listbox);
|
||||
|
||||
guiManager->readLuaScreenScript("singlePlayerMenu.lua");
|
||||
mapListbox = guiManager->getListboxes()[0];
|
||||
vector<Button*> buttons = guiManager->getButtons();
|
||||
guiManager->readLuaScreenScript("playerSelection.lua", buttons, vector<Listbox*>{mapListbox}, vector<Checkbox*>{}, vector<Slider*>{}, vector<Textbox*>{}, vector<Node*>{}, vector<Text*>{}, numSpawnPoints);
|
||||
cpuPlayerListboxes.clear();
|
||||
|
||||
string mapName = wstringToString(getContents()[getSelectedOption()]);
|
||||
int numSpawnPoints = Map::getSingleton()->getNumMapSpawnPoints(mapName);
|
||||
sol::state_view SOL_LUA_VIEW = generateView();
|
||||
|
||||
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 = listboxes.size() - prevNumListboxes;
|
||||
|
||||
for(int j = 0; j < diffNumListboxes; j++)
|
||||
cpuPlayerListboxes.push_back(listboxes[listboxes.size() - 1 - j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+8
-1
@@ -3,12 +3,19 @@
|
||||
|
||||
#include <listbox.h>
|
||||
|
||||
namespace vb01Gui{
|
||||
class Listbox;
|
||||
}
|
||||
|
||||
namespace battleship{
|
||||
class MapListbox : public vb01Gui::Listbox{
|
||||
public:
|
||||
MapListbox(vb01::Vector2, vb01::Vector2, std::vector<std::string>&, int, std::string, bool);
|
||||
MapListbox(vb01::Vector3, vb01::Vector2, std::vector<std::string>&, int, bool, std::string, bool);
|
||||
private:
|
||||
void onClose();
|
||||
|
||||
bool addPlayerGui;
|
||||
std::vector<vb01Gui::Listbox*> cpuPlayerListboxes;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
+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