| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- using UnityEngine;
- using GadgetCore.API;
- using UnityEngine.SceneManagement;
- using GadgetCore.API.ConfigMenu;
- using System;
- using System.Collections.Generic;
- namespace SplashTexts
- {
- [Gadget("SplashTexts")]
- public class SplashTexts : Gadget<SplashTexts>
- {
- public const string MOD_VERSION = "1.0"; // Set this to the version of your mod.
- public const string CONFIG_VERSION = "1.0"; // Increment this whenever you change your mod's config file.
- public override IGadgetConfigMenu GetConfigMenu() { return null; }
- public override string GetModDescription()
- {
- return "A mod that adds random splash texts to the main menu.";
- }
- protected override void Initialize()
- {
- Logger.Log("Platform Block 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 texture2D = GadgetCoreAPI.LoadTexture2D("roguelandsTitle.png");
- private static Texture2D texture2DL = GadgetCoreAPI.LoadTexture2D("roguelandsTitleL2.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;
- if (random.Next(2) == 0)
- {
- renderer.material = new Material(Shader.Find("Unlit/Transparent"))
- {
- mainTexture = texture2DL
- };
- }
- else if (random.Next(2) == 0)
- {
- renderer.material = new Material(Shader.Find("Unlit/Transparent"))
- {
- mainTexture = texture2D
- };
- }
- else
- {
- renderer.material = new Material(Shader.Find("Unlit/Transparent"))
- {
- mainTexture = Core.defaultTitleTexture
- };
- }
- var text = GetText();
- var textElement = GameObject.Find("MAIN").transform.Find("-").Find("txtALPHA").gameObject;
- var textElementShadow = textElement.transform.Find("txt0").gameObject;
- textElement.GetComponent<TextMesh>().color = SpliceColor(ref text);
- var shadowText = SpliceShadow(ref text);
- textElement.GetComponent<TextMesh>().text = text;
- textElementShadow.GetComponent<TextMesh>().text = shadowText;
- }
- catch (Exception e) { Core.logger.LogConsole(e); }
- }
- private static System.Random random = new System.Random();
- private static string GetText()
- {
- List<string> texts = new List<string>();
- texts.Add("v1.5.1 Deluxe");
- texts.Add("#C#AAAAFF#Infinity Edition");
- texts.Add("Gadget Core " + GadgetCoreAPI.GetFullVersion() + " Edition");
- texts.Add("There are mods?");
- texts.Add("1 + 5 = 1#S#1 + 5 = 6");
- texts.Add("v1.5.1#S#v1.5");
- texts.Add("Magicite 2");
- texts.Add("I wouldn't talk to the guy with the pickaxe.");
- return texts[random.Next(texts.Count)];
- }
- private static Color SpliceColor(ref string s)
- {
- if (s.StartsWith("#C#"))
- {
- try
- {
- var ar = s.Split(new char[] { '#' }, 4);
- s = ar[3];
- if (ar[2].Length == 6)
- {
- var i1 = Convert.ToInt32(ar[2].Substring(0, 2), 16);
- var i2 = Convert.ToInt32(ar[2].Substring(2, 2), 16);
- var i3 = Convert.ToInt32(ar[2].Substring(4, 2), 16);
- return new Color(((float)i1) / 0xFF, ((float)i2) / 0xFF, ((float)i3) / 0xFF);
- }
- }
- catch { }
- }
- return new Color(((float)0xFF) / 0xFF, ((float)0xD7) / 0xFF, ((float)0x31) / 0xFF);
- }
- private static string SpliceShadow(ref string s)
- {
- if (s.Contains("#S#"))
- {
- try
- {
- var ar = s.Split(new string[] { "#S#" }, 2, StringSplitOptions.None);
- s = ar[0];
- return ar[1];
- }
- catch { }
- }
- return s;
- }
- }
- }
|