public static void AddPodInventories(Part part, int crewCapacity) { for (var i = 0; i < crewCapacity; i++) { var moduleInventory = part.AddModule(typeof(ModuleKISInventory).Name) as ModuleKISInventory; KIS_Shared.AwakePartModule(moduleInventory); moduleInventory.invType = ModuleKISInventory.InventoryType.Pod; DebugEx.Fine("{0}: Add pod inventory to match the capacity", part); } var podInventories = part.Modules.OfType <ModuleKISInventory>() .Where(m => m.invType == ModuleKISInventory.InventoryType.Pod) .ToArray(); for (var i = 0; i < podInventories.Length; i++) { try { var baseFields = new BaseFieldList(podInventories[i]); baseFields.Load(evaInventory); podInventories[i].podSeat = i; DebugEx.Fine("{0}: Pod inventory for seat {1} loaded successfully", part, i); } catch { DebugEx.Error("{0}: Pod inventory module for seat {1} can't be loaded!", part, i); } } }
void SetInventoryConfig(Component moduleInventory, ConfigNode nodeSettings) { var nodeEvaInventory = nodeSettings.GetNode("EvaInventory"); if (nodeEvaInventory != null) { var baseFields = new BaseFieldList(moduleInventory); baseFields.Load(nodeEvaInventory); } }
public void Start() { if (part.Modules.Contains("FissionReactor")) { foreach (PartModule pm in part.Modules) //should be a shorter way to do this, but a foreach cycle works { if (pm.moduleName == "FissionReactor") //find the desired partmodule, note we stay as type PartModule, we do not cast to DifferentialThrustEngineModule { partFields = pm.Fields; // rotation = (float)pm.Fields.GetValue("rotation"); //which throttle is engine assigned to? } } } }
public void Awake() { ConfigAccessor.ReadFieldsInType(GetType(), this); ConfigAccessor.ReadFieldsInType(typeof(ModuleKISInventory), instance: null); // Set inventory module for every eva kerbal Debug.Log("Set KIS config..."); ConfigNode nodeSettings = GameDatabase.Instance.GetConfigNode("KIS/settings/KISConfig"); if (nodeSettings == null) { Debug.LogError("KIS settings.cfg not found or invalid !"); return; } // Kerbal parts. UpdateEvaPrefab(MaleKerbalEva, nodeSettings); UpdateEvaPrefab(FemaleKerbalEva, nodeSettings); // Set inventory module for every pod with crew capacity. Debug.Log("Loading pod inventories..."); foreach (AvailablePart avPart in PartLoader.LoadedPartsList) { if (avPart.name == MaleKerbalEva || avPart.name == FemaleKerbalEva || avPart.name == RdKerbalEva || !avPart.partPrefab || avPart.partPrefab.CrewCapacity < 1) { continue; } Debug.LogFormat("Found part with CrewCapacity: {0}", avPart.name); for (int i = 0; i < avPart.partPrefab.CrewCapacity; i++) { try { var moduleInventory = avPart.partPrefab.AddModule(typeof(ModuleKISInventory).Name) as ModuleKISInventory; KIS_Shared.AwakePartModule(moduleInventory); var baseFields = new BaseFieldList(moduleInventory); baseFields.Load(nodeSettings.GetNode("EvaInventory")); moduleInventory.podSeat = i; moduleInventory.invType = ModuleKISInventory.InventoryType.Pod; Debug.LogFormat("Pod inventory module(s) for seat {0} loaded successfully", i); } catch { Debug.LogErrorFormat("Pod inventory module(s) for seat {0} can't be loaded!", i); } } } }
/// <summary>Re-applies GUI name and GUI units strings from the event attributes.</summary> /// <param name="fields">The fields to process.</param> static void UpdateStockFields(BaseFieldList fields) { foreach (var kspField in fields) { SetupArgumentFromAttribute( kspField.MemberInfo, kspField.Attribute.GetType(), nameof(KSPField.guiName), x => { kspField.Attribute.guiName = x; kspField.guiName = kspField.Attribute.guiName; }); SetupArgumentFromAttribute( kspField.MemberInfo, kspField.Attribute.GetType(), nameof(KSPField.guiUnits), x => { kspField.Attribute.guiUnits = x; kspField.guiUnits = kspField.Attribute.guiUnits; }); } }
/// <summary>Loads config values for the part's module fro the provided config node.</summary> /// <returns><c>true</c> if loaded successfully.</returns> static bool LoadModuleConfig(Part p, Type moduleType, ConfigNode node) { var module = p.GetComponent(moduleType); if (module == null) { DebugEx.Warning( "Config node for module {0} in part {1} is NULL. Nothing to load!", moduleType, p); return(false); } if (node == null) { DebugEx.Warning("Cannot find module {0} on part {1}. Config not loaded!", moduleType, p); return(false); } var baseFields = new BaseFieldList(module); baseFields.Load(node); DebugEx.Info("Loaded config for {0} on part {1}", moduleType, p); return(true); }
void UpdateEvaPrefab(AvailablePart avPart, ConfigNode nodeSettings) { var prefab = avPart.partPrefab; // Adding module to EVA may cause an NPE but module update will still work. try { prefab.AddModule(typeof(ModuleKISInventory).Name); } catch (Exception ex) { Logger.logInfo( "NOT A BUG! Ignoring error while adding ModuleKISInventory to {0}: {1}", prefab, ex); } try { prefab.AddModule(typeof(ModuleKISPickup).Name); } catch (Exception ex) { Logger.logInfo("NOT A BUG! Ignoring error adding ModuleKISPickup to {0}: {1}", prefab, ex); } // Setup inventory module for eva. var evaInventory = prefab.GetComponent <ModuleKISInventory>(); CallAwakeMethod(evaInventory); if (evaInventory) { SetInventoryConfig(evaInventory, nodeSettings); evaInventory.invType = ModuleKISInventory.InventoryType.Eva; Logger.logInfo("Eva inventory module loaded successfully"); } // Load KSP fields for ModuleKISPickup module. var nodeEvaPickup = nodeSettings.GetNode("EvaPickup"); var evaPickup = prefab.GetComponent <ModuleKISPickup>(); CallAwakeMethod(evaPickup); if (evaPickup && nodeEvaPickup != null) { var fields = new BaseFieldList(evaPickup); fields.Load(nodeEvaPickup); Logger.logInfo("Eva pickup module loaded successfully"); } }
public BaseField GetField() { var fields = new BaseFieldList(this); BaseField bf = fields[0]; bf.guiName = name; UI_Control control = null; if (HighLogic.LoadedSceneIsEditor) { control = bf.uiControlEditor; } else if (HighLogic.LoadedSceneIsFlight) { control = bf.uiControlFlight; } if (control != null) { control.onFieldChanged += ModifyValue; } return(bf); }
/// <summary> /// Load infos into this object and create a new BaseEvent /// </summary> /// <returns>true - loaded successfull</returns> public override bool Load(ConfigNode n, FlightComputer fc) { if (base.Load(n, fc)) { // deprecated since 1.6.2, we need this for upgrading from 1.6.x => 1.6.2 int PartId = 0; { if (n.HasValue("PartId")) PartId = int.Parse(n.GetValue("PartId")); } if (n.HasValue("flightID")) this.flightID = uint.Parse(n.GetValue("flightID")); this.Module = n.GetValue("Module"); this.GUIName = n.GetValue("GUIName"); this.Name = n.GetValue("Name"); NewValueString = n.GetValue("NewValue"); RTLog.Notify("Try to load an PartActionCommand from persistent with {0},{1},{2},{3},{4}", PartId, this.flightID, this.Module, this.GUIName, this.Name); Part part = null; var partlist = FlightGlobals.ActiveVessel.parts; if (this.flightID == 0) { // only look with the partid if we've enough parts if (PartId < partlist.Count) part = partlist.ElementAt(PartId); } else { part = partlist.Where(p => p.flightID == this.flightID).FirstOrDefault(); } if (part == null) return false; PartModule partmodule = part.Modules[Module]; if (partmodule == null) return false; BaseFieldList fieldList = new BaseFieldList(partmodule); if (fieldList.Count <= 0) return false; this.BaseField = fieldList[this.Name]; return (this.BaseField != null); } return false; }
public override void OnUpdate() { base.OnUpdate(); if (FlightGlobals.fetch.vesselTargetMode != VesselTargetModes.None) { Vessel target = (Vessel)FlightGlobals.fetch.VesselTarget; //target.ctrlState.mainThrottle = 1f; foreach (Part part in target.Parts) { ControlSurface ctrlsurf = part.Modules.OfType <ControlSurface>().FirstOrDefault(); if (ctrlsurf != null) { ctrlsurf.ActivatesEvenIfDisconnected = true; ctrlsurf.inputVector = new Vector3(vessel.ctrlState.X, vessel.ctrlState.Y, vessel.ctrlState.Z); } } target.ctrlState.mainThrottle = vessel.ctrlState.Z; target.ctrlState.pitch = vessel.ctrlState.X; target.ctrlState.roll = vessel.ctrlState.Z; //Vessel targetVessel = (Vessel)target; //Debug.Log(target); BaseFieldList test = this.part.Fields; foreach (BaseField field in test) { field.guiActive = false; } fogDensity -= 0.0001f; if (fogDensity <= 0f) { fogDensity = 0.01f; } RenderSettings.fog = true; RenderSettings.fogColor = Color.white; RenderSettings.fogDensity = fogDensity; RenderSettings.fogStartDistance = -50f; RenderSettings.fogMode = FogMode.ExponentialSquared; //Camera.main.clearFlags = CameraClearFlags.SolidColor; //Camera.main.backgroundColor = new Color(1f,1f,1f,0.1f); } else { RenderSettings.fog = false; RenderSettings.fogColor = new Color(0.439f, 0.859f, 1.000f, 0.0f);; RenderSettings.fogDensity = 1.5E-05f; RenderSettings.fogMode = FogMode.ExponentialSquared; Camera.main.clearFlags = CameraClearFlags.Depth; Camera.main.backgroundColor = new Color(0f, 0f, 0f, 0.02f); /*Debug.Log("fs: rsFog " + RenderSettings.fog); * Debug.Log("fs: fogC " + RenderSettings.fogColor); * Debug.Log("fs: fDens " + RenderSettings.fogDensity); * Debug.Log("fs: fMode" + RenderSettings.fogMode); * Debug.Log("fs: camCF" + Camera.main.clearFlags); * Debug.Log("fs: camBGc" + Camera.main.backgroundColor);*/ } }
/// <summary> /// Load infos into this object and create a new BaseEvent /// </summary> /// <returns>true - loaded successfull</returns> public override bool Load(ConfigNode n, FlightComputer fc) { if (base.Load(n, fc)) { // deprecated since 1.6.2, we need this for upgrading from 1.6.x => 1.6.2 int PartId = 0; { if (n.HasValue("PartId")) { PartId = int.Parse(n.GetValue("PartId")); } } if (n.HasValue("flightID")) { this.flightID = uint.Parse(n.GetValue("flightID")); } this.Module = n.GetValue("Module"); this.GUIName = n.GetValue("GUIName"); this.Name = n.GetValue("Name"); NewValueString = n.GetValue("NewValue"); RTLog.Notify("Try to load an PartActionCommand from persistent with {0},{1},{2},{3},{4}", PartId, this.flightID, this.Module, this.GUIName, this.Name); Part part = null; var partlist = FlightGlobals.ActiveVessel.parts; if (this.flightID == 0) { // only look with the partid if we've enough parts if (PartId < partlist.Count) { part = partlist.ElementAt(PartId); } } else { part = partlist.Where(p => p.flightID == this.flightID).FirstOrDefault(); } if (part == null) { return(false); } PartModule partmodule = part.Modules[Module]; if (partmodule == null) { return(false); } BaseFieldList fieldList = new BaseFieldList(partmodule); if (fieldList.Count <= 0) { return(false); } this.BaseField = fieldList[this.Name]; return(this.BaseField != null); } return(false); }
void UpdateEvaPrefab(AvailablePart avPart, ConfigNode nodeSettings) { var prefab = avPart.partPrefab; // Adding module to EVA may cause an NPE but module update will still work. try { prefab.AddModule(typeof(ModuleKISInventory).Name); } catch (Exception ex) { Logger.logInfo( "NOT A BUG! Ignoring error while adding ModuleKISInventory to {0}: {1}", prefab, ex); } try { prefab.AddModule(typeof(ModuleKISPickup).Name); } catch (Exception ex) { Logger.logInfo("NOT A BUG! Ignoring error adding ModuleKISPickup to {0}: {1}", prefab, ex); } // Setup inventory module for eva. var evaInventory = prefab.GetComponent<ModuleKISInventory>(); KIS_Shared.AwakePartModule(evaInventory); if (evaInventory) { SetInventoryConfig(evaInventory, nodeSettings); evaInventory.invType = ModuleKISInventory.InventoryType.Eva; Logger.logInfo("Eva inventory module loaded successfully"); } // Load KSP fields for ModuleKISPickup module. var nodeEvaPickup = nodeSettings.GetNode("EvaPickup"); var evaPickup = prefab.GetComponent<ModuleKISPickup>(); KIS_Shared.AwakePartModule(evaPickup); if (evaPickup && nodeEvaPickup != null) { var fields = new BaseFieldList(evaPickup); fields.Load(nodeEvaPickup); Logger.logInfo("Eva pickup module loaded successfully"); } }