Ejemplo n.º 1
0
        public static bool DrawSpecialBetween(List <EditorMapLayer> layers, int xmin, int ymin, int xmax, int ymax,
                                              int gridFactor, Graphics gfx)
        {
            if (layers == null || layers.Count == 0)
            {
                return(false);
            }

            foreach (EditorMapLayer layer in layers)
            {
                for (int x = xmin; x < xmax; ++x)
                {
                    for (int y = ymin; y < ymax; ++y)
                    {
                        // Get the brush located at the provided x- and y-coordinates
                        EditorBrush brush = layer.GetBrushAt(x, y);

                        // If the brush is null, or it is not a special brush
                        if (brush == null || !brush.IsSpecial || brush.FrontAsset == null)
                        {
                            continue;
                        }

                        gfx.DrawImage(brush.FrontAsset.Image,
                                      x * gridFactor,
                                      y * gridFactor,
                                      brush.FrontAsset.Image.Width,
                                      brush.FrontAsset.Image.Height);
                    }
                }
            }

            return(true);
        }
Ejemplo n.º 2
0
        public static bool DrawBackgroundBetween(List <EditorMapLayer> layers, int xmin, int ymin, int xmax, int ymax,
                                                 int gridFactor, Graphics gfx)
        {
            if (layers == null || layers.Count == 0)
            {
                return(false);
            }

            foreach (EditorMapLayer layer in layers)
            {
                for (int x = xmin; x < xmax; ++x)
                {
                    for (int y = ymin; y < ymax; ++y)
                    {
                        // Get the brush located at the provided x- and y-coordinates
                        EditorBrush brush = layer.GetBrushAt(x, y);

                        // If the brush is null, or no back asset is needed for this brush
                        if (brush == null || !brush.NeedsBackAsset || brush.BackAsset == null)
                        {
                            continue;
                        }

                        // Don't draw this brush if it isn't flagged as a back brush, or if it
                        // is also flagged as a front brush.
                        if (brush.BrushTypes.Contains("back") && !brush.BrushTypes.Contains("front"))
                        {
                            DrawBackgroundTile((StarboundTile)brush.BackAsset, x, y, gridFactor, gfx);
                        }
                    }
                }
            }

            return(true);
        }
Ejemplo n.º 3
0
        public void SetSelectedBrush(EditorBrush brush)
        {
            m_selectedBrush = brush;

            string colour =
                "r: " + m_selectedBrush.Colour[0] +
                " g: " + m_selectedBrush.Colour[1] +
                " b: " + m_selectedBrush.Colour[2];

            // Tidy this display up at some point
            BottomBarBrushLabel.Text = "Selected Brush: " + m_selectedBrush.Comment;

            if (m_selectedBrush.FrontAsset != null)
            {
                BottomBarBrushLabel.Text += "       front: " + m_selectedBrush.FrontAsset.AssetName;
            }

            if (m_selectedBrush.BackAsset != null)
            {
                BottomBarBrushLabel.Text += "       back: " + m_selectedBrush.BackAsset.AssetName;
            }

            BottomBarBrushLabel.Text += "        " + colour;

            VisualRgbaBrushDescLabel.Text =
                "r: " + m_selectedBrush.Colour[0] +
                " g: " + m_selectedBrush.Colour[1] +
                " b: " + m_selectedBrush.Colour[2];

            // Populate the colour box
            VisualRgbaBrushImageBox.Image = EditorHelpers.GetGeneratedRectangle(1, 1,
                                                                                m_selectedBrush.Colour[0], m_selectedBrush.Colour[1],
                                                                                m_selectedBrush.Colour[2], m_selectedBrush.Colour[3]);

            Image assetImg = null;

            // Get the correct preview box asset
            if (m_selectedBrush.FrontAsset != null)
            {
                assetImg = m_selectedBrush.FrontAsset.Image;
                VisualGraphicBrushDescLabel.Text = m_selectedBrush.FrontAsset.AssetName;
            }
            else if (m_selectedBrush.BackAsset != null)
            {
                assetImg = m_selectedBrush.BackAsset.Image;
                VisualGraphicBrushDescLabel.Text = m_selectedBrush.BackAsset.AssetName;
            }

            // Populate the tile preview box
            if (assetImg != null)
            {
                VisualGraphicBrushImageBox.Image = assetImg;
            }

            MainPictureBox.SetSelectedBrush(m_selectedBrush);
        }
Ejemplo n.º 4
0
        public void OnCanvasRightClick(int gridX, int gridY, int lastGridX, int lastGridY)
        {
            EditorMapLayer activeLayer = GetSelectedLayer();

            if (activeLayer == null)
            {
                return;
            }

            // eyedropper tool

            EditorBrush brush = activeLayer.GetBrushAt(gridX, gridY);

            if (brush != null)
            {
                SetSelectedBrush(brush);
            }
        }
Ejemplo n.º 5
0
        public static bool DrawForegroundBetween(List <EditorMapLayer> layers, int xmin, int ymin, int xmax, int ymax,
                                                 int gridFactor, Graphics gfx)
        {
            if (layers == null || layers.Count == 0)
            {
                return(false);
            }

            foreach (EditorMapLayer layer in layers)
            {
                for (int x = xmin; x < xmax; ++x)
                {
                    for (int y = ymin; y < ymax; ++y)
                    {
                        // Get the brush located at the provided x- and y-coordinates
                        EditorBrush brush = layer.GetBrushAt(x, y);

                        // If the brush is null, or no front asset is needed for this brush
                        if (brush == null || !brush.NeedsFrontAsset || brush.FrontAsset == null)
                        {
                            continue;
                        }

                        if (brush.BrushTypes.Contains("object"))
                        {
                            var obj = (StarboundObject)brush.FrontAsset;
                            ObjectOrientation orientation = obj.GetCorrectOrientation(layers[0].Parent, x, y);
                            DrawObject(obj, x, y, orientation, brush.Direction, gridFactor, gfx);
                        }
                        else if (brush.BrushTypes.Contains("front"))
                        {
                            DrawForegroundTile((StarboundTile)brush.FrontAsset, x, y, gridFactor, gfx);
                        }
                    }
                }
            }

            return(true);
        }
Ejemplo n.º 6
0
        private void CleanUp()
        {
            MainPictureBox.SetImage(null, m_gridFactor);
            MainPictureBox.SetSelectedBrush(null);
            VisualGraphicBrushImageBox.Image = null;
            VisualRgbaBrushImageBox.Image    = null;
            PartTreeView.Nodes.Clear();
            BrushesTreeView.Nodes.Clear();
            BottomBarBrushLabel.Text = "Selected Brush: ";
            BottomBarXLabel.Text     = "Grid X: ";
            BottomBarYLabel.Text     = "Grid Y: ";
            BottomBarZoomLabel.Text  = "Zoom: ";
            m_brushNodeMap.Clear();
            m_mapNodeMap.Clear();
            m_parent.CleanUpResource();
            m_selectedBrush = null;
            m_selectedMap   = null;

            // Force the garbage collector to clean up
            // But it won't do it until next file load because that would be too easy
            GC.Collect();
        }
Ejemplo n.º 7
0
        public void SetSelectedBrush(EditorBrush brush)
        {
            StarboundAsset asset = null;

            if (brush != null && brush.NeedsFrontAsset && brush.FrontAsset != null)
            {
                asset = brush.FrontAsset;
            }
            else if (brush != null && brush.NeedsBackAsset && brush.BackAsset != null)
            {
                asset = brush.BackAsset;
            }
            else
            {
                asset           = new StarboundTile();
                asset.AssetName = "gridAsset.INTERNAL";
                asset.Image     = EditorHelpers.GetGeneratedRectangle(8, 8, 255, 255, 255, 128);
            }

            m_selectedBrush = brush;
            m_selectedAsset = asset;

            Invalidate();
        }
Ejemplo n.º 8
0
        public void OnCanvasLeftClick(int gridX, int gridY, int lastGridX, int lastGridY)
        {
            if (m_selectedBrush == null || m_selectedMap == null)
            {
                return;
            }

            // Get the current layer
            EditorMapLayer activeLayer = GetSelectedLayer();

            // Get the old brush, for redrawing purposes
            EditorBrush       oldBrush            = GetSelectedLayer().GetBrushAt(gridX, gridY);
            ObjectOrientation oldBrushOrientation = null;

            if (oldBrush != null && oldBrush.FrontAsset != null && oldBrush.FrontAsset is StarboundObject)
            {
                oldBrushOrientation = ((StarboundObject)oldBrush.FrontAsset).GetCorrectOrientation(m_selectedMap, gridX,
                                                                                                   gridY);
            }

            // If there's nothing to change, just leave
            if (gridX == lastGridX && gridY == lastGridY)
            {
                return;
            }

            // Change the layer brush
            activeLayer.SetBrushAt(m_selectedBrush, gridX, gridY, true);

            // We need to selectively redraw here
            if (m_gridFactor != 1)
            {
                var additionalRedrawList = new HashSet <List <int> >();

                int xmin = gridX;
                int xmax = gridX;

                int ymin = gridY;
                int ymax = gridY;

                // If the old brush was an object, we must redraw around it
                if (oldBrushOrientation != null)
                {
                    int sizeX   = oldBrushOrientation.GetWidth(m_selectedBrush.Direction, 1);
                    int sizeY   = oldBrushOrientation.GetHeight(m_selectedBrush.Direction, 1);
                    int originX = oldBrushOrientation.GetOriginX(m_selectedBrush.Direction, 1);
                    int originY = oldBrushOrientation.GetOriginY(m_selectedBrush.Direction, 1);

                    // Update the minimum and maximum bounds
                    xmin += originX;
                    xmax += sizeX + originX;

                    ymin += originY;
                    ymax += sizeY + originY;
                }
                // If the old brush isn't an object, just redraw a tile
                else
                {
                    xmax += 1;
                    ymax += 1;
                }

                // If the current brush is an object
                // Extend the range of our bounds, so we encompass the old object, AND the new object
                if (m_selectedBrush.FrontAsset is StarboundObject)
                {
                    ObjectOrientation orientation =
                        ((StarboundObject)m_selectedBrush.FrontAsset).GetCorrectOrientation(m_selectedMap, gridX, gridY);

                    int sizeX   = orientation.GetWidth(m_selectedBrush.Direction, 1);
                    int sizeY   = orientation.GetHeight(m_selectedBrush.Direction, 1);
                    int originX = orientation.GetOriginX(m_selectedBrush.Direction, 1);
                    int originY = orientation.GetOriginY(m_selectedBrush.Direction, 1);

                    int newxmin = xmin + originX;
                    int newxmax = xmax + sizeX + originX;

                    int newymin = ymin + originY;
                    int newymax = ymax + sizeY + originY;

                    if (newxmin < xmin)
                    {
                        xmin = newxmin;
                    }

                    if (newxmax > xmax)
                    {
                        xmax = newxmax;
                    }

                    if (newymin < ymin)
                    {
                        ymin = newymin;
                    }

                    if (newymax > ymax)
                    {
                        ymax = newymax;
                    }
                }

                for (int x = xmin; x < xmax; ++x)
                {
                    for (int y = ymin; y < ymax; ++y)
                    {
                        HashSet <List <int> > collisions = null;

                        if (m_selectedMap is EditorMapPart)
                        {
                            collisions = activeLayer.Parent.GetCollisionsAt(x, y);
                        }
                        else if (m_selectedMap is EditorMapLayer)
                        {
                            collisions = activeLayer.GetCollisionsAt(x, y);
                        }

                        if (collisions == null)
                        {
                            continue;
                        }

                        foreach (List <int> coords in collisions.Where(coords =>
                                                                       (coords[0] != x || coords[1] != y) &&
                                                                       (coords[0] != gridX || coords[1] != gridY)))
                        {
                            additionalRedrawList.Add(coords);
                        }
                    }
                }

                // Selectively redraw the composite image
                if (m_selectedMap is EditorMapPart)
                {
                    activeLayer.Parent.UpdateLayerImageBetween(
                        xmin,
                        ymin,
                        xmax,
                        ymax);

                    foreach (var coords in additionalRedrawList)
                    {
                        activeLayer.Parent.UpdateLayerImageBetween(
                            coords[0],
                            coords[1],
                            coords[0] + 1,
                            coords[1] + 1);
                    }
                }

                // Only selectively redraw the active layer
                else if (m_selectedMap is EditorMapLayer)
                {
                    activeLayer.Parent.UpdateLayerImageBetween(
                        new List <EditorMapLayer> {
                        activeLayer
                    },
                        xmin,
                        ymin,
                        xmax,
                        ymax);

                    foreach (var coords in additionalRedrawList)
                    {
                        activeLayer.Parent.UpdateLayerImageBetween(
                            new List <EditorMapLayer> {
                            activeLayer
                        },
                            coords[0],
                            coords[1],
                            coords[0] + 1,
                            coords[1] + 1);
                    }
                }
            }

            // There MUST be an immediate refresh here
            // Otherwise the system will delay the refresh on large images
            MainPictureBox.Refresh();
        }
Ejemplo n.º 9
0
 public void destroyTextureBrush()
 {
     state = EditorState.idle;
     currentbrush = null;
 }
Ejemplo n.º 10
0
 public void createTextureBrush(string fullpath)
 {
     state = EditorState.brush;
     currentbrush = new EditorBrush(fullpath);
 }