Skip to content

Commit

Permalink
fixed texts and expanded on it
Browse files Browse the repository at this point in the history
  • Loading branch information
Creepler13 committed Dec 18, 2022
1 parent 9b2affa commit 0780ce3
Show file tree
Hide file tree
Showing 7 changed files with 126 additions and 40 deletions.
1 change: 1 addition & 0 deletions CustomLoadingScreens.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="LocalLoadingTipsInfo_Patch.cs" />
<Compile Include="ModMain.cs" />
<Compile Include="Settings.cs" />
<Compile Include="TextureData.cs" />
Expand Down
29 changes: 14 additions & 15 deletions ImageRegistry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ namespace CustomLoadingScreens
{
public class ImageRegistry
{
internal List<TextureData> textData = new List<TextureData>();
internal List<Sprite> images = new List<Sprite>();
internal List<Texture2D> textures = new List<Texture2D>();
internal Dictionary<string, TextureData> textData = new Dictionary<string, TextureData>();
internal Dictionary<string, Sprite> images = new Dictionary<string, Sprite>();
internal Dictionary<string, Texture2D> textures = new Dictionary<string, Texture2D>();

private System.Random rand = new System.Random();
public void load()
Expand All @@ -26,6 +26,8 @@ public void load()
{
if (File.Exists(Imagepath))
{
string fileName = Path.GetFileName(Imagepath).Replace(".", "_");

Bitmap bm = new Bitmap(Imagepath);
Texture2D text = new Texture2D(bm.Width, bm.Height, TextureFormat.ARGB32, false);

Expand All @@ -43,29 +45,26 @@ public void load()
textDat.rawData = text.GetRawTextureData();
textDat.width = text.width;
textDat.height = text.height;
textData.Add(textDat);
textures.Add(text);
textData.Add(fileName, textDat);
textures.Add(fileName, text);
Sprite s = Sprite.Create(text, new Rect(0, 0, text.width, text.height), new Vector2(0.5f, 0.5f));

images.Add(s);
images.Add(fileName, s);

if (!Settings.customText.ContainsKey(fileName))
Settings.customText.Add(fileName, "");

//MelonLoader.MelonLogger.Msg("Loaded img " + Imagepath);
}
}


}
Settings.save();

}

public Sprite getRandomSprite()
{
return images[rand.Next(images.Count)];
}
public Texture2D getRandomTexture()
{
return textures[rand.Next(textures.Count)];

}


}
}
33 changes: 17 additions & 16 deletions LoadingImg_Patch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using UnityEngine;
using UnityEngine.UI;
using System.IO;
using Assets.Scripts.PeroTools.Managers;

namespace CustomLoadingScreens
{
Expand All @@ -28,7 +29,8 @@ public static void Postfix(ref LoadingImg __instance)
if (!Settings.onlyCustomImages)
if (rand.NextDouble() > Settings.customImageProbability) return;

TextureData dat = reg.textData[rand.Next(reg.textData.Count)];
string imageKey = reg.textData.Keys.ElementAt(rand.Next(reg.textData.Keys.Count));
TextureData dat = reg.textData[imageKey];

Texture2D tempText = new Texture2D(dat.width, dat.height, TextureFormat.ARGB32, false);
tempText.LoadRawTextureData(dat.rawData);
Expand Down Expand Up @@ -62,6 +64,20 @@ public static void Postfix(ref LoadingImg __instance)
c.sprite = temp;
}


foreach (Text Text in __instance.GetComponentsInChildren<Text>())
{



if (Settings.useCustomText && Settings.customText[imageKey] != "")
Text.m_Text = Settings.customText[imageKey];
else if (Settings.useRandomText && Settings.randomText.Length != 0) Text.m_Text = Settings.randomText[rand.Next(Settings.randomText.Length)];

}



}

public static bool is43(int x, int y)
Expand All @@ -71,22 +87,7 @@ public static bool is43(int x, int y)

}

[HarmonyPatch(typeof(LoadingTxt), "Start")]
internal class LoadingTxt_Patch
{
private static System.Random rand = new System.Random();

public static void Postfix(ref LoadingTxt __instance)
{
return;
MelonLoader.MelonLogger.Msg("Start");
if (__instance.m_Txt == null) return;
MelonLoader.MelonLogger.Msg(__instance.m_Txt.text);
if (Settings.customText.Length == 0) return;
__instance.m_Txt.text = Settings.customText[rand.Next(Settings.customText.Length)];
}

}


}
35 changes: 35 additions & 0 deletions LocalLoadingTipsInfo_Patch.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using Assets.Scripts.Database;
using HarmonyLib;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine.UI;

namespace CustomLoadingScreens
{
[HarmonyPatch(typeof(LoadingTxt), MethodType.Constructor)]
internal class LocalLoadingTipsInfo_Patch
{

public static List<LoadingTxt> LoadingTxt = new List<LoadingTxt>();
private static System.Random rand = new System.Random();

public static void Postfix(ref LoadingTxt __instance)
{

LoadingTxt.Add(__instance);

/* return;
MelonLoader.MelonLogger.Msg("Start");
if (__instance.m_Txt == null) return;
MelonLoader.MelonLogger.Msg(__instance.m_Txt.text);
if (Settings.customText.Length == 0) return;
__instance.m_Txt.text = Settings.customText[rand.Next(Settings.customText.Length)];
*/
}


}
}
3 changes: 2 additions & 1 deletion ModMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
using System.Threading.Tasks;
using MelonLoader;


namespace CustomLoadingScreens
{
public class ModMain : MelonMod
{

public override void OnApplicationStart()
{


Settings.load();
ImageRegistry reg = new ImageRegistry();
LoadingImg_Patch.reg = reg;
Expand Down
2 changes: 1 addition & 1 deletion Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

[assembly: MelonInfo(typeof(ModMain), "CustomLoadingScreens", "1.0.0", "Creepler13", null)]
[assembly: MelonInfo(typeof(ModMain), "CustomLoadingScreens", "1.1.0", "Creepler13", null)]
[assembly: MelonGame("PeroPeroGames", "MuseDash")]

// Setting ComVisible to false makes the types in this assembly not visible
Expand Down
63 changes: 56 additions & 7 deletions Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ internal class Settings

private static MelonPreferences_Entry<bool> onlyCustomImagesEntry;
private static MelonPreferences_Entry<double> customImageProbabilityEntry;
private static MelonPreferences_Entry<string[]> customTextEntry;
private static MelonPreferences_Entry<bool> useRandomTextEntrys;
private static MelonPreferences_Entry<string[]> randomTextEntry;
private static MelonPreferences_Entry<bool> useCustomTextEntrys;
private static MelonPreferences_Entry<Dictionary<string, string>> customTextEntries;



public static bool onlyCustomImages
{
Expand All @@ -40,26 +45,70 @@ public static double customImageProbability
}
}

public static string[] customText
public static bool useCustomText
{
get
{
return useCustomTextEntrys.Value;
}
set
{
useCustomTextEntrys.Value = value;
}
}

public static bool useRandomText
{
get
{
return customTextEntry.Value;
return useRandomTextEntrys.Value;
}
set
{
customTextEntry.Value = value;
useRandomTextEntrys.Value = value;
}
}

public static Dictionary<string, string> customText
{
get
{
return customTextEntries.Value;
}
set
{
customTextEntries.Value = value;
}
}

public static string[] randomText
{
get
{
return randomTextEntry.Value;
}
set
{
randomTextEntry.Value = value;
}
}

public static void load()
{
category = MelonPreferences.CreateCategory("CustomLoadingScreensSetttings");
category.IsInlined = false;
category.SetFilePath("Userdata/CustomLoadingScreens.cfg", true);
onlyCustomImagesEntry = category.CreateEntry<bool>("onlyCustomImages", true, "onlyCustomImages", "if true only custom images will be Shown during loading screens");
customImageProbabilityEntry = category.CreateEntry<double>("customImageProbability", 0, "customImageProbability", "only important if onlyCustomImages is false.probabilty from 0-1 that decides the chance that a custom image is shown (0 = the same probability as default images)");
customTextEntry = category.CreateEntry<string[]>("customText", new string[0], "customText", "custom text that will be shown during the loading screen");
onlyCustomImagesEntry = category.CreateEntry<bool>("onlyCustomImages", true, "onlyCustomImages", "Custom images will be Shown during loading screens");
customImageProbabilityEntry = category.CreateEntry<double>("customImageProbability", 0, "customImageProbability", "only important if onlyCustomImages is false.\n Probabilty from 0-1 that decides the chance that a custom image is shown (0 = the same probability as default images)");
useRandomTextEntrys = category.CreateEntry<bool>("useRandomTextEntrys", false, "userandomTextEntrys", "images will be shown together with random texts in the Array.");
randomTextEntry = category.CreateEntry<string[]>("randomTextEntrys", new string[0], "randomTextEntrys", "custom text that will randomly be shown during the loading screen (Example : [\"A\",\"B\"])");
useCustomTextEntrys = category.CreateEntry<bool>("useCustomTextEntrys", true, "useCustomTextEntrys", " custom images will be shown together with their set texts. (only if a value is set)");
customTextEntries = category.CreateEntry<Dictionary<string, string>>("customText", new Dictionary<string, string>(), "customText");
}

public static void save()
{
category.SaveToFile();
}

}
Expand Down

0 comments on commit 0780ce3

Please sign in to comment.