//private static Rect presetWindowRect = new Rect(Screen.width - 900 - presetWidth - margin, 40, presetWidth + margin, presetHeight + margin); //private static bool presetWindowOpen = false; public static void openGUI(ROEEngineThrustCurveGUI srbModule, string preset, FloatCurve inputCurve) { module = srbModule; id = module.GetInstanceID(); ROELog.debug("ThrustCurveEditor-input curve: " + curve + "\n" + ROEUtil.printFloatCurve(curve)); presetName = preset; setupCurveData(inputCurve); texture = new Texture2D(graphWidth, graphHeight); updateGraphTexture(); loadPresets(); if (activeGUI == null) { activeGUI = srbModule.gameObject.AddComponent <ThrustCurveEditorGUI>(); ROELog.debug("ROEngines - Created new gui object: " + activeGUI); } }
/// <summary> /// Initializes this module. Loads custom curve data from persistence if necessary, and updates the engine module with the currently loaded curve. /// </summary> private void initialize() { if (initialized) { return; } initialized = true; ROELog.debug("Initializing..."); if (currentCurve == null) { ROELog.debug("currentCurve is null"); if (!string.IsNullOrEmpty(customCurveData)) { ROELog.debug("Using customCurveData"); //load currentCurve from customCurveData currentCurve = new FloatCurve(); currentCurve.loadSingleLine(customCurveData); savedCurve = currentCurve.ToStringSingleLine(); thrustCurveName = part.partInfo.title + " Custom"; } else if (usePresetCurve && !string.IsNullOrEmpty(presetCurveName)) { ROELog.debug("Using presetCurve: " + presetCurveName); //load currentCurve from PresetCurve data loadPresetCurve(presetCurveName); thrustCurveName = presetCurveName; customCurveData = ""; } else { ROELog.debug("Using curve from existing Engine Module"); //init to the curve that exists in the engine already ModuleEnginesRF pm = part.Modules.GetModule <ModuleEnginesRF>(); usePresetCurve = true; thrustCurveName = part.partInfo.title + " Curve"; currentCurve = new FloatCurve(); currentCurve.loadSingleLine(pm.thrustCurve.ToStringSingleLine()); savedCurve = currentCurve.ToStringSingleLine(); } } updateEngineCurve(); }
private void loadPresetCurve(string presetName) { ConfigNode[] presetNodes = GameDatabase.Instance.GetConfigNodes("ROE_THRUSTCURVE"); ThrustCurvePreset preset; int len = presetNodes.Length; for (int i = 0; i < len; i++) { if (presetNodes[i].GetStringValue("name") == presetName) { ROELog.debug("Updating engine thrust curve data. Use preset: " + usePresetCurve); preset = new ThrustCurvePreset(presetNodes[i]); currentCurve = preset.curve; thrustCurveName = preset.name; savedCurve = currentCurve.ToStringSingleLine(); updateEngineCurve(); break; } } }
/// <summary> /// Applies the 'currentCurve' to the engine module as its active thrust curve. /// </summary> private void updateEngineCurve() { ROELog.debug("Updating engine curve"); if (currentCurve == null) // Code Error { ROELog.error("currentCurve is null"); return; } foreach (ModuleEnginesRF eng in part.FindModulesImplementing <ModuleEnginesRF>()) { ROELog.debug("currentCurve: " + currentCurve.ToStringSingleLine()); ROELog.debug("savedCurve: " + savedCurve); ROELog.debug("Engine curve set to: " + thrustCurveName); currentCurve = new FloatCurve(); currentCurve.loadSingleLine(savedCurve); eng.thrustCurve = currentCurve; ROELog.debug("savedCurve: " + savedCurve); ROELog.debug("New Curve: " + eng.thrustCurve.ToStringSingleLine()); } }