public override void OnEnd()
 {
     foreach (var body in PreviewBodies)
     {
         body.GetRoot().Delete();
     }
     PreviewBodies.Clear();
     Pattern = null;
     Player.VoxSelector.DrawVoxel = true;
     Player.VoxSelector.DrawBox   = true;
 }
Exemple #2
0
        public override void OnBegin(Object Arguments)
        {
            World.Tutorial("place rail");

            var args = Arguments as Arguments;

            if (args == null)
            {
                throw new InvalidProgramException();
            }

            Pattern       = args.Pattern;
            GodModeSwitch = args.Mode == Mode.GodMode;

            CreatePreviewBodies(World.ComponentManager, new VoxelHandle(World.ChunkManager, new GlobalVoxelCoordinate(0, 0, 0)));
        }
        public override void Update(DwarfGame game, DwarfTime time)
        {
            if (Player.IsCameraRotationModeActive())
            {
                Player.VoxSelector.Enabled = false;
                Player.World.SetMouse(null);
                Player.BodySelector.Enabled = false;
                return;
            }

            Player.VoxSelector.Enabled       = true;
            Player.BodySelector.Enabled      = false;
            Player.VoxSelector.DrawBox       = false;
            Player.VoxSelector.DrawVoxel     = false;
            Player.VoxSelector.SelectionType = VoxelSelectionType.SelectEmpty;

            if (Player.World.IsMouseOverGui)
            {
                Player.World.SetMouse(Player.World.MousePointer);
            }
            else
            {
                Player.World.SetMouse(new Gui.MousePointer("mouse", 1, 4));
            }

            // Don't attempt any control if the user is trying to type into a focus item.
            if (Player.World.Gui.FocusItem != null && !Player.World.Gui.FocusItem.IsAnyParentTransparent() && !Player.World.Gui.FocusItem.IsAnyParentHidden())
            {
                return;
            }

            KeyboardState state    = Keyboard.GetState();
            bool          leftKey  = state.IsKeyDown(ControlSettings.Mappings.RotateObjectLeft);
            bool          rightKey = state.IsKeyDown(ControlSettings.Mappings.RotateObjectRight);

            if (LeftPressed && !leftKey)
            {
                Pattern = Pattern.Rotate(Rail.PieceOrientation.East);
            }
            if (RightPressed && !rightKey)
            {
                Pattern = Pattern.Rotate(Rail.PieceOrientation.West);
            }
            LeftPressed  = leftKey;
            RightPressed = rightKey;

            var tint = Color.White;

            for (var i = 0; i < PreviewBodies.Count && i < Pattern.Pieces.Count; ++i)
            {
                PreviewBodies[i].UpdatePiece(Pattern.Pieces[i], Player.VoxSelector.VoxelUnderMouse);
            }

            if (RailHelper.CanPlace(Player, PreviewBodies))
            {
                tint = GameSettings.Default.Colors.GetColor("Positive", Color.Green);
            }
            else
            {
                tint = GameSettings.Default.Colors.GetColor("Negative", Color.Red);
            }

            foreach (var body in PreviewBodies)
            {
                body.SetVertexColorRecursive(tint);
            }
        }