mirror of
https://github.com/huderlem/porymap.git
synced 2026-08-16 21:58:24 -05:00
Move hex string conversions to Util
This commit is contained in:
@@ -8,6 +8,7 @@ namespace Util {
|
||||
void numericalModeSort(QStringList &list);
|
||||
int roundUp(int numToRound, int multiple);
|
||||
QString toDefineCase(QString input);
|
||||
QString toHexString(uint32_t value, int minLength = 0);
|
||||
}
|
||||
|
||||
#endif // UTILITY_H
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "selectablepixmapitem.h"
|
||||
#include "paletteutil.h"
|
||||
#include "imageproviders.h"
|
||||
#include "utility.h"
|
||||
|
||||
#include <memory>
|
||||
using std::shared_ptr;
|
||||
@@ -66,7 +67,7 @@ public:
|
||||
}
|
||||
|
||||
virtual QString info() const {
|
||||
return QString("Tile: 0x") + QString("%1 ").arg(this->id(), 4, 16, QChar('0')).toUpper();
|
||||
return QString("Tile: %1 ").arg(Util::toHexString(this->id(), 4));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include "shortcut.h"
|
||||
#include "map.h"
|
||||
#include "validator.h"
|
||||
#include "utility.h"
|
||||
#include <QDir>
|
||||
#include <QFile>
|
||||
#include <QFormLayout>
|
||||
@@ -877,16 +878,16 @@ QMap<QString, QString> ProjectConfig::getKeyValueMap() {
|
||||
map.insert("tilesets_have_is_compressed", QString::number(this->tilesetsHaveIsCompressed));
|
||||
map.insert("set_transparent_pixels_black", QString::number(this->setTransparentPixelsBlack));
|
||||
map.insert("metatile_attributes_size", QString::number(this->metatileAttributesSize));
|
||||
map.insert("metatile_behavior_mask", "0x" + QString::number(this->metatileBehaviorMask, 16).toUpper());
|
||||
map.insert("metatile_terrain_type_mask", "0x" + QString::number(this->metatileTerrainTypeMask, 16).toUpper());
|
||||
map.insert("metatile_encounter_type_mask", "0x" + QString::number(this->metatileEncounterTypeMask, 16).toUpper());
|
||||
map.insert("metatile_layer_type_mask", "0x" + QString::number(this->metatileLayerTypeMask, 16).toUpper());
|
||||
map.insert("block_metatile_id_mask", "0x" + QString::number(this->blockMetatileIdMask, 16).toUpper());
|
||||
map.insert("block_collision_mask", "0x" + QString::number(this->blockCollisionMask, 16).toUpper());
|
||||
map.insert("block_elevation_mask", "0x" + QString::number(this->blockElevationMask, 16).toUpper());
|
||||
map.insert("unused_tile_normal", "0x" + QString::number(this->unusedTileNormal, 16).toUpper());
|
||||
map.insert("unused_tile_covered", "0x" + QString::number(this->unusedTileCovered, 16).toUpper());
|
||||
map.insert("unused_tile_split", "0x" + QString::number(this->unusedTileSplit, 16).toUpper());
|
||||
map.insert("metatile_behavior_mask", Util::toHexString(this->metatileBehaviorMask));
|
||||
map.insert("metatile_terrain_type_mask", Util::toHexString(this->metatileTerrainTypeMask));
|
||||
map.insert("metatile_encounter_type_mask", Util::toHexString(this->metatileEncounterTypeMask));
|
||||
map.insert("metatile_layer_type_mask", Util::toHexString(this->metatileLayerTypeMask));
|
||||
map.insert("block_metatile_id_mask", Util::toHexString(this->blockMetatileIdMask));
|
||||
map.insert("block_collision_mask", Util::toHexString(this->blockCollisionMask));
|
||||
map.insert("block_elevation_mask", Util::toHexString(this->blockElevationMask));
|
||||
map.insert("unused_tile_normal", Util::toHexString(this->unusedTileNormal));
|
||||
map.insert("unused_tile_covered", Util::toHexString(this->unusedTileCovered));
|
||||
map.insert("unused_tile_split", Util::toHexString(this->unusedTileSplit));
|
||||
map.insert("enable_map_allow_flags", QString::number(this->mapAllowFlagsEnabled));
|
||||
map.insert("event_icon_path_object", this->eventIconPaths[Event::Group::Object]);
|
||||
map.insert("event_icon_path_warp", this->eventIconPaths[Event::Group::Warp]);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "metatile.h"
|
||||
#include "tileset.h"
|
||||
#include "project.h"
|
||||
#include "utility.h"
|
||||
|
||||
// Stores how each attribute should be laid out for all metatiles, according to the vanilla games.
|
||||
// Used to set default config values and import maps with AdvanceMap.
|
||||
@@ -42,7 +43,7 @@ QPoint Metatile::coordFromPixmapCoord(const QPointF &pixelCoord) {
|
||||
|
||||
static int numMetatileIdChars = 4;
|
||||
QString Metatile::getMetatileIdString(uint16_t metatileId) {
|
||||
return "0x" + QString("%1").arg(metatileId, numMetatileIdChars, 16, QChar('0')).toUpper();
|
||||
return Util::toHexString(metatileId, numMetatileIdChars);
|
||||
};
|
||||
|
||||
QString Metatile::getMetatileIdStrings(const QList<uint16_t> metatileIds) {
|
||||
@@ -127,8 +128,8 @@ void Metatile::setLayout(Project * project) {
|
||||
if (behaviorMask && !project->metatileBehaviorMapInverse.isEmpty()) {
|
||||
uint32_t maxBehavior = project->metatileBehaviorMapInverse.lastKey();
|
||||
if (packer.clamp(maxBehavior) != maxBehavior)
|
||||
logWarn(QString("Metatile Behavior mask '0x%1' is insufficient to contain all available options.")
|
||||
.arg(QString::number(behaviorMask, 16).toUpper()));
|
||||
logWarn(QString("Metatile Behavior mask '%1' is insufficient to contain all available options.")
|
||||
.arg(Util::toHexString(behaviorMask)));
|
||||
}
|
||||
attributePackers.insert(Metatile::Attr::Behavior, packer);
|
||||
|
||||
@@ -136,8 +137,8 @@ void Metatile::setLayout(Project * project) {
|
||||
packer.setMask(terrainTypeMask);
|
||||
const uint32_t maxTerrainType = NUM_METATILE_TERRAIN_TYPES - 1;
|
||||
if (terrainTypeMask && packer.clamp(maxTerrainType) != maxTerrainType) {
|
||||
logWarn(QString("Metatile Terrain Type mask '0x%1' is insufficient to contain all %2 available options.")
|
||||
.arg(QString::number(terrainTypeMask, 16).toUpper())
|
||||
logWarn(QString("Metatile Terrain Type mask '%1' is insufficient to contain all %2 available options.")
|
||||
.arg(Util::toHexString(terrainTypeMask))
|
||||
.arg(maxTerrainType + 1));
|
||||
}
|
||||
attributePackers.insert(Metatile::Attr::TerrainType, packer);
|
||||
@@ -146,8 +147,8 @@ void Metatile::setLayout(Project * project) {
|
||||
packer.setMask(encounterTypeMask);
|
||||
const uint32_t maxEncounterType = NUM_METATILE_ENCOUNTER_TYPES - 1;
|
||||
if (encounterTypeMask && packer.clamp(maxEncounterType) != maxEncounterType) {
|
||||
logWarn(QString("Metatile Encounter Type mask '0x%1' is insufficient to contain all %2 available options.")
|
||||
.arg(QString::number(encounterTypeMask, 16).toUpper())
|
||||
logWarn(QString("Metatile Encounter Type mask '%1' is insufficient to contain all %2 available options.")
|
||||
.arg(Util::toHexString(encounterTypeMask))
|
||||
.arg(maxEncounterType + 1));
|
||||
}
|
||||
attributePackers.insert(Metatile::Attr::EncounterType, packer);
|
||||
@@ -156,8 +157,8 @@ void Metatile::setLayout(Project * project) {
|
||||
packer.setMask(layerTypeMask);
|
||||
const uint32_t maxLayerType = NUM_METATILE_LAYER_TYPES - 1;
|
||||
if (layerTypeMask && packer.clamp(maxLayerType) != maxLayerType) {
|
||||
logWarn(QString("Metatile Layer Type mask '0x%1' is insufficient to contain all %2 available options.")
|
||||
.arg(QString::number(layerTypeMask, 16).toUpper())
|
||||
logWarn(QString("Metatile Layer Type mask '%1' is insufficient to contain all %2 available options.")
|
||||
.arg(Util::toHexString(layerTypeMask))
|
||||
.arg(maxLayerType + 1));
|
||||
}
|
||||
attributePackers.insert(Metatile::Attr::LayerType, packer);
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
// Sometimes we want to sort names alphabetically to make them easier to find in large combo box lists.
|
||||
// QStringList::sort (as of writing) can only sort numbers in lexical order, which has an undesirable
|
||||
// effect (e.g. MAPSEC_ROUTE_10 comes after MAPSEC_ROUTE_1, rather than MAPSEC_ROUTE_9).
|
||||
// effect (e.g. 'ROUTE_1, ROUTE_10, ROUTE_2,...' instead of 'ROUTE_1, ROUTE_2,... ROUTE_10').
|
||||
// We can use QCollator to sort these lists with better handling for numbers.
|
||||
void Util::numericalModeSort(QStringList &list) {
|
||||
static QCollator collator;
|
||||
@@ -38,3 +38,7 @@ QString Util::toDefineCase(QString input) {
|
||||
|
||||
return input.toUpper();
|
||||
}
|
||||
|
||||
QString Util::toHexString(uint32_t value, int minLength) {
|
||||
return "0x" + QString("%1").arg(value, minLength, 16, QChar('0')).toUpper();
|
||||
}
|
||||
|
||||
@@ -987,7 +987,7 @@ QString Editor::getMetatileDisplayMessage(uint16_t metatileId) {
|
||||
if (label.size())
|
||||
message += QString(" \"%1\"").arg(label);
|
||||
if (metatile && metatile->behavior() != 0) { // Skip MB_NORMAL
|
||||
const QString behaviorStr = this->project->metatileBehaviorMapInverse.value(metatile->behavior(), "0x" + QString::number(metatile->behavior(), 16));
|
||||
const QString behaviorStr = this->project->metatileBehaviorMapInverse.value(metatile->behavior(), Util::toHexString(metatile->behavior()));
|
||||
message += QString(", Behavior: %1").arg(behaviorStr);
|
||||
}
|
||||
return message;
|
||||
|
||||
@@ -2197,10 +2197,10 @@ bool Project::readFieldmapMasks() {
|
||||
return false;
|
||||
*value = static_cast<uint16_t>(it.value());
|
||||
if (*value != it.value()){
|
||||
logWarn(QString("Value for %1 truncated from '0x%2' to '0x%3'")
|
||||
logWarn(QString("Value for %1 truncated from '%2' to '%3'")
|
||||
.arg(name)
|
||||
.arg(QString::number(it.value(), 16).toUpper())
|
||||
.arg(QString::number(*value, 16).toUpper()));
|
||||
.arg(Util::toHexString(it.value()))
|
||||
.arg(Util::toHexString(*value)));
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "noscrollcombobox.h"
|
||||
#include "utility.h"
|
||||
|
||||
#include <QCompleter>
|
||||
#include <QLineEdit>
|
||||
@@ -82,7 +83,7 @@ void NoScrollComboBox::setNumberItem(int value)
|
||||
|
||||
void NoScrollComboBox::setHexItem(uint32_t value)
|
||||
{
|
||||
this->setItem(this->findData(value), "0x" + QString::number(value, 16).toUpper());
|
||||
this->setItem(this->findData(value), Util::toHexString(value));
|
||||
}
|
||||
|
||||
void NoScrollComboBox::setClearButtonEnabled(bool enabled) {
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include "shortcut.h"
|
||||
#include "config.h"
|
||||
#include "log.h"
|
||||
#include "utility.h"
|
||||
|
||||
#include <QDir>
|
||||
#include <QDialog>
|
||||
@@ -793,8 +794,7 @@ void RegionMapEditor::onRegionMapTileSelectorSelectedTileChanged(unsigned id) {
|
||||
}
|
||||
|
||||
void RegionMapEditor::onRegionMapTileSelectorHoveredTileChanged(unsigned tileId) {
|
||||
QString message = QString("Tile: 0x") + QString("%1").arg(tileId, 4, 16, QChar('0')).toUpper();
|
||||
this->ui->statusbar->showMessage(message);
|
||||
this->ui->statusbar->showMessage(QString("Tile: %1").arg(Util::toHexString(tileId, 4)));
|
||||
}
|
||||
|
||||
void RegionMapEditor::onRegionMapTileSelectorHoveredTileCleared() {
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include "filedialog.h"
|
||||
#include "validator.h"
|
||||
#include "eventfilters.h"
|
||||
#include "utility.h"
|
||||
#include <QMessageBox>
|
||||
#include <QDialogButtonBox>
|
||||
#include <QCloseEvent>
|
||||
@@ -420,9 +421,7 @@ void TilesetEditor::queueMetatileReload(uint16_t metatileId) {
|
||||
}
|
||||
|
||||
void TilesetEditor::onHoveredTileChanged(uint16_t tile) {
|
||||
QString message = QString("Tile: 0x%1")
|
||||
.arg(QString("%1").arg(tile, 3, 16, QChar('0')).toUpper());
|
||||
this->ui->statusbar->showMessage(message);
|
||||
this->ui->statusbar->showMessage(QString("Tile: %1").arg(Util::toHexString(tile, 3)));
|
||||
}
|
||||
|
||||
void TilesetEditor::onHoveredTileCleared() {
|
||||
|
||||
Reference in New Issue
Block a user