void EntityIDInput(ScreenResult result, string resultText)
        {
            if (result == ScreenResult.Ok)
            {
                uint entityID;
                if (uint.TryParse(resultText, out entityID))
                {
                    var entity = MyEntities.GetEntityByIdOrNull(new MyEntityIdentifier(entityID));
                    if (entity != null)
                    {
                        var position = entity.GetPosition() - entity.WorldVolume.Radius * entity.GetForward();
                        MySpectator.SetViewMatrix(Matrix.CreateLookAt(position, entity.GetPosition(), entity.GetUp()));

                        MyEditorGizmo.AddEntityToSelection(entity);
                    }
                    else
                    {
                        MyGuiScreenMessageBox.Show(MyTextsWrapperEnum.EntityIsNotExist, type: MyMessageBoxType.ERROR);
                    }
                }
                else
                {
                    MyGuiScreenMessageBox.Show(MyTextsWrapperEnum.WrongNumberFormat, type: MyMessageBoxType.ERROR);
                }
            }
        }
예제 #2
0
        private void m_listbox_ItemDoubleClick(object sender, MyGuiControlListboxItemEventArgs eventArgs)
        {
            MyEditorGizmo.ClearSelection();
            MyEntity entityToSelect = MyEntities.GetEntityById(new MyEntityIdentifier((uint)eventArgs.Key));

            MyEditorGizmo.AddEntityToSelection(entityToSelect);
        }
        private void OnOldBodClose(MyEntity entity)
        {
            var newBot = MyEntities.CreateFromObjectBuilderAndAdd(null, m_newBotBuilderToInit, m_newBotWorldMatrixToInit);

            newBot.Activate(m_activatedCheckbox.Checked, false);
            MyEditorGizmo.AddEntityToSelection(newBot);
            CloseAndCallOnOk();
        }
        /// <summary>
        /// Adds entity to scene
        /// </summary>
        /// <param name="entity"></param>
        protected virtual void AddToScene(MyEntity entity)
        {
            //add entity into world if possible to ensure we manipulate with object in scene
            if (!(entity is MyPrefabBase))
            {
                // Quit container edit mode if entity was created in non-edit mode
                if (m_activeContainer == null && MyEditor.Static.IsEditingPrefabContainer())
                {
                    MyEditor.Static.ExitActivePrefabContainer();
                }

                MyEntities.Add(entity);
            }
            else
            {
                // In case undo/redo is performed on prefab, make sure that its parent container is switched to edit mode
                MyPrefabBase prefab = (MyPrefabBase)entity;
                MyEditor.Static.EditPrefabContainer(m_activeContainer);
                MyEditor.Static.GetEditedPrefabContainer().AddPrefab(prefab);
            }

            // adding an entity will make its type selectable
            Type type = null;

            if (entity is MyPrefabBase || entity is MyPrefabContainer)
            {
                type = typeof(MyPrefabBase);
            }
            else if (entity is MyWayPoint)
            {
                type = typeof(MyWayPoint);
            }
            else if (entity is MyVoxelMap)
            {
                type = typeof(MyVoxelMap);
            }
            else if (entity is MyDummyPoint)
            {
                type = typeof(MyDummyPoint);
            }
            else if (entity is MySpawnPoint)
            {
                type = typeof(MySpawnPoint);
            }
            else if (entity is MyInfluenceSphere)
            {
                type = typeof(MyInfluenceSphere);
            }
            if (type != null)
            {
                MyEntities.SetTypeHidden(type, false);
                MyEntities.SetTypeSelectable(type, true);
            }

            MyEditorGizmo.AddEntityToSelection(entity);
        }
예제 #5
0
        void OnPlayerStartFlagChange(MyGuiControlCheckbox sender)
        {
            if (!m_canUpdateValues)
            {
                return;
            }

            // Make sure there's only one start location per sector
            if (m_playerStart.Checked && (DummyPoint.DummyFlags & MyDummyPointFlags.PLAYER_START) == 0)
            {
                foreach (var entity in MyEntities.GetEntities())
                {
                    var dummyPoint = entity as MyDummyPoint;
                    if (dummyPoint != null && (dummyPoint.DummyFlags & MyDummyPointFlags.PLAYER_START) > 0)
                    {
                        MyGuiManager.AddScreen(new MyGuiScreenMessageBox(MyMessageBoxType.ERROR, MyTextsWrapperEnum.EntryPointAlreadyDefined, MyTextsWrapperEnum.MessageBoxCaptionError,
                                                                         MyTextsWrapperEnum.Yes, MyTextsWrapperEnum.Cancel, mbReturn =>
                        {
                            if (mbReturn == MyGuiScreenMessageBoxCallbackEnum.YES)
                            {
                                MyEditorGizmo.ClearSelection();
                                MyEditorGizmo.AddEntityToSelection(dummyPoint);
                                CloseScreen();
                                return;
                            }
                            else
                            {
                                // We want to enable multiple start dummies
                                //m_playerStart.Checked = false;
                            }
                        }));
                    }
                }
            }

            if (m_playerStart.Checked)
            {
                DummyPoint.DummyFlags |= MyDummyPointFlags.PLAYER_START;
            }
            else
            {
                DummyPoint.DummyFlags &= ~MyDummyPointFlags.PLAYER_START;
            }

            if (m_playerStart.Checked)
            {
                DummyPoint.DummyFlags |= MyDummyPointFlags.PLAYER_START;
            }
            else
            {
                DummyPoint.DummyFlags &= ~MyDummyPointFlags.PLAYER_START;
            }

            UpdateValues();
        }
예제 #6
0
        protected override void AddToScene(MyEntity entity)
        {
            base.AddToScene(entity);

            // in case we are adding new prefab container, enter directly into edit mode of this new container
            // but we dont want enter into edit mode when containers are duplicated
            if (entity is MyPrefabContainer)
            {
                MyEditor.Static.EditPrefabContainer((MyPrefabContainer)entity);
                foreach (MyPrefabBase child in (entity as MyPrefabContainer).Children)
                {
                    MyEditorGizmo.AddEntityToSelection(child);
                }
            }
        }
        public virtual void Update()
        {
            FilterAddObjectTree(MyEditorGizmo.SelectedSnapPoint);

            // Get editor state and allowed context action
            var notDragging   = !m_addObjectTreeViewdragDrop.Dragging;
            var editorState   = MyEditor.GetCurrentState();
            var contextHelper = MyGuiContextMenuHelpers.GetEditorContextMenuHelper(editorState);

            // Choose editor state dependent textures
            var cameraText = editorState == MyEditorStateEnum.ATTACHED ? MyTextsWrapperEnum.ToolbarDetachFromCamera : MyTextsWrapperEnum.ToolbarAttachToCamera;
            var enterPrefabContainerText = CheckContextAction(contextHelper, MyGuiContextMenuItemActionType.EXIT_EDITING_MODE) ? MyTextsWrapperEnum.ToolbarExitEditingMode : MyTextsWrapperEnum.ToolbarEnterPrefabContainer;
            var enterVoxelHandText       = editorState == MyEditorStateEnum.VOXEL_HAND_ENABLED ? MyTextsWrapperEnum.ToolbarExitVoxelHand : MyTextsWrapperEnum.ToolbarEnterVoxelHand;
            var showSnapPointsText       = MyEditor.Static.ShowSnapPoints ? MyTextsWrapperEnum.ToolbarHideSnapPoints : MyTextsWrapperEnum.ToolbarShowSnapPoints;
            var linkSnapPointsText       = MyEditor.Static.CanUnlinkSnapPoints(MyEditorGizmo.SelectedSnapPoint) ? MyTextsWrapperEnum.ToolbarUnlinkSnapPoints : MyTextsWrapperEnum.ToolbarLinkSnapPoints;

            // Change look of editor state dependent buttons
            m_attachToCameraButton.SetTextEnum(cameraText);
            m_enterPrefabContainerButton.SetTextEnum(enterPrefabContainerText);
            m_enterVoxelHandButton.SetTextEnum(enterVoxelHandText);
            m_linkSnapPoints.SetTextEnum(linkSnapPointsText);

            // Enable/Disable buttons (context)
            m_addObjectButton.Enabled = notDragging &&
                                        (CheckContextAction(contextHelper, MyGuiContextMenuItemActionType.ADD_OBJECT) ||
                                         CheckContextAction(contextHelper, MyGuiContextMenuItemActionType.EXIT_VOXEL_HAND));
            //m_editObjectsButton.Enabled = notDragging &&
            //   ((CheckContextAction(contextHelper, MyGuiContextMenuItemActionType.EDIT_SELECTED) && MyEditor.Static.CanEditSelected()) ||
            //    CheckContextAction(contextHelper, MyGuiContextMenuItemActionType.EDIT_VOXEL_HAND));
            m_editObjectsButton.Enabled = notDragging &&
                                          (CheckContextAction(contextHelper, MyGuiContextMenuItemActionType.EDIT_SELECTED) && MyEditor.Static.CanEditSelected());
            m_resetRotationButton.Enabled        = notDragging && CheckContextAction(contextHelper, MyGuiContextMenuItemActionType.RESET_ROTATION);
            m_copySelectedButton.Enabled         = notDragging && CheckContextAction(contextHelper, MyGuiContextMenuItemActionType.COPY_SELECTED);
            m_switchGizmoSpaceButton.Enabled     = notDragging && CheckContextAction(contextHelper, MyGuiContextMenuItemActionType.SWITCH_GIZMO_SPACE);
            m_switchGizmoModeButton.Enabled      = notDragging && CheckContextAction(contextHelper, MyGuiContextMenuItemActionType.SWITCH_GIZMO_MODE);
            m_linkSnapPoints.Enabled             = notDragging && MyEditorGizmo.SelectedSnapPoint != null;
            m_toggleSnapPoints.Enabled           = notDragging && CheckContextAction(contextHelper, MyGuiContextMenuItemActionType.TOGGLE_SNAP_POINTS);
            m_selectAllObjectsButton.Enabled     = notDragging && CheckContextAction(contextHelper, MyGuiContextMenuItemActionType.SELECT_ALL_OBJECTS);
            m_exitSelectedButton.Enabled         = notDragging && CheckContextAction(contextHelper, MyGuiContextMenuItemActionType.EXIT_SELECTED);
            m_enterPrefabContainerButton.Enabled = notDragging &&
                                                   (CheckContextAction(contextHelper, MyGuiContextMenuItemActionType.ENTER_PREFAB_CONTAINER) ||
                                                    CheckContextAction(contextHelper, MyGuiContextMenuItemActionType.EXIT_EDITING_MODE));
            m_attachToCameraButton.Enabled = notDragging &&
                                             (CheckContextAction(contextHelper, MyGuiContextMenuItemActionType.ATTACH_TO_CAMERA) ||
                                              CheckContextAction(contextHelper, MyGuiContextMenuItemActionType.DETACH_FROM_CAMERA));
            m_enterVoxelHandButton.Enabled = notDragging &&
                                             (CheckContextAction(contextHelper, MyGuiContextMenuItemActionType.ENTER_VOXEL_HAND) ||
                                              CheckContextAction(contextHelper, MyGuiContextMenuItemActionType.EXIT_VOXEL_HAND));
            m_clearWholeSectorButton.Enabled = notDragging && CheckContextAction(contextHelper, MyGuiContextMenuItemActionType.CLEAR_WHOLE_SECTOR);
            m_loadSectorButton.Enabled       = notDragging && CheckContextAction(contextHelper, MyGuiContextMenuItemActionType.LOAD_SECTOR) && !m_isDemoUser;
            m_saveSectorButton.Enabled       = notDragging && CheckContextAction(contextHelper, MyGuiContextMenuItemActionType.SAVE_SECTOR) && MySession.CanBeSaved(false, MyGuiScreenGamePlay.Static.GetSectorIdentifier(), true);
            MyTextsWrapperEnum?isDemoS = null;

            if (MyClientServer.LoggedPlayer != null && MyClientServer.LoggedPlayer.IsDemoUser())
            {
                isDemoS = MyTextsWrapperEnum.NotAvailableInDemoMode;
            }
            m_saveSectorButton.AccessForbiddenReason = isDemoS;
            m_loadSectorButton.AccessForbiddenReason = isDemoS;
            //m_adjustGridButton.Enabled = notDragging && CheckContextAction(contextHelper, MyGuiContextMenuItemActionType.ADJUST_GRID);
            //m_sunSettingsButton.Enabled = false; // atm. disable, SUN_SETTINGS + FOG_SETTINGS
            m_groupsButton.Enabled         = notDragging;
            m_copyToolButton.Enabled       = notDragging;
            m_optionsButton.Enabled        = notDragging;
            m_selectAndHideButton.Enabled  = notDragging;
            m_editPropertiesButton.Enabled = notDragging && CheckContextAction(contextHelper, MyGuiContextMenuItemActionType.EDIT_PROPERTIES) &&
                                             MyGuiScreenEditorEditProperties.CanEditProperties(MyEditorGizmo.SelectedEntities);
            m_correctSnappedPrefabsButton.Enabled   = notDragging && CheckContextAction(contextHelper, MyGuiContextMenuItemActionType.CORRECT_SNAPPED_PREFABS);
            m_selectDeactivatedEntityButton.Enabled = notDragging;
            m_findEntityButton.Enabled = notDragging;

            if (!CheckContextAction(contextHelper, MyGuiContextMenuItemActionType.ADD_OBJECT) && m_addObjectTreeView.Visible)
            {
                SetAddObjectVisibility(false);
            }
            SetEditVoxelHandVisibility(CheckContextAction(contextHelper, MyGuiContextMenuItemActionType.EDIT_VOXEL_HAND));
            if (m_editVoxelHand.Visible && MyEditorGizmo.IsAnyEntitySelected())
            {
                if (!MyFakes.MWBUILDER)
                {
                    if (!(MyEditorVoxelHand.SelectedVoxelMap != null && MyEditorGizmo.SelectedEntities.Count == 1 && MyEditorGizmo.SelectedEntities[0] == MyEditorVoxelHand.SelectedVoxelMap))
                    {
                        MyEditor.Static.PerformContextMenuAction(MyGuiContextMenuItemActionType.EXIT_SELECTED);

                        if (MyEditorVoxelHand.SelectedVoxelMap != null)
                        {
                            MyEditorGizmo.AddEntityToSelection(MyEditorVoxelHand.SelectedVoxelMap);
                        }
                    }
                }
            }
        }
예제 #8
0
        protected override void OnOkClick(MyGuiControlButton sender)
        {
            CloseScreen();
            var focused = m_groupList.GetFocusedItem();

            if (focused != null)
            {
                var group = focused.Tag as MyMwcObjectBuilder_ObjectGroup;

                IEnumerable <MyMwcObjectBuilder_PrefabBase> prefabs     = group.GetPrefabBuilders(m_entities);
                IEnumerable <MyMwcObjectBuilder_Base>       rootObjects = group.GetRootBuilders(m_entities);
                var objects3d = rootObjects.OfType <MyMwcObjectBuilder_Object3dBase>();

                if (objects3d.Any())
                {
                    MyEditorGizmo.ClearSelection();

                    var basePos  = MyCamera.Position + Matrix.Invert(MyCamera.ViewMatrix).Forward * 100;
                    var firstPos = objects3d.First().PositionAndOrientation.Position;
                    var offset   = basePos - firstPos;

                    foreach (var b in objects3d)
                    {
                        b.PositionAndOrientation.Position += offset;
                        b.ClearEntityId();
                        MyEntity entity = MyEntities.CreateFromObjectBuilderAndAdd(null, b, b.PositionAndOrientation.GetMatrix());
                        MyEditorGizmo.AddEntityToSelection(entity);
                    }
                }

                // Prefabs
                var editedContainer = MyEditor.Static.GetEditedPrefabContainer();
                if (editedContainer == null)
                {
                    MyMwcObjectBuilder_PrefabContainer prefabContainerBuilder = new MyMwcObjectBuilder_PrefabContainer(
                        null, MyMwcObjectBuilder_PrefabContainer_TypesEnum.INSTANCE, new List <MyMwcObjectBuilder_PrefabBase>(), MyClientServer.LoggedPlayer.GetUserId(),
                        MyMwcObjectBuilder_FactionEnum.Euroamerican, new MyMwcObjectBuilder_Inventory(new List <MyMwcObjectBuilder_InventoryItem>(), MyInventory.DEFAULT_MAX_ITEMS));

                    editedContainer = MyEntities.CreateFromObjectBuilderAndAdd(
                        null, prefabContainerBuilder,
                        Matrix.CreateTranslation(MyCamera.Position + Matrix.Invert(MyCamera.ViewMatrix).Forward * 100)) as MyPrefabContainer;

                    MyEditor.Static.EditPrefabContainer(editedContainer);
                }

                if (editedContainer != null)
                {
                    MyEditorGizmo.ClearSelection();
                    List <MyEntity> addedEntities = new List <MyEntity>();

                    foreach (var prefabBuilder in prefabs)
                    {
                        prefabBuilder.EntityId = null;
                        var entity = editedContainer.CreateAndAddPrefab(null, prefabBuilder);
                        addedEntities.Add(entity);
                    }

                    // Select newly added objects
                    foreach (var entity in addedEntities)
                    {
                        MyEditorGizmo.AddEntityToSelection(entity);
                    }
                }
            }
        }