public override void OnOkClick(MyGuiControlButton sender)
        {
            bool isSaveSuccess = SaveChangesToInventory();

            if (!isSaveSuccess)
            {
                return;
            }

            base.OnOkClick(sender);
            //m_inventoryItemsRepository.Close();
            m_allItemsInventory.Close();
            CloseItems(ref m_itemsRemoved);
            m_itemsAdded.Clear();

            this.CloseScreen();
        }
Exemple #2
0
        public static MyGuiScreenInventory OpenInventory(MyGuiScreenInventoryType inventoryScreenType, MyEntity otherSide = null, MySmallShipInteractionActionEnum?action = null)
        {
            MyMwcLog.WriteLine("OpenInventory()");


            // return harvester when opening inventory, harvester can update inventory, which would not propagete to inventory screen and closing inventory would override those changes
            var harvester = MySession.PlayerShip.Weapons.GetMountedHarvestingDevice();

            if (harvester != null && harvester.CurrentState != MyHarvestingDeviceEnum.InsideShip)
            {
                harvester.Shot(null);
            }

            StringBuilder otherSideInventoryName = null;
            MyInventory   otherSideInventory     = null;
            List <MySmallShipBuilderWithName> shipsObjectBuilders = null;
            bool closeOtherSideInventory = false;

            m_inventoryScreenType = inventoryScreenType;
            m_shipsInventoryOwner = MySession.Static;
            m_player            = MySession.Static.Player;
            m_detectedEntity    = otherSide;
            m_detectedAction    = action;
            shipsObjectBuilders = new List <MySmallShipBuilderWithName>();
            shipsObjectBuilders.Add(new MySmallShipBuilderWithName(MySession.PlayerShip.GetObjectBuilder(true) as MyMwcObjectBuilder_SmallShip_Player));

            switch (m_inventoryScreenType)
            {
            case MyGuiScreenInventoryType.GodEditor:
                LoadGodEditorInventory(ref otherSideInventory, ref otherSideInventoryName, ref shipsObjectBuilders);
                closeOtherSideInventory = true;
                break;

            case MyGuiScreenInventoryType.InGameEditor:
                LoadIngameEditorInventory(ref otherSideInventory, ref otherSideInventoryName);
                break;

            case MyGuiScreenInventoryType.Game:
                LoadGameInventory(ref otherSideInventory, ref otherSideInventoryName, ref shipsObjectBuilders);
                break;
            }

            var currentShipBuilder = shipsObjectBuilders[0];

            shipsObjectBuilders.Sort((x, y) => ((int)x.Builder.ShipType).CompareTo((int)y.Builder.ShipType));
            m_curentIndex = shipsObjectBuilders.IndexOf(currentShipBuilder);
            MyMwcObjectBuilder_Inventory otherSideInventoryBuilder = otherSideInventory != null?otherSideInventory.GetObjectBuilder(true) : null;

            if (closeOtherSideInventory)
            {
                Debug.Assert(otherSideInventory != null);
                otherSideInventory.Close();
            }
            m_currentInventoryScreen = new MyGuiScreenInventory(shipsObjectBuilders, m_curentIndex,
                                                                m_player.Money, m_tradeForMoney,
                                                                otherSideInventoryBuilder, otherSideInventoryName,
                                                                m_inventoryScreenType);
            m_currentInventoryScreen.OnSave += Save;
            m_currentInventoryScreen.Closed += OnInventoryScreenClosed;
            MyGuiScreenGamePlay.Static.HideSelectAmmo();
            return(m_currentInventoryScreen);
        }