Esempio n. 1
0
        public void Update(UpdateState state, bool scrolled)
        {
            ushort pattern = (state.CtrlDown) ? (ushort)0 : Pattern;

            var   tilePos = World.EstTileAtPosWithScroll(Parent.GetScaledPoint(state.MouseState.Position).ToVector2() / FSOEnvironment.DPIScaleFactor);
            Point cursor  = new Point((int)tilePos.X, (int)tilePos.Y);

            if (!Drawing && Commands.Count > 0)
            {
                vm.Context.Architecture.SignalRedraw();
                Commands.Clear();
            }
            if (state.ShiftDown)
            {
                if (Commands.Count == 0 || Commands[0].Type != VMArchitectureCommandType.PATTERN_FILL)
                {
                    Commands.Clear();
                    vm.Context.Architecture.SignalRedraw();
                    Commands.Add(new VMArchitectureCommand
                    {
                        Type    = VMArchitectureCommandType.PATTERN_FILL,
                        level   = World.State.Level,
                        pattern = pattern,
                        style   = 0,
                        x       = cursor.X,
                        y       = cursor.Y
                    });
                }
            }
            else
            {
                if (Commands.Count > 0 && Commands[0].Type == VMArchitectureCommandType.PATTERN_FILL)
                {
                    Commands.Clear();
                    vm.Context.Architecture.SignalRedraw();
                }
                int     dir    = 0;
                int     altdir = 0;
                Vector2 fract  = new Vector2(tilePos.X - cursor.X, tilePos.Y - cursor.Y);
                switch (World.State.CutRotation)
                {
                case WorldRotation.BottomRight:
                    if (fract.X - fract.Y > 0)
                    {
                        dir = 2; altdir = 3;
                    }
                    else
                    {
                        dir = 3; altdir = 2;
                    }
                    break;

                case WorldRotation.TopRight:
                    if (fract.X + fract.Y > 1)
                    {
                        dir = 3; altdir = 0;
                    }
                    else
                    {
                        dir = 0; altdir = 3;
                    }
                    break;

                case WorldRotation.TopLeft:
                    //+x is right down. +y is left down
                    if (fract.X - fract.Y > 0)
                    {
                        dir = 1; altdir = 0;
                    }
                    else
                    {
                        dir = 0; altdir = 1;
                    }
                    break;

                case WorldRotation.BottomLeft:
                    if (fract.X + fract.Y > 1)
                    {
                        dir = 2; altdir = 1;
                    }
                    else
                    {
                        dir = 1; altdir = 2;
                    }
                    break;
                }

                var finalDir = VMArchitectureTools.GetPatternDirection(vm.Context.Architecture, cursor, pattern, dir, altdir, World.State.Level);
                if (finalDir != -1)
                {
                    CursorDir = finalDir;
                    var cmd = new VMArchitectureCommand
                    {
                        Type    = VMArchitectureCommandType.PATTERN_DOT,
                        level   = World.State.Level,
                        pattern = pattern,
                        style   = 0,
                        x       = cursor.X,
                        y       = cursor.Y,
                        x2      = dir,
                        y2      = altdir
                    };
                    if (!Commands.Contains(cmd))
                    {
                        vm.Context.Architecture.SignalRedraw();
                        Commands.Add(cmd);
                    }
                }
            }

            var cmds = vm.Context.Architecture.Commands;

            cmds.Clear();
            foreach (var cmd in Commands)
            {
                cmds.Add(cmd);
            }

            if (cmds.Count > 0)
            {
                var cost = vm.Context.Architecture.LastTestCost;
                if (cost != 0)
                {
                    var disallowed = Parent.ActiveEntity != null && cost > Parent.ActiveEntity.TSOState.Budget.Value;
                    state.UIState.TooltipProperties.Show     = true;
                    state.UIState.TooltipProperties.Color    = disallowed ? Color.DarkRed : Color.Black;
                    state.UIState.TooltipProperties.Opacity  = 1;
                    state.UIState.TooltipProperties.Position = new Vector2(state.MouseState.X, state.MouseState.Y);
                    state.UIState.Tooltip = (cost < 0) ? ("-$" + (-cost)) : ("$" + cost);
                    state.UIState.TooltipProperties.UpdateDead = false;

                    if (disallowed)
                    {
                        HITVM.Get().PlaySoundEvent(UISounds.Error);
                    }
                }
                else
                {
                    state.UIState.TooltipProperties.Show    = false;
                    state.UIState.TooltipProperties.Opacity = 0;
                }
            }

            WallCursor.SetVisualPosition(new Vector3(cursor.X + 0.5f, cursor.Y + 0.5f, (World.State.Level - 1) * 2.95f), (Direction)(1 << ((3 - CursorDir) * 2)), vm.Context);
        }
Esempio n. 2
0
        public void Update(UpdateState state, bool scrolled)
        {
            ushort pattern = (state.KeyboardState.IsKeyDown(Keys.LeftControl)) ? (ushort)0 : Pattern;

            var   tilePos = World.State.WorldSpace.GetTileAtPosWithScroll(new Vector2(state.MouseState.X, state.MouseState.Y));
            Point cursor  = new Point((int)tilePos.X, (int)tilePos.Y);

            if (!Drawing && Commands.Count > 0)
            {
                vm.Context.Architecture.SignalRedraw();
                Commands.Clear();
            }
            if (state.KeyboardState.IsKeyDown(Keys.LeftShift))
            {
                if (Commands.Count == 0 || Commands[0].Type != VMArchitectureCommandType.PATTERN_FILL)
                {
                    Commands.Clear();
                    vm.Context.Architecture.SignalRedraw();
                }
                Commands.Add(new VMArchitectureCommand
                {
                    Type    = VMArchitectureCommandType.PATTERN_FILL,
                    level   = World.State.Level,
                    pattern = pattern,
                    style   = 0,
                    x       = cursor.X,
                    y       = cursor.Y
                });
            }
            else
            {
                if (Commands.Count > 0 && Commands[0].Type == VMArchitectureCommandType.PATTERN_FILL)
                {
                    Commands.Clear();
                    vm.Context.Architecture.SignalRedraw();
                }
                int     dir    = 0;
                int     altdir = 0;
                Vector2 fract  = new Vector2(tilePos.X - cursor.X, tilePos.Y - cursor.Y);
                switch (World.State.Rotation)
                {
                case WorldRotation.BottomRight:
                    if (fract.X - fract.Y > 0)
                    {
                        dir = 2; altdir = 3;
                    }
                    else
                    {
                        dir = 3; altdir = 2;
                    }
                    break;

                case WorldRotation.TopRight:
                    if (fract.X + fract.Y > 1)
                    {
                        dir = 3; altdir = 0;
                    }
                    else
                    {
                        dir = 0; altdir = 3;
                    }
                    break;

                case WorldRotation.TopLeft:
                    //+x is right down. +y is left down
                    if (fract.X - fract.Y > 0)
                    {
                        dir = 1; altdir = 0;
                    }
                    else
                    {
                        dir = 0; altdir = 1;
                    }
                    break;

                case WorldRotation.BottomLeft:
                    if (fract.X + fract.Y > 1)
                    {
                        dir = 2; altdir = 1;
                    }
                    else
                    {
                        dir = 1; altdir = 2;
                    }
                    break;
                }

                var finalDir = VMArchitectureTools.GetPatternDirection(vm.Context.Architecture, cursor, pattern, dir, altdir, World.State.Level);
                if (finalDir != -1)
                {
                    CursorDir = finalDir;
                    var cmd = new VMArchitectureCommand
                    {
                        Type    = VMArchitectureCommandType.PATTERN_DOT,
                        level   = World.State.Level,
                        pattern = pattern,
                        style   = 0,
                        x       = cursor.X,
                        y       = cursor.Y,
                        x2      = dir,
                        y2      = altdir
                    };
                    if (!Commands.Contains(cmd))
                    {
                        vm.Context.Architecture.SignalRedraw();
                        Commands.Add(cmd);
                    }
                }
            }

            var cmds = vm.Context.Architecture.Commands;

            cmds.Clear();
            foreach (var cmd in Commands)
            {
                cmds.Add(cmd);
            }

            WallCursor.SetVisualPosition(new Vector3(cursor.X + 0.5f, cursor.Y + 0.5f, (World.State.Level - 1) * 2.95f), (Direction)(1 << ((3 - CursorDir) * 2)), vm.Context);
        }