Exemplo n.º 1
0
        public void Register(MyCameraBlock camera)
        {
            MyDebug.AssertDebug(camera != null);
            MyDebug.AssertDebug(!m_cameras.Contains(camera));

            m_cameras.Add(camera);
        }
Exemplo n.º 2
0
        internal static MyEntity SpawnCamera(string name, out MyCameraBlock camera)
        {
            try
            {
                if (string.IsNullOrEmpty(name))
                {
                    camera = null;
                    return(null);
                }
                PrefabCamera.SubtypeName = name;
                PrefabBuilder.CubeBlocks.Clear(); // need no leftovers from previous spawns
                PrefabBuilder.CubeBlocks.Add(PrefabCamera);
                MyEntities.RemapObjectBuilder(PrefabBuilder);
                var ent = MyEntities.CreateFromObjectBuilder(PrefabBuilder, false);
                ent.Render.CastShadows = false;
                ent.Render.Visible     = false;
                ent.IsPreview          = true;
                ent.Save             = false;
                ent.SyncFlag         = false;
                ent.NeedsWorldMatrix = false;
                ent.Flags           |= EntityFlags.IsNotGamePrunningStructureObject;
                ent.Render.RemoveRenderObjects();
                MyEntities.Add(ent, false);
                var cameraSlim = ((IMyCubeGrid)ent).GetCubeBlock(Vector3I.Zero);
                var gId        = MyResourceDistributorComponent.ElectricityId;
                camera = (MyCameraBlock)cameraSlim.FatBlock;
                camera.ResourceSink.SetInputFromDistributor(gId, 0, true);
                camera.RefreshModels(null, null);
                return(ent);
            }
            catch (Exception ex) { Log.Line($"Exception in SpawnPrefab: {ex}"); }

            camera = null;
            return(null);
        }
Exemplo n.º 3
0
        private MyCameraBlock GetPrev(MyCameraBlock current)
        {
            MyDebug.AssertDebug(current != null);
            MyDebug.AssertDebug(m_cameras.Contains(current));

            if (m_relayedCameras.Count == 1)
            {
                return(current);
            }

            int indexOf = m_relayedCameras.IndexOf(current);

            if (indexOf == -1)
            {
                ResetCamera();
                return(null);
            }
            int prevIndex = indexOf - 1;

            if (prevIndex < 0)
            {
                prevIndex = m_relayedCameras.Count - 1;
            }
            return(m_relayedCameras[prevIndex]);
        }
Exemplo n.º 4
0
        public static bool CameraIsInRangeAndPlayerHasAccess(MyCameraBlock camera)
        {
            if (MySession.Static.ControlledEntity != null)
            {
                MyIDModule module;
                if ((camera as IMyComponentOwner <MyIDModule>).GetComponent(out module))
                {
                    if (!(camera.HasPlayerAccess(MySession.Static.LocalPlayerId) || module.Owner == 0))
                    {
                        return(false);
                    }
                }

                if (MySession.Static.ControlledEntity is MyCharacter)
                {
                    return(MyAntennaSystem.Static.CheckConnection(MySession.Static.LocalCharacter, camera.CubeGrid, MySession.Static.LocalHumanPlayer));
                }
                else if (MySession.Static.ControlledEntity is MyShipController)
                {
                    return(MyAntennaSystem.Static.CheckConnection((MySession.Static.ControlledEntity as MyShipController).CubeGrid, camera.CubeGrid, MySession.Static.LocalHumanPlayer));
                }
            }

            return(false);
        }
Exemplo n.º 5
0
        public void SetAsCurrent(MyCameraBlock newCamera)
        {
            MyDebug.AssertDebug(newCamera != null);

            if (m_currentCamera == newCamera)
            {
                return;
            }

            if (newCamera.BlockDefinition.OverlayTexture != null)
            {
                MyHudCameraOverlay.TextureName = newCamera.BlockDefinition.OverlayTexture;
                MyHudCameraOverlay.Enabled     = true;
            }
            else
            {
                MyHudCameraOverlay.Enabled = false;
            }

            string shipName   = MyAntennaSystem.GetLogicalGroupRepresentative(m_grid).DisplayName ?? "";
            string cameraName = newCamera.DisplayNameText;

            MyHud.CameraInfo.Enable(shipName, cameraName);
            m_currentCamera   = newCamera;
            m_ignoreNextInput = true;

            MySessionComponentVoxelHand.Static.Enabled = false;
            MyCubeBuilder.Static.Deactivate();
        }
        public void SetAsCurrent(MyCameraBlock newCamera)
        {
            MyDebug.AssertDebug(newCamera != null);

            if (m_currentCamera == newCamera)
            {
                return;
            }

            if (newCamera.BlockDefinition.OverlayTexture != null)
            {
                MyHudCameraOverlay.TextureName = newCamera.BlockDefinition.OverlayTexture;
                MyHudCameraOverlay.Enabled     = true;
            }
            else
            {
                MyHudCameraOverlay.Enabled = false;
            }

            //By Gregory: Temporary fix cause Session component for antenna system hasn't been called yet and Static isn't assigned yet at game load(see BeforeStart function).
            string shipName = "";

            if (MyAntennaSystem.Static != null)
            {
                shipName = MyAntennaSystem.Static.GetLogicalGroupRepresentative(m_grid).DisplayName ?? "";
            }
            string cameraName = newCamera.DisplayNameText;

            MyHud.CameraInfo.Enable(shipName, cameraName);
            m_currentCamera   = newCamera;
            m_ignoreNextInput = true;

            MySessionComponentVoxelHand.Static.Enabled = false;
            MyCubeBuilder.Static.Deactivate();
        }
Exemplo n.º 7
0
 private void ResetCurrentCamera()
 {
     if (m_currentCamera != null)
     {
         m_currentCamera.OnExitView();
         m_currentCamera = null;
     }
 }
Exemplo n.º 8
0
        public void Unregister(MyCameraBlock camera)
        {
            MyDebug.AssertDebug(camera != null);
            MyDebug.AssertDebug(m_cameras.Contains(camera));

            if (camera == m_currentCamera)
            {
                ResetCamera();
            }

            m_cameras.Remove(camera);
        }
Exemplo n.º 9
0
        private bool GroupedCamera(MyCameraBlock camera)
        {
            long cameraGroupId;

            if (CameraChannelMappings.TryGetValue(camera, out cameraGroupId))
            {
                ActiveCameraBlock = camera;
                return(true);
            }
            ActiveCameraBlock = null;
            return(false);
        }
Exemplo n.º 10
0
        private MyCameraBlock GetNext(MyCameraBlock current)
        {
            MyDebug.AssertDebug(current != null);
            MyDebug.AssertDebug(m_cameras.Contains(current));

            if (m_relayedCameras.Count == 1)
            {
                return(current);
            }

            int indexOf = m_relayedCameras.IndexOf(current);

            if (indexOf == -1)
            {
                ResetCamera();
                return(null);
            }

            return(m_relayedCameras[(indexOf + 1) % m_relayedCameras.Count]);
        }
Exemplo n.º 11
0
        private void SetCamera(MyCameraBlock newCamera)
        {
            if (newCamera == m_currentCamera)
            {
                return;
            }

            if (m_cameras.Contains(newCamera))
            {
                SetAsCurrent(newCamera);
                newCamera.SetView();
            }
            else
            {
                MyHudCameraOverlay.Enabled = false;
                MyHud.CameraInfo.Disable();
                ResetCurrentCamera();
                newCamera.RequestSetView();
            }
        }
Exemplo n.º 12
0
 public virtual void UnregisterFromSystems(MyCubeBlock block)
 {
     if (block.GetType() != typeof(MyCubeBlock))
     {
         if (this.ResourceDistributor != null)
         {
             MyResourceSourceComponent source = block.Components.Get <MyResourceSourceComponent>();
             if (source != null)
             {
                 this.ResourceDistributor.RemoveSource(source);
             }
             MyResourceSinkComponent sink = block.Components.Get <MyResourceSinkComponent>();
             if (sink != null)
             {
                 this.ResourceDistributor.RemoveSink(sink, true, false);
             }
             IMyRechargeSocketOwner owner = block as IMyRechargeSocketOwner;
             if (owner != null)
             {
                 owner.RechargeSocket.ResourceDistributor = null;
             }
         }
         if (this.WeaponSystem != null)
         {
             IMyGunObject <MyDeviceBase> gun = block as IMyGunObject <MyDeviceBase>;
             if (gun != null)
             {
                 this.WeaponSystem.Unregister(gun);
             }
         }
         if (this.TerminalSystem != null)
         {
             MyTerminalBlock block5 = block as MyTerminalBlock;
             if (block5 != null)
             {
                 this.TerminalSystem.Remove(block5);
             }
         }
         if (block.HasInventory)
         {
             this.ConveyorSystem.Remove(block);
         }
         IMyConveyorEndpointBlock block2 = block as IMyConveyorEndpointBlock;
         if (block2 != null)
         {
             this.ConveyorSystem.RemoveConveyorBlock(block2);
         }
         IMyConveyorSegmentBlock segmentBlock = block as IMyConveyorSegmentBlock;
         if (segmentBlock != null)
         {
             this.ConveyorSystem.RemoveSegmentBlock(segmentBlock);
         }
         MyReflectorLight reflector = block as MyReflectorLight;
         if (reflector != null)
         {
             this.ReflectorLightSystem.Unregister(reflector);
         }
         MyDataBroadcaster broadcaster = block.Components.Get <MyDataBroadcaster>();
         if (broadcaster != null)
         {
             this.RadioSystem.Unregister(broadcaster);
         }
         MyDataReceiver reciever = block.Components.Get <MyDataReceiver>();
         if (reciever != null)
         {
             this.RadioSystem.Unregister(reciever);
         }
         if (MyFakes.ENABLE_WHEEL_CONTROLS_IN_COCKPIT)
         {
             MyMotorSuspension motor = block as MyMotorSuspension;
             if (motor != null)
             {
                 this.WheelSystem.Unregister(motor);
             }
         }
         IMyLandingGear gear = block as IMyLandingGear;
         if (gear != null)
         {
             this.LandingSystem.Unregister(gear);
         }
         MyGyro gyro = block as MyGyro;
         if (gyro != null)
         {
             this.GyroSystem.Unregister(gyro);
         }
         MyCameraBlock camera = block as MyCameraBlock;
         if (camera != null)
         {
             this.CameraSystem.Unregister(camera);
         }
     }
     block.OnUnregisteredFromGridSystems();
 }
Exemplo n.º 13
0
 public virtual void RegisterInSystems(MyCubeBlock block)
 {
     if (block.GetType() != typeof(MyCubeBlock))
     {
         MyCubeBlock block1;
         if (this.ResourceDistributor != null)
         {
             MyResourceSourceComponent source = block.Components.Get <MyResourceSourceComponent>();
             if (source != null)
             {
                 this.ResourceDistributor.AddSource(source);
             }
             MyResourceSinkComponent sink = block.Components.Get <MyResourceSinkComponent>();
             if (!(block is MyThrust) && (sink != null))
             {
                 this.ResourceDistributor.AddSink(sink);
             }
             IMyRechargeSocketOwner owner = block as IMyRechargeSocketOwner;
             if (owner != null)
             {
                 owner.RechargeSocket.ResourceDistributor = this.ResourceDistributor;
             }
         }
         if (this.WeaponSystem != null)
         {
             IMyGunObject <MyDeviceBase> gun = block as IMyGunObject <MyDeviceBase>;
             if (gun != null)
             {
                 this.WeaponSystem.Register(gun);
             }
         }
         if (this.TerminalSystem != null)
         {
             MyTerminalBlock block6 = block as MyTerminalBlock;
             if (block6 != null)
             {
                 this.TerminalSystem.Add(block6);
             }
         }
         if ((block == null) || !block.HasInventory)
         {
             block1 = null;
         }
         else
         {
             block1 = block;
         }
         MyCubeBlock block2 = block1;
         if (block2 != null)
         {
             this.ConveyorSystem.Add(block2);
         }
         IMyConveyorEndpointBlock endpointBlock = block as IMyConveyorEndpointBlock;
         if (endpointBlock != null)
         {
             endpointBlock.InitializeConveyorEndpoint();
             this.ConveyorSystem.AddConveyorBlock(endpointBlock);
         }
         IMyConveyorSegmentBlock segmentBlock = block as IMyConveyorSegmentBlock;
         if (segmentBlock != null)
         {
             segmentBlock.InitializeConveyorSegment();
             this.ConveyorSystem.AddSegmentBlock(segmentBlock);
         }
         MyReflectorLight reflector = block as MyReflectorLight;
         if (reflector != null)
         {
             this.ReflectorLightSystem.Register(reflector);
         }
         if (block.Components.Contains(typeof(MyDataBroadcaster)))
         {
             MyDataBroadcaster broadcaster = block.Components.Get <MyDataBroadcaster>();
             this.RadioSystem.Register(broadcaster);
         }
         if (block.Components.Contains(typeof(MyDataReceiver)))
         {
             MyDataReceiver reciever = block.Components.Get <MyDataReceiver>();
             this.RadioSystem.Register(reciever);
         }
         if (MyFakes.ENABLE_WHEEL_CONTROLS_IN_COCKPIT)
         {
             MyMotorSuspension motor = block as MyMotorSuspension;
             if (motor != null)
             {
                 this.WheelSystem.Register(motor);
             }
         }
         IMyLandingGear gear = block as IMyLandingGear;
         if (gear != null)
         {
             this.LandingSystem.Register(gear);
         }
         MyGyro gyro = block as MyGyro;
         if (gyro != null)
         {
             this.GyroSystem.Register(gyro);
         }
         MyCameraBlock camera = block as MyCameraBlock;
         if (camera != null)
         {
             this.CameraSystem.Register(camera);
         }
     }
     block.OnRegisteredToGridSystems();
 }