Esempio n. 1
0
 public void LateUpdate()
 {
     //MonoBehaviour.print("Checking late update1: " + needsStatusUpdate + " :: " + needsRebuilt);
     if (externalUpdateData != null)
     {
         updateFromExternalData(externalUpdateData);
     }
     //MonoBehaviour.print("Checking late update2: " + needsStatusUpdate + " :: " + needsRebuilt);
     if (needsStatusUpdate)
     {
         updateFairingStatus();
     }
     //MonoBehaviour.print("Checking late update3: " + needsStatusUpdate + " :: " + needsRebuilt);
     if (needsRebuilt)
     {
         rebuildFairing();
         updatePersistentDataString();
         ROTStockInterop.fireEditorUpdate();
         needsGuiUpdate = true;
         needsRebuilt   = false;
     }
     if (needsGuiUpdate)
     {
         updateGuiState();
         needsGuiUpdate = false;
     }
     if (HighLogic.LoadedSceneIsEditor && fairingParts != null)
     {
         updateOpacity();
     }
 }
Esempio n. 2
0
 /// <summary>
 /// Updates part highlight renderer list, sends message to ModuleROTFlagDecal to update its renderer,
 ///  sends message to FAR to update voxels, or if createDefaultCube==true will re-render the 'default' stock drag cube for the part<para/>
 /// Should be called anytime the model geometry in a part is changed -- either models added/deleted, procedural meshes updated.  Other methods exist for pure drag-cube updating in ROTStockInterop.
 /// </summary>
 /// <param name="part"></param>
 /// <param name="createDefaultCube"></param>
 public static void onPartGeometryUpdate(Part part, bool createDefaultCube)
 {
     if (!HighLogic.LoadedSceneIsEditor && !HighLogic.LoadedSceneIsFlight)
     {
         return;
     }                                                                                //noop on prefabs
     //MonoBehaviour.print(System.Environment.StackTrace);
     ROTStockInterop.updatePartHighlighting(part);
     part.airlock = locateAirlock(part);
     partGeometryUpdate(part);
     if (isFARInstalled())
     {
         ROTStockInterop.addFarUpdatePart(part);
         //FARdebug(part);
         //part.SendMessage("GeometryPartModuleRebuildMeshData");
     }
     else if (createDefaultCube && (HighLogic.LoadedSceneIsEditor || HighLogic.LoadedSceneIsFlight))
     {
         ROTStockInterop.addDragUpdatePart(part);
     }
     if (HighLogic.LoadedSceneIsEditor && part.parent == null && part != EditorLogic.RootPart) //likely the part under the cursor; this fixes problems with modular parts not wanting to attach to stuff
     {
         part.gameObject.SetLayerRecursive(1, 2097152);                                        //1<<21 = Part Triggers get skipped by the relayering (hatches, ladders, ??)
     }
 }
Esempio n. 3
0
 public void Start()
 {
     INSTANCE = this;
     KSPShaderTools.TexturesUnlimitedLoader.addPostLoadCallback(KSPShaderToolsPostLoad);
     GameObject.DontDestroyOnLoad(this);
     MonoBehaviour.print("ROTStockInterop Start");
 }
Esempio n. 4
0
        private void initialize()
        {
            if (initialized)
            {
                return;
            }
            initialized = true;

            prevDiameter = currentDiameter;

            coreNodeNames = ROTUtils.parseCSV(coreManagedNodes);

            //model-module setup/initialization
            ConfigNode node = ROTConfigNodeUtils.parseConfigNode(configNodeData);

            //list of CORE model nodes from config
            //each one may contain multiple 'model=modelDefinitionName' entries
            //but must contain no more than a single 'variant' entry.
            //if no variant is specified, they are added to the 'Default' variant.
            ConfigNode[] coreDefNodes = node.GetNodes("CORE");
            ModelDefinitionLayoutOptions[]      coreDefs;
            List <ModelDefinitionLayoutOptions> coreDefList = new List <ModelDefinitionLayoutOptions>();
            int coreDefLen = coreDefNodes.Length;

            for (int i = 0; i < coreDefLen; i++)
            {
                string variantName = coreDefNodes[i].GetStringValue("variant", "Default");
                coreDefs = ROTModelData.getModelDefinitionLayouts(coreDefNodes[i].GetStringValues("model"));
                coreDefList.AddUniqueRange(coreDefs);
                ModelDefinitionVariantSet mdvs = getVariantSet(variantName);
                mdvs.addModels(coreDefs);
            }
            coreDefs = coreDefList.ToArray();

            coreModule      = new ROTModelModule <ModuleROTProbe>(part, this, getRootTransform("ModularProbe-CORE"), ModelOrientation.CENTRAL, nameof(currentCore), null, nameof(currentCoreTexture), nameof(coreModulePersistentData));
            coreModule.name = "ModularProbe-Core";
            coreModule.getSymmetryModule = m => m.coreModule;
            coreModule.getValidOptions   = () => getVariantSet(currentVariant).definitions;

            coreModule.massScalar   = massScalingPower;
            coreModule.volumeScalar = volumeScalingPower;

            //set up the model lists and load the currently selected model
            coreModule.setupModelList(coreDefs);
            coreModule.setupModel();

            updateModulePositions();
            updateMassAndDimensions();
            updateAttachNodes(false);
            updateAvailableVariants();
            ROTStockInterop.updatePartHighlighting(part);
        }
Esempio n. 5
0
        /// <summary>
        /// Initialize the UI controls, including default values, and specifying delegates for their 'onClick' methods.<para/>
        /// All UI based interaction code will be defined/run through these delegates.
        /// </summary>
        private void initializeUI()
        {
            Action <ModuleROTank> modelChangedAction = (m) =>
            {
                m.updateModulePositions();
                m.updateDimensions();
                m.updateAttachNodes(true);
                m.updateFairing(true);
                m.updateAvailableVariants();
                m.updateDragCubes();
                ROTModInterop.updateResourceVolume(m.part);
            };

            //set up the core variant UI control
            string[] variantNames = ROTUtils.getNames(variantSets.Values, m => m.variantName);
            this.updateUIChooseOptionControl(nameof(currentVariant), variantNames, variantNames, true, currentVariant);
            Fields[nameof(currentVariant)].guiActiveEditor = variantSets.Count > 1;

            Fields[nameof(currentVariant)].uiControlEditor.onFieldChanged = (a, b) =>
            {
                //TODO find variant set for the currently enabled core model
                //query the index from that variant set
                ModelDefinitionVariantSet prevMdvs = getVariantSet(coreModule.definition.name);
                //this is the index of the currently selected model within its variant set
                int previousIndex = prevMdvs.indexOf(coreModule.layoutOptions);
                //grab ref to the current/new variant set
                ModelDefinitionVariantSet mdvs = getVariantSet(currentVariant);
                //and a reference to the model from same index out of the new set ([] call does validation internally for IAOOBE)
                ModelDefinitionLayoutOptions newCoreDef = mdvs[previousIndex];
                //now, call model-selected on the core model to update for the changes, including symmetry counterpart updating.
                this.actionWithSymmetry(m =>
                {
                    m.currentVariant = currentVariant;
                    m.coreModule.modelSelected(newCoreDef.definition.name);
                    modelChangedAction(m);
                });
            };

            Fields[nameof(currentDiameter)].uiControlEditor.onFieldChanged = (a, b) =>
            {
                this.actionWithSymmetry(m =>
                {
                    if (m != this)
                    {
                        m.currentDiameter = this.currentDiameter;
                    }
                    modelChangedAction(m);
                    m.prevDiameter = m.currentDiameter;
                });
                ROTStockInterop.fireEditorUpdate();
            };

            Fields[nameof(currentVScale)].uiControlEditor.onFieldChanged = (a, b) =>
            {
                this.actionWithSymmetry(m =>
                {
                    if (m != this)
                    {
                        m.currentVScale = this.currentVScale;
                    }
                    modelChangedAction(m);
                });
                ROTStockInterop.fireEditorUpdate();
            };

            Fields[nameof(currentNose)].uiControlEditor.onFieldChanged = (a, b) =>
            {
                noseModule.modelSelected(a, b);
                this.actionWithSymmetry(modelChangedAction);
                ROTStockInterop.fireEditorUpdate();
            };

            Fields[nameof(currentCore)].uiControlEditor.onFieldChanged = (a, b) =>
            {
                coreModule.modelSelected(a, b);
                this.actionWithSymmetry(modelChangedAction);
                ROTStockInterop.fireEditorUpdate();
            };

            Fields[nameof(currentMount)].uiControlEditor.onFieldChanged = (a, b) =>
            {
                mountModule.modelSelected(a, b);
                this.actionWithSymmetry(modelChangedAction);
                ROTStockInterop.fireEditorUpdate();
            };

            //------------------MODEL DIAMETER SWITCH UI INIT---------------------//
            if (maxDiameter == minDiameter)
            {
                Fields[nameof(currentDiameter)].guiActiveEditor = false;
            }
            else
            {
                this.updateUIFloatEditControl(nameof(currentDiameter), minDiameter, maxDiameter, diameterLargeStep, diameterSmallStep, diameterSlideStep, true, currentDiameter);
            }
            Fields[nameof(currentVScale)].guiActiveEditor = enableVScale;

            //------------------MODULE TEXTURE SWITCH UI INIT---------------------//
            Fields[nameof(currentNoseTexture)].uiControlEditor.onFieldChanged  = noseModule.textureSetSelected;
            Fields[nameof(currentCoreTexture)].uiControlEditor.onFieldChanged  = coreModule.textureSetSelected;
            Fields[nameof(currentMountTexture)].uiControlEditor.onFieldChanged = mountModule.textureSetSelected;

            if (HighLogic.LoadedSceneIsEditor)
            {
                GameEvents.onEditorShipModified.Add(new EventData <ShipConstruct> .OnEvent(onEditorVesselModified));
            }
        }