mirror of
https://github.com/ApfelTeeSaft/PlanetFleet.git
synced 2026-08-26 19:33:38 +00:00
variable number of CPU player listboxes in map selection screens
This commit is contained in:
@@ -4,6 +4,7 @@ gui = {
|
|||||||
pos = {x = 110, y = 190, z = 0},
|
pos = {x = 110, y = 190, z = 0},
|
||||||
size = {x = 360, y = 20},
|
size = {x = 360, y = 20},
|
||||||
guiType = GuiType.LISTBOX,
|
guiType = GuiType.LISTBOX,
|
||||||
|
addPlayerGui = false,
|
||||||
listboxType = ListboxType.MAPS,
|
listboxType = ListboxType.MAPS,
|
||||||
numMaxDisplay = 5
|
numMaxDisplay = 5
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,62 +1,14 @@
|
|||||||
Pos = {x = 110, y = 150, z = 0}
|
--playerListboxPos = {x = 210, y = 100, z = 0}
|
||||||
|
Pos = {x = playerListboxPos.x, y = playerListboxPos.y, z = playerListboxPos.z}
|
||||||
Size = {x = 100, y = 20}
|
Size = {x = 100, y = 20}
|
||||||
space = 60
|
|
||||||
|
|
||||||
gui = {
|
gui = {
|
||||||
{
|
{
|
||||||
pos = Pos,
|
pos = {x = Pos.x, y = Pos.y + (#factions * Size.y + 10) * (lineId + 1), z = Pos.z},
|
||||||
size = Size,
|
|
||||||
guiType = GuiType.LISTBOX,
|
|
||||||
numMaxDisplay = 3,
|
|
||||||
listboxType = ListboxType.FACTIONS
|
|
||||||
},
|
|
||||||
{
|
|
||||||
pos = {x = Pos.x, y = Pos.y + Size.y + space},
|
|
||||||
size = Size,
|
|
||||||
guiType = GuiType.LISTBOX,
|
|
||||||
numMaxDisplay = 3,
|
|
||||||
listboxType = ListboxType.FACTIONS
|
|
||||||
},
|
|
||||||
{
|
|
||||||
pos = {x = Pos.x, y = Pos.y + 2 * (Size.y + space)},
|
|
||||||
size = Size,
|
|
||||||
guiType = GuiType.LISTBOX,
|
|
||||||
numMaxDisplay = 3,
|
|
||||||
listboxType = ListboxType.FACTIONS
|
|
||||||
},
|
|
||||||
{
|
|
||||||
pos = {x = Pos.x, y = Pos.y + 3 * (Size.y + space)},
|
|
||||||
size = Size,
|
|
||||||
guiType = GuiType.LISTBOX,
|
|
||||||
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,
|
size = Size,
|
||||||
guiType = GuiType.LISTBOX,
|
guiType = GuiType.LISTBOX,
|
||||||
numMaxDisplay = 3,
|
numMaxDisplay = 3,
|
||||||
|
lines = factions,
|
||||||
listboxType = ListboxType.FACTIONS
|
listboxType = ListboxType.FACTIONS
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,32 +1,22 @@
|
|||||||
Size = {x = 100, y = 20}
|
Size = {x = 100, y = 20}
|
||||||
|
playerListboxPos = {x = 110, y = 10, z = 0}
|
||||||
|
factions = {"America inc.", "European Republic", "Asian Co-Prosperity Sphere"}
|
||||||
|
|
||||||
numGui = 6
|
numGui = 6
|
||||||
gui = {
|
gui = {
|
||||||
{
|
{
|
||||||
pos = {x = 100, y = 100, z = 0},
|
pos = playerListboxPos,
|
||||||
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,
|
size = Size,
|
||||||
guiType = GuiType.LISTBOX,
|
guiType = GuiType.LISTBOX,
|
||||||
numMaxDisplay = 3,
|
numMaxDisplay = 3,
|
||||||
|
lines = factions,
|
||||||
listboxType = ListboxType.FACTIONS
|
listboxType = ListboxType.FACTIONS
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
pos = {x = 110, y = 310, z = 0},
|
pos = {x = 110, y = 310, z = 0},
|
||||||
size = Size,
|
size = Size,
|
||||||
guiType = GuiType.LISTBOX,
|
guiType = GuiType.LISTBOX,
|
||||||
|
addPlayerGui = true,
|
||||||
listboxType = ListboxType.MAPS,
|
listboxType = ListboxType.MAPS,
|
||||||
numMaxDisplay = 5
|
numMaxDisplay = 5
|
||||||
},
|
},
|
||||||
|
|||||||
+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(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(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(GUI tooltip.cpp concreteGuiManager.cpp ${BUTTONS} ${LISTBOXES})
|
||||||
|
|
||||||
set(STATES activeGameState.cpp inGameAppState.cpp guiAppState.cpp mapEditorAppState.cpp)
|
set(STATES activeGameState.cpp inGameAppState.cpp guiAppState.cpp mapEditorAppState.cpp)
|
||||||
|
|||||||
+20
-6
@@ -15,6 +15,7 @@
|
|||||||
#include "newMapButton.h"
|
#include "newMapButton.h"
|
||||||
#include "loadMapButton.h"
|
#include "loadMapButton.h"
|
||||||
#include "exportButton.h"
|
#include "exportButton.h"
|
||||||
|
#include "mapListbox.h"
|
||||||
#include "skyboxTextureListbox.h"
|
#include "skyboxTextureListbox.h"
|
||||||
#include "landTextureListbox.h"
|
#include "landTextureListbox.h"
|
||||||
#include "gameObjectListbox.h"
|
#include "gameObjectListbox.h"
|
||||||
@@ -167,7 +168,7 @@ namespace battleship{
|
|||||||
}
|
}
|
||||||
|
|
||||||
int mid = guiTable["dependencies"][4]["id"];
|
int mid = guiTable["dependencies"][4]["id"];
|
||||||
Listbox *mapListbox = (Listbox*)guiElements[mid].second;
|
Listbox *mapListbox = (MapListbox*)guiElements[mid].second;
|
||||||
|
|
||||||
button = new PlayButton(difficultyListboxes, factionsListboxes, mapListbox, pos, size, name, true);
|
button = new PlayButton(difficultyListboxes, factionsListboxes, mapListbox, pos, size, name, true);
|
||||||
break;
|
break;
|
||||||
@@ -293,11 +294,19 @@ namespace battleship{
|
|||||||
int numMaxDisplay = guiTable["numMaxDisplay"];
|
int numMaxDisplay = guiTable["numMaxDisplay"];
|
||||||
ListboxType listboxType = (ListboxType)guiTable["listboxType"];
|
ListboxType listboxType = (ListboxType)guiTable["listboxType"];
|
||||||
|
|
||||||
vector<string> lines;
|
|
||||||
int maxDisplay, numLines;
|
int maxDisplay, numLines;
|
||||||
bool closable;
|
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";
|
string fontPath = fontBasePath + "batang.ttf";
|
||||||
|
|
||||||
switch(listboxType){
|
switch(listboxType){
|
||||||
@@ -326,14 +335,16 @@ namespace battleship{
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case MAPS:
|
case MAPS:{
|
||||||
lines = readDir(GameManager::getSingleton()->getPath() + "Models/Maps/", true);
|
lines = readDir(GameManager::getSingleton()->getPath() + "Models/Maps/", true);
|
||||||
numLines = lines.size();
|
numLines = lines.size();
|
||||||
closable = true;
|
closable = true;
|
||||||
maxDisplay = (numLines > numMaxDisplay ? numMaxDisplay : numLines);
|
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;
|
break;
|
||||||
|
}
|
||||||
case VEHICLES:
|
case VEHICLES:
|
||||||
case STRUCTURES:
|
case STRUCTURES:
|
||||||
case RESOURCE_DEPOSITS:{
|
case RESOURCE_DEPOSITS:{
|
||||||
@@ -386,7 +397,7 @@ namespace battleship{
|
|||||||
listbox = new Listbox(pos, size, lines, maxDisplay, fontPath);
|
listbox = new Listbox(pos, size, lines, maxDisplay, fontPath);
|
||||||
break;
|
break;
|
||||||
case FACTIONS:
|
case FACTIONS:
|
||||||
lines = vector<string>{"Empire", "Mutants", "Shapeshifters"};
|
//lines = vector<string>{"America inc.", "European Republic", "Asian Co-Prosperity Sphere"};
|
||||||
numLines = lines.size();
|
numLines = lines.size();
|
||||||
closable = true;
|
closable = true;
|
||||||
maxDisplay = (numLines > numMaxDisplay ? numMaxDisplay : numLines);
|
maxDisplay = (numLines > numMaxDisplay ? numMaxDisplay : numLines);
|
||||||
@@ -552,7 +563,10 @@ namespace battleship{
|
|||||||
){
|
){
|
||||||
removeAllGuiElements(buttonExceptions, listboxExceptions, checkboxExceptions, sliderExceptions, textboxExceptions, guiRecttboxExceptions, textExceptions);
|
removeAllGuiElements(buttonExceptions, listboxExceptions, checkboxExceptions, sliderExceptions, textboxExceptions, guiRecttboxExceptions, textExceptions);
|
||||||
guiElements.clear();
|
guiElements.clear();
|
||||||
|
parseLuaScript(script);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ConcreteGuiManager::parseLuaScript(string script){
|
||||||
string basePath = GameManager::getSingleton()->getPath() + "Scripts/Gui/";
|
string basePath = GameManager::getSingleton()->getPath() + "Scripts/Gui/";
|
||||||
sol::state_view SOL_LUA_VIEW = generateView();
|
sol::state_view SOL_LUA_VIEW = generateView();
|
||||||
SOL_LUA_VIEW.script_file(basePath + script);
|
SOL_LUA_VIEW.script_file(basePath + script);
|
||||||
|
|||||||
@@ -82,6 +82,7 @@ namespace battleship{
|
|||||||
std::vector<vb01::Node*> = std::vector<vb01::Node*>{},
|
std::vector<vb01::Node*> = std::vector<vb01::Node*>{},
|
||||||
std::vector<vb01::Text*> = std::vector<vb01::Text*>{}
|
std::vector<vb01::Text*> = std::vector<vb01::Text*>{}
|
||||||
);
|
);
|
||||||
|
void parseLuaScript(std::string);
|
||||||
private:
|
private:
|
||||||
ConcreteGuiManager();
|
ConcreteGuiManager();
|
||||||
vb01Gui::Button* parseButton(int);
|
vb01Gui::Button* parseButton(int);
|
||||||
|
|||||||
@@ -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(){
|
void Map::loadSpawnPoints(){
|
||||||
sol::state_view SOL_LUA_VIEW = generateView();
|
sol::state_view SOL_LUA_VIEW = generateView();
|
||||||
string spawnPointInd = "spawnPoints";
|
int numSpawnPoints = getNumSpawnPoints();
|
||||||
sol::table spawnPointsTbl = SOL_LUA_VIEW[mapTable][spawnPointInd];
|
|
||||||
int numSpawnPoints = spawnPointsTbl.size();
|
|
||||||
|
|
||||||
for(int i = 0; i < numSpawnPoints; i++){
|
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"]));
|
spawnPoints.push_back(Vector3(posTable["x"], posTable["y"], posTable["z"]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -76,6 +76,7 @@ namespace battleship{
|
|||||||
int getCellId(vb01::Vector3, bool = true);
|
int getCellId(vb01::Vector3, bool = true);
|
||||||
bool isPointWithinTerrainObject(vb01::Vector3, int);
|
bool isPointWithinTerrainObject(vb01::Vector3, int);
|
||||||
void loadPlayerGameObjects();
|
void loadPlayerGameObjects();
|
||||||
|
int getNumMapSpawnPoints(std::string = "");
|
||||||
inline std::string getMapName(){return mapName;}
|
inline std::string getMapName(){return mapName;}
|
||||||
inline vb01::Node* getNodeParent(){return terrainNode;}
|
inline vb01::Node* getNodeParent(){return terrainNode;}
|
||||||
inline vb01::Vector3 getCellSize(){return CELL_SIZE;}
|
inline vb01::Vector3 getCellSize(){return CELL_SIZE;}
|
||||||
|
|||||||
+24
-10
@@ -3,6 +3,8 @@
|
|||||||
#include "concreteGuiManager.h"
|
#include "concreteGuiManager.h"
|
||||||
#include "gameManager.h"
|
#include "gameManager.h"
|
||||||
|
|
||||||
|
#include <solUtil.h>
|
||||||
|
|
||||||
#include <button.h>
|
#include <button.h>
|
||||||
#include <checkbox.h>
|
#include <checkbox.h>
|
||||||
#include <slider.h>
|
#include <slider.h>
|
||||||
@@ -14,21 +16,33 @@ namespace battleship{
|
|||||||
using namespace vb01;
|
using namespace vb01;
|
||||||
using namespace vb01Gui;
|
using namespace vb01Gui;
|
||||||
using namespace std;
|
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(){
|
void MapListbox::onClose(){
|
||||||
|
if(addPlayerGui){
|
||||||
ConcreteGuiManager *guiManager = ConcreteGuiManager::getSingleton();
|
ConcreteGuiManager *guiManager = ConcreteGuiManager::getSingleton();
|
||||||
|
|
||||||
Listbox *mapListbox = guiManager->getListboxes()[0];
|
for(Listbox *listbox : cpuPlayerListboxes)
|
||||||
int selectedMap = mapListbox->getSelectedOption();
|
guiManager->removeListbox(listbox);
|
||||||
string mapName = wstringToString(mapListbox->getContents()[selectedMap]);
|
|
||||||
string mapPath = GameManager::getSingleton()->getPath() + "Models/Maps/" + mapName + "/" + mapName + ".lua";
|
|
||||||
int numSpawnPoints = Map::getNumSpawnPointsByMap(mapPath);
|
|
||||||
|
|
||||||
guiManager->readLuaScreenScript("singlePlayerMenu.lua");
|
cpuPlayerListboxes.clear();
|
||||||
mapListbox = guiManager->getListboxes()[0];
|
|
||||||
vector<Button*> buttons = guiManager->getButtons();
|
string mapName = wstringToString(getContents()[getSelectedOption()]);
|
||||||
guiManager->readLuaScreenScript("playerSelection.lua", buttons, vector<Listbox*>{mapListbox}, vector<Checkbox*>{}, vector<Slider*>{}, vector<Textbox*>{}, vector<Node*>{}, vector<Text*>{}, numSpawnPoints);
|
int numSpawnPoints = Map::getSingleton()->getNumMapSpawnPoints(mapName);
|
||||||
|
sol::state_view SOL_LUA_VIEW = generateView();
|
||||||
|
|
||||||
|
for(int i = 0; i < numSpawnPoints; i++){
|
||||||
|
SOL_LUA_VIEW.script("lineId = " + to_string(i));
|
||||||
|
guiManager->parseLuaScript("playerSelection.lua");
|
||||||
|
|
||||||
|
std::vector<Listbox*> listboxes = guiManager->getListboxes();
|
||||||
|
cpuPlayerListboxes.push_back(listboxes[listboxes.size() - 1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+8
-1
@@ -3,12 +3,19 @@
|
|||||||
|
|
||||||
#include <listbox.h>
|
#include <listbox.h>
|
||||||
|
|
||||||
|
namespace vb01Gui{
|
||||||
|
class Listbox;
|
||||||
|
}
|
||||||
|
|
||||||
namespace battleship{
|
namespace battleship{
|
||||||
class MapListbox : public vb01Gui::Listbox{
|
class MapListbox : public vb01Gui::Listbox{
|
||||||
public:
|
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:
|
private:
|
||||||
void onClose();
|
void onClose();
|
||||||
|
|
||||||
|
bool addPlayerGui;
|
||||||
|
std::vector<vb01Gui::Listbox*> cpuPlayerListboxes;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user