LocEdString.cs 2.7 KB

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