1 2 #ifndef _OSAPI_DIALOGS_H 3 #define _OSAPI_DIALOGS_H 4 #pragma once 5 6 #include "globalincs/pstypes.h" 7 8 #include <stdexcept> 9 10 struct lua_State; 11 12 namespace os 13 { 14 namespace dialogs 15 { 16 class DialogException : public std::runtime_error { 17 public: DialogException(const std::string & msg)18 explicit DialogException(const std::string& msg) : std::runtime_error(msg) {} 19 }; 20 class AssertException : public DialogException { 21 public: AssertException(const std::string & msg)22 explicit AssertException(const std::string& msg) : DialogException(msg) {} 23 }; 24 class LuaErrorException : public DialogException { 25 public: LuaErrorException(const std::string & msg)26 explicit LuaErrorException(const std::string& msg) : DialogException(msg) {} 27 }; 28 class ErrorException : public DialogException { 29 public: ErrorException(const std::string & msg)30 explicit ErrorException(const std::string& msg) : DialogException(msg) {} 31 }; 32 class WarningException : public DialogException { 33 public: WarningException(const std::string & msg)34 explicit WarningException(const std::string& msg) : DialogException(msg) {} 35 }; 36 37 // These map onto the SDL ShowSimpleMessageBox flags 38 enum MessageType 39 { 40 MESSAGEBOX_ERROR, 41 MESSAGEBOX_WARNING, 42 MESSAGEBOX_INFORMATION, 43 }; 44 45 /** 46 * @brief Displays an assert message. 47 * @note Used by Assert() and Assertion() to display an error message, should not be used directly 48 * 49 * @param text The text to display 50 * @param filename The source code filename where this function was called 51 * @param linenum The source code line number where this function was called 52 * @param format An optional message to display in addition to the specified text 53 */ 54 void AssertMessage(const char* text, const char* filename, int linenum, SCP_FORMAT_STRING 55 const char* format = nullptr, ...) 56 SCP_FORMAT_STRING_ARGS(4, 5) CLANG_ANALYZER_NORETURN; 57 58 /** 59 * @brief Shows a lua error. 60 * This captures the current state of the given lua_State and displays a dialog describing the error. 61 * If @c format is @c nullptr this function pops a string from the top of the lua stack and uses that as the error message. 62 * @param L The lua_State to capture the state of 63 * @param format The error message to display, may be @c nullptr 64 */ 65 void LuaError(lua_State *L, SCP_FORMAT_STRING const char *format = nullptr, ...) SCP_FORMAT_STRING_ARGS(2, 3); 66 67 /** 68 * @brief Shows an error dialog. 69 * Only use this function if the program is in an unrecoverable state because of invalid user data, programming errors should 70 * be handled with Assert() and Assertion(). This function usually doesn't return as the generated error is considered fatal. 71 * 72 * @param filename The source code filename where this function was called 73 * @param line The source code line number where this function was called 74 * @param format The error message to display (a format string) 75 */ 76 void Error(const char* filename, int line, SCP_FORMAT_STRING const char* format, ...) 77 SCP_FORMAT_STRING_ARGS(3, 4) CLANG_ANALYZER_NORETURN; 78 79 /** 80 * @brief Shows an error dialog. 81 * This is a more general version of Error(const char*,int,const char*,...) that only displays the dialog. 82 * 83 * @param text The text to display 84 */ 85 void Error(const char* text) CLANG_ANALYZER_NORETURN;; 86 87 /** 88 * @brief Shows a warning dialog. 89 * A warning should be generated if a recoverable user data error was detected. This function is only enabled in debug builds. 90 * 91 * @param filename The source code filename where this function was called 92 * @param line The source code line number where this function was called 93 * @param format The message to display 94 */ 95 void Warning(const char* filename, int line, SCP_FORMAT_STRING const char* format, ...) SCP_FORMAT_STRING_ARGS(3, 4); 96 97 /** 98 * @brief Shows an extra warning. 99 * Same as Warning(const char*,int,const char*) but only Cmdline_extra_warn is set to @c 1. 100 * 101 * @param filename The source code filename where this function was called 102 * @param line The source code line number where this function was called 103 * @param format The message to display 104 */ 105 void WarningEx(const char* filename, int line, SCP_FORMAT_STRING const char* format, ...) SCP_FORMAT_STRING_ARGS(3, 4); 106 107 /** 108 * @brief Shows a warning dialog. 109 * Same as #Warning but also appears in release builds. 110 * 111 * @param filename The source code filename where this function was called 112 * @param line The source code line number where this function was called 113 * @param format The message to display 114 */ 115 void ReleaseWarning(const char* filename, int line, SCP_FORMAT_STRING const char* format, ...) SCP_FORMAT_STRING_ARGS(3, 4); 116 117 void Message(MessageType type, const char* message, const char* title = NULL); 118 } 119 } 120 121 // Make these available in the global namespace for compatibility 122 using os::dialogs::LuaError; 123 using os::dialogs::Error; 124 using os::dialogs::Warning; 125 using os::dialogs::ReleaseWarning; 126 using os::dialogs::WarningEx; 127 128 #endif // _OSAPI_DIALOGS_H 129