private void UpdateResources() { Debug.Log("Update Resources"); ConfigNode akResources = new ConfigNode(); FuelConfiguration akConfig = new FuelConfiguration(); if (selectedTankName == "") { selectedTankName = FuelConfigurations[selectedTank].ConfigName; } else if (FuelConfigurations[selectedTank].ConfigName == selectedTankName) { akConfig = FuelConfigurations[selectedTank]; } else { selectedTank = FuelConfigurations.IndexOf(FuelConfigurations.FirstOrDefault(g => g.ConfigName == selectedTankName)); akConfig = FuelConfigurations[selectedTank]; } int I = 0; int N = 0; while (I < part.Resources.Count) { part.Resources.Remove(part.Resources[I]); I++; } part.Resources.Clear(); // part.SetupResources(); I = 0; N = 0; while (I < akConfig.Fuels.Length) { Debug.Log("Resource: " + akConfig.Fuels[I] + " has a " + akConfig.MaxAmount[I] + " tank."); if (akConfig.MaxAmount[I] > 0) { part.AddResource(LoadResource(akConfig.Fuels[I], akConfig.Amount[I], akConfig.MaxAmount[I])); } else { N++; } I++; } if (N + 1 >= akConfig.Fuels.Length) { Fields["selectedFuel"].guiActive = false; } Debug.Log("New Fuels: " + akConfig.Fuels.Length); if (tweakableUI == null) { tweakableUI = part.FindActionWindow(); } if (tweakableUI != null) { tweakableUI.displayDirty = true; } // curEngineT.Save(akResources); Debug.Log("Resources Updated"); }
private void InitializeFuelSelector() { Debug.Log("[KSPI]: InitializeFuelSelector Setup Fuels Configurations for " + part.partInfo.title); var chooseField = Fields["selectedFuel"]; chooseOptionEditor = chooseField.uiControlEditor as UI_ChooseOption; chooseOptionFlight = chooseField.uiControlFlight as UI_ChooseOption; Debug.Log("[KSPI]: InitializeFuelSelector call ActiveConfigurations hideEmpty = " + hideEmpty); _activeConfigurations = ActiveConfigurations; if (_activeConfigurations.Count <= 1) { chooseField.guiActive = false; chooseField.guiActiveEditor = false; selectedFuel = 0; selectedTankName = ""; } else { chooseField.guiActive = true; chooseField.guiActiveEditor = true; Debug.Log("[KSPI]: InitializeFuelSelector Looking for config # " + selectedTankName); _currentActiveConfiguration = _activeConfigurations.FirstOrDefault(m => m.ConfigName == selectedTankName); if (_currentActiveConfiguration != null) { selectedFuel = _activeConfigurations.IndexOf(_currentActiveConfiguration); Debug.Log("[KSPI]: InitializeFuelSelector Found config # " + selectedTankName + " with index " + selectedFuel); } else if (_activeConfigurations.Count > 0) { selectedFuel = 0; Debug.Log("[KSPI]: InitializeFuelSelector Selecting fuel index # " + selectedFuel); _currentActiveConfiguration = _activeConfigurations[selectedFuel]; selectedTankName = _currentActiveConfiguration.fuelConfigurationName; } } var names = _activeConfigurations.Select(m => m.fuelConfigurationName).ToArray(); if (chooseOptionEditor != null) { chooseOptionEditor.options = names; } if (chooseOptionFlight != null) { chooseOptionFlight.options = names; } // connect on change event if (chooseField.guiActive && chooseOptionFlight != null) { chooseOptionFlight.onFieldChanged = UpdateFlightGUI; } if (chooseField.guiActiveEditor && chooseOptionEditor != null) { chooseOptionEditor.onFieldChanged = UpdateEditorGUI; } _currentActiveConfiguration = _activeConfigurations[selectedFuel]; }