listboxes for map editting
@@ -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",
|
||||
|
||||
|
Before Width: | Height: | Size: 49 KiB After Width: | Height: | Size: 49 KiB |
|
Before Width: | Height: | Size: 220 KiB After Width: | Height: | Size: 220 KiB |
|
After Width: | Height: | Size: 302 KiB |
|
Before Width: | Height: | Size: 119 KiB After Width: | Height: | Size: 119 KiB |
|
Before Width: | Height: | Size: 370 KiB After Width: | Height: | Size: 370 KiB |
|
Before Width: | Height: | Size: 318 KiB After Width: | Height: | Size: 318 KiB |
|
Before Width: | Height: | Size: 411 KiB After Width: | Height: | Size: 411 KiB |
|
After Width: | Height: | Size: 373 KiB |
|
Before Width: | Height: | Size: 224 KiB After Width: | Height: | Size: 224 KiB |
|
Before Width: | Height: | Size: 1.8 MiB After Width: | Height: | Size: 1.8 MiB |
|
Before Width: | Height: | Size: 14 MiB |
@@ -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 <node.h>
|
||||
#include <quad.h>
|
||||
|
||||
#include <luaManager.h>
|
||||
|
||||
#include <listbox.h>
|
||||
|
||||
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<string> 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>{Index(i + 1)});
|
||||
string name = lm->getStringFromTable("name", vector<Index>{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<string> 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<string> 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),
|
||||
|
||||
@@ -8,31 +8,32 @@
|
||||
#include <string>
|
||||
|
||||
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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
#ifndef STATE_MANAGER_H
|
||||
#define STATE_MANAGER_H
|
||||
|
||||
#include <vector>
|
||||
|
||||
#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<AbstractAppState*> getAppStates(){return appStates;}
|
||||
private:
|
||||
std::vector<AbstractAppState*> appStates;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -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<string> 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<string> 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<Button*>{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<string> readDir(string path, bool findFolders){
|
||||
tinydir_dir dir;
|
||||
tinydir_open_sorted(&dir, path.c_str());
|
||||
vector<string> 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();
|
||||
|
||||
@@ -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<std::string> readDir(std::string, bool);
|
||||
vb01::Vector2 spaceToScreen(vb01::Vector3);
|
||||
vb01::Vector3 screenToSpace(vb01::Vector2);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||