diff --git a/Assets/Scripts/unitData.lua b/Assets/Scripts/unitData.lua index 1835d8b..4f6b236 100644 --- a/Assets/Scripts/unitData.lua +++ b/Assets/Scripts/unitData.lua @@ -14,6 +14,10 @@ unitType = { UnitType.LAND, UnitType.LAND } +isVehicle = { + true, true, true, false +}; + health = {500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500} cost = {500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500} range = {15, 15, 14, 14, 13, 13, 12, 12, 15, 25} @@ -247,7 +251,7 @@ unitAxisLength = {8, 8, 6, 6, 5, 5, 8, 8, 7, 2, 2} lineOfSight = {5, 8, 4, 4, 3, 3, 6, 6, 3, 3, 8} name = { "Battleship", "Battleship", - "Battleship", "Battleship", + "Battleship", "Sample", "Cruiser", "Cruiser", "Aircraft carrier", "Aircraft carrier", "Submarine", diff --git a/Assets/Textures/defaultTexture.jpg b/Assets/Textures/Landmass/defaultTexture.jpg similarity index 100% rename from Assets/Textures/defaultTexture.jpg rename to Assets/Textures/Landmass/defaultTexture.jpg diff --git a/Assets/Textures/back.jpg b/Assets/Textures/Skyboxes/Skybox1/back.jpg similarity index 100% rename from Assets/Textures/back.jpg rename to Assets/Textures/Skyboxes/Skybox1/back.jpg diff --git a/Assets/Textures/Skyboxes/Skybox1/bottom.jpg b/Assets/Textures/Skyboxes/Skybox1/bottom.jpg new file mode 100644 index 0000000..026b1d5 Binary files /dev/null and b/Assets/Textures/Skyboxes/Skybox1/bottom.jpg differ diff --git a/Assets/Textures/down.jpg b/Assets/Textures/Skyboxes/Skybox1/down.jpg similarity index 100% rename from Assets/Textures/down.jpg rename to Assets/Textures/Skyboxes/Skybox1/down.jpg diff --git a/Assets/Textures/front.jpg b/Assets/Textures/Skyboxes/Skybox1/front.jpg similarity index 100% rename from Assets/Textures/front.jpg rename to Assets/Textures/Skyboxes/Skybox1/front.jpg diff --git a/Assets/Textures/left.jpg b/Assets/Textures/Skyboxes/Skybox1/left.jpg similarity index 100% rename from Assets/Textures/left.jpg rename to Assets/Textures/Skyboxes/Skybox1/left.jpg diff --git a/Assets/Textures/right.jpg b/Assets/Textures/Skyboxes/Skybox1/right.jpg similarity index 100% rename from Assets/Textures/right.jpg rename to Assets/Textures/Skyboxes/Skybox1/right.jpg diff --git a/Assets/Textures/Skyboxes/Skybox1/top.jpg b/Assets/Textures/Skyboxes/Skybox1/top.jpg new file mode 100644 index 0000000..aa05448 Binary files /dev/null and b/Assets/Textures/Skyboxes/Skybox1/top.jpg differ diff --git a/Assets/Textures/up.jpg b/Assets/Textures/Skyboxes/Skybox1/up.jpg similarity index 100% rename from Assets/Textures/up.jpg rename to Assets/Textures/Skyboxes/Skybox1/up.jpg diff --git a/Assets/Textures/water.jpg b/Assets/Textures/Water/water.jpg similarity index 100% rename from Assets/Textures/water.jpg rename to Assets/Textures/Water/water.jpg diff --git a/Assets/Textures/water-texture.png b/Assets/Textures/water-texture.png deleted file mode 100644 index 065eb3d..0000000 Binary files a/Assets/Textures/water-texture.png and /dev/null differ diff --git a/mapEditorAppState.cpp b/mapEditorAppState.cpp index 44ce25d..bb81b99 100644 --- a/mapEditorAppState.cpp +++ b/mapEditorAppState.cpp @@ -1,5 +1,7 @@ #include "mapEditorAppState.h" #include "gameManager.h" +#include "stateManager.h" +#include "guiAppState.h" #include "defConfigs.h" #include "cameraController.h" #include "map.h" @@ -7,11 +9,17 @@ #include "util.h" #include +#include + +#include + +#include namespace battleship{ using namespace configData; - using namespace vb01; using namespace gameBase; + using namespace vb01; + using namespace vb01Gui; using namespace std; MapEditorAppState::MapEditor::MapEditor(string name, Vector2 size){ @@ -19,10 +27,12 @@ namespace battleship{ map->load(name, true); generatePlane(size); + prepareGui(); } + //TODO fix crash when using 100 side verts void MapEditorAppState::MapEditor::generatePlane(Vector2 size){ - int numSideVerts = 100, numIndices = 6 * (numSideVerts - 1) * (numSideVerts - 1); + int numSideVerts = 10, numIndices = 6 * (numSideVerts - 1) * (numSideVerts - 1); MeshData::Vertex *vertices = new MeshData::Vertex[numSideVerts * numSideVerts]; u32 *indices = new u32[numIndices]; @@ -34,7 +44,7 @@ namespace battleship{ float z = size.y * (numSideVerts - 2 * i) / (2 * numSideVerts); vert.pos = Vector3(x, 0, z); - vert.uv = Vector2((float)(j / numSideVerts), (float)(i / numSideVerts)); + vert.uv = Vector2((float)(j) / numSideVerts, (float)(i) / numSideVerts); vert.tan = Vector3::VEC_I; vert.biTan = Vector3::VEC_K; vert.norm = vert.tan.cross(vert.biTan); @@ -62,7 +72,7 @@ namespace battleship{ mat->addBoolUniform("lightingEnabled", false); mat->addVec4Uniform("diffuseColor", Vector4(1, 0, 0, 1)); - MeshData meshData(vertices, indices, numIndices / 6); + MeshData meshData(vertices, indices, numIndices / 3); Mesh *mesh = new Mesh(meshData); mesh->construct(); mesh->setMaterial(mat); @@ -74,6 +84,42 @@ namespace battleship{ map->addTerrainObject(TerrainObject(Vector3(0, 0, 0), Vector3(size.x, 0, size.y), Vector3(14, 6, 14), TerrainObject::LANDMASS, node, 0, new Cell, new vb01::u32*)); } + void MapEditorAppState::MapEditor::prepareGui(){ + GameManager *gm = GameManager::getSingleton(); + StateManager *sm = gm->getStateManager(); + GuiAppState *state = (GuiAppState*)sm->getAppStateByType((int)AppStateType::GUI_STATE); + string fontPath = gm->getPath() + "Fonts/batang.ttf"; + + Vector2 startPos = Vector2((float)gm->getWidth() / 16, (float)gm->getHeight() * .8); + Vector2 size = Vector2(140, 20), offset = Vector2(size.x + 10, 0); + int maxDisplay = 2; + + vector vehicles, structures; + + LuaManager *lm = LuaManager::getSingleton(); + int numUnits = lm->getInt("numUnits"); + + for(int i = 0; i < numUnits; i++){ + bool vehicle = lm->getBoolFromTable("isVehicle", vector{Index(i + 1)}); + string name = lm->getStringFromTable("name", vector{Index(i + 1)}); + (vehicle ? vehicles : structures).push_back(name); + } + + Listbox *vehicleListbox = new Listbox(startPos, size, vehicles, maxDisplay, fontPath); + state->addListbox(vehicleListbox); + + Listbox *structuresListbox = new Listbox(startPos + offset, size, structures, (structures.size() > maxDisplay ? maxDisplay : structures.size()), fontPath); + state->addListbox(structuresListbox); + + vector skyboxFolders = readDir(gm->getPath() + "Textures/Skyboxes", true); + Listbox *skyboxListbox = new Listbox(startPos + 2 * offset, size, skyboxFolders, (skyboxFolders.size() > maxDisplay ? maxDisplay : skyboxFolders.size()), fontPath); + state->addListbox(skyboxListbox); + + vector landTextures = readDir(gm->getPath() + "Textures/Landmass", false); + Listbox *landTexListbox = new Listbox(startPos + 3 * offset, size, landTextures, (landTextures.size() > maxDisplay ? maxDisplay : landTextures.size()), fontPath); + state->addListbox(landTexListbox); + } + 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 ca86ecb..0806505 100644 --- a/mapEditorAppState.h +++ b/mapEditorAppState.h @@ -8,31 +8,32 @@ #include namespace battleship{ - class MapEditor; - class Map; + class MapEditor; + class Map; - class MapEditorAppState : public gameBase::AbstractAppState{ + 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: - MapEditorAppState(std::string, vb01::Vector2); - void update(); - void onAttached(); - void onDettached(); - void onAction(int, bool); - void onAnalog(int, float); + MapEditor(std::string, vb01::Vector2); private: - class MapEditor{ - public: - MapEditor(std::string, vb01::Vector2); - private: - void generatePlane(vb01::Vector2); + void generatePlane(vb01::Vector2); + void prepareGui(); - Map *map; - }; + Map *map; + }; - MapEditor *mapEditor = nullptr; - std::string mapName; - vb01::Vector2 mapSize; - }; + MapEditor *mapEditor = nullptr; + std::string mapName; + vb01::Vector2 mapSize; + }; } #endif diff --git a/stateManager.cpp b/stateManager.cpp deleted file mode 100644 index f3c4115..0000000 --- a/stateManager.cpp +++ /dev/null @@ -1,43 +0,0 @@ -#include "stateManager.h" -#include "abstractAppState.h" - -namespace battleship{ - void StateManager::attachState(AbstractAppState *a) { - bool alreadyAttached = false; - for (int i = 0; i < appStates.size()&&!alreadyAttached; i++) - if (appStates[i] == a) - alreadyAttached = true; - if (!alreadyAttached) { - a->onAttachment(); - appStates.push_back(a); - } - } - - void StateManager::dettachState(AbstractAppState *a) { - bool alreadyDetached = false; - for (int i = 0; i < appStates.size()&&!alreadyDetached; i++) - if (appStates[i] == a) - alreadyDetached = true; - if (!alreadyDetached) { - a->onDetachment(); - for (int i = 0; i < appStates.size(); i++) - if (a == appStates[i]) { - appStates.erase(appStates.begin() + i); - } - } - } - - void StateManager::update() { - for (AbstractAppState *a : appStates) - if (a->isAttached() && a) - a->update(); - } - - AbstractAppState* StateManager::getAppState(AppStateTypes t) { - AbstractAppState *state = nullptr; - for (AbstractAppState *a : appStates) - if (a->getType() == t) - state = a; - return state; - } -} diff --git a/stateManager.h b/stateManager.h deleted file mode 100644 index 2e49997..0000000 --- a/stateManager.h +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef STATE_MANAGER_H -#define STATE_MANAGER_H - -#include - -#include "abstractAppState.h" - -namespace battleship{ - class StateManager{ - public: - StateManager(){} - void update(); - void attachState(AbstractAppState*); - void dettachState(AbstractAppState*); - void dettachState(AppStateTypes); - AbstractAppState* getAppState(AppStateTypes); - inline AbstractAppState* getAppState(int id){return appStates[id];} - inline void setAppState(int i, AbstractAppState *a){appStates[i]=a;} - inline int getAppStateNumber(){return appStates.size();} - inline std::vector getAppStates(){return appStates;} - private: - std::vector appStates; - }; -} - -#endif diff --git a/util.cpp b/util.cpp index 65b84c8..c78fd24 100755 --- a/util.cpp +++ b/util.cpp @@ -26,7 +26,7 @@ using namespace vb01; using namespace vb01Gui; namespace battleship{ - using namespace configData; + using namespace configData; void makeTitlescreenButtons(GuiAppState *state) { @@ -115,24 +115,13 @@ namespace battleship{ factions.push_back("0"); factions.push_back("1"); - tinydir_dir dir; - tinydir_open_sorted(&dir, (gm->getPath() + "Models/Maps").c_str()); - vector folders; - - for (int i = 0; i < dir.n_files; i++) { - tinydir_file file; - tinydir_readfile_n(&dir, &file, i); - if (file.is_dir && file.name[0] != '.') - folders.push_back(file.name); - } - - tinydir_close(&dir); - - string font = gm->getPath() + "Fonts/batang.ttf"; + string font = gm->getPath() + "Fonts/batang.ttf"; Listbox *cpuDifficulty = new Listbox(Vector2(pos.x, pos.y + 30), Vector2(100, 20), difficulties, 3, font); Listbox *cpuFaction = new Listbox(Vector2(pos.x + 110, pos.y + 30), Vector2(100, 20), factions, 2, font); Listbox *playerFaction = new Listbox(Vector2(pos.x + 110, pos.y), Vector2(100, 20), factions, 2, font); + + vector folders = readDir(gm->getPath() + "Models/Maps", true); int numMinDirs = 3; int numShowDirs = folders.size() < numMinDirs ? folders.size() : numMinDirs; Listbox *map = new Listbox(Vector2(pos.x + 110, pos.y + 100), Vector2(100, 20), folders, numShowDirs, font); @@ -231,6 +220,10 @@ namespace battleship{ void onClick(){ GameManager *gm = GameManager::getSingleton(); StateManager *stateManager = gm->getStateManager(); + GuiAppState *state = (GuiAppState*)stateManager->getAppStateByType((int)AppStateType::GUI_STATE); + + state->removeAllTextboxes(); + state->removeAllButtons(vector{this}); stateManager->attachAppState(new MapEditorAppState( wstringToString(name->getText()), @@ -240,8 +233,7 @@ namespace battleship{ ) ); - GuiAppState *state = (GuiAppState*)stateManager->getAppStateByType((int)AppStateType::GUI_STATE); - state->removeAllButtons(); + state->removeButton(this); } private: Textbox *name, *sizeX, *sizeY; @@ -299,6 +291,24 @@ namespace battleship{ state->addButton(exitButton); } + vector readDir(string path, bool findFolders){ + tinydir_dir dir; + tinydir_open_sorted(&dir, path.c_str()); + vector files; + + for (int i = 0; i < dir.n_files; i++) { + tinydir_file file; + tinydir_readfile_n(&dir, &file, i); + + if (file.is_dir == findFolders && file.name[0] != '.') + files.push_back(file.name); + } + + tinydir_close(&dir); + + return files; + } + Vector2 spaceToScreen(Vector3 pos){ Root *root = Root::getSingleton(); Camera *cam = root->getCamera(); diff --git a/util.h b/util.h index 5a1054d..4807351 100755 --- a/util.h +++ b/util.h @@ -20,13 +20,14 @@ namespace battleship{ typedef int s32; typedef long long s64; - enum AppStateType{GUI_STATE, IN_GAME_STATE, ACTIVE_STATE, MAP_EDITOR}; + enum AppStateType{GUI_STATE, IN_GAME_STATE, ACTIVE_STATE, MAP_EDITOR}; class GuiAppState; void makeTitlescreenButtons(GuiAppState*); - vb01::Vector2 spaceToScreen(vb01::Vector3); - vb01::Vector3 screenToSpace(vb01::Vector2); + std::vector readDir(std::string, bool); + vb01::Vector2 spaceToScreen(vb01::Vector3); + vb01::Vector3 screenToSpace(vb01::Vector2); } #endif