Merge pull request #302 from garakmon/fix827

Should Fix Project Open?
This commit is contained in:
huderlem 2020-12-14 18:16:33 -06:00 committed by GitHub
commit 53b9fa5dc7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
29 changed files with 63 additions and 26 deletions

View file

@ -1,3 +1,4 @@
#pragma once
#ifndef CONFIG_H #ifndef CONFIG_H
#define CONFIG_H #define CONFIG_H

View file

@ -1,3 +1,4 @@
#pragma once
#ifndef BLOCK_H #ifndef BLOCK_H
#define BLOCK_H #define BLOCK_H

View file

@ -1,3 +1,4 @@
#pragma once
#ifndef BLOCKDATA_H #ifndef BLOCKDATA_H
#define BLOCKDATA_H #define BLOCKDATA_H

View file

@ -1,3 +1,4 @@
#pragma once
#ifndef EDITCOMMANDS_H #ifndef EDITCOMMANDS_H
#define EDITCOMMANDS_H #define EDITCOMMANDS_H

View file

@ -1,3 +1,4 @@
#pragma once
#ifndef EVENT_H #ifndef EVENT_H
#define EVENT_H #define EVENT_H

View file

@ -1,3 +1,4 @@
#pragma once
#ifndef HEALLOCATION_H #ifndef HEALLOCATION_H
#define HEALLOCATION_H #define HEALLOCATION_H

View file

@ -1,3 +1,4 @@
#pragma once
#ifndef HISTORY_H #ifndef HISTORY_H
#define HISTORY_H #define HISTORY_H

View file

@ -1,3 +1,4 @@
#pragma once
#ifndef IMAGEEXPORT_H #ifndef IMAGEEXPORT_H
#define IMAGEEXPORT_H #define IMAGEEXPORT_H

View file

@ -1,3 +1,4 @@
#pragma once
#ifndef MAP_H #ifndef MAP_H
#define MAP_H #define MAP_H

View file

@ -1,3 +1,4 @@
#pragma once
#ifndef MAPCONNECTION_H #ifndef MAPCONNECTION_H
#define MAPCONNECTION_H #define MAPCONNECTION_H

View file

@ -1,3 +1,4 @@
#pragma once
#ifndef MAPLAYOUT_H #ifndef MAPLAYOUT_H
#define MAPLAYOUT_H #define MAPLAYOUT_H

View file

@ -1,3 +1,4 @@
#pragma once
#ifndef METATILE_H #ifndef METATILE_H
#define METATILE_H #define METATILE_H

View file

@ -1,3 +1,4 @@
#pragma once
#ifndef METATILEPARSER_H #ifndef METATILEPARSER_H
#define METATILEPARSER_H #define METATILEPARSER_H

View file

@ -1,3 +1,4 @@
#pragma once
#ifndef PALETTEUTIL_H #ifndef PALETTEUTIL_H
#define PALETTEUTIL_H #define PALETTEUTIL_H

View file

@ -1,3 +1,4 @@
#pragma once
#ifndef PARSEUTIL_H #ifndef PARSEUTIL_H
#define PARSEUTIL_H #define PARSEUTIL_H

View file

@ -1,3 +1,4 @@
#pragma once
#ifndef REGIONMAP_H #ifndef REGIONMAP_H
#define REGIONMAP_H #define REGIONMAP_H

View file

@ -1,3 +1,4 @@
#pragma once
#ifndef TILE_H #ifndef TILE_H
#define TILE_H #define TILE_H

View file

@ -1,3 +1,4 @@
#pragma once
#ifndef TILESET_H #ifndef TILESET_H
#define TILESET_H #define TILESET_H

View file

@ -1,3 +1,4 @@
#pragma once
#ifndef GUARD_WILDMONINFO_H #ifndef GUARD_WILDMONINFO_H
#define GUARD_WILDMONINFO_H #define GUARD_WILDMONINFO_H

View file

@ -1,3 +1,4 @@
#pragma once
#ifndef EDITOR_H #ifndef EDITOR_H
#define EDITOR_H #define EDITOR_H

View file

@ -52,6 +52,8 @@
*/ */
#pragma once #pragma once
#ifndef ORDERED_JSON_H
#define ORDERED_JSON_H
#include <QString> #include <QString>
#include <QVector> #include <QVector>
@ -240,3 +242,4 @@ protected:
} // namespace poryjson } // namespace poryjson
#endif // ORDERED_JSON_H

View file

@ -21,6 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE. * SOFTWARE.
*/ */
#pragma once
#ifndef TSL_ORDERED_MAP_H #ifndef TSL_ORDERED_MAP_H
#define TSL_ORDERED_MAP_H #define TSL_ORDERED_MAP_H

View file

@ -1,3 +1,4 @@
#pragma once
#ifndef QSTRINGHASH_H #ifndef QSTRINGHASH_H
#define QSTRINGHASH_H #define QSTRINGHASH_H

View file

@ -1,3 +1,4 @@
#pragma once
#ifndef LOG_H #ifndef LOG_H
#define LOG_H #define LOG_H

View file

@ -1,3 +1,4 @@
#pragma once
#ifndef MAINWINDOW_H #ifndef MAINWINDOW_H
#define MAINWINDOW_H #define MAINWINDOW_H
@ -271,6 +272,7 @@ private:
bool isProgrammaticEventTabChange; bool isProgrammaticEventTabChange;
bool projectHasUnsavedChanges; bool projectHasUnsavedChanges;
bool projectOpenFailure = false;
MapSortOrder mapSortOrder; MapSortOrder mapSortOrder;

View file

@ -1,3 +1,4 @@
#pragma once
#ifndef PROJECT_H #ifndef PROJECT_H
#define PROJECT_H #define PROJECT_H

View file

@ -1,3 +1,4 @@
#pragma once
#ifndef SCRIPTING_H #ifndef SCRIPTING_H
#define SCRIPTING_H #define SCRIPTING_H

View file

@ -1,3 +1,4 @@
#pragma once
#ifndef SETTINGS_H #ifndef SETTINGS_H
#define SETTINGS_H #define SETTINGS_H

View file

@ -58,10 +58,11 @@ MainWindow::MainWindow(QWidget *parent) :
this->initWindow(); this->initWindow();
if (!this->openRecentProject()) { if (!this->openRecentProject()) {
// Re-initialize everything to a blank slate if opening the recent project failed. setWindowDisabled(true);
this->initWindow(); } else {
setWindowDisabled(false);
on_toolButton_Paint_clicked();
} }
on_toolButton_Paint_clicked();
} }
MainWindow::~MainWindow() MainWindow::~MainWindow()
@ -173,6 +174,7 @@ void MainWindow::applyUserShortcuts() {
void MainWindow::initCustomUI() { void MainWindow::initCustomUI() {
// Set up the tab bar // Set up the tab bar
while (ui->mainTabBar->count()) ui->mainTabBar->removeTab(0);
ui->mainTabBar->addTab("Map"); ui->mainTabBar->addTab("Map");
ui->mainTabBar->setTabIcon(0, QIcon(QStringLiteral(":/icons/map.ico"))); ui->mainTabBar->setTabIcon(0, QIcon(QStringLiteral(":/icons/map.ico")));
ui->mainTabBar->addTab("Events"); ui->mainTabBar->addTab("Events");
@ -180,12 +182,19 @@ void MainWindow::initCustomUI() {
ui->mainTabBar->addTab("Connections"); ui->mainTabBar->addTab("Connections");
ui->mainTabBar->addTab("Wild Pokemon"); ui->mainTabBar->addTab("Wild Pokemon");
ui->mainTabBar->setTabIcon(4, QIcon(QStringLiteral(":/icons/tall_grass.ico"))); ui->mainTabBar->setTabIcon(4, QIcon(QStringLiteral(":/icons/tall_grass.ico")));
}
void MainWindow::initExtraSignals() {
// Right-clicking on items in the map list tree view brings up a context menu. // Right-clicking on items in the map list tree view brings up a context menu.
ui->mapList->setContextMenuPolicy(Qt::CustomContextMenu); ui->mapList->setContextMenuPolicy(Qt::CustomContextMenu);
connect(ui->mapList, SIGNAL(customContextMenuRequested(const QPoint &)), connect(ui->mapList, SIGNAL(customContextMenuRequested(const QPoint &)),
this, SLOT(onOpenMapListContextMenu(const QPoint &))); this, SLOT(onOpenMapListContextMenu(const QPoint &)));
// other signals
connect(ui->newEventToolButton, SIGNAL(newEventAdded(QString)), this, SLOT(addNewEvent(QString)));
connect(ui->tabWidget_EventType, &QTabWidget::currentChanged, this, &MainWindow::eventTabChanged);
// Change pages on wild encounter groups
QStackedWidget *stack = ui->stackedWidget_WildMons; QStackedWidget *stack = ui->stackedWidget_WildMons;
QComboBox *labelCombo = ui->comboBox_EncounterGroupLabel; QComboBox *labelCombo = ui->comboBox_EncounterGroupLabel;
connect(labelCombo, QOverload<int>::of(&QComboBox::currentIndexChanged), [=](int index){ connect(labelCombo, QOverload<int>::of(&QComboBox::currentIndexChanged), [=](int index){
@ -217,11 +226,6 @@ void MainWindow::initCustomUI() {
label_MapRulerStatus->setTextInteractionFlags(Qt::TextSelectableByMouse); label_MapRulerStatus->setTextInteractionFlags(Qt::TextSelectableByMouse);
} }
void MainWindow::initExtraSignals() {
connect(ui->newEventToolButton, SIGNAL(newEventAdded(QString)), this, SLOT(addNewEvent(QString)));
connect(ui->tabWidget_EventType, &QTabWidget::currentChanged, this, &MainWindow::eventTabChanged);
}
void MainWindow::initEditor() { void MainWindow::initEditor() {
this->editor = new Editor(ui); this->editor = new Editor(ui);
connect(this->editor, SIGNAL(objectsChanged()), this, SLOT(updateObjects())); connect(this->editor, SIGNAL(objectsChanged()), this, SLOT(updateObjects()));
@ -461,11 +465,12 @@ bool MainWindow::openRecentProject() {
return openProject(default_dir); return openProject(default_dir);
} }
return true; return false;
} }
bool MainWindow::openProject(QString dir) { bool MainWindow::openProject(QString dir) {
if (dir.isNull()) { if (dir.isNull()) {
projectOpenFailure = true;
return false; return false;
} }
@ -522,13 +527,12 @@ bool MainWindow::openProject(QString dir) {
Scripting::cb_ProjectOpened(dir); Scripting::cb_ProjectOpened(dir);
} }
setWindowDisabled(false); projectOpenFailure = !success;
return success; return success;
} }
bool MainWindow::isProjectOpen() { bool MainWindow::isProjectOpen() {
return editor != nullptr && editor->project != nullptr; return !projectOpenFailure && editor && editor->project;
} }
QString MainWindow::getDefaultMap() { QString MainWindow::getDefaultMap() {
@ -572,9 +576,7 @@ void MainWindow::on_action_Open_Project_triggered()
this->ui->graphicsView_Map->overlay.clearItems(); this->ui->graphicsView_Map->overlay.clearItems();
} }
porymapConfig.setRecentProject(dir); porymapConfig.setRecentProject(dir);
if (!openProject(dir)) { setWindowDisabled(!openProject(dir));
this->initWindow();
}
} }
} }
@ -1556,6 +1558,7 @@ void MainWindow::addNewEvent(QString event_type)
if (editor && editor->project) { if (editor && editor->project) {
DraggablePixmapItem *object = editor->addNewEvent(event_type); DraggablePixmapItem *object = editor->addNewEvent(event_type);
if (object) { if (object) {
updateObjects();
editor->selectMapEvent(object, false); editor->selectMapEvent(object, false);
} else { } else {
QMessageBox msgBox(this); QMessageBox msgBox(this);
@ -2827,19 +2830,22 @@ void MainWindow::closeSupplementaryWindows() {
} }
void MainWindow::closeEvent(QCloseEvent *event) { void MainWindow::closeEvent(QCloseEvent *event) {
if (projectHasUnsavedChanges || (editor->map && editor->map->hasUnsavedChanges())) { if (isProjectOpen()) {
QMessageBox::StandardButton result = QMessageBox::question( if (projectHasUnsavedChanges || (editor->map && editor->map->hasUnsavedChanges())) {
this, "porymap", "The project has been modified, save changes?", QMessageBox::StandardButton result = QMessageBox::question(
QMessageBox::No | QMessageBox::Yes | QMessageBox::Cancel, QMessageBox::Yes); this, "porymap", "The project has been modified, save changes?",
QMessageBox::No | QMessageBox::Yes | QMessageBox::Cancel, QMessageBox::Yes);
if (result == QMessageBox::Yes) { if (result == QMessageBox::Yes) {
editor->saveProject(); editor->saveProject();
} else if (result == QMessageBox::No) { } else if (result == QMessageBox::No) {
logWarn("Closing porymap with unsaved changes."); logWarn("Closing porymap with unsaved changes.");
} else if (result == QMessageBox::Cancel) { } else if (result == QMessageBox::Cancel) {
event->ignore(); event->ignore();
return; return;
}
} }
projectConfig.save();
} }
porymapConfig.setMainGeometry( porymapConfig.setMainGeometry(