Use spin boxes for border metatile settings if using default size

This commit is contained in:
GriffinR 2023-09-19 14:21:36 -04:00
parent 8054a808a6
commit 22fe7f2963
10 changed files with 210 additions and 96 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 41 KiB

After

Width:  |  Height:  |  Size: 42 KiB

View file

@ -81,9 +81,11 @@ New Map Defaults
:alt: New Map Defaults
Border Metatiles
This is a comma-separated list of metatile ID values that will be used to fill the border on new maps. If the number of metatiles in the border is not the same as the number of values in the list then the border will be filled with metatile ID ``0x000`` instead.
This is list of metatile ID values that will be used to fill the border on new maps. The spin boxes correspond to the top-left, top-right, bottom-left, and bottom-right border metatiles respectively.
Defaults to ``0x014,0x015,0x01C,0x01D`` for ``pokefirered``, and ``0x1D4,0x1D5,0x1DC,0x1DD`` for other versions.
If ``Enable Custom Border Size`` is checked, this will instead be a comma-separated list of metatile ID values that will be used to fill the border on new maps. Values in the list will be read sequentially to fill the new border left-to-right top-to-bottom. If the number of metatiles in the border for a new map is not the same as the number of values in the list then the border will be filled with metatile ID ``0x000`` instead.
Defaults to ``0x014``, ``0x015``, ``0x01C``, ``0x01D`` for ``pokefirered``, and ``0x1D4``, ``0x1D5``, ``0x1DC``, ``0x1DD`` for other versions.
Field name: ``new_map_border_metatiles``

View file

@ -94,65 +94,7 @@
<string>New Map Defaults</string>
</property>
<layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="1" colspan="2">
<widget class="QLineEdit" name="lineEdit_BorderMetatiles">
<property name="toolTip">
<string>A comma-separated list of metatile values that will be used to fill new map borders</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_Elevation">
<property name="text">
<string>Elevation</string>
</property>
</widget>
</item>
<item row="2" column="2">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="3" column="0" colspan="3">
<widget class="QCheckBox" name="checkBox_CreateTextFile">
<property name="toolTip">
<string>Whether a separate text.inc or text.pory file will be created for new maps, alongside the scripts file</string>
</property>
<property name="text">
<string>Create separate text file</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="NoScrollSpinBox" name="spinBox_Elevation">
<property name="toolTip">
<string>The default elevation that will be used to fill new maps</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_FillMetatile">
<property name="text">
<string>Fill Metatile</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_BorderMetatiles">
<property name="text">
<string>Border Metatiles</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="NoScrollSpinBox" name="spinBox_FillMetatile">
<property name="toolTip">
<string>The default metatile value that will be used to fill new maps</string>
@ -165,18 +107,145 @@
</property>
</widget>
</item>
<item row="1" column="2">
<spacer name="horizontalSpacer_5">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<item row="3" column="0">
<widget class="QLabel" name="label_Elevation">
<property name="text">
<string>Elevation</string>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</widget>
</item>
<item row="3" column="1">
<widget class="NoScrollSpinBox" name="spinBox_Elevation">
<property name="toolTip">
<string>The default elevation that will be used to fill new maps</string>
</property>
</spacer>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_FillMetatile">
<property name="text">
<string>Fill Metatile</string>
</property>
</widget>
</item>
<item row="4" column="0" colspan="6">
<widget class="QCheckBox" name="checkBox_CreateTextFile">
<property name="toolTip">
<string>Whether a separate text.inc or text.pory file will be created for new maps, alongside the scripts file</string>
</property>
<property name="text">
<string>Create separate text file</string>
</property>
</widget>
</item>
<item row="1" column="0" colspan="6">
<widget class="QWidget" name="widget_CustomSizeBorderMetatiles" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="label_BorderMetatiles_2">
<property name="text">
<string>Border Metatiles</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEdit_BorderMetatiles">
<property name="toolTip">
<string>A comma-separated list of metatile values that will be used to fill new map borders</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="0" column="0" colspan="5">
<widget class="QWidget" name="widget_DefaultSizeBorderMetatiles" native="true">
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="label_BorderMetatiles">
<property name="text">
<string>Border Metatiles</string>
</property>
</widget>
</item>
<item>
<widget class="NoScrollSpinBox" name="spinBox_BorderMetatile1">
<property name="toolTip">
<string>The default metatile value that will be used for the top-left border metatile on new maps.</string>
</property>
<property name="prefix">
<string>0x</string>
</property>
<property name="displayIntegerBase">
<number>16</number>
</property>
</widget>
</item>
<item>
<widget class="NoScrollSpinBox" name="spinBox_BorderMetatile2">
<property name="toolTip">
<string>The default metatile value that will be used for the top-right border metatile on new maps.</string>
</property>
<property name="prefix">
<string>0x</string>
</property>
<property name="displayIntegerBase">
<number>16</number>
</property>
</widget>
</item>
<item>
<widget class="NoScrollSpinBox" name="spinBox_BorderMetatile3">
<property name="toolTip">
<string>The default metatile value that will be used for the bottom-left border metatile on new maps.</string>
</property>
<property name="prefix">
<string>0x</string>
</property>
<property name="displayIntegerBase">
<number>16</number>
</property>
</widget>
</item>
<item>
<widget class="NoScrollSpinBox" name="spinBox_BorderMetatile4">
<property name="toolTip">
<string>The default metatile value that will be used for the bottom-right border metatile on new maps.</string>
</property>
<property name="prefix">
<string>0x</string>
</property>
<property name="displayIntegerBase">
<number>16</number>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>

View file

@ -267,7 +267,6 @@ public:
int getNewMapElevation();
void setNewMapBorderMetatileIds(QList<uint16_t> metatileIds);
QList<uint16_t> getNewMapBorderMetatileIds();
QString getNewMapBorderMetatileIdsString();
QString getDefaultPrimaryTileset();
QString getDefaultSecondaryTileset();
void setDefaultPrimaryTileset(QString tilesetName);

View file

@ -93,7 +93,15 @@ public:
static QPoint coordFromPixmapCoord(const QPointF &pixelCoord);
static int getDefaultAttributesSize(BaseGameVersion version);
static void setCustomLayout(Project*);
static QString getMetatileIdString(uint16_t metatileId) { return "0x" + QString("%1").arg(metatileId, 3, 16, QChar('0')).toUpper(); };
static QString getMetatileIdString(uint16_t metatileId) {
return "0x" + QString("%1").arg(metatileId, 3, 16, QChar('0')).toUpper();
};
static QString getMetatileIdStringList(const QList<uint16_t> metatileIds) {
QStringList metatiles;
for (auto metatileId : metatileIds)
metatiles << Metatile::getMetatileIdString(metatileId);
return metatiles.join(",");
};
private:
// Stores how each attribute should be laid out for all metatiles, according to the user's config

View file

@ -42,6 +42,10 @@ private:
bool promptSaveChanges();
bool promptRestoreDefaults();
void setBorderMetatilesUi(bool customSize);
void setBorderMetatileIds(bool customSize, QList<uint16_t> metatileIds);
QList<uint16_t> getBorderMetatileIds(bool customSize);
void createProjectPathsTable();
QString chooseProjectFile(const QString &defaultFilepath);

View file

@ -64,4 +64,4 @@ signals:
void textChanged(const QString &text);
};
#endif // UINTSPINBOX_H
#endif // UINTSPINBOX_H

View file

@ -735,7 +735,7 @@ QMap<QString, QString> ProjectConfig::getKeyValueMap() {
map.insert("enable_triple_layer_metatiles", QString::number(this->enableTripleLayerMetatiles));
map.insert("new_map_metatile", Metatile::getMetatileIdString(this->newMapMetatileId));
map.insert("new_map_elevation", QString::number(this->newMapElevation));
map.insert("new_map_border_metatiles", this->getNewMapBorderMetatileIdsString());
map.insert("new_map_border_metatiles", Metatile::getMetatileIdStringList(this->newMapBorderMetatileIds));
map.insert("default_primary_tileset", this->defaultPrimaryTileset);
map.insert("default_secondary_tileset", this->defaultSecondaryTileset);
map.insert("prefabs_filepath", this->prefabFilepath);
@ -983,14 +983,6 @@ QList<uint16_t> ProjectConfig::getNewMapBorderMetatileIds() {
return this->newMapBorderMetatileIds;
}
QString ProjectConfig::getNewMapBorderMetatileIdsString() {
QStringList metatiles;
for (auto metatileId : this->newMapBorderMetatileIds){
metatiles << Metatile::getMetatileIdString(metatileId);
}
return metatiles.join(",");
}
QString ProjectConfig::getDefaultPrimaryTileset() {
return this->defaultPrimaryTileset;
}

View file

@ -444,10 +444,6 @@ bool Project::readMapLayouts() {
"blockdata_filepath",
};
bool useCustomBorderSize = projectConfig.getUseCustomBorderSize();
if (useCustomBorderSize) {
requiredFields.append("border_width");
requiredFields.append("border_height");
}
for (int i = 0; i < layouts.size(); i++) {
QJsonObject layoutObj = layouts[i].toObject();
if (layoutObj.isEmpty())

View file

@ -37,6 +37,13 @@ void ProjectSettingsEditor::connectSignals() {
connect(ui->button_ImportDefaultPrefabs, &QAbstractButton::clicked, this, &ProjectSettingsEditor::importDefaultPrefabsClicked);
connect(ui->comboBox_BaseGameVersion, &QComboBox::currentTextChanged, this, &ProjectSettingsEditor::promptRestoreDefaults);
connect(ui->comboBox_AttributesSize, &QComboBox::currentTextChanged, this, &ProjectSettingsEditor::updateAttributeLimits);
connect(ui->checkBox_EnableCustomBorderSize, &QCheckBox::stateChanged, [this](int state) {
bool customSize = (state == Qt::Checked);
// When switching between the spin boxes or line edit for border metatiles we set
// the newly-shown UI using the values from the hidden UI.
this->setBorderMetatileIds(customSize, this->getBorderMetatileIds(!customSize));
this->setBorderMetatilesUi(customSize);
});
// Record that there are unsaved changes if any of the settings are modified
for (auto combo : ui->centralwidget->findChildren<NoScrollComboBox *>())
@ -69,9 +76,49 @@ void ProjectSettingsEditor::initUi() {
static const QRegularExpression expression(QString("^(%1,)*%1$").arg(regex_Hex)); // Comma-separated list of hex values
QRegularExpressionValidator *validator = new QRegularExpressionValidator(expression);
ui->lineEdit_BorderMetatiles->setValidator(validator);
this->setBorderMetatilesUi(projectConfig.getUseCustomBorderSize());
int maxMetatileId = Project::getNumMetatilesTotal() - 1;
ui->spinBox_FillMetatile->setMaximum(maxMetatileId);
ui->spinBox_BorderMetatile1->setMaximum(maxMetatileId);
ui->spinBox_BorderMetatile2->setMaximum(maxMetatileId);
ui->spinBox_BorderMetatile3->setMaximum(maxMetatileId);
ui->spinBox_BorderMetatile4->setMaximum(maxMetatileId);
ui->spinBox_Elevation->setMaximum(15);
ui->spinBox_FillMetatile->setMaximum(Project::getNumMetatilesTotal() - 1);
}
void ProjectSettingsEditor::setBorderMetatilesUi(bool customSize) {
ui->widget_DefaultSizeBorderMetatiles->setVisible(!customSize);
ui->widget_CustomSizeBorderMetatiles->setVisible(customSize);
}
void ProjectSettingsEditor::setBorderMetatileIds(bool customSize, QList<uint16_t> metatileIds) {
if (customSize) {
ui->lineEdit_BorderMetatiles->setText(Metatile::getMetatileIdStringList(metatileIds));
} else {
ui->spinBox_BorderMetatile1->setValue(metatileIds.value(0, 0x0));
ui->spinBox_BorderMetatile2->setValue(metatileIds.value(1, 0x0));
ui->spinBox_BorderMetatile3->setValue(metatileIds.value(2, 0x0));
ui->spinBox_BorderMetatile4->setValue(metatileIds.value(3, 0x0));
}
}
QList<uint16_t> ProjectSettingsEditor::getBorderMetatileIds(bool customSize) {
QList<uint16_t> metatileIds;
if (customSize) {
// Custom border size, read metatiles from line edit
for (auto s : ui->lineEdit_BorderMetatiles->text().split(",")) {
uint16_t metatileId = s.toUInt(nullptr, 0);
metatileIds.append(qMin(metatileId, static_cast<uint16_t>(Project::getNumMetatilesTotal() - 1)));
}
} else {
// Default border size, read metatiles from spin boxes
metatileIds.append(ui->spinBox_BorderMetatile1->value());
metatileIds.append(ui->spinBox_BorderMetatile2->value());
metatileIds.append(ui->spinBox_BorderMetatile3->value());
metatileIds.append(ui->spinBox_BorderMetatile4->value());
}
return metatileIds;
}
void ProjectSettingsEditor::updateAttributeLimits(const QString &attrSize) {
@ -186,8 +233,12 @@ void ProjectSettingsEditor::refresh() {
ui->spinBox_LayerTypeMask->setValue(projectConfig.getMetatileLayerTypeMask());
ui->spinBox_TerrainTypeMask->setValue(projectConfig.getMetatileTerrainTypeMask());
// Set (and sync) border metatile IDs
auto metatileIds = projectConfig.getNewMapBorderMetatileIds();
this->setBorderMetatileIds(false, metatileIds);
this->setBorderMetatileIds(true, metatileIds);
// Set line edit texts
ui->lineEdit_BorderMetatiles->setText(projectConfig.getNewMapBorderMetatileIdsString());
ui->lineEdit_PrefabsPath->setText(projectConfig.getPrefabFilepath());
for (auto lineEdit : ui->scrollAreaContents_ProjectPaths->findChildren<QLineEdit*>())
lineEdit->setText(projectConfig.getFilePath(lineEdit->objectName(), true));
@ -230,14 +281,7 @@ void ProjectSettingsEditor::save() {
projectConfig.setPrefabFilepath(ui->lineEdit_PrefabsPath->text());
for (auto lineEdit : ui->scrollAreaContents_ProjectPaths->findChildren<QLineEdit*>())
projectConfig.setFilePath(lineEdit->objectName(), lineEdit->text());
// Parse and save border metatile list
QList<uint16_t> metatileIds;
for (auto s : ui->lineEdit_BorderMetatiles->text().split(",")) {
uint16_t metatileId = s.toUInt(nullptr, 0);
metatileIds.append(qMin(metatileId, static_cast<uint16_t>(Project::getNumMetatilesTotal() - 1)));
}
projectConfig.setNewMapBorderMetatileIds(metatileIds);
projectConfig.setNewMapBorderMetatileIds(this->getBorderMetatileIds(ui->checkBox_EnableCustomBorderSize->isChecked()));
projectConfig.setSaveDisabled(false);
projectConfig.save();