Beispiel #1
0
 private void ClearSheet()
 {
     SpritesList.Children.Clear();
     _outFile = null;
     _sheet   = new RuntimeSpriteSheet();
     _activePreviews.Clear();
     ReloadSheet();
 }
Beispiel #2
0
        private void loadBtn_Click(object sender, RoutedEventArgs e)
        {
            if (_hasChanges)
            {
                var result = MessageBox.Show("Warning!", "You have unsaved changes. Would you like to save them first?",
                                             MessageBoxButton.YesNoCancel);
                if (result == MessageBoxResult.Yes)
                {
                    saveBtn_Click(sender, e);
                }
                if (result == MessageBoxResult.Cancel)
                {
                    return;
                }
            }

            var dlg = new OpenFileDialog();

            dlg.Filter = "MP Tanks Sprite sheets (*.ssjson)|*.ssjson";

            dlg.ShowDialog();

            var path = dlg.FileName;

            if (path == null || !File.Exists(path))
            {
                MessageBox.Show("Error", "Could not load the selected file");
                return; //Couldn't load
            }

            try
            {
                ClearSheet();
                _sheet   = RuntimeSpriteSheet.LoadWithImage(File.ReadAllBytes(path));
                _outFile = path;
                ReloadSheet();
            }
            catch
            {
                MessageBox.Show("Something's wrong with the file you chose; we couldn't load it.");
                return;
            }
        }
Beispiel #3
0
        private void setImgBtn_Click(object sender, RoutedEventArgs e)
        {
            var ofd = new OpenFileDialog();

            ofd.FileName = "Images (*.png, *.jpg, *.gif, *.tiff, *.jpeg)|*.jpeg;*.png;*.gif;*.tiff;*.jpeg";
            ofd.ShowDialog();

            if (ofd.FileName == null || !File.Exists(ofd.FileName))
            {
                MessageBox.Show("Could not find the file specified.");
                return;
            }
            try
            {
                _sheet.Image = RuntimeSpriteSheet.DecodePhoto(File.ReadAllBytes(ofd.FileName));
                ReloadSheet();
            }
            catch
            {
                MessageBox.Show("An unspecified error occurred while trying to load the image.");
            }
        }
        public static RuntimeSpriteSheet Load(JSONSpriteSheet sheet)
        {
            var ss = new RuntimeSpriteSheet();

            foreach (var sprite in sheet.Sprites)
            {
                ss.Sprites.Add(new RuntimeSprite(ss)
                {
                    Name      = sprite.Name,
                    Rectangle = new Rect(sprite.X, sprite.Y, sprite.Width, sprite.Height)
                });
            }
            foreach (var anim in sheet.Animations)
            {
                ss.Animations.Add(new RuntimeAnimation(ss)
                {
                    FrameRate = anim.FrameRate,
                    Name      = anim.Name,
                    Sprites   = anim.Frames.Select(a => ss.Sprites.First(b => b.Name == a)).ToList()
                });
            }

            return(ss);
        }
 public RuntimeAnimation(RuntimeSpriteSheet sheet)
 {
     Parent = sheet;
 }
 public RuntimeSprite(RuntimeSpriteSheet sheet)
 {
     Parent = sheet;
 }