Пример #1
0
        internal static void WorldEditModApi()
        {
            if (!(ScreensManager.GetScreenName(ScreensManager.CurrentScreen) == "Game")) // Выходим, если мы не в игре
            {
                return;
            }

            // Показазывеем контейнер с кнопками, если активирована кнопка WorldEditMenu
            ScreensManager.CurrentScreen.ScreenWidget.FindWidget<StackPanelWidget>("WorldEditMenuContainerTop", true).IsVisible = ScreensManager.CurrentScreen.ScreenWidget.FindWidget<BitmapButtonWidget>("WorldEditMenu", true).IsChecked;
            ScreensManager.CurrentScreen.ScreenWidget.FindWidget<StackPanelWidget>("WorldEditMenuContainerBottom", true).IsVisible = ScreensManager.CurrentScreen.ScreenWidget.FindWidget<BitmapButtonWidget>("WorldEditMenu", true).IsChecked;

            // Смена режима управления
            if (ScreensManager.CurrentScreen.ScreenWidget.FindWidget<BitmapButtonWidget>("WorldEditMenu", true).IsTapped)
            {
               if (ScreensManager.CurrentScreen.ScreenWidget.FindWidget<BitmapButtonWidget>("WorldEditMenu", true).IsChecked)
                {
                    OldLookControlMode = (int) SettingsManager.LookControlMode;
                    SettingsManager.LookControlMode = LookControlMode.SplitTouch;
                }
                else
                {
                    SettingsManager.LookControlMode = (LookControlMode) OldLookControlMode;
                }
            }

            if ((Engine.Input.Keyboard.IsKeyDown(Engine.Input.Key.F1)) || (ScreensManager.CurrentScreen.ScreenWidget.FindWidget<BitmapButtonWidget>("F1", true).IsTapped)) // Выделение 1 точки
            {
                ComponentMiner componentMiner = Subsystems.Player.ComponentPlayer.ComponentMiner;
                Point1 = componentMiner.PickTerrainForDigging(Subsystems.Drawing.ViewPosition, Subsystems.Drawing.ViewDirection);

                if (Point1.HasValue)
                {
                    SCModApi.Gui.DisplayMessage("Set position 1 on: " + Point1.Value.CellFace.X + ", " + Point1.Value.CellFace.Y + ", " + Point1.Value.CellFace.Z, false);
                    SelectedBlock = World.GetBlock(Point1.Value.CellFace.X, Point1.Value.CellFace.Y, Point1.Value.CellFace.Z);
                    return;
                }
            }

            if ((Engine.Input.Keyboard.IsKeyDown(Engine.Input.Key.F2)) || (ScreensManager.CurrentScreen.ScreenWidget.FindWidget<BitmapButtonWidget>("F2", true).IsTapped)) // Выделение 2 точки
            {
                ComponentMiner componentMiner = Subsystems.Player.ComponentPlayer.ComponentMiner;
                Point2 = componentMiner.PickTerrainForDigging(Subsystems.Drawing.ViewPosition, Subsystems.Drawing.ViewDirection);
                if (Point2.HasValue)
                {
                    SCModApi.Gui.DisplayMessage("Set position 2 on: " + Point1.Value.CellFace.X + ", " + Point1.Value.CellFace.Y + ", " + Point1.Value.CellFace.Z, false);
                    ReplaceableBlock = Subsystems.Terrain.TerrainData.GetCellValue(Point2.Value.CellFace.X, Point2.Value.CellFace.Y, Point2.Value.CellFace.Z);
                    return;
                }
            }

            if ((Engine.Input.Keyboard.IsKeyDown(Engine.Input.Key.F3)) || (ScreensManager.CurrentScreen.ScreenWidget.FindWidget<BitmapButtonWidget>("F3", true).IsTapped)) // Выделение 3 точки
            {
                ComponentMiner componentMiner = Subsystems.Player.ComponentPlayer.ComponentMiner;
                Point3 = componentMiner.PickTerrainForDigging(Subsystems.Drawing.ViewPosition, Subsystems.Drawing.ViewDirection);
                if (Point3.HasValue)
                {
                    SCModApi.Gui.DisplayMessage("Set position 3 on: " + Point1.Value.CellFace.X + ", " + Point1.Value.CellFace.Y + ", " + Point1.Value.CellFace.Z, false);
                    return;
                }
            }

            if (Point1.HasValue && Point2.HasValue && ScreensManager.CurrentScreen.ScreenWidget.FindWidget<BitmapButtonWidget>("WorldEditMenu", true).IsChecked) // Выделение зоны между точками 1 и 2
            {
                int startX = Math.Min(Point1.Value.CellFace.Point.X, Point2.Value.CellFace.Point.X);
                int endX = Math.Max(Point1.Value.CellFace.Point.X, Point2.Value.CellFace.Point.X);
                int startY = Math.Min(Point1.Value.CellFace.Point.Y, Point2.Value.CellFace.Point.Y);
                int endY = Math.Max(Point1.Value.CellFace.Point.Y, Point2.Value.CellFace.Point.Y);
                int startZ = Math.Min(Point1.Value.CellFace.Point.Z, Point2.Value.CellFace.Point.Z);
                int endZ = Math.Max(Point1.Value.CellFace.Point.Z, Point2.Value.CellFace.Point.Z);

                PrimitivesRenderer3D PrimitivesRenderer3D = new PrimitivesRenderer3D();
                Vector3 pointStart = new Vector3(startX, startY, startZ);
                Vector3 pointEnd = new Vector3(endX + 1, endY + 1, endZ + 1);
                BoundingBox boundingBox = new BoundingBox(pointStart, pointEnd);
                PrimitivesRenderer3D.FlatBatch(-1, DepthStencilState.None, (RasterizerState)null, (BlendState)null).QueueBoundingBox(boundingBox, Color.Green);
                PrimitivesRenderer3D.Flush(Subsystems.Drawing.ViewProjectionMatrix, true);
            }

            if (Point3.HasValue && ScreensManager.CurrentScreen.ScreenWidget.FindWidget<BitmapButtonWidget>("WorldEditMenu", true).IsChecked) // Выделение зоны вставки
            {

                int startX = Math.Min(Point1.Value.CellFace.Point.X, Point2.Value.CellFace.Point.X);
                int endX = Math.Max(Point1.Value.CellFace.Point.X, Point2.Value.CellFace.Point.X);
                int startY = Math.Min(Point1.Value.CellFace.Point.Y, Point2.Value.CellFace.Point.Y);
                int endY = Math.Max(Point1.Value.CellFace.Point.Y, Point2.Value.CellFace.Point.Y);
                int startZ = Math.Min(Point1.Value.CellFace.Point.Z, Point2.Value.CellFace.Point.Z);
                int endZ = Math.Max(Point1.Value.CellFace.Point.Z, Point2.Value.CellFace.Point.Z);

                startX += Point3.Value.CellFace.Point.X - Point1.Value.CellFace.Point.X;
                startY += Point3.Value.CellFace.Point.Y - Point1.Value.CellFace.Point.Y;
                startZ += Point3.Value.CellFace.Point.Z - Point1.Value.CellFace.Point.Z;
                endX += Point3.Value.CellFace.Point.X - Point1.Value.CellFace.Point.X;
                endY += Point3.Value.CellFace.Point.Y - Point1.Value.CellFace.Point.Y;
                endZ += Point3.Value.CellFace.Point.Z - Point1.Value.CellFace.Point.Z;

                PrimitivesRenderer3D primitivesRenderer3D = new PrimitivesRenderer3D();
                Vector3 pointStart = new Vector3(startX, startY, startZ);
                Vector3 pointEnd = new Vector3(endX + 1, endY + 1, endZ + 1);
                BoundingBox boundingBox = new BoundingBox(pointStart, pointEnd);
                primitivesRenderer3D.FlatBatch(-1, DepthStencilState.None, (RasterizerState)null, (BlendState)null).QueueBoundingBox(boundingBox, Color.Red);
                primitivesRenderer3D.Flush(Subsystems.Drawing.ViewProjectionMatrix, true);
            }

            if ((Engine.Input.Keyboard.IsKeyDownOnce(Engine.Input.Key.F5)) || (ScreensManager.CurrentScreen.ScreenWidget.FindWidget<BitmapButtonWidget>("F5", true).IsTapped)) // Копирование выделенной зоны
            {
                if (Point1 == null)
                {
                    Gui.DisplayMessage("You have not selected point 1", false);
                }
                else if (Point2 == null)
                {
                    Gui.DisplayMessage("You have not selected point 2", false);
                }
                else if (Point3 == null)
                {
                    Gui.DisplayMessage("You have not selected point 3", false);
                }
                else
                {
                    int startX = Math.Min(Point1.Value.CellFace.Point.X, Point2.Value.CellFace.Point.X);
                    int endX = Math.Max(Point1.Value.CellFace.Point.X, Point2.Value.CellFace.Point.X);
                    int startY = Math.Min(Point1.Value.CellFace.Point.Y, Point2.Value.CellFace.Point.Y);
                    int endY = Math.Max(Point1.Value.CellFace.Point.Y, Point2.Value.CellFace.Point.Y);
                    int startZ = Math.Min(Point1.Value.CellFace.Point.Z, Point2.Value.CellFace.Point.Z);
                    int endZ = Math.Max(Point1.Value.CellFace.Point.Z, Point2.Value.CellFace.Point.Z);

                    for (int y = 0; y <= endY - startY; y++)
                    {
                        for (int z = 0; z <= endZ - startZ; z++)
                        {
                            for (int x = 0; x <= endX - startX; x++)
                            {
                                int targetX, targetY, targetZ;
                                int PlaceX, PlaceY, PlaceZ;
                                if (Point1.Value.CellFace.Point.X > Point2.Value.CellFace.Point.X)
                                {
                                    targetX = Point1.Value.CellFace.Point.X - x;
                                    PlaceX = Point3.Value.CellFace.Point.X - x;
                                }
                                else
                                {
                                    targetX = Point1.Value.CellFace.Point.X + x;
                                    PlaceX = Point3.Value.CellFace.Point.X + x;
                                }

                                if (Point1.Value.CellFace.Point.Y > Point2.Value.CellFace.Point.Y)
                                {
                                    targetY = Point1.Value.CellFace.Point.Y - y;
                                    PlaceY = Point3.Value.CellFace.Point.Y - y;
                                }
                                else
                                {
                                    targetY = Point1.Value.CellFace.Point.Y + y;
                                    PlaceY = Point3.Value.CellFace.Point.Y + y;
                                }

                                if (Point1.Value.CellFace.Point.Z > Point2.Value.CellFace.Point.Z)
                                {
                                    targetZ = Point1.Value.CellFace.Point.Z - z;
                                    PlaceZ = Point3.Value.CellFace.Point.Z - z;
                                }
                                else
                                {
                                    targetZ = Point1.Value.CellFace.Point.Z + z;
                                    PlaceZ = Point3.Value.CellFace.Point.Z + z;
                                }

                                int block = World.GetBlock(targetX, targetY, targetZ);
                                // 15360 - Air
                                if (block != 15360) World.SetBlock(PlaceX, PlaceY, PlaceZ, block);
                            }
                        }
                    }
                }
                return;
            }

            if ((Engine.Input.Keyboard.IsKeyDownOnce(Engine.Input.Key.F6)) || (ScreensManager.CurrentScreen.ScreenWidget.FindWidget<BitmapButtonWidget>("F6", true).IsTapped)) // Заполнение зоны
            {
                if (Point1 == null)
                {
                    Gui.DisplayMessage("You have not selected point 1", false);
                }
                else if (Point2 == null)
                {
                    Gui.DisplayMessage("You have not selected point 2", false);
                }
                else
                {
                    int startX = Math.Min(Point1.Value.CellFace.Point.X, Point2.Value.CellFace.Point.X);
                    int endX = Math.Max(Point1.Value.CellFace.Point.X, Point2.Value.CellFace.Point.X);
                    int startY = Math.Min(Point1.Value.CellFace.Point.Y, Point2.Value.CellFace.Point.Y);
                    int endY = Math.Max(Point1.Value.CellFace.Point.Y, Point2.Value.CellFace.Point.Y);
                    int startZ = Math.Min(Point1.Value.CellFace.Point.Z, Point2.Value.CellFace.Point.Z);
                    int endZ = Math.Max(Point1.Value.CellFace.Point.Z, Point2.Value.CellFace.Point.Z);

                    for (int x = startX; x <= endX; x++)
                    {
                        for (int y = startY; y <= endY; y++)
                        {
                            for (int z = startZ; z <= endZ; z++)
                            {
                                World.SetBlock(x, y, z, SelectedBlock);
                            }
                        }
                    }
                }
                return;
            }

            if ((Engine.Input.Keyboard.IsKeyDownOnce(Engine.Input.Key.F7)) || (ScreensManager.CurrentScreen.ScreenWidget.FindWidget<BitmapButtonWidget>("F7", true).IsTapped)) // Замена зоны
            {
                if (Point1 == null)
                {
                    Gui.DisplayMessage("You have not selected point 1", false);
                }
                else if (Point2 == null)
                {
                    Gui.DisplayMessage("You have not selected point 2", false);
                }
                else
                {
                    int startX = Math.Min(Point1.Value.CellFace.Point.X, Point2.Value.CellFace.Point.X);
                    int endX = Math.Max(Point1.Value.CellFace.Point.X, Point2.Value.CellFace.Point.X);
                    int startY = Math.Min(Point1.Value.CellFace.Point.Y, Point2.Value.CellFace.Point.Y);
                    int endY = Math.Max(Point1.Value.CellFace.Point.Y, Point2.Value.CellFace.Point.Y);
                    int startZ = Math.Min(Point1.Value.CellFace.Point.Z, Point2.Value.CellFace.Point.Z);
                    int endZ = Math.Max(Point1.Value.CellFace.Point.Z, Point2.Value.CellFace.Point.Z);

                    for (int x = startX; x <= endX; x++)
                    {
                        for (int y = startY; y <= endY; y++)
                        {
                            for (int z = startZ; z <= endZ; z++)
                            {
                                if (World.GetBlock(x, y, z) == ReplaceableBlock) World.SetBlock(x, y, z, SelectedBlock);
                            }
                        }
                    }
                }
                return;
            }

            if ((Engine.Input.Keyboard.IsKeyDownOnce(Engine.Input.Key.F8)) || (ScreensManager.CurrentScreen.ScreenWidget.FindWidget<BitmapButtonWidget>("F8", true).IsTapped)) // Очистка зоны
            {
                if (Point1 == null)
                {
                    Gui.DisplayMessage("You have not selected point 1", false);
                }
                else if (Point2 == null)
                {
                    Gui.DisplayMessage("You have not selected point 2", false);
                }
                else
                {
                    int startX = Math.Min(Point1.Value.CellFace.Point.X, Point2.Value.CellFace.Point.X);
                    int endX = Math.Max(Point1.Value.CellFace.Point.X, Point2.Value.CellFace.Point.X);
                    int startY = Math.Min(Point1.Value.CellFace.Point.Y, Point2.Value.CellFace.Point.Y);
                    int endY = Math.Max(Point1.Value.CellFace.Point.Y, Point2.Value.CellFace.Point.Y);
                    int startZ = Math.Min(Point1.Value.CellFace.Point.Z, Point2.Value.CellFace.Point.Z);
                    int endZ = Math.Max(Point1.Value.CellFace.Point.Z, Point2.Value.CellFace.Point.Z);

                    for (int x = startX; x <= endX; x++)
                    {
                        for (int y = startY; y <= endY; y++)
                        {
                            for (int z = startZ; z <= endZ; z++)
                            {
                                World.SetBlock(x, y, z, 0);
                            }
                        }
                    }
                }
                return;
            }

            if ((Engine.Input.Keyboard.IsKeyDownOnce(Engine.Input.Key.F9)) || (ScreensManager.CurrentScreen.ScreenWidget.FindWidget<BitmapButtonWidget>("F9", true).IsTapped)) // Копирование зоны в память
            {
                if (Point1 == null)
                {
                    Gui.DisplayMessage("You have not selected point 1", false);
                }
                else if (Point2 == null)
                {
                    Gui.DisplayMessage("You have not selected point 2", false);
                }
                else
                {
                    int startX = Math.Min(Point1.Value.CellFace.Point.X, Point2.Value.CellFace.Point.X);
                    int endX = Math.Max(Point1.Value.CellFace.Point.X, Point2.Value.CellFace.Point.X);
                    int startY = Math.Min(Point1.Value.CellFace.Point.Y, Point2.Value.CellFace.Point.Y);
                    int endY = Math.Max(Point1.Value.CellFace.Point.Y, Point2.Value.CellFace.Point.Y);
                    int startZ = Math.Min(Point1.Value.CellFace.Point.Z, Point2.Value.CellFace.Point.Z);
                    int endZ = Math.Max(Point1.Value.CellFace.Point.Z, Point2.Value.CellFace.Point.Z);

                    blockCount = 0;
                    BlockList.Clear();

                    for (int x = 0; x <= endX - startX; x++)
                    {
                        for (int y = 0; y <= endY - startY; y++)
                        {
                            for (int z = 0; z <= endZ - startZ; z++)
                            {
                                BlockMem blmem = new BlockMem();
                                int X, Y, Z;
                                if (Point1.Value.CellFace.Point.X > Point2.Value.CellFace.Point.X)
                                {
                                    blmem.x = - x;
                                    X = Point1.Value.CellFace.Point.X - x;
                                }
                                else
                                {
                                    blmem.x = x;
                                    X = Point1.Value.CellFace.Point.X + x;
                                }

                                if (Point1.Value.CellFace.Point.Y > Point2.Value.CellFace.Point.Y)
                                {
                                    blmem.y = - y;
                                    Y = Point1.Value.CellFace.Point.Y - y;
                                }
                                else
                                {
                                    blmem.y = y;
                                    Y = Point1.Value.CellFace.Point.Y + y;
                                }

                                if (Point1.Value.CellFace.Point.Z > Point2.Value.CellFace.Point.Z)
                                {
                                    blmem.z = - z;
                                    Z = Point1.Value.CellFace.Point.Z - z;
                                }
                                else
                                {
                                    blmem.z = z;
                                    Z = Point1.Value.CellFace.Point.Z + z;
                                }

                                blmem.id = World.GetBlock(X, Y, Z);
                                BlockList.Add(blmem);
                                blockCount++;
                            }
                        }
                    }
                }
                Gui.DisplayMessage("Copied " + blockCount + " blocks", false);
                return;
            }

            if ((Engine.Input.Keyboard.IsKeyDownOnce(Engine.Input.Key.F10)) || (ScreensManager.CurrentScreen.ScreenWidget.FindWidget<BitmapButtonWidget>("F10", true).IsTapped))  // Вставка зоны из памяти
            {
                if (Point3 == null) Gui.DisplayMessage("You have not selected point 3", false);
                else
                {
                    for (var i = 0; i < blockCount; i++)
                    {
                        var xPos = Point3.Value.CellFace.X + BlockList[i].x;
                        var yPos = Point3.Value.CellFace.Y + BlockList[i].y;
                        var zPos = Point3.Value.CellFace.Z + BlockList[i].z;

                        World.SetBlock(xPos, yPos, zPos, BlockList[i].id);
                    }
                    Gui.DisplayMessage("Pasted " + blockCount + " blocks", false);
                }
            }
        }
        public void Draw(Camera camera, int drawOrder)
        {
            if (!(m_componentPlayer.ComponentHealth.Health > 0f) || !camera.GameWidget.IsEntityFirstPersonTarget(base.Entity) || !m_componentPlayer.ComponentInput.IsControlledByVr)
            {
                return;
            }
            Vector3 eyePosition      = m_componentPlayer.ComponentCreatureModel.EyePosition;
            int     x                = Terrain.ToCell(eyePosition.X);
            int     num              = Terrain.ToCell(eyePosition.Y);
            int     z                = Terrain.ToCell(eyePosition.Z);
            int     activeBlockValue = m_componentMiner.ActiveBlockValue;

            if (Time.FrameStartTime >= m_nextHandLightTime)
            {
                float?num2 = LightingManager.CalculateSmoothLight(m_subsystemTerrain, eyePosition);
                if (num2.HasValue)
                {
                    m_nextHandLightTime = Time.FrameStartTime + 0.1;
                    m_handLight         = num2.Value;
                }
            }
            Matrix identity = Matrix.Identity;

            if (m_pokeAnimationTime > 0f)
            {
                float num3 = MathUtils.Sin(MathUtils.Sqrt(m_pokeAnimationTime) * (float)Math.PI);
                if (activeBlockValue != 0)
                {
                    identity *= Matrix.CreateRotationX((0f - MathUtils.DegToRad(90f)) * num3);
                }
                else
                {
                    identity *= Matrix.CreateRotationX((0f - MathUtils.DegToRad(45f)) * num3);
                }
            }
            if (!VrManager.IsControllerPresent(VrController.Right))
            {
                return;
            }
            Matrix m = VrManager.HmdMatrixInverted * Matrix.CreateWorld(camera.ViewPosition, camera.ViewDirection, camera.ViewUp) * camera.ViewMatrix;
            Matrix controllerMatrix = VrManager.GetControllerMatrix(VrController.Right);

            if (activeBlockValue == 0)
            {
                Display.DepthStencilState      = DepthStencilState.Default;
                Display.RasterizerState        = RasterizerState.CullCounterClockwiseScissor;
                m_shader.Texture               = m_componentPlayer.ComponentCreatureModel.TextureOverride;
                m_shader.SamplerState          = SamplerState.PointClamp;
                m_shader.MaterialColor         = Vector4.One;
                m_shader.AmbientLightColor     = new Vector3(m_handLight * LightingManager.LightAmbient);
                m_shader.DiffuseLightColor1    = new Vector3(m_handLight);
                m_shader.DiffuseLightColor2    = new Vector3(m_handLight);
                m_shader.LightDirection1       = -Vector3.TransformNormal(LightingManager.DirectionToLight1, camera.ViewMatrix);
                m_shader.LightDirection2       = -Vector3.TransformNormal(LightingManager.DirectionToLight2, camera.ViewMatrix);
                m_shader.Transforms.View       = Matrix.Identity;
                m_shader.Transforms.Projection = camera.ProjectionMatrix;
                m_shader.Transforms.World[0]   = Matrix.CreateScale(0.01f) * identity * controllerMatrix * m;
                foreach (ModelMesh mesh in m_vrHandModel.Meshes)
                {
                    foreach (ModelMeshPart meshPart in mesh.MeshParts)
                    {
                        Display.DrawIndexed(PrimitiveType.TriangleList, m_shader, meshPart.VertexBuffer, meshPart.IndexBuffer, meshPart.StartIndex, meshPart.IndicesCount);
                    }
                }
            }
            else
            {
                if (num >= 0 && num <= 255)
                {
                    TerrainChunk chunkAtCell = m_subsystemTerrain.Terrain.GetChunkAtCell(x, z);
                    if (chunkAtCell != null && chunkAtCell.State >= TerrainChunkState.InvalidVertices1)
                    {
                        m_itemLight = m_subsystemTerrain.Terrain.GetCellLightFast(x, num, z);
                    }
                }
                int     num4   = Terrain.ExtractContents(activeBlockValue);
                Block   block  = BlocksManager.Blocks[num4];
                Vector3 vector = block.InHandRotation * ((float)Math.PI / 180f) + m_itemRotation;
                Matrix  matrix = Matrix.CreateFromYawPitchRoll(vector.Y, vector.X, vector.Z) * Matrix.CreateTranslation(block.InHandOffset) * identity * Matrix.CreateTranslation(m_itemOffset) * controllerMatrix * m;
                m_drawBlockEnvironmentData.SubsystemTerrain = m_subsystemTerrain;
                m_drawBlockEnvironmentData.InWorldMatrix    = matrix;
                m_drawBlockEnvironmentData.Light            = m_itemLight;
                m_drawBlockEnvironmentData.Humidity         = m_subsystemTerrain.Terrain.GetHumidity(x, z);
                m_drawBlockEnvironmentData.Temperature      = m_subsystemTerrain.Terrain.GetTemperature(x, z) + SubsystemWeather.GetTemperatureAdjustmentAtHeight(num);
                block.DrawBlock(m_primitivesRenderer, activeBlockValue, Color.White, block.InHandScale, ref matrix, m_drawBlockEnvironmentData);
            }
            m_primitivesRenderer.Flush(camera.ProjectionMatrix);
        }
        public override void Draw(DrawContext dc)
        {
            if (Design == null)
            {
                return;
            }
            Matrix matrix;

            if (Mode == ViewMode.Perspective)
            {
                Viewport viewport = Display.Viewport;
                Vector3  vector   = new Vector3(0.5f, 0.5f, 0.5f);
                Matrix   m        = Matrix.CreateLookAt(2.65f * m_direction + vector, vector, Vector3.UnitY);
                Matrix   m2       = Matrix.CreatePerspectiveFieldOfView(1.2f, base.ActualSize.X / base.ActualSize.Y, 0.4f, 4f);
                Matrix   m3       = MatrixUtils.CreateScaleTranslation(base.ActualSize.X, 0f - base.ActualSize.Y, base.ActualSize.X / 2f, base.ActualSize.Y / 2f) * base.GlobalTransform * MatrixUtils.CreateScaleTranslation(2f / (float)viewport.Width, -2f / (float)viewport.Height, -1f, 1f);
                matrix = m * m2 * m3;
                FlatBatch3D flatBatch3D = m_primitivesRenderer3d.FlatBatch(1, DepthStencilState.DepthRead);
                for (int i = 0; i <= Design.Resolution; i++)
                {
                    float num   = (float)i / (float)Design.Resolution;
                    Color color = (i % 2 == 0) ? new Color(56, 56, 56, 56) : new Color(28, 28, 28, 28);
                    color *= base.GlobalColorTransform;
                    flatBatch3D.QueueLine(new Vector3(num, 0f, 0f), new Vector3(num, 0f, 1f), color);
                    flatBatch3D.QueueLine(new Vector3(0f, 0f, num), new Vector3(1f, 0f, num), color);
                    flatBatch3D.QueueLine(new Vector3(0f, num, 0f), new Vector3(0f, num, 1f), color);
                    flatBatch3D.QueueLine(new Vector3(0f, 0f, num), new Vector3(0f, 1f, num), color);
                    flatBatch3D.QueueLine(new Vector3(0f, num, 1f), new Vector3(1f, num, 1f), color);
                    flatBatch3D.QueueLine(new Vector3(num, 0f, 1f), new Vector3(num, 1f, 1f), color);
                }
                Color       color2      = new Color(64, 64, 64, 255) * base.GlobalColorTransform;
                FontBatch3D fontBatch3D = m_primitivesRenderer3d.FontBatch(ContentManager.Get <BitmapFont>("Fonts/Pericles"), 1);
                fontBatch3D.QueueText("Front", new Vector3(0.5f, 0f, 0f), 0.004f * new Vector3(-1f, 0f, 0f), 0.004f * new Vector3(0f, 0f, -1f), color2, TextAnchor.HorizontalCenter);
                fontBatch3D.QueueText("Side", new Vector3(1f, 0f, 0.5f), 0.004f * new Vector3(0f, 0f, -1f), 0.004f * new Vector3(1f, 0f, 0f), color2, TextAnchor.HorizontalCenter);
                if (DrawDebugFurniture)
                {
                    DebugDraw();
                }
            }
            else
            {
                Vector3 position;
                Vector3 up;
                if (Mode == ViewMode.Side)
                {
                    position = new Vector3(1f, 0f, 0f);
                    up       = new Vector3(0f, 1f, 0f);
                }
                else if (Mode != ViewMode.Top)
                {
                    position = new Vector3(0f, 0f, -1f);
                    up       = new Vector3(0f, 1f, 0f);
                }
                else
                {
                    position = new Vector3(0f, 1f, 0f);
                    up       = new Vector3(0f, 0f, 1f);
                }
                Viewport viewport2 = Display.Viewport;
                float    num2      = MathUtils.Min(base.ActualSize.X, base.ActualSize.Y);
                Matrix   m4        = Matrix.CreateLookAt(position, new Vector3(0f, 0f, 0f), up);
                Matrix   m5        = Matrix.CreateOrthographic(2f, 2f, -10f, 10f);
                Matrix   m6        = MatrixUtils.CreateScaleTranslation(num2, 0f - num2, base.ActualSize.X / 2f, base.ActualSize.Y / 2f) * base.GlobalTransform * MatrixUtils.CreateScaleTranslation(2f / (float)viewport2.Width, -2f / (float)viewport2.Height, -1f, 1f);
                matrix = Matrix.CreateTranslation(-0.5f, -0.5f, -0.5f) * m4 * m5 * m6;
                FlatBatch2D flatBatch2D = m_primitivesRenderer2d.FlatBatch();
                Matrix      m7          = base.GlobalTransform;
                for (int j = 1; j < Design.Resolution; j++)
                {
                    float   num3 = (float)j / (float)Design.Resolution;
                    Vector2 v    = new Vector2(base.ActualSize.X * num3, 0f);
                    Vector2 v2   = new Vector2(base.ActualSize.X * num3, base.ActualSize.Y);
                    Vector2 v3   = new Vector2(0f, base.ActualSize.Y * num3);
                    Vector2 v4   = new Vector2(base.ActualSize.X, base.ActualSize.Y * num3);
                    Vector2.Transform(ref v, ref m7, out v);
                    Vector2.Transform(ref v2, ref m7, out v2);
                    Vector2.Transform(ref v3, ref m7, out v3);
                    Vector2.Transform(ref v4, ref m7, out v4);
                    Color color3 = (j % 2 == 0) ? new Color(0, 0, 0, 56) : new Color(0, 0, 0, 28);
                    Color color4 = (j % 2 == 0) ? new Color(56, 56, 56, 56) : new Color(28, 28, 28, 28);
                    color3 *= base.GlobalColorTransform;
                    color4 *= base.GlobalColorTransform;
                    flatBatch2D.QueueLine(v, v2, 0f, (j % 2 == 0) ? color3 : (color3 * 0.75f));
                    flatBatch2D.QueueLine(v + new Vector2(1f, 0f), v2 + new Vector2(1f, 0f), 0f, color4);
                    flatBatch2D.QueueLine(v3, v4, 0f, color3);
                    flatBatch2D.QueueLine(v3 + new Vector2(0f, 1f), v4 + new Vector2(0f, 1f), 0f, color4);
                }
            }
            Matrix            matrix2  = Matrix.Identity;
            FurnitureGeometry geometry = Design.Geometry;

            for (int k = 0; k < 6; k++)
            {
                Color globalColorTransform = base.GlobalColorTransform;
                if (Mode == ViewMode.Perspective)
                {
                    float num4 = LightingManager.LightIntensityByLightValueAndFace[15 + 16 * CellFace.OppositeFace(k)];
                    globalColorTransform *= new Color(num4, num4, num4);
                }
                if (geometry.SubsetOpaqueByFace[k] != null)
                {
                    BlocksManager.DrawMeshBlock(m_primitivesRenderer3d, geometry.SubsetOpaqueByFace[k], globalColorTransform, 1f, ref matrix2, null);
                }
                if (geometry.SubsetAlphaTestByFace[k] != null)
                {
                    BlocksManager.DrawMeshBlock(m_primitivesRenderer3d, geometry.SubsetAlphaTestByFace[k], globalColorTransform, 1f, ref matrix2, null);
                }
            }
            m_primitivesRenderer3d.Flush(matrix);
            m_primitivesRenderer2d.Flush();
        }
Пример #4
0
 public void Draw(Camera camera, int drawOrder)
 {
     if (m_componentPlayer.ComponentHealth.Health > 0f && camera.GameWidget.IsEntityFirstPersonTarget(base.Entity) && !m_componentPlayer.ComponentInput.IsControlledByVr)
     {
         Viewport viewport  = Display.Viewport;
         Viewport viewport2 = viewport;
         viewport2.MaxDepth *= 0.1f;
         Display.Viewport    = viewport2;
         try
         {
             Matrix identity = Matrix.Identity;
             if (m_swapAnimationTime > 0f)
             {
                 float num = MathUtils.Pow(MathUtils.Sin(m_swapAnimationTime * (float)Math.PI), 3f);
                 identity *= Matrix.CreateTranslation(0f, -0.8f * num, 0.2f * num);
             }
             if (m_pokeAnimationTime > 0f)
             {
                 float num2 = MathUtils.Sin(MathUtils.Sqrt(m_pokeAnimationTime) * (float)Math.PI);
                 if (m_value != 0)
                 {
                     identity *= Matrix.CreateRotationX((0f - MathUtils.DegToRad(90f)) * num2);
                     identity *= Matrix.CreateTranslation(-0.5f * num2, 0.1f * num2, 0f * num2);
                 }
                 else
                 {
                     identity *= Matrix.CreateRotationX((0f - MathUtils.DegToRad(45f)) * num2);
                     identity *= Matrix.CreateTranslation(-0.1f * num2, 0.2f * num2, -0.05f * num2);
                 }
             }
             if (m_componentRider.Mount != null)
             {
                 ComponentCreatureModel componentCreatureModel = m_componentRider.Mount.Entity.FindComponent <ComponentCreatureModel>();
                 if (componentCreatureModel != null)
                 {
                     float   num3     = componentCreatureModel.MovementAnimationPhase * (float)Math.PI * 2f + 0.5f;
                     Vector3 position = default(Vector3);
                     position.Y = 0.02f * MathUtils.Sin(num3);
                     position.Z = 0.02f * MathUtils.Sin(num3);
                     identity  *= Matrix.CreateRotationX(0.05f * MathUtils.Sin(num3 * 1f)) * Matrix.CreateTranslation(position);
                 }
             }
             else
             {
                 float   num4      = m_componentPlayer.ComponentCreatureModel.MovementAnimationPhase * (float)Math.PI * 2f;
                 Vector3 position2 = default(Vector3);
                 position2.X = 0.03f * MathUtils.Sin(num4 * 1f);
                 position2.Y = 0.02f * MathUtils.Sin(num4 * 2f);
                 position2.Z = 0.02f * MathUtils.Sin(num4 * 1f);
                 identity   *= Matrix.CreateRotationZ(1f * position2.X) * Matrix.CreateTranslation(position2);
             }
             Vector3 eyePosition = m_componentPlayer.ComponentCreatureModel.EyePosition;
             int     x           = Terrain.ToCell(eyePosition.X);
             int     num5        = Terrain.ToCell(eyePosition.Y);
             int     z           = Terrain.ToCell(eyePosition.Z);
             Matrix  m           = Matrix.CreateFromQuaternion(m_componentPlayer.ComponentCreatureModel.EyeRotation);
             m.Translation = m_componentPlayer.ComponentCreatureModel.EyePosition;
             if (m_value != 0)
             {
                 if (num5 >= 0 && num5 <= 255)
                 {
                     TerrainChunk chunkAtCell = m_subsystemTerrain.Terrain.GetChunkAtCell(x, z);
                     if (chunkAtCell != null && chunkAtCell.State >= TerrainChunkState.InvalidVertices1)
                     {
                         m_itemLight = m_subsystemTerrain.Terrain.GetCellLightFast(x, num5, z);
                     }
                 }
                 int     num6      = Terrain.ExtractContents(m_value);
                 Block   block     = BlocksManager.Blocks[num6];
                 Vector3 vector    = block.FirstPersonRotation * ((float)Math.PI / 180f) + m_itemRotation;
                 Vector3 position3 = block.FirstPersonOffset + m_itemOffset;
                 position3 += m_itemOffset;
                 Matrix matrix = Matrix.CreateFromYawPitchRoll(vector.Y, vector.X, vector.Z) * identity * Matrix.CreateTranslation(position3) * Matrix.CreateFromYawPitchRoll(m_lagAngles.X, m_lagAngles.Y, 0f) * m;
                 m_drawBlockEnvironmentData.SubsystemTerrain = m_subsystemTerrain;
                 m_drawBlockEnvironmentData.InWorldMatrix    = matrix;
                 m_drawBlockEnvironmentData.Light            = m_itemLight;
                 m_drawBlockEnvironmentData.Humidity         = m_subsystemTerrain.Terrain.GetSeasonalHumidity(x, z);
                 m_drawBlockEnvironmentData.Temperature      = m_subsystemTerrain.Terrain.GetSeasonalTemperature(x, z) + SubsystemWeather.GetTemperatureAdjustmentAtHeight(num5);
                 block.DrawBlock(m_primitivesRenderer, m_value, Color.White, block.FirstPersonScale, ref matrix, m_drawBlockEnvironmentData);
                 m_primitivesRenderer.Flush(camera.ViewProjectionMatrix);
             }
             else
             {
                 if (Time.FrameStartTime >= m_nextHandLightTime)
                 {
                     float?num7 = LightingManager.CalculateSmoothLight(m_subsystemTerrain, eyePosition);
                     if (num7.HasValue)
                     {
                         m_nextHandLightTime = Time.FrameStartTime + 0.1;
                         m_handLight         = num7.Value;
                     }
                 }
                 Vector3 position4 = new Vector3(0.25f, -0.3f, -0.05f);
                 Matrix  matrix2   = Matrix.CreateScale(0.01f) * Matrix.CreateRotationX(0.8f) * Matrix.CreateRotationY(0.4f) * identity * Matrix.CreateTranslation(position4) * Matrix.CreateFromYawPitchRoll(m_lagAngles.X, m_lagAngles.Y, 0f) * m * camera.ViewMatrix;
                 Display.DepthStencilState      = DepthStencilState.Default;
                 Display.RasterizerState        = RasterizerState.CullCounterClockwiseScissor;
                 m_shader.Texture               = m_componentPlayer.ComponentCreatureModel.TextureOverride;
                 m_shader.SamplerState          = SamplerState.PointClamp;
                 m_shader.MaterialColor         = Vector4.One;
                 m_shader.AmbientLightColor     = new Vector3(m_handLight * LightingManager.LightAmbient);
                 m_shader.DiffuseLightColor1    = new Vector3(m_handLight);
                 m_shader.DiffuseLightColor2    = new Vector3(m_handLight);
                 m_shader.LightDirection1       = Vector3.TransformNormal(LightingManager.DirectionToLight1, camera.ViewMatrix);
                 m_shader.LightDirection2       = Vector3.TransformNormal(LightingManager.DirectionToLight2, camera.ViewMatrix);
                 m_shader.Transforms.World[0]   = matrix2;
                 m_shader.Transforms.View       = Matrix.Identity;
                 m_shader.Transforms.Projection = camera.ProjectionMatrix;
                 foreach (ModelMesh mesh in m_handModel.Meshes)
                 {
                     foreach (ModelMeshPart meshPart in mesh.MeshParts)
                     {
                         Display.DrawIndexed(PrimitiveType.TriangleList, m_shader, meshPart.VertexBuffer, meshPart.IndexBuffer, meshPart.StartIndex, meshPart.IndicesCount);
                     }
                 }
             }
         }
         finally
         {
             Display.Viewport = viewport;
         }
     }
 }