diff --git a/src/editor/editloop.cpp b/src/editor/editloop.cpp index 200df6423..3aa3b6fa1 100644 --- a/src/editor/editloop.cpp +++ b/src/editor/editloop.cpp @@ -1272,7 +1272,7 @@ local void EditorCallbackKeyDown(unsigned key, unsigned keychar) case 's': // ALT s F11 save pud menu case 'S': case KeyCodeF11: - if (EditorSave()) { + if (EditorSave() != -1) { SetStatusLine("Pud saved"); } InterfaceState = IfaceStateNormal; @@ -1862,11 +1862,13 @@ local void CreateEditor(void) ** ** @param file Save the level to this file. ** +** @return 0 for success, -1 for error +** ** @todo FIXME: Check if the pud is valid, contains no failures. -** Alteast two players, one human slot, every player a startpoint +** At least two players, one human slot, every player a startpoint ** ... */ -global void EditorSavePud(const char *file) +global int EditorSavePud(const char *file) { int i; @@ -1881,7 +1883,15 @@ global void EditorSavePud(const char *file) ~MapFieldLandUnit; } } - SavePud(file, &TheMap); + if (SavePud(file, &TheMap) == -1) { + ErrorMenu("Cannot save map"); + MustRedraw = RedrawEverything; + InterfaceState = IfaceStateNormal; + EditorUpdateDisplay(); + InterfaceState = IfaceStateMenu; + MustRedraw = RedrawMenu; + return -1; + } for (i = 0; i < NumUnits; ++i) { const UnitType *type; @@ -1893,6 +1903,7 @@ global void EditorSavePud(const char *file) MapFieldLandUnit; } } + return 0; } /*---------------------------------------------------------------------------- diff --git a/src/include/editor.h b/src/include/editor.h index d42b3a3a7..3d5b04e5d 100644 --- a/src/include/editor.h +++ b/src/include/editor.h @@ -57,7 +57,7 @@ extern void EditorMainLoop(void); extern void EditorUpdateDisplay(void); /// Save a pud from editor -extern void EditorSavePud(const char *file); +extern int EditorSavePud(const char *file); /// Register ccl features extern void EditorCclRegister(void); diff --git a/src/ui/menus.cpp b/src/ui/menus.cpp index b8922eb23..4b46d6faf 100644 --- a/src/ui/menus.cpp +++ b/src/ui/menus.cpp @@ -5699,6 +5699,8 @@ local void EditorEditAiPropertiesCancel(void) /** ** Save map from the editor +** +** @return 0 for success, -1 for error */ global int EditorSave(void) { @@ -5706,7 +5708,9 @@ global int EditorSave(void) char path[PATH_MAX]; char *s; char *p; + int ret; + ret = 0; menu = FindMenu("menu-editor-save"); EditorCancelled = 0; @@ -5723,16 +5727,17 @@ global int EditorSave(void) if (!EditorCancelled) { sprintf(path, "%s/%s.gz", ScenSelectPath, ScenSelectFileName); - EditorSavePud(path); + if (EditorSavePud(path) == -1) { + ret = -1; + } s = ScenSelectPath + strlen(ScenSelectPath); *s = '/'; strcpy(s+1, ScenSelectFileName); // Final map name with path p = ScenSelectPath + strlen(FreeCraftLibPath) + 1; strcpy(CurrentMapPath, p); *s = '\0'; - return 1; } - return 0; + return ret; } /**