W_KIS_Item DrawInventoryItems(W_KIS_Item mouseOverItem) { // AvailableItems const int ItemRows = 10; const int ItemColumns = 3; var availableItems = KISWrapper.GetInventories(vessel).SelectMany(i => i.items).ToArray(); var maxPage = availableItems.Length / 30; for (var y = 0; y < ItemRows; y++) { for (var x = 0; x < ItemColumns; x++) { var left = 15 + x * 55; var top = 70 + y * 55; var itemIndex = y * ItemColumns + x; if (availableItems.Length > itemIndex) { var item = availableItems[itemIndex]; var icon = item.Value.Icon; if (icon == null) { item.Value.EnableIcon(64); icon = item.Value.Icon; } if (GUI.Button(new Rect(left, top, 50, 50), icon.texture)) { _queue.Add(new WorkshopItem(item.Value.availablePart)); item.Value.StackRemove(1); } if (item.Value.stackable) { GUI.Label(new Rect(left, top, 50, 50), item.Value.quantity.ToString("x#"), UI.UIStyles.lowerRightStyle); } if (Event.current.type == EventType.Repaint && new Rect(left, top, 50, 50).Contains(Event.current.mousePosition)) { mouseOverItem = item.Value; } } } } if (_activePage > 0) { if (GUI.Button(new Rect(15, 645, 75, 25), "Prev")) { _selectedPage = _activePage - 1; } } if (_activePage < maxPage) { if (GUI.Button(new Rect(100, 645, 75, 25), "Next")) { _selectedPage = _activePage + 1; } } return(mouseOverItem); }
public void ContextMenuOpenRecycler() { if (_showGui) { foreach (var inventory in KISWrapper.GetInventories(vessel).Where(i => i.showGui == false).ToList()) { foreach (var item in inventory.items) { item.Value.DisableIcon(); } foreach (var item in _queue) { item.DisableIcon(); } if (_processedItem != null) { _processedItem.DisableIcon(); } } _showGui = false; } else { if (!WorkshopUtils.PreLaunch()) { _showGui = true; } else { ScreenMessages.PostScreenMessage("Recycler is in travel mode, unable to print at this time", 5, ScreenMessageStyle.UPPER_CENTER); } } }
public void ContextMenuOnOpenRecycler() { if (_showGui) { foreach (var inventory in KISWrapper.GetInventories(vessel).Where(i => i.showGui == false).ToList()) { foreach (var item in inventory.items) { item.Value.DisableIcon(); } foreach (var item in _queue) { item.DisableIcon(); } if (_processedItem != null) { _processedItem.DisableIcon(); } } _showGui = false; } else { _showGui = true; } }
public override void OnAwake() { base.OnAwake(); try { IsKISAvailable = KISWrapper.Initialize(); } catch (Exception ex) { IsKISAvailable = false; WorkshopUtils.LogError("Error while checking for KIS. Workshop will be disabled", ex); } }
private void ApplyPaging() { if (_activePage != _selectedPage) { foreach (var inventory in KISWrapper.GetInventories(vessel).Where(i => i.showGui == false).ToList()) { foreach (var item in inventory.items) { item.Value.DisableIcon(); } } _activePage = _selectedPage; } }
public override void OnLoad(ConfigNode node) { if (HighLogic.LoadedSceneIsFlight) { UpdateCrewCapacity(false); } if (HighLogic.LoadedScene == GameScenes.LOADING) { if (KISWrapper.Initialize()) { KISWrapper.AddPodInventories(part, crewCapacityDeployed); } } }
public void Repair() { if (repairInProgress) { StopCoroutine(coroutine); repairInProgress = false; Events["Repair"].guiName = "Start Repair"; } else { if (part.protoModuleCrew.Count < 1) { RepairStatus = "No Crew to do repairs"; Fields["RepairStatus"].guiActive = true; return; } double availDuctTape = 0; // check to see if duct tape is in inventory of module occupants var availableItems = KISWrapper.GetInventories(this.part).SelectMany(i => i.items).ToArray(); ductTapeInInventory = new List <KeyValuePair <int, W_KIS_Item> >(); foreach (KeyValuePair <int, W_KIS_Item> i in availableItems) { Log.Info("Part in inventory: " + i.Value.availablePart.name + ", " + i.Value.quantity); if (i.Value.availablePart.name == DUCTTAPEPART) { double?res = KISAPI.PartNodeUtils.UpdateResource(i.Value.partNode, DUCTTAPERESOURCE, 0, true); availDuctTape += (double)res; ductTapeInInventory.Add(i); } } if (availDuctTape > 0) { Events["Repair"].guiName = "Stop Repair"; repairInProgress = true; coroutine = StartCoroutine(DoRepair(availDuctTape)); } } }
private void LoadMaxVolume() { try { var inventories = KISWrapper.GetInventories(vessel); if (inventories.Count == 0) { WorkshopUtils.LogError("No Inventories found on this vessel!"); } else { WorkshopUtils.Log(inventories.Count + " inventories found on this vessel!"); _maxVolume = inventories.Max(i => i.maxVolume); } } catch (Exception ex) { WorkshopUtils.LogError("Error while determing maximum volume of available inventories!", ex); } WorkshopUtils.Log($"Max volume is: {_maxVolume} liters"); }
private void LoadMaxVolume() { try { var inventories = KISWrapper.GetInventories(vessel); if (inventories.Count == 0) { Debug.Log("[OSE] - No Inventories found on this vessel!"); } else { Debug.Log("[OSE] - " + inventories.Count + " inventories found on this vessel!"); _maxVolume = inventories.Max(i => i.maxVolume); } } catch (Exception ex) { Debug.LogError("[OSE] - Error while determing maximum volume of available inventories!"); Debug.LogError("[OSE] - " + ex.Message); Debug.LogError("[OSE] - " + ex.StackTrace); } Debug.Log("[OSE] - Max volume is: " + _maxVolume + " liters"); }
public static float GetPackedPartVolume(AvailablePart part) { var moduleKisItem = KISWrapper.GetKisItem(part.partPrefab); return(moduleKisItem != null ? moduleKisItem.volumeOverride : KIS_Shared.GetPartVolume(part)); }
private ModuleKISInventory AddToContainer(WorkshopItem item) { var inventories = KISWrapper.GetInventories(vessel); if (inventories == null || inventories.Count == 0) { throw new Exception("No KIS Inventory found!"); } var freeInventories = inventories .Where(i => WorkshopUtils.HasFreeSpace(i, item)) .Where(WorkshopUtils.HasFreeSlot) .Where(WorkshopUtils.IsOccupied) .ToArray(); if (freeInventories.Any()) { // first pass with favored inventories var favoredInventories = freeInventories .Where(i => i.part.GetComponent <OseModuleInventoryPreference>() != null) .Where(i => i.part.GetComponent <OseModuleInventoryPreference>().IsFavored).ToArray(); foreach (var inventory in favoredInventories) { var kisItem = inventory.AddItem(item.Part.partPrefab); if (kisItem == null) { throw new Exception("Error adding item " + item.Part.name + " to inventory"); } foreach (var resourceInfo in kisItem.GetResources()) { if (WorkshopRecipeDatabase.HasResourceRecipe(resourceInfo.resourceName)) { kisItem.SetResource(resourceInfo.resourceName, (int)resourceInfo.maxAmount); } else { kisItem.SetResource(resourceInfo.resourceName, 0); } } return(inventory); } // second pass with the rest foreach (var inventory in freeInventories) { var kisItem = inventory.AddItem(item.Part.partPrefab); if (kisItem == null) { throw new Exception("Error adding item " + item.Part.name + " to inventory"); } foreach (var resourceInfo in kisItem.GetResources()) { if (WorkshopRecipeDatabase.HasResourceRecipe(resourceInfo.resourceName)) { kisItem.SetResource(resourceInfo.resourceName, (int)resourceInfo.maxAmount); } else { kisItem.SetResource(resourceInfo.resourceName, 0); } } return(inventory); } } return(null); }
private void DrawWindowContents(int windowId) { WorkshopItem mouseOverItem = null; KIS_Item mouseOverItemKIS = null; // styles var statsStyle = new GUIStyle(GUI.skin.box); statsStyle.fontSize = 11; statsStyle.alignment = TextAnchor.UpperLeft; statsStyle.padding.left = statsStyle.padding.top = 5; var tooltipDescriptionStyle = new GUIStyle(GUI.skin.box); tooltipDescriptionStyle.fontSize = 11; tooltipDescriptionStyle.alignment = TextAnchor.UpperCenter; tooltipDescriptionStyle.padding.top = 5; var queueSkin = new GUIStyle(GUI.skin.box); queueSkin.alignment = TextAnchor.UpperCenter; queueSkin.padding.top = 5; var lowerRightStyle = new GUIStyle(GUI.skin.label); lowerRightStyle.alignment = TextAnchor.LowerRight; lowerRightStyle.fontSize = 10; lowerRightStyle.padding = new RectOffset(4, 4, 4, 4); lowerRightStyle.normal.textColor = Color.white; // AvailableItems const int ItemRows = 10; const int ItemColumns = 3; var availableItems = KISWrapper.GetInventories(vessel).SelectMany(i => i.items).ToArray(); var maxPage = availableItems.Length / 30; for (var y = 0; y < ItemRows; y++) { for (var x = 0; x < ItemColumns; x++) { var left = 15 + x * 55; var top = 70 + y * 55; var itemIndex = y * ItemColumns + x; if (availableItems.Length > itemIndex) { var item = availableItems[itemIndex]; if (item.Value.Icon == null) { item.Value.EnableIcon(64); } if (GUI.Button(new Rect(left, top, 50, 50), item.Value.Icon.texture)) { _queue.Add(new WorkshopItem(item.Value.availablePart)); item.Value.StackRemove(1); } if (item.Value.stackable) { GUI.Label(new Rect(left, top, 50, 50), item.Value.quantity.ToString("x#"), lowerRightStyle); } if (Event.current.type == EventType.Repaint && new Rect(left, top, 50, 50).Contains(Event.current.mousePosition)) { mouseOverItemKIS = item.Value; } } } } if (_activePage > 0) { if (GUI.Button(new Rect(15, 645, 75, 25), "Prev")) { _selectedPage = _activePage - 1; } } if (_activePage < maxPage) { if (GUI.Button(new Rect(100, 645, 75, 25), "Next")) { _selectedPage = _activePage + 1; } } // Queued Items const int QueueRows = 4; const int QueueColumns = 7; GUI.Box(new Rect(190, 345, 440, 270), "Queue", queueSkin); for (var y = 0; y < QueueRows; y++) { for (var x = 0; x < QueueColumns; x++) { var left = 205 + x * 60; var top = 370 + y * 60; var itemIndex = y * QueueColumns + x; if (_queue.Count > itemIndex) { var item = _queue[itemIndex]; if (item.Icon == null) { item.EnableIcon(64); } if (GUI.Button(new Rect(left, top, 50, 50), item.Icon.texture)) { _queue.Remove(item); } if (Event.current.type == EventType.Repaint && new Rect(left, top, 50, 50).Contains(Event.current.mousePosition)) { mouseOverItem = item; } } } } // Tooltip GUI.Box(new Rect(190, 70, 440, 270), ""); if (mouseOverItem != null) { var blueprint = WorkshopRecipeDatabase.ProcessPart(mouseOverItem.Part); foreach (var resource in blueprint) { resource.Units *= ConversionRate; } GUI.Box(new Rect(200, 80, 100, 100), mouseOverItem.Icon.texture); GUI.Box(new Rect(310, 80, 150, 100), WorkshopUtils.GetKisStats(mouseOverItem.Part), statsStyle); GUI.Box(new Rect(470, 80, 150, 100), blueprint.Print(adjustedProductivity), statsStyle); GUI.Box(new Rect(200, 190, 420, 140), WorkshopUtils.GetDescription(mouseOverItem.Part), tooltipDescriptionStyle); } else if (mouseOverItemKIS != null) { var blueprint = WorkshopRecipeDatabase.ProcessPart(mouseOverItemKIS.availablePart); foreach (var resource in blueprint) { resource.Units *= ConversionRate; } GUI.Box(new Rect(200, 80, 100, 100), mouseOverItemKIS.Icon.texture); GUI.Box(new Rect(310, 80, 150, 100), WorkshopUtils.GetKisStats(mouseOverItemKIS.availablePart), statsStyle); GUI.Box(new Rect(470, 80, 150, 100), blueprint.Print(adjustedProductivity), statsStyle); GUI.Box(new Rect(200, 190, 420, 140), WorkshopUtils.GetDescription(mouseOverItemKIS.availablePart), tooltipDescriptionStyle); } // Currently build item if (_processedItem != null) { if (_processedItem.Icon == null) { _processedItem.EnableIcon(64); } GUI.Box(new Rect(190, 620, 50, 50), _processedItem.Icon.texture); } else { GUI.Box(new Rect(190, 620, 50, 50), ""); } // Progressbar GUI.Box(new Rect(250, 620, 260, 50), ""); if (progress >= 1) { var color = GUI.color; GUI.color = new Color(0, 1, 0, 1); GUI.Box(new Rect(250, 620, 260 * progress / 100, 50), ""); GUI.color = color; } GUI.Label(new Rect(250, 620, 260, 50), " " + progress.ToString("0.0") + " / 100"); // Toolbar if (recyclingPaused) { if (GUI.Button(new Rect(520, 620, 50, 50), _playTexture)) { recyclingPaused = false; } } else { if (GUI.Button(new Rect(520, 620, 50, 50), _pauseTexture)) { recyclingPaused = true; } } if (GUI.Button(new Rect(580, 620, 50, 50), _binTexture)) { this.CancelManufacturing(); } if (GUI.Button(new Rect(_windowPos.width - 25, 5, 20, 20), "X")) { this.ContextMenuOnOpenRecycler(); } GUI.DragWindow(); }