private void UpdatePreviewBBox()
        {
            if (m_previewFloatingObjects == null)
            {
                return;
            }

            if (m_visible == false)
            {
                foreach (var floatingObject in m_previewFloatingObjects)
                {
                    MyEntities.EnableEntityBoundingBoxDraw(floatingObject, false);
                }
                return;
            }

            Vector4 color = new Vector4(Color.Red.ToVector3() * 0.8f, 1);

            if (m_canBePlaced)
            {
                color = Color.Gray.ToVector4();
            }

            // Draw a little inflated bounding box
            var inflation = new Vector3(0.1f);

            foreach (var floatingObject in m_previewFloatingObjects)
            {
                MyEntities.EnableEntityBoundingBoxDraw(floatingObject, true, color, lineWidth: 0.04f, inflateAmount: inflation);
            }
        }
        private void ChangeClipboardPreview(bool visible)
        {
            if (m_copiedFloatingObjects.Count == 0 || !visible)
            {
                foreach (var grid in m_previewFloatingObjects)
                {
                    MyEntities.EnableEntityBoundingBoxDraw(grid, false);
                    grid.Close();
                }
                m_previewFloatingObjects.Clear();
                m_visible = false;
                return;
            }

            MyEntities.RemapObjectBuilderCollection(m_copiedFloatingObjects);

            foreach (var gridBuilder in m_copiedFloatingObjects)
            {
                var previewFloatingObject = MyEntities.CreateFromObjectBuilder(gridBuilder) as MyFloatingObject;
                if (previewFloatingObject == null)
                {
                    ChangeClipboardPreview(false);
                    return;// Not enough memory to create preview grid or there was some error.
                }

                MakeTransparent(previewFloatingObject);
                IsActive  = visible;
                m_visible = visible;
                MyEntities.Add(previewFloatingObject);

                previewFloatingObject.Save = false;
                DisablePhysicsRecursively(previewFloatingObject);
                m_previewFloatingObjects.Add(previewFloatingObject);
            }
        }
Пример #3
0
 void IMyEntities.EnableEntityBoundingBoxDraw(IMyEntity entity, bool enable, VRageMath.Vector4?color, float lineWidth, VRageMath.Vector3?inflateAmount)
 {
     if (entity is MyEntity)
     {
         MyEntities.EnableEntityBoundingBoxDraw(entity as MyEntity, enable, color, lineWidth, inflateAmount);
     }
 }
Пример #4
0
        private void ChangeClipboardPreview(bool visible)
        {
            if (m_copiedVoxelMaps.Count == 0 || !visible)
            {
                foreach (var voxelMap in m_previewVoxelMaps)
                {
                    MyEntities.EnableEntityBoundingBoxDraw(voxelMap, false);
                    if (m_shouldMarkForClose)
                    {
                        voxelMap.Close();
                    }
                }
                m_previewVoxelMaps.Clear();
                m_visible = false;
                return;
            }

            MyEntities.RemapObjectBuilderCollection(m_copiedVoxelMaps);

            for (int i = 0; i < m_copiedVoxelMaps.Count; ++i)
            {
                var voxelMapOb = m_copiedVoxelMaps[i];
                var storage    = m_copiedStorages[i];

                MyVoxelBase previewVoxelMap = null;

                if (voxelMapOb is MyObjectBuilder_VoxelMap)
                {
                    previewVoxelMap = new MyVoxelMap();
                }
                if (voxelMapOb is MyObjectBuilder_Planet)
                {
                    m_planetMode = true;
                    IsActive     = visible;
                    m_visible    = visible;
                    continue;
                }

                var pos = voxelMapOb.PositionAndOrientation.Value.Position;
                previewVoxelMap.Init(voxelMapOb, storage);
                previewVoxelMap.BeforePaste();

                DisablePhysicsRecursively(previewVoxelMap);
                MakeTransparent(previewVoxelMap);
                MyEntities.Add(previewVoxelMap);
                previewVoxelMap.PositionLeftBottomCorner = m_pastePosition - previewVoxelMap.Storage.Size * 0.5f;
                previewVoxelMap.PositionComp.SetPosition(m_pastePosition);
                previewVoxelMap.Save = false;

                m_previewVoxelMaps.Add(previewVoxelMap);

                IsActive             = visible;
                m_visible            = visible;
                m_shouldMarkForClose = true;
            }
        }
        private bool HandleCutInput()
        {
            if (MyInput.Static.IsNewKeyPressed(MyKeys.X) && MyInput.Static.IsAnyCtrlKeyPressed())
            {
                MyEntity entity = MyCubeGrid.GetTargetEntity();
                if (entity == null)
                {
                    return(false);
                }

                bool handled = false;

                if (entity is MyCubeGrid && m_clipboard.IsActive == false)
                {
                    MyGuiAudio.PlaySound(MyGuiSounds.HudClick);

                    bool cutGroup  = !MyInput.Static.IsAnyShiftKeyPressed();
                    bool cutOverLg = MyInput.Static.IsAnyAltKeyPressed();

                    MyEntities.EnableEntityBoundingBoxDraw(entity, true);

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

                        MyEntities.EnableEntityBoundingBoxDraw(entity, false);
                    }));

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

                    handled = true;
                }
                else if (entity is MyFloatingObject && !m_floatingObjectClipboard.IsActive)
                {
                    MyEntities.EnableEntityBoundingBoxDraw(entity, true);

                    MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                                               buttonType: MyMessageBoxButtonsType.YES_NO,
                                               messageText: MyTexts.Get(MyCommonTexts.MessageBoxTextAreYouSureToMoveGridToClipboard),
                                               messageCaption: MyTexts.Get(MyCommonTexts.MessageBoxCaptionPleaseConfirm),
                                               callback: (v) =>
                    {
                        if (v == MyGuiScreenMessageBox.ResultEnum.YES)
                        {
                            OnCutFloatingObjectConfirm(entity as MyFloatingObject);
                            handled = true;
                        }

                        MyEntities.EnableEntityBoundingBoxDraw(entity, false);
                    }));

                    handled = true;
                }

                if (handled)
                {
                    return(true);
                }
            }

            return(false);
        }