RecipePage.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. using System.Collections.Generic;
  2. using UnityEngine;
  3. namespace RecipeMenuCore.API
  4. {
  5. /// <summary>
  6. /// Defines a custom RecipePage. Make sure to call Register on it to enable your RecipePage and to add at least one RecipePageEntry using AddRecipePageEntry.
  7. /// </summary>
  8. public class RecipePage
  9. {
  10. /// <summary>
  11. /// The RecipePageType of this RecipePage
  12. /// </summary>
  13. public readonly RecipePageType Type;
  14. /// <summary>
  15. /// The Title displayed on top of this RecipePage.
  16. /// </summary>
  17. public readonly string Title;
  18. /// <summary>
  19. /// The Texture associated with this RecipePage. May be null.
  20. /// </summary>
  21. public Texture Tex { get; protected set; }
  22. /// <summary>
  23. /// The Material associated with this RecipePage. May be null.
  24. /// </summary>
  25. public Material Mat { get; protected set; }
  26. internal List<RecipePageEntry> Rows = new List<RecipePageEntry>();
  27. /// <summary>
  28. /// Use to create a new RecipePage. Make sure to call Register on it to enable your RecipePage.
  29. /// </summary>
  30. public RecipePage(RecipePageType Type, string Title, Texture Tex)
  31. {
  32. this.Type = Type;
  33. this.Title = Title;
  34. this.Tex = Tex;
  35. }
  36. /// <summary>
  37. /// Use to create a new RecipePage. Make sure to call Register on it to enable your RecipePage.
  38. /// </summary>
  39. public RecipePage(RecipePageType Type, string Title, Material Mat)
  40. {
  41. this.Type = Type;
  42. this.Title = Title;
  43. this.Mat = Mat;
  44. }
  45. /// <summary>
  46. /// Used to register the page and make it show.
  47. /// </summary>
  48. public virtual RecipePage Register()
  49. {
  50. PostRegister();
  51. switch (Type)
  52. {
  53. case RecipePageType.GearForge:
  54. Core.pageGearForgeInfoList.Add(this);
  55. break;
  56. case RecipePageType.AlchemyStation:
  57. Core.pageAlchemyStationInfoList.Add(this);
  58. break;
  59. case RecipePageType.UltimateForge:
  60. Core.pageUltimateForgeInfoList.Add(this);
  61. break;
  62. case RecipePageType.UniversalCrafter:
  63. Core.pageUniversalCrafterInfoList.Add(this);
  64. break;
  65. }
  66. return this;
  67. }
  68. /// <summary>
  69. /// Used to register the page to repalce a vanilla one and make it show.
  70. /// </summary>
  71. public virtual RecipePage RegisterAsVanilla(int i)
  72. {
  73. PostRegister();
  74. switch (Type)
  75. {
  76. case RecipePageType.GearForge:
  77. Core.pageGearForgeInfoListVanilla[i] = this;
  78. break;
  79. case RecipePageType.AlchemyStation:
  80. Core.pageAlchemyStationInfoListVanilla[i] = this;
  81. break;
  82. case RecipePageType.UltimateForge:
  83. Core.pageUltimateForgeInfoListVanilla[i] = this;
  84. break;
  85. }
  86. return this;
  87. }
  88. protected void PostRegister()
  89. {
  90. if (Mat == null)
  91. {
  92. Mat = new Material(Shader.Find("Unlit/Transparent"))
  93. {
  94. mainTexture = Tex
  95. };
  96. }
  97. else
  98. {
  99. Tex = Mat.mainTexture;
  100. }
  101. }
  102. /// <summary>
  103. /// Used to register the RecipePage to make it show up.
  104. /// </summary>
  105. public RecipePageType GetEntryType()
  106. {
  107. return Type;
  108. }
  109. /// <summary>
  110. /// Adds a new RecipePageEntry to the RecipePage.
  111. /// </summary>
  112. public void AddRecipePageEntry(RecipePageEntry row)
  113. {
  114. Rows.Add(row);
  115. }
  116. /// <summary>
  117. /// Returns the list of avalible RecipePageEntry on this RecipePage.
  118. /// </summary>
  119. public RecipePageEntry[] GetRecipePageEntries()
  120. {
  121. return Rows.ToArray();
  122. }
  123. }
  124. /// <summary>
  125. /// This indicates what types of recipes are avalible.
  126. /// </summary>
  127. public enum RecipePageType
  128. {
  129. /// <summary>
  130. /// This recipe is for the Gear Forge.
  131. /// </summary>
  132. GearForge,
  133. /// <summary>
  134. /// This recipe is for the Alchemy Station.
  135. /// </summary>
  136. AlchemyStation,
  137. /// <summary>
  138. /// This recipe is for the Ultimate Forge.
  139. /// </summary>
  140. UltimateForge,
  141. /// <summary>
  142. /// This recipe is for the Gadget Core Universal Crafter.
  143. /// </summary>
  144. UniversalCrafter
  145. }
  146. }