diff --git a/src/dialogue.c b/src/dialogue.c index 98475af..08ebbcb 100644 --- a/src/dialogue.c +++ b/src/dialogue.c @@ -24,6 +24,8 @@ #include "input.h" #include "dialogue.h" +int dialogue_open; /**< Number of dialogues open. */ + /* Extern. */ extern void main_loop(void); /* From lephisto.c */ @@ -39,6 +41,13 @@ static void dialogue_inputCancel(unsigned int wid, char* str); static int loop_done; /**< Used to indicate the secondary loop is finished. */ static int toolkit_loop(void); +/** + * @brief Check to see if a dialogue is open. + */ +int dialogue_isOpen(void) { + return !!dialogue_open; +} + /** * @brief Display an alert popup with only an ok button and a message. * @param fmt Printf stype message to display. @@ -63,6 +72,8 @@ void dialogue_alert(const char* fmt, ...) { &gl_smallFont, &cBlack, msg); window_addButton(wdw, 135, 20, 50, 30, "btnOK", "OK", dialogue_alertClose); + + dialogue_open++; } /** @@ -72,6 +83,7 @@ void dialogue_alert(const char* fmt, ...) { static void dialogue_alertClose(unsigned int wid, char* str) { (void)str; window_destroy(wid); + dialogue_open--; } /** @@ -143,6 +155,7 @@ void dialogue_msg(char* caption, const char* fmt, ...) { window_addButton(msg_wid, (w-50)/2, 20, 50, 30, "btnOK", "OK", dialogue_msgClose); + dialogue_open++; toolkit_loop(); } @@ -150,6 +163,7 @@ static void dialogue_msgClose(unsigned int wid, char* str) { (void)str; window_destroy(wid); loop_done = 1; + dialogue_open--; } /* Run a dialogue with a Yes and No button, return 1 if yes, 0 for no. */ @@ -186,6 +200,7 @@ int dialogue_YesNo(char* caption, const char* fmt, ...) { dialogue_YesNoClose); /* Tricky secondary loop. */ + dialogue_open++; toolkit_loop(); /* Return the result. */ @@ -202,6 +217,7 @@ static void dialogue_YesNoClose(unsigned int wid, char* str) { yesno_wid = 0; loop_done = 1; + dialogue_open--; } /* Toolkit input boxes, returns the input. */ @@ -243,6 +259,7 @@ char* dialogue_input(char* title, int min, int max, const char* fmt, ...) { "btnClose", "Done", dialogue_inputClose); /* Tricky secondary. */ + dialogue_open++; input = NULL; while(!input_cancelled && (!input || ((int) strlen(input) < min))) { /* Must be longer than min. */ @@ -265,6 +282,7 @@ char* dialogue_input(char* title, int min, int max, const char* fmt, ...) { /* Cleanup plox. */ window_destroy(input_wid); input_wid = 0; + dialogue_open--; return input; } diff --git a/src/dialogue.h b/src/dialogue.h index 0c484af..d389ff4 100644 --- a/src/dialogue.h +++ b/src/dialogue.h @@ -8,3 +8,6 @@ void dialogue_msg(char* caption, const char* fmt, ...); int dialogue_YesNo(char* caption, const char* fmt, ...); /* Yes = 1, No = 0. */ char* dialogue_input(char* title, int min, int max, const char* fmt, ...); +/* Misc. */ +int dialogue_isOpen(void); + diff --git a/src/menu.c b/src/menu.c index d5d887d..933b82b 100644 --- a/src/menu.c +++ b/src/menu.c @@ -47,8 +47,8 @@ #define BUTTON_WIDTH 90 /**< Button width, standard across menus. */ #define BUTTON_HEIGHT 30 /**< Button height, standard across menus. */ -#define menu_Open(f) (menu_open |= (f)) /**< Mark a menu as open. */ -#define menu_Close(f) (menu_open ^= (f)) /**< Mark a menu as closed. */ +#define menu_Open(f) (menu_open |= (f)) /**< Mark a menu as open. */ +#define menu_Close(f) (menu_open &= ~(f)) /**< Mark a menu as closed. */ int menu_open = 0; /**< Store the opened/closed menus. */ /* Main menu. */ @@ -189,6 +189,7 @@ void menu_small(void) { /* Check if menu should be openable. */ if((player == NULL) || player_isFlag(PLAYER_DESTROYED) || pilot_isFlag(player, PILOT_DEAD) || + dialogue_isOpen() || /* Shouldn't open OVER dialogues. */ (menu_isOpen(MENU_MAIN) || menu_isOpen(MENU_SMALL) || menu_isOpen(MENU_DEATH)))