public static ulong GetBattlePoints(MySlimBlock slimBlock) { Debug.Assert(slimBlock.BlockDefinition.Points > 0); ulong pts = (ulong)(slimBlock.BlockDefinition.Points > 0 ? slimBlock.BlockDefinition.Points : 1); if (slimBlock.BlockDefinition.IsGeneratedBlock) { pts = 0; } // Get points from container items IMyInventoryOwner inventoryOwner = slimBlock.FatBlock as IMyInventoryOwner; if (inventoryOwner != null) { var inventory = inventoryOwner.GetInventory(0); if (inventory != null) { foreach (var item in inventory.GetItems()) { if (item.Content is MyObjectBuilder_BlockItem) { MyObjectBuilder_BlockItem blockItem = item.Content as MyObjectBuilder_BlockItem; pts += GetBattlePoints(blockItem.BlockDefId); } } } } return(pts); }
private void DetachOwner() { if (m_inventoryOwner == null) { return; } for (int i = 0; i < m_inventoryOwner.InventoryCount; ++i) { var inventory = m_inventoryOwner.GetInventory(i); inventory.UserData = null; inventory.ContentsChanged -= inventory_OnContentsChanged; } for (int i = 0; i < m_inventoryGrids.Count; ++i) { Elements.Remove(m_massLabels[i]); Elements.Remove(m_volumeLabels[i]); Elements.Remove(m_inventoryGrids[i]); } m_inventoryGrids.Clear(); m_massLabels.Clear(); m_volumeLabels.Clear(); m_inventoryOwner = null; }
private void AttachOwner(IMyInventoryOwner owner) { if (owner == null) { return; } m_nameLabel.Text = owner.DisplayNameText.ToString(); for (int i = 0; i < owner.InventoryCount; ++i) { var inventory = owner.GetInventory(i); inventory.UserData = this; inventory.ContentsChanged += inventory_OnContentsChanged; var massLabel = MakeMassLabel(inventory); Elements.Add(massLabel); m_massLabels.Add(massLabel); var volumeLabel = MakeVolumeLabel(inventory); Elements.Add(volumeLabel); m_volumeLabels.Add(volumeLabel); var inventoryGrid = MakeInventoryGrid(inventory); Elements.Add(inventoryGrid); m_inventoryGrids.Add(inventoryGrid); } m_inventoryOwner = owner; RefreshInventoryContents(); }
static void OnRemoveItemsSuccess(ref RemoveItemsMsg msg, MyNetworkClient sender) { if (!MyEntities.EntityExists(msg.OwnerEntityId)) { return; } IMyInventoryOwner owner = MyEntities.GetEntityById(msg.OwnerEntityId) as IMyInventoryOwner; MyInventory inv = null; if (owner != null) { inv = owner.GetInventory(msg.InventoryIndex); } else { // NOTE: this should be the default code after we get rid of the inventory owner and should be searched by it's id MyEntity entity = MyEntities.GetEntityById(msg.OwnerEntityId); MyInventoryBase baseInventory; if (entity.Components.TryGet <MyInventoryBase>(out baseInventory)) { inv = baseInventory as MyInventory; } } if (inv != null) { inv.RemoveItemsInternal(msg.itemId, msg.Amount); } else { Debug.Fail("Inventory was not found!"); } }
private void OnOwnerChanged(IMyComponentInventory inventory, IMyInventoryOwner owner) { if (OwnerChanged != null) { OwnerChanged(inventory, owner); } }
private static void Reload(IMyInventoryOwner gun, SerializableDefinitionId ammo, bool reactor = false) { var cGun = gun; Sandbox.ModAPI.IMyInventory inv = (Sandbox.ModAPI.IMyInventory)cGun.GetInventory(0); VRage.MyFixedPoint point = inv.GetItemAmount(ammo, MyItemFlags.None | MyItemFlags.Damaged); Util.GetInstance().Log(ammo.SubtypeName + " [ReloadGuns] Amount " + point.RawValue, "ItemManager.txt"); if (point.RawValue > 1000000) return; //inv.Clear(); VRage.MyFixedPoint amount = new VRage.MyFixedPoint(); amount.RawValue = 2000000; MyObjectBuilder_InventoryItem ii; if (reactor) { ii = new MyObjectBuilder_InventoryItem() { Amount = 10, Content = new MyObjectBuilder_Ingot() { SubtypeName = ammo.SubtypeName } }; } else { ii = new MyObjectBuilder_InventoryItem() { Amount = 4, Content = new MyObjectBuilder_AmmoMagazine() { SubtypeName = ammo.SubtypeName } }; } inv.AddItems(amount, ii.PhysicalContent); point = inv.GetItemAmount(ammo, MyItemFlags.None | MyItemFlags.Damaged); Util.GetInstance().Log(ammo.SubtypeName + " [ReloadGuns] Amount " + point.RawValue, "ItemManager.txt"); }
private static void AddItemsInternal(AddItemsMsg msg) { IMyInventoryOwner owner = MyEntities.GetEntityById(msg.OwnerEntityId) as IMyInventoryOwner; MyInventory inv = owner.GetInventory(msg.InventoryIndex); inv.AddItemsInternal(msg.Amount, msg.Item, msg.itemIdx); }
static void OnRemoveItemsRequest(ref RemoveItemsMsg msg, MyNetworkClient sender) { if (!MyEntities.EntityExists(msg.OwnerEntityId)) { return; } IMyInventoryOwner owner = MyEntities.GetEntityById(msg.OwnerEntityId) as IMyInventoryOwner; MyInventory inv = null; if (owner != null) { inv = owner.GetInventory(msg.InventoryIndex); } else { // NOTE: this should be the default code after we get rid of the inventory owner and should be searched by it's id MyEntity entity = MyEntities.GetEntityById(msg.OwnerEntityId); MyInventoryBase baseInventory; if (entity.Components.TryGet <MyInventoryBase>(out baseInventory)) { inv = baseInventory as MyInventory; } } var item = inv.GetItemByID(msg.itemId); if (!item.HasValue) { return; } inv.RemoveItems(msg.itemId, msg.Amount, spawn: msg.Spawn); }
static void OnAddItemsRequest(ref AddItemsMsg msg, MyNetworkClient sender) { if (!MyEntities.EntityExists(msg.OwnerEntityId)) { return; } IMyInventoryOwner owner = MyEntities.GetEntityById(msg.OwnerEntityId) as IMyInventoryOwner; owner.GetInventory(msg.InventoryIndex).AddItems(msg.Amount, msg.Item, msg.itemIdx); }
static void OnRemoveItemsSuccess(ref RemoveItemsMsg msg, MyNetworkClient sender) { if (!MyEntities.EntityExists(msg.OwnerEntityId)) { return; } IMyInventoryOwner owner = MyEntities.GetEntityById(msg.OwnerEntityId) as IMyInventoryOwner; MyInventory inv = owner.GetInventory(msg.InventoryIndex); inv.RemoveItemsInternal(msg.itemId, msg.Amount); }
public MyInventory(MyFixedPoint maxVolume, Vector3 size, MyInventoryFlags flags, IMyInventoryOwner owner) { m_maxVolume = MyPerGameSettings.ConstrainInventory() ? maxVolume * MySession.Static.InventoryMultiplier : MyFixedPoint.MaxValue; m_size = size; m_flags = flags; m_owner = owner; Clear(); SyncObject = new MySyncInventory(); }
public void Remove(IMyInventoryOwner block) { bool removed = m_blocks.Remove(block); System.Diagnostics.Debug.Assert(removed, "Double remove or removing something not added"); var handler = BlockRemoved; if (handler != null) { handler(block); } }
public void Add(IMyInventoryOwner block) { bool added = m_blocks.Add(block); System.Diagnostics.Debug.Assert(added, "Double add"); var handler = BlockAdded; if (handler != null) { handler(block); } }
public MyInventory(MyFixedPoint maxVolume, MyFixedPoint maxMass, Vector3 size, MyInventoryFlags flags, IMyInventoryOwner owner) { m_maxVolume = maxVolume; m_maxMass = maxMass; m_size = size; m_flags = flags; m_owner = owner; Clear(); SyncObject = new MySyncInventory(); //ContentsChanged += OnContentsChanged; }
static void OnTransferItemsRequest(ref TransferItemsMsg msg, MyNetworkClient sender) { if (!MyEntities.EntityExists(msg.OwnerEntityId) || !MyEntities.EntityExists(msg.DestOwnerEntityId)) { return; } IMyInventoryOwner srcOwner = MyEntities.GetEntityById(msg.OwnerEntityId) as IMyInventoryOwner; IMyInventoryOwner destOwner = MyEntities.GetEntityById(msg.DestOwnerEntityId) as IMyInventoryOwner; MyInventory src = srcOwner.GetInventory(msg.InventoryIndex); MyInventory dst = destOwner.GetInventory(msg.DestInventoryIndex); TransferItemsInternal(src, dst, msg.itemId, msg.Spawn, msg.DestItemIndex, msg.Amount); }
private void EmptyBlockInventories(IMyInventoryOwner block) { for (int i = 0; i < block.InventoryCount; ++i) { var blockInventory = block.GetInventory(i); if (blockInventory.Empty()) continue; m_tmpItemList.Clear(); m_tmpItemList.AddList(blockInventory.GetItems()); foreach (var item in m_tmpItemList) { MyInventory.Transfer(blockInventory, Inventory, item.ItemId); } } }
private static bool FillInventoryWithIron() { IMyInventoryOwner invObject = MySession.ControlledEntity as IMyInventoryOwner; if (invObject != null) { MyFixedPoint amount = 20000; var oreBuilder = MyObjectBuilderSerializer.CreateNewObject <MyObjectBuilder_Ore>("Iron"); MyInventory inventory = invObject.GetInventory(0); amount = inventory.ComputeAmountThatFits(oreBuilder.GetId()); inventory.AddItems(amount, oreBuilder); } return(true); }
static void OnRemoveItemsRequest(ref RemoveItemsMsg msg, MyNetworkClient sender) { if (!MyEntities.EntityExists(msg.OwnerEntityId)) { return; } IMyInventoryOwner owner = MyEntities.GetEntityById(msg.OwnerEntityId) as IMyInventoryOwner; MyInventory inv = owner.GetInventory(msg.InventoryIndex); var item = inv.GetItemByID(msg.itemId); if (!item.HasValue) { return; } inv.RemoveItems(msg.itemId, msg.Amount, spawn: msg.Spawn); }
private static void Reload(IMyInventoryOwner gun, SerializableDefinitionId ammo, bool reactor = false) { var cGun = gun; Sandbox.ModAPI.IMyInventory inv = (Sandbox.ModAPI.IMyInventory)cGun.GetInventory(0); VRage.MyFixedPoint point = inv.GetItemAmount(ammo, MyItemFlags.None | MyItemFlags.Damaged); Util.GetInstance().Log(ammo.SubtypeName + " [ReloadGuns] Amount " + point.RawValue, "ItemManager.txt"); if (point.RawValue > 1000000) { return; } //inv.Clear(); VRage.MyFixedPoint amount = new VRage.MyFixedPoint(); amount.RawValue = 2000000; MyObjectBuilder_InventoryItem ii; if (reactor) { ii = new MyObjectBuilder_InventoryItem() { Amount = 10, Content = new MyObjectBuilder_Ingot() { SubtypeName = ammo.SubtypeName } }; } else { ii = new MyObjectBuilder_InventoryItem() { Amount = 4, Content = new MyObjectBuilder_AmmoMagazine() { SubtypeName = ammo.SubtypeName } }; } inv.AddItems(amount, ii.PhysicalContent); point = inv.GetItemAmount(ammo, MyItemFlags.None | MyItemFlags.Damaged); Util.GetInstance().Log(ammo.SubtypeName + " [ReloadGuns] Amount " + point.RawValue, "ItemManager.txt"); }
private void EmptyBlockInventories(IMyInventoryOwner block) { for (int i = 0; i < block.InventoryCount; ++i) { var blockInventory = block.GetInventory(i); if (blockInventory.Empty()) { continue; } m_tmpItemList.Clear(); m_tmpItemList.AddList(blockInventory.GetItems()); foreach (var item in m_tmpItemList) { MyInventory.Transfer(blockInventory, Inventory, item.ItemId); } } }
public MyGuiControlInventoryOwner(IMyInventoryOwner owner, Vector4 labelColorMask) : base(backgroundTexture: new MyGuiCompositeTexture() { Center = new MyGuiSizedTexture() { Texture = @"Textures\GUI\Controls\item_highlight_dark.dds" } }, canHaveFocus: true, allowFocusingElements: true, isActiveControl: false) { Debug.Assert(owner != null); m_nameLabel = MakeLabel(); m_nameLabel.ColorMask = labelColorMask; m_massLabels = new List<MyGuiControlLabel>(); m_volumeLabels = new List<MyGuiControlLabel>(); m_inventoryGrids = new List<MyGuiControlGrid>(); ShowTooltipWhenDisabled = true; m_nameLabel.Name = "NameLabel"; Elements.Add(m_nameLabel); InventoryOwner = owner; }
public MyGuiControlInventoryOwner(IMyInventoryOwner owner, Vector4 labelColorMask) : base(backgroundTexture: new MyGuiCompositeTexture() { Center = new MyGuiSizedTexture() { Texture = @"Textures\GUI\Controls\item_highlight_dark.dds" } }, canHaveFocus: true, allowFocusingElements: true, isActiveControl: false) { Debug.Assert(owner != null); m_nameLabel = MakeLabel(); m_nameLabel.ColorMask = labelColorMask; m_massLabels = new List <MyGuiControlLabel>(); m_volumeLabels = new List <MyGuiControlLabel>(); m_inventoryGrids = new List <MyGuiControlGrid>(); ShowTooltipWhenDisabled = true; m_nameLabel.Name = "NameLabel"; Elements.Add(m_nameLabel); InventoryOwner = owner; }
private static void OnUpdateOxygenLevel(ref UpdateOxygenLevelMsg msg, MyNetworkClient sender) { if (!MyEntities.EntityExists(msg.OwnerEntityId)) { return; } IMyInventoryOwner owner = MyEntities.GetEntityById(msg.OwnerEntityId) as IMyInventoryOwner; MyInventory inv = null; if (owner != null) { inv = owner.GetInventory(msg.InventoryIndex); } else { // NOTE: this should be the default code after we get rid of the inventory owner and should be searched by it's id MyEntity entity = MyEntities.GetEntityById(msg.OwnerEntityId); MyInventoryBase baseInventory; if (entity.Components.TryGet <MyInventoryBase>(out baseInventory)) { inv = baseInventory as MyInventory; } } var item = inv.GetItemByID(msg.ItemId); if (!item.HasValue) { return; } var oxygenContainer = item.Value.Content as MyObjectBuilder_OxygenContainerObject; if (oxygenContainer != null) { oxygenContainer.OxygenLevel = msg.OxygenLevel; inv.UpdateOxygenAmount(); } }
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(); }
protected override void OnLoad(BitStream stream, Action <MyInventory> loadingDoneHandler) { long entityId; VRage.Serialization.MySerializer.CreateAndRead(stream, out entityId); int inventoryId; VRage.Serialization.MySerializer.CreateAndRead(stream, out inventoryId); MyEntity entity; MyEntities.TryGetEntityById(entityId, out entity); IMyInventoryOwner owner = entity as IMyInventoryOwner; MyInventory inventory = null; if (owner != null) { inventory = owner.GetInventory(inventoryId); m_items.Clear(); int numItems; VRage.Serialization.MySerializer.CreateAndRead(stream, out numItems); for (int i = 0; i < numItems; ++i) { MyPhysicalInventoryItem item; VRage.Serialization.MySerializer.CreateAndRead(stream, out item, MyObjectBuilderSerializer.Dynamic); m_items.Add(item); } inventory.SetItems(m_items); } Debug.Assert(inventory != null, "Dusan, we should fix this, try to find out what is that EntityId of owner on server: " + entityId); loadingDoneHandler(inventory); }
private static void OnUpdateOxygenLevel(ref UpdateOxygenLevelMsg msg, MyNetworkClient sender) { if (!MyEntities.EntityExists(msg.OwnerEntityId)) { return; } IMyInventoryOwner owner = MyEntities.GetEntityById(msg.OwnerEntityId) as IMyInventoryOwner; MyInventory inv = owner.GetInventory(msg.InventoryIndex); var item = inv.GetItemByID(msg.ItemId); if (!item.HasValue) { return; } var oxygenContainer = item.Value.Content as MyObjectBuilder_OxygenContainerObject; if (oxygenContainer != null) { oxygenContainer.OxygenLevel = msg.OxygenLevel; inv.UpdateOxygenAmount(); } }
public void Remove(IMyInventoryOwner block) { bool removed = m_blocks.Remove(block); System.Diagnostics.Debug.Assert(removed, "Double remove or removing something not added"); var handler = BlockRemoved; if (handler != null) handler(block); }
public void Add(IMyInventoryOwner block) { bool added = m_blocks.Add(block); System.Diagnostics.Debug.Assert(added, "Double add"); var handler = BlockAdded; if (handler != null) handler(block); }
public static bool ItemPushRequest(IMyConveyorEndpointBlock start, MyInventory srcInventory, long playerId, MyPhysicalInventoryItem toSend, MyFixedPoint?amount = null) { var itemBuilder = toSend.Content; if (amount.HasValue) { Debug.Assert(toSend.Content.TypeId == typeof(MyObjectBuilder_Ore) || toSend.Content.TypeId == typeof(MyObjectBuilder_Ingot) || MyFixedPoint.Floor(amount.Value) == amount.Value); } MyFixedPoint remainingAmount = toSend.Amount; if (amount.HasValue) { remainingAmount = amount.Value; } SetTraversalPlayerId(playerId); var toSendContentId = toSend.Content.GetId(); SetTraversalInventoryItemDefinitionId(toSendContentId); if (NeedsLargeTube(toSendContentId)) { PrepareTraversal(start.ConveyorEndpoint, null, IsAccessAllowedPredicate, IsConveyorLargePredicate); } else { PrepareTraversal(start.ConveyorEndpoint, null, IsAccessAllowedPredicate); } bool success = false; foreach (var conveyorEndpoint in MyGridConveyorSystem.Pathfinding) { IMyInventoryOwner owner = conveyorEndpoint.CubeBlock as IMyInventoryOwner; if (owner == null) { continue; } for (int i = 0; i < owner.InventoryCount; ++i) { var inventory = owner.GetInventory(i); if ((inventory.GetFlags() & MyInventoryFlags.CanReceive) == 0) { continue; } if (inventory == srcInventory) { continue; } var fittingAmount = inventory.ComputeAmountThatFits(toSendContentId); fittingAmount = MyFixedPoint.Min(fittingAmount, remainingAmount); if (!inventory.CheckConstraint(toSendContentId)) { continue; } if (fittingAmount == 0) { continue; } MyInventory.Transfer(srcInventory, inventory, toSend.ItemId, -1, fittingAmount); success = true; } } return(success); }
public override void OnAddedToContainer() { Debug.Assert(m_owner == null || m_owner == Container.Entity, "Owner is supposed to be null before added to container or set to proper entity"); bool wasNull = m_owner == null; base.OnAddedToContainer(); m_owner = Container.Entity as IMyInventoryOwner; var handler = OnCreated; if (handler != null && wasNull) handler(this); }
public MyInventory(MyFixedPoint maxVolume, MyFixedPoint maxMass, Vector3 size, MyInventoryFlags flags, IMyInventoryOwner owner) : base("Inventory") { m_maxVolume = maxVolume; m_maxMass = maxMass; m_size = size; m_flags = flags; m_owner = owner; Clear(); SyncObject = new MySyncInventory(); var handler = OnCreated; if (handler != null && m_owner != null) handler(this); }
public MyInventoryAggregateBase(IMyInventoryOwner owner) { //TODO: This should be removed in the future, this is not necessary m_owner = owner; }
public bool Drill(bool collectOre = true, bool performCutout = true) { ProfilerShort.Begin("MyDrillBase::Drill()"); bool drillingSuccess = false; MySoundPair sound = null; if ((m_drillEntity.Parent != null) && (m_drillEntity.Parent.Physics != null) && !m_drillEntity.Parent.Physics.Enabled) { return(false); } if (performCutout) { var entitiesInRange = m_sensor.EntitiesInRange; foreach (var entry in entitiesInRange) { drillingSuccess = false; var entity = entry.Value.Entity; if (entity.MarkedForClose) { continue; } if (entity is MyCubeGrid) { var grid = entity as MyCubeGrid; if (grid.Physics != null && grid.Physics.Enabled) { drillingSuccess = TryDrillBlocks(grid, entry.Value.DetectionPoint, !Sync.IsServer); } if (drillingSuccess) { m_initialHeatup = false; sound = m_sounds.MetalLoop; CreateParticles(entry.Value.DetectionPoint, false, true, false); } } else if (entity is MyVoxelBase) { ProfilerShort.Begin("Drill voxel map"); var voxels = entity as MyVoxelBase; drillingSuccess = TryDrillVoxels(voxels, entry.Value.DetectionPoint, collectOre, !Sync.IsServer); ProfilerShort.BeginNextBlock("Create particles"); if (drillingSuccess) { sound = m_sounds.RockLoop; CreateParticles(entry.Value.DetectionPoint, true, false, true); } ProfilerShort.End(); } else if (entity is MyFloatingObject) { var sphere = (BoundingSphereD)m_cutOut.Sphere; sphere.Radius *= 1.33f; if (entity.GetIntersectionWithSphere(ref sphere)) { MyFloatingObject flObj = entity as MyFloatingObject; if (Sync.IsServer) { if (flObj.Item.Content.TypeId == typeof(MyObjectBuilder_Ore)) { IMyInventoryOwner invOwn = m_drillEntity as IMyInventoryOwner; if (invOwn == null) { invOwn = (m_drillEntity as MyHandDrill).Owner as IMyInventoryOwner; } invOwn.GetInventory(0).TakeFloatingObject(flObj); } else { (entity as MyFloatingObject).DoDamage(70, MyDamageType.Drill, true, attackerId: m_drillEntity != null ? m_drillEntity.EntityId : 0); } } drillingSuccess = true; } } else if (entity is MyCharacter) { var sphere = (BoundingSphereD)m_cutOut.Sphere; sphere.Radius *= (4 / 5f); var character = entity as MyCharacter; if (entity.GetIntersectionWithSphere(ref sphere)) { //MyRenderProxy.DebugDrawSphere(sphere.Center, sphere.Radius, Color.Green.ToVector3(), 1, true); if (Sync.IsServer) { character.DoDamage(20, MyDamageType.Drill, true, attackerId: m_drillEntity != null ? m_drillEntity.EntityId : 0); } drillingSuccess = true; } else { BoundingSphereD headSphere = new BoundingSphereD(character.PositionComp.WorldMatrix.Translation + character.WorldMatrix.Up * 1.25f, 0.6f); //MyRenderProxy.DebugDrawSphere(headSphere.Center, headSphere.Radius, Color.Red.ToVector3(), 1, false); if (headSphere.Intersects(sphere)) { //MyRenderProxy.DebugDrawSphere(sphere.Center, sphere.Radius, Color.Green.ToVector3(), 1, true); if (Sync.IsServer) { character.DoDamage(20, MyDamageType.Drill, true, attackerId: m_drillEntity != null ? m_drillEntity.EntityId : 0); } drillingSuccess = true; } } } if (drillingSuccess) { m_lastContactTime = MySandboxGame.TotalGamePlayTimeInMilliseconds; } } } if (sound != null) { StartLoopSound(sound); } else { StartIdleSound(m_sounds.IdleLoop); } IsDrilling = true; m_animationLastUpdateTime = MySandboxGame.TotalGamePlayTimeInMilliseconds; ProfilerShort.End(); return(drillingSuccess); }
private void ConveyorSystem_BlockRemoved(IMyInventoryOwner obj) { m_interactedGridOwners.Remove(obj); if (m_leftShowsGrid) LeftTypeGroup_SelectedChanged(m_leftTypeGroup); if (m_rightShowsGrid) RightTypeGroup_SelectedChanged(m_rightTypeGroup); if (m_dragAndDropInfo != null) { ClearDisabledControls(); DisableInvalidWhileDragging(); } }
/// <summary> /// It set's the inventory owner to self. This is a hack as all sync layers etc. are expecting to have IMyInventoryOwner. Before we rewrite it, we need to keep InventoryOwner. /// TODO: This can be deleted, when owner is not needed /// </summary> public void RemoveOwner() { m_owner = this; }
public MyInventory(MyObjectBuilder_InventoryDefinition definition, MyInventoryFlags flags, IMyInventoryOwner owner) : this(definition.InventoryVolume, definition.InventoryMass, new Vector3(definition.InventorySizeX, definition.InventorySizeY, definition.InventorySizeZ), flags, owner) { myObjectBuilder_InventoryDefinition = definition; }
public MyInventory(float maxVolume, Vector3 size, MyInventoryFlags flags, IMyInventoryOwner owner) : this((MyFixedPoint)maxVolume, size, flags, owner) { }
public MyInventory(float maxVolume, float maxMass, Vector3 size, MyInventoryFlags flags, IMyInventoryOwner owner) : this((MyFixedPoint)maxVolume, (MyFixedPoint)maxMass, size, flags, owner) { }
public static void ItemPullRequest(IMyConveyorEndpointBlock start, MyInventory destinationInventory, long playerId, MyDefinitionId itemId, MyFixedPoint?amount = null) { using (var invertedConductivity = new MyConveyorLine.InvertedConductivity()) { if (amount.HasValue) { Debug.Assert(itemId.TypeId == typeof(MyObjectBuilder_Ore) || itemId.TypeId == typeof(MyObjectBuilder_Ingot) || MyFixedPoint.Floor(amount.Value) == amount.Value); } SetTraversalPlayerId(playerId); SetTraversalInventoryItemDefinitionId(itemId); PrepareTraversal(start.ConveyorEndpoint, null, IsAccessAllowedPredicate, NeedsLargeTube(itemId) ? IsConveyorLargePredicate : null); foreach (var conveyorEndpoint in MyGridConveyorSystem.Pathfinding) { IMyInventoryOwner owner = conveyorEndpoint.CubeBlock as IMyInventoryOwner; if (owner == null) { continue; } for (int i = 0; i < owner.InventoryCount; ++i) { var inventory = owner.GetInventory(i); if ((inventory.GetFlags() & MyInventoryFlags.CanSend) == 0) { continue; } if (inventory == destinationInventory) { continue; } if (amount.HasValue) { var availableAmount = inventory.GetItemAmount(itemId); availableAmount = amount.HasValue ? MyFixedPoint.Min(availableAmount, amount.Value) : availableAmount; if (availableAmount == 0) { continue; } MyInventory.Transfer(inventory, destinationInventory, itemId, MyItemFlags.None, availableAmount); amount -= availableAmount; if (amount.Value == 0) { return; } } else { MyInventory.Transfer(inventory, destinationInventory, itemId, MyItemFlags.None); } } } } }
private void ReplaceCurrentInventoryOwner(IMyInventoryOwner owner) { DetachOwner(); AttachOwner(owner); }
private void AddItemsToInventory(int variant) { bool overrideCheck = variant != 0; bool spawnNonfitting = variant != 0; bool componentsOnly = variant == 2; IMyInventoryOwner invObject = MySession.ControlledEntity as IMyInventoryOwner; if (invObject != null) { MyInventory inventory = invObject.GetInventory(0); //inventory.Clear(); if (!componentsOnly) { MyObjectBuilder_AmmoMagazine ammoMag = new MyObjectBuilder_AmmoMagazine(); ammoMag.SubtypeName = "NATO_5p56x45mm"; ammoMag.ProjectilesCount = 50; AddItems(inventory, ammoMag, false, 5); MyObjectBuilder_AmmoMagazine ammoMag2 = new MyObjectBuilder_AmmoMagazine(); ammoMag2.SubtypeName = "NATO_25x184mm"; ammoMag2.ProjectilesCount = 50; AddItems(inventory, ammoMag2, false); MyObjectBuilder_AmmoMagazine ammoMag3 = new MyObjectBuilder_AmmoMagazine(); ammoMag3.SubtypeName = "Missile200mm"; ammoMag3.ProjectilesCount = 50; AddItems(inventory, ammoMag3, false); AddItems(inventory, CreateGunContent("AutomaticRifleItem"), false); AddItems(inventory, CreateGunContent("WelderItem"), false); AddItems(inventory, CreateGunContent("AngleGrinderItem"), false); AddItems(inventory, CreateGunContent("HandDrillItem"), false); } // Add all components foreach (var definition in MyDefinitionManager.Static.GetAllDefinitions()) { if (definition.Id.TypeId != typeof(MyObjectBuilder_Component) && definition.Id.TypeId != typeof(MyObjectBuilder_Ingot)) { continue; } if (componentsOnly && definition.Id.TypeId != typeof(MyObjectBuilder_Component)) { continue; } if (componentsOnly && ((MyComponentDefinition)definition).Volume > 0.05f) { continue; } var component = (MyObjectBuilder_PhysicalObject)MyObjectBuilderSerializer.CreateNewObject(definition.Id.TypeId); component.SubtypeName = definition.Id.SubtypeName; if (!AddItems(inventory, component, overrideCheck, 1) && spawnNonfitting) { Matrix headMatrix = MySession.ControlledEntity.GetHeadMatrix(true); MyFloatingObjects.Spawn(new MyPhysicalInventoryItem(1, component), headMatrix.Translation + headMatrix.Forward * 0.2f, headMatrix.Forward, headMatrix.Up, MySession.ControlledEntity.Entity.Physics); } } if (!componentsOnly) { string[] ores; MyDefinitionManager.Static.GetOreTypeNames(out ores); foreach (var ore in ores) { var oreBuilder = MyObjectBuilderSerializer.CreateNewObject <MyObjectBuilder_Ore>(ore); if (!AddItems(inventory, oreBuilder, overrideCheck, 1) && spawnNonfitting) { Matrix headMatrix = MySession.ControlledEntity.GetHeadMatrix(true); MyFloatingObjects.Spawn(new MyPhysicalInventoryItem(1, oreBuilder), headMatrix.Translation + headMatrix.Forward * 0.2f, headMatrix.Forward, headMatrix.Up, MySession.ControlledEntity.Entity.Physics); } } } } }
private void CreateInventoryControlInList(IMyInventoryOwner owner, MyGuiControlList listControl) { List<IMyInventoryOwner> inventories = new List<IMyInventoryOwner>(); if (owner != null) inventories.Add(owner); CreateInventoryControlsInList(inventories, listControl); }
private void DetachOwner() { if (m_inventoryOwner == null) return; for (int i = 0; i < m_inventoryOwner.InventoryCount; ++i) { var inventory = m_inventoryOwner.GetInventory(i); inventory.UserData = null; inventory.ContentsChanged -= inventory_OnContentsChanged; } for (int i = 0; i < m_inventoryGrids.Count; ++i) { Elements.Remove(m_massLabels[i]); Elements.Remove(m_volumeLabels[i]); Elements.Remove(m_inventoryGrids[i]); } m_inventoryGrids.Clear(); m_massLabels.Clear(); m_volumeLabels.Clear(); m_inventoryOwner = null; }
private void AttachOwner(IMyInventoryOwner owner) { if (owner == null) return; m_nameLabel.Text = owner.DisplayNameText.ToString(); for (int i = 0; i < owner.InventoryCount; ++i) { var inventory = owner.GetInventory(i); inventory.UserData = this; inventory.ContentsChanged += inventory_OnContentsChanged; var massLabel = MakeMassLabel(inventory); Elements.Add(massLabel); m_massLabels.Add(massLabel); var volumeLabel = MakeVolumeLabel(inventory); Elements.Add(volumeLabel); m_volumeLabels.Add(volumeLabel); var inventoryGrid = MakeInventoryGrid(inventory); Elements.Add(inventoryGrid); m_inventoryGrids.Add(inventoryGrid); } m_inventoryOwner = owner; RefreshInventoryContents(); }
public void Init(IMyGuiControlsParent controlsParent, MyEntity thisEntity, MyEntity interactedEntity, MyGridColorHelper colorHelper) { ProfilerShort.Begin("MyGuiScreenTerminal.ControllerInventory.Init"); m_userAsEntity = thisEntity; m_interactedAsEntity = interactedEntity; m_colorHelper = colorHelper; m_leftOwnersControl = (MyGuiControlList)controlsParent.Controls.GetControlByName("LeftInventory"); m_rightOwnersControl = (MyGuiControlList)controlsParent.Controls.GetControlByName("RightInventory"); m_leftSuitButton = (MyGuiControlRadioButton)controlsParent.Controls.GetControlByName("LeftSuitButton"); m_leftGridButton = (MyGuiControlRadioButton)controlsParent.Controls.GetControlByName("LeftGridButton"); m_leftFilterStorageButton = (MyGuiControlRadioButton)controlsParent.Controls.GetControlByName("LeftFilterStorageButton"); m_leftFilterSystemButton = (MyGuiControlRadioButton)controlsParent.Controls.GetControlByName("LeftFilterSystemButton"); m_leftFilterEnergyButton = (MyGuiControlRadioButton)controlsParent.Controls.GetControlByName("LeftFilterEnergyButton"); m_leftFilterAllButton = (MyGuiControlRadioButton)controlsParent.Controls.GetControlByName("LeftFilterAllButton"); m_rightSuitButton = (MyGuiControlRadioButton)controlsParent.Controls.GetControlByName("RightSuitButton"); m_rightGridButton = (MyGuiControlRadioButton)controlsParent.Controls.GetControlByName("RightGridButton"); m_rightFilterStorageButton = (MyGuiControlRadioButton)controlsParent.Controls.GetControlByName("RightFilterStorageButton"); m_rightFilterSystemButton = (MyGuiControlRadioButton)controlsParent.Controls.GetControlByName("RightFilterSystemButton"); m_rightFilterEnergyButton = (MyGuiControlRadioButton)controlsParent.Controls.GetControlByName("RightFilterEnergyButton"); m_rightFilterAllButton = (MyGuiControlRadioButton)controlsParent.Controls.GetControlByName("RightFilterAllButton"); m_throwOutButton = (MyGuiControlButton)controlsParent.Controls.GetControlByName("ThrowOutButton"); m_hideEmptyLeft = (MyGuiControlCheckbox)controlsParent.Controls.GetControlByName("CheckboxHideEmptyLeft"); m_hideEmptyLeftLabel = (MyGuiControlLabel)controlsParent.Controls.GetControlByName("LabelHideEmptyLeft"); m_hideEmptyRight = (MyGuiControlCheckbox)controlsParent.Controls.GetControlByName("CheckboxHideEmptyRight"); m_hideEmptyRightLabel = (MyGuiControlLabel)controlsParent.Controls.GetControlByName("LabelHideEmptyRight"); m_blockSearchLeft = (MyGuiControlTextbox)controlsParent.Controls.GetControlByName("BlockSearchLeft"); m_blockSearchClearLeft = (MyGuiControlButton)controlsParent.Controls.GetControlByName("BlockSearchClearLeft"); m_blockSearchRight = (MyGuiControlTextbox)controlsParent.Controls.GetControlByName("BlockSearchRight"); m_blockSearchClearRight = (MyGuiControlButton)controlsParent.Controls.GetControlByName("BlockSearchClearRight"); m_hideEmptyLeft.Visible = false; m_hideEmptyLeftLabel.Visible = false; m_hideEmptyRight.Visible = true; m_hideEmptyRightLabel.Visible = true; m_blockSearchLeft.Visible = false; m_blockSearchClearLeft.Visible = false; m_blockSearchRight.Visible = true; m_blockSearchClearRight.Visible = true; m_hideEmptyLeft.IsCheckedChanged += HideEmptyLeft_Checked; m_hideEmptyRight.IsCheckedChanged += HideEmptyRight_Checked; m_blockSearchLeft.TextChanged += BlockSearchLeft_TextChanged; m_blockSearchClearLeft.ButtonClicked += BlockSearchClearLeft_ButtonClicked; m_blockSearchRight.TextChanged += BlockSearchRight_TextChanged; m_blockSearchClearRight.ButtonClicked += BlockSearchClearRight_ButtonClicked; m_leftSuitButton.SetToolTip(MySpaceTexts.ToolTipTerminalInventory_ShowCharacter); m_leftGridButton.SetToolTip(MySpaceTexts.ToolTipTerminalInventory_ShowConnected); m_rightSuitButton.SetToolTip(MySpaceTexts.ToolTipTerminalInventory_ShowInteracted); m_rightGridButton.SetToolTip(MySpaceTexts.ToolTipTerminalInventory_ShowConnected); m_leftFilterAllButton.SetToolTip(MySpaceTexts.ToolTipTerminalInventory_FilterAll); m_leftFilterEnergyButton.SetToolTip(MySpaceTexts.ToolTipTerminalInventory_FilterEnergy); m_leftFilterStorageButton.SetToolTip(MySpaceTexts.ToolTipTerminalInventory_FilterStorage); m_leftFilterSystemButton.SetToolTip(MySpaceTexts.ToolTipTerminalInventory_FilterSystem); m_rightFilterAllButton.SetToolTip(MySpaceTexts.ToolTipTerminalInventory_FilterAll); m_rightFilterEnergyButton.SetToolTip(MySpaceTexts.ToolTipTerminalInventory_FilterEnergy); m_rightFilterStorageButton.SetToolTip(MySpaceTexts.ToolTipTerminalInventory_FilterStorage); m_rightFilterSystemButton.SetToolTip(MySpaceTexts.ToolTipTerminalInventory_FilterSystem); m_throwOutButton.SetToolTip(MySpaceTexts.ToolTipTerminalInventory_ThrowOut); m_throwOutButton.CueEnum = GuiSounds.None; m_leftTypeGroup.Add(m_leftSuitButton); m_leftTypeGroup.Add(m_leftGridButton); m_rightTypeGroup.Add(m_rightSuitButton); m_rightTypeGroup.Add(m_rightGridButton); m_leftFilterGroup.Add(m_leftFilterAllButton); m_leftFilterGroup.Add(m_leftFilterEnergyButton); m_leftFilterGroup.Add(m_leftFilterStorageButton); m_leftFilterGroup.Add(m_leftFilterSystemButton); m_rightFilterGroup.Add(m_rightFilterAllButton); m_rightFilterGroup.Add(m_rightFilterEnergyButton); m_rightFilterGroup.Add(m_rightFilterStorageButton); m_rightFilterGroup.Add(m_rightFilterSystemButton); m_throwOutButton.DrawCrossTextureWhenDisabled = false; //m_throwOutButton.Enabled = false; // initialize drag and drop // maybe this requires screen? m_dragAndDrop = new MyGuiControlGridDragAndDrop(MyGuiConstants.DRAG_AND_DROP_BACKGROUND_COLOR, MyGuiConstants.DRAG_AND_DROP_TEXT_COLOR, 0.7f, MyGuiConstants.DRAG_AND_DROP_TEXT_OFFSET, true); controlsParent.Controls.Add(m_dragAndDrop); m_dragAndDrop.DrawBackgroundTexture = false; m_throwOutButton.ButtonClicked += throwOutButton_OnButtonClick; m_dragAndDrop.ItemDropped += dragDrop_OnItemDropped; var thisInventoryOwner = m_userAsEntity as IMyInventoryOwner; if (thisInventoryOwner != null) m_userAsOwner = thisInventoryOwner; var targetInventoryOwner = m_interactedAsEntity as IMyInventoryOwner; if (targetInventoryOwner != null) m_interactedAsOwner = targetInventoryOwner; var parentGrid = (m_interactedAsEntity != null) ? m_interactedAsEntity.Parent as MyCubeGrid : null; m_interactedGridOwners.Clear(); if (parentGrid != null) { var group = MyCubeGridGroups.Static.Logical.GetGroup(parentGrid); foreach (var node in group.Nodes) { GetGridInventories(node.NodeData, m_interactedGridOwners); node.NodeData.GridSystems.ConveyorSystem.BlockAdded += ConveyorSystem_BlockAdded; node.NodeData.GridSystems.ConveyorSystem.BlockRemoved += ConveyorSystem_BlockRemoved; m_registeredConveyorSystems.Add(node.NodeData.GridSystems.ConveyorSystem); } } m_leftTypeGroup.SelectedIndex = 0; m_rightTypeGroup.SelectedIndex = (m_interactedAsEntity is MyCharacter) ? 0 : 1; m_leftFilterGroup.SelectedIndex = 0; m_rightFilterGroup.SelectedIndex = 0; LeftTypeGroup_SelectedChanged(m_leftTypeGroup); RightTypeGroup_SelectedChanged(m_rightTypeGroup); SetLeftFilter(null); SetRightFilter(null); m_leftTypeGroup.SelectedChanged += LeftTypeGroup_SelectedChanged; m_rightTypeGroup.SelectedChanged += RightTypeGroup_SelectedChanged; m_leftFilterAllButton.SelectedChanged += (button) => { if (button.Selected) SetLeftFilter(null); }; m_leftFilterEnergyButton.SelectedChanged += (button) => { if (button.Selected) SetLeftFilter(MyInventoryOwnerTypeEnum.Energy); }; m_leftFilterStorageButton.SelectedChanged += (button) => { if (button.Selected) SetLeftFilter(MyInventoryOwnerTypeEnum.Storage); }; m_leftFilterSystemButton.SelectedChanged += (button) => { if (button.Selected) SetLeftFilter(MyInventoryOwnerTypeEnum.System); }; m_rightFilterAllButton.SelectedChanged += (button) => { if (button.Selected) SetRightFilter(null); }; m_rightFilterEnergyButton.SelectedChanged += (button) => { if (button.Selected) SetRightFilter(MyInventoryOwnerTypeEnum.Energy); }; m_rightFilterStorageButton.SelectedChanged += (button) => { if (button.Selected) SetRightFilter(MyInventoryOwnerTypeEnum.Storage); }; m_rightFilterSystemButton.SelectedChanged += (button) => { if (button.Selected) SetRightFilter(MyInventoryOwnerTypeEnum.System); }; if (m_interactedAsEntity == null) { m_leftGridButton.Enabled = false; m_rightGridButton.Enabled = false; m_rightTypeGroup.SelectedIndex = 0; } RefreshSelectedInventoryItem(); ProfilerShort.End(); }