Support multiple connections in same direction, and darken non-selected connections
This commit is contained in:
parent
8df2a864a0
commit
9a6132314c
5 changed files with 204 additions and 141 deletions
281
editor.cpp
281
editor.cpp
|
@ -50,10 +50,8 @@ void Editor::setEditingMap() {
|
||||||
if (objects_group) {
|
if (objects_group) {
|
||||||
objects_group->setVisible(false);
|
objects_group->setVisible(false);
|
||||||
}
|
}
|
||||||
if (connection_item) {
|
setBorderItemsVisible(true);
|
||||||
connection_item->setVisible(false);
|
setConnectionItemsVisible(false);
|
||||||
connection_item->setEnabled(false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Editor::setEditingCollision() {
|
void Editor::setEditingCollision() {
|
||||||
|
@ -68,10 +66,8 @@ void Editor::setEditingCollision() {
|
||||||
if (objects_group) {
|
if (objects_group) {
|
||||||
objects_group->setVisible(false);
|
objects_group->setVisible(false);
|
||||||
}
|
}
|
||||||
if (connection_item) {
|
setBorderItemsVisible(true);
|
||||||
connection_item->setVisible(false);
|
setConnectionItemsVisible(false);
|
||||||
connection_item->setEnabled(false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Editor::setEditingObjects() {
|
void Editor::setEditingObjects() {
|
||||||
|
@ -87,13 +83,11 @@ void Editor::setEditingObjects() {
|
||||||
if (collision_item) {
|
if (collision_item) {
|
||||||
collision_item->setVisible(false);
|
collision_item->setVisible(false);
|
||||||
}
|
}
|
||||||
if (connection_item) {
|
setBorderItemsVisible(true);
|
||||||
connection_item->setVisible(false);
|
setConnectionItemsVisible(false);
|
||||||
connection_item->setEnabled(false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Editor::setEditingConnections(QString direction) {
|
void Editor::setEditingConnections() {
|
||||||
current_view = map_item;
|
current_view = map_item;
|
||||||
if (map_item) {
|
if (map_item) {
|
||||||
map_item->draw();
|
map_item->draw();
|
||||||
|
@ -104,7 +98,10 @@ void Editor::setEditingConnections(QString direction) {
|
||||||
ui->comboBox_ConnectedMap->addItems(*project->mapNames);
|
ui->comboBox_ConnectedMap->addItems(*project->mapNames);
|
||||||
ui->comboBox_ConnectedMap->blockSignals(false);
|
ui->comboBox_ConnectedMap->blockSignals(false);
|
||||||
setConnectionsVisibility(false);
|
setConnectionsVisibility(false);
|
||||||
showCurrentConnectionMap(direction);
|
if (current_connection_edit_item) {
|
||||||
|
onConnectionOffsetChanged(current_connection_edit_item->connection->offset.toInt());
|
||||||
|
updateConnectionMap(current_connection_edit_item->connection->map_name, current_connection_edit_item->connection->direction);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (collision_item) {
|
if (collision_item) {
|
||||||
collision_item->setVisible(false);
|
collision_item->setVisible(false);
|
||||||
|
@ -112,71 +109,63 @@ void Editor::setEditingConnections(QString direction) {
|
||||||
if (objects_group) {
|
if (objects_group) {
|
||||||
objects_group->setVisible(false);
|
objects_group->setVisible(false);
|
||||||
}
|
}
|
||||||
|
setBorderItemsVisible(true, 0.4);
|
||||||
|
setConnectionItemsVisible(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Editor::showCurrentConnectionMap(QString curDirection) {
|
void Editor::setConnectionItemsVisible(bool visible) {
|
||||||
bool connectionExists = false;
|
for (ConnectionPixmapItem* item : connection_edit_items) {
|
||||||
for (Connection* connection : map->connections) {
|
item->setVisible(visible);
|
||||||
if (connection->direction != curDirection) continue;
|
item->setEnabled(visible);
|
||||||
if (connection_item) {
|
}
|
||||||
scene->removeItem(connection_item);
|
}
|
||||||
delete connection_item;
|
|
||||||
connection_item = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
connectionExists = true;
|
void Editor::setBorderItemsVisible(bool visible, qreal opacity) {
|
||||||
Map *connected_map = project->getMap(connection->map_name);
|
for (QGraphicsPixmapItem* item : borderItems) {
|
||||||
QPixmap pixmap = connected_map->renderConnection(*connection);
|
item->setVisible(visible);
|
||||||
int offset = connection->offset.toInt(nullptr, 0);
|
item->setOpacity(opacity);
|
||||||
int x = 0, y = 0;
|
}
|
||||||
if (connection->direction == "up") {
|
}
|
||||||
x = offset * 16;
|
|
||||||
y = -pixmap.height();
|
|
||||||
} else if (connection->direction == "down") {
|
|
||||||
x = offset * 16;
|
|
||||||
y = map->getHeight() * 16;
|
|
||||||
} else if (connection->direction == "left") {
|
|
||||||
x = -pixmap.width();
|
|
||||||
y = offset * 16;
|
|
||||||
} else if (connection->direction == "right") {
|
|
||||||
x = map->getWidth() * 16;
|
|
||||||
y = offset * 16;
|
|
||||||
}
|
|
||||||
|
|
||||||
QPainter painter(&pixmap);
|
void Editor::setCurrentConnectionDirection(QString curDirection) {
|
||||||
painter.setPen(QColor(255, 0, 255));
|
if (!current_connection_edit_item)
|
||||||
painter.drawRect(0, 0, pixmap.width() - 1, pixmap.height() - 1);
|
return;
|
||||||
painter.end();
|
|
||||||
connection_item = new ConnectionPixmapItem(pixmap, connection, x, y);
|
|
||||||
connection_item->setX(x);
|
|
||||||
connection_item->setY(y);
|
|
||||||
connection_item->setZValue(21);
|
|
||||||
scene->addItem(connection_item);
|
|
||||||
|
|
||||||
connect(connection_item, SIGNAL(connectionMoved(int)), this, SLOT(onConnectionOffsetChanged(int)));
|
current_connection_edit_item->connection->direction = curDirection;
|
||||||
onConnectionOffsetChanged(connection->offset.toInt());
|
Map *connected_map = project->getMap(current_connection_edit_item->connection->map_name);
|
||||||
|
QPixmap pixmap = connected_map->renderConnection(*current_connection_edit_item->connection);
|
||||||
ui->comboBox_ConnectedMap->setCurrentText(connection->map_name);
|
int offset = current_connection_edit_item->connection->offset.toInt(nullptr, 0);
|
||||||
break;
|
current_connection_edit_item->initialOffset = offset;
|
||||||
|
int x = 0, y = 0;
|
||||||
|
if (current_connection_edit_item->connection->direction == "up") {
|
||||||
|
x = offset * 16;
|
||||||
|
y = -pixmap.height();
|
||||||
|
} else if (current_connection_edit_item->connection->direction == "down") {
|
||||||
|
x = offset * 16;
|
||||||
|
y = map->getHeight() * 16;
|
||||||
|
} else if (current_connection_edit_item->connection->direction == "left") {
|
||||||
|
x = -pixmap.width();
|
||||||
|
y = offset * 16;
|
||||||
|
} else if (current_connection_edit_item->connection->direction == "right") {
|
||||||
|
x = map->getWidth() * 16;
|
||||||
|
y = offset * 16;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!connectionExists) {
|
current_connection_edit_item->basePixmap = pixmap;
|
||||||
if (connection_item) {
|
QPainter painter(&pixmap);
|
||||||
delete connection_item;
|
painter.setPen(QColor(255, 0, 255));
|
||||||
connection_item = NULL;
|
painter.drawRect(0, 0, pixmap.width() - 1, pixmap.height() - 1);
|
||||||
|
painter.end();
|
||||||
|
current_connection_edit_item->setPixmap(pixmap);
|
||||||
|
current_connection_edit_item->initialX = x;
|
||||||
|
current_connection_edit_item->initialY = y;
|
||||||
|
current_connection_edit_item->blockSignals(true);
|
||||||
|
current_connection_edit_item->setX(x);
|
||||||
|
current_connection_edit_item->setY(y);
|
||||||
|
current_connection_edit_item->setZValue(-1);
|
||||||
|
current_connection_edit_item->blockSignals(false);
|
||||||
|
|
||||||
if (map->connection_items.contains(curDirection)) {
|
setConnectionEditControlValues(current_connection_edit_item->connection);
|
||||||
delete map->connection_items.value(curDirection);
|
|
||||||
map->connection_items.remove(curDirection);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ui->comboBox_ConnectedMap->setCurrentText("");
|
|
||||||
ui->spinBox_ConnectionOffset->setDisabled(true);
|
|
||||||
ui->spinBox_ConnectionOffset->setValue(0);
|
|
||||||
} else {
|
|
||||||
ui->spinBox_ConnectionOffset->setDisabled(false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Editor::onConnectionOffsetChanged(int newOffset) {
|
void Editor::onConnectionOffsetChanged(int newOffset) {
|
||||||
|
@ -185,6 +174,54 @@ void Editor::onConnectionOffsetChanged(int newOffset) {
|
||||||
ui->spinBox_ConnectionOffset->blockSignals(false);
|
ui->spinBox_ConnectionOffset->blockSignals(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Editor::setConnectionEditControlValues(Connection* connection) {
|
||||||
|
ui->comboBox_ConnectedMap->blockSignals(true);
|
||||||
|
ui->comboBox_ConnectionDirection->blockSignals(true);
|
||||||
|
ui->spinBox_ConnectionOffset->blockSignals(true);
|
||||||
|
|
||||||
|
ui->comboBox_ConnectedMap->setCurrentText(connection->map_name);
|
||||||
|
ui->comboBox_ConnectionDirection->setCurrentText(connection->direction);
|
||||||
|
ui->spinBox_ConnectionOffset->setValue(connection->offset.toInt());
|
||||||
|
|
||||||
|
ui->comboBox_ConnectedMap->blockSignals(false);
|
||||||
|
ui->comboBox_ConnectionDirection->blockSignals(false);
|
||||||
|
ui->spinBox_ConnectionOffset->blockSignals(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Editor::setConnectionEditControlsEnabled(bool enabled) {
|
||||||
|
ui->comboBox_ConnectionDirection->setEnabled(enabled);
|
||||||
|
ui->comboBox_ConnectedMap->setEnabled(enabled);
|
||||||
|
ui->spinBox_ConnectionOffset->setEnabled(enabled);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Editor::onConnectionItemSelected(ConnectionPixmapItem* connectionItem) {
|
||||||
|
for (ConnectionPixmapItem* item : connection_edit_items) {
|
||||||
|
bool isSelectedItem = item == connectionItem;
|
||||||
|
int zValue = isSelectedItem ? 0 : -1;
|
||||||
|
qreal opacity = isSelectedItem ? 1 : 0.75;
|
||||||
|
item->setZValue(zValue);
|
||||||
|
item->render(opacity);
|
||||||
|
if (isSelectedItem) {
|
||||||
|
QPixmap pixmap = item->pixmap();
|
||||||
|
QPainter painter(&pixmap);
|
||||||
|
painter.setPen(QColor(255, 0, 255));
|
||||||
|
painter.drawRect(0, 0, pixmap.width() - 1, pixmap.height() - 1);
|
||||||
|
painter.end();
|
||||||
|
item->setPixmap(pixmap);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
current_connection_edit_item = connectionItem;
|
||||||
|
current_connection_edit_item->setZValue(0);
|
||||||
|
setConnectionEditControlsEnabled(true);
|
||||||
|
setConnectionEditControlValues(current_connection_edit_item->connection);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Editor::onConnectionDirectionChanged(QString newDirection) {
|
||||||
|
ui->comboBox_ConnectionDirection->blockSignals(true);
|
||||||
|
ui->comboBox_ConnectionDirection->setCurrentText(newDirection);
|
||||||
|
ui->comboBox_ConnectionDirection->blockSignals(false);
|
||||||
|
}
|
||||||
|
|
||||||
void Editor::setConnectionsVisibility(bool visible) {
|
void Editor::setConnectionsVisibility(bool visible) {
|
||||||
for (QGraphicsPixmapItem* item : map->connection_items) {
|
for (QGraphicsPixmapItem* item : map->connection_items) {
|
||||||
item->setVisible(visible);
|
item->setVisible(visible);
|
||||||
|
@ -320,10 +357,16 @@ DraggablePixmapItem *Editor::addMapObject(Event *event) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Editor::displayMapConnections() {
|
void Editor::displayMapConnections() {
|
||||||
for (QString key : map->connection_items.keys()) {
|
for (QGraphicsPixmapItem* item : map->connection_items) {
|
||||||
scene->removeItem(map->connection_items.value(key));
|
scene->removeItem(item);
|
||||||
delete map->connection_items.value(key);
|
delete item;
|
||||||
}
|
}
|
||||||
|
map->connection_items.clear();
|
||||||
|
|
||||||
|
for (ConnectionPixmapItem* item : connection_edit_items) {
|
||||||
|
delete item;
|
||||||
|
}
|
||||||
|
connection_edit_items.clear();
|
||||||
|
|
||||||
for (Connection *connection : map->connections) {
|
for (Connection *connection : map->connections) {
|
||||||
if (connection->direction == "dive" || connection->direction == "emerge") {
|
if (connection->direction == "dive" || connection->direction == "emerge") {
|
||||||
|
@ -346,12 +389,26 @@ void Editor::displayMapConnections() {
|
||||||
x = map->getWidth() * 16;
|
x = map->getWidth() * 16;
|
||||||
y = offset * 16;
|
y = offset * 16;
|
||||||
}
|
}
|
||||||
|
|
||||||
QGraphicsPixmapItem *item = new QGraphicsPixmapItem(pixmap);
|
QGraphicsPixmapItem *item = new QGraphicsPixmapItem(pixmap);
|
||||||
item->setZValue(-1);
|
item->setZValue(-1);
|
||||||
item->setX(x);
|
item->setX(x);
|
||||||
item->setY(y);
|
item->setY(y);
|
||||||
scene->addItem(item);
|
scene->addItem(item);
|
||||||
map->connection_items.insert(connection->direction, item);
|
map->connection_items.append(item);
|
||||||
|
|
||||||
|
ConnectionPixmapItem *connection_edit_item = new ConnectionPixmapItem(pixmap, connection, x, y);
|
||||||
|
connection_edit_item->setX(x);
|
||||||
|
connection_edit_item->setY(y);
|
||||||
|
connection_edit_item->setZValue(-1);
|
||||||
|
scene->addItem(connection_edit_item);
|
||||||
|
connect(connection_edit_item, SIGNAL(connectionMoved(int)), this, SLOT(onConnectionOffsetChanged(int)));
|
||||||
|
connect(connection_edit_item, SIGNAL(connectionItemSelected(ConnectionPixmapItem*)), this, SLOT(onConnectionItemSelected(ConnectionPixmapItem*)));
|
||||||
|
connection_edit_items.append(connection_edit_item);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!connection_edit_items.empty()) {
|
||||||
|
onConnectionItemSelected(connection_edit_items.first());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -364,6 +421,7 @@ void Editor::displayMapBorder() {
|
||||||
item->setY(y * 16);
|
item->setY(y * 16);
|
||||||
item->setZValue(-2);
|
item->setZValue(-2);
|
||||||
scene->addItem(item);
|
scene->addItem(item);
|
||||||
|
borderItems.append(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -385,17 +443,17 @@ void Editor::displayMapGrid() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Editor::updateConnectionOffset(int offset) {
|
void Editor::updateConnectionOffset(int offset) {
|
||||||
if (!connection_item)
|
if (!current_connection_edit_item)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
connection_item->blockSignals(true);
|
current_connection_edit_item->blockSignals(true);
|
||||||
connection_item->connection->offset = QString::number(offset);
|
current_connection_edit_item->connection->offset = QString::number(offset);
|
||||||
if (connection_item->connection->direction == "up" || connection_item->connection->direction == "down") {
|
if (current_connection_edit_item->connection->direction == "up" || current_connection_edit_item->connection->direction == "down") {
|
||||||
connection_item->setX(connection_item->initialX + (offset - connection_item->initialOffset) * 16);
|
current_connection_edit_item->setX(current_connection_edit_item->initialX + (offset - current_connection_edit_item->initialOffset) * 16);
|
||||||
} else {
|
} else {
|
||||||
connection_item->setY(connection_item->initialY + (offset - connection_item->initialOffset) * 16);
|
current_connection_edit_item->setY(current_connection_edit_item->initialY + (offset - current_connection_edit_item->initialOffset) * 16);
|
||||||
}
|
}
|
||||||
connection_item->blockSignals(false);
|
current_connection_edit_item->blockSignals(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Editor::updateConnectionMap(QString mapName, QString direction) {
|
void Editor::updateConnectionMap(QString mapName, QString direction) {
|
||||||
|
@ -403,31 +461,24 @@ void Editor::updateConnectionMap(QString mapName, QString direction) {
|
||||||
qDebug() << "Invalid map name " << mapName << " specified for connection.";
|
qDebug() << "Invalid map name " << mapName << " specified for connection.";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (!current_connection_edit_item)
|
||||||
|
return;
|
||||||
|
|
||||||
if (connection_item) {
|
if (mapName.isEmpty()) {
|
||||||
// Find the connection we are updating.
|
map->connections.removeOne(current_connection_edit_item->connection);
|
||||||
bool foundConnection = false;
|
connection_edit_items.removeOne(current_connection_edit_item);
|
||||||
for (Connection* connection : map->connections) {
|
scene->removeItem(current_connection_edit_item);
|
||||||
if (connection->direction == direction) {
|
delete current_connection_edit_item;
|
||||||
foundConnection = true;
|
current_connection_edit_item = NULL;
|
||||||
if (mapName.isEmpty()) {
|
setConnectionEditControlsEnabled(false);
|
||||||
map->connections.removeOne(connection);
|
ui->spinBox_ConnectionOffset->setValue(0);
|
||||||
} else {
|
return;
|
||||||
connection->map_name = mapName;
|
} else {
|
||||||
}
|
setConnectionEditControlsEnabled(true);
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (!mapName.isEmpty()) {
|
|
||||||
// Create a brand new connection.
|
|
||||||
Connection* newConnection = new Connection;
|
|
||||||
newConnection->direction = direction;
|
|
||||||
newConnection->offset = "0";
|
|
||||||
newConnection->map_name = mapName;
|
|
||||||
map->connections.append(newConnection);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
showCurrentConnectionMap(direction);
|
current_connection_edit_item->connection->map_name = mapName;
|
||||||
|
setCurrentConnectionDirection(direction);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MetatilesPixmapItem::paintTileChanged(Map *map) {
|
void MetatilesPixmapItem::paintTileChanged(Map *map) {
|
||||||
|
@ -543,24 +594,8 @@ QVariant ConnectionPixmapItem::itemChange(GraphicsItemChange change, const QVari
|
||||||
return QGraphicsItem::itemChange(change, value);
|
return QGraphicsItem::itemChange(change, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void ConnectionPixmapItem::dragEnterEvent(QGraphicsSceneDragDropEvent *event) {
|
|
||||||
QPointF pos = event->pos();
|
|
||||||
qDebug() << "enter: " << pos.x() << ", " << pos.y();
|
|
||||||
}
|
|
||||||
void ConnectionPixmapItem::dragMoveEvent(QGraphicsSceneDragDropEvent *event) {
|
|
||||||
QPointF pos = event->pos();
|
|
||||||
qDebug() << "drag: " << pos.x() << ", " << pos.y();
|
|
||||||
}
|
|
||||||
void ConnectionPixmapItem::dragLeaveEvent(QGraphicsSceneDragDropEvent *event) {
|
|
||||||
QPointF pos = event->pos();
|
|
||||||
qDebug() << "leave: " << pos.x() << ", " << pos.y();
|
|
||||||
}
|
|
||||||
void ConnectionPixmapItem::dropEvent(QGraphicsSceneDragDropEvent *event) {
|
|
||||||
QPointF pos = event->pos();
|
|
||||||
qDebug() << "drop: " << pos.x() << ", " << pos.y();
|
|
||||||
}
|
|
||||||
void ConnectionPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent* event) {
|
void ConnectionPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent* event) {
|
||||||
QPointF pos = event->pos();
|
emit connectionItemSelected(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ElevationMetatilesPixmapItem::updateCurHoveredMetatile(QPointF pos) {
|
void ElevationMetatilesPixmapItem::updateCurHoveredMetatile(QPointF pos) {
|
||||||
|
@ -694,10 +729,6 @@ void MapPixmapItem::paintSmartPath(int x, int y) {
|
||||||
if (left && IS_SMART_PATH_TILE(left))
|
if (left && IS_SMART_PATH_TILE(left))
|
||||||
id += 8;
|
id += 8;
|
||||||
|
|
||||||
if (block) {
|
|
||||||
qDebug() << "tile: " << block->tile << "base: " << map->paint_tile << "id: " << id;
|
|
||||||
}
|
|
||||||
|
|
||||||
block->tile = map->paint_tile + smartPathTable[id];;
|
block->tile = map->paint_tile + smartPathTable[id];;
|
||||||
map->_setBlock(actualX, actualY, *block);
|
map->_setBlock(actualX, actualY, *block);
|
||||||
}
|
}
|
||||||
|
|
33
editor.h
33
editor.h
|
@ -46,8 +46,8 @@ public:
|
||||||
void setEditingMap();
|
void setEditingMap();
|
||||||
void setEditingCollision();
|
void setEditingCollision();
|
||||||
void setEditingObjects();
|
void setEditingObjects();
|
||||||
void setEditingConnections(QString direction);
|
void setEditingConnections();
|
||||||
void showCurrentConnectionMap(QString curDirection);
|
void setCurrentConnectionDirection(QString curDirection);
|
||||||
void setConnectionsVisibility(bool visible);
|
void setConnectionsVisibility(bool visible);
|
||||||
void updateConnectionOffset(int offset);
|
void updateConnectionOffset(int offset);
|
||||||
void updateConnectionMap(QString mapName, QString direction);
|
void updateConnectionMap(QString mapName, QString direction);
|
||||||
|
@ -65,9 +65,11 @@ public:
|
||||||
QGraphicsScene *scene = NULL;
|
QGraphicsScene *scene = NULL;
|
||||||
QGraphicsPixmapItem *current_view = NULL;
|
QGraphicsPixmapItem *current_view = NULL;
|
||||||
MapPixmapItem *map_item = NULL;
|
MapPixmapItem *map_item = NULL;
|
||||||
ConnectionPixmapItem *connection_item = NULL;
|
ConnectionPixmapItem* current_connection_edit_item = NULL;
|
||||||
|
QList<ConnectionPixmapItem*> connection_edit_items;
|
||||||
CollisionPixmapItem *collision_item = NULL;
|
CollisionPixmapItem *collision_item = NULL;
|
||||||
QGraphicsItemGroup *objects_group = NULL;
|
QGraphicsItemGroup *objects_group = NULL;
|
||||||
|
QList<QGraphicsPixmapItem*> borderItems;
|
||||||
|
|
||||||
QGraphicsScene *scene_metatiles = NULL;
|
QGraphicsScene *scene_metatiles = NULL;
|
||||||
QGraphicsScene *scene_collision_metatiles = NULL;
|
QGraphicsScene *scene_collision_metatiles = NULL;
|
||||||
|
@ -85,10 +87,18 @@ public:
|
||||||
void objectsView_onMouseMove(QMouseEvent *event);
|
void objectsView_onMouseMove(QMouseEvent *event);
|
||||||
void objectsView_onMouseRelease(QMouseEvent *event);
|
void objectsView_onMouseRelease(QMouseEvent *event);
|
||||||
|
|
||||||
|
private:
|
||||||
|
void setConnectionItemsVisible(bool);
|
||||||
|
void setBorderItemsVisible(bool, qreal = 1);
|
||||||
|
void setConnectionEditControlValues(Connection*);
|
||||||
|
void setConnectionEditControlsEnabled(bool);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void mouseEvent_map(QGraphicsSceneMouseEvent *event, MapPixmapItem *item);
|
void mouseEvent_map(QGraphicsSceneMouseEvent *event, MapPixmapItem *item);
|
||||||
void mouseEvent_collision(QGraphicsSceneMouseEvent *event, CollisionPixmapItem *item);
|
void mouseEvent_collision(QGraphicsSceneMouseEvent *event, CollisionPixmapItem *item);
|
||||||
void onConnectionOffsetChanged(int newOffset);
|
void onConnectionOffsetChanged(int newOffset);
|
||||||
|
void onConnectionItemSelected(ConnectionPixmapItem* connectionItem);
|
||||||
|
void onConnectionDirectionChanged(QString newDirection);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void objectsChanged();
|
void objectsChanged();
|
||||||
|
@ -253,6 +263,7 @@ class ConnectionPixmapItem : public QObject, public QGraphicsPixmapItem {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
ConnectionPixmapItem(QPixmap pixmap, Connection* connection, int x, int y): QGraphicsPixmapItem(pixmap) {
|
ConnectionPixmapItem(QPixmap pixmap, Connection* connection, int x, int y): QGraphicsPixmapItem(pixmap) {
|
||||||
|
this->basePixmap = pixmap;
|
||||||
this->connection = connection;
|
this->connection = connection;
|
||||||
setFlag(ItemIsMovable);
|
setFlag(ItemIsMovable);
|
||||||
setFlag(ItemSendsGeometryChanges);
|
setFlag(ItemSendsGeometryChanges);
|
||||||
|
@ -260,18 +271,26 @@ public:
|
||||||
this->initialY = y;
|
this->initialY = y;
|
||||||
this->initialOffset = connection->offset.toInt();
|
this->initialOffset = connection->offset.toInt();
|
||||||
}
|
}
|
||||||
|
void render(qreal opacity = 1) {
|
||||||
|
QPixmap newPixmap = basePixmap.copy(0, 0, basePixmap.width(), basePixmap.height());
|
||||||
|
if (opacity < 1) {
|
||||||
|
QPainter painter(&newPixmap);
|
||||||
|
int alpha = (int)(255 * (1 - opacity));
|
||||||
|
painter.fillRect(0, 0, newPixmap.width(), newPixmap.height(), QColor(0, 0, 0, alpha));
|
||||||
|
painter.end();
|
||||||
|
}
|
||||||
|
this->setPixmap(newPixmap);
|
||||||
|
}
|
||||||
|
QPixmap basePixmap;
|
||||||
Connection* connection;
|
Connection* connection;
|
||||||
int initialX;
|
int initialX;
|
||||||
int initialY;
|
int initialY;
|
||||||
int initialOffset;
|
int initialOffset;
|
||||||
protected:
|
protected:
|
||||||
QVariant itemChange(GraphicsItemChange change, const QVariant &value);
|
QVariant itemChange(GraphicsItemChange change, const QVariant &value);
|
||||||
void dragEnterEvent(QGraphicsSceneDragDropEvent *event) override;
|
|
||||||
void dragLeaveEvent(QGraphicsSceneDragDropEvent *event) override;
|
|
||||||
void dropEvent(QGraphicsSceneDragDropEvent *event) override;
|
|
||||||
void dragMoveEvent(QGraphicsSceneDragDropEvent *event) override;
|
|
||||||
void mousePressEvent(QGraphicsSceneMouseEvent*);
|
void mousePressEvent(QGraphicsSceneMouseEvent*);
|
||||||
signals:
|
signals:
|
||||||
|
void connectionItemSelected(ConnectionPixmapItem* connectionItem);
|
||||||
void connectionMoved(int offset);
|
void connectionMoved(int offset);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -487,7 +487,7 @@ void MainWindow::on_tabWidget_currentChanged(int index)
|
||||||
} else if (index == 1) {
|
} else if (index == 1) {
|
||||||
editor->setEditingObjects();
|
editor->setEditingObjects();
|
||||||
} else if (index == 3) {
|
} else if (index == 3) {
|
||||||
editor->setEditingConnections(ui->comboBox_ConnectionDirection->currentText().toLower());
|
editor->setEditingConnections();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -768,7 +768,7 @@ void MainWindow::on_action_Export_Map_Image_triggered()
|
||||||
|
|
||||||
void MainWindow::on_comboBox_ConnectionDirection_currentIndexChanged(const QString &direction)
|
void MainWindow::on_comboBox_ConnectionDirection_currentIndexChanged(const QString &direction)
|
||||||
{
|
{
|
||||||
editor->showCurrentConnectionMap(direction.toLower());
|
editor->setCurrentConnectionDirection(direction);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_spinBox_ConnectionOffset_valueChanged(int offset)
|
void MainWindow::on_spinBox_ConnectionOffset_valueChanged(int offset)
|
||||||
|
|
|
@ -1286,22 +1286,22 @@
|
||||||
<widget class="QComboBox" name="comboBox_ConnectionDirection">
|
<widget class="QComboBox" name="comboBox_ConnectionDirection">
|
||||||
<item>
|
<item>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Up</string>
|
<string>up</string>
|
||||||
</property>
|
</property>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Right</string>
|
<string>right</string>
|
||||||
</property>
|
</property>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Down</string>
|
<string>down</string>
|
||||||
</property>
|
</property>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Left</string>
|
<string>left</string>
|
||||||
</property>
|
</property>
|
||||||
</item>
|
</item>
|
||||||
</widget>
|
</widget>
|
||||||
|
@ -1346,7 +1346,10 @@
|
||||||
<item>
|
<item>
|
||||||
<widget class="QSpinBox" name="spinBox_ConnectionOffset">
|
<widget class="QSpinBox" name="spinBox_ConnectionOffset">
|
||||||
<property name="minimum">
|
<property name="minimum">
|
||||||
<number>-99</number>
|
<number>-999</number>
|
||||||
|
</property>
|
||||||
|
<property name="maximum">
|
||||||
|
<number>999</number>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
@ -1412,7 +1415,17 @@
|
||||||
</property>
|
</property>
|
||||||
<layout class="QGridLayout" name="gridLayout_14">
|
<layout class="QGridLayout" name="gridLayout_14">
|
||||||
<item row="1" column="1">
|
<item row="1" column="1">
|
||||||
<widget class="QGraphicsView" name="graphicsView_Connections"/>
|
<widget class="QGraphicsView" name="graphicsView_Connections">
|
||||||
|
<property name="backgroundBrush">
|
||||||
|
<brush brushstyle="SolidPattern">
|
||||||
|
<color alpha="255">
|
||||||
|
<red>0</red>
|
||||||
|
<green>0</green>
|
||||||
|
<blue>0</blue>
|
||||||
|
</color>
|
||||||
|
</brush>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="0">
|
<item row="1" column="0">
|
||||||
<spacer name="horizontalSpacer_7">
|
<spacer name="horizontalSpacer_7">
|
||||||
|
|
2
map.h
2
map.h
|
@ -180,7 +180,7 @@ public:
|
||||||
QMap<QString, QList<Event*>> events;
|
QMap<QString, QList<Event*>> events;
|
||||||
|
|
||||||
QList<Connection*> connections;
|
QList<Connection*> connections;
|
||||||
QMap<QString, QGraphicsPixmapItem*> connection_items;
|
QList<QGraphicsPixmapItem*> connection_items;
|
||||||
QPixmap renderConnection(Connection);
|
QPixmap renderConnection(Connection);
|
||||||
|
|
||||||
QImage border_image;
|
QImage border_image;
|
||||||
|
|
Loading…
Reference in a new issue