Пример #1
0
 public override void Update(UpdateState state)
 {
     base.Update(state);
     if (AutoRotate){
         var startAngle = RotationStartAngle;
         var time = state.Time.TotalRealTime.Ticks;
         var phase = (time % RotationSpeed) / RotationSpeed;
         var multiplier = Math.Sin((Math.PI * 2) * phase);
         var newAngle = startAngle + (RotationRange * multiplier);
         Avatar.RotationY = (float)MathUtils.DegreeToRadian(newAngle);
     }
 }
Пример #2
0
 public override void Update(UpdateState state)
 {
     for (int i = 0; i < m_Elements.Count; i++)
     {
         m_Elements[i].Update(state);
     }
 }
Пример #3
0
 public abstract void Update(UpdateState Time);
Пример #4
0
        public override void Update(UpdateState state)
        {
            base.Update(state);
            /** Check for mouse scrolling **/
            var mouse = state.MouseState;

            if (State == null) { return; }

            var screenWidth = State.WorldSpace.WorldPxWidth;
            var screenHeight = State.WorldSpace.WorldPxHeight;

            /** Corners **/
            var xBound = screenWidth - ScrollBounds;
            var yBound = screenHeight - ScrollBounds;

            var cursor = CursorType.Normal;
            var scrollVector = new Vector2(0, 0);

            if (mouse.X > 0 && mouse.Y > 0 && mouse.X < screenWidth && mouse.Y < screenHeight)
            {
                if (mouse.Y <= ScrollBounds)
                {
                    if (mouse.X <= ScrollBounds)
                    {
                        /** Scroll top left **/
                        cursor = CursorType.ArrowUpLeft;
                        scrollVector = new Vector2(-1, -1);
                    }
                    else if (mouse.X >= xBound)
                    {
                        /** Scroll top right **/
                        cursor = CursorType.ArrowUpRight;
                        scrollVector = new Vector2(1, -1);
                    }
                    else
                    {
                        /** Scroll up **/
                        cursor = CursorType.ArrowUp;
                        scrollVector = new Vector2(0, -1);
                    }
                }
                else if (mouse.Y <= yBound)
                {
                    if (mouse.X <= ScrollBounds)
                    {
                        /** Left **/
                        cursor = CursorType.ArrowLeft;
                        scrollVector = new Vector2(-1, 0);
                    }
                    else if (mouse.X >= xBound)
                    {
                        /** Right **/
                        cursor = CursorType.ArrowRight;
                        scrollVector = new Vector2(1, -1);
                    }
                }
                else
                {
                    if (mouse.X <= ScrollBounds)
                    {
                        /** Scroll bottom left **/
                        cursor = CursorType.ArrowDownLeft;
                        scrollVector = new Vector2(-1, 1);
                    }
                    else if (mouse.X >= xBound)
                    {
                        /** Scroll bottom right **/
                        cursor = CursorType.ArrowDownRight;
                        scrollVector = new Vector2(1, 1);
                    }
                    else
                    {
                        /** Scroll down **/
                        cursor = CursorType.ArrowDown;
                        scrollVector = new Vector2(0, 1);
                    }
                }
            }

            if (cursor != CursorType.Normal)
            {
                /**
                 * Calculate scroll vector based on rotation & scroll type
                 */
                scrollVector = new Vector2();
                switch (State.Rotation)
                {
                    case WorldRotation.TopLeft:
                        switch (cursor)
                        {
                            case CursorType.ArrowDown:
                                scrollVector = new Vector2(1, 1);
                                break;

                            case CursorType.ArrowUp:
                                scrollVector = new Vector2(-1, -1);
                                break;

                            case CursorType.ArrowLeft:
                                scrollVector = new Vector2(-1, 1);
                                break;

                            case CursorType.ArrowRight:
                                scrollVector = new Vector2(1, -1);
                                break;
                        }
                        break;

                    case WorldRotation.TopRight:
                        switch (cursor){
                            case CursorType.ArrowDown:
                                scrollVector = new Vector2(1, -1);
                                break;
                            case CursorType.ArrowUp:
                                scrollVector = new Vector2(-1, 1);
                                break;
                            case CursorType.ArrowLeft:
                                scrollVector = new Vector2(1, 1);
                                break;
                            case CursorType.ArrowRight:
                                scrollVector = new Vector2(-1, -1);
                                break;
                        }
                        break;

                    case WorldRotation.BottomRight:
                        switch (cursor)
                        {
                            case CursorType.ArrowDown:
                                scrollVector = new Vector2(-1, -1);
                                break;

                            case CursorType.ArrowUp:
                                scrollVector = new Vector2(1, 1);
                                break;
                        }
                        break;

                    case WorldRotation.BottomLeft:
                        switch (cursor)
                        {
                            case CursorType.ArrowDown:
                                scrollVector = new Vector2(1, -1);
                                break;

                            case CursorType.ArrowUp:
                                scrollVector = new Vector2(-1, 1);
                                break;
                        }
                        break;
                }

                /** We need to scroll **/
                if (scrollVector != Vector2.Zero)
                {
                    State.CenterTile += scrollVector * new Vector2(0.0625f, 0.0625f);
                }
            }

            CursorManager.INSTANCE.SetCursor(cursor);
            //GameFacade.Cursor.SetCursor(cursor);
        }
Пример #5
0
 public abstract void Update(UpdateState state);
Пример #6
0
        public void HandleMouseEvents(UpdateState state)
        {
            var mouseBtnDown = state.MouseState.LeftButton == Microsoft.Xna.Framework.Input.ButtonState.Pressed;
            var mouseDif = mouseBtnDown != LastMouseDownState;
            LastMouseDownState = mouseBtnDown;

            if (mouseDif)
            {
                if (mouseBtnDown)
                {
                    if (LastMouseDown != null)
                    {
                        /** We already have mouse down on an object **/
                        return;
                    }
                    if (LastMouseOver != null)
                    {
                        LastMouseDown = LastMouseOver;
                        LastMouseDown.Callback(UIMouseEventType.MouseDown, state);
                    }
                }
                else
                {
                    if (LastMouseDown != null)
                    {
                        LastMouseDown.Callback(UIMouseEventType.MouseUp, state);
                        LastMouseDown = null;
                    }
                }
            }

            if (state.MouseEvents.Count > 0)
            {
                var topMost =
                    state.MouseEvents.OrderByDescending(x => x.Element.Depth).First();

                /** Same element **/
                if (LastMouseOver == topMost)
                {
                    return;
                }

                if (LastMouseOver != null)
                {
                    LastMouseOver.Callback(UIMouseEventType.MouseOut, state);
                }

                topMost.Callback(UIMouseEventType.MouseOver, state);
                LastMouseOver = topMost;
            }
            else
            {
                if (LastMouseOver != null)
                {
                    LastMouseOver.Callback(UIMouseEventType.MouseOut, state);
                    LastMouseOver = null;
                }
            }
        }
Пример #7
0
        /// <summary>
        /// Utility to apply the result of pressing keys against a buffer
        /// </summary>
        /// <param name="buffer"></param>
        /// <param name="keys"></param>
        public KeyboardInputResult ApplyKeyboardInput(StringBuilder m_SBuilder, UpdateState state, int cursorIndex, int cursorEndIndex, bool allowInput)
        {
            var PressedKeys = state.KeyboardState.GetPressedKeys();
            if (PressedKeys.Length == 0) { return null; }

            var didChange = false;
            var result = new KeyboardInputResult();

            var m_CurrentKeyState = state.KeyboardState;
            var m_OldKeyState = state.PreviousKeyboardState;

            result.ShiftDown = PressedKeys.Contains(Keys.LeftShift) || PressedKeys.Contains(Keys.RightShift);
            result.CapsDown = System.Windows.Forms.Control.IsKeyLocked(System.Windows.Forms.Keys.CapsLock);
            result.NumLockDown = System.Windows.Forms.Control.IsKeyLocked(System.Windows.Forms.Keys.NumLock);
            result.CtrlDown = PressedKeys.Contains(Keys.LeftControl) || PressedKeys.Contains(Keys.RightControl);

            for (int j = 0; j < state.NewKeys.Count; j++)
            {
                var key = state.NewKeys[j];

                if (key == Keys.Back || key == Keys.Delete)
                {
                    if (m_SBuilder.Length > 0)
                    {
                        /**
                         * Delete previous character or delete selection
                         */
                        if (cursorEndIndex == -1 && result.CtrlDown)
                        {
                            /** Delete up until the previous whitespace char **/
                            int newEndIndex = cursorIndex;
                            if (newEndIndex == -1)
                            {
                                newEndIndex = m_SBuilder.Length - 1;
                            }
                            while (newEndIndex >= 0)
                            {
                                if (Char.IsWhiteSpace(m_SBuilder[newEndIndex]))
                                {
                                    /** Keep the whitespace char **/
                                    newEndIndex++;
                                    break;
                                }
                                newEndIndex--;
                            }
                            cursorEndIndex = newEndIndex;
                        }

                        if (cursorEndIndex == -1)
                        {
                            /** Previous character **/
                            var index = cursorIndex == -1 ? m_SBuilder.Length : cursorIndex;
                            if ((key == Keys.Back) && (index > 0))
                            {
                                var numToDelete = 1;
                                if (index > 1 && m_SBuilder[index-1] == '\n' && m_SBuilder[index - 2] == '\r')
                                {
                                    numToDelete = 2;
                                }

                                m_SBuilder.Remove(index - numToDelete, numToDelete);
                                result.NumDeletes += numToDelete;

                                if (cursorIndex != -1)
                                {
                                    cursorIndex -= numToDelete;
                                }
                            }
                            else if ((key == Keys.Delete) && (index < m_SBuilder.Length))
                            {
                                /** Guys, delete removes the next character, not the last!! **/
                                var numToDelete = 1;
                                if ((index < m_SBuilder.Length - 1) && m_SBuilder[index] == '\r' && m_SBuilder[index + 1] == '\n')
                                {
                                    numToDelete = 2;
                                }

                                m_SBuilder.Remove(index, numToDelete);
                                result.NumDeletes += numToDelete;
                            }
                        }
                        else
                        {
                            DeleteSelectedText(m_SBuilder, ref cursorIndex, ref cursorEndIndex, ref didChange, result);
                        }
                        result.SelectionChanged = true;
                        didChange = true;
                    }
                }
                else if (key == Keys.Enter)
                {
                    if (allowInput)
                    {
                        /** Line break **/
                        if (cursorEndIndex != -1)
                        {
                            /** Delete selected text **/
                            DeleteSelectedText(m_SBuilder, ref cursorIndex, ref cursorEndIndex, ref didChange, result);
                        }

                        if (cursorIndex == -1)
                        {
                            m_SBuilder.Append("\r\n");
                        }
                        else
                        {
                            m_SBuilder.Insert(cursorIndex, "\r\n");
                            cursorIndex += 2;
                        }
                        result.NumInsertions += 2;
                        didChange = true;
                        result.EnterPressed = true;
                    }
                }
                else if (key == Keys.Tab)
                {
                    result.TabPressed = true;
                }
                else
                {
                    if (result.CtrlDown)
                    {
                        switch (key)
                        {
                            case Keys.A:
                                /** Select all **/
                                cursorIndex = 0;
                                cursorEndIndex = m_SBuilder.Length;
                                result.SelectionChanged = true;
                                break;

                            case Keys.C:
                            case Keys.X:
                                /** Copy text to clipboard **/
                                if (cursorEndIndex != -1)
                                {
                                    var selectionStart = Math.Max(0, cursorIndex);
                                    var selectionEnd = cursorEndIndex;
                                    GetSelectionRange(ref selectionStart, ref selectionEnd);

                                    var str = m_SBuilder.ToString().Substring(selectionStart, selectionEnd - selectionStart);
                                    System.Windows.Forms.Clipboard.SetText((str == null) ? " " : str);

                                    if (key == Keys.X)
                                    {
                                        DeleteSelectedText(m_SBuilder, ref cursorIndex, ref cursorEndIndex, ref didChange, result);
                                    }
                                }
                                break;

                            case Keys.V:
                                /** Paste text in **/
                                var clipboardText = System.Windows.Forms.Clipboard.GetText(System.Windows.Forms.TextDataFormat.Text);
                                if (clipboardText != null)
                                {
                                    /** TODO: Cleanup the clipboard text to make sure its valid **/

                                    /** If i have selection, delete it **/
                                    if (cursorEndIndex != -1)
                                    {
                                        DeleteSelectedText(m_SBuilder, ref cursorIndex, ref cursorEndIndex, ref didChange, result);
                                    }

                                    /** Paste **/
                                    if (cursorIndex == -1)
                                    {
                                        m_SBuilder.Append(clipboardText);
                                    }
                                    else
                                    {
                                        m_SBuilder.Insert(Math.Min(cursorIndex, m_SBuilder.Length), clipboardText);
                                        cursorIndex += clipboardText.Length;
                                    }
                                    result.NumInsertions += clipboardText.Length;
                                    didChange = true;
                                }
                                break;
                        }
                        continue;
                    }

                    char value = TranslateChar(key, result.ShiftDown, result.CapsDown, result.NumLockDown);
                    /** For now we dont support tabs in text **/
                    if (value != '\0' && value != '\t')
                    {
                        if (allowInput)
                        {
                            if (cursorEndIndex != -1)
                            {
                                /** Delete selected text **/
                                DeleteSelectedText(m_SBuilder, ref cursorIndex, ref cursorEndIndex, ref didChange, result);
                            }

                            if (cursorIndex == -1)
                            {
                                m_SBuilder.Append(value);
                            }
                            else
                            {
                                m_SBuilder.Insert(cursorIndex, value);
                                cursorIndex++;
                            }
                            result.NumInsertions++;
                            didChange = true;
                        }
                    }
                    else
                    {
                        result.UnhandledKeys.Add(key);
                    }
                }

            }

            result.SelectionStart = cursorIndex;
            result.SelectionEnd = cursorEndIndex;

            result.ContentChanged = didChange;
            return result;
        }
Пример #8
0
        public GameScreen(GraphicsDevice device)
        {
            this.Device = device;

            State = new UpdateState();
        }
Пример #9
0
        public override void Update(UpdateState state)
        {
            m_LastMouseState = m_MouseState;
            m_MouseState = Mouse.GetState();

            m_MouseMove = (m_MouseState.MiddleButton == ButtonState.Pressed);

            if (m_HandleMouse)
            {

                if (m_Zoomed)
                {
                    m_SelTile = GetHoverSquare();
                }

                if (m_MouseState.MiddleButton == ButtonState.Pressed && m_LastMouseState.MiddleButton == ButtonState.Released)
                {
                    m_MouseStart = new Vector2(m_MouseState.X, m_MouseState.Y); //if middle mouse button activated, record where we started pressing it (to use for panning)
                }

                else if (m_MouseState.LeftButton == ButtonState.Released && m_LastMouseState.LeftButton == ButtonState.Pressed) //if clicked...
                {
                    if (!m_Zoomed)
                    {
                        m_Zoomed = true;
                        double ResScale = 768.0 / m_ScrHeight;
                        double isoScale = (Math.Sqrt(0.5 * 0.5 * 2) / 5.10) * ResScale;
                        double hb = m_ScrWidth * isoScale;
                        double vb = m_ScrHeight * isoScale;

                        m_TargVOffX = (float)(-hb + m_MouseState.X * isoScale * 2);
                        m_TargVOffY = (float)(vb - m_MouseState.Y * isoScale * 2); //zoom into approximate location of mouse cursor if not zoomed already
                    }
                    CoreGameScreen test = (CoreGameScreen)GameFacade.Screens.CurrentUIScreen;
                    test.ucp.UpdateZoomButton();
                }
            }
            else
            {
                m_SelTile = new int[] { -1, -1 };
            }

            //m_SecondsBehind += time.ElapsedGameTime.TotalSeconds;
            //m_SecondsBehind -= 1 / 60;
            FixedTimeUpdate();
            SetTimeOfDay(m_DayNightCycle%1); //calculates sun/moon light colour and position
            m_DayNightCycle += 0.001; //adjust the cycle speed here. When ingame, set m_DayNightCycle to to the percentage of time passed through the day. (0 to 1)

            m_ViewOffX = (m_TargVOffX) * m_ZoomProgress;
            m_ViewOffY = (m_TargVOffY) * m_ZoomProgress;
        }