public override void OnEquip(KIS_Item item) { base.OnEquip(item); Vessel v = FlightGlobals.ActiveVessel; if (v.isEVA) { foreach (PartResource r in base.part.Resources) { if (!v.rootPart.Resources.Contains(r.resourceName)) { ConfigNode i = new ConfigNode("RESOURCE"); i.AddValue("name", r.resourceName); i.AddValue("amount", 0); i.AddValue("maxAmount", r.maxAmount); v.rootPart.Resources.Add(i); } else { ConfigNode i = new ConfigNode("RESOURCE"); i.AddValue("name", r.resourceName); i.AddValue("amount", 0); i.AddValue("maxAmount", r.maxAmount); v.rootPart.SetResource(i); } } } }
void DrawMouseOverItem(WorkshopItem mouseOverItem, KIS_Item mouseOverItemKIS) { // Tooltip adjustedProductivity = WorkshopUtils.GetProductivityBonus(part, ExperienceEffect, SpecialistEfficiencyFactor, ProductivityFactor); 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), UI.UIStyles.StatsStyle); GUI.Box(new Rect(470, 80, 150, 100), blueprint.Print(adjustedProductivity), UI.UIStyles.StatsStyle); GUI.Box(new Rect(200, 190, 420, 25), mouseOverItem.Part.title, UI.UIStyles.TitleDescriptionStyle); GUI.Box(new Rect(200, 220, 420, 110), mouseOverItem.Part.description, UI.UIStyles.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), UI.UIStyles.StatsStyle); GUI.Box(new Rect(470, 80, 150, 100), blueprint.Print(adjustedProductivity), UI.UIStyles.StatsStyle); GUI.Box(new Rect(200, 190, 420, 25), mouseOverItemKIS.availablePart.title, UI.UIStyles.TitleDescriptionStyle); GUI.Box(new Rect(200, 220, 420, 110), mouseOverItemKIS.availablePart.description, UI.UIStyles.TooltipDescriptionStyle); } }
public override void OnItemUse(KIS_Item item, KIS_Item.UseFrom useFrom) { string shipProp = this.settings.ShipPropellantName; string evaProp = this.settings.EvaPropellantName; if (useFrom != KIS_Item.UseFrom.KeyUp && item.inventory.invType == ModuleKISInventory.InventoryType.Pod) { double fuelLeft = 0; double fuelMax = 0; fuelLeft = GetCanisterFuelResource(item).amount; fuelMax = GetCanisterFuelResource(item).maxAmount; double fuelRequest = item.inventory.part.RequestResource(shipProp, fuelMax - fuelLeft); item.SetResource(evaProp, fuelLeft + fuelRequest); if (fuelRequest < fuelMax - fuelLeft) { ScreenMessaging.ShowPriorityScreenMessage("Warning! Only " + Math.Round(fuelRequest, 2).ToString() + " units of " + shipProp + " were left to fill the tank!"); } else { ScreenMessaging.ShowPriorityScreenMessage("Fuel tank refueled with " + Math.Round(fuelRequest, 2).ToString() + " units of " + shipProp + "."); } UISoundPlayer.instance.Play(refuelSndPath); } else { base.OnItemUse(item, useFrom); } }
private void unloadCargo() { if (Events ["stopUnloadCargo"].active) { KIS_Item found = findCargo(); if (found == null) { updateMenu(); return; } ModuleKISInventory tgtInventory = findStorageFor(null); if (tgtInventory == null) { Debug.Log("No target Inventory found"); return; } if (!tgtInventory.showGui) { tgtInventory.ShowInventory(); } ModuleKISInventory.MoveItem(found, tgtInventory, tgtInventory.GetFreeSlot()); Invoke("unloadCargo", calculateDelay(found.availablePart, false)); } else { updateMenu(); } }
KIS_Item DrawInventoryItems(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]; 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#"), 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); }
private KIS_Item findCargo(Part search_at, Part search_for = null) { if (search_at == null) { Debug.Log("no search_at"); return(null); } ModuleKISInventory[] itemInventorys = search_at.GetComponents <ModuleKISInventory> (); foreach (ModuleKISInventory itemInventory in itemInventorys) { if (itemInventory.invType != ModuleKISInventory.InventoryType.Container) { continue; } if (!itemInventory.externalAccess) { continue; } if (!itemInventory.showGui) { itemInventory.ShowInventory(); } foreach (KeyValuePair <int, KIS_Item> item in itemInventory.items) { if (item.Value == null) { continue; } if (search_for == null) { return(item.Value); } if (item.Value.availablePart.name == search_for.name) { return(item.Value); } } } foreach (Part new_search_at in search_at.children) { KIS_Item found = findCargo(new_search_at, search_for); if (found != null) { return(found); } } return(null); }
private KIS_Item findCargo() { KIS_Item found = null; foreach (string node in assemblyNodes.Split(',')) { AttachNode search_in = part.FindAttachNode(node.Trim()); found = findCargo(search_in.attachedPart); if (found != null) { break; } } return(found); }
/// <summary>Spawns the item in the inventory.</summary> void GuiSpawnItems(AvailablePart avPart) { int quantity; if (!int.TryParse(createQuantity, out quantity) || quantity < 1) { quantity = 1; DebugEx.Error("Wrong quantity: selected='{0}', fallback={1}", createQuantity, quantity); } if (quantity > 1 && !KIS_Item.CheckItemStackable(avPart)) { quantity = 1; DebugEx.Warning("Part {0} is not stackable. Only adding 1 item", avPart.name); } tgtInventory.AddItem(avPart.partPrefab, qty: quantity); }
private void DrawWindowContents(int windowId) { WorkshopItem mouseOverItem = null; KIS_Item mouseOverItemKIS = null; mouseOverItemKIS = DrawInventoryItems(mouseOverItemKIS); mouseOverItem = DrawQueue(mouseOverItem); DrawMouseOverItem(mouseOverItem, mouseOverItemKIS); DrawRecyclingProgress(); if (GUI.Button(new Rect(_windowPos.width - 25, 5, 20, 20), "X")) { ContextMenuOnOpenRecycler(); } GUI.DragWindow(); }
public override void OnItemUse(KIS_Item item, KIS_Item.UseFrom useFrom) { if (ModEnabled && KISIntegrationEnabled) { if (useFrom != KIS_Item.UseFrom.KeyUp && item.inventory.invType == ModuleKISInventory.InventoryType.Pod) { double fuelLeft = 0; double fuelMax = 0; fuelLeft = ModuleKISItemEvaPropellant.GetCanisterFuelResource(item).amount; fuelMax = ModuleKISItemEvaPropellant.GetCanisterFuelResource(item).maxAmount; double takenFuel = item.inventory.part.RequestResource(shipPropName, (fuelMax - fuelLeft) / fuelConvFactor); double fuelRequest = takenFuel * fuelConvFactor; item.UpdateResource(resourceName, fuelLeft + fuelRequest); if (fuelRequest + 0.001 < fuelMax - fuelLeft) //0.001 for floating point rounding issues. Don't want to trigger insufficient fuel all the time. { if (ShowLowFuelWarning) { PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), "OnItemUse", "Low EVA Fuel!", "Warning! Only " + Math.Round(takenFuel, 2).ToString() + " units of " + shipPropName + " were available to refill the EVA Canister! Meaning it only has " + Math.Round(fuelLeft + fuelRequest, 2).ToString() + " units of " + resourceName + "!", "OK", false, HighLogic.UISkin); } } else { if (ShowInfoMessage) { ScreenMessaging.ShowPriorityScreenMessage("Fuel tank refueled with " + Math.Round(takenFuel, 2).ToString() + " units of " + shipPropName + "."); } } UISoundPlayer.instance.Play(refuelSndPath); } else { base.OnItemUse(item, useFrom); } } else { base.OnItemUse(item, useFrom); } }
public bool isWeldingTool = false; // false => screw tool // check if the pointed part can be attach with our current tool public override void OnItemUse(KIS_Item item, KIS_Item.UseFrom useFrom) { // Check if grab key is pressed //if (useFrom == KIS_Item.UseFrom.KeyDown) //{ // KISAddonPickup.instance.EnableAttachMode(); //} // Check if grab key is pressed if (useFrom == KIS_Item.UseFrom.KeyDown) { if (KISAddonPointer.isRunning && KISAddonPointer.pointerTarget != KISAddonPointer.PointerTarget.PartMount) { //float attachPartMass = KISAddonPointer.partToAttach.mass + KISAddonPointer.partToAttach.GetResourceMass(); //if (attachPartMass < attachMaxMass) { //test if the tool can attach this part (screw or weld) //default (when ModuleAttachMode is not here) : magical yes bool testIfCanAttachPart = true; if (KISAddonPointer.partToAttach.Modules.Contains("ModuleAttachMode")) { ModuleAttachMode mkpam = (KISAddonPointer.partToAttach.Modules["ModuleAttachMode"] as ModuleAttachMode); if (!mkpam.canBeWeld && !mkpam.canBeScrewed) { ScreenMessages.PostScreenMessage("This part can't be attached", 5, ScreenMessageStyle.UPPER_CENTER); testIfCanAttachPart = false; } else { testIfCanAttachPart = isWeldingTool ? mkpam.canBeWeld : mkpam.canBeScrewed; item.PlaySound(KIS_Shared.bipWrongSndPath); if (!testIfCanAttachPart) { ScreenMessages.PostScreenMessage("This part can't be attached with this tool: it need a " + (isWeldingTool ? "screwdriver" : "weld tool"), 5, ScreenMessageStyle.UPPER_CENTER); } } } if (testIfCanAttachPart) { //KISAddonPickup.instance.pointerMode = KISAddonPickup.PointerMode.Attach; //KISAddonPointer.allowStack = allowStack; //item.PlaySound(changeModeSndPath); KISAddonPickup.instance.EnableAttachMode(); } } //else //{ // item.PlaySound(KIS_Shared.bipWrongSndPath); // ScreenMessages.PostScreenMessage("This part is too heavy for this tool", 5, ScreenMessageStyle.UPPER_CENTER); //} } if (useFrom == KIS_Item.UseFrom.KeyUp) { KISAddonPickup.instance.DisableAttachMode(); } } //if (useFrom == KIS_Item.UseFrom.KeyUp) //{ // if (KISAddonPointer.isRunning && KISAddonPickup.instance.pointerMode == KISAddonPickup.PointerMode.Attach) // { // KISAddonPickup.instance.pointerMode = KISAddonPickup.PointerMode.Drop; // KISAddonPointer.allowStack = false; // item.PlaySound(changeModeSndPath); // } //} }
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(); }