Пример #1
0
        public void Update(GameTime gameTime, Dictionary dictionary)
        {
            var mouseState = Mouse.GetState();

            SwipeKeyboard.GetBoundingBox(_centerPosition, out Vector2 cornerKeyboard, out Vector2 sizeKeyboard);

            Rectangle interactRect = VirtualCoords.ComputePixelRect(cornerKeyboard - new Vector2(CONSTELLATION_WIDTH * 0.01f), sizeKeyboard + new Vector2(CONSTELLATION_WIDTH * 0.02f));

            if (interactRect.Contains(mouseState.Position)) // TODO: or intersects word rect
            {
                _selectionInterpolation = _selectionInterpolation + (float)gameTime.ElapsedGameTime.TotalSeconds / SELECTION_ANIMATION_DURATION;
                _selectionInterpolation = Math.Min(1f, _selectionInterpolation);
            }
            else
            {
                _selectionInterpolation = _selectionInterpolation - (float)gameTime.ElapsedGameTime.TotalSeconds / SELECTION_ANIMATION_DURATION;
                _selectionInterpolation = Math.Max(0f, _selectionInterpolation);
            }

            _swipeLine.Update(gameTime, _centerPosition);

            _associatedWord.ActiveWord = dictionary.ClosestWordToSwipePattern(_swipeLine.HandlePositionsRelative);

            _associatedWord.UpdateConstallationWord(_selectionInterpolation);
        }
Пример #2
0
        public Constellation(Word word, Vector2 center)
        {
            _associatedWord         = word;
            _centerPosition         = center;
            _underlyingKeyboard     = new SwipeKeyboard();
            _swipeLine              = new SwipeLine(word.OriginalWord);
            _selectionInterpolation = 0;

            OriginalConfiguration = SwipeKeyboard.WordToSwipePositions(_associatedWord.OriginalWord).ToArray();
        }
Пример #3
0
        public void Update()
        {
            var mouseState = Mouse.GetState();

            SwipeKeyboard.GetBoundingBox(_centerPosition, out Vector2 cornerKeyboard, out Vector2 sizeKeyboard);

            Rectangle interactRect = DrawArea();

            IsPressed = mouseState.LeftButton == ButtonState.Pressed && _mouseStateLastFrame == ButtonState.Released && interactRect.Contains(mouseState.Position);

            _mouseStateLastFrame = mouseState.LeftButton;
        }
Пример #4
0
        public void Load()
        {
            var dict = File.ReadLines("Content/dictionary.txt").ToList();

            _wordsByLength = new List <List <string> >();
            for (int i = 0; i < 10; ++i)
            {
                _wordsByLength.Add(dict.Where(w => w.Length == i).ToList());
            }

            // UNIT TEST
            var testWord = "princess";

            Debug.Assert(ClosestWordToSwipePattern(SwipeKeyboard.WordToSwipePositions(testWord).ToArray()) == testWord);

            //=foreach(var sentence in ComputeSentenceVariations("the 0princess is in another 1castle"))
            //    Console.WriteLine(sentence.Item1, sentence.Item2);
        }
Пример #5
0
        public void Draw(SpriteBatch spriteBatch, float selectionInterpolation, Vector2 centerPosition)
        {
            SwipeKeyboard.GetBoundingBox(centerPosition, out Vector2 cornerKeyboard, out Vector2 sizeKeyboard);
            Rectangle rectKeyboard = VirtualCoords.ComputePixelRect(cornerKeyboard, sizeKeyboard);

            float thicknessScaled  = VirtualCoords.ComputePixelScale(BASE_LINE_THICKNESS);
            float dashLengthScaled = VirtualCoords.ComputePixelScale(BASE_LINE_DASH * selectionInterpolation);
            float dashTotalScaled  = VirtualCoords.ComputePixelScale(BASE_LINE_DASH);
            float radiusScaled     = VirtualCoords.ComputePixelScale(BASE_LINE_THICKNESS);

            for (int h = 0; h < Length; ++h)
            {
                if (h > 0)
                {
                    Vector2 pos0 = OriginalHandlePositionsRelative[h - 1] * rectKeyboard.Width + new Vector2(rectKeyboard.X, rectKeyboard.Y);
                    Vector2 pos1 = OriginalHandlePositionsRelative[h] * rectKeyboard.Width + new Vector2(rectKeyboard.X, rectKeyboard.Y);
                    LineRendering.DrawLineDashed(spriteBatch, pos0, pos1, StyleSheet.BackgroundColor * selectionInterpolation, dashLengthScaled, dashTotalScaled * 2 - dashLengthScaled,
                                                 thicknessScaled * 0.7f, radiusScaled * 2f, radiusScaled * 2f);
                }

                //DrawFromRelative(spriteBatch, rectKeyboard, StyleSheet.DotTexture,
                //                 StyleSheet.BackgroundColor * selectionInterpolation, OriginalHandlePositionsRelative[h], BASE_LINE_THICKNESS * 1.5f, 0);
            }

            for (int h = 0; h < Length; ++h)
            {
                Color color  = Color.Lerp(StyleSheet.BackgroundColor, StyleSheet.HighlightColor, selectionInterpolation);
                float radius = MathHelper.Lerp(BASE_STAR_SIZE, SELECTED_STAR_SIZE, _selectIntepolationHandles[h]);

                if (h > 0)
                {
                    Vector2 pos0 = HandlePositionsRelative[h - 1] * rectKeyboard.Width + new Vector2(rectKeyboard.X, rectKeyboard.Y);
                    Vector2 pos1 = HandlePositionsRelative[h] * rectKeyboard.Width + new Vector2(rectKeyboard.X, rectKeyboard.Y);
                    LineRendering.DrawLineDashed(spriteBatch, pos0, pos1, color * (0.5f + 0.5f * selectionInterpolation), dashTotalScaled + dashLengthScaled, dashTotalScaled - dashLengthScaled,
                                                 thicknessScaled, radiusScaled * 2f, radiusScaled * 2f);
                }

                DrawFromRelative(spriteBatch, rectKeyboard, StyleSheet.StarTexture,
                                 color, HandlePositionsRelative[h], radius * 2, _selectIntepolationHandles[h] + selectionInterpolation + h);
            }
        }
Пример #6
0
        public void Update(GameTime gameTime, Vector2 centerPosition)
        {
            var mouseState = Mouse.GetState();

            SwipeKeyboard.GetBoundingBox(centerPosition, out Vector2 cornerKeyboard, out Vector2 sizeKeyboard);
            Rectangle rectKeyboard = VirtualCoords.ComputePixelRect(cornerKeyboard, sizeKeyboard);
            bool      mouseInside  = rectKeyboard.Contains(mouseState.Position);

            if (_selectedHandle != -1 && mouseInside)
            {
                HandlePositionsRelative[_selectedHandle] = (mouseState.Position - rectKeyboard.Location).ToVector2() / rectKeyboard.Width;
            }

            bool  clicked      = mouseState.LeftButton == ButtonState.Pressed && _lastMouseState.LeftButton == ButtonState.Released && mouseInside;
            bool  released     = mouseState.LeftButton == ButtonState.Released && _lastMouseState.LeftButton == ButtonState.Pressed;
            float radius       = SELECTED_STAR_SIZE;
            float radiusScaled = VirtualCoords.ComputePixelScale(radius);
            int   closestStar  = -1;

            if (_selectedHandle == -1 && mouseInside)
            {
                float minDist = float.MaxValue;
                for (int h = 0; h < Length; ++h)
                {
                    Point centerStar = new Point((int)(rectKeyboard.X + rectKeyboard.Width * HandlePositionsRelative[h].X + 0.5f),
                                                 (int)(rectKeyboard.Y + rectKeyboard.Width * HandlePositionsRelative[h].Y + 0.5f));
                    float distStar = (centerStar - mouseState.Position).ToVector2().Length();
                    if (minDist > distStar && distStar < radiusScaled)
                    {
                        minDist     = distStar;
                        closestStar = h;
                        if (clicked)
                        {
                            _selectedHandle = h;
                        }
                    }
                }
            }

            for (int h = 0; h < Length; ++h)
            {
                Point centerStar = new Point((int)(rectKeyboard.X + rectKeyboard.Width * HandlePositionsRelative[h].X + 0.5f),
                                             (int)(rectKeyboard.Y + rectKeyboard.Width * HandlePositionsRelative[h].Y + 0.5f));
                if (closestStar == h || _selectedHandle == h)
                {
                    _selectIntepolationHandles[h] += (float)gameTime.ElapsedGameTime.TotalSeconds / SELECTION_ANIMATION_DURATION;
                    _selectIntepolationHandles[h]  = Math.Min(1f, _selectIntepolationHandles[h]);
                }
                else if (h != closestStar)
                {
                    _selectIntepolationHandles[h] -= (float)gameTime.ElapsedGameTime.TotalSeconds / SELECTION_ANIMATION_DURATION;
                    _selectIntepolationHandles[h]  = Math.Max(0f, _selectIntepolationHandles[h]);
                }

                if (_selectedHandle == h && released)
                {
                    _selectedHandle = -1;
                }
            }

            if (mouseState.LeftButton != ButtonState.Pressed)
            {
                _selectedHandle = -1;
            }

            _lastMouseState = mouseState;
        }
Пример #7
0
 /// <summary>
 /// hyphothetical - real user words ahve floaty swipe patterns
 /// </summary>
 public float WordDifference(string wordA, string wordB) =>
 SwipePatternDifference(SwipeKeyboard.WordToSwipePositions(wordA), SwipeKeyboard.WordToSwipePositions(wordB));
Пример #8
0
 private IEnumerable <string> ClosestWordsToSwipePattern(Vector2[] swipePositions)
 {
     return(_wordsByLength[swipePositions.Length].OrderBy(word =>
                                                          SwipeKeyboard.SwipePositionToWordDistance(word, swipePositions)
                                                          ));
 }