コード例 #1
0
        public void OpenProject(string path)
        {
            Stream projectStream;

            if ((projectStream = File.OpenRead(path)) != null)
            {
                project.ProjectPath = $"{path}";
                projectStream.Dispose();
            }

            TimeLine.timeLine.ClearKeyframes();

            foreach (Animation animation in project.GetProjectInfo().animations)
            {
                Dictionary <string, Spritebox> spriteBoxes = new Dictionary <string, Spritebox>();

                foreach (KeyValuePair <string, SpriteboxJson> pair in animation.spriteBoxes)
                {
                    SpriteboxJson spritebox = pair.Value;

                    spriteBoxes.Add(pair.Key, Spritebox.FromJsonElement(spritebox));
                }

                TimeLine.timeLine.AddKeyframe(new Keyframe(animation.timelineX, 0, spriteBoxes, TimeLine.timeLine));
            }

            TimeLine.timeLine.TimeLineEnd = project.GetProjectInfo().TimelineEnd;
        }
コード例 #2
0
        // Create new keyframe button
        private void Button_Click_2(object sender, RoutedEventArgs e)
        {
            int keyFramePos = (int)Math.Floor(TimeLineInfo.timelineMs / 16);

            Dictionary <string, Spritebox> sprBoxes = new Dictionary <string, Spritebox>();

            foreach (KeyValuePair <string, Spritebox> pair in MainWindowViewModel.MonogameWindow.GetPreviewObject().GetSpriteBoxes())
            {
                SpriteboxJson jsonSpr   = Spritebox.ToJsonElement(pair.Value);
                Spritebox     spriteBox = Spritebox.FromJsonElement(jsonSpr);
                string        newKey    = pair.Key.Substring(0, pair.Key.Length);
                sprBoxes.Add(newKey, spriteBox);
            }
            List <Keyframe> toRemove = new List <Keyframe>();

            foreach (Keyframe frame in _KeyFrames)
            {
                if (frame.PositionX == keyFramePos)
                {
                    toRemove.Add(frame);
                }
            }

            foreach (Keyframe frame in toRemove)
            {
                RemoveKeyframe(frame);
            }

            Keyframe newFrame = new Keyframe(keyFramePos, 0, sprBoxes, this);

            AddKeyframe(newFrame);
        }
コード例 #3
0
        /// <summary>
        /// Displays current animation in preview window.
        /// </summary>
        public void DisplayAtScrubber()
        {
            int closestKeyframeTo       = -1;
            int closestKeyframeDistance = -1;

            MainWindowViewModel.MonogameWindow.setSprBoxSelected("enginereserved_null");

            if (_KeyFrames.Count > 0)
            {
                for (int i = 0; i < _KeyFrames.Count; i++)
                {
                    int      scrubberPos  = (int)Math.Floor(TimeLineInfo.timelineMs / 16);
                    Keyframe currentFrame = _KeyFrames.ElementAt(i);

                    bool isValid = true;

                    if (currentFrame.PositionX > scrubberPos)
                    {
                        isValid = false;
                    }

                    if (isValid)
                    {
                        if (closestKeyframeDistance == -1)
                        {
                            closestKeyframeDistance = Math.Abs(scrubberPos - _KeyFrames.ElementAt(i).PositionX);
                            closestKeyframeTo       = i;
                        }
                        else
                        {
                            if (Math.Abs(scrubberPos - _KeyFrames.ElementAt(i).PositionX) < closestKeyframeDistance)
                            {
                                closestKeyframeDistance = Math.Abs(scrubberPos - _KeyFrames.ElementAt(i).PositionX);
                                closestKeyframeTo       = i;
                            }
                        }
                    }
                }
            }

            if (closestKeyframeTo >= 0 && _KeyFrames.Count > 0)
            {
                Keyframe originalKeyframe = _KeyFrames.ElementAt(closestKeyframeTo);

                Dictionary <string, Spritebox> sprBoxes = new Dictionary <string, Spritebox>();

                foreach (KeyValuePair <string, Spritebox> pair in originalKeyframe.GetSpriteBoxes())
                {
                    SpriteboxJson jsonSpr   = Spritebox.ToJsonElement(pair.Value);
                    Spritebox     spriteBox = Spritebox.FromJsonElement(jsonSpr);
                    string        newKey    = pair.Key.Substring(0, pair.Key.Length);
                    sprBoxes.Add(newKey, spriteBox);
                }

                MainWindowViewModel.MonogameWindow.GetPreviewObject().SetSpriteBoxes(sprBoxes);
            }

            MainWindow.mainWindow.Properties.UpdateSpriteTree();
        }
コード例 #4
0
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            // Open project
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.Filter = "PestControl Engine Animation Project (*.animproj)|*.animproj|All files (*.*)|*.*";
            if (openFileDialog.ShowDialog() == true)
            {
                Stream projectStream;

                if ((projectStream = openFileDialog.OpenFile()) != null)
                {
                    MainWindow.project.ProjectPath = $"{openFileDialog.FileName}";
                    projectStream.Dispose();
                }

                Close();

                TimeLine.timeLine.GetKeyframes().Clear();

                foreach (Animation animation in MainWindow.project.GetProjectInfo().animations)
                {
                    Dictionary <string, Spritebox> spriteBoxes = new Dictionary <string, Spritebox>();

                    foreach (KeyValuePair <string, SpriteboxJson> pair in animation.spriteBoxes)
                    {
                        SpriteboxJson spritebox = pair.Value;

                        spriteBoxes.Add(pair.Key, Spritebox.FromJsonElement(spritebox));
                    }

                    TimeLine.timeLine.AddKeyframe(new Keyframe(animation.timelineX, 0, spriteBoxes, TimeLine.timeLine));
                }

                TimeLine.timeLine.TimeLineEnd = MainWindow.project.GetProjectInfo().TimelineEnd;

                // If content path was invalid, show error dialog
                if (!Directory.Exists(MainWindow.project.GetProjectInfo().ContentPath))
                {
                    MessageBox.Show("Content Path is invalid or corrupt. No textures will be loaded.", "Content Path missing or corrupt");
                }
            }
        }
コード例 #5
0
        public static void ReadAnimationFile(string filePath, ProjectManager projectManager, TimeLine timeLine)
        {
            FileInfo file = new FileInfo(filePath);

            // Null checking
            if (file == null)
            {
                return;
            }

            if (projectManager == null)
            {
                return;
            }

            if (timeLine == null)
            {
                return;
            }

            BinaryReader binaryReader = new BinaryReader(File.Open(filePath, FileMode.Open));

            // Check if header is correct(basically check if this is even a valid PCAF file.)
            string headerString = binaryReader.ReadString();

            if (headerString == headerName)
            {
                // Clear keyframes in timeline
                timeLine.ClearKeyframes();

                // Ok cool so this file is a PCAF file.
                // Load version number incase this is ever useful(and because we kinda have to push the reader forward for it to read correctly)
                int versionNumber = binaryReader.ReadInt32();

                // Load Project Info
                binaryReader.ReadBoolean();
                binaryReader.ReadInt32();
                binaryReader.ReadString();
                binaryReader.ReadInt32();

                int keyframeCount = binaryReader.ReadInt32();

                for (int i = 0; i < keyframeCount; i++)
                {
                    // Read timeline x coordinate
                    int timelineX = binaryReader.ReadInt32();

                    int spriteboxCount = binaryReader.ReadInt32();

                    Keyframe keyframe = new Keyframe(timelineX, 0, new Dictionary <string, monogame.objects.Spritebox>(), timeLine);

                    for (int j = 0; j < spriteboxCount; j++)
                    {
                        // Get name
                        string name = binaryReader.ReadString();

                        // General properties
                        double posX         = binaryReader.ReadDouble();
                        double posY         = binaryReader.ReadDouble();
                        int    width        = binaryReader.ReadInt32();
                        int    height       = binaryReader.ReadInt32();
                        string textureKey   = binaryReader.ReadString();
                        float  rotation     = binaryReader.ReadSingle();
                        int    sourceX      = binaryReader.ReadInt32();
                        int    sourceY      = binaryReader.ReadInt32();
                        int    sourceWidth  = binaryReader.ReadInt32();
                        int    sourceHeight = binaryReader.ReadInt32();
                        float  layer        = binaryReader.ReadSingle();
                        bool   visible      = binaryReader.ReadBoolean();

                        SpriteboxJson spriteBox = new SpriteboxJson();
                        spriteBox.posX         = posX;
                        spriteBox.posY         = posY;
                        spriteBox.width        = width;
                        spriteBox.height       = height;
                        spriteBox.textureKey   = textureKey;
                        spriteBox.rotation     = rotation;
                        spriteBox.sourceX      = sourceX;
                        spriteBox.sourceY      = sourceY;
                        spriteBox.sourceWidth  = sourceWidth;
                        spriteBox.sourceHeight = sourceHeight;
                        spriteBox.layer        = layer;
                        spriteBox.visible      = visible;

                        keyframe.AddSpriteBox(name, Spritebox.FromJsonElement(spriteBox));
                    }

                    timeLine.AddKeyframe(keyframe);
                }

                MainWindowViewModel.MonogameWindow.setSprBoxSelected("enginereserved_null");
                timeLine.DisplayAtScrubber();
            }

            binaryReader.Dispose();
        }