| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- using UnityEngine;
- using GadgetCore.API;
- using UnityEngine.SceneManagement;
- using GadgetCore.API.ConfigMenu;
- using System;
- using System.Collections.Generic;
- using AlternativeTitles.ConfigEnums;
- namespace AlternativeTitles
- {
- [Gadget("AlternativeTitles", RequiredOnClients: false)]
- public class AlternativeTitles : Gadget<AlternativeTitles>
- {
- public const string MOD_VERSION = "1.1"; // Set this to the version of your mod.
- public const string CONFIG_VERSION = "1.1"; // Increment this whenever you change your mod's config file.
- protected override void LoadConfig()
- {
- Config.Load();
- string fileVersion = Config.ReadString("ConfigVersion", CONFIG_VERSION, comments: "The Config Version (not to be confused with mod version)");
- if (fileVersion != CONFIG_VERSION)
- {
- Config.Reset();
- Config.WriteString("ConfigVersion", CONFIG_VERSION, comments: "The Config Version (not to be confused with mod version)");
- }
- Core.settingTitleRarity = Config.ReadEnum("TitleRarity", TitleRarityEnum.Common, comments: new string[] { });
- Core.settingOnOffMagicite = Config.ReadEnum("Magicite", OnOffEnum.On, comments: new string[] { });
- Core.settingOnOffLittlewood = Config.ReadEnum("Littlewood", OnOffEnum.On, comments: new string[] { });
- Core.settingOnOffWraithslayer = Config.ReadEnum("Wraithslayer", OnOffEnum.On, comments: new string[] { });
- Core.settingOnOffForager = Config.ReadEnum("Forager", OnOffEnum.On, comments: new string[] { });
- Config.Save();
- }
- public override string GetModDescription()
- {
- return "A mod that adds random alternative titles to the main menu.";
- }
- protected override void Initialize()
- {
- Logger.Log("Alternative Titles v" + Info.Mod.Version);
- Core.logger = Logger;
- SceneManager.sceneLoaded += OnSceneLoaded;
- ChangeMenuText();
- }
- internal static void OnSceneLoaded(Scene scene, LoadSceneMode mode)
- {
- if (scene.buildIndex == 0)
- {
- ChangeMenuText();
- }
- }
- private static Texture2D texture2DM = GadgetCoreAPI.LoadTexture2D("roguelandsTitleM.png");
- private static Texture2D texture2DL = GadgetCoreAPI.LoadTexture2D("roguelandsTitleL.png");
- private static Texture2D texture2DW = GadgetCoreAPI.LoadTexture2D("roguelandsTitleW.png");
- private static Texture2D texture2DF = GadgetCoreAPI.LoadTexture2D("roguelandsTitleF.png");
- private static void ChangeMenuText()
- {
- try
- {
- var titleElement = GameObject.Find("MAIN").transform.Find("-").gameObject;
- var renderer = titleElement.GetComponent<Renderer>();
- if (Core.defaultTitleTexture == null)
- Core.defaultTitleTexture = renderer.material.mainTexture;
- int i = 8;
- switch (Core.settingTitleRarity)
- {
- case TitleRarityEnum.VeryRare:
- i = 120;
- break;
- case TitleRarityEnum.Rare:
- i = 40;
- break;
- case TitleRarityEnum.Common:
- i = 8;
- break;
- case TitleRarityEnum.VeryCommon:
- i = 2;
- break;
- case TitleRarityEnum.Allways:
- i = 1;
- break;
- }
- renderer.material = new Material(Shader.Find("Unlit/Transparent")) { mainTexture = Core.defaultTitleTexture };
- if (random.Next(i) == 0)
- {
- List<Material> t2ds = new List<Material>();
- if (Core.settingOnOffMagicite == OnOffEnum.On)
- t2ds.Add(new Material(Shader.Find("Unlit/Transparent")) { mainTexture = texture2DM });
- if (Core.settingOnOffLittlewood == OnOffEnum.On)
- t2ds.Add(new Material(Shader.Find("Unlit/Transparent")) { mainTexture = texture2DL });
- if (Core.settingOnOffWraithslayer == OnOffEnum.On)
- t2ds.Add(new Material(Shader.Find("Unlit/Transparent")) { mainTexture = texture2DW });
- if (Core.settingOnOffForager == OnOffEnum.On)
- t2ds.Add(new Material(Shader.Find("Unlit/Transparent")) { mainTexture = texture2DF });
- if (t2ds.Count > 0)
- renderer.material = t2ds[random.Next(t2ds.Count)];
- }
- }
- catch (Exception e) { Core.logger.Log(e); }
- }
- private static System.Random random = new System.Random();
- }
- }
|