Exemplo n.º 1
0
        private void UpdateCutaway(UpdateState state)
        {
            if (vm.Context.Blueprint != null)
            {
                World.State.DynamicCutaway = (WallsMode == 1);
                //first we need to cycle the rooms that are being cutaway. Keep this up even if we're in all-cut mode.
                var mouseTilePos = World.EstTileAtPosWithScroll(new Vector2(state.MouseState.X, state.MouseState.Y) / FSOEnvironment.DPIScaleFactor);
                var roomHover    = vm.Context.GetRoomAt(LotTilePos.FromBigTile((short)(mouseTilePos.X), (short)(mouseTilePos.Y), World.State.Level));
                var outside      = (vm.Context.RoomInfo[roomHover].Room.IsOutside);
                if (!outside && !CutRooms.Contains(roomHover))
                {
                    CutRooms.Add(roomHover); //outside hover should not persist like with other rooms.
                }
                while (CutRooms.Count > 3)
                {
                    CutRooms.Remove(CutRooms.ElementAt(0));
                }

                if (LastWallMode != WallsMode)
                {
                    if (WallsMode == 0) //walls down
                    {
                        LastCuts = new bool[vm.Context.Architecture.Width * vm.Context.Architecture.Height];
                        vm.Context.Blueprint.Cutaway = LastCuts;
                        vm.Context.Blueprint.Damage.Add(new FSO.LotView.Model.BlueprintDamage(FSO.LotView.Model.BlueprintDamageType.WALL_CUT_CHANGED));
                        for (int i = 0; i < LastCuts.Length; i++)
                        {
                            LastCuts[i] = true;
                        }
                    }
                    else if (WallsMode == 1)
                    {
                        MouseCutRect = new Rectangle();
                        LastCutRooms = new HashSet <uint>()
                        {
                            uint.MaxValue
                        };                                                    //must regenerate cuts
                    }
                    else //walls up or roof
                    {
                        LastCuts = new bool[vm.Context.Architecture.Width * vm.Context.Architecture.Height];
                        vm.Context.Blueprint.Cutaway = LastCuts;
                        vm.Context.Blueprint.Damage.Add(new FSO.LotView.Model.BlueprintDamage(FSO.LotView.Model.BlueprintDamageType.WALL_CUT_CHANGED));
                    }
                    LastWallMode = WallsMode;
                }

                if (WallsMode == 1)
                {
                    if (RMBScroll || !MouseIsOn)
                    {
                        return;
                    }
                    int recut      = 0;
                    var finalRooms = new HashSet <uint>(CutRooms);

                    var newCut = new Rectangle((int)(mouseTilePos.X - 2.5), (int)(mouseTilePos.Y - 2.5), 5, 5);
                    newCut.X -= VMArchitectureTools.CutCheckDir[(int)World.State.CutRotation][0] * 2;
                    newCut.Y -= VMArchitectureTools.CutCheckDir[(int)World.State.CutRotation][1] * 2;
                    if (newCut != MouseCutRect)
                    {
                        MouseCutRect = newCut;
                        recut        = 1;
                    }

                    if (LastFloor != World.State.Level || LastRotation != World.State.CutRotation || !finalRooms.SetEquals(LastCutRooms))
                    {
                        LastCuts     = VMArchitectureTools.GenerateRoomCut(vm.Context.Architecture, World.State.Level, World.State.CutRotation, finalRooms);
                        recut        = 2;
                        LastFloor    = World.State.Level;
                        LastRotation = World.State.CutRotation;
                    }
                    LastCutRooms = finalRooms;

                    if (recut > 0)
                    {
                        var finalCut = new bool[LastCuts.Length];
                        Array.Copy(LastCuts, finalCut, LastCuts.Length);
                        var notableChange = VMArchitectureTools.ApplyCutRectangle(vm.Context.Architecture, World.State.Level, finalCut, MouseCutRect);
                        if (recut > 1 || notableChange || LastRectCutNotable)
                        {
                            vm.Context.Blueprint.Cutaway = finalCut;
                            vm.Context.Blueprint.Damage.Add(new FSO.LotView.Model.BlueprintDamage(FSO.LotView.Model.BlueprintDamageType.WALL_CUT_CHANGED));
                        }
                        LastRectCutNotable = notableChange;
                    }
                }
            }
        }
Exemplo n.º 2
0
        public override void Update(UpdateState state)
        {
            base.Update(state);
            Cheats.Update(state);

            if (!vm.Ready)
            {
                return;
            }

            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)))
                {
                    UIScreen.RemoveDialog(BlockingDialog);
                    LastDialogID   = 0;
                    BlockingDialog = null;
                }
            }

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

                bool scrolled = false;
                if (KBScroll)
                {
                    World.State.ScrollAnchor = null;
                    int     KeyboardAxisX = 0;
                    int     KeyboardAxisY = 0;
                    Vector2 scrollBy      = new Vector2();
                    if (state.KeyboardState.IsKeyDown(Keys.Up) || state.KeyboardState.IsKeyDown(Keys.W))
                    {
                        KeyboardAxisY -= 1;
                    }
                    if (state.KeyboardState.IsKeyDown(Keys.Left) || state.KeyboardState.IsKeyDown(Keys.A))
                    {
                        KeyboardAxisX -= 1;
                    }
                    if (state.KeyboardState.IsKeyDown(Keys.Down) || state.KeyboardState.IsKeyDown(Keys.S))
                    {
                        KeyboardAxisY += 1;
                    }
                    if (state.KeyboardState.IsKeyDown(Keys.Right) || state.KeyboardState.IsKeyDown(Keys.D))
                    {
                        KeyboardAxisX += 1;
                    }
                    scrollBy  = new Vector2(KeyboardAxisX, KeyboardAxisY);
                    scrollBy *= 0.05f;
                    World.Scroll(scrollBy * (60f / 60));
                }
                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 / 60));
                    scrolled = true;
                }

                var nofocus = state.InputManager.GetFocus() == null;
                var keyst   = state.KeyboardState;
                if (nofocus && (keyst.IsKeyDown(Keys.Up) || keyst.IsKeyDown(Keys.Left) || keyst.IsKeyDown(Keys.Down) || keyst.IsKeyDown(Keys.Right) ||
                                (keyst.IsKeyDown(Keys.W) || keyst.IsKeyDown(Keys.A) || keyst.IsKeyDown(Keys.S) || keyst.IsKeyDown(Keys.D))))
                {
                    KBScroll = true;
                }
                else
                {
                    KBScroll = false;
                }

                if (MouseIsOn)
                {
                    if (state.MouseState.RightButton == ButtonState.Pressed)
                    {
                        if (RMBScroll == false)
                        {
                            RMBScroll = true;
                            state.InputManager.SetFocus(null);
                            RMBScrollX = state.MouseState.X;
                            RMBScrollY = state.MouseState.Y;
                        }
                    }
                    else
                    {
                        RMBScroll = false;
                        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

                if (vm.Context.Blueprint != null)
                {
                    World.State.DynamicCutaway = (WallsMode == 1);
                    //first we need to cycle the rooms that are being cutaway. Keep this up even if we're in all-cut mode.
                    var mouseTilePos = World.State.WorldSpace.GetTileAtPosWithScroll(new Vector2(state.MouseState.X, state.MouseState.Y) / FSOEnvironment.DPIScaleFactor);
                    var roomHover    = vm.Context.GetRoomAt(LotTilePos.FromBigTile((short)(mouseTilePos.X), (short)(mouseTilePos.Y), World.State.Level));
                    var outside      = (vm.Context.RoomInfo[roomHover].Room.IsOutside);
                    if (!outside && !CutRooms.Contains(roomHover))
                    {
                        CutRooms.Add(roomHover); //outside hover should not persist like with other rooms.
                    }
                    while (CutRooms.Count > 3)
                    {
                        CutRooms.Remove(CutRooms.ElementAt(0));
                    }

                    if (LastWallMode != WallsMode)
                    {
                        if (WallsMode == 0) //walls down
                        {
                            LastCuts = new bool[vm.Context.Architecture.Width * vm.Context.Architecture.Height];
                            vm.Context.Blueprint.Cutaway = LastCuts;
                            vm.Context.Blueprint.Damage.Add(new FSO.LotView.Model.BlueprintDamage(FSO.LotView.Model.BlueprintDamageType.WALL_CUT_CHANGED));
                            for (int i = 0; i < LastCuts.Length; i++)
                            {
                                LastCuts[i] = true;
                            }
                        }
                        else if (WallsMode == 1)
                        {
                            MouseCutRect = new Rectangle();
                            LastCutRooms = new HashSet <uint>()
                            {
                                uint.MaxValue
                            };                                                    //must regenerate cuts
                        }
                        else //walls up or roof
                        {
                            LastCuts = new bool[vm.Context.Architecture.Width * vm.Context.Architecture.Height];
                            vm.Context.Blueprint.Cutaway = LastCuts;
                            vm.Context.Blueprint.Damage.Add(new FSO.LotView.Model.BlueprintDamage(FSO.LotView.Model.BlueprintDamageType.WALL_CUT_CHANGED));
                        }
                        LastWallMode = WallsMode;
                    }

                    if (WallsMode == 1)
                    {
                        int recut      = 0;
                        var finalRooms = new HashSet <uint>(CutRooms);

                        var newCut = new Rectangle((int)(mouseTilePos.X - 2.5), (int)(mouseTilePos.Y - 2.5), 5, 5);
                        newCut.X -= VMArchitectureTools.CutCheckDir[(int)World.State.Rotation][0] * 2;
                        newCut.Y -= VMArchitectureTools.CutCheckDir[(int)World.State.Rotation][1] * 2;
                        if (newCut != MouseCutRect)
                        {
                            MouseCutRect = newCut;
                            recut        = 1;
                        }

                        if (LastFloor != World.State.Level || LastRotation != World.State.Rotation || !finalRooms.SetEquals(LastCutRooms))
                        {
                            LastCuts     = VMArchitectureTools.GenerateRoomCut(vm.Context.Architecture, World.State.Level, World.State.Rotation, finalRooms);
                            recut        = 2;
                            LastFloor    = World.State.Level;
                            LastRotation = World.State.Rotation;
                        }
                        LastCutRooms = finalRooms;

                        if (recut > 0)
                        {
                            var finalCut = new bool[LastCuts.Length];
                            Array.Copy(LastCuts, finalCut, LastCuts.Length);
                            var notableChange = VMArchitectureTools.ApplyCutRectangle(vm.Context.Architecture, World.State.Level, finalCut, MouseCutRect);
                            if (recut > 1 || notableChange || LastRectCutNotable)
                            {
                                vm.Context.Blueprint.Cutaway = finalCut;
                                vm.Context.Blueprint.Damage.Add(new FSO.LotView.Model.BlueprintDamage(FSO.LotView.Model.BlueprintDamageType.WALL_CUT_CHANGED));
                            }
                            LastRectCutNotable = notableChange;
                        }
                    }
                }
            }
        }