Support adding/removing connections via buttons
This commit is contained in:
parent
9a6132314c
commit
5301b299e2
5 changed files with 203 additions and 44 deletions
126
editor.cpp
126
editor.cpp
|
@ -97,6 +97,7 @@ void Editor::setEditingConnections() {
|
||||||
ui->comboBox_ConnectedMap->clear();
|
ui->comboBox_ConnectedMap->clear();
|
||||||
ui->comboBox_ConnectedMap->addItems(*project->mapNames);
|
ui->comboBox_ConnectedMap->addItems(*project->mapNames);
|
||||||
ui->comboBox_ConnectedMap->blockSignals(false);
|
ui->comboBox_ConnectedMap->blockSignals(false);
|
||||||
|
ui->label_NumConnections->setText(QString::number(map->connections.length()));
|
||||||
setConnectionsVisibility(false);
|
setConnectionsVisibility(false);
|
||||||
if (current_connection_edit_item) {
|
if (current_connection_edit_item) {
|
||||||
onConnectionOffsetChanged(current_connection_edit_item->connection->offset.toInt());
|
onConnectionOffsetChanged(current_connection_edit_item->connection->offset.toInt());
|
||||||
|
@ -195,6 +196,9 @@ void Editor::setConnectionEditControlsEnabled(bool enabled) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Editor::onConnectionItemSelected(ConnectionPixmapItem* connectionItem) {
|
void Editor::onConnectionItemSelected(ConnectionPixmapItem* connectionItem) {
|
||||||
|
if (!connectionItem)
|
||||||
|
return;
|
||||||
|
|
||||||
for (ConnectionPixmapItem* item : connection_edit_items) {
|
for (ConnectionPixmapItem* item : connection_edit_items) {
|
||||||
bool isSelectedItem = item == connectionItem;
|
bool isSelectedItem = item == connectionItem;
|
||||||
int zValue = isSelectedItem ? 0 : -1;
|
int zValue = isSelectedItem ? 0 : -1;
|
||||||
|
@ -372,39 +376,7 @@ void Editor::displayMapConnections() {
|
||||||
if (connection->direction == "dive" || connection->direction == "emerge") {
|
if (connection->direction == "dive" || connection->direction == "emerge") {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
Map *connected_map = project->getMap(connection->map_name);
|
createConnectionItem(connection, false);
|
||||||
QPixmap pixmap = connected_map->renderConnection(*connection);
|
|
||||||
int offset = connection->offset.toInt(nullptr, 0);
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
QGraphicsPixmapItem *item = new QGraphicsPixmapItem(pixmap);
|
|
||||||
item->setZValue(-1);
|
|
||||||
item->setX(x);
|
|
||||||
item->setY(y);
|
|
||||||
scene->addItem(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()) {
|
if (!connection_edit_items.empty()) {
|
||||||
|
@ -412,6 +384,43 @@ void Editor::displayMapConnections() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Editor::createConnectionItem(Connection* connection, bool hide) {
|
||||||
|
Map *connected_map = project->getMap(connection->map_name);
|
||||||
|
QPixmap pixmap = connected_map->renderConnection(*connection);
|
||||||
|
int offset = connection->offset.toInt(nullptr, 0);
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
QGraphicsPixmapItem *item = new QGraphicsPixmapItem(pixmap);
|
||||||
|
item->setZValue(-1);
|
||||||
|
item->setX(x);
|
||||||
|
item->setY(y);
|
||||||
|
scene->addItem(item);
|
||||||
|
map->connection_items.append(item);
|
||||||
|
item->setVisible(!hide);
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
void Editor::displayMapBorder() {
|
void Editor::displayMapBorder() {
|
||||||
QPixmap pixmap = map->renderBorder();
|
QPixmap pixmap = map->renderBorder();
|
||||||
for (int y = -6; y < map->getHeight() + 6; y += 2)
|
for (int y = -6; y < map->getHeight() + 6; y += 2)
|
||||||
|
@ -465,13 +474,7 @@ void Editor::updateConnectionMap(QString mapName, QString direction) {
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (mapName.isEmpty()) {
|
if (mapName.isEmpty()) {
|
||||||
map->connections.removeOne(current_connection_edit_item->connection);
|
removeCurrentConnection();
|
||||||
connection_edit_items.removeOne(current_connection_edit_item);
|
|
||||||
scene->removeItem(current_connection_edit_item);
|
|
||||||
delete current_connection_edit_item;
|
|
||||||
current_connection_edit_item = NULL;
|
|
||||||
setConnectionEditControlsEnabled(false);
|
|
||||||
ui->spinBox_ConnectionOffset->setValue(0);
|
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
setConnectionEditControlsEnabled(true);
|
setConnectionEditControlsEnabled(true);
|
||||||
|
@ -481,6 +484,49 @@ void Editor::updateConnectionMap(QString mapName, QString direction) {
|
||||||
setCurrentConnectionDirection(direction);
|
setCurrentConnectionDirection(direction);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Editor::addNewConnection() {
|
||||||
|
// Find direction with least number of connections.
|
||||||
|
QMap<QString, int> directionCounts = QMap<QString, int>({{"up", 0}, {"right", 0}, {"down", 0}, {"left", 0}});
|
||||||
|
for (Connection* connection : map->connections) {
|
||||||
|
directionCounts[connection->direction]++;
|
||||||
|
}
|
||||||
|
QString minDirection = "up";
|
||||||
|
int minCount = INT_MAX;
|
||||||
|
for (QString direction : directionCounts.keys()) {
|
||||||
|
if (directionCounts[direction] < minCount) {
|
||||||
|
minDirection = direction;
|
||||||
|
minCount = directionCounts[direction];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Connection* newConnection = new Connection;
|
||||||
|
newConnection->direction = minDirection;
|
||||||
|
newConnection->offset = "0";
|
||||||
|
newConnection->map_name = project->mapNames->first();
|
||||||
|
map->connections.append(newConnection);
|
||||||
|
createConnectionItem(newConnection, true);
|
||||||
|
onConnectionItemSelected(connection_edit_items.last());
|
||||||
|
ui->label_NumConnections->setText(QString::number(map->connections.length()));
|
||||||
|
}
|
||||||
|
|
||||||
|
void Editor::removeCurrentConnection() {
|
||||||
|
if (!current_connection_edit_item)
|
||||||
|
return;
|
||||||
|
|
||||||
|
map->connections.removeOne(current_connection_edit_item->connection);
|
||||||
|
connection_edit_items.removeOne(current_connection_edit_item);
|
||||||
|
scene->removeItem(current_connection_edit_item);
|
||||||
|
delete current_connection_edit_item;
|
||||||
|
current_connection_edit_item = NULL;
|
||||||
|
setConnectionEditControlsEnabled(false);
|
||||||
|
ui->spinBox_ConnectionOffset->setValue(0);
|
||||||
|
ui->label_NumConnections->setText(QString::number(map->connections.length()));
|
||||||
|
|
||||||
|
if (connection_edit_items.length() > 0) {
|
||||||
|
onConnectionItemSelected(connection_edit_items.last());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void MetatilesPixmapItem::paintTileChanged(Map *map) {
|
void MetatilesPixmapItem::paintTileChanged(Map *map) {
|
||||||
draw();
|
draw();
|
||||||
}
|
}
|
||||||
|
|
3
editor.h
3
editor.h
|
@ -51,6 +51,8 @@ public:
|
||||||
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);
|
||||||
|
void addNewConnection();
|
||||||
|
void removeCurrentConnection();
|
||||||
|
|
||||||
DraggablePixmapItem *addMapObject(Event *event);
|
DraggablePixmapItem *addMapObject(Event *event);
|
||||||
void selectMapObject(DraggablePixmapItem *object);
|
void selectMapObject(DraggablePixmapItem *object);
|
||||||
|
@ -92,6 +94,7 @@ private:
|
||||||
void setBorderItemsVisible(bool, qreal = 1);
|
void setBorderItemsVisible(bool, qreal = 1);
|
||||||
void setConnectionEditControlValues(Connection*);
|
void setConnectionEditControlValues(Connection*);
|
||||||
void setConnectionEditControlsEnabled(bool);
|
void setConnectionEditControlsEnabled(bool);
|
||||||
|
void createConnectionItem(Connection* connection, bool hide);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void mouseEvent_map(QGraphicsSceneMouseEvent *event, MapPixmapItem *item);
|
void mouseEvent_map(QGraphicsSceneMouseEvent *event, MapPixmapItem *item);
|
||||||
|
|
|
@ -780,3 +780,13 @@ void MainWindow::on_comboBox_ConnectedMap_currentTextChanged(const QString &mapN
|
||||||
{
|
{
|
||||||
editor->updateConnectionMap(mapName, ui->comboBox_ConnectionDirection->currentText().toLower());
|
editor->updateConnectionMap(mapName, ui->comboBox_ConnectionDirection->currentText().toLower());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::on_pushButton_AddConnection_clicked()
|
||||||
|
{
|
||||||
|
editor->addNewConnection();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::on_pushButton_RemoveConnection_clicked()
|
||||||
|
{
|
||||||
|
editor->removeCurrentConnection();
|
||||||
|
}
|
||||||
|
|
|
@ -80,6 +80,10 @@ private slots:
|
||||||
|
|
||||||
void on_comboBox_ConnectedMap_currentTextChanged(const QString &mapName);
|
void on_comboBox_ConnectedMap_currentTextChanged(const QString &mapName);
|
||||||
|
|
||||||
|
void on_pushButton_AddConnection_clicked();
|
||||||
|
|
||||||
|
void on_pushButton_RemoveConnection_clicked();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::MainWindow *ui;
|
Ui::MainWindow *ui;
|
||||||
QStandardItemModel *mapListModel;
|
QStandardItemModel *mapListModel;
|
||||||
|
|
104
mainwindow.ui
104
mainwindow.ui
|
@ -60,7 +60,7 @@
|
||||||
</sizepolicy>
|
</sizepolicy>
|
||||||
</property>
|
</property>
|
||||||
<property name="currentIndex">
|
<property name="currentIndex">
|
||||||
<number>0</number>
|
<number>3</number>
|
||||||
</property>
|
</property>
|
||||||
<property name="tabsClosable">
|
<property name="tabsClosable">
|
||||||
<bool>false</bool>
|
<bool>false</bool>
|
||||||
|
@ -1246,7 +1246,7 @@
|
||||||
<property name="spacing">
|
<property name="spacing">
|
||||||
<number>0</number>
|
<number>0</number>
|
||||||
</property>
|
</property>
|
||||||
<item row="0" column="0">
|
<item row="1" column="0">
|
||||||
<widget class="QFrame" name="horizontalFrame">
|
<widget class="QFrame" name="horizontalFrame">
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||||
|
@ -1369,7 +1369,7 @@
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="0">
|
<item row="2" column="0">
|
||||||
<widget class="QFrame" name="gridFrame">
|
<widget class="QFrame" name="gridFrame">
|
||||||
<property name="frameShape">
|
<property name="frameShape">
|
||||||
<enum>QFrame::StyledPanel</enum>
|
<enum>QFrame::StyledPanel</enum>
|
||||||
|
@ -1410,7 +1410,7 @@
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>826</width>
|
<width>826</width>
|
||||||
<height>621</height>
|
<height>587</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QGridLayout" name="gridLayout_14">
|
<layout class="QGridLayout" name="gridLayout_14">
|
||||||
|
@ -1486,6 +1486,102 @@
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item row="0" column="0">
|
||||||
|
<widget class="QFrame" name="horizontalFrame">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="minimumSize">
|
||||||
|
<size>
|
||||||
|
<width>0</width>
|
||||||
|
<height>32</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="frameShape">
|
||||||
|
<enum>QFrame::StyledPanel</enum>
|
||||||
|
</property>
|
||||||
|
<property name="frameShadow">
|
||||||
|
<enum>QFrame::Raised</enum>
|
||||||
|
</property>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout_4">
|
||||||
|
<property name="spacing">
|
||||||
|
<number>4</number>
|
||||||
|
</property>
|
||||||
|
<property name="leftMargin">
|
||||||
|
<number>4</number>
|
||||||
|
</property>
|
||||||
|
<property name="topMargin">
|
||||||
|
<number>4</number>
|
||||||
|
</property>
|
||||||
|
<property name="rightMargin">
|
||||||
|
<number>4</number>
|
||||||
|
</property>
|
||||||
|
<property name="bottomMargin">
|
||||||
|
<number>4</number>
|
||||||
|
</property>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="pushButton_AddConnection">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string/>
|
||||||
|
</property>
|
||||||
|
<property name="icon">
|
||||||
|
<iconset>
|
||||||
|
<activeon>:/icons/add.ico</activeon>
|
||||||
|
</iconset>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="pushButton_RemoveConnection">
|
||||||
|
<property name="text">
|
||||||
|
<string/>
|
||||||
|
</property>
|
||||||
|
<property name="icon">
|
||||||
|
<iconset>
|
||||||
|
<activeon>:/icons/delete.ico</activeon>
|
||||||
|
</iconset>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label_13">
|
||||||
|
<property name="text">
|
||||||
|
<string>Number of Connections:</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label_NumConnections">
|
||||||
|
<property name="text">
|
||||||
|
<string/>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<spacer name="horizontalSpacer_9">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>40</width>
|
||||||
|
<height>20</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
|
Loading…
Reference in a new issue