using System.Collections.Generic; using UnityEngine; namespace RecipeMenuCore.API { /// /// Defines a custom RecipePage. Make sure to call Register on it to enable your RecipePage and to add at least one RecipePageEntry using AddRecipePageEntry. /// public class RecipePage { /// /// The RecipePageType of this RecipePage /// public readonly RecipePageType Type; /// /// The id of this crafter for RecipePageType = Custom /// public readonly string CrafterId; /// /// The Title displayed on top of this RecipePage. /// public readonly string Title; /// /// The Texture associated with this RecipePage. May be null. /// public Texture Tex { get; protected set; } /// /// The Material associated with this RecipePage. May be null. /// public Material Mat { get; protected set; } internal List Rows = new List(); /// /// Use to create a new RecipePage. Make sure to call Register on it to enable your RecipePage. /// public RecipePage(RecipePageType Type, string Title, Texture Tex) { if (Type == RecipePageType.Custom) throw new System.Exception("RecipePageType.Custom requires a crafter name to be set."); this.Type = Type; this.Title = Title; this.Tex = Tex; } /// /// Use to create a new RecipePage. Make sure to call Register on it to enable your RecipePage. /// public RecipePage(RecipePageType Type, string Title, Material Mat) { if (Type == RecipePageType.Custom) throw new System.Exception("RecipePageType.Custom requires a crafter name to be set."); this.Type = Type; this.Title = Title; this.Mat = Mat; } /// /// Use to create a new RecipePage. Make sure to call Register on it to enable your RecipePage. /// public RecipePage(RecipePageType Type, string Title, Texture Tex, string CrafterId) { if (Type != RecipePageType.Custom) throw new System.Exception("CrafterId is only used for RecipePageType = Custom."); this.Type = Type; this.Title = Title; this.Tex = Tex; this.CrafterId = CrafterId; } /// /// Use to create a new RecipePage. Make sure to call Register on it to enable your RecipePage. /// public RecipePage(RecipePageType Type, string Title, Material Mat, string CrafterId) { if (Type != RecipePageType.Custom) throw new System.Exception("CrafterId is only used for RecipePageType = Custom."); this.Type = Type; this.Title = Title; this.Mat = Mat; this.CrafterId = CrafterId; } /// /// Used to register the page and make it show. /// public virtual RecipePage Register() { PostRegister(); switch (Type) { case RecipePageType.GearForge: Core.pageGearForgeInfoList.Add(this); break; case RecipePageType.AlchemyStation: Core.pageAlchemyStationInfoList.Add(this); break; case RecipePageType.UltimateForge: Core.pageUltimateForgeInfoList.Add(this); break; case RecipePageType.UniversalCrafter: Core.pageUniversalCrafterInfoList.Add(this); break; case RecipePageType.Custom: if (!Core.pageCustomCrafterInfoLists.ContainsKey(CrafterId)) Core.pageCustomCrafterInfoLists.Add(CrafterId, new List()); Core.pageCustomCrafterInfoLists[CrafterId].Add(this); break; } return this; } /// /// Used to register the page to repalce a vanilla one and make it show. /// public virtual RecipePage RegisterAsVanilla(int i) { if (Type != RecipePageType.GearForge && Type != RecipePageType.AlchemyStation && Type != RecipePageType.UltimateForge) throw new System.Exception("RegisterAsVanilla can only be used for vanilla crafters."); PostRegister(); switch (Type) { case RecipePageType.GearForge: Core.pageGearForgeInfoListVanilla[i] = this; break; case RecipePageType.AlchemyStation: Core.pageAlchemyStationInfoListVanilla[i] = this; break; case RecipePageType.UltimateForge: Core.pageUltimateForgeInfoListVanilla[i] = this; break; } return this; } protected void PostRegister() { if (Mat == null) { Mat = new Material(Shader.Find("Unlit/Transparent")) { mainTexture = Tex }; } else { Tex = Mat.mainTexture; } } /// /// Used to register the RecipePage to make it show up. /// public RecipePageType GetEntryType() { return Type; } /// /// Adds a new RecipePageEntry to the RecipePage. /// public void AddRecipePageEntry(RecipePageEntry row) { if (Type != RecipePageType.Custom && row.IsReverse) throw new System.Exception("Reverse recipes are only supported in custom crafting stations."); Rows.Add(row); } /// /// Returns the list of avalible RecipePageEntry on this RecipePage. /// public RecipePageEntry[] GetRecipePageEntries() { return Rows.ToArray(); } } /// /// This indicates what types of recipes are avalible. /// public enum RecipePageType { /// /// This recipe is for the Gear Forge. /// GearForge, /// /// This recipe is for the Alchemy Station. /// AlchemyStation, /// /// This recipe is for the Ultimate Forge. /// UltimateForge, /// /// This recipe is for the Gadget Core Universal Crafter. /// UniversalCrafter, /// /// This recipe is for a custom Crafter. /// Custom } }