Ejemplo n.º 1
0
        private void AddSomething(string something, int amount)
        {
            foreach (var definition in MyDefinitionManager.Static.GetAllDefinitions())
            {
                var physicalItemDef = definition as MyPhysicalItemDefinition;
                if (physicalItemDef == null || physicalItemDef.CanSpawnFromScreen == false)
                {
                    continue;
                }

                if (definition.DisplayNameText == something)
                {
                    MyEntity    invObject = MySession.Static.ControlledEntity as MyEntity;
                    MyInventory inventory = invObject.GetInventory(0) as MyInventory;
                    if (inventory != null)
                    {
                        var builder = (MyObjectBuilder_PhysicalObject)VRage.ObjectBuilders.MyObjectBuilderSerializer.CreateNewObject(definition.Id);
                        inventory.DebugAddItems(amount, builder);
                    }
                    break;
                }
            }
        }
        void confirmButton_OnButtonClick(MyGuiControlButton sender)
        {
            IMyInventoryOwner invObject = MySession.ControlledEntity as IMyInventoryOwner;

            if (invObject != null)
            {
                double amountDec = 0;
                double.TryParse(m_amountTextbox.Text, out amountDec);

                MyFixedPoint amount = (MyFixedPoint)amountDec;

                var         itemId    = m_physicalItemDefinitions[(int)m_items.GetSelectedKey()].Id;
                MyInventory inventory = invObject.GetInventory(0);
                if (!MySession.Static.CreativeMode)
                {
                    amount = MyFixedPoint.Min(inventory.ComputeAmountThatFits(itemId), amount);
                }

                var builder = (MyObjectBuilder_PhysicalObject)MyObjectBuilderSerializer.CreateNewObject(itemId);
                inventory.DebugAddItems(amount, builder);
            }

            CloseScreen();
        }
        void confirmButton_OnButtonClick(MyGuiControlButton sender)
        {
            MyEntity invObject = MySession.Static.ControlledEntity as MyEntity;

            if (invObject != null && invObject.HasInventory)
            {
                double amountDec = 0;
                double.TryParse(m_amountTextbox.Text, out amountDec);
                m_lastAmount = amountDec;

                MyFixedPoint amount = (MyFixedPoint)amountDec;

                if (m_items.GetSelectedKey() < 0 || (int)m_items.GetSelectedKey() >= m_physicalItemDefinitions.Count)
                {
                    return;
                }

                var itemId = m_physicalItemDefinitions[(int)m_items.GetSelectedKey()].Id;
                m_lastSelectedItem = (int)m_items.GetSelectedKey();
                MyInventory inventory = invObject.GetInventory(0) as MyInventory;
                System.Diagnostics.Debug.Assert(inventory != null, "Null or other inventory type!");

                if (inventory != null)
                {
                    if (!MySession.Static.CreativeMode)
                    {
                        amount = MyFixedPoint.Min(inventory.ComputeAmountThatFits(itemId), amount);
                    }

                    var builder = (MyObjectBuilder_PhysicalObject)MyObjectBuilderSerializer.CreateNewObject(itemId);
                    inventory.DebugAddItems(amount, builder);
                }
            }

            CloseScreen();
        }