A stable modding interface between Techblox and mods https://mod.exmods.org/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

TextBlock.cs 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. using System;
  2. using Gamecraft.Blocks.GUI;
  3. using RobocraftX.Common;
  4. using Svelto.ECS;
  5. using Unity.Mathematics;
  6. using GamecraftModdingAPI;
  7. using GamecraftModdingAPI.Utility;
  8. namespace GamecraftModdingAPI.Blocks
  9. {
  10. public class TextBlock : Block
  11. {
  12. public static TextBlock PlaceNew(float3 position,
  13. float3 rotation = default, BlockColors color = BlockColors.Default, byte darkness = 0,
  14. int uscale = 1, float3 scale = default, Player player = null)
  15. {
  16. if (PlacementEngine.IsInGame && GameState.IsBuildMode())
  17. {
  18. EGID id = PlacementEngine.PlaceBlock(BlockIDs.TextBlock, color, darkness,
  19. position, uscale, scale, player, rotation);
  20. return new TextBlock(id);
  21. }
  22. return null;
  23. }
  24. public TextBlock(EGID id) : base(id)
  25. {
  26. if (!BlockEngine.GetBlockInfoExists<TextBlockDataStruct>(this.Id))
  27. {
  28. throw new BlockTypeException($"Block is not a {this.GetType().Name} block");
  29. }
  30. }
  31. public TextBlock(uint id) : base(new EGID(id, CommonExclusiveGroups.BUILD_TEXT_BLOCK_GROUP))
  32. {
  33. if (!BlockEngine.GetBlockInfoExists<TextBlockDataStruct>(this.Id))
  34. {
  35. throw new BlockTypeException($"Block is not a {this.GetType().Name} block");
  36. }
  37. }
  38. // custom text block properties
  39. /// <summary>
  40. /// The text block's current text.
  41. /// </summary>
  42. public string Text
  43. {
  44. get
  45. {
  46. return BlockEngine.GetBlockInfo<TextBlockDataStruct>(Id).textCurrent;
  47. }
  48. set
  49. {
  50. ref TextBlockDataStruct tbds = ref BlockEngine.GetBlockInfo<TextBlockDataStruct>(Id);
  51. tbds.textCurrent.Set(value);
  52. tbds.textStored.Set(value);
  53. BlockEngine.GetBlockInfo<TextBlockNetworkDataStruct>(Id).newTextBlockStringContent.Set(value);
  54. }
  55. }
  56. /// <summary>
  57. /// The text block's current text block ID (used in ChangeTextBlockCommand).
  58. /// </summary>
  59. public string TextBlockId
  60. {
  61. get
  62. {
  63. return BlockEngine.GetBlockInfo<TextBlockDataStruct>(Id).textBlockID;
  64. }
  65. set
  66. {
  67. BlockEngine.GetBlockInfo<TextBlockDataStruct>(Id).textBlockID.Set(value);
  68. BlockEngine.GetBlockInfo<TextBlockNetworkDataStruct>(Id).newTextBlockID.Set(value);
  69. }
  70. }
  71. }
  72. }