Beispiel #1
0
        public static UIElement GetCloseButton(Action closingAction)
        {
            (UIHelper.BounceClose as AnimatedTexture2D).Paused       = true;
            (UIHelper.BounceClose as AnimatedTexture2D).CurrentFrame = 0;
            (UIHelper.BounceClose as AnimatedTexture2D).SetSpeed(12);

            return(UIElement.GetImage(UIHelper.BounceClose, Color.White, "CloseBtn", 1, 9, UIHelper.GetTopRight(20, -40, 40)).WithInteractivity(click: (point, right, released, hold, element) =>
            {
                if (released)
                {
                    closingAction?.Invoke();
                }
            }, hover: (point, hoverin, element) =>
            {
                if (hoverin != element.WasHover)
                {
                    Game1.playSound("smallSelect");
                }

                AnimatedTexture2D a = (element.Theme as AnimatedTexture2D);

                if (hoverin)
                {
                    a.Paused = false;
                }
                else
                {
                    a.Paused = true;
                    a.CurrentFrame = 0;
                }
            }));
        }
        private void loadContentPacks()
        {
            if (!Helper.ModRegistry.IsLoaded("Pathoschild.ContentPatcher"))
            {
                return;
            }
            var modData        = Helper.ModRegistry.Get("Pathoschild.ContentPatcher");
            var contentPatcher = (Mod)modData.GetType().GetProperty("Mod", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public).GetValue(modData);

            PyTK.APIs.IScalerAPI ScalerAPI = new PyTK.APIs.PyTKAPI();

            foreach (var pack in contentPatcher.Helper.ContentPacks.GetOwned())
            {
                Content content = pack.ReadJsonFile <Content>("content.json");
                if (content == null)
                {
                    continue;
                }

                foreach (Changes change in content.Changes)
                {
                    if ((change.Action != "Load" && change.Action != "EditImage") || !change.ScaleUp || (change.Action == "Load" && change.OriginalWidth == -1) || change.Target == "")
                    {
                        continue;
                    }

                    if (change.Action == "EditImage" && change.FromFileScaled != "" && change.ToArea.ContainsKey("X") && change.ToArea.ContainsKey("Y") && change.ToArea.ContainsKey("Width") && change.ToArea.ContainsKey("Height"))
                    {
                        change.Target = change.Target.Replace('/', '\\');
                        Texture2D sTex = pack.LoadAsset <Texture2D>(change.FromFileScaled);
                        Texture2D s    = null;

                        if (change.AnimationFrameTime == -1)
                        {
                            s = ScaledTexture2D.FromTexture(PyTK.PyDraw.getRectangle(change.ToArea["Width"], change.ToArea["Height"], Color.White), sTex, sTex.Width / change.OriginalWidth);
                        }
                        else if ((sTex.Width / (float)change.OriginalWidth) is float sc)
                        {
                            s = new AnimatedTexture2D(sTex, (int)(change.ToArea["Width"] * sc), (int)(change.ToArea["Height"] * sc), 60 / change.AnimationFrameTime, true, sc);
                        }

                        ScalerAPI.ReplaceAssetAt(change.Target, new Microsoft.Xna.Framework.Rectangle(change.ToArea["X"], change.ToArea["Y"], change.ToArea["Width"], change.ToArea["Height"]), s);
                    }
                    else if (change.Action == "Load")
                    {
                        Scaler.Assets.AddOrReplace(change.Target, change.OriginalWidth);
                    }
                }
            }
        }
Beispiel #3
0
        public Fighter(Vector2 pos, Texture2D overlay_, AnimatedTexture2D idleAnim_, AnimatedTexture2D punchAnim_, AnimatedTexture2D recoilAnim_, FighterInput input_, HitBox punch_, bool flip_, float speed_, double health_, double power_)
            : base(pos)
        {
            idleAnim   = idleAnim_;
            punchAnim  = punchAnim_;
            recoilAnim = recoilAnim_;

            Vector2 ov = getOverlayPos();

            overlay = new Image((int)ov.X, (int)ov.Y, overlay_);

            input      = input_;
            flip       = flip_;
            speed      = speed_;
            Health     = health_;
            Power      = power_;
            punch      = punch_;
            invulnTime = 0;

            punching       = false;
            gettingPunched = false;
            punch.parent   = this;
        }
        public static void LoadFix(Stream stream, ref Texture2D __result)
        {
            if (stream is FileStream fs && Path.GetFileNameWithoutExtension(fs.Name) is string key)
            {
                bool  scaled     = false;
                bool  animated   = false;
                float scale      = 1f;
                int   tileWidth  = 0;
                int   tileHeight = 0;
                int   fps        = 0;
                bool  loop       = true;

                scaled   = Regex.IsMatch(key, scalePattern);
                animated = Regex.IsMatch(key, animPattern);

                if (!scaled && !animated)
                {
                    return;
                }

                if (!(animated && Regex.Match(key, animPattern) is Match ma &&
                      int.TryParse(ma.Groups[1].Value, out tileWidth) &&
                      int.TryParse(ma.Groups[2].Value, out tileHeight) &&
                      int.TryParse(ma.Groups[3].Value, out fps)))
                {
                    animated = false;
                }

                if (!(scaled && Regex.Match(key, scalePattern) is Match m && float.TryParse(m.Groups[1].Value, out scale)))
                {
                    scaled = false;
                }

                if (scaled && scale == 1f)
                {
                    scaled = false;
                }

                if (animated && tileHeight == -1)
                {
                    tileHeight = __result.Height;
                }

                if (animated && tileWidth == -1)
                {
                    tileWidth = __result.Width;
                }

                if (animated && tileWidth == __result.Width && tileHeight == __result.Height)
                {
                    animated = false;
                }

                if (!scaled && !animated)
                {
                    return;
                }

                if (animated)
                {
                    __result = new AnimatedTexture2D(__result, tileWidth, tileHeight, fps, loop, !scaled ? 1f : scale);
                }
                else if (scaled)
                {
                    __result = ScaledTexture2D.FromTexture(__result.ScaleUpTexture(1f / scale, false), __result, scale);
                }
            }
        }
Beispiel #5
0
        private static void loadAllPortraits()
        {
            foreach (string dir in Directory.EnumerateDirectories(contentFolder))
            {
                string folderName = new DirectoryInfo(dir).Name;

                folders.Add(folderName);
                foreach (string file in Directory.EnumerateFiles(dir, "*.*", SearchOption.TopDirectoryOnly).Where(s => s.EndsWith(".png") || s.EndsWith(".xnb")))
                {
                    string fileName  = Path.GetFileName(file);
                    string name      = Path.GetFileNameWithoutExtension(file).Split(new[] { "_anim_" }, StringSplitOptions.RemoveEmptyEntries)[0];
                    string extention = Path.GetExtension(file).ToLower();

                    if (extention == "xnb")
                    {
                        fileName = name;
                    }

                    Texture2D texture = PortraitureMod.helper.Content.Load <Texture2D>($"Portraits/{folderName}/{fileName}");

                    Texture2D frame  = texture;
                    int       fps    = 12;
                    int       frames = 1;
                    bool      loop   = false;
                    if (fileName.Contains("_anim_"))
                    {
                        string[] fdata = fileName.Split(new[] { "_anim_" }, StringSplitOptions.RemoveEmptyEntries);
                        if (fdata.Length > 1)
                        {
                            frames = int.Parse(fdata[1]);
                        }

                        if (fdata.Length > 2)
                        {
                            fps = int.Parse(fdata[2]);
                        }

                        if (fdata.Length > 3)
                        {
                            loop = fdata[3] == "loop";
                        }

                        if (frames < 1)
                        {
                            frames = 1;
                        }

                        if (fps < 1)
                        {
                            fps = 12;
                        }
                    }

                    double    tileWith = Convert.ToDouble(Math.Max(texture.Width / 2, 64)) / frames;
                    float     scale    = (float)(tileWith / 64);
                    Texture2D scaled   = texture;
                    if (frames == 1 && scale != 1)
                    {
                        scaled = new ScaledTexture2D(texture, scale);
                    }
                    else if (frames > 1)
                    {
                        scaled = new AnimatedTexture2D(texture, texture.Width / frames, texture.Height, fps, loop, scale);
                    }

                    if (!pTextures.ContainsKey(folderName + ">" + name))
                    {
                        pTextures.Add(folderName + ">" + name, scaled);
                    }
                    else
                    {
                        pTextures[folderName + ">" + name] = scaled;
                    }
                }
            }

            var contentPacks = PortraitureMod.helper.ContentPacks.GetOwned();

            foreach (StardewModdingAPI.IContentPack pack in contentPacks)
            {
                string folderName = pack.Manifest.UniqueID;

                folders.Add(folderName);

                foreach (string file in Directory.EnumerateFiles(pack.DirectoryPath, "*.*", SearchOption.TopDirectoryOnly).Where(s => s.EndsWith(".png") || s.EndsWith(".xnb")))
                {
                    string fileName  = Path.GetFileName(file);
                    string name      = Path.GetFileNameWithoutExtension(file);
                    string extention = Path.GetExtension(file).ToLower();

                    if (extention == "xnb")
                    {
                        fileName = name;
                    }
                    Texture2D       texture  = pack.LoadAsset <Texture2D>($"{fileName}");
                    int             tileWith = Math.Max(texture.Width / 2, 64);
                    float           scale    = tileWith / 64;
                    ScaledTexture2D scaled;
                    try
                    {
                        scaled = ScaledTexture2D.FromTexture(Game1.getCharacterFromName(name).Portrait, texture, scale);
                    }
                    catch
                    {
                        scaled = ScaledTexture2D.FromTexture(Game1.getCharacterFromName("Pierre").Portrait, texture, scale);
                    }
                    if (!pTextures.ContainsKey(folderName + ">" + name))
                    {
                        pTextures.Add(folderName + ">" + name, scaled);
                    }
                    else
                    {
                        pTextures[folderName + ">" + name] = scaled;
                    }
                }
            }
        }
 public CharacterButton(int x, int y, AnimatedTexture2D anim_, Texture2D up, Texture2D down) : base(x, y, up, down)
 {
     anim = anim_;
 }