private void SetupIGeometryUpdaters() { geometryUpdaters = new List <IGeometryUpdater>(); if (part is CompoundPart) { CompoundPartGeoUpdater compoundUpdate = new CompoundPartGeoUpdater((CompoundPart)part, this); geometryUpdaters.Add(compoundUpdate); } if (part.Modules.Contains("ModuleProceduralFairing")) { ModuleProceduralFairing[] fairings = part.GetComponents <ModuleProceduralFairing>(); for (int i = 0; i < fairings.Length; i++) { ModuleProceduralFairing fairing = fairings[i]; StockProcFairingGeoUpdater fairingUpdater = new StockProcFairingGeoUpdater(fairing, this); geometryUpdaters.Add(fairingUpdater); } } if (part.Modules.Contains("ModuleJettison")) { ModuleJettison[] engineFairings = part.GetComponents <ModuleJettison>(); for (int i = 0; i < engineFairings.Length; i++) { ModuleJettison engineFairing = engineFairings[i]; StockJettisonTransformGeoUpdater fairingUpdater = new StockJettisonTransformGeoUpdater(engineFairing, this); geometryUpdaters.Add(fairingUpdater); } } }
public StockJettisonTransformGeoUpdater(ModuleJettison engineFairing, GeometryPartModule geoModule) { this.engineFairing = engineFairing; this.geoModule = geoModule; if (ObjectsNotNull()) fairingVisible = engineFairing.jettisonTransform.gameObject.activeSelf && !engineFairing.isJettisoned; else fairingVisible = false; }
public void JettisonEvent(ModuleJettison jettisonModule, KSPActionParam param) { Debug.Log("JettisonEvent called for " + jettisonModule.jettisonName + " with param=" + param); jettisonModule.JettisonAction(param); this.hasJettisonedTable[jettisonModule.jettisonName] = true; this.Events[string.Format("{0}{1}", jettisonModule.jettisonName, "jettisonEvent")].guiActive = false; }
private void UpdateSequentialFire() { saveSequentialFire = sequentialFire; engine = part.FindModulesImplementing <ModuleEngines>().FirstOrDefault(); if (engine != null) { //stagingEnabled = engine.stagingEnabled && sequentialFire; engine.stagingEnabled = !sequentialFire; } jettison = part.FindModulesImplementing <ModuleJettison>().FirstOrDefault(); if (jettison != null) { jettison.stagingEnabled = !sequentialFire; } }
//Executes when shroud is enabled/disabled void activeToggled(object arg) { Part topPart = GetShroudedPart(); if (topPart != null) { engineShroud = topPart.GetComponent <ModuleJettison>(); if (engineShroud != null) { engineShroud.shroudHideOverride = shroudEnabled; } } setButtonActive(); detectSize(); updateShroud(); }
void GetReferences() { decouplerModule = this.part.FindModuleImplementing <ModuleDecouple>(); decouplerPartModule = decouplerModule; crossfeedToggleModule = this.part.FindModuleImplementing <ModuleToggleCrossfeed>(); ModuleJettison moduleJettison = this.part.FindModuleImplementing <ModuleJettison>(); pmEvents = Events; if (decouplerModule == null) { Log.Info("ModuleDecouple NOT found"); } else { Log.Info("ModuleDecouple found"); } }
private void SetupIGeometryUpdaters() { geometryUpdaters = new List<IGeometryUpdater>(); if(part is CompoundPart) { CompoundPartGeoUpdater compoundUpdate = new CompoundPartGeoUpdater((CompoundPart)part, this); geometryUpdaters.Add(compoundUpdate); } if(part.Modules.Contains<ModuleProceduralFairing>()) { List<ModuleProceduralFairing> fairings = part.Modules.GetModules<ModuleProceduralFairing>(); for (int i = 0; i < fairings.Count; ++i) { ModuleProceduralFairing fairing = fairings[i]; StockProcFairingGeoUpdater fairingUpdater = new StockProcFairingGeoUpdater(fairing, this); geometryUpdaters.Add(fairingUpdater); } } if(part.Modules.Contains<ModuleJettison>()) { List<ModuleJettison> engineFairings = part.Modules.GetModules<ModuleJettison>(); for (int i = 0; i < engineFairings.Count; ++i) { ModuleJettison engineFairing = engineFairings[i]; StockJettisonTransformGeoUpdater fairingUpdater = new StockJettisonTransformGeoUpdater(engineFairing, this); geometryUpdaters.Add(fairingUpdater); } } if (part.Modules.Contains<ModuleAsteroid>()) { ModuleAsteroid asteroidModule = part.Modules.GetModule<ModuleAsteroid>(); StockProcAsteroidGeoUpdater asteroidUpdater = new StockProcAsteroidGeoUpdater(asteroidModule, this); geometryUpdaters.Add(asteroidUpdater); } }
private List <MeshData> CreateMeshListFromTransforms(ref List <Transform> meshTransforms) { List <MeshData> meshList = new List <MeshData>(); List <Transform> validTransformList = new List <Transform>(); if (part.Modules.Contains <KerbalEVA>() || part.Modules.Contains <FlagSite>()) { Debug.Log("Adding vox box to Kerbal / Flag"); meshList.Add(CreateBoxMeshForKerbalEVA()); validTransformList.Add(part.partTransform); meshTransforms = validTransformList; return(meshList); } Bounds rendererBounds = this.part.GetPartOverallMeshBoundsInBasis(part.partTransform.worldToLocalMatrix); Bounds colliderBounds = this.part.GetPartColliderBoundsInBasis(part.partTransform.worldToLocalMatrix); bool cantUseColliders = true; bool isFairing = part.Modules.Contains <ModuleProceduralFairing>() || part.Modules.Contains("ProceduralFairingSide"); bool isDrill = part.Modules.Contains <ModuleAsteroidDrill>() || part.Modules.Contains <ModuleResourceHarvester>(); //Voxelize colliders if ((forceUseColliders || isFairing || isDrill || (rendererBounds.size.x * rendererBounds.size.z < colliderBounds.size.x * colliderBounds.size.z * 1.6f && rendererBounds.size.y < colliderBounds.size.y * 1.2f && (rendererBounds.center - colliderBounds.center).magnitude < 0.3f)) && !forceUseMeshes) { foreach (Transform t in meshTransforms) { MeshData md = GetColliderMeshData(t); if (md == null) { continue; } meshList.Add(md); validTransformList.Add(t); cantUseColliders = false; } } if (part.Modules.Contains <ModuleJettison>()) { List <ModuleJettison> jettisons = part.Modules.GetModules <ModuleJettison>(); HashSet <Transform> jettisonTransforms = new HashSet <Transform>(); for (int i = 0; i < jettisons.Count; i++) { ModuleJettison j = jettisons[i]; if (j.jettisonTransform == null) { continue; } jettisonTransforms.Add(j.jettisonTransform); if (j.isJettisoned) { continue; } Transform t = j.jettisonTransform; if (t.gameObject.activeInHierarchy == false) { continue; } MeshData md = GetVisibleMeshData(t, false); if (md == null) { continue; } meshList.Add(md); validTransformList.Add(t); } //Voxelize Everything if ((cantUseColliders || forceUseMeshes || isFairing) && !isDrill) //in this case, voxelize _everything_ { foreach (Transform t in meshTransforms) { if (jettisonTransforms.Contains(t)) { continue; } MeshData md = GetVisibleMeshData(t, false); if (md == null) { continue; } meshList.Add(md); validTransformList.Add(t); } } } else { //Voxelize Everything if ((cantUseColliders || forceUseMeshes || isFairing) && !isDrill) //in this case, voxelize _everything_ { foreach (Transform t in meshTransforms) { MeshData md = GetVisibleMeshData(t, false); if (md == null) { continue; } meshList.Add(md); validTransformList.Add(t); } } } meshTransforms = validTransformList; return(meshList); }
public StockJettisonTransformGeoUpdater(ModuleJettison engineFairing, GeometryPartModule geoModule) { this.engineFairing = engineFairing; this.geoModule = geoModule; fairingVisible = engineFairing.jettisonTransform.gameObject.activeSelf && !engineFairing.isJettisoned; }
public StockJettisonTransformGeoUpdater(ModuleJettison engineFairing, GeometryPartModule geoModule) { this.engineFairing = engineFairing; this.geoModule = geoModule; fairingVisible = engineFairing.jettisonTransform.gameObject.activeSelf; }
private List <MeshData> CreateMeshListFromTransforms(ref List <Transform> meshTransforms) { DebugClear(); List <MeshData> meshList = new List <MeshData>(); List <Transform> validTransformList = new List <Transform>(); if (part.Modules.Contains <KerbalEVA>() || part.Modules.Contains <FlagSite>()) { FARLogger.Info("Adding vox box to Kerbal / Flag"); meshList.Add(CreateBoxMeshForKerbalEVA()); validTransformList.Add(part.partTransform); meshTransforms = validTransformList; return(meshList); } var worldToLocalMatrix = part.partTransform.worldToLocalMatrix; var rendererBounds = part.GetPartOverallMeshBoundsInBasis(worldToLocalMatrix); var colliderBounds = part.GetPartColliderBoundsInBasis(worldToLocalMatrix); bool cantUseColliders = true; bool isFairing = part.Modules.Contains <ModuleProceduralFairing>() || part.Modules.Contains("ProceduralFairingSide"); bool isDrill = part.Modules.Contains <ModuleAsteroidDrill>() || part.Modules.Contains <ModuleResourceHarvester>(); //Voxelize colliders if ((forceUseColliders || isFairing || isDrill || (rendererBounds.size.x * rendererBounds.size.z < colliderBounds.size.x * colliderBounds.size.z * 1.6f && rendererBounds.size.y < colliderBounds.size.y * 1.2f && (rendererBounds.center - colliderBounds.center).magnitude < 0.3f)) && !forceUseMeshes) { foreach (Transform t in meshTransforms) { MeshData md = GetColliderMeshData(t); if (md == null) { continue; } DebugAddCollider(t); meshList.Add(md); validTransformList.Add(t); cantUseColliders = false; } } if (part.Modules.Contains <ModuleJettison>()) { bool variants = part.Modules.Contains <ModulePartVariants>(); List <ModuleJettison> jettisons = part.Modules.GetModules <ModuleJettison>(); HashSet <string> jettisonTransforms = new HashSet <string>(); for (int i = 0; i < jettisons.Count; i++) { ModuleJettison j = jettisons[i]; if (j.jettisonTransform == null) { continue; } if (variants) { // with part variants, jettison name is a comma separated list of transform names foreach (string name in j.jettisonName.Split(',')) { jettisonTransforms.Add(name); } } else { jettisonTransforms.Add(j.jettisonTransform.name); } if (j.isJettisoned) { continue; } Transform t = j.jettisonTransform; if (t.gameObject.activeInHierarchy == false) { continue; } MeshData md = GetVisibleMeshData(t, ignoreIfNoRenderer, false); if (md == null) { continue; } DebugAddMesh(t); meshList.Add(md); validTransformList.Add(t); } //Voxelize Everything if ((cantUseColliders || forceUseMeshes || isFairing) && !isDrill) //in this case, voxelize _everything_ { foreach (Transform t in meshTransforms) { if (jettisonTransforms.Contains(t.name)) { continue; } MeshData md = GetVisibleMeshData(t, ignoreIfNoRenderer, false); if (md == null) { continue; } DebugAddMesh(t); meshList.Add(md); validTransformList.Add(t); } } } else { //Voxelize Everything if ((cantUseColliders || forceUseMeshes || isFairing) && !isDrill) //in this case, voxelize _everything_ { foreach (Transform t in meshTransforms) { MeshData md = GetVisibleMeshData(t, ignoreIfNoRenderer, false); if (md == null) { continue; } DebugAddMesh(t); meshList.Add(md); validTransformList.Add(t); } } } DebugPrint(); meshTransforms = validTransformList; return(meshList); }
protected void buildSceneWindowGUI(int windowID) { preventEditorClickthroughs(); if (buildSceneMinimized) { GUILayout.BeginHorizontal(); if (GUILayout.Button("Max")) { buildSceneMinimized = false; } if (GUILayout.Button("X", ARUtils.buttonStyle(Color.red))) { if (weLockedEditor && EditorLogic.editorLocked) { EditorLogic.fetch.Unlock(); } buildSceneShow = false; } GUILayout.EndHorizontal(); base.WindowGUI(windowID); return; } double mass = 0; int cost = 0; foreach (Part part in EditorLogic.SortedShipList) { cost += part.partInfo.cost; if (part.physicalSignificance != Part.PhysicalSignificance.NONE) { mass += part.totalMass(); } //In the VAB, ModuleJettison (which adds fairings) forgets to subtract the fairing mass from //the part mass if the engine does have a fairing, so we have to do this manually if (part.vessel == null && //hacky way to tell whether we're in the VAB (part.Modules.OfType <ModuleJettison>().Count() > 0)) { ModuleJettison jettison = part.Modules.OfType <ModuleJettison>().First(); if (part.findAttachNode(jettison.bottomNodeName).attachedPart == null) { mass -= jettison.jettisonedObjectMass; } } } double TWR = 0; if (twrPerStage.Length > 0) { TWR = twrPerStage[twrPerStage.Length - 1]; } int partCount = EditorLogic.SortedShipList.Count; GUIStyle txtR = new GUIStyle(GUI.skin.label); txtR.alignment = TextAnchor.UpperRight; GUIStyle sty = new GUIStyle(GUI.skin.button); sty.normal.textColor = sty.focused.textColor = Color.white; sty.hover.textColor = sty.active.textColor = Color.yellow; sty.onNormal.textColor = sty.onFocused.textColor = sty.onHover.textColor = sty.onActive.textColor = Color.green; sty.padding = txtR.padding; sty.margin = txtR.margin; GUILayout.BeginVertical(); GUILayout.BeginHorizontal(); if (GUILayout.Button("Minimize")) { buildSceneMinimized = true; } if (GUILayout.Button("Close", ARUtils.buttonStyle(Color.red))) { if (weLockedEditor && EditorLogic.editorLocked) { EditorLogic.fetch.Unlock(); } buildSceneShow = false; } GUILayout.EndHorizontal(); //Alloc my planitron if (_planitron == null) { _planitron = new MechJebModulePlanitron(core); } GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true)); GUILayout.Label("Show planitron", GUILayout.ExpandWidth(true)); _planitron.enabled = GUILayout.Toggle(_planitron.enabled, _planitron.getPlanet(), sty); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true)); GUILayout.Label("Total mass", GUILayout.ExpandWidth(true)); GUILayout.Label(mass.ToString("F2") + " tons", txtR); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true)); GUILayout.Label("Surface weight", GUILayout.ExpandWidth(true)); GUILayout.Label((mass * _planitron.gravity()).ToString("F2") + " tons", txtR); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true)); GUILayout.Label("Surface TWR", GUILayout.ExpandWidth(true)); GUILayout.Label(TWR.ToString("F2"), txtR); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true)); GUILayout.Label("Part count", GUILayout.ExpandWidth(true)); GUILayout.Label(partCount.ToString(), txtR); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true)); GUILayout.Label("Total Cost", GUILayout.ExpandWidth(true)); GUILayout.Label(cost.ToString(), txtR); GUILayout.EndHorizontal(); doStagingAnalysisGUI(true); GUILayout.EndVertical(); base.WindowGUI(windowID); }
public override void OnStart(StartState state) { // Start up the base PartModule, just in case. base.OnStart(state); // Fetch all of the ModuleJettisons from the part, filling a list of modules and a dict of transforms PartModule module; for (int mIdx = 0; mIdx < base.part.Modules.Count; mIdx++) { module = base.part.Modules[mIdx]; if (module is ModuleJettison) { ModuleJettison jettisonModule = module as ModuleJettison; if (jettisonModule == null || jettisonModule.jettisonName == string.Empty) { Debug.Log("Skipping problematic jettisonModule"); continue; } if (this.bottomNode == null) { this.bottomNode = this.part.findAttachNode(jettisonModule.bottomNodeName); } this.jettisonModules.Add(jettisonModule); this.jettisonTransforms[jettisonModule.jettisonName] = jettisonModule.jettisonTransform; // Seed the hasJettisoned table with the module's state at start up to avoid loading up a shroud // when we shouldn't have one. this.hasJettisonedTable[jettisonModule.jettisonName] = jettisonModule.isJettisoned; BaseEvent moduleJettisonEvent = new BaseEvent( this.Events, string.Format("{0}{1}", jettisonModule.jettisonName, "jettisonEvent"), (BaseEventDelegate) delegate { this.JettisonEvent(jettisonModule, actionParam); } ); moduleJettisonEvent.active = true; moduleJettisonEvent.guiActive = jettisonModule.isJettisoned && !this.disableFairing; moduleJettisonEvent.guiActiveEditor = false; moduleJettisonEvent.guiName = "Jettison"; this.Events.Add(moduleJettisonEvent); Debug.Log("Added new Jettison event wrapper " + moduleJettisonEvent); jettisonModule.Events["Jettison"].active = false; jettisonModule.Events["Jettison"].guiActive = false; jettisonModule.Events["Jettison"].guiActiveEditor = false; jettisonModule.Events["Jettison"].guiName += "(DEPRECATED)"; BaseAction moduleJettisonAction = new BaseAction( this.Actions, string.Format("{0}{1}", jettisonModule.jettisonName, "jettisonAction"), (BaseActionDelegate) delegate(KSPActionParam param) { this.JettisonEvent(jettisonModule, param); }, new KSPAction("Jettison") ); this.Actions.Add(moduleJettisonAction); Debug.Log("Added new JettisonAction action wrapper " + moduleJettisonAction); jettisonModule.Actions["JettisonAction"].active = false; jettisonModule.Actions["JettisonAction"].guiName += "(DEPRECRATED)"; } } Debug.Log("Found " + jettisonModules.Count + " ModuleJettisons."); // Seed the disableState for first-run behavior. if (this.disableFairing || true) { this.disableState = !this.disableFairing; } }