protected virtual void setTankSetFromEditor(String newTankSet, bool updateSymmetry) { TankSet newSet = Array.Find(tankSets, m => m.name == newTankSet); currentTankSetModule = newSet; string variant = lastSelectedVariant; string newTankName = newSet.getDefaultModel(lastSelectedVariant); this.updateUIChooseOptionControl("currentTankType", newSet.getModelNames(), newSet.getTankDescriptions(), true, newTankName); setMainTankModuleFromEditor(newTankName, false); Fields["currentTankType"].guiActiveEditor = newSet.Length > 1; //re-seat this if it was changed in the 'setMainTankModuleFromEditor' method //will allow for user-initiated main-tank changes to still change the 'last variant' but will //persist the variant if the newly selected set did not contain the selected variant //so that it will persist to the next set selection, OR be reseated on the next user-tank selection within the current set if (!currentTankSetModule.hasVariant(variant)) { lastSelectedVariant = variant; } if (updateSymmetry) { foreach (Part p in part.symmetryCounterparts) { p.GetComponent <SSTUModularFuelTank>().setTankSetFromEditor(newTankSet, false); } } }
public override void OnStart(StartState state) { base.OnStart(state); initialize(); string[] groupNames = TankSet.getSetNames(tankSets); this.updateUIChooseOptionControl("currentTankSet", groupNames, groupNames, true, currentTankSet); string[] names = currentTankSetModule.getModelNames(); string[] descs = currentTankSetModule.getTankDescriptions(); this.updateUIChooseOptionControl("currentTankType", names, descs, true, currentTankType); if (maxTankDiameter == minTankDiameter) { Fields["currentTankDiameter"].guiActiveEditor = false; } else { this.updateUIFloatEditControl("currentTankDiameter", minTankDiameter, maxTankDiameter, tankDiameterIncrement * 2, tankDiameterIncrement, tankDiameterIncrement * 0.05f, true, currentTankDiameter); } updateAvailableVariants(); updateUIScaleControls(); currentNoseModule.updateTextureUIControl(this, "currentNoseTexture", currentNoseTexture); currentMainTankModule.updateTextureUIControl(this, "currentTankTexture", currentTankTexture); currentMountModule.updateTextureUIControl(this, "currentMountTexture", currentMountTexture); bool useModelSelectionGUI = HighLogic.CurrentGame.Parameters.CustomParams <SSTUGameSettings>().useModelSelectGui; Events["selectNoseEvent"].guiActiveEditor = useModelSelectionGUI; Events["selectMountEvent"].guiActiveEditor = useModelSelectionGUI; Fields["currentTankDiameter"].uiControlEditor.onFieldChanged = tankDiameterUpdated; Fields["currentTankVerticalScale"].uiControlEditor.onFieldChanged = tankHeightScaleUpdated; Fields["currentTankSet"].uiControlEditor.onFieldChanged = tankSetUpdated; Fields["currentTankType"].uiControlEditor.onFieldChanged = tankTypeUpdated; Fields["currentNoseType"].uiControlEditor.onFieldChanged = noseTypeUpdated; Fields["currentMountType"].uiControlEditor.onFieldChanged = mountTypeUpdated; Fields["currentNoseTexture"].uiControlEditor.onFieldChanged = onNoseTextureUpdated; Fields["currentTankTexture"].uiControlEditor.onFieldChanged = onTankTextureUpdated; Fields["currentMountTexture"].uiControlEditor.onFieldChanged = onMountTextureUpdated; Fields["currentTankSet"].guiActiveEditor = tankSets.Length > 1; Fields["currentTankType"].guiActiveEditor = currentTankSetModule.Length > 1; Fields["currentNoseType"].guiActiveEditor = !useModelSelectionGUI && noseModules.Length > 1; Fields["currentMountType"].guiActiveEditor = !useModelSelectionGUI && mountModules.Length > 1; SSTUStockInterop.fireEditorUpdate(); SSTUModInterop.onPartGeometryUpdate(part, true); if (HighLogic.LoadedSceneIsEditor) { GameEvents.onEditorShipModified.Add(new EventData <ShipConstruct> .OnEvent(onEditorVesselModified)); } }
public static TankSet[] parseSets(ConfigNode[] nodes) { int len = nodes.Length; TankSet[] sets = new TankSet[len]; for (int i = 0; i < len; i++) { sets[i] = new TankSet(nodes[i]); } return(sets); }
/// <summary> /// Restores ModelData instances from config node data, and populates the 'currentModule' instances with the currently enabled modules. /// </summary> private void loadConfigData() { ConfigNode node = SSTUConfigNodeUtils.parseConfigNode(configNodeData); ConfigNode[] tankSetsNodes = node.GetNodes("TANKSET"); ConfigNode[] tankNodes = node.GetNodes("TANK"); ConfigNode[] mountNodes = node.GetNodes("CAP"); ConfigNode[] limitNodes = node.GetNodes("TECHLIMIT"); tankSets = TankSet.parseSets(tankSetsNodes); //if no sets exist, initialize a default set to add all models to if (tankSets.Length == 0) { tankSets = new TankSet[1]; ConfigNode defaultSetNode = new ConfigNode("TANKSET"); defaultSetNode.AddValue("name", "default"); tankSets[0] = new TankSet(defaultSetNode); } mainTankModules = ModelData.parseModels <TankModelData>(tankNodes, m => new TankModelData(m)); int len = mainTankModules.Length; TankSet set; for (int i = 0; i < len; i++) { set = Array.Find(tankSets, m => m.name == mainTankModules[i].setName); //if set is not found by name, add it to the first set which is guaranteed to exist due to the default-set-adding code above. if (set == null) { set = tankSets[0]; } set.addModel(mainTankModules[i]); } len = mountNodes.Length; ConfigNode mountNode; List <SingleModelData> noses = new List <SingleModelData>(); List <SingleModelData> mounts = new List <SingleModelData>(); for (int i = 0; i < len; i++) { mountNode = mountNodes[i]; if (mountNode.GetBoolValue("useForNose", true)) { mountNode.SetValue("nose", "true"); noses.Add(new SingleModelData(mountNode)); } if (mountNode.GetBoolValue("useForMount", true)) { mountNode.SetValue("nose", "false"); mounts.Add(new SingleModelData(mountNode)); } } mountModules = mounts.ToArray(); noseModules = noses.ToArray(); topNodeNames = SSTUUtils.parseCSV(topManagedNodeNames); bottomNodeNames = SSTUUtils.parseCSV(bottomManagedNodeNames); currentMainTankModule = Array.Find(mainTankModules, m => m.name == currentTankType); if (currentMainTankModule == null) { MonoBehaviour.print("ERROR: Could not locate tank type for: " + currentTankType + ". reverting to first available tank type."); currentMainTankModule = mainTankModules[0]; currentTankType = currentMainTankModule.name; } currentTankSetModule = Array.Find(tankSets, m => m.name == currentMainTankModule.setName); currentTankSet = currentTankSetModule.name; lastSelectedVariant = currentMainTankModule.variantName; currentNoseModule = Array.Find(noseModules, m => m.name == currentNoseType); if (currentNoseModule == null) { MonoBehaviour.print("ERROR: Could not locate nose type for: " + currentNoseType + ". reverting to first available nose type."); currentNoseModule = noseModules[0]; currentNoseType = currentNoseModule.name; } currentMountModule = Array.Find(mountModules, m => m.name == currentMountType); if (currentMountModule == null) { MonoBehaviour.print("ERROR: Could not locate mount type for: " + currentMountType + ". reverting to first available mount type."); currentMountModule = mountModules[0]; currentMountType = currentMountModule.name; } if (!currentMainTankModule.isValidTextureSet(currentTankTexture)) { currentTankTexture = currentMainTankModule.getDefaultTextureSet(); } if (!currentNoseModule.isValidTextureSet(currentNoseTexture)) { currentNoseTexture = currentNoseModule.getDefaultTextureSet(); } if (!currentMountModule.isValidTextureSet(currentMountTexture)) { currentMountTexture = currentMountModule.getDefaultTextureSet(); } }
public static TankSet[] parseSets(ConfigNode[] nodes) { int len = nodes.Length; TankSet[] sets = new TankSet[len]; for (int i = 0; i < len; i++) { sets[i] = new TankSet(nodes[i]); } return sets; }
public static string[] getSetNames(TankSet[] sets, bool includeEmpty = false) { List<string> names = new List<string>(); int len = sets.Length; for (int i = 0; i < len; i++) { if (sets[i].Length > 0 || includeEmpty) { names.Add(sets[i].name); } } return names.ToArray(); }
/// <summary> /// Restores ModelData instances from config node data, and populates the 'currentModule' instances with the currently enabled modules. /// </summary> private void loadConfigData() { ConfigNode node = SSTUConfigNodeUtils.parseConfigNode(configNodeData); ConfigNode[] tankSetsNodes = node.GetNodes("TANKSET"); ConfigNode[] tankNodes = node.GetNodes("TANK"); ConfigNode[] mountNodes = node.GetNodes("CAP"); ConfigNode[] limitNodes = node.GetNodes("TECHLIMIT"); tankSets = TankSet.parseSets(tankSetsNodes); //if no sets exist, initialize a default set to add all models to if (tankSets.Length == 0) { tankSets = new TankSet[1]; ConfigNode defaultSetNode = new ConfigNode("TANKSET"); defaultSetNode.AddValue("name", "default"); tankSets[0] = new TankSet(defaultSetNode); } mainTankModules = ModelData.parseModels<TankModelData>(tankNodes, m => new TankModelData(m)); int len = mainTankModules.Length; TankSet set; for (int i = 0; i < len; i++) { set = Array.Find(tankSets, m => m.name == mainTankModules[i].setName); //if set is not found by name, add it to the first set which is guaranteed to exist due to the default-set-adding code above. if (set == null) { set = tankSets[0]; } set.addModel(mainTankModules[i]); } len = mountNodes.Length; ConfigNode mountNode; List<SingleModelData> noses = new List<SingleModelData>(); List<SingleModelData> mounts = new List<SingleModelData>(); for (int i = 0; i < len; i++) { mountNode = mountNodes[i]; if (mountNode.GetBoolValue("useForNose", true)) { mountNode.SetValue("nose", "true"); noses.Add(new SingleModelData(mountNode)); } if (mountNode.GetBoolValue("useForMount", true)) { mountNode.SetValue("nose", "false"); mounts.Add(new SingleModelData(mountNode)); } } mountModules = mounts.ToArray(); noseModules = noses.ToArray(); topNodeNames = SSTUUtils.parseCSV(topManagedNodeNames); bottomNodeNames = SSTUUtils.parseCSV(bottomManagedNodeNames); currentMainTankModule = Array.Find(mainTankModules, m => m.name == currentTankType); if (currentMainTankModule == null) { MonoBehaviour.print("ERROR: Could not locate tank type for: " + currentTankType + ". reverting to first available tank type."); currentMainTankModule = mainTankModules[0]; currentTankType = currentMainTankModule.name; } currentTankSetModule = Array.Find(tankSets, m => m.name == currentMainTankModule.setName); currentTankSet = currentTankSetModule.name; lastSelectedVariant = currentMainTankModule.variantName; currentNoseModule = Array.Find(noseModules, m => m.name == currentNoseType); if (currentNoseModule == null) { MonoBehaviour.print("ERROR: Could not locate nose type for: " + currentNoseType + ". reverting to first available nose type."); currentNoseModule = noseModules[0]; currentNoseType = currentNoseModule.name; } currentMountModule = Array.Find(mountModules, m => m.name == currentMountType); if (currentMountModule == null) { MonoBehaviour.print("ERROR: Could not locate mount type for: " + currentMountType + ". reverting to first available mount type."); currentMountModule = mountModules[0]; currentMountType = currentMountModule.name; } if (!currentMainTankModule.isValidTextureSet(currentTankTexture)) { currentTankTexture = currentMainTankModule.getDefaultTextureSet(); } if (!currentNoseModule.isValidTextureSet(currentNoseTexture)) { currentNoseTexture = currentNoseModule.getDefaultTextureSet(); } if (!currentMountModule.isValidTextureSet(currentMountTexture)) { currentMountTexture = currentMountModule.getDefaultTextureSet(); } }
protected virtual void setTankSetFromEditor(String newTankSet, bool updateSymmetry) { TankSet newSet = Array.Find(tankSets, m => m.name == newTankSet); currentTankSetModule = newSet; string variant = lastSelectedVariant; string newTankName = newSet.getDefaultModel(lastSelectedVariant); this.updateUIChooseOptionControl("currentTankType", newSet.getModelNames(), newSet.getTankDescriptions(), true, newTankName); setMainTankModuleFromEditor(newTankName, false); Fields["currentTankType"].guiActiveEditor = newSet.Length > 1; //re-seat this if it was changed in the 'setMainTankModuleFromEditor' method //will allow for user-initiated main-tank changes to still change the 'last variant' but will //persist the variant if the newly selected set did not contain the selected variant //so that it will persist to the next set selection, OR be reseated on the next user-tank selection within the current set if (!currentTankSetModule.hasVariant(variant)) { lastSelectedVariant = variant; } if (updateSymmetry) { foreach (Part p in part.symmetryCounterparts) { p.GetComponent<SSTUModularFuelTank>().setTankSetFromEditor(newTankSet, false); } } }
/// <summary> /// Restores ModelData instances from config node data, and populates the 'currentModule' instances with the currently enabled modules. /// </summary> private void loadConfigData() { ConfigNode node = SSTUConfigNodeUtils.parseConfigNode(configNodeData); ConfigNode[] tankSetsNodes = node.GetNodes("TANKSET"); ConfigNode[] tankNodes = node.GetNodes("TANK"); ConfigNode[] mountNodes = node.GetNodes("CAP"); variantData = TankVariant.parseVariants(node.GetNodes("VARIANT")); tankSets = TankSet.parseSets(tankSetsNodes); //if no sets exist, initialize a default set to add all models to if (tankSets.Length == 0) { tankSets = new TankSet[1]; ConfigNode defaultSetNode = new ConfigNode("TANKSET"); defaultSetNode.AddValue("name", "default"); tankSets[0] = new TankSet(defaultSetNode); } TankModelData[] mainTankModules = ModelData.parseModels <TankModelData>(tankNodes, m => new TankModelData(m)); int len = mainTankModules.Length; TankSet set; for (int i = 0; i < len; i++) { set = Array.Find(tankSets, m => m.name == mainTankModules[i].setName); //if set is not found by name, add it to the first set which is guaranteed to exist due to the default-set-adding code above. if (set == null) { set = tankSets[0]; } set.addModel(mainTankModules[i]); } topNodeNames = SSTUUtils.parseCSV(topManagedNodeNames); bottomNodeNames = SSTUUtils.parseCSV(bottomManagedNodeNames); tankModule = new ModelModule <TankModelData, SSTUModularFuelTank>(part, this, getRootTransform(rootTransformName, true), ModelOrientation.CENTRAL, nameof(bodyModuleData), nameof(currentTankType), nameof(currentTankTexture)); tankModule.getSymmetryModule = m => m.tankModule; tankModule.getDisplayNames = m => SSTUUtils.getNames(m, s => s.variantName); tankModule.setupModelList(mainTankModules); currentTankSetModule = Array.Find(tankSets, m => m.name == tankModule.model.setName); currentTankSet = currentTankSetModule.name; lastSelectedVariant = tankModule.model.variantName; tankModule.getValidSelections = delegate(IEnumerable <TankModelData> data) { return(System.Linq.Enumerable.Where(data, s => s.setName == currentTankSet)); }; tankModule.updateSelections(); tankModule.setupModel(); len = mountNodes.Length; ConfigNode mountNode; List <SingleModelData> noses = new List <SingleModelData>(); List <SingleModelData> mounts = new List <SingleModelData>(); for (int i = 0; i < len; i++) { mountNode = mountNodes[i]; if (mountNode.GetBoolValue("useForNose", true)) { mountNode.SetValue("nose", "true"); noses.Add(new SingleModelData(mountNode)); } if (mountNode.GetBoolValue("useForMount", true)) { mountNode.SetValue("nose", "false"); mounts.Add(new SingleModelData(mountNode)); } } noseModule = new ModelModule <SingleModelData, SSTUModularFuelTank>(part, this, getRootTransform(rootNoseTransformName, true), ModelOrientation.TOP, nameof(noseModuleData), nameof(currentNoseType), nameof(currentNoseTexture)); noseModule.getSymmetryModule = m => m.noseModule; noseModule.getValidSelections = delegate(IEnumerable <SingleModelData> data) { return(System.Linq.Enumerable.Where(data, m => m.canSwitchTo(part, topNodeNames) && TankVariant.isValidNose(m.name, tankModule.model.variantName, variantData))); }; noseModule.setupModelList(noses); noseModule.setupModel(); mountModule = new ModelModule <SingleModelData, SSTUModularFuelTank>(part, this, getRootTransform(rootMountTransformName, true), ModelOrientation.BOTTOM, nameof(mountModuleData), nameof(currentMountType), nameof(currentMountTexture)); mountModule.getSymmetryModule = m => m.mountModule; mountModule.getValidSelections = delegate(IEnumerable <SingleModelData> data) { return(System.Linq.Enumerable.Where(data, m => m.canSwitchTo(part, bottomNodeNames) && TankVariant.isValidMount(m.name, tankModule.model.variantName, variantData))); }; mountModule.setupModelList(mounts); mountModule.setupModel(); }
public override void OnStart(StartState state) { base.OnStart(state); initialize(); string[] groupNames = TankSet.getSetNames(tankSets); this.updateUIChooseOptionControl(nameof(currentTankSet), groupNames, groupNames, true, currentTankSet); string[] names = currentTankSetModule.getModelNames(); string[] descs = currentTankSetModule.getTankDescriptions(); this.updateUIChooseOptionControl(nameof(currentTankType), names, descs, true, currentTankType); if (maxTankDiameter == minTankDiameter) { Fields[nameof(currentTankDiameter)].guiActiveEditor = false; } else { this.updateUIFloatEditControl(nameof(currentTankDiameter), minTankDiameter, maxTankDiameter, tankDiameterIncrement * 2, tankDiameterIncrement, tankDiameterIncrement * 0.05f, true, currentTankDiameter); } updateAvailableVariants(false); updateUIScaleControls(); Fields[nameof(currentTankDiameter)].uiControlEditor.onFieldChanged = delegate(BaseField a, object b) { this.actionWithSymmetry(m => { m.updateEditorStats(true); SSTUAttachNodeUtils.updateSurfaceAttachedChildren(m.part, m.prevTankDiameter, m.currentTankDiameter); SSTUModInterop.onPartGeometryUpdate(m.part, true); }); SSTUStockInterop.fireEditorUpdate(); }; Fields[nameof(currentTankVerticalScale)].uiControlEditor.onFieldChanged = delegate(BaseField a, object b) { this.actionWithSymmetry(m => { m.updateEditorStats(true); SSTUModInterop.onPartGeometryUpdate(m.part, true); }); SSTUStockInterop.fireEditorUpdate(); }; Fields[nameof(currentTankSet)].uiControlEditor.onFieldChanged = delegate(BaseField a, object b) { this.actionWithSymmetry(m => { TankSet newSet = Array.Find(m.tankSets, s => s.name == m.currentTankSet); m.currentTankSetModule = newSet; string variant = m.lastSelectedVariant; m.currentTankType = newSet.getDefaultModel(m.lastSelectedVariant); m.tankModule.updateSelections(); m.tankModule.modelSelected(m.currentTankType); m.Fields[nameof(m.currentTankType)].guiActiveEditor = newSet.Length > 1; //re-seat this if it was changed in the 'setMainTankModuleFromEditor' method //will allow for user-initiated main-tank changes to still change the 'last variant' but will //persist the variant if the newly selected set did not contain the selected variant //so that it will persist to the next set selection, OR be reseated on the next user-tank selection within the current set if (!m.currentTankSetModule.hasVariant(variant)) { m.lastSelectedVariant = variant; } if (m.variantData != null) { m.updateAvailableVariants(true); } m.updateEditorStats(true); m.updateUIScaleControls(); SSTUModInterop.onPartGeometryUpdate(m.part, true); }); SSTUStockInterop.fireEditorUpdate(); }; Fields[nameof(currentNoseType)].uiControlEditor.onFieldChanged = delegate(BaseField a, object b) { noseModule.modelSelected(a, b); this.actionWithSymmetry(m => { m.updateEditorStats(true); m.updateAnimationControl(m.noseAnimationID, m.noseModule.model, 1); SSTUModInterop.onPartGeometryUpdate(m.part, true); }); SSTUStockInterop.fireEditorUpdate(); }; Fields[nameof(currentTankType)].uiControlEditor.onFieldChanged = delegate(BaseField a, object b) { tankModule.modelSelected(a, b); this.actionWithSymmetry(m => { if (variantData != null) { m.updateAvailableVariants(true); } m.updateEditorStats(true); m.lastSelectedVariant = tankModule.model.variantName; m.updateAnimationControl(m.bodyAnimationID, m.tankModule.model, 3); m.updateUIScaleControls(); SSTUModInterop.onPartGeometryUpdate(m.part, true); }); SSTUStockInterop.fireEditorUpdate(); }; Fields[nameof(currentMountType)].uiControlEditor.onFieldChanged = delegate(BaseField a, object b) { mountModule.modelSelected(a, b); this.actionWithSymmetry(m => { m.updateEditorStats(true); m.updateAnimationControl(m.mountAnimationID, m.mountModule.model, 5); SSTUModInterop.onPartGeometryUpdate(m.part, true); }); SSTUStockInterop.fireEditorUpdate(); }; Fields[nameof(currentNoseTexture)].uiControlEditor.onFieldChanged = noseModule.textureSetSelected; Fields[nameof(currentTankTexture)].uiControlEditor.onFieldChanged = tankModule.textureSetSelected; Fields[nameof(currentMountTexture)].uiControlEditor.onFieldChanged = mountModule.textureSetSelected; Fields[nameof(currentTankSet)].guiActiveEditor = tankSets.Length > 1; Fields[nameof(currentTankType)].guiActiveEditor = currentTankSetModule.Length > 1; Fields[nameof(currentNoseType)].guiActiveEditor = noseModule.models.Count > 1; Fields[nameof(currentMountType)].guiActiveEditor = mountModule.models.Count > 1; SSTUStockInterop.fireEditorUpdate(); SSTUModInterop.onPartGeometryUpdate(part, true); if (HighLogic.LoadedSceneIsEditor) { GameEvents.onEditorShipModified.Add(new EventData <ShipConstruct> .OnEvent(onEditorVesselModified)); } }