示例#1
0
 private void FindAnimations()
 {
     Animation[] componentsInChildren = part.transform.ROLFindRecursive("model").GetComponentsInChildren <Animation>();
     foreach (Animation a in componentsInChildren)
     {
         if (a.GetClip(this.animationName) != null)
         {
             ROLLog.debug($"[AnimDebug] Animation: {a}");
             this.anim = a;
             ROLLog.debug($"a.GetClip(this.animationName) this.anim: {this.anim}");
         }
     }
     if (componentsInChildren.Length > 0 && this.anim == null)
     {
         this.anim = componentsInChildren[0];
         ROLLog.debug($"componentsInChildren.Length > 0 - this.anim: {this.anim}");
     }
     if (this.anim == null)
     {
         this.useAnimation = false;
     }
     else
     {
         this.useAnimation = true;
     }
 }
示例#2
0
        private void UpdateAttachNodes(bool userInput)
        {
            coreModule.updateAttachNodeBody(coreNodeNames, userInput);
            AttachNode surfaceNode = part.srfAttachNode;

            ROLLog.debug($"part.srfAttachNode: {part.srfAttachNode}");
            coreModule.updateSurfaceAttachNode(surfaceNode, panelLength, panelWidth, userInput);
        }
示例#3
0
        private void UpdateMassAndCost()
        {
            lengthWidth = coreModule.definition.lengthWidth;
            if (!lengthWidth)
            {
                ROLLog.debug($"UpdateMassAndCost() lengthWidth false");
                area = coreModule.definition.panelArea * panelScale * panelScale;
                ROLLog.debug($"coreModule.definition.panelArea: {coreModule.definition.panelArea}");
                ROLLog.debug($"panelScale: {panelScale}");
                ROLLog.debug($"area: {area}");
            }
            else
            {
                ROLLog.debug($"UpdateMassAndCost() lengthWidth true");
                float lengthScale = panelLength / coreModule.definition.panelLength;
                float widthScale  = panelWidth / coreModule.definition.panelWidth;
                area = coreModule.definition.panelArea * lengthScale * widthScale;
                ROLLog.debug($"coreModule.definition.panelArea: {coreModule.definition.panelArea}");
                ROLLog.debug($"lengthScale: {lengthScale}");
                ROLLog.debug($"widthScale: {widthScale}");
                ROLLog.debug($"area: {area}");
            }

            kgPerM2   = stl.kgPerM2;
            costPerM2 = stl.costPerM2;
            mass      = area * kgPerM2;
            cost      = area * costPerM2;
            switch (solarPanelType)
            {
            case "hinged":
                mass *= stl.massMultHinged;
                cost *= stl.costMultHinged;
                break;

            case "folded":
                mass *= stl.massMultFolded;
                cost *= stl.costMultFolded;
                break;

            case "tracking":
                mass *= stl.massMultTrack;
                cost *= stl.costMultTrack;
                break;

            default:
                break;
            }
            if (addMass > 0)
            {
                mass += addMass;
            }
            if (addCost > 0)
            {
                cost += addCost;
            }
            modifiedMass = mass = Math.Max(mass, 0.0001f);
            modifiedCost = cost = Math.Max(cost, 0.1f);
        }
示例#4
0
        /// <summary>
        /// Updates all dimensions for the PAW and tooling.
        /// </summary>
        public void UpdateDimensions()
        {
            float mountMaxDiam = currentMount.Contains("Mount") ? mountModule.moduleUpperDiameter : Math.Max(mountModule.moduleLowerDiameter, mountModule.moduleUpperDiameter);
            float noseMaxDiam  = Math.Max(noseModule.moduleLowerDiameter, noseModule.moduleUpperDiameter);

            totalTankLength = GetTotalHeight();
            largestDiameter = Math.Max(currentDiameter, Math.Max(noseMaxDiam, mountMaxDiam));
            ROLLog.debug($"UpdateDimensions() currentMount: {currentMount}  Largest Diameter: {largestDiameter}.  Total Tank length: {totalTankLength}");
        }
示例#5
0
 private bool FindDecoupler()
 {
     ROLLog.debug("Finding Decoupler...");
     if (decouple == null)
     {
         decouple = part.Modules["ModuleDecouple"] as ModuleDecouple;
     }
     return(decouple != null);
 }
示例#6
0
 public override void OnLoad(ConfigNode node)
 {
     base.OnLoad(node);
     if (string.IsNullOrEmpty(configNodeData))
     {
         ROLLog.debug($"{modName}: OnLoad loading configNodeData");
         configNodeData = node.ToString();
         ROLLog.debug($"{modName}: OnLoad() configNodeData: {configNodeData}");
     }
     ROLLog.debug($"{modName}: OnLoad calling Initialize()");
     Initialize();
 }
示例#7
0
        private void SetupUICallbacks()
        {
            ROLLog.debug("Setting up UICallbacks...");
            if (FindModularPart() is ModuleROTank p)
            {
                ROLLog.debug("p: " + p);
                ROLLog.debug("p.Fields[nameof(p.currentDiameter): " + p.Fields[nameof(p.currentDiameter)]);
                ROLLog.debug("p.Fields: " + p.Fields);

                UI_FloatEdit mp = p.Fields[nameof(p.currentDiameter)].uiControlEditor as UI_FloatEdit;
                mp.onFieldChanged += new Callback <BaseField, object>(OnDiameterChange);
            }
        }
示例#8
0
 public static void Init(ConfigNode config)
 {
     ROLLog.debug($"{modTag}: Init() Started");
     allTL.Clear();
     foreach (ConfigNode node in config.GetNodes("ROS_TECH"))
     {
         SolarTechLimit obj = ConfigNode.CreateObjectFromConfig <SolarTechLimit>(node);
         ROLLog.debug($"{modTag}: Adding ROSTL {obj}");
         allTL.Add(obj.level, obj);
         maxTL = Math.Max(maxTL, obj.level);
     }
     isInitialized = true;
 }
示例#9
0
        /// <summary>
        /// Return the total height of this part in its current configuration.  This will be the distance from the bottom attach node to the top attach node, and may not include any 'extra' structure. TOOLING
        /// </summary>
        /// <returns></returns>
        private float getTotalHeight()
        {
            float totalHeight = noseModule.moduleHeight;

            totalHeight += mountModule.moduleHeight;
            if (currentCore.Contains("Booster"))
            {
                ROLLog.debug("currentCore: " + currentCore);
                totalHeight += coreModule.moduleActualHeight;
            }
            else
            {
                totalHeight += coreModule.moduleHeight;
            }
            return(totalHeight);
        }
示例#10
0
        public void toggleNode()
        {
            AttachNode node = part.FindAttachNode(nodeName);

            ROLLog.debug("toggleNode() node: " + node);
            if (node == null)
            {
                currentlyEnabled = true;
                ROLAttachNodeUtils.createAttachNode(part, nodeName, nodeDefaultPosition, nodeDefaultOrientation, 2);
            }
            else if (node.attachedPart == null)
            {
                currentlyEnabled = false;
                ROLAttachNodeUtils.destroyAttachNode(part, node);
            }
        }
示例#11
0
 public override void OnStart(StartState state)
 {
     ROLLog.debug($"OnStart(state)");
     base.OnStart(state);
     ROLLog.debug($"this.anim: {this.anim}");
     ROLLog.debug("Anim loop");
     foreach (Animation a in this.GetComponentsInChildren <Animation>())
     {
         ROLLog.debug($"[AnimDebug] Animation: {a}");
     }
     ROLLog.debug("Anim loop done");
     SetMaxTechLevel();
     ROLLog.debug($"{modName} OnStart calling Initialize()");
     Initialize();
     ROLLog.debug($"{modName} OnStart calling InitializeUI()");
     InitializeUI();
 }
示例#12
0
        /// <summary>
        /// Update the scale and position values for all currently configured models.  Does no validation, only updates positions.<para/>
        /// After calling this method, all models will be scaled and positioned according to their internal position/scale values and the orientations/offsets defined in the models.
        /// </summary>
        public void updateModulePositions()
        {
            ROLLog.debug($"UpdateModulePositions()");
            //scales for modules depend on the module above/below them
            //first set the scale for the core module -- this depends directly on the UI specified 'diameter' value.
            if (lengthWidth)
            {
                debug($"UpdateModulePositions(): setScaleForHeightAndDiameter");
                coreModule.setScaleForHeightAndDiameter(currentLength, currentDiameter);
            }
            else
            {
                debug($"UpdateModulePositions(): setScaleForDiameter");
                coreModule.setScaleForDiameter(currentDiameter, currentVScale);
            }
            ROLLog.debug($"UpdateModulePositions(): currentDiameter: {currentDiameter}, currentVScale: {currentVScale}");

            //next, set nose scale values
            noseModule.setDiameterFromBelow(coreModule.moduleUpperDiameter, currentVScale);

            //finally, set mount scale values
            mountModule.setDiameterFromAbove(coreModule.moduleLowerDiameter, currentVScale);

            //total height of the part is determined by the sum of the heights of the modules at their current scale
            float totalHeight = noseModule.moduleHeight;

            totalHeight += coreModule.moduleHeight;
            totalHeight += mountModule.moduleHeight;

            //position of each module is set such that the vertical center of the models is at part origin/COM
            float pos = totalHeight * 0.5f;        //abs top of model

            pos -= noseModule.moduleHeight;        //bottom of nose model
            noseModule.setPosition(pos);
            pos -= coreModule.moduleHeight * 0.5f; //center of 'core' model
            coreModule.setPosition(pos);
            pos -= coreModule.moduleHeight * 0.5f; //bottom of 'core' model
            mountModule.setPosition(pos);

            //update actual model positions and scales
            noseModule.updateModelMeshes();
            coreModule.updateModelMeshes();
            mountModule.updateModelMeshes();
        }
示例#13
0
        public override void OnStartFinished(StartState state)
        {
            base.OnStartFinished(state);

            ROLLog.debug("OnStartFinished()...");
            if (!FindModularPart())
            {
                ROLLog.error("Unable to find any Modular Part modules");
                isEnabled = enabled = false;
                return;
            }

            SetupUICallbacks();

            if (HighLogic.LoadedSceneIsEditor)
            {
                UpdateImpulseValues();
            }
        }
示例#14
0
        /// <summary>
        /// Updates all dimensions for the PAW and tooling.
        /// </summary>
        public void updateDimensions()
        {
            float noseMaxDiam, mountMaxDiam = 0.0f;

            noseMaxDiam = Math.Max(noseModule.moduleLowerDiameter, noseModule.moduleUpperDiameter);
            ROLLog.debug("currentMount: " + currentMount);
            if (currentMount.Contains("Mount"))
            {
                ROLLog.debug("currentMount: " + currentMount);
                mountMaxDiam = mountModule.moduleUpperDiameter;
            }
            else
            {
                mountMaxDiam = Math.Max(mountModule.moduleLowerDiameter, mountModule.moduleUpperDiameter);
            }

            totalTankLength = getTotalHeight();
            ROLLog.debug("The Total Tank Length is: " + totalTankLength);
            largestDiameter = Math.Max(currentDiameter, Math.Max(noseMaxDiam, mountMaxDiam));
        }
示例#15
0
        public static bool RealFuelsVolumeUpdate(Part part, float liters)
        {
            if (!IsRFInstalled() && !IsMFTInstalled())
            {
                ROLLog.error($"Config for {part} is set to use RF/MFT, but neither RF nor MFT is installed, cannot update part volumes through them.  Please check your configs and/or patches for errors.");
                return(false);
            }

            if (MFTChangeTotalVolumeMI is MethodInfo && MFTCalculateMassMI is MethodInfo && GetModuleFuelTanks(part) is PartModule pm)
            {
                double volumeLiters = liters;
                MFTChangeTotalVolumeMI.Invoke(pm, new object[] { volumeLiters, false });
                MFTCalculateMassMI.Invoke(pm, new object[] { });
                UpdatePartResourceDisplay(part);
                ROLLog.debug($"ROTModInterop - Set RF/MFT total tank volume to: {volumeLiters} Liters for part: {part.name}");
                return(true);
            }
            else
            {
                ROLLog.error($"Could not find ModuleFuelTank in part {part} for RealFuels/MFT!");
                return(false);
            }
        }
示例#16
0
        private void SetModelFromDimensions()
        {
            currentVScale = 0.0f;

            if (!lengthWidth)
            {
                return;
            }

            // Round to nearest 0.5: Multiply by 2, round to nearest int, divide by 2.
            float dimRatio   = currentLength / currentDiameter;
            float modelRatio = Mathf.Round(dimRatio * 2) / 2;

            modelRatio = Mathf.Clamp(modelRatio, minModelRatio, maxModelRatio);

            string ratioName = $"{modelRatio:0.0}";
            string s         = $"{ratioName}x-{currentVariant}";

            ROLLog.debug($"dimRatio: {dimRatio}, modelRatio: {modelRatio}, {ratioName}x-{currentVariant}");

            currentVScale = (dimRatio / modelRatio) - 1;
            coreModule.modelSelected(s);
        }
示例#17
0
        private void UpdateModulePositions()
        {
            float height, pos = 0.0f;

            ROLLog.debug("UpdateModulePositions()");
            lengthWidth = coreModule.definition.lengthWidth;
            ROLLog.debug($"lengthWidth: {lengthWidth}");
            if (lengthWidth)
            {
                coreModule.setScaleForHeightAndDiameter(panelLength, panelWidth, lengthWidth);
                height = panelLength;
            }
            else
            {
                coreModule.setScaleForHeightAndDiameter(panelScale, panelScale, lengthWidth);
                height = coreModule.moduleHeight;
            }
            pos = height * 0.5f;
            coreModule.setPosition(pos);
            coreModule.updateModelMeshes(lengthWidth);

            /*
             * if (fullScale)
             * {
             *  ROLLog.debug("UpdateModulePositions() fullScale");
             *  float currentDiameter = coreModule.definition.diameter * panelScale;
             *  coreModule.setScaleForDiameter(currentDiameter, 1);
             *  height = coreModule.moduleHeight;
             *  pos = height * 0.5f;
             *  coreModule.setPosition(pos);
             *  coreModule.updateModelMeshes();
             * }
             * else
             * {
             *  ROLLog.debug("UpdateModulePositions()");
             *  lengthWidth = coreModule.definition.lengthWidth;
             *  ROLLog.debug($"lengthWidth: {lengthWidth}");
             *  if (lengthWidth)
             *  {
             *      coreModule.setScaleForHeightAndDiameter(panelLength, panelWidth, lengthWidth);
             *      height = coreModule.modulePanelLength;
             *  }
             *  else
             *  {
             *      coreModule.setScaleForHeightAndDiameter(panelScale, panelScale, lengthWidth);
             *      height = coreModule.moduleHeight;
             *  }
             *  pos = height * 0.5f;
             *  coreModule.setPosition(pos);
             *  coreModule.updateModelMeshes(lengthWidth);
             * }
             */

            ROLLog.debug("Setting the rotation and animation for the solar panel.");

            this.animationName = coreModule.definition.animationName;
            if (!this.animationName.Equals("fakeAnimation"))
            {
                ROLLog.debug("Get the animations");
                FindAnimations();
                this.anim[this.animationName].wrapMode = WrapMode.ClampForever;
                switch (this.deployState)
                {
                case DeployState.RETRACTED:
                    this.anim[this.animationName].normalizedTime = 0.0f;
                    this.anim[this.animationName].enabled        = true;
                    this.anim[this.animationName].weight         = 1f;
                    this.anim.Stop(this.animationName);
                    this.Events["Retract"].active = false;
                    this.Events["Extend"].active  = true;
                    break;

                case DeployState.EXTENDED:
                    this.anim[this.animationName].normalizedTime = 1f;
                    this.anim[this.animationName].enabled        = true;
                    this.anim[this.animationName].speed          = 0.0f;
                    this.anim[this.animationName].weight         = 1f;
                    this.Events["Extend"].active  = false;
                    this.Events["Retract"].active = true;
                    break;

                default:
                    break;
                }
            }

            if (pivotName.Equals("sunPivot"))
            {
                ROLLog.debug("Set hasPivot to false");
                this.hasPivot = false;
                ROLLog.debug($"this.hasPivot: {this.hasPivot}");
            }

            this.pivotName = coreModule.GetPivotName();
            this.panelRotationTransform = this.part.FindModelTransform(this.pivotName);
            this.originalRotation       = this.currentRotation = this.panelRotationTransform.localRotation;
            this.secondaryTransformName = this.raycastTransformName = coreModule.GetSecondaryTransform();

            /*
             * if (pivotName == "sunPivot")
             * {
             *  ROLLog.debug("sunPivot");
             *  this.deployState = DeployState.RETRACTED;
             *  FindAnimations();
             *  this.animationName = coreModule.definition.animationName;
             *  this.anim[this.animationName].wrapMode = WrapMode.ClampForever;
             *  //ROLLog.debug("Set pivotName to null");
             *  //this.pivotName = null;
             *  //ROLLog.debug($"this.pivotName: {this.pivotName}");
             *  //ROLLog.debug("Get the animationName");
             *  //this.animationName = coreModule.definition.animationName;
             *  //ROLLog.debug($"this.animationName: {this.animationName}");
             *  ROLLog.debug("Set hasPivot to false");
             *  this.hasPivot = false;
             *  ROLLog.debug($"this.hasPivot: {this.hasPivot}");
             *  //ROLLog.debug("Set useAnimation to true");
             *  //this.useAnimation = true;
             *  //ROLLog.debug($"this.useAnimation: {this.useAnimation}");
             *  //ROLLog.debug("Set this.anim to this.animationName");
             *  //this.anim.GetClip(this.animationName);
             *  //ROLLog.debug($"this.anim: {this.anim}");
             *  this.pivotName = coreModule.GetPivotName();
             *  this.panelRotationTransform = this.part.FindModelTransform(this.pivotName);
             *  this.originalRotation = this.currentRotation = this.panelRotationTransform.localRotation;
             *  //FindAnimations();
             *  //ROLLog.debug($"this.anim: {this.anim}");
             *  //ROLLog.debug("Anim loop");
             *  //foreach (Animation a in this.GetComponentsInChildren<Animation>())
             *  //{
             *  //    ROLLog.debug($"[AnimDebug] Animation: {a}");
             *  //}
             *  //ROLLog.debug("Anim loop done");
             * }
             * this.pivotName = coreModule.GetPivotName();
             * this.panelRotationTransform = this.part.FindModelTransform(this.pivotName);
             * this.originalRotation = this.currentRotation = this.panelRotationTransform.localRotation;
             * this.secondaryTransformName = this.raycastTransformName = coreModule.GetSecondaryTransform();
             */
        }
示例#18
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>
        public void InitializeUI()
        {
            ROLLog.debug($"ModuleDeployablePart.deployState: {this.deployState}");
            ROLLog.debug($"{modName}InitalizeUI() modelChangedAction");
            Action <ModuleROSolar> modelChangedAction = (m) =>
            {
                m.stl = SolarTechLimit.GetTechLevel(techLevel);
                m.UpdateModulePositions();
                m.UpdateAttachNodes(true);
                m.UpdateAvailableVariants();
                m.UpdateDragCubes();
                m.UpdateMassAndCost();
                m.RecalculateStats();
            };

            // Set up the core variant UI control
            string[] variantNames = ROLUtils.getNames(variantSets.Values, m => m.variantName);
            this.ROLupdateUIChooseOptionControl(nameof(currentVariant), variantNames, variantNames, true, currentVariant);
            Fields[nameof(currentVariant)].guiActiveEditor = variantSets.Count > 1;
            Fields[nameof(currentVariant)].uiControlEditor.onFieldChanged = (a, b) =>
            {
                // 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.ROLactionWithSymmetry(m =>
                {
                    m.currentVariant = currentVariant;
                    m.coreModule.modelSelected(newCoreDef.definition.name);
                    lengthWidth = coreModule.definition.lengthWidth;
                    if (!lengthWidth)
                    {
                        Fields[nameof(panelLength)].guiActiveEditor = false;
                        Fields[nameof(panelWidth)].guiActiveEditor  = false;
                        Fields[nameof(panelScale)].guiActiveEditor  = true;
                        this.ROLupdateUIFloatEditControl(nameof(panelScale), 0.1f, 100f, largeStep, smallStep, slideStep, true, panelScale);
                    }
                    else
                    {
                        Fields[nameof(panelLength)].guiActiveEditor = true;
                        Fields[nameof(panelWidth)].guiActiveEditor  = true;
                        Fields[nameof(panelScale)].guiActiveEditor  = false;
                        this.ROLupdateUIFloatEditControl(nameof(panelLength), minLength, maxLength, largeStep, smallStep, slideStep, true, panelLength);
                        this.ROLupdateUIFloatEditControl(nameof(panelWidth), minWidth, maxWidth, largeStep, smallStep, slideStep, true, panelWidth);
                    }
                    m.ResetModel();
                    modelChangedAction(m);
                });
            };

            Fields[nameof(currentCore)].uiControlEditor.onFieldChanged = (a, b) =>
            {
                coreModule.modelSelected(a, b);
                lengthWidth = coreModule.definition.lengthWidth;
                if (!lengthWidth)
                {
                    Fields[nameof(panelLength)].guiActiveEditor = false;
                    Fields[nameof(panelWidth)].guiActiveEditor  = false;
                    Fields[nameof(panelScale)].guiActiveEditor  = true;
                    this.ROLupdateUIFloatEditControl(nameof(panelScale), 0.1f, 100f, largeStep, smallStep, slideStep, true, panelScale);
                }
                else
                {
                    Fields[nameof(panelLength)].guiActiveEditor = true;
                    Fields[nameof(panelWidth)].guiActiveEditor  = true;
                    Fields[nameof(panelScale)].guiActiveEditor  = false;
                    this.ROLupdateUIFloatEditControl(nameof(panelLength), minLength, maxLength, largeStep, smallStep, slideStep, true, panelLength);
                    this.ROLupdateUIFloatEditControl(nameof(panelWidth), minWidth, maxWidth, largeStep, smallStep, slideStep, true, panelWidth);
                }
                this.ROLactionWithSymmetry(modelChangedAction);
                ROLStockInterop.fireEditorUpdate();
            };

            Fields[nameof(panelLength)].uiControlEditor.onFieldChanged = (a, b) =>
            {
                this.ROLactionWithSymmetry(m =>
                {
                    if (m != this)
                    {
                        m.panelLength = this.panelLength;
                    }
                    modelChangedAction(m);
                    m.prevLength = m.panelLength;
                });
                ROLStockInterop.fireEditorUpdate();
            };

            Fields[nameof(panelWidth)].uiControlEditor.onFieldChanged = (a, b) =>
            {
                this.ROLactionWithSymmetry(m =>
                {
                    if (m != this)
                    {
                        m.panelWidth = this.panelWidth;
                    }
                    modelChangedAction(m);
                    m.prevWidth = m.panelWidth;
                });
                ROLStockInterop.fireEditorUpdate();
            };

            Fields[nameof(panelScale)].uiControlEditor.onFieldChanged = (a, b) =>
            {
                this.ROLactionWithSymmetry(m =>
                {
                    if (m != this)
                    {
                        m.panelScale = this.panelScale;
                    }
                    modelChangedAction(m);
                    m.prevScale = m.panelScale;
                });
                ROLStockInterop.fireEditorUpdate();
            };

            if (maxLength == minLength || !lengthWidth)
            {
                Fields[nameof(panelLength)].guiActiveEditor = false;
            }
            else
            {
                this.ROLupdateUIFloatEditControl(nameof(panelLength), minLength, maxLength, largeStep, smallStep, slideStep, true, panelLength);
            }

            if (maxWidth == minWidth || !lengthWidth)
            {
                Fields[nameof(panelWidth)].guiActiveEditor = false;
            }
            else
            {
                this.ROLupdateUIFloatEditControl(nameof(panelWidth), minWidth, maxWidth, largeStep, smallStep, slideStep, true, panelWidth);
            }

            if (lengthWidth)
            {
                Fields[nameof(panelScale)].guiActiveEditor = false;
            }
            else
            {
                Fields[nameof(panelScale)].guiActiveEditor = true;
                this.ROLupdateUIFloatEditControl(nameof(panelScale), 0.1f, 100f, largeStep, smallStep, slideStep, true, panelScale);
            }

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

            Fields[nameof(TechLevel)].uiControlEditor.onFieldChanged = (a, b) =>
            {
                UpdateMassAndCost();
                RecalculateStats();
                this.ROLactionWithSymmetry(modelChangedAction);
                ROLStockInterop.fireEditorUpdate();
            };
        }
示例#19
0
        /// <summary>
        /// Initialization method.  Sets up model modules, loads their configs from the input config node.  Does all initial linking of part-modules.<para/>
        /// Does NOT set up their UI interaction -- that is all handled during OnStart()
        /// </summary>
        private void Initialize()
        {
            if (initialized)
            {
                return;
            }
            ROLLog.debug($"{modName}: Initialize Starting");
            initialized = true;

            prevLength = panelLength;
            prevWidth  = panelWidth;
            prevScale  = panelScale;

            ROLLog.debug($"{modName}: Initialize() parseCSV");
            coreNodeNames = ROLUtils.parseCSV(coreManagedNodes);

            ROLLog.debug($"{modName}: Initialize() Model-Module Initialization");
            // Model-Module Setup / Initialization
            ConfigNode node = ROLConfigNodeUtils.parseConfigNode(configNodeData);

            ROLLog.debug($"{modName}: Initialize() Core Model Nodes");
            // 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");

            ROLLog.debug($"{modName}: Initialize() MDLO");
            List <ModelDefinitionLayoutOptions> coreDefList = new List <ModelDefinitionLayoutOptions>();
            int coreDefLen = coreDefNodes.Length;

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

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

            coreModule.setupModelList(coreDefs);
            coreModule.setupModel();

            if (GameDatabase.Instance.GetConfigNode("ROSolar/TechLimits/ROSOLAR_CONFIG") is ConfigNode ROSconfig)
            {
                SolarTechLimit.Init(ROSconfig);
            }

            stl = SolarTechLimit.GetTechLevel(techLevel);

            UpdateModulePositions();
            UpdateAttachNodes(false);
            UpdateAvailableVariants();
            UpdateMassAndCost();
            RecalculateStats();
            ROLStockInterop.updatePartHighlighting(part);
        }
示例#20
0
 public void OpenTankDimensionGUIEvent()
 {
     ROLLog.debug("EditDimensions() called");
     EditDimensions(this);
 }
示例#21
0
        private void SetModelFromDimensions()
        {
            currentVScale = 0.0f;

            if (!lengthWidth)
            {
                return;
            }

            Action <ModuleROTank> modelChangedAction = (m) =>
            {
                m.updateModulePositions();
                m.updateDimensions();
                m.updateAttachNodes(true);
                m.updateAvailableVariants();
                m.updateDragCubes();
                if (scaleMass)
                {
                    m.updateMass();
                }
                if (scaleCost)
                {
                    m.updateCost();
                }
                m.UpdateTankVolume(lengthWidth);
            };

            float  dimRatio, modelRatio = 0.0f;
            string s = "1.0x-Kerolox";

            dimRatio = currentLength / currentDiameter;

            if (dimRatio < 0.625)
            {
                modelRatio = 0.5f;
            }
            else if (dimRatio < 1.25)
            {
                modelRatio = 1.0f;
            }
            else if (dimRatio < 1.75)
            {
                modelRatio = 1.5f;
            }
            else if (dimRatio < 2.25)
            {
                modelRatio = 2.0f;
            }
            else if (dimRatio < 2.75)
            {
                modelRatio = 2.5f;
            }
            else if (dimRatio < 3.25)
            {
                modelRatio = 3.0f;
            }
            else if (dimRatio < 3.75)
            {
                modelRatio = 3.5f;
            }
            else if (dimRatio < 4.25)
            {
                modelRatio = 4.0f;
            }
            else if (dimRatio < 4.75)
            {
                modelRatio = 4.5f;
            }
            else if (dimRatio < 5.25)
            {
                modelRatio = 5.0f;
            }
            else if (dimRatio < 5.75)
            {
                modelRatio = 5.5f;
            }
            else if (dimRatio < 6.25)
            {
                modelRatio = 6.0f;
            }
            else if (dimRatio < 6.75)
            {
                modelRatio = 6.5f;
            }
            else if (dimRatio < 7.25)
            {
                modelRatio = 7.0f;
            }
            else if (dimRatio < 7.75)
            {
                modelRatio = 7.5f;
            }
            else
            {
                modelRatio = 8.0f;
            }

            string ratioName = string.Format("{0:0.0}", modelRatio);

            s = $"{ratioName}x-{currentVariant}";
            ROLLog.debug($"dimRatio: {dimRatio}, modelRatio: {modelRatio}, string: {s}");

            currentVScale = (dimRatio / modelRatio) - 1;

            coreModule.modelSelected(s);
            this.ROLactionWithSymmetry(modelChangedAction);
            ROLStockInterop.fireEditorUpdate();
        }