| 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 "box_container.h" |
| 34 |
#include "scene/gui/button.h" |
| 35 |
#include "scene/gui/label.h" |
| 36 |
#include "scene/gui/panel.h" |
| 37 |
#include "scene/gui/popup.h" |
| 38 |
#include "scene/gui/texture_button.h" |
| 39 |
#include "scene/main/window.h" |
| 40 |
|
| 41 |
class LineEdit; |
| 42 |
|
| 43 |
class AcceptDialog : public Window { |
| 44 |
GDCLASS(AcceptDialog, Window); |
| 45 |
|
| 46 |
Window *parent_visible = nullptr; |
| 47 |
|
| 48 |
Panel *bg_panel = nullptr; |
| 49 |
Label *message_label = nullptr; |
| 50 |
HBoxContainer *buttons_hbox = nullptr; |
| 51 |
Button *ok_button = nullptr; |
| 52 |
|
| 53 |
bool popped_up = false; |
| 54 |
String ok_text; |
| 55 |
String default_ok_text; |
| 56 |
|
| 57 |
bool hide_on_ok = true; |
| 58 |
bool close_on_escape = true; |
| 59 |
|
| 60 |
struct ThemeCache { |
| 61 |
Ref<StyleBox> panel_style; |
| 62 |
int buttons_separation = 0; |
| 63 |
int buttons_min_width = 0; |
| 64 |
int buttons_min_height = 0; |
| 65 |
} theme_cache; |
| 66 |
|
| 67 |
void _custom_action(const String &p_action); |
| 68 |
void _button_visibility_changed(Button *button); |
| 69 |
void _update_child_rects(); |
| 70 |
void _update_ok_text(); |
| 71 |
|
| 72 |
inline static bool swap_cancel_ok = false; |
| 73 |
|
| 74 |
void _parent_focused(); |
| 75 |
|
| 76 |
protected: |
| 77 |
virtual Size2 _get_contents_minimum_size() const override; |
| 78 |
virtual void _input_from_window(const Ref<InputEvent> &p_event) override; |
| 79 |
virtual void _post_popup() override; |
| 80 |
|
| 81 |
void _notification(int p_what); |
| 82 |
static void _bind_methods(); |
| 83 |
void _validate_property(PropertyInfo &p_property) const; |
| 84 |
|
| 85 |
virtual void ok_pressed() {} |
| 86 |
virtual void cancel_pressed() {} |
| 87 |
virtual void custom_action(const String &) {} |
| 88 |
|
| 89 |
void set_default_ok_text(const String &p_text); |
| 90 |
|
| 91 |
|
| 92 |
void _text_submitted(const String &p_text); |
| 93 |
void _ok_pressed(); |
| 94 |
void _cancel_pressed(); |
| 95 |
|
| 96 |
#ifndef DISABLE_DEPRECATED |
| 97 |
void _register_text_enter_bind_compat_89419(Control *p_line_edit); |
| 98 |
void _remove_button_bind_compat_89419(Control *p_button); |
| 99 |
|
| 100 |
static void _bind_compatibility_methods(); |
| 101 |
#endif |
| 102 |
|
| 103 |
public: |
| 104 |
Label *get_label() { return message_label; } |
| 105 |
static void set_swap_cancel_ok(bool p_swap); |
| 106 |
|
| 107 |
void register_text_enter(LineEdit *p_line_edit); |
| 108 |
|
| 109 |
Button *get_ok_button() { return ok_button; } |
| 110 |
Button *add_button(const String &p_text, bool p_right = false, const String &p_action = ""); |
| 111 |
Button *add_cancel_button(const String &p_cancel = ""); |
| 112 |
void remove_button(Button *p_button); |
| 113 |
|
| 114 |
void set_hide_on_ok(bool p_hide); |
| 115 |
bool get_hide_on_ok() const; |
| 116 |
|
| 117 |
void set_close_on_escape(bool p_enable); |
| 118 |
bool get_close_on_escape() const; |
| 119 |
|
| 120 |
void set_text(String p_text); |
| 121 |
String get_text() const; |
| 122 |
|
| 123 |
void set_autowrap(bool p_autowrap); |
| 124 |
bool has_autowrap(); |
| 125 |
|
| 126 |
void set_ok_button_text(String p_ok_button_text); |
| 127 |
String get_ok_button_text() const; |
| 128 |
|
| 129 |
AcceptDialog(); |
| 130 |
~AcceptDialog(); |
| 131 |
}; |
| 132 |
|
| 133 |
class ConfirmationDialog : public AcceptDialog { |
| 134 |
GDCLASS(ConfirmationDialog, AcceptDialog); |
| 135 |
Button *cancel = nullptr; |
| 136 |
|
| 137 |
protected: |
| 138 |
static void _bind_methods(); |
| 139 |
|
| 140 |
public: |
| 141 |
Button *get_cancel_button(); |
| 142 |
|
| 143 |
void set_cancel_button_text(String p_cancel_button_text); |
| 144 |
String get_cancel_button_text() const; |
| 145 |
|
| 146 |
ConfirmationDialog(); |
| 147 |
}; |