From 2255f86e2363d144e3a17db2fa18da161a0e0320 Mon Sep 17 00:00:00 2001 From: GinYuH <72181395+GinYuH@users.noreply.github.com> Date: Sat, 20 Apr 2024 01:32:04 -0700 Subject: [PATCH] mod call --- ILEditing/MechanicILChanges.cs | 4 +- ModSupport/ModCalls.cs | 48 +++++++++++++++++++++++ Systems/WorldSelectionDifficultySystem.cs | 14 +++---- 3 files changed, 57 insertions(+), 9 deletions(-) diff --git a/ILEditing/MechanicILChanges.cs b/ILEditing/MechanicILChanges.cs index 470e7f6b4d..b4e5a2a9ac 100644 --- a/ILEditing/MechanicILChanges.cs +++ b/ILEditing/MechanicILChanges.cs @@ -1375,9 +1375,9 @@ namespace CalamityMod.ILEditing string difficultyText = expertText; Color difficultyColor = gameModeColor; - for (int i = WorldSelectionDifficultySystem.difficulties.Count - 1; i >= 0; i--) + for (int i = WorldSelectionDifficultySystem.WorldDifficulties.Count - 1; i >= 0; i--) { - WorldSelectionDifficultySystem.WorldDifficulty d = WorldSelectionDifficultySystem.difficulties[i]; + WorldSelectionDifficultySystem.WorldDifficulty d = WorldSelectionDifficultySystem.WorldDifficulties[i]; { if (d.function(self)) { diff --git a/ModSupport/ModCalls.cs b/ModSupport/ModCalls.cs index ca2be1f1bb..e73f62e73c 100644 --- a/ModSupport/ModCalls.cs +++ b/ModSupport/ModCalls.cs @@ -16,6 +16,7 @@ using CalamityMod.World; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Terraria; +using Terraria.GameContent.UI.Elements; using Terraria.Localization; using Terraria.ModLoader; @@ -553,6 +554,23 @@ namespace CalamityMod DifficultyModeSystem.Difficulties.Add(newMode); DifficultyModeSystem.CalculateDifficultyData(); } + + public static void AddWorldScreenDifficulty(string name, Func function, Color color, int index = -1) + { + // Construct the difficulty + WorldSelectionDifficultySystem.WorldDifficulty difficulty = new WorldSelectionDifficultySystem.WorldDifficulty(name, function, color); + + // Add the new difficulty + // If no index was provided, just add it to the end of the list, otherwise insert it at the desired spot on the list + if (index == -1) + { + WorldSelectionDifficultySystem.WorldDifficulties.Add(difficulty); + } + else + { + WorldSelectionDifficultySystem.WorldDifficulties.Insert(index, difficulty); + } + } #endregion #region Rogue Class @@ -1168,6 +1186,36 @@ namespace CalamityMod AddCustomDifficulty(mode); return null; + case "AddWorldScreenDifficulty": + case "AddWorldSelectionDifficulty": + { + if (args.Length < 2) + return new ArgumentNullException("ERROR: Must specify a difficulty mode name as a string."); + if (args.Length < 3) + return new ArgumentNullException("ERROR: Must specify a Func."); + if (args.Length < 4) + return new ArgumentNullException("ERROR: Must specify a Color."); + + if (args.Length >= 5) + { + if (!(args[4] is int)) + return new ArgumentException("ERROR: The fourth argument to \"AddWorldScreenDifficulty\" must be an int."); + } + if (!(args[3] is Color color)) + return new ArgumentException("ERROR: The third argument to \"AddWorldScreenDifficulty\" must be a Color."); + if (!(args[2] is Func worldFunction)) + return new ArgumentException("ERROR: The second argument to \"AddWorldScreenDifficulty\" must be a Func."); + if (!(args[1] is string)) + return new ArgumentException("ERROR: The first argument to \"AddWorldScreenDifficulty\" must be a string."); + + if (args.Length >= 5) + AddWorldScreenDifficulty(args[1].ToString(), worldFunction, color, (int)args[4]); + else + AddWorldScreenDifficulty(args[1].ToString(), worldFunction, color); + return null; + } + + case "GetLight": case "GetLightLevel": case "GetLightStrength": diff --git a/Systems/WorldSelectionDifficultySystem.cs b/Systems/WorldSelectionDifficultySystem.cs index d9c052d9dc..a8ac35bee0 100644 --- a/Systems/WorldSelectionDifficultySystem.cs +++ b/Systems/WorldSelectionDifficultySystem.cs @@ -22,12 +22,12 @@ namespace CalamityMod.Systems string legend = CalamityUtils.GetTextValue("UI.Legend"); string plus = "+"; - difficulties.Add(new WorldDifficulty(revenge, GetRevengeance, new(211, 42, 42))); - difficulties.Add(new WorldDifficulty(death, GetDeath, new(192, 64, 219))); - difficulties.Add(new WorldDifficulty(rev + plus + master, GetMasterRevengeance, new(124, 153, 242))); - difficulties.Add(new WorldDifficulty(death + plus + master, GetMasterDeath, new(255, 25, 255))); - difficulties.Add(new WorldDifficulty(rev + plus + legend, GetLegendRevengeance, new(240, 128, 128))); - difficulties.Add(new WorldDifficulty(death + plus + legend, GetLegendDeath, new(220, 255, 132))); + WorldDifficulties.Add(new WorldDifficulty(revenge, GetRevengeance, new(211, 42, 42))); + WorldDifficulties.Add(new WorldDifficulty(death, GetDeath, new(192, 64, 219))); + WorldDifficulties.Add(new WorldDifficulty(rev + plus + master, GetMasterRevengeance, new(124, 153, 242))); + WorldDifficulties.Add(new WorldDifficulty(death + plus + master, GetMasterDeath, new(255, 25, 255))); + WorldDifficulties.Add(new WorldDifficulty(rev + plus + legend, GetLegendRevengeance, new(240, 128, 128))); + WorldDifficulties.Add(new WorldDifficulty(death + plus + legend, GetLegendDeath, new(220, 255, 132))); } // Since CalamityWorld is static, and therefore invalid for TryGetHeaderData, make copies for Rev and Death @@ -39,7 +39,7 @@ namespace CalamityMod.Systems public record WorldDifficulty(string name, Func function, Color color); - public static List difficulties = new List(); + public static List WorldDifficulties = new List(); public static bool GetRevengeance(AWorldListItem item) { if (item.Data.TryGetHeaderData(out TagCompound tag))