Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply set_read_only() to child classes of EditorProperty elements #51722

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions core/object/object.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ enum PropertyUsageFlags {
PROPERTY_USAGE_DEFERRED_SET_RESOURCE = 1 << 26, // when loading, the resource for this property can be set at the end of loading
PROPERTY_USAGE_EDITOR_INSTANTIATE_OBJECT = 1 << 27, // For Object properties, instantiate them when creating in editor.
PROPERTY_USAGE_EDITOR_BASIC_SETTING = 1 << 28, //for project or editor settings, show when basic settings are selected
PROPERTY_USAGE_READ_ONLY = 1 << 29,

PROPERTY_USAGE_DEFAULT = PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_NETWORK,
PROPERTY_USAGE_DEFAULT_INTL = PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_NETWORK | PROPERTY_USAGE_INTERNATIONALIZED,
Expand Down
15 changes: 10 additions & 5 deletions editor/editor_inspector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,9 @@ void EditorProperty::_notification(int p_what) {

Color color;
if (draw_red) {
color = get_theme_color(SNAME("error_color"));
color = get_theme_color(is_read_only() ? SNAME("readonly_error_color") : SNAME("error_color"));
} else {
color = get_theme_color(SNAME("property_color"));
color = get_theme_color(is_read_only() ? SNAME("readonly_color") : SNAME("property_color"));
}
if (label.find(".") != -1) {
color.a = 0.5; //this should be un-hacked honestly, as it's used for editor overrides
Expand Down Expand Up @@ -283,7 +283,7 @@ void EditorProperty::_notification(int p_what) {
check_rect = Rect2();
}

if (can_revert) {
if (can_revert && !is_read_only()) {
Ref<Texture2D> reload_icon = get_theme_icon(SNAME("ReloadSmall"), SNAME("EditorIcons"));
text_limit -= reload_icon->get_width() + get_theme_constant(SNAME("hseparator"), SNAME("Tree")) * 2;
revert_rect = Rect2(text_limit + get_theme_constant(SNAME("hseparator"), SNAME("Tree")), (size.height - reload_icon->get_height()) / 2, reload_icon->get_width(), reload_icon->get_height());
Expand Down Expand Up @@ -384,8 +384,12 @@ void EditorProperty::update_property() {
GDVIRTUAL_CALL(_update_property);
}

void EditorProperty::_set_read_only(bool p_read_only) {
TokageItLab marked this conversation as resolved.
Show resolved Hide resolved
}

void EditorProperty::set_read_only(bool p_read_only) {
read_only = p_read_only;
_set_read_only(p_read_only);
}

bool EditorProperty::is_read_only() const {
Expand Down Expand Up @@ -1910,6 +1914,8 @@ void EditorInspector::update_tree() {
checked = p.usage & PROPERTY_USAGE_CHECKED;
}

bool property_read_only = (p.usage & PROPERTY_USAGE_READ_ONLY) || read_only;

if (p.usage & PROPERTY_USAGE_RESTART_IF_CHANGED) {
restart_request_props.insert(p.name);
}
Expand Down Expand Up @@ -2008,8 +2014,7 @@ void EditorInspector::update_tree() {
ep->set_checkable(checkable);
ep->set_checked(checked);
ep->set_keying(keying);

ep->set_read_only(read_only);
ep->set_read_only(property_read_only);
ep->set_deletable(deletable_properties);
}

Expand Down
1 change: 1 addition & 0 deletions editor/editor_inspector.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ class EditorProperty : public Container {
protected:
void _notification(int p_what);
static void _bind_methods();
virtual void _set_read_only(bool p_read_only);

virtual void gui_input(const Ref<InputEvent> &p_event) override;
virtual void unhandled_key_input(const Ref<InputEvent> &p_event) override;
Expand Down
Loading