Check for unsaved changes before changing area/world
This commit is contained in:
parent
1a07a9c083
commit
0fe0c667a1
|
@ -33,12 +33,15 @@ void CStartWindow::on_actionOpen_MLVL_triggered()
|
|||
QString WorldFile = QFileDialog::getOpenFileName(this, "Open MLVL", "", "Metroid Prime World (*.MLVL)");
|
||||
if (WorldFile.isEmpty()) return;
|
||||
|
||||
if (mpWorldEditor->CheckUnsavedChanges())
|
||||
{
|
||||
gResCache.SetFolder(TString(WorldFile.toStdString()).GetFileDirectory());
|
||||
mpWorld = gResCache.GetResource(WorldFile.toStdString());
|
||||
mpWorldEditor->close();
|
||||
|
||||
FillWorldUI();
|
||||
}
|
||||
}
|
||||
|
||||
void CStartWindow::FillWorldUI()
|
||||
{
|
||||
|
@ -155,6 +158,8 @@ void CStartWindow::on_AttachedAreasList_doubleClicked(const QModelIndex &index)
|
|||
}
|
||||
|
||||
void CStartWindow::on_LaunchWorldEditorButton_clicked()
|
||||
{
|
||||
if (mpWorldEditor->CheckUnsavedChanges())
|
||||
{
|
||||
u64 AreaID = mpWorld->GetAreaResourceID(mSelectedAreaIndex);
|
||||
TResPtr<CGameArea> pArea = gResCache.GetResource(AreaID, "MREA");
|
||||
|
@ -162,7 +167,6 @@ void CStartWindow::on_LaunchWorldEditorButton_clicked()
|
|||
if (!pArea)
|
||||
{
|
||||
QMessageBox::warning(this, "Error", "Couldn't load area!");
|
||||
mpWorldEditor->close();
|
||||
}
|
||||
|
||||
else
|
||||
|
@ -178,10 +182,11 @@ void CStartWindow::on_LaunchWorldEditorButton_clicked()
|
|||
|
||||
if (HasErrors)
|
||||
ErrorDialog.exec();
|
||||
}
|
||||
|
||||
gResCache.Clean();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CStartWindow::on_actionLaunch_model_viewer_triggered()
|
||||
{
|
||||
|
|
|
@ -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()
|
||||
{
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue