Ejemplo n.º 1
0
        public void DrawHilites(
            DesignationSet Set,
            Action <Vector3, Vector3, Color, float, bool> DrawBoxCallback,
            Action <Vector3, VoxelType> DrawPhantomCallback)
        {
            var colorModulation = Math.Abs(Math.Sin(DwarfTime.LastTime.TotalGameTime.TotalSeconds * 2.0f));

            foreach (var properties in DesignationProperties)
            {
                properties.Value.ModulatedColor = new Color(
                    (byte)(MathFunctions.Clamp((float)(properties.Value.Color.R * colorModulation + 50), 0.0f, 255.0f)),
                    (byte)(MathFunctions.Clamp((float)(properties.Value.Color.G * colorModulation + 50), 0.0f, 255.0f)),
                    (byte)(MathFunctions.Clamp((float)(properties.Value.Color.B * colorModulation + 50), 0.0f, 255.0f)),
                    255);
            }

            foreach (var voxel in Set.EnumerateDesignations())
            {
                if ((voxel.Type & VisibleTypes) == voxel.Type)
                {
                    var props = DefaultProperties;
                    if (DesignationProperties.ContainsKey(voxel.Type))
                    {
                        props = DesignationProperties[voxel.Type];
                    }

                    var v = voxel.Voxel.Coordinate.ToVector3();
                    if (props.Icon != null)
                    {
                        Drawer2D.DrawSprite(props.Icon, v + Vector3.One * 0.5f, Vector2.One * 0.5f, Vector2.Zero, new Color(255, 255, 255, 100));
                    }

                    if (voxel.Type == DesignationType.Put) // Hate this.
                    {
                        DrawPhantomCallback(v, VoxelLibrary.GetVoxelType((voxel.Tag as short?).Value));
                    }
                    else
                    {
                        DrawBoxCallback(v, Vector3.One, props.ModulatedColor, props.LineWidth, true);
                    }
                }
            }

            foreach (var entity in Set.EnumerateEntityDesignations())
            {
                if ((entity.Type & VisibleTypes) == entity.Type)
                {
                    var props = DefaultProperties;
                    if (DesignationProperties.ContainsKey(entity.Type))
                    {
                        props = DesignationProperties[entity.Type];
                    }

                    entity.Body.SetTintRecursive(props.ModulatedColor);

                    // Todo: More consistent drawing?
                    if (entity.Type == DesignationType.Craft)
                    {
                        entity.Body.SetFlagRecursive(GameComponent.Flag.Visible, true);
                    }
                    else
                    {
                        var box = entity.Body.GetBoundingBox();
                        DrawBoxCallback(box.Min, box.Max - box.Min, props.ModulatedColor, props.LineWidth, false);
                    }

                    if (props.Icon != null)
                    {
                        Drawer2D.DrawSprite(props.Icon, entity.Body.Position + Vector3.One * 0.5f, Vector2.One * 0.5f, Vector2.Zero, new Color(255, 255, 255, 100));
                    }
                }
                else if (entity.Type == DesignationType.Craft) // Make the ghost object invisible if these designations are turned off.
                {
                    entity.Body.SetFlagRecursive(GameComponent.Flag.Visible, false);
                }
            }
        }
Ejemplo n.º 2
0
        private static void BuildDesignationGeometry(RawPrimitive Into, VoxelChunk Chunk, Cache Cache, DesignationSet Designations, WorldManager World, VoxelHandle v)
        {
            var designations    = Designations == null ? new List <DesignationSet.VoxelDesignation>() : Designations.EnumerateDesignations(v).ToList();
            int maxViewingLevel = World.Renderer.PersistentSettings.MaxViewingLevel;

            foreach (var designation in designations)
            {
                if ((designation.Type & World.Renderer.PersistentSettings.VisibleTypes) == designation.Type)
                {
                    var props = Library.GetDesignationTypeProperties(designation.Type);
                    var designationVisible = false;

                    if (designation.Type == DesignationType.Put)
                    {
                        designationVisible = v.Coordinate.Y < maxViewingLevel;
                    }
                    else
                    {
                        designationVisible = VoxelHelpers.DoesVoxelHaveVisibleSurface(World, v);
                    }

                    if (designationVisible)
                    {
                        var desPrim = Library.GetVoxelPrimitive(Library.DesignationVoxelType);
                        switch (props.DrawType)
                        {
                        case DrawBoxType.FullBox:
                            for (int i = 0; i < 6; i++)
                            {
                                BuildVoxelFaceGeometry(Into, Chunk, Cache, desPrim, v, props.Color, desPrim.UVs, DesignationTransform, i, false);
                            }
                            break;

                        case DrawBoxType.TopBox:
                            BuildVoxelFaceGeometry(Into, Chunk, Cache, desPrim, v, props.Color, desPrim.UVs, DesignationTransform, 0, false);
                            break;

                        case DrawBoxType.PreviewVoxel:
                        {
                            var previewPrim  = Library.GetVoxelPrimitive(Library.GetVoxelType(designation.Tag.ToString()));
                            var offsetMatrix = Matrix.Identity;
                            if (!v.IsEmpty)
                            {
                                offsetMatrix = Matrix.CreateTranslation(0.0f, 0.1f, 0.0f);
                            }
                            for (int i = 0; i < 6; i++)
                            {
                                BuildVoxelFaceGeometry(Into, Chunk, Cache, previewPrim, v, props.Color, previewPrim.UVs, offsetMatrix, i, false);
                            }
                        }
                        break;
                        }
                    }
                }
            }
        }
Ejemplo n.º 3
0
        private static void BuildDesignationGeometry(RawPrimitive Into, VoxelChunk Chunk, Cache Cache, DesignationSet Designations, WorldManager World, VoxelHandle v)
        {
            // Todo: Store designations per chunk.
            foreach (var designation in Designations == null ? new List <DesignationSet.VoxelDesignation>() : Designations.EnumerateDesignations(v).ToList())
            {
                if ((designation.Type & World.Renderer.PersistentSettings.VisibleTypes) != designation.Type) // If hidden by player, do not draw.
                {
                    return;
                }

                var designationProperties = Library.GetDesignationTypeProperties(designation.Type).Value;
                var designationVisible    = false;

                if (designation.Type == DesignationType.Put)
                {
                    designationVisible = v.Coordinate.Y < World.Renderer.PersistentSettings.MaxViewingLevel;
                }
                else
                {
                    designationVisible = VoxelHelpers.DoesVoxelHaveVisibleSurface(World, v);
                }

                if (designationVisible &&
                    Library.GetVoxelPrimitive(Library.DesignationVoxelType).HasValue(out BoxPrimitive designationPrimitive))
                {
                    switch (designationProperties.DrawType)
                    {
                    case DesignationDrawType.FullBox:
                        for (int i = 0; i < 6; i++)
                        {
                            BuildVoxelFaceGeometry(Into, Chunk, Cache, designationPrimitive, v, designationProperties.Color, designationPrimitive.UVs, DesignationTransform, (BoxFace)i, false);
                        }
                        break;

                    case DesignationDrawType.TopBox:
                        BuildVoxelFaceGeometry(Into, Chunk, Cache, designationPrimitive, v, designationProperties.Color, designationPrimitive.UVs, DesignationTransform, 0, false);
                        break;

                    case DesignationDrawType.PreviewVoxel:
                    {
                        if (Library.GetVoxelType(designation.Tag.ToString()).HasValue(out VoxelType voxelType) &&
                            Library.GetVoxelPrimitive(voxelType).HasValue(out BoxPrimitive previewPrimitive))
                        {
                            var offsetMatrix = Matrix.Identity;
                            if (!v.IsEmpty)
                            {
                                offsetMatrix = Matrix.CreateTranslation(0.0f, 0.1f, 0.0f);
                            }
                            for (int i = 0; i < 6; i++)
                            {
                                BuildVoxelFaceGeometry(Into, Chunk, Cache, previewPrimitive, v, designationProperties.Color, previewPrimitive.UVs, offsetMatrix, (BoxFace)i, false);
                            }
                        }
                    }
                    break;
                    }
                }
            }
        }