Skip to content

Commit

Permalink
Add property name style toggle to Inspector
Browse files Browse the repository at this point in the history
  • Loading branch information
timothyqiu committed Mar 28, 2022
1 parent 6b2481f commit ccde2bf
Show file tree
Hide file tree
Showing 18 changed files with 200 additions and 57 deletions.
2 changes: 1 addition & 1 deletion editor/debugger/script_editor_debugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1763,7 +1763,7 @@ ScriptEditorDebugger::ScriptEditorDebugger() {
inspector = memnew(EditorDebuggerInspector);
inspector->set_h_size_flags(SIZE_EXPAND_FILL);
inspector->set_v_size_flags(SIZE_EXPAND_FILL);
inspector->set_enable_capitalize_paths(false);
inspector->set_property_name_style(EditorPropertyNameProcessor::STYLE_RAW);
inspector->set_read_only(true);
inspector->connect("object_selected", callable_mp(this, &ScriptEditorDebugger::_remote_object_selected));
inspector->connect("object_edited", callable_mp(this, &ScriptEditorDebugger::_remote_object_edited));
Expand Down
10 changes: 8 additions & 2 deletions editor/editor_feature_profile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -608,18 +608,24 @@ void EditorFeatureProfileManager::_class_list_item_selected() {
TreeItem *properties = property_list->create_item(root);
properties->set_text(0, TTR("Class Properties:"));

const EditorPropertyNameProcessor::Style text_style = EditorPropertyNameProcessor::get_settings_style();
const EditorPropertyNameProcessor::Style tooltip_style = EditorPropertyNameProcessor::get_tooltip_style(text_style);

for (const PropertyInfo &E : props) {
String name = E.name;
if (!(E.usage & PROPERTY_USAGE_EDITOR)) {
continue;
}
const String text = EditorPropertyNameProcessor::get_singleton()->process_name(name, text_style);
const String tooltip = EditorPropertyNameProcessor::get_singleton()->process_name(name, tooltip_style);

TreeItem *property = property_list->create_item(properties);
property->set_cell_mode(0, TreeItem::CELL_MODE_CHECK);
property->set_editable(0, true);
property->set_selectable(0, true);
property->set_checked(0, !edited->is_class_property_disabled(class_name, name));
property->set_text(0, EditorPropertyNameProcessor::get_singleton()->process_name(name));
property->set_tooltip(0, EditorPropertyNameProcessor::get_singleton()->make_tooltip_for_name(name));
property->set_text(0, text);
property->set_tooltip(0, tooltip);
property->set_metadata(0, name);
String icon_type = Variant::get_type_name(E.type);
property->set_icon(0, EditorNode::get_singleton()->get_class_icon(icon_type));
Expand Down
50 changes: 30 additions & 20 deletions editor/editor_inspector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@
#include "scene/property_utils.h"
#include "scene/resources/packed_scene.h"

static bool _property_path_matches(const String &p_property_path, const String &p_filter) {
static bool _property_path_matches(const String &p_property_path, const String &p_filter, EditorPropertyNameProcessor::Style p_style) {
if (p_property_path.findn(p_filter) != -1) {
return true;
}

const Vector<String> sections = p_property_path.split("/");
for (int i = 0; i < sections.size(); i++) {
if (p_filter.is_subsequence_ofn(EditorPropertyNameProcessor::get_singleton()->process_name(sections[i]))) {
if (p_filter.is_subsequence_ofn(EditorPropertyNameProcessor::get_singleton()->process_name(sections[i], p_style))) {
return true;
}
}
Expand Down Expand Up @@ -2456,6 +2456,8 @@ void EditorInspector::update_tree() {
_parse_added_editors(main_vbox, ped);
}

bool in_script_variables = false;

// Get the lists of editors for properties.
for (List<PropertyInfo>::Element *E_property = plist.front(); E_property; E_property = E_property->next()) {
PropertyInfo &p = E_property->get();
Expand Down Expand Up @@ -2547,6 +2549,9 @@ void EditorInspector::update_tree() {
if (category->icon.is_null() && has_theme_icon(base_type, SNAME("EditorIcons"))) {
category->icon = get_theme_icon(base_type, SNAME("EditorIcons"));
}
in_script_variables = true;
} else {
in_script_variables = false;
}
if (category->icon.is_null()) {
if (!type.is_empty()) { // Can happen for built-in scripts.
Expand Down Expand Up @@ -2673,18 +2678,22 @@ void EditorInspector::update_tree() {

// Get the property label's string.
String name_override = (path.contains("/")) ? path.substr(path.rfind("/") + 1) : path;
String property_label_string = name_override;
if (capitalize_paths) {
// Capitalize paths.
int dot = property_label_string.find(".");
String feature_tag;
{
const int dot = name_override.find(".");
if (dot != -1) {
feature_tag = name_override.right(dot);
name_override = name_override.substr(0, dot);
property_label_string = EditorPropertyNameProcessor::get_singleton()->process_name(name_override) + property_label_string.substr(dot);
} else {
property_label_string = EditorPropertyNameProcessor::get_singleton()->process_name(property_label_string);
}
}

// Don't localize properties in Script Variables category.
EditorPropertyNameProcessor::Style name_style = property_name_style;
if (in_script_variables && name_style == EditorPropertyNameProcessor::STYLE_LOCALIZED) {
name_style = EditorPropertyNameProcessor::STYLE_CAPITALIZED;
}
const String property_label_string = EditorPropertyNameProcessor::get_singleton()->process_name(name_override, name_style) + feature_tag;

// Remove the property from the path.
int idx = path.rfind("/");
if (idx > -1) {
Expand All @@ -2696,7 +2705,7 @@ void EditorInspector::update_tree() {
// Ignore properties that do not fit the filter.
if (use_filter && !filter.is_empty()) {
const String property_path = property_prefix + (path.is_empty() ? "" : path + "/") + name_override;
if (!_property_path_matches(property_path, filter)) {
if (!_property_path_matches(property_path, filter, property_name_style)) {
continue;
}
}
Expand Down Expand Up @@ -2733,15 +2742,13 @@ void EditorInspector::update_tree() {
current_vbox->add_child(section);
sections.push_back(section);

String label = component;
if (capitalize_paths) {
label = EditorPropertyNameProcessor::get_singleton()->process_name(label);
}
const String label = EditorPropertyNameProcessor::get_singleton()->process_name(component, property_name_style);
const String tooltip = EditorPropertyNameProcessor::get_singleton()->process_name(component, EditorPropertyNameProcessor::get_tooltip_style(property_name_style));

Color c = sscolor;
c.a /= level;
section->setup(acc_path, label, object, c, use_folding, section_depth);
section->set_tooltip(EditorPropertyNameProcessor::get_singleton()->make_tooltip_for_name(component));
section->set_tooltip(tooltip);

// Add editors at the start of a group.
for (Ref<EditorInspectorPlugin> &ped : valid_plugins) {
Expand Down Expand Up @@ -2773,7 +2780,7 @@ void EditorInspector::update_tree() {
editor_inspector_array = memnew(EditorInspectorArray);

String array_label = path.contains("/") ? path.substr(path.rfind("/") + 1) : path;
array_label = EditorPropertyNameProcessor::get_singleton()->process_name(property_label_string);
array_label = EditorPropertyNameProcessor::get_singleton()->process_name(property_label_string, property_name_style);
int page = per_array_page.has(array_element_prefix) ? per_array_page[array_element_prefix] : 0;
editor_inspector_array->setup_with_move_element_function(object, array_label, array_element_prefix, page, c, use_folding);
editor_inspector_array->connect("page_change_request", callable_mp(this, &EditorInspector::_page_change_request), varray(array_element_prefix));
Expand Down Expand Up @@ -3037,12 +3044,15 @@ void EditorInspector::set_read_only(bool p_read_only) {
update_tree();
}

bool EditorInspector::is_capitalize_paths_enabled() const {
return capitalize_paths;
EditorPropertyNameProcessor::Style EditorInspector::get_property_name_style() const {
return property_name_style;
}

void EditorInspector::set_enable_capitalize_paths(bool p_capitalize) {
capitalize_paths = p_capitalize;
void EditorInspector::set_property_name_style(EditorPropertyNameProcessor::Style p_style) {
if (property_name_style == p_style) {
return;
}
property_name_style = p_style;
update_tree();
}

Expand Down
8 changes: 5 additions & 3 deletions editor/editor_inspector.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#ifndef EDITOR_INSPECTOR_H
#define EDITOR_INSPECTOR_H

#include "editor_property_name_processor.h"
#include "scene/gui/box_container.h"
#include "scene/gui/button.h"
#include "scene/gui/dialogs.h"
Expand Down Expand Up @@ -448,7 +449,7 @@ class EditorInspector : public ScrollContainer {
bool hide_script = true;
bool hide_metadata = true;
bool use_doc_hints = false;
bool capitalize_paths = true;
EditorPropertyNameProcessor::Style property_name_style = EditorPropertyNameProcessor::STYLE_CAPITALIZED;
bool use_filter = false;
bool autoclear = false;
bool use_folding = false;
Expand Down Expand Up @@ -545,8 +546,9 @@ class EditorInspector : public ScrollContainer {
void set_keying(bool p_active);
void set_read_only(bool p_read_only);

bool is_capitalize_paths_enabled() const;
void set_enable_capitalize_paths(bool p_capitalize);
EditorPropertyNameProcessor::Style get_property_name_style() const;
void set_property_name_style(EditorPropertyNameProcessor::Style p_style);

void set_autoclear(bool p_enable);

void set_show_categories(bool p_show);
Expand Down
5 changes: 3 additions & 2 deletions editor/editor_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6055,9 +6055,10 @@ EditorNode::EditorNode() {
EDITOR_DEF("interface/editor/save_on_focus_loss", false);
EDITOR_DEF("interface/editor/show_update_spinner", false);
EDITOR_DEF("interface/editor/update_continuously", false);
EDITOR_DEF("interface/editor/translate_properties", true);
EDITOR_DEF("interface/editor/localize_settings", true);
EDITOR_DEF_RST("interface/scene_tabs/restore_scenes_on_load", true);
EDITOR_DEF_RST("interface/inspector/capitalize_properties", true);
EDITOR_DEF_RST("interface/inspector/default_property_name_style", EditorPropertyNameProcessor::STYLE_CAPITALIZED);
EditorSettings::get_singleton()->add_property_hint(PropertyInfo(Variant::INT, "interface/inspector/default_property_name_style", PROPERTY_HINT_ENUM, "Raw,Capitalized,Localized"));
EDITOR_DEF_RST("interface/inspector/default_float_step", 0.001);
EditorSettings::get_singleton()->add_property_hint(PropertyInfo(Variant::FLOAT, "interface/inspector/default_float_step", PROPERTY_HINT_RANGE, "0,1,0"));
EDITOR_DEF_RST("interface/inspector/disable_folding", false);
Expand Down
2 changes: 1 addition & 1 deletion editor/editor_properties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3221,7 +3221,7 @@ void EditorPropertyResource::update_property() {
sub_inspector->set_use_doc_hints(true);

sub_inspector->set_sub_inspector(true);
sub_inspector->set_enable_capitalize_paths(bool(EDITOR_GET("interface/inspector/capitalize_properties")));
sub_inspector->set_property_name_style(InspectorDock::get_singleton()->get_property_name_style());

sub_inspector->connect("property_keyed", callable_mp(this, &EditorPropertyResource::_sub_inspector_property_keyed));
sub_inspector->connect("resource_selected", callable_mp(this, &EditorPropertyResource::_sub_inspector_resource_selected));
Expand Down
56 changes: 44 additions & 12 deletions editor/editor_property_name_processor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,28 @@

EditorPropertyNameProcessor *EditorPropertyNameProcessor::singleton = nullptr;

EditorPropertyNameProcessor::Style EditorPropertyNameProcessor::get_default_inspector_style() {
const Style style = (Style)EDITOR_GET("interface/inspector/default_property_name_style").operator int();
if (style == STYLE_LOCALIZED && !is_localization_available()) {
return STYLE_CAPITALIZED;
}
return style;
}

EditorPropertyNameProcessor::Style EditorPropertyNameProcessor::get_settings_style() {
const bool translate = EDITOR_GET("interface/editor/localize_settings");
return translate ? STYLE_LOCALIZED : STYLE_CAPITALIZED;
}

EditorPropertyNameProcessor::Style EditorPropertyNameProcessor::get_tooltip_style(Style p_style) {
return p_style == STYLE_LOCALIZED ? STYLE_CAPITALIZED : STYLE_LOCALIZED;
}

bool EditorPropertyNameProcessor::is_localization_available() {
const Vector<String> forbidden = String("en").split(",");
return forbidden.find(EDITOR_GET("interface/editor/editor_language")) == -1;
}

String EditorPropertyNameProcessor::_capitalize_name(const String &p_name) const {
const Map<String, String>::Element *cached = capitalize_string_cache.find(p_name);
if (cached) {
Expand All @@ -55,20 +77,21 @@ String EditorPropertyNameProcessor::_capitalize_name(const String &p_name) const
return capitalized;
}

String EditorPropertyNameProcessor::process_name(const String &p_name) const {
const String capitalized_string = _capitalize_name(p_name);
if (EDITOR_GET("interface/editor/translate_properties")) {
return TTRGET(capitalized_string);
}
return capitalized_string;
}
String EditorPropertyNameProcessor::process_name(const String &p_name, Style p_style) const {
switch (p_style) {
case STYLE_RAW: {
return p_name;
} break;

case STYLE_CAPITALIZED: {
return _capitalize_name(p_name);
} break;

String EditorPropertyNameProcessor::make_tooltip_for_name(const String &p_name) const {
const String capitalized_string = _capitalize_name(p_name);
if (EDITOR_GET("interface/editor/translate_properties")) {
return capitalized_string;
case STYLE_LOCALIZED: {
return TTRGET(_capitalize_name(p_name));
} break;
}
return TTRGET(capitalized_string);
ERR_FAIL_V_MSG(p_name, "Unexpected property name style.");
}

EditorPropertyNameProcessor::EditorPropertyNameProcessor() {
Expand All @@ -84,6 +107,8 @@ EditorPropertyNameProcessor::EditorPropertyNameProcessor() {
capitalize_string_remaps["adb"] = "ADB";
capitalize_string_remaps["ao"] = "AO";
capitalize_string_remaps["apk"] = "APK";
capitalize_string_remaps["arm64-v8a"] = "arm64-v8a";
capitalize_string_remaps["armeabi-v7a"] = "armeabi-v7a";
capitalize_string_remaps["arvr"] = "ARVR";
capitalize_string_remaps["bg"] = "BG";
capitalize_string_remaps["bp"] = "BP";
Expand Down Expand Up @@ -130,6 +155,7 @@ EditorPropertyNameProcessor::EditorPropertyNameProcessor() {
capitalize_string_remaps["ipad"] = "iPad";
capitalize_string_remaps["iphone"] = "iPhone";
capitalize_string_remaps["ipv6"] = "IPv6";
capitalize_string_remaps["ir"] = "IR";
capitalize_string_remaps["jit"] = "JIT";
capitalize_string_remaps["k1"] = "K1";
capitalize_string_remaps["k2"] = "K2";
Expand All @@ -139,10 +165,12 @@ EditorPropertyNameProcessor::EditorPropertyNameProcessor() {
capitalize_string_remaps["lowpass"] = "Low-pass";
capitalize_string_remaps["macos"] = "macOS";
capitalize_string_remaps["mb"] = "(MB)"; // Unit.
capitalize_string_remaps["mms"] = "MMS";
capitalize_string_remaps["ms"] = "(ms)"; // Unit
// Not used for now as AudioEffectReverb has a `msec` property.
//capitalize_string_remaps["msec"] = "(msec)"; // Unit.
capitalize_string_remaps["msaa"] = "MSAA";
capitalize_string_remaps["nfc"] = "NFC";
capitalize_string_remaps["normalmap"] = "Normal Map";
capitalize_string_remaps["ok"] = "OK";
capitalize_string_remaps["opengl"] = "OpenGL";
Expand All @@ -162,6 +190,7 @@ EditorPropertyNameProcessor::EditorPropertyNameProcessor() {
capitalize_string_remaps["sdfgi"] = "SDFGI";
capitalize_string_remaps["sdk"] = "SDK";
capitalize_string_remaps["sec"] = "(sec)"; // Unit.
capitalize_string_remaps["sms"] = "SMS";
capitalize_string_remaps["srgb"] = "sRGB";
capitalize_string_remaps["ssao"] = "SSAO";
capitalize_string_remaps["ssh"] = "SSH";
Expand All @@ -182,12 +211,15 @@ EditorPropertyNameProcessor::EditorPropertyNameProcessor() {
capitalize_string_remaps["uv2"] = "UV2";
capitalize_string_remaps["uwp"] = "UWP";
capitalize_string_remaps["vector2"] = "Vector2";
capitalize_string_remaps["vpn"] = "VPN";
capitalize_string_remaps["vram"] = "VRAM";
capitalize_string_remaps["vsync"] = "V-Sync";
capitalize_string_remaps["wap"] = "WAP";
capitalize_string_remaps["webp"] = "WebP";
capitalize_string_remaps["webrtc"] = "WebRTC";
capitalize_string_remaps["websocket"] = "WebSocket";
capitalize_string_remaps["wifi"] = "Wi-Fi";
capitalize_string_remaps["x86"] = "x86";
capitalize_string_remaps["xr"] = "XR";
capitalize_string_remaps["xy"] = "XY";
capitalize_string_remaps["xz"] = "XZ";
Expand Down
19 changes: 15 additions & 4 deletions editor/editor_property_name_processor.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,27 @@ class EditorPropertyNameProcessor : public Node {
mutable Map<String, String> capitalize_string_cache;
Map<String, String> capitalize_string_remaps;

// Capitalizes property path segments.
String _capitalize_name(const String &p_name) const;

public:
// Matches `interface/inspector/capitalize_properties` editor setting.
enum Style {
STYLE_RAW,
STYLE_CAPITALIZED,
STYLE_LOCALIZED,
};

static EditorPropertyNameProcessor *get_singleton() { return singleton; }

// Capitalize & localize property path segments.
String process_name(const String &p_name) const;
static Style get_default_inspector_style();
static Style get_settings_style();
static Style get_tooltip_style(Style p_style);

static bool is_localization_available();

// Make tooltip string for names processed by process_name().
String make_tooltip_for_name(const String &p_name) const;
// Turns property path segment into the given style.
String process_name(const String &p_name, Style p_style) const;

EditorPropertyNameProcessor();
~EditorPropertyNameProcessor();
Expand Down
Loading

0 comments on commit ccde2bf

Please sign in to comment.