variable number of CPU player listboxes in map selection screens

This commit is contained in:
devZoGok
2025-03-02 16:16:55 +02:00
parent a1011e14f0
commit ae3e9b8b73
10 changed files with 76 additions and 90 deletions
+1
View File
@@ -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
},
+4 -52
View File
@@ -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}
space = 60
gui = {
{
pos = Pos,
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)},
pos = {x = Pos.x, y = Pos.y + (#factions * Size.y + 10) * (lineId + 1), z = Pos.z},
size = Size,
guiType = GuiType.LISTBOX,
numMaxDisplay = 3,
lines = factions,
listboxType = ListboxType.FACTIONS
},
}
+5 -15
View File
@@ -1,32 +1,22 @@
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 = {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},
pos = playerListboxPos,
size = Size,
guiType = GuiType.LISTBOX,
numMaxDisplay = 3,
lines = factions,
listboxType = ListboxType.FACTIONS
},
{
pos = {x = 110, y = 310, z = 0},
size = Size,
guiType = GuiType.LISTBOX,
addPlayerGui = true,
listboxType = ListboxType.MAPS,
numMaxDisplay = 5
},
+1 -1
View File
@@ -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)
+20 -6
View File
@@ -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"
@@ -167,7 +168,7 @@ namespace battleship{
}
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);
break;
@@ -293,11 +294,19 @@ 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";
switch(listboxType){
@@ -326,14 +335,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:{
@@ -386,7 +397,7 @@ namespace battleship{
listbox = new Listbox(pos, size, lines, maxDisplay, fontPath);
break;
case FACTIONS:
lines = vector<string>{"Empire", "Mutants", "Shapeshifters"};
//lines = vector<string>{"America inc.", "European Republic", "Asian Co-Prosperity Sphere"};
numLines = lines.size();
closable = true;
maxDisplay = (numLines > numMaxDisplay ? numMaxDisplay : numLines);
@@ -552,7 +563,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);
+1
View File
@@ -82,6 +82,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);
+10 -4
View File
@@ -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 = getNumSpawnPoints();
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"]));
}
}
+1
View File
@@ -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;}
+25 -11
View File
@@ -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,33 @@ 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++){
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
View File
@@ -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;
};
}