| 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 "core/variant/callable_bind.h" |
| 34 |
#include "scene/gui/dialogs.h" |
| 35 |
#include "scene/gui/tree.h" |
| 36 |
|
| 37 |
class Button; |
| 38 |
class CheckBox; |
| 39 |
class CheckButton; |
| 40 |
class ConnectDialogBinds; |
| 41 |
class EditorInspector; |
| 42 |
class EditorVariantTypeOptionButton; |
| 43 |
class Label; |
| 44 |
class LineEdit; |
| 45 |
class OptionButton; |
| 46 |
class PopupMenu; |
| 47 |
class SceneTreeEditor; |
| 48 |
class SpinBox; |
| 49 |
|
| 50 |
class ConnectDialog : public ConfirmationDialog { |
| 51 |
GDCLASS(ConnectDialog, ConfirmationDialog); |
| 52 |
|
| 53 |
public: |
| 54 |
struct ConnectionData { |
| 55 |
Object *source = nullptr; |
| 56 |
Object *target = nullptr; |
| 57 |
StringName signal; |
| 58 |
StringName method; |
| 59 |
uint32_t flags = 0; |
| 60 |
int unbinds = 0; |
| 61 |
Vector<Variant> binds; |
| 62 |
|
| 63 |
ConnectionData() {} |
| 64 |
|
| 65 |
ConnectionData(const Connection &p_connection) { |
| 66 |
source = p_connection.signal.get_object(); |
| 67 |
signal = p_connection.signal.get_name(); |
| 68 |
target = p_connection.callable.get_object(); |
| 69 |
flags = p_connection.flags; |
| 70 |
|
| 71 |
Callable base_callable; |
| 72 |
if (p_connection.callable.is_custom()) { |
| 73 |
CallableCustomBind *ccb = dynamic_cast<CallableCustomBind *>(p_connection.callable.get_custom()); |
| 74 |
if (ccb) { |
| 75 |
binds = ccb->get_binds(); |
| 76 |
unbinds = ccb->get_unbound_arguments_count(); |
| 77 |
|
| 78 |
base_callable = ccb->get_callable(); |
| 79 |
} |
| 80 |
|
| 81 |
CallableCustomUnbind *ccu = dynamic_cast<CallableCustomUnbind *>(p_connection.callable.get_custom()); |
| 82 |
if (ccu) { |
| 83 |
ccu->get_bound_arguments(binds); |
| 84 |
unbinds = ccu->get_unbinds(); |
| 85 |
base_callable = ccu->get_callable(); |
| 86 |
} |
| 87 |
} else { |
| 88 |
base_callable = p_connection.callable; |
| 89 |
} |
| 90 |
method = base_callable.get_method(); |
| 91 |
} |
| 92 |
|
| 93 |
Callable get_callable() const { |
| 94 |
Callable callable = Callable(target, method); |
| 95 |
|
| 96 |
if (!binds.is_empty()) { |
| 97 |
const Variant **argptrs = (const Variant **)alloca(sizeof(Variant *) * binds.size()); |
| 98 |
for (int i = 0; i < binds.size(); i++) { |
| 99 |
argptrs[i] = &binds[i]; |
| 100 |
} |
| 101 |
callable = callable.bindp(argptrs, binds.size()); |
| 102 |
} |
| 103 |
|
| 104 |
if (unbinds > 0) { |
| 105 |
callable = callable.unbind(unbinds); |
| 106 |
} |
| 107 |
|
| 108 |
return callable; |
| 109 |
} |
| 110 |
}; |
| 111 |
|
| 112 |
private: |
| 113 |
Label *connect_to_label = nullptr; |
| 114 |
LineEdit *from_signal = nullptr; |
| 115 |
LineEdit *filter_nodes = nullptr; |
| 116 |
Object *source = nullptr; |
| 117 |
ConnectionData source_connection_data; |
| 118 |
StringName signal; |
| 119 |
PackedStringArray signal_args; |
| 120 |
LineEdit *dst_method = nullptr; |
| 121 |
ConnectDialogBinds *cdbinds = nullptr; |
| 122 |
bool edit_mode = false; |
| 123 |
bool first_popup = true; |
| 124 |
NodePath dst_path; |
| 125 |
VBoxContainer *vbc_right = nullptr; |
| 126 |
SceneTreeEditor *tree = nullptr; |
| 127 |
AcceptDialog *error = nullptr; |
| 128 |
|
| 129 |
Button *open_method_tree = nullptr; |
| 130 |
AcceptDialog *method_popup = nullptr; |
| 131 |
Tree *method_tree = nullptr; |
| 132 |
Label *empty_tree_label = nullptr; |
| 133 |
LineEdit *method_search = nullptr; |
| 134 |
CheckButton *script_methods_only = nullptr; |
| 135 |
CheckButton *compatible_methods_only = nullptr; |
| 136 |
|
| 137 |
SpinBox *unbind_count = nullptr; |
| 138 |
EditorInspector *bind_editor = nullptr; |
| 139 |
EditorVariantTypeOptionButton *type_list = nullptr; |
| 140 |
CheckBox *deferred = nullptr; |
| 141 |
CheckBox *one_shot = nullptr; |
| 142 |
CheckBox *append_source = nullptr; |
| 143 |
CheckButton *advanced = nullptr; |
| 144 |
Vector<Control *> bind_controls; |
| 145 |
|
| 146 |
Label *warning_label = nullptr; |
| 147 |
Label *error_label = nullptr; |
| 148 |
|
| 149 |
void ok_pressed() override; |
| 150 |
void _cancel_pressed(); |
| 151 |
void _item_activated(); |
| 152 |
void _tree_node_selected(); |
| 153 |
void _focus_currently_connected(); |
| 154 |
|
| 155 |
void _method_selected(); |
| 156 |
void _create_method_tree_items(const List<MethodInfo> &p_methods, TreeItem *p_parent_item); |
| 157 |
List<MethodInfo> _filter_method_list(const List<MethodInfo> &p_methods, const MethodInfo &p_signal, const String &p_search_string) const; |
| 158 |
void _update_method_tree(); |
| 159 |
void _method_check_button_pressed(const CheckButton *p_button); |
| 160 |
void _open_method_popup(); |
| 161 |
|
| 162 |
void _unbind_count_changed(double p_count); |
| 163 |
void _add_bind(); |
| 164 |
void _remove_bind(); |
| 165 |
void _advanced_pressed(); |
| 166 |
void _update_ok_enabled(); |
| 167 |
void _update_warning_label(); |
| 168 |
|
| 169 |
protected: |
| 170 |
virtual void _post_popup() override; |
| 171 |
void _notification(int p_what); |
| 172 |
static void _bind_methods(); |
| 173 |
|
| 174 |
public: |
| 175 |
static StringName generate_method_callback_name(Object *p_source, const String &p_signal_name, Object *p_target); |
| 176 |
Object *get_source() const; |
| 177 |
ConnectionData get_source_connection_data() const; |
| 178 |
StringName get_signal_name() const; |
| 179 |
PackedStringArray get_signal_args() const; |
| 180 |
NodePath get_dst_path() const; |
| 181 |
void set_dst_node(Node *p_node); |
| 182 |
StringName get_dst_method_name() const; |
| 183 |
void set_dst_method(const StringName &p_method); |
| 184 |
int get_unbinds() const; |
| 185 |
Vector<Variant> get_binds() const; |
| 186 |
String get_signature(const MethodInfo &p_method, PackedStringArray *r_arg_names = nullptr); |
| 187 |
|
| 188 |
bool get_deferred() const; |
| 189 |
bool get_one_shot() const; |
| 190 |
bool get_append_source() const; |
| 191 |
bool is_editing() const; |
| 192 |
|
| 193 |
virtual void shortcut_input(const Ref<InputEvent> &p_event) override; |
| 194 |
|
| 195 |
void init(const ConnectionData &p_cd, const PackedStringArray &p_signal_args, bool p_edit = false); |
| 196 |
|
| 197 |
void popup_dialog(const String &p_for_signal); |
| 198 |
ConnectDialog(); |
| 199 |
~ConnectDialog(); |
| 200 |
}; |
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
class ConnectionsDockTree : public Tree { |
| 206 |
virtual Control *make_custom_tooltip(const String &p_text) const; |
| 207 |
}; |
| 208 |
|
| 209 |
class ConnectionsDock : public VBoxContainer { |
| 210 |
GDCLASS(ConnectionsDock, VBoxContainer); |
| 211 |
|
| 212 |
enum TreeItemType { |
| 213 |
TREE_ITEM_TYPE_ROOT, |
| 214 |
TREE_ITEM_TYPE_CLASS, |
| 215 |
TREE_ITEM_TYPE_SIGNAL, |
| 216 |
TREE_ITEM_TYPE_CONNECTION, |
| 217 |
}; |
| 218 |
|
| 219 |
|
| 220 |
enum ClassMenuOption { |
| 221 |
CLASS_MENU_OPEN_DOCS, |
| 222 |
}; |
| 223 |
enum SignalMenuOption { |
| 224 |
SIGNAL_MENU_CONNECT, |
| 225 |
SIGNAL_MENU_DISCONNECT_ALL, |
| 226 |
SIGNAL_MENU_COPY_NAME, |
| 227 |
SIGNAL_MENU_OPEN_DOCS, |
| 228 |
}; |
| 229 |
enum SlotMenuOption { |
| 230 |
SLOT_MENU_EDIT, |
| 231 |
SLOT_MENU_GO_TO_METHOD, |
| 232 |
SLOT_MENU_DISCONNECT, |
| 233 |
}; |
| 234 |
|
| 235 |
VBoxContainer *holder = nullptr; |
| 236 |
Label *select_an_object = nullptr; |
| 237 |
|
| 238 |
Object *selected_object = nullptr; |
| 239 |
ConnectionsDockTree *tree = nullptr; |
| 240 |
|
| 241 |
ConfirmationDialog *disconnect_all_dialog = nullptr; |
| 242 |
ConnectDialog *connect_dialog = nullptr; |
| 243 |
Button *connect_button = nullptr; |
| 244 |
PopupMenu *class_menu = nullptr; |
| 245 |
String class_menu_doc_class_name; |
| 246 |
PopupMenu *signal_menu = nullptr; |
| 247 |
PopupMenu *slot_menu = nullptr; |
| 248 |
LineEdit *search_box = nullptr; |
| 249 |
|
| 250 |
bool is_editing_resource = false; |
| 251 |
|
| 252 |
void _filter_changed(const String &p_text); |
| 253 |
|
| 254 |
void _make_or_edit_connection(); |
| 255 |
void _connect(const ConnectDialog::ConnectionData &p_cd); |
| 256 |
void _disconnect(const ConnectDialog::ConnectionData &p_cd); |
| 257 |
void _disconnect_all(); |
| 258 |
|
| 259 |
void _tree_item_selected(); |
| 260 |
void _tree_item_activated(); |
| 261 |
TreeItemType _get_item_type(const TreeItem &p_item) const; |
| 262 |
bool _is_connection_inherited(Connection &p_connection); |
| 263 |
|
| 264 |
void _open_connection_dialog(TreeItem &p_item); |
| 265 |
void _open_edit_connection_dialog(TreeItem &p_item); |
| 266 |
void _go_to_method(TreeItem &p_item); |
| 267 |
|
| 268 |
void _handle_class_menu_option(int p_option); |
| 269 |
void _class_menu_about_to_popup(); |
| 270 |
void _handle_signal_menu_option(int p_option); |
| 271 |
void _signal_menu_about_to_popup(); |
| 272 |
void _handle_slot_menu_option(int p_option); |
| 273 |
void _slot_menu_about_to_popup(); |
| 274 |
void _tree_gui_input(const Ref<InputEvent> &p_event); |
| 275 |
void _close(); |
| 276 |
|
| 277 |
protected: |
| 278 |
void _connect_pressed(); |
| 279 |
void _notification(int p_what); |
| 280 |
static void _bind_methods(); |
| 281 |
|
| 282 |
public: |
| 283 |
void set_object(Object *p_object); |
| 284 |
void update_tree(); |
| 285 |
|
| 286 |
ConnectionsDock(); |
| 287 |
}; |