Add config options for showing border/grid

This commit is contained in:
GriffinR 2021-11-07 22:00:20 -05:00 committed by garak
parent f64b03d684
commit 7368f443f0
6 changed files with 50 additions and 0 deletions

View file

@ -13,6 +13,7 @@ The **"Breaking Changes"** listed below are changes that have been made in the d
- Porymap is now compatible with Qt6.
- Add tool to count the times each metatile or tile is used in the tileset editor.
- Events, current metatile selections, and map images can now be copied and pasted, including between windows.
- The grid and map border visibility are now saved as config options.
### Changed
- New events will be placed in the center of the current view of the map.

View file

@ -44,6 +44,8 @@ public:
this->metatilesZoom = 30;
this->showPlayerView = false;
this->showCursorTile = true;
this->showBorder = true;
this->showGrid = false;
this->monitorFiles = true;
this->regionMapDimensions = QSize(32, 20);
this->theme = "default";
@ -61,6 +63,8 @@ public:
void setMetatilesZoom(int zoom);
void setShowPlayerView(bool enabled);
void setShowCursorTile(bool enabled);
void setShowBorder(bool enabled);
void setShowGrid(bool enabled);
void setMonitorFiles(bool monitor);
void setRegionMapDimensions(int width, int height);
void setTheme(QString theme);
@ -77,6 +81,8 @@ public:
int getMetatilesZoom();
bool getShowPlayerView();
bool getShowCursorTile();
bool getShowBorder();
bool getShowGrid();
bool getMonitorFiles();
QSize getRegionMapDimensions();
QString getTheme();
@ -109,6 +115,8 @@ private:
int metatilesZoom;
bool showPlayerView;
bool showCursorTile;
bool showBorder;
bool showGrid;
bool monitorFiles;
QSize regionMapDimensions;
QString theme;

View file

@ -201,6 +201,7 @@ private slots:
void onHoveredMapMovementPermissionCleared();
void onSelectedMetatilesChanged();
void onWheelZoom(int);
void onToggleGridClicked(bool);
signals:
void objectsChanged();

View file

@ -168,6 +168,18 @@ void PorymapConfig::parseConfigKeyValue(QString key, QString value) {
if (!ok) {
logWarn(QString("Invalid config value for show_cursor_tile: '%1'. Must be 0 or 1.").arg(value));
}
} else if (key == "show_border") {
bool ok;
this->showBorder = value.toInt(&ok);
if (!ok) {
logWarn(QString("Invalid config value for show_border: '%1'. Must be 0 or 1.").arg(value));
}
} else if (key == "show_grid") {
bool ok;
this->showGrid = value.toInt(&ok);
if (!ok) {
logWarn(QString("Invalid config value for show_grid: '%1'. Must be 0 or 1.").arg(value));
}
} else if (key == "monitor_files") {
bool ok;
this->monitorFiles = value.toInt(&ok);
@ -215,6 +227,8 @@ QMap<QString, QString> PorymapConfig::getKeyValueMap() {
map.insert("metatiles_zoom", QString("%1").arg(this->metatilesZoom));
map.insert("show_player_view", this->showPlayerView ? "1" : "0");
map.insert("show_cursor_tile", this->showCursorTile ? "1" : "0");
map.insert("show_border", this->showBorder ? "1" : "0");
map.insert("show_grid", this->showGrid ? "1" : "0");
map.insert("monitor_files", this->monitorFiles ? "1" : "0");
map.insert("region_map_dimensions", QString("%1x%2").arg(this->regionMapDimensions.width())
.arg(this->regionMapDimensions.height()));
@ -308,6 +322,16 @@ void PorymapConfig::setShowCursorTile(bool enabled) {
this->save();
}
void PorymapConfig::setShowBorder(bool enabled) {
this->showBorder = enabled;
this->save();
}
void PorymapConfig::setShowGrid(bool enabled) {
this->showGrid = enabled;
this->save();
}
void PorymapConfig::setRegionMapDimensions(int width, int height) {
this->regionMapDimensions = QSize(width, height);
}
@ -392,6 +416,14 @@ bool PorymapConfig::getShowCursorTile() {
return this->showCursorTile;
}
bool PorymapConfig::getShowBorder() {
return this->showBorder;
}
bool PorymapConfig::getShowGrid() {
return this->showGrid;
}
bool PorymapConfig::getMonitorFiles() {
return this->monitorFiles;
}

View file

@ -1663,6 +1663,10 @@ int Editor::getBorderDrawDistance(int dimension) {
}
}
void Editor::onToggleGridClicked(bool checked) {
porymapConfig.setShowGrid(checked);
}
void Editor::displayMapGrid() {
for (QGraphicsLineItem* item : gridLines) {
if (item && item->scene()) {
@ -1689,6 +1693,7 @@ void Editor::displayMapGrid() {
gridLines.append(line);
connect(ui->checkBox_ToggleGrid, &QCheckBox::toggled, [=](bool checked){line->setVisible(checked);});
}
connect(ui->checkBox_ToggleGrid, &QCheckBox::toggled, this, &Editor::onToggleGridClicked);
}
void Editor::updateConnectionOffset(int offset) {
@ -1915,6 +1920,7 @@ void Editor::toggleBorderVisibility(bool visible)
{
this->setBorderItemsVisible(visible);
this->setConnectionsVisibility(visible);
porymapConfig.setShowBorder(visible);
}
void Editor::updateCustomMapHeaderValues(QTableWidget *table)

View file

@ -456,6 +456,8 @@ void MainWindow::loadUserSettings() {
this->editor->settings->playerViewRectEnabled = porymapConfig.getShowPlayerView();
ui->actionCursor_Tile_Outline->setChecked(porymapConfig.getShowCursorTile());
this->editor->settings->cursorTileRectEnabled = porymapConfig.getShowCursorTile();
ui->checkBox_ToggleBorder->setChecked(porymapConfig.getShowBorder());
ui->checkBox_ToggleGrid->setChecked(porymapConfig.getShowGrid());
mapSortOrder = porymapConfig.getMapSortOrder();
ui->horizontalSlider_CollisionTransparency->blockSignals(true);
this->editor->collisionOpacity = static_cast<qreal>(porymapConfig.getCollisionOpacity()) / 100;