public void TransferAllBlocksTo(long newOwnerIdentityId)
        {
            MyAPIGateway.Entities.GetEntities(m_entitiesCache, (x) => x is IMyCubeGrid);
            foreach (var ent in m_entitiesCache)
            {
                var grid = ent as MyCubeGrid;
                foreach (var block in grid.GetFatBlocks <MyTerminalBlock>())
                {
                    if (block.IDModule != null && block.OwnerId == IdentityId)
                    {
                        m_requests.Add(new MySyncGrid.MySingleOwnershipRequest()
                        {
                            BlockId = block.EntityId,
                            Owner   = newOwnerIdentityId
                        });
                    }
                }
            }
            m_entitiesCache.Clear();

            if (m_requests.Count > 0)
            {
                MySyncGrid.ChangeOwnersRequest(MyOwnershipShareModeEnum.None, m_requests, IdentityId);
            }
            m_requests.Clear();
        }
Exemple #2
0
        void m_shareModeCombobox_ItemSelected()
        {
            if (!m_canChangeShareMode)
            {
                return;
            }

            m_canChangeShareMode = false;

            bool updateVisuals = false;

            MyOwnershipShareModeEnum shareMode = (MyOwnershipShareModeEnum)m_shareModeCombobox.GetSelectedKey();

            if (m_currentBlocks.Length > 0)
            {
                m_requests.Clear();

                foreach (var block in m_currentBlocks)
                {
                    if (block.IDModule != null)
                    {
                        if (shareMode >= 0 && (block.OwnerId == MySession.LocalPlayerId))
                        {
                            m_requests.Add(new MySyncGrid.MySingleOwnershipRequest()
                            {
                                BlockId = block.EntityId,
                                Owner   = block.IDModule.Owner
                            });
                            updateVisuals = true;
                        }
                    }
                }

                if (m_requests.Count > 0)
                {
                    MySyncGrid.ChangeOwnersRequest(shareMode, m_requests);
                }
            }

            m_canChangeShareMode = true;

            if (updateVisuals)
            {
                block_PropertiesChanged(null);
            }
        }
Exemple #3
0
        void m_transferToCombobox_ItemSelected()
        {
            if (m_transferToCombobox.GetSelectedIndex() == -1)
            {
                return;
            }

            if (m_askForConfirmation)
            {
                long ownerKey   = m_transferToCombobox.GetSelectedKey();
                int  ownerIndex = m_transferToCombobox.GetSelectedIndex();
                var  ownerName  = m_transferToCombobox.GetItemByIndex(ownerIndex).Value;

                var messageBox = MyGuiSandbox.CreateMessageBox(
                    buttonType : MyMessageBoxButtonsType.YES_NO,
                    messageCaption : MyTexts.Get(MySpaceTexts.MessageBoxCaptionPleaseConfirm),
                    messageText : new StringBuilder().AppendFormat(MyTexts.GetString(MySpaceTexts.MessageBoxTextChangeOwner), ownerName.ToString()),
                    focusedResult : MyGuiScreenMessageBox.ResultEnum.NO,
                    callback : delegate(MyGuiScreenMessageBox.ResultEnum retval)
                {
                    if (retval == MyGuiScreenMessageBox.ResultEnum.YES)
                    {
                        if (m_currentBlocks.Length > 0)
                        {
                            m_requests.Clear();

                            foreach (var block in m_currentBlocks)
                            {
                                if (block.IDModule != null)
                                {
                                    if (block.OwnerId == 0 || block.OwnerId == MySession.LocalPlayerId)
                                    {
                                        m_requests.Add(new MySyncGrid.MySingleOwnershipRequest()
                                        {
                                            BlockId = block.EntityId,
                                            Owner   = ownerKey
                                        });
                                    }
                                }
                            }

                            if (m_requests.Count > 0)
                            {
                                MySyncGrid.ChangeOwnersRequest(MyOwnershipShareModeEnum.None, m_requests);
                            }
                        }

                        RecreateOwnershipControls();
                        UpdateOwnerGui();
                    }
                    else
                    {
                        m_askForConfirmation = false;
                        m_transferToCombobox.SelectItemByIndex(-1);
                        m_askForConfirmation = true;
                    }
                });
                messageBox.CanHideOthers = false;
                MyGuiSandbox.AddScreen(messageBox);
            }
            else
            {
                UpdateOwnerGui();
            }
        }
Exemple #4
0
        void m_transferToCombobox_ItemSelected()
        {
            if (m_transferToCombobox.GetSelectedIndex() == -1)
            {
                return;
            }

            if (m_askForConfirmation)
            {
                long ownerKey   = m_transferToCombobox.GetSelectedKey();
                int  ownerIndex = m_transferToCombobox.GetSelectedIndex();
                var  ownerName  = m_transferToCombobox.GetItemByIndex(ownerIndex).Value;

                var messageBox = MyGuiSandbox.CreateMessageBox(
                    buttonType : MyMessageBoxButtonsType.YES_NO,
                    messageCaption : MyTexts.Get(MyCommonTexts.MessageBoxCaptionPleaseConfirm),
                    messageText : new StringBuilder().AppendFormat(MyTexts.GetString(MyCommonTexts.MessageBoxTextChangeOwner), ownerName.ToString()),
                    focusedResult : MyGuiScreenMessageBox.ResultEnum.NO,
                    callback : delegate(MyGuiScreenMessageBox.ResultEnum retval)
                {
                    if (retval == MyGuiScreenMessageBox.ResultEnum.YES)
                    {
                        if (m_currentBlocks.Length > 0)
                        {
                            m_requests.Clear();

                            foreach (var block in m_currentBlocks)
                            {
                                if (block.IDModule != null)
                                {
                                    if (block.OwnerId == 0 || block.OwnerId == MySession.Static.LocalPlayerId)
                                    {
                                        m_requests.Add(new MySyncGrid.MySingleOwnershipRequest()
                                        {
                                            BlockId = block.EntityId,
                                            Owner   = ownerKey
                                        });
                                    }
                                }
                            }

                            if (m_requests.Count > 0)
                            {
                                if (MySession.Static.Settings.ScenarioEditMode && Sync.Players.IdentityIsNpc(ownerKey))
                                {
                                    MySyncGrid.ChangeOwnersRequest(MyOwnershipShareModeEnum.Faction, m_requests, MySession.Static.LocalPlayerId);
                                }
                                else if (MySession.Static.LocalPlayerId == ownerKey)
                                {
                                    // this should not be changed to No share, without approval from a designer, see ticket https://app.asana.com/0/64822442925263/64356719169418
                                    MySyncGrid.ChangeOwnersRequest(MyOwnershipShareModeEnum.Faction, m_requests, MySession.Static.LocalPlayerId);
                                }
                                else
                                {
                                    MySyncGrid.ChangeOwnersRequest(MyOwnershipShareModeEnum.None, m_requests, MySession.Static.LocalPlayerId);
                                }
                            }
                        }

                        RecreateOwnershipControls();
                        UpdateOwnerGui();
                    }
                    else
                    {
                        m_askForConfirmation = false;
                        m_transferToCombobox.SelectItemByIndex(-1);
                        m_askForConfirmation = true;
                    }
                });
                messageBox.CanHideOthers = false;
                MyGuiSandbox.AddScreen(messageBox);
            }
            else
            {
                UpdateOwnerGui();
            }
        }