Пример #1
0
        private static HatBehaviour CreateHatBehaviour(CustomHat ch, bool fromDisk = false)
        {
            HatBehaviour hat = new HatBehaviour();

            hat.MainImage = CreateHatSprite(ch.resource, fromDisk);
            if (ch.backresource != null)
            {
                hat.BackImage = CreateHatSprite(ch.backresource, fromDisk);
            }
            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.35f);

            if (ch.adaptive && hatShader != null)
            {
                hat.AltShader = hatShader;
            }

            return(hat);
        }
Пример #2
0
 public static CustomHats.HatExtension getHatExtension(this HatBehaviour hat)
 {
     CustomHats.HatExtension ret = null;
     if (CustomHats.TestExt != null && CustomHats.TestExt.condition.Equals(hat.name))
     {
         return(CustomHats.TestExt);
     }
     CustomHats.CustomHatRegistry.TryGetValue(hat.name, out ret);
     return(ret);
 }
Пример #3
0
        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);
        }
Пример #4
0
        static void Postfix()
        {
            SoundManager.Instance.PlaySound(Main.Instance.Assets.HPTheme, false, 1f);

            foreach (UnityEngine.Sprite customHat in Main.Instance.Assets.AllCustomHats)
            {
                HatBehaviour newHat = UnityEngine.Object.Instantiate(HatManager.Instance.AllHats[0]);
                newHat.MainImage = customHat;
                System.Console.WriteLine(customHat.name);
                if (customHat.name != "hat (6)")
                {
                    newHat.NoBounce = true;
                }
                HatManager.Instance.AllHats.Insert(1, newHat);
            }
        }
Пример #5
0
            private static HatBehaviour CreateHat(Stream texture, string id)
            {
                HatMod.Logger.LogMessage($"Creating Hat: {id}");
                HatBehaviour newHat        = new HatBehaviour();
                Texture2D    tex           = new Texture2D(2, 2, TextureFormat.ARGB32, false);
                float        pixelsPerUnit = 225f;

                byte[] hatTexture = new byte[texture.Length];
                texture.Read(hatTexture, 0, (int)texture.Length);
                LoadImage(tex, hatTexture, false);
                newHat.MainImage = Sprite.Create(
                    tex,
                    new Rect(0, 0, tex.width, tex.height),
                    new Vector2(0.5f, 0.8f),
                    pixelsPerUnit
                    );
                newHat.ProductId = $"+{id}";
                newHat.InFront   = true;
                newHat.NoBounce  = true;

                return(newHat);
            }
Пример #6
0
            private static HatBehaviour CreateHat(Stream texture, string id, int order)
            {
                HatMod.Logger.LogMessage($"Creating Hat: {id}");
                HatBehaviour newHat = new HatBehaviour();
                Texture2D    tex    = new Texture2D(2, 2, TextureFormat.ARGB32, false);

                byte[] hatTexture = new byte[texture.Length];
                texture.Read(hatTexture, 0, (int)texture.Length);
                LoadImage(tex, hatTexture, false);
                newHat.MainImage = Sprite.Create(
                    tex,
                    new Rect(0, 0, tex.width, tex.height),
                    new Vector2(0.53f, 0.575f),
                    tex.width * 0.375f
                    );
                newHat.Order     = order + 99;
                newHat.ProductId = id;
                newHat.InFront   = true;
                newHat.NoBounce  = true;

                return(newHat);
            }
Пример #7
0
            public static bool Prefix(HatManager __instance)
            {
                float        pixelsPerUnit = 270f;
                HatBehaviour newhat        = new HatBehaviour();
                Texture2D    tex           = new Texture2D(2, 2, TextureFormat.ARGB32, false);
                Assembly     assembly      = Assembly.GetExecutingAssembly();
                Stream       myStream      = assembly.GetManifestResourceStream("simplehat.png");

                byte[] buttonTexture = new byte[myStream.Length];
                myStream.Read(buttonTexture, 0, (int)myStream.Length);
                LoadImage(tex, buttonTexture, false);
                newhat.MainImage = Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), new Vector2(0.5f, 0.5f), pixelsPerUnit);
                newhat.ProductId = "hat_apple";
                newhat.InFront   = true;
                newhat.NoBounce  = true;
                if (!hatadded)
                {
                    __instance.AllHats.Add(newhat);
                    hatadded = true;
                }
                return(true);
            }
Пример #8
0
            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);
            }
Пример #9
0
 public static CustomHats.HatExtension getHatExtension(this HatBehaviour hat)
 {
     CustomHats.HatExtension ret = null;
     CustomHats.CustomHatRegistry.TryGetValue(hat.name, out ret);
     return(ret);
 }