zoomedit: Rooms can now be connected to portals.
This commit is contained in:
parent
2687501f21
commit
f457ec5027
7 changed files with 77 additions and 36 deletions
|
@ -39,9 +39,9 @@ class LevelVertex : public LevelObject {
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual bool canConnect() const {return provider->canConnectVertex(id);}
|
virtual bool canConnect() const {return provider->canConnectVertex(id);}
|
||||||
virtual void connect() {provider->connectVertex(id);}
|
virtual size_t connect() {return provider->connectVertex(id);}
|
||||||
|
|
||||||
const VertexProvider* getProvider() const {
|
VertexProvider* getProvider() const {
|
||||||
return provider;
|
return provider;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
5
Portal.h
5
Portal.h
|
@ -130,8 +130,11 @@ class Portal : public LevelObject, public VertexProvider {
|
||||||
return !connected[id];
|
return !connected[id];
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void connectVertex(size_t id) {
|
virtual size_t connectVertex(size_t id) {
|
||||||
connected[id] = true;
|
connected[id] = true;
|
||||||
|
connected[(7-id)%4] = true;
|
||||||
|
|
||||||
|
return (7-id)%4;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
24
Room.cpp
24
Room.cpp
|
@ -20,30 +20,6 @@ const Room& Room::operator=(const Room &room) {
|
||||||
return room;
|
return room;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Room::addVertex(Vertex v) {
|
|
||||||
vertices.push_back(SharedPtr<RoomVertex>(new RoomVertexDirect(v)));
|
|
||||||
|
|
||||||
if(vertices.size() < 2)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if(vertices.size() == 2) {
|
|
||||||
LevelVertex v1(this, 0, this), v2(this, 1, this);
|
|
||||||
|
|
||||||
edges.push_back(Edge(v1, v2));
|
|
||||||
edges.push_back(Edge(v2, v1));
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
edges.pop_back();
|
|
||||||
LevelVertex v1(edges.back().getVertex2());
|
|
||||||
LevelVertex v2(this, vertices.size()-1, this);
|
|
||||||
LevelVertex v3(edges.front().getVertex1());
|
|
||||||
|
|
||||||
edges.push_back(Edge(v1, v2));
|
|
||||||
edges.push_back(Edge(v2, v3));
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<SharedPtr<LevelObject> > Room::getChildren() {
|
std::vector<SharedPtr<LevelObject> > Room::getChildren() {
|
||||||
std::vector<SharedPtr<LevelObject> > children;
|
std::vector<SharedPtr<LevelObject> > children;
|
||||||
|
|
||||||
|
|
47
Room.h
47
Room.h
|
@ -39,6 +39,7 @@ class Room : public LevelObject, private VertexProvider, private EdgeProvider {
|
||||||
vertex += v;
|
vertex += v;
|
||||||
return vertex;
|
return vertex;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual const Vertex& operator-=(const Vertex &v) {
|
virtual const Vertex& operator-=(const Vertex &v) {
|
||||||
vertex -= v;
|
vertex -= v;
|
||||||
return vertex;
|
return vertex;
|
||||||
|
@ -68,6 +69,18 @@ class Room : public LevelObject, private VertexProvider, private EdgeProvider {
|
||||||
std::vector<SharedPtr<RoomVertex> > vertices;
|
std::vector<SharedPtr<RoomVertex> > vertices;
|
||||||
std::vector<Edge> edges;
|
std::vector<Edge> edges;
|
||||||
|
|
||||||
|
void addEdge() {
|
||||||
|
if(vertices.size() < 2)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if(vertices.size() == 2) {
|
||||||
|
edges.push_back(Edge(LevelVertex(this, 0, this), LevelVertex(this, 1, this)));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
edges.push_back(Edge(LevelVertex(this, vertices.size()-2, this), LevelVertex(this, vertices.size()-1, this)));
|
||||||
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Room() {height = 10;}
|
Room() {height = 10;}
|
||||||
Room(std::string name) {this->name = name; height = 10;}
|
Room(std::string name) {this->name = name; height = 10;}
|
||||||
|
@ -89,7 +102,39 @@ class Room : public LevelObject, private VertexProvider, private EdgeProvider {
|
||||||
float getHeight() const {return height;}
|
float getHeight() const {return height;}
|
||||||
void setHeight(float height) {this->height = height;}
|
void setHeight(float height) {this->height = height;}
|
||||||
|
|
||||||
void addVertex(Vertex v);
|
void addVertex(Vertex v) {
|
||||||
|
vertices.push_back(SharedPtr<RoomVertex>(new RoomVertexDirect(v)));
|
||||||
|
addEdge();
|
||||||
|
}
|
||||||
|
|
||||||
|
void addVertex(LevelVertex &v) {
|
||||||
|
size_t s = v.connect();
|
||||||
|
|
||||||
|
if(s == v.getId()) {
|
||||||
|
vertices.push_back(SharedPtr<RoomVertex>(new RoomVertexIndirect(v)));
|
||||||
|
addEdge();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if(vertices.empty()) {
|
||||||
|
LevelVertex v2(v.getProvider(), s, v.getParent());
|
||||||
|
|
||||||
|
vertices.push_back(SharedPtr<RoomVertex>(new RoomVertexIndirect(v2)));
|
||||||
|
vertices.push_back(SharedPtr<RoomVertex>(new RoomVertexIndirect(v)));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
LevelVertex v2(v.getProvider(), s, v.getParent());
|
||||||
|
|
||||||
|
vertices.push_back(SharedPtr<RoomVertex>(new RoomVertexIndirect(v)));
|
||||||
|
addEdge();
|
||||||
|
vertices.push_back(SharedPtr<RoomVertex>(new RoomVertexIndirect(v2)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void close() {
|
||||||
|
if(!edges.empty())
|
||||||
|
edges.push_back(Edge(edges.back().getVertex2(), edges.front().getVertex1()));
|
||||||
|
}
|
||||||
|
|
||||||
Polygon getPolygon() const {
|
Polygon getPolygon() const {
|
||||||
Polygon polygon;
|
Polygon polygon;
|
||||||
|
|
|
@ -20,6 +20,7 @@ void ToolAddPolygon::activate() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ToolAddPolygon::deactivate() {
|
void ToolAddPolygon::deactivate() {
|
||||||
|
newRoom.close();
|
||||||
editManager->addRoom(newRoom);
|
editManager->addRoom(newRoom);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,13 +53,26 @@ bool ToolAddPolygon::buttonPress(unsigned int button, const Vertex *v) {
|
||||||
if(button != 1)
|
if(button != 1)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if(!v)
|
if(editManager->getHoveredObject() && editManager->getHoveredObject()->isOfType("LevelVertex")) {
|
||||||
return false;
|
LevelVertex *vertex = (LevelVertex*)editManager->getHoveredObject();
|
||||||
|
|
||||||
if(!editManager->vertexOk(*v, &newRoom))
|
if(!vertex->canConnect())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
newRoom.addVertex(*v);
|
if(!editManager->vertexOk(**vertex, &newRoom))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
newRoom.addVertex(*vertex);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if(!v)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if(!editManager->vertexOk(*v, &newRoom))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
newRoom.addVertex(*v);
|
||||||
|
}
|
||||||
|
|
||||||
editManager->redraw();
|
editManager->redraw();
|
||||||
sidebar.update();
|
sidebar.update();
|
||||||
|
|
|
@ -10,6 +10,7 @@ Room ToolAddRect::createRoom() {
|
||||||
room.addVertex(Vertex(v1.getX(), v2->getY()));
|
room.addVertex(Vertex(v1.getX(), v2->getY()));
|
||||||
room.addVertex(*v2);
|
room.addVertex(*v2);
|
||||||
room.addVertex(Vertex(v2->getX(), v1.getY()));
|
room.addVertex(Vertex(v2->getX(), v1.getY()));
|
||||||
|
room.close();
|
||||||
|
|
||||||
return room;
|
return room;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,8 @@
|
||||||
#include "Vertex.h"
|
#include "Vertex.h"
|
||||||
|
|
||||||
|
|
||||||
|
class LevelVertex;
|
||||||
|
|
||||||
class VertexProvider {
|
class VertexProvider {
|
||||||
public:
|
public:
|
||||||
virtual ~VertexProvider() {}
|
virtual ~VertexProvider() {}
|
||||||
|
@ -15,7 +17,7 @@ class VertexProvider {
|
||||||
virtual void rotateVertex(size_t id, Vertex m, float a) {}
|
virtual void rotateVertex(size_t id, Vertex m, float a) {}
|
||||||
|
|
||||||
virtual bool canConnectVertex(size_t id) const {return false;}
|
virtual bool canConnectVertex(size_t id) const {return false;}
|
||||||
virtual void connectVertex(size_t id) {}
|
virtual size_t connectVertex(size_t id) {return id;}
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /*VERTEXPROVIDER_H_*/
|
#endif /*VERTEXPROVIDER_H_*/
|
||||||
|
|
Reference in a new issue