Created a simple confirm_dialog. Currently only used by the level editor, but can...
authorRicardo Cruz <rick2@aeiou.pt>
Thu, 29 Apr 2004 10:00:51 +0000 (10:00 +0000)
committerRicardo Cruz <rick2@aeiou.pt>
Thu, 29 Apr 2004 10:00:51 +0000 (10:00 +0000)
SVN-Revision: 832

src/leveleditor.cpp
src/menu.cpp
src/menu.h

index a9907f7..072b0ee 100644 (file)
@@ -970,38 +970,13 @@ void le_checkevents()
                         {
                           Level new_lev;
                           char str[1024];
-                          int d = 0;
-                          sprintf(str,"Level %d doesn't exist.",le_level+1);
-                          white_text->drawf(str,0,-18,A_HMIDDLE,A_VMIDDLE,2);
-                          white_text->drawf("Do you want to create it?",0,0,A_HMIDDLE,A_VMIDDLE,2);
-                          red_text->drawf("(Y)es/(N)o",0,20,A_HMIDDLE,A_VMIDDLE,2);
-                          flipscreen();
-                          while(d == 0)
+                          sprintf(str,"Level %d doesn't exist. Create it?",le_level+1);
+                          if(confirm_dialog(str))
                             {
-                              while(SDL_PollEvent(&event))
-                                switch(event.type)
-                                  {
-                                  case SDL_KEYDOWN:            // key pressed
-                                    switch(event.key.keysym.sym)
-                                      {
-                                      case SDLK_y:
-                                        new_lev.init_defaults();
-                                        new_lev.save(le_level_subset.name.c_str(),++le_level);
-                                        le_level_subset.levels = le_level;
-                                        le_goto_level(le_level);
-                                        d = 1;
-                                        break;
-                                      case SDLK_n:
-                                        d = 1;
-                                        break;
-                                      default:
-                                        break;
-                                      }
-                                    break;
-                                  default:
-                                    break;
-                                  }
-                              SDL_Delay(50);
+                            new_lev.init_defaults();
+                            new_lev.save(le_level_subset.name.c_str(),++le_level);
+                            le_level_subset.levels = le_level;
+                            le_goto_level(le_level);
                             }
                         }
                     }
index b8c41e9..d838269 100644 (file)
@@ -60,6 +60,44 @@ Menu* contrib_subset_menu   = 0;
 std::vector<Menu*> Menu::last_menus;
 Menu* Menu::current_ = 0;
 
+/* just displays a Yes/No text that can be used to confirm stuff */
+bool confirm_dialog(char *text)
+{
+white_text->drawf(text,0,0,A_HMIDDLE,A_VMIDDLE,2);
+red_text->drawf("(Y)es/(N)o",0,20,A_HMIDDLE,A_VMIDDLE,2);
+flipscreen();
+SDL_Event event;
+int done = 0;
+bool confirm = false;
+while(done == 0)
+  {
+  while(SDL_PollEvent(&event))
+    switch(event.type)
+      {
+      case SDL_KEYDOWN:                // key pressed
+        switch(event.key.keysym.sym)
+          {
+          case SDLK_y:
+            done = 1;
+            confirm = true;
+            break;
+          case SDLK_n:
+            done = 1;
+            break;
+          default:
+            break;
+          }
+        break;
+      case SDL_QUIT:           // quit signal
+        done = 1;
+      default:
+        break;
+      }
+  SDL_Delay(50);
+  }
+return confirm;
+}
+
 void
 Menu::push_current(Menu* pmenu)
 {
index 419a1e8..60d6205 100644 (file)
@@ -67,6 +67,8 @@ enum LevelEditorSettingsMenuIDs {
   MNID_APPLY
   };
 
+bool confirm_dialog(char *text);
+
 /* Kinds of menu items */
 enum MenuItemKind {
   MN_ACTION,