public static float createHatPackage(List <System.Tuple <HatData, HatExtension> > hats, string packageName, float YStart, HatsTab __instance) { float offset = YStart; if (textTemplate != null) { TMPro.TMP_Text title = UnityEngine.Object.Instantiate <TMPro.TMP_Text>(textTemplate, __instance.scroller.Inner); title.transform.parent = __instance.scroller.Inner; title.transform.localPosition = new Vector3(headerX, YStart, inventoryZ); title.alignment = TMPro.TextAlignmentOptions.Center; title.fontSize *= 1.25f; title.fontWeight = TMPro.FontWeight.Thin; title.enableAutoSizing = false; title.autoSizeTextContainer = true; title.text = ModTranslation.getString(packageName); offset -= headerSize * __instance.YOffset; hatsTabCustomTexts.Add(title); } var numHats = hats.Count; for (int i = 0; i < hats.Count; i++) { HatData hat = hats[i].Item1; HatExtension ext = hats[i].Item2; float xpos = __instance.XRange.Lerp((i % __instance.NumPerRow) / (__instance.NumPerRow - 1f)); float ypos = offset - (i / __instance.NumPerRow) * __instance.YOffset; ColorChip colorChip = UnityEngine.Object.Instantiate <ColorChip>(__instance.ColorTabPrefab, __instance.scroller.Inner); int color = __instance.HasLocalPlayer() ? PlayerControl.LocalPlayer.Data.DefaultOutfit.ColorId : SaveManager.BodyColor; colorChip.transform.localPosition = new Vector3(xpos, ypos, inventoryZ); if (ActiveInputManager.currentControlType == ActiveInputManager.InputType.Keyboard) { colorChip.Button.OnMouseOver.AddListener((UnityEngine.Events.UnityAction)(() => __instance.SelectHat(hat))); colorChip.Button.OnMouseOut.AddListener((UnityEngine.Events.UnityAction)(() => __instance.SelectHat(DestroyableSingleton <HatManager> .Instance.GetHatById(SaveManager.LastHat)))); colorChip.Button.OnClick.AddListener((UnityEngine.Events.UnityAction)(() => __instance.ClickEquip())); } else { colorChip.Button.OnClick.AddListener((UnityEngine.Events.UnityAction)(() => __instance.SelectHat(hat))); } colorChip.Inner.SetHat(hat, color); colorChip.Inner.transform.localPosition = hat.ChipOffset; colorChip.Tag = hat; colorChip.Button.ClickMask = __instance.scroller.Hitbox; __instance.ColorChips.Add(colorChip); } return(offset - ((numHats - 1) / __instance.NumPerRow) * __instance.YOffset - headerSize); }
private static HatBehaviour CreateHatBehaviour(CustomHat ch, bool fromDisk = false, bool testOnly = false) { if (hatShader == null && DestroyableSingleton <HatManager> .InstanceExists) { foreach (HatBehaviour h in DestroyableSingleton <HatManager> .Instance.AllHats) { if (h.AltShader != null) { hatShader = h.AltShader; break; } } } HatBehaviour hat = new HatBehaviour(); hat.MainImage = CreateHatSprite(ch.resource, fromDisk); if (ch.backresource != null) { hat.BackImage = CreateHatSprite(ch.backresource, fromDisk); ch.behind = true; // Required to view backresource } if (ch.climbresource != null) { hat.ClimbImage = CreateHatSprite(ch.climbresource, fromDisk); } hat.name = ch.name; hat.Order = 99; hat.ProductId = "hat_" + ch.name.Replace(' ', '_'); hat.InFront = !ch.behind; hat.NoBounce = !ch.bounce; hat.ChipOffset = new Vector2(0f, 0.2f); if (ch.adaptive && hatShader != null) { hat.AltShader = hatShader; } if (!testOnly) { HatExtension extend = new HatExtension(); extend.author = ch.author != null ? ch.author : "Unknown"; extend.package = ch.package != null ? ch.package : "Misc."; extend.condition = ch.condition != null ? ch.condition : "none"; CustomHatRegistry.Add(hat.name, extend); } return(hat); }
private static void Postfix(PlayerPhysics __instance) { AnimationClip currentAnimation = __instance.Animator.GetCurrentAnimation(); if (currentAnimation == __instance.CurrentAnimationGroup.ClimbAnim || currentAnimation == __instance.CurrentAnimationGroup.ClimbDownAnim) { return; } HatParent hp = __instance.myPlayer.HatRenderer; if (hp.Hat == null) { return; } HatExtension extend = hp.Hat.getHatExtension(); if (extend == null) { return; } if (extend.FlipImage != null) { if (__instance.rend.flipX) { hp.FrontLayer.sprite = extend.FlipImage; } else { hp.FrontLayer.sprite = hp.Hat.hatViewData.viewData.MainImage; } } if (extend.BackFlipImage != null) { if (__instance.rend.flipX) { hp.BackLayer.sprite = extend.BackFlipImage; } else { hp.BackLayer.sprite = hp.Hat.hatViewData.viewData.BackImage; } } }
public static bool Prefix(HatsTab __instance) { calcItemBounds(__instance); HatData[] unlockedHats = DestroyableSingleton <HatManager> .Instance.GetUnlockedHats(); Dictionary <string, List <System.Tuple <HatData, HatExtension> > > packages = new Dictionary <string, List <System.Tuple <HatData, HatExtension> > >(); Helpers.destroyList(hatsTabCustomTexts); Helpers.destroyList(__instance.ColorChips); hatsTabCustomTexts.Clear(); __instance.ColorChips.Clear(); textTemplate = PlayerCustomizationMenu.Instance.itemName; foreach (HatData hatData in unlockedHats) { HatExtension ext = hatData.getHatExtension(); if (ext != null) { if (!packages.ContainsKey(ext.package)) { packages[ext.package] = new List <System.Tuple <HatData, HatExtension> >(); } packages[ext.package].Add(new System.Tuple <HatData, HatExtension>(hatData, ext)); } else { if (!packages.ContainsKey(innerslothPackageName)) { packages[innerslothPackageName] = new List <System.Tuple <HatData, HatExtension> >(); } packages[innerslothPackageName].Add(new System.Tuple <HatData, HatExtension>(hatData, null)); } } float YOffset = __instance.YStart; var orderedKeys = packages.Keys.OrderBy((string x) => { if (x == innerslothPackageName) { return(100003); } if (x == "developerHats") { return(10000); } if (x.Contains("gmEdition")) { return(10002); } if (x.Contains("shiune")) { return(10001); } if (x.Contains("01haomingHat")) { return(0); } if (x.Contains("02haomingHat")) { return(1); } return(500); }); foreach (string key in orderedKeys) { List <System.Tuple <HatData, HatExtension> > value = packages[key]; YOffset = createHatPackage(value, key, YOffset, __instance); } __instance.scroller.ContentYBounds.max = -(YOffset + 3.0f + headerSize); return(false); }
private static HatData CreateHatData(CustomHat ch, bool fromDisk = false, bool testOnly = false) { if (hatShader == null && DestroyableSingleton <HatManager> .InstanceExists) { hatShader = new Material(Shader.Find("Unlit/PlayerShader")); } HatData hat = new HatData(); hat.hatViewData.viewData = new HatViewData(); hat.hatViewData.viewData.MainImage = CreateHatSprite(ch.resource, fromDisk); if (ch.backresource != null) { hat.hatViewData.viewData.BackImage = CreateHatSprite(ch.backresource, fromDisk); ch.behind = true; // Required to view backresource } if (ch.climbresource != null) { hat.hatViewData.viewData.ClimbImage = CreateHatSprite(ch.climbresource, fromDisk); } hat.name = ch.name + "\nby " + ch.author; hat.displayOrder = 99; hat.ProductId = "hat_" + ch.name.Replace(' ', '_'); hat.InFront = !ch.behind; hat.NoBounce = !ch.bounce; hat.ChipOffset = new Vector2(0f, 0.2f); hat.Free = true; hat.NotInStore = true; if (ch.adaptive && hatShader != null) { hat.hatViewData.viewData.AltShader = hatShader; } HatExtension extend = new HatExtension(); extend.author = ch.author != null ? ch.author : "Unknown"; extend.package = ch.package != null ? ch.package : "Misc."; extend.condition = ch.condition != null ? ch.condition : "none"; if (ch.flipresource != null) { extend.FlipImage = CreateHatSprite(ch.flipresource, fromDisk); } if (ch.backflipresource != null) { extend.BackFlipImage = CreateHatSprite(ch.backflipresource, fromDisk); } if (testOnly) { TestExt = extend; TestExt.condition = hat.name; } else { CustomHatRegistry.Add(hat.name, extend); } return(hat); }
public static bool Prefix(HatsTab __instance) { PlayerControl.SetPlayerMaterialColors(PlayerControl.LocalPlayer.Data.ColorId, __instance.DemoImage); __instance.HatImage.SetHat(SaveManager.LastHat, PlayerControl.LocalPlayer.Data.ColorId); PlayerControl.SetSkinImage(SaveManager.LastSkin, __instance.SkinImage); PlayerControl.SetPetImage(SaveManager.LastPet, PlayerControl.LocalPlayer.Data.ColorId, __instance.PetImage); HatBehaviour[] unlockedHats = DestroyableSingleton <HatManager> .Instance.GetUnlockedHats(); Dictionary <string, List <System.Tuple <HatBehaviour, HatExtension> > > packages = new Dictionary <string, List <System.Tuple <HatBehaviour, HatExtension> > >(); hatsTabCustomTexts = new List <TMPro.TMP_Text>(); foreach (HatBehaviour hatBehaviour in unlockedHats) { HatExtension ext = hatBehaviour.getHatExtension(); if (ext != null) { if (!packages.ContainsKey(ext.package)) { packages[ext.package] = new List <System.Tuple <HatBehaviour, HatExtension> >(); } packages[ext.package].Add(new System.Tuple <HatBehaviour, HatExtension>(hatBehaviour, ext)); } else { if (!packages.ContainsKey(innerslothPackageName)) { packages[innerslothPackageName] = new List <System.Tuple <HatBehaviour, HatExtension> >(); } packages[innerslothPackageName].Add(new System.Tuple <HatBehaviour, HatExtension>(hatBehaviour, null)); } } float YOffset = __instance.YStart; var hatButton = GameObject.Find("HatButton"); if (hatButton != null && hatButton.transform.FindChild("ButtonText_TMP") != null) { textTemplate = hatButton.transform.FindChild("ButtonText_TMP").GetComponent <TMPro.TMP_Text>(); } var orderedKeys = packages.Keys.OrderBy((string x) => { if (x == innerslothPackageName) { return(1000); } if (x == "Developer Hats") { return(0); } return(500); }); foreach (string key in orderedKeys) { List <System.Tuple <HatBehaviour, HatExtension> > value = packages[key]; YOffset = createHatPackage(value, key, YOffset, __instance); } // __instance.scroller.YBounds.max = -(__instance.YStart - (float)(unlockedHats.Length / this.NumPerRow) * this.YOffset) - 3f; // __instance.scroller.YBounds.max = YOffset * -0.875f; // probably needs to fix up the entire messed math to solve this correctly __instance.scroller.YBounds.max = -(YOffset + 4.1f); return(false); }
public static float createHatPackage(List <System.Tuple <HatBehaviour, HatExtension> > hats, string packageName, float YStart, HatsTab __instance) { bool isDefaultPackage = innerslothPackageName == packageName; float offset = YStart; if (textTemplate != null) { TMPro.TMP_Text title = UnityEngine.Object.Instantiate <TMPro.TMP_Text>(textTemplate, __instance.scroller.Inner); title.transform.localPosition = new Vector3(2.25f, YStart, -1f); title.transform.localScale = Vector3.one * 1.5f; // title.currentFontSize title.fontSize *= 0.5f; title.enableAutoSizing = false; __instance.StartCoroutine(Effects.Lerp(0.1f, new System.Action <float>((p) => { title.SetText(packageName); }))); offset -= 0.8f * __instance.YOffset; hatsTabCustomTexts.Add(title); } for (int i = 0; i < hats.Count; i++) { HatBehaviour hat = hats[i].Item1; HatExtension ext = hats[i].Item2; float xpos = __instance.XRange.Lerp((i % __instance.NumPerRow) / (__instance.NumPerRow - 1f)); float ypos = offset - (i / __instance.NumPerRow) * (isDefaultPackage ? 1f : 1.5f) * __instance.YOffset; ColorChip colorChip = UnityEngine.Object.Instantiate <ColorChip>(__instance.ColorTabPrefab, __instance.scroller.Inner); if (ext != null) { Transform background = colorChip.transform.FindChild("Background"); Transform foreground = colorChip.transform.FindChild("ForeGround"); if (background != null) { background.localScale = new Vector3(1, 1.5f, 1); background.localPosition = Vector3.down * 0.243f; } if (foreground != null) { foreground.localPosition = Vector3.down * 0.243f; } if (textTemplate != null) { TMPro.TMP_Text description = UnityEngine.Object.Instantiate <TMPro.TMP_Text>(textTemplate, colorChip.transform); description.transform.localPosition = new Vector3(0f, -0.75f, -1f); description.transform.localScale = Vector3.one * 0.7f; __instance.StartCoroutine(Effects.Lerp(0.1f, new System.Action <float>((p) => { description.SetText($"{hat.name}\nby {ext.author}"); }))); hatsTabCustomTexts.Add(description); } if (!ext.isUnlocked()) // Hat is locked { UnityEngine.Object.Destroy(colorChip.Button); var overlay = UnityEngine.Object.Instantiate(colorChip.InUseForeground, colorChip.transform); overlay.SetActive(true); } } colorChip.transform.localPosition = new Vector3(xpos, ypos, -1f); colorChip.Button.OnClick.AddListener((UnityEngine.Events.UnityAction)(() => { __instance.SelectHat(hat); })); colorChip.Inner.SetHat(hat, PlayerControl.LocalPlayer.Data.ColorId); colorChip.Inner.transform.localPosition = hat.ChipOffset; colorChip.Tag = hat; __instance.ColorChips.Add(colorChip); } return(offset - ((hats.Count - 1) / __instance.NumPerRow) * (isDefaultPackage ? 1f : 1.5f) * __instance.YOffset - 0.85f); }