FSO.LotView.World.Scroll C# (CSharp) Method

Scroll() public method

public Scroll ( Vector2 dir ) : void
dir Vector2
return void
        public void Scroll(Vector2 dir)
        {
            var basis = GetScrollBasis();
            State.CenterTile += dir.X*basis[0] + dir.Y*basis[1];
        }

Usage Example

Ejemplo n.º 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);
            }
        }