diff --git a/Assets/Textures/Landmass/woodChips.jpg b/Assets/Textures/Landmass/woodChips.jpg new file mode 100755 index 0000000..74c2d86 Binary files /dev/null and b/Assets/Textures/Landmass/woodChips.jpg differ diff --git a/Assets/Textures/Skyboxes/Skybox1/bottom.jpg b/Assets/Textures/Skyboxes/Skybox1/bottom.jpg deleted file mode 100644 index 026b1d5..0000000 Binary files a/Assets/Textures/Skyboxes/Skybox1/bottom.jpg and /dev/null differ diff --git a/Assets/Textures/Skyboxes/Skybox1/top.jpg b/Assets/Textures/Skyboxes/Skybox1/top.jpg deleted file mode 100644 index aa05448..0000000 Binary files a/Assets/Textures/Skyboxes/Skybox1/top.jpg and /dev/null differ diff --git a/Assets/Textures/Skyboxes/TestSkybox/back.jpg b/Assets/Textures/Skyboxes/TestSkybox/back.jpg new file mode 100755 index 0000000..8cef7fb Binary files /dev/null and b/Assets/Textures/Skyboxes/TestSkybox/back.jpg differ diff --git a/Assets/Textures/Skyboxes/TestSkybox/down.jpg b/Assets/Textures/Skyboxes/TestSkybox/down.jpg new file mode 100755 index 0000000..c5e81db Binary files /dev/null and b/Assets/Textures/Skyboxes/TestSkybox/down.jpg differ diff --git a/Assets/Textures/Skyboxes/TestSkybox/front.jpg b/Assets/Textures/Skyboxes/TestSkybox/front.jpg new file mode 100755 index 0000000..802ea55 Binary files /dev/null and b/Assets/Textures/Skyboxes/TestSkybox/front.jpg differ diff --git a/Assets/Textures/Skyboxes/TestSkybox/left.jpg b/Assets/Textures/Skyboxes/TestSkybox/left.jpg new file mode 100755 index 0000000..687f651 Binary files /dev/null and b/Assets/Textures/Skyboxes/TestSkybox/left.jpg differ diff --git a/Assets/Textures/Skyboxes/TestSkybox/right.jpg b/Assets/Textures/Skyboxes/TestSkybox/right.jpg new file mode 100755 index 0000000..da27a8a Binary files /dev/null and b/Assets/Textures/Skyboxes/TestSkybox/right.jpg differ diff --git a/Assets/Textures/Skyboxes/TestSkybox/up.jpg b/Assets/Textures/Skyboxes/TestSkybox/up.jpg new file mode 100755 index 0000000..d7826e5 Binary files /dev/null and b/Assets/Textures/Skyboxes/TestSkybox/up.jpg differ diff --git a/mapEditorAppState.cpp b/mapEditorAppState.cpp index bb81b99..e535cae 100644 --- a/mapEditorAppState.cpp +++ b/mapEditorAppState.cpp @@ -8,8 +8,11 @@ #include "mesh.h" #include "util.h" +#include #include #include +#include +#include #include @@ -28,6 +31,10 @@ namespace battleship{ generatePlane(size); prepareGui(); + + string basePath = GameManager::getSingleton()->getPath() + "Textures/"; + prepareTextures(basePath + "Skyboxes/", true, skyTextures); + prepareTextures(basePath + "Landmass/", false, landmassTextures); } //TODO fix crash when using 100 side verts @@ -111,15 +118,94 @@ namespace battleship{ Listbox *structuresListbox = new Listbox(startPos + offset, size, structures, (structures.size() > maxDisplay ? maxDisplay : structures.size()), fontPath); state->addListbox(structuresListbox); + class SkyboxListbox : public Listbox{ + public: + SkyboxListbox(Vector2 pos, Vector2 size, vector lines, int maxDisplay, string fontPath) : Listbox(pos, size, lines, maxDisplay, fontPath){} + + void onClose(){ + Root *root = Root::getSingleton(); + StateManager *sm = GameManager::getSingleton()->getStateManager(); + 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); + + } + private: + }; + vector skyboxFolders = readDir(gm->getPath() + "Textures/Skyboxes", true); - Listbox *skyboxListbox = new Listbox(startPos + 2 * offset, size, skyboxFolders, (skyboxFolders.size() > maxDisplay ? maxDisplay : skyboxFolders.size()), fontPath); + SkyboxListbox *skyboxListbox = new SkyboxListbox(startPos + 2 * offset, size, skyboxFolders, (skyboxFolders.size() > maxDisplay ? maxDisplay : skyboxFolders.size()), fontPath); state->addListbox(skyboxListbox); + class LandTexListbox : public Listbox{ + public: + LandTexListbox(Vector2 pos, Vector2 size, vector lines, int maxDisplay, string fontPath) : Listbox(pos, size, lines, maxDisplay, fontPath){} + + void onClose(){ + StateManager *sm = GameManager::getSingleton()->getStateManager(); + 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); + } + private: + }; + vector landTextures = readDir(gm->getPath() + "Textures/Landmass", false); - Listbox *landTexListbox = new Listbox(startPos + 3 * offset, size, landTextures, (landTextures.size() > maxDisplay ? maxDisplay : landTextures.size()), fontPath); + LandTexListbox *landTexListbox = new LandTexListbox(startPos + 3 * 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(); + assetManager->load(basePath, skybox); + vector texturePaths; + + for(int i = 0; i < assetManager->getNumAssets(); i++){ + string assetPath = assetManager->getAsset(i)->path; + + if(assetPath.length() >= basePath.length() && assetPath.substr(0, basePath.length()) == basePath) + texturePaths.push_back(assetPath); + } + + if(skybox){ + const int numTex = 6; + + for(int i = 0; i < texturePaths.size() / numTex; i++){ + string paths[]{ + texturePaths[i * numTex], + texturePaths[i * numTex + 1], + texturePaths[i * numTex + 2], + texturePaths[i * numTex + 3], + texturePaths[i * numTex + 4], + texturePaths[i * numTex + 5], + }; + + textures.push_back(new Texture(paths, numTex, true)); + } + } + else{ + for(int i = 0; i < texturePaths.size(); i++){ + string paths[]{texturePaths[i]}; + textures.push_back(new Texture(paths, 1, false)); + } + } + } + MapEditorAppState::MapEditorAppState(string name, Vector2 size) : AbstractAppState( AppStateType::MAP_EDITOR, configData::calcSumBinds(AppStateType::MAP_EDITOR, true), diff --git a/mapEditorAppState.h b/mapEditorAppState.h index 0806505..9e294a0 100644 --- a/mapEditorAppState.h +++ b/mapEditorAppState.h @@ -7,29 +7,38 @@ #include +namespace vb01{ + class Texture; +} + namespace battleship{ class MapEditor; class Map; class MapEditorAppState : public gameBase::AbstractAppState{ public: - MapEditorAppState(std::string, vb01::Vector2); - void update(); - void onAttached(); - void onDettached(); - void onAction(int, bool); - void onAnalog(int, float); - private: class MapEditor{ public: MapEditor(std::string, vb01::Vector2); private: void generatePlane(vb01::Vector2); void prepareGui(); + void prepareTextures(std::string, bool, std::vector&); + inline vb01::Texture* getSkyTexture(int i){return skyTextures[i];} + inline vb01::Texture* getLandmassTexture(int i){return landmassTextures[i];} Map *map; + std::vector skyTextures, landmassTextures; }; + MapEditorAppState(std::string, vb01::Vector2); + void update(); + void onAttached(); + void onDettached(); + void onAction(int, bool); + void onAnalog(int, float); + inline MapEditor* getMapEditor(){return mapEditor;} + private: MapEditor *mapEditor = nullptr; std::string mapName; vb01::Vector2 mapSize;