Save map list settings in config

This commit is contained in:
GriffinR
2025-03-16 17:53:09 -04:00
parent 4b8bbe9400
commit 854880f9f8
6 changed files with 85 additions and 35 deletions

View File

@@ -52,6 +52,8 @@ public:
this->projectManuallyClosed = false;
this->reopenOnLaunch = true;
this->mapListTab = 0;
this->mapListEditGroupsEnabled = false;
this->mapListHideEmptyEnabled.clear();
this->prettyCursors = true;
this->mirrorConnectingMaps = true;
this->showDiveEmergeMaps = false;
@@ -110,6 +112,8 @@ public:
bool reopenOnLaunch;
bool projectManuallyClosed;
int mapListTab;
bool mapListEditGroupsEnabled;
QMap<int, bool> mapListHideEmptyEnabled;
bool prettyCursors;
bool mirrorConnectingMaps;
bool showDiveEmergeMaps;

View File

@@ -423,6 +423,7 @@ private:
double getMetatilesZoomScale();
void redrawMetatileSelection();
void scrollMetatileSelectorToSelection();
MapListToolBar* getMapListToolBar(int tab);
MapListToolBar* getCurrentMapListToolBar();
MapTree* getCurrentMapList();
void setLocationComboBoxes(const QStringList &locations);

View File

@@ -42,6 +42,8 @@ public:
signals:
void filterCleared(MapTree*);
void addFolderClicked();
void editsAllowedChanged(bool allowed);
void emptyFoldersVisibleChanged(bool visible);
private:
Ui::MapListToolBar *ui;

View File

@@ -304,6 +304,16 @@ void PorymapConfig::parseConfigKeyValue(QString key, QString value) {
this->prettyCursors = getConfigBool(key, value);
} else if (key == "map_list_tab") {
this->mapListTab = getConfigInteger(key, value, 0, 2, 0);
} else if (key == "map_list_edit_groups_enabled") {
this->mapListEditGroupsEnabled = getConfigBool(key, value);
} else if (key.startsWith("map_list_hide_empty_enabled/")) {
bool ok;
int tab = key.mid(QStringLiteral("map_list_hide_empty_enabled/").length()).toInt(&ok, 0);
if (!ok) {
logWarn(QString("Invalid config key found in config file %1: '%2'").arg(this->getConfigFilepath()).arg(key));
return;
}
this->mapListHideEmptyEnabled.insert(tab, getConfigBool(key, value));
} else if (key == "main_window_geometry") {
this->mainWindowGeometry = bytesFromString(value);
} else if (key == "main_window_state") {
@@ -445,6 +455,10 @@ QMap<QString, QString> PorymapConfig::getKeyValueMap() {
map.insert("reopen_on_launch", this->reopenOnLaunch ? "1" : "0");
map.insert("pretty_cursors", this->prettyCursors ? "1" : "0");
map.insert("map_list_tab", QString::number(this->mapListTab));
map.insert("map_list_edit_groups_enabled", this->mapListEditGroupsEnabled ? "1" : "0");
for (auto i = this->mapListHideEmptyEnabled.constBegin(); i != this->mapListHideEmptyEnabled.constEnd(); i++) {
map.insert(QStringLiteral("map_list_hide_empty_enabled/") + QString::number(i.key()), i.value() ? "1" : "0");
}
map.insert("main_window_geometry", stringFromByteArray(this->mainWindowGeometry));
map.insert("main_window_state", stringFromByteArray(this->mainWindowState));
map.insert("map_splitter_state", stringFromByteArray(this->mapSplitterState));
@@ -769,14 +783,14 @@ void ProjectConfig::parseConfigKeyValue(QString key, QString value) {
userConfig.parseCustomScripts(value);
#endif
} else if (key.startsWith("path/")) {
auto k = reverseDefaultPaths(key.mid(5));
auto k = reverseDefaultPaths(key.mid(QStringLiteral("path/").length()));
if (k != static_cast<ProjectFilePath>(-1)) {
this->setFilePath(k, value);
} else {
logWarn(QString("Invalid config key found in config file %1: '%2'").arg(this->getConfigFilepath()).arg(key));
}
} else if (key.startsWith("ident/")) {
auto identifierId = reverseDefaultIdentifier(key.mid(6));
auto identifierId = reverseDefaultIdentifier(key.mid(QStringLiteral("ident/").length()));
if (identifierId != static_cast<ProjectIdentifier>(-1)) {
this->setIdentifier(identifierId, value);
} else {
@@ -803,7 +817,7 @@ void ProjectConfig::parseConfigKeyValue(QString key, QString value) {
} else if (key == "event_icon_path_heal") {
this->eventIconPaths[Event::Group::Heal] = value;
} else if (key.startsWith("pokemon_icon_path/")) {
this->pokemonIconPaths.insert(key.mid(18).toUpper(), value);
this->pokemonIconPaths.insert(key.mid(QStringLiteral("pokemon_icon_path/").length()).toUpper(), value);
} else if (key == "collision_sheet_path") {
this->collisionSheetPath = value;
} else if (key == "collision_sheet_width") {

View File

@@ -449,6 +449,27 @@ void MainWindow::initMapList() {
ui->mapListToolBar_Locations->setEditsAllowedButtonVisible(false);
ui->mapListToolBar_Layouts->setEditsAllowedButtonVisible(false);
// Initialize settings from config
ui->mapListToolBar_Groups->setEditsAllowed(porymapConfig.mapListEditGroupsEnabled);
for (auto i = porymapConfig.mapListHideEmptyEnabled.constBegin(); i != porymapConfig.mapListHideEmptyEnabled.constEnd(); i++) {
auto toolbar = getMapListToolBar(i.key());
if (toolbar) toolbar->setEmptyFoldersVisible(!i.value());
}
// Update config if map list settings change
connect(ui->mapListToolBar_Groups, &MapListToolBar::editsAllowedChanged, [](bool allowed) {
porymapConfig.mapListEditGroupsEnabled = allowed;
});
connect(ui->mapListToolBar_Groups, &MapListToolBar::emptyFoldersVisibleChanged, [](bool visible) {
porymapConfig.mapListHideEmptyEnabled[MapListTab::Groups] = !visible;
});
connect(ui->mapListToolBar_Locations, &MapListToolBar::emptyFoldersVisibleChanged, [](bool visible) {
porymapConfig.mapListHideEmptyEnabled[MapListTab::Locations] = !visible;
});
connect(ui->mapListToolBar_Layouts, &MapListToolBar::emptyFoldersVisibleChanged, [](bool visible) {
porymapConfig.mapListHideEmptyEnabled[MapListTab::Layouts] = !visible;
});
// When map list search filter is cleared we want the current map/layout in the editor to be visible in the list.
connect(ui->mapListToolBar_Groups, &MapListToolBar::filterCleared, this, &MainWindow::scrollMapListToCurrentMap);
connect(ui->mapListToolBar_Locations, &MapListToolBar::filterCleared, this, &MainWindow::scrollMapListToCurrentMap);
@@ -1149,7 +1170,8 @@ bool MainWindow::setProjectUI() {
// map models
this->mapGroupModel = new MapGroupModel(editor->project);
this->groupListProxyModel = new FilterChildrenProxyModel();
groupListProxyModel->setSourceModel(this->mapGroupModel);
this->groupListProxyModel->setSourceModel(this->mapGroupModel);
this->groupListProxyModel->setHideEmpty(porymapConfig.mapListHideEmptyEnabled[MapListTab::Groups]);
ui->mapList->setModel(groupListProxyModel);
this->ui->mapList->setItemDelegateForColumn(0, new GroupNameDelegate(this->editor->project, this));
@@ -1157,13 +1179,16 @@ bool MainWindow::setProjectUI() {
this->mapLocationModel = new MapLocationModel(editor->project);
this->locationListProxyModel = new FilterChildrenProxyModel();
locationListProxyModel->setSourceModel(this->mapLocationModel);
this->locationListProxyModel->setSourceModel(this->mapLocationModel);
this->locationListProxyModel->setHideEmpty(porymapConfig.mapListHideEmptyEnabled[MapListTab::Locations]);
ui->locationList->setModel(locationListProxyModel);
ui->locationList->sortByColumn(0, Qt::SortOrder::AscendingOrder);
this->layoutTreeModel = new LayoutTreeModel(editor->project);
this->layoutListProxyModel = new FilterChildrenProxyModel();
this->layoutListProxyModel->setSourceModel(this->layoutTreeModel);
this->layoutListProxyModel->setHideEmpty(porymapConfig.mapListHideEmptyEnabled[MapListTab::Layouts]);
ui->layoutList->setModel(layoutListProxyModel);
ui->layoutList->sortByColumn(0, Qt::SortOrder::AscendingOrder);
@@ -2708,8 +2733,8 @@ void MainWindow::initTilesetEditor() {
connect(this->tilesetEditor, &TilesetEditor::tilesetsSaved, this, &MainWindow::onTilesetsSaved);
}
MapListToolBar* MainWindow::getCurrentMapListToolBar() {
switch (ui->mapListContainer->currentIndex()) {
MapListToolBar* MainWindow::getMapListToolBar(int tab) {
switch (tab) {
case MapListTab::Groups: return ui->mapListToolBar_Groups;
case MapListTab::Locations: return ui->mapListToolBar_Locations;
case MapListTab::Layouts: return ui->mapListToolBar_Layouts;
@@ -2717,6 +2742,10 @@ MapListToolBar* MainWindow::getCurrentMapListToolBar() {
}
}
MapListToolBar* MainWindow::getCurrentMapListToolBar() {
return getMapListToolBar(ui->mapListContainer->currentIndex());
}
MapTree* MainWindow::getCurrentMapList() {
auto toolbar = getCurrentMapListToolBar();
if (toolbar)

View File

@@ -4,11 +4,6 @@
#include <QToolTip>
/*
TODO: The button states for each tool bar (just the two toggleable buttons, hide empty folders and allow editing)
should be saved in the config. This will be cleaner/easier once the config is JSON, so holding off on that for now.
*/
MapListToolBar::MapListToolBar(QWidget *parent)
: QFrame(parent)
, ui(new Ui::MapListToolBar)
@@ -18,7 +13,7 @@ MapListToolBar::MapListToolBar(QWidget *parent)
ui->button_ToggleEmptyFolders->setChecked(!m_emptyFoldersVisible);
ui->button_ToggleEdit->setChecked(m_editsAllowed);
connect(ui->button_AddFolder, &QAbstractButton::clicked, this, &MapListToolBar::addFolderClicked); // TODO: Tool tip
connect(ui->button_AddFolder, &QAbstractButton::clicked, this, &MapListToolBar::addFolderClicked);
connect(ui->button_ExpandAll, &QAbstractButton::clicked, this, &MapListToolBar::expandList);
connect(ui->button_CollapseAll, &QAbstractButton::clicked, this, &MapListToolBar::collapseList);
connect(ui->button_ToggleEdit, &QAbstractButton::clicked, this, &MapListToolBar::toggleEditsAllowed);
@@ -57,28 +52,30 @@ void MapListToolBar::toggleEditsAllowed() {
}
void MapListToolBar::setEditsAllowed(bool allowed) {
m_editsAllowed = allowed;
if (m_list) {
if (allowed) {
m_list->setSelectionMode(QAbstractItemView::ExtendedSelection);
m_list->setDragEnabled(true);
m_list->setAcceptDrops(true);
m_list->setDropIndicatorShown(true);
m_list->setDragDropMode(QAbstractItemView::InternalMove);
m_list->setEditTriggers(QAbstractItemView::DoubleClicked | QAbstractItemView::EditKeyPressed);
} else {
m_list->setSelectionMode(QAbstractItemView::NoSelection);
m_list->setDragEnabled(false);
m_list->setAcceptDrops(false);
m_list->setDropIndicatorShown(false);
m_list->setDragDropMode(QAbstractItemView::NoDragDrop);
m_list->setEditTriggers(QAbstractItemView::NoEditTriggers);
}
}
const QSignalBlocker b(ui->button_ToggleEdit);
ui->button_ToggleEdit->setChecked(allowed);
const QSignalBlocker b(ui->button_ToggleEdit);
ui->button_ToggleEdit->setChecked(allowed);
if (!m_list)
return;
if (allowed) {
m_list->setSelectionMode(QAbstractItemView::ExtendedSelection);
m_list->setDragEnabled(true);
m_list->setAcceptDrops(true);
m_list->setDropIndicatorShown(true);
m_list->setDragDropMode(QAbstractItemView::InternalMove);
m_list->setEditTriggers(QAbstractItemView::DoubleClicked | QAbstractItemView::EditKeyPressed);
} else {
m_list->setSelectionMode(QAbstractItemView::NoSelection);
m_list->setDragEnabled(false);
m_list->setAcceptDrops(false);
m_list->setDropIndicatorShown(false);
m_list->setDragDropMode(QAbstractItemView::NoDragDrop);
m_list->setEditTriggers(QAbstractItemView::NoEditTriggers);
if (m_editsAllowed != allowed) {
m_editsAllowed = allowed;
emit editsAllowedChanged(allowed);
}
}
@@ -87,8 +84,6 @@ void MapListToolBar::toggleEmptyFolders() {
}
void MapListToolBar::setEmptyFoldersVisible(bool visible) {
m_emptyFoldersVisible = visible;
if (m_list) {
auto model = static_cast<FilterChildrenProxyModel*>(m_list->model());
if (model) {
@@ -103,6 +98,11 @@ void MapListToolBar::setEmptyFoldersVisible(bool visible) {
const QSignalBlocker b(ui->button_ToggleEmptyFolders);
ui->button_ToggleEmptyFolders->setChecked(!visible);
if (m_emptyFoldersVisible != visible) {
m_emptyFoldersVisible = visible;
emit emptyFoldersVisibleChanged(visible);
}
}
void MapListToolBar::expandList() {