예제 #1
0
        public static MyEntity SpawnEntity(Action <MyEntity> onEntity)
        {
            var dialog = new ValueGetScreenWithCaption("Spawn new Entity", "", delegate(string text)
            {
                var entity         = new MyEntity();
                entity.WorldMatrix = MyAPIGateway.Session.Camera.WorldMatrix;
                entity.PositionComp.SetPosition(MyAPIGateway.Session.Camera.Position);
                entity.EntityId = MyEntityIdentifier.AllocateId();
                entity.Components.Remove <MyPhysicsComponentBase>();
                entity.Components.Remove <MyRenderComponentBase>();
                entity.DisplayName = "EmptyEntity";
                MyEntities.Add(entity);
                entity.Name = text;
                MyEntities.SetEntityName(entity, true);

                if (onEntity != null)
                {
                    onEntity(entity);
                }

                return(true);
            });

            MyGuiSandbox.AddScreen(dialog);

            return(null);
        }
예제 #2
0
        public bool SetTriggerSize()
        {
            if (m_selectedTrigger == null)
            {
                return(false);
            }

            var dialog = new ValueGetScreenWithCaption("Set trigger size dialog", m_selectedTrigger.Radius.ToString(CultureInfo.InvariantCulture), delegate(string text)
            {
                float value;
                if (!float.TryParse(text, out value))
                {
                    return(false);
                }

                m_selectedTrigger.Radius = value;

                return(true);
            });

            MyGuiSandbox.AddScreen(dialog);


            return(true);
        }
예제 #3
0
        private void NameDialog(MyEntity entity)
        {
            var dialog = new ValueGetScreenWithCaption("Name a Grid dialog: " + entity.DisplayName, entity.Name ?? entity.DisplayName + " has no name.", delegate(string text)
            {
                MyEntity foundEntity;
                if (MyEntities.TryGetEntityByName(text, out foundEntity))
                {
                    MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                                               buttonType: MyMessageBoxButtonsType.OK,
                                               messageText: new StringBuilder("Entity with same name already exits, please enter different name."),
                                               messageCaption: new StringBuilder("Naming error")));
                }
                else
                {
                    entity.Name = text;
                    MyEntities.SetEntityName(entity, true);

                    return(true);
                }

                return(false);
            });

            MyGuiSandbox.AddScreen(dialog);
        }
예제 #4
0
        private bool RenameTrigger()
        {
            if (m_selectedTrigger == null)
            {
                return(false);
            }

            var dialog = new ValueGetScreenWithCaption("Rename Dialog", m_selectedTrigger.Name, text =>
            {
                m_selectedTrigger.Name = text;
                return(true);
            });

            MyGuiSandbox.AddScreen(dialog);

            return(true);
        }
예제 #5
0
        private bool TryPutTriggerOnEntity()
        {
            var worldMatrix = MyAPIGateway.Session.Camera.WorldMatrix;
            List <MyPhysics.HitInfo> hits = new List <MyPhysics.HitInfo>();

            MyPhysics.CastRay(worldMatrix.Translation, worldMatrix.Translation + worldMatrix.Forward * 30, hits, 15);

            foreach (var hitInfo in hits)
            {
                var body = (MyPhysicsBody)hitInfo.HkHitInfo.Body.UserObject;
                if (body.Entity is MyCubeGrid)
                {
                    var rayEntity = (MyEntity)body.Entity;
                    var dialog    = new ValueGetScreenWithCaption("Entity Spawn on: " + rayEntity.DisplayName, "", delegate(string text)
                    {
                        if (m_selectedTrigger != null)
                        {
                            m_selectedTrigger.CustomDebugColor = Color.Red;
                        }

                        m_selectedTrigger = new MyAreaTriggerComponent(text);
                        if (!rayEntity.Components.Contains(typeof(MyTriggerAggregate)))
                        {
                            rayEntity.Components.Add(typeof(MyTriggerAggregate), new MyTriggerAggregate());
                        }
                        rayEntity.Components.Get <MyTriggerAggregate>().AddComponent(m_selectedTrigger);
                        m_selectedTrigger.Center = MyAPIGateway.Session.Camera.Position;
                        m_selectedTrigger.Radius = 2;

                        m_selectedTrigger.CustomDebugColor = Color.Yellow;

                        return(true);
                    });
                    MyGuiSandbox.AddScreen(dialog);
                    return(true);
                }
            }
            return(false);
        }
예제 #6
0
        public bool SpawnTrigger()
        {
            var dialog = new ValueGetScreenWithCaption("Spawn new Trigger", "", delegate(string text)
            {
                var trigger    = new MyAreaTriggerComponent(text);
                var entity     = new MyEntity();
                trigger.Radius = 2;
                trigger.Center = MyAPIGateway.Session.Camera.Position;
                entity.PositionComp.SetPosition(MyAPIGateway.Session.Camera.Position);
                entity.PositionComp.LocalVolume = new BoundingSphere(Vector3.Zero, 0.5f);
                entity.EntityId = MyEntityIdentifier.AllocateId();
                entity.Components.Remove <MyPhysicsComponentBase>();
                entity.Components.Remove <MyRenderComponentBase>();
                entity.DisplayName = "TriggerHolder";
                MyEntities.Add(entity);

                if (!entity.Components.Contains(typeof(MyTriggerAggregate)))
                {
                    entity.Components.Add(typeof(MyTriggerAggregate), new MyTriggerAggregate());
                }
                entity.Components.Get <MyTriggerAggregate>().AddComponent(trigger);


                if (m_selectedTrigger != null)
                {
                    m_selectedTrigger.CustomDebugColor = Color.Red;
                }
                ;

                m_selectedTrigger = trigger;
                m_selectedTrigger.CustomDebugColor = Color.Yellow;
                return(true);
            });

            MyGuiSandbox.AddScreen(dialog);

            return(true);
        }
        public bool TryNamingAnBlockOrFloatingObject()
        {
            var worldMatrix = MyAPIGateway.Session.Camera.WorldMatrix; // most accurate for player view.
            var position = worldMatrix.Translation + worldMatrix.Forward * 0.5f;
            var ray = new RayD(position, worldMatrix.Forward * 1000);

            var boundingSphere = new BoundingSphereD(worldMatrix.Translation, 30);
            var entites = MyEntities.GetEntitiesInSphere(ref boundingSphere);

            List<MyPhysics.HitInfo> hits = new List<MyPhysics.HitInfo>();
            MyPhysics.CastRay(worldMatrix.Translation, worldMatrix.Translation + worldMatrix.Forward * 5, hits, 15);

            foreach (var hitInfo in hits)
            {
                var body = (MyPhysicsBody)hitInfo.HkHitInfo.Body.UserObject;
                if (body.Entity is MyFloatingObject)
                {
                    var rayEntity = (MyEntity) body.Entity;
                    NameDialog(rayEntity);
                    return true;
                }
            }

            foreach (var entity in entites)
            {
                var cubeGrid = entity as MyCubeGrid;

                if (cubeGrid != null && ray.Intersects(entity.PositionComp.WorldAABB).HasValue)
                {
                    var hit = cubeGrid.RayCastBlocks(worldMatrix.Translation, worldMatrix.Translation + worldMatrix.Forward * 100);
                    if (hit.HasValue)
                    {
                        var block = cubeGrid.GetCubeBlock(hit.Value);
                        
                        if(block.FatBlock != null)
                        {
                            var dialog = new ValueGetScreenWithCaption("Name block dialog: " + block.FatBlock.DefinitionDisplayNameText, block.FatBlock.Name ?? block.FatBlock.DefinitionDisplayNameText + " has no name.", delegate(string text)
                            {
                                MyEntity foundEntity;
                                if (MyEntities.TryGetEntityByName(text, out foundEntity))
                                {
                                    MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                                        buttonType: MyMessageBoxButtonsType.OK,
                                        messageText: new StringBuilder("Entity with same name already exits, please enter different name."),
                                        messageCaption: new StringBuilder("Naming error")));
                                }
                                else
                                {
                                    block.FatBlock.Name = text;
                                    MyEntities.SetEntityName(block.FatBlock, true);

                                    return true;
                                }

                                return false;
                            }); 
                            MyGuiSandbox.AddScreen(dialog);
                            entites.Clear();
                            return true;
                        }
                    }
                }
            }

            entites.Clear();
            return false;
        }
        private void AttachTriggerOnClick(MyGuiControlButton myGuiControlButton)
        {
            if(m_transformSys.ControlledEntity == null) return;

            var selectedEntity = m_transformSys.ControlledEntity;
            var dialog = new ValueGetScreenWithCaption("Entity Spawn on: " + m_transformSys.ControlledEntity.DisplayName,
                "", 
                delegate(string text)
            {
                var areaTrigger = new MyAreaTriggerComponent(text);
                m_triggerManipulator.SelectedTrigger = areaTrigger;

                if (!selectedEntity.Components.Contains(typeof(MyTriggerAggregate)))
                {
                    // Add agregate if its missing
                    selectedEntity.Components.Add(typeof(MyTriggerAggregate), new MyTriggerAggregate());
                }
                // add trigger it self
                selectedEntity.Components.Get<MyTriggerAggregate>().AddComponent(m_triggerManipulator.SelectedTrigger);
                // Init trigger dimensions
                areaTrigger.Center = MyAPIGateway.Session.Camera.Position;
                areaTrigger.Radius = 2;
                // Selected color
                areaTrigger.CustomDebugColor = Color.Yellow;

                return true;
            });
            MyGuiSandbox.AddScreen(dialog);
        }
        private bool TryPutTriggerOnEntity()
        {
            var worldMatrix = MyAPIGateway.Session.Camera.WorldMatrix;
            List<MyPhysics.HitInfo> hits = new List<MyPhysics.HitInfo>();
            MyPhysics.CastRay(worldMatrix.Translation, worldMatrix.Translation + worldMatrix.Forward * 30, hits, 15);

            foreach (var hitInfo in hits)
            {
                var body = (MyPhysicsBody)hitInfo.HkHitInfo.Body.UserObject;
                if (body.Entity is MyCubeGrid)
                {
                    var rayEntity = (MyEntity)body.Entity;
                    var dialog = new ValueGetScreenWithCaption("Entity Spawn on: " + rayEntity.DisplayName, "", delegate(string text)
                    {
                        if (m_selectedTrigger != null)
                            m_selectedTrigger.CustomDebugColor = Color.Red;

                        m_selectedTrigger = new MyAreaTriggerComponent(text);
                        if (!rayEntity.Components.Contains(typeof(MyTriggerAggregate)))
                            rayEntity.Components.Add(typeof(MyTriggerAggregate), new MyTriggerAggregate());
                        rayEntity.Components.Get<MyTriggerAggregate>().AddComponent(m_selectedTrigger);
                        m_selectedTrigger.Center = MyAPIGateway.Session.Camera.Position;
                        m_selectedTrigger.Radius = 2;

                        m_selectedTrigger.CustomDebugColor = Color.Yellow;

                        return true;
                    });
                    MyGuiSandbox.AddScreen(dialog);
                    return true;
                }
            }
            return false;
        }
        public static MyEntity SpawnEntity(Action<MyEntity> onEntity)
        {
            var dialog = new ValueGetScreenWithCaption("Spawn new Entity", "", delegate(string text)
            {
                var entity = new MyEntity();
                entity.WorldMatrix = MyAPIGateway.Session.Camera.WorldMatrix;
                entity.PositionComp.SetPosition(MyAPIGateway.Session.Camera.Position);
                entity.EntityId = MyEntityIdentifier.AllocateId();
                entity.Components.Remove<MyPhysicsComponentBase>();
                entity.Components.Remove<MyRenderComponentBase>();
                entity.DisplayName = "EmptyEntity";
                MyEntities.Add(entity);
                entity.Name = text;
                MyEntities.SetEntityName(entity, true);

                if (onEntity != null)
                    onEntity(entity);

                return true;
            });
            MyGuiSandbox.AddScreen(dialog);

            return null;
        }
        public bool SpawnTrigger()
        {
            var dialog = new ValueGetScreenWithCaption("Spawn new Trigger", "", delegate(string text)
            {
                var trigger = new MyAreaTriggerComponent(text);
                var entity = new MyEntity();
                trigger.Radius = 2;
                trigger.Center = MyAPIGateway.Session.Camera.Position;
                entity.PositionComp.SetPosition(MyAPIGateway.Session.Camera.Position);
                entity.PositionComp.LocalVolume = new BoundingSphere(Vector3.Zero, 0.5f);
                entity.EntityId = MyEntityIdentifier.AllocateId();
                entity.Components.Remove<MyPhysicsComponentBase>();
                entity.Components.Remove<MyRenderComponentBase>();
                entity.DisplayName = "TriggerHolder";
                MyEntities.Add(entity);

                if (!entity.Components.Contains(typeof(MyTriggerAggregate)))
                    entity.Components.Add(typeof(MyTriggerAggregate), new MyTriggerAggregate());
                entity.Components.Get<MyTriggerAggregate>().AddComponent(trigger);


                if(m_selectedTrigger != null)
                    m_selectedTrigger.CustomDebugColor = Color.Red;;

                m_selectedTrigger = trigger;
                m_selectedTrigger.CustomDebugColor = Color.Yellow;
                return true;
            });
            MyGuiSandbox.AddScreen(dialog);

            return true;
        }
        public bool SetTriggerSize()
        {
            if(m_selectedTrigger == null)
                return false;

            var dialog = new ValueGetScreenWithCaption("Set trigger size dialog", m_selectedTrigger.Radius.ToString(CultureInfo.InvariantCulture), delegate(string text)
            {
                float value;
                if(!float.TryParse(text, out value))
                    return false;

                m_selectedTrigger.Radius = value;

                return true;
            });
            MyGuiSandbox.AddScreen(dialog);


            return true;
        }
        private bool RenameTrigger()
        {
            if(m_selectedTrigger == null)
                return false;

            var dialog = new ValueGetScreenWithCaption("Rename Dialog", m_selectedTrigger.Name, text =>
            {
                m_selectedTrigger.Name = text;
                return true;
            });
            MyGuiSandbox.AddScreen(dialog);

            return true;
        }
        private void SetSizeOnClick(MyGuiControlButton button)
        {
            if (m_triggerManipulator.SelectedTrigger == null) return;

            var areaTrigger = (MyAreaTriggerComponent) m_triggerManipulator.SelectedTrigger;
            var dialog = new ValueGetScreenWithCaption("Set trigger size dialog",
                areaTrigger.Radius.ToString(CultureInfo.InvariantCulture),
                delegate(string text)
                {
                    float value;
                    if (!float.TryParse(text, out value))
                        return false;

                    areaTrigger.Radius = value;

                    return true;
                });
            MyGuiSandbox.AddScreen(dialog);
        }
        private void NameDialog(MyEntity entity)
        {
            var dialog = new ValueGetScreenWithCaption("Name a Grid dialog: " + entity.DisplayName, entity.Name ?? entity.DisplayName + " has no name.", delegate(string text)
            {
                MyEntity foundEntity;
                if (MyEntities.TryGetEntityByName(text, out foundEntity))
                {
                    MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                        buttonType: MyMessageBoxButtonsType.OK,
                        messageText: new StringBuilder("Entity with same name already exits, please enter different name."),
                        messageCaption: new StringBuilder("Naming error")));
                }
                else
                {
                    entity.Name = text;
                    MyEntities.SetEntityName(entity, true);

                    return true;
                }

                return false;
            });
            MyGuiSandbox.AddScreen(dialog);
        }
예제 #16
0
        public bool TryNamingAnBlockOrFloatingObject()
        {
            var worldMatrix = MyAPIGateway.Session.Camera.WorldMatrix; // most accurate for player view.
            var position    = worldMatrix.Translation + worldMatrix.Forward * 0.5f;
            var ray         = new RayD(position, worldMatrix.Forward * 1000);

            var boundingSphere = new BoundingSphereD(worldMatrix.Translation, 30);
            var entites        = MyEntities.GetEntitiesInSphere(ref boundingSphere);

            List <MyPhysics.HitInfo> hits = new List <MyPhysics.HitInfo>();

            MyPhysics.CastRay(worldMatrix.Translation, worldMatrix.Translation + worldMatrix.Forward * 5, hits, 15);

            foreach (var hitInfo in hits)
            {
                var body = (MyPhysicsBody)hitInfo.HkHitInfo.Body.UserObject;
                if (body.Entity is MyFloatingObject)
                {
                    var rayEntity = (MyEntity)body.Entity;
                    NameDialog(rayEntity);
                    return(true);
                }
            }

            foreach (var entity in entites)
            {
                var cubeGrid = entity as MyCubeGrid;

                if (cubeGrid != null && ray.Intersects(entity.PositionComp.WorldAABB).HasValue)
                {
                    var hit = cubeGrid.RayCastBlocks(worldMatrix.Translation, worldMatrix.Translation + worldMatrix.Forward * 100);
                    if (hit.HasValue)
                    {
                        var block = cubeGrid.GetCubeBlock(hit.Value);

                        if (block.FatBlock != null)
                        {
                            var dialog = new ValueGetScreenWithCaption("Name block dialog: " + block.FatBlock.DefinitionDisplayNameText, block.FatBlock.Name ?? block.FatBlock.DefinitionDisplayNameText + " has no name.", delegate(string text)
                            {
                                MyEntity foundEntity;
                                if (MyEntities.TryGetEntityByName(text, out foundEntity))
                                {
                                    MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                                                               buttonType: MyMessageBoxButtonsType.OK,
                                                               messageText: new StringBuilder("Entity with same name already exits, please enter different name."),
                                                               messageCaption: new StringBuilder("Naming error")));
                                }
                                else
                                {
                                    block.FatBlock.Name = text;
                                    MyEntities.SetEntityName(block.FatBlock, true);

                                    return(true);
                                }

                                return(false);
                            });
                            MyGuiSandbox.AddScreen(dialog);
                            entites.Clear();
                            return(true);
                        }
                    }
                }
            }

            entites.Clear();
            return(false);
        }
        private void RenameSelectedEntityOnClick(MyGuiControlButton myGuiControlButton)
        {
            if (m_transformSys.ControlledEntity == null) return;

            // Disable picking
            m_disablePicking = true;
            m_transformSys.DisablePicking = true;

            // Rename dialog
            var selectedEntity = m_transformSys.ControlledEntity;
            var dialog = new ValueGetScreenWithCaption("Entity Rename: " + m_transformSys.ControlledEntity.DisplayNameText,
                "",
                delegate(string text)
                {
                    MyEntity e;
                    if(MyEntities.TryGetEntityByName(text, out e))
                        return false;

                    selectedEntity.Name = text;
                    MyEntities.SetEntityName(selectedEntity, true);

                    return true;
                });

            // Enable picking
            dialog.Closed += source => { m_disablePicking = false; m_transformSys.DisablePicking = false; };

            MyGuiSandbox.AddScreen(dialog);
        }