Fix border visibility in API

This commit is contained in:
GriffinR 2024-07-03 11:34:27 -04:00
parent 367198f98f
commit 6b0034e523
5 changed files with 41 additions and 68 deletions

View file

@ -165,9 +165,7 @@ private:
const QImage collisionPlaceholder = QImage(":/images/collisions_unknown.png"); const QImage collisionPlaceholder = QImage(":/images/collisions_unknown.png");
QPixmap collisionSheetPixmap; QPixmap collisionSheetPixmap;
void setConnectionItemsVisible(bool); void updateBorderVisibility();
void setBorderItemsVisible(bool, qreal = 1);
void setConnectionsEditable(bool);
QPoint calculateConnectionPosition(const MapConnection *connection, const QPixmap &pixmap); QPoint calculateConnectionPosition(const MapConnection *connection, const QPixmap &pixmap);
void redrawConnection(ConnectionPixmapItem* connectionItem); void redrawConnection(ConnectionPixmapItem* connectionItem);
void createConnectionItem(MapConnection* connection); void createConnectionItem(MapConnection* connection);
@ -197,8 +195,6 @@ private slots:
void mouseEvent_collision(QGraphicsSceneMouseEvent *event, CollisionPixmapItem *item); void mouseEvent_collision(QGraphicsSceneMouseEvent *event, CollisionPixmapItem *item);
void onConnectionMoved(MapConnection*); void onConnectionMoved(MapConnection*);
void onConnectionItemSelected(ConnectionPixmapItem* connectionItem); void onConnectionItemSelected(ConnectionPixmapItem* connectionItem);
void onConnectionItemDoubleClicked(ConnectionPixmapItem* connectionItem);
void onConnectionDirectionChanged(QString newDirection);
void onHoveredMovementPermissionChanged(uint16_t, uint16_t); void onHoveredMovementPermissionChanged(uint16_t, uint16_t);
void onHoveredMovementPermissionCleared(); void onHoveredMovementPermissionCleared();
void onHoveredMetatileSelectionChanged(uint16_t); void onHoveredMetatileSelectionChanged(uint16_t);
@ -213,7 +209,7 @@ private slots:
signals: signals:
void objectsChanged(); void objectsChanged();
void loadMapRequested(QString, QString); void connectionItemDoubleClicked(QString, QString);
void wildMonDataChanged(); void wildMonDataChanged();
void warpEventDoubleClicked(QString, int, Event::Group); void warpEventDoubleClicked(QString, int, Event::Group);
void currentMetatilesSelectionChanged(); void currentMetatilesSelectionChanged();

View file

@ -177,7 +177,7 @@ private slots:
void copy(); void copy();
void paste(); void paste();
void onLoadMapRequested(QString, QString); void onConnectionItemDoubleClicked(QString, QString);
void onMapChanged(Map *map); void onMapChanged(Map *map);
void onMapNeedsRedrawing(); void onMapNeedsRedrawing();
void onTilesetsSaved(QString, QString); void onTilesetsSaved(QString, QString);

View file

@ -99,9 +99,7 @@ void Editor::setEditingMap() {
if (events_group) { if (events_group) {
events_group->setVisible(false); events_group->setVisible(false);
} }
setBorderItemsVisible(ui->checkBox_ToggleBorder->isChecked()); updateBorderVisibility();
setConnectionItemsVisible(ui->checkBox_ToggleBorder->isChecked());
setConnectionsEditable(false);
this->cursorMapTileRect->stopSingleTileMode(); this->cursorMapTileRect->stopSingleTileMode();
this->cursorMapTileRect->setActive(true); this->cursorMapTileRect->setActive(true);
@ -123,9 +121,7 @@ void Editor::setEditingCollision() {
if (events_group) { if (events_group) {
events_group->setVisible(false); events_group->setVisible(false);
} }
setBorderItemsVisible(ui->checkBox_ToggleBorder->isChecked()); updateBorderVisibility();
setConnectionItemsVisible(ui->checkBox_ToggleBorder->isChecked());
setConnectionsEditable(false);
this->cursorMapTileRect->setSingleTileMode(); this->cursorMapTileRect->setSingleTileMode();
this->cursorMapTileRect->setActive(true); this->cursorMapTileRect->setActive(true);
@ -146,9 +142,7 @@ void Editor::setEditingObjects() {
if (collision_item) { if (collision_item) {
collision_item->setVisible(false); collision_item->setVisible(false);
} }
setBorderItemsVisible(ui->checkBox_ToggleBorder->isChecked()); updateBorderVisibility();
setConnectionItemsVisible(ui->checkBox_ToggleBorder->isChecked());
setConnectionsEditable(false);
this->cursorMapTileRect->setSingleTileMode(); this->cursorMapTileRect->setSingleTileMode();
this->cursorMapTileRect->setActive(false); this->cursorMapTileRect->setActive(false);
updateWarpEventWarnings(); updateWarpEventWarnings();
@ -179,10 +173,6 @@ void Editor::setEditingConnections() {
map_item->draw(); map_item->draw();
map_item->setVisible(true); map_item->setVisible(true);
populateConnectionsList(); populateConnectionsList();
if (selected_connection_item) {
// TODO: Do we need additional handling here again
redrawConnection(selected_connection_item);
}
maskNonVisibleConnectionTiles(); maskNonVisibleConnectionTiles();
} }
if (collision_item) { if (collision_item) {
@ -191,9 +181,7 @@ void Editor::setEditingConnections() {
if (events_group) { if (events_group) {
events_group->setVisible(false); events_group->setVisible(false);
} }
setBorderItemsVisible(true, 0.4); updateBorderVisibility();
setConnectionItemsVisible(true);
setConnectionsEditable(true);
this->cursorMapTileRect->setSingleTileMode(); this->cursorMapTileRect->setSingleTileMode();
this->cursorMapTileRect->setActive(false); this->cursorMapTileRect->setActive(false);
} }
@ -804,20 +792,6 @@ void Editor::removeConnection(ConnectionPixmapItem* connectionItem) {
emit editedMapData(); emit editedMapData();
} }
void Editor::setConnectionItemsVisible(bool visible) {
for (ConnectionPixmapItem* item : connection_items) {
item->setVisible(visible);
item->setEnabled(visible);
}
}
void Editor::setBorderItemsVisible(bool visible, qreal opacity) {
for (QGraphicsPixmapItem* item : borderItems) {
item->setVisible(visible);
item->setOpacity(opacity);
}
}
QPoint Editor::calculateConnectionPosition(const MapConnection *connection, const QPixmap &pixmap) { QPoint Editor::calculateConnectionPosition(const MapConnection *connection, const QPixmap &pixmap) {
int x = 0, y = 0; int x = 0, y = 0;
const int mWidth = 16, mHeight = 16; const int mWidth = 16, mHeight = 16;
@ -883,7 +857,7 @@ void Editor::redrawConnection(ConnectionPixmapItem* connectionItem) {
// TODO: Generalize, maybe use in addConnectionToList connection instead of full render // TODO: Generalize, maybe use in addConnectionToList connection instead of full render
void Editor::updateConnectionOffset(int offset) { void Editor::updateConnectionOffset(int offset) {
if (!selected_connection_item) /*if (!selected_connection_item)
return; return;
selected_connection_item->blockSignals(true); selected_connection_item->blockSignals(true);
@ -895,7 +869,7 @@ void Editor::updateConnectionOffset(int offset) {
} }
selected_connection_item->blockSignals(false); selected_connection_item->blockSignals(false);
updateMirroredConnectionOffset(selected_connection_item->connection); updateMirroredConnectionOffset(selected_connection_item->connection);
maskNonVisibleConnectionTiles(); maskNonVisibleConnectionTiles();*/
} }
void Editor::onConnectionMoved(MapConnection* connection) { void Editor::onConnectionMoved(MapConnection* connection) {
@ -907,13 +881,6 @@ void Editor::onConnectionMoved(MapConnection* connection) {
emit editedMapData(); emit editedMapData();
} }
void Editor::setConnectionsEditable(bool editable) {
for (ConnectionPixmapItem* item : connection_items) {
item->setEditable(editable);
item->updateHighlight(item == selected_connection_item);
}
}
void Editor::onConnectionItemSelected(ConnectionPixmapItem* connectionItem) { void Editor::onConnectionItemSelected(ConnectionPixmapItem* connectionItem) {
if (!connectionItem) if (!connectionItem)
return; return;
@ -925,6 +892,7 @@ void Editor::onConnectionItemSelected(ConnectionPixmapItem* connectionItem) {
// TODO: Handle the highlight done in redrawConnection? // TODO: Handle the highlight done in redrawConnection?
} }
// TODO: Inaccurate if there are multiple connections from the same map
void Editor::setSelectedConnectionFromMap(QString mapName) { void Editor::setSelectedConnectionFromMap(QString mapName) {
// Search for the first connection that connects to the given map map. // Search for the first connection that connects to the given map map.
for (ConnectionPixmapItem* item : connection_items) { for (ConnectionPixmapItem* item : connection_items) {
@ -935,21 +903,9 @@ void Editor::setSelectedConnectionFromMap(QString mapName) {
} }
} }
void Editor::onConnectionItemDoubleClicked(ConnectionPixmapItem* connectionItem) {
emit loadMapRequested(connectionItem->connection->map_name, map->name);
}
void Editor::onConnectionDirectionChanged(QString newDirection) {
/* // Connections TODO:
ui->comboBox_ConnectionDirection->blockSignals(true);
ui->comboBox_ConnectionDirection->setCurrentText(newDirection);
ui->comboBox_ConnectionDirection->blockSignals(false);
*/
}
void Editor::onBorderMetatilesChanged() { void Editor::onBorderMetatilesChanged() {
displayMapBorder(); displayMapBorder();
setBorderItemsVisible(ui->checkBox_ToggleBorder->isChecked()); updateBorderVisibility(); // TODO: Why do we need to call this here
} }
void Editor::onHoveredMovementPermissionChanged(uint16_t collision, uint16_t elevation) { void Editor::onHoveredMovementPermissionChanged(uint16_t collision, uint16_t elevation) {
@ -1606,7 +1562,9 @@ void Editor::createConnectionItem(MapConnection* connection) {
connect(item, &ConnectionPixmapItem::connectionMoved, this, &Editor::onConnectionMoved); connect(item, &ConnectionPixmapItem::connectionMoved, this, &Editor::onConnectionMoved);
connect(item, &ConnectionPixmapItem::connectionItemSelected, this, &Editor::onConnectionItemSelected); connect(item, &ConnectionPixmapItem::connectionItemSelected, this, &Editor::onConnectionItemSelected);
connect(item, &ConnectionPixmapItem::connectionItemDoubleClicked, this, &Editor::onConnectionItemDoubleClicked); connect(item, &ConnectionPixmapItem::connectionItemDoubleClicked, [this, item] {
emit this->connectionItemDoubleClicked(item->connection->map_name, map->name);
});
connection_items.append(item); connection_items.append(item);
} }
@ -1886,13 +1844,33 @@ void Editor::updateSecondaryTileset(QString tilesetLabel, bool forceLoad)
void Editor::toggleBorderVisibility(bool visible, bool enableScriptCallback) void Editor::toggleBorderVisibility(bool visible, bool enableScriptCallback)
{ {
this->setBorderItemsVisible(visible);
this->setConnectionItemsVisible(visible);
porymapConfig.setShowBorder(visible); porymapConfig.setShowBorder(visible);
updateBorderVisibility();
if (enableScriptCallback) if (enableScriptCallback)
Scripting::cb_BorderVisibilityToggled(visible); Scripting::cb_BorderVisibilityToggled(visible);
} }
void Editor::updateBorderVisibility() {
// On the connections tab, the border is always visible, and the connections can be edited.
bool editingConnections = (ui->mainTabBar->currentIndex() == 3);
bool visible = (editingConnections || ui->checkBox_ToggleBorder->isChecked());
// Update border
const qreal borderOpacity = editingConnections ? 0.4 : 1;
for (QGraphicsPixmapItem* item : borderItems) {
item->setVisible(visible);
item->setOpacity(borderOpacity);
}
// Update map connections
for (ConnectionPixmapItem* item : connection_items) {
item->setVisible(visible);
item->setEditable(editingConnections);
item->setEnabled(visible);
item->updateHighlight(item == selected_connection_item);
}
}
void Editor::updateCustomMapHeaderValues(QTableWidget *table) void Editor::updateCustomMapHeaderValues(QTableWidget *table)
{ {
map->customHeaders = CustomAttributesTable::getAttributes(table); map->customHeaders = CustomAttributesTable::getAttributes(table);

View file

@ -298,7 +298,7 @@ void MainWindow::checkForUpdates(bool) {}
void MainWindow::initEditor() { void MainWindow::initEditor() {
this->editor = new Editor(ui); this->editor = new Editor(ui);
connect(this->editor, &Editor::objectsChanged, this, &MainWindow::updateObjects); connect(this->editor, &Editor::objectsChanged, this, &MainWindow::updateObjects);
connect(this->editor, &Editor::loadMapRequested, this, &MainWindow::onLoadMapRequested); connect(this->editor, &Editor::connectionItemDoubleClicked, this, &MainWindow::onConnectionItemDoubleClicked);
connect(this->editor, &Editor::warpEventDoubleClicked, this, &MainWindow::openWarpMap); connect(this->editor, &Editor::warpEventDoubleClicked, this, &MainWindow::openWarpMap);
connect(this->editor, &Editor::currentMetatilesSelectionChanged, this, &MainWindow::currentMetatilesSelectionChanged); connect(this->editor, &Editor::currentMetatilesSelectionChanged, this, &MainWindow::currentMetatilesSelectionChanged);
connect(this->editor, &Editor::wildMonDataChanged, this, &MainWindow::onWildMonDataChanged); connect(this->editor, &Editor::wildMonDataChanged, this, &MainWindow::onWildMonDataChanged);
@ -2419,8 +2419,8 @@ void MainWindow::clickToolButtonFromEditMode(QString editMode) {
} }
} }
void MainWindow::onLoadMapRequested(QString mapName, QString fromMapName) { void MainWindow::onConnectionItemDoubleClicked(QString mapName, QString fromMapName) {
if (userSetMap(mapName, true)) if (mapName != fromMapName && userSetMap(mapName, true))
editor->setSelectedConnectionFromMap(fromMapName); editor->setSelectedConnectionFromMap(fromMapName);
} }
@ -2706,8 +2706,7 @@ void MainWindow::on_checkBox_smartPaths_stateChanged(int selected)
void MainWindow::on_checkBox_ToggleBorder_stateChanged(int selected) void MainWindow::on_checkBox_ToggleBorder_stateChanged(int selected)
{ {
bool visible = selected != 0; editor->toggleBorderVisibility(selected != 0);
editor->toggleBorderVisibility(visible);
} }
void MainWindow::on_actionTileset_Editor_triggered() void MainWindow::on_actionTileset_Editor_triggered()

View file

@ -168,7 +168,7 @@ bool ScriptUtility::getGridVisibility() {
} }
void ScriptUtility::setBorderVisibility(bool visible) { void ScriptUtility::setBorderVisibility(bool visible) {
window->editor->toggleBorderVisibility(visible, false); window->ui->checkBox_ToggleBorder->setChecked(visible);
} }
bool ScriptUtility::getBorderVisibility() { bool ScriptUtility::getBorderVisibility() {