Final MapConnection UI updates

This commit is contained in:
GriffinR 2024-08-19 18:49:57 -04:00
parent 186e20171b
commit 7a0ae53143
8 changed files with 104 additions and 33 deletions

View file

@ -65,7 +65,7 @@
<item row="3" column="2">
<widget class="QToolButton" name="button_Delete">
<property name="toolTip">
<string>Remove this connection</string>
<string>Remove this connection.</string>
</property>
<property name="text">
<string>...</string>
@ -79,21 +79,35 @@
<item row="1" column="1" colspan="2">
<widget class="NoScrollComboBox" name="comboBox_Direction">
<property name="toolTip">
<string>Where the connected map should be positioned relative to the current map</string>
<string>Where the connected map should be positioned relative to the current map.</string>
</property>
</widget>
</item>
<item row="0" column="1" colspan="2">
<widget class="NoScrollComboBox" name="comboBox_Map">
<property name="toolTip">
<string>The name of the map to connect to the current map</string>
<string>The name of the map to connect to the current map.</string>
</property>
</widget>
</item>
<item row="2" column="1" colspan="2">
<widget class="NoScrollSpinBox" name="spinBox_Offset">
<property name="toolTip">
<string>The number of spaces to move the connected map perpendicular to its connected direction</string>
<string>The number of spaces to move the connected map perpendicular to its connected direction.</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QToolButton" name="button_OpenMap">
<property name="toolTip">
<string>Open the connected map.</string>
</property>
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="../resources/images.qrc">
<normaloff>:/icons/map_go.ico</normaloff>:/icons/map_go.ico</iconset>
</property>
</widget>
</item>

View file

@ -2664,6 +2664,9 @@
</item>
<item row="0" column="4" rowspan="2">
<widget class="QGroupBox" name="groupBox_DiveMapOpacity">
<property name="toolTip">
<string>If enabled, the connected Emerge and/or Dive maps will be displayed with an opacity set using the slider.</string>
</property>
<property name="title">
<string>Show Emerge/Dive Maps</string>
</property>
@ -2874,8 +2877,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>100</width>
<height>30</height>
<width>365</width>
<height>651</height>
</rect>
</property>
<layout class="QVBoxLayout" name="layout_ConnectionsList">

View file

@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>234</width>
<height>120</height>
<height>162</height>
</rect>
</property>
<property name="windowTitle">
@ -43,7 +43,11 @@
</widget>
</item>
<item row="0" column="1">
<widget class="NoScrollComboBox" name="comboBox_Map"/>
<widget class="NoScrollComboBox" name="comboBox_Map">
<property name="toolTip">
<string>The name of the map to connect to the current map.</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_Direction">
@ -53,7 +57,24 @@
</widget>
</item>
<item row="1" column="1">
<widget class="NoScrollComboBox" name="comboBox_Direction"/>
<widget class="NoScrollComboBox" name="comboBox_Direction">
<property name="toolTip">
<string>Where the connected map should be positioned relative to the current map.</string>
</property>
</widget>
</item>
<item row="2" column="0" colspan="2">
<widget class="QLabel" name="label_Warning">
<property name="styleSheet">
<string notr="true">color: rgb(255, 0, 0)</string>
</property>
<property name="text">
<string>'Map' must be the name of an existing map.</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
@ -84,12 +105,32 @@
<signal>accepted()</signal>
<receiver>NewMapConnectionDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>20</x>
<y>20</y>
</hint>
<hint type="destinationlabel">
<x>20</x>
<y>20</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>NewMapConnectionDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>20</x>
<y>20</y>
</hint>
<hint type="destinationlabel">
<x>20</x>
<y>20</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View file

@ -14,8 +14,7 @@ class ConnectionsListItem;
// We show the data for each map connection in the panel on the right side of the Connections tab.
// An instance of this class is used for each item in that list.
// It communicates with the ConnectionPixmapItem on the map through a shared MapConnection pointer,
// and the two classes should signal one another when they change this data.
// It communicates with the ConnectionPixmapItem on the map through a shared MapConnection pointer.
class ConnectionsListItem : public QFrame
{
Q_OBJECT
@ -27,28 +26,27 @@ public:
void updateUI();
void setSelected(bool selected);
QPointer<MapConnection> connection;
private:
Ui::ConnectionsListItem *ui;
QPointer<MapConnection> connection;
Map *map;
bool isSelected = false;
unsigned actionId = 0;
protected:
void mousePressEvent(QMouseEvent*) override;
void mouseDoubleClickEvent(QMouseEvent*) override;
signals:
void removed(MapConnection*);
void selected();
void doubleClicked(MapConnection*);
void removed(MapConnection*);
void openMapClicked(MapConnection*);
private slots:
void on_comboBox_Direction_currentTextChanged(const QString &direction);
void on_comboBox_Map_currentTextChanged(const QString &mapName);
void on_spinBox_Offset_valueChanged(int offset);
void on_button_Delete_clicked();
void on_button_OpenMap_clicked();
};
#endif // CONNECTIONSLISTITEM_H

View file

@ -24,6 +24,9 @@ signals:
private:
Ui::NewMapConnectionDialog *ui;
bool mapNameIsValid();
void setWarningVisible(bool visible);
};
#endif // NEWMAPCONNECTIONDIALOG_H

View file

@ -758,8 +758,8 @@ void Editor::displayConnection(MapConnection* connection) {
QObject::disconnect(connection, &MapConnection::directionChanged, nullptr, nullptr);
QObject::disconnect(connection, &MapConnection::offsetChanged, nullptr, nullptr);
// Double clicking the list item or pixmap opens the connected map
connect(listItem, &ConnectionsListItem::doubleClicked, this, &Editor::onMapConnectionDoubleClicked);
// Double clicking the pixmap or clicking the list item's map button opens the connected map
connect(listItem, &ConnectionsListItem::openMapClicked, this, &Editor::onMapConnectionDoubleClicked);
connect(pixmapItem, &ConnectionPixmapItem::connectionItemDoubleClicked, this, &Editor::onMapConnectionDoubleClicked);
// Sync the selection highlight between the list UI and the pixmap
@ -937,7 +937,6 @@ void Editor::setDivingMapName(QString mapName, QString direction) {
auto pixmapItem = diving_map_items.value(direction);
MapConnection *connection = pixmapItem ? pixmapItem->connection() : nullptr;
// TODO: Test edit history
if (connection) {
if (mapName == connection->targetMapName())
return; // No change
@ -1823,11 +1822,8 @@ void Editor::updateMapBorder() {
void Editor::updateMapConnections() {
for (auto item : connection_items)
item->render(true);
maskNonVisibleConnectionTiles();
}
// TODO: Check first condition, move to Map
int Editor::getBorderDrawDistance(int dimension) {
// Draw sufficient border blocks to fill the player's view (BORDER_DISTANCE)
if (dimension >= BORDER_DISTANCE) {
@ -1920,7 +1916,12 @@ void Editor::updateBorderVisibility() {
item->setVisible(visible);
item->setEditable(editingConnections);
item->setEnabled(visible);
item->render();
// When connecting a map to itself we don't bother to re-render the map connections in real-time,
// i.e. if the user paints a new metatile on the map this isn't immediately reflected in the connection.
// We're rendering them now, so we take the opportunity to do a full re-render for self-connections.
bool fullRender = (this->map && item->connection && this->map->name == item->connection->targetMapName());
item->render(fullRender);
}
}

View file

@ -75,11 +75,6 @@ void ConnectionsListItem::mousePressEvent(QMouseEvent *) {
this->setSelected(true);
}
// TODO: This happens by accident a lot. Convert to button?
void ConnectionsListItem::mouseDoubleClickEvent(QMouseEvent *) {
emit doubleClicked(this->connection);
}
void ConnectionsListItem::on_comboBox_Direction_currentTextChanged(const QString &direction) {
this->setSelected(true);
if (this->map)
@ -102,3 +97,7 @@ void ConnectionsListItem::on_button_Delete_clicked() {
if (this->map)
this->map->editHistory.push(new MapConnectionRemove(this->map, this->connection));
}
void ConnectionsListItem::on_button_OpenMap_clicked() {
emit openMapClicked(this->connection);
}

View file

@ -9,10 +9,8 @@ NewMapConnectionDialog::NewMapConnectionDialog(QWidget *parent, Map* map, const
setAttribute(Qt::WA_DeleteOnClose);
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);
ui->comboBox_Map->setInsertPolicy(QComboBox::NoInsert);
@ -42,6 +40,12 @@ NewMapConnectionDialog::NewMapConnectionDialog(QWidget *parent, Map* map, const
defaultMapName = mapNames.first();
}
ui->comboBox_Map->setTextItem(defaultMapName);
connect(ui->comboBox_Map, &QComboBox::currentTextChanged, [this] {
if (ui->label_Warning->isVisible() && mapNameIsValid())
setWarningVisible(false);
});
setWarningVisible(false);
}
NewMapConnectionDialog::~NewMapConnectionDialog()
@ -49,10 +53,18 @@ NewMapConnectionDialog::~NewMapConnectionDialog()
delete ui;
}
bool NewMapConnectionDialog::mapNameIsValid() {
return ui->comboBox_Map->findText(ui->comboBox_Map->currentText()) >= 0;
}
void NewMapConnectionDialog::setWarningVisible(bool visible) {
ui->label_Warning->setVisible(visible);
adjustSize();
}
void NewMapConnectionDialog::accept() {
// Invalid map names are not allowed
if (ui->comboBox_Map->findText(ui->comboBox_Map->currentText()) < 0) {
// TODO: Display error message
if (!mapNameIsValid()) {
setWarningVisible(true);
return;
}
emit accepted(new MapConnection(ui->comboBox_Map->currentText(), ui->comboBox_Direction->currentText()));