diff --git a/scripts/modules/bl_i18n_utils/settings.py b/scripts/modules/bl_i18n_utils/settings.py index 4003fc21051..1670ebe8892 100644 --- a/scripts/modules/bl_i18n_utils/settings.py +++ b/scripts/modules/bl_i18n_utils/settings.py @@ -273,7 +273,17 @@ PYGETTEXT_KEYWORDS = (() + tuple((r"\.{}\(\s*" + _msg_re + r"\s*\)").format(it) for it in ("description", "error_message_add")) + - # Node socket labels + # Node socket labels from declarations: context-less names + tuple((r"\.{}\(\s*" + _msg_re + + r"\s*\)(?![^;]*\.translation_context\()[^;]*;").format(it) + for it in ("short_label",)) + + + # Node socket labels from declarations: names with contexts + tuple((r"\.{}\(\s*" + _msg_re + r"[^;]*\.translation_context\(\s*" + + _ctxt_re + r"\s*\)").format(it) + for it in ("short_label",)) + + + # Dynamic node socket labels tuple((r"{}\(\s*[^,]+,\s*" + _msg_re + r"\s*\)").format(it) for it in ("node_sock_label",)) + diff --git a/source/blender/blenkernel/BKE_node.hh b/source/blender/blenkernel/BKE_node.hh index 24e0f58d91a..0c2ceea97c4 100644 --- a/source/blender/blenkernel/BKE_node.hh +++ b/source/blender/blenkernel/BKE_node.hh @@ -286,6 +286,12 @@ void nodeLabel(const bNodeTree *ntree, const bNode *node, char *label, int maxle */ const char *nodeSocketLabel(const bNodeSocket *sock); +/** + * Get node socket short label if it is set. + * It is used when grouping sockets under panels, to avoid redundancy in the label. + */ +const char *nodeSocketShortLabel(const bNodeSocket *sock); + /** * Initialize a new node type struct with default values and callbacks. */ diff --git a/source/blender/blenkernel/intern/node.cc b/source/blender/blenkernel/intern/node.cc index 45115febc2b..e109899ccec 100644 --- a/source/blender/blenkernel/intern/node.cc +++ b/source/blender/blenkernel/intern/node.cc @@ -4021,6 +4021,17 @@ void nodeLabel(const bNodeTree *ntree, const bNode *node, char *label, const int BLI_strncpy(label, IFACE_(node->typeinfo->ui_name), label_maxncpy); } +const char *nodeSocketShortLabel(const bNodeSocket *sock) +{ + if (sock->runtime->declaration != nullptr) { + blender::StringRefNull short_label = sock->runtime->declaration->short_label; + if (!short_label.is_empty()) { + return sock->runtime->declaration->short_label.data(); + } + } + return nullptr; +} + const char *nodeSocketLabel(const bNodeSocket *sock) { return (sock->label[0] != '\0') ? sock->label : sock->name; diff --git a/source/blender/editors/space_node/node_draw.cc b/source/blender/editors/space_node/node_draw.cc index 6c36c09a198..cc754f26156 100644 --- a/source/blender/editors/space_node/node_draw.cc +++ b/source/blender/editors/space_node/node_draw.cc @@ -404,8 +404,16 @@ static bool node_update_basis_buttons(const bContext &C, const char *node_socket_get_label(const bNodeSocket *socket, const char *panel_label) { - const char *socket_label = bke::nodeSocketLabel(socket); + /* Get the short label if possible. This is used when grouping sockets under panels, + * to avoid redundancy in the label. */ + const char *socket_short_label = bke::nodeSocketShortLabel(socket); const char *socket_translation_context = node_socket_get_translation_context(*socket); + + if (socket_short_label) { + return CTX_IFACE_(socket_translation_context, socket_short_label); + } + + const char *socket_label = bke::nodeSocketLabel(socket); const char *translated_socket_label = CTX_IFACE_(socket_translation_context, socket_label); /* Shorten socket label if it begins with the panel label. */ diff --git a/source/blender/makesdna/DNA_node_types.h b/source/blender/makesdna/DNA_node_types.h index ab9571240ee..6d846a26836 100644 --- a/source/blender/makesdna/DNA_node_types.h +++ b/source/blender/makesdna/DNA_node_types.h @@ -157,6 +157,7 @@ typedef struct bNodeSocket { /** Custom dynamic defined label, MAX_NAME. */ char label[64]; + char short_label[64]; char description[64]; /** diff --git a/source/blender/nodes/NOD_node_declaration.hh b/source/blender/nodes/NOD_node_declaration.hh index 32a74302d8e..2f337a5a59d 100644 --- a/source/blender/nodes/NOD_node_declaration.hh +++ b/source/blender/nodes/NOD_node_declaration.hh @@ -171,6 +171,7 @@ using ItemDeclarationPtr = std::unique_ptr; class SocketDeclaration : public ItemDeclaration { public: std::string name; + std::string short_label; std::string identifier; std::string description; std::string translation_context; @@ -314,6 +315,17 @@ class SocketDeclarationBuilder : public BaseSocketDeclarationBuilder { return *(Self *)this; } + Self &short_label(std::string value = "") + { + if (decl_in_) { + decl_in_->short_label = std::move(value); + } + if (decl_out_) { + decl_out_->short_label = std::move(value); + } + return *(Self *)this; + } + Self &description(std::string value = "") { if (decl_in_) { diff --git a/source/blender/nodes/shader/nodes/node_shader_bsdf_principled.cc b/source/blender/nodes/shader/nodes/node_shader_bsdf_principled.cc index d32f9e0dcb6..ade0412151b 100644 --- a/source/blender/nodes/shader/nodes/node_shader_bsdf_principled.cc +++ b/source/blender/nodes/shader/nodes/node_shader_bsdf_principled.cc @@ -57,6 +57,7 @@ static void node_declare(NodeDeclarationBuilder &b) uiItemR(layout, ptr, "subsurface_method", UI_ITEM_R_SPLIT_EMPTY_NAME, "", ICON_NONE); }); sss.add_input("Subsurface Weight") + .short_label("Weight") .default_value(0.0f) .min(0.0f) .max(1.0f) @@ -66,12 +67,14 @@ static void node_declare(NodeDeclarationBuilder &b) "Typically should be zero or one (either fully diffuse or subsurface)"); #define SOCK_SUBSURFACE_WEIGHT_ID 7 sss.add_input("Subsurface Radius") + .short_label("Radius") .default_value({1.0f, 0.2f, 0.1f}) .min(0.0f) .max(100.0f) .description("Scattering radius to use for subsurface component (multiplied with Scale)"); #define SOCK_SUBSURFACE_RADIUS_ID 8 sss.add_input("Subsurface Scale") + .short_label("Scale") .default_value(0.05f) .min(0.0f) .max(10.0f) @@ -79,6 +82,7 @@ static void node_declare(NodeDeclarationBuilder &b) .description("Scale of the subsurface scattering (multiplied with Radius)"); #define SOCK_SUBSURFACE_SCALE_ID 9 sss.add_input("Subsurface IOR") + .short_label("IOR") .default_value(1.4f) .min(1.01f) .max(3.8f) @@ -86,6 +90,7 @@ static void node_declare(NodeDeclarationBuilder &b) .description("Index of refraction used for rays that enter the subsurface component"); #define SOCK_SUBSURFACE_IOR_ID 10 sss.add_input("Subsurface Anisotropy") + .short_label("Anisotropy") .default_value(0.0f) .min(0.0f) .max(1.0f) @@ -100,6 +105,7 @@ static void node_declare(NodeDeclarationBuilder &b) uiItemR(layout, ptr, "distribution", UI_ITEM_R_SPLIT_EMPTY_NAME, "", ICON_NONE); }); spec.add_input("Specular IOR Level") + .short_label("IOR Level") .default_value(0.5f) .min(0.0f) .max(1.0f) @@ -110,10 +116,12 @@ static void node_declare(NodeDeclarationBuilder &b) "incidence)"); #define SOCK_SPECULAR_ID 12 spec.add_input("Specular Tint") + .short_label("Tint") .default_value({1.0f, 1.0f, 1.0f, 1.0f}) .description( "Tint dielectric reflection at normal incidence for artistic control, and metallic " - "reflection at near-grazing incidence to simulate complex index of refraction"); + "reflection at near-grazing incidence to simulate complex index of refraction") + .translation_context(BLT_I18NCONTEXT_ID_NODETREE); #define SOCK_SPECULAR_TINT_ID 13 spec.add_input("Anisotropic") .default_value(0.0f) @@ -133,6 +141,7 @@ static void node_declare(NodeDeclarationBuilder &b) /* Panel for Transmission settings. */ PanelDeclarationBuilder &transmission = b.add_panel("Transmission").default_closed(true); transmission.add_input("Transmission Weight") + .short_label("Weight") .default_value(0.0f) .min(0.0f) .max(1.0f) @@ -143,6 +152,7 @@ static void node_declare(NodeDeclarationBuilder &b) /* Panel for Coat settings. */ PanelDeclarationBuilder &coat = b.add_panel("Coat").default_closed(true); coat.add_input("Coat Weight") + .short_label("Weight") .default_value(0.0f) .min(0.0f) .max(1.0f) @@ -152,6 +162,7 @@ static void node_declare(NodeDeclarationBuilder &b) "Typically should be zero or one for physically-based materials"); #define SOCK_COAT_WEIGHT_ID 18 coat.add_input("Coat Roughness") + .short_label("Roughness") .default_value(0.03f) .min(0.0f) .max(1.0f) @@ -159,6 +170,7 @@ static void node_declare(NodeDeclarationBuilder &b) .description("The roughness of the coat layer"); #define SOCK_COAT_ROUGHNESS_ID 19 coat.add_input("Coat IOR") + .short_label("IOR") .default_value(1.5f) .min(1.0f) .max(4.0f) @@ -167,37 +179,50 @@ static void node_declare(NodeDeclarationBuilder &b) "(affects its reflectivity as well as the falloff of coat tinting)"); #define SOCK_COAT_IOR_ID 20 coat.add_input("Coat Tint") + .short_label("Tint") .default_value({1.0f, 1.0f, 1.0f, 1.0f}) .description( "Adds a colored tint to the coat layer by modeling absorption in the layer. " "Saturation increases at shallower angles, as the light travels farther " - "through the medium (depending on the Coat IOR)"); + "through the medium (depending on the Coat IOR)") + .translation_context(BLT_I18NCONTEXT_ID_NODETREE); #define SOCK_COAT_TINT_ID 21 - coat.add_input("Coat Normal").hide_value(); + coat.add_input("Coat Normal").short_label("Normal").hide_value(); #define SOCK_COAT_NORMAL_ID 22 /* Panel for Sheen settings. */ PanelDeclarationBuilder &sheen = b.add_panel("Sheen").default_closed(true); sheen.add_input("Sheen Weight") + .short_label("Weight") .default_value(0.0f) .min(0.0f) .max(1.0f) .subtype(PROP_FACTOR); #define SOCK_SHEEN_WEIGHT_ID 23 sheen.add_input("Sheen Roughness") + .short_label("Roughness") .default_value(0.5f) .min(0.0f) .max(1.0f) .subtype(PROP_FACTOR); #define SOCK_SHEEN_ROUGHNESS_ID 24 - sheen.add_input("Sheen Tint").default_value({1.0f, 1.0f, 1.0f, 1.0f}); + sheen.add_input("Sheen Tint") + .short_label("Tint") + .default_value({1.0f, 1.0f, 1.0f, 1.0f}) + .translation_context(BLT_I18NCONTEXT_ID_NODETREE); #define SOCK_SHEEN_TINT_ID 25 /* Panel for Emission settings. */ PanelDeclarationBuilder &emis = b.add_panel("Emission").default_closed(true); - emis.add_input("Emission Color").default_value({1.0f, 1.0f, 1.0f, 1.0f}); + emis.add_input("Emission Color") + .short_label("Color") + .default_value({1.0f, 1.0f, 1.0f, 1.0f}); #define SOCK_EMISSION_ID 26 - emis.add_input("Emission Strength").default_value(0.0).min(0.0f).max(1000000.0f); + emis.add_input("Emission Strength") + .short_label("Strength") + .default_value(0.0) + .min(0.0f) + .max(1000000.0f); #define SOCK_EMISSION_STRENGTH_ID 27 }