LocEdString.cs 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. using bs;
  4. namespace bs.Editor
  5. {
  6. /** @addtogroup GUI-Editor
  7. * @{
  8. */
  9. /// <summary>
  10. /// Helper object that creates a localized string in the editor-specific string table. Allows easier separation between
  11. /// editor and game string tables.
  12. /// </summary>
  13. internal class LocEdString
  14. {
  15. // Note: This must match C++ HEString::ENGINE_STRING_TABLE_ID
  16. private const int EDITOR_STRING_TABLE_ID = 30000;
  17. private LocString internalString;
  18. /// <summary>
  19. /// Creates a new empty localized string in the editor string table.
  20. /// </summary>
  21. public LocEdString()
  22. {
  23. internalString = new LocString(EDITOR_STRING_TABLE_ID);
  24. }
  25. /// <summary>
  26. /// Creates a new localized string with the specified identifier in the editor string table. If the identifier
  27. /// doesn't previously exist in the string table, identifier value will also be used for initializing the default
  28. /// language version of the string.
  29. /// </summary>
  30. /// <param name="identifier">String you can use for later referencing the localized string.</param>
  31. public LocEdString(string identifier)
  32. {
  33. internalString = new LocString(identifier, EDITOR_STRING_TABLE_ID);
  34. }
  35. /// <summary>
  36. /// Implicitly converts between an editor localized string and a normal localized string. The normal localized
  37. /// string will still internally reference the editor string table, making it equivalent to the original editor
  38. /// string aside from being different types.
  39. /// </summary>
  40. /// <param name="edString">Editor localized string to convert to normal localized string.</param>
  41. /// <returns>Normal localized string referencing the editor string table.</returns>
  42. public static implicit operator LocString(LocEdString edString)
  43. {
  44. return edString.internalString;
  45. }
  46. /// <summary>
  47. /// Implicity converts between an editor localized string and GUI contents.
  48. /// </summary>
  49. /// <param name="edString">Editor localized string to convert.</param>
  50. /// <returns>GUI contents object that may be used for initializing various GUI elements.</returns>
  51. public static implicit operator GUIContent(LocEdString edString)
  52. {
  53. return new GUIContent(edString.internalString);
  54. }
  55. }
  56. /** @} */
  57. }