mirror of
https://github.com/AxioDL/PrimeWorldEditor.git
synced 2025-06-22 22:43:30 +00:00
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)");
|
QString WorldFile = QFileDialog::getOpenFileName(this, "Open MLVL", "", "Metroid Prime World (*.MLVL)");
|
||||||
if (WorldFile.isEmpty()) return;
|
if (WorldFile.isEmpty()) return;
|
||||||
|
|
||||||
|
if (mpWorldEditor->CheckUnsavedChanges())
|
||||||
|
{
|
||||||
gResCache.SetFolder(TString(WorldFile.toStdString()).GetFileDirectory());
|
gResCache.SetFolder(TString(WorldFile.toStdString()).GetFileDirectory());
|
||||||
mpWorld = gResCache.GetResource(WorldFile.toStdString());
|
mpWorld = gResCache.GetResource(WorldFile.toStdString());
|
||||||
mpWorldEditor->close();
|
mpWorldEditor->close();
|
||||||
|
|
||||||
FillWorldUI();
|
FillWorldUI();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void CStartWindow::FillWorldUI()
|
void CStartWindow::FillWorldUI()
|
||||||
{
|
{
|
||||||
@ -155,6 +158,8 @@ void CStartWindow::on_AttachedAreasList_doubleClicked(const QModelIndex &index)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void CStartWindow::on_LaunchWorldEditorButton_clicked()
|
void CStartWindow::on_LaunchWorldEditorButton_clicked()
|
||||||
|
{
|
||||||
|
if (mpWorldEditor->CheckUnsavedChanges())
|
||||||
{
|
{
|
||||||
u64 AreaID = mpWorld->GetAreaResourceID(mSelectedAreaIndex);
|
u64 AreaID = mpWorld->GetAreaResourceID(mSelectedAreaIndex);
|
||||||
TResPtr<CGameArea> pArea = gResCache.GetResource(AreaID, "MREA");
|
TResPtr<CGameArea> pArea = gResCache.GetResource(AreaID, "MREA");
|
||||||
@ -162,7 +167,6 @@ void CStartWindow::on_LaunchWorldEditorButton_clicked()
|
|||||||
if (!pArea)
|
if (!pArea)
|
||||||
{
|
{
|
||||||
QMessageBox::warning(this, "Error", "Couldn't load area!");
|
QMessageBox::warning(this, "Error", "Couldn't load area!");
|
||||||
mpWorldEditor->close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else
|
||||||
@ -178,10 +182,11 @@ void CStartWindow::on_LaunchWorldEditorButton_clicked()
|
|||||||
|
|
||||||
if (HasErrors)
|
if (HasErrors)
|
||||||
ErrorDialog.exec();
|
ErrorDialog.exec();
|
||||||
}
|
|
||||||
|
|
||||||
gResCache.Clean();
|
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…
x
Reference in New Issue
Block a user