Esempio n. 1
0
        public override void Update(GameTime gameTime)
        {
            if (gameTime == null)
            {
                return;
            }

            SpriteManager.Update(gameTime);

            // Timeline is updated here because monogame has a nice update loop and delta time system just sitting here waiting for us.
            if (TimeLineInfo.isPlaying)
            {
                TimeLineInfo.timelineMs += gameTime.ElapsedGameTime.TotalMilliseconds;

                if (TimeLineInfo.timelineMs > TimeLine.timeLine.TimeLineEnd * 16)
                {
                    float msDifference = ((float)TimeLineInfo.timelineMs) - ((float)TimeLine.timeLine.TimeLineEnd * 16);
                    TimeLineInfo.timelineMs = TimeLine.timeLine.TimeLineEnd * 16;

                    if (MainWindow.project.GetProjectInfo().Loop)
                    {
                        TimeLineInfo.timelineMs = MainWindow.project.GetProjectInfo().LoopToFrame * 16 + msDifference;
                    }
                    else
                    {
                        TimeLineInfo.isPlaying = false;
                    }
                }

                Canvas.SetLeft(MainWindow.mainWindow.MainTimeline.Scrubber, (TimeLineInfo.timelineMs / 16) * MainWindow.mainWindow.MainTimeline.ScreenScale);
                if (TimeLine.timeLine != null)
                {
                    TimeLine.timeLine.DisplayAtScrubber();
                }
            }

            // Make scrubber's height correct
            MainWindow.mainWindow.MainTimeline.Scrubber.Height = MainWindow.mainWindow.MainTimeline.TimeLineCanvas.ActualHeight;

            foreach (UIElement c in MainWindow.mainWindow.MainTimeline.TimeLineCanvas.Children)
            {
                Keyframe keyframe = c as Keyframe;

                // If keyframe is null, that means the object is not a type of keyframe.
                if (keyframe != null)
                {
                    Canvas.SetLeft(c, (keyframe.PositionX * MainWindow.mainWindow.MainTimeline.ScreenScale) - (keyframe.ActualWidth / 2) - (MainWindow.mainWindow.MainTimeline.GetRealScreenOffset()));
                }
            }

            // Resize timeline so scrolling works
            int greatestX = 0;

            foreach (FrameworkElement element in TimeLine.timeLine.TimeLineCanvas.Children)
            {
                if (Canvas.GetLeft(element) + TimeLine.timeLine.TimeLineEndPadding > greatestX)
                {
                    greatestX = (int)Canvas.GetLeft(element) + TimeLine.timeLine.TimeLineEndPadding;
                }
            }
            TimeLine.timeLine.TimeLineCanvas.Width  = greatestX;
            TimeLine.timeLine.TimeLineCanvas.Margin = new Thickness(0, TimeLine.timeLine.TimeLineCanvas.Margin.Top, TimeLine.timeLine.TimeLineCanvas.Margin.Right, TimeLine.timeLine.TimeLineCanvas.Margin.Bottom);
            TimeLine.timeLine.TimeLineCanvas.HorizontalAlignment = HorizontalAlignment.Left;

            // World mouse position, used for transforming wpf mouse coords into coordinates relative to the world and camera.
            worldMousePosition = Vector2.Transform(new Vector2(_mouseX, _mouseY), Matrix.Invert(MainCamera.Transform));

            if (sidebarVisible && sidebarCoords < 0)
            {
                sidebarCoords = Lerp(sidebarCoords, 1f, 0.1f);
                if (sidebarCoords > 0)
                {
                    sidebarCoords = 0;
                }
            }
            if (!sidebarVisible)
            {
                sidebarCoords = Lerp(sidebarCoords, -33f, 0.1f);
                if (sidebarCoords < -32)
                {
                    sidebarCoords = -32;
                }
            }

            // Selection
            if (sprBoxSelected != "enginereserved_null")
            {
                foreach (KeyValuePair <string, Spritebox> pair in previewObject.GetSpriteBoxes())
                {
                    if (pair.Key == sprBoxSelected)
                    {
                        selectionBox.SetBoundObject(pair.Value);
                        if (_shouldUpdateProperties)
                        {
                            MainWindow.mainWindow.Properties.UpdateFields();
                            _shouldUpdateProperties = false;
                        }
                    }
                }
            }
            else
            {
                selectionBox.SetBoundObject(null);
                if (_shouldUpdateProperties)
                {
                    MainWindow.mainWindow.Properties.UpdateFields();
                    _shouldUpdateProperties = false;
                }
            }
            MainCamera.UpdateCamera(GraphicsDevice.Viewport, gameTime);
        }