Add identifiers to the settings window

This commit is contained in:
GriffinR 2023-12-18 21:07:36 -05:00
parent 6d995cee9b
commit b74b007186
5 changed files with 144 additions and 28 deletions

View file

@ -1351,9 +1351,9 @@
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_ProjectFiles">
<widget class="QWidget" name="tab_Files">
<attribute name="title">
<string>Project Files</string>
<string>Files</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_9">
<item>
@ -1372,9 +1372,9 @@
</property>
<layout class="QVBoxLayout" name="verticalLayout_10">
<item>
<widget class="QLabel" name="label_ProjectFiles">
<widget class="QLabel" name="label_ProjectFilesHelp">
<property name="text">
<string> &lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;a href=&quot;https://huderlem.github.io/porymap/manual/project-files.html&quot;&gt;&lt;span style=&quot; text-decoration: underline;&quot;&gt;What are Project Files?&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
<string> &lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;a href=&quot;https://huderlem.github.io/porymap/manual/project-files.html&quot;&gt;&lt;span style=&quot; text-decoration: underline;&quot;&gt;Help&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="textFormat">
<enum>Qt::RichText</enum>
@ -1445,6 +1445,100 @@
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_Identifiers">
<attribute name="title">
<string>Identifiers</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_21">
<item>
<widget class="QScrollArea" name="scrollArea_IdentifiersTab">
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents_IdentifiersTab">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>559</width>
<height>490</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_19">
<item>
<widget class="QLabel" name="label_IdentifiersHelp">
<property name="text">
<string> &lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;a href=&quot;https://huderlem.github.io/porymap/manual/project-files.html&quot;&gt;&lt;span style=&quot; text-decoration: underline;&quot;&gt;Help&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="textFormat">
<enum>Qt::RichText</enum>
</property>
<property name="alignment">
<set>Qt::AlignBottom|Qt::AlignLeading|Qt::AlignLeft</set>
</property>
<property name="openExternalLinks">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QWidget" name="widget_Identifiers" native="true">
<layout class="QVBoxLayout" name="verticalLayout_20">
<property name="spacing">
<number>2</number>
</property>
<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="QScrollArea" name="scrollArea_Identifiers">
<property name="lineWidth">
<number>2</number>
</property>
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="scrollAreaContents_Identifiers">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>533</width>
<height>440</height>
</rect>
</property>
<layout class="QFormLayout" name="layout_Identifiers">
<property name="verticalSpacing">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>4</number>
</property>
</layout>
</widget>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
<item>

View file

@ -309,7 +309,7 @@ public:
this->readKeys.clear();
}
static const QMap<ProjectIdentifier, QPair<QString, QString>> defaultIdentifiers;
static const QMap<ProjectFilePath, std::pair<QString, QString>> defaultPaths;
static const QMap<ProjectFilePath, QPair<QString, QString>> defaultPaths;
static const QStringList versionStrings;
void reset(BaseGameVersion baseGameVersion);
void setBaseGameVersion(BaseGameVersion baseGameVersion);

View file

@ -52,7 +52,9 @@ private:
void setBorderMetatileIds(bool customSize, QList<uint16_t> metatileIds);
QList<uint16_t> getBorderMetatileIds(bool customSize);
void createConfigTextTable(const QList<QPair<QString, QString>> configPairs, bool filesTab);
void createProjectPathsTable();
void createProjectIdentifiersTable();
QString chooseProjectFile(const QString &defaultFilepath);
void choosePrefabsFile();
void chooseImageFile(QLineEdit * filepathEdit);

View file

@ -106,7 +106,7 @@ const QMap<ProjectIdentifier, QPair<QString, QString>> ProjectConfig::defaultIde
{ProjectIdentifier::regex_species, {"regex_species", "\\bSPECIES_"}},
};
const QMap<ProjectFilePath, std::pair<QString, QString>> ProjectConfig::defaultPaths = {
const QMap<ProjectFilePath, QPair<QString, QString>> ProjectConfig::defaultPaths = {
{ProjectFilePath::data_map_folders, { "data_map_folders", "data/maps/"}},
{ProjectFilePath::data_scripts_folders, { "data_scripts_folders", "data/scripts/"}},
{ProjectFilePath::data_layouts_folders, { "data_layouts_folders", "data/layouts/"}},

View file

@ -22,6 +22,7 @@ ProjectSettingsEditor::ProjectSettingsEditor(QWidget *parent, Project *project)
setAttribute(Qt::WA_DeleteOnClose);
this->initUi();
this->createProjectPathsTable();
this->createProjectIdentifiersTable();
this->connectSignals();
this->refresh();
this->restoreWindowState();
@ -326,40 +327,56 @@ void ProjectSettingsEditor::updateWarpBehaviorsList(bool adding) {
this->hasUnsavedChanges = true;
}
void ProjectSettingsEditor::createProjectPathsTable() {
auto pathPairs = ProjectConfig::defaultPaths.values();
for (auto pathPair : pathPairs) {
// Name of the path
// Dynamically populate the tabs for project files and identifiers
void ProjectSettingsEditor::createConfigTextTable(const QList<QPair<QString, QString>> configPairs, bool filesTab) {
for (auto pair : configPairs) {
const QString idName = pair.first;
const QString defaultText = pair.second;
auto name = new QLabel();
name->setAlignment(Qt::AlignBottom);
name->setText(pathPair.first);
name->setText(idName);
// Filepath line edit
auto lineEdit = new QLineEdit();
lineEdit->setObjectName(pathPair.first); // Used when saving the paths
lineEdit->setPlaceholderText(pathPair.second);
lineEdit->setObjectName(idName); // Used when saving
lineEdit->setPlaceholderText(defaultText);
lineEdit->setClearButtonEnabled(true);
// "Choose file" button
auto button = new QToolButton();
button->setIcon(QIcon(":/icons/folder.ico"));
connect(button, &QAbstractButton::clicked, [this, lineEdit](bool) {
const QString path = this->chooseProjectFile(lineEdit->placeholderText());
if (!path.isEmpty()) {
lineEdit->setText(path);
this->markEdited();
}
});
// Add to list
auto editArea = new QWidget();
auto layout = new QHBoxLayout(editArea);
layout->addWidget(lineEdit);
layout->addWidget(button);
ui->layout_ProjectPaths->addRow(name, editArea);
if (filesTab) {
// "Choose file" button
auto button = new QToolButton();
button->setIcon(QIcon(":/icons/folder.ico"));
connect(button, &QAbstractButton::clicked, [this, lineEdit](bool) {
const QString path = this->chooseProjectFile(lineEdit->placeholderText());
if (!path.isEmpty()) {
lineEdit->setText(path);
this->markEdited();
}
});
layout->addWidget(button);
ui->layout_ProjectPaths->addRow(name, editArea);
} else {
ui->layout_Identifiers->addRow(name, editArea);
}
}
}
void ProjectSettingsEditor::createProjectPathsTable() {
auto pairs = ProjectConfig::defaultPaths.values();
this->createConfigTextTable(pairs, true);
}
void ProjectSettingsEditor::createProjectIdentifiersTable() {
auto pairs = ProjectConfig::defaultIdentifiers.values();
this->createConfigTextTable(pairs, false);
}
QString ProjectSettingsEditor::chooseProjectFile(const QString &defaultFilepath) {
const QString startDir = this->baseDir + defaultFilepath;
@ -451,6 +468,8 @@ void ProjectSettingsEditor::refresh() {
ui->lineEdit_HealspotsIcon->setText(projectConfig.getEventIconPath(Event::Group::Heal));
for (auto lineEdit : ui->scrollAreaContents_ProjectPaths->findChildren<QLineEdit*>())
lineEdit->setText(projectConfig.getCustomFilePath(lineEdit->objectName()));
for (auto lineEdit : ui->scrollAreaContents_Identifiers->findChildren<QLineEdit*>())
lineEdit->setText(projectConfig.getCustomIdentifier(lineEdit->objectName()));
this->setWarpBehaviorsList(projectConfig.getWarpBehaviors());
this->refreshing = false; // Allow signals
@ -511,7 +530,8 @@ void ProjectSettingsEditor::save() {
projectConfig.setEventIconPath(Event::Group::Heal, ui->lineEdit_HealspotsIcon->text());
for (auto lineEdit : ui->scrollAreaContents_ProjectPaths->findChildren<QLineEdit*>())
projectConfig.setFilePath(lineEdit->objectName(), lineEdit->text());
for (auto lineEdit : ui->scrollAreaContents_Identifiers->findChildren<QLineEdit*>())
projectConfig.setIdentifier(lineEdit->objectName(), lineEdit->text());
projectConfig.setWarpBehaviors(this->getWarpBehaviorsList());
// Save border metatile IDs