|
@@ -30,6 +30,8 @@
|
|
|
|
|
|
#include "status_indicator.h"
|
|
|
|
|
|
+#include "scene/gui/popup_menu.h"
|
|
|
+
|
|
|
void StatusIndicator::_notification(int p_what) {
|
|
|
ERR_MAIN_THREAD_GUARD;
|
|
|
#ifdef TOOLS_ENABLED
|
|
@@ -43,12 +45,22 @@ void StatusIndicator::_notification(int p_what) {
|
|
|
if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_STATUS_INDICATOR)) {
|
|
|
if (visible && iid == DisplayServer::INVALID_INDICATOR_ID) {
|
|
|
iid = DisplayServer::get_singleton()->create_status_indicator(icon, tooltip, callable_mp(this, &StatusIndicator::_callback));
|
|
|
+ PopupMenu *pm = Object::cast_to<PopupMenu>(get_node_or_null(menu));
|
|
|
+ if (pm) {
|
|
|
+ RID menu_rid = pm->bind_global_menu();
|
|
|
+ DisplayServer::get_singleton()->status_indicator_set_menu(iid, menu_rid);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
} break;
|
|
|
case NOTIFICATION_EXIT_TREE: {
|
|
|
if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_STATUS_INDICATOR)) {
|
|
|
if (iid != DisplayServer::INVALID_INDICATOR_ID) {
|
|
|
+ PopupMenu *pm = Object::cast_to<PopupMenu>(get_node_or_null(menu));
|
|
|
+ if (pm) {
|
|
|
+ pm->unbind_global_menu();
|
|
|
+ DisplayServer::get_singleton()->status_indicator_set_menu(iid, RID());
|
|
|
+ }
|
|
|
DisplayServer::get_singleton()->delete_status_indicator(iid);
|
|
|
iid = DisplayServer::INVALID_INDICATOR_ID;
|
|
|
}
|
|
@@ -66,11 +78,14 @@ void StatusIndicator::_bind_methods() {
|
|
|
ClassDB::bind_method(D_METHOD("get_icon"), &StatusIndicator::get_icon);
|
|
|
ClassDB::bind_method(D_METHOD("set_visible", "visible"), &StatusIndicator::set_visible);
|
|
|
ClassDB::bind_method(D_METHOD("is_visible"), &StatusIndicator::is_visible);
|
|
|
+ ClassDB::bind_method(D_METHOD("set_menu", "menu"), &StatusIndicator::set_menu);
|
|
|
+ ClassDB::bind_method(D_METHOD("get_menu"), &StatusIndicator::get_menu);
|
|
|
|
|
|
ADD_SIGNAL(MethodInfo("pressed", PropertyInfo(Variant::INT, "mouse_button"), PropertyInfo(Variant::VECTOR2I, "mouse_position")));
|
|
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::STRING, "tooltip", PROPERTY_HINT_MULTILINE_TEXT), "set_tooltip", "get_tooltip");
|
|
|
- ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "icon", PROPERTY_HINT_RESOURCE_TYPE, "Image"), "set_icon", "get_icon");
|
|
|
+ ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "icon", PROPERTY_HINT_RESOURCE_TYPE, "Texture2D"), "set_icon", "get_icon");
|
|
|
+ ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "menu", PROPERTY_HINT_NODE_PATH_VALID_TYPES, "PopupMenu"), "set_menu", "get_menu");
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "visible"), "set_visible", "is_visible");
|
|
|
}
|
|
|
|
|
@@ -78,7 +93,7 @@ void StatusIndicator::_callback(MouseButton p_index, const Point2i &p_pos) {
|
|
|
emit_signal(SNAME("pressed"), p_index, p_pos);
|
|
|
}
|
|
|
|
|
|
-void StatusIndicator::set_icon(const Ref<Image> &p_icon) {
|
|
|
+void StatusIndicator::set_icon(const Ref<Texture2D> &p_icon) {
|
|
|
ERR_MAIN_THREAD_GUARD;
|
|
|
icon = p_icon;
|
|
|
if (iid != DisplayServer::INVALID_INDICATOR_ID) {
|
|
@@ -86,7 +101,7 @@ void StatusIndicator::set_icon(const Ref<Image> &p_icon) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-Ref<Image> StatusIndicator::get_icon() const {
|
|
|
+Ref<Texture2D> StatusIndicator::get_icon() const {
|
|
|
return icon;
|
|
|
}
|
|
|
|
|
@@ -102,6 +117,30 @@ String StatusIndicator::get_tooltip() const {
|
|
|
return tooltip;
|
|
|
}
|
|
|
|
|
|
+void StatusIndicator::set_menu(const NodePath &p_menu) {
|
|
|
+ PopupMenu *pm = Object::cast_to<PopupMenu>(get_node_or_null(menu));
|
|
|
+ if (pm) {
|
|
|
+ pm->unbind_global_menu();
|
|
|
+ if (iid != DisplayServer::INVALID_INDICATOR_ID) {
|
|
|
+ DisplayServer::get_singleton()->status_indicator_set_menu(iid, RID());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ menu = p_menu;
|
|
|
+
|
|
|
+ pm = Object::cast_to<PopupMenu>(get_node_or_null(menu));
|
|
|
+ if (pm) {
|
|
|
+ if (iid != DisplayServer::INVALID_INDICATOR_ID) {
|
|
|
+ RID menu_rid = pm->bind_global_menu();
|
|
|
+ DisplayServer::get_singleton()->status_indicator_set_menu(iid, menu_rid);
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+NodePath StatusIndicator::get_menu() const {
|
|
|
+ return menu;
|
|
|
+}
|
|
|
+
|
|
|
void StatusIndicator::set_visible(bool p_visible) {
|
|
|
ERR_MAIN_THREAD_GUARD;
|
|
|
if (visible == p_visible) {
|
|
@@ -122,8 +161,18 @@ void StatusIndicator::set_visible(bool p_visible) {
|
|
|
if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_STATUS_INDICATOR)) {
|
|
|
if (visible && iid == DisplayServer::INVALID_INDICATOR_ID) {
|
|
|
iid = DisplayServer::get_singleton()->create_status_indicator(icon, tooltip, callable_mp(this, &StatusIndicator::_callback));
|
|
|
+ PopupMenu *pm = Object::cast_to<PopupMenu>(get_node_or_null(menu));
|
|
|
+ if (pm) {
|
|
|
+ RID menu_rid = pm->bind_global_menu();
|
|
|
+ DisplayServer::get_singleton()->status_indicator_set_menu(iid, menu_rid);
|
|
|
+ }
|
|
|
}
|
|
|
if (!visible && iid != DisplayServer::INVALID_INDICATOR_ID) {
|
|
|
+ PopupMenu *pm = Object::cast_to<PopupMenu>(get_node_or_null(menu));
|
|
|
+ if (pm) {
|
|
|
+ pm->unbind_global_menu();
|
|
|
+ DisplayServer::get_singleton()->status_indicator_set_menu(iid, RID());
|
|
|
+ }
|
|
|
DisplayServer::get_singleton()->delete_status_indicator(iid);
|
|
|
iid = DisplayServer::INVALID_INDICATOR_ID;
|
|
|
}
|