AlternativeTitles.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. using UnityEngine;
  2. using GadgetCore.API;
  3. using UnityEngine.SceneManagement;
  4. using GadgetCore.API.ConfigMenu;
  5. using System;
  6. using System.Collections.Generic;
  7. using AlternativeTitles.ConfigEnums;
  8. namespace AlternativeTitles
  9. {
  10. [Gadget("AlternativeTitles", RequiredOnClients: false)]
  11. public class AlternativeTitles : Gadget<AlternativeTitles>
  12. {
  13. public const string MOD_VERSION = "1.1"; // Set this to the version of your mod.
  14. public const string CONFIG_VERSION = "1.1"; // Increment this whenever you change your mod's config file.
  15. protected override void LoadConfig()
  16. {
  17. Config.Load();
  18. string fileVersion = Config.ReadString("ConfigVersion", CONFIG_VERSION, comments: "The Config Version (not to be confused with mod version)");
  19. if (fileVersion != CONFIG_VERSION)
  20. {
  21. Config.Reset();
  22. Config.WriteString("ConfigVersion", CONFIG_VERSION, comments: "The Config Version (not to be confused with mod version)");
  23. }
  24. Core.settingTitleRarity = Config.ReadEnum("TitleRarity", TitleRarityEnum.Common, comments: new string[] { });
  25. Core.settingOnOffMagicite = Config.ReadEnum("Magicite", OnOffEnum.On, comments: new string[] { });
  26. Core.settingOnOffLittlewood = Config.ReadEnum("Littlewood", OnOffEnum.On, comments: new string[] { });
  27. Core.settingOnOffWraithslayer = Config.ReadEnum("Wraithslayer", OnOffEnum.On, comments: new string[] { });
  28. Core.settingOnOffForager = Config.ReadEnum("Forager", OnOffEnum.On, comments: new string[] { });
  29. Config.Save();
  30. }
  31. public override string GetModDescription()
  32. {
  33. return "A mod that adds random alternative titles to the main menu.";
  34. }
  35. protected override void Initialize()
  36. {
  37. Logger.Log("Alternative Titles v" + Info.Mod.Version);
  38. Core.logger = Logger;
  39. SceneManager.sceneLoaded += OnSceneLoaded;
  40. ChangeMenuText();
  41. }
  42. internal static void OnSceneLoaded(Scene scene, LoadSceneMode mode)
  43. {
  44. if (scene.buildIndex == 0)
  45. {
  46. ChangeMenuText();
  47. }
  48. }
  49. private static Texture2D texture2DM = GadgetCoreAPI.LoadTexture2D("roguelandsTitleM.png");
  50. private static Texture2D texture2DL = GadgetCoreAPI.LoadTexture2D("roguelandsTitleL.png");
  51. private static Texture2D texture2DW = GadgetCoreAPI.LoadTexture2D("roguelandsTitleW.png");
  52. private static Texture2D texture2DF = GadgetCoreAPI.LoadTexture2D("roguelandsTitleF.png");
  53. private static void ChangeMenuText()
  54. {
  55. try
  56. {
  57. var titleElement = GameObject.Find("MAIN").transform.Find("-").gameObject;
  58. var renderer = titleElement.GetComponent<Renderer>();
  59. if (Core.defaultTitleTexture == null)
  60. Core.defaultTitleTexture = renderer.material.mainTexture;
  61. int i = 8;
  62. switch (Core.settingTitleRarity)
  63. {
  64. case TitleRarityEnum.VeryRare:
  65. i = 120;
  66. break;
  67. case TitleRarityEnum.Rare:
  68. i = 40;
  69. break;
  70. case TitleRarityEnum.Common:
  71. i = 8;
  72. break;
  73. case TitleRarityEnum.VeryCommon:
  74. i = 2;
  75. break;
  76. case TitleRarityEnum.Allways:
  77. i = 1;
  78. break;
  79. }
  80. renderer.material = new Material(Shader.Find("Unlit/Transparent")) { mainTexture = Core.defaultTitleTexture };
  81. if (random.Next(i) == 0)
  82. {
  83. List<Material> t2ds = new List<Material>();
  84. if (Core.settingOnOffMagicite == OnOffEnum.On)
  85. t2ds.Add(new Material(Shader.Find("Unlit/Transparent")) { mainTexture = texture2DM });
  86. if (Core.settingOnOffLittlewood == OnOffEnum.On)
  87. t2ds.Add(new Material(Shader.Find("Unlit/Transparent")) { mainTexture = texture2DL });
  88. if (Core.settingOnOffWraithslayer == OnOffEnum.On)
  89. t2ds.Add(new Material(Shader.Find("Unlit/Transparent")) { mainTexture = texture2DW });
  90. if (Core.settingOnOffForager == OnOffEnum.On)
  91. t2ds.Add(new Material(Shader.Find("Unlit/Transparent")) { mainTexture = texture2DF });
  92. if (t2ds.Count > 0)
  93. renderer.material = t2ds[random.Next(t2ds.Count)];
  94. }
  95. }
  96. catch (Exception e) { Core.logger.Log(e); }
  97. }
  98. private static System.Random random = new System.Random();
  99. }
  100. }