protected override void Draw(GameTime gameTime)
        {
            float frameRate = 1 / (float)gameTime.ElapsedGameTime.TotalSeconds;
            int   TickCount = Environment.TickCount;
            float delta     = gameTime.ElapsedGameTime.Milliseconds / 1000f;

            MouseState mouseState          = mouseCursor.MouseState;
            int        mouseXRelativeToMap = mouseState.X - mapShiftX;
            int        mouseYRelativeToMap = mouseState.Y - mapShiftY;

            //System.Diagnostics.Debug.WriteLine("Mouse relative to map: X {0}, Y {1}", mouseXRelativeToMap, mouseYRelativeToMap);

            //GraphicsDevice.Clear(ClearOptions.Target, Color.Black, 1.0f, 0); // Clear the window to black
            GraphicsDevice.Clear(Color.Black);

            spriteBatch.Begin(
                SpriteSortMode.Immediate, // spine :( needs to be drawn immediately to maintain the layer orders
                                          //SpriteSortMode.Deferred,
                BlendState.NonPremultiplied, null, null, null, null, Matrix.CreateScale(RenderObjectScaling));
            //skeletonMeshRenderer.Begin();

            // Back Backgrounds
            backgrounds_back.ForEach(bg =>
            {
                bg.Draw(spriteBatch, skeletonMeshRenderer, gameTime,
                        mapShiftX, mapShiftY, mapBoard.CenterPoint.X, mapBoard.CenterPoint.Y,
                        RenderWidth, RenderHeight, RenderObjectScaling, mapRenderResolution,
                        TickCount);
            });

            // Map objects
            foreach (List <BaseItem> mapItem in mapObjects)
            {
                foreach (BaseItem item in mapItem)
                {
                    item.Draw(spriteBatch, skeletonMeshRenderer, gameTime,
                              mapShiftX, mapShiftY, mapBoard.CenterPoint.X, mapBoard.CenterPoint.Y,
                              RenderWidth, RenderHeight, RenderObjectScaling, mapRenderResolution,
                              TickCount);
                }
            }
            // Portals
            foreach (PortalItem portalItem in mapObjects_Portal)
            {
                portalItem.Draw(spriteBatch, skeletonMeshRenderer, gameTime,
                                mapShiftX, mapShiftY, mapBoard.CenterPoint.X, mapBoard.CenterPoint.Y,
                                RenderWidth, RenderHeight, RenderObjectScaling, mapRenderResolution,
                                TickCount);
            }

            // Reactors
            foreach (ReactorItem reactorItem in mapObjects_Reactors)
            {
                reactorItem.Draw(spriteBatch, skeletonMeshRenderer, gameTime,
                                 mapShiftX, mapShiftY, mapBoard.CenterPoint.X, mapBoard.CenterPoint.Y,
                                 RenderWidth, RenderHeight, RenderObjectScaling, mapRenderResolution,
                                 TickCount);
            }

            // Life (NPC + Mobs)
            foreach (MobItem mapMob in mapObjects_Mobs) // Mobs
            {
                mapMob.Draw(spriteBatch, skeletonMeshRenderer, gameTime,
                            mapShiftX, mapShiftY, mapBoard.CenterPoint.X, mapBoard.CenterPoint.Y,
                            RenderWidth, RenderHeight, RenderObjectScaling, mapRenderResolution,
                            TickCount);
            }
            foreach (NpcItem mapNpc in mapObjects_NPCs) // NPCs (always in front of mobs)
            {
                mapNpc.Draw(spriteBatch, skeletonMeshRenderer, gameTime,
                            mapShiftX, mapShiftY, mapBoard.CenterPoint.X, mapBoard.CenterPoint.Y,
                            RenderWidth, RenderHeight, RenderObjectScaling, mapRenderResolution,
                            TickCount);
            }

            // Front Backgrounds
            backgrounds_front.ForEach(bg =>
            {
                bg.Draw(spriteBatch, skeletonMeshRenderer, gameTime,
                        mapShiftX, mapShiftY, mapBoard.CenterPoint.X, mapBoard.CenterPoint.Y,
                        RenderWidth, RenderHeight, RenderObjectScaling, mapRenderResolution,
                        TickCount);
            });

            // Borders
            // Create any rectangle you want. Here we'll use the TitleSafeArea for fun.
            //Rectangle titleSafeRectangle = GraphicsDevice.Viewport.TitleSafeArea;
            //DrawBorder(spriteBatch, titleSafeRectangle, 1, Color.Black);

            //////////////////// UI related here ////////////////////
            // Tooltips
            foreach (TooltipItem tooltip in mapObjects_tooltips) // NPCs (always in front of mobs)
            {
                if (tooltip.TooltipInstance.CharacterToolTip != null)
                {
                    Rectangle tooltipRect = tooltip.TooltipInstance.CharacterToolTip.Rectangle;
                    if (tooltipRect != null) // if this is null, show it at all times
                    {
                        Rectangle rect = new Rectangle(
                            tooltipRect.X - ((mapShiftX) - mapBoard.CenterPoint.X),
                            tooltipRect.Y - ((mapShiftY) - mapBoard.CenterPoint.Y),
                            tooltipRect.Width, tooltipRect.Height);

#if SIMULATOR_DEBUG_INFO_EXTRAS
                        DrawBorder(spriteBatch, rect, 1, Color.White); // test
                        spriteBatch.DrawString(font_DebugValues, "X: " + rect.X + ", Y: " + rect.Y, new Vector2(rect.X, rect.Y), Color.White);
#endif

                        if (!rect.Contains(mouseState.X, mouseState.Y))
                        {
                            continue;
                        }
                    }
                }

                tooltip.Draw(spriteBatch, skeletonMeshRenderer, gameTime,
                             mapShiftX, mapShiftY, mapBoard.CenterPoint.X, mapBoard.CenterPoint.Y,
                             RenderWidth, RenderHeight, RenderObjectScaling, mapRenderResolution,
                             TickCount);
            }

            // Minimap
            miniMap.Draw(spriteBatch, skeletonMeshRenderer, gameTime,
                         mapShiftX, mapShiftY, minimapPos.X, minimapPos.Y,
                         RenderWidth, RenderHeight, RenderObjectScaling, mapRenderResolution,
                         TickCount);

            if (gameTime.TotalGameTime.TotalSeconds < 3)
            {
                spriteBatch.DrawString(font_navigationKeysHelper, "Press [Left] [Right] [Up] [Down] [Shift] [Alt+Enter] [PrintSc] for navigation.", new Vector2(20, 10), Color.White);
            }


#if SIMULATOR_DEBUG_INFO
            StringBuilder sb = new StringBuilder();
            sb.Append("FPS: ").Append(frameRate).Append(Environment.NewLine);
            sb.Append("Mouse : X ").Append(mouseXRelativeToMap).Append(", Y ").Append(mouseYRelativeToMap).Append(Environment.NewLine);
            sb.Append("RMouse: X ").Append(mouseState.X).Append(", Y ").Append(mouseState.Y);
            spriteBatch.DrawString(font_DebugValues, sb.ToString(), new Vector2(RenderWidth - 170, 10), Color.White);
#endif


            // Cursor [this is in front of everything else]
            mouseCursor.Draw(spriteBatch, skeletonMeshRenderer, gameTime,
                             0, 0, 0, 0, // pos determined in the class
                             RenderWidth, RenderHeight, RenderObjectScaling, mapRenderResolution, TickCount);

            spriteBatch.End();
            //skeletonMeshRenderer.End();


            // Save screenshot if render is activated
            DoScreenshot();


            base.Draw(gameTime);
        }
Exemple #2
0
        protected override void Draw(GameTime gameTime)
        {
            float frameRate = 1 / (float)gameTime.ElapsedGameTime.TotalSeconds;
            int   TickCount = currTickCount;
            //float delta = gameTime.ElapsedGameTime.Milliseconds / 1000f;

            MouseState mouseState          = this.oldMouseState;
            int        mouseXRelativeToMap = mouseState.X - mapShiftX;
            int        mouseYRelativeToMap = mouseState.Y - mapShiftY;
            //System.Diagnostics.Debug.WriteLine("Mouse relative to map: X {0}, Y {1}", mouseXRelativeToMap, mouseYRelativeToMap);

            int mapCenterX     = mapBoard.CenterPoint.X;
            int mapCenterY     = mapBoard.CenterPoint.Y;
            int shiftCenteredX = mapShiftX - mapCenterX;
            int shiftCenteredY = mapShiftY - mapCenterY;

            //GraphicsDevice.Clear(ClearOptions.Target, Color.Black, 1.0f, 0); // Clear the window to black
            GraphicsDevice.Clear(Color.Black);

            spriteBatch.Begin(
                SpriteSortMode.Immediate, // spine :( needs to be drawn immediately to maintain the layer orders
                                          //SpriteSortMode.Deferred,
                BlendState.NonPremultiplied, null, null, null, null, this.matrixScale);
            //skeletonMeshRenderer.Begin();

            // Back Backgrounds
            backgrounds_back.ForEach(bg =>
            {
                bg.Draw(spriteBatch, skeletonMeshRenderer, gameTime,
                        mapShiftX, mapShiftY, mapCenterX, mapCenterY,
                        null,
                        RenderWidth, RenderHeight, RenderObjectScaling, mapRenderResolution,
                        TickCount);
            });

            // Map objects
            foreach (List <BaseDXDrawableItem> mapItem in mapObjects)
            {
                foreach (BaseDXDrawableItem item in mapItem)
                {
                    item.Draw(spriteBatch, skeletonMeshRenderer, gameTime,
                              mapShiftX, mapShiftY, mapCenterX, mapCenterY,
                              null,
                              RenderWidth, RenderHeight, RenderObjectScaling, mapRenderResolution,
                              TickCount);
                }
            }
            // Portals
            foreach (PortalItem portalItem in mapObjects_Portal)
            {
                portalItem.Draw(spriteBatch, skeletonMeshRenderer, gameTime,
                                mapShiftX, mapShiftY, mapCenterX, mapCenterY,
                                null,
                                RenderWidth, RenderHeight, RenderObjectScaling, mapRenderResolution,
                                TickCount);
            }

            // Reactors
            foreach (ReactorItem reactorItem in mapObjects_Reactors)
            {
                reactorItem.Draw(spriteBatch, skeletonMeshRenderer, gameTime,
                                 mapShiftX, mapShiftY, mapCenterX, mapCenterY,
                                 null,
                                 RenderWidth, RenderHeight, RenderObjectScaling, mapRenderResolution,
                                 TickCount);
            }

            // Life (NPC + Mobs)
            foreach (MobItem mapMob in mapObjects_Mobs) // Mobs
            {
                ReflectionDrawableBoundary mirrorFieldData = null;
                if (mirrorBottomReflection != null)
                {
                    if (rect_mirrorBottom.Contains(new Point(mapMob.MobInstance.X, mapMob.MobInstance.Y)))
                    {
                        mirrorFieldData = mirrorBottomReflection;
                    }
                }
                if (mirrorFieldData == null) // a field may contain both 'info/mirror_Bottom' and 'MirrorFieldData'
                {
                    mirrorFieldData = mapBoard.BoardItems.CheckObjectWithinMirrorFieldDataBoundary(mapMob.MobInstance.X, mapMob.MobInstance.Y, MirrorFieldDataType.mob)?.ReflectionInfo;
                }

                mapMob.Draw(spriteBatch, skeletonMeshRenderer, gameTime,
                            mapShiftX, mapShiftY, mapCenterX, mapCenterY,
                            mirrorFieldData,
                            RenderWidth, RenderHeight, RenderObjectScaling, mapRenderResolution,
                            TickCount);
            }
            foreach (NpcItem mapNpc in mapObjects_NPCs) // NPCs (always in front of mobs)
            {
                ReflectionDrawableBoundary mirrorFieldData = null;
                if (mirrorBottomReflection != null)
                {
                    if (rect_mirrorBottom.Contains(new Point(mapNpc.NpcInstance.X, mapNpc.NpcInstance.Y)))
                    {
                        mirrorFieldData = mirrorBottomReflection;
                    }
                }
                if (mirrorFieldData == null)  // a field may contain both 'info/mirror_Bottom' and 'MirrorFieldData'
                {
                    mirrorFieldData = mapBoard.BoardItems.CheckObjectWithinMirrorFieldDataBoundary(mapNpc.NpcInstance.X, mapNpc.NpcInstance.Y, MirrorFieldDataType.npc)?.ReflectionInfo;
                }

                mapNpc.Draw(spriteBatch, skeletonMeshRenderer, gameTime,
                            mapShiftX, mapShiftY, mapCenterX, mapCenterY,
                            mirrorFieldData,
                            RenderWidth, RenderHeight, RenderObjectScaling, mapRenderResolution,
                            TickCount);
            }

            // Front Backgrounds
            backgrounds_front.ForEach(bg =>
            {
                bg.Draw(spriteBatch, skeletonMeshRenderer, gameTime,
                        mapShiftX, mapShiftY, mapCenterX, mapCenterY,
                        null,
                        RenderWidth, RenderHeight, RenderObjectScaling, mapRenderResolution,
                        TickCount);
            });

            // Borders
            // Create any rectangle you want. Here we'll use the TitleSafeArea for fun.
            //Rectangle titleSafeRectangle = GraphicsDevice.Viewport.TitleSafeArea;
            //DrawBorder(spriteBatch, titleSafeRectangle, 1, Color.Black);

            DrawVRFieldBorder(spriteBatch);

            //////////////////// UI related here ////////////////////
            // Tooltips
            if (mapObjects_tooltips.Count > 0)
            {
                foreach (TooltipItem tooltip in mapObjects_tooltips) // NPCs (always in front of mobs)
                {
                    if (tooltip.TooltipInstance.CharacterToolTip != null)
                    {
                        Rectangle tooltipRect = tooltip.TooltipInstance.CharacterToolTip.Rectangle;
                        if (tooltipRect != null) // if this is null, show it at all times
                        {
                            Rectangle rect = new Rectangle(
                                tooltipRect.X - shiftCenteredX,
                                tooltipRect.Y - shiftCenteredY,
                                tooltipRect.Width, tooltipRect.Height);

                            if (bShowDebugMode)
                            {
                                DrawBorder(spriteBatch, rect, 1, Color.White); // test
                                spriteBatch.DrawString(font_DebugValues, "X: " + rect.X + ", Y: " + rect.Y, new Vector2(rect.X, rect.Y), Color.White);
                            }

                            if (!rect.Contains(mouseState.X, mouseState.Y))
                            {
                                continue;
                            }
                        }
                    }

                    tooltip.Draw(spriteBatch, skeletonMeshRenderer, gameTime,
                                 mapShiftX, mapShiftY, mapBoard.CenterPoint.X, mapBoard.CenterPoint.Y,
                                 null,
                                 RenderWidth, RenderHeight, RenderObjectScaling, mapRenderResolution,
                                 TickCount);
                }
            }

            // Minimap
            if (miniMap != null)
            {
                miniMap.Draw(spriteBatch, skeletonMeshRenderer, gameTime,
                             mapShiftX, mapShiftY, minimapPos.X, minimapPos.Y,
                             null,
                             RenderWidth, RenderHeight, RenderObjectScaling, mapRenderResolution,
                             TickCount);

                miniMap.CheckMouseEvent(shiftCenteredX, shiftCenteredY, mouseState);
            }

            if (gameTime.TotalGameTime.TotalSeconds < 4)
            {
                spriteBatch.DrawString(font_navigationKeysHelper,
                                       string.Format("[Left] [Right] [Up] [Down] [Shift] for navigation.{0}[F5] for debug mode{1}[Alt+Enter] Full screen{2}[PrintSc] Screenshot",
                                                     Environment.NewLine, Environment.NewLine, Environment.NewLine),
                                       new Vector2(20, Height - 140), Color.White);
            }

            if (!bSaveScreenshot && bShowDebugMode)
            {
                StringBuilder sb = new StringBuilder();
                sb.Append("FPS: ").Append(frameRate).Append(Environment.NewLine);
                sb.Append("Mouse : X ").Append(mouseXRelativeToMap).Append(", Y ").Append(mouseYRelativeToMap).Append(Environment.NewLine);
                sb.Append("RMouse: X ").Append(mouseState.X).Append(", Y ").Append(mouseState.Y);
                spriteBatch.DrawString(font_DebugValues, sb.ToString(),
                                       new Vector2(Width - 170, 10), Color.White); // use the original width to render text
            }

            // Cursor [this is in front of everything else]
            mouseCursor.Draw(spriteBatch, skeletonMeshRenderer, gameTime,
                             0, 0, 0, 0, // pos determined in the class
                             null,
                             RenderWidth, RenderHeight, RenderObjectScaling, mapRenderResolution, TickCount);

            spriteBatch.End();
            //skeletonMeshRenderer.End();

            // Save screenshot if render is activated
            DoScreenshot();


            base.Draw(gameTime);
        }