Write config with project settings editor

This commit is contained in:
GriffinR 2023-08-23 21:07:13 -04:00
parent 4d8f5ef150
commit 9bed66ecfc
12 changed files with 423 additions and 280 deletions

View file

@ -3012,9 +3012,7 @@
<property name="title"> <property name="title">
<string>Options</string> <string>Options</string>
</property> </property>
<addaction name="actionUse_Encounter_Json"/>
<addaction name="actionMonitor_Project_Files"/> <addaction name="actionMonitor_Project_Files"/>
<addaction name="actionUse_Poryscript"/>
<addaction name="actionOpen_Recent_Project_On_Launch"/> <addaction name="actionOpen_Recent_Project_On_Launch"/>
<addaction name="separator"/> <addaction name="separator"/>
<addaction name="actionEdit_Project_Settings"/> <addaction name="actionEdit_Project_Settings"/>
@ -3065,14 +3063,6 @@
<string>Ctrl+S</string> <string>Ctrl+S</string>
</property> </property>
</action> </action>
<action name="actionUse_Encounter_Json">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>Show Wild Encounter Tables</string>
</property>
</action>
<action name="actionMonitor_Project_Files"> <action name="actionMonitor_Project_Files">
<property name="checkable"> <property name="checkable">
<bool>true</bool> <bool>true</bool>
@ -3081,14 +3071,6 @@
<string>Monitor Project Files</string> <string>Monitor Project Files</string>
</property> </property>
</action> </action>
<action name="actionUse_Poryscript">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>Use Poryscript</string>
</property>
</action>
<action name="actionOpen_Recent_Project_On_Launch"> <action name="actionOpen_Recent_Project_On_Launch">
<property name="checkable"> <property name="checkable">
<bool>true</bool> <bool>true</bool>

View file

@ -72,15 +72,8 @@
<string>New Map Defaults</string> <string>New Map Defaults</string>
</property> </property>
<layout class="QGridLayout" name="gridLayout_3"> <layout class="QGridLayout" name="gridLayout_3">
<item row="1" column="0"> <item row="0" column="1" colspan="2">
<widget class="QLabel" name="label_FillMetatile"> <widget class="QLineEdit" name="lineEdit_BorderMetatiles"/>
<property name="toolTip">
<string>The default metatile value that will be used to fill new maps</string>
</property>
<property name="text">
<string>Fill Metatile</string>
</property>
</widget>
</item> </item>
<item row="2" column="0"> <item row="2" column="0">
<widget class="QLabel" name="label_Elevation"> <widget class="QLabel" name="label_Elevation">
@ -92,19 +85,6 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="0">
<widget class="QLabel" name="label_BorderMetatiles">
<property name="toolTip">
<string>A comma-separated list of metatile values that will be used to fill new map borders</string>
</property>
<property name="text">
<string>Border Metatiles</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QSpinBox" name="spinBox_Elevation"/>
</item>
<item row="2" column="2"> <item row="2" column="2">
<spacer name="horizontalSpacer"> <spacer name="horizontalSpacer">
<property name="orientation"> <property name="orientation">
@ -118,12 +98,6 @@
</property> </property>
</spacer> </spacer>
</item> </item>
<item row="1" column="1" colspan="2">
<widget class="QLineEdit" name="lineEdit_FillMetatile"/>
</item>
<item row="0" column="1" colspan="2">
<widget class="QLineEdit" name="lineEdit_BorderMetatiles"/>
</item>
<item row="3" column="0" colspan="3"> <item row="3" column="0" colspan="3">
<widget class="QCheckBox" name="checkBox_CreateTextFile"> <widget class="QCheckBox" name="checkBox_CreateTextFile">
<property name="toolTip"> <property name="toolTip">
@ -134,6 +108,52 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="2" column="1">
<widget class="QSpinBox" name="spinBox_Elevation"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_FillMetatile">
<property name="toolTip">
<string>The default metatile value that will be used to fill new maps</string>
</property>
<property name="text">
<string>Fill Metatile</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_BorderMetatiles">
<property name="toolTip">
<string>A comma-separated list of metatile values that will be used to fill new map borders</string>
</property>
<property name="text">
<string>Border Metatiles</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QSpinBox" name="spinBox_FillMetatile">
<property name="prefix">
<string>0x</string>
</property>
<property name="displayIntegerBase">
<number>16</number>
</property>
</widget>
</item>
<item row="1" column="2">
<spacer name="horizontalSpacer_5">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout> </layout>
</widget> </widget>
</item> </item>
@ -217,16 +237,6 @@
<string>Tilesets / Metatiles</string> <string>Tilesets / Metatiles</string>
</property> </property>
<layout class="QGridLayout" name="gridLayout_2"> <layout class="QGridLayout" name="gridLayout_2">
<item row="3" column="0">
<widget class="QLabel" name="label_BehaviorMask">
<property name="toolTip">
<string>The mask used to read/write Metatile Behavior from the metatile's attributes data. If 0, this attribute is disabled.</string>
</property>
<property name="text">
<string>Behavior mask</string>
</property>
</widget>
</item>
<item row="2" column="0"> <item row="2" column="0">
<widget class="QLabel" name="label_AttributesSize"> <widget class="QLabel" name="label_AttributesSize">
<property name="toolTip"> <property name="toolTip">
@ -237,15 +247,18 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="5" column="0"> <item row="1" column="0">
<widget class="QLabel" name="label_LayerTypeMask"> <spacer name="verticalSpacer">
<property name="toolTip"> <property name="orientation">
<string>The mask used to read/write Layer Type from the metatile's attributes data. If 0, this attribute is disabled.</string> <enum>Qt::Vertical</enum>
</property> </property>
<property name="text"> <property name="sizeHint" stdset="0">
<string>Layer Type mask</string> <size>
<width>20</width>
<height>15</height>
</size>
</property> </property>
</widget> </spacer>
</item> </item>
<item row="6" column="0"> <item row="6" column="0">
<widget class="QLabel" name="label_TerrainTypeMask"> <widget class="QLabel" name="label_TerrainTypeMask">
@ -264,32 +277,16 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="0"> <item row="2" column="1">
<spacer name="verticalSpacer"> <widget class="QWidget" name="widget_SizeDropdown" native="true"/>
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>15</height>
</size>
</property>
</spacer>
</item> </item>
<item row="4" column="1"> <item row="10" column="0">
<widget class="QLineEdit" name="lineEdit_EncounterTypeMask"/> <widget class="QCheckBox" name="checkBox_OutputIsCompressed">
</item>
<item row="5" column="1">
<widget class="QLineEdit" name="lineEdit_LayerTypeMask"/>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_EncounterTypeMask">
<property name="toolTip"> <property name="toolTip">
<string>The mask used to read/write Encounter Type from the metatile's attributes data. If 0, this attribute is disabled.</string> <string>Whether the C data outputted for new tilesets will include the &quot;isCompressed&quot; field</string>
</property> </property>
<property name="text"> <property name="text">
<string>Encounter Type mask</string> <string>Output 'isCompressed' field</string>
</property> </property>
</widget> </widget>
</item> </item>
@ -306,27 +303,35 @@
</property> </property>
</spacer> </spacer>
</item> </item>
<item row="6" column="1"> <item row="4" column="1">
<widget class="QLineEdit" name="lineEdit_TerrainTypeMask"/> <widget class="QSpinBox" name="spinBox_EncounterTypeMask">
</item> <property name="prefix">
<item row="3" column="1"> <string>0x</string>
<widget class="QLineEdit" name="lineEdit_BehaviorMask"/>
</item>
<item row="2" column="1">
<widget class="QWidget" name="widget_SizeDropdown" native="true"/>
</item>
<item row="3" column="2">
<spacer name="horizontalSpacer_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property> </property>
<property name="sizeHint" stdset="0"> <property name="displayIntegerBase">
<size> <number>16</number>
<width>40</width>
<height>20</height>
</size>
</property> </property>
</spacer> </widget>
</item>
<item row="5" column="1">
<widget class="QSpinBox" name="spinBox_LayerTypeMask">
<property name="prefix">
<string>0x</string>
</property>
<property name="displayIntegerBase">
<number>16</number>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_EncounterTypeMask">
<property name="toolTip">
<string>The mask used to read/write Encounter Type from the metatile's attributes data. If 0, this attribute is disabled.</string>
</property>
<property name="text">
<string>Encounter Type mask</string>
</property>
</widget>
</item> </item>
<item row="9" column="0"> <item row="9" column="0">
<widget class="QCheckBox" name="checkBox_OutputCallback"> <widget class="QCheckBox" name="checkBox_OutputCallback">
@ -338,13 +343,43 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="10" column="0"> <item row="3" column="0">
<widget class="QCheckBox" name="checkBox_OutputIsCompressed"> <widget class="QLabel" name="label_BehaviorMask">
<property name="toolTip"> <property name="toolTip">
<string>Whether the C data outputted for new tilesets will include the &quot;isCompressed&quot; field</string> <string>The mask used to read/write Metatile Behavior from the metatile's attributes data. If 0, this attribute is disabled.</string>
</property> </property>
<property name="text"> <property name="text">
<string>Output 'isCompressed' field</string> <string>Behavior mask</string>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QLabel" name="label_LayerTypeMask">
<property name="toolTip">
<string>The mask used to read/write Layer Type from the metatile's attributes data. If 0, this attribute is disabled.</string>
</property>
<property name="text">
<string>Layer Type mask</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QSpinBox" name="spinBox_BehaviorMask">
<property name="prefix">
<string>0x</string>
</property>
<property name="displayIntegerBase">
<number>16</number>
</property>
</widget>
</item>
<item row="6" column="1">
<widget class="QSpinBox" name="spinBox_TerrainTypeMask">
<property name="prefix">
<string>0x</string>
</property>
<property name="displayIntegerBase">
<number>16</number>
</property> </property>
</widget> </widget>
</item> </item>

View file

@ -10,8 +10,8 @@
#include <QMultiMap> #include <QMultiMap>
// In both versions the default new map border is a generic tree // In both versions the default new map border is a generic tree
#define DEFAULT_BORDER_RSE (QList<int>{468, 469, 476, 477}) #define DEFAULT_BORDER_RSE (QList<uint16_t>{0x1D4, 0x1D5, 0x1DC, 0x1DD})
#define DEFAULT_BORDER_FRLG (QList<int>{20, 21, 28, 29}) #define DEFAULT_BORDER_FRLG (QList<uint16_t>{0x14, 0x15, 0x1C, 0x1D})
#define CONFIG_BACKWARDS_COMPATABILITY #define CONFIG_BACKWARDS_COMPATABILITY
@ -26,6 +26,7 @@ class KeyValueConfigBase
public: public:
void save(); void save();
void load(); void load();
void setSaveDisabled(bool disabled);
virtual ~KeyValueConfigBase(); virtual ~KeyValueConfigBase();
virtual void reset() = 0; virtual void reset() = 0;
protected: protected:
@ -37,6 +38,8 @@ protected:
bool getConfigBool(QString key, QString value); bool getConfigBool(QString key, QString value);
int getConfigInteger(QString key, QString value, int min, int max, int defaultValue); int getConfigInteger(QString key, QString value, int min, int max, int defaultValue);
uint32_t getConfigUint32(QString key, QString value, uint32_t min, uint32_t max, uint32_t defaultValue); uint32_t getConfigUint32(QString key, QString value, uint32_t min, uint32_t max, uint32_t defaultValue);
private:
bool saveDisabled = false;
}; };
class PorymapConfig: public KeyValueConfigBase class PorymapConfig: public KeyValueConfigBase
@ -203,20 +206,11 @@ public:
} }
virtual void reset() override { virtual void reset() override {
this->baseGameVersion = BaseGameVersion::pokeemerald; this->baseGameVersion = BaseGameVersion::pokeemerald;
this->useCustomBorderSize = false; // Reset non-version-specific settings
this->enableEventWeatherTrigger = true;
this->enableEventSecretBase = true;
this->enableHiddenItemQuantity = false;
this->enableHiddenItemRequiresItemfinder = false;
this->enableHealLocationRespawnData = false;
this->enableEventCloneObject = false;
this->enableFloorNumber = false;
this->createMapTextFile = false;
this->usePoryScript = false; this->usePoryScript = false;
this->enableTripleLayerMetatiles = false; this->enableTripleLayerMetatiles = false;
this->newMapMetatileId = 1; this->newMapMetatileId = 1;
this->newMapElevation = 3; this->newMapElevation = 3;
this->newMapBorderMetatileIds = DEFAULT_BORDER_RSE;
this->defaultPrimaryTileset = "gTileset_General"; this->defaultPrimaryTileset = "gTileset_General";
this->prefabFilepath = QString(); this->prefabFilepath = QString();
this->prefabImportPrompted = false; this->prefabImportPrompted = false;
@ -225,10 +219,12 @@ public:
this->filePaths.clear(); this->filePaths.clear();
this->readKeys.clear(); this->readKeys.clear();
} }
static const QStringList baseGameVersions; static const QStringList versionStrings;
void reset(BaseGameVersion baseGameVersion);
void setBaseGameVersion(BaseGameVersion baseGameVersion); void setBaseGameVersion(BaseGameVersion baseGameVersion);
BaseGameVersion getBaseGameVersion(); BaseGameVersion getBaseGameVersion();
QString getBaseGameVersionString(); QString getBaseGameVersionString();
BaseGameVersion stringToBaseGameVersion(QString string, bool * ok = nullptr);
void setUsePoryScript(bool usePoryScript); void setUsePoryScript(bool usePoryScript);
bool getUsePoryScript(); bool getUsePoryScript();
void setProjectDir(QString projectDir); void setProjectDir(QString projectDir);
@ -255,16 +251,17 @@ public:
bool getTripleLayerMetatilesEnabled(); bool getTripleLayerMetatilesEnabled();
int getNumLayersInMetatile(); int getNumLayersInMetatile();
int getNumTilesInMetatile(); int getNumTilesInMetatile();
void setNewMapMetatileId(int metatileId); void setNewMapMetatileId(uint16_t metatileId);
int getNewMapMetatileId(); uint16_t getNewMapMetatileId();
QString getNewMapMetatileIdString();
void setNewMapElevation(int elevation); void setNewMapElevation(int elevation);
int getNewMapElevation(); int getNewMapElevation();
void setNewMapBorderMetatileIds(QList<int> metatileIds); void setNewMapBorderMetatileIds(QList<uint16_t> metatileIds);
QList<int> getNewMapBorderMetatileIds(); QList<uint16_t> getNewMapBorderMetatileIds();
QString getNewMapBorderMetatileIdsString(); QString getNewMapBorderMetatileIdsString();
QString getDefaultPrimaryTileset(); QString getDefaultPrimaryTileset();
QString getDefaultSecondaryTileset(); QString getDefaultSecondaryTileset();
void setDefaultPrimaryTileset(QString tilesetName);
void setDefaultSecondaryTileset(QString tilesetName);
void setFilePath(ProjectFilePath pathId, QString path); void setFilePath(ProjectFilePath pathId, QString path);
QString getFilePath(ProjectFilePath pathId); QString getFilePath(ProjectFilePath pathId);
void setPrefabFilepath(QString filepath); void setPrefabFilepath(QString filepath);
@ -276,12 +273,17 @@ public:
void setTilesetsHaveIsCompressed(bool has); void setTilesetsHaveIsCompressed(bool has);
bool getTilesetsHaveIsCompressed(); bool getTilesetsHaveIsCompressed();
int getMetatileAttributesSize(); int getMetatileAttributesSize();
void setMetatileAttributesSize(int size);
uint32_t getMetatileBehaviorMask(); uint32_t getMetatileBehaviorMask();
uint32_t getMetatileTerrainTypeMask(); uint32_t getMetatileTerrainTypeMask();
uint32_t getMetatileEncounterTypeMask(); uint32_t getMetatileEncounterTypeMask();
uint32_t getMetatileLayerTypeMask(); uint32_t getMetatileLayerTypeMask();
static QString getMaskString(uint32_t mask); void setMetatileBehaviorMask(uint32_t mask);
void setMetatileTerrainTypeMask(uint32_t mask);
void setMetatileEncounterTypeMask(uint32_t mask);
void setMetatileLayerTypeMask(uint32_t mask);
bool getMapAllowFlagsEnabled(); bool getMapAllowFlagsEnabled();
void setMapAllowFlagsEnabled(bool enabled);
protected: protected:
virtual QString getConfigFilepath() override; virtual QString getConfigFilepath() override;
virtual void parseConfigKeyValue(QString key, QString value) override; virtual void parseConfigKeyValue(QString key, QString value) override;
@ -303,9 +305,9 @@ private:
bool enableFloorNumber; bool enableFloorNumber;
bool createMapTextFile; bool createMapTextFile;
bool enableTripleLayerMetatiles; bool enableTripleLayerMetatiles;
int newMapMetatileId; uint16_t newMapMetatileId;
int newMapElevation; int newMapElevation;
QList<int> newMapBorderMetatileIds; QList<uint16_t> newMapBorderMetatileIds;
QString defaultPrimaryTileset; QString defaultPrimaryTileset;
QString defaultSecondaryTileset; QString defaultSecondaryTileset;
QStringList readKeys; QStringList readKeys;

View file

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

View file

@ -198,9 +198,7 @@ private slots:
void on_checkBox_AllowBiking_stateChanged(int selected); void on_checkBox_AllowBiking_stateChanged(int selected);
void on_checkBox_AllowEscaping_stateChanged(int selected); void on_checkBox_AllowEscaping_stateChanged(int selected);
void on_spinBox_FloorNumber_valueChanged(int offset); void on_spinBox_FloorNumber_valueChanged(int offset);
void on_actionUse_Encounter_Json_triggered(bool checked);
void on_actionMonitor_Project_Files_triggered(bool checked); void on_actionMonitor_Project_Files_triggered(bool checked);
void on_actionUse_Poryscript_triggered(bool checked);
void on_actionOpen_Recent_Project_On_Launch_triggered(bool checked); void on_actionOpen_Recent_Project_On_Launch_triggered(bool checked);
void on_actionEdit_Shortcuts_triggered(); void on_actionEdit_Shortcuts_triggered();

View file

@ -31,11 +31,17 @@ private:
NoScrollComboBox *combo_baseGameVersion; NoScrollComboBox *combo_baseGameVersion;
NoScrollComboBox *combo_attributesSize; NoScrollComboBox *combo_attributesSize;
bool hasUnsavedChanges = false;
void initUi(); void initUi();
void saveFields(); void saveFields();
void connectSignals();
void refresh();
bool prompt(const QString &text);
private slots: private slots:
void dialogButtonClicked(QAbstractButton *button); void dialogButtonClicked(QAbstractButton *button);
void markEdited();
}; };
#endif // PROJECTSETTINGSEDITOR_H #endif // PROJECTSETTINGSEDITOR_H

View file

@ -119,6 +119,9 @@ void KeyValueConfigBase::load() {
} }
void KeyValueConfigBase::save() { void KeyValueConfigBase::save() {
if (this->saveDisabled)
return;
QString text = ""; QString text = "";
QMap<QString, QString> map = this->getKeyValueMap(); QMap<QString, QString> map = this->getKeyValueMap();
for (QMap<QString, QString>::iterator it = map.begin(); it != map.end(); it++) { for (QMap<QString, QString>::iterator it = map.begin(); it != map.end(); it++) {
@ -163,6 +166,11 @@ uint32_t KeyValueConfigBase::getConfigUint32(QString key, QString value, uint32_
return qMin(max, qMax(min, result)); return qMin(max, qMax(min, result));
} }
// For temporarily disabling saving during frequent config changes.
void KeyValueConfigBase::setSaveDisabled(bool disabled) {
this->saveDisabled = disabled;
}
const QMap<MapSortOrder, QString> mapSortOrderMap = { const QMap<MapSortOrder, QString> mapSortOrderMap = {
{MapSortOrder::Group, "group"}, {MapSortOrder::Group, "group"},
{MapSortOrder::Layout, "layout"}, {MapSortOrder::Layout, "layout"},
@ -513,24 +521,34 @@ int PorymapConfig::getPaletteEditorBitDepth() {
return this->paletteEditorBitDepth; return this->paletteEditorBitDepth;
} }
const QStringList ProjectConfig::baseGameVersions = { const QStringList ProjectConfig::versionStrings = {
"pokeruby", "pokeruby",
"pokefirered", "pokefirered",
"pokeemerald", "pokeemerald",
}; };
const QMap<BaseGameVersion, QString> baseGameVersionMap = { const QMap<BaseGameVersion, QString> baseGameVersionMap = {
{BaseGameVersion::pokeruby, ProjectConfig::baseGameVersions[0]}, {BaseGameVersion::pokeruby, ProjectConfig::versionStrings[0]},
{BaseGameVersion::pokefirered, ProjectConfig::baseGameVersions[1]}, {BaseGameVersion::pokefirered, ProjectConfig::versionStrings[1]},
{BaseGameVersion::pokeemerald, ProjectConfig::baseGameVersions[2]}, {BaseGameVersion::pokeemerald, ProjectConfig::versionStrings[2]},
}; };
const QMap<QString, BaseGameVersion> baseGameVersionReverseMap = { const QMap<QString, BaseGameVersion> baseGameVersionReverseMap = {
{ProjectConfig::baseGameVersions[0], BaseGameVersion::pokeruby}, {ProjectConfig::versionStrings[0], BaseGameVersion::pokeruby},
{ProjectConfig::baseGameVersions[1], BaseGameVersion::pokefirered}, {ProjectConfig::versionStrings[1], BaseGameVersion::pokefirered},
{ProjectConfig::baseGameVersions[2], BaseGameVersion::pokeemerald}, {ProjectConfig::versionStrings[2], BaseGameVersion::pokeemerald},
}; };
BaseGameVersion ProjectConfig::stringToBaseGameVersion(QString string, bool * ok) {
if (baseGameVersionReverseMap.contains(string)) {
if (ok) *ok = true;
return baseGameVersionReverseMap.value(string);
} else {
if (ok) *ok = false;
return BaseGameVersion::pokeemerald;
}
}
ProjectConfig projectConfig; ProjectConfig projectConfig;
QString ProjectConfig::getConfigFilepath() { QString ProjectConfig::getConfigFilepath() {
@ -540,13 +558,10 @@ QString ProjectConfig::getConfigFilepath() {
void ProjectConfig::parseConfigKeyValue(QString key, QString value) { void ProjectConfig::parseConfigKeyValue(QString key, QString value) {
if (key == "base_game_version") { if (key == "base_game_version") {
QString baseGameVersion = value.toLower(); bool ok;
if (baseGameVersionReverseMap.contains(baseGameVersion)) { this->baseGameVersion = this->stringToBaseGameVersion(value.toLower(), &ok);
this->baseGameVersion = baseGameVersionReverseMap.value(baseGameVersion); if (!ok)
} else {
this->baseGameVersion = BaseGameVersion::pokeemerald;
logWarn(QString("Invalid config value for base_game_version: '%1'. Must be 'pokeruby', 'pokefirered' or 'pokeemerald'.").arg(value)); logWarn(QString("Invalid config value for base_game_version: '%1'. Must be 'pokeruby', 'pokefirered' or 'pokeemerald'.").arg(value));
}
} else if (key == "use_poryscript") { } else if (key == "use_poryscript") {
this->usePoryScript = getConfigBool(key, value); this->usePoryScript = getConfigBool(key, value);
} else if (key == "use_custom_border_size") { } else if (key == "use_custom_border_size") {
@ -571,24 +586,18 @@ void ProjectConfig::parseConfigKeyValue(QString key, QString value) {
} else if (key == "enable_triple_layer_metatiles") { } else if (key == "enable_triple_layer_metatiles") {
this->enableTripleLayerMetatiles = getConfigBool(key, value); this->enableTripleLayerMetatiles = getConfigBool(key, value);
} else if (key == "new_map_metatile") { } else if (key == "new_map_metatile") {
this->newMapMetatileId = getConfigInteger(key, value, 0, 1023, 0); this->newMapMetatileId = getConfigUint32(key, value, 0, 1023, 0);
} else if (key == "new_map_elevation") { } else if (key == "new_map_elevation") {
this->newMapElevation = getConfigInteger(key, value, 0, 15, 3); this->newMapElevation = getConfigInteger(key, value, 0, 15, 3);
} else if (key == "new_map_border_metatiles") { } else if (key == "new_map_border_metatiles") {
this->newMapBorderMetatileIds.clear(); this->newMapBorderMetatileIds.clear();
QList<QString> metatileIds = value.split(","); QList<QString> metatileIds = value.split(",");
const int maxSize = DEFAULT_BORDER_WIDTH * DEFAULT_BORDER_HEIGHT; for (int i = 0; i < metatileIds.size(); i++) {
const int size = qMin(metatileIds.size(), maxSize); // TODO: The max of 1023 here should eventually reflect Project::num_metatiles_total-1,
int i; // but the config is parsed well before that constant is.
for (i = 0; i < size; i++) { int metatileId = getConfigUint32(key, metatileIds.at(i), 0, 1023, 0);
int metatileId = getConfigInteger(key, metatileIds.at(i), 0, 1023, 0);
this->newMapBorderMetatileIds.append(metatileId); this->newMapBorderMetatileIds.append(metatileId);
} }
// TODO: If insufficient metatiles are provided, it should loop the provided metatiles instead.
for (; i < maxSize; i++) {
// Set any metatiles not provided to 0
this->newMapBorderMetatileIds.append(0);
}
} else if (key == "default_primary_tileset") { } else if (key == "default_primary_tileset") {
this->defaultPrimaryTileset = value; this->defaultPrimaryTileset = value;
} else if (key == "default_secondary_tileset") { } else if (key == "default_secondary_tileset") {
@ -646,6 +655,13 @@ void ProjectConfig::parseConfigKeyValue(QString key, QString value) {
readKeys.append(key); readKeys.append(key);
} }
// Restore config to version-specific defaults
void::ProjectConfig::reset(BaseGameVersion baseGameVersion) {
this->reset();
this->setBaseGameVersion(baseGameVersion);
this->setUnreadKeys();
}
void ProjectConfig::setUnreadKeys() { void ProjectConfig::setUnreadKeys() {
// Set game-version specific defaults for any config field that wasn't read // Set game-version specific defaults for any config field that wasn't read
bool isPokefirered = this->baseGameVersion == BaseGameVersion::pokefirered; bool isPokefirered = this->baseGameVersion == BaseGameVersion::pokefirered;
@ -682,7 +698,7 @@ QMap<QString, QString> ProjectConfig::getKeyValueMap() {
map.insert("enable_floor_number", QString::number(this->enableFloorNumber)); map.insert("enable_floor_number", QString::number(this->enableFloorNumber));
map.insert("create_map_text_file", QString::number(this->createMapTextFile)); map.insert("create_map_text_file", QString::number(this->createMapTextFile));
map.insert("enable_triple_layer_metatiles", QString::number(this->enableTripleLayerMetatiles)); map.insert("enable_triple_layer_metatiles", QString::number(this->enableTripleLayerMetatiles));
map.insert("new_map_metatile", this->getNewMapMetatileIdString()); map.insert("new_map_metatile", Metatile::getMetatileIdString(this->newMapMetatileId));
map.insert("new_map_elevation", QString::number(this->newMapElevation)); map.insert("new_map_elevation", QString::number(this->newMapElevation));
map.insert("new_map_border_metatiles", this->getNewMapBorderMetatileIdsString()); map.insert("new_map_border_metatiles", this->getNewMapBorderMetatileIdsString());
map.insert("default_primary_tileset", this->defaultPrimaryTileset); map.insert("default_primary_tileset", this->defaultPrimaryTileset);
@ -695,10 +711,10 @@ QMap<QString, QString> ProjectConfig::getKeyValueMap() {
map.insert("tilesets_have_callback", QString::number(this->tilesetsHaveCallback)); map.insert("tilesets_have_callback", QString::number(this->tilesetsHaveCallback));
map.insert("tilesets_have_is_compressed", QString::number(this->tilesetsHaveIsCompressed)); map.insert("tilesets_have_is_compressed", QString::number(this->tilesetsHaveIsCompressed));
map.insert("metatile_attributes_size", QString::number(this->metatileAttributesSize)); map.insert("metatile_attributes_size", QString::number(this->metatileAttributesSize));
map.insert("metatile_behavior_mask", getMaskString(this->metatileBehaviorMask)); map.insert("metatile_behavior_mask", "0x" + QString::number(this->metatileBehaviorMask, 16).toUpper());
map.insert("metatile_terrain_type_mask", getMaskString(this->metatileTerrainTypeMask)); map.insert("metatile_terrain_type_mask", "0x" + QString::number(this->metatileTerrainTypeMask, 16).toUpper());
map.insert("metatile_encounter_type_mask", getMaskString(this->metatileEncounterTypeMask)); map.insert("metatile_encounter_type_mask", "0x" + QString::number(this->metatileEncounterTypeMask, 16).toUpper());
map.insert("metatile_layer_type_mask", getMaskString(this->metatileLayerTypeMask)); map.insert("metatile_layer_type_mask", "0x" + QString::number(this->metatileLayerTypeMask, 16).toUpper());
map.insert("enable_map_allow_flags", QString::number(this->enableMapAllowFlags)); map.insert("enable_map_allow_flags", QString::number(this->enableMapAllowFlags));
return map; return map;
} }
@ -875,19 +891,15 @@ int ProjectConfig::getNumTilesInMetatile() {
return this->enableTripleLayerMetatiles ? 12 : 8; return this->enableTripleLayerMetatiles ? 12 : 8;
} }
void ProjectConfig::setNewMapMetatileId(int metatileId) { void ProjectConfig::setNewMapMetatileId(uint16_t metatileId) {
this->newMapMetatileId = metatileId; this->newMapMetatileId = metatileId;
this->save(); this->save();
} }
int ProjectConfig::getNewMapMetatileId() { uint16_t ProjectConfig::getNewMapMetatileId() {
return this->newMapMetatileId; return this->newMapMetatileId;
} }
QString ProjectConfig::getNewMapMetatileIdString() {
return "0x" + QString::number(this->newMapMetatileId, 16).toUpper();
}
void ProjectConfig::setNewMapElevation(int elevation) { void ProjectConfig::setNewMapElevation(int elevation) {
this->newMapElevation = elevation; this->newMapElevation = elevation;
this->save(); this->save();
@ -897,19 +909,19 @@ int ProjectConfig::getNewMapElevation() {
return this->newMapElevation; return this->newMapElevation;
} }
void ProjectConfig::setNewMapBorderMetatileIds(QList<int> metatileIds) { void ProjectConfig::setNewMapBorderMetatileIds(QList<uint16_t> metatileIds) {
this->newMapBorderMetatileIds = metatileIds; this->newMapBorderMetatileIds = metatileIds;
this->save(); this->save();
} }
QList<int> ProjectConfig::getNewMapBorderMetatileIds() { QList<uint16_t> ProjectConfig::getNewMapBorderMetatileIds() {
return this->newMapBorderMetatileIds; return this->newMapBorderMetatileIds;
} }
QString ProjectConfig::getNewMapBorderMetatileIdsString() { QString ProjectConfig::getNewMapBorderMetatileIdsString() {
QStringList metatiles; QStringList metatiles;
for (auto metatileId : this->newMapBorderMetatileIds){ for (auto metatileId : this->newMapBorderMetatileIds){
metatiles << ("0x" + QString::number(metatileId, 16).toUpper()); metatiles << Metatile::getMetatileIdString(metatileId);
} }
return metatiles.join(","); return metatiles.join(",");
} }
@ -922,6 +934,16 @@ QString ProjectConfig::getDefaultSecondaryTileset() {
return this->defaultSecondaryTileset; return this->defaultSecondaryTileset;
} }
void ProjectConfig::setDefaultPrimaryTileset(QString tilesetName) {
this->defaultPrimaryTileset = tilesetName;
this->save();
}
void ProjectConfig::setDefaultSecondaryTileset(QString tilesetName) {
this->defaultSecondaryTileset = tilesetName;
this->save();
}
void ProjectConfig::setPrefabFilepath(QString filepath) { void ProjectConfig::setPrefabFilepath(QString filepath) {
this->prefabFilepath = filepath; this->prefabFilepath = filepath;
this->save(); this->save();
@ -965,6 +987,11 @@ int ProjectConfig::getMetatileAttributesSize() {
return this->metatileAttributesSize; return this->metatileAttributesSize;
} }
void ProjectConfig::setMetatileAttributesSize(int size) {
this->metatileAttributesSize = size;
this->save();
}
uint32_t ProjectConfig::getMetatileBehaviorMask() { uint32_t ProjectConfig::getMetatileBehaviorMask() {
return this->metatileBehaviorMask; return this->metatileBehaviorMask;
} }
@ -981,14 +1008,35 @@ uint32_t ProjectConfig::getMetatileLayerTypeMask() {
return this->metatileLayerTypeMask; return this->metatileLayerTypeMask;
} }
QString ProjectConfig::getMaskString(uint32_t mask) { void ProjectConfig::setMetatileBehaviorMask(uint32_t mask) {
return "0x" + QString::number(mask, 16).toUpper(); this->metatileBehaviorMask = mask;
this->save();
}
void ProjectConfig::setMetatileTerrainTypeMask(uint32_t mask) {
this->metatileTerrainTypeMask = mask;
this->save();
}
void ProjectConfig::setMetatileEncounterTypeMask(uint32_t mask) {
this->metatileEncounterTypeMask = mask;
this->save();
}
void ProjectConfig::setMetatileLayerTypeMask(uint32_t mask) {
this->metatileLayerTypeMask = mask;
this->save();
} }
bool ProjectConfig::getMapAllowFlagsEnabled() { bool ProjectConfig::getMapAllowFlagsEnabled() {
return this->enableMapAllowFlags; return this->enableMapAllowFlags;
} }
void ProjectConfig::setMapAllowFlagsEnabled(bool enabled) {
this->enableMapAllowFlags = enabled;
this->save();
}
UserConfig userConfig; UserConfig userConfig;

View file

@ -933,8 +933,7 @@ void Editor::onHoveredMovementPermissionCleared() {
QString Editor::getMetatileDisplayMessage(uint16_t metatileId) { QString Editor::getMetatileDisplayMessage(uint16_t metatileId) {
Metatile *metatile = Tileset::getMetatile(metatileId, map->layout->tileset_primary, map->layout->tileset_secondary); Metatile *metatile = Tileset::getMetatile(metatileId, map->layout->tileset_primary, map->layout->tileset_secondary);
QString label = Tileset::getMetatileLabel(metatileId, map->layout->tileset_primary, map->layout->tileset_secondary); QString label = Tileset::getMetatileLabel(metatileId, map->layout->tileset_primary, map->layout->tileset_secondary);
QString hexString = QString("%1").arg(metatileId, 3, 16, QChar('0')).toUpper(); QString message = QString("Metatile: %1").arg(Metatile::getMetatileIdString(metatileId));
QString message = QString("Metatile: 0x%1").arg(hexString);
if (label.size()) if (label.size())
message += QString(" \"%1\"").arg(label); message += QString(" \"%1\"").arg(label);
if (metatile && metatile->behavior) // Skip MB_NORMAL if (metatile && metatile->behavior) // Skip MB_NORMAL

View file

@ -369,13 +369,11 @@ void MainWindow::markMapEdited() {
} }
void MainWindow::setWildEncountersUIEnabled(bool enabled) { void MainWindow::setWildEncountersUIEnabled(bool enabled) {
ui->actionUse_Encounter_Json->setChecked(enabled);
ui->mainTabBar->setTabEnabled(4, enabled); ui->mainTabBar->setTabEnabled(4, enabled);
} }
void MainWindow::setProjectSpecificUIVisibility() void MainWindow::setProjectSpecificUIVisibility()
{ {
ui->actionUse_Poryscript->setChecked(projectConfig.getUsePoryScript());
this->setWildEncountersUIEnabled(userConfig.getEncounterJsonActive()); this->setWildEncountersUIEnabled(userConfig.getEncounterJsonActive());
bool hasFlags = projectConfig.getMapAllowFlagsEnabled(); bool hasFlags = projectConfig.getMapAllowFlagsEnabled();
@ -1757,25 +1755,11 @@ void MainWindow::on_actionCursor_Tile_Outline_triggered()
} }
} }
void MainWindow::on_actionUse_Encounter_Json_triggered(bool checked)
{
QMessageBox warning(this);
warning.setText("You must reload the project for this setting to take effect.");
warning.setIcon(QMessageBox::Information);
warning.exec();
userConfig.setEncounterJsonActive(checked);
}
void MainWindow::on_actionMonitor_Project_Files_triggered(bool checked) void MainWindow::on_actionMonitor_Project_Files_triggered(bool checked)
{ {
porymapConfig.setMonitorFiles(checked); porymapConfig.setMonitorFiles(checked);
} }
void MainWindow::on_actionUse_Poryscript_triggered(bool checked)
{
projectConfig.setUsePoryScript(checked);
}
void MainWindow::on_actionOpen_Recent_Project_On_Launch_triggered(bool checked) void MainWindow::on_actionOpen_Recent_Project_On_Launch_triggered(bool checked)
{ {
porymapConfig.setReopenOnLaunch(checked); porymapConfig.setReopenOnLaunch(checked);

View file

@ -957,9 +957,9 @@ void Project::saveTilesetMetatileLabels(Tileset *primaryTileset, Tileset *second
} }
for (QString defineName : definesOut.keys()) { for (QString defineName : definesOut.keys()) {
int value = defines[defineName]; int value = defines[defineName];
QString line = QString("#define %1 0x%2\n") QString line = QString("#define %1 %2\n")
.arg(defineName, -1 * longestLength) .arg(defineName, -1 * longestLength)
.arg(QString("%1").arg(value, 3, 16, QChar('0')).toUpper()); .arg(Metatile::getMetatileIdString(value));
outputText += line; outputText += line;
} }
i += j; i += j;
@ -1142,16 +1142,21 @@ void Project::setNewMapBorder(Map *map) {
map->layout->border.clear(); map->layout->border.clear();
int width = map->getBorderWidth(); int width = map->getBorderWidth();
int height = map->getBorderHeight(); int height = map->getBorderHeight();
if (width != DEFAULT_BORDER_WIDTH || height != DEFAULT_BORDER_HEIGHT) {
const QList<uint16_t> configMetatileIds = projectConfig.getNewMapBorderMetatileIds();
if (configMetatileIds.length() != width * height) {
// Border size doesn't match the number of default border metatiles.
// Fill the border with empty metatiles.
for (int i = 0; i < width * height; i++) { for (int i = 0; i < width * height; i++) {
map->layout->border.append(0); map->layout->border.append(0);
} }
} else { } else {
QList<int> metatileIds = projectConfig.getNewMapBorderMetatileIds(); // Fill the border with the default metatiles from the config.
for (int i = 0; i < DEFAULT_BORDER_WIDTH * DEFAULT_BORDER_HEIGHT; i++) { for (int i = 0; i < width * height; i++) {
map->layout->border.append(qint16(metatileIds.at(i))); map->layout->border.append(configMetatileIds.at(i));
} }
} }
map->layout->lastCommitBlocks.border = map->layout->border; map->layout->lastCommitBlocks.border = map->layout->border;
map->layout->lastCommitBlocks.borderDimensions = QSize(width, height); map->layout->lastCommitBlocks.borderDimensions = QSize(width, height);
} }
@ -2174,8 +2179,8 @@ bool Project::readCoordEventWeatherNames() {
fileWatcher.addPath(root + "/" + filename); fileWatcher.addPath(root + "/" + filename);
coordEventWeatherNames = parser.readCDefinesSorted(filename, prefixes); coordEventWeatherNames = parser.readCDefinesSorted(filename, prefixes);
if (coordEventWeatherNames.isEmpty()) { if (coordEventWeatherNames.isEmpty()) {
logError(QString("Failed to read coord event weather constants from %1").arg(filename)); logWarn(QString("Failed to read coord event weather constants from %1. Disabling Weather Trigger events.").arg(filename));
return false; projectConfig.setEventWeatherTriggerEnabled(false);
} }
return true; return true;
} }
@ -2189,8 +2194,8 @@ bool Project::readSecretBaseIds() {
fileWatcher.addPath(root + "/" + filename); fileWatcher.addPath(root + "/" + filename);
secretBaseIds = parser.readCDefinesSorted(filename, prefixes); secretBaseIds = parser.readCDefinesSorted(filename, prefixes);
if (secretBaseIds.isEmpty()) { if (secretBaseIds.isEmpty()) {
logError(QString("Failed to read secret base id constants from %1").arg(filename)); logWarn(QString("Failed to read secret base id constants from '%1'. Disabling Secret Base events.").arg(filename));
return false; projectConfig.setEventSecretBaseEnabled(false);
} }
return true; return true;
} }

View file

@ -22,8 +22,8 @@ ProjectSettingsEditor::ProjectSettingsEditor(QWidget *parent, Project *project)
ui->setupUi(this); ui->setupUi(this);
initUi(); initUi();
setAttribute(Qt::WA_DeleteOnClose); setAttribute(Qt::WA_DeleteOnClose);
connect(ui->buttonBox, &QDialogButtonBox::clicked, connectSignals();
this, &ProjectSettingsEditor::dialogButtonClicked); refresh();
} }
ProjectSettingsEditor::~ProjectSettingsEditor() ProjectSettingsEditor::~ProjectSettingsEditor()
@ -31,8 +31,76 @@ ProjectSettingsEditor::~ProjectSettingsEditor()
delete ui; delete ui;
} }
void ProjectSettingsEditor::connectSignals() {
connect(ui->buttonBox, &QDialogButtonBox::clicked, this, &ProjectSettingsEditor::dialogButtonClicked);
// Connect combo boxes
QList<NoScrollComboBox *> combos = ui->centralwidget->findChildren<NoScrollComboBox *>();
foreach(auto i, combos)
connect(i, &QComboBox::currentTextChanged, this, &ProjectSettingsEditor::markEdited);
// Connect check boxes
QList<QCheckBox *> checkboxes = ui->centralwidget->findChildren<QCheckBox *>();
foreach(auto i, checkboxes)
connect(i, &QCheckBox::stateChanged, this, &ProjectSettingsEditor::markEdited);
// Connect spin boxes
QList<QSpinBox *> spinBoxes = ui->centralwidget->findChildren<QSpinBox *>();
foreach(auto i, spinBoxes)
connect(i, QOverload<int>::of(&QSpinBox::valueChanged), [this](int) { this->markEdited(); });
// Connect line edits
QList<QLineEdit *> lineEdits = ui->centralwidget->findChildren<QLineEdit *>();
foreach(auto i, lineEdits)
connect(i, &QLineEdit::textEdited, this, &ProjectSettingsEditor::markEdited);
}
void ProjectSettingsEditor::markEdited() {
this->hasUnsavedChanges = true;
}
void ProjectSettingsEditor::initUi() { void ProjectSettingsEditor::initUi() {
// Block signals while setting initial UI states // Create Default Tilesets combo boxes
auto *defaultTilesetsLayout = new QFormLayout(ui->groupBox_DefaultTilesets);
combo_defaultPrimaryTileset = new NoScrollComboBox(ui->groupBox_DefaultTilesets);
combo_defaultSecondaryTileset = new NoScrollComboBox(ui->groupBox_DefaultTilesets);
if (project) combo_defaultPrimaryTileset->addItems(project->primaryTilesetLabels);
if (project) combo_defaultSecondaryTileset->addItems(project->secondaryTilesetLabels);
defaultTilesetsLayout->addRow("Primary Tileset", combo_defaultPrimaryTileset);
defaultTilesetsLayout->addRow("Secondary Tileset", combo_defaultSecondaryTileset);
// Create Base game version combo box
combo_baseGameVersion = new NoScrollComboBox(ui->widget_BaseGameVersion);
combo_baseGameVersion->addItems(ProjectConfig::versionStrings);
combo_baseGameVersion->setEditable(false);
ui->layout_BaseGameVersion->insertRow(0, "Base game version", combo_baseGameVersion);
// Create Attributes size combo box
auto *attributesSizeLayout = new QFormLayout(ui->widget_SizeDropdown);
combo_attributesSize = new NoScrollComboBox(ui->widget_SizeDropdown);
combo_attributesSize->addItems({"1", "2", "4"});
combo_attributesSize->setEditable(false);
attributesSizeLayout->addRow("", combo_attributesSize);
// Validate that the border metatiles text is a comma-separated list of hex values
static const QRegularExpression expression("^((0[xX])?[A-Fa-f0-9]+,)*(0[xX])?[A-Fa-f0-9]$");
QRegularExpressionValidator *validator = new QRegularExpressionValidator(expression);
ui->lineEdit_BorderMetatiles->setValidator(validator);
ui->spinBox_Elevation->setMaximum(15);
ui->spinBox_FillMetatile->setMaximum(Project::getNumMetatilesTotal() - 1);
// TODO: These need to be subclassed to handle larger values
ui->spinBox_BehaviorMask->setMaximum(INT_MAX);
ui->spinBox_EncounterTypeMask->setMaximum(INT_MAX);
ui->spinBox_LayerTypeMask->setMaximum(INT_MAX);
ui->spinBox_TerrainTypeMask->setMaximum(INT_MAX);
// TODO: File picker for prefabs?
}
// Set UI states using config data
void ProjectSettingsEditor::refresh() {
const QSignalBlocker blocker0(combo_defaultPrimaryTileset); const QSignalBlocker blocker0(combo_defaultPrimaryTileset);
const QSignalBlocker blocker1(combo_defaultSecondaryTileset); const QSignalBlocker blocker1(combo_defaultSecondaryTileset);
const QSignalBlocker blocker2(combo_baseGameVersion); const QSignalBlocker blocker2(combo_baseGameVersion);
@ -54,41 +122,21 @@ void ProjectSettingsEditor::initUi() {
const QSignalBlocker blocker12(ui->checkBox_OutputCallback); const QSignalBlocker blocker12(ui->checkBox_OutputCallback);
const QSignalBlocker blocker13(ui->checkBox_OutputIsCompressed); const QSignalBlocker blocker13(ui->checkBox_OutputIsCompressed);
const QSignalBlocker blocker14(ui->spinBox_Elevation); const QSignalBlocker blocker14(ui->spinBox_Elevation);
const QSignalBlocker blocker15(ui->lineEdit_BorderMetatiles); const QSignalBlocker blocker15(ui->spinBox_FillMetatile);
const QSignalBlocker blocker16(ui->lineEdit_FillMetatile); const QSignalBlocker blocker16(ui->spinBox_BehaviorMask);
const QSignalBlocker blocker17(ui->lineEdit_PrefabsPath); const QSignalBlocker blocker17(ui->spinBox_EncounterTypeMask);
const QSignalBlocker blocker18(ui->lineEdit_BehaviorMask); const QSignalBlocker blocker18(ui->spinBox_LayerTypeMask);
const QSignalBlocker blocker19(ui->lineEdit_EncounterTypeMask); const QSignalBlocker blocker19(ui->spinBox_TerrainTypeMask);
const QSignalBlocker blocker1A(ui->lineEdit_LayerTypeMask); const QSignalBlocker blocker1A(ui->lineEdit_BorderMetatiles);
const QSignalBlocker blocker1B(ui->lineEdit_TerrainTypeMask); const QSignalBlocker blocker1B(ui->lineEdit_PrefabsPath);
// Create Default Tilesets combo boxes // Set combo box texts
auto *defaultTilesetsLayout = new QFormLayout(ui->groupBox_DefaultTilesets);
combo_defaultPrimaryTileset = new NoScrollComboBox(ui->groupBox_DefaultTilesets);
combo_defaultSecondaryTileset = new NoScrollComboBox(ui->groupBox_DefaultTilesets);
if (project) combo_defaultPrimaryTileset->addItems(project->primaryTilesetLabels);
if (project) combo_defaultSecondaryTileset->addItems(project->secondaryTilesetLabels);
combo_defaultPrimaryTileset->setTextItem(projectConfig.getDefaultPrimaryTileset()); combo_defaultPrimaryTileset->setTextItem(projectConfig.getDefaultPrimaryTileset());
combo_defaultSecondaryTileset->setTextItem(projectConfig.getDefaultSecondaryTileset()); combo_defaultSecondaryTileset->setTextItem(projectConfig.getDefaultSecondaryTileset());
defaultTilesetsLayout->addRow("Primary Tileset", combo_defaultPrimaryTileset);
defaultTilesetsLayout->addRow("Secondary Tileset", combo_defaultSecondaryTileset);
// Create Base game version combo box
combo_baseGameVersion = new NoScrollComboBox(ui->widget_BaseGameVersion);
combo_baseGameVersion->addItems(ProjectConfig::baseGameVersions);
combo_baseGameVersion->setTextItem(projectConfig.getBaseGameVersionString()); combo_baseGameVersion->setTextItem(projectConfig.getBaseGameVersionString());
combo_baseGameVersion->setEditable(false);
ui->layout_BaseGameVersion->insertRow(0, "Base game version", combo_baseGameVersion);
// Create Attributes size combo box
auto *attributesSizeLayout = new QFormLayout(ui->widget_SizeDropdown);
combo_attributesSize = new NoScrollComboBox(ui->widget_SizeDropdown);
combo_attributesSize->addItems({"1", "2", "4"});
combo_attributesSize->setTextItem(QString::number(projectConfig.getMetatileAttributesSize())); combo_attributesSize->setTextItem(QString::number(projectConfig.getMetatileAttributesSize()));
combo_attributesSize->setEditable(false);
attributesSizeLayout->addRow("", combo_attributesSize);
// Init check boxes // Set check box states
ui->checkBox_UsePoryscript->setChecked(projectConfig.getUsePoryScript()); ui->checkBox_UsePoryscript->setChecked(projectConfig.getUsePoryScript());
ui->checkBox_ShowWildEncounterTables->setChecked(userConfig.getEncounterJsonActive()); ui->checkBox_ShowWildEncounterTables->setChecked(userConfig.getEncounterJsonActive());
ui->checkBox_CreateTextFile->setChecked(projectConfig.getCreateMapTextFileEnabled()); ui->checkBox_CreateTextFile->setChecked(projectConfig.getCreateMapTextFileEnabled());
@ -106,71 +154,107 @@ void ProjectSettingsEditor::initUi() {
ui->checkBox_OutputCallback->setChecked(projectConfig.getTilesetsHaveCallback()); ui->checkBox_OutputCallback->setChecked(projectConfig.getTilesetsHaveCallback());
ui->checkBox_OutputIsCompressed->setChecked(projectConfig.getTilesetsHaveIsCompressed()); ui->checkBox_OutputIsCompressed->setChecked(projectConfig.getTilesetsHaveIsCompressed());
// Init spinners // Set spin box values
ui->spinBox_Elevation->setRange(0, 15);
ui->spinBox_Elevation->setValue(projectConfig.getNewMapElevation()); ui->spinBox_Elevation->setValue(projectConfig.getNewMapElevation());
ui->spinBox_FillMetatile->setValue(projectConfig.getNewMapMetatileId());
ui->spinBox_BehaviorMask->setValue(projectConfig.getMetatileBehaviorMask());
ui->spinBox_EncounterTypeMask->setValue(projectConfig.getMetatileEncounterTypeMask());
ui->spinBox_LayerTypeMask->setValue(projectConfig.getMetatileLayerTypeMask());
ui->spinBox_TerrainTypeMask->setValue(projectConfig.getMetatileTerrainTypeMask());
// Init text boxes // Set line edit texts
// TODO: Validator for Border Metatiles and Fill Metatile
ui->lineEdit_BorderMetatiles->setText(projectConfig.getNewMapBorderMetatileIdsString()); ui->lineEdit_BorderMetatiles->setText(projectConfig.getNewMapBorderMetatileIdsString());
ui->lineEdit_FillMetatile->setText(projectConfig.getNewMapMetatileIdString());
ui->lineEdit_PrefabsPath->setText(projectConfig.getPrefabFilepath(false)); ui->lineEdit_PrefabsPath->setText(projectConfig.getPrefabFilepath(false));
QString mask = ProjectConfig::getMaskString(projectConfig.getMetatileBehaviorMask());
ui->lineEdit_BehaviorMask->setText(mask);
mask = ProjectConfig::getMaskString(projectConfig.getMetatileEncounterTypeMask());
ui->lineEdit_EncounterTypeMask->setText(mask);
mask = ProjectConfig::getMaskString(projectConfig.getMetatileLayerTypeMask());
ui->lineEdit_LayerTypeMask->setText(mask);
mask = ProjectConfig::getMaskString(projectConfig.getMetatileTerrainTypeMask());
ui->lineEdit_TerrainTypeMask->setText(mask);
} }
// TODO: Certain setting changes may require project reload
void ProjectSettingsEditor::saveFields() { void ProjectSettingsEditor::saveFields() {
// TODO if (!this->hasUnsavedChanges)
/* return;
TODO combo_defaultPrimaryTileset
TODO combo_defaultSecondaryTileset // Prevent a call to save() for each of the config settings
setBaseGameVersion combo_baseGameVersion projectConfig.setSaveDisabled(true);
TODO combo_attributesSize userConfig.setSaveDisabled(true);
setUsePoryScript ui->checkBox_UsePoryscript
userConfig.setEncounterJsonActive ui->checkBox_ShowWildEncounterTables projectConfig.setDefaultPrimaryTileset(combo_defaultPrimaryTileset->currentText());
setCreateMapTextFileEnabled ui->checkBox_CreateTextFile projectConfig.setDefaultSecondaryTileset(combo_defaultSecondaryTileset->currentText());
setPrefabImportPrompted ui->checkBox_PrefabImportPrompted projectConfig.setBaseGameVersion(projectConfig.stringToBaseGameVersion(combo_baseGameVersion->currentText()));
setTripleLayerMetatilesEnabled ui->checkBox_EnableTripleLayerMetatiles projectConfig.setMetatileAttributesSize(combo_attributesSize->currentText().toInt());
setHiddenItemRequiresItemfinderEnabled ui->checkBox_EnableRequiresItemfinder projectConfig.setUsePoryScript(ui->checkBox_UsePoryscript->isChecked());
setHiddenItemQuantityEnabled ui->checkBox_EnableQuantity userConfig.setEncounterJsonActive(ui->checkBox_ShowWildEncounterTables->isChecked());
setEventCloneObjectEnabled ui->checkBox_EnableCloneObjects projectConfig.setCreateMapTextFileEnabled(ui->checkBox_CreateTextFile->isChecked());
setEventWeatherTriggerEnabled ui->checkBox_EnableWeatherTriggers projectConfig.setPrefabImportPrompted(ui->checkBox_PrefabImportPrompted->isChecked());
setEventSecretBaseEnabled ui->checkBox_EnableSecretBases projectConfig.setTripleLayerMetatilesEnabled(ui->checkBox_EnableTripleLayerMetatiles->isChecked());
setHealLocationRespawnDataEnabled ui->checkBox_EnableRespawn projectConfig.setHiddenItemRequiresItemfinderEnabled(ui->checkBox_EnableRequiresItemfinder->isChecked());
TODO ui->checkBox_EnableAllowFlags projectConfig.setHiddenItemQuantityEnabled(ui->checkBox_EnableQuantity->isChecked());
setFloorNumberEnabled ui->checkBox_EnableFloorNumber projectConfig.setEventCloneObjectEnabled(ui->checkBox_EnableCloneObjects->isChecked());
setUseCustomBorderSize ui->checkBox_EnableCustomBorderSize projectConfig.setEventWeatherTriggerEnabled(ui->checkBox_EnableWeatherTriggers->isChecked());
setTilesetsHaveCallback ui->checkBox_OutputCallback projectConfig.setEventSecretBaseEnabled(ui->checkBox_EnableSecretBases->isChecked());
setTilesetsHaveIsCompressed ui->checkBox_OutputIsCompressed projectConfig.setHealLocationRespawnDataEnabled(ui->checkBox_EnableRespawn->isChecked());
setNewMapElevation ui->spinBox_Elevation projectConfig.setMapAllowFlagsEnabled(ui->checkBox_EnableAllowFlags->isChecked());
setPrefabFilepath ui->lineEdit_PrefabsPath projectConfig.setFloorNumberEnabled(ui->checkBox_EnableFloorNumber->isChecked());
TODO ui->lineEdit_BehaviorMask projectConfig.setUseCustomBorderSize(ui->checkBox_EnableCustomBorderSize->isChecked());
TODO ui->lineEdit_EncounterTypeMask projectConfig.setTilesetsHaveCallback(ui->checkBox_OutputCallback->isChecked());
TODO ui->lineEdit_LayerTypeMask projectConfig.setTilesetsHaveIsCompressed(ui->checkBox_OutputIsCompressed->isChecked());
TODO ui->lineEdit_TerrainTypeMask projectConfig.setNewMapElevation(ui->spinBox_Elevation->value());
setNewMapMetatileId ui->lineEdit_FillMetatile projectConfig.setNewMapMetatileId(ui->spinBox_FillMetatile->value());
setNewMapBorderMetatileIds ui->lineEdit_BorderMetatiles projectConfig.setMetatileBehaviorMask(ui->spinBox_BehaviorMask->value());
*/ projectConfig.setMetatileTerrainTypeMask(ui->spinBox_EncounterTypeMask->value());
projectConfig.setMetatileEncounterTypeMask(ui->spinBox_LayerTypeMask->value());
projectConfig.setMetatileLayerTypeMask(ui->spinBox_TerrainTypeMask->value());
projectConfig.setPrefabFilepath(ui->lineEdit_PrefabsPath->text());
// Parse border metatile list
QList<QString> metatileIdStrings = ui->lineEdit_BorderMetatiles->text().split(",");
QList<uint16_t> metatileIds;
for (auto s : metatileIdStrings) {
uint16_t metatileId = s.toUInt(nullptr, 0);
metatileIds.append(qMin(metatileId, static_cast<uint16_t>(Project::getNumMetatilesTotal() - 1)));
}
projectConfig.setNewMapBorderMetatileIds(metatileIds);
projectConfig.setSaveDisabled(false);
projectConfig.save();
userConfig.setSaveDisabled(false);
userConfig.save();
this->hasUnsavedChanges = false;
emit saved(); emit saved();
} }
// TODO: Standard prompt replacement?
bool ProjectSettingsEditor::prompt(const QString &text) {
QMessageBox messageBox(this);
messageBox.setText(text);
messageBox.setIcon(QMessageBox::Question);
messageBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No); // TODO: Cancel
return messageBox.exec() == QMessageBox::Yes;
}
void ProjectSettingsEditor::dialogButtonClicked(QAbstractButton *button) { void ProjectSettingsEditor::dialogButtonClicked(QAbstractButton *button) {
auto buttonRole = ui->buttonBox->buttonRole(button); auto buttonRole = ui->buttonBox->buttonRole(button);
if (buttonRole == QDialogButtonBox::AcceptRole) { if (buttonRole == QDialogButtonBox::AcceptRole) {
// TODO: Prompt for unsaved changes
saveFields(); saveFields();
close(); close();
} else if (buttonRole == QDialogButtonBox::ResetRole) {
// TODO
} else if (buttonRole == QDialogButtonBox::ApplyRole) { } else if (buttonRole == QDialogButtonBox::ApplyRole) {
saveFields(); saveFields();
} else if (buttonRole == QDialogButtonBox::ResetRole) {
// Restore Defaults
// TODO: Confirm dialogue?
const QString versionText = combo_baseGameVersion->currentText();
if (!prompt(QString("Restore default config settings for %1?").arg(versionText)))
return;
projectConfig.reset(projectConfig.stringToBaseGameVersion(versionText));
projectConfig.save();
userConfig.reset();
userConfig.save();
refresh();
} else if (buttonRole == QDialogButtonBox::RejectRole) { } else if (buttonRole == QDialogButtonBox::RejectRole) {
if (this->hasUnsavedChanges && !prompt(QString("Discard unsaved changes?"))) {
// TODO:
// Unsaved changes prompt
}
close(); close();
} }
// TODO: Save geometry on close // TODO: Save geometry on close

View file

@ -348,8 +348,7 @@ void TilesetEditor::drawSelectedTiles() {
void TilesetEditor::onHoveredMetatileChanged(uint16_t metatileId) { void TilesetEditor::onHoveredMetatileChanged(uint16_t metatileId) {
QString label = Tileset::getMetatileLabel(metatileId, this->primaryTileset, this->secondaryTileset); QString label = Tileset::getMetatileLabel(metatileId, this->primaryTileset, this->secondaryTileset);
QString hexString = QString("%1").arg(metatileId, 3, 16, QChar('0')).toUpper(); QString message = QString("Metatile: %1").arg(Metatile::getMetatileIdString(metatileId));
QString message = QString("Metatile: 0x%1").arg(hexString);
if (label.size() != 0) { if (label.size() != 0) {
message += QString(" \"%1\"").arg(label); message += QString(" \"%1\"").arg(label);
} }