private void Update() { if (Time.unscaledTime > lastConnectionUpdate + 10) { lastConnectionUpdate = Time.unscaledTime; // Only update in the editor, since that's the only place where we need to actively track the inventory. if (HighLogic.LoadedScene == GameScenes.EDITOR) { string bodyName; if (FlightGlobals.ActiveVessel != null) { bodyName = FlightGlobals.ActiveVessel.mainBody.bodyName; } else { bodyName = "Kerbin"; } if (XenoIndustrySignpost.IsConnected(bodyName)) { StartCoroutine(XenoIndustrySignpost.GetClusterioInventory(bodyName, clusterioInventory)); } } } }
private void Update() { if (Time.unscaledTime > lastConnectionUpdate + 10) { lastConnectionUpdate = Time.unscaledTime; // Periodically update Clusterio inventory if not ingame if (HighLogic.LoadedScene == GameScenes.SPACECENTER || HighLogic.LoadedScene == GameScenes.EDITOR || HighLogic.LoadedScene == GameScenes.TRACKSTATION) { string bodyName; if (FlightGlobals.ActiveVessel != null) { bodyName = FlightGlobals.ActiveVessel.mainBody.bodyName; } else { bodyName = "Kerbin"; } if (XenoIndustrySignpost.IsConnected(bodyName)) { StartCoroutine(XenoIndustrySignpost.GetClusterioInventory(bodyName, clusterioInventory)); } else { XenoIndustrySignpost.RefreshConnection(bodyName); } } } }
private void OnCargoWindowInternal(int id) { GUILayout.BeginVertical(); string bodyName; if (FlightGlobals.ActiveVessel != null) { bodyName = FlightGlobals.ActiveVessel.mainBody.bodyName; } else { bodyName = "Kerbin"; } if (!XenoIndustrySignpost.BodyHasServer(bodyName)) { GUILayout.Label("This celestial body has no associated master server."); } else if (!XenoIndustrySignpost.IsConnected(bodyName)) { GUILayout.Label("Cannot connect to Clusterio master server!"); GUILayout.Label("Error: " + XenoIndustrySignpost.GetConnectionError(bodyName)); if (GUILayout.Button("Refresh connection")) { XenoIndustrySignpost.RefreshConnection(bodyName); } } else if (FlightGlobals.ActiveVessel != null && FlightGlobals.ActiveVessel.situation != Vessel.Situations.LANDED && FlightGlobals.ActiveVessel.situation != Vessel.Situations.PRELAUNCH && FlightGlobals.ActiveVessel.situation != Vessel.Situations.SPLASHED) { GUILayout.Label("Cannot transfer cargo until vessel is landed"); } else { // Clusterio inventory handling if (HighLogic.LoadedScene == GameScenes.SPACECENTER || HighLogic.LoadedScene == GameScenes.EDITOR || HighLogic.LoadedScene == GameScenes.TRACKSTATION || HighLogic.LoadedScene == GameScenes.FLIGHT) { GUILayout.Label("Available inventory:"); if (clusterioInventory.Count > 0) { int spaceRemaining = (int)(windowActivePart.cargoResource.maxAmount - windowActivePart.cargoResource.amount); int netTransfer = 0; // Item names GUILayout.BeginHorizontal(); GUILayout.BeginVertical(); GUILayout.Label("Resource"); GUILayout.Space(8); foreach (KeyValuePair <string, int> kvPair in clusterioInventory) { GUILayout.Label(kvPair.Key + ":"); } GUILayout.EndVertical(); // Loaded cargo GUILayout.BeginVertical(); GUILayout.Label("Loaded"); GUILayout.Space(8); foreach (KeyValuePair <string, int> kvPair in clusterioInventory) { if (windowActivePart.carriedCargo.ContainsKey(kvPair.Key)) { GUILayout.Label(windowActivePart.carriedCargo[kvPair.Key].ToString()); } else { GUILayout.Label("0"); } } GUILayout.EndVertical(); // Item amount to transfer GUILayout.BeginVertical(); GUILayout.Label("Transfer"); GUILayout.Space(8); foreach (KeyValuePair <string, int> kvPair in clusterioInventory) { if (!cargoSelected.ContainsKey(kvPair.Key)) { cargoSelected[kvPair.Key] = 0; } int result; int.TryParse(GUILayout.TextField(cargoSelected[kvPair.Key].ToString()), out result); cargoSelected[kvPair.Key] = result; spaceRemaining -= result; netTransfer += result; } GUILayout.EndVertical(); // Items stocks GUILayout.BeginVertical(); GUILayout.Label("Available"); GUILayout.Space(8); foreach (KeyValuePair <string, int> kvPair in clusterioInventory) { GUILayout.Label(kvPair.Value.ToString()); } GUILayout.EndVertical(); GUILayout.EndHorizontal(); GUILayout.Space(8); // Remaining space GUILayout.BeginHorizontal(); GUILayout.Label("Space remaining:"); GUILayout.Label(spaceRemaining.ToString() + " / " + ((int)windowActivePart.cargoResource.maxAmount).ToString()); GUILayout.EndHorizontal(); // Net amount of items transferred to part GUILayout.BeginHorizontal(); GUILayout.Label("Net items transferred:"); GUILayout.Label(netTransfer.ToString()); GUILayout.EndHorizontal(); GUILayout.Space(8); GUILayout.Label(windowResponse); if (GUILayout.Button("Transfer cargo")) { // Check if we aren't trying to load more than the module can actually hold if (spaceRemaining < 0) { windowResponse = "Cannot load more cargo than the module can hold"; } else { bool success = true; // Check if we aren't trying to more cargo than the the server actually has foreach (KeyValuePair <string, int> kvPair in cargoSelected) { if (clusterioInventory.ContainsKey(kvPair.Key)) { if (kvPair.Value > clusterioInventory[kvPair.Key]) { windowResponse = String.Format("Cannot load {0} of item {1}, only {2} is available", kvPair.Value, kvPair.Key, clusterioInventory[kvPair.Key]); success = false; break; } } } // Check if we aren't trying to unload more cargo than the module has foreach (KeyValuePair <string, int> kvPair in cargoSelected) { if (kvPair.Value < 0) { if (!windowActivePart.carriedCargo.ContainsKey(kvPair.Key)) { windowResponse = String.Format("Cannot unload {0} item {1}, none currently loaded", kvPair.Value, kvPair.Key); success = false; break; } if (-kvPair.Value > windowActivePart.carriedCargo[kvPair.Key]) { windowResponse = String.Format("Cannot unload {0} of item {1}, only {2} currently loaded", kvPair.Value, kvPair.Key, windowActivePart.carriedCargo[kvPair.Key]); success = false; break; } } } if (success) { windowResponse = "Cargo transfer successful"; foreach (KeyValuePair <string, int> kvPair in cargoSelected) { // Sanity check if (kvPair.Value == 0) { continue; } Action <bool> cargoCallback = delegate(bool requestSuccessful) { if (requestSuccessful) { if (windowActivePart.carriedCargo.ContainsKey(kvPair.Key)) { windowActivePart.carriedCargo[kvPair.Key] += kvPair.Value; } else { windowActivePart.carriedCargo[kvPair.Key] = kvPair.Value; } } }; if (kvPair.Value > 0) { StartCoroutine(XenoIndustrySignpost.RemoveItemsFromClusterio(bodyName, clusterioInventory, kvPair.Key, kvPair.Value, cargoCallback)); } else { StartCoroutine(XenoIndustrySignpost.AddItemsToClusterio(bodyName, kvPair.Key, -kvPair.Value, cargoCallback)); } } windowActivePart.cargoResource.amount += netTransfer; cargoSelected.Clear(); } } } } else { GUILayout.Label("No cargo available for transfer."); } GUILayout.Space(16); if (GUILayout.Button("Refresh Clusterio inventory")) { StartCoroutine(XenoIndustrySignpost.GetClusterioInventory(bodyName, clusterioInventory)); } } } GUILayout.EndVertical(); // --- GUI.DragWindow(); }
private void OnWindowInternal(int id) { GUILayout.BeginVertical(); string bodyName = "Kerbin"; // Since this is for launching, only Kerbin is possible for now if (!XenoIndustrySignpost.BodyHasServer(bodyName)) { GUILayout.Label("This celestial body has no associated master server."); } else if (!XenoIndustrySignpost.IsConnected(bodyName)) { GUILayout.Label("Cannot connect to Clusterio master server!"); GUILayout.Label("Error: " + XenoIndustrySignpost.GetConnectionError(bodyName)); if (GUILayout.Button("Refresh connection")) { XenoIndustrySignpost.RefreshConnection(bodyName); } } else { // Show ship costs in editor if (HighLogic.LoadedScene == GameScenes.EDITOR) { //GUILayout.Space(16); //GUILayout.Label("", GUI.skin.horizontalSlider); //GUILayout.Space(8); if (latestLaunchCosts.Count > 0) { // Item names GUILayout.BeginHorizontal(); GUILayout.BeginVertical(); GUILayout.Label("Resource"); GUILayout.Space(8); foreach (KeyValuePair <string, int> kvPair in latestLaunchCosts) { GUILayout.Label(kvPair.Key + ":"); } GUILayout.EndVertical(); // Item costs GUILayout.BeginVertical(); GUILayout.Label("Required"); GUILayout.Space(8); foreach (KeyValuePair <string, int> kvPair in latestLaunchCosts) { GUILayout.Label(kvPair.Value.ToString()); } GUILayout.EndVertical(); // Items stocks GUILayout.BeginVertical(); GUILayout.Label("Available"); GUILayout.Space(8); foreach (KeyValuePair <string, int> kvPair in latestLaunchCosts) { GUILayout.Label((clusterioInventory.ContainsKey(kvPair.Key)) ? clusterioInventory[kvPair.Key].ToString() : 0.ToString()); } GUILayout.EndVertical(); GUILayout.EndHorizontal(); GUILayout.Space(8); if (GUILayout.Button("Refresh Clusterio inventory")) { StartCoroutine(XenoIndustrySignpost.GetClusterioInventory(bodyName, clusterioInventory)); } } else { GUILayout.Label("None"); } } } GUILayout.EndVertical(); // --- GUI.DragWindow(); }
private void OnCoreWindowInternal(int id) { GUILayout.BeginVertical(); string bodyName; if (FlightGlobals.ActiveVessel != null) { bodyName = FlightGlobals.ActiveVessel.mainBody.bodyName; } else { bodyName = "Kerbin"; } if (!XenoIndustrySignpost.BodyHasServer(bodyName)) { GUILayout.Label("This celestial body has no associated master server."); } else if (!XenoIndustrySignpost.IsConnected(bodyName)) { GUILayout.Label("Cannot connect to Clusterio master server!"); GUILayout.Label("Error: " + XenoIndustrySignpost.GetConnectionError(bodyName)); if (GUILayout.Button("Refresh connection")) { XenoIndustrySignpost.RefreshConnection(bodyName); } } else { // Clusterio inventory handling if (HighLogic.LoadedScene == GameScenes.SPACECENTER || HighLogic.LoadedScene == GameScenes.EDITOR || HighLogic.LoadedScene == GameScenes.TRACKSTATION || HighLogic.LoadedScene == GameScenes.FLIGHT) { GUILayout.Label("Clusterio inventory:"); if (clusterioInventory.Count > 0) { GUILayout.BeginHorizontal(); GUILayout.BeginVertical(); foreach (KeyValuePair <string, int> kvPair in clusterioInventory) { GUILayout.Label(kvPair.Key + ":"); } GUILayout.EndVertical(); GUILayout.BeginVertical(); foreach (KeyValuePair <string, int> kvPair in clusterioInventory) { GUILayout.Label(kvPair.Value.ToString()); } GUILayout.EndVertical(); GUILayout.EndHorizontal(); } else { GUILayout.Label("Clusterio inventory is empty."); } GUILayout.Space(8); if (GUILayout.Button("Refresh Clusterio inventory")) { StartCoroutine(XenoIndustrySignpost.GetClusterioInventory(bodyName, clusterioInventory)); } } if (debug) { if (GUILayout.Button("Add 1000 rocket component items")) { StartCoroutine(XenoIndustrySignpost.AddItemsToClusterio(bodyName, "low-density-structure", 1000)); StartCoroutine(XenoIndustrySignpost.AddItemsToClusterio(bodyName, "rocket-control-unit", 1000)); StartCoroutine(XenoIndustrySignpost.AddItemsToClusterio(bodyName, "solar-panel", 1000)); StartCoroutine(XenoIndustrySignpost.AddItemsToClusterio(bodyName, "uranium-238", 1000)); StartCoroutine(XenoIndustrySignpost.AddItemsToClusterio(bodyName, "accumulator", 1000)); StartCoroutine(XenoIndustrySignpost.AddItemsToClusterio(bodyName, "electric-mining-drill", 1000)); StartCoroutine(XenoIndustrySignpost.AddItemsToClusterio(bodyName, "electric-furnace", 1000)); StartCoroutine(XenoIndustrySignpost.AddItemsToClusterio(bodyName, "radar", 1000)); StartCoroutine(XenoIndustrySignpost.AddItemsToClusterio(bodyName, "processing-unit", 1000)); } if (GUILayout.Button("Add 1000 rocket fuel items")) { StartCoroutine(XenoIndustrySignpost.AddItemsToClusterio(bodyName, "rocket-fuel", 1000)); StartCoroutine(XenoIndustrySignpost.AddItemsToClusterio(bodyName, "explosives", 1000)); } if (GUILayout.Button("Write out CelestialBody names")) { XenoIndustrySignpost.WriteOutCelestialBodies(); } } } GUILayout.EndVertical(); // --- GUI.DragWindow(); }
private void OnClusterioWindowInternal(int id) { GUILayout.BeginVertical(); string bodyName = "Kerbin"; // Science transfer can only be done on Kerbin right now if (!XenoIndustrySignpost.BodyHasServer(bodyName)) { GUILayout.Label("This celestial body has no associated master server."); } else if (!XenoIndustrySignpost.IsConnected(bodyName)) { GUILayout.Label("Cannot connect to Clusterio master server!"); GUILayout.Label("Error: " + XenoIndustrySignpost.GetConnectionError(bodyName)); if (GUILayout.Button("Refresh connection")) { XenoIndustrySignpost.RefreshConnection(bodyName); } } else if (ResearchAndDevelopment.Instance == null) { GUILayout.Label("Cannot transfer science in sandbox mode!"); } else { // Science transfer to Factorio //if (HighLogic.LoadedScene == GameScenes.SPACECENTER || HighLogic.LoadedScene == GameScenes.EDITOR || HighLogic.LoadedScene == GameScenes.TRACKSTATION || HighLogic.LoadedScene == GameScenes.FLIGHT) if (HighLogic.LoadedScene == GameScenes.SPACECENTER || HighLogic.LoadedScene == GameScenes.TRACKSTATION || HighLogic.LoadedScene == GameScenes.FLIGHT) { /*GUILayout.Space(16); * GUILayout.Label("", GUI.skin.horizontalSlider); * GUILayout.Space(8);*/ int scienceTransferAmount = (int)(ResearchAndDevelopment.Instance.Science - (ResearchAndDevelopment.Instance.Science % sciencePerSciencePack)); GUILayout.Label(String.Format("Can use {0} science to transfer {1} science packs to Factorio.", scienceTransferAmount, (scienceTransferAmount / sciencePerSciencePack).ToString())); GUILayout.Space(8); if (GUILayout.Button("Transfer Science to Clusterio") && ResearchAndDevelopment.Instance != null) { Debug.Log("ClusterioTest: transferring science to Factorio"); StartCoroutine(TransferScienceToClusterio()); } GUILayout.Space(8); if (GUILayout.Button("Refresh Clusterio inventory")) { StartCoroutine(XenoIndustrySignpost.GetClusterioInventory(bodyName, clusterioInventory)); } } } GUILayout.EndVertical(); // --- GUI.DragWindow(); }