Пример #1
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;
 }
Пример #2
0
 public override void OnLoad(ConfigNode node)
 {
     base.OnLoad(node);
     if (node.name != "CURRENTUPGRADE")
     {
         if (string.IsNullOrEmpty(configNodeData))
         {
             configNodeData = node.ToString();
         }
         Initialize();
         // OnStart() appears to be too late for setting the TimeEfficCurve for Kerbalism.
         // SolarPanelFixer is possibly getting this field too soon.
         stl = SolarTechLimit.GetTechLevel(techLevel);
         ReloadTimeCurve();
     }
 }
Пример #3
0
 internal void ModelChangedHandler(bool pushNodes)
 {
     stl         = SolarTechLimit.GetTechLevel(techLevel);
     retractable = stl.retractable && solarPanelType != "static";
     UpdateModulePositions();
     startFSM();
     UpdateAttachNodes(pushNodes);
     UpdateAvailableVariants();
     UpdateDragCubes();
     UpdateMassAndCost();
     RecalculateStats();
     ROLStockInterop.UpdatePartHighlighting(part);
     if (HighLogic.LoadedSceneIsEditor)
     {
         ROLStockInterop.FireEditorUpdate();
     }
 }
Пример #4
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();
            };
        }
Пример #5
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);
        }