diff --git a/Assets/Scripts/Gui/loadMap.lua b/Assets/Scripts/Gui/loadMap.lua index f77ec44..6538fda 100644 --- a/Assets/Scripts/Gui/loadMap.lua +++ b/Assets/Scripts/Gui/loadMap.lua @@ -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 }, diff --git a/Assets/Scripts/Gui/playerSelection.lua b/Assets/Scripts/Gui/playerSelection.lua index f6f09d2..f7f18d5 100644 --- a/Assets/Scripts/Gui/playerSelection.lua +++ b/Assets/Scripts/Gui/playerSelection.lua @@ -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 }, } diff --git a/Assets/Scripts/Gui/singlePlayerMenu.lua b/Assets/Scripts/Gui/singlePlayerMenu.lua index d43e620..3fdd312 100644 --- a/Assets/Scripts/Gui/singlePlayerMenu.lua +++ b/Assets/Scripts/Gui/singlePlayerMenu.lua @@ -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 }, diff --git a/CMakeLists.txt b/CMakeLists.txt index 92806cf..cb5a78a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/concreteGuiManager.cpp b/concreteGuiManager.cpp index d8c950a..9fbbd16 100644 --- a/concreteGuiManager.cpp +++ b/concreteGuiManager.cpp @@ -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 lines; int maxDisplay, numLines; bool closable; - Listbox *listbox = nullptr; + vector lines; + sol::optional 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{"Empire", "Mutants", "Shapeshifters"}; + //lines = vector{"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); diff --git a/concreteGuiManager.h b/concreteGuiManager.h index 36b3340..45c24e5 100644 --- a/concreteGuiManager.h +++ b/concreteGuiManager.h @@ -82,6 +82,7 @@ namespace battleship{ std::vector = std::vector{}, std::vector = std::vector{} ); + void parseLuaScript(std::string); private: ConcreteGuiManager(); vb01Gui::Button* parseButton(int); diff --git a/map.cpp b/map.cpp index 749e2e4..fde0027 100755 --- a/map.cpp +++ b/map.cpp @@ -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"])); } } diff --git a/map.h b/map.h index 1348358..3dfb454 100755 --- a/map.h +++ b/map.h @@ -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;} diff --git a/mapListbox.cpp b/mapListbox.cpp index f187d3f..982bc09 100644 --- a/mapListbox.cpp +++ b/mapListbox.cpp @@ -3,6 +3,8 @@ #include "concreteGuiManager.h" #include "gameManager.h" +#include + #include #include #include @@ -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 &lines, int maxDisplay, string fontPath, bool closeable) : Listbox(pos, size, lines, maxDisplay, fontPath, closeable){} + MapListbox::MapListbox(Vector3 pos, Vector2 size, std::vector &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 buttons = guiManager->getButtons(); - guiManager->readLuaScreenScript("playerSelection.lua", buttons, vector{mapListbox}, vector{}, vector{}, vector{}, vector{}, vector{}, 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 listboxes = guiManager->getListboxes(); + cpuPlayerListboxes.push_back(listboxes[listboxes.size() - 1]); + } + } } } diff --git a/mapListbox.h b/mapListbox.h index ffe9c16..3464735 100644 --- a/mapListbox.h +++ b/mapListbox.h @@ -3,12 +3,19 @@ #include +namespace vb01Gui{ + class Listbox; +} + namespace battleship{ class MapListbox : public vb01Gui::Listbox{ public: - MapListbox(vb01::Vector2, vb01::Vector2, std::vector&, int, std::string, bool); + MapListbox(vb01::Vector3, vb01::Vector2, std::vector&, int, bool, std::string, bool); private: void onClose(); + + bool addPlayerGui; + std::vector cpuPlayerListboxes; }; }