RecipePage.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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. }
  63. return this;
  64. }
  65. /// <summary>
  66. /// Used to register the page to repalce a vanilla one and make it show.
  67. /// </summary>
  68. public virtual RecipePage RegisterAsVanilla(int i)
  69. {
  70. PostRegister();
  71. switch (Type)
  72. {
  73. case RecipePageType.GearForge:
  74. Core.pageGearForgeInfoListVanilla[i] = this;
  75. break;
  76. case RecipePageType.AlchemyStation:
  77. Core.pageAlchemyStationInfoListVanilla[i] = this;
  78. break;
  79. case RecipePageType.UltimateForge:
  80. Core.pageUltimateForgeInfoListVanilla[i] = this;
  81. break;
  82. }
  83. return this;
  84. }
  85. protected void PostRegister()
  86. {
  87. if (Mat == null)
  88. {
  89. Mat = new Material(Shader.Find("Unlit/Transparent"))
  90. {
  91. mainTexture = Tex
  92. };
  93. }
  94. else
  95. {
  96. Tex = Mat.mainTexture;
  97. }
  98. }
  99. /// <summary>
  100. /// Used to register the RecipePage to make it show up.
  101. /// </summary>
  102. public RecipePageType GetEntryType()
  103. {
  104. return Type;
  105. }
  106. /// <summary>
  107. /// Adds a new RecipePageEntry to the RecipePage.
  108. /// </summary>
  109. public void AddRecipePageEntry(RecipePageEntry row)
  110. {
  111. Rows.Add(row);
  112. }
  113. /// <summary>
  114. /// Returns the list of avalible RecipePageEntry on this RecipePage.
  115. /// </summary>
  116. public RecipePageEntry[] GetRecipePageEntries()
  117. {
  118. return Rows.ToArray();
  119. }
  120. }
  121. /// <summary>
  122. /// This indicates what types of recipes are avalible.
  123. /// </summary>
  124. public enum RecipePageType
  125. {
  126. /// <summary>
  127. /// This recipe is for the Gear Forge.
  128. /// </summary>
  129. GearForge,
  130. /// <summary>
  131. /// This recipe is for the Alchemy Station.
  132. /// </summary>
  133. AlchemyStation,
  134. /// <summary>
  135. /// This recipe is for the Ultimate Forge.
  136. /// </summary>
  137. UltimateForge
  138. }
  139. }