Editor: Show only relevant hints for the chosen variant type in the Blackboard Plan editor
This commit is contained in:
parent
761b211740
commit
a6717ec76d
|
@ -65,7 +65,19 @@ void BlackboardPlanEditor::_rename_var(const String &p_new_name, int p_index) {
|
||||||
|
|
||||||
void BlackboardPlanEditor::_change_var_type(Variant::Type p_new_type, int p_index) {
|
void BlackboardPlanEditor::_change_var_type(Variant::Type p_new_type, int p_index) {
|
||||||
ERR_FAIL_NULL(plan);
|
ERR_FAIL_NULL(plan);
|
||||||
plan->get_var_by_index(p_index).second.set_type(p_new_type);
|
|
||||||
|
BBVariable var = plan->get_var_by_index(p_index).second;
|
||||||
|
if (var.get_type() == p_new_type) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
PackedInt32Array allowed_hints = LimboUtility::get_singleton()->get_property_hints_allowed_for_type(p_new_type);
|
||||||
|
if (!allowed_hints.has(var.get_hint())) {
|
||||||
|
var.set_hint(PROPERTY_HINT_NONE);
|
||||||
|
}
|
||||||
|
|
||||||
|
var.set_type(p_new_type);
|
||||||
|
|
||||||
plan->notify_property_list_changed();
|
plan->notify_property_list_changed();
|
||||||
_refresh();
|
_refresh();
|
||||||
}
|
}
|
||||||
|
@ -99,6 +111,16 @@ void BlackboardPlanEditor::_show_button_popup(Button *p_button, PopupMenu *p_pop
|
||||||
p_popup->set_size(rect.size);
|
p_popup->set_size(rect.size);
|
||||||
p_popup->set_position(rect.position);
|
p_popup->set_position(rect.position);
|
||||||
|
|
||||||
|
if (p_popup == hint_menu) {
|
||||||
|
hint_menu->clear();
|
||||||
|
hint_menu->reset_size();
|
||||||
|
Variant::Type t = plan->get_var_by_index(p_index).second.get_type();
|
||||||
|
PackedInt32Array hints = LimboUtility::get_singleton()->get_property_hints_allowed_for_type(t);
|
||||||
|
for (int i = 0; i < hints.size(); i++) {
|
||||||
|
hint_menu->add_item(LimboUtility::get_singleton()->get_property_hint_text(PropertyHint(hints[i])), hints[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
last_index = p_index;
|
last_index = p_index;
|
||||||
p_popup->popup();
|
p_popup->popup();
|
||||||
}
|
}
|
||||||
|
|
|
@ -300,7 +300,7 @@ String LimboUtility::get_property_hint_text(PropertyHint p_hint) const {
|
||||||
return "ENUM";
|
return "ENUM";
|
||||||
}
|
}
|
||||||
case PROPERTY_HINT_ENUM_SUGGESTION: {
|
case PROPERTY_HINT_ENUM_SUGGESTION: {
|
||||||
return "SUGGESTION";
|
return "ENUM_SUGGESTION";
|
||||||
}
|
}
|
||||||
case PROPERTY_HINT_EXP_EASING: {
|
case PROPERTY_HINT_EXP_EASING: {
|
||||||
return "EXP_EASING";
|
return "EXP_EASING";
|
||||||
|
@ -411,6 +411,110 @@ String LimboUtility::get_property_hint_text(PropertyHint p_hint) const {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PackedInt32Array LimboUtility::get_property_hints_allowed_for_type(Variant::Type p_type) const {
|
||||||
|
PackedInt32Array hints;
|
||||||
|
hints.append(PROPERTY_HINT_NONE);
|
||||||
|
|
||||||
|
// * According to editor/editor_properties.cpp
|
||||||
|
switch (p_type) {
|
||||||
|
case Variant::Type::NIL:
|
||||||
|
case Variant::Type::RID:
|
||||||
|
case Variant::Type::CALLABLE:
|
||||||
|
case Variant::Type::SIGNAL:
|
||||||
|
case Variant::Type::BOOL: {
|
||||||
|
} break;
|
||||||
|
case Variant::Type::INT: {
|
||||||
|
hints.append(PROPERTY_HINT_RANGE);
|
||||||
|
hints.append(PROPERTY_HINT_ENUM);
|
||||||
|
hints.append(PROPERTY_HINT_FLAGS);
|
||||||
|
hints.append(PROPERTY_HINT_LAYERS_2D_RENDER);
|
||||||
|
hints.append(PROPERTY_HINT_LAYERS_2D_PHYSICS);
|
||||||
|
hints.append(PROPERTY_HINT_LAYERS_2D_NAVIGATION);
|
||||||
|
hints.append(PROPERTY_HINT_LAYERS_3D_RENDER);
|
||||||
|
hints.append(PROPERTY_HINT_LAYERS_3D_PHYSICS);
|
||||||
|
hints.append(PROPERTY_HINT_LAYERS_3D_NAVIGATION);
|
||||||
|
hints.append(PROPERTY_HINT_LAYERS_AVOIDANCE);
|
||||||
|
} break;
|
||||||
|
case Variant::Type::FLOAT: {
|
||||||
|
hints.append(PROPERTY_HINT_RANGE);
|
||||||
|
hints.append(PROPERTY_HINT_EXP_EASING);
|
||||||
|
} break;
|
||||||
|
case Variant::Type::STRING: {
|
||||||
|
hints.append(PROPERTY_HINT_ENUM);
|
||||||
|
hints.append(PROPERTY_HINT_ENUM_SUGGESTION);
|
||||||
|
hints.append(PROPERTY_HINT_FILE);
|
||||||
|
hints.append(PROPERTY_HINT_DIR);
|
||||||
|
hints.append(PROPERTY_HINT_GLOBAL_FILE);
|
||||||
|
hints.append(PROPERTY_HINT_GLOBAL_DIR);
|
||||||
|
hints.append(PROPERTY_HINT_MULTILINE_TEXT);
|
||||||
|
hints.append(PROPERTY_HINT_EXPRESSION);
|
||||||
|
hints.append(PROPERTY_HINT_PLACEHOLDER_TEXT);
|
||||||
|
// hints.append(PROPERTY_HINT_TYPE_STRING); // ! Causes a crash.
|
||||||
|
hints.append(PROPERTY_HINT_SAVE_FILE);
|
||||||
|
hints.append(PROPERTY_HINT_GLOBAL_SAVE_FILE);
|
||||||
|
hints.append(PROPERTY_HINT_LOCALE_ID);
|
||||||
|
hints.append(PROPERTY_HINT_PASSWORD);
|
||||||
|
} break;
|
||||||
|
case Variant::Type::VECTOR2:
|
||||||
|
case Variant::Type::VECTOR2I:
|
||||||
|
case Variant::Type::VECTOR3:
|
||||||
|
case Variant::Type::VECTOR3I:
|
||||||
|
case Variant::Type::VECTOR4:
|
||||||
|
case Variant::Type::VECTOR4I: {
|
||||||
|
hints.append(PROPERTY_HINT_RANGE);
|
||||||
|
hints.append(PROPERTY_HINT_LINK);
|
||||||
|
} break;
|
||||||
|
case Variant::Type::RECT2:
|
||||||
|
case Variant::Type::RECT2I:
|
||||||
|
case Variant::Type::TRANSFORM2D:
|
||||||
|
case Variant::Type::PLANE:
|
||||||
|
case Variant::Type::AABB:
|
||||||
|
case Variant::Type::BASIS:
|
||||||
|
case Variant::Type::TRANSFORM3D:
|
||||||
|
case Variant::Type::PROJECTION: {
|
||||||
|
hints.append(PROPERTY_HINT_RANGE);
|
||||||
|
} break;
|
||||||
|
case Variant::Type::QUATERNION: {
|
||||||
|
hints.append(PROPERTY_HINT_RANGE);
|
||||||
|
hints.append(PROPERTY_HINT_HIDE_QUATERNION_EDIT);
|
||||||
|
} break;
|
||||||
|
case Variant::Type::COLOR: {
|
||||||
|
hints.append(PROPERTY_HINT_COLOR_NO_ALPHA);
|
||||||
|
} break;
|
||||||
|
case Variant::Type::STRING_NAME: {
|
||||||
|
hints.append(PROPERTY_HINT_ENUM);
|
||||||
|
hints.append(PROPERTY_HINT_ENUM_SUGGESTION);
|
||||||
|
hints.append(PROPERTY_HINT_PLACEHOLDER_TEXT);
|
||||||
|
hints.append(PROPERTY_HINT_PASSWORD);
|
||||||
|
} break;
|
||||||
|
case Variant::Type::NODE_PATH: {
|
||||||
|
hints.append(PROPERTY_HINT_NODE_PATH_VALID_TYPES);
|
||||||
|
hints.append(PROPERTY_USAGE_NODE_PATH_FROM_SCENE_ROOT);
|
||||||
|
|
||||||
|
} break;
|
||||||
|
case Variant::Type::OBJECT: {
|
||||||
|
hints.append(PROPERTY_HINT_RESOURCE_TYPE);
|
||||||
|
hints.append(PROPERTY_HINT_NODE_TYPE);
|
||||||
|
} break;
|
||||||
|
case Variant::Type::DICTIONARY: {
|
||||||
|
hints.append(PROPERTY_HINT_LOCALIZABLE_STRING);
|
||||||
|
} break;
|
||||||
|
case Variant::Type::ARRAY:
|
||||||
|
case Variant::Type::PACKED_BYTE_ARRAY:
|
||||||
|
case Variant::Type::PACKED_INT32_ARRAY:
|
||||||
|
case Variant::Type::PACKED_INT64_ARRAY:
|
||||||
|
case Variant::Type::PACKED_FLOAT32_ARRAY:
|
||||||
|
case Variant::Type::PACKED_FLOAT64_ARRAY:
|
||||||
|
case Variant::Type::PACKED_STRING_ARRAY:
|
||||||
|
case Variant::Type::PACKED_VECTOR2_ARRAY:
|
||||||
|
case Variant::Type::PACKED_VECTOR3_ARRAY:
|
||||||
|
case Variant::Type::PACKED_COLOR_ARRAY:
|
||||||
|
case Variant::Type::VARIANT_MAX: {
|
||||||
|
} break;
|
||||||
|
}
|
||||||
|
return hints;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef TOOLS_ENABLED
|
#ifdef TOOLS_ENABLED
|
||||||
|
|
||||||
Ref<Shortcut> LimboUtility::add_shortcut(const String &p_path, const String &p_name, Key p_keycode) {
|
Ref<Shortcut> LimboUtility::add_shortcut(const String &p_path, const String &p_name, Key p_keycode) {
|
||||||
|
|
|
@ -89,6 +89,7 @@ public:
|
||||||
Variant perform_operation(Operation p_operation, const Variant &left_value, const Variant &right_value);
|
Variant perform_operation(Operation p_operation, const Variant &left_value, const Variant &right_value);
|
||||||
|
|
||||||
String get_property_hint_text(PropertyHint p_hint) const;
|
String get_property_hint_text(PropertyHint p_hint) const;
|
||||||
|
PackedInt32Array get_property_hints_allowed_for_type(Variant::Type p_type) const;
|
||||||
|
|
||||||
#ifdef TOOLS_ENABLED
|
#ifdef TOOLS_ENABLED
|
||||||
Ref<Shortcut> add_shortcut(const String &p_path, const String &p_name, Key p_keycode = LW_KEY(NONE));
|
Ref<Shortcut> add_shortcut(const String &p_path, const String &p_name, Key p_keycode = LW_KEY(NONE));
|
||||||
|
|
Loading…
Reference in New Issue