diff --git a/CHANGELOG.md b/CHANGELOG.md
index 007e60b7..5fa47e5a 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,7 +6,7 @@ and this project somewhat adheres to [Semantic Versioning](https://semver.org/sp
## [Unreleased]
### Added
-- Add setting to display tile and metatile IDs in decimal instead of hexadecimal.
+- Add setting to display tile and metatile IDs in decimal instead of hexadecimal. Defaults to displaying both.
- Add API functions for reading and writing text files.
### Changed
diff --git a/forms/preferenceeditor.ui b/forms/preferenceeditor.ui
index d849a1f5..571a0276 100644
--- a/forms/preferenceeditor.ui
+++ b/forms/preferenceeditor.ui
@@ -122,6 +122,16 @@
+ -
+
+
+ <html><head/><body><p>If checked, tile IDs and metatile IDs will be displayed as "<hexadecimal> (<decimal>)"</p></body></html>
+
+
+ Both
+
+
+
-
diff --git a/include/config/porymapconfig.h b/include/config/porymapconfig.h
index 3e1bf5d7..e0075578 100644
--- a/include/config/porymapconfig.h
+++ b/include/config/porymapconfig.h
@@ -6,6 +6,7 @@
#include "block.h"
#include "events.h"
#include "log.h"
+#include "utility.h"
#include
#include
@@ -73,7 +74,7 @@ public:
bool monitorFiles = true;
bool tilesetCheckerboardFill = true;
bool newMapHeaderSectionExpanded = false;
- bool displayIdsHexadecimal = true;
+ NumberSystemMode tileNumberSystem = NumberSystemMode::Both;
QString theme = QStringLiteral("default");
QString wildMonChartTheme;
QString textEditorOpenFolder;
@@ -141,7 +142,7 @@ public:
m_fm->addField(&this->monitorFiles, "monitor_files");
m_fm->addField(&this->tilesetCheckerboardFill, "tileset_checkerboard_fill");
m_fm->addField(&this->newMapHeaderSectionExpanded, "new_map_header_section_expanded");
- m_fm->addField(&this->displayIdsHexadecimal, "display_ids_hexadecimal");
+ m_fm->addField(&this->tileNumberSystem, "tile_number_system");
m_fm->addField(&this->theme, "theme");
m_fm->addField(&this->wildMonChartTheme, "wild_mon_chart_theme");
m_fm->addField(&this->textEditorOpenFolder, "text_editor_open_folder");
diff --git a/include/core/utility.h b/include/core/utility.h
index 40dd1423..97bf882f 100644
--- a/include/core/utility.h
+++ b/include/core/utility.h
@@ -6,6 +6,12 @@
#include
#include
+enum NumberSystemMode {
+ Both,
+ Decimal,
+ Hexadecimal,
+};
+
namespace Util {
void numericalModeSort(QStringList &list);
int roundUpToMultiple(int numToRound, int multiple);
@@ -21,6 +27,19 @@ namespace Util {
QString mkpath(const QString& dirPath);
QString getFileHash(const QString &filepath);
+ template
+ QString getNumberSystemString(T value, NumberSystemMode mode, int minHexLength = 0) {
+ switch (mode) {
+ case NumberSystemMode::Hexadecimal: return toHexString(value, minHexLength);
+ case NumberSystemMode::Decimal: return QString::number(value);
+ case NumberSystemMode::Both: return QString("%1 (%2)")
+ .arg(getNumberSystemString(value, NumberSystemMode::Hexadecimal, minHexLength))
+ .arg(getNumberSystemString(value, NumberSystemMode::Decimal));
+ }
+ Q_ASSERT("Cannot get string for invalid NumberSystemMode.");
+ return QString();
+ }
+
// Given a QMap, erases all entries with empty strings.
// Returns the number of entries erased.
template
diff --git a/src/core/metatile.cpp b/src/core/metatile.cpp
index 539bde5b..7ae743e9 100644
--- a/src/core/metatile.cpp
+++ b/src/core/metatile.cpp
@@ -45,9 +45,7 @@ QPoint Metatile::coordFromPixmapCoord(const QPointF &pixelCoord) {
static int numMetatileIdChars = 4;
QString Metatile::getMetatileIdString(uint16_t metatileId) {
- return porymapConfig.displayIdsHexadecimal
- ? Util::toHexString(metatileId, numMetatileIdChars)
- : QString::number(metatileId);
+ return Util::getNumberSystemString(metatileId, porymapConfig.tileNumberSystem, numMetatileIdChars);
};
QString Metatile::getMetatileIdStrings(const QList &metatileIds) {
diff --git a/src/core/tile.cpp b/src/core/tile.cpp
index 1b1a28a8..713cb880 100644
--- a/src/core/tile.cpp
+++ b/src/core/tile.cpp
@@ -1,6 +1,7 @@
#include "tile.h"
#include "project.h"
#include "bitpacker.h"
+#include "utility.h"
// At the moment these are fixed, and not exposed to the user.
// We're only using them for convenience when converting between raw values.
@@ -71,7 +72,5 @@ QString Tile::toString() const {
}
QString Tile::getTileIdString(uint16_t tileId) {
- return porymapConfig.displayIdsHexadecimal
- ? Util::toHexString(tileId, 3)
- : QString::number(tileId);
-}
+ return Util::getNumberSystemString(tileId, porymapConfig.tileNumberSystem, 3);
+};
diff --git a/src/ui/preferenceeditor.cpp b/src/ui/preferenceeditor.cpp
index 638fde9b..a25e08f8 100644
--- a/src/ui/preferenceeditor.cpp
+++ b/src/ui/preferenceeditor.cpp
@@ -107,10 +107,10 @@ void PreferenceEditor::updateFields() {
ui->checkBox_StatusWarnings->setChecked(porymapConfig.statusBarLogTypes.find(LogType::LOG_WARN) != logTypeEnd);
ui->checkBox_StatusInformation->setChecked(porymapConfig.statusBarLogTypes.find(LogType::LOG_INFO) != logTypeEnd);
- if (porymapConfig.displayIdsHexadecimal) {
- ui->radioButton_Hexadecimal->setChecked(true);
- } else {
- ui->radioButton_Decimal->setChecked(true);
+ switch (porymapConfig.tileNumberSystem) {
+ case NumberSystemMode::Hexadecimal: ui->radioButton_Hexadecimal->setChecked(true); break;
+ case NumberSystemMode::Decimal: ui->radioButton_Decimal->setChecked(true); break;
+ case NumberSystemMode::Both: ui->radioButton_DecimalHexadecimal->setChecked(true); break;
}
this->applicationFont = porymapConfig.applicationFont;
@@ -150,7 +150,10 @@ void PreferenceEditor::saveFields() {
porymapConfig.checkForUpdates = ui->checkBox_CheckForUpdates->isChecked();
porymapConfig.eventDeleteWarningDisabled = ui->checkBox_DisableEventWarning->isChecked();
porymapConfig.showProjectLoadingScreen = ui->checkBox_ShowProjectLoadingScreen->isChecked();
- porymapConfig.displayIdsHexadecimal = ui->radioButton_Hexadecimal->isChecked();
+
+ if (ui->radioButton_Hexadecimal->isChecked()) porymapConfig.tileNumberSystem = NumberSystemMode::Hexadecimal;
+ else if (ui->radioButton_Decimal->isChecked()) porymapConfig.tileNumberSystem = NumberSystemMode::Decimal;
+ else if (ui->radioButton_DecimalHexadecimal->isChecked()) porymapConfig.tileNumberSystem = NumberSystemMode::Both;
porymapConfig.statusBarLogTypes.clear();
if (ui->checkBox_StatusErrors->isChecked()) porymapConfig.statusBarLogTypes.insert(LogType::LOG_ERROR);