editor_property_name_processor.cpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. /**************************************************************************/
  2. /* editor_property_name_processor.cpp */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #include "editor_property_name_processor.h"
  31. #include "editor_settings.h"
  32. EditorPropertyNameProcessor *EditorPropertyNameProcessor::singleton = nullptr;
  33. EditorPropertyNameProcessor::Style EditorPropertyNameProcessor::get_default_inspector_style() {
  34. const Style style = (Style)EDITOR_GET("interface/inspector/default_property_name_style").operator int();
  35. if (style == STYLE_LOCALIZED && !is_localization_available()) {
  36. return STYLE_CAPITALIZED;
  37. }
  38. return style;
  39. }
  40. EditorPropertyNameProcessor::Style EditorPropertyNameProcessor::get_settings_style() {
  41. const bool translate = EDITOR_GET("interface/editor/localize_settings");
  42. return translate ? STYLE_LOCALIZED : STYLE_CAPITALIZED;
  43. }
  44. EditorPropertyNameProcessor::Style EditorPropertyNameProcessor::get_tooltip_style(Style p_style) {
  45. return p_style == STYLE_LOCALIZED ? STYLE_CAPITALIZED : STYLE_LOCALIZED;
  46. }
  47. bool EditorPropertyNameProcessor::is_localization_available() {
  48. const Vector<String> forbidden = String("en").split(",");
  49. return forbidden.find(EDITOR_GET("interface/editor/editor_language")) == -1;
  50. }
  51. String EditorPropertyNameProcessor::_capitalize_name(const String &p_name) const {
  52. const Map<String, String>::Element *cached = capitalize_string_cache.find(p_name);
  53. if (cached) {
  54. return cached->value();
  55. }
  56. Vector<String> parts = p_name.split("_", false);
  57. for (int i = 0; i < parts.size(); i++) {
  58. const Map<String, String>::Element *remap = capitalize_string_remaps.find(parts[i]);
  59. if (remap) {
  60. parts.write[i] = remap->get();
  61. } else {
  62. parts.write[i] = parts[i].capitalize();
  63. }
  64. }
  65. const String capitalized = String(" ").join(parts);
  66. capitalize_string_cache[p_name] = capitalized;
  67. return capitalized;
  68. }
  69. String EditorPropertyNameProcessor::process_name(const String &p_name, Style p_style) const {
  70. switch (p_style) {
  71. case STYLE_RAW: {
  72. return p_name;
  73. } break;
  74. case STYLE_CAPITALIZED: {
  75. return _capitalize_name(p_name);
  76. } break;
  77. case STYLE_LOCALIZED: {
  78. return TTRGET(_capitalize_name(p_name));
  79. } break;
  80. }
  81. ERR_FAIL_V_MSG(p_name, "Unexpected property name style.");
  82. }
  83. EditorPropertyNameProcessor::EditorPropertyNameProcessor() {
  84. ERR_FAIL_COND(singleton != nullptr);
  85. singleton = this;
  86. // The following initialization is parsed in `editor/translations/extract.py` with a regex.
  87. // The map name and value definition format should be kept synced with the regex.
  88. capitalize_string_remaps["2d"] = "2D";
  89. capitalize_string_remaps["3d"] = "3D";
  90. capitalize_string_remaps["aa"] = "AA";
  91. capitalize_string_remaps["aabb"] = "AABB";
  92. capitalize_string_remaps["adb"] = "ADB";
  93. capitalize_string_remaps["ao"] = "AO";
  94. capitalize_string_remaps["apk"] = "APK";
  95. capitalize_string_remaps["arm64-v8a"] = "arm64-v8a";
  96. capitalize_string_remaps["armeabi-v7a"] = "armeabi-v7a";
  97. capitalize_string_remaps["arvr"] = "ARVR";
  98. capitalize_string_remaps["bg"] = "BG";
  99. capitalize_string_remaps["bidi"] = "BiDi";
  100. capitalize_string_remaps["bp"] = "BP";
  101. capitalize_string_remaps["bpc"] = "BPC";
  102. capitalize_string_remaps["bptc"] = "BPTC";
  103. capitalize_string_remaps["bvh"] = "BVH";
  104. capitalize_string_remaps["ca"] = "CA";
  105. capitalize_string_remaps["cd"] = "CD";
  106. capitalize_string_remaps["commentfocus"] = "Comment Focus";
  107. capitalize_string_remaps["cpu"] = "CPU";
  108. capitalize_string_remaps["csg"] = "CSG";
  109. capitalize_string_remaps["db"] = "dB";
  110. capitalize_string_remaps["defaultfocus"] = "Default Focus";
  111. capitalize_string_remaps["defaultframe"] = "Default Frame";
  112. capitalize_string_remaps["dof"] = "DoF";
  113. capitalize_string_remaps["dpi"] = "DPI";
  114. capitalize_string_remaps["dtls"] = "DTLS";
  115. capitalize_string_remaps["erp"] = "ERP";
  116. capitalize_string_remaps["etc"] = "ETC";
  117. capitalize_string_remaps["etc2"] = "ETC2";
  118. capitalize_string_remaps["fbx"] = "FBX";
  119. capitalize_string_remaps["fft"] = "FFT";
  120. capitalize_string_remaps["fg"] = "FG";
  121. capitalize_string_remaps["filesystem"] = "FileSystem";
  122. capitalize_string_remaps["fov"] = "FOV";
  123. capitalize_string_remaps["fps"] = "FPS";
  124. capitalize_string_remaps["fs"] = "FS";
  125. capitalize_string_remaps["fsr"] = "FSR";
  126. capitalize_string_remaps["fxaa"] = "FXAA";
  127. capitalize_string_remaps["gdscript"] = "GDScript";
  128. capitalize_string_remaps["ggx"] = "GGX";
  129. capitalize_string_remaps["gi"] = "GI";
  130. capitalize_string_remaps["glb"] = "GLB";
  131. capitalize_string_remaps["gles2"] = "GLES2";
  132. capitalize_string_remaps["gles3"] = "GLES3";
  133. capitalize_string_remaps["gpu"] = "GPU";
  134. capitalize_string_remaps["gui"] = "GUI";
  135. capitalize_string_remaps["guid"] = "GUID";
  136. capitalize_string_remaps["hdr"] = "HDR";
  137. capitalize_string_remaps["hidpi"] = "hiDPI";
  138. capitalize_string_remaps["hipass"] = "High-pass";
  139. capitalize_string_remaps["hseparation"] = "H Separation";
  140. capitalize_string_remaps["hsv"] = "HSV";
  141. capitalize_string_remaps["html"] = "HTML";
  142. capitalize_string_remaps["http"] = "HTTP";
  143. capitalize_string_remaps["id"] = "ID";
  144. capitalize_string_remaps["igd"] = "IGD";
  145. capitalize_string_remaps["ik"] = "IK";
  146. capitalize_string_remaps["image@2x"] = "Image @2x";
  147. capitalize_string_remaps["image@3x"] = "Image @3x";
  148. capitalize_string_remaps["iod"] = "IOD";
  149. capitalize_string_remaps["ios"] = "iOS";
  150. capitalize_string_remaps["ip"] = "IP";
  151. capitalize_string_remaps["ipad"] = "iPad";
  152. capitalize_string_remaps["iphone"] = "iPhone";
  153. capitalize_string_remaps["ipv6"] = "IPv6";
  154. capitalize_string_remaps["ir"] = "IR";
  155. capitalize_string_remaps["itunes"] = "iTunes";
  156. capitalize_string_remaps["jit"] = "JIT";
  157. capitalize_string_remaps["k1"] = "K1";
  158. capitalize_string_remaps["k2"] = "K2";
  159. capitalize_string_remaps["kb"] = "(KB)"; // Unit.
  160. capitalize_string_remaps["ldr"] = "LDR";
  161. capitalize_string_remaps["lod"] = "LOD";
  162. capitalize_string_remaps["lowpass"] = "Low-pass";
  163. capitalize_string_remaps["macos"] = "macOS";
  164. capitalize_string_remaps["mb"] = "(MB)"; // Unit.
  165. capitalize_string_remaps["mms"] = "MMS";
  166. capitalize_string_remaps["ms"] = "(ms)"; // Unit
  167. capitalize_string_remaps["msaa"] = "MSAA";
  168. capitalize_string_remaps["msdf"] = "MSDF";
  169. // Not used for now as AudioEffectReverb has a `msec` property.
  170. //capitalize_string_remaps["msec"] = "(msec)"; // Unit.
  171. capitalize_string_remaps["navmesh"] = "NavMesh";
  172. capitalize_string_remaps["nfc"] = "NFC";
  173. capitalize_string_remaps["normalmap"] = "Normal Map";
  174. capitalize_string_remaps["ofs"] = "Offset";
  175. capitalize_string_remaps["ok"] = "OK";
  176. capitalize_string_remaps["opengl"] = "OpenGL";
  177. capitalize_string_remaps["opentype"] = "OpenType";
  178. capitalize_string_remaps["openxr"] = "OpenXR";
  179. capitalize_string_remaps["pck"] = "PCK";
  180. capitalize_string_remaps["png"] = "PNG";
  181. capitalize_string_remaps["po2"] = "(Power of 2)"; // Unit.
  182. capitalize_string_remaps["pvrtc"] = "PVRTC";
  183. capitalize_string_remaps["pvs"] = "PVS";
  184. capitalize_string_remaps["rgb"] = "RGB";
  185. capitalize_string_remaps["rid"] = "RID";
  186. capitalize_string_remaps["rmb"] = "RMB";
  187. capitalize_string_remaps["rpc"] = "RPC";
  188. capitalize_string_remaps["s3tc"] = "S3TC";
  189. capitalize_string_remaps["sdf"] = "SDF";
  190. capitalize_string_remaps["sdfgi"] = "SDFGI";
  191. capitalize_string_remaps["sdk"] = "SDK";
  192. capitalize_string_remaps["sec"] = "(sec)"; // Unit.
  193. capitalize_string_remaps["selectedframe"] = "Selected Frame";
  194. capitalize_string_remaps["sms"] = "SMS";
  195. capitalize_string_remaps["srgb"] = "sRGB";
  196. capitalize_string_remaps["ssao"] = "SSAO";
  197. capitalize_string_remaps["ssh"] = "SSH";
  198. capitalize_string_remaps["ssil"] = "SSIL";
  199. capitalize_string_remaps["ssl"] = "SSL";
  200. capitalize_string_remaps["stderr"] = "stderr";
  201. capitalize_string_remaps["stdout"] = "stdout";
  202. capitalize_string_remaps["sv"] = "SV";
  203. capitalize_string_remaps["svg"] = "SVG";
  204. capitalize_string_remaps["tcp"] = "TCP";
  205. capitalize_string_remaps["ui"] = "UI";
  206. capitalize_string_remaps["url"] = "URL";
  207. capitalize_string_remaps["urls"] = "URLs";
  208. capitalize_string_remaps["us"] = String::utf8("(µs)"); // Unit.
  209. capitalize_string_remaps["usb"] = "USB";
  210. capitalize_string_remaps["usec"] = String::utf8("(µsec)"); // Unit.
  211. capitalize_string_remaps["uuid"] = "UUID";
  212. capitalize_string_remaps["uv"] = "UV";
  213. capitalize_string_remaps["uv1"] = "UV1";
  214. capitalize_string_remaps["uv2"] = "UV2";
  215. capitalize_string_remaps["uwp"] = "UWP";
  216. capitalize_string_remaps["vadjust"] = "V Adjust";
  217. capitalize_string_remaps["valign"] = "V Align";
  218. capitalize_string_remaps["vector2"] = "Vector2";
  219. capitalize_string_remaps["vpn"] = "VPN";
  220. capitalize_string_remaps["vram"] = "VRAM";
  221. capitalize_string_remaps["vseparation"] = "V Separation";
  222. capitalize_string_remaps["vsync"] = "V-Sync";
  223. capitalize_string_remaps["wap"] = "WAP";
  224. capitalize_string_remaps["webp"] = "WebP";
  225. capitalize_string_remaps["webrtc"] = "WebRTC";
  226. capitalize_string_remaps["websocket"] = "WebSocket";
  227. capitalize_string_remaps["wifi"] = "Wi-Fi";
  228. capitalize_string_remaps["x86"] = "x86";
  229. capitalize_string_remaps["xr"] = "XR";
  230. capitalize_string_remaps["xy"] = "XY";
  231. capitalize_string_remaps["xz"] = "XZ";
  232. capitalize_string_remaps["yz"] = "YZ";
  233. }
  234. EditorPropertyNameProcessor::~EditorPropertyNameProcessor() {
  235. singleton = nullptr;
  236. }