public void SelectBlueprint()
        {
            if (MyGuiScreenTerminal.IsOpen)
            {
                MyGuiScreenTerminal.Hide();
            }

            RemoveProjection(false);
            var blueprintScreen = new MyGuiBlueprintScreen(m_clipboard, true);
            blueprintScreen.Closed += OnBlueprintScreen_Closed;
            MyGuiSandbox.AddScreen(blueprintScreen);

        }
Esempio n. 2
0
        public bool HandleGameInput()
        {
            m_rotationHintRotating = false;
            int frameDt = MySandboxGame.TotalGamePlayTimeInMilliseconds - m_lastInputHandleTime;
            m_lastInputHandleTime += frameDt;

            bool disallowCockpitBuilding = MySession.ControlledEntity is MyCockpit && !DeveloperSpectatorIsBuilding;

            // Don't allow cube builder when paused or when in cockpit and not in developer spectator mode
            if (MySandboxGame.IsPaused || disallowCockpitBuilding)
                return false;

            //batch convert should be active in any game mode
            if (MyInput.Static.ENABLE_DEVELOPER_KEYS && MyInput.Static.IsNewKeyPressed(MyKeys.R) && MyInput.Static.IsAnyCtrlKeyPressed() && !MyInput.Static.IsAnyShiftKeyPressed() && !MyInput.Static.IsAnyMousePressed())
            {
                MyGuiAudio.PlaySound(MyGuiSounds.HudMouseClick);
                MyCubeGrid.ConvertPrefabsToObjs();
                return true;
            }

            if (MyInput.Static.ENABLE_DEVELOPER_KEYS && MyInput.Static.IsNewKeyPressed(MyKeys.T) && MyInput.Static.IsAnyCtrlKeyPressed() && !MyInput.Static.IsAnyShiftKeyPressed() && !MyInput.Static.IsAnyMousePressed() && MyPerGameSettings.EnableObjectExport)
            {
                MyGuiAudio.PlaySound(MyGuiSounds.HudMouseClick);
                MyCubeGrid.PlacePrefabsToWorld();
                return true;
            }
            if (MyInput.Static.IsNewKeyPressed(MyKeys.E) && MyInput.Static.IsAnyAltKeyPressed() && MyInput.Static.IsAnyCtrlKeyPressed() && !MyInput.Static.IsAnyShiftKeyPressed() && !MyInput.Static.IsAnyMousePressed() && MyPerGameSettings.EnableObjectExport)
            {
                MyGuiAudio.PlaySound(MyGuiSounds.HudMouseClick);
                var targetGrid = MyCubeGrid.GetTargetGrid();
                if (targetGrid != null)
                {
                    MyCubeGrid.ExportObject(targetGrid, false, true);
                }
                return true;
            }

            if (MyInput.Static.IsNewGameControlPressed(ME_SI_VIEW))
            {
                MyCubeGrid.ShowStructuralIntegrity = !MyCubeGrid.ShowStructuralIntegrity;
            }

            var context = (IsActivated && MySession.ControlledEntity is MyCharacter) ? MySession.ControlledEntity.ControlContext : MyStringId.NullOrEmpty;

            if (IsActivated && MyControllerHelper.IsControl(context, MyControlsSpace.BUILD_MODE))
            {
                IsBuildMode = !IsBuildMode;
            }

            // When spectator active, building is instant
            if (MySession.Static.CreativeMode || DeveloperSpectatorIsBuilding)
            {
                if (MySession.Static.EnableCopyPaste)
                {
                    if (MyInput.Static.IsNewKeyPressed(MyKeys.C) && MyInput.Static.IsAnyCtrlKeyPressed() && !MyInput.Static.IsAnyMousePressed())
                    {
                        if (MySession.Static.CameraController is MyCharacter || MySession.GetCameraControllerEnum() == MyCameraControllerEnum.Spectator)
                        {
                            MyGuiAudio.PlaySound(MyGuiSounds.HudClick);

                            if (m_clipboard.IsActive == false)
                            {
                                MySessionComponentVoxelHand.Static.Enabled = false;
                                DeactivateMultiBlockClipboard();

                                if (!MyInput.Static.IsAnyShiftKeyPressed())
                                {
                                    m_clipboard.CopyGroup(MyCubeGrid.GetTargetGrid());
                                }
                                else
                                    m_clipboard.CopyGrid(MyCubeGrid.GetTargetGrid());
                                UpdatePasteNotification(MySpaceTexts.CubeBuilderPasteNotification);
                            }
                            return true;
                        }
                    }

                    if (MyInput.Static.IsNewKeyPressed(MyKeys.X) && MyInput.Static.IsAnyCtrlKeyPressed())
                    {
                        MyGuiAudio.PlaySound(MyGuiSounds.HudClick);

                        MyEntity entity = MyCubeGrid.GetTargetEntity();

                        if (entity == null)
                        {
                            return true;
                        }
                        else if (entity is MyCubeGrid && m_clipboard.IsActive == false)
                        {
                            bool cutGroup = !MyInput.Static.IsAnyShiftKeyPressed();

                            if (MyFakes.CLIPBOARD_CUT_CONFIRMATION)
                            {
                                MyEntities.EnableEntityBoundingBoxDraw(entity, true);

                                MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                                buttonType: MyMessageBoxButtonsType.YES_NO,
                                messageText: MyTexts.Get(MySpaceTexts.MessageBoxTextAreYouSureToMoveGridToClipboard),
                                messageCaption: MyTexts.Get(MySpaceTexts.MessageBoxCaptionPleaseConfirm),
                                callback: (v) =>
                                {
                                    if (v == MyGuiScreenMessageBox.ResultEnum.YES)
                                        OnCutConfirm(entity as MyCubeGrid, cutGroup);

                                    MyEntities.EnableEntityBoundingBoxDraw(entity, false);
                                }));
                            }
                            else
                                OnCutConfirm(entity as MyCubeGrid, cutGroup);

                        }
                        else if (entity is MyVoxelMap && m_voxelClipboard.IsActive == false &&
                            MyPerGameSettings.GUI.VoxelMapEditingScreen == typeof(MyGuiScreenDebugSpawnMenu) // hack to disable this in ME
                            )
                        {
                            if (MyFakes.CLIPBOARD_CUT_CONFIRMATION)
                            {
                                MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                                    buttonType: MyMessageBoxButtonsType.YES_NO,
                                    messageText: MyTexts.Get(MySpaceTexts.MessageBoxTextAreYouSureToRemoveAsteroid),
                                    messageCaption: MyTexts.Get(MySpaceTexts.MessageBoxCaptionPleaseConfirm),
                                    callback: (v) =>
                                    {
                                        if (v == MyGuiScreenMessageBox.ResultEnum.YES)
                                            OnCutAsteroidConfirm(entity as MyVoxelMap);
                                        MyEntities.EnableEntityBoundingBoxDraw(entity, false);
                                    }));
                            }
                            else
                                OnCutAsteroidConfirm(entity as MyVoxelMap);
                        }
                        return true;
                    }

                    if (MyInput.Static.IsNewKeyPressed(MyKeys.V) && MyInput.Static.IsAnyCtrlKeyPressed() && !MyInput.Static.IsAnyShiftKeyPressed())
                    {
                        DeactivateBlockCreation();
                        if (m_clipboard.PasteGrid())
                        {
                            UpdatePasteNotification(MySpaceTexts.CubeBuilderPasteNotification);
                            return true;
                        }
                    }

                    if (HandleBlockCreationMovement(context))
                        return true;
                }

                if (MyInput.Static.IsAnyCtrlKeyPressed() && m_shipCreationClipboard.IsActive)
                {
                    if (MyInput.Static.PreviousMouseScrollWheelValue() < MyInput.Static.MouseScrollWheelValue())
                    {
                        m_shipCreationClipboard.MoveEntityFurther();
                        return true;
                    }
                    else if (MyInput.Static.PreviousMouseScrollWheelValue() > MyInput.Static.MouseScrollWheelValue())
                    {
                        m_shipCreationClipboard.MoveEntityCloser();
                        return true;
                    }
                }

                if (MyInput.Static.IsNewKeyPressed(MyKeys.Escape))
                {
                    if (m_clipboard.IsActive)
                    {
                        m_clipboard.Deactivate();
                        UpdatePasteNotification(MySpaceTexts.CubeBuilderPasteNotification);
                        return true;
                    }

                    if (m_floatingObjectClipboard.IsActive)
                    {
                        m_floatingObjectClipboard.Deactivate();
                        UpdatePasteNotification(MySpaceTexts.CubeBuilderPasteNotification);
                        return true;
                    }

                    if (m_voxelClipboard.IsActive)
                    {
                        m_voxelClipboard.Deactivate();
                        UpdatePasteNotification(MySpaceTexts.CubeBuilderPasteNotification);
                        return true;
                    }

                    if (m_shipCreationClipboard.IsActive)
                    {
                        m_shipCreationClipboard.Deactivate();
                        UpdatePasteNotification(MySpaceTexts.CubeBuilderPasteNotification);
                        return true;
                    }

                    //if (m_multiBlockCreationClipboard.IsActive)
                    //{
                    //    m_multiBlockCreationClipboard.Deactivate();
                    //    UpdatePasteNotification(MySpaceTexts.CubeBuilderPasteNotification);
                    //    return true;
                    //}
                }

                if (MyInput.Static.IsNewGameControlPressed(ME_PICK_BLOCK) && !MyInput.Static.IsAnyCtrlKeyPressed())
                {
                    LineD line = new LineD(MySector.MainCamera.Position, MySector.MainCamera.Position + MySector.MainCamera.ForwardVector * 100);
                    MyCubeGrid grid = m_currentGrid;
                    Vector3D hitPos;
                    if (grid != null || MyCubeGrid.TryRayCastGrid(ref line, out grid, out hitPos))
                    {
                        var result = grid.RayCastBlocks(MySector.MainCamera.Position, MySector.MainCamera.Position + MySector.MainCamera.ForwardVector * 100);
                        if (result.HasValue)
                        {
                            var slot = MyToolbarComponent.CurrentToolbar.SelectedSlot;
                            SelectBlockToToolbar(grid.GetCubeBlock(result.Value), slot.HasValue ? false : true);
                            if (slot.HasValue)
                                MyToolbarComponent.CurrentToolbar.ActivateItemAtSlot(slot.Value);
                        }
                    }
                }

                if (MyControllerHelper.IsControl(context, MyControlsSpace.PRIMARY_TOOL_ACTION))
                {
                    if (m_clipboard.IsActive)
                    {
                        if (m_clipboard.PasteGrid())
                        {
                            UpdatePasteNotification(MySpaceTexts.CubeBuilderPasteNotification);
                            return true;
                        }
                    }

                    if (m_floatingObjectClipboard.IsActive)
                    {
                        if (m_floatingObjectClipboard.PasteFloatingObject())
                        {
                            UpdatePasteNotification(MySpaceTexts.CubeBuilderPasteNotification);
                            return true;
                        }
                    }

                    if (m_voxelClipboard.IsActive)
                    {
                        if (m_voxelClipboard.PasteVoxelMap())
                        {
                            UpdatePasteNotification(MySpaceTexts.CubeBuilderPasteNotification);
                            return true;
                        }
                    }

                    if (m_shipCreationClipboard.IsActive)
                    {
                        if (m_shipCreationClipboard.PasteGrid())
                        {
                            MyGuiAudio.PlaySound(MyGuiSounds.HudPlaceBlock);
                            return true;
                        }
                    }

                    if (m_multiBlockCreationClipboard.IsActive)
                    {
                        if (m_multiBlockCreationClipboard.PasteGrid(deactivate: false))
                            MyGuiAudio.PlaySound(MyGuiSounds.HudPlaceBlock);

                        return true;
                    }

                }

                if (CurrentGrid != null)
                {

                    if (MyControllerHelper.IsControl(context, MyControlsSpace.SYMMETRY_SWITCH, MyControlStateType.NEW_PRESSED))
                    {
                        if (BlockCreationIsActivated)
                            MyGuiAudio.PlaySound(MyGuiSounds.HudClick);

                        switch (m_symmetrySettingMode)
                        {
                            case MySymmetrySettingModeEnum.NoPlane:
                                m_symmetrySettingMode = MySymmetrySettingModeEnum.XPlane;
                                UpdateSymmetryNotification(MySpaceTexts.SettingSymmetryX);
                                break;
                            case MySymmetrySettingModeEnum.XPlane:
                                m_symmetrySettingMode = MySymmetrySettingModeEnum.XPlaneOdd;
                                UpdateSymmetryNotification(MySpaceTexts.SettingSymmetryXOffset);
                                break;
                            case MySymmetrySettingModeEnum.XPlaneOdd:
                                m_symmetrySettingMode = MySymmetrySettingModeEnum.YPlane;
                                UpdateSymmetryNotification(MySpaceTexts.SettingSymmetryY);
                                break;
                            case MySymmetrySettingModeEnum.YPlane:
                                m_symmetrySettingMode = MySymmetrySettingModeEnum.YPlaneOdd;
                                UpdateSymmetryNotification(MySpaceTexts.SettingSymmetryYOffset);
                                break;
                            case MySymmetrySettingModeEnum.YPlaneOdd:
                                m_symmetrySettingMode = MySymmetrySettingModeEnum.ZPlane;
                                UpdateSymmetryNotification(MySpaceTexts.SettingSymmetryZ);
                                break;
                            case MySymmetrySettingModeEnum.ZPlane:
                                m_symmetrySettingMode = MySymmetrySettingModeEnum.ZPlaneOdd;
                                UpdateSymmetryNotification(MySpaceTexts.SettingSymmetryZOffset);
                                break;
                            case MySymmetrySettingModeEnum.ZPlaneOdd:
                                m_symmetrySettingMode = MySymmetrySettingModeEnum.NoPlane;
                                RemoveSymmetryNotification();
                                break;
                        }
                    }

                    if (MyControllerHelper.IsControl(context, MyControlsSpace.USE_SYMMETRY, MyControlStateType.NEW_PRESSED))
                    {
                        MyGuiAudio.PlaySound(MyGuiSounds.HudClick);

                        if (m_symmetrySettingMode != MySymmetrySettingModeEnum.NoPlane)
                        {
                            UseSymmetry = false;
                            m_symmetrySettingMode = MySymmetrySettingModeEnum.NoPlane;
                            RemoveSymmetryNotification();
                            return true;
                        }

                        UseSymmetry = !UseSymmetry;
                    }

                    if (CurrentBlockDefinition == null || !BlockCreationIsActivated)
                    {
                        m_symmetrySettingMode = MySymmetrySettingModeEnum.NoPlane;
                        RemoveSymmetryNotification();
                    }

                    if (IsInSymmetrySettingMode)
                    {
                        if (MyControllerHelper.IsControl(context, MyControlsSpace.PRIMARY_TOOL_ACTION, MyControlStateType.NEW_PRESSED))
                        {
                            if (m_gizmo.SpaceDefault.m_removeBlock != null)
                            {
                                Vector3I center = (m_gizmo.SpaceDefault.m_removeBlock.Min + m_gizmo.SpaceDefault.m_removeBlock.Max) / 2;

                                MyGuiAudio.PlaySound(MyGuiSounds.HudClick);
                                switch (m_symmetrySettingMode)
                                {
                                    case MySymmetrySettingModeEnum.NoPlane:
                                        System.Diagnostics.Debug.Assert(false, "Cannot get here");
                                        break;
                                    case MySymmetrySettingModeEnum.XPlane:
                                        CurrentGrid.XSymmetryPlane = center;
                                        CurrentGrid.XSymmetryOdd = false;
                                        break;
                                    case MySymmetrySettingModeEnum.XPlaneOdd:
                                        CurrentGrid.XSymmetryPlane = center;
                                        CurrentGrid.XSymmetryOdd = true;
                                        break;
                                    case MySymmetrySettingModeEnum.YPlane:
                                        CurrentGrid.YSymmetryPlane = center;
                                        CurrentGrid.YSymmetryOdd = false;
                                        break;
                                    case MySymmetrySettingModeEnum.YPlaneOdd:
                                        CurrentGrid.YSymmetryPlane = center;
                                        CurrentGrid.YSymmetryOdd = true;
                                        break;
                                    case MySymmetrySettingModeEnum.ZPlane:
                                        CurrentGrid.ZSymmetryPlane = center;
                                        CurrentGrid.ZSymmetryOdd = false;
                                        break;
                                    case MySymmetrySettingModeEnum.ZPlaneOdd:
                                        CurrentGrid.ZSymmetryPlane = center;
                                        CurrentGrid.ZSymmetryOdd = true;
                                        break;
                                }
                            }

                            return true;
                        } //if (input.IsNewLeftMousePressed())

                        if (MyControllerHelper.IsControl(context, MyControlsSpace.SECONDARY_TOOL_ACTION, MyControlStateType.NEW_PRESSED))
                        {
                            MyGuiAudio.PlaySound(MyGuiSounds.HudDeleteBlock);

                            switch (m_symmetrySettingMode)
                            {
                                case MySymmetrySettingModeEnum.NoPlane:
                                    System.Diagnostics.Debug.Assert(false, "Cannot get here");
                                    break;
                                case MySymmetrySettingModeEnum.XPlane:
                                case MySymmetrySettingModeEnum.XPlaneOdd:
                                    CurrentGrid.XSymmetryPlane = null;
                                    CurrentGrid.XSymmetryOdd = false;
                                    break;
                                case MySymmetrySettingModeEnum.YPlane:
                                case MySymmetrySettingModeEnum.YPlaneOdd:
                                    CurrentGrid.YSymmetryPlane = null;
                                    CurrentGrid.YSymmetryOdd = false;
                                    break;
                                case MySymmetrySettingModeEnum.ZPlane:
                                case MySymmetrySettingModeEnum.ZPlaneOdd:
                                    CurrentGrid.ZSymmetryPlane = null;
                                    CurrentGrid.ZSymmetryOdd = false;
                                    break;
                            }

                            return false;
                        }
                    } //if (IsInSymmetrySettingMode)


                    if (MyInput.Static.IsNewKeyPressed(MyKeys.Escape))
                    {
                        if (m_symmetrySettingMode != MySymmetrySettingModeEnum.NoPlane)
                        {
                            m_symmetrySettingMode = MySymmetrySettingModeEnum.NoPlane;
                            RemoveSymmetryNotification();
                            return true;
                        }

                        if (m_gizmo.SpaceDefault.m_continueBuild != null)
                        {
                            m_gizmo.SpaceDefault.m_startBuild = null;
                            m_gizmo.SpaceDefault.m_startRemove = null;
                            m_gizmo.SpaceDefault.m_continueBuild = null;
                            return true;
                        }
                    }

                    if (MyInput.Static.IsNewLeftMousePressed() || MyControllerHelper.IsControl(context, MyControlsSpace.PRIMARY_BUILD_ACTION))
                    {
                        if (!PlacingSmallGridOnLargeStatic && (MyInput.Static.IsAnyCtrlKeyPressed() || BuildingMode != BuildingModeEnum.SingleBlock))
                        {
                            StartBuilding();
                        }
                        else
                        {
                            Add();
                        }
                    }

                    if (MyInput.Static.IsNewRightMousePressed() || MyControllerHelper.IsControl(context, MyControlsSpace.SECONDARY_BUILD_ACTION))
                    {
                        if (MyInput.Static.IsAnyCtrlKeyPressed() || BuildingMode != BuildingModeEnum.SingleBlock)
                        {
                            StartRemoving();
                        }
                        else
                        {
                            if (MyFakes.ENABLE_COMPOUND_BLOCKS && !CompoundEnabled)
                            {
                                foreach (var gizmoSpace in m_gizmo.Spaces)
                                {
                                    if (!gizmoSpace.Enabled)
                                        continue;

                                    gizmoSpace.m_blockIdInCompound = null;
                                }
                            }

                            Remove();
                        }
                    }

                    if (MyInput.Static.IsLeftMousePressed() ||
                        MyInput.Static.IsRightMousePressed())
                    {
                        ContinueBuilding(MyInput.Static.IsAnyShiftKeyPressed() || BuildingMode == BuildingModeEnum.Plane);
                    }

                    if (MyInput.Static.IsNewLeftMouseReleased() ||
                        MyInput.Static.IsNewRightMouseReleased())
                    {
                        StopBuilding();
                    }

                } //if (CurrentGrid != null)
                else if (CurrentVoxelMap != null)
                {
                    //RKTODO - creation of blocks in line or plane will be done when server function will be prepared 
                    // (need to create grid with one block - the first target and then build all other blocks in the grid)
                    //if (MyInput.Static.IsNewKeyPressed(Keys.Escape))
                    //{
                    //    if (m_gizmo.SpaceDefault.m_continueBuild != null)
                    //    {
                    //        m_gizmo.SpaceDefault.m_startBuild = null;
                    //        m_gizmo.SpaceDefault.m_startRemove = null;
                    //        m_gizmo.SpaceDefault.m_continueBuild = null;
                    //        return true;
                    //    }
                    //}

                    if (MyControllerHelper.IsControl(context, MyControlsSpace.PRIMARY_TOOL_ACTION))
                    {
                        //if (MyInput.Static.IsAnyCtrlKeyPressed() || BuildingMode != BuildingModeEnum.SingleBlock)
                        //{
                        //    StartBuilding();
                        //}
                        //else
                        {
                            Add();
                        }
                    }

                    //if (MyInput.Static.IsLeftMousePressed() ||
                    //    MyInput.Static.IsRightMousePressed())
                    //{
                    //    ContinueBuilding(MyInput.Static.IsAnyShiftKeyPressed() || BuildingMode == BuildingModeEnum.Plane);
                    //}

                    //if (MyInput.Static.IsNewLeftMouseReleased() ||
                    //    MyInput.Static.IsNewRightMouseReleased())
                    //{
                    //    StopBuilding();
                    //}
                } //if (CurrentVoxelMap != null)
                else if (DynamicMode)
                {
                    if (MyControllerHelper.IsControl(context, MyControlsSpace.PRIMARY_TOOL_ACTION))
                    {
                        Add();
                    }
                } // if (DynamicMode)
            }
            else if (MySession.Static.SimpleSurvival)
            {
                if (DynamicMode && HandleBlockCreationMovement(context))
                    return true;

                if (MyControllerHelper.IsControl(MySpaceBindingCreator.CX_CHARACTER, MyControlsSpace.SECONDARY_TOOL_ACTION))
                {
                    if (MyFakes.ENABLE_COMPOUND_BLOCKS && !CompoundEnabled)
                    {
                        foreach (var gizmoSpace in m_gizmo.Spaces)
                        {
                            if (!gizmoSpace.Enabled)
                                continue;

                            gizmoSpace.m_blockIdInCompound = null;
                        }
                    }

                    Remove();
                }
            }
            else if (MyFakes.ENABLE_BATTLE_SYSTEM && MySession.Static.Battle) 
            {
                if (MyControllerHelper.IsControl(context, MyControlsSpace.PRIMARY_TOOL_ACTION))
                {
                    if (m_clipboard.IsActive)
                    {
                        if (m_clipboard.PasteGrid())
                        {
                            UpdatePasteNotification(MySpaceTexts.CubeBuilderPasteNotification);
                            return true;
                        }
                    }
                }
            }

            if (MyControllerHelper.IsControl(context, MyControlsSpace.SWITCH_COMPOUND, MyControlStateType.NEW_PRESSED))
                CompoundEnabled = !CompoundEnabled;

            if (MyInput.Static.IsNewGameControlPressed(ME_PRESS_TO_COMPOUND))
                CompoundEnabled = true;

            if (MyInput.Static.IsNewGameControlReleased(ME_PRESS_TO_COMPOUND))
                CompoundEnabled = false;

            if (MyInput.Static.IsNewKeyPressed(MyKeys.B) && MyInput.Static.IsAnyCtrlKeyPressed() && !MyInput.Static.IsAnyMousePressed())
            {
                MyGuiAudio.PlaySound(MyGuiSounds.HudClick);

                if (!m_clipboard.IsActive && !MySession.Static.Battle)
                {
                    MySessionComponentVoxelHand.Static.Enabled = false;
                    var copiedGrid = MyCubeGrid.GetTargetGrid();
                    if (!MyInput.Static.IsAnyShiftKeyPressed())
                        m_clipboard.CopyGroup(copiedGrid);
                    else
                        m_clipboard.CopyGrid(copiedGrid);

                    UpdatePasteNotification(MySpaceTexts.CubeBuilderPasteNotification);

                    var blueprintScreen = new MyGuiBlueprintScreen(m_clipboard);
                    if (copiedGrid != null)
                    {
                        blueprintScreen.CreateFromClipboard(true);
                    }
                    m_clipboard.Deactivate();
                    MyGuiSandbox.AddScreen(blueprintScreen);
                }
                return true;
            }

            if (MyInput.Static.IsNewKeyPressed(MyKeys.Escape))
            {
                if (m_shipCreationClipboard.IsActive)
                {
                    /*m_shipCreationClipboard.Deactivate();*/
                    Deactivate();
                    return true;
                }
            }

            if (MyInput.Static.IsNewGameControlPressed(MyControlsSpace.LANDING_GEAR) && MySession.LocalHumanPlayer != null && MySession.LocalHumanPlayer.Identity.Character == MySession.ControlledEntity)
            {
                if (!MyInput.Static.IsAnyShiftKeyPressed() && MyGuiScreenGamePlay.ActiveGameplayScreen == null)
                {
                    MyGuiAudio.PlaySound(MyGuiSounds.HudClick);
                    MyGuiSandbox.AddScreen(MyGuiScreenGamePlay.ActiveGameplayScreen = new MyGuiScreenColorPicker());
                }
            }

            if (CurrentGrid != null && MyInput.Static.IsNewGameControlPressed(MyControlsSpace.LANDING_GEAR))
            {
                if (MyInput.Static.IsAnyShiftKeyPressed())
                {
                    foreach (var gizmoSpace in m_gizmo.Spaces)
                    {
                        if (gizmoSpace.m_removeBlock != null)
                            MyToolbar.ColorMaskHSV = gizmoSpace.m_removeBlock.ColorMaskHSV;
                    }
                }
            }

            if (CurrentGrid != null && MyInput.Static.IsGameControlPressed(MyControlsSpace.CUBE_COLOR_CHANGE))
            {
                int expand = MyInput.Static.IsAnyCtrlKeyPressed() ? 1 : 0;
                expand = MyInput.Static.IsAnyShiftKeyPressed() ? 3 : expand;
                Change(expand);
            }

            if (IsActivated)
            {
                for (int i = 0; i < 6; ++i)
                {
                    bool standardRotation = MyControllerHelper.IsControl(context, m_rotationControls[i], MyControlStateType.PRESSED);
                    if (standardRotation)
                    {
                        bool newStandardPress = MyControllerHelper.IsControl(context, m_rotationControls[i], MyControlStateType.NEW_PRESSED);
                        bool newPress = newStandardPress;

                        int axis = -1;
                        int direction = m_rotationDirections[i];

                        if (MyFakes.ENABLE_STANDARD_AXES_ROTATION)
                        {
                            axis = GetStandardRotationAxisAndDirection(i, ref direction);
                        }
                        else
                        {
                            if (i < 2)
                            {
                                axis = m_rotationHints.RotationUpAxis;
                                direction *= m_rotationHints.RotationUpDirection;
                            }
                            if (i >= 2 && i < 4)
                            {
                                axis = m_rotationHints.RotationRightAxis;
                                direction *= m_rotationHints.RotationRightDirection;
                            }
                            if (i >= 4)
                            {
                                axis = m_rotationHints.RotationForwardAxis;
                                direction *= m_rotationHints.RotationForwardDirection;
                            }
                        }

                        if (axis != -1)
                        {
                            m_rotationHintRotating |= !newPress;
                            RotateAxis(axis, direction, newPress, frameDt);
                        }
                    }
                }
            }

            if (MyInput.Static.IsNewGameControlPressed(MyControlsSpace.SWITCH_LEFT))
            {
                if (IsActivated && (CurrentBlockDefinition == null || MyFakes.ENABLE_BLOCK_COLORING))
                {
                    MyGuiAudio.PlaySound(MyGuiSounds.HudClick);
                    MyToolbar.PrevColorSlot();
                }
            }
            if (MyInput.Static.IsNewGameControlPressed(MyControlsSpace.SWITCH_RIGHT))
            {
                if (IsActivated && (CurrentBlockDefinition == null || MyFakes.ENABLE_BLOCK_COLORING))
                {
                    MyGuiAudio.PlaySound(MyGuiSounds.HudClick);
                    MyToolbar.NextColorSlot();
                }
            }

            if (MyFakes.ENABLE_BLOCK_STAGES && CurrentBlockDefinition != null && CurrentBlockDefinitionStages.Count > 0)
            {
                bool? switchForward = null;

                if (!MyInput.Static.IsGameControlPressed(MyControlsSpace.LOOKAROUND) && !MyInput.Static.IsAnyCtrlKeyPressed() && !MyInput.Static.IsAnyShiftKeyPressed())
                {
                    if (MyInput.Static.PreviousMouseScrollWheelValue() < MyInput.Static.MouseScrollWheelValue()
                        || MyControllerHelper.IsControl(context, MyControlsSpace.NEXT_BLOCK_STAGE, MyControlStateType.NEW_PRESSED))
                    {
                        switchForward = true;
                    }
                    else if (MyInput.Static.PreviousMouseScrollWheelValue() > MyInput.Static.MouseScrollWheelValue()
                        || MyControllerHelper.IsControl(context, MyControlsSpace.PREV_BLOCK_STAGE, MyControlStateType.NEW_PRESSED))
                    {
                        switchForward = false;
                    }
                }

                //if (switchForward == null && MyInput.Static.IsNewGameControlPressed(ME_SWITCH_STAGES))
                //{
                //    switchForward = true;
                //    if (MyInput.Static.IsAnyShiftKeyPressed())
                //        switchForward = false;
                //}

                if (switchForward.HasValue)
                {
                    int currDefinitionIndex = CurrentBlockDefinitionStages.IndexOf(CurrentBlockDefinition);
                    int nextIndex;

                    if (switchForward.Value)
                    {
                        nextIndex = 0;
                        if (currDefinitionIndex != -1 && currDefinitionIndex < CurrentBlockDefinitionStages.Count - 1)
                            nextIndex = currDefinitionIndex + 1;
                    }
                    else
                    {
                        nextIndex = CurrentBlockDefinitionStages.Count - 1;
                        if (currDefinitionIndex != -1 && currDefinitionIndex > 0)
                            nextIndex = currDefinitionIndex - 1;
                    }

                    UpdateCubeBlockStageDefinition(CurrentBlockDefinitionStages[nextIndex]);
                }
            }

            if (MyFakes.ENABLE_CUBE_BUILDER_DYNAMIC_MODE
                && (CurrentBlockDefinition != null || (MyFakes.ENABLE_ALTERNATIVE_CLIPBOARD && m_clipboard.IsActive))
                &&  MyControllerHelper.IsControl(context, MyControlsSpace.SWITCH_BUILDING_MODE, MyControlStateType.NEW_PRESSED))
            {
                DynamicMode = !DynamicMode;

                if (DynamicMode)
                {
                    if (MySession.Static.SurvivalMode && !DeveloperSpectatorIsBuilding && CurrentBlockDefinition != null)
                    {
                        float gridSize = MyDefinitionManager.Static.GetCubeSize(CurrentBlockDefinition.CubeSize);
                        float maxSize = MathHelper.Max(CurrentBlockDefinition.Size.X, CurrentBlockDefinition.Size.Y, CurrentBlockDefinition.Size.Z) * gridSize;
                        IntersectionDistance = 1 + maxSize;
                        m_multiBlockCreationClipboard.SetDragDistance(IntersectionDistance);
                    }
                }
                else
                {
                    IntersectionDistance = DEFAULT_BLOCK_BUILDING_DISTANCE;
                    m_multiBlockCreationClipboard.SetDragDistance(IntersectionDistance);
                }

                if (MyFakes.ENABLE_ALTERNATIVE_CLIPBOARD)
                {
                    ((MyGridClipboard2)m_clipboard).DynamicModeChanged();
                }
            }

            return false;
        }
        private bool HandleBlueprintInput()
        {
            if (MyInput.Static.IsNewKeyPressed(MyKeys.B) && MyInput.Static.IsAnyCtrlKeyPressed() && !MyInput.Static.IsAnyMousePressed())
            {
                MyGuiAudio.PlaySound(MyGuiSounds.HudClick);

                if (!m_clipboard.IsActive && !MySession.Static.Battle)
                {
                    MySessionComponentVoxelHand.Static.Enabled = false;
                    var copiedGrid = MyCubeGrid.GetTargetGrid();

                    if (!MyInput.Static.IsAnyShiftKeyPressed())
                        m_clipboard.CopyGroup(copiedGrid, MyInput.Static.IsAnyAltKeyPressed() ? GridLinkTypeEnum.Physical : GridLinkTypeEnum.Logical);
                    else
                        m_clipboard.CopyGrid(copiedGrid);

                    UpdatePasteNotification(MyCommonTexts.CubeBuilderPasteNotification);

                    var blueprintScreen = new MyGuiBlueprintScreen(m_clipboard, MySession.Static.CreativeMode || MySession.Static.IsAdminModeEnabled(Sync.MyId));
                    if (copiedGrid != null)
                    {
                        blueprintScreen.CreateFromClipboard(true);
                    }
                    m_clipboard.Deactivate();
                    MyGuiSandbox.AddScreen(blueprintScreen);
                }
                return true;
            }

            return false;
        }
Esempio n. 4
0
        public MyGuiDetailScreenDefault(Action<MyGuiControlListbox.Item> callBack, MyGuiControlListbox.Item selectedItem, MyGuiBlueprintScreen parent, MyGuiCompositeTexture thumbnailTexture, float textScale) :
            base(false, parent, thumbnailTexture, selectedItem, textScale)
        {
            var prefabPath = Path.Combine(m_defaultBlueprintFolder, m_blueprintName, "bp.sbc");
            this.callBack = callBack;

            if (File.Exists(prefabPath))
            {
                m_loadedPrefab = LoadPrefab(prefabPath);

                if (m_loadedPrefab == null)
                {
                    MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                        buttonType: MyMessageBoxButtonsType.OK,
                        styleEnum: MyMessageBoxStyleEnum.Error,
                        messageCaption: new StringBuilder("Error"),
                        messageText: new StringBuilder("Failed to load the blueprint file.")
                        ));
                    m_killScreen = true;
                }
                else
                {
                    RecreateControls(true);
                }
            }
            else
            {
                m_killScreen = true;
            }
        }
Esempio n. 5
0
        public MyGuiDetailScreenSteam(Action<MyGuiControlListbox.Item> callBack, MyGuiControlListbox.Item selectedItem, MyGuiBlueprintScreen parent , MyGuiCompositeTexture thumbnailTexture, float textScale) :
            base(false, parent, thumbnailTexture, selectedItem, textScale)
        {
            this.callBack = callBack;

            m_publishedItemId = (selectedItem.UserData as MyBlueprintItemInfo).PublishedItemId;

            var prefabPath = Path.Combine(m_workshopBlueprintFolder, m_publishedItemId.ToString() + m_workshopBlueprintSuffix);
            
            if (File.Exists(prefabPath))
            {
                m_loadedPrefab = LoadWorkshopPrefab(prefabPath, m_publishedItemId);

                Debug.Assert(m_loadedPrefab != null);
                if (m_loadedPrefab == null)
                {
                    m_killScreen = true;
                }
                else
                {
                    var name = m_loadedPrefab.ShipBlueprints[0].CubeGrids[0].DisplayName;
                    if (name.Length > 40)
                    {
                        var newName = name.Substring(0, 40);
                        m_loadedPrefab.ShipBlueprints[0].CubeGrids[0].DisplayName = newName;
                    }
                    RecreateControls(true);
                }
            }
            else
            {
                m_killScreen = true;
            }
        }
Esempio n. 6
0
        public MyGuiDetailScreenDefault(Action <MyGuiControlListbox.Item> callBack, MyGuiControlListbox.Item selectedItem, MyGuiBlueprintScreen parent, string thumbnailTexture, float textScale) :
            base(false, parent, thumbnailTexture, selectedItem, textScale)
        {
            var prefabPath = Path.Combine(m_defaultBlueprintFolder, m_blueprintName, "bp.sbc");

            this.callBack = callBack;

            if (File.Exists(prefabPath))
            {
                m_loadedPrefab = LoadPrefab(prefabPath);

                if (m_loadedPrefab == null)
                {
                    MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                                               buttonType: MyMessageBoxButtonsType.OK,
                                               styleEnum: MyMessageBoxStyleEnum.Error,
                                               messageCaption: new StringBuilder("Error"),
                                               messageText: new StringBuilder("Failed to load the blueprint file.")
                                               ));
                    m_killScreen = true;
                }
                else
                {
                    RecreateControls(true);
                }
            }
            else
            {
                m_killScreen = true;
            }
        }
Esempio n. 7
0
        public MyGuiDetailScreenSteam(Action <MyGuiControlListbox.Item> callBack, MyGuiControlListbox.Item selectedItem, MyGuiBlueprintScreen parent, string thumbnailTexture, float textScale) :
            base(false, parent, thumbnailTexture, selectedItem, textScale)
        {
            this.callBack = callBack;

            m_publishedItemId = (selectedItem.UserData as MyBlueprintItemInfo).PublishedItemId;

            var prefabPath = Path.Combine(m_workshopBlueprintFolder, m_publishedItemId.ToString() + m_workshopBlueprintSuffix);

            if (File.Exists(prefabPath))
            {
                m_loadedPrefab = LoadWorkshopPrefab(prefabPath, m_publishedItemId);

                Debug.Assert(m_loadedPrefab != null);
                if (m_loadedPrefab == null)
                {
                    m_killScreen = true;
                }
                else
                {
                    var name = m_loadedPrefab.ShipBlueprints[0].CubeGrids[0].DisplayName;
                    if (name.Length > 40)
                    {
                        var newName = name.Substring(0, 40);
                        m_loadedPrefab.ShipBlueprints[0].CubeGrids[0].DisplayName = newName;
                    }
                    RecreateControls(true);
                }
            }
            else
            {
                m_killScreen = true;
            }
        }
 public LoadPrefabData(MyObjectBuilder_Definitions prefab, string path, MyGuiBlueprintScreen blueprintScreen, ulong? id = null)
 {
     m_prefab = prefab;
     m_path = path;
     m_blueprintScreen = blueprintScreen;
     m_id = id;
 }