/// <summary>Creates a new part from save.</summary> public KIS_Item(AvailablePart availablePart, ConfigNode itemNode, ModuleKISInventory inventory, float quantity = 1) { // Get part node this.availablePart = availablePart; partNode = new ConfigNode(); itemNode.GetNode("PART").CopyTo(partNode); // init config this.InitConfig(availablePart, inventory, quantity); // Get mass if (itemNode.HasValue("resourceMass")) { resourceMass = float.Parse(itemNode.GetValue("resourceMass")); } else { resourceMass = availablePart.partPrefab.GetResourceMass(); } if (itemNode.HasValue("contentMass")) { contentMass = float.Parse(itemNode.GetValue("contentMass")); } if (itemNode.HasValue("contentCost")) { contentCost = float.Parse(itemNode.GetValue("contentCost")); } if (itemNode.HasValue("inventoryName")) { inventoryName = itemNode.GetValue("inventoryName"); } }
/// <summary>Adds the specified items into the inventory.</summary> /// <param name="inventory">An inventory to add items into.</param> /// <param name="itemNames">A list of names of the parts to add.</param> void AddItems(ModuleKISInventory inventory, List<string> itemNames) { foreach (var defItemName in itemNames) { var defPart = PartLoader.getPartInfoByName(defItemName); if (defPart != null) { inventory.AddItem(defPart.partPrefab); } else { Logger.logError("Cannot make item {0} specified as a default for the pod seat", defItemName); } } }
/// <summary> /// Checks if the current equipped equipment is different from the previous equipped equipment. /// Throws an event if equipment changed. /// </summary> /// <param name="inventory">Inventory to compare to the previous inventory.</param> private void CheckEquipmentChange(ModuleKISInventory inventory) { //No inventory. if (inventory == null) { //Only send "Changed" event if something changed. if (previousEquipment != null && EquipmentChanged != null) EquipmentChanged(this, null); previousEquipment = null; return; } //No items in inventory. if (inventory.items.Values.Count == 0) { //Only send "Changed" event if something changed. if (previousEquipment != null && EquipmentChanged != null) EquipmentChanged(this, null); previousEquipment = null; return; } //Items in inventory. foreach (KIS_Item item in inventory.items.Values) { if (!_equippedTools.Contains(item)) { //Only get equipped items. if (!item.equipped) continue; //Add equipped items. _equippedTools.Add(item); } //Remove unequipped items. else if (!item.equipped) _equippedTools.Remove(item); } //Only sent a "Changed" event when something changed. if ((previousEquipment == null || !previousEquipment.Equals(_equippedTools)) && EquipmentChanged != null) EquipmentChanged(this, _equippedTools); //Fire EquipmentChanged event. previousEquipment = _equippedTools.ToArray(); }
// New part from scene public KIS_Item(Part part, ModuleKISInventory inventory, float quantity = 1) { // Get part node this.availablePart = PartLoader.getPartInfoByName(part.partInfo.name); this.partNode = new ConfigNode(); KIS_Shared.PartSnapshot(part).CopyTo(this.partNode); // init config this.InitConfig(availablePart, inventory, quantity); // Get mass this.resourceMass = part.GetResourceMass(); ModuleKISInventory itemInventory = part.GetComponent<ModuleKISInventory>(); if (itemInventory) { this.contentMass = itemInventory.GetContentMass(); this.contentCost = itemInventory.GetContentCost(); if (itemInventory.invName != "") this.inventoryName = itemInventory.invName; } }
internal void OnRescale(ScalingFactor factor) { Log.dbg("OnRescale {0}:{1:X} to {2}", this.name, this.part.GetInstanceID(), factor.ToString()); KISP.ModuleKISInventory prefab = this.part.partInfo.partPrefab.Modules.GetModule <KISP.ModuleKISInventory>(); KISP.ModuleKISInventory part = this.part.Modules.GetModule <KISP.ModuleKISInventory>(); TweakScale.TweakScale ts_prefab = this.part.partInfo.partPrefab.Modules.GetModule <TweakScale.TweakScale>(); TweakScale.TweakScale ts_part = this.part.Modules.GetModule <TweakScale.TweakScale>(); part.maxVolume = prefab.maxVolume * factor.absolute.cubic; ts_part.DryCost = (float)(ts_prefab.DryCost * factor.absolute.cubic); if (this.increaseSlotsNumber) { //part.slotSize = prefab.slotSize; part.slotsX = (int)Math.Floor(prefab.slotsX * factor.absolute.linear); part.slotsY = (int)Math.Floor(prefab.slotsY * factor.absolute.linear); int slotsCount = part.slotsX * part.slotsY; if (slotsCount > prefab.slotsX * prefab.slotsY) { Log.dbg("before {0} {1}", part.maxVolume, ts_part.DryCost); part.maxVolume -= (float)(slotsCount * (0.0005 * part.maxVolume)); // Reduce volume by 0.05% per slot ts_part.DryCost += (float)(slotsCount * (0.001 * ts_part.DryCost)); // Add 0.1% of cost penalty per slot Log.dbg("after {0} {1}", part.maxVolume, ts_part.DryCost); } } else { //part.slotSize = (int)Math.Floor(prefab.slotSize * factor.absolute.linear); part.slotsX = prefab.slotsX; part.slotsY = prefab.slotsY; } // FIXME: Resize the Inventory Window size! Log.dbg("Current size : {0} maxVolume, {1} slotsX, {2} slotsX, {3} dry cost; {4} currentScale; {5} defaultScale", part.maxVolume, part.slotsX, part.slotsY, ts_part.DryCost, ts_part.currentScale, ts_part.defaultScale); }
public void MoveItems(Dictionary<int, KIS_Item> srcItems, ModuleKISInventory destInventory) { destInventory.items.Clear(); destInventory.items = new Dictionary<int, KIS_Item>(srcItems); foreach (KeyValuePair<int, KIS_Item> item in destInventory.items) { item.Value.inventory = destInventory; } srcItems.Clear(); srcItems = null; }
public static void MoveItem(KIS_Item srcItem, ModuleKISInventory tgtInventory, int tgtSlot) { ModuleKISInventory srcInventory = srcItem.inventory; int srcSlot = srcItem.slot; tgtInventory.items.Add(tgtSlot, srcItem); srcItem.inventory.items.Remove(srcSlot); srcItem.inventory = tgtInventory; tgtInventory.items[tgtSlot].OnMove(srcInventory, tgtInventory); srcInventory.RefreshMassAndVolume(); tgtInventory.RefreshMassAndVolume(); }
private IEnumerator WaitAndTransferItems(Dictionary<int, KIS_Item> transferedItems, ProtoCrewMember protoCrew, ModuleKISInventory srcInventory = null) { yield return new WaitForFixedUpdate(); InternalSeat seat = this.part.internalModel.seats[podSeat]; if (seat.crew == protoCrew) { MoveItems(transferedItems, this); KIS_Shared.DebugLog("Item transfer | destination :" + this.part.name + " (" + this.podSeat + ")"); this.RefreshMassAndVolume(); if (srcInventory) srcInventory.RefreshMassAndVolume(); } }
public static bool HasFreeSpace(ModuleKISInventory inventory, WorkshopItem item) { return inventory.GetContentVolume() + KIS_Shared.GetPartVolume(item.Part) <= inventory.maxVolume; }
public static bool IsOccupied(ModuleKISInventory inventory) { return inventory.invType != ModuleKISInventory.InventoryType.Pod || inventory.part.protoModuleCrew.Any(protoCrewMember => protoCrewMember.seatIdx == inventory.podSeat); }
public ModuleKISInventory(object obj) { _moduleKISInventory = (KIS.ModuleKISInventory)obj; }
public static bool HasFreeSlot(ModuleKISInventory inventory) { return !inventory.isFull(); }
private void AddNewItemToQueue() { if (_addedItem == null) { return; } _queue.Add(_addedItem); _addedItemInventory.DeleteItem(_addedItemKey); _addedItem = null; _addedItemInventory = null; _addedItemKey = -1; }
private void DrawAvailableItems() { GUILayout.BeginVertical(); _scrollPosItems = GUILayout.BeginScrollView(_scrollPosItems, WorkshopStyles.Databox(), GUILayout.Width(400f), GUILayout.Height(250f)); foreach (var inventory in part.vessel.FindPartModulesImplementing<ModuleKISInventory>()) { foreach (var item in inventory.items) { if (item.Value.icon == null) { item.Value.EnableIcon(128); } GUILayout.BeginHorizontal(); WorkshopGui.ItemThumbnail(item.Value.icon); WorkshopGui.ItemDescription(item.Value.availablePart, this.OutputResource, this.ConversionRate); if (GUILayout.Button("Queue", WorkshopStyles.Button(), GUILayout.Width(60f), GUILayout.Height(40f))) { _addedItem = new WorkshopItem(item.Value.availablePart); _addedItemKey = item.Key; _addedItemInventory = inventory; } GUILayout.EndHorizontal(); } } GUILayout.EndScrollView(); GUILayout.EndVertical(); }
private void InitConfig(AvailablePart availablePart, ModuleKISInventory inventory, float quantity) { this.inventory = inventory; this.quantity = quantity; this.prefabModule = availablePart.partPrefab.GetComponent<ModuleKISItem>(); this.volume = GetVolume(); this.cost = GetCost(); // Set launchID if (this.partNode.HasValue("launchID")) { if (int.Parse(this.partNode.GetValue("launchID")) == 0) { this.partNode.SetValue("launchID", this.inventory.part.launchID.ToString(), true); } } else { this.partNode.SetValue("launchID", this.inventory.part.launchID.ToString(), true); } if (this.prefabModule) { if (this.prefabModule.volumeOverride > 0) { this.volume = this.prefabModule.volumeOverride; } this.equipable = prefabModule.equipable; this.stackable = prefabModule.stackable; this.equipSlot = prefabModule.equipSlot; this.usableFromEva = prefabModule.usableFromEva; this.usableFromContainer = prefabModule.usableFromContainer; this.usableFromPod = prefabModule.usableFromPod; this.usableFromEditor = prefabModule.usableFromEditor; this.carriable = prefabModule.carriable; } int nonStackableModule = 0; foreach (PartModule pModule in availablePart.partPrefab.Modules) { if (!KISAddonConfig.stackableModules.Contains(pModule.moduleName)) { nonStackableModule++; } } if (nonStackableModule == 0 && GetResources().Count == 0) { KIS_Shared.DebugLog("No non-stackable module and ressource found on the part, set item as stackable"); this.stackable = true; } if (KISAddonConfig.stackableList.Contains(availablePart.name)) { KIS_Shared.DebugLog("Part name present in settings.cfg (node StackableItemOverride), force item as stackable"); this.stackable = true; } }
public virtual void OnDragToInventory(KIS_Item item, ModuleKISInventory destInventory, int destSlot) { }
private IEnumerator WaitAndTransferItems(Dictionary<int, KIS_Item> transferedItems, ProtoCrewMember protoCrew, ModuleKISInventory srcInventory = null) { yield return new WaitForFixedUpdate(); ProtoCrewMember crewAtPodSeat = this.part.protoModuleCrew.Find(x => x.seatIdx == podSeat); if (crewAtPodSeat == protoCrew) { MoveItems(transferedItems, this); KIS_Shared.DebugLog("Item transfer | destination :" + this.part.name + " (" + this.podSeat + ")"); this.RefreshMassAndVolume(); if (srcInventory) srcInventory.RefreshMassAndVolume(); } }
private void SetInventoryConfig(ConfigNode node, ModuleKISInventory moduleInventory) { if (node.HasValue("inventoryKey")) moduleInventory.evaInventoryKey = node.GetValue("inventoryKey"); if (node.HasValue("rightHandKey")) moduleInventory.evaRightHandKey = node.GetValue("rightHandKey"); if (node.HasValue("slotsX")) moduleInventory.slotsX = int.Parse(node.GetValue("slotsX")); if (node.HasValue("slotsY")) moduleInventory.slotsY = int.Parse(node.GetValue("slotsY")); if (node.HasValue("slotSize")) moduleInventory.slotSize = int.Parse(node.GetValue("slotSize")); if (node.HasValue("itemIconResolution")) moduleInventory.itemIconResolution = int.Parse(node.GetValue("itemIconResolution")); if (node.HasValue("selfIconResolution")) moduleInventory.selfIconResolution = int.Parse(node.GetValue("selfIconResolution")); if (node.HasValue("maxVolume")) moduleInventory.maxVolume = float.Parse(node.GetValue("maxVolume")); if (node.HasValue("openSndPath")) moduleInventory.openSndPath = node.GetValue("openSndPath"); if (node.HasValue("closeSndPath")) moduleInventory.closeSndPath = node.GetValue("closeSndPath"); }
void InitConfig(AvailablePart availablePart, ModuleKISInventory inventory, float quantity) { this.inventory = inventory; this.quantity = quantity; prefabModule = availablePart.partPrefab.GetComponent<ModuleKISItem>(); volume = KIS_Shared.GetPartVolume(availablePart); cost = GetCost(); // Set launchID if (partNode.HasValue("launchID")) { if (int.Parse(this.partNode.GetValue("launchID")) == 0) { partNode.SetValue("launchID", this.inventory.part.launchID.ToString(), true); } } else { partNode.SetValue("launchID", this.inventory.part.launchID.ToString(), true); } if (prefabModule) { equipable = prefabModule.equipable; stackable = prefabModule.stackable; equipSlot = prefabModule.equipSlot; usableFromEva = prefabModule.usableFromEva; usableFromContainer = prefabModule.usableFromContainer; usableFromPod = prefabModule.usableFromPod; usableFromEditor = prefabModule.usableFromEditor; carriable = prefabModule.carriable; } int nonStackableModule = 0; foreach (PartModule pModule in availablePart.partPrefab.Modules) { if (!KISAddonConfig.stackableModules.Contains(pModule.moduleName)) { nonStackableModule++; } } if (nonStackableModule == 0 && GetResources().Count == 0) { Logger.logInfo( "No non-stackable module or a resource found on the part, set the item as stackable"); stackable = true; } if (KISAddonConfig.stackableList.Contains(availablePart.name) || availablePart.name.IndexOf('.') != -1 && KISAddonConfig.stackableList.Contains(availablePart.name.Replace('.', '_'))) { Logger.logInfo("Part name present in settings.cfg (node StackableItemOverride)," + " force item as stackable"); stackable = true; } }
public void DragToInventory(ModuleKISInventory destInventory, int destSlot) { if (prefabModule) { prefabModule.OnDragToInventory(this, destInventory, destSlot); } }
public void OnMove(ModuleKISInventory srcInventory, ModuleKISInventory destInventory) { if (srcInventory != destInventory && equipped) { Unequip(); } if (prefabModule) { PlaySound(prefabModule.moveSndPath); } else { PlaySound(inventory.defaultMoveSndPath); } }