Check for unsaved changes before changing area/world
This commit is contained in:
parent
1a07a9c083
commit
0fe0c667a1
|
@ -33,11 +33,14 @@ void CStartWindow::on_actionOpen_MLVL_triggered()
|
||||||
QString WorldFile = QFileDialog::getOpenFileName(this, "Open MLVL", "", "Metroid Prime World (*.MLVL)");
|
QString WorldFile = QFileDialog::getOpenFileName(this, "Open MLVL", "", "Metroid Prime World (*.MLVL)");
|
||||||
if (WorldFile.isEmpty()) return;
|
if (WorldFile.isEmpty()) return;
|
||||||
|
|
||||||
gResCache.SetFolder(TString(WorldFile.toStdString()).GetFileDirectory());
|
if (mpWorldEditor->CheckUnsavedChanges())
|
||||||
mpWorld = gResCache.GetResource(WorldFile.toStdString());
|
{
|
||||||
mpWorldEditor->close();
|
gResCache.SetFolder(TString(WorldFile.toStdString()).GetFileDirectory());
|
||||||
|
mpWorld = gResCache.GetResource(WorldFile.toStdString());
|
||||||
|
mpWorldEditor->close();
|
||||||
|
|
||||||
FillWorldUI();
|
FillWorldUI();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CStartWindow::FillWorldUI()
|
void CStartWindow::FillWorldUI()
|
||||||
|
@ -156,31 +159,33 @@ void CStartWindow::on_AttachedAreasList_doubleClicked(const QModelIndex &index)
|
||||||
|
|
||||||
void CStartWindow::on_LaunchWorldEditorButton_clicked()
|
void CStartWindow::on_LaunchWorldEditorButton_clicked()
|
||||||
{
|
{
|
||||||
u64 AreaID = mpWorld->GetAreaResourceID(mSelectedAreaIndex);
|
if (mpWorldEditor->CheckUnsavedChanges())
|
||||||
TResPtr<CGameArea> pArea = gResCache.GetResource(AreaID, "MREA");
|
|
||||||
|
|
||||||
if (!pArea)
|
|
||||||
{
|
{
|
||||||
QMessageBox::warning(this, "Error", "Couldn't load area!");
|
u64 AreaID = mpWorld->GetAreaResourceID(mSelectedAreaIndex);
|
||||||
mpWorldEditor->close();
|
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()
|
void CStartWindow::on_actionLaunch_model_viewer_triggered()
|
||||||
|
|
|
@ -89,21 +89,7 @@ CWorldEditor::~CWorldEditor()
|
||||||
|
|
||||||
void CWorldEditor::closeEvent(QCloseEvent *pEvent)
|
void CWorldEditor::closeEvent(QCloseEvent *pEvent)
|
||||||
{
|
{
|
||||||
bool ShouldClose = true;
|
bool ShouldClose = CheckUnsavedChanges();
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ShouldClose)
|
if (ShouldClose)
|
||||||
{
|
{
|
||||||
|
@ -198,6 +184,28 @@ CGameArea* CWorldEditor::ActiveArea()
|
||||||
return mpArea;
|
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 ************
|
// ************ PUBLIC SLOTS ************
|
||||||
bool CWorldEditor::Save()
|
bool CWorldEditor::Save()
|
||||||
{
|
{
|
||||||
|
|
|
@ -44,6 +44,7 @@ public:
|
||||||
bool eventFilter(QObject *pObj, QEvent *pEvent);
|
bool eventFilter(QObject *pObj, QEvent *pEvent);
|
||||||
void SetArea(CWorld *pWorld, CGameArea *pArea, u32 AreaIndex);
|
void SetArea(CWorld *pWorld, CGameArea *pArea, u32 AreaIndex);
|
||||||
CGameArea* ActiveArea();
|
CGameArea* ActiveArea();
|
||||||
|
bool CheckUnsavedChanges();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
bool Save();
|
bool Save();
|
||||||
|
|
Loading…
Reference in New Issue