Prompt for new map connections
This commit is contained in:
parent
edb4a67994
commit
6fbc6d8d86
7 changed files with 201 additions and 29 deletions
95
forms/newmapconnectiondialog.ui
Normal file
95
forms/newmapconnectiondialog.ui
Normal file
|
@ -0,0 +1,95 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>NewMapConnectionDialog</class>
|
||||||
|
<widget class="QDialog" name="NewMapConnectionDialog">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>234</width>
|
||||||
|
<height>120</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>Add New Map Connection</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QFrame" name="frame">
|
||||||
|
<property name="frameShape">
|
||||||
|
<enum>QFrame::NoFrame</enum>
|
||||||
|
</property>
|
||||||
|
<property name="frameShadow">
|
||||||
|
<enum>QFrame::Plain</enum>
|
||||||
|
</property>
|
||||||
|
<layout class="QFormLayout" name="formLayout_2">
|
||||||
|
<property name="leftMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="topMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="rightMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="bottomMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<item row="0" column="0">
|
||||||
|
<widget class="QLabel" name="label_Map">
|
||||||
|
<property name="text">
|
||||||
|
<string>Map</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="0" column="1">
|
||||||
|
<widget class="NoScrollComboBox" name="comboBox_Map"/>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="0">
|
||||||
|
<widget class="QLabel" name="label_Direction">
|
||||||
|
<property name="text">
|
||||||
|
<string>Direction</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="1">
|
||||||
|
<widget class="NoScrollComboBox" name="comboBox_Direction"/>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QDialogButtonBox" name="buttonBox">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="standardButtons">
|
||||||
|
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<customwidgets>
|
||||||
|
<customwidget>
|
||||||
|
<class>NoScrollComboBox</class>
|
||||||
|
<extends>QComboBox</extends>
|
||||||
|
<header>noscrollcombobox.h</header>
|
||||||
|
</customwidget>
|
||||||
|
</customwidgets>
|
||||||
|
<resources/>
|
||||||
|
<connections>
|
||||||
|
<connection>
|
||||||
|
<sender>buttonBox</sender>
|
||||||
|
<signal>accepted()</signal>
|
||||||
|
<receiver>NewMapConnectionDialog</receiver>
|
||||||
|
<slot>accept()</slot>
|
||||||
|
</connection>
|
||||||
|
<connection>
|
||||||
|
<sender>buttonBox</sender>
|
||||||
|
<signal>rejected()</signal>
|
||||||
|
<receiver>NewMapConnectionDialog</receiver>
|
||||||
|
<slot>reject()</slot>
|
||||||
|
</connection>
|
||||||
|
</connections>
|
||||||
|
</ui>
|
|
@ -77,7 +77,6 @@ public:
|
||||||
void setMapEditingButtonsEnabled(bool enabled);
|
void setMapEditingButtonsEnabled(bool enabled);
|
||||||
void setConnectionsVisibility(bool visible);
|
void setConnectionsVisibility(bool visible);
|
||||||
void updateDiveEmergeVisibility();
|
void updateDiveEmergeVisibility();
|
||||||
void addNewConnection();
|
|
||||||
void addConnection(MapConnection* connection, bool addMirror = true);
|
void addConnection(MapConnection* connection, bool addMirror = true);
|
||||||
void removeConnection(MapConnection* connection, bool addMirror = true);
|
void removeConnection(MapConnection* connection, bool addMirror = true);
|
||||||
void removeConnectionPixmap(ConnectionPixmapItem* connectionItem);
|
void removeConnectionPixmap(ConnectionPixmapItem* connectionItem);
|
||||||
|
@ -86,6 +85,7 @@ public:
|
||||||
void deleteWildMonGroup();
|
void deleteWildMonGroup();
|
||||||
void updateDiveMap(QString mapName);
|
void updateDiveMap(QString mapName);
|
||||||
void updateEmergeMap(QString mapName);
|
void updateEmergeMap(QString mapName);
|
||||||
|
void selectLastConnection();
|
||||||
void setSelectedConnectionFromMap(QString mapName);
|
void setSelectedConnectionFromMap(QString mapName);
|
||||||
void updatePrimaryTileset(QString tilesetLabel, bool forceLoad = false);
|
void updatePrimaryTileset(QString tilesetLabel, bool forceLoad = false);
|
||||||
void updateSecondaryTileset(QString tilesetLabel, bool forceLoad = false);
|
void updateSecondaryTileset(QString tilesetLabel, bool forceLoad = false);
|
||||||
|
|
29
include/ui/newmapconnectiondialog.h
Normal file
29
include/ui/newmapconnectiondialog.h
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
#ifndef NEWMAPCONNECTIONDIALOG_H
|
||||||
|
#define NEWMAPCONNECTIONDIALOG_H
|
||||||
|
|
||||||
|
#include <QDialog>
|
||||||
|
#include "map.h"
|
||||||
|
#include "mapconnection.h"
|
||||||
|
|
||||||
|
namespace Ui {
|
||||||
|
class NewMapConnectionDialog;
|
||||||
|
}
|
||||||
|
|
||||||
|
class NewMapConnectionDialog : public QDialog
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit NewMapConnectionDialog(QWidget *parent, Map* map, const QStringList &mapNames);
|
||||||
|
~NewMapConnectionDialog();
|
||||||
|
|
||||||
|
MapConnection *result;
|
||||||
|
|
||||||
|
virtual void accept() override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
Ui::NewMapConnectionDialog *ui;
|
||||||
|
Map *map;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // NEWMAPCONNECTIONDIALOG_H
|
|
@ -55,6 +55,7 @@ SOURCES += src/core/block.cpp \
|
||||||
src/ui/collisionpixmapitem.cpp \
|
src/ui/collisionpixmapitem.cpp \
|
||||||
src/ui/connectionpixmapitem.cpp \
|
src/ui/connectionpixmapitem.cpp \
|
||||||
src/ui/currentselectedmetatilespixmapitem.cpp \
|
src/ui/currentselectedmetatilespixmapitem.cpp \
|
||||||
|
src/ui/newmapconnectiondialog.cpp \
|
||||||
src/ui/overlay.cpp \
|
src/ui/overlay.cpp \
|
||||||
src/ui/prefab.cpp \
|
src/ui/prefab.cpp \
|
||||||
src/ui/projectsettingseditor.cpp \
|
src/ui/projectsettingseditor.cpp \
|
||||||
|
@ -149,6 +150,7 @@ HEADERS += include/core/block.h \
|
||||||
include/ui/collisionpixmapitem.h \
|
include/ui/collisionpixmapitem.h \
|
||||||
include/ui/connectionpixmapitem.h \
|
include/ui/connectionpixmapitem.h \
|
||||||
include/ui/currentselectedmetatilespixmapitem.h \
|
include/ui/currentselectedmetatilespixmapitem.h \
|
||||||
|
include/ui/newmapconnectiondialog.h \
|
||||||
include/ui/prefabframe.h \
|
include/ui/prefabframe.h \
|
||||||
include/ui/projectsettingseditor.h \
|
include/ui/projectsettingseditor.h \
|
||||||
include/ui/regionmaplayoutpixmapitem.h \
|
include/ui/regionmaplayoutpixmapitem.h \
|
||||||
|
@ -209,6 +211,7 @@ HEADERS += include/core/block.h \
|
||||||
|
|
||||||
FORMS += forms/mainwindow.ui \
|
FORMS += forms/mainwindow.ui \
|
||||||
forms/connectionslistitem.ui \
|
forms/connectionslistitem.ui \
|
||||||
|
forms/newmapconnectiondialog.ui \
|
||||||
forms/prefabcreationdialog.ui \
|
forms/prefabcreationdialog.ui \
|
||||||
forms/prefabframe.ui \
|
forms/prefabframe.ui \
|
||||||
forms/tileseteditor.ui \
|
forms/tileseteditor.ui \
|
||||||
|
|
|
@ -752,6 +752,7 @@ void Editor::displayConnection(MapConnection* connection) {
|
||||||
ConnectionPixmapItem *pixmapItem = new ConnectionPixmapItem(pixmap, connection, pos.x(), pos.y());
|
ConnectionPixmapItem *pixmapItem = new ConnectionPixmapItem(pixmap, connection, pos.x(), pos.y());
|
||||||
pixmapItem->render();
|
pixmapItem->render();
|
||||||
scene->addItem(pixmapItem);
|
scene->addItem(pixmapItem);
|
||||||
|
maskNonVisibleConnectionTiles();
|
||||||
|
|
||||||
// Create item for the list panel
|
// Create item for the list panel
|
||||||
ConnectionsListItem *listItem = new ConnectionsListItem(ui->scrollAreaContents_ConnectionsList, pixmapItem->connection, project->mapNames);
|
ConnectionsListItem *listItem = new ConnectionsListItem(ui->scrollAreaContents_ConnectionsList, pixmapItem->connection, project->mapNames);
|
||||||
|
@ -812,32 +813,6 @@ void Editor::displayConnection(MapConnection* connection) {
|
||||||
connection_items.append(pixmapItem);
|
connection_items.append(pixmapItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Editor::addNewConnection() {
|
|
||||||
// Find direction with least number of connections.
|
|
||||||
QMap<QString, int> directionCounts;
|
|
||||||
for (MapConnection* connection : map->connections) {
|
|
||||||
directionCounts[connection->direction()]++;
|
|
||||||
}
|
|
||||||
QString minDirection = "up";
|
|
||||||
int minCount = INT_MAX;
|
|
||||||
for (QString direction : MapConnection::cardinalDirections) {
|
|
||||||
if (directionCounts[direction] < minCount) {
|
|
||||||
minDirection = direction;
|
|
||||||
minCount = directionCounts[direction];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Prefer not to connect the map to itself (we have to if it's the only map).
|
|
||||||
QString defaultMapName = project->mapNames.first();
|
|
||||||
if (defaultMapName == map->name && project->mapNames.length() > 1) {
|
|
||||||
defaultMapName = project->mapNames.at(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
addConnection(new MapConnection(minDirection, map->name, defaultMapName));
|
|
||||||
setSelectedConnection(connection_items.last());
|
|
||||||
}
|
|
||||||
|
|
||||||
void Editor::addConnection(MapConnection * connection, bool addMirror) {
|
void Editor::addConnection(MapConnection * connection, bool addMirror) {
|
||||||
if (!connection)
|
if (!connection)
|
||||||
return;
|
return;
|
||||||
|
@ -1056,6 +1031,10 @@ void Editor::setSelectedConnectionFromMap(QString mapName) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Editor::selectLastConnection() {
|
||||||
|
setSelectedConnection(connection_items.last());
|
||||||
|
}
|
||||||
|
|
||||||
void Editor::onMapConnectionDoubleClicked(MapConnection* connection) {
|
void Editor::onMapConnectionDoubleClicked(MapConnection* connection) {
|
||||||
emit openConnectedMap(connection->targetMapName(), connection->hostMapName());
|
emit openConnectedMap(connection->targetMapName(), connection->hostMapName());
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
#include "prefab.h"
|
#include "prefab.h"
|
||||||
#include "montabwidget.h"
|
#include "montabwidget.h"
|
||||||
#include "imageexport.h"
|
#include "imageexport.h"
|
||||||
|
#include "newmapconnectiondialog.h"
|
||||||
|
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
#include <QClipboard>
|
#include <QClipboard>
|
||||||
|
@ -2649,8 +2650,11 @@ void MainWindow::showExportMapImageWindow(ImageExporterMode mode) {
|
||||||
|
|
||||||
void MainWindow::on_pushButton_AddConnection_clicked()
|
void MainWindow::on_pushButton_AddConnection_clicked()
|
||||||
{
|
{
|
||||||
// TODO: Bring up a prompt for information?
|
auto dialog = new NewMapConnectionDialog(this, this->editor->map, this->editor->project->mapNames);
|
||||||
editor->addNewConnection();
|
if(dialog->exec() == QDialog::Accepted) {
|
||||||
|
this->editor->addConnection(dialog->result);
|
||||||
|
this->editor->selectLastConnection();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_pushButton_NewWildMonGroup_clicked() {
|
void MainWindow::on_pushButton_NewWildMonGroup_clicked() {
|
||||||
|
|
62
src/ui/newmapconnectiondialog.cpp
Normal file
62
src/ui/newmapconnectiondialog.cpp
Normal file
|
@ -0,0 +1,62 @@
|
||||||
|
#include "newmapconnectiondialog.h"
|
||||||
|
#include "ui_newmapconnectiondialog.h"
|
||||||
|
|
||||||
|
NewMapConnectionDialog::NewMapConnectionDialog(QWidget *parent, Map* map, const QStringList &mapNames) :
|
||||||
|
QDialog(parent),
|
||||||
|
ui(new Ui::NewMapConnectionDialog)
|
||||||
|
{
|
||||||
|
ui->setupUi(this);
|
||||||
|
setAttribute(Qt::WA_DeleteOnClose);
|
||||||
|
|
||||||
|
this->map = map;
|
||||||
|
this->result = nullptr;
|
||||||
|
|
||||||
|
ui->comboBox_Direction->setEditable(false);
|
||||||
|
ui->comboBox_Direction->setMinimumContentsLength(0);
|
||||||
|
ui->comboBox_Direction->addItems(MapConnection::cardinalDirections);
|
||||||
|
|
||||||
|
ui->comboBox_Map->setMinimumContentsLength(6);
|
||||||
|
ui->comboBox_Map->addItems(mapNames);
|
||||||
|
|
||||||
|
// Choose default direction
|
||||||
|
QMap<QString, int> directionCounts;
|
||||||
|
for (auto connection : map->connections) {
|
||||||
|
directionCounts[connection->direction()]++;
|
||||||
|
}
|
||||||
|
QString defaultDirection;
|
||||||
|
int minCount = INT_MAX;
|
||||||
|
for (auto direction : MapConnection::cardinalDirections) {
|
||||||
|
if (directionCounts[direction] < minCount) {
|
||||||
|
defaultDirection = direction;
|
||||||
|
minCount = directionCounts[direction];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ui->comboBox_Direction->setTextItem(defaultDirection);
|
||||||
|
|
||||||
|
// Choose default map
|
||||||
|
QString defaultMapName;
|
||||||
|
if (mapNames.isEmpty()) {
|
||||||
|
defaultMapName = QString();
|
||||||
|
} else if (mapNames.first() == map->name && mapNames.length() > 1) {
|
||||||
|
// Prefer not to connect the map to itself
|
||||||
|
defaultMapName = mapNames.at(1);
|
||||||
|
} else {
|
||||||
|
defaultMapName = mapNames.first();
|
||||||
|
}
|
||||||
|
ui->comboBox_Map->setTextItem(defaultMapName);
|
||||||
|
}
|
||||||
|
|
||||||
|
NewMapConnectionDialog::~NewMapConnectionDialog()
|
||||||
|
{
|
||||||
|
delete ui;
|
||||||
|
}
|
||||||
|
|
||||||
|
void NewMapConnectionDialog::accept() {
|
||||||
|
QString direction = ui->comboBox_Direction->currentText();
|
||||||
|
QString hostMapName = this->map ? this->map->name : QString();
|
||||||
|
QString targetMapName = ui->comboBox_Map->currentText();
|
||||||
|
|
||||||
|
this->result = new MapConnection(direction, this->map->name, targetMapName);
|
||||||
|
|
||||||
|
QDialog::accept();
|
||||||
|
}
|
Loading…
Reference in a new issue