コード例 #1
0
        protected override void Closing()
        {
            if (UseObjectsComponent.DetectorPhysics != null)
            {
                UseObjectsComponent.ClearPhysics();
            }

            if (MyFakes.ENABLE_SUBBLOCKS)
            {
                foreach (var pair in SubBlocks)
                {
                    MySlimBlock subBlock = pair.Value;
                    if (subBlock.FatBlock != null)
                    {
                        subBlock.FatBlock.OwnerBlock   = null;
                        subBlock.FatBlock.SubBlockName = null;
                        subBlock.FatBlock.OnClosing   -= SubBlock_OnClosing;
                    }
                }
            }
            SetDamageEffect(false);
            //Moved to RemoveBlockInternal
            //CubeGrid.ChangeOwner(this, OwnerId, 0);

            SlimBlock.ComponentStack.IsFunctionalChanged -= ComponentStack_IsFunctionalChanged;

            base.Closing();
        }
コード例 #2
0
 public override void UpdateVisual()
 {
     base.UpdateVisual();
     UpdateEmissivity();
     m_buttonsUseObjects.Clear();
     UseObjectsComponent.GetInteractiveObjects <MyUseObjectPanelButton>(m_buttonsUseObjects);
 }
コード例 #3
0
 public IMyUseObject GetInteractiveObject(uint shapeKey)
 {
     if (!IsFunctional)
     {
         return(null);
     }
     return(UseObjectsComponent.GetInteractiveObject(shapeKey));
 }
コード例 #4
0
        public override void Init(MyObjectBuilder_CubeBlock builder, MyCubeGrid cubeGrid)
        {
            SyncFlag = true;

            var sinkComp = new MyResourceSinkComponent();

            sinkComp.Init(
                BlockDefinition.ResourceSinkGroup,
                0.0001f,
                () => IsFunctional ? 0.0001f : 0);
            sinkComp.IsPoweredChanged += Receiver_IsPoweredChanged;
            sinkComp.IsPoweredChanged += ComponentStack_IsFunctionalChanged;
            ResourceSink = sinkComp;

            base.Init(builder, cubeGrid);
            m_emissiveNames = new List <string>(BlockDefinition.ButtonCount);
            for (int i = 1; i <= BlockDefinition.ButtonCount; i++)    //button dummies have 1-based index
            {
                m_emissiveNames.Add(string.Format("Emissive{0}", i)); // because of modding
            }
            var ob = builder as MyObjectBuilder_ButtonPanel;

            Toolbar             = new MyToolbar(MyToolbarType.ButtonPanel, Math.Min(BlockDefinition.ButtonCount, MyToolbar.DEF_SLOT_COUNT), (BlockDefinition.ButtonCount / MyToolbar.DEF_SLOT_COUNT) + 1);
            Toolbar.DrawNumbers = false;
            Toolbar.GetSymbol   = (slot) =>
            {
                var ret = new Sandbox.Graphics.GUI.MyGuiControlGrid.ColoredIcon();
                if (Toolbar.SlotToIndex(slot) < BlockDefinition.ButtonCount)
                {
                    ret.Icon = BlockDefinition.ButtonSymbols[Toolbar.SlotToIndex(slot) % BlockDefinition.ButtonSymbols.Length];
                    var color = BlockDefinition.ButtonColors[Toolbar.SlotToIndex(slot) % BlockDefinition.ButtonColors.Length];
                    color.W   = 1;
                    ret.Color = color;
                }
                return(ret);
            };

            Toolbar.Init(ob.Toolbar, this);
            Toolbar.ItemChanged += Toolbar_ItemChanged;
            AnyoneCanUse         = ob.AnyoneCanUse;

            SlimBlock.ComponentStack.IsFunctionalChanged += ComponentStack_IsFunctionalChanged;

            ResourceSink.Update();

            if (ob.CustomButtonNames != null)
            {
                m_customButtonNames = ob.CustomButtonNames;
            }

            NeedsUpdate |= MyEntityUpdateEnum.BEFORE_NEXT_FRAME;

            UseObjectsComponent.GetInteractiveObjects <MyUseObjectPanelButton>(m_buttonsUseObjects);
        }
コード例 #5
0
        private void InitOwnership(MyObjectBuilder_CubeBlock builder)
        {
            bool canHaveOwnership = BlockDefinition.ContainsComputer() || (MyFakes.ENABLE_BATTLE_SYSTEM && MySession.Static.Battle);

            if (UseObjectsComponent != null)
            {
                canHaveOwnership = canHaveOwnership || UseObjectsComponent.GetDetectors("ownership").Count > 0;
            }

            if (canHaveOwnership)
            {
                m_IDModule = new MyIDModule();

                bool resetOwnership = MySession.Static.Settings.ResetOwnership && Sync.IsServer;

                if (resetOwnership)
                {
                    m_IDModule.Owner     = 0;
                    m_IDModule.ShareMode = MyOwnershipShareModeEnum.None;
                }
                else
                {
                    if ((int)builder.ShareMode == -1)
                    {
                        builder.ShareMode = MyOwnershipShareModeEnum.None;
                    }

                    var ownerType = MyEntityIdentifier.GetIdObjectType(builder.Owner);
                    if (builder.Owner != 0 && ownerType != MyEntityIdentifier.ID_OBJECT_TYPE.NPC && ownerType != MyEntityIdentifier.ID_OBJECT_TYPE.SPAWN_GROUP)
                    {
                        System.Diagnostics.Debug.Assert(ownerType == MyEntityIdentifier.ID_OBJECT_TYPE.IDENTITY, "Old save detected, reseting owner to Nobody, please resave.");

                        if (!Sync.Players.HasIdentity(builder.Owner))
                        {
                            builder.Owner = 0; //reset, it was old version
                        }
                    }

                    m_IDModule.Owner     = builder.Owner;
                    m_IDModule.ShareMode = builder.ShareMode;
                }
            }
        }
コード例 #6
0
        public void Init()
        {
            PositionComp.LocalAABB = new BoundingBox(new Vector3(-SlimBlock.CubeGrid.GridSize / 2), new Vector3(SlimBlock.CubeGrid.GridSize / 2));
            Components.Add <MyUseObjectsComponentBase>(new MyUseObjectsComponent());

            Matrix localMatrix;
            string currModel;

            if (BlockDefinition.CubeDefinition != null)
            {
                //Ensure we have always only one distinct orientation use
                SlimBlock.Orientation = MyCubeGridDefinitions.GetTopologyUniqueOrientation(BlockDefinition.CubeDefinition.CubeTopology, Orientation);
            }

            CalcLocalMatrix(out localMatrix, out currModel);

            if (!string.IsNullOrEmpty(currModel))
            {
                Init(null, currModel, null, null, null);

                OnModelChange();
            }

            Render.EnableColorMaskHsv = true;

            // Can't skip
            Render.SkipIfTooSmall = false;

            CheckConnectionAllowed = false;

            WorldMatrix = localMatrix;
            Save        = false;

            UseObjectsComponent.LoadDetectorsFromModel();

            SlimBlock.ComponentStack.IsFunctionalChanged += ComponentStack_IsFunctionalChanged;
        }
コード例 #7
0
        public virtual void UpdateVisual()
        {
            Matrix orientation;
            var    currModel = SlimBlock.CalculateCurrentModel(out orientation);

            if (Model != null && Model.AssetName != currModel || Render.ColorMaskHsv != SlimBlock.ColorMaskHSV || Render.Transparency != SlimBlock.Dithering)
            {
                Render.ColorMaskHsv = SlimBlock.ColorMaskHSV;
                Render.Transparency = SlimBlock.Dithering;

                Vector3D position       = WorldMatrix.Translation;
                MatrixD  newWorldMatrix = orientation * CubeGrid.WorldMatrix;
                newWorldMatrix.Translation = position;

                WorldMatrix = newWorldMatrix;

                RefreshModels(currModel, null);

                Render.RemoveRenderObjects();
                Render.AddRenderObjects();
                UseObjectsComponent.LoadDetectorsFromModel();
                OnModelChange();
            }
        }