static CelestialBodies()
 {
     try
     {
         SystemBody = new BodyInfo(PSystemManager.Instance.localBodies.Find(b => b.referenceBody == null || b.referenceBody == b));
         String homeCBName = Planetarium.fetch.Home.bodyName;
         if (!SetSelectedBody(homeCBName))
         {
             SelectedBody = SystemBody;
             SelectedBody.SetSelected(true);
         }
     }
     catch (Exception ex)
     {
         Logger.Exception(ex);
     }
 }
Example #2
0
        private void HandleOrientation()
        {
            // Don't attempt any camera control if the user is trying to type intoa 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)
            {
                OverrideOrientation = true;
                leftPressed         = false;
                CurrentOrientation += (float)(Math.PI / 2);
                if (SelectedBody != null)
                {
                    SelectedBody.Orient(CurrentOrientation);
                    SelectedBody.UpdateBoundingBox();
                    SelectedBody.UpdateTransform();
                    SelectedBody.PropogateTransforms();
                    SelectedBody.UpdateBoundingBox();
                    SoundManager.PlaySound(ContentPaths.Audio.Oscar.sfx_gui_confirm_selection, SelectedBody.Position, 0.5f);
                }
            }

            if (rightPressed && !rightKey)
            {
                OverrideOrientation = true;
                rightPressed        = false;
                CurrentOrientation -= (float)(Math.PI / 2);
                if (SelectedBody != null)
                {
                    SelectedBody.Orient(CurrentOrientation);
                    SelectedBody.UpdateBoundingBox();
                    SelectedBody.UpdateTransform();
                    SelectedBody.PropogateTransforms();
                    SelectedBody.UpdateBoundingBox();
                    SoundManager.PlaySound(ContentPaths.Audio.Oscar.sfx_gui_confirm_selection, SelectedBody.Position, 0.5f);
                }
            }

            leftPressed  = leftKey;
            rightPressed = rightKey;
        }
        public override void OnEnd()
        {
            if (SelectedBody != null)
            {
                foreach (var tinter in SelectedBody.GetRoot().EnumerateAll().OfType <Tinter>())
                {
                    tinter.VertexColorTint = Color.White;
                    tinter.Stipple         = false;
                }

                if (State == ToolState.Dragging)
                {
                    SelectedBody.LocalTransform = OrigTransform;
                    SelectedBody.PropogateTransforms();
                }
            }
        }
Example #4
0
 /// <summary>
 ///     Sets the selected body to one matching the supplied body name.  Returns true if successful.
 /// </summary>
 public static bool SetSelectedBody(string bodyName)
 {
     try
     {
         BodyInfo body = GetBodyInfo(bodyName);
         if (body != null)
         {
             if (SelectedBody != null)
             {
                 SelectedBody.SetSelected(false);
             }
             SelectedBody = body;
             SelectedBody.SetSelected(true);
             return(true);
         }
     }
     catch (Exception ex)
     {
         Logger.Exception(ex);
     }
     return(false);
 }
Example #5
0
        public override void Update(DwarfGame game, DwarfTime time)
        {
            if (Player.IsCameraRotationModeActive())
            {
                return;
            }

            Player.VoxSelector.Enabled  = false;
            Player.BodySelector.Enabled = false;

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

            MouseState mouse = Mouse.GetState();


            if (State == ToolState.Selecting)
            {
                if (SelectedBody != null)
                {
                    foreach (var tinter in SelectedBody.GetRoot().EnumerateAll().OfType <Tinter>())
                    {
                        tinter.VertexColorTint = Color.White;
                        tinter.Stipple         = false;
                    }
                }

                SelectedBody = Player.World.ComponentManager.SelectRootBodiesOnScreen(new Rectangle(mouse.X, mouse.Y, 1, 1), Player.World.Camera)
                               .Where(body => body.Tags.Contains("Moveable"))
                               .FirstOrDefault();

                if (SelectedBody != null)
                {
                    if (SelectedBody.IsReserved)
                    {
                        Player.World.ShowTooltip("Can't move this " + SelectedBody.Name + "\nIt is being used.");
                    }
                    else
                    {
                        Player.World.ShowTooltip("Left click and drag to move this " + SelectedBody.Name);
                        foreach (var tinter in SelectedBody.GetRoot().EnumerateAll().OfType <Tinter>())
                        {
                            tinter.VertexColorTint = Color.Blue;
                            tinter.Stipple         = false;
                        }
                    }

                    if (mouse.LeftButton == ButtonState.Pressed)
                    {
                        StartDragging(SelectedBody);
                    }
                }
            }
            else if (State == ToolState.Dragging)
            {
                if (SelectedBody == null)
                {
                    throw new InvalidProgramException();
                }

                var craftDetails = SelectedBody.GetRoot().GetComponent <CraftDetails>();
                if (craftDetails != null && CraftLibrary.GetCraftable(craftDetails.CraftType).AllowRotation)
                {
                    HandleOrientation();
                    Player.World.ShowToolPopup(String.Format("Press {0}/{1} to rotate.", ControlSettings.Mappings.RotateObjectLeft, ControlSettings.Mappings.RotateObjectRight));
                }

                var voxelUnderMouse = Player.VoxSelector.VoxelUnderMouse;
                if (voxelUnderMouse.IsValid && voxelUnderMouse.IsEmpty)
                {
                    var       spawnOffset = Vector3.Zero;
                    CraftItem craftItem   = null;

                    if (craftDetails != null)
                    {
                        craftItem = CraftLibrary.GetCraftable(craftDetails.CraftType);
                        if (craftItem != null)
                        {
                            spawnOffset = craftItem.SpawnOffset;
                        }
                        else
                        {
                            Console.Error.WriteLine("{0} had no craft item.", craftDetails.CraftType);
                        }
                    }


                    if (craftItem == null)
                    {
                        return;
                    }

                    SelectedBody.LocalPosition = voxelUnderMouse.WorldPosition + new Vector3(0.5f, 0.0f, 0.5f) + spawnOffset;
                    SelectedBody.UpdateTransform();

                    if (OverrideOrientation)
                    {
                        SelectedBody.Orient(CurrentOrientation);
                    }
                    else
                    {
                        SelectedBody.OrientToWalls();
                    }

                    SelectedBody.PropogateTransforms();

                    var validPlacement = ObjectHelper.IsValidPlacement(voxelUnderMouse, craftItem, Player, SelectedBody, "move", "moved");

                    foreach (var tinter in SelectedBody.GetRoot().EnumerateAll().OfType <Tinter>())
                    {
                        tinter.VertexColorTint = validPlacement ? Color.Green : Color.Red;
                        tinter.Stipple         = true;
                    }

                    if (mouse.LeftButton == ButtonState.Released)
                    {
                        if (validPlacement)
                        {
                        }
                        else
                        {
                            SelectedBody.LocalTransform = OrigTransform;
                            SelectedBody.PropogateTransforms();
                        }

                        foreach (var tinter in SelectedBody.GetRoot().EnumerateAll().OfType <Tinter>())
                        {
                            tinter.VertexColorTint = Color.White;
                            tinter.Stipple         = false;
                        }

                        State = ToolState.Selecting;
                    }
                }
            }
        }