Пример #1
0
        private void DrawHangingWire(SpriteBatch spriteBatch, Vector2 start, float depth)
        {
            float   angle  = (float)Math.Sin(GameMain.GameScreen.GameTime * 2.0f + item.ID) * 0.2f;
            Vector2 endPos = start + new Vector2((float)Math.Sin(angle), -(float)Math.Cos(angle)) * 50.0f;

            WireSection.Draw(
                spriteBatch,
                start, endPos,
                Color.Orange, depth + 0.00001f, 0.2f);

            WireSection.Draw(
                spriteBatch,
                start, start + (endPos - start) * 0.7f,
                item.Color, depth, 0.3f);
        }
Пример #2
0
        public void Draw(SpriteBatch spriteBatch, bool editing)
        {
            if (sections.Count == 0 && !IsActive)
            {
                Drawable = false;
                return;
            }

            Vector2 drawOffset = Vector2.Zero;

            if (item.Submarine != null)
            {
                drawOffset = item.Submarine.DrawPosition + item.Submarine.HiddenSubPosition;
            }

            float depth = item.IsSelected ? 0.0f : wireSprite.Depth + ((item.ID % 100) * 0.00001f);

            if (item.IsHighlighted)
            {
                foreach (WireSection section in sections)
                {
                    section.Draw(spriteBatch, Color.Gold, drawOffset, depth + 0.00001f, 0.7f);
                }
            }
            else if (item.IsSelected)
            {
                foreach (WireSection section in sections)
                {
                    section.Draw(spriteBatch, Color.Red, drawOffset, depth + 0.00001f, 0.7f);
                }
            }

            foreach (WireSection section in sections)
            {
                section.Draw(spriteBatch, item.Submarine == null ? Color.Green : item.Color, drawOffset, depth, 0.3f);
            }

            if (IsActive && nodes.Count > 0 && Vector2.Distance(newNodePos, nodes[nodes.Count - 1]) > nodeDistance)
            {
                Submarine sub = null;
                if (connections[0] != null && connections[0].Item.Submarine != null)
                {
                    sub = connections[0].Item.Submarine;
                }
                if (connections[1] != null && connections[1].Item.Submarine != null)
                {
                    sub = connections[1].Item.Submarine;
                }
                if (sub != null)
                {
                    drawOffset = sub.DrawPosition + sub.HiddenSubPosition;
                }

                WireSection.Draw(
                    spriteBatch,
                    new Vector2(nodes[nodes.Count - 1].X, nodes[nodes.Count - 1].Y) + drawOffset,
                    new Vector2(newNodePos.X, newNodePos.Y) + drawOffset,
                    item.Color * 0.5f,
                    depth,
                    0.3f);
            }

            if (!editing || !GameMain.SubEditorScreen.WiringMode)
            {
                return;
            }

            for (int i = 0; i < nodes.Count; i++)
            {
                Vector2 drawPos = nodes[i];
                if (item.Submarine != null)
                {
                    drawPos += item.Submarine.Position + item.Submarine.HiddenSubPosition;
                }
                drawPos.Y = -drawPos.Y;

                if ((highlightedNodeIndex == i && item.IsHighlighted) || (selectedNodeIndex == i && item.IsSelected))
                {
                    GUI.DrawRectangle(spriteBatch, drawPos + new Vector2(-10, -10), new Vector2(20, 20), Color.Red, false, 0.0f);
                }

                if (item.IsSelected)
                {
                    GUI.DrawRectangle(spriteBatch, drawPos + new Vector2(-5, -5), new Vector2(10, 10), item.Color, true, 0.0f);
                }
                else
                {
                    GUI.DrawRectangle(spriteBatch, drawPos + new Vector2(-3, -3), new Vector2(6, 6), item.Color, true, 0.0f);
                }
            }
        }
Пример #3
0
        public void Draw(SpriteBatch spriteBatch, bool editing, float itemDepth = -1)
        {
            if (sections.Count == 0 && !IsActive || Hidden)
            {
                Drawable = false;
                return;
            }

            Vector2   drawOffset = Vector2.Zero;
            Submarine sub        = item.Submarine;

            if (IsActive && sub == null) // currently being rewired, we need to get the sub from the connections in case the wire has been taken outside
            {
                if (connections[0] != null && connections[0].Item.Submarine != null)
                {
                    sub = connections[0].Item.Submarine;
                }
                if (connections[1] != null && connections[1].Item.Submarine != null)
                {
                    sub = connections[1].Item.Submarine;
                }
            }

            if (sub != null)
            {
                drawOffset = sub.DrawPosition + sub.HiddenSubPosition;
            }

            float depth = item.IsSelected ? 0.0f : wireSprite.Depth + ((item.ID % 100) * 0.00001f);

            if (item.IsHighlighted)
            {
                foreach (WireSection section in sections)
                {
                    section.Draw(spriteBatch, this, Color.Gold, drawOffset, depth + 0.00001f, 0.7f);
                }
            }
            else if (item.IsSelected)
            {
                foreach (WireSection section in sections)
                {
                    section.Draw(spriteBatch, this, Color.Red, drawOffset, depth + 0.00001f, 0.7f);
                }
            }

            foreach (WireSection section in sections)
            {
                section.Draw(spriteBatch, this, item.Color, drawOffset, depth, 0.3f);
            }

            if (nodes.Count > 0)
            {
                if (!IsActive)
                {
                    if (connections[0] == null)
                    {
                        DrawHangingWire(spriteBatch, nodes[0] + drawOffset, depth);
                    }
                    if (connections[1] == null)
                    {
                        DrawHangingWire(spriteBatch, nodes.Last() + drawOffset, depth);
                    }
                }
                if (IsActive && Vector2.Distance(newNodePos, nodes[nodes.Count - 1]) > nodeDistance)
                {
                    WireSection.Draw(
                        spriteBatch,
                        this,
                        new Vector2(nodes[nodes.Count - 1].X, nodes[nodes.Count - 1].Y) + drawOffset,
                        new Vector2(newNodePos.X, newNodePos.Y) + drawOffset,
                        item.Color * 0.5f,
                        depth,
                        0.3f);
                }
            }

            if (!editing || !GameMain.SubEditorScreen.WiringMode)
            {
                return;
            }

            for (int i = 0; i < nodes.Count; i++)
            {
                Vector2 drawPos = nodes[i];
                if (item.Submarine != null)
                {
                    drawPos += item.Submarine.Position + item.Submarine.HiddenSubPosition;
                }
                drawPos.Y = -drawPos.Y;

                if ((highlightedNodeIndex == i && item.IsHighlighted) || (selectedNodeIndex == i && item.IsSelected))
                {
                    GUI.DrawRectangle(spriteBatch, drawPos + new Vector2(-10, -10), new Vector2(20, 20), Color.Red, false, 0.0f);
                }

                if (item.IsSelected)
                {
                    GUI.DrawRectangle(spriteBatch, drawPos + new Vector2(-5, -5), new Vector2(10, 10), item.Color, true, 0.0f);
                }
                else
                {
                    GUI.DrawRectangle(spriteBatch, drawPos + new Vector2(-3, -3), new Vector2(6, 6), item.Color, true, 0.0f);
                }
            }
        }