|
| 1 | +using HarmonyLib; |
| 2 | +using System.Collections.Generic; |
| 3 | +using UMM; |
| 4 | +using UnityEngine; |
| 5 | +using UnityEngine.SceneManagement; |
| 6 | +using UnityEngine.UI; |
| 7 | + |
| 8 | +namespace BetterWeaponColourMenu |
| 9 | +{ |
| 10 | + [UKPlugin("Better Weapon Colour Menu", "1.0.0", "IDFK WHAT TO PUT HERE :)", true, true)] |
| 11 | + public class BetterWeaponColourMenu : UKMod |
| 12 | + { |
| 13 | + |
| 14 | + public const string GUID = "bot.betterweaponcolourmenu"; |
| 15 | + |
| 16 | + private static Harmony harmony; |
| 17 | + public override void OnModLoaded() |
| 18 | + { |
| 19 | + //Debug.Log("Starting custom arms"); |
| 20 | + harmony = new Harmony(GUID); |
| 21 | + harmony.PatchAll(); |
| 22 | + |
| 23 | + } |
| 24 | + |
| 25 | + private void Start() |
| 26 | + { |
| 27 | + SceneManager.sceneLoaded += SceneManagerOnsceneLoaded; |
| 28 | + } |
| 29 | + |
| 30 | + public override void OnModUnload() |
| 31 | + { |
| 32 | + SceneManager.sceneLoaded -= SceneManagerOnsceneLoaded; |
| 33 | + harmony.UnpatchSelf(); |
| 34 | + base.OnModUnload(); |
| 35 | + } |
| 36 | + |
| 37 | + |
| 38 | + private void SceneManagerOnsceneLoaded(Scene scene, LoadSceneMode mode) |
| 39 | + { |
| 40 | + swapped = false; |
| 41 | + CreateSkinGUI(); |
| 42 | + } |
| 43 | + |
| 44 | + |
| 45 | + string[] windowNames = new string[] { "Revolver", "Shotgun", "Nailgun", "Railcannon", "RocketLauncher" }; |
| 46 | + |
| 47 | + public void CreateSkinGUI() |
| 48 | + { |
| 49 | + foreach (ShopGearChecker shopGearChecker in Resources.FindObjectsOfTypeAll<ShopGearChecker>()) |
| 50 | + { |
| 51 | + |
| 52 | + foreach(var name in windowNames) |
| 53 | + { |
| 54 | + var pannel = shopGearChecker.gameObject.transform.Find($"{name}Window"); |
| 55 | + |
| 56 | + if (pannel == null) |
| 57 | + { |
| 58 | + Debug.LogError($"Could not find {name}Window!!!!"); |
| 59 | + continue; |
| 60 | + } |
| 61 | + |
| 62 | + var colourScreen = pannel.Find("Color Screen"); |
| 63 | + |
| 64 | + if (colourScreen == null) |
| 65 | + { |
| 66 | + Debug.LogError($"Could not find {name}Window Color Screen!!!!"); |
| 67 | + continue; |
| 68 | + } |
| 69 | + |
| 70 | + DoModificationsToPage(colourScreen.Find("Standard").gameObject, name, false); |
| 71 | + DoModificationsToPage(colourScreen.Find("Alternate").gameObject, name, true); |
| 72 | + |
| 73 | + LoadCustomColourPreset(colourScreen.Find("Standard").gameObject, name, false); |
| 74 | + LoadCustomColourPreset(colourScreen.Find("Alternate").gameObject, name, true); |
| 75 | + |
| 76 | + } |
| 77 | + } |
| 78 | + } |
| 79 | + |
| 80 | + public void DoModificationsToPage(GameObject gameObject, string type, bool alt) |
| 81 | + { |
| 82 | + |
| 83 | + var sliders = gameObject.transform.Find("Custom").Find("Unlocked"); |
| 84 | + |
| 85 | + |
| 86 | + foreach (Transform child in sliders.transform) |
| 87 | + { |
| 88 | + Transform copyButton = Instantiate(sliders.parent.parent.parent.Find("Done"), child); |
| 89 | + copyButton.gameObject.name = "Copy"; |
| 90 | + copyButton.localPosition = new Vector3(150, -30, -0.0004f); |
| 91 | + copyButton.localScale = new Vector3(0.4f, 0.5f, 0.4f); |
| 92 | + copyButton.GetComponentInChildren<Text>().text = "COPY COLOR"; |
| 93 | + |
| 94 | + GameObject cAGO = Instantiate(new GameObject(), copyButton.transform); |
| 95 | + cAGO.SetActive(false); |
| 96 | + |
| 97 | + var copyButtonController = copyButton.gameObject.AddComponent<CopyButton>(); |
| 98 | + copyButtonController.activator = cAGO; |
| 99 | + copyButtonController.messagePopupText = "Copied Color!"; |
| 100 | + |
| 101 | + |
| 102 | + copyButton.GetComponent<ShopButton>().toActivate = new GameObject[] { cAGO }; |
| 103 | + copyButton.GetComponent<ShopButton>().toDeactivate = new GameObject[0]; |
| 104 | + |
| 105 | + |
| 106 | + Transform pasteButton = Instantiate(sliders.parent.parent.parent.Find("Done"), child); |
| 107 | + pasteButton.gameObject.name = "Paste"; |
| 108 | + pasteButton.localPosition = new Vector3(150, -50, -0.0004f); |
| 109 | + pasteButton.localScale = new Vector3(0.4f, 0.5f, 0.4f); |
| 110 | + pasteButton.GetComponentInChildren<Text>().text = "PASTE COLOR"; |
| 111 | + |
| 112 | + |
| 113 | + GameObject pAGO = Instantiate(new GameObject(), pasteButton.transform); |
| 114 | + pAGO.SetActive(false); |
| 115 | + |
| 116 | + var pasteButtonController = pasteButton.gameObject.AddComponent<PasteButton>(); |
| 117 | + pasteButtonController.activator = pAGO; |
| 118 | + pasteButtonController.messagePopupText = "Pasted Color!"; |
| 119 | + |
| 120 | + |
| 121 | + pasteButton.GetComponent<ShopButton>().toActivate = new GameObject[] { pAGO }; |
| 122 | + pasteButton.GetComponent<ShopButton>().toDeactivate = new GameObject[0]; |
| 123 | + |
| 124 | + |
| 125 | + Transform randomButton = Instantiate(sliders.parent.parent.parent.Find("Done"), child); |
| 126 | + randomButton.gameObject.name = "Random"; |
| 127 | + randomButton.localPosition = new Vector3(150, -70, -0.0004f); |
| 128 | + randomButton.localScale = new Vector3(0.4f, 0.5f, 0.4f); |
| 129 | + randomButton.GetComponentInChildren<Text>().text = "RANDOMISE COLOR"; |
| 130 | + |
| 131 | + |
| 132 | + GameObject rAGO = Instantiate(new GameObject(), randomButton.transform); |
| 133 | + rAGO.SetActive(false); |
| 134 | + |
| 135 | + var randomButtonController = randomButton.gameObject.AddComponent<RandomButton>(); |
| 136 | + randomButtonController.activator = rAGO; |
| 137 | + randomButtonController.triggerMessage = false; |
| 138 | + |
| 139 | + |
| 140 | + randomButton.GetComponent<ShopButton>().toActivate = new GameObject[] { rAGO }; |
| 141 | + randomButton.GetComponent<ShopButton>().toDeactivate = new GameObject[0]; |
| 142 | + } |
| 143 | + |
| 144 | + var templates = gameObject.transform.Find("Template"); |
| 145 | + |
| 146 | + for(int i = 2; i <= 5; i++) |
| 147 | + { |
| 148 | + var template = templates.Find($"Template {i}"); |
| 149 | + |
| 150 | + template.transform.GetChild(0).localScale = new Vector3(0.75f, 1, 1); |
| 151 | + template.transform.GetChild(0).GetChild(0).localScale = new Vector3(1.5f, 1, 1); |
| 152 | + |
| 153 | + Transform saveButton = Instantiate(sliders.parent.parent.parent.Find("Done"), template); |
| 154 | + |
| 155 | + saveButton.gameObject.name = "Save"; |
| 156 | + saveButton.localPosition = new Vector3(225, -40, -0.0005f); |
| 157 | + saveButton.localScale = new Vector3(0.2f, 1f, 1f); |
| 158 | + saveButton.GetComponentInChildren<Text>().text = "SAVE"; |
| 159 | + saveButton.GetComponentInChildren<Text>().transform.localScale = new Vector3(5f, 1f, 1f); |
| 160 | + |
| 161 | + GameObject sAGO = Instantiate(new GameObject(), saveButton.transform); |
| 162 | + sAGO.SetActive(false); |
| 163 | + |
| 164 | + var saveButtonController = saveButton.gameObject.AddComponent<SaveButton>(); |
| 165 | + saveButtonController.activator = sAGO; |
| 166 | + saveButtonController.messagePopupText = "Overrode Preset!"; |
| 167 | + saveButtonController.index = i - 1; |
| 168 | + saveButtonController.text = template.transform.GetChild(0).GetChild(0).GetComponent<UnityEngine.UI.Text>(); |
| 169 | + saveButtonController.weaponType = type; |
| 170 | + saveButtonController.alt = alt; |
| 171 | + |
| 172 | + |
| 173 | + saveButton.GetComponent<ShopButton>().toActivate = new GameObject[] { sAGO }; |
| 174 | + saveButton.GetComponent<ShopButton>().toDeactivate = new GameObject[0]; |
| 175 | + |
| 176 | + Transform clearButton = Instantiate(sliders.parent.parent.parent.Find("Done"), template); |
| 177 | + |
| 178 | + clearButton.gameObject.name = "Clear"; |
| 179 | + clearButton.localPosition = new Vector3(285, -40, -0.0005f); |
| 180 | + clearButton.localScale = new Vector3(0.2f, 1f, 1f); |
| 181 | + clearButton.GetComponentInChildren<Text>().text = "RESET"; |
| 182 | + clearButton.GetComponentInChildren<Text>().transform.localScale = new Vector3(5f, 1f, 1f); |
| 183 | + |
| 184 | + GameObject cAGO = Instantiate(new GameObject(), clearButton.transform); |
| 185 | + cAGO.SetActive(false); |
| 186 | + |
| 187 | + var clearButtonController = clearButton.gameObject.AddComponent<ClearButton>(); |
| 188 | + clearButtonController.activator = cAGO; |
| 189 | + clearButtonController.messagePopupText = "Reset Preset!"; |
| 190 | + clearButtonController.index = i - 1; |
| 191 | + clearButtonController.text = template.transform.GetChild(0).GetChild(0).GetComponent<UnityEngine.UI.Text>(); |
| 192 | + clearButtonController.weaponType = type; |
| 193 | + |
| 194 | + |
| 195 | + clearButton.GetComponent<ShopButton>().toActivate = new GameObject[] { cAGO }; |
| 196 | + clearButton.GetComponent<ShopButton>().toDeactivate = new GameObject[0]; |
| 197 | + } |
| 198 | + |
| 199 | + sliders.parent.parent.parent.Find("Done").localScale = new Vector3(0.75f, 1f, 1f); |
| 200 | + |
| 201 | + Transform importButton = Instantiate(sliders.parent.parent.parent.Find("Done"), sliders); |
| 202 | + importButton.gameObject.name = "Import"; |
| 203 | + importButton.localPosition = new Vector3(20.0116f, 110f, -0.0004f); |
| 204 | + importButton.localScale = new Vector3(0.4f, 0.5f, 0.4f); |
| 205 | + importButton.GetComponentInChildren<Text>().text = "IMPORT PRESET"; |
| 206 | + |
| 207 | + GameObject iAGO = Instantiate(new GameObject(), importButton.transform); |
| 208 | + iAGO.SetActive(false); |
| 209 | + |
| 210 | + var importButtonController = importButton.gameObject.AddComponent<ImportButton>(); |
| 211 | + importButtonController.activator = iAGO; |
| 212 | + importButtonController.messagePopupText = "Imported!"; |
| 213 | + importButtonController.weaponType = type; |
| 214 | + importButtonController.alt = alt; |
| 215 | + |
| 216 | + |
| 217 | + importButton.GetComponent<ShopButton>().toActivate = new GameObject[] { iAGO }; |
| 218 | + importButton.GetComponent<ShopButton>().toDeactivate = new GameObject[0]; |
| 219 | + |
| 220 | + |
| 221 | + } |
| 222 | + |
| 223 | + public void LoadCustomColourPreset(GameObject gameObject, string weaponType, bool alt) |
| 224 | + { |
| 225 | + for(int i = 1; i < 5; i++) |
| 226 | + { |
| 227 | + |
| 228 | + var template = gameObject.transform.Find("Template").Find($"Template {i + 1}"); |
| 229 | + |
| 230 | + Color[] colours = new Color[3]; |
| 231 | + |
| 232 | + //fucking die |
| 233 | + //if (!(EnsurePersistentModDataExists($"customPresetOverride.{weaponType}.{i}.isCustom", GUID) && UKMod.RetrieveBooleanPersistentModData($"customPresetOverride.{weaponType}.{i}.isCustom", GUID))) continue; |
| 234 | + if (!(EnsurePersistentModDataExists($"customPresetOverride.{weaponType}.{i}.isCustom", GUID) && UKMod.RetrieveBooleanPersistentModData(GUID, $"customPresetOverride.{weaponType}.{i}.isCustom"))) continue; |
| 235 | + |
| 236 | + for (int t = 1; t <= 3; t++) |
| 237 | + { |
| 238 | + float[] rgbColourValues = new float[3]; |
| 239 | + |
| 240 | + for (int c = 0; c < 3; c++) |
| 241 | + { |
| 242 | + EnsurePersistentModDataExists($"customPresetOverride.{weaponType}.{i}.{t}.{rgbValueFromInt[c]}", GUID); |
| 243 | + rgbColourValues[c] = UKMod.RetrieveFloatPersistentModData(GUID, $"customPresetOverride.{weaponType}.{i}.{t}.{rgbValueFromInt[c]}"); |
| 244 | + } |
| 245 | + |
| 246 | + colours[t - 1] = new Color(rgbColourValues[0], rgbColourValues[1], rgbColourValues[2]); |
| 247 | + } |
| 248 | + |
| 249 | + |
| 250 | + |
| 251 | + GunColorPreset newPreset = new GunColorPreset(colours[0], colours[1], colours[2]); |
| 252 | + |
| 253 | + template.transform.GetChild(0).GetChild(0).GetComponent<UnityEngine.UI.Text>().text = "Custom " + i; |
| 254 | + |
| 255 | + switch (weaponType) |
| 256 | + { |
| 257 | + case "Revolver": |
| 258 | + MonoSingleton<GunColorController>.Instance.revolverColors[i] = newPreset; |
| 259 | + break; |
| 260 | + case "Shotgun": |
| 261 | + MonoSingleton<GunColorController>.Instance.shotgunColors[i] = newPreset; |
| 262 | + break; |
| 263 | + case "Nailgun": |
| 264 | + MonoSingleton<GunColorController>.Instance.nailgunColors[i] = newPreset; |
| 265 | + break; |
| 266 | + case "Railcannon": |
| 267 | + MonoSingleton<GunColorController>.Instance.railcannonColors[i] = newPreset; |
| 268 | + break; |
| 269 | + case "RocketLauncher": |
| 270 | + MonoSingleton<GunColorController>.Instance.rocketLauncherColors[i] = newPreset; |
| 271 | + break; |
| 272 | + } |
| 273 | + } |
| 274 | + } |
| 275 | + |
| 276 | + public bool EnsurePersistentModDataExists(string key, string modName) |
| 277 | + { |
| 278 | + //Debug.LogWarning($"{key}: \"{UKMod.RetrieveStringPersistentModData(key, modName)}\""); |
| 279 | + return !string.IsNullOrEmpty(UKMod.RetrieveStringPersistentModData(key, modName)); |
| 280 | + } |
| 281 | + |
| 282 | + public static bool swapped; |
| 283 | + |
| 284 | + Dictionary<int, string> rgbValueFromInt = new Dictionary<int, string>() |
| 285 | + { |
| 286 | + { 0, "r" }, |
| 287 | + { 1, "g" }, |
| 288 | + { 2, "b" }, |
| 289 | + }; |
| 290 | + |
| 291 | + public static Dictionary<string, GunColorPreset[]> baseWeaponPresetColours = new Dictionary<string, GunColorPreset[]>() |
| 292 | + { |
| 293 | + { "Revolver", new GunColorPreset[] { new GunColorPreset(new Color(0, 0, 0), new Color(0, 0, 0), new Color(0.42f, 0.19f, 0)), new GunColorPreset(new Color(0, 0.6f, 1), new Color(0.4f, 0.5f, 0.54f), new Color(0.4f, 0.5f, 0.54f)), new GunColorPreset(new Color(1, 0.24f, 0), new Color(0.25f, 0.25f, 0.25f), new Color(0.25f, 0.25f, 0.25f)), new GunColorPreset(new Color(0.5f, 0f, 0f), new Color(0.25f, 0f, 0f), new Color(0.25f, 0f, 0f)) } }, |
| 294 | + { "Shotgun", new GunColorPreset[] { new GunColorPreset(new Color(0f, 0f, 0f), new Color(0f, 0f, 0f), new Color(0f, 0f, 0f)), new GunColorPreset(new Color(0.6f, 0.6f, 0.6f), new Color(1f, 0.66f, 0f), new Color(1f, 1f, 1f)), new GunColorPreset(new Color(1f, 0.8f, 0.6f), new Color(0.6f, 0.6f, 0.6f), new Color(1f, 0.8f, 0.6f)), new GunColorPreset(new Color(0f, 0f, 0f), new Color(1f, 0.65f, 0f), new Color(0f, 0f, 0f)), } }, |
| 295 | + { "Nailgun", new GunColorPreset[] { new GunColorPreset(new Color(0.6f, 0.6f, 0.6f), new Color(0.6f, 0.6f, 0.6f), new Color(0.33f, 1f, 0f)), new GunColorPreset(new Color(0.12f, 0.48f, 1f), new Color(0.12f, 0.48f, 1f), new Color(0f, 0f, 0f)), new GunColorPreset(new Color(1f, 1f, 1f), new Color(0f, 0f, 0f), new Color(0f, 0f, 0f)), new GunColorPreset(new Color(0f, 0f, 0f), new Color(0.5f, 0f, 0f), new Color(0.5f, 0f, 0f)), } }, |
| 296 | + { "Railcannon", new GunColorPreset[] { new GunColorPreset(new Color(0.88f, 0.88f, 0.88f), new Color(0.25f, 0.45f, 0.7f), new Color(0f, 0.35f, 0.7f)), new GunColorPreset(new Color(0.8f, 0.4f, 0.7f), new Color(0.6f, 0.6f, 0.6f), new Color(0f, 0f, 0f)), new GunColorPreset(new Color(0.6f, 0.6f, 0.6f), new Color(0.6f, 0.6f, 0.6f), new Color(1f, 0f, 0f)), new GunColorPreset(new Color(0.88f, 0.66f, 0f), new Color(0f, 0f, 0f), new Color(0f, 0f, 0f)), } }, |
| 297 | + { "RocketLauncher", new GunColorPreset[] { new GunColorPreset(new Color(0.5f, 0.25f, 0.25f), new Color(1f, 0.85f, 0.6f), new Color(0.65f, 0.65f, 0.65f)), new GunColorPreset(new Color(0.66f, 0.66f, 0.66f), new Color(1f, 0f, 0.42f), new Color(0.44f, 0.44f, 0.44f)), new GunColorPreset(new Color(0.7f, 1f, 0f), new Color(0.6f, 0f, 0.4f), new Color(0.64f, 0f, 0.48f)), new GunColorPreset(new Color(0f, 0f, 0f), new Color(0.32f, 0.2f, 0.6f), new Color(0f, 0f, 0f)), } }, |
| 298 | + }; |
| 299 | + |
| 300 | + } |
| 301 | +} |
0 commit comments