Skip to content

Commit

Permalink
[ScnEditor]Prevent deletion of the last focusable vessel (#497)
Browse files Browse the repository at this point in the history
  • Loading branch information
TheGondos authored Sep 22, 2024
1 parent 6457942 commit 9bdd778
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
22 changes: 21 additions & 1 deletion Src/Plugin/ScnEditor/Editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,21 @@ void EditorTab_Vessel::VesselDeleted (OBJHANDLE hV)
}
}

// Orbiter closes when there is no focusable vessels in the scenario
// Check if there's another focusable object present
bool EditorTab_Vessel::CanDelete(OBJHANDLE hVessel)
{
for(int i = 0; i < oapiGetVesselCount(); i++) {
OBJHANDLE obj = oapiGetVesselByIndex (i);
if(obj == hVessel)
continue;
VESSEL *v = oapiGetVesselInterface (obj);
if(v->GetEnableFocus())
return true;
}
return false;
}

bool EditorTab_Vessel::DeleteVessel ()
{
char cbuf[256];
Expand All @@ -622,7 +637,12 @@ bool EditorTab_Vessel::DeleteVessel ()
OBJHANDLE hV = oapiGetVesselByName (ed->ExtractVesselName (cbuf));
if (!hV) return false;
//ed->hVessel = hV;
oapiDeleteVessel (hV);
if(CanDelete(hV)) {
oapiDeleteVessel (hV);
} else {
MessageBox(hTab, "Cannot delete the last focusable vessel in a scenario", NULL, MB_OK);
return false;
}
return true;
}

Expand Down
1 change: 1 addition & 0 deletions Src/Plugin/ScnEditor/Editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ class EditorTab_Vessel: public ScnEditorTab {
protected:
void ScanVesselList ();
bool DeleteVessel ();
bool CanDelete (OBJHANDLE hVessel);
};


Expand Down

0 comments on commit 9bdd778

Please sign in to comment.