| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
#pragma once |
| 32 |
|
| 33 |
#include "scene/gui/box_container.h" |
| 34 |
|
| 35 |
class Button; |
| 36 |
class PanelContainer; |
| 37 |
class StyleBoxFlat; |
| 38 |
|
| 39 |
class EditorToaster : public HBoxContainer { |
| 40 |
GDCLASS(EditorToaster, HBoxContainer); |
| 41 |
|
| 42 |
public: |
| 43 |
enum Severity { |
| 44 |
SEVERITY_INFO = 0, |
| 45 |
SEVERITY_WARNING, |
| 46 |
SEVERITY_ERROR, |
| 47 |
}; |
| 48 |
|
| 49 |
private: |
| 50 |
ErrorHandlerList eh; |
| 51 |
|
| 52 |
const int stylebox_radius = 3; |
| 53 |
|
| 54 |
Ref<StyleBoxFlat> info_panel_style_background; |
| 55 |
Ref<StyleBoxFlat> warning_panel_style_background; |
| 56 |
Ref<StyleBoxFlat> error_panel_style_background; |
| 57 |
|
| 58 |
Ref<StyleBoxFlat> info_panel_style_progress; |
| 59 |
Ref<StyleBoxFlat> warning_panel_style_progress; |
| 60 |
Ref<StyleBoxFlat> error_panel_style_progress; |
| 61 |
|
| 62 |
Button *main_button = nullptr; |
| 63 |
PanelContainer *disable_notifications_panel = nullptr; |
| 64 |
Button *disable_notifications_button = nullptr; |
| 65 |
|
| 66 |
VBoxContainer *vbox_container = nullptr; |
| 67 |
const int max_temporary_count = 5; |
| 68 |
struct Toast { |
| 69 |
Severity severity = SEVERITY_INFO; |
| 70 |
|
| 71 |
|
| 72 |
real_t duration = -1.0; |
| 73 |
real_t remaining_time = 0.0; |
| 74 |
bool popped = false; |
| 75 |
|
| 76 |
|
| 77 |
Button *copy_button = nullptr; |
| 78 |
Button *close_button = nullptr; |
| 79 |
|
| 80 |
|
| 81 |
String message; |
| 82 |
String tooltip; |
| 83 |
int count = 0; |
| 84 |
Label *message_label = nullptr; |
| 85 |
Label *message_count_label = nullptr; |
| 86 |
}; |
| 87 |
HashMap<Control *, Toast> toasts; |
| 88 |
|
| 89 |
bool is_processing_error = false; |
| 90 |
|
| 91 |
const double default_message_duration = 5.0; |
| 92 |
|
| 93 |
static void _error_handler(void *p_self, const char *p_func, const char *p_file, int p_line, const char *p_error, const char *p_errorexp, bool p_editor_notify, ErrorHandlerType p_type); |
| 94 |
static void _error_handler_impl(const String &p_file, int p_line, const String &p_error, const String &p_errorexp, bool p_editor_notify, int p_type); |
| 95 |
void _update_vbox_position(); |
| 96 |
void _update_disable_notifications_button(); |
| 97 |
void _auto_hide_or_free_toasts(); |
| 98 |
|
| 99 |
void _draw_button(); |
| 100 |
void _draw_progress(Control *panel); |
| 101 |
|
| 102 |
void _set_notifications_enabled(bool p_enabled); |
| 103 |
void _repop_old(); |
| 104 |
void _popup_str(const String &p_message, Severity p_severity, const String &p_tooltip); |
| 105 |
void _toast_theme_changed(Control *p_control); |
| 106 |
|
| 107 |
protected: |
| 108 |
static void _bind_methods(); |
| 109 |
static EditorToaster *singleton; |
| 110 |
|
| 111 |
void _notification(int p_what); |
| 112 |
|
| 113 |
public: |
| 114 |
static EditorToaster *get_singleton(); |
| 115 |
|
| 116 |
Control *popup(Control *p_control, Severity p_severity = SEVERITY_INFO, double p_time = 0.0, const String &p_tooltip = String()); |
| 117 |
void popup_str(const String &p_message, Severity p_severity = SEVERITY_INFO, const String &p_tooltip = String()); |
| 118 |
void close(Control *p_control); |
| 119 |
void instant_close(Control *p_control); |
| 120 |
void copy(Control *p_control); |
| 121 |
|
| 122 |
EditorToaster(); |
| 123 |
~EditorToaster(); |
| 124 |
}; |
| 125 |
|
| 126 |
VARIANT_ENUM_CAST(EditorToaster::Severity); |