diff --git a/Assets/Scripts/Gui/loadMap.lua b/Assets/Scripts/Gui/loadMap.lua index 29f5092..2e4b5f3 100644 --- a/Assets/Scripts/Gui/loadMap.lua +++ b/Assets/Scripts/Gui/loadMap.lua @@ -1,4 +1,4 @@ -numGui = 2 +numGui = 3 gui = { { pos = {x = 110, y = 190}, @@ -17,5 +17,13 @@ gui = { dependencies = { {dep = 0} } + }, + { + pos = {x = 420, y = 400}, + size = {x = 150, y = 50}, + guiType = GuiType.BUTTON, + name = 'Back', + buttonType = ButtonType.BACK, + screen = 'mapEditorMenu.lua' } } diff --git a/Assets/Scripts/Gui/main.lua b/Assets/Scripts/Gui/main.lua index 178babf..c665673 100644 --- a/Assets/Scripts/Gui/main.lua +++ b/Assets/Scripts/Gui/main.lua @@ -16,11 +16,15 @@ ButtonType = { NEW_MAP = 12, NEW_MAP_OK = 13, LOAD_MAP = 14, - LOAD_MAP_OK = 15 + LOAD_MAP_OK = 15, + EXPORT = 16 } ListboxType = { CONTROLS = 0, RESOLUTION = 1, - MAPS = 2 + MAPS = 2, + UNITS = 3, + SKYBOX_TEXTURES = 4, + LAND_TEXTURES = 5 } diff --git a/Assets/Scripts/Gui/mapEditor.lua b/Assets/Scripts/Gui/mapEditor.lua new file mode 100644 index 0000000..07161aa --- /dev/null +++ b/Assets/Scripts/Gui/mapEditor.lua @@ -0,0 +1,43 @@ +numGui = 5 + +Size = {x = 140, y = 20} +startX = 100 +gui = { + { + pos = {x = startX, y = 400}, + size = Size, + guiType = GuiType.BUTTON, + buttonType = ButtonType.EXPORT, + name = 'Export' + }, + { + pos = {x = startX + Size.x + 10, y = 400}, + size = Size, + guiType = GuiType.LISTBOX, + listboxType = ListboxType.UNITS, + vehicles = true, + numMaxDisplay = 5 + }, + { + pos = {x = startX + 2 * (Size.x + 10), y = 400}, + size = Size, + guiType = GuiType.LISTBOX, + listboxType = ListboxType.UNITS, + vehicles = false, + numMaxDisplay = 5 + }, + { + pos = {x = startX + 3 * (Size.x + 10), y = 400}, + size = Size, + guiType = GuiType.LISTBOX, + listboxType = ListboxType.SKYBOX_TEXTURES, + numMaxDisplay = 5 + }, + { + pos = {x = startX + 4 * (Size.x + 10), y = 400}, + size = Size, + guiType = GuiType.LISTBOX, + listboxType = ListboxType.LAND_TEXTURES, + numMaxDisplay = 5 + } +} diff --git a/Assets/Scripts/Gui/mapEditorMenu.lua b/Assets/Scripts/Gui/mapEditorMenu.lua index 31f0603..c053a39 100644 --- a/Assets/Scripts/Gui/mapEditorMenu.lua +++ b/Assets/Scripts/Gui/mapEditorMenu.lua @@ -1,6 +1,6 @@ Size = {x = 150, y = 40} -numGui = 2 +numGui = 3 gui = { { pos = {x = 110, y = 40}, @@ -15,5 +15,13 @@ gui = { guiType = GuiType.BUTTON, name = 'Load map', buttonType = ButtonType.LOAD_MAP + }, + { + pos = {x = 110, y = 140}, + size = Size, + guiType = GuiType.BUTTON, + name = 'Back', + buttonType = ButtonType.BACK, + screen = 'mainMenu.lua' } } diff --git a/Assets/Scripts/Gui/newMap.lua b/Assets/Scripts/Gui/newMap.lua index 813b1e8..1b1a4d4 100644 --- a/Assets/Scripts/Gui/newMap.lua +++ b/Assets/Scripts/Gui/newMap.lua @@ -1,6 +1,6 @@ Size = {x = 140, y = 40} -numGui = 4 +numGui = 5 gui = { { pos = {x = 110, y = 150}, @@ -29,5 +29,13 @@ gui = { {id = 1}, {id = 2} } + }, + { + pos = {x = 250, y = 400}, + size = {x = 150, y = 50}, + guiType = GuiType.BUTTON, + name = 'Back', + buttonType = ButtonType.BACK, + screen = 'mapEditorMenu.lua' } } diff --git a/CMakeLists.txt b/CMakeLists.txt index 07417fe..d51a410 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,9 +8,12 @@ set(CMAKE_BUILD_TYPE Debug) set(BUILD_TESTS ON) cmake_policy(SET CMP0015 NEW) +set(BUTTONS singlePlayerButton.cpp mapEditorButton.cpp newMapButton.cpp loadMapButton.cpp optionsButton.cpp exitButton.cpp tabButton.cpp okButton.cpp defaultsButton.cpp backButton.cpp consoleCommand.cpp exportButton.cpp) +set(LISTBOXES skyboxTextureListbox.cpp landTextureListbox.cpp) +set(GUI tooltip.cpp concreteGuiManager.cpp ${BUTTONS} ${LISTBOXES}) + set(STATES activeGameState.cpp inGameAppState.cpp guiAppState.cpp mapEditorAppState.cpp) set(UTIL util.cpp binds.h) -set(GUI tooltip.cpp concreteGuiManager.cpp singlePlayerButton.cpp mapEditorButton.cpp newMapButton.cpp loadMapButton.cpp optionsButton.cpp exitButton.cpp tabButton.cpp okButton.cpp defaultsButton.cpp backButton.cpp consoleCommand.cpp) set(CONTROLLERS unitFrameController.cpp cameraController.cpp) set(CORE gameManager.cpp defConfigs.cpp ${CONTROLLERS}) set(PROJECTILES projectile.cpp) diff --git a/concreteGuiManager.cpp b/concreteGuiManager.cpp index e0b5cbc..4234e44 100644 --- a/concreteGuiManager.cpp +++ b/concreteGuiManager.cpp @@ -12,6 +12,9 @@ #include "backButton.h" #include "newMapButton.h" #include "loadMapButton.h" +#include "exportButton.h" +#include "skyboxTextureListbox.h" +#include "landTextureListbox.h" namespace battleship{ using namespace std; @@ -108,6 +111,9 @@ namespace battleship{ button = new LoadMapButton::OkButton(pos, size, (Listbox*)guiElements[lid].second); break; } + case EXPORT: + button = new ExportButton(pos, size); + break; } int typeArr[2]{(int)GuiElementType::BUTTON, (int)type}; @@ -134,6 +140,9 @@ namespace battleship{ vector lines; int maxDisplay, numLines; bool closable; + Listbox *listbox = nullptr; + + string fontPath = GameManager::getSingleton()->getPath() + "Fonts/batang.ttf"; switch(listboxType){ case CONTROLS:{ @@ -142,8 +151,12 @@ namespace battleship{ for(int i = 0; i < numLines; i++) lines.push_back(to_string(i)); - } + + maxDisplay = (numLines > numMaxDisplay ? numMaxDisplay : numLines); + listbox = new Listbox(pos, size, lines, maxDisplay, fontPath, closable); + break; + } case RESOLUTION:{ numLines = lm->getIntFromTable(guiTable, vector{Index(guiId + 1), Index("numLines")}); @@ -151,19 +164,59 @@ namespace battleship{ lines.push_back(lm->getStringFromTable(guiTable, vector{Index(guiId + 1), Index("lines"), Index(i + 1)})); closable = true; - } + maxDisplay = (numLines > numMaxDisplay ? numMaxDisplay : numLines); + + listbox = new Listbox(pos, size, lines, maxDisplay, fontPath, closable); + break; + } case MAPS: lines = readDir(GameManager::getSingleton()->getPath() + "Models/Maps/", true); numLines = lines.size(); closable = true; + maxDisplay = (numLines > numMaxDisplay ? numMaxDisplay : numLines); + + listbox = new Listbox(pos, size, lines, maxDisplay, fontPath, closable); + break; + case UNITS:{ + bool vehicles = lm->getBoolFromTable(guiTable, vector{Index(guiId + 1), Index("vehicles")}); + int numUnits = lm->getInt("numUnits"); + + for(int i = 0; i < numUnits; i++){ + bool v = lm->getBoolFromTable("isVehicle", vector{Index(i + 1)}); + + if(v == vehicles){ + string name = lm->getStringFromTable("name", vector{Index(i + 1)}); + lines.push_back(name); + } + + } + + numLines = lines.size(); + closable = true; + maxDisplay = (numLines > numMaxDisplay ? numMaxDisplay : numLines); + + listbox = new Listbox(pos, size, lines, maxDisplay, fontPath, closable); + break; + } + case SKYBOX_TEXTURES: + lines = readDir(GameManager::getSingleton()->getPath() + "Textures/Skyboxes", true); + numLines = lines.size(); + closable = true; + maxDisplay = (numLines > numMaxDisplay ? numMaxDisplay : numLines); + + listbox = new SkyboxTextureListbox(pos, size, lines, maxDisplay, fontPath); + break; + case LAND_TEXTURES: + lines = readDir(GameManager::getSingleton()->getPath() + "Textures/Landmass", false); + numLines = lines.size(); + closable = true; + maxDisplay = (numLines > numMaxDisplay ? numMaxDisplay : numLines); + + listbox = new LandTextureListbox(pos, size, lines, maxDisplay, fontPath); break; } - maxDisplay = (numLines > numMaxDisplay ? numMaxDisplay : numLines); - string fontPath = GameManager::getSingleton()->getPath() + "Fonts/batang.ttf"; - Listbox *listbox = new Listbox(pos, size, lines, maxDisplay, fontPath, closable); - int typeArr[2]{(int)GuiElementType::LISTBOX, (int)listboxType}; guiElements.push_back(make_pair(typeArr, (void*)listbox)); @@ -234,6 +287,8 @@ namespace battleship{ } void ConcreteGuiManager::readLuaScreenScript(string script){ + removeAllGuiElements(); + guiElements.clear(); LuaManager *lm = LuaManager::getSingleton(); diff --git a/concreteGuiManager.h b/concreteGuiManager.h index 26dfe8f..8d7aa6f 100644 --- a/concreteGuiManager.h +++ b/concreteGuiManager.h @@ -25,12 +25,16 @@ namespace battleship{ NEW_MAP, NEW_MAP_OK, LOAD_MAP, - LOAD_MAP_OK + LOAD_MAP_OK, + EXPORT }; enum ListboxType { CONTROLS, RESOLUTION, - MAPS + MAPS, + UNITS, + SKYBOX_TEXTURES, + LAND_TEXTURES }; class ConcreteGuiManager : public vb01Gui::AbstractGuiManager{ diff --git a/exportButton.cpp b/exportButton.cpp new file mode 100644 index 0000000..e8c4640 --- /dev/null +++ b/exportButton.cpp @@ -0,0 +1,20 @@ +#include "exportButton.h" +#include "gameManager.h" +#include "mapEditorAppState.h" + +#include + +namespace battleship{ + using namespace std; + using namespace vb01; + using namespace vb01Gui; + using namespace gameBase; + + ExportButton::ExportButton(Vector2 pos, Vector2 size) : Button(pos, size, "Export", GameManager::getSingleton()->getPath() + "Fonts/batang.ttf"){} + + void ExportButton::onClick(){ + StateManager *sm = GameManager::getSingleton()->getStateManager(); + MapEditorAppState::MapEditor *mapEditor = ((MapEditorAppState*)sm->getAppStateByType((int)AppStateType::MAP_EDITOR))->getMapEditor(); + mapEditor->exportMap(); + } +} diff --git a/exportButton.h b/exportButton.h new file mode 100644 index 0000000..698f9d0 --- /dev/null +++ b/exportButton.h @@ -0,0 +1,15 @@ +#ifndef EXPORT_BUTTON_H +#define EXPORT_BUTTON_H + +#include + +namespace battleship{ + class ExportButton : public vb01Gui::Button{ + public: + ExportButton(vb01::Vector2 pos, vb01::Vector2 size); + void onClick(); + }; +} + +#endif + diff --git a/landTextureListbox.cpp b/landTextureListbox.cpp new file mode 100644 index 0000000..e831f26 --- /dev/null +++ b/landTextureListbox.cpp @@ -0,0 +1,37 @@ +#include "landTextureListbox.h" +#include "mapEditorAppState.h" +#include "gameManager.h" + +#include +#include +#include +#include + +#include + +namespace battleship{ + using namespace std; + using namespace vb01; + using namespace vb01Gui; + using namespace gameBase; + + LandTextureListbox::LandTextureListbox(Vector2 pos, Vector2 size, vector lines, int maxDisplay, std::string fontPath) : Listbox(pos, size, lines, maxDisplay, fontPath){} + + void LandTextureListbox::onClose(){ + StateManager *sm = GameManager::getSingleton()->getStateManager(); + MapEditorAppState::MapEditor *mapEditor = ((MapEditorAppState*)sm->getAppStateByType((int)AppStateType::MAP_EDITOR))->getMapEditor(); + + Map *map = Map::getSingleton(); + Material *mat = map->getTerrainObject(0).node->getMesh(0)->getMaterial(); + Material::BoolUniform *texturingUniform = (Material::BoolUniform*)mat->getUniform("texturingEnabled"); + Texture *landTex = mapEditor->getLandmassTexture(selectedOption); + string texUni = "textures[0]"; + + if(!texturingUniform->value){ + texturingUniform->value = true; + mat->addTexUniform(texUni, landTex, false); + } + else + mat->setTexUniform(texUni, landTex, false); + } +} diff --git a/landTextureListbox.h b/landTextureListbox.h new file mode 100644 index 0000000..ac5ce5b --- /dev/null +++ b/landTextureListbox.h @@ -0,0 +1,16 @@ +#ifndef LAND_TEXTURE_LISTBOX_H +#define LAND_TEXTURE_LISTBOX_H + +#include + +namespace battleship{ + class LandTextureListbox : public vb01Gui::Listbox{ + public: + LandTextureListbox(vb01::Vector2, vb01::Vector2, std::vector, int, std::string); + void onClose(); + private: + }; +} + +#endif + diff --git a/loadMapButton.cpp b/loadMapButton.cpp index a78d43e..e7dd42b 100644 --- a/loadMapButton.cpp +++ b/loadMapButton.cpp @@ -1,11 +1,15 @@ #include "loadMapButton.h" #include "concreteGuiManager.h" #include "gameManager.h" +#include "mapEditorAppState.h" + +#include namespace battleship{ using namespace std; using namespace vb01; using namespace vb01Gui; + using namespace gameBase; LoadMapButton::OkButton::OkButton(vb01::Vector2 pos, vb01::Vector2 size, vb01Gui::Listbox *listbox) : Button(pos, size, "Ok", GameManager::getSingleton()->getPath() + "Fonts/batang.ttf"){ this->listbox = listbox; } @@ -22,18 +26,16 @@ namespace battleship{ guiState->removeButton(this); */ + StateManager *sm = GameManager::getSingleton()->getStateManager(); + string name = wstringToString(listbox->getContents()[listbox->getSelectedOption()]); + sm->attachAppState(new MapEditorAppState(name, Vector2::VEC_ZERO, false)); + ConcreteGuiManager::getSingleton()->readLuaScreenScript("mapEditor.lua"); } LoadMapButton::LoadMapButton(Vector2 pos, Vector2 size) : Button(pos, size, "Load map", GameManager::getSingleton()->getPath() + "Fonts/batang.ttf"){} void LoadMapButton::onClick(){ - ConcreteGuiManager *guiManager = ConcreteGuiManager::getSingleton(); - guiManager->removeAllButtons(); - guiManager->removeAllListboxes(); - guiManager->removeAllCheckboxes(); - guiManager->removeAllSliders(); - guiManager->removeAllTextboxes(); - guiManager->readLuaScreenScript("loadMap.lua"); + ConcreteGuiManager::getSingleton()->readLuaScreenScript("loadMap.lua"); /* GameManager *gm = GameManager::getSingleton(); diff --git a/mapEditorAppState.cpp b/mapEditorAppState.cpp index 31a5b46..97f2e7a 100644 --- a/mapEditorAppState.cpp +++ b/mapEditorAppState.cpp @@ -65,8 +65,6 @@ namespace battleship{ generatePlane(size); } - prepareGui(); - string basePath = GameManager::getSingleton()->getPath(); prepareTextures(basePath + "Textures/Skyboxes/", true, skyTextures); prepareTextures(basePath + "Textures/Landmass/", false, landmassTextures); @@ -198,8 +196,8 @@ namespace battleship{ prepareCellMarkers(map->getTerrainObject(0)); } - void MapEditorAppState::MapEditor::prepareGui(){ /* + void MapEditorAppState::MapEditor::prepareGui(){ GameManager *gm = GameManager::getSingleton(); StateManager *sm = gm->getStateManager(); GuiAppState *state = (GuiAppState*)sm->getAppStateByType((int)AppStateType::GUI_STATE); @@ -288,8 +286,8 @@ namespace battleship{ vector landTextures = readDir(gm->getPath() + "Textures/Landmass", false); LandTexListbox *landTexListbox = new LandTexListbox(startPos + 4 * offset, size, landTextures, (landTextures.size() > maxDisplay ? maxDisplay : landTextures.size()), fontPath); state->addListbox(landTexListbox); - */ } + */ void MapEditorAppState::MapEditor::prepareTextures(string basePath, bool skybox, vector &textures){ AssetManager *assetManager = AssetManager::getSingleton(); diff --git a/mapEditorAppState.h b/mapEditorAppState.h index f27c885..c301190 100644 --- a/mapEditorAppState.h +++ b/mapEditorAppState.h @@ -57,9 +57,10 @@ namespace battleship{ inline MovementAxis getMovementAxis(){return movementAxis;} inline void setMovementAxis(MovementAxis m){movementAxis = m;} inline bool isWeightsGenerated(){return weightsGenerated;} + inline vb01::Texture* getSkyTexture(int i){return skyTextures[i];} + inline vb01::Texture* getLandmassTexture(int i){return landmassTextures[i];} private: void generatePlane(vb01::Vector2); - void prepareGui(); void prepareTextures(std::string, bool, std::vector&); void toggleSelection(TerrainObject*, bool); void parseLandmass(); @@ -68,8 +69,6 @@ namespace battleship{ void deleteWeights(); void prepareTerrainObject(vb01::u32**, Cell*, int[3], float, bool); void prepareCellMarkers(TerrainObject&); - inline vb01::Texture* getSkyTexture(int i){return skyTextures[i];} - inline vb01::Texture* getLandmassTexture(int i){return landmassTextures[i];} Map *map; TerrainObject *selectedTerrainObject = nullptr; diff --git a/mapEditorButton.cpp b/mapEditorButton.cpp index c7ce59b..ed810a3 100644 --- a/mapEditorButton.cpp +++ b/mapEditorButton.cpp @@ -13,13 +13,7 @@ namespace battleship{ using namespace gameBase; void MapEditorButton::onClick(){ - ConcreteGuiManager *guiManager = ConcreteGuiManager::getSingleton(); - guiManager->removeAllButtons(); - guiManager->removeAllListboxes(); - guiManager->removeAllCheckboxes(); - guiManager->removeAllSliders(); - guiManager->removeAllTextboxes(); - guiManager->readLuaScreenScript("mapEditorMenu.lua"); + ConcreteGuiManager::getSingleton()->readLuaScreenScript("mapEditorMenu.lua"); /* GameManager *gm = GameManager::getSingleton(); GuiAppState *guiState = (GuiAppState*)gm->getStateManager()->getAppStateByType((int)AppStateType::GUI_STATE); diff --git a/newMapButton.cpp b/newMapButton.cpp index b4cbbf3..a6459ad 100644 --- a/newMapButton.cpp +++ b/newMapButton.cpp @@ -1,11 +1,18 @@ #include "newMapButton.h" -#include "concreteGuiManager.h" #include "gameManager.h" +#include "mapEditorAppState.h" +#include "concreteGuiManager.h" + +#include + +#include +#include namespace battleship{ using namespace std; using namespace vb01; using namespace vb01Gui; + using namespace gameBase; NewMapButton::OkButton::OkButton(vb01::Vector2 pos, vb01::Vector2 size, vb01Gui::Textbox *name, vb01Gui::Textbox *sx, vb01Gui::Textbox *sy) : Button(pos, size, "Ok", GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", -1, true){ this->name = name; @@ -14,6 +21,14 @@ namespace battleship{ } void NewMapButton::OkButton::onClick(){ + Vector2 size = Vector2( + atof(wstringToString(sizeX->getText()).c_str()), + atof(wstringToString(sizeY->getText()).c_str()) + ); + StateManager *stateManager = GameManager::getSingleton()->getStateManager(); + stateManager->attachAppState(new MapEditorAppState(wstringToString(name->getText()), size, true)); + + ConcreteGuiManager::getSingleton()->readLuaScreenScript("mapEditor.lua"); /* GameManager *gm = GameManager::getSingleton(); StateManager *stateManager = gm->getStateManager(); @@ -35,13 +50,7 @@ namespace battleship{ NewMapButton::NewMapButton(Vector2 pos, Vector2 size) : Button(pos, size, "New map", GameManager::getSingleton()->getPath() + "Fonts/batang.ttf"){} void NewMapButton::onClick(){ - ConcreteGuiManager *guiManager = ConcreteGuiManager::getSingleton(); - guiManager->removeAllButtons(); - guiManager->removeAllListboxes(); - guiManager->removeAllCheckboxes(); - guiManager->removeAllSliders(); - guiManager->removeAllTextboxes(); - guiManager->readLuaScreenScript("newMap.lua"); + ConcreteGuiManager::getSingleton()->readLuaScreenScript("newMap.lua"); /* GameManager *gm = GameManager::getSingleton(); diff --git a/skyboxTextureListbox.cpp b/skyboxTextureListbox.cpp new file mode 100644 index 0000000..ccc5d0a --- /dev/null +++ b/skyboxTextureListbox.cpp @@ -0,0 +1,31 @@ +#include "skyboxTextureListbox.h" +#include "gameManager.h" +#include "mapEditorAppState.h" + +#include + +#include +#include +#include +#include + +namespace battleship{ + using namespace std; + using namespace vb01; + using namespace vb01Gui; + using namespace gameBase; + + SkyboxTextureListbox::SkyboxTextureListbox(Vector2 pos, Vector2 size, vector lines, int maxDisplay, string fontPath) : Listbox(pos, size, lines, maxDisplay, fontPath){} + + void SkyboxTextureListbox::onClose(){ + Root *root = Root::getSingleton(); + StateManager *sm = GameManager::getSingleton()->getStateManager(); + MapEditorAppState::MapEditor *mapEditor = ((MapEditorAppState*)sm->getAppStateByType((int)AppStateType::MAP_EDITOR))->getMapEditor(); + Texture *skyTexture = mapEditor->getSkyTexture(selectedOption); + + if(!root->getSkybox()) + root->createSkybox(skyTexture); + else + root->getSkybox()->getMaterial()->setTexUniform("tex", skyTexture, true); + } +} diff --git a/skyboxTextureListbox.h b/skyboxTextureListbox.h new file mode 100644 index 0000000..4e594a1 --- /dev/null +++ b/skyboxTextureListbox.h @@ -0,0 +1,16 @@ +#ifndef SKYBOX_TEXTURE_LISTBOX_H +#define SKYBOX_TEXTURE_LISTBOX_H + +#include + +namespace battleship{ + class SkyboxTextureListbox : public vb01Gui::Listbox{ + public: + SkyboxTextureListbox(vb01::Vector2, vb01::Vector2, std::vector, int, std::string); + void onClose(); + private: + }; +} + +#endif +