Add prompt to import default prefabs for each game version
This commit is contained in:
parent
a081af85c4
commit
71a34c6b22
8 changed files with 42964 additions and 5 deletions
|
@ -158,6 +158,7 @@ public:
|
||||||
this->createMapTextFile = false;
|
this->createMapTextFile = false;
|
||||||
this->enableTripleLayerMetatiles = false;
|
this->enableTripleLayerMetatiles = false;
|
||||||
this->prefabFilepath = QString();
|
this->prefabFilepath = QString();
|
||||||
|
this->prefabImportPrompted = false;
|
||||||
this->customScripts.clear();
|
this->customScripts.clear();
|
||||||
this->readKeys.clear();
|
this->readKeys.clear();
|
||||||
}
|
}
|
||||||
|
@ -195,7 +196,9 @@ public:
|
||||||
void setCustomScripts(QList<QString> scripts);
|
void setCustomScripts(QList<QString> scripts);
|
||||||
QList<QString> getCustomScripts();
|
QList<QString> getCustomScripts();
|
||||||
void setPrefabFilepath(QString filepath);
|
void setPrefabFilepath(QString filepath);
|
||||||
QString getPrefabFilepath();
|
QString getPrefabFilepath(bool setIfEmpty);
|
||||||
|
void setPrefabImportPrompted(bool prompted);
|
||||||
|
bool getPrefabImportPrompted();
|
||||||
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;
|
||||||
|
@ -221,6 +224,7 @@ private:
|
||||||
QList<QString> customScripts;
|
QList<QString> customScripts;
|
||||||
QStringList readKeys;
|
QStringList readKeys;
|
||||||
QString prefabFilepath;
|
QString prefabFilepath;
|
||||||
|
bool prefabImportPrompted;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern ProjectConfig projectConfig;
|
extern ProjectConfig projectConfig;
|
||||||
|
|
|
@ -23,6 +23,7 @@ public:
|
||||||
void initPrefabUI(MetatileSelector *selector, QWidget *prefabWidget, QLabel *emptyPrefabLabel, Map *map);
|
void initPrefabUI(MetatileSelector *selector, QWidget *prefabWidget, QLabel *emptyPrefabLabel, Map *map);
|
||||||
void addPrefab(MetatileSelection selection, Map *map, QString name);
|
void addPrefab(MetatileSelection selection, Map *map, QString name);
|
||||||
void updatePrefabUi(Map *map);
|
void updatePrefabUi(Map *map);
|
||||||
|
void handlePrefabImport();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
MetatileSelector *selector;
|
MetatileSelector *selector;
|
||||||
|
|
|
@ -3,5 +3,8 @@
|
||||||
<file>text/region_map_default_emerald.json</file>
|
<file>text/region_map_default_emerald.json</file>
|
||||||
<file>text/region_map_default_firered.json</file>
|
<file>text/region_map_default_firered.json</file>
|
||||||
<file>text/region_map_default_ruby.json</file>
|
<file>text/region_map_default_ruby.json</file>
|
||||||
|
<file>text/prefabs_default_emerald.json</file>
|
||||||
|
<file>text/prefabs_default_firered.json</file>
|
||||||
|
<file>text/prefabs_default_ruby.json</file>
|
||||||
</qresource>
|
</qresource>
|
||||||
</RCC>
|
</RCC>
|
||||||
|
|
19429
resources/text/prefabs_default_emerald.json
Normal file
19429
resources/text/prefabs_default_emerald.json
Normal file
File diff suppressed because it is too large
Load diff
11712
resources/text/prefabs_default_firered.json
Normal file
11712
resources/text/prefabs_default_firered.json
Normal file
File diff suppressed because it is too large
Load diff
11732
resources/text/prefabs_default_ruby.json
Normal file
11732
resources/text/prefabs_default_ruby.json
Normal file
File diff suppressed because it is too large
Load diff
|
@ -505,6 +505,8 @@ void ProjectConfig::parseConfigKeyValue(QString key, QString value) {
|
||||||
}
|
}
|
||||||
} else if (key == "prefabs_filepath") {
|
} else if (key == "prefabs_filepath") {
|
||||||
this->prefabFilepath = value;
|
this->prefabFilepath = value;
|
||||||
|
} else if (key == "prefabs_import_prompted") {
|
||||||
|
setConfigBool(key, &this->prefabImportPrompted, value);
|
||||||
} else {
|
} else {
|
||||||
logWarn(QString("Invalid config key found in config file %1: '%2'").arg(this->getConfigFilepath()).arg(key));
|
logWarn(QString("Invalid config key found in config file %1: '%2'").arg(this->getConfigFilepath()).arg(key));
|
||||||
}
|
}
|
||||||
|
@ -543,6 +545,7 @@ QMap<QString, QString> ProjectConfig::getKeyValueMap() {
|
||||||
map.insert("enable_triple_layer_metatiles", QString::number(this->enableTripleLayerMetatiles));
|
map.insert("enable_triple_layer_metatiles", QString::number(this->enableTripleLayerMetatiles));
|
||||||
map.insert("custom_scripts", this->customScripts.join(","));
|
map.insert("custom_scripts", this->customScripts.join(","));
|
||||||
map.insert("prefabs_filepath", this->prefabFilepath);
|
map.insert("prefabs_filepath", this->prefabFilepath);
|
||||||
|
map.insert("prefabs_import_prompted", QString::number(this->prefabImportPrompted));
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -740,13 +743,22 @@ void ProjectConfig::setPrefabFilepath(QString filepath) {
|
||||||
this->save();
|
this->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString ProjectConfig::getPrefabFilepath() {
|
QString ProjectConfig::getPrefabFilepath(bool setIfEmpty) {
|
||||||
if (this->prefabFilepath.isEmpty()) {
|
if (setIfEmpty && this->prefabFilepath.isEmpty()) {
|
||||||
this->setPrefabFilepath("prefabs.json");
|
this->setPrefabFilepath("prefabs.json");
|
||||||
}
|
}
|
||||||
return this->prefabFilepath;
|
return this->prefabFilepath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ProjectConfig::setPrefabImportPrompted(bool prompted) {
|
||||||
|
this->prefabImportPrompted = prompted;
|
||||||
|
this->save();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ProjectConfig::getPrefabImportPrompted() {
|
||||||
|
return this->prefabImportPrompted;
|
||||||
|
}
|
||||||
|
|
||||||
ShortcutsConfig shortcutsConfig;
|
ShortcutsConfig shortcutsConfig;
|
||||||
|
|
||||||
QString ShortcutsConfig::getConfigFilepath() {
|
QString ShortcutsConfig::getConfigFilepath() {
|
||||||
|
|
|
@ -21,7 +21,7 @@ using OrderedJsonDoc = poryjson::JsonDoc;
|
||||||
|
|
||||||
void Prefab::loadPrefabs() {
|
void Prefab::loadPrefabs() {
|
||||||
this->items.clear();
|
this->items.clear();
|
||||||
QString filepath = projectConfig.getPrefabFilepath();
|
QString filepath = projectConfig.getPrefabFilepath(false);
|
||||||
if (filepath.isEmpty()) return;
|
if (filepath.isEmpty()) return;
|
||||||
|
|
||||||
ParseUtil parser;
|
ParseUtil parser;
|
||||||
|
@ -85,7 +85,7 @@ void Prefab::loadPrefabs() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Prefab::savePrefabs() {
|
void Prefab::savePrefabs() {
|
||||||
QString filepath = projectConfig.getPrefabFilepath();
|
QString filepath = projectConfig.getPrefabFilepath(true);
|
||||||
if (filepath.isEmpty()) return;
|
if (filepath.isEmpty()) return;
|
||||||
|
|
||||||
QFileInfo info(filepath);
|
QFileInfo info(filepath);
|
||||||
|
@ -159,6 +159,7 @@ void Prefab::initPrefabUI(MetatileSelector *selector, QWidget *prefabWidget, QLa
|
||||||
this->selector = selector;
|
this->selector = selector;
|
||||||
this->prefabWidget = prefabWidget;
|
this->prefabWidget = prefabWidget;
|
||||||
this->emptyPrefabLabel = emptyPrefabLabel;
|
this->emptyPrefabLabel = emptyPrefabLabel;
|
||||||
|
this->handlePrefabImport();
|
||||||
this->loadPrefabs();
|
this->loadPrefabs();
|
||||||
this->updatePrefabUi(map);
|
this->updatePrefabUi(map);
|
||||||
}
|
}
|
||||||
|
@ -268,4 +269,69 @@ void Prefab::addPrefab(MetatileSelection selection, Map *map, QString name) {
|
||||||
this->updatePrefabUi(map);
|
this->updatePrefabUi(map);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Prefab::handlePrefabImport() {
|
||||||
|
BaseGameVersion version = projectConfig.getBaseGameVersion();
|
||||||
|
// Ensure we have default prefabs for the project's game version.
|
||||||
|
if (version != BaseGameVersion::pokeruby && version != BaseGameVersion::pokeemerald && version != BaseGameVersion::pokefirered)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// Exit early if the user has already setup prefabs.
|
||||||
|
if (!projectConfig.getPrefabFilepath(false).isEmpty())
|
||||||
|
return;
|
||||||
|
|
||||||
|
// Exit early if the user has already gone through this import prompt before.
|
||||||
|
if (projectConfig.getPrefabImportPrompted())
|
||||||
|
return;
|
||||||
|
|
||||||
|
// Display a dialog box to the user, asking if the default prefabs should be imported
|
||||||
|
// into their project.
|
||||||
|
QMessageBox::StandardButton prompt =
|
||||||
|
QMessageBox::question(nullptr,
|
||||||
|
"Import Default Prefabs",
|
||||||
|
QString("Would you like to import the default prefabs for %1? This will create a file called 'prefabs.json' in your project directory.")
|
||||||
|
.arg(projectConfig.getBaseGameVersionString()),
|
||||||
|
QMessageBox::Yes | QMessageBox::No);
|
||||||
|
|
||||||
|
if (prompt == QMessageBox::Yes) {
|
||||||
|
// Sets up the default prefabs.json filepath.
|
||||||
|
QString filepath = projectConfig.getPrefabFilepath(true);
|
||||||
|
|
||||||
|
QFileInfo info(filepath);
|
||||||
|
if (info.isRelative()) {
|
||||||
|
filepath = QDir::cleanPath(projectConfig.getProjectDir() + QDir::separator() + filepath);
|
||||||
|
}
|
||||||
|
QFile prefabsFile(filepath);
|
||||||
|
if (!prefabsFile.open(QIODevice::WriteOnly)) {
|
||||||
|
projectConfig.setPrefabFilepath(QString());
|
||||||
|
|
||||||
|
logError(QString("Error: Could not open %1 for writing").arg(filepath));
|
||||||
|
QMessageBox messageBox;
|
||||||
|
messageBox.setText("Failed to import default prefabs file!");
|
||||||
|
messageBox.setInformativeText(QString("Could not open \"%1\" for writing").arg(filepath));
|
||||||
|
messageBox.setIcon(QMessageBox::Warning);
|
||||||
|
messageBox.exec();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ParseUtil parser;
|
||||||
|
QString content;
|
||||||
|
switch (version) {
|
||||||
|
case BaseGameVersion::pokeruby:
|
||||||
|
content = parser.readTextFile(":/text/prefabs_default_ruby.json");
|
||||||
|
break;
|
||||||
|
case BaseGameVersion::pokefirered:
|
||||||
|
content = parser.readTextFile(":/text/prefabs_default_firered.json");
|
||||||
|
break;
|
||||||
|
case BaseGameVersion::pokeemerald:
|
||||||
|
content = parser.readTextFile(":/text/prefabs_default_emerald.json");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
prefabsFile.write(content.toUtf8());
|
||||||
|
prefabsFile.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
projectConfig.setPrefabImportPrompted(true);
|
||||||
|
}
|
||||||
|
|
||||||
Prefab prefab;
|
Prefab prefab;
|
||||||
|
|
Loading…
Reference in a new issue