mirror of
https://github.com/devZoGok/PlanetFleet.git
synced 2026-08-26 19:43:29 +00:00
current maps can be loaded in the map editor
This commit is contained in:
+1
-1
@@ -9,7 +9,7 @@ cmake_policy(SET CMP0015 NEW)
|
||||
|
||||
set(STATES activeGameState.cpp inGameAppState.cpp guiAppState.cpp mapEditorAppState.cpp)
|
||||
set(UTIL util.cpp binds.h)
|
||||
set(GUI tooltip.cpp optionsButton.cpp exitButton.cpp consoleCommand.cpp)
|
||||
set(GUI tooltip.cpp mapEditorButton.cpp optionsButton.cpp exitButton.cpp consoleCommand.cpp)
|
||||
set(CONTROLLERS unitFrameController.cpp cameraController.cpp)
|
||||
set(CORE gameManager.cpp defConfigs.cpp ${CONTROLLERS})
|
||||
set(PROJECTILES projectile.cpp)
|
||||
|
||||
@@ -44,13 +44,15 @@ namespace battleship{
|
||||
ufCtr->setPlacingFrames(true);
|
||||
}
|
||||
|
||||
MapEditorAppState::MapEditor::MapEditor(string name, Vector2 size){
|
||||
MapEditorAppState::MapEditor::MapEditor(string name, Vector2 size, bool newMap){
|
||||
map = Map::getSingleton();
|
||||
map->load(name, true);
|
||||
map->load(name, newMap);
|
||||
|
||||
map->addPlayer(new Player(0, 0, 0));
|
||||
if(newMap){
|
||||
map->addPlayer(new Player(0, 0, 0));
|
||||
generatePlane(size);
|
||||
}
|
||||
|
||||
generatePlane(size);
|
||||
prepareGui();
|
||||
|
||||
string basePath = GameManager::getSingleton()->getPath();
|
||||
@@ -322,13 +324,14 @@ namespace battleship{
|
||||
}
|
||||
}
|
||||
|
||||
MapEditorAppState::MapEditorAppState(string name, Vector2 size) : AbstractAppState(
|
||||
MapEditorAppState::MapEditorAppState(string name, Vector2 size, bool newMap) : AbstractAppState(
|
||||
AppStateType::MAP_EDITOR,
|
||||
configData::calcSumBinds(AppStateType::MAP_EDITOR, true),
|
||||
configData::calcSumBinds(AppStateType::MAP_EDITOR, false),
|
||||
GameManager::getSingleton()->getPath() + "Scripts/options.lua"){
|
||||
mapName = name;
|
||||
mapSize = size;
|
||||
this->newMap = newMap;
|
||||
}
|
||||
|
||||
void MapEditorAppState::update(){
|
||||
@@ -347,7 +350,7 @@ namespace battleship{
|
||||
|
||||
void MapEditorAppState::onAttached(){
|
||||
AbstractAppState::onAttached();
|
||||
mapEditor = new MapEditor(mapName, mapSize);
|
||||
mapEditor = new MapEditor(mapName, mapSize, newMap);
|
||||
|
||||
Root *root = Root::getSingleton();
|
||||
Material *mat = new Material(root->getLibPath() + "text");
|
||||
|
||||
+3
-2
@@ -35,7 +35,7 @@ namespace battleship{
|
||||
Z_AXIS
|
||||
};
|
||||
|
||||
MapEditor(std::string, vb01::Vector2);
|
||||
MapEditor(std::string, vb01::Vector2, bool);
|
||||
void updateCircleRadius(bool);
|
||||
void pushLandmassVerts(float);
|
||||
void castSelectionRay();
|
||||
@@ -70,7 +70,7 @@ namespace battleship{
|
||||
UnitListbox *vehicleListbox = nullptr, *structureListbox = nullptr;
|
||||
};
|
||||
|
||||
MapEditorAppState(std::string, vb01::Vector2);
|
||||
MapEditorAppState(std::string, vb01::Vector2, bool);
|
||||
void update();
|
||||
void onAttached();
|
||||
void onDettached();
|
||||
@@ -81,6 +81,7 @@ namespace battleship{
|
||||
MapEditor *mapEditor = nullptr;
|
||||
std::string mapName;
|
||||
vb01::Vector2 mapSize;
|
||||
bool newMap;
|
||||
vb01::Text *radiusText = nullptr;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -0,0 +1,124 @@
|
||||
#include "mapEditorButton.h"
|
||||
#include "guiAppState.h"
|
||||
#include "inGameAppState.h"
|
||||
#include "mapEditorAppState.h"
|
||||
|
||||
#include <stateManager.h>
|
||||
|
||||
namespace battleship{
|
||||
using namespace std;
|
||||
using namespace vb01;
|
||||
using namespace vb01Gui;
|
||||
using namespace gameBase;
|
||||
|
||||
void MapEditorButton::onClick(){
|
||||
class NewMapButton : public Button{
|
||||
public:
|
||||
NewMapButton(Vector2 pos, Vector2 size) : Button(pos, size, "New map", GameManager::getSingleton()->getPath() + "Fonts/batang.ttf"){}
|
||||
void onClick(){
|
||||
class OkButton : public Button{
|
||||
public:
|
||||
OkButton(Vector2 pos, Vector2 size, Textbox *name, Textbox *sx, Textbox *sy) : Button(pos, size, "Ok", GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", -1, true){
|
||||
this->name = name;
|
||||
this->sizeX = sx;
|
||||
this->sizeY = sy;
|
||||
}
|
||||
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});
|
||||
|
||||
Vector2 size = Vector2(
|
||||
atof(wstringToString(sizeX->getText()).c_str()),
|
||||
atof(wstringToString(sizeY->getText()).c_str())
|
||||
);
|
||||
stateManager->attachAppState(new MapEditorAppState(wstringToString(name->getText()), size, true));
|
||||
|
||||
state->removeButton(this);
|
||||
}
|
||||
private:
|
||||
Textbox *name, *sizeX, *sizeY;
|
||||
};
|
||||
|
||||
GameManager *gm = GameManager::getSingleton();
|
||||
StateManager *stateManager = gm->getStateManager();
|
||||
GuiAppState *state = (GuiAppState*)stateManager->getAppStateByType((int)AppStateType::GUI_STATE);
|
||||
state->removeAllButtons(vector<Button*>{this});
|
||||
|
||||
Vector2 size = Vector2(140, 20);
|
||||
|
||||
string fontPath = gm->getPath() + "Fonts/batang.ttf";
|
||||
Textbox *name = new Textbox(Vector2(100, 150), size, fontPath);
|
||||
Textbox *sizeX = new Textbox(Vector2(100, 150 + (size.y + 10)), size, fontPath);
|
||||
Textbox *sizeY = new Textbox(Vector2(100, 150 + 2 * (size.y + 10)), size, fontPath);
|
||||
state->addTextbox(name);
|
||||
state->addTextbox(sizeX);
|
||||
state->addTextbox(sizeY);
|
||||
|
||||
state->addButton(new OkButton(Vector2(200, gm->getHeight() - 150), Vector2(140, 50), name, sizeX, sizeY));
|
||||
|
||||
state->removeButton(this);
|
||||
}
|
||||
private:
|
||||
};
|
||||
|
||||
class LoadMapButton : public Button{
|
||||
public:
|
||||
LoadMapButton(Vector2 pos, Vector2 size) : Button(pos, size, "Load map", GameManager::getSingleton()->getPath() + "Fonts/batang.ttf"){}
|
||||
void onClick(){
|
||||
class OkButton : public Button{
|
||||
public:
|
||||
OkButton(Vector2 pos, Vector2 size, Listbox *listbox) : Button(pos, size, "Ok", GameManager::getSingleton()->getPath() + "Fonts/batang.ttf"){
|
||||
this->listbox = listbox;
|
||||
}
|
||||
|
||||
void onClick(){
|
||||
string name = wstringToString(listbox->getContents()[listbox->getSelectedOption()]);
|
||||
|
||||
StateManager *sm = GameManager::getSingleton()->getStateManager();
|
||||
GuiAppState *guiState = (GuiAppState*)sm->getAppStateByType((int)AppStateType::GUI_STATE);
|
||||
guiState->removeAllListboxes();
|
||||
guiState->removeAllButtons(vector<Button*>{this});
|
||||
|
||||
sm->attachAppState(new MapEditorAppState(name, Vector2::VEC_ZERO, false));
|
||||
|
||||
guiState->removeButton(this);
|
||||
}
|
||||
private:
|
||||
Listbox *listbox;
|
||||
};
|
||||
|
||||
GameManager *gm = GameManager::getSingleton();
|
||||
StateManager *sm = gm->getStateManager();
|
||||
GuiAppState *guiState = (GuiAppState*)sm->getAppStateByType((int)AppStateType::GUI_STATE);
|
||||
guiState->removeAllButtons(vector<Button*>{this});
|
||||
|
||||
string basePath = gm->getPath();
|
||||
vector<string> maps = readDir(basePath + "Models/Maps/", true);
|
||||
int displayLimit = 2;
|
||||
Listbox *mapsListbox = new Listbox(Vector2(100, 150), Vector2(140, 20), maps, (maps.size() > displayLimit ? maps.size() : displayLimit), basePath + "Fonts/batang.ttf");
|
||||
guiState->addListbox(mapsListbox);
|
||||
guiState->addButton(new OkButton(Vector2(100, 350), Vector2(100, 20), mapsListbox));
|
||||
|
||||
guiState->removeButton(this);
|
||||
}
|
||||
private:
|
||||
};
|
||||
|
||||
GameManager *gm = GameManager::getSingleton();
|
||||
GuiAppState *guiState = (GuiAppState*)gm->getStateManager()->getAppStateByType((int)AppStateType::GUI_STATE);
|
||||
guiState->removeAllButtons(vector<Button*>{this});
|
||||
|
||||
int width = gm->getWidth(), height = gm->getHeight();
|
||||
Vector2 size = Vector2(150, 40);
|
||||
|
||||
NewMapButton *newMapButton = new NewMapButton(Vector2(width / 16, height / 12), size);
|
||||
LoadMapButton *loadMapButton = new LoadMapButton(Vector2(width / 16, height / 12 * 2), size);
|
||||
guiState->addButton(newMapButton);
|
||||
guiState->addButton(loadMapButton);
|
||||
guiState->removeButton(this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
#ifndef MAP_EDITOR_BUTTON_H
|
||||
#define MAP_EDITOR_BUTTON_H
|
||||
|
||||
#include <button.h>
|
||||
|
||||
#include "gameManager.h"
|
||||
|
||||
namespace battleship{
|
||||
class MapEditorButton : public vb01Gui::Button{
|
||||
public:
|
||||
MapEditorButton(vb01::Vector2 pos, vb01::Vector2 size) : vb01Gui::Button(pos, size, "Map editor", GameManager::getSingleton()->getPath() + "Fonts/batang.ttf"){}
|
||||
void onClick();
|
||||
private:
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -18,7 +18,7 @@
|
||||
#include "gameManager.h"
|
||||
#include "guiAppState.h"
|
||||
#include "inGameAppState.h"
|
||||
#include "mapEditorAppState.h"
|
||||
#include "mapEditorButton.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace glm;
|
||||
@@ -205,72 +205,6 @@ namespace battleship{
|
||||
};
|
||||
};
|
||||
|
||||
class NewMapButton : public Button{
|
||||
public:
|
||||
NewMapButton(Vector2 pos, Vector2 size) : Button(pos, size, "New map", GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", -1, true){}
|
||||
void onClick(){
|
||||
class OkButton : public Button{
|
||||
public:
|
||||
OkButton(Vector2 pos, Vector2 size, Textbox *name, Textbox *sx, Textbox *sy) : Button(pos, size, "Ok", GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", -1, true){
|
||||
this->name = name;
|
||||
this->sizeX = sx;
|
||||
this->sizeY = sy;
|
||||
}
|
||||
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()),
|
||||
Vector2(
|
||||
atof(wstringToString(sizeX->getText()).c_str()),
|
||||
atof(wstringToString(sizeY->getText()).c_str()))
|
||||
)
|
||||
);
|
||||
|
||||
state->removeButton(this);
|
||||
}
|
||||
private:
|
||||
Textbox *name, *sizeX, *sizeY;
|
||||
};
|
||||
|
||||
GameManager *gm = GameManager::getSingleton();
|
||||
StateManager *stateManager = gm->getStateManager();
|
||||
GuiAppState *state = (GuiAppState*)stateManager->getAppStateByType((int)AppStateType::GUI_STATE);
|
||||
state->removeAllButtons(vector<Button*>{this});
|
||||
|
||||
Vector2 size = Vector2(140, 20);
|
||||
|
||||
string fontPath = gm->getPath() + "Fonts/batang.ttf";
|
||||
Textbox *name = new Textbox(Vector2(100, 150), size, fontPath);
|
||||
Textbox *sizeX = new Textbox(Vector2(100, 150 + (size.y + 10)), size, fontPath);
|
||||
Textbox *sizeY = new Textbox(Vector2(100, 150 + 2 * (size.y + 10)), size, fontPath);
|
||||
state->addTextbox(name);
|
||||
state->addTextbox(sizeX);
|
||||
state->addTextbox(sizeY);
|
||||
|
||||
state->addButton(new OkButton(Vector2(200, gm->getHeight() - 150), Vector2(140, 50), name, sizeX, sizeY));
|
||||
|
||||
state->removeButton(this);
|
||||
}
|
||||
private:
|
||||
};
|
||||
|
||||
class LoadMapButton : public Button{
|
||||
public:
|
||||
LoadMapButton(Vector2 pos, Vector2 size) : Button(pos, size, "Load map", GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", -1, true){}
|
||||
void onClick(){
|
||||
StateManager *stateManager = GameManager::getSingleton()->getStateManager();
|
||||
GuiAppState *state = (GuiAppState*)stateManager->getAppStateByType((int)AppStateType::GUI_STATE);
|
||||
state->removeAllButtons();
|
||||
}
|
||||
private:
|
||||
};
|
||||
|
||||
GameManager *gm = GameManager::getSingleton();
|
||||
string font = gm->getPath() + "Fonts/batang.ttf";
|
||||
int width = gm->getWidth(), height = gm->getHeight();
|
||||
@@ -280,13 +214,11 @@ namespace battleship{
|
||||
|
||||
SpButton *spButton = new SpButton(state, Vector2(width / 16, height / 12), size, "Singleplayer", true);
|
||||
MainMenuOptionsButton *optionsButton = new MainMenuOptionsButton(state, Vector2(width / 16, height / 12 * 2), size, "Options", true);
|
||||
NewMapButton *newMapButton = new NewMapButton(Vector2(width / 16, height / 12 * 3), size);
|
||||
LoadMapButton *loadMapButton = new LoadMapButton(Vector2(width / 16, height / 12 * 4), size);
|
||||
ExitButton *exitButton = new ExitButton(Vector2(width / 16, height / 12 * 5), size);
|
||||
MapEditorButton *editorButton = new MapEditorButton(Vector2(width / 16, height / 12 * 3), size);
|
||||
ExitButton *exitButton = new ExitButton(Vector2(width / 16, height / 12 * 4), size);
|
||||
state->addButton(spButton);
|
||||
state->addButton(optionsButton);
|
||||
state->addButton(newMapButton);
|
||||
state->addButton(loadMapButton);
|
||||
state->addButton(editorButton);
|
||||
state->addButton(exitButton);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user