Esempio n. 1
0
        private void HandleOrientation()
        {
            if (CurrentDesignation == null || CurrentCraftBody == null)
            {
                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);
                CurrentCraftBody.Orient(CurrentOrientation);
                CurrentCraftBody.UpdateBoundingBox();
                CurrentCraftBody.UpdateTransform();
                CurrentCraftBody.PropogateTransforms();
                SoundManager.PlaySound(ContentPaths.Audio.Oscar.sfx_gui_confirm_selection, CurrentCraftBody.Position,
                                       0.5f);
                CurrentCraftBody.SetTintRecursive(IsValid(CurrentDesignation) ? Color.Green : Color.Red);
            }
            if (rightPressed && !rightKey)
            {
                OverrideOrientation = true;
                rightPressed        = false;
                CurrentOrientation -= (float)(Math.PI / 2);
                CurrentCraftBody.Orient(CurrentOrientation);
                CurrentCraftBody.UpdateBoundingBox();
                CurrentCraftBody.UpdateTransform();
                CurrentCraftBody.PropogateTransforms();
                SoundManager.PlaySound(ContentPaths.Audio.Oscar.sfx_gui_confirm_selection, CurrentCraftBody.Position, 0.5f);
                CurrentCraftBody.SetTintRecursive(IsValid(CurrentDesignation) ? Color.Green : Color.Red);
            }


            leftPressed  = leftKey;
            rightPressed = rightKey;

            CurrentDesignation.OverrideOrientation = this.OverrideOrientation;
            CurrentDesignation.Orientation         = this.CurrentOrientation;
        }
Esempio n. 2
0
        public void Update(DwarfTime gameTime, GameMaster player)
        {
            if (!IsEnabled)
            {
                if (CurrentCraftBody != null)
                {
                    CurrentCraftBody.Delete();
                    CurrentCraftBody = null;
                }

                return;
            }

            if (Faction == null)
            {
                Faction = player.Faction;
            }

            if (CurrentCraftType != null && CurrentCraftBody == null)
            {
                CurrentCraftBody = EntityFactory.CreateEntity <Body>(CurrentCraftType.Name,
                                                                     player.VoxSelector.VoxelUnderMouse.WorldPosition,
                                                                     Blackboard.Create <List <ResourceAmount> >("Resources", SelectedResources));
                EntityFactory.GhostEntity(CurrentCraftBody, Color.White);

                CurrentDesignation = new CraftDesignation()
                {
                    ItemType = CurrentCraftType,
                    Location = VoxelHandle.InvalidHandle,
                    Valid    = true
                };

                OverrideOrientation = false;
                CurrentCraftBody.SetTintRecursive(Color.Green);
            }

            if (CurrentCraftBody == null || !player.VoxSelector.VoxelUnderMouse.IsValid)
            {
                return;
            }

            CurrentCraftBody.LocalPosition = player.VoxSelector.VoxelUnderMouse.WorldPosition + new Vector3(0.5f, 0.0f, 0.5f) + CurrentCraftType.SpawnOffset;

            CurrentCraftBody.GlobalTransform = CurrentCraftBody.LocalTransform;
            CurrentCraftBody.UpdateTransform();
            CurrentCraftBody.PropogateTransforms();
            if (OverrideOrientation)
            {
                CurrentCraftBody.Orient(CurrentOrientation);
            }
            else
            {
                CurrentCraftBody.OrientToWalls();
            }

            HandleOrientation();

            if (CurrentDesignation != null)
            {
                if (CurrentDesignation.Location.Equals(player.VoxSelector.VoxelUnderMouse))
                {
                    return;
                }

                CurrentDesignation.Location = player.VoxSelector.VoxelUnderMouse;

                World.ShowTooltip("Click to build. Press R/T to rotate.");
                CurrentCraftBody.SetTintRecursive(IsValid(CurrentDesignation) ? Color.Green : Color.Red);
            }
        }