Esempio n. 1
0
        public void Setup()
        {
            m_SelectedVertices = new List <int>();
            m_Selection        = Substitute.For <ISelection <int> >();
            m_Selection.Count.Returns(x => m_SelectedVertices.Count);
            m_Selection.Contains(Arg.Any <int>()).Returns(x => m_SelectedVertices.Contains((int)x[0]));
            m_Selection.elements.Returns(x => m_SelectedVertices.ToArray());
            m_Selection.activeElement.Returns(x =>
            {
                if (m_SelectedVertices.Count == 0)
                {
                    return(-1);
                }
                return(m_SelectedVertices[0]);
            });

            m_SpriteMeshData = new SpriteMeshData();
            m_SpriteMeshDataController.spriteMeshData = m_SpriteMeshData;
        }
Esempio n. 2
0
        public void SmoothWeights(int iterations, ISelection <int> selection)
        {
            var boneWeights = new BoneWeight[spriteMeshData.vertexCount];

            for (var i = 0; i < spriteMeshData.vertexCount; i++)
            {
                boneWeights[i] = spriteMeshData.GetWeight(i).ToBoneWeight(false);
            }

            BoneWeight[] smoothedWeights;
            SmoothingUtility.SmoothWeights(boneWeights, spriteMeshData.indices, spriteMeshData.boneCount, iterations, out smoothedWeights);

            for (var i = 0; i < spriteMeshData.vertexCount; i++)
            {
                if (selection == null || (selection.Count == 0 || selection.Contains(i)))
                {
                    spriteMeshData.GetWeight(i).SetFromBoneWeight(smoothedWeights[i]);
                }
            }
        }
Esempio n. 3
0
        protected override bool OnHotkeyActivated(KeyInput e)
        {
            var player = world.RenderPlayer ?? world.LocalPlayer;

            var bases = world.ActorsHavingTrait <BaseBuilding>()
                        .Where(a => a.Owner == player)
                        .ToList();

            // If no BaseBuilding exist pick the first selectable Building.
            if (!bases.Any())
            {
                var building = world.ActorsHavingTrait <Building>()
                               .FirstOrDefault(a => a.Owner == player && a.Info.HasTraitInfo <SelectableInfo>());

                // No buildings left
                if (building == null)
                {
                    return(true);
                }

                selection.Combine(world, new Actor[] { building }, false, true);
                viewport.Center(selection.Actors);
                return(true);
            }

            var next = bases
                       .SkipWhile(b => !selection.Contains(b))
                       .Skip(1)
                       .FirstOrDefault();

            if (next == null)
            {
                next = bases.First();
            }

            selection.Combine(world, new Actor[] { next }, false, true);
            viewport.Center(selection.Actors);

            return(true);
        }
Esempio n. 4
0
        public void CalculateWeights(IWeightsGenerator weightsGenerator, ISelection <int> selection, float filterTolerance)
        {
            Debug.Assert(spriteMeshData != null);

            Vector2[] controlPoints;
            Edge[]    bones;
            int[]     pins;

            GetControlPoints(out controlPoints, out bones, out pins);

            Vector2[] vertices = new Vector2[spriteMeshData.vertexCount];

            for (int i = 0; i < spriteMeshData.vertexCount; ++i)
            {
                vertices[i] = spriteMeshData.GetPosition(i);
            }

            BoneWeight[] boneWeights = weightsGenerator.Calculate(spriteMeshData.spriteName, vertices, spriteMeshData.indices.ToArray(), spriteMeshData.edges.ToArray(), controlPoints, bones, pins);

            Debug.Assert(boneWeights.Length == spriteMeshData.vertexCount);

            for (int i = 0; i < spriteMeshData.vertexCount; ++i)
            {
                if (selection == null || (selection.Count == 0 || selection.Contains(i)))
                {
                    EditableBoneWeight editableBoneWeight = EditableBoneWeightUtility.CreateFromBoneWeight(boneWeights[i]);

                    if (filterTolerance > 0f)
                    {
                        editableBoneWeight.FilterChannels(filterTolerance);
                        editableBoneWeight.Normalize();
                    }

                    spriteMeshData.SetWeight(i, editableBoneWeight);
                }
            }
        }
Esempio n. 5
0
        public void CalculateWeightsSafe(IWeightsGenerator weightsGenerator, ISelection <int> selection, float filterTolerance)
        {
            var tempSelection  = new IndexedSelection();
            var vertexSelector = new GenericVertexSelector();

            vertexSelector.spriteMeshData    = spriteMeshData;
            vertexSelector.selection         = tempSelection;
            vertexSelector.SelectionCallback = (int i) => {
                return(spriteMeshData.GetWeight(i).Sum() == 0f && (selection == null || selection.Count == 0 || selection.Contains(i)));
            };
            vertexSelector.Select();

            if (tempSelection.Count > 0)
            {
                CalculateWeights(weightsGenerator, tempSelection, filterTolerance);
            }
        }
Esempio n. 6
0
        /// <summary>Displays the next frame.</summary>
        public override void Render(IGraphics graphics, long currentTimeInMicroseconds)
        {
            ISelection selection = model.CurrentSelection;

            if (selection != null)
            {
                RectangleF area = view.StackInspectorArea;

                IStackInspectorCursorLocation cursorLocation = model.ThisPlayer.CursorLocation as IStackInspectorCursorLocation;

                // render background
                float scale = view.GameDisplayAreaInPixels.Height / 1200.0f;
                //image.Render(new RectangleF(area.X + 7.0f * scale, area.Y + 6.0f * scale, area.Width - 14.0f * scale, area.Height - 12.0f * scale), 0xb0f0c67d);
                frameImageElements[0].Render(new RectangleF(area.X, area.Y, 11.0f * scale, 10.0f * scale));
                frameImageElements[1].Render(new RectangleF(area.X + 11.0f * scale, area.Y, area.Width - 22.0f * scale, 10.0f * scale));
                frameImageElements[2].Render(new RectangleF(area.Right - 11.0f * scale, area.Y, 11.0f * scale, 10.0f * scale));
                frameImageElements[3].Render(new RectangleF(area.X, area.Y + 10.0f * scale, 11.0f * scale, area.Height - 20.0f * scale));
                frameImageElements[4].Render(new RectangleF(area.X + 11.0f * scale, area.Y + 10.0f * scale, area.Width - 22.0f * scale, area.Height - 20.0f * scale));
                frameImageElements[5].Render(new RectangleF(area.Right - 11.0f * scale, area.Y + 10.0f * scale, 11.0f * scale, area.Height - 20.0f * scale));
                frameImageElements[6].Render(new RectangleF(area.X, area.Bottom - 10.0f * scale, 11.0f * scale, 10.0f * scale));
                frameImageElements[7].Render(new RectangleF(area.X + 11.0f * scale, area.Bottom - 10.0f * scale, area.Width - 22.0f * scale, 10.0f * scale));
                frameImageElements[8].Render(new RectangleF(area.Right - 11.0f * scale, area.Bottom - 10.0f * scale, 11.0f * scale, 10.0f * scale));

                // render selected pieces
                float pieceScaling    = PieceScaling;
                float positionScaling = PositionScaling;

                IPiece[] piecesInStack  = selection.Stack.Pieces;
                PointF[] piecePositions = model.StackInspectorPositions;

                // computes modulation color for blinking
                uint blinkFactor          = (uint)(128 * Math.Sin((double)(currentTimeInMicroseconds % (long)400000) * (Math.PI / 200000.0)) + 128);
                uint blinkModulationColor = 0xFF000000 | blinkFactor << 16 | blinkFactor << 8 | blinkFactor;

                // render each selection hint (from back to front)
                float xOffset = area.X + area.Width * 0.5f;
                float yOffset = area.Y + piecesInStack[piecesInStack.Length - 1].Diagonal * 0.5f * pieceScaling;
                for (int i = 0; i < piecesInStack.Length; ++i)
                {
                    if (piecePositions[i].X != 1.0f)
                    {
                        IPiece piece = piecesInStack[i];
                        if (selection.Contains(piece))
                        {
                            SizeF      pieceSize        = piece.Size;
                            PointF     position         = new PointF(xOffset, yOffset + piecePositions[i].Y * positionScaling);
                            float      flipAngleCosinus = piece.FlipAngleCosinus;
                            RectangleF localisation     = new RectangleF(
                                position.X - (pieceSize.Width * flipAngleCosinus * pieceScaling) * 0.5f - 2.0f,
                                position.Y - (pieceSize.Height * pieceScaling) * 0.5f - 2.0f,
                                pieceSize.Width * flipAngleCosinus * pieceScaling + 4.0f,
                                pieceSize.Height * pieceScaling + 4.0f);
                            piece.Graphics.RenderSilhouette(localisation, piece.RotationAngle, blinkModulationColor);
                        }
                    }
                }

                // render each piece in order (from back to front)
                for (int i = 0; i < piecesInStack.Length; ++i)
                {
                    if (piecePositions[i].X != 1.0f)
                    {
                        IPiece piece = piecesInStack[i];

                        SizeF      pieceSize        = piece.Size;
                        PointF     position         = new PointF(xOffset, yOffset + piecePositions[i].Y * positionScaling);
                        float      flipAngleCosinus = piece.FlipAngleCosinus;
                        RectangleF localisation     = new RectangleF(
                            position.X - (pieceSize.Width * flipAngleCosinus * pieceScaling) * 0.5f,
                            position.Y - (pieceSize.Height * pieceScaling) * 0.5f,
                            pieceSize.Width * flipAngleCosinus * pieceScaling,
                            pieceSize.Height * pieceScaling);
                        piece.Graphics.Render(localisation, piece.RotationAngle);
                    }
                }

                // render insertion mark, if needed
                if (cursorLocation != null && (model.ThisPlayer.PieceBeingDragged != null || model.ThisPlayer.StackBeingDragged != null))
                {
                    int insertionIndex = cursorLocation.Index;

                    // ideal arrangement of pieces in stack inspector (to avoid too much wobbling)
                    float yPos;
                    if (insertionIndex == 0)
                    {
                        float bottomPieceYPos     = yOffset + piecePositions[0].Y * positionScaling;
                        float bottomPieceDiagonal = piecesInStack[0].Diagonal;
                        yPos = bottomPieceYPos + bottomPieceDiagonal * 0.5f * pieceScaling - 3.0f;
                    }
                    else if (insertionIndex == piecesInStack.Length)
                    {
                        yPos = area.Top + 3.0f;
                    }
                    else
                    {
                        float precedingPieceYPos     = yOffset + piecePositions[insertionIndex - 1].Y * positionScaling;
                        float nextPieceYPos          = yOffset + piecePositions[insertionIndex].Y * positionScaling;
                        float precedingPieceDiagonal = piecesInStack[insertionIndex - 1].Diagonal;
                        float nextPieceDiagonal      = piecesInStack[insertionIndex].Diagonal;

                        yPos = nextPieceYPos + (precedingPieceYPos - nextPieceYPos) * precedingPieceDiagonal / (precedingPieceDiagonal + nextPieceDiagonal);
                    }

                    IImage image = graphics.MonochromaticImage;
                    image.Render(new RectangleF(area.X + 2.0f, yPos - 1.0f, area.Width - 4.0f, 3.0f));
                }

                // icons
                closeIcon.Render(new RectangleF(area.Right - 11.0f * scale - 13.0f, area.Y + 10.0f * scale, 13.0f, 12.0f),
                                 (cursorLocation != null && cursorLocation.Icon == StackInspectorIcon.Close && model.ThisPlayer.StackBeingDragged == null && model.ThisPlayer.PieceBeingDragged == null ? 0xff7fff7f : 0xffffffff));
                invertIcon.Render(new RectangleF(area.Left + 11.0f * scale, area.Y + 10.0f * scale, 11.0f, 12.0f),
                                  (selection.Stack.Pieces.Length < 2 ? 0xff7f7f7f : (cursorLocation != null && cursorLocation.Icon == StackInspectorIcon.Invert && model.ThisPlayer.StackBeingDragged == null && model.ThisPlayer.PieceBeingDragged == null ? 0xff7fff7f : 0xffffffff)));
                shuffleIcon.Render(new RectangleF(area.Left + 2 * 11.0f * scale + 11.0f, area.Y + 10.0f * scale, 16.0f, 13.0f),
                                   (selection.Stack.Pieces.Length < 2 ? 0xff7f7f7f : (cursorLocation != null && cursorLocation.Icon == StackInspectorIcon.Shuffle && model.ThisPlayer.StackBeingDragged == null && model.ThisPlayer.PieceBeingDragged == null ? 0xff7fff7f : 0xffffffff)));
                recycleIcon.Render(new RectangleF(area.Left + 3 * 11.0f * scale + 27.0f, area.Y + 10.0f * scale, 13.0f, 12.0f),
                                   (selection.Empty || selection.Stack.AttachedToCounterSection ? 0xff7f7f7f : (cursorLocation != null && cursorLocation.Icon == StackInspectorIcon.Recycle && model.ThisPlayer.StackBeingDragged == null && model.ThisPlayer.PieceBeingDragged == null ? 0xff7fff7f : 0xffffffff)));

                // tool tips
                if (cursorLocation != null && model.ThisPlayer.StackBeingDragged == null && model.ThisPlayer.PieceBeingDragged == null)
                {
                    if (cursorLocation.Icon == StackInspectorIcon.Close)
                    {
                        graphics.DrawText(font, 0xff7fff7f,
                                          new RectangleF(area.Right - 11.0f * scale - 13.0f, area.Y + 10.0f * scale - 17.0f, 13.0f, 17.0f), StringAlignment.Near,
                                          Resources.ToolTipClose);
                    }
                    else if (cursorLocation.Icon == StackInspectorIcon.Recycle)
                    {
                        graphics.DrawText(font, (selection.Empty || selection.Stack.AttachedToCounterSection ? 0xff7f7f7f : 0xff7fff7f),
                                          new RectangleF(area.Left + 3 * 11.0f * scale + 27.0f, area.Y + 10.0f * scale - 17.0f, 13.0f, 17.0f), StringAlignment.Near,
                                          Resources.ToolTipRecycle);
                    }
                    else if (cursorLocation.Icon == StackInspectorIcon.Shuffle)
                    {
                        graphics.DrawText(font, (selection.Stack.Pieces.Length < 2 ? 0xff7f7f7f : 0xff7fff7f),
                                          new RectangleF(area.Left + 2 * 11.0f * scale + 11.0f, area.Y + 10.0f * scale - 17.0f, 13.0f, 17.0f), StringAlignment.Near,
                                          Resources.ToolTipShuffle);
                    }
                    else if (cursorLocation.Icon == StackInspectorIcon.Invert)
                    {
                        graphics.DrawText(font, (selection.Stack.Pieces.Length < 2 ? 0xff7f7f7f : 0xff7fff7f),
                                          new RectangleF(area.Left + 11.0f * scale, area.Y + 10.0f * scale - 17.0f, 13.0f, 17.0f), StringAlignment.Near,
                                          Resources.ToolTipInvert);
                    }
                }
            }
        }