Exemplo n.º 1
0
        public void UpdateSIMI(VM vm)
        {
            if (SimulationInfo == null)
            {
                return;
            }

            var objValue = VMArchitectureStats.GetObjectValue(vm);

            SimulationInfo.ArchitectureValue = VMArchitectureStats.GetArchValue(vm.Context.Architecture) + objValue.Item2;
            SimulationInfo.ObjectsValue      = objValue.Item1;
            SimulationInfo.Version           = 0x3E;
            SimulationInfo.GlobalData        = vm.GlobalState;
        }
Exemplo n.º 2
0
        public override void Update(UpdateState state)
        {
            base.Update(state);

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

            //handling smooth scaled zoom
            var camType = World.State.Cameras.ActiveType;

            Touch._3D = camType != FSO.LotView.Utils.Camera.CameraControllerType._2D;
            if (World.State.Cameras.ActiveType == FSO.LotView.Utils.Camera.CameraControllerType._3D)
            {
                if (World.BackbufferScale != 1)
                {
                    World.BackbufferScale = 1;
                }
                var s3d = World.State.Cameras.Camera3D;
                if (TargetZoom < -0.25f)
                {
                    TargetZoom -= (TargetZoom - 0.25f) * (1f - (float)Math.Pow(0.975f, 60f / FSOEnvironment.RefreshRate));
                }
                s3d.Zoom3D += ((9.75f - (TargetZoom - 0.25f) * 5.7f) - s3d.Zoom3D) / 10;
            }
            else if (World.State.Cameras.ActiveType == FSO.LotView.Utils.Camera.CameraControllerType._2D)
            {
                if (World.State.Zoom != LastZoom)
                {
                    //zoom has been changed by something else. inherit the value
                    SetTargetZoom(World.State.Zoom);
                    LastZoom = World.State.Zoom;
                }

                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;
            }

            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];
            }


            //update plumbbob
            var plumb = Content.Get().RCMeshes.Get("arrow.fsom");

            foreach (VMAvatar avatar in vm.Context.ObjectQueries.Avatars)
            {
                if (avatar.Avatar == null)
                {
                    continue;
                }
                var isActive = (avatar == ActiveEntity);
                if ((avatar.Avatar.HeadObject == plumb) != isActive)
                {
                    avatar.Avatar.HeadObject          = (avatar == ActiveEntity) ? plumb : null;
                    avatar.Avatar.HeadObjectSpeedyVel = 0.2f;
                }
                avatar.Avatar.HeadObjectRotation += 3f / FSOEnvironment.RefreshRate;
                if (isActive)
                {
                    avatar.Avatar.HeadObjectRotation  += avatar.Avatar.HeadObjectSpeedyVel;
                    avatar.Avatar.HeadObjectSpeedyVel *= 0.98f;
                }
                else if (avatar.GetValue(FSO.SimAntics.Model.VMStackObjectVariable.Category) == 87)
                {
                    avatar.Avatar.HeadObject = Content.Get().RCMeshes.Get("star.fsom");
                }
            }

            /*
             * 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 && PieMenu != null)
                {
                    PieMenu.RemoveSimScene();
                    this.Remove(PieMenu);
                    PieMenu = null;
                }

                if (state.NewKeys.Contains(Keys.F11))
                {
                    var utils = new FSO.SimAntics.Test.CollisionTestUtils();
                    utils.VerifyAllCollision(vm);
                }

                if (state.NewKeys.Contains(Keys.F8))
                {
                    UIMobileAlert alert = null;
                    alert = new UIMobileAlert(new UIAlertOptions()
                    {
                        Title   = "Debug Lot Thumbnail",
                        Message = "Arch Value: " + VMArchitectureStats.GetArchValue(vm.Context.Architecture),
                        Buttons = UIAlertButton.Ok((btn) => UIScreen.RemoveDialog(alert))
                    });
                    Texture2D roofless = null;
                    var       thumb    = World.GetLotThumb(GameFacade.GraphicsDevice, (tex) => roofless = FSO.Common.Utils.TextureUtils.Decimate(tex, GameFacade.GraphicsDevice, 2, false));
                    thumb = FSO.Common.Utils.TextureUtils.Decimate(thumb, GameFacade.GraphicsDevice, 2, false);
                    alert.SetIcon(thumb, thumb.Width, thumb.Height);
                    UIScreen.GlobalShowDialog(alert, true);
                }
                if (LiveMode)
                {
                    LiveModeUpdate(state, scrolled);
                }
                else if (CustomControl != null)
                {
                    if (FSOEnvironment.SoftwareKeyboard)
                    {
                        CustomControl.MousePosition = new Point(UIScreen.Current.ScreenWidth / 2, UIScreen.Current.ScreenHeight / 2);
                    }
                    else
                    {
                        CustomControl.Modifiers = 0;
                        if (state.CtrlDown)
                        {
                            CustomControl.Modifiers |= UILotControlModifiers.CTRL;
                        }
                        if (state.ShiftDown)
                        {
                            CustomControl.Modifiers |= UILotControlModifiers.SHIFT;
                        }
                        CustomControl.MousePosition = state.MouseState.Position;
                    }
                    CustomControl.Update(state, scrolled);
                }
                else
                {
                    ObjectHolder.Update(state, scrolled);
                }

                //set cutaway around mouse
                UpdateCutaway(state);

                if (RMBScrollX == int.MinValue)
                {
                    Dummy();                             //cannon fodder for mono AOT compilation: never called but gives these constructors a meaning in life
                }
            }
        }