Exemple #1
0
        //node addition
        private void buttonAddNode_Click(object sender, EventArgs e)
        {
            Node.BodyType type  = Node.BodyType.Block;
            Size          size  = blockSize;
            Layer         layer = Layer.None;

            //if(comboBoxAddNode.Text == "Block")
            //{
            //    type = Node.BodyType.Block;
            //}
            //else
            switch (comboBoxAddNode.Text)
            {
            case "Solid":
                type = Node.BodyType.Solid;
                size = solidSize;
                break;

            case "Item":
                type = Node.BodyType.Item;
                size = itemSize;
                break;

            case "Water":
                type = Node.BodyType.Water;
                break;

            case "Light":
                type = Node.BodyType.Light;
                size = lightSize;
                break;

            case "Detail":
                if (m_spriteSheets.Count > 0)
                {
                    type = Node.BodyType.Detail;
                    size = m_selectedFrame.largeImage.Size;
                    //layer = Layer.RearDetail;
                    break;
                }
                MessageBox.Show("Details cannot be added when no sprite sheets are loaded");
                return;

            default: break;
            }

            selectNode(addNode(type, new Point(960, 540), size, layer));
        }
Exemple #2
0
        private void comboBoxNodePropertyType_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (m_selectedNode != null)
            {
                checkBoxFrontDetail.Enabled = false;
                //checkBoxFrontDetail.Checked = false;

                Node.BodyType type     = (Node.BodyType)comboBoxNodePropertyType.SelectedValue;
                var           nodeData = (NodeData)m_selectedNode.Tag;
                if (nodeData.type == type)
                {
                    return;
                }

                //check if we're currently a light and remove from light array if necessary
                if (nodeData.light != null)
                {
                    m_lights.Remove(nodeData.light);
                    nodeData.light = null;
                }

                nodeData.type        = type;
                nodeData.spriteSheet = null;
                nodeData.frameName   = null;

                var oldLayer = nodeData.layer;

                switch (type)
                {
                case Node.BodyType.Block:
                    m_selectedNode.BackColor       = blockColour;
                    m_selectedNode.Width           = blockSize.Width / scale;
                    m_selectedNode.Height          = blockSize.Height / scale;
                    m_selectedNode.BackgroundImage = Properties.Resources.block;
                    m_selectedNode.Size            = new Size(blockSize.Width / scale, blockSize.Height / scale);
                    nodeData.layer = Layer.Dynamic;

                    if (nodeData.drawable != null)
                    {
                        nodeData.drawable.FillColor      = SFML.Graphics.Color.White;
                        nodeData.drawable.Texture        = m_textureResource.Get("icons/block.png");
                        nodeData.drawable.Texture.Smooth = true;
                        nodeData.drawable.TextureRect    = new SFML.Graphics.IntRect(0, 0, (int)nodeData.drawable.Texture.Size.X, (int)nodeData.drawable.Texture.Size.Y);
                    }

                    break;

                case Node.BodyType.Item:
                    m_selectedNode.BackColor       = bonusColour;
                    m_selectedNode.Width           = itemSize.Width / scale;
                    m_selectedNode.Height          = itemSize.Height / scale;
                    m_selectedNode.BackgroundImage = Properties.Resources.item;
                    m_selectedNode.Size            = new Size(itemSize.Width / scale, itemSize.Height / scale);
                    nodeData.layer = Layer.Dynamic;

                    if (nodeData.drawable != null)
                    {
                        nodeData.drawable.FillColor      = SFML.Graphics.Color.White;
                        nodeData.drawable.Texture        = m_textureResource.Get("icons/item.png");
                        nodeData.drawable.Texture.Smooth = true;
                        nodeData.drawable.TextureRect    = new SFML.Graphics.IntRect(0, 0, (int)nodeData.drawable.Texture.Size.X, (int)nodeData.drawable.Texture.Size.Y);
                    }

                    break;

                case Node.BodyType.Solid:
                    m_selectedNode.BackColor       = solidColour;
                    m_selectedNode.BackgroundImage = null;
                    nodeData.layer = Layer.Solid;

                    if (nodeData.drawable != null)
                    {
                        string texturePath = m_mapTextureDirectory + "\\" + m_platformFileName;
                        if (File.Exists(texturePath))
                        {
                            nodeData.drawable.FillColor        = SFML.Graphics.Color.White;
                            nodeData.drawable.Texture          = m_textureResource.Get(texturePath);
                            nodeData.drawable.Texture.Repeated = true;
                            nodeData.drawable.TextureRect      = new SFML.Graphics.IntRect((int)nodeData.drawable.Position.X, (int)nodeData.drawable.Position.Y,
                                                                                           (int)numericUpDownNodePropertySizeX.Value, (int)numericUpDownNodePropertySizeY.Value);
                            nodeData.drawable.FillColor = SFML.Graphics.Color.White;
                        }
                        else
                        {
                            nodeData.drawable.FillColor = new SFML.Graphics.Color(solidColour.R, solidColour.G, solidColour.B);
                            nodeData.drawable.Texture   = null;
                        }
                    }

                    break;

                case Node.BodyType.Water:
                    m_selectedNode.BackColor       = waterColour;
                    m_selectedNode.BackgroundImage = null;
                    nodeData.layer = Layer.Water;

                    if (nodeData.drawable != null)
                    {
                        nodeData.drawable.FillColor = waterFillColour;
                        nodeData.drawable.Texture   = null;
                    }

                    break;

                case Node.BodyType.Detail:
                    if (m_spriteSheets.Count > 0)
                    {
                        m_selectedNode.BackColor       = Color.Transparent;
                        m_selectedNode.BackgroundImage = m_selectedFrame.smallImage;
                        m_selectedNode.Size            = m_selectedFrame.smallImage.Size;
                        nodeData.layer              = Layer.RearDetail;
                        nodeData.spriteSheet        = m_selectedFrame.parentSheet.meta.image;
                        nodeData.frameName          = m_selectedFrame.filename;
                        checkBoxFrontDetail.Enabled = true;

                        if (nodeData.drawable != null)
                        {
                            var size = new Size(m_selectedNode.Size.Width * scale, m_selectedNode.Size.Height * scale);
                            nodeData.drawable.Size        = new SFML.Window.Vector2f(size.Width, size.Height);
                            nodeData.drawable.Texture     = m_textureResource.Get(m_atlasTextureDirectory + "\\" + nodeData.spriteSheet);
                            nodeData.drawable.TextureRect = m_selectedFrame.subrect;

                            if (m_selectedFrame.rotated)
                            {
                                nodeData.drawable.Rotation = -90f;
                                nodeData.drawable.Origin   = new SFML.Window.Vector2f(nodeData.drawable.Size.Y, 0f);
                                nodeData.drawable.Size     = new SFML.Window.Vector2f(nodeData.drawable.Size.Y, nodeData.drawable.Size.X);
                            }
                            else
                            {
                                nodeData.drawable.Rotation = 0f;
                                nodeData.drawable.Origin   = new SFML.Window.Vector2f();
                            }
                        }
                        break;
                    }
                    else
                    {
                        //TODO find previously selected index and return to it
                        comboBoxNodePropertyType.SelectedIndex--;
                        return;
                    }

                case Node.BodyType.Light:

                    //check we have lights availble first
                    if (m_lights.Count < m_maxLights)
                    {
                        m_selectedNode.Width           = lightSize.Width / scale;
                        m_selectedNode.Height          = lightSize.Height / scale;
                        m_selectedNode.BackgroundImage = Properties.Resources.bulb;
                        nodeData.layer = Layer.FrontDetail;

                        if (nodeData.drawable != null)
                        {
                            nodeData.drawable.FillColor   = SFML.Graphics.Color.White;
                            nodeData.drawable.Texture     = m_textureResource.Get("icons/bulb2.png");
                            nodeData.drawable.TextureRect = new SFML.Graphics.IntRect(0, 0, (int)nodeData.drawable.Texture.Size.X, (int)nodeData.drawable.Texture.Size.Y);
                        }

                        nodeData.light          = new Light();
                        nodeData.light.Colour   = SFML.Graphics.Color.White;
                        nodeData.light.Range    = 700f;
                        nodeData.light.Position = new SFML.Window.Vector2f(m_selectedNode.Left * scale + m_selectedNode.Width, m_selectedNode.Top * scale + m_selectedNode.Height);
                        m_lights.Add(nodeData.light);

                        break;
                    }
                    else
                    {
                        //TODO find previously selected index and return to it
                        comboBoxNodePropertyType.SelectedIndex--;
                        return;
                    }

                default: break;
                }

                //update drawable if necessary
                if (nodeData.drawable != null)
                {
                    nodeData.drawable.Size = new SFML.Window.Vector2f(m_selectedNode.Size.Width * scale, m_selectedNode.Height * scale);
                    m_previewLayers[(int)nodeData.layer].Add(nodeData.drawable);
                    m_previewLayers[(int)oldLayer].Remove(nodeData.drawable);
                }


                m_selectedNode.Tag = nodeData;

                if (type == Node.BodyType.Solid ||
                    type == Node.BodyType.Water)
                {
                    numericUpDownNodePropertySizeX.Enabled = true;
                    numericUpDownNodePropertySizeY.Enabled = true;
                }
                else
                {
                    numericUpDownNodePropertySizeX.Enabled = false;
                    numericUpDownNodePropertySizeY.Enabled = false;
                }

                //sort layers
                sortNodes();
            }
        }
        /// <summary>
        /// adds a node to the UI
        /// </summary>
        /// <param name="type">Type of node</param>
        /// <param name="position">Position of node</param>
        /// <param name="size">Size of node</param>
        private Panel addNode(Node.BodyType type, Point position, Size size, Layer layer = Layer.None)
        {
            //divide by two as UI is half world game world size
            Panel p = new Panel();

            p.Left   = position.X / scale;
            p.Top    = position.Y / scale;
            p.Width  = size.Width / scale;
            p.Height = size.Height / scale;

            p.MouseDown += mouseDown;
            p.MouseUp   += mouseUp;
            p.MouseMove += mouseMove;

            NodeData nd = new NodeData();

            nd.type = type;

            switch (type)
            {
            case Node.BodyType.Block:
                p.BackColor        = blockColour;
                p.Move            += node_Move;
                p.ContextMenuStrip = m_nodeMenu;
                p.BackgroundImage  = Properties.Resources.block;
                nd.layer           = Layer.Dynamic;
                {
                    var shape = new SFML.Graphics.RectangleShape();
                    shape.Texture        = m_textureResource.Get("icons/block.png");
                    shape.Texture.Smooth = true;
                    shape.Size           = new SFML.Window.Vector2f(shape.Texture.Size.X, shape.Texture.Size.Y) * scale;
                    shape.TextureRect    = new SFML.Graphics.IntRect(0, 0, (int)shape.Texture.Size.X, (int)shape.Texture.Size.Y);
                    shape.Position       = new SFML.Window.Vector2f(position.X, position.Y);
                    m_previewLayers[(int)Layer.Dynamic].Add(shape);
                    nd.drawable = shape;
                }

                break;

            case Node.BodyType.PlayerOne:
                p.BackColor       = playerOneColour;
                p.Move           += p1_Move;
                p.BackgroundImage = Properties.Resources.player_one;
                nd.layer          = Layer.Dynamic;

                numericUpDownPlayerOneX.ValueChanged -= numericUpDownPlayerOneX_ValueChanged;
                numericUpDownPlayerOneY.ValueChanged -= numericUpDownPlayerOneY_ValueChanged;
                numericUpDownPlayerOneX.Value         = (decimal)position.X;
                numericUpDownPlayerOneY.Value         = (decimal)position.Y;
                numericUpDownPlayerOneX.ValueChanged += numericUpDownPlayerOneX_ValueChanged;
                numericUpDownPlayerOneY.ValueChanged += numericUpDownPlayerOneY_ValueChanged;
                {
                    var shape = new SFML.Graphics.RectangleShape();
                    shape.Texture        = m_textureResource.Get("icons/player_one.png");
                    shape.Texture.Smooth = true;
                    shape.Size           = new SFML.Window.Vector2f(shape.Texture.Size.X, shape.Texture.Size.Y) * scale;
                    shape.TextureRect    = new SFML.Graphics.IntRect(0, 0, (int)shape.Texture.Size.X, (int)shape.Texture.Size.Y);
                    shape.Position       = new SFML.Window.Vector2f(position.X, position.Y);
                    m_previewLayers[(int)Layer.Dynamic].Add(shape);
                    nd.drawable = shape;
                }
                break;

            case Node.BodyType.PlayerTwo:
                p.BackColor       = playerTwoColour;
                p.Move           += p2_Move;
                p.BackgroundImage = Properties.Resources.player_two;
                nd.layer          = Layer.Dynamic;

                numericUpDownPlayerTwoX.ValueChanged -= numericUpDownPlayerTwoX_ValueChanged;
                numericUpDownPlayerTwoY.ValueChanged -= numericUpDownPlayerTwoY_ValueChanged;
                numericUpDownPlayerTwoX.Value         = (decimal)position.X;
                numericUpDownPlayerTwoY.Value         = (decimal)position.Y;
                numericUpDownPlayerTwoX.ValueChanged += numericUpDownPlayerTwoX_ValueChanged;
                numericUpDownPlayerTwoY.ValueChanged += numericUpDownPlayerTwoY_ValueChanged;
                {
                    var shape = new SFML.Graphics.RectangleShape();
                    shape.Texture        = m_textureResource.Get("icons/player_two.png");
                    shape.Texture.Smooth = true;
                    shape.Size           = new SFML.Window.Vector2f(shape.Texture.Size.X, shape.Texture.Size.Y) * scale;
                    shape.TextureRect    = new SFML.Graphics.IntRect(0, 0, (int)shape.Texture.Size.X, (int)shape.Texture.Size.Y);
                    shape.Position       = new SFML.Window.Vector2f(position.X, position.Y);
                    m_previewLayers[(int)Layer.Dynamic].Add(shape);
                    nd.drawable = shape;
                }
                break;

            case Node.BodyType.Solid:
                p.BackColor = solidColour;
                if (m_platformTexture != null)
                {
                    p.BackgroundImage = m_platformTexture;
                }
                p.Move            += node_Move;
                p.ContextMenuStrip = m_nodeMenu;
                nd.layer           = Layer.Solid;
                {
                    var shape = new SFML.Graphics.RectangleShape(new SFML.Window.Vector2f(Size.Width, size.Height));
                    shape.FillColor = new SFML.Graphics.Color(solidColour.R, solidColour.G, solidColour.B);
                    string texturePath = m_mapTextureDirectory + "\\" + m_platformFileName;
                    if (File.Exists(texturePath))
                    {
                        shape.Texture          = m_textureResource.Get(texturePath);
                        shape.Texture.Repeated = true;
                        shape.TextureRect      = new SFML.Graphics.IntRect(position.X, position.Y, size.Width, size.Height);
                        shape.FillColor        = SFML.Graphics.Color.White;
                    }

                    shape.Size     = new SFML.Window.Vector2f(size.Width, size.Height);
                    shape.Position = new SFML.Window.Vector2f(position.X, position.Y);
                    m_previewLayers[(int)Layer.Solid].Add(shape);
                    nd.drawable = shape;
                }


                break;

            case Node.BodyType.Item:
                p.BackColor        = bonusColour;
                p.Move            += node_Move;
                p.ContextMenuStrip = m_nodeMenu;
                p.BackgroundImage  = Properties.Resources.item;
                nd.layer           = Layer.Dynamic;
                {
                    var shape = new SFML.Graphics.RectangleShape();
                    shape.Texture     = m_textureResource.Get("icons/item.png");
                    shape.Size        = new SFML.Window.Vector2f(shape.Texture.Size.X, shape.Texture.Size.Y) * scale;
                    shape.TextureRect = new SFML.Graphics.IntRect(0, 0, (int)shape.Texture.Size.X, (int)shape.Texture.Size.Y);
                    shape.Position    = new SFML.Window.Vector2f(position.X, position.Y);
                    m_previewLayers[(int)Layer.Dynamic].Add(shape);
                    nd.drawable = shape;
                }
                break;

            case Node.BodyType.Water:
                p.BackColor        = waterColour;
                p.Move            += node_Move;
                p.ContextMenuStrip = m_nodeMenu;
                nd.layer           = Layer.Water;
                {
                    var shape = new SFML.Graphics.RectangleShape();
                    shape.Size      = new SFML.Window.Vector2f(size.Width, size.Height);
                    shape.Position  = new SFML.Window.Vector2f(position.X, position.Y);
                    shape.FillColor = waterFillColour;

                    m_previewLayers[(int)Layer.Water].Add(shape);
                    nd.drawable = shape;
                }
                break;

            case Node.BodyType.Light:
                if (m_lights.Count < m_maxLights)
                {
                    p.BackColor        = sunColour;
                    p.Move            += node_Move;
                    p.ContextMenuStrip = m_nodeMenu;
                    p.BackgroundImage  = Properties.Resources.bulb;
                    nd.layer           = Layer.FrontDetail;
                    {
                        var shape = new SFML.Graphics.RectangleShape();
                        shape.Texture     = m_textureResource.Get("icons/bulb2.png");
                        shape.Size        = new SFML.Window.Vector2f(shape.Texture.Size.X, shape.Texture.Size.Y);// *scale;
                        shape.TextureRect = new SFML.Graphics.IntRect(0, 0, (int)shape.Texture.Size.X, (int)shape.Texture.Size.Y);
                        shape.Position    = new SFML.Window.Vector2f(position.X, position.Y);
                        shape.FillColor   = new SFML.Graphics.Color(sunColour.R, sunColour.G, sunColour.B);
                        m_previewLayers[(int)Layer.Dynamic].Add(shape);
                        nd.drawable = shape;
                    }
                    nd.light          = new Light();
                    nd.light.Colour   = new SFML.Graphics.Color(sunColour.R, sunColour.G, sunColour.B);
                    nd.light.Position = new SFML.Window.Vector2f(position.X + (size.Width / 2), position.Y + (size.Height / 2));
                    nd.light.Range    = 700f;
                    m_lights.Add(nd.light);
                }
                else
                {
                    MessageBox.Show("Maps cannot contain more than 4 dynamic lights");
                    return(null);
                }
                break;

            case Node.BodyType.Detail:
                p.BackColor        = Color.Transparent;
                p.BackgroundImage  = m_selectedFrame.smallImage;
                p.Move            += node_Move;
                p.ContextMenuStrip = m_nodeMenu;
                nd.layer           = (layer == Layer.None) ? Layer.RearDetail : layer;
                nd.frameName       = m_selectedFrame.filename;
                nd.spriteSheet     = m_selectedFrame.parentSheet.meta.image;
                {
                    var shape = new SFML.Graphics.RectangleShape();
                    shape.Size        = new SFML.Window.Vector2f(size.Width, size.Height);
                    shape.Position    = new SFML.Window.Vector2f(position.X, position.Y);
                    shape.Texture     = m_textureResource.Get(m_atlasTextureDirectory + "\\" + nd.spriteSheet);
                    shape.TextureRect = m_selectedFrame.subrect;
                    if (m_selectedFrame.rotated)
                    {
                        shape.Size     = new SFML.Window.Vector2f(size.Height, size.Width);
                        shape.Rotation = -90f;
                        shape.Origin   = new SFML.Window.Vector2f(size.Height, 0f);
                    }

                    m_previewLayers[(int)nd.layer].Add(shape);
                    nd.drawable = shape;
                }
                break;

            default: break;
            }

            if (layer != Layer.None)
            {
                nd.layer = layer;
            }
            p.Tag = nd;
            panelEditorInner.Controls.Add(p);
            if (m_canSort)
            {
                sortNodes();
            }
            return(p);
        }