Skip to content

Commit

Permalink
Final MapConnection UI updates
Browse files Browse the repository at this point in the history
  • Loading branch information
GriffinRichards committed Aug 19, 2024
1 parent 186e201 commit 7a0ae53
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 33 deletions.
22 changes: 18 additions & 4 deletions forms/connectionslistitem.ui
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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>
Expand Down
7 changes: 5 additions & 2 deletions forms/mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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">
Expand Down
47 changes: 44 additions & 3 deletions forms/newmapconnectiondialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>234</width>
<height>120</height>
<height>162</height>
</rect>
</property>
<property name="windowTitle">
Expand Down Expand Up @@ -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">
Expand All @@ -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>
Expand Down Expand Up @@ -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>
12 changes: 5 additions & 7 deletions include/ui/connectionslistitem.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -27,28 +26,27 @@ class ConnectionsListItem : public QFrame
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
3 changes: 3 additions & 0 deletions include/ui/newmapconnectiondialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ class NewMapConnectionDialog : public QDialog

private:
Ui::NewMapConnectionDialog *ui;

bool mapNameIsValid();
void setWarningVisible(bool visible);
};

#endif // NEWMAPCONNECTIONDIALOG_H
15 changes: 8 additions & 7 deletions src/editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
}
}

Expand Down
9 changes: 4 additions & 5 deletions src/ui/connectionslistitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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);
}
22 changes: 17 additions & 5 deletions src/ui/newmapconnectiondialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -42,17 +40,31 @@ 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()
{
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()));
Expand Down

0 comments on commit 7a0ae53

Please sign in to comment.