FSO.LotView.World.TestScroll C# (CSharp) Метод

TestScroll() публичный Метод

public TestScroll ( UpdateState state ) : bool
state UpdateState
Результат bool
        public bool TestScroll(UpdateState state)
        {
            var mouse = state.MouseState;

            if (State == null) { return false; }

            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();

                var basis = GetScrollBasis();

                switch (cursor)
                {
                    case CursorType.ArrowDown:
                        scrollVector = basis[1];
                        break;

                    case CursorType.ArrowUp:
                        scrollVector = -basis[1];
                        break;

                    case CursorType.ArrowLeft:
                        scrollVector = -basis[0];
                        break;

                    case CursorType.ArrowRight:
                        scrollVector = basis[0];
                        break;
                }

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

            if (cursor != CursorType.Normal)
            {
                CursorManager.INSTANCE.SetCursor(cursor);
                return true; //we scrolled, return true and set cursor
            }
            return false;
        }

Usage Example

Пример #1
0
        public override void Update(UpdateState state)
        {
            base.Update(state);

            if (!vm.Ready || vm.Context.Architecture == null)
            {
                return;
            }

            //handling smooth scaled zoom
            if (FSOEnvironment.Enable3D)
            {
                var s3d = ((WorldStateRC)World.State);
                s3d.Zoom3D += ((9.75f - (TargetZoom - 0.25f) * 10) - s3d.Zoom3D) / 10;
            }
            else
            {
                float     BaseScale;
                WorldZoom targetZoom;
                if (TargetZoom < 0.5f)
                {
                    targetZoom = WorldZoom.Far;
                    BaseScale  = 0.25f;
                }
                else if (TargetZoom < 1f)
                {
                    targetZoom = WorldZoom.Medium;
                    BaseScale  = 0.5f;
                }
                else
                {
                    targetZoom = WorldZoom.Near;
                    BaseScale  = 1f;
                }
                World.BackbufferScale = TargetZoom / BaseScale;
                if (World.State.Zoom != targetZoom)
                {
                    World.State.Zoom = targetZoom;
                }
                WorldConfig.Current.SmoothZoom = false;
            }

            //Cheats.Update(state);
            //AvatarDS.Update();
            if (ActiveEntity == null || ActiveEntity.Dead || ActiveEntity.PersistID != SelectedSimID)
            {
                ActiveEntity = vm.Entities.FirstOrDefault(x => x is VMAvatar && x.PersistID == SelectedSimID); //try and hook onto a sim if we have none selected.
                if (ActiveEntity == null)
                {
                    ActiveEntity = vm.Entities.FirstOrDefault(x => x is VMAvatar);
                }

                if (!FoundMe && ActiveEntity != null)
                {
                    vm.Context.World.State.CenterTile   = new Vector2(ActiveEntity.VisualPosition.X, ActiveEntity.VisualPosition.Y);
                    vm.Context.World.State.ScrollAnchor = null;
                    FoundMe = true;
                }
                Queue.QueueOwner = ActiveEntity;
            }

            if (GotoObject == null)
            {
                GotoObject = vm.Context.CreateObjectInstance(GOTO_GUID, LotTilePos.OUT_OF_WORLD, Direction.NORTH, true).Objects[0];
            }

            /*
             * if (ActiveEntity != null && BlockingDialog != null)
             * {
             *  //are we still waiting on a blocking dialog? if not, cancel.
             *  if (ActiveEntity.Thread != null && (ActiveEntity.Thread.BlockingState == null || !(ActiveEntity.Thread.BlockingState is VMDialogResult)))
             *  {
             *      BlockingDialog.Close();
             *      LastDialogID = 0;
             *      BlockingDialog = null;
             *  }
             * }*/

            if (Visible)
            {
                if (ShowTooltip)
                {
                    state.UIState.TooltipProperties.UpdateDead = false;
                }

                bool scrolled = false;
                if (RMBScroll)
                {
                    World.State.ScrollAnchor = null;
                    Vector2 scrollBy = new Vector2();
                    if (state.TouchMode)
                    {
                        scrollBy   = new Vector2(RMBScrollX - state.MouseState.X, RMBScrollY - state.MouseState.Y);
                        RMBScrollX = state.MouseState.X;
                        RMBScrollY = state.MouseState.Y;
                        scrollBy  /= 128f;
                        scrollBy  /= FSOEnvironment.DPIScaleFactor;
                    }
                    else
                    {
                        scrollBy  = new Vector2(state.MouseState.X - RMBScrollX, state.MouseState.Y - RMBScrollY);
                        scrollBy *= 0.0005f;

                        var angle = (Math.Atan2(state.MouseState.X - RMBScrollX, (RMBScrollY - state.MouseState.Y) * 2) / Math.PI) * 4;
                        angle += 8;
                        angle %= 8;

                        CursorType type = CursorType.ArrowUp;
                        switch ((int)Math.Round(angle))
                        {
                        case 0: type = CursorType.ArrowUp; break;

                        case 1: type = CursorType.ArrowUpRight; break;

                        case 2: type = CursorType.ArrowRight; break;

                        case 3: type = CursorType.ArrowDownRight; break;

                        case 4: type = CursorType.ArrowDown; break;

                        case 5: type = CursorType.ArrowDownLeft; break;

                        case 6: type = CursorType.ArrowLeft; break;

                        case 7: type = CursorType.ArrowUpLeft; break;
                        }
                        GameFacade.Cursor.SetCursor(type);
                    }
                    World.Scroll(scrollBy * (60f / FSOEnvironment.RefreshRate));
                    scrolled = true;
                }
                if (MouseIsOn)
                {
                    if (state.MouseState.RightButton == ButtonState.Pressed)
                    {
                        if (RMBScroll == false)
                        {
                            RMBScroll  = true;
                            RMBScrollX = state.MouseState.X;
                            RMBScrollY = state.MouseState.Y;
                        }
                    }
                    else
                    {
                        if (!scrolled && GlobalSettings.Default.EdgeScroll && !state.TouchMode)
                        {
                            scrolled = World.TestScroll(state);
                        }
                    }
                }

                if (state.MouseState.RightButton != ButtonState.Pressed)
                {
                    if (RMBScroll)
                    {
                        GameFacade.Cursor.SetCursor(CursorType.Normal);
                    }
                    RMBScroll = false;
                }

                if (LiveMode)
                {
                    LiveModeUpdate(state, scrolled);
                }
                //else if (CustomControl != null) CustomControl.Update(state, scrolled);
                //else ObjectHolder.Update(state, scrolled);

                //set cutaway around mouse
                UpdateCutaway(state);
            }
        }