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 e80a8be commit b1044b9
Show file tree
Hide file tree
Showing 17 changed files with 212 additions and 60 deletions.
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 (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) {
String name = E->get().name;
if (!(E->get().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->get().type);
property->set_icon(0, EditorNode::get_singleton()->get_class_icon(icon_type));
Expand Down
49 changes: 30 additions & 19 deletions editor/editor_inspector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,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_ofi(EditorPropertyNameProcessor::get_singleton()->process_name(sections[i]))) {
if (p_filter.is_subsequence_ofi(EditorPropertyNameProcessor::get_singleton()->process_name(sections[i], p_style))) {
return true;
}
}
Expand Down Expand Up @@ -1463,6 +1463,8 @@ void EditorInspector::update_tree() {
_parse_added_editors(main_vbox, ped);
}

bool in_script_variables = false;

for (List<PropertyInfo>::Element *I = plist.front(); I; I = I->next()) {
PropertyInfo &p = I->get();

Expand Down Expand Up @@ -1503,6 +1505,8 @@ void EditorInspector::update_tree() {
main_vbox->add_child(category);
category_vbox = nullptr; //reset

in_script_variables = p.name == "Script Variables";

String type = p.name;
category->icon = EditorNode::get_singleton()->get_class_icon(type, "Object");
category->label = type;
Expand Down Expand Up @@ -1562,22 +1566,27 @@ void EditorInspector::update_tree() {

String name = (basename.find("/") != -1) ? basename.right(basename.rfind("/") + 1) : basename;
String name_override = name;

if (capitalize_paths) {
int dot = name.find(".");
String feature_tag;
{
const int dot = name.find(".");
if (dot != -1) {
name_override = name.substr(0, dot);
name = EditorPropertyNameProcessor::get_singleton()->process_name(name_override) + name.right(dot);
} else {
name = EditorPropertyNameProcessor::get_singleton()->process_name(name);
feature_tag = name.right(dot);
}
}

// 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;
}
name = EditorPropertyNameProcessor::get_singleton()->process_name(name_override, name_style) + feature_tag;

String path = basename.left(basename.rfind("/"));

if (use_filter && !filter.empty()) {
const String property_path = property_prefix + (path.empty() ? "" : path + "/") + name_override;
if (!_property_path_matches(property_path, filter)) {
if (!_property_path_matches(property_path, filter, property_name_style)) {
continue;
}
}
Expand All @@ -1603,15 +1612,13 @@ void EditorInspector::update_tree() {
current_vbox->add_child(section);
sections.push_back(section);

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

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

VBoxContainer *vb = section->get_vbox();
item_path[acc_path] = vb;
Expand Down Expand Up @@ -1853,11 +1860,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 Expand Up @@ -2346,7 +2357,7 @@ EditorInspector::EditorInspector() {
show_categories = false;
hide_script = true;
use_doc_hints = false;
capitalize_paths = true;
property_name_style = EditorPropertyNameProcessor::STYLE_CAPITALIZED;
use_filter = false;
autoclear = false;
changing = 0;
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/line_edit.h"
#include "scene/gui/scroll_container.h"
Expand Down Expand Up @@ -288,7 +289,7 @@ class EditorInspector : public ScrollContainer {
bool show_categories;
bool hide_script;
bool use_doc_hints;
bool capitalize_paths;
EditorPropertyNameProcessor::Style property_name_style;
bool use_filter;
bool autoclear;
bool use_folding;
Expand Down Expand Up @@ -371,8 +372,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 @@ -5984,10 +5984,11 @@ EditorNode::EditorNode() {
EDITOR_DEF("interface/editor/show_update_spinner", false);
EDITOR_DEF("interface/editor/update_continuously", false);
EDITOR_DEF("interface/editor/update_vital_only", 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", false);
EDITOR_DEF_RST("interface/scene_tabs/show_thumbnail_on_hover", 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::REAL, "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 @@ -2606,7 +2606,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(EditorNode::get_singleton()->get_inspector_dock()->get_property_name_style());

sub_inspector->connect("property_keyed", this, "_sub_inspector_property_keyed");
sub_inspector->connect("resource_selected", this, "_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 b1044b9

Please sign in to comment.