public override void OnStart(PartModule.StartState state) { try { ParseSet(componentToggles, ActuatorType.PartComponent); ParseSet(groupToggles, ActuatorType.PartComponentGroup); ParseSet(moduleToggles, ActuatorType.PartModule); ParseSet(textureToggles, ActuatorType.TransformTexture); ParseSet(shaderToggles, ActuatorType.TransformShader); ParseSet(numericToggles, ActuatorType.StraightParameter); ParseSet(managedResources, ActuatorType.Resource); ParseSet(controlCrewCapacity, ActuatorType.CrewCapacity); ParseSet(managedNodes, ActuatorType.AttachmentNode); } catch { JUtil.LogErrorMessage(this, "Please check your configuration."); Destroy(this); } foreach (string eventName in new [] { "JSIGuiToggleComponents", "JSIGuiEnableComponents", "JSIGuiDisableComponents" }) { Events [eventName].guiActive = activeInFlight; Events [eventName].guiActiveEditor = activeInEditor; Events [eventName].guiActiveUnfocused = activeWhenUnfocused; Events [eventName].externalToEVAOnly = externalToEVAOnly; Events [eventName].unfocusedRange = unfocusedActivationRange; } if (!string.IsNullOrEmpty(enableMenuString)) { Events ["JSIGuiEnableComponents"].guiName = enableMenuString; } if (!string.IsNullOrEmpty(disableMenuString)) { Events ["JSIGuiDisableComponents"].guiName = disableMenuString; } if (!string.IsNullOrEmpty(toggleMenuString)) { Events ["JSIGuiToggleComponents"].guiName = toggleMenuString; } if ((HighLogic.LoadedSceneIsEditor && !spawned) || (HighLogic.LoadedSceneIsFlight && !persistAfterEditor)) { currentState = areComponentsEnabled; } if (currentState) { Events ["JSIGuiEnableComponents"].active = false; } else { Events ["JSIGuiDisableComponents"].active = false; } Events ["JSIGuiToggleComponents"].active &= showToggleOption; if (!showEnableDisableOption) { Events ["JSIGuiEnableComponents"].active = false; Events ["JSIGuiDisableComponents"].active = false; } spawned = true; if (HighLogic.LoadedSceneIsEditor) { StartCoroutine(DelayedLoop(0.05f)); } else { LoopThroughActuators(currentState); } }
public override void OnStart(PartModule.StartState state) { if (!string.IsNullOrEmpty(flagTransform)) { Transform target = part.FindModelTransform(flagTransform); if (target != null) { Renderer mat = target.GetComponent <Renderer> (); initialTexture = mat.material.GetTexture(textureLayer); } else { JUtil.LogMessage(this, "Flag transform '{0}' not found.", flagTransform); Destroy(this); return; } if (!flagWasSelected && !string.IsNullOrEmpty(defaultFlag)) { switch (defaultFlag) { case "$RANDOM$": var allFlags = GameDatabase.Instance.GetAllTexturesInFolderType("Flags"); if (allFlags.Count > 0) { defaultFlag = allFlags [UnityEngine.Random.Range(0, allFlags.Count - 1)].name; } else { JUtil.LogMessage(this, "Could not find any flags to pick a random one, wtf?"); } break; case "$SPONSOR$": if (HighLogic.CurrentGame.Mode == Game.Modes.CAREER) { // Other modes can't have contracts. var agentURLs = new List <string> (); foreach (Contract thatContract in ContractSystem.Instance.Contracts) { if (!agentURLs.Contains(thatContract.Agent.LogoURL) && thatContract.ContractState == Contract.State.Active) { agentURLs.Add(thatContract.Agent.LogoURL); } } if (agentURLs.Count > 0) { defaultFlag = agentURLs [UnityEngine.Random.Range(0, agentURLs.Count - 1)]; } } else { var Agencies = Contracts.Agents.AgentList.Instance.Agencies; if (Agencies.Count > 0) { defaultFlag = Agencies[UnityEngine.Random.Range(0, Agencies.Count - 1)].LogoURL; } } break; } if (GameDatabase.Instance.ExistsTexture(defaultFlag)) { selectedFlag = defaultFlag; } } Events ["SelectFlag"].guiName = menuString; ChangeFlag(); } else { JUtil.LogMessage(this, "Nothing to do, flag transform name is empty."); Destroy(this); } }
public override void OnStart(PartModule.StartState state) { componentList = componentName.Split(new [] { ',', ' ', '|' }, StringSplitOptions.RemoveEmptyEntries); foreach (string componentText in componentList) { Component thatComponent = part.FindModelComponent <Component> (componentText); if (thatComponent == null) { JUtil.LogErrorMessage(this, "Target part component {0} was not found in part {1}. Selfdestructing the module...", componentText, part.name); Destroy(this); } } JUtil.LogMessage(this, "Active in part {0}, handling {1} components", part.name, componentList.Length); foreach (string eventName in new [] { "JSIGuiToggleComponent", "JSIGuiEnableComponent", "JSIGuiDisableComponent" }) { Events [eventName].guiActive = activeInFlight; Events [eventName].guiActiveEditor = activeInEditor; Events [eventName].guiActiveUnfocused = activeWhenUnfocused; Events [eventName].externalToEVAOnly = externalToEVAOnly; Events [eventName].unfocusedRange = unfocusedActivationRange; } if (!string.IsNullOrEmpty(enableMenuString)) { Events ["JSIGuiEnableComponent"].guiName = enableMenuString; } if (!string.IsNullOrEmpty(disableMenuString)) { Events ["JSIGuiDisableComponent"].guiName = disableMenuString; } if (!string.IsNullOrEmpty(toggleMenuString)) { Events ["JSIGuiToggleComponent"].guiName = toggleMenuString; } if ((HighLogic.LoadedSceneIsEditor && !spawned) || (HighLogic.LoadedSceneIsFlight && !persistAfterEditor)) { currentState = componentIsEnabled; } if (currentState) { Events ["JSIGuiEnableComponent"].active = false; } else { Events ["JSIGuiDisableComponent"].active = false; } Events ["JSIGuiToggleComponent"].active &= showToggleOption; if (!showEnableDisableOption) { Events ["JSIGuiEnableComponent"].active = false; Events ["JSIGuiDisableComponent"].active = false; } spawned = true; LoopComponents(currentState); }
public Actuator(string configData, ActuatorType creatingType, Part thatPart) { savedNodePosition = faraway; type = creatingType; string remainder; if (configData.StartsWith("!", StringComparison.Ordinal)) { inverted = true; remainder = configData.Substring(1).Trim(); } else { inverted = false; remainder = configData; } string[] tokens = remainder.Split(','); switch (type) { case ActuatorType.PartComponent: moduleID = remainder; JUtil.LogMessage(this, "Controlling PartComponent with moduleID {0}, {1}", moduleID, inverted ? "inverted" : "regular"); break; case ActuatorType.PartComponentGroup: moduleID = remainder; JUtil.LogMessage(this, "Controlling PartComponentGroup with groupID {0}, {1}", moduleID, inverted ? "inverted" : "regular"); break; case ActuatorType.PartModule: int moduleIndex = int.Parse(remainder.Split(',') [1]); var thoseModules = new List <PartModule> (); foreach (PartModule thatModule in thatPart.Modules) { if (thatModule.ClassName == tokens [0].Trim()) { thoseModules.Add(thatModule); } } if (moduleIndex < thoseModules.Count) { controlledModule = thoseModules [moduleIndex]; } else { JUtil.LogErrorMessage(this, "Could not find PartModule named {2} number {0} in part {1}", moduleIndex, thatPart.name, tokens [0].Trim()); } JUtil.LogMessage(this, "Controlling PartModule named {0}, {1}", controlledModule.ClassName, inverted ? "inverted" : "regular"); break; case ActuatorType.TransformTexture: if (tokens.Length == 3 || tokens.Length == 4) { targetTransform = thatPart.FindModelTransform(tokens [0].Trim()); if (targetTransform == null) { throw new ArgumentException("Could not find model transform."); } if (GameDatabase.Instance.ExistsTexture(tokens [1].Trim()) && GameDatabase.Instance.ExistsTexture(tokens [2].Trim())) { falseString = tokens [1].Trim(); trueString = tokens [2].Trim(); JUtil.LogMessage(this, "Controlling texture on transform '{0}', {1}", tokens [0].Trim(), inverted ? "inverted" : "regular"); } else { throw new ArgumentException("Textures not found."); } if (tokens.Length == 4) { textureLayer = tokens [3].Trim(); } } else { throw new ArgumentException("Bad arguments."); } break; case ActuatorType.TransformShader: if (tokens.Length == 3) { targetTransform = thatPart.FindModelTransform(tokens [0].Trim()); if (targetTransform == null) { throw new ArgumentException("Could not find model transform."); } if (Shader.Find(tokens [1].Trim()) && Shader.Find(tokens [2].Trim())) { falseString = tokens [1].Trim(); trueString = tokens [2].Trim(); JUtil.LogMessage(this, "Controlling shader on transform '{0}', {1}", tokens [0].Trim(), inverted ? "inverted" : "regular"); } else { throw new ArgumentException("Shaders not found."); } } else { throw new ArgumentException("Bad arguments."); } break; case ActuatorType.StraightParameter: if (tokens.Length == 2) { if (float.TryParse(tokens [1], out addToParameterWhenEnabled)) { if (Array.IndexOf(knownStraightParameters, tokens [0].Trim()) >= 0) { nameOfParameter = tokens [0].Trim(); originalParameterValue = GetParameter(nameOfParameter, thatPart); JUtil.LogMessage(this, "Controlling parameter '{0}' on part {1}, {2}", nameOfParameter, thatPart.partName, inverted ? "inverted" : "regular"); } else { throw new ArgumentException("Bad arguments, unknown straight parameter " + tokens [0]); } } else { throw new ArgumentException("Bad argument, maxTemp must be a float."); } } else { throw new ArgumentException("Bad arguments."); } break; case ActuatorType.Resource: if (tokens.Length == 2) { if (float.TryParse(tokens [1], out maxAmount)) { bool found = false; resourceName = tokens [0].Trim(); foreach (PartResourceDefinition thatResource in PartResourceLibrary.Instance.resourceDefinitions) { found |= thatResource.name == resourceName; } if (!found) { throw new ArgumentException("Bad resource name."); } JUtil.LogMessage(this, "Controlling resource tank for resource {0} in part {1}, {2}", resourceName, thatPart.partName, inverted ? "inverted" : "regular"); } else { throw new ArgumentException("Bad resource amount."); } } else { throw new ArgumentException("Bad arguments."); } break; case ActuatorType.CrewCapacity: if (tokens.Length == 1) { switch (tokens [0].ToLowerInvariant()) { case "regular": inverted = false; break; case "inverted": inverted = true; break; default: throw new ArgumentException("I need a 'regular' or 'inverted' here."); } JUtil.LogMessage(this, "Controlling crew capacity in part {0}, {1}", thatPart.partName, inverted ? "inverted" : "regular"); } else { throw new ArgumentException("Bad arguments."); } break; case ActuatorType.AttachmentNode: if (tokens.Length == 1) { nodeName = tokens [0].Trim(); var foundNode = thatPart.findAttachNode(nodeName); if (foundNode == null) { throw new ArgumentException("Node not found."); } savedNodePosition = foundNode.position; JUtil.LogMessage(this, "Managing attach node in part {0}, node name {1}, {2}", thatPart.partName, nodeName, inverted ? "inverted" : "regular"); } else { throw new ArgumentException("Node name missing."); } break; } }