Check for unsaved changes before changing area/world

This commit is contained in:
parax0 2016-02-01 18:30:09 -07:00
parent 1a07a9c083
commit 0fe0c667a1
3 changed files with 56 additions and 42 deletions

View File

@ -33,11 +33,14 @@ void CStartWindow::on_actionOpen_MLVL_triggered()
QString WorldFile = QFileDialog::getOpenFileName(this, "Open MLVL", "", "Metroid Prime World (*.MLVL)");
if (WorldFile.isEmpty()) return;
gResCache.SetFolder(TString(WorldFile.toStdString()).GetFileDirectory());
mpWorld = gResCache.GetResource(WorldFile.toStdString());
mpWorldEditor->close();
if (mpWorldEditor->CheckUnsavedChanges())
{
gResCache.SetFolder(TString(WorldFile.toStdString()).GetFileDirectory());
mpWorld = gResCache.GetResource(WorldFile.toStdString());
mpWorldEditor->close();
FillWorldUI();
FillWorldUI();
}
}
void CStartWindow::FillWorldUI()
@ -156,31 +159,33 @@ void CStartWindow::on_AttachedAreasList_doubleClicked(const QModelIndex &index)
void CStartWindow::on_LaunchWorldEditorButton_clicked()
{
u64 AreaID = mpWorld->GetAreaResourceID(mSelectedAreaIndex);
TResPtr<CGameArea> pArea = gResCache.GetResource(AreaID, "MREA");
if (!pArea)
if (mpWorldEditor->CheckUnsavedChanges())
{
QMessageBox::warning(this, "Error", "Couldn't load area!");
mpWorldEditor->close();
u64 AreaID = mpWorld->GetAreaResourceID(mSelectedAreaIndex);
TResPtr<CGameArea> pArea = gResCache.GetResource(AreaID, "MREA");
if (!pArea)
{
QMessageBox::warning(this, "Error", "Couldn't load area!");
}
else
{
mpWorld->SetAreaLayerInfo(pArea, mSelectedAreaIndex);
mpWorldEditor->SetArea(mpWorld, pArea, mSelectedAreaIndex);
mpWorldEditor->setWindowModality(Qt::WindowModal);
mpWorldEditor->showMaximized();
// Display errors
CErrorLogDialog ErrorDialog(mpWorldEditor);
bool HasErrors = ErrorDialog.GatherErrors();
if (HasErrors)
ErrorDialog.exec();
gResCache.Clean();
}
}
else
{
mpWorld->SetAreaLayerInfo(pArea, mSelectedAreaIndex);
mpWorldEditor->SetArea(mpWorld, pArea, mSelectedAreaIndex);
mpWorldEditor->setWindowModality(Qt::WindowModal);
mpWorldEditor->showMaximized();
// Display errors
CErrorLogDialog ErrorDialog(mpWorldEditor);
bool HasErrors = ErrorDialog.GatherErrors();
if (HasErrors)
ErrorDialog.exec();
}
gResCache.Clean();
}
void CStartWindow::on_actionLaunch_model_viewer_triggered()

View File

@ -89,21 +89,7 @@ CWorldEditor::~CWorldEditor()
void CWorldEditor::closeEvent(QCloseEvent *pEvent)
{
bool ShouldClose = true;
if (isWindowModified())
{
int Result = QMessageBox::warning(this, "Save", "You have unsaved changes. Save?", QMessageBox::Yes, QMessageBox::No, QMessageBox::Cancel);
if (Result == QMessageBox::Yes)
ShouldClose = Save();
else if (Result == QMessageBox::No)
ShouldClose = true;
else if (Result == QMessageBox::Cancel)
ShouldClose = false;
}
bool ShouldClose = CheckUnsavedChanges();
if (ShouldClose)
{
@ -198,6 +184,28 @@ CGameArea* CWorldEditor::ActiveArea()
return mpArea;
}
bool CWorldEditor::CheckUnsavedChanges()
{
// Check whether the user has unsaved changes, return whether it's okay to clear the scene
bool OkToClear = !isWindowModified();
if (!OkToClear)
{
int Result = QMessageBox::warning(this, "Save", "You have unsaved changes. Save?", QMessageBox::Yes, QMessageBox::No, QMessageBox::Cancel);
if (Result == QMessageBox::Yes)
OkToClear = Save();
else if (Result == QMessageBox::No)
OkToClear = true;
else if (Result == QMessageBox::Cancel)
OkToClear = false;
}
return OkToClear;
}
// ************ PUBLIC SLOTS ************
bool CWorldEditor::Save()
{

View File

@ -44,6 +44,7 @@ public:
bool eventFilter(QObject *pObj, QEvent *pEvent);
void SetArea(CWorld *pWorld, CGameArea *pArea, u32 AreaIndex);
CGameArea* ActiveArea();
bool CheckUnsavedChanges();
public slots:
bool Save();