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 MyCubeGrid.MySingleOwnershipRequest()
                                        {
                                            BlockId = block.EntityId,
                                            Owner   = ownerKey
                                        });
                                    }
                                }
                            }

                            if (m_requests.Count > 0)
                            {
                                if (MySession.Static.Settings.ScenarioEditMode && Sync.Players.IdentityIsNpc(ownerKey))
                                {
                                    MyCubeGrid.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
                                    MyCubeGrid.ChangeOwnersRequest(MyOwnershipShareModeEnum.Faction, m_requests, MySession.Static.LocalPlayerId);
                                }
                                else
                                {
                                    MyCubeGrid.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();
            }
        }
예제 #2
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();
            }
        }