Exemple #1
0
        private void handleFrameChange()
        {
            if (!IsInitialized || ViewModel.CurrentObject == null)
            {
                overworldPic.Source = null;
                return;
            }
            EventObject.Frame currentFrame = ViewModel.CurrentFrame;

            // If the frame is invalid, copy the previous frames and raise an event.
            if (currentFrame == null)
            {
                copyPreviousFrames();
                ViewModel.RaisePropertyChanged("AnimTableIndex");
                ViewModel.RaisePropertyChanged("CurrentFrame");
                return;
            }
            indexCount.Content = "of " + (ViewModel.CurrentObject.Frames.Count - 1);

            BitmapImage fileBitmap = FileUtils.loadBitmapImage(currentFrame.Pic.FullPath);

            // Make sure the object width/height is appropriate for the actual image.
            EventObject currentObject = ViewModel.CurrentObject;

            currentObject.Width  = Math.Min(currentObject.Width, fileBitmap.PixelWidth);
            currentObject.Height = Math.Min(currentObject.Height, fileBitmap.PixelHeight);

            // Set max for framecount.
            spriteFrame.Maximum = ((fileBitmap.PixelWidth / 8) / (spriteWidth.Value / 8)) - 1;
            currentFrame.Index  = Math.Min(currentFrame.Index, (int)spriteFrame.Maximum);

            // Check to see if the width/height of the object is the same as the image.
            if (currentObject.Width == fileBitmap.PixelWidth &&
                currentObject.Height == fileBitmap.PixelHeight)
            {
                overworldPic.Source   = fileBitmap;
                spriteFrame.IsEnabled = false;
                return;
            }

            // Otherwise, slice the image to get the specific frame.
            overworldPic.Source = new CroppedBitmap(fileBitmap, new Int32Rect(
                                                        currentObject.Width * currentFrame.Index, /*y=*/ 0, currentObject.Width,
                                                        currentObject.Height));
            spriteFrame.IsEnabled = true;
        }
Exemple #2
0
        private void copyPreviousFrames()
        {
            int curIndex = ViewModel.AnimTableIndex;
            ObservableCollection <EventObject.Frame> frames = ViewModel.CurrentObject.Frames;
            int neededFrames = (curIndex - frames.Count) + 1;

            if (neededFrames <= 0)
            {
                return;
            }

            EventObject.Frame lastValidFrame = frames[Math.Min(curIndex - 1, frames.Count - 1)];
            int maxFrame = FileUtils.getImageWidth(lastValidFrame.Pic.FullPath);

            maxFrame /= ViewModel.CurrentObject.Width;
            for (int i = 0, e = neededFrames; i < e; ++i)
            {
                frames.Add(new EventObject.Frame()
                {
                    Pic   = lastValidFrame.Pic,
                    Index = Math.Min(maxFrame - 1, lastValidFrame.Index + i + 1)
                });
            }
        }