From b091acec8fe313ce1dc6e9ce2afd59fcaae472ad Mon Sep 17 00:00:00 2001 From: Ricardo Cruz Date: Thu, 29 Apr 2004 10:00:51 +0000 Subject: [PATCH] Created a simple confirm_dialog. Currently only used by the level editor, but can be used, for instance, by slot delete confirmation. SVN-Revision: 832 --- src/leveleditor.cpp | 37 ++++++------------------------------- src/menu.cpp | 38 ++++++++++++++++++++++++++++++++++++++ src/menu.h | 2 ++ 3 files changed, 46 insertions(+), 31 deletions(-) diff --git a/src/leveleditor.cpp b/src/leveleditor.cpp index a9907f745..072b0ee2b 100644 --- a/src/leveleditor.cpp +++ b/src/leveleditor.cpp @@ -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); } } } diff --git a/src/menu.cpp b/src/menu.cpp index b8c41e9d3..d8382693e 100644 --- a/src/menu.cpp +++ b/src/menu.cpp @@ -60,6 +60,44 @@ Menu* contrib_subset_menu = 0; std::vector 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) { diff --git a/src/menu.h b/src/menu.h index 419a1e8e2..60d6205cc 100644 --- a/src/menu.h +++ b/src/menu.h @@ -67,6 +67,8 @@ enum LevelEditorSettingsMenuIDs { MNID_APPLY }; +bool confirm_dialog(char *text); + /* Kinds of menu items */ enum MenuItemKind { MN_ACTION, -- 2.11.0